Skip to content

Commit ae0bbbd

Browse files
committed
sync with java mode
1 parent 8ca0b00 commit ae0bbbd

3 files changed

Lines changed: 984 additions & 946 deletions

File tree

core/src/processing/opengl/PGL.java

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,15 @@ public class PGL {
352352
/** Selected GL profile */
353353
public static GLProfile profile;
354354

355+
/** The PGraphics object using this interface */
356+
protected PGraphicsOpenGL pg;
357+
358+
/** Whether OpenGL has been initialized or not */
359+
protected boolean initialized;
360+
361+
/** Flag to signal rendering of first frame */
362+
protected boolean firstFrame;
363+
355364
/** The capabilities of the OpenGL rendering surface */
356365
protected static GLCapabilitiesImmutable capabilities;
357366

@@ -365,13 +374,6 @@ public class PGL {
365374
* multisampled renerbuffers) */
366375
protected static GL2 gl2x;
367376

368-
/** The PGraphics object using this interface */
369-
protected PGraphicsOpenGL pg;
370-
371-
/** Whether OpenGL has been initialized or not */
372-
protected boolean initialized;
373-
protected boolean firstFrame;
374-
375377
/** Windowing toolkit */
376378
protected static int toolkit = NEWT;
377379

@@ -456,8 +458,6 @@ public class PGL {
456458
+1.0f, +1.0f, 1.0f, 1.0f
457459
};
458460
protected static FloatBuffer texData;
459-
protected static ByteBuffer byteBuffer;
460-
protected static IntBuffer intBuffer;
461461

462462
protected static String texVertShaderSource =
463463
"attribute vec2 inVertex;" +
@@ -486,7 +486,10 @@ public class PGL {
486486

487487
///////////////////////////////////////////////////////////
488488

489-
// 1-pixel color, depth, stencil buffers
489+
// Utilities
490+
491+
protected ByteBuffer byteBuffer;
492+
protected IntBuffer intBuffer;
490493

491494
protected IntBuffer colorBuffer;
492495
protected FloatBuffer depthBuffer;
@@ -503,6 +506,12 @@ public PGL(PGraphicsOpenGL pg) {
503506
if (glu == null) {
504507
glu = new GLU();
505508
}
509+
if (byteBuffer == null) {
510+
byteBuffer = allocateDirectByteBuffer(1);
511+
}
512+
if (intBuffer == null) {
513+
intBuffer = allocateDirectIntBuffer(1);
514+
}
506515
initialized = false;
507516
}
508517

@@ -846,7 +855,11 @@ public String getString(int name) {
846855

847856

848857
public void getIntegerv(int name, IntBuffer values) {
849-
gl.glGetIntegerv(name, values);
858+
if (-1 < name) {
859+
gl.glGetIntegerv(name, values);
860+
} else {
861+
fillBuffer(values, 0, values.capacity() - 1, 0);
862+
}
850863
}
851864

852865

@@ -856,7 +869,11 @@ public void getIntegerv(int name, IntBuffer values) {
856869

857870

858871
public void getFloatv(int name, FloatBuffer values) {
859-
gl.glGetFloatv(name, values);
872+
if (-1 < name) {
873+
gl.glGetFloatv(name, values);
874+
} else {
875+
fillBuffer(values, 0, values.capacity() - 1, 0);
876+
}
860877
}
861878

862879

@@ -873,12 +890,21 @@ public void getFloatv(int name, FloatBuffer values) {
873890
// }
874891

875892

876-
public void getBooleanv(int name, ByteBuffer values) {
877-
gl.glGetBooleanv(name, values);
893+
public void getBooleanv(int name, IntBuffer values) {
894+
if (-1 < name) {
895+
if (byteBuffer.capacity() < values.capacity()) {
896+
byteBuffer = allocateDirectByteBuffer(values.capacity());
897+
}
898+
gl.glGetBooleanv(name, byteBuffer);
899+
for (int i = 0; i < values.capacity(); i++) {
900+
values.put(i, byteBuffer.get(i));
901+
}
902+
} else {
903+
fillBuffer(values, 0, values.capacity() - 1, 0);
904+
}
878905
}
879906

880907

881-
882908
///////////////////////////////////////////////////////////
883909

884910
// Enable/disable caps
@@ -1902,22 +1928,18 @@ protected void drawTexture2D(int id, int width, int height,
19021928
texData = allocateDirectFloatBuffer(texCoords.length);
19031929
}
19041930

1905-
if (byteBuffer == null) {
1906-
byteBuffer = allocateDirectByteBuffer(1);
1907-
}
1908-
19091931
if (0 < tex2DShaderProgram) {
19101932
// The texture overwrites anything drawn earlier.
1911-
getBooleanv(DEPTH_TEST, byteBuffer);
1912-
boolean depthTest = byteBuffer.get(0) == 0 ? false : true;
1933+
getBooleanv(DEPTH_TEST, intBuffer);
1934+
boolean depthTest = intBuffer.get(0) == 0 ? false : true;
19131935
disable(DEPTH_TEST);
19141936

19151937
// When drawing the texture we don't write to the
19161938
// depth mask, so the texture remains in the background
19171939
// and can be occluded by anything drawn later, even if
19181940
// if it is behind it.
1919-
getBooleanv(DEPTH_WRITEMASK, byteBuffer);
1920-
boolean depthMask = byteBuffer.get(0) == 0 ? false : true;
1941+
getBooleanv(DEPTH_WRITEMASK, intBuffer);
1942+
boolean depthMask = intBuffer.get(0) == 0 ? false : true;
19211943
depthMask(false);
19221944

19231945
useProgram(tex2DShaderProgram);
@@ -2013,22 +2035,18 @@ protected void drawTextureRect(int id, int width, int height,
20132035
texData = allocateDirectFloatBuffer(texCoords.length);
20142036
}
20152037

2016-
if (byteBuffer == null) {
2017-
byteBuffer = allocateDirectByteBuffer(1);
2018-
}
2019-
20202038
if (0 < texRectShaderProgram) {
20212039
// The texture overwrites anything drawn earlier.
2022-
getBooleanv(DEPTH_TEST, byteBuffer);
2023-
boolean depthTest = byteBuffer.get(0) == 0 ? false : true;
2040+
getBooleanv(DEPTH_TEST, intBuffer);
2041+
boolean depthTest = intBuffer.get(0) == 0 ? false : true;
20242042
disable(DEPTH_TEST);
20252043

20262044
// When drawing the texture we don't write to the
20272045
// depth mask, so the texture remains in the background
20282046
// and can be occluded by anything drawn later, even if
20292047
// if it is behind it.
2030-
getBooleanv(DEPTH_WRITEMASK, byteBuffer);
2031-
boolean depthMask = byteBuffer.get(0) == 0 ? false : true;
2048+
getBooleanv(DEPTH_WRITEMASK, intBuffer);
2049+
boolean depthMask = intBuffer.get(0) == 0 ? false : true;
20322050
depthMask(false);
20332051

20342052
useProgram(texRectShaderProgram);
@@ -2443,9 +2461,6 @@ protected static void javaToNativeRGB(int[] pixels, int width, int height) {
24432461
protected int createShader(int shaderType, String source) {
24442462
int shader = createShader(shaderType);
24452463
if (shader != 0) {
2446-
if (intBuffer == null) {
2447-
intBuffer = allocateDirectIntBuffer(1);
2448-
}
24492464
shaderSource(shader, source);
24502465
compileShader(shader);
24512466
getShaderiv(shader, COMPILE_STATUS, intBuffer);
@@ -2464,9 +2479,6 @@ protected int createShader(int shaderType, String source) {
24642479
protected int createProgram(int vertexShader, int fragmentShader) {
24652480
int program = createProgram();
24662481
if (program != 0) {
2467-
if (intBuffer == null) {
2468-
intBuffer = allocateDirectIntBuffer(1);
2469-
}
24702482
attachShader(program, vertexShader);
24712483
attachShader(program, fragmentShader);
24722484
linkProgram(program);
@@ -2563,38 +2575,42 @@ protected static FloatBuffer allocateDirectFloatBuffer(int size) {
25632575

25642576

25652577
protected static void fillBuffer(ByteBuffer buf, int i0, int i1, byte val) {
2566-
int n = i1 - i0 + 1;
2578+
int n = i1 - i0;
25672579
byte[] temp = new byte[n];
25682580
Arrays.fill(temp, 0, n, val);
25692581
buf.position(i0);
25702582
buf.put(temp, 0, n);
2583+
buf.rewind();
25712584
}
25722585

25732586

25742587
protected static void fillBuffer(ShortBuffer buf, int i0, int i1, short val) {
2575-
int n = i1 - i0 + 1;
2588+
int n = i1 - i0;
25762589
short[] temp = new short[n];
25772590
Arrays.fill(temp, 0, n, val);
25782591
buf.position(i0);
25792592
buf.put(temp, 0, n);
2593+
buf.rewind();
25802594
}
25812595

25822596

25832597
protected static void fillBuffer(IntBuffer buf, int i0, int i1, int val) {
2584-
int n = i1 - i0 + 1;
2598+
int n = i1 - i0;
25852599
int[] temp = new int[n];
25862600
Arrays.fill(temp, 0, n, val);
25872601
buf.position(i0);
25882602
buf.put(temp, 0, n);
2603+
buf.rewind();
25892604
}
25902605

25912606

25922607
protected static void fillBuffer(FloatBuffer buf, int i0, int i1, float val) {
2593-
int n = i1 - i0 + 1;
2608+
int n = i1 - i0;
25942609
float[] temp = new float[n];
25952610
Arrays.fill(temp, 0, n, val);
25962611
buf.position(i0);
25972612
buf.put(temp, 0, n);
2613+
buf.rewind();
25982614
}
25992615

26002616

0 commit comments

Comments
 (0)