Skip to content

Commit 972bc6d

Browse files
committed
Removed DummyContext and re-ordered init calls in LWJGL renderer
1 parent e904d7a commit 972bc6d

File tree

1 file changed

+18
-24
lines changed
  • java/libraries/lwjgl/src/processing/lwjgl

1 file changed

+18
-24
lines changed

java/libraries/lwjgl/src/processing/lwjgl/PGL.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.lwjgl.input.Keyboard;
4141
import org.lwjgl.input.Mouse;
4242
import org.lwjgl.opengl.Display;
43+
import org.lwjgl.opengl.DisplayMode;
4344
import org.lwjgl.opengl.EXTFramebufferObject;
4445
import org.lwjgl.opengl.EXTTextureFilterAnisotropic;
4546
import org.lwjgl.opengl.GL11;
@@ -349,7 +350,7 @@ public class PGL extends processing.opengl.PGL {
349350
protected static Thread glThread;
350351

351352
/** Just holds a unique ID */
352-
protected static DummyContext context;
353+
protected static int context;
353354

354355
/** The PGraphics object using this interface */
355356
protected PGraphicsOpenGL pg;
@@ -394,15 +395,15 @@ public class PGL extends processing.opengl.PGL {
394395
protected static int tex2DShaderProgram;
395396
protected static int tex2DVertShader;
396397
protected static int tex2DFragShader;
397-
protected static DummyContext tex2DShaderContext;
398+
protected static int tex2DShaderContext;
398399
protected static int tex2DVertLoc;
399400
protected static int tex2DTCoordLoc;
400401

401402
protected static boolean loadedTexRectShader = false;
402403
protected static int texRectShaderProgram;
403404
protected static int texRectVertShader;
404405
protected static int texRectFragShader;
405-
protected static DummyContext texRectShaderContext;
406+
protected static int texRectShaderContext;
406407
protected static int texRectVertLoc;
407408
protected static int texRectTCoordLoc;
408409

@@ -500,27 +501,29 @@ protected void initSurface(int antialias) {
500501
}
501502

502503
canvas = new Canvas();
503-
canvas.setBounds(0, 0, pg.parent.width, pg.parent.height);
504504
canvas.setFocusable(true);
505505
canvas.requestFocus();
506506
canvas.setIgnoreRepaint(true);
507507
canvas.setBackground(Color.BLACK);
508-
508+
canvas.setForeground(Color.BLACK);
509+
509510
pg.parent.setLayout(new BorderLayout());
510-
pg.parent.add(canvas, BorderLayout.CENTER);
511-
512-
try {
513-
Display.setParent(canvas);
511+
pg.parent.add(canvas, BorderLayout.CENTER);
512+
canvas.setBounds(0, 0, pg.parent.width, pg.parent.height);
513+
514+
try {
514515
PixelFormat format = new PixelFormat(32, request_alpha_bits,
515516
request_depth_bits,
516517
request_stencil_bits, 0);
518+
Display.setDisplayMode(new DisplayMode(pg.parent.width, pg.parent.height));
519+
Display.setParent(canvas);
517520
Display.create(format);
518521
Display.setVSyncEnabled(true);
519522
} catch (LWJGLException e) {
520523
e.printStackTrace();
521524
}
522-
523-
context = new DummyContext(Display.getDrawable().hashCode());
525+
526+
context = Display.getDrawable().hashCode();
524527

525528
keyPoller = new KeyPoller(pg.parent);
526529
keyPoller.start();
@@ -1614,7 +1617,7 @@ protected int createEmptyContext() {
16141617

16151618

16161619
protected int getCurrentContext() {
1617-
return context.hashCode();
1620+
return context;
16181621
}
16191622

16201623

@@ -1719,7 +1722,7 @@ public void combine(double[] coords, Object[] data,
17191722

17201723

17211724
protected boolean contextIsCurrent(int other) {
1722-
return other == -1 || other == context.hashCode();
1725+
return other == -1 || other == context;
17231726
}
17241727

17251728

@@ -1818,8 +1821,7 @@ protected void drawTexture(int target, int id, int width, int height,
18181821
protected void drawTexture2D(int id, int width, int height,
18191822
int texX0, int texY0, int texX1, int texY1,
18201823
int scrX0, int scrY0, int scrX1, int scrY1) {
1821-
if (!loadedTex2DShader ||
1822-
tex2DShaderContext.hashCode() != context.hashCode()) {
1824+
if (!loadedTex2DShader || tex2DShaderContext != context) {
18231825
tex2DVertShader = createShader(VERTEX_SHADER, texVertShaderSource);
18241826
tex2DFragShader = createShader(FRAGMENT_SHADER, tex2DFragShaderSource);
18251827
if (0 < tex2DVertShader && 0 < tex2DFragShader) {
@@ -1922,8 +1924,7 @@ protected void drawTexture2D(int id, int width, int height,
19221924
protected void drawTextureRect(int id, int width, int height,
19231925
int texX0, int texY0, int texX1, int texY1,
19241926
int scrX0, int scrY0, int scrX1, int scrY1) {
1925-
if (!loadedTexRectShader ||
1926-
texRectShaderContext.hashCode() != context.hashCode()) {
1927+
if (!loadedTexRectShader || texRectShaderContext != context) {
19271928
texRectVertShader = createShader(VERTEX_SHADER, texVertShaderSource);
19281929
texRectFragShader = createShader(FRAGMENT_SHADER, texRectFragShaderSource);
19291930
if (0 < texRectVertShader && 0 < texRectFragShader) {
@@ -2989,13 +2990,6 @@ public void requestStop() {
29892990
}
29902991
}
29912992

2992-
protected class DummyContext {
2993-
int id;
2994-
DummyContext(int id) {
2995-
this.id = id;
2996-
}
2997-
}
2998-
29992993
// To complete later...
30002994
// http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html
30012995
// http://processing.org/reference/keyCode.html

0 commit comments

Comments
 (0)