2323import com .thomasdiewald .liquidfun .java .DwViewportTransform ;
2424
2525import processing .core .PApplet ;
26+ import processing .core .PGraphics ;
2627import processing .core .PMatrix3D ;
2728import processing .opengl .PGraphics2D ;
2829import processing .opengl .PJOGL ;
@@ -44,17 +45,18 @@ public class DwParticleRenderGL extends DwParticleRender{
4445 static public final String SHADER_DIR = "/com/thomasdiewald/liquidfun/glsl/" ;
4546
4647 // GL
47- public GL3 gl ;
48+ protected GL3 gl ;
49+ protected PJOGL pgl ;
4850
4951 // Shader
5052 public PShader shader_particles ;
5153
5254
5355 // GL: VBO HANDLES
5456 public int [] HANDLE_vbo_pos = {0 };
55- public int [] HANDLE_vbo_vel = {0 };
57+ // public int[] HANDLE_vbo_vel = {0};
5658 public int [] HANDLE_vbo_col = {0 };
57- public int [] HANDLE_vbo_con = {0 };
59+ // public int[] HANDLE_vbo_con = {0};
5860
5961 // GL: VBO Index Handle
6062 public int [] HANDLE_vbo_idx = {0 };
@@ -116,6 +118,7 @@ public void release(){
116118 gl .glDeleteBuffers (1 , HANDLE_vbo_col , 0 ); HANDLE_vbo_col [0 ] = 0 ;
117119// gl.glDeleteBuffers(1, HANDLE_vbo_vel, 0); HANDLE_vbo_vel[0] = 0;
118120// gl.glDeleteBuffers(1, HANDLE_vbo_con, 0); HANDLE_vbo_con[0] = 0;
121+ errCheck ("DwParticleRenderGL.release" );
119122 endGL ();
120123
121124 super .release ();
@@ -161,6 +164,8 @@ protected void updateVBOs(){
161164 gl .glBindBuffer (GL .GL_ELEMENT_ARRAY_BUFFER , 0 );
162165 }
163166
167+ errCheck ("DwParticleRenderGL.updateVBOs" );
168+
164169 endGL ();
165170 }
166171
@@ -193,8 +198,10 @@ public void display(PGraphics2D canvas){
193198
194199 PShader shader = shader_particles ;
195200 shader .bind ();
201+
196202 shader .set ("mat_mvp" , mat_mvp );
197203 shader .set ("tex_sprite" , param .tex_sprite );
204+ errCheck ("DwParticleRenderGL.display-uniforms" );
198205
199206 // shader vertex attribute: position
200207 int LOC_pos = gl .glGetAttribLocation (shader .glProgram , "pos" );
@@ -213,23 +220,23 @@ public void display(PGraphics2D canvas){
213220 }
214221
215222 // shader vertex attribute: velocity
216- int LOC_vel = gl .glGetAttribLocation (shader .glProgram , "vel" );
217- if (LOC_vel != -1 ){
218- gl .glBindBuffer (GL .GL_ARRAY_BUFFER , HANDLE_vbo_vel [0 ]);
219- gl .glEnableVertexAttribArray (LOC_vel );
220- gl .glVertexAttribPointer (LOC_vel , 2 , GL .GL_FLOAT , false , 0 , 0 );
221- }
223+ // int LOC_vel = gl.glGetAttribLocation(shader.glProgram, "vel");
224+ // if(LOC_vel != -1){
225+ // gl.glBindBuffer(GL.GL_ARRAY_BUFFER, HANDLE_vbo_vel[0]);
226+ // gl.glEnableVertexAttribArray(LOC_vel);
227+ // gl.glVertexAttribPointer(LOC_vel, 2, GL.GL_FLOAT, false, 0, 0);
228+ // }
222229
223230 // shader vertex attribute: contact
224- int LOC_con = gl .glGetAttribLocation (shader .glProgram , "con" );
225- if (LOC_con != -1 ){
226- gl .glBindBuffer (GL .GL_ARRAY_BUFFER , HANDLE_vbo_con [0 ]);
227- gl .glEnableVertexAttribArray (LOC_con );
228- gl .glVertexAttribPointer (LOC_con , 2 , GL .GL_FLOAT , false , 0 , 0 );
229- }
231+ // int LOC_con = gl.glGetAttribLocation(shader.glProgram, "con");
232+ // if(LOC_con != -1){
233+ // gl.glBindBuffer(GL.GL_ARRAY_BUFFER, HANDLE_vbo_con[0]);
234+ // gl.glEnableVertexAttribArray(LOC_con);
235+ // gl.glVertexAttribPointer(LOC_con, 2, GL.GL_FLOAT, false, 0, 0);
236+ // }
230237
231238 gl .glBindBuffer (GL .GL_ARRAY_BUFFER , 0 );
232-
239+ errCheck ( "DwParticleRenderGL.display-buffers" );
233240
234241
235242 // settings
@@ -239,6 +246,7 @@ public void display(PGraphics2D canvas){
239246 gl .glEnable (GL3 .GL_VERTEX_PROGRAM_POINT_SIZE );
240247 gl .glEnable (GL2ES1 .GL_POINT_SPRITE );
241248 gl .glPointSize (particle_rad_screen * 2 );
249+ errCheck ("DwParticleRenderGL.display-pointRendering" );
242250
243251
244252
@@ -258,31 +266,32 @@ public void display(PGraphics2D canvas){
258266 gl .glDrawElements (GL3 .GL_POINTS , len , GL .GL_UNSIGNED_INT , off * 4 );
259267 }
260268 gl .glBindBuffer (GL .GL_ELEMENT_ARRAY_BUFFER , 0 );
269+ errCheck ("DwParticleRenderGL.display-glDrawElements" );
261270 }
262271 else {
263272 gl .glDrawArrays (GL3 .GL_POINTS , 0 , particle_num );
273+ errCheck ("DwParticleRenderGL.display-glDrawArrays" );
264274 }
265275
266276
267-
268-
269277 // cleanup
270278 if (LOC_pos != -1 ) gl .glDisableVertexAttribArray (LOC_pos );
271279 if (LOC_col != -1 ) gl .glDisableVertexAttribArray (LOC_col );
272- if (LOC_vel != -1 ) gl .glDisableVertexAttribArray (LOC_vel );
273- if (LOC_con != -1 ) gl .glDisableVertexAttribArray (LOC_con );
280+ // if(LOC_vel != -1) gl.glDisableVertexAttribArray(LOC_vel);
281+ // if(LOC_con != -1) gl.glDisableVertexAttribArray(LOC_con);
274282
275283 shader .unbind ();
276-
284+ errCheck ("DwParticleRenderGL.shader.unbind()" );
285+
277286 endGL ();
278287 }
279288
280-
289+
281290
282291
283292 protected void beginGL (){
284293 if (gl == null ){
285- PJOGL pgl = (PJOGL ) papplet .beginPGL ();
294+ pgl = (PJOGL ) papplet .beginPGL ();
286295 gl = pgl .gl .getGL3 ();
287296 }
288297 }
@@ -294,5 +303,14 @@ protected void endGL(){
294303 }
295304 }
296305
306+ protected void errCheck (String user_msg ){
307+ int err = pgl .getError ();
308+ if (err != 0 ) {
309+ String errString = pgl .errorString (err );
310+ String msg = "OpenGL error " + err + " at " + user_msg + ": " + errString ;
311+ PGraphics .showWarning (msg );
312+ }
313+ }
314+
297315
298316}
0 commit comments