48
48
49
49
DP_STATIC_ASSERT ( (WORKGROUP_SIZE % 32 ) == 0 );
50
50
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
54
55
55
56
// #define NO_GLSL_BARRIER
56
57
@@ -117,28 +118,21 @@ static const char* shader =
117
118
" uint cfa = 0xffffffff;\n "
118
119
" \n "
119
120
" 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 "
122
122
" \n "
123
123
" vec4 x = extent.x * modelViewProjection[0];\n "
124
124
" vec4 y = extent.y * modelViewProjection[1];\n "
125
125
" vec4 z = extent.z * modelViewProjection[2];\n "
126
126
" \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 "
134
134
" \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 "
142
136
" }\n "
143
137
" \n "
144
138
" uniform mat4 viewProjection;\n "
@@ -147,7 +141,7 @@ static const char* shader =
147
141
" uint index = gl_GlobalInvocationID.x * 32;\n "
148
142
" uint visibleMask = 0;\n "
149
143
" uint bit = 1u;\n "
150
- // " for ( uint count = 0;count < 32;++count )\n"
144
+ " for ( uint count = 0;count < 32;++count )\n "
151
145
" {\n "
152
146
" uint globalIndex = index + count;\n "
153
147
" visibleMask = visibleMask | (isVisible( viewProjection, matrices[objects[globalIndex].matrix], objects[globalIndex].lowerLeft, objects[globalIndex].extent ) ? bit : 0);\n "
@@ -214,7 +208,7 @@ namespace dp
214
208
dp::gl::ProgramSharedPtr program = dp::gl::Program::create ( dp::gl::ComputeShader::create ( shader ) );
215
209
m_shaderInitialized = true ;
216
210
m_uniformViewProjection = program->getActiveUniform ( program->getActiveUniformIndex ( " viewProjection" ) ).location ;
217
- m_program = dp::gl::ProgramInstance::create ( program ) ;
211
+ m_program = program;
218
212
}
219
213
}
220
214
@@ -233,7 +227,7 @@ namespace dp
233
227
// initialize output buffer
234
228
size_t numberOfWorkingGroups = (groupImpl->getObjectCount () + WORKGROUP_SIZE - 1 ) / WORKGROUP_SIZE;
235
229
236
- m_program->apply ( );
230
+ glUseProgram ( m_program->getGLId () );
237
231
glUniformMatrix4fv ( m_uniformViewProjection, 1 , false , viewProjection[0 ].getPtr () );
238
232
239
233
glBindBufferBase ( GL_SHADER_STORAGE_BUFFER, OBJECT_BINDING, groupImpl->getInputBuffer ()->getGLId () );
0 commit comments