cleaned-up handling of direct/indirect buffers in android

This commit is contained in:
codeanticode
2012-12-15 14:50:12 +00:00
parent 42cf088cb5
commit c9e037666e
4 changed files with 370 additions and 390 deletions
+261 -65
View File
@@ -52,10 +52,9 @@ import android.opengl.GLU;
*
*/
public class PGL {
public static final boolean SAVE_SURFACE_TO_PIXELS = false;
public static final boolean USE_DIRECT_PIXEL_BUFFERS = false;
public static final boolean USE_DIRECT_VERTEX_BUFFERS = false;
public static final int MIN_DIRECT_BUFFER_SIZE = 1;
public static final boolean USE_DIRECT_BUFFERS = false;
public static final int MIN_DIRECT_BUFFER_SIZE = 1;
public static final boolean SAVE_SURFACE_TO_PIXELS = false;
/** Size of a short (in bytes). */
protected static final int SIZEOF_SHORT = Short.SIZE / 8;
@@ -330,19 +329,19 @@ public class PGL {
/** The current opengl context */
public static EGLContext context;
/** OpenGL thread */
protected static Thread glThread;
/** The PGraphics object using this interface */
protected PGraphicsOpenGL pg;
/** Whether OpenGL has been initialized or not */
protected boolean initialized;
/** The renderer object driving the rendering loop,
* analogous to the GLEventListener in JOGL */
protected static AndroidRenderer renderer;
/** OpenGL thread */
protected static Thread glThread;
/** Whether OpenGL has been initialized or not */
protected static boolean glInitialized = false;
/** Which texturing targets are enabled */
protected static boolean[] texturingTargets = { false };
@@ -354,8 +353,9 @@ public class PGL {
// FBO layer
public static boolean FORCE_SCREEN_FBO = false;
protected boolean usingFBOlayer = false;
protected boolean firstFrame = true;
protected static boolean fboLayerCreated = false;
protected static boolean fboLayerInUse = false;
protected static boolean firstFrame = true;
protected static IntBuffer glColorFbo;
protected static IntBuffer glColorTex;
protected static IntBuffer glDepthStencil;
@@ -423,9 +423,16 @@ public class PGL {
if (glu == null) {
glu = new PGLU();
}
byteBuffer = allocateDirectByteBuffer(1);
intBuffer = allocateDirectIntBuffer(1);
initialized = false;
if (glColorTex == null) {
glColorTex = allocateIntBuffer(2);
glColorFbo = allocateIntBuffer(1);
glDepthStencil = allocateIntBuffer(1);
glDepth = allocateIntBuffer(1);
glStencil = allocateIntBuffer(1);
}
byteBuffer = allocateByteBuffer(1);
intBuffer = allocateIntBuffer(1);
}
@@ -442,16 +449,20 @@ public class PGL {
protected void deleteSurface() {
deleteTextures(2, glColorTex);
deleteFramebuffers(1, glColorFbo);
deleteRenderbuffers(1, glDepthStencil);
deleteRenderbuffers(1, glDepth);
deleteRenderbuffers(1, glStencil);
if (glColorTex != null) {
deleteTextures(2, glColorTex);
deleteFramebuffers(1, glColorFbo);
deleteRenderbuffers(1, glDepthStencil);
deleteRenderbuffers(1, glDepth);
deleteRenderbuffers(1, glStencil);
}
fboLayerCreated = false;
glInitialized = false;
}
protected void update() {
if (!initialized) {
if (!fboLayerCreated) {
String ext = getString(EXTENSIONS);
if (-1 < ext.indexOf("texture_non_power_of_two")) {
fboWidth = pg.width;
@@ -465,12 +476,6 @@ public class PGL {
int depthBits = getDepthBits();
int stencilBits = getStencilBits();
glColorTex = allocateDirectIntBuffer(2);
glColorFbo = allocateDirectIntBuffer(1);
glDepthStencil = allocateDirectIntBuffer(1);
glDepth = allocateDirectIntBuffer(1);
glStencil = allocateDirectIntBuffer(1);
genTextures(2, glColorTex);
for (int i = 0; i < 2; i++) {
bindTexture(TEXTURE_2D, glColorTex.get(i));
@@ -549,13 +554,13 @@ public class PGL {
bindFramebuffer(FRAMEBUFFER, 0);
initialized = true;
fboLayerCreated = true;
}
}
protected int getReadFramebuffer() {
if (usingFBOlayer) {
if (fboLayerInUse) {
return glColorFbo.get(0);
} else {
return 0;
@@ -564,7 +569,7 @@ public class PGL {
protected int getDrawFramebuffer() {
if (usingFBOlayer) {
if (fboLayerInUse) {
return glColorFbo.get(0);
} else {
return 0;
@@ -573,7 +578,7 @@ public class PGL {
protected int getDefaultDrawBuffer() {
if (usingFBOlayer) {
if (fboLayerInUse) {
return COLOR_ATTACHMENT0;
} else {
return BACK;
@@ -582,7 +587,7 @@ public class PGL {
protected int getDefaultReadBuffer() {
if (usingFBOlayer) {
if (fboLayerInUse) {
return COLOR_ATTACHMENT0;
} else {
return FRONT;
@@ -591,7 +596,7 @@ public class PGL {
protected boolean isFBOBacked() {
return usingFBOlayer;
return fboLayerInUse;
}
@@ -713,9 +718,9 @@ public class PGL {
fboWidth, fboHeight, 0, 0, pg.width, pg.height,
0, 0, pg.width, pg.height);
}
usingFBOlayer = true;
fboLayerInUse = true;
} else {
usingFBOlayer = false;
fboLayerInUse = false;
}
if (firstFrame) {
@@ -725,7 +730,7 @@ public class PGL {
protected void endDraw(boolean clear) {
if (usingFBOlayer) {
if (fboLayerInUse) {
// Draw the contents of the back texture to the screen framebuffer.
bindFramebuffer(FRAMEBUFFER, 0);
@@ -776,7 +781,7 @@ public class PGL {
if (-1 < name) {
GLES20.glGetIntegerv(name, values);
} else {
fillBuffer(values, 0, values.capacity(), 0);
fillIntBuffer(values, 0, values.capacity(), 0);
}
}
@@ -785,7 +790,7 @@ public class PGL {
if (-1 < name) {
GLES20.glGetFloatv(name, values);
} else {
fillBuffer(values, 0, values.capacity(), 0);
fillFloatBuffer(values, 0, values.capacity(), 0);
}
}
@@ -794,7 +799,7 @@ public class PGL {
if (-1 < name) {
GLES20.glGetBooleanv(name, values);
} else {
fillBuffer(values, 0, values.capacity(), 0);
fillIntBuffer(values, 0, values.capacity(), 0);
}
}
@@ -1588,12 +1593,7 @@ public class PGL {
// Doing in patches of 16x16 pixels to avoid creating a (potentially)
// very large transient array which in certain situations (memory-
// constrained android devices) might lead to an out-of-memory error.
IntBuffer texels;
if (USE_DIRECT_PIXEL_BUFFERS) {
texels = PGL.allocateDirectIntBuffer(16 * 16);
} else {
texels = IntBuffer.allocate(16 * 16);
}
IntBuffer texels = PGL.allocateIntBuffer(16 * 16);
for (int y = 0; y < height; y += 16) {
int h = PApplet.min(16, height - y);
for (int x = 0; x < width; x += 16) {
@@ -1646,6 +1646,8 @@ public class PGL {
}
if (texData == null) {
// This buffer has to be direct because vertexAttribPointer only accepts
// direct buffers.
texData = allocateDirectFloatBuffer(texCoords.length);
}
@@ -2170,6 +2172,60 @@ public class PGL {
}
protected static ByteBuffer allocateByteBuffer(int size) {
if (USE_DIRECT_BUFFERS) {
return allocateDirectByteBuffer(size);
} else {
return ByteBuffer.allocate(size);
}
}
protected static ByteBuffer allocateByteBuffer(byte[] arr) {
if (USE_DIRECT_BUFFERS) {
return PGL.allocateDirectByteBuffer(arr.length);
} else {
return ByteBuffer.wrap(arr);
}
}
protected static ByteBuffer updateByteBuffer(ByteBuffer buf, byte[] arr,
boolean wrap) {
if (USE_DIRECT_BUFFERS) {
if (buf == null || buf.capacity() < arr.length) {
buf = PGL.allocateDirectByteBuffer(arr.length);
}
buf.position(0);
buf.put(arr);
buf.rewind();
} else {
if (wrap) {
buf = ByteBuffer.wrap(arr);
} else {
if (buf == null || buf.capacity() < arr.length) {
buf = ByteBuffer.allocate(arr.length);
}
buf.position(0);
buf.put(arr);
buf.rewind();
}
}
return buf;
}
protected static void fillByteBuffer(ByteBuffer buf, int i0, int i1,
byte val) {
int n = i1 - i0;
byte[] temp = new byte[n];
Arrays.fill(temp, 0, n, val);
buf.position(i0);
buf.put(temp, 0, n);
buf.rewind();
}
protected static ShortBuffer allocateDirectShortBuffer(int size) {
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_SHORT;
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
@@ -2177,6 +2233,60 @@ public class PGL {
}
protected static ShortBuffer allocateShortBuffer(int size) {
if (USE_DIRECT_BUFFERS) {
return allocateDirectShortBuffer(size);
} else {
return ShortBuffer.allocate(size);
}
}
protected static ShortBuffer allocateShortBuffer(short[] arr) {
if (USE_DIRECT_BUFFERS) {
return PGL.allocateDirectShortBuffer(arr.length);
} else {
return ShortBuffer.wrap(arr);
}
}
protected static ShortBuffer updateShortBuffer(ShortBuffer buf, short[] arr,
boolean wrap) {
if (USE_DIRECT_BUFFERS) {
if (buf == null || buf.capacity() < arr.length) {
buf = PGL.allocateDirectShortBuffer(arr.length);
}
buf.position(0);
buf.put(arr);
buf.rewind();
} else {
if (wrap) {
buf = ShortBuffer.wrap(arr);
} else {
if (buf == null || buf.capacity() < arr.length) {
buf = ShortBuffer.allocate(arr.length);
}
buf.position(0);
buf.put(arr);
buf.rewind();
}
}
return buf;
}
protected static void fillShortBuffer(ShortBuffer buf, int i0, int i1,
short val) {
int n = i1 - i0;
short[] temp = new short[n];
Arrays.fill(temp, 0, n, val);
buf.position(i0);
buf.put(temp, 0, n);
buf.rewind();
}
protected static IntBuffer allocateDirectIntBuffer(int size) {
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_INT;
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
@@ -2184,34 +2294,50 @@ public class PGL {
}
protected static FloatBuffer allocateDirectFloatBuffer(int size) {
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_FLOAT;
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
asFloatBuffer();
protected static IntBuffer allocateIntBuffer(int size) {
if (USE_DIRECT_BUFFERS) {
return allocateDirectIntBuffer(size);
} else {
return IntBuffer.allocate(size);
}
}
protected static void fillBuffer(ByteBuffer buf, int i0, int i1, byte val) {
int n = i1 - i0;
byte[] temp = new byte[n];
Arrays.fill(temp, 0, n, val);
buf.position(i0);
buf.put(temp, 0, n);
buf.rewind();
protected static IntBuffer allocateIntBuffer(int[] arr) {
if (USE_DIRECT_BUFFERS) {
return PGL.allocateDirectIntBuffer(arr.length);
} else {
return IntBuffer.wrap(arr);
}
}
protected static void fillBuffer(ShortBuffer buf, int i0, int i1, short val) {
int n = i1 - i0;
short[] temp = new short[n];
Arrays.fill(temp, 0, n, val);
buf.position(i0);
buf.put(temp, 0, n);
buf.rewind();
protected static IntBuffer updateIntBuffer(IntBuffer buf, int[] arr,
boolean wrap) {
if (USE_DIRECT_BUFFERS) {
if (buf == null || buf.capacity() < arr.length) {
buf = PGL.allocateDirectIntBuffer(arr.length);
}
buf.position(0);
buf.put(arr);
buf.rewind();
} else {
if (wrap) {
buf = IntBuffer.wrap(arr);
} else {
if (buf == null || buf.capacity() < arr.length) {
buf = IntBuffer.allocate(arr.length);
}
buf.position(0);
buf.put(arr);
buf.rewind();
}
}
return buf;
}
protected static void fillBuffer(IntBuffer buf, int i0, int i1, int val) {
protected static void fillIntBuffer(IntBuffer buf, int i0, int i1, int val) {
int n = i1 - i0;
int[] temp = new int[n];
Arrays.fill(temp, 0, n, val);
@@ -2221,7 +2347,58 @@ public class PGL {
}
protected static void fillBuffer(FloatBuffer buf, int i0, int i1, float val) {
protected static FloatBuffer allocateDirectFloatBuffer(int size) {
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_FLOAT;
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
asFloatBuffer();
}
protected static FloatBuffer allocateFloatBuffer(int size) {
if (USE_DIRECT_BUFFERS) {
return allocateDirectFloatBuffer(size);
} else {
return FloatBuffer.allocate(size);
}
}
protected static FloatBuffer allocateFloatBuffer(float[] arr) {
if (USE_DIRECT_BUFFERS) {
return PGL.allocateDirectFloatBuffer(arr.length);
} else {
return FloatBuffer.wrap(arr);
}
}
protected static FloatBuffer updateFloatBuffer(FloatBuffer buf, float[] arr,
boolean wrap) {
if (USE_DIRECT_BUFFERS) {
if (buf == null || buf.capacity() < arr.length) {
buf = PGL.allocateDirectFloatBuffer(arr.length);
}
buf.position(0);
buf.put(arr);
buf.rewind();
} else {
if (wrap) {
buf = FloatBuffer.wrap(arr);
} else {
if (buf == null || buf.capacity() < arr.length) {
buf = FloatBuffer.allocate(arr.length);
}
buf.position(0);
buf.put(arr);
buf.rewind();
}
}
return buf;
}
protected static void fillFloatBuffer(FloatBuffer buf, int i0, int i1,
float val) {
int n = i1 - i0;
float[] temp = new float[n];
Arrays.fill(temp, 0, n, val);
@@ -2231,6 +2408,24 @@ public class PGL {
}
protected static void getPixels(IntBuffer buf, int[] arr) {
if (USE_DIRECT_BUFFERS) {
buf.position(0);
buf.get(arr);
buf.rewind();
}
}
protected static void putPixels(IntBuffer buf, int[] arr) {
if (USE_DIRECT_BUFFERS) {
buf.position(0);
buf.put(arr);
buf.rewind();
}
}
///////////////////////////////////////////////////////////
// Android specific stuff
@@ -2277,6 +2472,7 @@ public class PGL {
public void onSurfaceCreated(GL10 igl, EGLConfig config) {
gl = igl;
context = ((EGL10)EGLContext.getEGL()).eglGetCurrentContext();
glInitialized = true;
}
}
@@ -106,6 +106,9 @@ public class PGraphicsOpenGL extends PGraphics {
// Basic rendering parameters:
/** Whether the PGraphics object is ready to render or not. */
protected boolean initialized;
/** Flush modes: continuously (geometry is flushed after each call to
* endShape) when-full (geometry is accumulated until a maximum size is
* reached. */
@@ -425,7 +428,6 @@ public class PGraphicsOpenGL extends PGraphics {
// Offscreen rendering:
protected boolean initializedOffscreen;
protected FrameBuffer offscreenFramebuffer;
protected FrameBuffer multisampleFramebuffer;
protected boolean offscreenMultisample;
@@ -533,10 +535,9 @@ public class PGraphicsOpenGL extends PGraphics {
tessellator = new Tessellator();
}
intBuffer = PGL.allocateDirectIntBuffer(2);
floatBuffer = PGL.allocateDirectFloatBuffer(2);
viewport = PGL.allocateDirectIntBuffer(4);
intBuffer = PGL.allocateIntBuffer(2);
floatBuffer = PGL.allocateFloatBuffer(2);
viewport = PGL.allocateIntBuffer(4);
inGeo = newInGeometry(IMMEDIATE);
tessGeo = newTessGeometry(IMMEDIATE);
@@ -561,6 +562,8 @@ public class PGraphicsOpenGL extends PGraphics {
glPointColor = 0;
glPointAttrib = 0;
glPointIndex = 0;
initialized = false;
}
@@ -609,7 +612,6 @@ public class PGraphicsOpenGL extends PGraphics {
cameraAspect = (float) width / (float) height;
// Forces a restart of OpenGL so the canvas has the right size.
//pgl.initialized = false;
restartPGL();
// set this flag so that beginDraw() will do an update to the camera.
@@ -660,6 +662,7 @@ public class PGraphicsOpenGL extends PGraphics {
deletePolyBuffers();
deleteLineBuffers();
deletePointBuffers();
deleteDefaultShaders();
pgl.deleteSurface();
}
@@ -1571,7 +1574,7 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void requestDraw() {
if (primarySurface) {
if (pgl.initialized) {
if (initialized) {
pgl.requestDraw();
} else {
initPrimary();
@@ -1634,7 +1637,7 @@ public class PGraphicsOpenGL extends PGraphics {
flush();
if (PGL.SAVE_SURFACE_TO_PIXELS &&
(!pgPrimary.pgl.initialized || parent.frameCount == 0)) {
(!pgPrimary.initialized || parent.frameCount == 0)) {
// Smooth was disabled/enabled at some point during drawing. We save
// the current contents of the back buffer (because the buffers haven't
// been swapped yet) to the pixels array. The frameCount == 0 condition
@@ -1686,7 +1689,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected void restartPGL() {
pgl.initialized = false;
initialized = false;
}
@@ -5032,11 +5035,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected void allocatePixels() {
if ((pixels == null) || (pixels.length != width * height)) {
pixels = new int[width * height];
if (PGL.USE_DIRECT_PIXEL_BUFFERS) {
pixelBuffer = PGL.allocateDirectIntBuffer(width * height);
} else {
pixelBuffer = IntBuffer.wrap(pixels);
}
pixelBuffer = PGL.allocateIntBuffer(pixels);
}
}
@@ -5068,11 +5067,7 @@ public class PGraphicsOpenGL extends PGraphics {
endPixelsOp();
try {
// Idem...
if (PGL.USE_DIRECT_PIXEL_BUFFERS) {
pixelBuffer.position(0);
pixelBuffer.get(pixels);
pixelBuffer.rewind();
}
PGL.getPixels(pixelBuffer, pixels);
PGL.nativeToJavaARGB(pixels, width, height);
} catch (ArrayIndexOutOfBoundsException e) {
}
@@ -5083,11 +5078,7 @@ public class PGraphicsOpenGL extends PGraphics {
int len = w * h;
if (nativePixels == null || nativePixels.length < len) {
nativePixels = new int[len];
if (PGL.USE_DIRECT_PIXEL_BUFFERS) {
nativePixelBuffer = PGL.allocateDirectIntBuffer(len);
} else {
nativePixelBuffer = IntBuffer.wrap(nativePixels);
}
nativePixelBuffer = PGL.allocateIntBuffer(nativePixels);
}
try {
@@ -5109,7 +5100,7 @@ public class PGraphicsOpenGL extends PGraphics {
PGL.javaToNativeARGB(nativePixels, w, h);
} catch (ArrayIndexOutOfBoundsException e) {
}
PGL.putPixels(nativePixelBuffer, nativePixels);
// Copying pixel buffer to screen texture...
if (primarySurface && !pgl.isFBOBacked()) {
// First making sure that the screen texture is valid. Only in the case
@@ -5117,13 +5108,6 @@ public class PGraphicsOpenGL extends PGraphics {
loadTextureImpl(POINT, false);
}
if (PGL.USE_DIRECT_PIXEL_BUFFERS) {
// Put native pixels in direct buffer for copy.
nativePixelBuffer.position(0);
nativePixelBuffer.put(nativePixels);
nativePixelBuffer.rewind();
}
boolean needToDrawTex = primarySurface && (!pgl.isFBOBacked() ||
(pgl.isFBOBacked() && pgl.isMultisampled())) ||
offscreenMultisample;
@@ -5226,11 +5210,7 @@ public class PGraphicsOpenGL extends PGraphics {
// then copy this array into the texture.
if (nativePixels == null || nativePixels.length < width * height) {
nativePixels = new int[width * height];
if (PGL.USE_DIRECT_PIXEL_BUFFERS) {
nativePixelBuffer = PGL.allocateDirectIntBuffer(width * height);
} else {
nativePixelBuffer = IntBuffer.wrap(nativePixels);
}
nativePixelBuffer = PGL.allocateIntBuffer(nativePixels);
}
beginPixelsOp(OP_READ);
@@ -5821,6 +5801,7 @@ public class PGraphicsOpenGL extends PGraphics {
pgPrimary.removeCache(this);
texture = ptexture = null;
}
initialized = true;
}
@@ -5894,12 +5875,12 @@ public class PGraphicsOpenGL extends PGraphics {
offscreenFramebuffer.setColorBuffer(texture);
offscreenFramebuffer.clear();
initializedOffscreen = true;
initialized = true;
}
protected void updateOffscreen() {
if (!initializedOffscreen) {
if (!initialized) {
initOffscreen();
} else {
boolean outdated = offscreenFramebuffer != null &&
@@ -6349,6 +6330,20 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected void deleteDefaultShaders() {
// The default shaders contains references to the PGraphics object that
// creates them, so when restarting the renderer, those references should
// dissapear.
defPolyColorShader = null;
defPolyTexShader = null;
defPolyLightShader = null;
defPolyTexlightShader = null;
defLineShader = null;
defPointShader = null;
maskShader = null;
}
protected BaseShader getPolyShader(boolean lit, boolean tex) {
BaseShader shader;
if (lit) {
@@ -9028,47 +9023,25 @@ public class PGraphicsOpenGL extends PGraphics {
pointAttribs = new float[2 * PGL.DEFAULT_TESS_VERTICES];
pointIndices = new short[PGL.DEFAULT_TESS_VERTICES];
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * PGL.DEFAULT_TESS_VERTICES);
polyColorsBuffer = PGL.allocateDirectIntBuffer(PGL.DEFAULT_TESS_VERTICES);
polyNormalsBuffer = PGL.allocateDirectFloatBuffer(3 * PGL.DEFAULT_TESS_VERTICES);
polyTexcoordsBuffer = PGL.allocateDirectFloatBuffer(2 * PGL.DEFAULT_TESS_VERTICES);
polyAmbientBuffer = PGL.allocateDirectIntBuffer(PGL.DEFAULT_TESS_VERTICES);
polySpecularBuffer = PGL.allocateDirectIntBuffer(PGL.DEFAULT_TESS_VERTICES);
polyEmissiveBuffer = PGL.allocateDirectIntBuffer(PGL.DEFAULT_TESS_VERTICES);
polyShininessBuffer = PGL.allocateDirectFloatBuffer(PGL.DEFAULT_TESS_VERTICES);
polyIndicesBuffer = PGL.allocateDirectShortBuffer(PGL.DEFAULT_TESS_VERTICES);
polyVerticesBuffer = PGL.allocateFloatBuffer(polyVertices);
polyColorsBuffer = PGL.allocateIntBuffer(polyColors);
polyNormalsBuffer = PGL.allocateFloatBuffer(polyNormals);
polyTexcoordsBuffer = PGL.allocateFloatBuffer(polyTexcoords);
polyAmbientBuffer = PGL.allocateIntBuffer(polyAmbient);
polySpecularBuffer = PGL.allocateIntBuffer(polySpecular);
polyEmissiveBuffer = PGL.allocateIntBuffer(polyEmissive);
polyShininessBuffer = PGL.allocateFloatBuffer(polyShininess);
polyIndicesBuffer = PGL.allocateShortBuffer(polyIndices);
lineVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * PGL.DEFAULT_TESS_VERTICES);
lineColorsBuffer = PGL.allocateDirectIntBuffer(PGL.DEFAULT_TESS_VERTICES);
lineAttribsBuffer = PGL.allocateDirectFloatBuffer(4 * PGL.DEFAULT_TESS_VERTICES);
lineIndicesBuffer = PGL.allocateDirectShortBuffer(PGL.DEFAULT_TESS_VERTICES);
lineVerticesBuffer = PGL.allocateFloatBuffer(lineVertices);
lineColorsBuffer = PGL.allocateIntBuffer(lineColors);
lineAttribsBuffer = PGL.allocateFloatBuffer(lineAttribs);
lineIndicesBuffer = PGL.allocateShortBuffer(lineIndices);
pointVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * PGL.DEFAULT_TESS_VERTICES);
pointColorsBuffer = PGL.allocateDirectIntBuffer(PGL.DEFAULT_TESS_VERTICES);
pointAttribsBuffer = PGL.allocateDirectFloatBuffer(2 * PGL.DEFAULT_TESS_VERTICES);
pointIndicesBuffer = PGL.allocateDirectShortBuffer(PGL.DEFAULT_TESS_VERTICES);
} else {
polyVerticesBuffer = FloatBuffer.wrap(polyVertices);
polyColorsBuffer = IntBuffer.wrap(polyColors);
polyNormalsBuffer = FloatBuffer.wrap(polyNormals);
polyTexcoordsBuffer = FloatBuffer.wrap(polyTexcoords);
polyAmbientBuffer = IntBuffer.wrap(polyAmbient);
polySpecularBuffer = IntBuffer.wrap(polySpecular);
polyEmissiveBuffer = IntBuffer.wrap(polyEmissive);
polyShininessBuffer = FloatBuffer.wrap(polyShininess);
polyIndicesBuffer = ShortBuffer.wrap(polyIndices);
lineVerticesBuffer = FloatBuffer.wrap(lineVertices);
lineColorsBuffer = IntBuffer.wrap(lineColors);
lineAttribsBuffer = FloatBuffer.wrap(lineAttribs);
lineIndicesBuffer = ShortBuffer.wrap(lineIndices);
pointVerticesBuffer = FloatBuffer.wrap(pointVertices);
pointColorsBuffer = IntBuffer.wrap(pointColors);
pointAttribsBuffer = FloatBuffer.wrap(pointAttribs);
pointIndicesBuffer = ShortBuffer.wrap(pointIndices);
}
pointVerticesBuffer = PGL.allocateFloatBuffer(pointVertices);
pointColorsBuffer = PGL.allocateIntBuffer(pointColors);
pointAttribsBuffer = PGL.allocateFloatBuffer(pointAttribs);
pointIndicesBuffer = PGL.allocateShortBuffer(pointIndices);
clear();
}
@@ -9485,204 +9458,119 @@ public class PGraphicsOpenGL extends PGraphics {
float temp[] = new float[4 * n];
PApplet.arrayCopy(polyVertices, 0, temp, 0, 4 * polyVertexCount);
polyVertices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * n);
} else {
polyVerticesBuffer = FloatBuffer.wrap(polyVertices);
}
polyVerticesBuffer = PGL.allocateFloatBuffer(polyVertices);
}
void expandPolyColors(int n) {
int temp[] = new int[n];
PApplet.arrayCopy(polyColors, 0, temp, 0, polyVertexCount);
polyColors = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyColorsBuffer = PGL.allocateDirectIntBuffer(n);
} else {
polyColorsBuffer = IntBuffer.wrap(polyColors);
}
polyColorsBuffer = PGL.allocateIntBuffer(polyColors);
}
void expandPolyNormals(int n) {
float temp[] = new float[3 * n];
PApplet.arrayCopy(polyNormals, 0, temp, 0, 3 * polyVertexCount);
polyNormals = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyNormalsBuffer = PGL.allocateDirectFloatBuffer(3 * n);
} else {
polyNormalsBuffer = FloatBuffer.wrap(polyNormals);
}
polyNormalsBuffer = PGL.allocateFloatBuffer(polyNormals);
}
void expandPolyTexcoords(int n) {
float temp[] = new float[2 * n];
PApplet.arrayCopy(polyTexcoords, 0, temp, 0, 2 * polyVertexCount);
polyTexcoords = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyTexcoordsBuffer = PGL.allocateDirectFloatBuffer(2 * n);
} else {
polyTexcoordsBuffer = FloatBuffer.wrap(polyTexcoords);
}
polyTexcoordsBuffer = PGL.allocateFloatBuffer(polyTexcoords);
}
void expandPolyAmbient(int n) {
int temp[] = new int[n];
PApplet.arrayCopy(polyAmbient, 0, temp, 0, polyVertexCount);
polyAmbient = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyAmbientBuffer = PGL.allocateDirectIntBuffer(n);
} else {
polyAmbientBuffer = IntBuffer.wrap(polyAmbient);
}
polyAmbientBuffer = PGL.allocateIntBuffer(polyAmbient);
}
void expandPolySpecular(int n) {
int temp[] = new int[n];
PApplet.arrayCopy(polySpecular, 0, temp, 0, polyVertexCount);
polySpecular = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polySpecularBuffer = PGL.allocateDirectIntBuffer(n);
} else {
polySpecularBuffer = IntBuffer.wrap(polySpecular);
}
polySpecularBuffer = PGL.allocateIntBuffer(polySpecular);
}
void expandPolyEmissive(int n) {
int temp[] = new int[n];
PApplet.arrayCopy(polyEmissive, 0, temp, 0, polyVertexCount);
polyEmissive = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyEmissiveBuffer = PGL.allocateDirectIntBuffer(n);
} else {
polyEmissiveBuffer = IntBuffer.wrap(polyEmissive);
}
polyEmissiveBuffer = PGL.allocateIntBuffer(polyEmissive);
}
void expandPolyShininess(int n) {
float temp[] = new float[n];
PApplet.arrayCopy(polyShininess, 0, temp, 0, polyVertexCount);
polyShininess = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyShininessBuffer = PGL.allocateDirectFloatBuffer(n);
} else {
polyShininessBuffer = FloatBuffer.wrap(polyShininess);
}
polyShininessBuffer = PGL.allocateFloatBuffer(polyShininess);
}
void expandPolyIndices(int n) {
short temp[] = new short[n];
PApplet.arrayCopy(polyIndices, 0, temp, 0, polyIndexCount);
polyIndices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyIndicesBuffer = PGL.allocateDirectShortBuffer(n);
} else {
polyIndicesBuffer = ShortBuffer.wrap(polyIndices);
}
polyIndicesBuffer = PGL.allocateShortBuffer(polyIndices);
}
void expandLineVertices(int n) {
float temp[] = new float[4 * n];
PApplet.arrayCopy(lineVertices, 0, temp, 0, 4 * lineVertexCount);
lineVertices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
lineVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * n);
} else {
lineVerticesBuffer = FloatBuffer.wrap(lineVertices);
}
lineVerticesBuffer = PGL.allocateFloatBuffer(lineVertices);
}
void expandLineColors(int n) {
int temp[] = new int[n];
PApplet.arrayCopy(lineColors, 0, temp, 0, lineVertexCount);
lineColors = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
lineColorsBuffer = PGL.allocateDirectIntBuffer(n);
} else {
lineColorsBuffer = IntBuffer.wrap(lineColors);
}
lineColorsBuffer = PGL.allocateIntBuffer(lineColors);
}
void expandLineAttribs(int n) {
float temp[] = new float[4 * n];
PApplet.arrayCopy(lineAttribs, 0, temp, 0, 4 * lineVertexCount);
lineAttribs = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
lineAttribsBuffer = PGL.allocateDirectFloatBuffer(4 * n);
} else {
lineAttribsBuffer = FloatBuffer.wrap(lineAttribs);
}
lineAttribsBuffer = PGL.allocateFloatBuffer(lineAttribs);
}
void expandLineIndices(int n) {
short temp[] = new short[n];
PApplet.arrayCopy(lineIndices, 0, temp, 0, lineIndexCount);
lineIndices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
lineIndicesBuffer = PGL.allocateDirectShortBuffer(n);
} else {
lineIndicesBuffer = ShortBuffer.wrap(lineIndices);
}
lineIndicesBuffer = PGL.allocateShortBuffer(lineIndices);
}
void expandPointVertices(int n) {
float temp[] = new float[4 * n];
PApplet.arrayCopy(pointVertices, 0, temp, 0, 4 * pointVertexCount);
pointVertices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
pointVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * n);
} else {
pointVerticesBuffer = FloatBuffer.wrap(pointVertices);
}
pointVerticesBuffer = PGL.allocateFloatBuffer(pointVertices);
}
void expandPointColors(int n) {
int temp[] = new int[n];
PApplet.arrayCopy(pointColors, 0, temp, 0, pointVertexCount);
pointColors = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
pointColorsBuffer = PGL.allocateDirectIntBuffer(n);
} else {
pointColorsBuffer = IntBuffer.wrap(pointColors);
}
pointColorsBuffer = PGL.allocateIntBuffer(pointColors);
}
void expandPointAttribs(int n) {
float temp[] = new float[2 * n];
PApplet.arrayCopy(pointAttribs, 0, temp, 0, 2 * pointVertexCount);
pointAttribs = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
pointAttribsBuffer = PGL.allocateDirectFloatBuffer(2 * n);
} else {
pointAttribsBuffer = FloatBuffer.wrap(pointAttribs);
}
pointAttribsBuffer = PGL.allocateFloatBuffer(pointAttribs);
}
void expandPointIndices(int n) {
short temp[] = new short[n];
PApplet.arrayCopy(pointIndices, 0, temp, 0, pointIndexCount);
pointIndices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
pointIndicesBuffer = PGL.allocateDirectShortBuffer(n);
} else {
pointIndicesBuffer = ShortBuffer.wrap(pointIndices);
}
pointIndicesBuffer = PGL.allocateShortBuffer(pointIndices);
}
// -----------------------------------------------------------------
@@ -9730,204 +9618,119 @@ public class PGraphicsOpenGL extends PGraphics {
float temp[] = new float[4 * polyVertexCount];
PApplet.arrayCopy(polyVertices, 0, temp, 0, 4 * polyVertexCount);
polyVertices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * polyVertexCount);
} else {
polyVerticesBuffer = FloatBuffer.wrap(polyVertices);
}
polyVerticesBuffer = PGL.allocateFloatBuffer(polyVertices);
}
void trimPolyColors() {
int temp[] = new int[polyVertexCount];
PApplet.arrayCopy(polyColors, 0, temp, 0, polyVertexCount);
polyColors = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyColorsBuffer = PGL.allocateDirectIntBuffer(polyVertexCount);
} else {
polyColorsBuffer = IntBuffer.wrap(polyColors);
}
polyColorsBuffer = PGL.allocateIntBuffer(polyColors);
}
void trimPolyNormals() {
float temp[] = new float[3 * polyVertexCount];
PApplet.arrayCopy(polyNormals, 0, temp, 0, 3 * polyVertexCount);
polyNormals = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyNormalsBuffer = PGL.allocateDirectFloatBuffer(3 * polyVertexCount);
} else {
polyNormalsBuffer = FloatBuffer.wrap(polyNormals);
}
polyNormalsBuffer = PGL.allocateFloatBuffer(polyNormals);
}
void trimPolyTexcoords() {
float temp[] = new float[2 * polyVertexCount];
PApplet.arrayCopy(polyTexcoords, 0, temp, 0, 2 * polyVertexCount);
polyTexcoords = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyTexcoordsBuffer = PGL.allocateDirectFloatBuffer(2 * polyVertexCount);
} else {
polyTexcoordsBuffer = FloatBuffer.wrap(polyTexcoords);
}
polyTexcoordsBuffer = PGL.allocateFloatBuffer(polyTexcoords);
}
void trimPolyAmbient() {
int temp[] = new int[polyVertexCount];
PApplet.arrayCopy(polyAmbient, 0, temp, 0, polyVertexCount);
polyAmbient = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyAmbientBuffer = PGL.allocateDirectIntBuffer(polyVertexCount);
} else {
polyAmbientBuffer = IntBuffer.wrap(polyAmbient);
}
polyAmbientBuffer = PGL.allocateIntBuffer(polyAmbient);
}
void trimPolySpecular() {
int temp[] = new int[polyVertexCount];
PApplet.arrayCopy(polySpecular, 0, temp, 0, polyVertexCount);
polySpecular = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polySpecularBuffer = PGL.allocateDirectIntBuffer(polyVertexCount);
} else {
polySpecularBuffer = IntBuffer.wrap(polySpecular);
}
polySpecularBuffer = PGL.allocateIntBuffer(polySpecular);
}
void trimPolyEmissive() {
int temp[] = new int[polyVertexCount];
PApplet.arrayCopy(polyEmissive, 0, temp, 0, polyVertexCount);
polyEmissive = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyEmissiveBuffer = PGL.allocateDirectIntBuffer(polyVertexCount);
} else {
polyEmissiveBuffer = IntBuffer.wrap(polyEmissive);
}
polyEmissiveBuffer = PGL.allocateIntBuffer(polyEmissive);
}
void trimPolyShininess() {
float temp[] = new float[polyVertexCount];
PApplet.arrayCopy(polyShininess, 0, temp, 0, polyVertexCount);
polyShininess = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyShininessBuffer = PGL.allocateDirectFloatBuffer(polyVertexCount);
} else {
polyShininessBuffer = FloatBuffer.wrap(polyShininess);
}
polyShininessBuffer = PGL.allocateFloatBuffer(polyShininess);
}
void trimPolyIndices() {
short temp[] = new short[polyIndexCount];
PApplet.arrayCopy(polyIndices, 0, temp, 0, polyIndexCount);
polyIndices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
polyIndicesBuffer = PGL.allocateDirectShortBuffer(polyIndexCount);
} else {
polyIndicesBuffer = ShortBuffer.wrap(polyIndices);
}
polyIndicesBuffer = PGL.allocateShortBuffer(polyIndices);
}
void trimLineVertices() {
float temp[] = new float[4 * lineVertexCount];
PApplet.arrayCopy(lineVertices, 0, temp, 0, 4 * lineVertexCount);
lineVertices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
lineVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * lineVertexCount);
} else {
lineVerticesBuffer = FloatBuffer.wrap(lineVertices);
}
lineVerticesBuffer = PGL.allocateFloatBuffer(lineVertices);
}
void trimLineColors() {
int temp[] = new int[lineVertexCount];
PApplet.arrayCopy(lineColors, 0, temp, 0, lineVertexCount);
lineColors = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
lineColorsBuffer = PGL.allocateDirectIntBuffer(lineVertexCount);
} else {
lineColorsBuffer = IntBuffer.wrap(lineColors);
}
lineColorsBuffer = PGL.allocateIntBuffer(lineColors);
}
void trimLineAttribs() {
float temp[] = new float[4 * lineVertexCount];
PApplet.arrayCopy(lineAttribs, 0, temp, 0, 4 * lineVertexCount);
lineAttribs = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
lineAttribsBuffer = PGL.allocateDirectFloatBuffer(4 * lineVertexCount);
} else {
lineAttribsBuffer = FloatBuffer.wrap(lineAttribs);
}
lineAttribsBuffer = PGL.allocateFloatBuffer(lineAttribs);
}
void trimLineIndices() {
short temp[] = new short[lineIndexCount];
PApplet.arrayCopy(lineIndices, 0, temp, 0, lineIndexCount);
lineIndices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
lineIndicesBuffer = PGL.allocateDirectShortBuffer(lineIndexCount);
} else {
lineIndicesBuffer = ShortBuffer.wrap(lineIndices);
}
lineIndicesBuffer = PGL.allocateShortBuffer(lineIndices);
}
void trimPointVertices() {
float temp[] = new float[4 * pointVertexCount];
PApplet.arrayCopy(pointVertices, 0, temp, 0, 4 * pointVertexCount);
pointVertices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
pointVerticesBuffer = PGL.allocateDirectFloatBuffer(4 * pointVertexCount);
} else {
pointVerticesBuffer = FloatBuffer.wrap(pointVertices);
}
pointVerticesBuffer = PGL.allocateFloatBuffer(pointVertices);
}
void trimPointColors() {
int temp[] = new int[pointVertexCount];
PApplet.arrayCopy(pointColors, 0, temp, 0, pointVertexCount);
pointColors = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
pointColorsBuffer = PGL.allocateDirectIntBuffer(pointVertexCount);
} else {
pointColorsBuffer = IntBuffer.wrap(pointColors);
}
pointColorsBuffer = PGL.allocateIntBuffer(pointColors);
}
void trimPointAttribs() {
float temp[] = new float[2 * pointVertexCount];
PApplet.arrayCopy(pointAttribs, 0, temp, 0, 2 * pointVertexCount);
pointAttribs = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
pointAttribsBuffer = PGL.allocateDirectFloatBuffer(2 * pointVertexCount);
} else {
pointAttribsBuffer = FloatBuffer.wrap(pointAttribs);
}
pointAttribsBuffer = PGL.allocateFloatBuffer(pointAttribs);
}
void trimPointIndices() {
short temp[] = new short[pointIndexCount];
PApplet.arrayCopy(pointIndices, 0, temp, 0, pointIndexCount);
pointIndices = temp;
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
pointIndicesBuffer = PGL.allocateDirectShortBuffer(pointIndexCount);
} else {
pointIndicesBuffer = ShortBuffer.wrap(pointIndices);
}
pointIndicesBuffer = PGL.allocateShortBuffer(pointIndices);
}
// -----------------------------------------------------------------
+23 -33
View File
@@ -102,7 +102,7 @@ public class PShader {
firstTexUnit = 0;
intBuffer = PGL.allocateDirectIntBuffer(1);
intBuffer = PGL.allocateIntBuffer(1);
floatBuffer = PGL.allocateDirectFloatBuffer(1);
bound = false;
@@ -141,8 +141,8 @@ public class PShader {
glVertex = 0;
glFragment = 0;
intBuffer = PGL.allocateDirectIntBuffer(1);
floatBuffer = PGL.allocateDirectFloatBuffer(1);
intBuffer = PGL.allocateIntBuffer(1);
floatBuffer = PGL.allocateFloatBuffer(1);
}
/**
@@ -163,8 +163,8 @@ public class PShader {
glVertex = 0;
glFragment = 0;
intBuffer = PGL.allocateDirectIntBuffer(1);
floatBuffer = PGL.allocateDirectFloatBuffer(1);
intBuffer = PGL.allocateIntBuffer(1);
floatBuffer = PGL.allocateFloatBuffer(1);
}
@@ -474,7 +474,7 @@ public class PShader {
protected void setUniformVector(int loc, int[] vec, int ncoords,
int length) {
if (-1 < loc) {
copyToIntBuffer(vec);
updateIntBuffer(vec);
if (ncoords == 1) {
pgl.uniform1iv(loc, length, intBuffer);
} else if (ncoords == 2) {
@@ -491,7 +491,7 @@ public class PShader {
protected void setUniformVector(int loc, float[] vec, int ncoords,
int length) {
if (-1 < loc) {
copyToFloatBuffer(vec);
updateFloatBuffer(vec);
if (ncoords == 1) {
pgl.uniform1fv(loc, length, floatBuffer);
} else if (ncoords == 2) {
@@ -507,7 +507,7 @@ public class PShader {
protected void setUniformMatrix(int loc, float[] mat) {
if (-1 < loc) {
copyToFloatBuffer(mat);
updateFloatBuffer(mat);
if (mat.length == 4) {
pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
} else if (mat.length == 9) {
@@ -604,47 +604,47 @@ public class PShader {
pgl.uniform4f(loc, v[0], v[1], v[2], v[3]);
} else if (val.type == UniformValue.INT1VEC) {
int[] v = ((int[])val.value);
copyToIntBuffer(v);
updateIntBuffer(v);
pgl.uniform1iv(loc, v.length, intBuffer);
} else if (val.type == UniformValue.INT2VEC) {
int[] v = ((int[])val.value);
copyToIntBuffer(v);
updateIntBuffer(v);
pgl.uniform2iv(loc, v.length / 2, intBuffer);
} else if (val.type == UniformValue.INT3VEC) {
int[] v = ((int[])val.value);
copyToIntBuffer(v);
updateIntBuffer(v);
pgl.uniform3iv(loc, v.length / 3, intBuffer);
} else if (val.type == UniformValue.INT4VEC) {
int[] v = ((int[])val.value);
copyToIntBuffer(v);
updateIntBuffer(v);
pgl.uniform4iv(loc, v.length / 4, intBuffer);
} else if (val.type == UniformValue.FLOAT1VEC) {
float[] v = ((float[])val.value);
copyToFloatBuffer(v);
updateFloatBuffer(v);
pgl.uniform1fv(loc, v.length, floatBuffer);
} else if (val.type == UniformValue.FLOAT2VEC) {
float[] v = ((float[])val.value);
copyToFloatBuffer(v);
updateFloatBuffer(v);
pgl.uniform2fv(loc, v.length / 2, floatBuffer);
} else if (val.type == UniformValue.FLOAT3VEC) {
float[] v = ((float[])val.value);
copyToFloatBuffer(v);
updateFloatBuffer(v);
pgl.uniform3fv(loc, v.length / 3, floatBuffer);
} else if (val.type == UniformValue.FLOAT4VEC) {
float[] v = ((float[])val.value);
copyToFloatBuffer(v);
updateFloatBuffer(v);
pgl.uniform4fv(loc, v.length / 4, floatBuffer);
} else if (val.type == UniformValue.MAT2) {
float[] v = ((float[])val.value);
copyToFloatBuffer(v);
updateFloatBuffer(v);
pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
} else if (val.type == UniformValue.MAT3) {
float[] v = ((float[])val.value);
copyToFloatBuffer(v);
updateFloatBuffer(v);
pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
} else if (val.type == UniformValue.MAT4) {
float[] v = ((float[])val.value);
copyToFloatBuffer(v);
updateFloatBuffer(v);
pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
} else if (val.type == UniformValue.SAMPLER2D) {
PImage img = (PImage)val.value;
@@ -662,23 +662,13 @@ public class PShader {
}
protected void copyToIntBuffer(int[] vec) {
if (intBuffer.capacity() < vec.length) {
intBuffer = PGL.allocateDirectIntBuffer(vec.length);
}
intBuffer.rewind();
intBuffer.put(vec, 0, vec.length);
intBuffer.rewind();
protected void updateIntBuffer(int[] vec) {
intBuffer = PGL.updateIntBuffer(intBuffer, vec, false);
}
protected void copyToFloatBuffer(float[] vec) {
if (floatBuffer.capacity() < vec.length) {
floatBuffer = PGL.allocateDirectFloatBuffer(vec.length);
}
floatBuffer.rewind();
floatBuffer.put(vec, 0, vec.length);
floatBuffer.rewind();
protected void updateFloatBuffer(float[] vec) {
floatBuffer = PGL.updateFloatBuffer(floatBuffer, vec, false);
}
@@ -856,16 +856,7 @@ public class Texture implements PConstants {
protected void updatePixelBuffer(int[] pixels) {
if (PGL.USE_DIRECT_VERTEX_BUFFERS) {
if (pixelBuffer == null || pixelBuffer.capacity() < pixels.length) {
pixelBuffer = PGL.allocateDirectIntBuffer(pixels.length);
}
pixelBuffer.position(0);
pixelBuffer.put(pixels);
pixelBuffer.rewind();
} else {
pixelBuffer = IntBuffer.wrap(pixels);
}
pixelBuffer = PGL.updateIntBuffer(pixelBuffer, pixels, true);
}
////////////////////////////////////////////////////////////