propane 3.4.2-java → 3.5.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +5 -1
- data/Gemfile +2 -0
- data/README.md +15 -3
- data/Rakefile +9 -10
- data/bin/propane +3 -1
- data/lib/propane.rb +2 -1
- data/lib/propane/app.rb +2 -1
- data/lib/propane/creators/sketch_class.rb +7 -1
- data/lib/propane/creators/sketch_factory.rb +4 -2
- data/lib/propane/creators/sketch_writer.rb +1 -0
- data/lib/propane/helper_methods.rb +22 -22
- data/lib/propane/helpers/numeric.rb +2 -0
- data/lib/propane/helpers/version_error.rb +1 -0
- data/lib/propane/library.rb +5 -1
- data/lib/propane/library_loader.rb +2 -0
- data/lib/propane/native_folder.rb +10 -9
- data/lib/propane/native_loader.rb +3 -0
- data/lib/propane/runner.rb +11 -5
- data/lib/propane/version.rb +2 -1
- data/library/boids/boids.rb +21 -11
- data/library/color_group/color_group.rb +2 -0
- data/library/control_panel/control_panel.rb +8 -5
- data/library/dxf/dxf.rb +2 -0
- data/library/file_chooser/chooser.rb +10 -9
- data/library/file_chooser/file_chooser.rb +10 -9
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +2 -0
- data/library/simplex_noise/simplex_noise.rb +2 -0
- data/library/slider/slider.rb +23 -22
- data/library/vector_utils/vector_utils.rb +4 -0
- data/library/video_event/video_event.rb +2 -0
- data/pom.rb +46 -45
- data/pom.xml +4 -4
- data/propane.gemspec +8 -7
- data/src/main/java/monkstone/ColorUtil.java +1 -3
- data/src/main/java/monkstone/MathToolModule.java +1 -1
- data/src/main/java/monkstone/PropaneLibrary.java +2 -2
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +788 -283
- data/src/main/java/processing/awt/PImageAWT.java +260 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +56 -53
- data/src/main/java/processing/awt/PSurfaceAWT.java +309 -211
- data/src/main/java/processing/awt/ShimAWT.java +580 -0
- data/src/main/java/processing/core/PApplet.java +2877 -2098
- data/src/main/java/processing/core/PConstants.java +477 -447
- data/src/main/java/processing/core/PFont.java +930 -884
- data/src/main/java/processing/core/PGraphics.java +337 -309
- data/src/main/java/processing/core/PImage.java +1689 -1689
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +456 -410
- data/src/main/java/processing/core/PMatrix3D.java +755 -735
- data/src/main/java/processing/core/PShape.java +2910 -2656
- data/src/main/java/processing/core/PShapeOBJ.java +97 -94
- data/src/main/java/processing/core/PShapeSVG.java +1656 -1462
- data/src/main/java/processing/core/PStyle.java +40 -37
- data/src/main/java/processing/core/PSurface.java +134 -97
- data/src/main/java/processing/core/PSurfaceNone.java +292 -218
- data/src/main/java/processing/core/PVector.java +991 -966
- data/src/main/java/processing/core/ThinkDifferent.java +12 -8
- data/src/main/java/processing/data/DoubleDict.java +756 -710
- data/src/main/java/processing/data/DoubleList.java +749 -696
- data/src/main/java/processing/data/FloatDict.java +748 -702
- data/src/main/java/processing/data/FloatList.java +751 -697
- data/src/main/java/processing/data/IntDict.java +720 -673
- data/src/main/java/processing/data/IntList.java +699 -633
- data/src/main/java/processing/data/JSONArray.java +931 -873
- data/src/main/java/processing/data/JSONObject.java +1262 -1165
- data/src/main/java/processing/data/JSONTokener.java +351 -341
- data/src/main/java/processing/data/LongDict.java +710 -663
- data/src/main/java/processing/data/LongList.java +701 -635
- data/src/main/java/processing/data/Sort.java +37 -41
- data/src/main/java/processing/data/StringDict.java +525 -486
- data/src/main/java/processing/data/StringList.java +626 -580
- data/src/main/java/processing/data/Table.java +3693 -3513
- data/src/main/java/processing/data/TableRow.java +182 -183
- data/src/main/java/processing/data/XML.java +954 -880
- data/src/main/java/processing/event/Event.java +87 -67
- data/src/main/java/processing/event/KeyEvent.java +48 -41
- data/src/main/java/processing/event/MouseEvent.java +87 -113
- data/src/main/java/processing/event/TouchEvent.java +10 -6
- data/src/main/java/processing/javafx/PSurfaceFX.java +26 -0
- data/src/main/java/processing/net/Client.java +20 -20
- data/src/main/java/processing/net/Server.java +9 -9
- data/src/main/java/processing/opengl/FontTexture.java +286 -266
- data/src/main/java/processing/opengl/FrameBuffer.java +390 -376
- data/src/main/java/processing/opengl/LinePath.java +130 -91
- data/src/main/java/processing/opengl/LineStroker.java +593 -582
- data/src/main/java/processing/opengl/PGL.java +645 -579
- data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
- data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12287 -12030
- data/src/main/java/processing/opengl/PJOGL.java +1743 -1672
- data/src/main/java/processing/opengl/PShader.java +345 -416
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4601 -4543
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1113 -1029
- data/src/main/java/processing/opengl/Texture.java +1489 -1401
- data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
- data/test/create_test.rb +21 -20
- data/test/deglut_spec_test.rb +4 -2
- data/test/helper_methods_test.rb +49 -20
- data/test/math_tool_test.rb +39 -32
- data/test/native_folder.rb +47 -0
- data/test/respond_to_test.rb +3 -2
- data/test/sketches/key_event.rb +2 -2
- data/test/sketches/library/my_library/my_library.rb +3 -0
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +35 -22
- data/vendors/Rakefile +28 -22
- metadata +13 -13
- data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
4
|
Part of the Processing project - http://processing.org
|
|
3
5
|
|
|
@@ -18,7 +20,8 @@
|
|
|
18
20
|
Public License along with this library; if not, write to the
|
|
19
21
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
20
22
|
Boston, MA 02111-1307 USA
|
|
21
|
-
|
|
23
|
+
*/
|
|
24
|
+
|
|
22
25
|
package processing.opengl;
|
|
23
26
|
|
|
24
27
|
import java.io.IOException;
|
|
@@ -30,12 +33,14 @@ import java.nio.FloatBuffer;
|
|
|
30
33
|
import java.nio.IntBuffer;
|
|
31
34
|
import java.nio.ShortBuffer;
|
|
32
35
|
import java.util.Arrays;
|
|
36
|
+
import java.util.Optional;
|
|
33
37
|
import java.util.regex.Pattern;
|
|
34
38
|
|
|
35
39
|
import processing.core.PApplet;
|
|
36
40
|
import processing.core.PConstants;
|
|
37
41
|
import processing.core.PGraphics;
|
|
38
42
|
|
|
43
|
+
|
|
39
44
|
/**
|
|
40
45
|
* Processing-OpenGL abstraction layer. Needs to be implemented by subclasses
|
|
41
46
|
* using specific OpenGL-Java bindings.
|
|
@@ -47,112 +52,93 @@ public abstract class PGL {
|
|
|
47
52
|
// ........................................................
|
|
48
53
|
|
|
49
54
|
// Basic fields
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*/
|
|
55
|
+
|
|
56
|
+
/** The PGraphics and PApplet objects using this interface */
|
|
53
57
|
protected PGraphicsOpenGL graphics;
|
|
54
58
|
protected PApplet sketch;
|
|
55
59
|
|
|
56
|
-
/**
|
|
57
|
-
* OpenGL thread
|
|
58
|
-
*/
|
|
60
|
+
/** OpenGL thread */
|
|
59
61
|
protected Thread glThread;
|
|
60
62
|
|
|
61
|
-
/**
|
|
62
|
-
* ID of the GL context associated to the surface *
|
|
63
|
-
*/
|
|
63
|
+
/** ID of the GL context associated to the surface **/
|
|
64
64
|
protected int glContext;
|
|
65
65
|
|
|
66
|
-
/**
|
|
67
|
-
* true if this is the GL interface for a primary surface PGraphics
|
|
68
|
-
*/
|
|
66
|
+
/** true if this is the GL interface for a primary surface PGraphics */
|
|
69
67
|
public boolean primaryPGL;
|
|
70
68
|
|
|
71
69
|
// ........................................................
|
|
70
|
+
|
|
72
71
|
// Parameters
|
|
73
|
-
|
|
72
|
+
|
|
73
|
+
public static int REQUESTED_DEPTH_BITS = 24;
|
|
74
74
|
public static int REQUESTED_STENCIL_BITS = 8;
|
|
75
|
-
public static int REQUESTED_ALPHA_BITS
|
|
75
|
+
public static int REQUESTED_ALPHA_BITS = 8;
|
|
76
76
|
|
|
77
|
-
/**
|
|
78
|
-
* Switches between the use of regular and direct buffers.
|
|
79
|
-
*/
|
|
77
|
+
/** Switches between the use of regular and direct buffers. */
|
|
80
78
|
protected static boolean USE_DIRECT_BUFFERS = true;
|
|
81
79
|
protected static int MIN_DIRECT_BUFFER_SIZE = 1;
|
|
82
80
|
|
|
83
|
-
/**
|
|
84
|
-
* Enables/disables mipmap use.
|
|
85
|
-
*/
|
|
81
|
+
/** Enables/disables mipmap use. */
|
|
86
82
|
protected static boolean MIPMAPS_ENABLED = true;
|
|
87
83
|
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
protected static int
|
|
92
|
-
protected static int DEFAULT_IN_EDGES = 128;
|
|
93
|
-
protected static int DEFAULT_IN_TEXTURES = 64;
|
|
84
|
+
/** Initial sizes for arrays of input and tessellated data. */
|
|
85
|
+
protected static int DEFAULT_IN_VERTICES = 64;
|
|
86
|
+
protected static int DEFAULT_IN_EDGES = 128;
|
|
87
|
+
protected static int DEFAULT_IN_TEXTURES = 64;
|
|
94
88
|
protected static int DEFAULT_TESS_VERTICES = 64;
|
|
95
|
-
protected static int DEFAULT_TESS_INDICES
|
|
89
|
+
protected static int DEFAULT_TESS_INDICES = 128;
|
|
96
90
|
|
|
97
|
-
/**
|
|
98
|
-
* Maximum lights by default is 8, the minimum defined by OpenGL.
|
|
99
|
-
*/
|
|
91
|
+
/** Maximum lights by default is 8, the minimum defined by OpenGL. */
|
|
100
92
|
protected static int MAX_LIGHTS = 8;
|
|
101
93
|
|
|
102
|
-
/**
|
|
103
|
-
* Maximum index value of a tessellated vertex. GLES restricts the vertex
|
|
94
|
+
/** Maximum index value of a tessellated vertex. GLES restricts the vertex
|
|
104
95
|
* indices to be of type unsigned short. Since Java only supports signed
|
|
105
96
|
* shorts as primitive type we have 2^15 = 32768 as the maximum number of
|
|
106
97
|
* vertices that can be referred to within a single VBO.
|
|
107
98
|
*/
|
|
108
|
-
protected
|
|
99
|
+
protected static int MAX_VERTEX_INDEX = 32767;
|
|
109
100
|
protected static int MAX_VERTEX_INDEX1 = MAX_VERTEX_INDEX + 1;
|
|
110
101
|
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* MAX_VERTEX_INDEX limit.
|
|
102
|
+
/** Count of tessellated fill, line or point vertices that will
|
|
103
|
+
* trigger a flush in the immediate mode. It doesn't necessarily
|
|
104
|
+
* be equal to MAX_VERTEX_INDEX1, since the number of vertices can
|
|
105
|
+
* be effectively much large since the renderer uses offsets to
|
|
106
|
+
* refer to vertices beyond the MAX_VERTEX_INDEX limit.
|
|
117
107
|
*/
|
|
118
108
|
protected static int FLUSH_VERTEX_COUNT = MAX_VERTEX_INDEX1;
|
|
119
109
|
|
|
120
|
-
/**
|
|
121
|
-
* Minimum/maximum dimensions of a texture used to hold font data.
|
|
122
|
-
*/
|
|
110
|
+
/** Minimum/maximum dimensions of a texture used to hold font data. */
|
|
123
111
|
protected static int MIN_FONT_TEX_SIZE = 256;
|
|
124
112
|
protected static int MAX_FONT_TEX_SIZE = 1024;
|
|
125
113
|
|
|
126
|
-
/**
|
|
127
|
-
*
|
|
128
|
-
* properly generates caps and joins.
|
|
114
|
+
/** Minimum stroke weight needed to apply the full path stroking
|
|
115
|
+
* algorithm that properly generates caps and joins.
|
|
129
116
|
*/
|
|
130
117
|
protected static float MIN_CAPS_JOINS_WEIGHT = 2f;
|
|
131
118
|
|
|
132
|
-
/**
|
|
133
|
-
*
|
|
134
|
-
* generates accurate caps and joins.
|
|
119
|
+
/** Maximum length of linear paths to be stroked with the
|
|
120
|
+
* full algorithm that generates accurate caps and joins.
|
|
135
121
|
*/
|
|
136
122
|
protected static int MAX_CAPS_JOINS_LENGTH = 5000;
|
|
137
123
|
|
|
138
|
-
/**
|
|
139
|
-
* Minimum array size to use arrayCopy method().
|
|
140
|
-
*/
|
|
124
|
+
/** Minimum array size to use arrayCopy method(). */
|
|
141
125
|
protected static int MIN_ARRAYCOPY_SIZE = 2;
|
|
142
126
|
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
145
|
-
* make sure the lines are always on top of the fill geometry
|
|
146
|
-
*/
|
|
127
|
+
/** Factor used to displace the stroke vertices towards the camera in
|
|
128
|
+
* order to make sure the lines are always on top of the fill geometry */
|
|
147
129
|
protected static float STROKE_DISPLACEMENT = 0.999f;
|
|
148
130
|
|
|
149
131
|
// ........................................................
|
|
132
|
+
|
|
150
133
|
// Variables to handle single-buffered situations (i.e.: Android)
|
|
134
|
+
|
|
151
135
|
protected IntBuffer firstFrame;
|
|
152
136
|
protected static boolean SINGLE_BUFFERED = false;
|
|
153
137
|
|
|
154
138
|
// ........................................................
|
|
139
|
+
|
|
155
140
|
// FBO layer
|
|
141
|
+
|
|
156
142
|
protected boolean fboLayerEnabled = false;
|
|
157
143
|
protected boolean fboLayerCreated = false;
|
|
158
144
|
protected boolean fboLayerEnabledReq = false;
|
|
@@ -176,14 +162,22 @@ public abstract class PGL {
|
|
|
176
162
|
protected int fboWidth, fboHeight;
|
|
177
163
|
protected int backTex, frontTex;
|
|
178
164
|
|
|
179
|
-
/**
|
|
180
|
-
* Flags used to handle the creation of a separate front texture
|
|
181
|
-
*/
|
|
165
|
+
/** Flags used to handle the creation of a separate front texture */
|
|
182
166
|
protected boolean usingFrontTex = false;
|
|
183
167
|
protected boolean needSepFrontTex = false;
|
|
184
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Defines if FBO Layer is allowed in the given environment.
|
|
171
|
+
* Using FBO can cause a fatal error during runtime for
|
|
172
|
+
* Intel HD Graphics 3000 chipsets (commonly used on older MacBooks)
|
|
173
|
+
* <a href="https://github.com/processing/processing/issues/4104">#4104</a>
|
|
174
|
+
*/
|
|
175
|
+
private Optional<Boolean> fboAllowed = Optional.empty();
|
|
176
|
+
|
|
185
177
|
// ........................................................
|
|
178
|
+
|
|
186
179
|
// Texture rendering
|
|
180
|
+
|
|
187
181
|
protected boolean loadedTex2DShader = false;
|
|
188
182
|
protected int tex2DShaderProgram;
|
|
189
183
|
protected int tex2DVertShader;
|
|
@@ -213,11 +207,11 @@ public abstract class PGL {
|
|
|
213
207
|
};
|
|
214
208
|
protected FloatBuffer texData;
|
|
215
209
|
|
|
216
|
-
protected static final String SHADER_PREPROCESSOR_DIRECTIVE
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
210
|
+
protected static final String SHADER_PREPROCESSOR_DIRECTIVE =
|
|
211
|
+
"#ifdef GL_ES\n" +
|
|
212
|
+
"precision mediump float;\n" +
|
|
213
|
+
"precision mediump int;\n" +
|
|
214
|
+
"#endif\n";
|
|
221
215
|
|
|
222
216
|
protected static String[] texVertShaderSource = {
|
|
223
217
|
"attribute vec2 position;",
|
|
@@ -234,7 +228,7 @@ public abstract class PGL {
|
|
|
234
228
|
"uniform sampler2D texMap;",
|
|
235
229
|
"varying vec2 vertTexCoord;",
|
|
236
230
|
"void main() {",
|
|
237
|
-
|
|
231
|
+
" gl_FragColor = texture2D(texMap, vertTexCoord.st);",
|
|
238
232
|
"}"
|
|
239
233
|
};
|
|
240
234
|
|
|
@@ -247,26 +241,26 @@ public abstract class PGL {
|
|
|
247
241
|
"}"
|
|
248
242
|
};
|
|
249
243
|
|
|
250
|
-
/**
|
|
251
|
-
|
|
252
|
-
*/
|
|
253
|
-
protected boolean[] texturingTargets = {false, false};
|
|
244
|
+
/** Which texturing targets are enabled */
|
|
245
|
+
protected boolean[] texturingTargets = { false, false };
|
|
254
246
|
|
|
255
|
-
/**
|
|
256
|
-
* Used to keep track of which textures are bound to each target
|
|
257
|
-
*/
|
|
247
|
+
/** Used to keep track of which textures are bound to each target */
|
|
258
248
|
protected int maxTexUnits;
|
|
259
249
|
protected int activeTexUnit = 0;
|
|
260
250
|
protected int[][] boundTextures;
|
|
261
251
|
|
|
262
252
|
// ........................................................
|
|
253
|
+
|
|
263
254
|
// Framerate handling
|
|
255
|
+
|
|
264
256
|
protected float targetFps = 60;
|
|
265
257
|
protected float currentFps = 60;
|
|
266
258
|
protected boolean setFps = false;
|
|
267
259
|
|
|
268
260
|
// ........................................................
|
|
261
|
+
|
|
269
262
|
// Utility buffers
|
|
263
|
+
|
|
270
264
|
protected ByteBuffer byteBuffer;
|
|
271
265
|
protected IntBuffer intBuffer;
|
|
272
266
|
protected IntBuffer viewBuffer;
|
|
@@ -276,16 +270,14 @@ public abstract class PGL {
|
|
|
276
270
|
protected ByteBuffer stencilBuffer;
|
|
277
271
|
|
|
278
272
|
//........................................................
|
|
273
|
+
|
|
279
274
|
// Rendering information
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
*/
|
|
275
|
+
|
|
276
|
+
/** Used to register amount of geometry rendered in each frame. */
|
|
283
277
|
protected int geomCount = 0;
|
|
284
278
|
protected int pgeomCount;
|
|
285
279
|
|
|
286
|
-
/**
|
|
287
|
-
* Used to register calls to background.
|
|
288
|
-
*/
|
|
280
|
+
/** Used to register calls to background. */
|
|
289
281
|
protected boolean clearColor = false;
|
|
290
282
|
protected boolean pclearColor;
|
|
291
283
|
|
|
@@ -295,66 +287,66 @@ public abstract class PGL {
|
|
|
295
287
|
protected boolean clearStencil = false;
|
|
296
288
|
protected boolean pclearStencil;
|
|
297
289
|
|
|
290
|
+
|
|
298
291
|
// ........................................................
|
|
292
|
+
|
|
299
293
|
// Error messages
|
|
300
|
-
public static final String WIKI
|
|
301
|
-
= " Read http://wiki.processing.org/w/OpenGL_Issues for help.";
|
|
302
294
|
|
|
303
|
-
public static final String
|
|
304
|
-
|
|
295
|
+
public static final String WIKI =
|
|
296
|
+
" Read http://wiki.processing.org/w/OpenGL_Issues for help.";
|
|
305
297
|
|
|
306
|
-
public static final String
|
|
307
|
-
|
|
298
|
+
public static final String FRAMEBUFFER_ERROR =
|
|
299
|
+
"Framebuffer error (%1$s), rendering will probably not work as expected" + WIKI;
|
|
308
300
|
|
|
309
|
-
public static final String
|
|
310
|
-
|
|
301
|
+
public static final String MISSING_FBO_ERROR =
|
|
302
|
+
"Framebuffer objects are not supported by this hardware (or driver)" + WIKI;
|
|
311
303
|
|
|
312
|
-
public static final String
|
|
313
|
-
|
|
304
|
+
public static final String MISSING_GLSL_ERROR =
|
|
305
|
+
"GLSL shaders are not supported by this hardware (or driver)" + WIKI;
|
|
314
306
|
|
|
315
|
-
public static final String
|
|
316
|
-
|
|
307
|
+
public static final String MISSING_GLFUNC_ERROR =
|
|
308
|
+
"GL function %1$s is not available on this hardware (or driver)" + WIKI;
|
|
317
309
|
|
|
318
|
-
public static final String
|
|
319
|
-
|
|
310
|
+
public static final String UNSUPPORTED_GLPROF_ERROR =
|
|
311
|
+
"Unsupported OpenGL profile.";
|
|
320
312
|
|
|
321
|
-
public static final String
|
|
322
|
-
|
|
323
|
-
+ "This is most likely due to a bug in the renderer's code, please report it with an "
|
|
324
|
-
+ "issue on Processing's github page https://github.com/processing/processing/issues?state=open "
|
|
325
|
-
+ "if using any of the built-in OpenGL renderers. If you are using a contributed "
|
|
326
|
-
+ "library, contact the library's developers.";
|
|
313
|
+
public static final String TEXUNIT_ERROR =
|
|
314
|
+
"Number of texture units not supported by this hardware (or driver)" + WIKI;
|
|
327
315
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
316
|
+
public static final String NONPRIMARY_ERROR =
|
|
317
|
+
"The renderer is trying to call a PGL function that can only be called on a primary PGL. " +
|
|
318
|
+
"This is most likely due to a bug in the renderer's code, please report it with an " +
|
|
319
|
+
"issue on Processing's github page https://github.com/processing/processing/issues?state=open " +
|
|
320
|
+
"if using any of the built-in OpenGL renderers. If you are using a contributed " +
|
|
321
|
+
"library, contact the library's developers.";
|
|
322
|
+
|
|
323
|
+
protected static final String DEPTH_READING_NOT_ENABLED_ERROR =
|
|
324
|
+
"Reading depth and stencil values from this multisampled buffer is not enabled. " +
|
|
325
|
+
"You can enable it by calling hint(ENABLE_DEPTH_READING) once. " +
|
|
326
|
+
"If your sketch becomes too slow, disable multisampling with noSmooth() instead.";
|
|
332
327
|
|
|
333
328
|
// ........................................................
|
|
329
|
+
|
|
334
330
|
// Constants
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
*/
|
|
331
|
+
|
|
332
|
+
/** Size of different types in bytes */
|
|
338
333
|
protected static int SIZEOF_SHORT = Short.SIZE / 8;
|
|
339
|
-
protected static int SIZEOF_INT
|
|
334
|
+
protected static int SIZEOF_INT = Integer.SIZE / 8;
|
|
340
335
|
protected static int SIZEOF_FLOAT = Float.SIZE / 8;
|
|
341
|
-
protected static int SIZEOF_BYTE
|
|
336
|
+
protected static int SIZEOF_BYTE = Byte.SIZE / 8;
|
|
342
337
|
protected static int SIZEOF_INDEX = SIZEOF_SHORT;
|
|
343
|
-
protected static int INDEX_TYPE
|
|
338
|
+
protected static int INDEX_TYPE = 0x1403; // GL_UNSIGNED_SHORT
|
|
344
339
|
|
|
345
|
-
/**
|
|
346
|
-
* Machine Epsilon for float precision.
|
|
347
|
-
*/
|
|
340
|
+
/** Machine Epsilon for float precision. */
|
|
348
341
|
protected static float FLOAT_EPS = Float.MIN_VALUE;
|
|
349
342
|
// Calculation of the Machine Epsilon for float precision. From:
|
|
350
343
|
// http://en.wikipedia.org/wiki/Machine_epsilon#Approximation_using_Java
|
|
351
|
-
|
|
352
344
|
static {
|
|
353
345
|
float eps = 1.0f;
|
|
354
346
|
|
|
355
347
|
do {
|
|
356
348
|
eps /= 2.0f;
|
|
357
|
-
} while ((float)
|
|
349
|
+
} while ((float)(1.0 + (eps / 2.0)) != 1.0);
|
|
358
350
|
|
|
359
351
|
FLOAT_EPS = eps;
|
|
360
352
|
}
|
|
@@ -363,13 +355,17 @@ public abstract class PGL {
|
|
|
363
355
|
* Set to true if the host system is big endian (PowerPC, MIPS, SPARC), false
|
|
364
356
|
* if little endian (x86 Intel for Mac or PC).
|
|
365
357
|
*/
|
|
366
|
-
protected static boolean BIG_ENDIAN
|
|
367
|
-
|
|
358
|
+
protected static boolean BIG_ENDIAN =
|
|
359
|
+
ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
|
|
368
360
|
|
|
369
361
|
// ........................................................
|
|
362
|
+
|
|
370
363
|
// Present mode
|
|
364
|
+
|
|
371
365
|
// ........................................................
|
|
366
|
+
|
|
372
367
|
// Present mode
|
|
368
|
+
|
|
373
369
|
protected boolean presentMode = false;
|
|
374
370
|
protected boolean showStopButton = true;
|
|
375
371
|
public float presentX;
|
|
@@ -396,10 +392,14 @@ public abstract class PGL {
|
|
|
396
392
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0,
|
|
397
393
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0};
|
|
398
394
|
|
|
395
|
+
|
|
399
396
|
///////////////////////////////////////////////////////////////
|
|
397
|
+
|
|
400
398
|
// Initialization, finalization
|
|
401
|
-
|
|
402
|
-
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
public PGL() { }
|
|
402
|
+
|
|
403
403
|
|
|
404
404
|
public PGL(PGraphicsOpenGL pg) {
|
|
405
405
|
this.graphics = pg;
|
|
@@ -422,14 +422,17 @@ public abstract class PGL {
|
|
|
422
422
|
viewBuffer = allocateIntBuffer(4);
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
+
|
|
425
426
|
public void dispose() {
|
|
426
427
|
destroyFBOLayer();
|
|
427
428
|
}
|
|
428
429
|
|
|
430
|
+
|
|
429
431
|
public void setPrimary(boolean primary) {
|
|
430
432
|
primaryPGL = primary;
|
|
431
433
|
}
|
|
432
434
|
|
|
435
|
+
|
|
433
436
|
static public int smoothToSamples(int smooth) {
|
|
434
437
|
switch (smooth) {
|
|
435
438
|
case 0:
|
|
@@ -444,85 +447,102 @@ public abstract class PGL {
|
|
|
444
447
|
}
|
|
445
448
|
}
|
|
446
449
|
|
|
450
|
+
|
|
447
451
|
abstract public Object getNative();
|
|
448
452
|
|
|
453
|
+
|
|
449
454
|
abstract protected void setFrameRate(float fps);
|
|
450
455
|
|
|
456
|
+
|
|
451
457
|
abstract protected void initSurface(int antialias);
|
|
452
458
|
|
|
459
|
+
|
|
453
460
|
abstract protected void reinitSurface();
|
|
454
461
|
|
|
462
|
+
|
|
455
463
|
abstract protected void registerListeners();
|
|
456
464
|
|
|
457
|
-
|
|
465
|
+
|
|
466
|
+
protected int getReadFramebuffer() {
|
|
458
467
|
return fboLayerEnabled ? glColorFbo.get(0) : 0;
|
|
459
468
|
}
|
|
460
469
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
return 0;
|
|
467
|
-
}
|
|
470
|
+
|
|
471
|
+
protected int getDrawFramebuffer() {
|
|
472
|
+
if (fboLayerEnabled) return 1 < numSamples ? glMultiFbo.get(0) :
|
|
473
|
+
glColorFbo.get(0);
|
|
474
|
+
else return 0;
|
|
468
475
|
}
|
|
469
476
|
|
|
470
|
-
|
|
477
|
+
|
|
478
|
+
protected int getDefaultDrawBuffer() {
|
|
471
479
|
return fboLayerEnabled ? COLOR_ATTACHMENT0 : BACK;
|
|
472
480
|
}
|
|
473
481
|
|
|
474
|
-
|
|
482
|
+
|
|
483
|
+
protected int getDefaultReadBuffer() {
|
|
475
484
|
return fboLayerEnabled ? COLOR_ATTACHMENT0 : FRONT;
|
|
476
485
|
}
|
|
477
486
|
|
|
478
|
-
|
|
487
|
+
|
|
488
|
+
protected boolean isFBOBacked() {
|
|
479
489
|
return fboLayerEnabled;
|
|
480
490
|
}
|
|
481
491
|
|
|
492
|
+
|
|
482
493
|
@Deprecated
|
|
483
494
|
public void requestFBOLayer() {
|
|
484
495
|
enableFBOLayer();
|
|
485
496
|
}
|
|
486
497
|
|
|
498
|
+
|
|
487
499
|
public void enableFBOLayer() {
|
|
488
500
|
fboLayerEnabledReq = true;
|
|
489
501
|
}
|
|
490
502
|
|
|
503
|
+
|
|
491
504
|
public void disableFBOLayer() {
|
|
492
505
|
fboLayerDisableReq = true;
|
|
493
506
|
}
|
|
494
507
|
|
|
508
|
+
|
|
495
509
|
public void resetFBOLayer() {
|
|
496
510
|
fbolayerResetReq = true;
|
|
497
511
|
}
|
|
498
512
|
|
|
513
|
+
|
|
499
514
|
protected boolean isMultisampled() {
|
|
500
515
|
return 1 < numSamples;
|
|
501
516
|
}
|
|
502
517
|
|
|
518
|
+
|
|
503
519
|
abstract protected int getDepthBits();
|
|
504
520
|
|
|
521
|
+
|
|
505
522
|
abstract protected int getStencilBits();
|
|
506
523
|
|
|
524
|
+
|
|
507
525
|
protected boolean getDepthTest() {
|
|
508
526
|
intBuffer.rewind();
|
|
509
527
|
getBooleanv(DEPTH_TEST, intBuffer);
|
|
510
528
|
return intBuffer.get(0) != 0;
|
|
511
529
|
}
|
|
512
530
|
|
|
531
|
+
|
|
513
532
|
protected boolean getDepthWriteMask() {
|
|
514
533
|
intBuffer.rewind();
|
|
515
534
|
getBooleanv(DEPTH_WRITEMASK, intBuffer);
|
|
516
535
|
return intBuffer.get(0) != 0;
|
|
517
536
|
}
|
|
518
537
|
|
|
538
|
+
|
|
519
539
|
protected Texture wrapBackTexture(Texture texture) {
|
|
520
540
|
if (texture == null) {
|
|
521
541
|
texture = new Texture(graphics);
|
|
522
542
|
texture.init(graphics.width, graphics.height,
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
543
|
+
glColorTex.get(backTex), TEXTURE_2D, RGBA,
|
|
544
|
+
fboWidth, fboHeight, NEAREST, NEAREST,
|
|
545
|
+
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
|
|
526
546
|
texture.invertedY(true);
|
|
527
547
|
texture.colorBuffer(true);
|
|
528
548
|
graphics.setCache(graphics, texture);
|
|
@@ -532,13 +552,14 @@ public abstract class PGL {
|
|
|
532
552
|
return texture;
|
|
533
553
|
}
|
|
534
554
|
|
|
535
|
-
|
|
555
|
+
|
|
556
|
+
protected Texture wrapFrontTexture(Texture texture) {
|
|
536
557
|
if (texture == null) {
|
|
537
558
|
texture = new Texture(graphics);
|
|
538
559
|
texture.init(graphics.width, graphics.height,
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
560
|
+
glColorTex.get(frontTex), TEXTURE_2D, RGBA,
|
|
561
|
+
fboWidth, fboHeight, NEAREST, NEAREST,
|
|
562
|
+
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
|
|
542
563
|
texture.invertedY(true);
|
|
543
564
|
texture.colorBuffer(true);
|
|
544
565
|
} else {
|
|
@@ -547,6 +568,7 @@ public abstract class PGL {
|
|
|
547
568
|
return texture;
|
|
548
569
|
}
|
|
549
570
|
|
|
571
|
+
|
|
550
572
|
protected void bindFrontTexture() {
|
|
551
573
|
usingFrontTex = true;
|
|
552
574
|
if (!texturingIsEnabled(TEXTURE_2D)) {
|
|
@@ -555,6 +577,7 @@ public abstract class PGL {
|
|
|
555
577
|
bindTexture(TEXTURE_2D, glColorTex.get(frontTex));
|
|
556
578
|
}
|
|
557
579
|
|
|
580
|
+
|
|
558
581
|
protected void unbindFrontTexture() {
|
|
559
582
|
if (textureIsBound(TEXTURE_2D, glColorTex.get(frontTex))) {
|
|
560
583
|
// We don't want to unbind another texture
|
|
@@ -569,10 +592,9 @@ public abstract class PGL {
|
|
|
569
592
|
}
|
|
570
593
|
}
|
|
571
594
|
|
|
595
|
+
|
|
572
596
|
protected void syncBackTexture() {
|
|
573
|
-
if (usingFrontTex)
|
|
574
|
-
needSepFrontTex = true;
|
|
575
|
-
}
|
|
597
|
+
if (usingFrontTex) needSepFrontTex = true;
|
|
576
598
|
if (1 < numSamples) {
|
|
577
599
|
bindFramebufferImpl(READ_FRAMEBUFFER, glMultiFbo.get(0));
|
|
578
600
|
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
|
|
@@ -581,15 +603,19 @@ public abstract class PGL {
|
|
|
581
603
|
mask |= DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT;
|
|
582
604
|
}
|
|
583
605
|
blitFramebuffer(0, 0, fboWidth, fboHeight,
|
|
584
|
-
|
|
585
|
-
|
|
606
|
+
0, 0, fboWidth, fboHeight,
|
|
607
|
+
mask, NEAREST);
|
|
586
608
|
}
|
|
587
609
|
}
|
|
588
610
|
|
|
611
|
+
|
|
589
612
|
abstract protected float getPixelScale();
|
|
590
613
|
|
|
591
614
|
///////////////////////////////////////////////////////////
|
|
615
|
+
|
|
592
616
|
// Present mode
|
|
617
|
+
|
|
618
|
+
|
|
593
619
|
public void initPresentMode(float x, float y, int stopColor) {
|
|
594
620
|
presentMode = true;
|
|
595
621
|
showStopButton = stopColor != 0;
|
|
@@ -599,28 +625,34 @@ public abstract class PGL {
|
|
|
599
625
|
enableFBOLayer();
|
|
600
626
|
}
|
|
601
627
|
|
|
628
|
+
|
|
602
629
|
public boolean presentMode() {
|
|
603
630
|
return presentMode;
|
|
604
631
|
}
|
|
605
632
|
|
|
633
|
+
|
|
606
634
|
public float presentX() {
|
|
607
635
|
return presentX;
|
|
608
636
|
}
|
|
609
637
|
|
|
638
|
+
|
|
610
639
|
public float presentY() {
|
|
611
640
|
return presentY;
|
|
612
641
|
}
|
|
613
642
|
|
|
643
|
+
|
|
614
644
|
public boolean insideStopButton(float x, float y) {
|
|
615
|
-
if (!showStopButton)
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
return stopButtonX < x && x < stopButtonX + stopButtonWidth
|
|
619
|
-
&& -(closeButtonY + stopButtonHeight) < y && y < -closeButtonY;
|
|
645
|
+
if (!showStopButton) return false;
|
|
646
|
+
return stopButtonX < x && x < stopButtonX + stopButtonWidth &&
|
|
647
|
+
-(closeButtonY + stopButtonHeight) < y && y < -closeButtonY;
|
|
620
648
|
}
|
|
621
649
|
|
|
650
|
+
|
|
622
651
|
///////////////////////////////////////////////////////////
|
|
652
|
+
|
|
623
653
|
// Frame rendering
|
|
654
|
+
|
|
655
|
+
|
|
624
656
|
protected void clearDepthStencil() {
|
|
625
657
|
if (!pclearDepth && !pclearStencil) {
|
|
626
658
|
depthMask(true);
|
|
@@ -637,8 +669,9 @@ public abstract class PGL {
|
|
|
637
669
|
}
|
|
638
670
|
}
|
|
639
671
|
|
|
672
|
+
|
|
640
673
|
protected void clearBackground(float r, float g, float b, float a,
|
|
641
|
-
|
|
674
|
+
boolean depth, boolean stencil) {
|
|
642
675
|
clearColor(r, g, b, a);
|
|
643
676
|
if (depth && stencil) {
|
|
644
677
|
clearDepth(1);
|
|
@@ -668,6 +701,7 @@ public abstract class PGL {
|
|
|
668
701
|
}
|
|
669
702
|
}
|
|
670
703
|
|
|
704
|
+
|
|
671
705
|
protected void beginRender() {
|
|
672
706
|
if (sketch == null) {
|
|
673
707
|
sketch = graphics.parent;
|
|
@@ -706,7 +740,7 @@ public abstract class PGL {
|
|
|
706
740
|
// Draw to the back texture
|
|
707
741
|
bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
|
|
708
742
|
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
|
|
709
|
-
|
|
743
|
+
TEXTURE_2D, glColorTex.get(backTex), 0);
|
|
710
744
|
|
|
711
745
|
if (1 < numSamples) {
|
|
712
746
|
bindFramebufferImpl(FRAMEBUFFER, glMultiFbo.get(0));
|
|
@@ -727,18 +761,19 @@ public abstract class PGL {
|
|
|
727
761
|
int x = 0;
|
|
728
762
|
int y = 0;
|
|
729
763
|
if (presentMode) {
|
|
730
|
-
x = (int)
|
|
731
|
-
y = (int)
|
|
764
|
+
x = (int)presentX;
|
|
765
|
+
y = (int)presentY;
|
|
732
766
|
}
|
|
733
767
|
float scale = getPixelScale();
|
|
734
768
|
drawTexture(TEXTURE_2D, glColorTex.get(frontTex), fboWidth, fboHeight,
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
769
|
+
x, y, graphics.width, graphics.height,
|
|
770
|
+
0, 0, (int)(scale * graphics.width), (int)(scale * graphics.height),
|
|
771
|
+
0, 0, graphics.width, graphics.height);
|
|
738
772
|
}
|
|
739
773
|
}
|
|
740
774
|
}
|
|
741
775
|
|
|
776
|
+
|
|
742
777
|
protected void endRender(int windowColor) {
|
|
743
778
|
if (fboLayerEnabled) {
|
|
744
779
|
syncBackTexture();
|
|
@@ -747,7 +782,7 @@ public abstract class PGL {
|
|
|
747
782
|
bindFramebufferImpl(FRAMEBUFFER, 0);
|
|
748
783
|
|
|
749
784
|
if (presentMode) {
|
|
750
|
-
float wa = ((windowColor >> 24) & 0xff)
|
|
785
|
+
float wa = ((windowColor >> 24) & 0xff) / 255.0f;
|
|
751
786
|
float wr = ((windowColor >> 16) & 0xff) / 255.0f;
|
|
752
787
|
float wg = ((windowColor >> 8) & 0xff) / 255.0f;
|
|
753
788
|
float wb = (windowColor & 0xff) / 255.0f;
|
|
@@ -769,17 +804,18 @@ public abstract class PGL {
|
|
|
769
804
|
int[] color = new int[closeButtonPix.length];
|
|
770
805
|
PApplet.arrayCopy(closeButtonPix, color);
|
|
771
806
|
|
|
807
|
+
|
|
772
808
|
// Multiply the texture by the button color
|
|
773
809
|
float ba = ((stopButtonColor >> 24) & 0xFF) / 255f;
|
|
774
810
|
float br = ((stopButtonColor >> 16) & 0xFF) / 255f;
|
|
775
|
-
float bg = ((stopButtonColor >>
|
|
776
|
-
float bb = ((stopButtonColor) & 0xFF) / 255f;
|
|
811
|
+
float bg = ((stopButtonColor >> 8) & 0xFF) / 255f;
|
|
812
|
+
float bb = ((stopButtonColor >> 0) & 0xFF) / 255f;
|
|
777
813
|
for (int i = 0; i < color.length; i++) {
|
|
778
814
|
int c = closeButtonPix[i];
|
|
779
|
-
int a = (int)
|
|
780
|
-
int r = (int)
|
|
781
|
-
int g = (int)
|
|
782
|
-
int b = (int)
|
|
815
|
+
int a = (int)(ba * ((c >> 24) & 0xFF));
|
|
816
|
+
int r = (int)(br * ((c >> 16) & 0xFF));
|
|
817
|
+
int g = (int)(bg * ((c >> 8) & 0xFF));
|
|
818
|
+
int b = (int)(bb * ((c >> 0) & 0xFF));
|
|
783
819
|
color[i] = javaToNativeARGB((a << 24) | (r << 16) | (g << 8) | b);
|
|
784
820
|
}
|
|
785
821
|
IntBuffer buf = allocateIntBuffer(color);
|
|
@@ -787,10 +823,10 @@ public abstract class PGL {
|
|
|
787
823
|
bindTexture(TEXTURE_2D, 0);
|
|
788
824
|
}
|
|
789
825
|
drawTexture(TEXTURE_2D, closeButtonTex.get(0), stopButtonWidth, stopButtonHeight,
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
826
|
+
0, 0, stopButtonX + stopButtonWidth, closeButtonY + stopButtonHeight,
|
|
827
|
+
0, stopButtonHeight, stopButtonWidth, 0,
|
|
828
|
+
stopButtonX, closeButtonY, stopButtonX + stopButtonWidth, closeButtonY + stopButtonHeight);
|
|
829
|
+
}
|
|
794
830
|
} else {
|
|
795
831
|
clearDepth(1);
|
|
796
832
|
clearColor(0, 0, 0, 0);
|
|
@@ -802,15 +838,15 @@ public abstract class PGL {
|
|
|
802
838
|
int x = 0;
|
|
803
839
|
int y = 0;
|
|
804
840
|
if (presentMode) {
|
|
805
|
-
x = (int)
|
|
806
|
-
y = (int)
|
|
841
|
+
x = (int)presentX;
|
|
842
|
+
y = (int)presentY;
|
|
807
843
|
}
|
|
808
844
|
float scale = getPixelScale();
|
|
809
845
|
drawTexture(TEXTURE_2D, glColorTex.get(backTex),
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
846
|
+
fboWidth, fboHeight,
|
|
847
|
+
x, y, graphics.width, graphics.height,
|
|
848
|
+
0, 0, (int)(scale * graphics.width), (int)(scale * graphics.height),
|
|
849
|
+
0, 0, graphics.width, graphics.height);
|
|
814
850
|
|
|
815
851
|
// Swapping front and back textures.
|
|
816
852
|
int temp = frontTex;
|
|
@@ -826,48 +862,58 @@ public abstract class PGL {
|
|
|
826
862
|
saveFirstFrame();
|
|
827
863
|
}
|
|
828
864
|
|
|
829
|
-
if (
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
865
|
+
if (getIsFboAllowed()) {
|
|
866
|
+
if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) {
|
|
867
|
+
enableFBOLayer();
|
|
868
|
+
if (SINGLE_BUFFERED) {
|
|
869
|
+
createFBOLayer();
|
|
870
|
+
}
|
|
833
871
|
}
|
|
834
872
|
}
|
|
835
873
|
}
|
|
836
874
|
}
|
|
837
875
|
|
|
876
|
+
|
|
838
877
|
protected abstract void getGL(PGL pgl);
|
|
839
878
|
|
|
879
|
+
|
|
840
880
|
protected abstract boolean canDraw();
|
|
841
881
|
|
|
882
|
+
|
|
842
883
|
protected abstract void requestFocus();
|
|
843
884
|
|
|
885
|
+
|
|
844
886
|
protected abstract void requestDraw();
|
|
845
887
|
|
|
888
|
+
|
|
846
889
|
protected abstract void swapBuffers();
|
|
847
890
|
|
|
848
|
-
|
|
891
|
+
|
|
892
|
+
public boolean threadIsCurrent() {
|
|
849
893
|
return Thread.currentThread() == glThread;
|
|
850
894
|
}
|
|
851
895
|
|
|
896
|
+
|
|
852
897
|
public void setThread(Thread thread) {
|
|
853
898
|
glThread = thread;
|
|
854
899
|
}
|
|
855
900
|
|
|
856
|
-
protected void beginGL() {
|
|
857
|
-
}
|
|
858
901
|
|
|
859
|
-
protected void
|
|
860
|
-
|
|
902
|
+
protected void beginGL() { }
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
protected void endGL() { }
|
|
906
|
+
|
|
861
907
|
|
|
862
908
|
private void createFBOLayer() {
|
|
863
909
|
float scale = getPixelScale();
|
|
864
910
|
|
|
865
911
|
if (hasNpotTexSupport()) {
|
|
866
|
-
fboWidth = (int)
|
|
867
|
-
fboHeight = (int)
|
|
912
|
+
fboWidth = (int)(scale * graphics.width);
|
|
913
|
+
fboHeight = (int)(scale * graphics.height);
|
|
868
914
|
} else {
|
|
869
|
-
fboWidth = nextPowerOfTwo((int)
|
|
870
|
-
fboHeight = nextPowerOfTwo((int)
|
|
915
|
+
fboWidth = nextPowerOfTwo((int)(scale * graphics.width));
|
|
916
|
+
fboHeight = nextPowerOfTwo((int)(scale * graphics.height));
|
|
871
917
|
}
|
|
872
918
|
|
|
873
919
|
if (hasFboMultisampleSupport()) {
|
|
@@ -890,7 +936,7 @@ public abstract class PGL {
|
|
|
890
936
|
texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
|
|
891
937
|
texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
|
|
892
938
|
texImage2D(TEXTURE_2D, 0, RGBA, fboWidth, fboHeight, 0,
|
|
893
|
-
|
|
939
|
+
RGBA, UNSIGNED_BYTE, null);
|
|
894
940
|
initTexture(TEXTURE_2D, RGBA, fboWidth, fboHeight, graphics.backgroundColor);
|
|
895
941
|
}
|
|
896
942
|
bindTexture(TEXTURE_2D, 0);
|
|
@@ -901,7 +947,7 @@ public abstract class PGL {
|
|
|
901
947
|
genFramebuffers(1, glColorFbo);
|
|
902
948
|
bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
|
|
903
949
|
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D,
|
|
904
|
-
|
|
950
|
+
glColorTex.get(backTex), 0);
|
|
905
951
|
|
|
906
952
|
if (!multisample || graphics.getHint(PConstants.ENABLE_BUFFER_READING)) {
|
|
907
953
|
// If not multisampled, this is the only depth and stencil buffer.
|
|
@@ -919,9 +965,9 @@ public abstract class PGL {
|
|
|
919
965
|
genRenderbuffers(1, glMultiColor);
|
|
920
966
|
bindRenderbuffer(RENDERBUFFER, glMultiColor.get(0));
|
|
921
967
|
renderbufferStorageMultisample(RENDERBUFFER, numSamples,
|
|
922
|
-
|
|
968
|
+
RGBA8, fboWidth, fboHeight);
|
|
923
969
|
framebufferRenderbuffer(FRAMEBUFFER, COLOR_ATTACHMENT0,
|
|
924
|
-
|
|
970
|
+
RENDERBUFFER, glMultiColor.get(0));
|
|
925
971
|
|
|
926
972
|
// Creating multisampled depth and stencil buffers
|
|
927
973
|
createDepthAndStencilBuffer(true, depthBits, stencilBits, packed);
|
|
@@ -957,18 +1003,16 @@ public abstract class PGL {
|
|
|
957
1003
|
|
|
958
1004
|
protected abstract void initFBOLayer();
|
|
959
1005
|
|
|
1006
|
+
|
|
960
1007
|
protected void saveFirstFrame() {
|
|
961
1008
|
firstFrame = allocateDirectIntBuffer(graphics.width * graphics.height);
|
|
962
|
-
if (hasReadBuffer())
|
|
963
|
-
readBuffer(BACK);
|
|
964
|
-
}
|
|
1009
|
+
if (hasReadBuffer()) readBuffer(BACK);
|
|
965
1010
|
readPixelsImpl(0, 0, graphics.width, graphics.height, RGBA, UNSIGNED_BYTE, firstFrame);
|
|
966
1011
|
}
|
|
967
1012
|
|
|
1013
|
+
|
|
968
1014
|
protected void restoreFirstFrame() {
|
|
969
|
-
if (firstFrame == null)
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
1015
|
+
if (firstFrame == null) return;
|
|
972
1016
|
|
|
973
1017
|
IntBuffer tex = allocateIntBuffer(1);
|
|
974
1018
|
genTextures(1, tex);
|
|
@@ -976,11 +1020,11 @@ public abstract class PGL {
|
|
|
976
1020
|
int w, h;
|
|
977
1021
|
float scale = getPixelScale();
|
|
978
1022
|
if (hasNpotTexSupport()) {
|
|
979
|
-
w = (int)
|
|
980
|
-
h = (int)
|
|
1023
|
+
w = (int)(scale * graphics.width);
|
|
1024
|
+
h = (int)(scale * graphics.height);
|
|
981
1025
|
} else {
|
|
982
|
-
w = nextPowerOfTwo((int)
|
|
983
|
-
h = nextPowerOfTwo((int)
|
|
1026
|
+
w = nextPowerOfTwo((int)(scale * graphics.width));
|
|
1027
|
+
h = nextPowerOfTwo((int)(scale * graphics.height));
|
|
984
1028
|
}
|
|
985
1029
|
|
|
986
1030
|
bindTexture(TEXTURE_2D, tex.get(0));
|
|
@@ -992,9 +1036,9 @@ public abstract class PGL {
|
|
|
992
1036
|
texSubImage2D(TEXTURE_2D, 0, 0, 0, graphics.width, graphics.height, RGBA, UNSIGNED_BYTE, firstFrame);
|
|
993
1037
|
|
|
994
1038
|
drawTexture(TEXTURE_2D, tex.get(0), w, h,
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1039
|
+
0, 0, graphics.width, graphics.height,
|
|
1040
|
+
0, 0, (int)(scale * graphics.width), (int)(scale * graphics.height),
|
|
1041
|
+
0, 0, graphics.width, graphics.height);
|
|
998
1042
|
|
|
999
1043
|
deleteTextures(1, tex);
|
|
1000
1044
|
firstFrame.clear();
|
|
@@ -1018,26 +1062,27 @@ public abstract class PGL {
|
|
|
1018
1062
|
fboLayerCreated = false;
|
|
1019
1063
|
}
|
|
1020
1064
|
|
|
1065
|
+
|
|
1021
1066
|
private void createDepthAndStencilBuffer(boolean multisample, int depthBits,
|
|
1022
|
-
|
|
1067
|
+
int stencilBits, boolean packed) {
|
|
1023
1068
|
// Creating depth and stencil buffers
|
|
1024
1069
|
if (packed && depthBits == 24 && stencilBits == 8) {
|
|
1025
1070
|
// packed depth+stencil buffer
|
|
1026
|
-
IntBuffer depthStencilBuf
|
|
1027
|
-
|
|
1071
|
+
IntBuffer depthStencilBuf =
|
|
1072
|
+
multisample ? glMultiDepthStencil : glDepthStencil;
|
|
1028
1073
|
genRenderbuffers(1, depthStencilBuf);
|
|
1029
1074
|
bindRenderbuffer(RENDERBUFFER, depthStencilBuf.get(0));
|
|
1030
1075
|
if (multisample) {
|
|
1031
1076
|
renderbufferStorageMultisample(RENDERBUFFER, numSamples,
|
|
1032
|
-
|
|
1077
|
+
DEPTH24_STENCIL8, fboWidth, fboHeight);
|
|
1033
1078
|
} else {
|
|
1034
1079
|
renderbufferStorage(RENDERBUFFER, DEPTH24_STENCIL8,
|
|
1035
|
-
|
|
1080
|
+
fboWidth, fboHeight);
|
|
1036
1081
|
}
|
|
1037
1082
|
framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER,
|
|
1038
|
-
|
|
1083
|
+
depthStencilBuf.get(0));
|
|
1039
1084
|
framebufferRenderbuffer(FRAMEBUFFER, STENCIL_ATTACHMENT, RENDERBUFFER,
|
|
1040
|
-
|
|
1085
|
+
depthStencilBuf.get(0));
|
|
1041
1086
|
} else {
|
|
1042
1087
|
// separate depth and stencil buffers
|
|
1043
1088
|
if (0 < depthBits) {
|
|
@@ -1061,29 +1106,23 @@ public abstract class PGL {
|
|
|
1061
1106
|
bindRenderbuffer(RENDERBUFFER, depthBuf.get(0));
|
|
1062
1107
|
if (multisample) {
|
|
1063
1108
|
renderbufferStorageMultisample(RENDERBUFFER, numSamples,
|
|
1064
|
-
|
|
1109
|
+
depthComponent, fboWidth, fboHeight);
|
|
1065
1110
|
} else {
|
|
1066
1111
|
renderbufferStorage(RENDERBUFFER, depthComponent,
|
|
1067
|
-
|
|
1112
|
+
fboWidth, fboHeight);
|
|
1068
1113
|
}
|
|
1069
1114
|
framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT,
|
|
1070
|
-
|
|
1115
|
+
RENDERBUFFER, depthBuf.get(0));
|
|
1071
1116
|
}
|
|
1072
1117
|
|
|
1073
1118
|
if (0 < stencilBits) {
|
|
1074
1119
|
int stencilIndex = STENCIL_INDEX1;
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
break;
|
|
1082
|
-
case 1:
|
|
1083
|
-
stencilIndex = STENCIL_INDEX1;
|
|
1084
|
-
break;
|
|
1085
|
-
default:
|
|
1086
|
-
break;
|
|
1120
|
+
if (stencilBits == 8) {
|
|
1121
|
+
stencilIndex = STENCIL_INDEX8;
|
|
1122
|
+
} else if (stencilBits == 4) {
|
|
1123
|
+
stencilIndex = STENCIL_INDEX4;
|
|
1124
|
+
} else if (stencilBits == 1) {
|
|
1125
|
+
stencilIndex = STENCIL_INDEX1;
|
|
1087
1126
|
}
|
|
1088
1127
|
|
|
1089
1128
|
IntBuffer stencilBuf = multisample ? glMultiStencil : glStencil;
|
|
@@ -1091,33 +1130,43 @@ public abstract class PGL {
|
|
|
1091
1130
|
bindRenderbuffer(RENDERBUFFER, stencilBuf.get(0));
|
|
1092
1131
|
if (multisample) {
|
|
1093
1132
|
renderbufferStorageMultisample(RENDERBUFFER, numSamples,
|
|
1094
|
-
|
|
1133
|
+
stencilIndex, fboWidth, fboHeight);
|
|
1095
1134
|
} else {
|
|
1096
1135
|
renderbufferStorage(RENDERBUFFER, stencilIndex,
|
|
1097
|
-
|
|
1136
|
+
fboWidth, fboHeight);
|
|
1098
1137
|
}
|
|
1099
1138
|
framebufferRenderbuffer(FRAMEBUFFER, STENCIL_ATTACHMENT,
|
|
1100
|
-
|
|
1139
|
+
RENDERBUFFER, stencilBuf.get(0));
|
|
1101
1140
|
}
|
|
1102
1141
|
}
|
|
1103
1142
|
}
|
|
1104
1143
|
|
|
1144
|
+
|
|
1105
1145
|
///////////////////////////////////////////////////////////
|
|
1146
|
+
|
|
1106
1147
|
// Context interface
|
|
1148
|
+
|
|
1149
|
+
|
|
1107
1150
|
protected int createEmptyContext() {
|
|
1108
1151
|
return -1;
|
|
1109
1152
|
}
|
|
1110
1153
|
|
|
1154
|
+
|
|
1111
1155
|
protected int getCurrentContext() {
|
|
1112
1156
|
return glContext;
|
|
1113
1157
|
}
|
|
1114
1158
|
|
|
1159
|
+
|
|
1115
1160
|
///////////////////////////////////////////////////////////
|
|
1161
|
+
|
|
1116
1162
|
// Utility functions
|
|
1163
|
+
|
|
1164
|
+
|
|
1117
1165
|
protected boolean contextIsCurrent(int other) {
|
|
1118
1166
|
return other == -1 || other == glContext;
|
|
1119
1167
|
}
|
|
1120
1168
|
|
|
1169
|
+
|
|
1121
1170
|
protected void enableTexturing(int target) {
|
|
1122
1171
|
if (target == TEXTURE_2D) {
|
|
1123
1172
|
texturingTargets[0] = true;
|
|
@@ -1126,6 +1175,7 @@ public abstract class PGL {
|
|
|
1126
1175
|
}
|
|
1127
1176
|
}
|
|
1128
1177
|
|
|
1178
|
+
|
|
1129
1179
|
protected void disableTexturing(int target) {
|
|
1130
1180
|
if (target == TEXTURE_2D) {
|
|
1131
1181
|
texturingTargets[0] = false;
|
|
@@ -1134,6 +1184,7 @@ public abstract class PGL {
|
|
|
1134
1184
|
}
|
|
1135
1185
|
}
|
|
1136
1186
|
|
|
1187
|
+
|
|
1137
1188
|
protected boolean texturingIsEnabled(int target) {
|
|
1138
1189
|
if (target == TEXTURE_2D) {
|
|
1139
1190
|
return texturingTargets[0];
|
|
@@ -1144,10 +1195,9 @@ public abstract class PGL {
|
|
|
1144
1195
|
}
|
|
1145
1196
|
}
|
|
1146
1197
|
|
|
1198
|
+
|
|
1147
1199
|
protected boolean textureIsBound(int target, int id) {
|
|
1148
|
-
if (boundTextures == null)
|
|
1149
|
-
return false;
|
|
1150
|
-
}
|
|
1200
|
+
if (boundTextures == null) return false;
|
|
1151
1201
|
|
|
1152
1202
|
if (target == TEXTURE_2D) {
|
|
1153
1203
|
return boundTextures[activeTexUnit][0] == id;
|
|
@@ -1158,12 +1208,14 @@ public abstract class PGL {
|
|
|
1158
1208
|
}
|
|
1159
1209
|
}
|
|
1160
1210
|
|
|
1211
|
+
|
|
1161
1212
|
protected void initTexture(int target, int format, int width, int height) {
|
|
1162
1213
|
initTexture(target, format, width, height, 0);
|
|
1163
1214
|
}
|
|
1164
1215
|
|
|
1216
|
+
|
|
1165
1217
|
protected void initTexture(int target, int format, int width, int height,
|
|
1166
|
-
|
|
1218
|
+
int initColor) {
|
|
1167
1219
|
int[] glcolor = new int[16 * 16];
|
|
1168
1220
|
Arrays.fill(glcolor, javaToNativeARGB(initColor));
|
|
1169
1221
|
IntBuffer texels = allocateDirectIntBuffer(16 * 16);
|
|
@@ -1178,14 +1230,15 @@ public abstract class PGL {
|
|
|
1178
1230
|
}
|
|
1179
1231
|
}
|
|
1180
1232
|
|
|
1233
|
+
|
|
1181
1234
|
protected void copyToTexture(int target, int format, int id, int x, int y,
|
|
1182
|
-
|
|
1235
|
+
int w, int h, int[] buffer) {
|
|
1183
1236
|
copyToTexture(target, format, id, x, y, w, h, IntBuffer.wrap(buffer));
|
|
1184
1237
|
|
|
1185
1238
|
}
|
|
1186
1239
|
|
|
1187
1240
|
protected void copyToTexture(int target, int format, int id, int x, int y,
|
|
1188
|
-
|
|
1241
|
+
int w, int h, IntBuffer buffer) {
|
|
1189
1242
|
activeTexture(TEXTURE0);
|
|
1190
1243
|
boolean enabledTex = false;
|
|
1191
1244
|
if (!texturingIsEnabled(target)) {
|
|
@@ -1200,50 +1253,54 @@ public abstract class PGL {
|
|
|
1200
1253
|
}
|
|
1201
1254
|
}
|
|
1202
1255
|
|
|
1256
|
+
|
|
1203
1257
|
/**
|
|
1204
1258
|
* Not an approved function, this will change or be removed in the future.
|
|
1205
1259
|
*/
|
|
1206
1260
|
public void drawTexture(int target, int id, int width, int height,
|
|
1207
|
-
|
|
1261
|
+
int X0, int Y0, int X1, int Y1) {
|
|
1208
1262
|
// If a texture is drawing on a viewport of the same size as its resolution,
|
|
1209
1263
|
// the pixel factor is 1:1, so we override the surface's pixel factor.
|
|
1210
1264
|
drawTexture(target, id, width, height,
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1265
|
+
0, 0, width, height, 1,
|
|
1266
|
+
X0, Y0, X1, Y1,
|
|
1267
|
+
X0, Y0, X1, Y1);
|
|
1214
1268
|
}
|
|
1215
1269
|
|
|
1270
|
+
|
|
1216
1271
|
/**
|
|
1217
1272
|
* Not an approved function, this will change or be removed in the future.
|
|
1218
1273
|
*/
|
|
1219
|
-
public void drawTexture(int target, int id,
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
int viewF = (int)
|
|
1274
|
+
public void drawTexture(int target, int id,int texW, int texH,
|
|
1275
|
+
int viewX, int viewY, int viewW, int viewH,
|
|
1276
|
+
int texX0, int texY0, int texX1, int texY1,
|
|
1277
|
+
int scrX0, int scrY0, int scrX1, int scrY1) {
|
|
1278
|
+
int viewF = (int)getPixelScale();
|
|
1224
1279
|
drawTexture(target, id, texW, texH,
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1280
|
+
viewX, viewY, viewW, viewH, viewF,
|
|
1281
|
+
texX0, texY0, texX1, texY1,
|
|
1282
|
+
scrX0, scrY0, scrX1, scrY1);
|
|
1228
1283
|
}
|
|
1229
1284
|
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1285
|
+
|
|
1286
|
+
public void drawTexture(int target, int id,int texW, int texH,
|
|
1287
|
+
int viewX, int viewY, int viewW, int viewH, int viewF,
|
|
1288
|
+
int texX0, int texY0, int texX1, int texY1,
|
|
1289
|
+
int scrX0, int scrY0, int scrX1, int scrY1) {
|
|
1234
1290
|
if (target == TEXTURE_2D) {
|
|
1235
1291
|
drawTexture2D(id, texW, texH,
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1292
|
+
viewX, viewY, viewW, viewH, viewF,
|
|
1293
|
+
texX0, texY0, texX1, texY1,
|
|
1294
|
+
scrX0, scrY0, scrX1, scrY1);
|
|
1239
1295
|
} else if (target == TEXTURE_RECTANGLE) {
|
|
1240
1296
|
drawTextureRect(id, texW, texH,
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1297
|
+
viewX, viewY, viewW, viewH, viewF,
|
|
1298
|
+
texX0, texY0, texX1, texY1,
|
|
1299
|
+
scrX0, scrY0, scrX1, scrY1);
|
|
1244
1300
|
}
|
|
1245
1301
|
}
|
|
1246
1302
|
|
|
1303
|
+
|
|
1247
1304
|
protected PGL initTex2DShader() {
|
|
1248
1305
|
PGL ppgl = primaryPGL ? this : graphics.getPrimaryPGL();
|
|
1249
1306
|
|
|
@@ -1278,10 +1335,11 @@ public abstract class PGL {
|
|
|
1278
1335
|
return ppgl;
|
|
1279
1336
|
}
|
|
1280
1337
|
|
|
1338
|
+
|
|
1281
1339
|
protected void drawTexture2D(int id, int texW, int texH,
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1340
|
+
int viewX, int viewY, int viewW, int viewH, int viewF,
|
|
1341
|
+
int texX0, int texY0, int texX1, int texY1,
|
|
1342
|
+
int scrX0, int scrY0, int scrX1, int scrY1) {
|
|
1285
1343
|
PGL ppgl = initTex2DShader();
|
|
1286
1344
|
|
|
1287
1345
|
if (0 < ppgl.tex2DShaderProgram) {
|
|
@@ -1309,25 +1367,25 @@ public abstract class PGL {
|
|
|
1309
1367
|
// Vertex coordinates of the textured quad are specified
|
|
1310
1368
|
// in normalized screen space (-1, 1):
|
|
1311
1369
|
// Corner 1
|
|
1312
|
-
texCoords[0] = 2 * (float)
|
|
1313
|
-
texCoords[1] = 2 * (float)
|
|
1314
|
-
texCoords[2] = (float)
|
|
1315
|
-
texCoords[3] = (float)
|
|
1370
|
+
texCoords[ 0] = 2 * (float)scrX0 / viewW - 1;
|
|
1371
|
+
texCoords[ 1] = 2 * (float)scrY0 / viewH - 1;
|
|
1372
|
+
texCoords[ 2] = (float)texX0 / texW;
|
|
1373
|
+
texCoords[ 3] = (float)texY0 / texH;
|
|
1316
1374
|
// Corner 2
|
|
1317
|
-
texCoords[4] = 2 * (float)
|
|
1318
|
-
texCoords[5] = 2 * (float)
|
|
1319
|
-
texCoords[6] = (float)
|
|
1320
|
-
texCoords[7] = (float)
|
|
1375
|
+
texCoords[ 4] = 2 * (float)scrX1 / viewW - 1;
|
|
1376
|
+
texCoords[ 5] = 2 * (float)scrY0 / viewH - 1;
|
|
1377
|
+
texCoords[ 6] = (float)texX1 / texW;
|
|
1378
|
+
texCoords[ 7] = (float)texY0 / texH;
|
|
1321
1379
|
// Corner 3
|
|
1322
|
-
texCoords[8] = 2 * (float)
|
|
1323
|
-
texCoords[9] = 2 * (float)
|
|
1324
|
-
texCoords[10] = (float)
|
|
1325
|
-
texCoords[11] = (float)
|
|
1380
|
+
texCoords[ 8] = 2 * (float)scrX0 / viewW - 1;
|
|
1381
|
+
texCoords[ 9] = 2 * (float)scrY1 / viewH - 1;
|
|
1382
|
+
texCoords[10] = (float)texX0 / texW;
|
|
1383
|
+
texCoords[11] = (float)texY1 / texH;
|
|
1326
1384
|
// Corner 4
|
|
1327
|
-
texCoords[12] = 2 * (float)
|
|
1328
|
-
texCoords[13] = 2 * (float)
|
|
1329
|
-
texCoords[14] = (float)
|
|
1330
|
-
texCoords[15] = (float)
|
|
1385
|
+
texCoords[12] = 2 * (float)scrX1 / viewW - 1;
|
|
1386
|
+
texCoords[13] = 2 * (float)scrY1 / viewH - 1;
|
|
1387
|
+
texCoords[14] = (float)texX1 / texW;
|
|
1388
|
+
texCoords[15] = (float)texY1 / texH;
|
|
1331
1389
|
|
|
1332
1390
|
texData.rewind();
|
|
1333
1391
|
texData.put(texCoords);
|
|
@@ -1370,10 +1428,11 @@ public abstract class PGL {
|
|
|
1370
1428
|
depthMask(depthMask);
|
|
1371
1429
|
|
|
1372
1430
|
viewportImpl(viewBuffer.get(0), viewBuffer.get(1),
|
|
1373
|
-
|
|
1431
|
+
viewBuffer.get(2), viewBuffer.get(3));
|
|
1374
1432
|
}
|
|
1375
1433
|
}
|
|
1376
1434
|
|
|
1435
|
+
|
|
1377
1436
|
protected PGL initTexRectShader() {
|
|
1378
1437
|
PGL ppgl = primaryPGL ? this : graphics.getPrimaryPGL();
|
|
1379
1438
|
|
|
@@ -1386,7 +1445,7 @@ public abstract class PGL {
|
|
|
1386
1445
|
ppgl.texRectFragShader = createShader(FRAGMENT_SHADER, fragSource);
|
|
1387
1446
|
if (0 < ppgl.texRectVertShader && 0 < ppgl.texRectFragShader) {
|
|
1388
1447
|
ppgl.texRectShaderProgram = createProgram(ppgl.texRectVertShader,
|
|
1389
|
-
|
|
1448
|
+
ppgl.texRectFragShader);
|
|
1390
1449
|
}
|
|
1391
1450
|
if (0 < ppgl.texRectShaderProgram) {
|
|
1392
1451
|
ppgl.texRectVertLoc = getAttribLocation(ppgl.texRectShaderProgram, "position");
|
|
@@ -1405,10 +1464,11 @@ public abstract class PGL {
|
|
|
1405
1464
|
return ppgl;
|
|
1406
1465
|
}
|
|
1407
1466
|
|
|
1467
|
+
|
|
1408
1468
|
protected void drawTextureRect(int id, int texW, int texH,
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1469
|
+
int viewX, int viewY, int viewW, int viewH, int viewF,
|
|
1470
|
+
int texX0, int texY0, int texX1, int texY1,
|
|
1471
|
+
int scrX0, int scrY0, int scrX1, int scrY1) {
|
|
1412
1472
|
PGL ppgl = initTexRectShader();
|
|
1413
1473
|
|
|
1414
1474
|
if (texData == null) {
|
|
@@ -1440,23 +1500,23 @@ public abstract class PGL {
|
|
|
1440
1500
|
// Vertex coordinates of the textured quad are specified
|
|
1441
1501
|
// in normalized screen space (-1, 1):
|
|
1442
1502
|
// Corner 1
|
|
1443
|
-
texCoords[0] = 2 * (float)
|
|
1444
|
-
texCoords[1] = 2 * (float)
|
|
1445
|
-
texCoords[2] = texX0;
|
|
1446
|
-
texCoords[3] = texY0;
|
|
1503
|
+
texCoords[ 0] = 2 * (float)scrX0 / viewW - 1;
|
|
1504
|
+
texCoords[ 1] = 2 * (float)scrY0 / viewH - 1;
|
|
1505
|
+
texCoords[ 2] = texX0;
|
|
1506
|
+
texCoords[ 3] = texY0;
|
|
1447
1507
|
// Corner 2
|
|
1448
|
-
texCoords[4] = 2 * (float)
|
|
1449
|
-
texCoords[5] = 2 * (float)
|
|
1450
|
-
texCoords[6] = texX1;
|
|
1451
|
-
texCoords[7] = texY0;
|
|
1508
|
+
texCoords[ 4] = 2 * (float)scrX1 / viewW - 1;
|
|
1509
|
+
texCoords[ 5] = 2 * (float)scrY0 / viewH - 1;
|
|
1510
|
+
texCoords[ 6] = texX1;
|
|
1511
|
+
texCoords[ 7] = texY0;
|
|
1452
1512
|
// Corner 3
|
|
1453
|
-
texCoords[8] = 2 * (float)
|
|
1454
|
-
texCoords[9] = 2 * (float)
|
|
1513
|
+
texCoords[ 8] = 2 * (float)scrX0 / viewW - 1;
|
|
1514
|
+
texCoords[ 9] = 2 * (float)scrY1 / viewH - 1;
|
|
1455
1515
|
texCoords[10] = texX0;
|
|
1456
1516
|
texCoords[11] = texY1;
|
|
1457
1517
|
// Corner 4
|
|
1458
|
-
texCoords[12] = 2 * (float)
|
|
1459
|
-
texCoords[13] = 2 * (float)
|
|
1518
|
+
texCoords[12] = 2 * (float)scrX1 / viewW - 1;
|
|
1519
|
+
texCoords[13] = 2 * (float)scrY1 / viewH - 1;
|
|
1460
1520
|
texCoords[14] = texX1;
|
|
1461
1521
|
texCoords[15] = texY1;
|
|
1462
1522
|
|
|
@@ -1501,59 +1561,60 @@ public abstract class PGL {
|
|
|
1501
1561
|
depthMask(depthMask);
|
|
1502
1562
|
|
|
1503
1563
|
viewportImpl(viewBuffer.get(0), viewBuffer.get(1),
|
|
1504
|
-
|
|
1564
|
+
viewBuffer.get(2), viewBuffer.get(3));
|
|
1505
1565
|
}
|
|
1506
1566
|
}
|
|
1507
1567
|
|
|
1568
|
+
|
|
1508
1569
|
protected int getColorValue(int scrX, int scrY) {
|
|
1509
1570
|
if (colorBuffer == null) {
|
|
1510
1571
|
colorBuffer = IntBuffer.allocate(1);
|
|
1511
1572
|
}
|
|
1512
1573
|
colorBuffer.rewind();
|
|
1513
1574
|
readPixels(scrX, graphics.height - scrY - 1, 1, 1, RGBA, UNSIGNED_BYTE,
|
|
1514
|
-
|
|
1575
|
+
colorBuffer);
|
|
1515
1576
|
return colorBuffer.get();
|
|
1516
1577
|
}
|
|
1517
1578
|
|
|
1579
|
+
|
|
1518
1580
|
protected float getDepthValue(int scrX, int scrY) {
|
|
1519
1581
|
if (depthBuffer == null) {
|
|
1520
1582
|
depthBuffer = FloatBuffer.allocate(1);
|
|
1521
1583
|
}
|
|
1522
1584
|
depthBuffer.rewind();
|
|
1523
1585
|
readPixels(scrX, graphics.height - scrY - 1, 1, 1, DEPTH_COMPONENT, FLOAT,
|
|
1524
|
-
|
|
1586
|
+
depthBuffer);
|
|
1525
1587
|
return depthBuffer.get(0);
|
|
1526
1588
|
}
|
|
1527
1589
|
|
|
1590
|
+
|
|
1528
1591
|
protected byte getStencilValue(int scrX, int scrY) {
|
|
1529
1592
|
if (stencilBuffer == null) {
|
|
1530
1593
|
stencilBuffer = ByteBuffer.allocate(1);
|
|
1531
1594
|
}
|
|
1532
1595
|
stencilBuffer.rewind();
|
|
1533
1596
|
readPixels(scrX, graphics.height - scrY - 1, 1, 1, STENCIL_INDEX,
|
|
1534
|
-
|
|
1597
|
+
UNSIGNED_BYTE, stencilBuffer);
|
|
1535
1598
|
return stencilBuffer.get(0);
|
|
1536
1599
|
}
|
|
1537
1600
|
|
|
1601
|
+
|
|
1538
1602
|
protected static boolean isPowerOfTwo(int val) {
|
|
1539
1603
|
return (val & (val - 1)) == 0;
|
|
1540
1604
|
}
|
|
1541
1605
|
|
|
1606
|
+
|
|
1542
1607
|
// bit shifting this might be more efficient
|
|
1543
1608
|
protected static int nextPowerOfTwo(int val) {
|
|
1544
1609
|
int ret = 1;
|
|
1545
|
-
while (ret < val)
|
|
1546
|
-
ret <<= 1;
|
|
1547
|
-
}
|
|
1610
|
+
while (ret < val) ret <<= 1;
|
|
1548
1611
|
return ret;
|
|
1549
1612
|
}
|
|
1550
1613
|
|
|
1614
|
+
|
|
1551
1615
|
/**
|
|
1552
1616
|
* Converts input native OpenGL value (RGBA on big endian, ABGR on little
|
|
1553
1617
|
* endian) to Java ARGB.
|
|
1554
|
-
*
|
|
1555
|
-
* @param color
|
|
1556
|
-
* @return
|
|
1557
1618
|
*/
|
|
1558
1619
|
protected static int nativeToJavaARGB(int color) {
|
|
1559
1620
|
if (BIG_ENDIAN) { // RGBA to ARGB
|
|
@@ -1564,15 +1625,12 @@ public abstract class PGL {
|
|
|
1564
1625
|
}
|
|
1565
1626
|
}
|
|
1566
1627
|
|
|
1628
|
+
|
|
1567
1629
|
/**
|
|
1568
1630
|
* Converts input array of native OpenGL values (RGBA on big endian, ABGR on
|
|
1569
1631
|
* little endian) representing an image of width x height resolution to Java
|
|
1570
|
-
* ARGB.It also rearranges the elements in the array so that the image is
|
|
1632
|
+
* ARGB. It also rearranges the elements in the array so that the image is
|
|
1571
1633
|
* flipped vertically.
|
|
1572
|
-
*
|
|
1573
|
-
* @param pixels
|
|
1574
|
-
* @param width
|
|
1575
|
-
* @param height
|
|
1576
1634
|
*/
|
|
1577
1635
|
protected static void nativeToJavaARGB(int[] pixels, int width, int height) {
|
|
1578
1636
|
int index = 0;
|
|
@@ -1611,34 +1669,29 @@ public abstract class PGL {
|
|
|
1611
1669
|
}
|
|
1612
1670
|
}
|
|
1613
1671
|
|
|
1672
|
+
|
|
1614
1673
|
/**
|
|
1615
1674
|
* Converts input native OpenGL value (RGBA on big endian, ABGR on little
|
|
1616
|
-
* endian) to Java RGB, so that the alpha component of the result is set
|
|
1617
|
-
* opaque (255).
|
|
1618
|
-
*
|
|
1619
|
-
* @param color
|
|
1620
|
-
* @return
|
|
1675
|
+
* endian) to Java RGB, so that the alpha component of the result is set
|
|
1676
|
+
* to opaque (255).
|
|
1621
1677
|
*/
|
|
1622
1678
|
protected static int nativeToJavaRGB(int color) {
|
|
1623
1679
|
if (BIG_ENDIAN) { // RGBA to ARGB
|
|
1624
1680
|
return (color >>> 8) | 0xFF000000;
|
|
1625
1681
|
} else { // ABGR to ARGB
|
|
1626
1682
|
int rb = color & 0x00FF00FF;
|
|
1627
|
-
return 0xFF000000 | (rb << 16)
|
|
1628
|
-
|
|
1683
|
+
return 0xFF000000 | (rb << 16) |
|
|
1684
|
+
(color & 0x0000FF00) | (rb >> 16);
|
|
1629
1685
|
}
|
|
1630
1686
|
}
|
|
1631
1687
|
|
|
1688
|
+
|
|
1632
1689
|
/**
|
|
1633
1690
|
* Converts input array of native OpenGL values (RGBA on big endian, ABGR on
|
|
1634
1691
|
* little endian) representing an image of width x height resolution to Java
|
|
1635
|
-
* RGB, so that the alpha component of all pixels is set to opaque (255).It
|
|
1692
|
+
* RGB, so that the alpha component of all pixels is set to opaque (255). It
|
|
1636
1693
|
* also rearranges the elements in the array so that the image is flipped
|
|
1637
1694
|
* vertically.
|
|
1638
|
-
*
|
|
1639
|
-
* @param pixels
|
|
1640
|
-
* @param width
|
|
1641
|
-
* @param height
|
|
1642
1695
|
*/
|
|
1643
1696
|
protected static void nativeToJavaRGB(int[] pixels, int width, int height) {
|
|
1644
1697
|
int index = 0;
|
|
@@ -1653,10 +1706,10 @@ public abstract class PGL {
|
|
|
1653
1706
|
} else { // ABGR to ARGB
|
|
1654
1707
|
int rbi = pixi & 0x00FF00FF;
|
|
1655
1708
|
int rby = pixy & 0x00FF00FF;
|
|
1656
|
-
pixels[index] = 0xFF000000 | (rby << 16)
|
|
1657
|
-
|
|
1658
|
-
pixels[yindex] = 0xFF000000 | (rbi << 16)
|
|
1659
|
-
|
|
1709
|
+
pixels[index] = 0xFF000000 | (rby << 16) |
|
|
1710
|
+
(pixy & 0x0000FF00) | (rby >> 16);
|
|
1711
|
+
pixels[yindex] = 0xFF000000 | (rbi << 16) |
|
|
1712
|
+
(pixi & 0x0000FF00) | (rbi >> 16);
|
|
1660
1713
|
}
|
|
1661
1714
|
index++;
|
|
1662
1715
|
yindex++;
|
|
@@ -1672,20 +1725,18 @@ public abstract class PGL {
|
|
|
1672
1725
|
pixels[index] = (pixi >>> 8) | 0xFF000000;
|
|
1673
1726
|
} else { // ABGR to ARGB
|
|
1674
1727
|
int rbi = pixi & 0x00FF00FF;
|
|
1675
|
-
pixels[index] = 0xFF000000 | (rbi << 16)
|
|
1676
|
-
|
|
1728
|
+
pixels[index] = 0xFF000000 | (rbi << 16) |
|
|
1729
|
+
(pixi & 0x000FF00) | (rbi >> 16);
|
|
1677
1730
|
}
|
|
1678
1731
|
index++;
|
|
1679
1732
|
}
|
|
1680
1733
|
}
|
|
1681
1734
|
}
|
|
1682
1735
|
|
|
1736
|
+
|
|
1683
1737
|
/**
|
|
1684
1738
|
* Converts input Java ARGB value to native OpenGL format (RGBA on big endian,
|
|
1685
1739
|
* BGRA on little endian).
|
|
1686
|
-
*
|
|
1687
|
-
* @param color
|
|
1688
|
-
* @return
|
|
1689
1740
|
*/
|
|
1690
1741
|
protected static int javaToNativeARGB(int color) {
|
|
1691
1742
|
if (BIG_ENDIAN) { // ARGB to RGBA
|
|
@@ -1696,15 +1747,12 @@ public abstract class PGL {
|
|
|
1696
1747
|
}
|
|
1697
1748
|
}
|
|
1698
1749
|
|
|
1750
|
+
|
|
1699
1751
|
/**
|
|
1700
1752
|
* Converts input array of Java ARGB values representing an image of width x
|
|
1701
1753
|
* height resolution to native OpenGL format (RGBA on big endian, BGRA on
|
|
1702
|
-
* little endian).It also rearranges the elements in the array so that the
|
|
1754
|
+
* little endian). It also rearranges the elements in the array so that the
|
|
1703
1755
|
* image is flipped vertically.
|
|
1704
|
-
*
|
|
1705
|
-
* @param pixels
|
|
1706
|
-
* @param width
|
|
1707
|
-
* @param height
|
|
1708
1756
|
*/
|
|
1709
1757
|
protected static void javaToNativeARGB(int[] pixels, int width, int height) {
|
|
1710
1758
|
int index = 0;
|
|
@@ -1743,12 +1791,10 @@ public abstract class PGL {
|
|
|
1743
1791
|
}
|
|
1744
1792
|
}
|
|
1745
1793
|
|
|
1794
|
+
|
|
1746
1795
|
/**
|
|
1747
1796
|
* Converts input Java ARGB value to native OpenGL format (RGBA on big endian,
|
|
1748
1797
|
* BGRA on little endian), setting alpha component to opaque (255).
|
|
1749
|
-
*
|
|
1750
|
-
* @param color
|
|
1751
|
-
* @return
|
|
1752
1798
|
*/
|
|
1753
1799
|
protected static int javaToNativeRGB(int color) {
|
|
1754
1800
|
if (BIG_ENDIAN) { // ARGB to RGB
|
|
@@ -1759,16 +1805,13 @@ public abstract class PGL {
|
|
|
1759
1805
|
}
|
|
1760
1806
|
}
|
|
1761
1807
|
|
|
1808
|
+
|
|
1762
1809
|
/**
|
|
1763
1810
|
* Converts input array of Java ARGB values representing an image of width x
|
|
1764
1811
|
* height resolution to native OpenGL format (RGBA on big endian, BGRA on
|
|
1765
1812
|
* little endian), while setting alpha component of all pixels to opaque
|
|
1766
|
-
* (255).It also rearranges the elements in the array so that the image is
|
|
1813
|
+
* (255). It also rearranges the elements in the array so that the image is
|
|
1767
1814
|
* flipped vertically.
|
|
1768
|
-
*
|
|
1769
|
-
* @param pixels
|
|
1770
|
-
* @param width
|
|
1771
|
-
* @param height
|
|
1772
1815
|
*/
|
|
1773
1816
|
protected static void javaToNativeRGB(int[] pixels, int width, int height) {
|
|
1774
1817
|
int index = 0;
|
|
@@ -1783,10 +1826,10 @@ public abstract class PGL {
|
|
|
1783
1826
|
} else { // ARGB to BGR
|
|
1784
1827
|
int rbi = pixi & 0x00FF00FF;
|
|
1785
1828
|
int rby = pixy & 0x00FF00FF;
|
|
1786
|
-
pixels[index] = 0xFF000000 | (rby << 16)
|
|
1787
|
-
|
|
1788
|
-
pixels[yindex] = 0xFF000000 | (rbi << 16)
|
|
1789
|
-
|
|
1829
|
+
pixels[index] = 0xFF000000 | (rby << 16) |
|
|
1830
|
+
(pixy & 0x0000FF00) | (rby >> 16);
|
|
1831
|
+
pixels[yindex] = 0xFF000000 | (rbi << 16) |
|
|
1832
|
+
(pixi & 0x0000FF00) | (rbi >> 16);
|
|
1790
1833
|
}
|
|
1791
1834
|
index++;
|
|
1792
1835
|
yindex++;
|
|
@@ -1802,14 +1845,15 @@ public abstract class PGL {
|
|
|
1802
1845
|
pixels[index] = 0xFF | (pixi << 8);
|
|
1803
1846
|
} else { // ARGB to BGR
|
|
1804
1847
|
int rbi = pixi & 0x00FF00FF;
|
|
1805
|
-
pixels[index] = 0xFF000000 | (rbi << 16)
|
|
1806
|
-
|
|
1848
|
+
pixels[index] = 0xFF000000 | (rbi << 16) |
|
|
1849
|
+
(pixi & 0x0000FF00) | (rbi >> 16);
|
|
1807
1850
|
}
|
|
1808
1851
|
index++;
|
|
1809
1852
|
}
|
|
1810
1853
|
}
|
|
1811
1854
|
}
|
|
1812
1855
|
|
|
1856
|
+
|
|
1813
1857
|
protected static int qualityToSamples(int quality) {
|
|
1814
1858
|
if (quality <= 1) {
|
|
1815
1859
|
return 1;
|
|
@@ -1820,18 +1864,21 @@ public abstract class PGL {
|
|
|
1820
1864
|
}
|
|
1821
1865
|
}
|
|
1822
1866
|
|
|
1823
|
-
abstract protected int getGLSLVersion();
|
|
1824
1867
|
|
|
1868
|
+
abstract protected int getGLSLVersion();
|
|
1825
1869
|
abstract protected String getGLSLVersionSuffix();
|
|
1826
1870
|
|
|
1871
|
+
|
|
1827
1872
|
protected String[] loadVertexShader(String filename) {
|
|
1828
1873
|
return sketch.loadStrings(filename);
|
|
1829
1874
|
}
|
|
1830
1875
|
|
|
1876
|
+
|
|
1831
1877
|
protected String[] loadFragmentShader(String filename) {
|
|
1832
1878
|
return sketch.loadStrings(filename);
|
|
1833
1879
|
}
|
|
1834
1880
|
|
|
1881
|
+
|
|
1835
1882
|
protected String[] loadFragmentShader(URL url) {
|
|
1836
1883
|
try {
|
|
1837
1884
|
return PApplet.loadStrings(url.openStream());
|
|
@@ -1841,6 +1888,7 @@ public abstract class PGL {
|
|
|
1841
1888
|
return null;
|
|
1842
1889
|
}
|
|
1843
1890
|
|
|
1891
|
+
|
|
1844
1892
|
protected String[] loadVertexShader(URL url) {
|
|
1845
1893
|
try {
|
|
1846
1894
|
return PApplet.loadStrings(url.openStream());
|
|
@@ -1850,25 +1898,30 @@ public abstract class PGL {
|
|
|
1850
1898
|
return null;
|
|
1851
1899
|
}
|
|
1852
1900
|
|
|
1901
|
+
|
|
1853
1902
|
protected String[] loadVertexShader(String filename, int version, String versionSuffix) {
|
|
1854
1903
|
return loadVertexShader(filename);
|
|
1855
1904
|
}
|
|
1856
1905
|
|
|
1906
|
+
|
|
1857
1907
|
protected String[] loadFragmentShader(String filename, int version, String versionSuffix) {
|
|
1858
1908
|
return loadFragmentShader(filename);
|
|
1859
1909
|
}
|
|
1860
1910
|
|
|
1911
|
+
|
|
1861
1912
|
protected String[] loadFragmentShader(URL url, int version, String versionSuffix) {
|
|
1862
1913
|
return loadFragmentShader(url);
|
|
1863
1914
|
}
|
|
1864
1915
|
|
|
1916
|
+
|
|
1865
1917
|
protected String[] loadVertexShader(URL url, int version, String versionSuffix) {
|
|
1866
1918
|
return loadVertexShader(url);
|
|
1867
1919
|
}
|
|
1868
1920
|
|
|
1921
|
+
|
|
1869
1922
|
protected static String[] preprocessFragmentSource(String[] fragSrc0,
|
|
1870
|
-
|
|
1871
|
-
|
|
1923
|
+
int version,
|
|
1924
|
+
String versionSuffix) {
|
|
1872
1925
|
if (containsVersionDirective(fragSrc0)) {
|
|
1873
1926
|
// The user knows what she or he is doing
|
|
1874
1927
|
return fragSrc0;
|
|
@@ -1877,8 +1930,8 @@ public abstract class PGL {
|
|
|
1877
1930
|
String[] fragSrc;
|
|
1878
1931
|
|
|
1879
1932
|
if (version < 130) {
|
|
1880
|
-
Pattern[] search = {};
|
|
1881
|
-
String[] replace = {};
|
|
1933
|
+
Pattern[] search = { };
|
|
1934
|
+
String[] replace = { };
|
|
1882
1935
|
int offset = 1;
|
|
1883
1936
|
|
|
1884
1937
|
fragSrc = preprocessShaderSource(fragSrc0, search, replace, offset);
|
|
@@ -1887,14 +1940,14 @@ public abstract class PGL {
|
|
|
1887
1940
|
// We need to replace 'texture' uniform by 'texMap' uniform and
|
|
1888
1941
|
// 'textureXXX()' functions by 'texture()' functions. Order of these
|
|
1889
1942
|
// replacements is important to prevent collisions between these two.
|
|
1890
|
-
Pattern[] search = new Pattern[]{
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1943
|
+
Pattern[] search = new Pattern[] {
|
|
1944
|
+
Pattern.compile(String.format(GLSL_ID_REGEX, "varying|attribute")),
|
|
1945
|
+
Pattern.compile(String.format(GLSL_ID_REGEX, "texture")),
|
|
1946
|
+
Pattern.compile(String.format(GLSL_FN_REGEX, "texture2DRect|texture2D|texture3D|textureCube")),
|
|
1947
|
+
Pattern.compile(String.format(GLSL_ID_REGEX, "gl_FragColor"))
|
|
1895
1948
|
};
|
|
1896
|
-
String[] replace = new String[]{
|
|
1897
|
-
|
|
1949
|
+
String[] replace = new String[] {
|
|
1950
|
+
"in", "texMap", "texture", "_fragColor"
|
|
1898
1951
|
};
|
|
1899
1952
|
int offset = 2;
|
|
1900
1953
|
|
|
@@ -1911,8 +1964,8 @@ public abstract class PGL {
|
|
|
1911
1964
|
}
|
|
1912
1965
|
|
|
1913
1966
|
protected static String[] preprocessVertexSource(String[] vertSrc0,
|
|
1914
|
-
|
|
1915
|
-
|
|
1967
|
+
int version,
|
|
1968
|
+
String versionSuffix) {
|
|
1916
1969
|
if (containsVersionDirective(vertSrc0)) {
|
|
1917
1970
|
// The user knows what she or he is doing
|
|
1918
1971
|
return vertSrc0;
|
|
@@ -1921,8 +1974,8 @@ public abstract class PGL {
|
|
|
1921
1974
|
String[] vertSrc;
|
|
1922
1975
|
|
|
1923
1976
|
if (version < 130) {
|
|
1924
|
-
Pattern[] search = {};
|
|
1925
|
-
String[] replace = {};
|
|
1977
|
+
Pattern[] search = { };
|
|
1978
|
+
String[] replace = { };
|
|
1926
1979
|
int offset = 1;
|
|
1927
1980
|
|
|
1928
1981
|
vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
|
|
@@ -1931,14 +1984,15 @@ public abstract class PGL {
|
|
|
1931
1984
|
// We need to replace 'texture' uniform by 'texMap' uniform and
|
|
1932
1985
|
// 'textureXXX()' functions by 'texture()' functions. Order of these
|
|
1933
1986
|
// replacements is important to prevent collisions between these two.
|
|
1934
|
-
Pattern[] search = new Pattern[]{
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1987
|
+
Pattern[] search = new Pattern[] {
|
|
1988
|
+
Pattern.compile(String.format(GLSL_ID_REGEX, "varying")),
|
|
1989
|
+
Pattern.compile(String.format(GLSL_ID_REGEX, "attribute")),
|
|
1990
|
+
Pattern.compile(String.format(GLSL_ID_REGEX, "texture")),
|
|
1991
|
+
Pattern.compile(String.format(GLSL_FN_REGEX, "texture2DRect|texture2D|texture3D|textureCube"))
|
|
1992
|
+
};
|
|
1993
|
+
String[] replace = new String[] {
|
|
1994
|
+
"out", "in", "texMap", "texture",
|
|
1939
1995
|
};
|
|
1940
|
-
String[] replace = new String[]{
|
|
1941
|
-
"out", "in", "texMap", "texture",};
|
|
1942
1996
|
int offset = 1;
|
|
1943
1997
|
|
|
1944
1998
|
vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
|
|
@@ -1948,14 +2002,16 @@ public abstract class PGL {
|
|
|
1948
2002
|
return vertSrc;
|
|
1949
2003
|
}
|
|
1950
2004
|
|
|
2005
|
+
|
|
1951
2006
|
protected static final String GLSL_ID_REGEX = "(?<![0-9A-Z_a-z])(%s)(?![0-9A-Z_a-z]|\\s*\\()";
|
|
1952
2007
|
protected static final String GLSL_FN_REGEX = "(?<![0-9A-Z_a-z])(%s)(?=\\s*\\()";
|
|
1953
2008
|
|
|
2009
|
+
|
|
1954
2010
|
protected static String[] preprocessShaderSource(String[] src0,
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
String[] src = new String[src0.length
|
|
2011
|
+
Pattern[] search,
|
|
2012
|
+
String[] replace,
|
|
2013
|
+
int offset) {
|
|
2014
|
+
String[] src = new String[src0.length+offset];
|
|
1959
2015
|
for (int i = 0; i < src0.length; i++) {
|
|
1960
2016
|
String line = src0[i];
|
|
1961
2017
|
int versionIndex = line.indexOf("#version");
|
|
@@ -1965,7 +2021,7 @@ public abstract class PGL {
|
|
|
1965
2021
|
for (int j = 0; j < search.length; j++) {
|
|
1966
2022
|
line = search[j].matcher(line).replaceAll(replace[j]);
|
|
1967
2023
|
}
|
|
1968
|
-
src[i
|
|
2024
|
+
src[i+offset] = line;
|
|
1969
2025
|
}
|
|
1970
2026
|
return src;
|
|
1971
2027
|
}
|
|
@@ -1998,6 +2054,7 @@ public abstract class PGL {
|
|
|
1998
2054
|
return shader;
|
|
1999
2055
|
}
|
|
2000
2056
|
|
|
2057
|
+
|
|
2001
2058
|
protected int createProgram(int vertexShader, int fragmentShader) {
|
|
2002
2059
|
int program = createProgram();
|
|
2003
2060
|
if (program != 0) {
|
|
@@ -2014,55 +2071,58 @@ public abstract class PGL {
|
|
|
2014
2071
|
return program;
|
|
2015
2072
|
}
|
|
2016
2073
|
|
|
2074
|
+
|
|
2017
2075
|
protected boolean compiled(int shader) {
|
|
2018
2076
|
intBuffer.rewind();
|
|
2019
2077
|
getShaderiv(shader, COMPILE_STATUS, intBuffer);
|
|
2020
2078
|
return intBuffer.get(0) != 0;
|
|
2021
2079
|
}
|
|
2022
2080
|
|
|
2081
|
+
|
|
2023
2082
|
protected boolean linked(int program) {
|
|
2024
2083
|
intBuffer.rewind();
|
|
2025
2084
|
getProgramiv(program, LINK_STATUS, intBuffer);
|
|
2026
2085
|
return intBuffer.get(0) != 0;
|
|
2027
2086
|
}
|
|
2028
2087
|
|
|
2088
|
+
|
|
2029
2089
|
protected int validateFramebuffer() {
|
|
2030
2090
|
int status = checkFramebufferStatus(FRAMEBUFFER);
|
|
2031
2091
|
if (status == FRAMEBUFFER_COMPLETE) {
|
|
2032
2092
|
return 0;
|
|
2033
2093
|
} else if (status == FRAMEBUFFER_UNDEFINED) {
|
|
2034
2094
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2035
|
-
|
|
2095
|
+
"framebuffer undefined"));
|
|
2036
2096
|
} else if (status == FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
|
|
2037
2097
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2038
|
-
|
|
2098
|
+
"incomplete attachment"));
|
|
2039
2099
|
} else if (status == FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
|
|
2040
2100
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2041
|
-
|
|
2101
|
+
"incomplete missing attachment"));
|
|
2042
2102
|
} else if (status == FRAMEBUFFER_INCOMPLETE_DIMENSIONS) {
|
|
2043
2103
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2044
|
-
|
|
2104
|
+
"incomplete dimensions"));
|
|
2045
2105
|
} else if (status == FRAMEBUFFER_INCOMPLETE_FORMATS) {
|
|
2046
2106
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2047
|
-
|
|
2107
|
+
"incomplete formats"));
|
|
2048
2108
|
} else if (status == FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
|
|
2049
2109
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2050
|
-
|
|
2110
|
+
"incomplete draw buffer"));
|
|
2051
2111
|
} else if (status == FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
|
|
2052
2112
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2053
|
-
|
|
2113
|
+
"incomplete read buffer"));
|
|
2054
2114
|
} else if (status == FRAMEBUFFER_UNSUPPORTED) {
|
|
2055
2115
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2056
|
-
|
|
2116
|
+
"framebuffer unsupported"));
|
|
2057
2117
|
} else if (status == FRAMEBUFFER_INCOMPLETE_MULTISAMPLE) {
|
|
2058
2118
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2059
|
-
|
|
2119
|
+
"incomplete multisample buffer"));
|
|
2060
2120
|
} else if (status == FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS) {
|
|
2061
2121
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2062
|
-
|
|
2122
|
+
"incomplete layer targets"));
|
|
2063
2123
|
} else {
|
|
2064
2124
|
System.err.println(String.format(FRAMEBUFFER_ERROR,
|
|
2065
|
-
|
|
2125
|
+
"unknown error " + status));
|
|
2066
2126
|
}
|
|
2067
2127
|
return status;
|
|
2068
2128
|
}
|
|
@@ -2087,19 +2147,16 @@ public abstract class PGL {
|
|
|
2087
2147
|
String[] nums = part.split("\\.");
|
|
2088
2148
|
try {
|
|
2089
2149
|
res[0] = Integer.parseInt(nums[0]);
|
|
2090
|
-
} catch (NumberFormatException e) {
|
|
2091
|
-
}
|
|
2150
|
+
} catch (NumberFormatException e) { }
|
|
2092
2151
|
if (1 < nums.length) {
|
|
2093
2152
|
try {
|
|
2094
2153
|
res[1] = Integer.parseInt(nums[1]);
|
|
2095
|
-
} catch (NumberFormatException e) {
|
|
2096
|
-
}
|
|
2154
|
+
} catch (NumberFormatException e) { }
|
|
2097
2155
|
}
|
|
2098
2156
|
if (2 < nums.length) {
|
|
2099
2157
|
try {
|
|
2100
2158
|
res[2] = Integer.parseInt(nums[2]);
|
|
2101
|
-
} catch (NumberFormatException e) {
|
|
2102
|
-
}
|
|
2159
|
+
} catch (NumberFormatException e) { }
|
|
2103
2160
|
}
|
|
2104
2161
|
break;
|
|
2105
2162
|
}
|
|
@@ -2107,20 +2164,22 @@ public abstract class PGL {
|
|
|
2107
2164
|
return res;
|
|
2108
2165
|
}
|
|
2109
2166
|
|
|
2167
|
+
|
|
2110
2168
|
protected boolean hasFBOs() {
|
|
2111
2169
|
// FBOs might still be available through extensions.
|
|
2112
2170
|
int major = getGLVersion()[0];
|
|
2113
2171
|
if (major < 2) {
|
|
2114
2172
|
String ext = getString(EXTENSIONS);
|
|
2115
|
-
return ext.contains("_framebuffer_object")
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2173
|
+
return ext.contains("_framebuffer_object") &&
|
|
2174
|
+
ext.contains("_vertex_shader") &&
|
|
2175
|
+
ext.contains("_shader_objects") &&
|
|
2176
|
+
ext.contains("_shading_language");
|
|
2119
2177
|
} else {
|
|
2120
2178
|
return true;
|
|
2121
2179
|
}
|
|
2122
2180
|
}
|
|
2123
2181
|
|
|
2182
|
+
|
|
2124
2183
|
protected boolean hasShaders() {
|
|
2125
2184
|
// GLSL might still be available through extensions. For instance,
|
|
2126
2185
|
// GLContext.hasGLSL() gives false for older intel integrated chipsets on
|
|
@@ -2128,15 +2187,16 @@ public abstract class PGL {
|
|
|
2128
2187
|
int major = getGLVersion()[0];
|
|
2129
2188
|
if (major < 2) {
|
|
2130
2189
|
String ext = getString(EXTENSIONS);
|
|
2131
|
-
return ext.contains("_fragment_shader")
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2190
|
+
return ext.contains("_fragment_shader") &&
|
|
2191
|
+
ext.contains("_vertex_shader") &&
|
|
2192
|
+
ext.contains("_shader_objects") &&
|
|
2193
|
+
ext.contains("_shading_language");
|
|
2135
2194
|
} else {
|
|
2136
2195
|
return true;
|
|
2137
2196
|
}
|
|
2138
2197
|
}
|
|
2139
2198
|
|
|
2199
|
+
|
|
2140
2200
|
protected boolean hasNpotTexSupport() {
|
|
2141
2201
|
int major = getGLVersion()[0];
|
|
2142
2202
|
if (major < 3) {
|
|
@@ -2151,6 +2211,7 @@ public abstract class PGL {
|
|
|
2151
2211
|
}
|
|
2152
2212
|
}
|
|
2153
2213
|
|
|
2214
|
+
|
|
2154
2215
|
protected boolean hasAutoMipmapGenSupport() {
|
|
2155
2216
|
int major = getGLVersion()[0];
|
|
2156
2217
|
if (isES() && major >= 2) {
|
|
@@ -2163,6 +2224,7 @@ public abstract class PGL {
|
|
|
2163
2224
|
}
|
|
2164
2225
|
}
|
|
2165
2226
|
|
|
2227
|
+
|
|
2166
2228
|
protected boolean hasFboMultisampleSupport() {
|
|
2167
2229
|
int major = getGLVersion()[0];
|
|
2168
2230
|
if (major < 3) {
|
|
@@ -2173,6 +2235,7 @@ public abstract class PGL {
|
|
|
2173
2235
|
}
|
|
2174
2236
|
}
|
|
2175
2237
|
|
|
2238
|
+
|
|
2176
2239
|
protected boolean hasPackedDepthStencilSupport() {
|
|
2177
2240
|
int major = getGLVersion()[0];
|
|
2178
2241
|
if (major < 3) {
|
|
@@ -2183,6 +2246,7 @@ public abstract class PGL {
|
|
|
2183
2246
|
}
|
|
2184
2247
|
}
|
|
2185
2248
|
|
|
2249
|
+
|
|
2186
2250
|
protected boolean hasAnisoSamplingSupport() {
|
|
2187
2251
|
int major = getGLVersion()[0];
|
|
2188
2252
|
if (isES() || major < 3) {
|
|
@@ -2193,6 +2257,7 @@ public abstract class PGL {
|
|
|
2193
2257
|
}
|
|
2194
2258
|
}
|
|
2195
2259
|
|
|
2260
|
+
|
|
2196
2261
|
protected boolean hasSynchronization() {
|
|
2197
2262
|
int[] version = getGLVersion();
|
|
2198
2263
|
if (isES()) {
|
|
@@ -2201,6 +2266,7 @@ public abstract class PGL {
|
|
|
2201
2266
|
return (version[0] > 3) || (version[0] == 3 && version[1] >= 2);
|
|
2202
2267
|
}
|
|
2203
2268
|
|
|
2269
|
+
|
|
2204
2270
|
protected boolean hasPBOs() {
|
|
2205
2271
|
int[] version = getGLVersion();
|
|
2206
2272
|
if (isES()) {
|
|
@@ -2209,6 +2275,7 @@ public abstract class PGL {
|
|
|
2209
2275
|
return (version[0] > 2) || (version[0] == 2 && version[1] >= 1);
|
|
2210
2276
|
}
|
|
2211
2277
|
|
|
2278
|
+
|
|
2212
2279
|
protected boolean hasReadBuffer() {
|
|
2213
2280
|
int[] version = getGLVersion();
|
|
2214
2281
|
if (isES()) {
|
|
@@ -2217,6 +2284,7 @@ public abstract class PGL {
|
|
|
2217
2284
|
return version[0] >= 2;
|
|
2218
2285
|
}
|
|
2219
2286
|
|
|
2287
|
+
|
|
2220
2288
|
protected boolean hasDrawBuffer() {
|
|
2221
2289
|
int[] version = getGLVersion();
|
|
2222
2290
|
if (isES()) {
|
|
@@ -2225,23 +2293,62 @@ public abstract class PGL {
|
|
|
2225
2293
|
return version[0] >= 2;
|
|
2226
2294
|
}
|
|
2227
2295
|
|
|
2296
|
+
|
|
2228
2297
|
protected int maxSamples() {
|
|
2229
2298
|
intBuffer.rewind();
|
|
2230
2299
|
getIntegerv(MAX_SAMPLES, intBuffer);
|
|
2231
2300
|
return intBuffer.get(0);
|
|
2232
2301
|
}
|
|
2233
2302
|
|
|
2303
|
+
|
|
2234
2304
|
protected int getMaxTexUnits() {
|
|
2235
2305
|
intBuffer.rewind();
|
|
2236
2306
|
getIntegerv(MAX_TEXTURE_IMAGE_UNITS, intBuffer);
|
|
2237
2307
|
return intBuffer.get(0);
|
|
2238
2308
|
}
|
|
2239
2309
|
|
|
2310
|
+
|
|
2311
|
+
/**
|
|
2312
|
+
* Determine if the renderer / hardware supports frame buffer objects (FBOs).
|
|
2313
|
+
*
|
|
2314
|
+
* @return True if confirmed that FBOs are supported by the renderer on the current hardware. Will
|
|
2315
|
+
* be false if the support status has not been confirmed yet (for example, because the graphics
|
|
2316
|
+
* context has not been itiliazed) or if it is confirmed that the renderer / hardware
|
|
2317
|
+
* combination do not support FBOs.
|
|
2318
|
+
*/
|
|
2319
|
+
protected boolean getIsFboAllowed() {
|
|
2320
|
+
|
|
2321
|
+
// If not yet determined, try to find.
|
|
2322
|
+
if (fboAllowed.isEmpty()) {
|
|
2323
|
+
boolean isNoFboRenderer;
|
|
2324
|
+
if (PApplet.platform == PConstants.MACOS) {
|
|
2325
|
+
String rendererName;
|
|
2326
|
+
try {
|
|
2327
|
+
rendererName = getString(PGL.RENDERER);
|
|
2328
|
+
isNoFboRenderer = String.valueOf(rendererName).contains("Intel HD Graphics 3000");
|
|
2329
|
+
} catch (RuntimeException e) {
|
|
2330
|
+
System.err.println("Could not read renderer name. FBOs disabled. Reason: " + e);
|
|
2331
|
+
return false; // Try again later.
|
|
2332
|
+
}
|
|
2333
|
+
} else {
|
|
2334
|
+
isNoFboRenderer = false;
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
// Cache value.
|
|
2338
|
+
fboAllowed = Optional.of(!isNoFboRenderer);
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
// Return cached value.
|
|
2342
|
+
return fboAllowed.get();
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
|
|
2240
2346
|
protected static ByteBuffer allocateDirectByteBuffer(int size) {
|
|
2241
2347
|
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_BYTE;
|
|
2242
2348
|
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder());
|
|
2243
2349
|
}
|
|
2244
2350
|
|
|
2351
|
+
|
|
2245
2352
|
protected static ByteBuffer allocateByteBuffer(int size) {
|
|
2246
2353
|
if (USE_DIRECT_BUFFERS) {
|
|
2247
2354
|
return allocateDirectByteBuffer(size);
|
|
@@ -2250,6 +2357,7 @@ public abstract class PGL {
|
|
|
2250
2357
|
}
|
|
2251
2358
|
}
|
|
2252
2359
|
|
|
2360
|
+
|
|
2253
2361
|
protected static ByteBuffer allocateByteBuffer(byte[] arr) {
|
|
2254
2362
|
if (USE_DIRECT_BUFFERS) {
|
|
2255
2363
|
ByteBuffer buf = allocateDirectByteBuffer(arr.length);
|
|
@@ -2261,8 +2369,9 @@ public abstract class PGL {
|
|
|
2261
2369
|
}
|
|
2262
2370
|
}
|
|
2263
2371
|
|
|
2372
|
+
|
|
2264
2373
|
protected static ByteBuffer updateByteBuffer(ByteBuffer buf, byte[] arr,
|
|
2265
|
-
|
|
2374
|
+
boolean wrap) {
|
|
2266
2375
|
if (USE_DIRECT_BUFFERS) {
|
|
2267
2376
|
if (buf == null || buf.capacity() < arr.length) {
|
|
2268
2377
|
buf = allocateDirectByteBuffer(arr.length);
|
|
@@ -2285,8 +2394,9 @@ public abstract class PGL {
|
|
|
2285
2394
|
return buf;
|
|
2286
2395
|
}
|
|
2287
2396
|
|
|
2397
|
+
|
|
2288
2398
|
protected static void updateByteBuffer(ByteBuffer buf, byte[] arr,
|
|
2289
|
-
|
|
2399
|
+
int offset, int size) {
|
|
2290
2400
|
if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
|
|
2291
2401
|
buf.position(offset);
|
|
2292
2402
|
buf.put(arr, offset, size);
|
|
@@ -2294,6 +2404,7 @@ public abstract class PGL {
|
|
|
2294
2404
|
}
|
|
2295
2405
|
}
|
|
2296
2406
|
|
|
2407
|
+
|
|
2297
2408
|
protected static void getByteArray(ByteBuffer buf, byte[] arr) {
|
|
2298
2409
|
if (!buf.hasArray() || buf.array() != arr) {
|
|
2299
2410
|
buf.position(0);
|
|
@@ -2302,6 +2413,7 @@ public abstract class PGL {
|
|
|
2302
2413
|
}
|
|
2303
2414
|
}
|
|
2304
2415
|
|
|
2416
|
+
|
|
2305
2417
|
protected static void putByteArray(ByteBuffer buf, byte[] arr) {
|
|
2306
2418
|
if (!buf.hasArray() || buf.array() != arr) {
|
|
2307
2419
|
buf.position(0);
|
|
@@ -2310,8 +2422,9 @@ public abstract class PGL {
|
|
|
2310
2422
|
}
|
|
2311
2423
|
}
|
|
2312
2424
|
|
|
2425
|
+
|
|
2313
2426
|
protected static void fillByteBuffer(ByteBuffer buf, int i0, int i1,
|
|
2314
|
-
|
|
2427
|
+
byte val) {
|
|
2315
2428
|
int n = i1 - i0;
|
|
2316
2429
|
byte[] temp = new byte[n];
|
|
2317
2430
|
Arrays.fill(temp, 0, n, val);
|
|
@@ -2320,12 +2433,14 @@ public abstract class PGL {
|
|
|
2320
2433
|
buf.rewind();
|
|
2321
2434
|
}
|
|
2322
2435
|
|
|
2436
|
+
|
|
2323
2437
|
protected static ShortBuffer allocateDirectShortBuffer(int size) {
|
|
2324
2438
|
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_SHORT;
|
|
2325
2439
|
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
|
|
2326
|
-
|
|
2440
|
+
asShortBuffer();
|
|
2327
2441
|
}
|
|
2328
2442
|
|
|
2443
|
+
|
|
2329
2444
|
protected static ShortBuffer allocateShortBuffer(int size) {
|
|
2330
2445
|
if (USE_DIRECT_BUFFERS) {
|
|
2331
2446
|
return allocateDirectShortBuffer(size);
|
|
@@ -2334,6 +2449,7 @@ public abstract class PGL {
|
|
|
2334
2449
|
}
|
|
2335
2450
|
}
|
|
2336
2451
|
|
|
2452
|
+
|
|
2337
2453
|
protected static ShortBuffer allocateShortBuffer(short[] arr) {
|
|
2338
2454
|
if (USE_DIRECT_BUFFERS) {
|
|
2339
2455
|
ShortBuffer buf = allocateDirectShortBuffer(arr.length);
|
|
@@ -2345,8 +2461,9 @@ public abstract class PGL {
|
|
|
2345
2461
|
}
|
|
2346
2462
|
}
|
|
2347
2463
|
|
|
2464
|
+
|
|
2348
2465
|
protected static ShortBuffer updateShortBuffer(ShortBuffer buf, short[] arr,
|
|
2349
|
-
|
|
2466
|
+
boolean wrap) {
|
|
2350
2467
|
if (USE_DIRECT_BUFFERS) {
|
|
2351
2468
|
if (buf == null || buf.capacity() < arr.length) {
|
|
2352
2469
|
buf = allocateDirectShortBuffer(arr.length);
|
|
@@ -2369,8 +2486,9 @@ public abstract class PGL {
|
|
|
2369
2486
|
return buf;
|
|
2370
2487
|
}
|
|
2371
2488
|
|
|
2489
|
+
|
|
2372
2490
|
protected static void updateShortBuffer(ShortBuffer buf, short[] arr,
|
|
2373
|
-
|
|
2491
|
+
int offset, int size) {
|
|
2374
2492
|
if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
|
|
2375
2493
|
buf.position(offset);
|
|
2376
2494
|
buf.put(arr, offset, size);
|
|
@@ -2378,6 +2496,7 @@ public abstract class PGL {
|
|
|
2378
2496
|
}
|
|
2379
2497
|
}
|
|
2380
2498
|
|
|
2499
|
+
|
|
2381
2500
|
protected static void getShortArray(ShortBuffer buf, short[] arr) {
|
|
2382
2501
|
if (!buf.hasArray() || buf.array() != arr) {
|
|
2383
2502
|
buf.position(0);
|
|
@@ -2386,6 +2505,7 @@ public abstract class PGL {
|
|
|
2386
2505
|
}
|
|
2387
2506
|
}
|
|
2388
2507
|
|
|
2508
|
+
|
|
2389
2509
|
protected static void putShortArray(ShortBuffer buf, short[] arr) {
|
|
2390
2510
|
if (!buf.hasArray() || buf.array() != arr) {
|
|
2391
2511
|
buf.position(0);
|
|
@@ -2394,8 +2514,9 @@ public abstract class PGL {
|
|
|
2394
2514
|
}
|
|
2395
2515
|
}
|
|
2396
2516
|
|
|
2517
|
+
|
|
2397
2518
|
protected static void fillShortBuffer(ShortBuffer buf, int i0, int i1,
|
|
2398
|
-
|
|
2519
|
+
short val) {
|
|
2399
2520
|
int n = i1 - i0;
|
|
2400
2521
|
short[] temp = new short[n];
|
|
2401
2522
|
Arrays.fill(temp, 0, n, val);
|
|
@@ -2404,12 +2525,14 @@ public abstract class PGL {
|
|
|
2404
2525
|
buf.rewind();
|
|
2405
2526
|
}
|
|
2406
2527
|
|
|
2528
|
+
|
|
2407
2529
|
protected static IntBuffer allocateDirectIntBuffer(int size) {
|
|
2408
2530
|
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_INT;
|
|
2409
2531
|
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
|
|
2410
|
-
|
|
2532
|
+
asIntBuffer();
|
|
2411
2533
|
}
|
|
2412
2534
|
|
|
2535
|
+
|
|
2413
2536
|
protected static IntBuffer allocateIntBuffer(int size) {
|
|
2414
2537
|
if (USE_DIRECT_BUFFERS) {
|
|
2415
2538
|
return allocateDirectIntBuffer(size);
|
|
@@ -2418,6 +2541,7 @@ public abstract class PGL {
|
|
|
2418
2541
|
}
|
|
2419
2542
|
}
|
|
2420
2543
|
|
|
2544
|
+
|
|
2421
2545
|
protected static IntBuffer allocateIntBuffer(int[] arr) {
|
|
2422
2546
|
if (USE_DIRECT_BUFFERS) {
|
|
2423
2547
|
IntBuffer buf = allocateDirectIntBuffer(arr.length);
|
|
@@ -2429,8 +2553,9 @@ public abstract class PGL {
|
|
|
2429
2553
|
}
|
|
2430
2554
|
}
|
|
2431
2555
|
|
|
2556
|
+
|
|
2432
2557
|
protected static IntBuffer updateIntBuffer(IntBuffer buf, int[] arr,
|
|
2433
|
-
|
|
2558
|
+
boolean wrap) {
|
|
2434
2559
|
if (USE_DIRECT_BUFFERS) {
|
|
2435
2560
|
if (buf == null || buf.capacity() < arr.length) {
|
|
2436
2561
|
buf = allocateDirectIntBuffer(arr.length);
|
|
@@ -2453,14 +2578,16 @@ public abstract class PGL {
|
|
|
2453
2578
|
return buf;
|
|
2454
2579
|
}
|
|
2455
2580
|
|
|
2581
|
+
|
|
2456
2582
|
protected static void updateIntBuffer(IntBuffer buf, int[] arr,
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2583
|
+
int offset, int size) {
|
|
2584
|
+
if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
|
|
2585
|
+
buf.position(offset);
|
|
2586
|
+
buf.put(arr, offset, size);
|
|
2587
|
+
buf.rewind();
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2464
2591
|
|
|
2465
2592
|
protected static void getIntArray(IntBuffer buf, int[] arr) {
|
|
2466
2593
|
if (!buf.hasArray() || buf.array() != arr) {
|
|
@@ -2470,6 +2597,7 @@ public abstract class PGL {
|
|
|
2470
2597
|
}
|
|
2471
2598
|
}
|
|
2472
2599
|
|
|
2600
|
+
|
|
2473
2601
|
protected static void putIntArray(IntBuffer buf, int[] arr) {
|
|
2474
2602
|
if (!buf.hasArray() || buf.array() != arr) {
|
|
2475
2603
|
buf.position(0);
|
|
@@ -2478,6 +2606,7 @@ public abstract class PGL {
|
|
|
2478
2606
|
}
|
|
2479
2607
|
}
|
|
2480
2608
|
|
|
2609
|
+
|
|
2481
2610
|
protected static void fillIntBuffer(IntBuffer buf, int i0, int i1, int val) {
|
|
2482
2611
|
int n = i1 - i0;
|
|
2483
2612
|
int[] temp = new int[n];
|
|
@@ -2487,12 +2616,14 @@ public abstract class PGL {
|
|
|
2487
2616
|
buf.rewind();
|
|
2488
2617
|
}
|
|
2489
2618
|
|
|
2619
|
+
|
|
2490
2620
|
protected static FloatBuffer allocateDirectFloatBuffer(int size) {
|
|
2491
2621
|
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_FLOAT;
|
|
2492
2622
|
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
|
|
2493
|
-
|
|
2623
|
+
asFloatBuffer();
|
|
2494
2624
|
}
|
|
2495
2625
|
|
|
2626
|
+
|
|
2496
2627
|
protected static FloatBuffer allocateFloatBuffer(int size) {
|
|
2497
2628
|
if (USE_DIRECT_BUFFERS) {
|
|
2498
2629
|
return allocateDirectFloatBuffer(size);
|
|
@@ -2501,6 +2632,7 @@ public abstract class PGL {
|
|
|
2501
2632
|
}
|
|
2502
2633
|
}
|
|
2503
2634
|
|
|
2635
|
+
|
|
2504
2636
|
protected static FloatBuffer allocateFloatBuffer(float[] arr) {
|
|
2505
2637
|
if (USE_DIRECT_BUFFERS) {
|
|
2506
2638
|
FloatBuffer buf = allocateDirectFloatBuffer(arr.length);
|
|
@@ -2512,8 +2644,9 @@ public abstract class PGL {
|
|
|
2512
2644
|
}
|
|
2513
2645
|
}
|
|
2514
2646
|
|
|
2647
|
+
|
|
2515
2648
|
protected static FloatBuffer updateFloatBuffer(FloatBuffer buf, float[] arr,
|
|
2516
|
-
|
|
2649
|
+
boolean wrap) {
|
|
2517
2650
|
if (USE_DIRECT_BUFFERS) {
|
|
2518
2651
|
if (buf == null || buf.capacity() < arr.length) {
|
|
2519
2652
|
buf = allocateDirectFloatBuffer(arr.length);
|
|
@@ -2536,14 +2669,16 @@ public abstract class PGL {
|
|
|
2536
2669
|
return buf;
|
|
2537
2670
|
}
|
|
2538
2671
|
|
|
2672
|
+
|
|
2539
2673
|
protected static void updateFloatBuffer(FloatBuffer buf, float[] arr,
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2674
|
+
int offset, int size) {
|
|
2675
|
+
if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
|
|
2676
|
+
buf.position(offset);
|
|
2677
|
+
buf.put(arr, offset, size);
|
|
2678
|
+
buf.rewind();
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2547
2682
|
|
|
2548
2683
|
protected static void getFloatArray(FloatBuffer buf, float[] arr) {
|
|
2549
2684
|
if (!buf.hasArray() || buf.array() != arr) {
|
|
@@ -2553,6 +2688,7 @@ public abstract class PGL {
|
|
|
2553
2688
|
}
|
|
2554
2689
|
}
|
|
2555
2690
|
|
|
2691
|
+
|
|
2556
2692
|
protected static void putFloatArray(FloatBuffer buf, float[] arr) {
|
|
2557
2693
|
if (!buf.hasArray() || buf.array() != arr) {
|
|
2558
2694
|
buf.position(0);
|
|
@@ -2561,8 +2697,9 @@ public abstract class PGL {
|
|
|
2561
2697
|
}
|
|
2562
2698
|
}
|
|
2563
2699
|
|
|
2700
|
+
|
|
2564
2701
|
protected static void fillFloatBuffer(FloatBuffer buf, int i0, int i1,
|
|
2565
|
-
|
|
2702
|
+
float val) {
|
|
2566
2703
|
int n = i1 - i0;
|
|
2567
2704
|
float[] temp = new float[n];
|
|
2568
2705
|
Arrays.fill(temp, 0, n, val);
|
|
@@ -2571,63 +2708,65 @@ public abstract class PGL {
|
|
|
2571
2708
|
buf.rewind();
|
|
2572
2709
|
}
|
|
2573
2710
|
|
|
2711
|
+
|
|
2574
2712
|
// TODO: the next three functions shouldn't be here...
|
|
2575
2713
|
// Uses 'Object' so that the API can be used w/ Android Typeface objects
|
|
2714
|
+
|
|
2576
2715
|
abstract protected int getFontAscent(Object font);
|
|
2577
2716
|
|
|
2717
|
+
|
|
2578
2718
|
abstract protected int getFontDescent(Object font);
|
|
2579
2719
|
|
|
2720
|
+
|
|
2580
2721
|
abstract protected int getTextWidth(Object font, char[] buffer, int start, int stop);
|
|
2581
2722
|
|
|
2723
|
+
|
|
2582
2724
|
abstract protected Object getDerivedFont(Object font, float size);
|
|
2583
2725
|
|
|
2726
|
+
|
|
2584
2727
|
///////////////////////////////////////////////////////////
|
|
2728
|
+
|
|
2585
2729
|
// Tessellator interface
|
|
2730
|
+
|
|
2731
|
+
|
|
2586
2732
|
protected abstract Tessellator createTessellator(TessellatorCallback callback);
|
|
2587
2733
|
|
|
2588
|
-
protected interface Tessellator {
|
|
2589
2734
|
|
|
2735
|
+
protected interface Tessellator {
|
|
2590
2736
|
public void setCallback(int flag);
|
|
2591
|
-
|
|
2592
2737
|
public void setWindingRule(int rule);
|
|
2593
|
-
|
|
2594
2738
|
public void setProperty(int property, int value);
|
|
2595
2739
|
|
|
2596
2740
|
public void beginPolygon();
|
|
2597
|
-
|
|
2598
2741
|
public void beginPolygon(Object data);
|
|
2599
|
-
|
|
2600
2742
|
public void endPolygon();
|
|
2601
|
-
|
|
2602
2743
|
public void beginContour();
|
|
2603
|
-
|
|
2604
2744
|
public void endContour();
|
|
2605
|
-
|
|
2606
2745
|
public void addVertex(double[] v);
|
|
2607
|
-
|
|
2608
2746
|
public void addVertex(double[] v, int n, Object data);
|
|
2609
2747
|
}
|
|
2610
2748
|
|
|
2611
|
-
protected interface TessellatorCallback {
|
|
2612
2749
|
|
|
2750
|
+
protected interface TessellatorCallback {
|
|
2613
2751
|
public void begin(int type);
|
|
2614
|
-
|
|
2615
2752
|
public void end();
|
|
2616
|
-
|
|
2617
2753
|
public void vertex(Object data);
|
|
2618
|
-
|
|
2619
2754
|
public void combine(double[] coords, Object[] data,
|
|
2620
|
-
|
|
2621
|
-
|
|
2755
|
+
float[] weight, Object[] outData);
|
|
2622
2756
|
public void error(int errnum);
|
|
2623
2757
|
}
|
|
2624
2758
|
|
|
2759
|
+
|
|
2625
2760
|
protected String tessError(int err) {
|
|
2626
2761
|
return "";
|
|
2627
2762
|
}
|
|
2628
2763
|
|
|
2764
|
+
|
|
2629
2765
|
///////////////////////////////////////////////////////////
|
|
2766
|
+
|
|
2630
2767
|
// FontOutline interface
|
|
2768
|
+
|
|
2769
|
+
|
|
2631
2770
|
protected static boolean SHAPE_TEXT_SUPPORTED;
|
|
2632
2771
|
protected static int SEG_MOVETO;
|
|
2633
2772
|
protected static int SEG_LINETO;
|
|
@@ -2635,17 +2774,17 @@ public abstract class PGL {
|
|
|
2635
2774
|
protected static int SEG_CUBICTO;
|
|
2636
2775
|
protected static int SEG_CLOSE;
|
|
2637
2776
|
|
|
2777
|
+
|
|
2638
2778
|
protected abstract FontOutline createFontOutline(char ch, Object font);
|
|
2639
2779
|
|
|
2640
|
-
protected interface FontOutline {
|
|
2641
2780
|
|
|
2781
|
+
protected interface FontOutline {
|
|
2642
2782
|
public boolean isDone();
|
|
2643
|
-
|
|
2644
2783
|
public int currentSegment(float coords[]);
|
|
2645
|
-
|
|
2646
2784
|
public void next();
|
|
2647
2785
|
}
|
|
2648
2786
|
|
|
2787
|
+
|
|
2649
2788
|
//////////////////////////////////////////////////////////////////////////////
|
|
2650
2789
|
//
|
|
2651
2790
|
// OpenGL ES 2.0 API, with a few additional functions for multisampling and
|
|
@@ -2665,7 +2804,9 @@ public abstract class PGL {
|
|
|
2665
2804
|
// Also, keep in mind the note about the PGL constants below.
|
|
2666
2805
|
//
|
|
2667
2806
|
//////////////////////////////////////////////////////////////////////////////
|
|
2807
|
+
|
|
2668
2808
|
///////////////////////////////////////////////////////////
|
|
2809
|
+
|
|
2669
2810
|
// Constants
|
|
2670
2811
|
// Very important note: set the GL constants in your PGL subclass by using an
|
|
2671
2812
|
// static initialization block as follows:
|
|
@@ -2678,6 +2819,7 @@ public abstract class PGL {
|
|
|
2678
2819
|
// errors when the constants are accessed through PGL because they are not
|
|
2679
2820
|
// overridden but hidden by the new declarations, and hence they keep their
|
|
2680
2821
|
// initial values (all zeroes) when accessed through the superclass.
|
|
2822
|
+
|
|
2681
2823
|
public static int FALSE;
|
|
2682
2824
|
public static int TRUE;
|
|
2683
2825
|
|
|
@@ -2972,80 +3114,82 @@ public abstract class PGL {
|
|
|
2972
3114
|
public static int CONDITION_SATISFIED;
|
|
2973
3115
|
|
|
2974
3116
|
///////////////////////////////////////////////////////////
|
|
3117
|
+
|
|
2975
3118
|
// Special Functions
|
|
2976
|
-
public abstract void flush();
|
|
2977
3119
|
|
|
3120
|
+
public abstract void flush();
|
|
2978
3121
|
public abstract void finish();
|
|
2979
|
-
|
|
2980
3122
|
public abstract void hint(int target, int hint);
|
|
2981
3123
|
|
|
2982
3124
|
///////////////////////////////////////////////////////////
|
|
3125
|
+
|
|
2983
3126
|
// State and State Requests
|
|
2984
|
-
public abstract void enable(int value);
|
|
2985
3127
|
|
|
3128
|
+
public abstract void enable(int value);
|
|
2986
3129
|
public abstract void disable(int value);
|
|
2987
|
-
|
|
2988
3130
|
public abstract void getBooleanv(int value, IntBuffer data);
|
|
2989
|
-
|
|
2990
3131
|
public abstract void getIntegerv(int value, IntBuffer data);
|
|
2991
|
-
|
|
2992
3132
|
public abstract void getFloatv(int value, FloatBuffer data);
|
|
2993
|
-
|
|
2994
3133
|
public abstract boolean isEnabled(int value);
|
|
2995
3134
|
|
|
2996
|
-
|
|
3135
|
+
/**
|
|
3136
|
+
* Get a configuration or status string from the underlying renderer.
|
|
3137
|
+
*
|
|
3138
|
+
* @param name The name or ID of the attribute to request.
|
|
3139
|
+
* @return The requested value as a string.
|
|
3140
|
+
* @throws GraphicsNotInitializedException Thrown if an attribute is requested that is not
|
|
3141
|
+
* available until graphics initialization before that initialization compeltes. For example,
|
|
3142
|
+
* if requesting a GL string before GL context is available.
|
|
3143
|
+
*/
|
|
3144
|
+
public abstract String getString(int name) throws GraphicsNotInitializedException;
|
|
2997
3145
|
|
|
2998
3146
|
///////////////////////////////////////////////////////////
|
|
3147
|
+
|
|
2999
3148
|
// Error Handling
|
|
3000
|
-
public abstract int getError();
|
|
3001
3149
|
|
|
3150
|
+
public abstract int getError();
|
|
3002
3151
|
public abstract String errorString(int err);
|
|
3003
3152
|
|
|
3004
3153
|
//////////////////////////////////////////////////////////////////////////////
|
|
3154
|
+
|
|
3005
3155
|
// Buffer Objects
|
|
3006
|
-
public abstract void genBuffers(int n, IntBuffer buffers);
|
|
3007
3156
|
|
|
3157
|
+
public abstract void genBuffers(int n, IntBuffer buffers);
|
|
3008
3158
|
public abstract void deleteBuffers(int n, IntBuffer buffers);
|
|
3009
|
-
|
|
3010
3159
|
public abstract void bindBuffer(int target, int buffer);
|
|
3011
|
-
|
|
3012
3160
|
public abstract void bufferData(int target, int size, Buffer data, int usage);
|
|
3013
|
-
|
|
3014
3161
|
public abstract void bufferSubData(int target, int offset, int size, Buffer data);
|
|
3015
|
-
|
|
3016
3162
|
public abstract void isBuffer(int buffer);
|
|
3017
|
-
|
|
3018
3163
|
public abstract void getBufferParameteriv(int target, int value, IntBuffer data);
|
|
3019
|
-
|
|
3020
3164
|
public abstract ByteBuffer mapBuffer(int target, int access);
|
|
3021
|
-
|
|
3022
3165
|
public abstract ByteBuffer mapBufferRange(int target, int offset, int length, int access);
|
|
3023
|
-
|
|
3024
3166
|
public abstract void unmapBuffer(int target);
|
|
3025
3167
|
|
|
3026
3168
|
//////////////////////////////////////////////////////////////////////////////
|
|
3169
|
+
|
|
3027
3170
|
// Synchronization
|
|
3028
|
-
public abstract long fenceSync(int condition, int flags);
|
|
3029
3171
|
|
|
3172
|
+
public abstract long fenceSync(int condition, int flags);
|
|
3030
3173
|
public abstract void deleteSync(long sync);
|
|
3031
|
-
|
|
3032
3174
|
public abstract int clientWaitSync(long sync, int flags, long timeout);
|
|
3033
3175
|
|
|
3034
3176
|
//////////////////////////////////////////////////////////////////////////////
|
|
3177
|
+
|
|
3035
3178
|
// Viewport and Clipping
|
|
3036
|
-
public abstract void depthRangef(float n, float f);
|
|
3037
3179
|
|
|
3180
|
+
public abstract void depthRangef(float n, float f);
|
|
3038
3181
|
public abstract void viewport(int x, int y, int w, int h);
|
|
3039
|
-
|
|
3040
3182
|
protected abstract void viewportImpl(int x, int y, int w, int h);
|
|
3041
3183
|
|
|
3042
3184
|
//////////////////////////////////////////////////////////////////////////////
|
|
3185
|
+
|
|
3043
3186
|
// Reading Pixels
|
|
3044
3187
|
// This is a special case: because the renderer might be using an FBO even on
|
|
3045
3188
|
// the main surface, some extra handling might be needed before and after
|
|
3046
3189
|
// reading the pixels. To make this transparent to the user, the actual call
|
|
3047
3190
|
// to glReadPixels() should be done in readPixelsImpl().
|
|
3048
|
-
|
|
3191
|
+
|
|
3192
|
+
public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer){
|
|
3049
3193
|
boolean multisampled = isMultisampled() || graphics.offscreenMultisample;
|
|
3050
3194
|
boolean depthReadingEnabled = graphics.getHint(PConstants.ENABLE_BUFFER_READING);
|
|
3051
3195
|
boolean depthRequested = format == STENCIL_INDEX || format == DEPTH_COMPONENT || format == DEPTH_STENCIL;
|
|
@@ -3060,7 +3204,7 @@ public abstract class PGL {
|
|
|
3060
3204
|
graphics.endReadPixels();
|
|
3061
3205
|
}
|
|
3062
3206
|
|
|
3063
|
-
public void readPixels(int x, int y, int width, int height, int format, int type, long offset)
|
|
3207
|
+
public void readPixels(int x, int y, int width, int height, int format, int type, long offset){
|
|
3064
3208
|
boolean multisampled = isMultisampled() || graphics.offscreenMultisample;
|
|
3065
3209
|
boolean depthReadingEnabled = graphics.getHint(PConstants.ENABLE_BUFFER_READING);
|
|
3066
3210
|
boolean depthRequested = format == STENCIL_INDEX || format == DEPTH_COMPONENT || format == DEPTH_STENCIL;
|
|
@@ -3076,31 +3220,22 @@ public abstract class PGL {
|
|
|
3076
3220
|
}
|
|
3077
3221
|
|
|
3078
3222
|
protected abstract void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer);
|
|
3079
|
-
|
|
3080
3223
|
protected abstract void readPixelsImpl(int x, int y, int width, int height, int format, int type, long offset);
|
|
3081
3224
|
|
|
3082
3225
|
//////////////////////////////////////////////////////////////////////////////
|
|
3226
|
+
|
|
3083
3227
|
// Vertices
|
|
3084
|
-
public abstract void vertexAttrib1f(int index, float value);
|
|
3085
3228
|
|
|
3229
|
+
public abstract void vertexAttrib1f(int index, float value);
|
|
3086
3230
|
public abstract void vertexAttrib2f(int index, float value0, float value1);
|
|
3087
|
-
|
|
3088
3231
|
public abstract void vertexAttrib3f(int index, float value0, float value1, float value2);
|
|
3089
|
-
|
|
3090
3232
|
public abstract void vertexAttrib4f(int index, float value0, float value1, float value2, float value3);
|
|
3091
|
-
|
|
3092
3233
|
public abstract void vertexAttrib1fv(int index, FloatBuffer values);
|
|
3093
|
-
|
|
3094
3234
|
public abstract void vertexAttrib2fv(int index, FloatBuffer values);
|
|
3095
|
-
|
|
3096
3235
|
public abstract void vertexAttrib3fv(int index, FloatBuffer values);
|
|
3097
|
-
|
|
3098
3236
|
public abstract void vertexAttrib4fv(int index, FloatBuffer values);
|
|
3099
|
-
|
|
3100
3237
|
public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset);
|
|
3101
|
-
|
|
3102
3238
|
public abstract void enableVertexAttribArray(int index);
|
|
3103
|
-
|
|
3104
3239
|
public abstract void disableVertexAttribArray(int index);
|
|
3105
3240
|
|
|
3106
3241
|
public void drawArrays(int mode, int first, int count) {
|
|
@@ -3118,51 +3253,39 @@ public abstract class PGL {
|
|
|
3118
3253
|
public abstract void drawElementsImpl(int mode, int count, int type, int offset);
|
|
3119
3254
|
|
|
3120
3255
|
//////////////////////////////////////////////////////////////////////////////
|
|
3256
|
+
|
|
3121
3257
|
// Rasterization
|
|
3122
|
-
public abstract void lineWidth(float width);
|
|
3123
3258
|
|
|
3259
|
+
public abstract void lineWidth(float width);
|
|
3124
3260
|
public abstract void frontFace(int dir);
|
|
3125
|
-
|
|
3126
3261
|
public abstract void cullFace(int mode);
|
|
3127
|
-
|
|
3128
3262
|
public abstract void polygonOffset(float factor, float units);
|
|
3129
3263
|
|
|
3130
3264
|
//////////////////////////////////////////////////////////////////////////////
|
|
3265
|
+
|
|
3131
3266
|
// Pixel Rectangles
|
|
3267
|
+
|
|
3132
3268
|
public abstract void pixelStorei(int pname, int param);
|
|
3133
3269
|
|
|
3134
3270
|
///////////////////////////////////////////////////////////
|
|
3271
|
+
|
|
3135
3272
|
// Texturing
|
|
3136
|
-
public abstract void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data);
|
|
3137
3273
|
|
|
3274
|
+
public abstract void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data);
|
|
3138
3275
|
public abstract void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border);
|
|
3139
|
-
|
|
3140
3276
|
public abstract void texSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, Buffer data);
|
|
3141
|
-
|
|
3142
3277
|
public abstract void copyTexSubImage2D(int target, int level, int xOffset, int yOffset, int x, int y, int width, int height);
|
|
3143
|
-
|
|
3144
3278
|
public abstract void compressedTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int imageSize, Buffer data);
|
|
3145
|
-
|
|
3146
3279
|
public abstract void compressedTexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int imageSize, Buffer data);
|
|
3147
|
-
|
|
3148
3280
|
public abstract void texParameteri(int target, int pname, int param);
|
|
3149
|
-
|
|
3150
3281
|
public abstract void texParameterf(int target, int pname, float param);
|
|
3151
|
-
|
|
3152
3282
|
public abstract void texParameteriv(int target, int pname, IntBuffer params);
|
|
3153
|
-
|
|
3154
3283
|
public abstract void texParameterfv(int target, int pname, FloatBuffer params);
|
|
3155
|
-
|
|
3156
3284
|
public abstract void generateMipmap(int target);
|
|
3157
|
-
|
|
3158
3285
|
public abstract void genTextures(int n, IntBuffer textures);
|
|
3159
|
-
|
|
3160
3286
|
public abstract void deleteTextures(int n, IntBuffer textures);
|
|
3161
|
-
|
|
3162
3287
|
public abstract void getTexParameteriv(int target, int pname, IntBuffer params);
|
|
3163
|
-
|
|
3164
3288
|
public abstract void getTexParameterfv(int target, int pname, FloatBuffer params);
|
|
3165
|
-
|
|
3166
3289
|
public abstract boolean isTexture(int texture);
|
|
3167
3290
|
|
|
3168
3291
|
// activeTexture() and bindTexture() have some extra logic to keep track of
|
|
@@ -3193,198 +3316,141 @@ public abstract class PGL {
|
|
|
3193
3316
|
boundTextures[activeTexUnit][1] = texture;
|
|
3194
3317
|
}
|
|
3195
3318
|
}
|
|
3196
|
-
|
|
3197
3319
|
protected abstract void bindTextureImpl(int target, int texture);
|
|
3198
3320
|
|
|
3199
3321
|
///////////////////////////////////////////////////////////
|
|
3322
|
+
|
|
3200
3323
|
// Shaders and Programs
|
|
3201
|
-
public abstract int createShader(int type);
|
|
3202
3324
|
|
|
3325
|
+
public abstract int createShader(int type);
|
|
3203
3326
|
public abstract void shaderSource(int shader, String source);
|
|
3204
|
-
|
|
3205
3327
|
public abstract void compileShader(int shader);
|
|
3206
|
-
|
|
3207
3328
|
public abstract void releaseShaderCompiler();
|
|
3208
|
-
|
|
3209
3329
|
public abstract void deleteShader(int shader);
|
|
3210
|
-
|
|
3211
3330
|
public abstract void shaderBinary(int count, IntBuffer shaders, int binaryFormat, Buffer binary, int length);
|
|
3212
|
-
|
|
3213
3331
|
public abstract int createProgram();
|
|
3214
|
-
|
|
3215
3332
|
public abstract void attachShader(int program, int shader);
|
|
3216
|
-
|
|
3217
3333
|
public abstract void detachShader(int program, int shader);
|
|
3218
|
-
|
|
3219
3334
|
public abstract void linkProgram(int program);
|
|
3220
|
-
|
|
3221
3335
|
public abstract void useProgram(int program);
|
|
3222
|
-
|
|
3223
3336
|
public abstract void deleteProgram(int program);
|
|
3224
|
-
|
|
3225
3337
|
public abstract String getActiveAttrib(int program, int index, IntBuffer size, IntBuffer type);
|
|
3226
|
-
|
|
3227
3338
|
public abstract int getAttribLocation(int program, String name);
|
|
3228
|
-
|
|
3229
3339
|
public abstract void bindAttribLocation(int program, int index, String name);
|
|
3230
|
-
|
|
3231
3340
|
public abstract int getUniformLocation(int program, String name);
|
|
3232
|
-
|
|
3233
3341
|
public abstract String getActiveUniform(int program, int index, IntBuffer size, IntBuffer type);
|
|
3234
|
-
|
|
3235
3342
|
public abstract void uniform1i(int location, int value);
|
|
3236
|
-
|
|
3237
3343
|
public abstract void uniform2i(int location, int value0, int value1);
|
|
3238
|
-
|
|
3239
3344
|
public abstract void uniform3i(int location, int value0, int value1, int value2);
|
|
3240
|
-
|
|
3241
3345
|
public abstract void uniform4i(int location, int value0, int value1, int value2, int value3);
|
|
3242
|
-
|
|
3243
3346
|
public abstract void uniform1f(int location, float value);
|
|
3244
|
-
|
|
3245
3347
|
public abstract void uniform2f(int location, float value0, float value1);
|
|
3246
|
-
|
|
3247
3348
|
public abstract void uniform3f(int location, float value0, float value1, float value2);
|
|
3248
|
-
|
|
3249
3349
|
public abstract void uniform4f(int location, float value0, float value1, float value2, float value3);
|
|
3250
|
-
|
|
3251
3350
|
public abstract void uniform1iv(int location, int count, IntBuffer v);
|
|
3252
|
-
|
|
3253
3351
|
public abstract void uniform2iv(int location, int count, IntBuffer v);
|
|
3254
|
-
|
|
3255
3352
|
public abstract void uniform3iv(int location, int count, IntBuffer v);
|
|
3256
|
-
|
|
3257
3353
|
public abstract void uniform4iv(int location, int count, IntBuffer v);
|
|
3258
|
-
|
|
3259
3354
|
public abstract void uniform1fv(int location, int count, FloatBuffer v);
|
|
3260
|
-
|
|
3261
3355
|
public abstract void uniform2fv(int location, int count, FloatBuffer v);
|
|
3262
|
-
|
|
3263
3356
|
public abstract void uniform3fv(int location, int count, FloatBuffer v);
|
|
3264
|
-
|
|
3265
3357
|
public abstract void uniform4fv(int location, int count, FloatBuffer v);
|
|
3266
|
-
|
|
3267
3358
|
public abstract void uniformMatrix2fv(int location, int count, boolean transpose, FloatBuffer mat);
|
|
3268
|
-
|
|
3269
3359
|
public abstract void uniformMatrix3fv(int location, int count, boolean transpose, FloatBuffer mat);
|
|
3270
|
-
|
|
3271
3360
|
public abstract void uniformMatrix4fv(int location, int count, boolean transpose, FloatBuffer mat);
|
|
3272
|
-
|
|
3273
3361
|
public abstract void validateProgram(int program);
|
|
3274
|
-
|
|
3275
3362
|
public abstract boolean isShader(int shader);
|
|
3276
|
-
|
|
3277
3363
|
public abstract void getShaderiv(int shader, int pname, IntBuffer params);
|
|
3278
|
-
|
|
3279
3364
|
public abstract void getAttachedShaders(int program, int maxCount, IntBuffer count, IntBuffer shaders);
|
|
3280
|
-
|
|
3281
3365
|
public abstract String getShaderInfoLog(int shader);
|
|
3282
|
-
|
|
3283
3366
|
public abstract String getShaderSource(int shader);
|
|
3284
|
-
|
|
3285
3367
|
public abstract void getShaderPrecisionFormat(int shaderType, int precisionType, IntBuffer range, IntBuffer precision);
|
|
3286
|
-
|
|
3287
3368
|
public abstract void getVertexAttribfv(int index, int pname, FloatBuffer params);
|
|
3288
|
-
|
|
3289
3369
|
public abstract void getVertexAttribiv(int index, int pname, IntBuffer params);
|
|
3290
|
-
|
|
3291
3370
|
public abstract void getVertexAttribPointerv(int index, int pname, ByteBuffer data);
|
|
3292
|
-
|
|
3293
3371
|
public abstract void getUniformfv(int program, int location, FloatBuffer params);
|
|
3294
|
-
|
|
3295
3372
|
public abstract void getUniformiv(int program, int location, IntBuffer params);
|
|
3296
|
-
|
|
3297
3373
|
public abstract boolean isProgram(int program);
|
|
3298
|
-
|
|
3299
3374
|
public abstract void getProgramiv(int program, int pname, IntBuffer params);
|
|
3300
|
-
|
|
3301
3375
|
public abstract String getProgramInfoLog(int program);
|
|
3302
3376
|
|
|
3303
3377
|
///////////////////////////////////////////////////////////
|
|
3378
|
+
|
|
3304
3379
|
// Per-Fragment Operations
|
|
3305
|
-
public abstract void scissor(int x, int y, int w, int h);
|
|
3306
3380
|
|
|
3381
|
+
public abstract void scissor(int x, int y, int w, int h);
|
|
3307
3382
|
public abstract void sampleCoverage(float value, boolean invert);
|
|
3308
|
-
|
|
3309
3383
|
public abstract void stencilFunc(int func, int ref, int mask);
|
|
3310
|
-
|
|
3311
3384
|
public abstract void stencilFuncSeparate(int face, int func, int ref, int mask);
|
|
3312
|
-
|
|
3313
3385
|
public abstract void stencilOp(int sfail, int dpfail, int dppass);
|
|
3314
|
-
|
|
3315
3386
|
public abstract void stencilOpSeparate(int face, int sfail, int dpfail, int dppass);
|
|
3316
|
-
|
|
3317
3387
|
public abstract void depthFunc(int func);
|
|
3318
|
-
|
|
3319
3388
|
public abstract void blendEquation(int mode);
|
|
3320
|
-
|
|
3321
3389
|
public abstract void blendEquationSeparate(int modeRGB, int modeAlpha);
|
|
3322
|
-
|
|
3323
3390
|
public abstract void blendFunc(int src, int dst);
|
|
3324
|
-
|
|
3325
3391
|
public abstract void blendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
|
|
3326
|
-
|
|
3327
3392
|
public abstract void blendColor(float red, float green, float blue, float alpha);
|
|
3328
3393
|
|
|
3329
3394
|
///////////////////////////////////////////////////////////
|
|
3395
|
+
|
|
3330
3396
|
// Whole Framebuffer Operations
|
|
3331
|
-
public abstract void colorMask(boolean r, boolean g, boolean b, boolean a);
|
|
3332
3397
|
|
|
3398
|
+
public abstract void colorMask(boolean r, boolean g, boolean b, boolean a);
|
|
3333
3399
|
public abstract void depthMask(boolean mask);
|
|
3334
|
-
|
|
3335
3400
|
public abstract void stencilMask(int mask);
|
|
3336
|
-
|
|
3337
3401
|
public abstract void stencilMaskSeparate(int face, int mask);
|
|
3338
|
-
|
|
3339
3402
|
public abstract void clearColor(float r, float g, float b, float a);
|
|
3340
|
-
|
|
3341
3403
|
public abstract void clearDepth(float d);
|
|
3342
|
-
|
|
3343
3404
|
public abstract void clearStencil(int s);
|
|
3344
|
-
|
|
3345
3405
|
public abstract void clear(int buf);
|
|
3346
3406
|
|
|
3347
3407
|
///////////////////////////////////////////////////////////
|
|
3408
|
+
|
|
3348
3409
|
// Framebuffers Objects
|
|
3410
|
+
|
|
3349
3411
|
public void bindFramebuffer(int target, int framebuffer) {
|
|
3350
3412
|
graphics.beginBindFramebuffer(target, framebuffer);
|
|
3351
3413
|
bindFramebufferImpl(target, framebuffer);
|
|
3352
3414
|
graphics.endBindFramebuffer(target, framebuffer);
|
|
3353
3415
|
}
|
|
3354
|
-
|
|
3355
3416
|
protected abstract void bindFramebufferImpl(int target, int framebuffer);
|
|
3356
3417
|
|
|
3357
3418
|
public abstract void deleteFramebuffers(int n, IntBuffer framebuffers);
|
|
3358
|
-
|
|
3359
3419
|
public abstract void genFramebuffers(int n, IntBuffer framebuffers);
|
|
3360
|
-
|
|
3361
3420
|
public abstract void bindRenderbuffer(int target, int renderbuffer);
|
|
3362
|
-
|
|
3363
3421
|
public abstract void deleteRenderbuffers(int n, IntBuffer renderbuffers);
|
|
3364
|
-
|
|
3365
3422
|
public abstract void genRenderbuffers(int n, IntBuffer renderbuffers);
|
|
3366
|
-
|
|
3367
3423
|
public abstract void renderbufferStorage(int target, int internalFormat, int width, int height);
|
|
3368
|
-
|
|
3369
3424
|
public abstract void framebufferRenderbuffer(int target, int attachment, int rendbuferfTarget, int renderbuffer);
|
|
3370
|
-
|
|
3371
3425
|
public abstract void framebufferTexture2D(int target, int attachment, int texTarget, int texture, int level);
|
|
3372
|
-
|
|
3373
3426
|
public abstract int checkFramebufferStatus(int target);
|
|
3374
|
-
|
|
3375
3427
|
public abstract boolean isFramebuffer(int framebuffer);
|
|
3376
|
-
|
|
3377
3428
|
public abstract void getFramebufferAttachmentParameteriv(int target, int attachment, int pname, IntBuffer params);
|
|
3378
|
-
|
|
3379
3429
|
public abstract boolean isRenderbuffer(int renderbuffer);
|
|
3380
|
-
|
|
3381
3430
|
public abstract void getRenderbufferParameteriv(int target, int pname, IntBuffer params);
|
|
3382
|
-
|
|
3383
3431
|
public abstract void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter);
|
|
3384
|
-
|
|
3385
3432
|
public abstract void renderbufferStorageMultisample(int target, int samples, int format, int width, int height);
|
|
3386
|
-
|
|
3387
3433
|
public abstract void readBuffer(int buf);
|
|
3388
|
-
|
|
3389
3434
|
public abstract void drawBuffer(int buf);
|
|
3435
|
+
|
|
3436
|
+
///////////////////////////////////////////////////////////
|
|
3437
|
+
|
|
3438
|
+
// Exceptions
|
|
3439
|
+
|
|
3440
|
+
/**
|
|
3441
|
+
* Exception for when attempting an operation requiring the graphics renderer, context, etc
|
|
3442
|
+
* to have been initialized before that initialization.
|
|
3443
|
+
*/
|
|
3444
|
+
public class GraphicsNotInitializedException extends RuntimeException {
|
|
3445
|
+
|
|
3446
|
+
/**
|
|
3447
|
+
* Create a new exception indicating that an action could not be fulfilled because the rendering
|
|
3448
|
+
* context or equivalent is not ready.
|
|
3449
|
+
*
|
|
3450
|
+
* @param msg Further details about the issue.
|
|
3451
|
+
*/
|
|
3452
|
+
public GraphicsNotInitializedException(String msg) {
|
|
3453
|
+
super(msg);
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3390
3456
|
}
|