[1938] | 1 | #include "glInterface.h"
|
---|
[1939] | 2 | #include "GlobalLinesRenderer.h"
|
---|
| 3 | #include "common.h"
|
---|
| 4 |
|
---|
[1938] | 5 | #include <Cg/cg.h>
|
---|
| 6 | #include <Cg/cgGL.h>
|
---|
| 7 |
|
---|
[1940] | 8 | #include <QtOpenGL>
|
---|
[1938] | 9 |
|
---|
| 10 | namespace GtpVisibilityPreprocessor {
|
---|
| 11 |
|
---|
| 12 | static CGcontext sCgContext = NULL;
|
---|
| 13 | static CGprogram sCgDepthPeelingProgram = NULL;
|
---|
| 14 | static CGprofile sCgFragmentProfile;
|
---|
| 15 |
|
---|
[1940] | 16 |
|
---|
[1938] | 17 | static void handleCgError()
|
---|
| 18 | {
|
---|
[1940] | 19 | cerr << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
|
---|
[1938] | 20 | exit(1);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
[1940] | 23 |
|
---|
| 24 | GlobalLinesRenderer::GlobalLinesRenderer(QGLPixelBuffer *buffer1, QGLPixelBuffer *buffer2):
|
---|
| 25 | mNewBuffer(buffer1), mOldBuffer(buffer2)
|
---|
[1938] | 26 | {
|
---|
[1940] | 27 | }
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | GlobalLinesRenderer::~GlobalLinesRenderer()
|
---|
| 31 | {
|
---|
[1938] | 32 | if (sCgDepthPeelingProgram)
|
---|
| 33 | cgDestroyProgram(sCgDepthPeelingProgram);
|
---|
| 34 | if (sCgContext)
|
---|
| 35 | cgDestroyContext(sCgContext);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[1940] | 38 |
|
---|
| 39 | void GlobalLinesRenderer::CastGlobalLines(Beam &beam, const int samples)
|
---|
| 40 | {
|
---|
| 41 | // bind pixel shader implementing the front depth buffer functionality
|
---|
| 42 | cgGLBindProgram(sCgDepthPeelingProgram);
|
---|
| 43 | cgGLEnableProfile(sCgFragmentProfile);
|
---|
[1938] | 44 |
|
---|
[1940] | 45 | ApplyDepthPeeling(beam, samples);
|
---|
| 46 | }
|
---|
[1938] | 47 |
|
---|
[1940] | 48 |
|
---|
| 49 | void GlobalLinesRenderer::DrawGeometry()
|
---|
| 50 | {
|
---|
[1938] | 51 | }
|
---|
[1940] | 52 |
|
---|
| 53 | void GlobalLinesRenderer::ApplyDepthPeeling(Beam &beam, const int samples)
|
---|
| 54 | {
|
---|
| 55 | /* if (rtNew->IsDoubleBuffered())
|
---|
| 56 | glDrawBuffer(GL_BACK);
|
---|
| 57 |
|
---|
| 58 | rtNew->BeginCapture();
|
---|
| 59 | {
|
---|
| 60 | cgGLBindProgram(passthru);
|
---|
| 61 | glColor3f(0,0.0,0.0);
|
---|
| 62 | DrawGeometry(); //just random geomerty
|
---|
| 63 | }
|
---|
| 64 | rtNew->EndCapture();
|
---|
| 65 |
|
---|
| 66 | for(int l = 0; l < mCurrentDepth; l++)
|
---|
| 67 | {
|
---|
| 68 | // Peel another layer
|
---|
| 69 | pingpong(); // switch pointer between rendertextures
|
---|
| 70 |
|
---|
| 71 | rtNew->BeginCapture();
|
---|
| 72 | {
|
---|
| 73 | if (rtNew->IsDoubleBuffered())
|
---|
| 74 | glDrawBuffer(GL_BACK);
|
---|
| 75 |
|
---|
| 76 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 77 |
|
---|
| 78 | cgGLBindProgram(fragmentProgram);
|
---|
| 79 | cgGLSetTextureParameter(input1, rtOld->GetDepthTextureID());
|
---|
| 80 | cgGLEnableTextureParameter(input1);
|
---|
| 81 |
|
---|
| 82 | glColor3f(0,0.0,0.0);
|
---|
| 83 | DrawGeometry();
|
---|
| 84 | cgGLDisableTextureParameter(input1);
|
---|
| 85 | }
|
---|
| 86 | rtNew->EndCapture();
|
---|
| 87 | }*/
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | }
|
---|