propane 3.4.1-java → 3.7.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
- data/.mvn/wrapper/maven-wrapper.properties +2 -2
- data/.travis.yml +1 -1
- data/CHANGELOG.md +9 -1
- data/Gemfile +2 -0
- data/README.md +9 -5
- data/Rakefile +10 -11
- data/bin/propane +3 -1
- data/lib/propane.rb +4 -2
- 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 -23
- 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 +20 -14
- 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 +37 -36
- data/pom.xml +6 -6
- data/propane.gemspec +12 -10
- data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
- data/src/main/java/monkstone/ColorUtil.java +1 -3
- data/src/main/java/monkstone/MathToolModule.java +10 -9
- 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 +781 -285
- data/src/main/java/processing/awt/PImageAWT.java +377 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
- data/src/main/java/processing/awt/PSurfaceAWT.java +308 -208
- data/src/main/java/processing/awt/ShimAWT.java +581 -0
- data/src/main/java/processing/core/PApplet.java +4225 -4855
- data/src/main/java/processing/core/PConstants.java +477 -447
- data/src/main/java/processing/core/PFont.java +914 -880
- data/src/main/java/processing/core/PGraphics.java +150 -134
- data/src/main/java/processing/core/PImage.java +275 -372
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +478 -415
- data/src/main/java/processing/core/PMatrix3D.java +762 -735
- data/src/main/java/processing/core/PShape.java +2887 -2651
- data/src/main/java/processing/core/PShapeOBJ.java +97 -92
- data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
- data/src/main/java/processing/core/PStyle.java +40 -37
- data/src/main/java/processing/core/PSurface.java +139 -97
- data/src/main/java/processing/core/PSurfaceNone.java +296 -218
- data/src/main/java/processing/core/PVector.java +995 -963
- 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 +3690 -3510
- data/src/main/java/processing/data/TableRow.java +182 -183
- data/src/main/java/processing/data/XML.java +957 -883
- 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 +88 -113
- data/src/main/java/processing/event/TouchEvent.java +10 -6
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
- data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
- 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 +389 -377
- data/src/main/java/processing/opengl/LinePath.java +132 -89
- data/src/main/java/processing/opengl/LineStroker.java +588 -581
- data/src/main/java/processing/opengl/PGL.java +660 -567
- 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 +12378 -12075
- data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
- data/src/main/java/processing/opengl/PShader.java +369 -461
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
- data/src/main/java/processing/opengl/Texture.java +1492 -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 +35 -40
- metadata +42 -22
- 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 processing.core.*;
|
@@ -30,49 +33,48 @@ import java.nio.IntBuffer;
|
|
30
33
|
import java.util.HashMap;
|
31
34
|
|
32
35
|
/**
|
33
|
-
* This class encapsulates a GLSL shader program, including a vertex
|
34
|
-
* fragment shader. Based on the GLSLShader class from GLGraphics, which
|
35
|
-
* was originally based in the code by JohnG:
|
36
|
+
* This class encapsulates a GLSL shader program, including a vertex
|
37
|
+
* and a fragment shader. Based on the GLSLShader class from GLGraphics, which
|
38
|
+
* in turn was originally based in the code by JohnG:
|
36
39
|
* http://processing.org/discourse/beta/num_1159494801.html
|
37
40
|
*
|
38
41
|
* @webref rendering:shaders
|
39
42
|
*/
|
40
43
|
public class PShader implements PConstants {
|
41
|
-
|
42
|
-
static protected final int
|
43
|
-
static protected final int
|
44
|
-
static protected final int
|
45
|
-
static protected final int
|
46
|
-
static protected final int
|
47
|
-
static protected final int TEXTURE = 5;
|
44
|
+
static protected final int POINT = 0;
|
45
|
+
static protected final int LINE = 1;
|
46
|
+
static protected final int POLY = 2;
|
47
|
+
static protected final int COLOR = 3;
|
48
|
+
static protected final int LIGHT = 4;
|
49
|
+
static protected final int TEXTURE = 5;
|
48
50
|
static protected final int TEXLIGHT = 6;
|
49
51
|
|
50
|
-
static protected String pointShaderAttrRegexp
|
51
|
-
|
52
|
-
static protected String pointShaderInRegexp
|
53
|
-
|
54
|
-
static protected String lineShaderAttrRegexp
|
55
|
-
|
56
|
-
static protected String lineShaderInRegexp
|
57
|
-
|
58
|
-
static protected String pointShaderDefRegexp
|
59
|
-
|
60
|
-
static protected String lineShaderDefRegexp
|
61
|
-
|
62
|
-
static protected String colorShaderDefRegexp
|
63
|
-
|
64
|
-
static protected String lightShaderDefRegexp
|
65
|
-
|
66
|
-
static protected String texShaderDefRegexp
|
67
|
-
|
68
|
-
static protected String texlightShaderDefRegexp
|
69
|
-
|
70
|
-
static protected String polyShaderDefRegexp
|
71
|
-
|
72
|
-
static protected String triShaderAttrRegexp
|
73
|
-
|
74
|
-
static protected String quadShaderAttrRegexp
|
75
|
-
|
52
|
+
static protected String pointShaderAttrRegexp =
|
53
|
+
"attribute *vec2 *offset";
|
54
|
+
static protected String pointShaderInRegexp =
|
55
|
+
"in *vec2 *offset;";
|
56
|
+
static protected String lineShaderAttrRegexp =
|
57
|
+
"attribute *vec4 *direction";
|
58
|
+
static protected String lineShaderInRegexp =
|
59
|
+
"in *vec4 *direction";
|
60
|
+
static protected String pointShaderDefRegexp =
|
61
|
+
"#define *PROCESSING_POINT_SHADER";
|
62
|
+
static protected String lineShaderDefRegexp =
|
63
|
+
"#define *PROCESSING_LINE_SHADER";
|
64
|
+
static protected String colorShaderDefRegexp =
|
65
|
+
"#define *PROCESSING_COLOR_SHADER";
|
66
|
+
static protected String lightShaderDefRegexp =
|
67
|
+
"#define *PROCESSING_LIGHT_SHADER";
|
68
|
+
static protected String texShaderDefRegexp =
|
69
|
+
"#define *PROCESSING_TEXTURE_SHADER";
|
70
|
+
static protected String texlightShaderDefRegexp =
|
71
|
+
"#define *PROCESSING_TEXLIGHT_SHADER";
|
72
|
+
static protected String polyShaderDefRegexp =
|
73
|
+
"#define *PROCESSING_POLYGON_SHADER";
|
74
|
+
static protected String triShaderAttrRegexp =
|
75
|
+
"#define *PROCESSING_TRIANGLES_SHADER";
|
76
|
+
static protected String quadShaderAttrRegexp =
|
77
|
+
"#define *PROCESSING_QUADS_SHADER";
|
76
78
|
|
77
79
|
protected PApplet parent;
|
78
80
|
// The main renderer associated to the parent PApplet.
|
@@ -183,16 +185,19 @@ public class PShader implements PConstants {
|
|
183
185
|
type = -1;
|
184
186
|
}
|
185
187
|
|
188
|
+
|
186
189
|
public PShader(PApplet parent) {
|
187
190
|
this();
|
188
191
|
this.parent = parent;
|
189
|
-
primaryPG = (PGraphicsOpenGL)
|
192
|
+
primaryPG = (PGraphicsOpenGL)parent.g;
|
190
193
|
pgl = primaryPG.pgl;
|
191
194
|
context = pgl.createEmptyContext();
|
192
195
|
}
|
193
196
|
|
197
|
+
|
194
198
|
/**
|
195
|
-
* Creates a shader program using the specified vertex and fragment
|
199
|
+
* Creates a shader program using the specified vertex and fragment
|
200
|
+
* shaders.
|
196
201
|
*
|
197
202
|
* @param parent the parent program
|
198
203
|
* @param vertFilename name of the vertex shader
|
@@ -200,7 +205,7 @@ public class PShader implements PConstants {
|
|
200
205
|
*/
|
201
206
|
public PShader(PApplet parent, String vertFilename, String fragFilename) {
|
202
207
|
this.parent = parent;
|
203
|
-
primaryPG = (PGraphicsOpenGL)
|
208
|
+
primaryPG = (PGraphicsOpenGL)parent.g;
|
204
209
|
pgl = primaryPG.pgl;
|
205
210
|
|
206
211
|
this.vertexURL = null;
|
@@ -225,21 +230,21 @@ public class PShader implements PConstants {
|
|
225
230
|
type = fragType;
|
226
231
|
} else if (fragType == -1) {
|
227
232
|
type = vertType;
|
228
|
-
} else if (fragType == vertType)
|
233
|
+
} else if (fragType == vertType) {
|
229
234
|
type = vertType;
|
230
235
|
} else {
|
231
236
|
PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
|
232
237
|
}
|
233
238
|
}
|
234
239
|
|
240
|
+
|
235
241
|
/**
|
236
|
-
* @param parent
|
237
242
|
* @param vertURL network location of the vertex shader
|
238
243
|
* @param fragURL network location of the fragment shader
|
239
244
|
*/
|
240
245
|
public PShader(PApplet parent, URL vertURL, URL fragURL) {
|
241
246
|
this.parent = parent;
|
242
|
-
primaryPG = (PGraphicsOpenGL)
|
247
|
+
primaryPG = (PGraphicsOpenGL)parent.g;
|
243
248
|
pgl = primaryPG.pgl;
|
244
249
|
|
245
250
|
this.vertexURL = vertURL;
|
@@ -264,7 +269,7 @@ public class PShader implements PConstants {
|
|
264
269
|
type = fragType;
|
265
270
|
} else if (fragType == -1) {
|
266
271
|
type = vertType;
|
267
|
-
} else if (fragType == vertType)
|
272
|
+
} else if (fragType == vertType) {
|
268
273
|
type = vertType;
|
269
274
|
} else {
|
270
275
|
PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
|
@@ -273,7 +278,7 @@ public class PShader implements PConstants {
|
|
273
278
|
|
274
279
|
public PShader(PApplet parent, String[] vertSource, String[] fragSource) {
|
275
280
|
this.parent = parent;
|
276
|
-
primaryPG = (PGraphicsOpenGL)
|
281
|
+
primaryPG = (PGraphicsOpenGL)parent.g;
|
277
282
|
pgl = primaryPG.pgl;
|
278
283
|
|
279
284
|
this.vertexURL = null;
|
@@ -298,32 +303,37 @@ public class PShader implements PConstants {
|
|
298
303
|
type = fragType;
|
299
304
|
} else if (fragType == -1) {
|
300
305
|
type = vertType;
|
301
|
-
} else if (fragType == vertType)
|
306
|
+
} else if (fragType == vertType) {
|
302
307
|
type = vertType;
|
303
308
|
} else {
|
304
309
|
PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
|
305
310
|
}
|
306
311
|
}
|
307
312
|
|
313
|
+
|
308
314
|
public void setVertexShader(String vertFilename) {
|
309
315
|
this.vertexFilename = vertFilename;
|
310
316
|
vertexShaderSource = pgl.loadVertexShader(vertFilename);
|
311
317
|
}
|
312
318
|
|
319
|
+
|
313
320
|
public void setVertexShader(URL vertURL) {
|
314
321
|
this.vertexURL = vertURL;
|
315
322
|
vertexShaderSource = pgl.loadVertexShader(vertURL);
|
316
323
|
}
|
317
324
|
|
325
|
+
|
318
326
|
public void setVertexShader(String[] vertSource) {
|
319
327
|
vertexShaderSource = vertSource;
|
320
328
|
}
|
321
329
|
|
330
|
+
|
322
331
|
public void setFragmentShader(String fragFilename) {
|
323
332
|
this.fragmentFilename = fragFilename;
|
324
333
|
fragmentShaderSource = pgl.loadFragmentShader(fragFilename);
|
325
334
|
}
|
326
335
|
|
336
|
+
|
327
337
|
public void setFragmentShader(URL fragURL) {
|
328
338
|
this.fragmentURL = fragURL;
|
329
339
|
fragmentShaderSource = pgl.loadFragmentShader(fragURL);
|
@@ -333,6 +343,7 @@ public class PShader implements PConstants {
|
|
333
343
|
fragmentShaderSource = fragSource;
|
334
344
|
}
|
335
345
|
|
346
|
+
|
336
347
|
/**
|
337
348
|
* Initializes (if needed) and binds the shader program.
|
338
349
|
*/
|
@@ -345,18 +356,15 @@ public class PShader implements PConstants {
|
|
345
356
|
bindTextures();
|
346
357
|
}
|
347
358
|
|
348
|
-
if (hasType())
|
349
|
-
bindTyped();
|
350
|
-
}
|
359
|
+
if (hasType()) bindTyped();
|
351
360
|
}
|
352
361
|
|
362
|
+
|
353
363
|
/**
|
354
364
|
* Unbinds the shader program.
|
355
365
|
*/
|
356
366
|
public void unbind() {
|
357
|
-
if (hasType())
|
358
|
-
unbindTyped();
|
359
|
-
}
|
367
|
+
if (hasType()) unbindTyped();
|
360
368
|
|
361
369
|
if (bound) {
|
362
370
|
unbindTextures();
|
@@ -365,10 +373,9 @@ public class PShader implements PConstants {
|
|
365
373
|
}
|
366
374
|
}
|
367
375
|
|
376
|
+
|
368
377
|
/**
|
369
378
|
* Returns true if the shader is bound, false otherwise.
|
370
|
-
*
|
371
|
-
* @return
|
372
379
|
*/
|
373
380
|
public boolean bound() {
|
374
381
|
return bound;
|
@@ -381,94 +388,88 @@ public class PShader implements PConstants {
|
|
381
388
|
* @param x first component of the variable to modify
|
382
389
|
*/
|
383
390
|
public void set(String name, int x) {
|
384
|
-
setUniformImpl(name, UniformValue.INT1, new int[]{x});
|
391
|
+
setUniformImpl(name, UniformValue.INT1, new int[] { x });
|
385
392
|
}
|
386
393
|
|
387
394
|
/**
|
388
|
-
* @param
|
389
|
-
* @param x
|
390
|
-
* @param y second component of the variable to modify. The variable has to be
|
391
|
-
* declared with an array/vector type in the shader (i.e.: int[2], vec2)
|
395
|
+
* @param y second component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[2], vec2)
|
392
396
|
*/
|
393
397
|
public void set(String name, int x, int y) {
|
394
|
-
setUniformImpl(name, UniformValue.INT2, new int[]{x, y});
|
398
|
+
setUniformImpl(name, UniformValue.INT2, new int[] { x, y });
|
395
399
|
}
|
396
400
|
|
397
401
|
/**
|
398
|
-
* @param
|
399
|
-
* @param x
|
400
|
-
* @param y
|
401
|
-
* @param z third component of the variable to modify. The variable has to be
|
402
|
-
* declared with an array/vector type in the shader (i.e.: int[3], vec3)
|
402
|
+
* @param z third component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[3], vec3)
|
403
403
|
*/
|
404
404
|
public void set(String name, int x, int y, int z) {
|
405
|
-
setUniformImpl(name, UniformValue.INT3, new int[]{x, y, z});
|
405
|
+
setUniformImpl(name, UniformValue.INT3, new int[] { x, y, z });
|
406
406
|
}
|
407
407
|
|
408
408
|
/**
|
409
|
-
* @param
|
410
|
-
* @param x
|
411
|
-
* @param y
|
412
|
-
* @param z
|
413
|
-
* @param w fourth component of the variable to modify. The variable has to be
|
414
|
-
* declared with an array/vector type in the shader (i.e.: int[4], vec4)
|
409
|
+
* @param w fourth component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[4], vec4)
|
415
410
|
*/
|
416
411
|
public void set(String name, int x, int y, int z, int w) {
|
417
|
-
setUniformImpl(name, UniformValue.INT4, new int[]{x, y, z, w});
|
412
|
+
setUniformImpl(name, UniformValue.INT4, new int[] { x, y, z, w });
|
418
413
|
}
|
419
414
|
|
415
|
+
|
420
416
|
public void set(String name, float x) {
|
421
|
-
setUniformImpl(name, UniformValue.FLOAT1, new float[]{x});
|
417
|
+
setUniformImpl(name, UniformValue.FLOAT1, new float[] { x });
|
422
418
|
}
|
423
419
|
|
420
|
+
|
424
421
|
public void set(String name, float x, float y) {
|
425
|
-
setUniformImpl(name, UniformValue.FLOAT2, new float[]{x, y});
|
422
|
+
setUniformImpl(name, UniformValue.FLOAT2, new float[] { x, y });
|
426
423
|
}
|
427
424
|
|
425
|
+
|
428
426
|
public void set(String name, float x, float y, float z) {
|
429
|
-
setUniformImpl(name, UniformValue.FLOAT3, new float[]{x, y, z});
|
427
|
+
setUniformImpl(name, UniformValue.FLOAT3, new float[] { x, y, z });
|
430
428
|
}
|
431
429
|
|
430
|
+
|
432
431
|
public void set(String name, float x, float y, float z, float w) {
|
433
|
-
setUniformImpl(name, UniformValue.FLOAT4, new float[]{x, y, z, w});
|
432
|
+
setUniformImpl(name, UniformValue.FLOAT4, new float[] { x, y, z, w });
|
434
433
|
}
|
435
434
|
|
436
435
|
/**
|
437
|
-
* @param
|
438
|
-
* @param vec modifies all the components of an array/vector uniform variable.
|
439
|
-
* PVector can only be used if the type of the variable is vec3.
|
436
|
+
* @param vec modifies all the components of an array/vector uniform variable. PVector can only be used if the type of the variable is vec3.
|
440
437
|
*/
|
441
438
|
public void set(String name, PVector vec) {
|
442
439
|
setUniformImpl(name, UniformValue.FLOAT3,
|
443
|
-
|
440
|
+
new float[] { vec.x, vec.y, vec.z });
|
444
441
|
}
|
445
442
|
|
443
|
+
|
446
444
|
public void set(String name, boolean x) {
|
447
|
-
setUniformImpl(name, UniformValue.INT1, new int[]{(x)
|
445
|
+
setUniformImpl(name, UniformValue.INT1, new int[] { (x)?1:0 });
|
448
446
|
}
|
449
447
|
|
448
|
+
|
450
449
|
public void set(String name, boolean x, boolean y) {
|
451
450
|
setUniformImpl(name, UniformValue.INT2,
|
452
|
-
|
451
|
+
new int[] { (x)?1:0, (y)?1:0 });
|
453
452
|
}
|
454
453
|
|
454
|
+
|
455
455
|
public void set(String name, boolean x, boolean y, boolean z) {
|
456
456
|
setUniformImpl(name, UniformValue.INT3,
|
457
|
-
|
457
|
+
new int[] { (x)?1:0, (y)?1:0, (z)?1:0 });
|
458
458
|
}
|
459
459
|
|
460
|
+
|
460
461
|
public void set(String name, boolean x, boolean y, boolean z, boolean w) {
|
461
462
|
setUniformImpl(name, UniformValue.INT4,
|
462
|
-
|
463
|
+
new int[] { (x)?1:0, (y)?1:0, (z)?1:0, (w)?1:0 });
|
463
464
|
}
|
464
465
|
|
466
|
+
|
465
467
|
public void set(String name, int[] vec) {
|
466
468
|
set(name, vec, 1);
|
467
469
|
}
|
468
470
|
|
471
|
+
|
469
472
|
/**
|
470
|
-
* @param name
|
471
|
-
* @param vec
|
472
473
|
* @param ncoords number of coordinates per element, max 4
|
473
474
|
*/
|
474
475
|
public void set(String name, int[] vec, int ncoords) {
|
@@ -481,17 +482,19 @@ public class PShader implements PConstants {
|
|
481
482
|
} else if (ncoords == 4) {
|
482
483
|
setUniformImpl(name, UniformValue.INT4VEC, vec);
|
483
484
|
} else if (4 < ncoords) {
|
484
|
-
PGraphics.showWarning("Only up to 4 coordinates per element are "
|
485
|
-
|
485
|
+
PGraphics.showWarning("Only up to 4 coordinates per element are " +
|
486
|
+
"supported.");
|
486
487
|
} else {
|
487
488
|
PGraphics.showWarning("Wrong number of coordinates: it is negative!");
|
488
489
|
}
|
489
490
|
}
|
490
491
|
|
492
|
+
|
491
493
|
public void set(String name, float[] vec) {
|
492
494
|
set(name, vec, 1);
|
493
495
|
}
|
494
496
|
|
497
|
+
|
495
498
|
public void set(String name, float[] vec, int ncoords) {
|
496
499
|
if (ncoords == 1) {
|
497
500
|
setUniformImpl(name, UniformValue.FLOAT1VEC, vec);
|
@@ -502,84 +505,86 @@ public class PShader implements PConstants {
|
|
502
505
|
} else if (ncoords == 4) {
|
503
506
|
setUniformImpl(name, UniformValue.FLOAT4VEC, vec);
|
504
507
|
} else if (4 < ncoords) {
|
505
|
-
PGraphics.showWarning("Only up to 4 coordinates per element are "
|
506
|
-
|
508
|
+
PGraphics.showWarning("Only up to 4 coordinates per element are " +
|
509
|
+
"supported.");
|
507
510
|
} else {
|
508
511
|
PGraphics.showWarning("Wrong number of coordinates: it is negative!");
|
509
512
|
}
|
510
513
|
}
|
511
514
|
|
515
|
+
|
512
516
|
public void set(String name, boolean[] vec) {
|
513
517
|
set(name, vec, 1);
|
514
518
|
}
|
515
519
|
|
520
|
+
|
516
521
|
public void set(String name, boolean[] boolvec, int ncoords) {
|
517
522
|
int[] vec = new int[boolvec.length];
|
518
523
|
for (int i = 0; i < boolvec.length; i++) {
|
519
|
-
vec[i] = (boolvec[i])
|
524
|
+
vec[i] = (boolvec[i])?1:0;
|
520
525
|
}
|
521
526
|
set(name, vec, ncoords);
|
522
527
|
}
|
523
528
|
|
529
|
+
|
524
530
|
/**
|
525
|
-
* @param name
|
526
531
|
* @param mat matrix of values
|
527
532
|
*/
|
528
533
|
public void set(String name, PMatrix2D mat) {
|
529
|
-
float[] matv = {mat.m00, mat.m01,
|
530
|
-
|
534
|
+
float[] matv = { mat.m00, mat.m01,
|
535
|
+
mat.m10, mat.m11 };
|
531
536
|
setUniformImpl(name, UniformValue.MAT2, matv);
|
532
537
|
}
|
533
538
|
|
539
|
+
|
534
540
|
public void set(String name, PMatrix3D mat) {
|
535
541
|
set(name, mat, false);
|
536
542
|
}
|
537
543
|
|
538
544
|
/**
|
539
|
-
* @param name
|
540
|
-
* @param mat
|
541
545
|
* @param use3x3 enforces the matrix is 3 x 3
|
542
546
|
*/
|
543
547
|
public void set(String name, PMatrix3D mat, boolean use3x3) {
|
544
548
|
if (use3x3) {
|
545
|
-
float[] matv = {mat.m00, mat.m01, mat.m02,
|
546
|
-
|
547
|
-
|
549
|
+
float[] matv = { mat.m00, mat.m01, mat.m02,
|
550
|
+
mat.m10, mat.m11, mat.m12,
|
551
|
+
mat.m20, mat.m21, mat.m22 };
|
548
552
|
setUniformImpl(name, UniformValue.MAT3, matv);
|
549
553
|
} else {
|
550
|
-
float[] matv = {mat.m00, mat.m01, mat.m02, mat.m03,
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
+
float[] matv = { mat.m00, mat.m01, mat.m02, mat.m03,
|
555
|
+
mat.m10, mat.m11, mat.m12, mat.m13,
|
556
|
+
mat.m20, mat.m21, mat.m22, mat.m23,
|
557
|
+
mat.m30, mat.m31, mat.m32, mat.m33 };
|
554
558
|
setUniformImpl(name, UniformValue.MAT4, matv);
|
555
559
|
}
|
556
560
|
}
|
557
561
|
|
558
562
|
/**
|
559
|
-
* @param
|
560
|
-
* @param tex sets the sampler uniform variable to read from this image
|
561
|
-
* texture
|
563
|
+
* @param tex sets the sampler uniform variable to read from this image texture
|
562
564
|
*/
|
563
565
|
public void set(String name, PImage tex) {
|
564
566
|
setUniformImpl(name, UniformValue.SAMPLER2D, tex);
|
565
567
|
}
|
566
568
|
|
569
|
+
|
567
570
|
/**
|
568
571
|
* Extra initialization method that can be used by subclasses, called after
|
569
|
-
* compiling and attaching the vertex and fragment shaders, and before
|
570
|
-
* the shader program.
|
572
|
+
* compiling and attaching the vertex and fragment shaders, and before
|
573
|
+
* linking the shader program.
|
571
574
|
*
|
572
575
|
*/
|
573
576
|
protected void setup() {
|
574
577
|
}
|
575
578
|
|
579
|
+
|
576
580
|
protected void draw(int idxId, int count, int offset) {
|
577
581
|
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, idxId);
|
578
582
|
pgl.drawElements(PGL.TRIANGLES, count, PGL.INDEX_TYPE,
|
579
|
-
|
583
|
+
offset * PGL.SIZEOF_INDEX);
|
580
584
|
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
|
581
585
|
}
|
582
586
|
|
587
|
+
|
583
588
|
/**
|
584
589
|
* Returns the ID location of the attribute parameter given its name.
|
585
590
|
*
|
@@ -591,6 +596,7 @@ public class PShader implements PConstants {
|
|
591
596
|
return pgl.getAttribLocation(glProgram, name);
|
592
597
|
}
|
593
598
|
|
599
|
+
|
594
600
|
/**
|
595
601
|
* Returns the ID location of the uniform parameter given its name.
|
596
602
|
*
|
@@ -602,38 +608,44 @@ public class PShader implements PConstants {
|
|
602
608
|
return pgl.getUniformLocation(glProgram, name);
|
603
609
|
}
|
604
610
|
|
611
|
+
|
605
612
|
protected void setAttributeVBO(int loc, int vboId, int size, int type,
|
606
|
-
|
613
|
+
boolean normalized, int stride, int offset) {
|
607
614
|
if (-1 < loc) {
|
608
615
|
pgl.bindBuffer(PGL.ARRAY_BUFFER, vboId);
|
609
616
|
pgl.vertexAttribPointer(loc, size, type, normalized, stride, offset);
|
610
617
|
}
|
611
618
|
}
|
612
619
|
|
620
|
+
|
613
621
|
protected void setUniformValue(int loc, int x) {
|
614
622
|
if (-1 < loc) {
|
615
623
|
pgl.uniform1i(loc, x);
|
616
624
|
}
|
617
625
|
}
|
618
626
|
|
627
|
+
|
619
628
|
protected void setUniformValue(int loc, int x, int y) {
|
620
629
|
if (-1 < loc) {
|
621
630
|
pgl.uniform2i(loc, x, y);
|
622
631
|
}
|
623
632
|
}
|
624
633
|
|
634
|
+
|
625
635
|
protected void setUniformValue(int loc, int x, int y, int z) {
|
626
636
|
if (-1 < loc) {
|
627
637
|
pgl.uniform3i(loc, x, y, z);
|
628
638
|
}
|
629
639
|
}
|
630
640
|
|
641
|
+
|
631
642
|
protected void setUniformValue(int loc, int x, int y, int z, int w) {
|
632
643
|
if (-1 < loc) {
|
633
644
|
pgl.uniform4i(loc, x, y, z, w);
|
634
645
|
}
|
635
646
|
}
|
636
647
|
|
648
|
+
|
637
649
|
protected void setUniformValue(int loc, float x) {
|
638
650
|
if (-1 < loc) {
|
639
651
|
pgl.uniform1f(loc, x);
|
@@ -646,83 +658,69 @@ public class PShader implements PConstants {
|
|
646
658
|
}
|
647
659
|
}
|
648
660
|
|
661
|
+
|
649
662
|
protected void setUniformValue(int loc, float x, float y, float z) {
|
650
663
|
if (-1 < loc) {
|
651
664
|
pgl.uniform3f(loc, x, y, z);
|
652
665
|
}
|
653
666
|
}
|
654
667
|
|
668
|
+
|
655
669
|
protected void setUniformValue(int loc, float x, float y, float z, float w) {
|
656
670
|
if (-1 < loc) {
|
657
671
|
pgl.uniform4f(loc, x, y, z, w);
|
658
672
|
}
|
659
673
|
}
|
660
674
|
|
675
|
+
|
661
676
|
protected void setUniformVector(int loc, int[] vec, int ncoords,
|
662
|
-
|
677
|
+
int length) {
|
663
678
|
if (-1 < loc) {
|
664
679
|
updateIntBuffer(vec);
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
pgl.uniform3iv(loc, length, intBuffer);
|
674
|
-
break;
|
675
|
-
case 4:
|
676
|
-
pgl.uniform3iv(loc, length, intBuffer);
|
677
|
-
break;
|
678
|
-
default:
|
679
|
-
break;
|
680
|
+
if (ncoords == 1) {
|
681
|
+
pgl.uniform1iv(loc, length, intBuffer);
|
682
|
+
} else if (ncoords == 2) {
|
683
|
+
pgl.uniform2iv(loc, length, intBuffer);
|
684
|
+
} else if (ncoords == 3) {
|
685
|
+
pgl.uniform3iv(loc, length, intBuffer);
|
686
|
+
} else if (ncoords == 4) {
|
687
|
+
pgl.uniform3iv(loc, length, intBuffer);
|
680
688
|
}
|
681
689
|
}
|
682
690
|
}
|
683
691
|
|
692
|
+
|
684
693
|
protected void setUniformVector(int loc, float[] vec, int ncoords,
|
685
|
-
|
694
|
+
int length) {
|
686
695
|
if (-1 < loc) {
|
687
696
|
updateFloatBuffer(vec);
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
pgl.uniform3fv(loc, length, floatBuffer);
|
697
|
-
break;
|
698
|
-
case 4:
|
699
|
-
pgl.uniform4fv(loc, length, floatBuffer);
|
700
|
-
break;
|
701
|
-
default:
|
702
|
-
break;
|
697
|
+
if (ncoords == 1) {
|
698
|
+
pgl.uniform1fv(loc, length, floatBuffer);
|
699
|
+
} else if (ncoords == 2) {
|
700
|
+
pgl.uniform2fv(loc, length, floatBuffer);
|
701
|
+
} else if (ncoords == 3) {
|
702
|
+
pgl.uniform3fv(loc, length, floatBuffer);
|
703
|
+
} else if (ncoords == 4) {
|
704
|
+
pgl.uniform4fv(loc, length, floatBuffer);
|
703
705
|
}
|
704
706
|
}
|
705
707
|
}
|
706
708
|
|
709
|
+
|
707
710
|
protected void setUniformMatrix(int loc, float[] mat) {
|
708
711
|
if (-1 < loc) {
|
709
712
|
updateFloatBuffer(mat);
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
break;
|
717
|
-
case 16:
|
718
|
-
pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
|
719
|
-
break;
|
720
|
-
default:
|
721
|
-
break;
|
713
|
+
if (mat.length == 4) {
|
714
|
+
pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
|
715
|
+
} else if (mat.length == 9) {
|
716
|
+
pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
|
717
|
+
} else if (mat.length == 16) {
|
718
|
+
pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
|
722
719
|
}
|
723
720
|
}
|
724
721
|
}
|
725
722
|
|
723
|
+
|
726
724
|
protected void setUniformTex(int loc, Texture tex) {
|
727
725
|
if (texUnits != null) {
|
728
726
|
Integer unit = texUnits.get(loc);
|
@@ -735,6 +733,7 @@ public class PShader implements PConstants {
|
|
735
733
|
}
|
736
734
|
}
|
737
735
|
|
736
|
+
|
738
737
|
protected void setUniformImpl(String name, int type, Object value) {
|
739
738
|
if (uniformValues == null) {
|
740
739
|
uniformValues = new HashMap<>();
|
@@ -742,179 +741,123 @@ public class PShader implements PConstants {
|
|
742
741
|
uniformValues.put(name, new UniformValue(type, value));
|
743
742
|
}
|
744
743
|
|
744
|
+
|
745
745
|
protected void consumeUniforms() {
|
746
746
|
if (uniformValues != null && 0 < uniformValues.size()) {
|
747
747
|
int unit = 0;
|
748
|
-
for (String name
|
748
|
+
for (String name: uniformValues.keySet()) {
|
749
749
|
int loc = getUniformLoc(name);
|
750
750
|
if (loc == -1) {
|
751
|
-
PGraphics.showWarning("The shader doesn't have a uniform called \""
|
752
|
-
|
753
|
-
|
751
|
+
PGraphics.showWarning("The shader doesn't have a uniform called \"" +
|
752
|
+
name + "\" OR the uniform was removed during " +
|
753
|
+
"compilation because it was unused.");
|
754
754
|
continue;
|
755
755
|
}
|
756
756
|
UniformValue val = uniformValues.get(name);
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
case UniformValue.FLOAT2VEC:
|
842
|
-
{
|
843
|
-
float[] v = ((float[]) val.value);
|
844
|
-
updateFloatBuffer(v);
|
845
|
-
pgl.uniform2fv(loc, v.length / 2, floatBuffer);
|
846
|
-
break;
|
847
|
-
}
|
848
|
-
case UniformValue.FLOAT3VEC:
|
849
|
-
{
|
850
|
-
float[] v = ((float[]) val.value);
|
851
|
-
updateFloatBuffer(v);
|
852
|
-
pgl.uniform3fv(loc, v.length / 3, floatBuffer);
|
853
|
-
break;
|
854
|
-
}
|
855
|
-
case UniformValue.FLOAT4VEC:
|
856
|
-
{
|
857
|
-
float[] v = ((float[]) val.value);
|
858
|
-
updateFloatBuffer(v);
|
859
|
-
pgl.uniform4fv(loc, v.length / 4, floatBuffer);
|
860
|
-
break;
|
861
|
-
}
|
862
|
-
case UniformValue.MAT2:
|
863
|
-
{
|
864
|
-
float[] v = ((float[]) val.value);
|
865
|
-
updateFloatBuffer(v);
|
866
|
-
pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
|
867
|
-
break;
|
868
|
-
}
|
869
|
-
case UniformValue.MAT3:
|
870
|
-
{
|
871
|
-
float[] v = ((float[]) val.value);
|
872
|
-
updateFloatBuffer(v);
|
873
|
-
pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
|
874
|
-
break;
|
875
|
-
}
|
876
|
-
case UniformValue.MAT4:
|
877
|
-
{
|
878
|
-
float[] v = ((float[]) val.value);
|
879
|
-
updateFloatBuffer(v);
|
880
|
-
pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
|
881
|
-
break;
|
882
|
-
}
|
883
|
-
case UniformValue.SAMPLER2D:
|
884
|
-
PImage img = (PImage) val.value;
|
885
|
-
Texture tex = currentPG.getTexture(img);
|
886
|
-
if (textures == null) {
|
887
|
-
textures = new HashMap<>();
|
888
|
-
} textures.put(loc, tex);
|
889
|
-
if (texUnits == null) {
|
890
|
-
texUnits = new HashMap<>();
|
891
|
-
} if (texUnits.containsKey(loc)) {
|
892
|
-
unit = texUnits.get(loc);
|
893
|
-
pgl.uniform1i(loc, unit);
|
894
|
-
} else {
|
895
|
-
texUnits.put(loc, unit);
|
896
|
-
pgl.uniform1i(loc, unit);
|
897
|
-
} unit++;
|
898
|
-
break;
|
899
|
-
default:
|
900
|
-
break;
|
757
|
+
if (val.type == UniformValue.INT1) {
|
758
|
+
int[] v = ((int[])val.value);
|
759
|
+
pgl.uniform1i(loc, v[0]);
|
760
|
+
} else if (val.type == UniformValue.INT2) {
|
761
|
+
int[] v = ((int[])val.value);
|
762
|
+
pgl.uniform2i(loc, v[0], v[1]);
|
763
|
+
} else if (val.type == UniformValue.INT3) {
|
764
|
+
int[] v = ((int[])val.value);
|
765
|
+
pgl.uniform3i(loc, v[0], v[1], v[2]);
|
766
|
+
} else if (val.type == UniformValue.INT4) {
|
767
|
+
int[] v = ((int[])val.value);
|
768
|
+
pgl.uniform4i(loc, v[0], v[1], v[2], v[3]);
|
769
|
+
} else if (val.type == UniformValue.FLOAT1) {
|
770
|
+
float[] v = ((float[])val.value);
|
771
|
+
pgl.uniform1f(loc, v[0]);
|
772
|
+
} else if (val.type == UniformValue.FLOAT2) {
|
773
|
+
float[] v = ((float[])val.value);
|
774
|
+
pgl.uniform2f(loc, v[0], v[1]);
|
775
|
+
} else if (val.type == UniformValue.FLOAT3) {
|
776
|
+
float[] v = ((float[])val.value);
|
777
|
+
pgl.uniform3f(loc, v[0], v[1], v[2]);
|
778
|
+
} else if (val.type == UniformValue.FLOAT4) {
|
779
|
+
float[] v = ((float[])val.value);
|
780
|
+
pgl.uniform4f(loc, v[0], v[1], v[2], v[3]);
|
781
|
+
} else if (val.type == UniformValue.INT1VEC) {
|
782
|
+
int[] v = ((int[])val.value);
|
783
|
+
updateIntBuffer(v);
|
784
|
+
pgl.uniform1iv(loc, v.length, intBuffer);
|
785
|
+
} else if (val.type == UniformValue.INT2VEC) {
|
786
|
+
int[] v = ((int[])val.value);
|
787
|
+
updateIntBuffer(v);
|
788
|
+
pgl.uniform2iv(loc, v.length / 2, intBuffer);
|
789
|
+
} else if (val.type == UniformValue.INT3VEC) {
|
790
|
+
int[] v = ((int[])val.value);
|
791
|
+
updateIntBuffer(v);
|
792
|
+
pgl.uniform3iv(loc, v.length / 3, intBuffer);
|
793
|
+
} else if (val.type == UniformValue.INT4VEC) {
|
794
|
+
int[] v = ((int[])val.value);
|
795
|
+
updateIntBuffer(v);
|
796
|
+
pgl.uniform4iv(loc, v.length / 4, intBuffer);
|
797
|
+
} else if (val.type == UniformValue.FLOAT1VEC) {
|
798
|
+
float[] v = ((float[])val.value);
|
799
|
+
updateFloatBuffer(v);
|
800
|
+
pgl.uniform1fv(loc, v.length, floatBuffer);
|
801
|
+
} else if (val.type == UniformValue.FLOAT2VEC) {
|
802
|
+
float[] v = ((float[])val.value);
|
803
|
+
updateFloatBuffer(v);
|
804
|
+
pgl.uniform2fv(loc, v.length / 2, floatBuffer);
|
805
|
+
} else if (val.type == UniformValue.FLOAT3VEC) {
|
806
|
+
float[] v = ((float[])val.value);
|
807
|
+
updateFloatBuffer(v);
|
808
|
+
pgl.uniform3fv(loc, v.length / 3, floatBuffer);
|
809
|
+
} else if (val.type == UniformValue.FLOAT4VEC) {
|
810
|
+
float[] v = ((float[])val.value);
|
811
|
+
updateFloatBuffer(v);
|
812
|
+
pgl.uniform4fv(loc, v.length / 4, floatBuffer);
|
813
|
+
} else if (val.type == UniformValue.MAT2) {
|
814
|
+
float[] v = ((float[])val.value);
|
815
|
+
updateFloatBuffer(v);
|
816
|
+
pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
|
817
|
+
} else if (val.type == UniformValue.MAT3) {
|
818
|
+
float[] v = ((float[])val.value);
|
819
|
+
updateFloatBuffer(v);
|
820
|
+
pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
|
821
|
+
} else if (val.type == UniformValue.MAT4) {
|
822
|
+
float[] v = ((float[])val.value);
|
823
|
+
updateFloatBuffer(v);
|
824
|
+
pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
|
825
|
+
} else if (val.type == UniformValue.SAMPLER2D) {
|
826
|
+
PImage img = (PImage)val.value;
|
827
|
+
Texture tex = currentPG.getTexture(img);
|
828
|
+
|
829
|
+
if (textures == null) textures = new HashMap<>();
|
830
|
+
textures.put(loc, tex);
|
831
|
+
|
832
|
+
if (texUnits == null) texUnits = new HashMap<Integer, Integer>();
|
833
|
+
if (texUnits.containsKey(loc)) {
|
834
|
+
unit = texUnits.get(loc);
|
835
|
+
pgl.uniform1i(loc, unit);
|
836
|
+
} else {
|
837
|
+
texUnits.put(loc, unit);
|
838
|
+
pgl.uniform1i(loc, unit);
|
839
|
+
}
|
840
|
+
unit++;
|
901
841
|
}
|
902
842
|
}
|
903
843
|
uniformValues.clear();
|
904
844
|
}
|
905
845
|
}
|
906
846
|
|
847
|
+
|
907
848
|
protected void updateIntBuffer(int[] vec) {
|
908
849
|
intBuffer = PGL.updateIntBuffer(intBuffer, vec, false);
|
909
850
|
}
|
910
851
|
|
852
|
+
|
911
853
|
protected void updateFloatBuffer(float[] vec) {
|
912
854
|
floatBuffer = PGL.updateFloatBuffer(floatBuffer, vec, false);
|
913
855
|
}
|
914
856
|
|
857
|
+
|
915
858
|
protected void bindTextures() {
|
916
859
|
if (textures != null && texUnits != null) {
|
917
|
-
textures.keySet()
|
860
|
+
for (int loc: textures.keySet()) {
|
918
861
|
Texture tex = textures.get(loc);
|
919
862
|
Integer unit = texUnits.get(loc);
|
920
863
|
if (unit != null) {
|
@@ -923,10 +866,11 @@ public class PShader implements PConstants {
|
|
923
866
|
} else {
|
924
867
|
throw new RuntimeException("Cannot find unit for texture " + tex);
|
925
868
|
}
|
926
|
-
}
|
869
|
+
}
|
927
870
|
}
|
928
871
|
}
|
929
872
|
|
873
|
+
|
930
874
|
protected void unbindTextures() {
|
931
875
|
if (textures != null && texUnits != null) {
|
932
876
|
textures.keySet().forEach((loc) -> {
|
@@ -943,6 +887,7 @@ public class PShader implements PConstants {
|
|
943
887
|
}
|
944
888
|
}
|
945
889
|
|
890
|
+
|
946
891
|
public void init() {
|
947
892
|
if (glProgram == 0 || contextIsOutdated()) {
|
948
893
|
create();
|
@@ -959,11 +904,13 @@ public class PShader implements PConstants {
|
|
959
904
|
}
|
960
905
|
}
|
961
906
|
|
907
|
+
|
962
908
|
protected void create() {
|
963
909
|
context = pgl.getCurrentContext();
|
964
910
|
glres = new GLResourceShader(this);
|
965
911
|
}
|
966
912
|
|
913
|
+
|
967
914
|
protected boolean compile() {
|
968
915
|
boolean vertRes = true;
|
969
916
|
if (hasVertexShader()) {
|
@@ -982,23 +929,25 @@ public class PShader implements PConstants {
|
|
982
929
|
return vertRes && fragRes;
|
983
930
|
}
|
984
931
|
|
932
|
+
|
985
933
|
protected void validate() {
|
986
934
|
pgl.getProgramiv(glProgram, PGL.LINK_STATUS, intBuffer);
|
987
935
|
boolean linked = intBuffer.get(0) != 0;
|
988
936
|
if (!linked) {
|
989
|
-
PGraphics.showException("Cannot link shader program:\n"
|
990
|
-
|
937
|
+
PGraphics.showException("Cannot link shader program:\n" +
|
938
|
+
pgl.getProgramInfoLog(glProgram));
|
991
939
|
}
|
992
940
|
|
993
941
|
pgl.validateProgram(glProgram);
|
994
942
|
pgl.getProgramiv(glProgram, PGL.VALIDATE_STATUS, intBuffer);
|
995
943
|
boolean validated = intBuffer.get(0) != 0;
|
996
944
|
if (!validated) {
|
997
|
-
PGraphics.showException("Cannot validate shader program:\n"
|
998
|
-
|
945
|
+
PGraphics.showException("Cannot validate shader program:\n" +
|
946
|
+
pgl.getProgramInfoLog(glProgram));
|
999
947
|
}
|
1000
948
|
}
|
1001
949
|
|
950
|
+
|
1002
951
|
protected boolean contextIsOutdated() {
|
1003
952
|
boolean outdated = !pgl.contextIsCurrent(context);
|
1004
953
|
if (outdated) {
|
@@ -1007,32 +956,37 @@ public class PShader implements PConstants {
|
|
1007
956
|
return outdated;
|
1008
957
|
}
|
1009
958
|
|
959
|
+
|
960
|
+
|
1010
961
|
protected boolean hasVertexShader() {
|
1011
962
|
return vertexShaderSource != null && 0 < vertexShaderSource.length;
|
1012
963
|
}
|
1013
964
|
|
965
|
+
|
1014
966
|
protected boolean hasFragmentShader() {
|
1015
967
|
return fragmentShaderSource != null && 0 < fragmentShaderSource.length;
|
1016
968
|
}
|
1017
969
|
|
970
|
+
|
1018
971
|
/**
|
1019
|
-
* @
|
972
|
+
* @param shaderSource a string containing the shader's code
|
1020
973
|
*/
|
1021
974
|
protected boolean compileVertexShader() {
|
1022
975
|
pgl.shaderSource(glVertex, PApplet.join(vertexShaderSource, "\n"));
|
1023
976
|
pgl.compileShader(glVertex);
|
1024
977
|
|
1025
978
|
pgl.getShaderiv(glVertex, PGL.COMPILE_STATUS, intBuffer);
|
1026
|
-
boolean compiled = intBuffer.get(0)
|
979
|
+
boolean compiled = intBuffer.get(0) == 0 ? false : true;
|
1027
980
|
if (!compiled) {
|
1028
|
-
PGraphics.showException("Cannot compile vertex shader:\n"
|
1029
|
-
|
981
|
+
PGraphics.showException("Cannot compile vertex shader:\n" +
|
982
|
+
pgl.getShaderInfoLog(glVertex));
|
1030
983
|
return false;
|
1031
984
|
} else {
|
1032
985
|
return true;
|
1033
986
|
}
|
1034
987
|
}
|
1035
988
|
|
989
|
+
|
1036
990
|
/**
|
1037
991
|
* @return
|
1038
992
|
*/
|
@@ -1043,14 +997,15 @@ public class PShader implements PConstants {
|
|
1043
997
|
pgl.getShaderiv(glFragment, PGL.COMPILE_STATUS, intBuffer);
|
1044
998
|
boolean compiled = intBuffer.get(0) != 0;
|
1045
999
|
if (!compiled) {
|
1046
|
-
PGraphics.showException("Cannot compile fragment shader:\n"
|
1047
|
-
|
1000
|
+
PGraphics.showException("Cannot compile fragment shader:\n" +
|
1001
|
+
pgl.getShaderInfoLog(glFragment));
|
1048
1002
|
return false;
|
1049
1003
|
} else {
|
1050
1004
|
return true;
|
1051
1005
|
}
|
1052
1006
|
}
|
1053
1007
|
|
1008
|
+
|
1054
1009
|
protected void dispose() {
|
1055
1010
|
if (glres != null) {
|
1056
1011
|
glres.dispose();
|
@@ -1061,71 +1016,78 @@ public class PShader implements PConstants {
|
|
1061
1016
|
}
|
1062
1017
|
}
|
1063
1018
|
|
1019
|
+
|
1064
1020
|
static protected int getShaderType(String[] source, int defaultType) {
|
1065
1021
|
for (String source1 : source) {
|
1066
1022
|
String line = source1.trim();
|
1067
|
-
if (PApplet.match(line, colorShaderDefRegexp) != null)
|
1023
|
+
if (PApplet.match(line, colorShaderDefRegexp) != null)
|
1068
1024
|
return PShader.COLOR;
|
1069
|
-
|
1025
|
+
else if (PApplet.match(line, lightShaderDefRegexp) != null)
|
1070
1026
|
return PShader.LIGHT;
|
1071
|
-
|
1027
|
+
else if (PApplet.match(line, texShaderDefRegexp) != null)
|
1072
1028
|
return PShader.TEXTURE;
|
1073
|
-
|
1029
|
+
else if (PApplet.match(line, texlightShaderDefRegexp) != null)
|
1074
1030
|
return PShader.TEXLIGHT;
|
1075
|
-
|
1031
|
+
else if (PApplet.match(line, polyShaderDefRegexp) != null)
|
1076
1032
|
return PShader.POLY;
|
1077
|
-
|
1033
|
+
else if (PApplet.match(line, triShaderAttrRegexp) != null)
|
1078
1034
|
return PShader.POLY;
|
1079
|
-
|
1035
|
+
else if (PApplet.match(line, quadShaderAttrRegexp) != null)
|
1080
1036
|
return PShader.POLY;
|
1081
|
-
|
1037
|
+
else if (PApplet.match(line, pointShaderDefRegexp) != null)
|
1082
1038
|
return PShader.POINT;
|
1083
|
-
|
1039
|
+
else if (PApplet.match(line, lineShaderDefRegexp) != null)
|
1084
1040
|
return PShader.LINE;
|
1085
|
-
|
1041
|
+
else if (PApplet.match(line, pointShaderAttrRegexp) != null)
|
1086
1042
|
return PShader.POINT;
|
1087
|
-
|
1043
|
+
else if (PApplet.match(line, pointShaderInRegexp) != null)
|
1088
1044
|
return PShader.POINT;
|
1089
|
-
|
1045
|
+
else if (PApplet.match(line, lineShaderAttrRegexp) != null)
|
1090
1046
|
return PShader.LINE;
|
1091
|
-
|
1047
|
+
else if (PApplet.match(line, lineShaderInRegexp) != null)
|
1092
1048
|
return PShader.LINE;
|
1093
|
-
}
|
1094
1049
|
}
|
1095
1050
|
return defaultType;
|
1096
1051
|
}
|
1097
1052
|
|
1053
|
+
|
1098
1054
|
// ***************************************************************************
|
1099
1055
|
//
|
1100
1056
|
// Processing specific
|
1057
|
+
|
1058
|
+
|
1101
1059
|
protected int getType() {
|
1102
1060
|
return type;
|
1103
1061
|
}
|
1104
1062
|
|
1063
|
+
|
1105
1064
|
protected void setType(int type) {
|
1106
1065
|
this.type = type;
|
1107
1066
|
}
|
1108
1067
|
|
1068
|
+
|
1109
1069
|
protected boolean hasType() {
|
1110
1070
|
return POINT <= type && type <= TEXLIGHT;
|
1111
1071
|
}
|
1112
1072
|
|
1073
|
+
|
1113
1074
|
protected boolean isPointShader() {
|
1114
1075
|
return type == POINT;
|
1115
1076
|
}
|
1116
1077
|
|
1078
|
+
|
1117
1079
|
protected boolean isLineShader() {
|
1118
1080
|
return type == LINE;
|
1119
1081
|
}
|
1120
1082
|
|
1083
|
+
|
1121
1084
|
protected boolean isPolyShader() {
|
1122
1085
|
return POLY <= type && type <= TEXLIGHT;
|
1123
1086
|
}
|
1124
1087
|
|
1088
|
+
|
1125
1089
|
protected boolean checkPolyType(int type) {
|
1126
|
-
if (getType() == PShader.POLY)
|
1127
|
-
return true;
|
1128
|
-
}
|
1090
|
+
if (getType() == PShader.POLY) return true;
|
1129
1091
|
|
1130
1092
|
if (getType() != type) {
|
1131
1093
|
switch (type) {
|
@@ -1150,23 +1112,22 @@ public class PShader implements PConstants {
|
|
1150
1112
|
return true;
|
1151
1113
|
}
|
1152
1114
|
|
1115
|
+
|
1153
1116
|
protected int getLastTexUnit() {
|
1154
1117
|
return texUnits == null ? -1 : texUnits.size() - 1;
|
1155
1118
|
}
|
1156
1119
|
|
1120
|
+
|
1157
1121
|
protected void setRenderer(PGraphicsOpenGL pg) {
|
1158
1122
|
this.currentPG = pg;
|
1159
1123
|
}
|
1160
1124
|
|
1125
|
+
|
1161
1126
|
protected void loadAttributes() {
|
1162
|
-
if (loadedAttributes)
|
1163
|
-
return;
|
1164
|
-
}
|
1127
|
+
if (loadedAttributes) return;
|
1165
1128
|
|
1166
1129
|
vertexLoc = getAttributeLoc("vertex");
|
1167
|
-
if (vertexLoc == -1)
|
1168
|
-
vertexLoc = getAttributeLoc("position");
|
1169
|
-
}
|
1130
|
+
if (vertexLoc == -1) vertexLoc = getAttributeLoc("position");
|
1170
1131
|
|
1171
1132
|
colorLoc = getAttributeLoc("color");
|
1172
1133
|
texCoordLoc = getAttributeLoc("texCoord");
|
@@ -1187,24 +1148,20 @@ public class PShader implements PConstants {
|
|
1187
1148
|
loadedAttributes = true;
|
1188
1149
|
}
|
1189
1150
|
|
1151
|
+
|
1190
1152
|
protected void loadUniforms() {
|
1191
|
-
if (loadedUniforms)
|
1192
|
-
return;
|
1193
|
-
}
|
1153
|
+
if (loadedUniforms) return;
|
1194
1154
|
transformMatLoc = getUniformLoc("transform");
|
1195
|
-
if (transformMatLoc == -1)
|
1155
|
+
if (transformMatLoc == -1)
|
1196
1156
|
transformMatLoc = getUniformLoc("transformMatrix");
|
1197
|
-
}
|
1198
1157
|
|
1199
1158
|
modelviewMatLoc = getUniformLoc("modelview");
|
1200
|
-
if (modelviewMatLoc == -1)
|
1159
|
+
if (modelviewMatLoc == -1)
|
1201
1160
|
modelviewMatLoc = getUniformLoc("modelviewMatrix");
|
1202
|
-
}
|
1203
1161
|
|
1204
1162
|
projectionMatLoc = getUniformLoc("projection");
|
1205
|
-
if (projectionMatLoc == -1)
|
1163
|
+
if (projectionMatLoc == -1)
|
1206
1164
|
projectionMatLoc = getUniformLoc("projectionMatrix");
|
1207
|
-
}
|
1208
1165
|
|
1209
1166
|
viewportLoc = getUniformLoc("viewport");
|
1210
1167
|
resolutionLoc = getUniformLoc("resolution");
|
@@ -1234,6 +1191,7 @@ public class PShader implements PConstants {
|
|
1234
1191
|
loadedUniforms = true;
|
1235
1192
|
}
|
1236
1193
|
|
1194
|
+
|
1237
1195
|
protected void setCommonUniforms() {
|
1238
1196
|
if (-1 < transformMatLoc) {
|
1239
1197
|
currentPG.updateGLProjmodelview();
|
@@ -1274,6 +1232,7 @@ public class PShader implements PConstants {
|
|
1274
1232
|
}
|
1275
1233
|
}
|
1276
1234
|
|
1235
|
+
|
1277
1236
|
protected void bindTyped() {
|
1278
1237
|
if (currentPG == null) {
|
1279
1238
|
setRenderer(primaryPG.getCurrentPG());
|
@@ -1282,36 +1241,20 @@ public class PShader implements PConstants {
|
|
1282
1241
|
}
|
1283
1242
|
setCommonUniforms();
|
1284
1243
|
|
1285
|
-
if (-1 < vertexLoc)
|
1286
|
-
|
1287
|
-
|
1288
|
-
if (-1 <
|
1289
|
-
pgl.enableVertexAttribArray(colorLoc);
|
1290
|
-
}
|
1291
|
-
if (-1 < texCoordLoc) {
|
1292
|
-
pgl.enableVertexAttribArray(texCoordLoc);
|
1293
|
-
}
|
1294
|
-
if (-1 < normalLoc) {
|
1295
|
-
pgl.enableVertexAttribArray(normalLoc);
|
1296
|
-
}
|
1244
|
+
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
|
1245
|
+
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
|
1246
|
+
if (-1 < texCoordLoc) pgl.enableVertexAttribArray(texCoordLoc);
|
1247
|
+
if (-1 < normalLoc) pgl.enableVertexAttribArray(normalLoc);
|
1297
1248
|
|
1298
1249
|
if (-1 < normalMatLoc) {
|
1299
1250
|
currentPG.updateGLNormal();
|
1300
1251
|
setUniformMatrix(normalMatLoc, currentPG.glNormal);
|
1301
1252
|
}
|
1302
1253
|
|
1303
|
-
if (-1 < ambientLoc)
|
1304
|
-
|
1305
|
-
|
1306
|
-
if (-1 <
|
1307
|
-
pgl.enableVertexAttribArray(specularLoc);
|
1308
|
-
}
|
1309
|
-
if (-1 < emissiveLoc) {
|
1310
|
-
pgl.enableVertexAttribArray(emissiveLoc);
|
1311
|
-
}
|
1312
|
-
if (-1 < shininessLoc) {
|
1313
|
-
pgl.enableVertexAttribArray(shininessLoc);
|
1314
|
-
}
|
1254
|
+
if (-1 < ambientLoc) pgl.enableVertexAttribArray(ambientLoc);
|
1255
|
+
if (-1 < specularLoc) pgl.enableVertexAttribArray(specularLoc);
|
1256
|
+
if (-1 < emissiveLoc) pgl.enableVertexAttribArray(emissiveLoc);
|
1257
|
+
if (-1 < shininessLoc) pgl.enableVertexAttribArray(shininessLoc);
|
1315
1258
|
|
1316
1259
|
int count = currentPG.lightCount;
|
1317
1260
|
setUniformValue(lightCountLoc, count);
|
@@ -1322,21 +1265,17 @@ public class PShader implements PConstants {
|
|
1322
1265
|
setUniformVector(lightDiffuseLoc, currentPG.lightDiffuse, 3, count);
|
1323
1266
|
setUniformVector(lightSpecularLoc, currentPG.lightSpecular, 3, count);
|
1324
1267
|
setUniformVector(lightFalloffLoc, currentPG.lightFalloffCoefficients,
|
1325
|
-
|
1268
|
+
3, count);
|
1326
1269
|
setUniformVector(lightSpotLoc, currentPG.lightSpotParameters, 2, count);
|
1327
1270
|
}
|
1328
1271
|
|
1329
|
-
if (-1 < directionLoc)
|
1330
|
-
pgl.enableVertexAttribArray(directionLoc);
|
1331
|
-
}
|
1272
|
+
if (-1 < directionLoc) pgl.enableVertexAttribArray(directionLoc);
|
1332
1273
|
|
1333
|
-
if (-1 < offsetLoc)
|
1334
|
-
pgl.enableVertexAttribArray(offsetLoc);
|
1335
|
-
}
|
1274
|
+
if (-1 < offsetLoc) pgl.enableVertexAttribArray(offsetLoc);
|
1336
1275
|
|
1337
1276
|
if (-1 < perspectiveLoc) {
|
1338
|
-
if (currentPG.getHint(ENABLE_STROKE_PERSPECTIVE)
|
1339
|
-
|
1277
|
+
if (currentPG.getHint(ENABLE_STROKE_PERSPECTIVE) &&
|
1278
|
+
currentPG.nonOrthoProjection()) {
|
1340
1279
|
setUniformValue(perspectiveLoc, 1);
|
1341
1280
|
} else {
|
1342
1281
|
setUniformValue(perspectiveLoc, 0);
|
@@ -1358,13 +1297,9 @@ public class PShader implements PConstants {
|
|
1358
1297
|
}
|
1359
1298
|
|
1360
1299
|
protected void unbindTyped() {
|
1361
|
-
if (-1 < offsetLoc)
|
1362
|
-
pgl.disableVertexAttribArray(offsetLoc);
|
1363
|
-
}
|
1300
|
+
if (-1 < offsetLoc) pgl.disableVertexAttribArray(offsetLoc);
|
1364
1301
|
|
1365
|
-
if (-1 < directionLoc)
|
1366
|
-
pgl.disableVertexAttribArray(directionLoc);
|
1367
|
-
}
|
1302
|
+
if (-1 < directionLoc) pgl.disableVertexAttribArray(directionLoc);
|
1368
1303
|
|
1369
1304
|
if (-1 < textureLoc && texture != null) {
|
1370
1305
|
pgl.activeTexture(PGL.TEXTURE0 + texUnit);
|
@@ -1373,31 +1308,15 @@ public class PShader implements PConstants {
|
|
1373
1308
|
texture = null;
|
1374
1309
|
}
|
1375
1310
|
|
1376
|
-
if (-1 < ambientLoc)
|
1377
|
-
|
1378
|
-
|
1379
|
-
if (-1 <
|
1380
|
-
pgl.disableVertexAttribArray(specularLoc);
|
1381
|
-
}
|
1382
|
-
if (-1 < emissiveLoc) {
|
1383
|
-
pgl.disableVertexAttribArray(emissiveLoc);
|
1384
|
-
}
|
1385
|
-
if (-1 < shininessLoc) {
|
1386
|
-
pgl.disableVertexAttribArray(shininessLoc);
|
1387
|
-
}
|
1311
|
+
if (-1 < ambientLoc) pgl.disableVertexAttribArray(ambientLoc);
|
1312
|
+
if (-1 < specularLoc) pgl.disableVertexAttribArray(specularLoc);
|
1313
|
+
if (-1 < emissiveLoc) pgl.disableVertexAttribArray(emissiveLoc);
|
1314
|
+
if (-1 < shininessLoc) pgl.disableVertexAttribArray(shininessLoc);
|
1388
1315
|
|
1389
|
-
if (-1 < vertexLoc)
|
1390
|
-
|
1391
|
-
|
1392
|
-
if (-1 <
|
1393
|
-
pgl.disableVertexAttribArray(colorLoc);
|
1394
|
-
}
|
1395
|
-
if (-1 < texCoordLoc) {
|
1396
|
-
pgl.disableVertexAttribArray(texCoordLoc);
|
1397
|
-
}
|
1398
|
-
if (-1 < normalLoc) {
|
1399
|
-
pgl.disableVertexAttribArray(normalLoc);
|
1400
|
-
}
|
1316
|
+
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
|
1317
|
+
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
|
1318
|
+
if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc);
|
1319
|
+
if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc);
|
1401
1320
|
|
1402
1321
|
if (-1 < ppixelsLoc) {
|
1403
1322
|
pgl.enableFBOLayer();
|
@@ -1414,29 +1333,29 @@ public class PShader implements PConstants {
|
|
1414
1333
|
|
1415
1334
|
float scaleu = 1;
|
1416
1335
|
float scalev = 1;
|
1417
|
-
float dispu
|
1418
|
-
float dispv
|
1336
|
+
float dispu = 0;
|
1337
|
+
float dispv = 0;
|
1419
1338
|
|
1420
1339
|
if (tex != null) {
|
1421
1340
|
if (tex.invertedX()) {
|
1422
1341
|
scaleu = -1;
|
1423
|
-
dispu
|
1342
|
+
dispu = 1;
|
1424
1343
|
}
|
1425
1344
|
|
1426
1345
|
if (tex.invertedY()) {
|
1427
1346
|
scalev = -1;
|
1428
|
-
dispv
|
1347
|
+
dispv = 1;
|
1429
1348
|
}
|
1430
1349
|
|
1431
1350
|
scaleu *= tex.maxTexcoordU();
|
1432
|
-
dispu
|
1351
|
+
dispu *= tex.maxTexcoordU();
|
1433
1352
|
scalev *= tex.maxTexcoordV();
|
1434
|
-
dispv
|
1353
|
+
dispv *= tex.maxTexcoordV();
|
1435
1354
|
|
1436
1355
|
setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
|
1437
1356
|
|
1438
1357
|
if (-1 < textureLoc) {
|
1439
|
-
texUnit =
|
1358
|
+
texUnit = -1 < ppixelsUnit ? ppixelsUnit + 1 : getLastTexUnit() + 1;
|
1440
1359
|
setUniformValue(textureLoc, texUnit);
|
1441
1360
|
pgl.activeTexture(PGL.TEXTURE0 + texUnit);
|
1442
1361
|
tex.bind();
|
@@ -1447,26 +1366,15 @@ public class PShader implements PConstants {
|
|
1447
1366
|
if (tcmat == null) {
|
1448
1367
|
tcmat = new float[16];
|
1449
1368
|
}
|
1450
|
-
tcmat[0] = scaleu;
|
1451
|
-
tcmat[
|
1452
|
-
tcmat[
|
1453
|
-
tcmat[
|
1454
|
-
tcmat[1] = 0;
|
1455
|
-
tcmat[5] = scalev;
|
1456
|
-
tcmat[9] = 0;
|
1457
|
-
tcmat[13] = dispv;
|
1458
|
-
tcmat[2] = 0;
|
1459
|
-
tcmat[6] = 0;
|
1460
|
-
tcmat[10] = 0;
|
1461
|
-
tcmat[14] = 0;
|
1462
|
-
tcmat[3] = 0;
|
1463
|
-
tcmat[7] = 0;
|
1464
|
-
tcmat[11] = 0;
|
1465
|
-
tcmat[15] = 0;
|
1369
|
+
tcmat[0] = scaleu; tcmat[4] = 0; tcmat[ 8] = 0; tcmat[12] = dispu;
|
1370
|
+
tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv;
|
1371
|
+
tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0;
|
1372
|
+
tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0;
|
1466
1373
|
setUniformMatrix(texMatrixLoc, tcmat);
|
1467
1374
|
}
|
1468
1375
|
}
|
1469
1376
|
|
1377
|
+
|
1470
1378
|
protected boolean supportsTexturing() {
|
1471
1379
|
return -1 < textureLoc;
|
1472
1380
|
}
|
@@ -1484,85 +1392,85 @@ public class PShader implements PConstants {
|
|
1484
1392
|
}
|
1485
1393
|
|
1486
1394
|
protected boolean accessLightAttribs() {
|
1487
|
-
return -1 < ambientLoc || -1 < specularLoc || -1 < emissiveLoc
|
1488
|
-
|
1395
|
+
return -1 < ambientLoc || -1 < specularLoc || -1 < emissiveLoc ||
|
1396
|
+
-1 < shininessLoc;
|
1489
1397
|
}
|
1490
1398
|
|
1491
1399
|
protected void setVertexAttribute(int vboId, int size, int type,
|
1492
|
-
|
1400
|
+
int stride, int offset) {
|
1493
1401
|
setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
|
1494
1402
|
}
|
1495
1403
|
|
1496
1404
|
protected void setColorAttribute(int vboId, int size, int type,
|
1497
|
-
|
1405
|
+
int stride, int offset) {
|
1498
1406
|
setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
|
1499
1407
|
}
|
1500
1408
|
|
1501
1409
|
protected void setNormalAttribute(int vboId, int size, int type,
|
1502
|
-
|
1410
|
+
int stride, int offset) {
|
1503
1411
|
setAttributeVBO(normalLoc, vboId, size, type, false, stride, offset);
|
1504
1412
|
}
|
1505
1413
|
|
1506
1414
|
protected void setTexcoordAttribute(int vboId, int size, int type,
|
1507
|
-
|
1415
|
+
int stride, int offset) {
|
1508
1416
|
setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset);
|
1509
1417
|
}
|
1510
1418
|
|
1511
1419
|
protected void setAmbientAttribute(int vboId, int size, int type,
|
1512
|
-
|
1420
|
+
int stride, int offset) {
|
1513
1421
|
setAttributeVBO(ambientLoc, vboId, size, type, true, stride, offset);
|
1514
1422
|
}
|
1515
1423
|
|
1516
1424
|
protected void setSpecularAttribute(int vboId, int size, int type,
|
1517
|
-
|
1425
|
+
int stride, int offset) {
|
1518
1426
|
setAttributeVBO(specularLoc, vboId, size, type, true, stride, offset);
|
1519
1427
|
}
|
1520
1428
|
|
1521
1429
|
protected void setEmissiveAttribute(int vboId, int size, int type,
|
1522
|
-
|
1430
|
+
int stride, int offset) {
|
1523
1431
|
setAttributeVBO(emissiveLoc, vboId, size, type, true, stride, offset);
|
1524
1432
|
}
|
1525
1433
|
|
1526
1434
|
protected void setShininessAttribute(int vboId, int size, int type,
|
1527
|
-
|
1435
|
+
int stride, int offset) {
|
1528
1436
|
setAttributeVBO(shininessLoc, vboId, size, type, false, stride, offset);
|
1529
1437
|
}
|
1530
1438
|
|
1531
1439
|
protected void setLineAttribute(int vboId, int size, int type,
|
1532
|
-
|
1440
|
+
int stride, int offset) {
|
1533
1441
|
setAttributeVBO(directionLoc, vboId, size, type, false, stride, offset);
|
1534
1442
|
}
|
1535
1443
|
|
1536
1444
|
protected void setPointAttribute(int vboId, int size, int type,
|
1537
|
-
|
1445
|
+
int stride, int offset) {
|
1538
1446
|
setAttributeVBO(offsetLoc, vboId, size, type, false, stride, offset);
|
1539
1447
|
}
|
1540
1448
|
|
1449
|
+
|
1541
1450
|
// ***************************************************************************
|
1542
1451
|
//
|
1543
1452
|
// Class to store a user-specified value for a uniform parameter
|
1544
1453
|
// in the shader
|
1545
1454
|
protected static class UniformValue {
|
1546
|
-
|
1547
|
-
static final int
|
1548
|
-
static final int
|
1549
|
-
static final int
|
1550
|
-
static final int
|
1551
|
-
static final int
|
1552
|
-
static final int
|
1553
|
-
static final int
|
1554
|
-
static final int
|
1555
|
-
static final int
|
1556
|
-
static final int
|
1557
|
-
static final int
|
1558
|
-
static final int INT4VEC = 11;
|
1455
|
+
static final int INT1 = 0;
|
1456
|
+
static final int INT2 = 1;
|
1457
|
+
static final int INT3 = 2;
|
1458
|
+
static final int INT4 = 3;
|
1459
|
+
static final int FLOAT1 = 4;
|
1460
|
+
static final int FLOAT2 = 5;
|
1461
|
+
static final int FLOAT3 = 6;
|
1462
|
+
static final int FLOAT4 = 7;
|
1463
|
+
static final int INT1VEC = 8;
|
1464
|
+
static final int INT2VEC = 9;
|
1465
|
+
static final int INT3VEC = 10;
|
1466
|
+
static final int INT4VEC = 11;
|
1559
1467
|
static final int FLOAT1VEC = 12;
|
1560
1468
|
static final int FLOAT2VEC = 13;
|
1561
1469
|
static final int FLOAT3VEC = 14;
|
1562
1470
|
static final int FLOAT4VEC = 15;
|
1563
|
-
static final int MAT2
|
1564
|
-
static final int MAT3
|
1565
|
-
static final int MAT4
|
1471
|
+
static final int MAT2 = 16;
|
1472
|
+
static final int MAT3 = 17;
|
1473
|
+
static final int MAT4 = 18;
|
1566
1474
|
static final int SAMPLER2D = 19;
|
1567
1475
|
|
1568
1476
|
int type;
|