Skip to content

Commit 4c87cdc

Browse files
committed
starting the refactoring of PGL
1 parent 95a466a commit 4c87cdc

File tree

6 files changed

+761
-563
lines changed

6 files changed

+761
-563
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,6 +2969,7 @@ public void keyTyped(com.jogamp.newt.event.KeyEvent e) {
29692969
public static final int VERTEX_ATTRIB_ARRAY_STRIDE = GL2.GL_VERTEX_ATTRIB_ARRAY_STRIDE;
29702970
public static final int VERTEX_ATTRIB_ARRAY_TYPE = GL2.GL_VERTEX_ATTRIB_ARRAY_TYPE;
29712971
public static final int VERTEX_ATTRIB_ARRAY_NORMALIZED = GL2.GL_VERTEX_ATTRIB_ARRAY_NORMALIZED;
2972+
public static final int VERTEX_ATTRIB_ARRAY_POINTER = GL2.GL_VERTEX_ATTRIB_ARRAY_POINTER;
29722973

29732974
public static final int BLEND = GL.GL_BLEND;
29742975
public static final int ONE = GL.GL_ONE;
@@ -3226,15 +3227,11 @@ public void viewport(int x, int y, int w, int h) {
32263227
// Reading Pixels
32273228

32283229
public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer) {
3229-
boolean needBeginOp = format != STENCIL_INDEX &&
3230-
format != DEPTH_COMPONENT && format != DEPTH_STENCIL;
3231-
if (needBeginOp) {
3232-
PGraphicsOpenGL.pgCurrent.beginPixelsOp(PGraphicsOpenGL.OP_READ);
3233-
}
3230+
boolean needEndBegin = format != STENCIL_INDEX &&
3231+
format != DEPTH_COMPONENT && format != DEPTH_STENCIL;
3232+
if (needEndBegin) pg.beginReadPixels();
32343233
readPixelsImpl(x, y, width, height, format, type, buffer);
3235-
if (needBeginOp) {
3236-
PGraphicsOpenGL.pgCurrent.endPixelsOp();
3237-
}
3234+
if (needEndBegin) pg.endReadPixels();
32383235
}
32393236

32403237
protected void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer) {
@@ -3477,13 +3474,14 @@ public void deleteProgram(int program) {
34773474
gl2.glDeleteProgram(program);
34783475
}
34793476

3480-
public void getActiveAttrib(int program, int index, int[] size, int[] type, String[] name) {
3477+
public String glGetActiveAttrib (int program, int index, IntBuffer size, IntBuffer type) {
34813478
int[] tmp = {0, 0, 0};
34823479
byte[] namebuf = new byte[1024];
34833480
gl2.glGetActiveAttrib(program, index, 1024, tmp, 0, tmp, 1, tmp, 2, namebuf, 0);
3484-
if (size != null && size.length != 0) size[0] = tmp[1];
3485-
if (type != null && type.length != 0) type[0] = tmp[2];
3486-
if (name != null && name.length != 0) name[0] = new String(namebuf, 0, tmp[0]);
3481+
size.put(tmp[1]);
3482+
type.put(tmp[2]);
3483+
String name = new String(namebuf, 0, tmp[0]);
3484+
return name;
34873485
}
34883486

34893487
public int getAttribLocation(int program, String name) {
@@ -3498,13 +3496,14 @@ public int getUniformLocation(int program, String name) {
34983496
return gl2.glGetUniformLocation(program, name);
34993497
}
35003498

3501-
public void getActiveUniform(int program, int index, int[] size,int[] type, String[] name) {
3499+
public String getActiveUniform(int program, int index, IntBuffer size, IntBuffer type) {
35023500
int[] tmp= {0, 0, 0};
35033501
byte[] namebuf = new byte[1024];
35043502
gl2.glGetActiveUniform(program, index, 1024, tmp, 0, tmp, 1, tmp, 2, namebuf, 0);
3505-
if (size != null && size.length != 0) size[0] = tmp[1];
3506-
if (type != null && type.length != 0) type[0] = tmp[2];
3507-
if (name != null && name.length != 0) name[0] = new String(namebuf, 0, tmp[0]);
3503+
size.put(tmp[1]);
3504+
type.put(tmp[2]);
3505+
String name = new String(namebuf, 0, tmp[0]);
3506+
return name;
35083507
}
35093508

35103509
public void uniform1i(int location, int value) {
@@ -3628,7 +3627,7 @@ public void getVertexAttribiv(int index, int pname, IntBuffer params) {
36283627
gl2.glGetVertexAttribiv(index, pname, params);
36293628
}
36303629

3631-
public void getVertexAttribPointerv() {
3630+
public void getVertexAttribPointerv(int index, int pname, ByteBuffer data) {
36323631
throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glGetVertexAttribPointerv()"));
36333632
}
36343633

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public class PGraphicsOpenGL extends PGraphics {
532532

533533
public PGraphicsOpenGL() {
534534
if (pgl == null) {
535-
pgl = new PGL(this);
535+
pgl = createPGL(this);
536536
}
537537

538538
if (tessellator == null) {
@@ -1699,6 +1699,12 @@ public void endDraw() {
16991699
}
17001700

17011701

1702+
// Factory method
1703+
static public PGL createPGL(PGraphicsOpenGL pg) {
1704+
return new PGL(pg);
1705+
}
1706+
1707+
17021708
@Override
17031709
public PGL beginPGL() {
17041710
flush();
@@ -1768,6 +1774,13 @@ protected void restoreGL() {
17681774
pgl.drawBuffer(currentFramebuffer.getDefaultDrawBuffer());
17691775
}
17701776

1777+
public void beginReadPixels() {
1778+
pgCurrent.beginPixelsOp(OP_READ);
1779+
}
1780+
1781+
public void endReadPixels() {
1782+
pgCurrent.endPixelsOp();
1783+
}
17711784

17721785
protected void beginPixelsOp(int op) {
17731786
FrameBuffer pixfb = null;

java/libraries/lwjgl/src/processing/lwjgl/PGraphics2D.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

java/libraries/lwjgl/src/processing/lwjgl/PGraphics3D.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

java/libraries/lwjgl/src/processing/lwjgl/PGraphicsLWJGL.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,16 @@
2222

2323
package processing.lwjgl;
2424

25+
import processing.opengl.PGL;
2526
import processing.opengl.PGraphicsOpenGL;
2627

2728
/**
2829
* LWJGL renderer.
2930
*
3031
*/
3132
public class PGraphicsLWJGL extends PGraphicsOpenGL {
32-
33-
//////////////////////////////////////////////////////////////
34-
35-
// INIT/ALLOCATE/FINISH
36-
37-
38-
public PGraphicsLWJGL() {
39-
pgl = new PGL(this);
40-
41-
if (tessellator == null) {
42-
tessellator = new Tessellator();
43-
}
44-
45-
intBuffer = PGL.allocateIntBuffer(2);
46-
floatBuffer = PGL.allocateFloatBuffer(2);
47-
viewport = PGL.allocateIntBuffer(4);
48-
49-
inGeo = newInGeometry(IMMEDIATE);
50-
tessGeo = newTessGeometry(IMMEDIATE);
51-
texCache = newTexCache();
52-
53-
initialized = false;
33+
34+
static public PGL createPGL(PGraphicsOpenGL pg) {
35+
return new PLWJGL(pg);
5436
}
5537
}

0 commit comments

Comments
 (0)