Skip to content

Commit b54be3b

Browse files
committed
[dp::culling::gl] Revive OpenGL frustum culling
Change-Id: I39dace0c856e1e99f0187e7f8cacf2c811d5be83 Reviewed-on: http://git-master/r/1258694 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Markus Tavenrath <[email protected]> Tested-by: Markus Tavenrath <[email protected]>
1 parent 72f91bc commit b54be3b

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

dp/culling/opengl/inc/ManagerImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace dp
5555
/************************************************************************/
5656
/* OpenGL resources */
5757
/************************************************************************/
58-
dp::gl::ProgramInstanceSharedPtr m_program;
58+
dp::gl::ProgramSharedPtr m_program;
5959
GLint m_uniformViewProjection;
6060
bool m_shaderInitialized;
6161
};

dp/culling/opengl/src/ManagerImpl.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848

4949
DP_STATIC_ASSERT( (WORKGROUP_SIZE % 32) == 0 );
5050

51-
#define OBJECT_BINDING 0
52-
#define MATRIX_BINDING 1
53-
#define VISIBILITY_BINDING 2
51+
// HACK when starting with offset 0 OBJECT_BINDING is not visible to the shader, find out why
52+
#define OBJECT_BINDING 1
53+
#define MATRIX_BINDING 2
54+
#define VISIBILITY_BINDING 3
5455

5556
//#define NO_GLSL_BARRIER
5657

@@ -117,28 +118,21 @@ static const char* shader =
117118
" uint cfa = 0xffffffff;\n"
118119
"\n"
119120
" mat4 modelViewProjection = viewProjection * modelView;\n"
120-
" vec4 vectors[8];\n"
121-
" vectors[0] = modelViewProjection * lower;\n"
121+
" vec4 point = modelViewProjection * lower; determineCullFlags( point, cfo, cfa );\n"
122122
"\n"
123123
" vec4 x = extent.x * modelViewProjection[0];\n"
124124
" vec4 y = extent.y * modelViewProjection[1];\n"
125125
" vec4 z = extent.z * modelViewProjection[2];\n"
126126
"\n"
127-
" vectors[1] = vectors[0] + x;\n"
128-
" vectors[2] = vectors[0] + y;\n"
129-
" vectors[3] = vectors[1] + y;\n"
130-
" vectors[4] = vectors[0] + z;\n"
131-
" vectors[5] = vectors[1] + z;\n"
132-
" vectors[6] = vectors[2] + z;\n"
133-
" vectors[7] = vectors[3] + z;\n"
127+
" point = point + x; determineCullFlags( point, cfo, cfa );\n"
128+
" point = point + y; determineCullFlags( point, cfo, cfa );\n"
129+
" point = point - x; determineCullFlags( point, cfo, cfa );\n"
130+
" point = point + z; determineCullFlags( point, cfo, cfa );\n"
131+
" point = point + x; determineCullFlags( point, cfo, cfa );\n"
132+
" point = point - x; determineCullFlags( point, cfo, cfa );\n"
133+
" point = point + x; determineCullFlags( point, cfo, cfa );\n"
134134
"\n"
135-
" for ( uint i = 0;i < 8; ++i )\n"
136-
" {\n"
137-
" determineCullFlags( vectors[i], cfo, cfa );\n"
138-
" }\n"
139-
140-
"\n"
141-
" return (cfo == 0) || (cfa == 0);\n"
135+
" return cfo == 0 || cfa == 0;\n"
142136
"}\n"
143137
"\n"
144138
"uniform mat4 viewProjection;\n"
@@ -147,7 +141,7 @@ static const char* shader =
147141
" uint index = gl_GlobalInvocationID.x * 32;\n"
148142
" uint visibleMask = 0;\n"
149143
" uint bit = 1u;\n"
150-
//" for ( uint count = 0;count < 32;++count )\n"
144+
" for ( uint count = 0;count < 32;++count )\n"
151145
" {\n"
152146
" uint globalIndex = index + count;\n"
153147
" visibleMask = visibleMask | (isVisible( viewProjection, matrices[objects[globalIndex].matrix], objects[globalIndex].lowerLeft, objects[globalIndex].extent ) ? bit : 0);\n"
@@ -214,7 +208,7 @@ namespace dp
214208
dp::gl::ProgramSharedPtr program = dp::gl::Program::create( dp::gl::ComputeShader::create( shader ) );
215209
m_shaderInitialized = true;
216210
m_uniformViewProjection = program->getActiveUniform( program->getActiveUniformIndex( "viewProjection" ) ).location;
217-
m_program = dp::gl::ProgramInstance::create( program );
211+
m_program = program;
218212
}
219213
}
220214

@@ -233,7 +227,7 @@ namespace dp
233227
// initialize output buffer
234228
size_t numberOfWorkingGroups = (groupImpl->getObjectCount() + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
235229

236-
m_program->apply();
230+
glUseProgram(m_program->getGLId());
237231
glUniformMatrix4fv( m_uniformViewProjection, 1, false, viewProjection[0].getPtr() );
238232

239233
glBindBufferBase( GL_SHADER_STORAGE_BUFFER, OBJECT_BINDING, groupImpl->getInputBuffer()->getGLId() );

0 commit comments

Comments
 (0)