mirror of
https://github.com/processing/processing4.git
synced 2026-03-16 01:17:39 +01:00
PShader updates
This commit is contained in:
@@ -5,8 +5,7 @@ import controlP5.*;
|
||||
|
||||
ControlP5 controlP5;
|
||||
|
||||
PShader shader;
|
||||
PGraphicsOpenGL pg;
|
||||
PShader badPrint;
|
||||
|
||||
boolean enabled = true;
|
||||
float scaleR = 1.0, scaleG = 1.0, scaleB = 1.0;
|
||||
@@ -20,9 +19,8 @@ public void setup() {
|
||||
noStroke();
|
||||
fill(204);
|
||||
|
||||
pg = (PGraphicsOpenGL)g;
|
||||
shader = pg.loadShader("BadPrintVert.glsl", "BadPrintFrag.glsl", PShader.LIT);
|
||||
pg.setShader(shader, PShader.LIT);
|
||||
badPrint = (PShader)loadShader("BadPrintVert.glsl", "BadPrintFrag.glsl", PShader.LIT);
|
||||
shader(badPrint, PShader.LIT);
|
||||
|
||||
sphereDetail(60);
|
||||
|
||||
@@ -46,14 +44,14 @@ public void draw() {
|
||||
background(0);
|
||||
|
||||
if (enabled) {
|
||||
pg.setShader(shader, PShader.LIT);
|
||||
shader(badPrint, PShader.LIT);
|
||||
|
||||
shader.set("Scale", scaleR, scaleG, scaleB);
|
||||
shader.set("Offset", offsetR, offsetG, offsetB);
|
||||
shader.set("Register", registerR, registerG, registerB);
|
||||
shader.set("Size", sizeR, sizeG, sizeB);
|
||||
badPrint.set("Scale", scaleR, scaleG, scaleB);
|
||||
badPrint.set("Offset", offsetR, offsetG, offsetB);
|
||||
badPrint.set("Register", registerR, registerG, registerB);
|
||||
badPrint.set("Size", sizeR, sizeG, sizeB);
|
||||
} else {
|
||||
pg.defaultShader(PShader.LIT);
|
||||
resetShader(PShader.LIT);
|
||||
}
|
||||
|
||||
noStroke();
|
||||
@@ -71,4 +69,3 @@ public void draw() {
|
||||
controlP5.draw();
|
||||
hint(ENABLE_DEPTH_TEST);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,15 @@
|
||||
// Press the mouse to switch between the custom and the default shader.
|
||||
|
||||
PImage img;
|
||||
PShader shader;
|
||||
PGraphicsOpenGL pg;
|
||||
PShader edges;
|
||||
boolean customShader;
|
||||
|
||||
void setup() {
|
||||
size(400, 400, P2D);
|
||||
img = loadImage("berlin-1.jpg");
|
||||
|
||||
pg = (PGraphicsOpenGL)g;
|
||||
shader = pg.loadShader("edges.glsl", PShader.TEXTURED);
|
||||
pg.setShader(shader, PShader.TEXTURED);
|
||||
edges = (PShader)loadShader("edges.glsl", PShader.TEXTURED);
|
||||
shader(edges, PShader.TEXTURED);
|
||||
customShader = true;
|
||||
}
|
||||
|
||||
@@ -25,10 +23,10 @@ public void draw() {
|
||||
|
||||
public void mousePressed() {
|
||||
if (customShader) {
|
||||
pg.defaultShader(PShader.TEXTURED);
|
||||
resetShader(PShader.TEXTURED);
|
||||
customShader = false;
|
||||
} else {
|
||||
pg.setShader(shader, PShader.TEXTURED);
|
||||
shader(edges, PShader.TEXTURED);
|
||||
customShader = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
|
||||
PGraphics canvas;
|
||||
boolean drawing = false;
|
||||
PGraphicsOpenGL pg;
|
||||
PShader shader;
|
||||
PShader fxaa;
|
||||
boolean usingShader;
|
||||
String message;
|
||||
float msgLen;
|
||||
@@ -19,9 +18,8 @@ void setup() {
|
||||
canvas = createGraphics(width, height, P2D);
|
||||
canvas.noSmooth();
|
||||
|
||||
pg = (PGraphicsOpenGL) g;
|
||||
shader = pg.loadShader("fxaa.glsl", PShader.TEXTURED);
|
||||
pg.setShader(shader, PShader.TEXTURED);
|
||||
fxaa = (PShader)loadShader("fxaa.glsl", PShader.TEXTURED);
|
||||
shader(fxaa, PShader.TEXTURED);
|
||||
usingShader = true;
|
||||
|
||||
canvas.beginDraw();
|
||||
@@ -55,10 +53,10 @@ public void draw() {
|
||||
public void mousePressed() {
|
||||
if (!drawing && width - msgLen < mouseX && height - 23 < mouseY) {
|
||||
if (usingShader) {
|
||||
pg.defaultShader(PShader.TEXTURED);
|
||||
resetShader(PShader.TEXTURED);
|
||||
usingShader = false;
|
||||
} else {
|
||||
pg.setShader(shader, PShader.TEXTURED);
|
||||
shader(fxaa, PShader.TEXTURED);
|
||||
usingShader = true;
|
||||
}
|
||||
updateMessage();
|
||||
@@ -84,11 +82,11 @@ void drawMessage() {
|
||||
if (usingShader) {
|
||||
// We need the default texture shader to
|
||||
// render text.
|
||||
pg.defaultShader(PShader.TEXTURED);
|
||||
resetShader(PShader.TEXTURED);
|
||||
}
|
||||
fill(0);
|
||||
text(message, width - msgLen, height - 5);
|
||||
if (usingShader) {
|
||||
pg.setShader(shader, PShader.TEXTURED);
|
||||
shader(fxaa, PShader.TEXTURED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,9 @@ void setup() {
|
||||
size(400, 400, P3D);
|
||||
canvas = createGraphics(400, 400, P3D);
|
||||
|
||||
PGraphicsOpenGL pg = (PGraphicsOpenGL)g;
|
||||
fisheye = pg.loadShader("FishEye.glsl", PShader.TEXTURED);
|
||||
fisheye = (PShader)loadShader("FishEye.glsl", PShader.TEXTURED);
|
||||
fisheye.set("aperture", 180.0);
|
||||
pg.setShader(fisheye, PShader.TEXTURED);
|
||||
shader(fisheye, PShader.TEXTURED);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
@@ -36,4 +35,3 @@ void draw() {
|
||||
// it was set as the PShader.TEXTURED shader of the main surface.
|
||||
image(canvas, 0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,13 +13,12 @@ void setup() {
|
||||
size(800, 800, P3D);
|
||||
canvas = createGraphics(800, 800, P3D);
|
||||
|
||||
PGraphicsOpenGL pg = (PGraphicsOpenGL)g;
|
||||
fisheye = pg.loadShader("FishEye.glsl", PShader.TEXTURED);
|
||||
fisheye = (PShader)loadShader("FishEye.glsl", PShader.TEXTURED);
|
||||
fisheye.set("aperture", 180.0);
|
||||
pg.setShader(fisheye, PShader.TEXTURED);
|
||||
shader(fisheye, PShader.TEXTURED);
|
||||
usingFishEye = true;
|
||||
|
||||
glossy = pg.loadShader("GlossyVert.glsl", "GlossyFrag.glsl", PShader.LIT);
|
||||
glossy = (PShader)loadShader("GlossyVert.glsl", "GlossyFrag.glsl", PShader.LIT);
|
||||
glossy.set("AmbientColour", 0, 0, 0);
|
||||
glossy.set("DiffuseColour", 0.9, 0.2, 0.2);
|
||||
glossy.set("SpecularColour", 1.0, 1.0, 1.0);
|
||||
@@ -28,7 +27,7 @@ void setup() {
|
||||
glossy.set("SpecularIntensity", 0.7);
|
||||
glossy.set("Roughness", 0.7);
|
||||
glossy.set("Sharpness", 0.0);
|
||||
((PGraphicsOpenGL)canvas).setShader(glossy, PShader.LIT);
|
||||
canvas.shader(glossy, PShader.LIT);
|
||||
|
||||
ball = createShape(SPHERE, 50);
|
||||
//ball.fill(200, 50, 50);
|
||||
@@ -62,10 +61,10 @@ void draw() {
|
||||
|
||||
public void mousePressed() {
|
||||
if (usingFishEye) {
|
||||
((PGraphicsOpenGL)g).defaultShader(PShader.TEXTURED);
|
||||
resetShader(PShader.TEXTURED);
|
||||
usingFishEye = false;
|
||||
} else {
|
||||
((PGraphicsOpenGL)g).setShader(fisheye, PShader.TEXTURED);
|
||||
shader(fisheye, PShader.TEXTURED);
|
||||
usingFishEye = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.nio.FloatBuffer;
|
||||
PGraphicsOpenGL pg;
|
||||
PGL pgl;
|
||||
|
||||
PShader shader;
|
||||
PShader flatShader;
|
||||
|
||||
int vertLoc;
|
||||
int colorLoc;
|
||||
@@ -19,9 +19,10 @@ void setup() {
|
||||
size(400, 400, P3D);
|
||||
|
||||
pg = (PGraphicsOpenGL)g;
|
||||
|
||||
// Get the default shader that Processing uses to
|
||||
// render flat geometry (w/out textures and lights).
|
||||
shader = pg.getShader(PShader.FLAT);
|
||||
flatShader = (PShader)getShader(PShader.FLAT);
|
||||
|
||||
vertices = new float[12];
|
||||
vertData = PGL.allocateDirectFloatBuffer(12);
|
||||
@@ -40,10 +41,10 @@ void draw() {
|
||||
updateGeometry();
|
||||
|
||||
pgl = pg.beginPGL();
|
||||
shader.bind();
|
||||
flatShader.bind();
|
||||
|
||||
vertLoc = pgl.glGetAttribLocation(shader.glProgramObjectID, "inVertex");
|
||||
colorLoc = pgl.glGetAttribLocation(shader.glProgramObjectID, "inColor");
|
||||
vertLoc = pgl.glGetAttribLocation(flatShader.glProgram, "inVertex");
|
||||
colorLoc = pgl.glGetAttribLocation(flatShader.glProgram, "inColor");
|
||||
|
||||
pgl.glEnableVertexAttribArray(vertLoc);
|
||||
pgl.glEnableVertexAttribArray(colorLoc);
|
||||
@@ -56,7 +57,7 @@ void draw() {
|
||||
pgl.glDisableVertexAttribArray(vertLoc);
|
||||
pgl.glDisableVertexAttribArray(colorLoc);
|
||||
|
||||
shader.unbind();
|
||||
flatShader.unbind();
|
||||
pg.endPGL();
|
||||
}
|
||||
|
||||
@@ -98,4 +99,4 @@ void updateGeometry() {
|
||||
colorData.rewind();
|
||||
colorData.put(colors);
|
||||
colorData.position(0);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
// Separable-blur shader (works by applying two succesive passes
|
||||
// Separable-blur shader (works by applying two successive passes
|
||||
// in each direction of the image)
|
||||
|
||||
PShader shader;
|
||||
PGraphicsOpenGL src;
|
||||
PGraphicsOpenGL pass1, pass2;
|
||||
PShader blur;
|
||||
PGraphics src;
|
||||
PGraphics pass1, pass2;
|
||||
|
||||
void setup() {
|
||||
size(200, 200, P2D);
|
||||
|
||||
shader = ((PGraphicsOpenGL)g).loadShader("blur.glsl", PShader.TEXTURED);
|
||||
shader.set("blurSize", 9);
|
||||
shader.set("sigma", 5.0f);
|
||||
blur = (PShader)loadShader("blur.glsl", PShader.TEXTURED);
|
||||
blur.set("blurSize", 9);
|
||||
blur.set("sigma", 5.0f);
|
||||
|
||||
src = (PGraphicsOpenGL)createGraphics(width, height, P2D);
|
||||
src = createGraphics(width, height, P2D);
|
||||
|
||||
pass1 = (PGraphicsOpenGL)createGraphics(width, height, P2D);
|
||||
pass1 = createGraphics(width, height, P2D);
|
||||
pass1.noSmooth();
|
||||
pass1.setShader(shader, PShader.TEXTURED);
|
||||
pass1.shader(blur, PShader.TEXTURED);
|
||||
|
||||
pass2 = (PGraphicsOpenGL)createGraphics(width, height, P2D);
|
||||
pass2 = createGraphics(width, height, P2D);
|
||||
pass2.noSmooth();
|
||||
pass2.setShader(shader, PShader.TEXTURED);
|
||||
pass2.shader(blur, PShader.TEXTURED);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
@@ -31,13 +31,13 @@ void draw() {
|
||||
src.endDraw();
|
||||
|
||||
// Applying the blur shader along the vertical direction
|
||||
shader.set("horizontalPass", 0);
|
||||
blur.set("horizontalPass", 0);
|
||||
pass1.beginDraw();
|
||||
pass1.image(src, 0, 0);
|
||||
pass1.endDraw();
|
||||
|
||||
// Applying the blur shader along the horizontal direction
|
||||
shader.set("horizontalPass", 1);
|
||||
blur.set("horizontalPass", 1);
|
||||
pass2.beginDraw();
|
||||
pass2.image(pass1, 0, 0);
|
||||
pass2.endDraw();
|
||||
@@ -47,16 +47,16 @@ void draw() {
|
||||
|
||||
void keyPressed() {
|
||||
if (key == '9') {
|
||||
shader.set("blurSize", 9);
|
||||
shader.set("sigma", 5.0);
|
||||
blur.set("blurSize", 9);
|
||||
blur.set("sigma", 5.0);
|
||||
} else if (key == '7') {
|
||||
shader.set("blurSize", 7);
|
||||
shader.set("sigma", 3.0);
|
||||
blur.set("blurSize", 7);
|
||||
blur.set("sigma", 3.0);
|
||||
} else if (key == '5') {
|
||||
shader.set("blurSize", 5);
|
||||
shader.set("sigma", 2.0);
|
||||
blur.set("blurSize", 5);
|
||||
blur.set("sigma", 2.0);
|
||||
} else if (key == '3') {
|
||||
shader.set("blurSize", 5);
|
||||
shader.set("sigma", 1.0);
|
||||
blur.set("blurSize", 5);
|
||||
blur.set("sigma", 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@
|
||||
// Based on the glsl tutorial from lighthouse 3D:
|
||||
// http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/
|
||||
|
||||
PShader shader;
|
||||
PGraphicsOpenGL pg;
|
||||
PShader toon;
|
||||
boolean customShader;
|
||||
|
||||
public void setup() {
|
||||
@@ -12,9 +11,8 @@ public void setup() {
|
||||
noStroke();
|
||||
fill(204);
|
||||
|
||||
pg = (PGraphicsOpenGL)g;
|
||||
shader = pg.loadShader("ToonVert.glsl", "ToonFrag.glsl", PShader.LIT);
|
||||
pg.setShader(shader, PShader.LIT);
|
||||
toon = (PShader)loadShader("ToonVert.glsl", "ToonFrag.glsl", PShader.LIT);
|
||||
shader(toon, PShader.LIT);
|
||||
customShader = true;
|
||||
}
|
||||
|
||||
@@ -31,11 +29,11 @@ public void draw() {
|
||||
public void mousePressed() {
|
||||
if (dist(mouseX, mouseY, width/2, height/2) < 80) {
|
||||
if (customShader) {
|
||||
pg.defaultShader(PShader.LIT);
|
||||
resetShader(PShader.LIT);
|
||||
customShader = false;
|
||||
}
|
||||
else {
|
||||
pg.setShader(shader, PShader.LIT);
|
||||
shader(toon, PShader.LIT);
|
||||
customShader = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +45,11 @@ public class FrameBuffer implements PConstants {
|
||||
protected PGL pgl;
|
||||
protected PGL.Context context; // The context that created this framebuffer.
|
||||
|
||||
public int glFboID;
|
||||
public int glDepthBufferID;
|
||||
public int glStencilBufferID;
|
||||
public int glDepthStencilBufferID;
|
||||
public int glColorBufferMultisampleID;
|
||||
public int glFbo;
|
||||
public int glDepth;
|
||||
public int glStencil;
|
||||
public int glDepthStencil;
|
||||
public int glMultisample;
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
@@ -84,11 +84,11 @@ public class FrameBuffer implements PConstants {
|
||||
pgl = pg.pgl;
|
||||
context = pgl.createEmptyContext();
|
||||
|
||||
glFboID = 0;
|
||||
glDepthBufferID = 0;
|
||||
glStencilBufferID = 0;
|
||||
glDepthStencilBufferID = 0;
|
||||
glColorBufferMultisampleID = 0;
|
||||
glFbo = 0;
|
||||
glDepth = 0;
|
||||
glStencil = 0;
|
||||
glDepthStencil = 0;
|
||||
glMultisample = 0;
|
||||
|
||||
if (screen) {
|
||||
// If this framebuffer is used to represent a on-screen buffer,
|
||||
@@ -143,20 +143,20 @@ public class FrameBuffer implements PConstants {
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (glFboID != 0) {
|
||||
pg.finalizeFrameBufferObject(glFboID, context.code());
|
||||
if (glFbo != 0) {
|
||||
pg.finalizeFrameBufferObject(glFbo, context.code());
|
||||
}
|
||||
if (glDepthBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthBufferID, context.code());
|
||||
if (glDepth != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepth, context.code());
|
||||
}
|
||||
if (glStencilBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glStencilBufferID, context.code());
|
||||
if (glStencil != 0) {
|
||||
pg.finalizeRenderBufferObject(glStencil, context.code());
|
||||
}
|
||||
if (glColorBufferMultisampleID != 0) {
|
||||
pg.finalizeRenderBufferObject(glColorBufferMultisampleID, context.code());
|
||||
if (glMultisample != 0) {
|
||||
pg.finalizeRenderBufferObject(glMultisample, context.code());
|
||||
}
|
||||
if (glDepthStencilBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthStencilBufferID, context.code());
|
||||
if (glDepthStencil != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthStencil, context.code());
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
@@ -174,15 +174,15 @@ public class FrameBuffer implements PConstants {
|
||||
}
|
||||
|
||||
public void copy(FrameBuffer dest) {
|
||||
pgl.glBindFramebuffer(PGL.GL_READ_FRAMEBUFFER, this.glFboID);
|
||||
pgl.glBindFramebuffer(PGL.GL_DRAW_FRAMEBUFFER, dest.glFboID);
|
||||
pgl.glBindFramebuffer(PGL.GL_READ_FRAMEBUFFER, this.glFbo);
|
||||
pgl.glBindFramebuffer(PGL.GL_DRAW_FRAMEBUFFER, dest.glFbo);
|
||||
pgl.glBlitFramebuffer(0, 0, this.width, this.height,
|
||||
0, 0, dest.width, dest.height,
|
||||
PGL.GL_COLOR_BUFFER_BIT, PGL.GL_NEAREST);
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
pgl.glBindFramebuffer(PGL.GL_FRAMEBUFFER, glFboID);
|
||||
pgl.glBindFramebuffer(PGL.GL_FRAMEBUFFER, glFbo);
|
||||
}
|
||||
|
||||
public void disableDepthTest() {
|
||||
@@ -260,7 +260,7 @@ public class FrameBuffer implements PConstants {
|
||||
}
|
||||
|
||||
for (int i = 0; i < numColorBuffers; i++) {
|
||||
pgl.glFramebufferTexture2D(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0 + i, colorBufferTex[i].glTarget, colorBufferTex[i].glID, 0);
|
||||
pgl.glFramebufferTexture2D(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0 + i, colorBufferTex[i].glTarget, colorBufferTex[i].glName, 0);
|
||||
}
|
||||
|
||||
pgl.validateFramebuffer();
|
||||
@@ -280,9 +280,9 @@ public class FrameBuffer implements PConstants {
|
||||
context = pgl.getCurrentContext();
|
||||
|
||||
if (screenFb) {
|
||||
glFboID = 0;
|
||||
glFbo = 0;
|
||||
} else {
|
||||
glFboID = pg.createFrameBufferObject(context.code());
|
||||
glFbo = pg.createFrameBufferObject(context.code());
|
||||
}
|
||||
|
||||
// create the rest of the stuff...
|
||||
@@ -304,25 +304,25 @@ public class FrameBuffer implements PConstants {
|
||||
|
||||
|
||||
protected void release() {
|
||||
if (glFboID != 0) {
|
||||
pg.finalizeFrameBufferObject(glFboID, context.code());
|
||||
glFboID = 0;
|
||||
if (glFbo != 0) {
|
||||
pg.finalizeFrameBufferObject(glFbo, context.code());
|
||||
glFbo = 0;
|
||||
}
|
||||
if (glDepthBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthBufferID, context.code());
|
||||
glDepthBufferID = 0;
|
||||
if (glDepth != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepth, context.code());
|
||||
glDepth = 0;
|
||||
}
|
||||
if (glStencilBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glStencilBufferID, context.code());
|
||||
glStencilBufferID = 0;
|
||||
if (glStencil != 0) {
|
||||
pg.finalizeRenderBufferObject(glStencil, context.code());
|
||||
glStencil = 0;
|
||||
}
|
||||
if (glColorBufferMultisampleID != 0) {
|
||||
pg.finalizeRenderBufferObject(glColorBufferMultisampleID, context.code());
|
||||
glColorBufferMultisampleID = 0;
|
||||
if (glMultisample != 0) {
|
||||
pg.finalizeRenderBufferObject(glMultisample, context.code());
|
||||
glMultisample = 0;
|
||||
}
|
||||
if (glDepthStencilBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthStencilBufferID, context.code());
|
||||
glDepthStencilBufferID = 0;
|
||||
if (glDepthStencil != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthStencil, context.code());
|
||||
glDepthStencil = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,17 +330,17 @@ public class FrameBuffer implements PConstants {
|
||||
protected boolean contextIsOutdated() {
|
||||
boolean outdated = !pgl.contextIsCurrent(context);
|
||||
if (outdated) {
|
||||
pg.removeFrameBufferObject(glFboID, context.code());
|
||||
pg.removeRenderBufferObject(glDepthBufferID, context.code());
|
||||
pg.removeRenderBufferObject(glStencilBufferID, context.code());
|
||||
pg.removeRenderBufferObject(glDepthStencilBufferID, context.code());
|
||||
pg.removeRenderBufferObject(glColorBufferMultisampleID, context.code());
|
||||
pg.removeFrameBufferObject(glFbo, context.code());
|
||||
pg.removeRenderBufferObject(glDepth, context.code());
|
||||
pg.removeRenderBufferObject(glStencil, context.code());
|
||||
pg.removeRenderBufferObject(glDepthStencil, context.code());
|
||||
pg.removeRenderBufferObject(glMultisample, context.code());
|
||||
|
||||
glFboID = 0;
|
||||
glDepthBufferID = 0;
|
||||
glStencilBufferID = 0;
|
||||
glDepthStencilBufferID = 0;
|
||||
glColorBufferMultisampleID = 0;
|
||||
glFbo = 0;
|
||||
glDepth = 0;
|
||||
glStencil = 0;
|
||||
glDepthStencil = 0;
|
||||
glMultisample = 0;
|
||||
|
||||
for (int i = 0; i < numColorBuffers; i++) {
|
||||
colorBufferTex[i] = null;
|
||||
@@ -356,10 +356,10 @@ public class FrameBuffer implements PConstants {
|
||||
pg.pushFramebuffer();
|
||||
pg.setFramebuffer(this);
|
||||
|
||||
glColorBufferMultisampleID = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glColorBufferMultisampleID);
|
||||
glMultisample = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glMultisample);
|
||||
pgl.glRenderbufferStorageMultisample(PGL.GL_RENDERBUFFER, nsamples, PGL.GL_RGBA8, width, height);
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0, PGL.GL_RENDERBUFFER, glColorBufferMultisampleID);
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0, PGL.GL_RENDERBUFFER, glMultisample);
|
||||
|
||||
pg.popFramebuffer();
|
||||
}
|
||||
@@ -375,8 +375,8 @@ public class FrameBuffer implements PConstants {
|
||||
pg.pushFramebuffer();
|
||||
pg.setFramebuffer(this);
|
||||
|
||||
glDepthStencilBufferID = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthStencilBufferID);
|
||||
glDepthStencil = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthStencil);
|
||||
|
||||
if (multisample) {
|
||||
pgl.glRenderbufferStorageMultisample(PGL.GL_RENDERBUFFER, nsamples, PGL.GL_DEPTH24_STENCIL8, width, height);
|
||||
@@ -384,8 +384,8 @@ public class FrameBuffer implements PConstants {
|
||||
pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, PGL.GL_DEPTH24_STENCIL8, width, height);
|
||||
}
|
||||
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencilBufferID);
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencilBufferID);
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencil);
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencil);
|
||||
|
||||
pg.popFramebuffer();
|
||||
}
|
||||
@@ -401,8 +401,8 @@ public class FrameBuffer implements PConstants {
|
||||
pg.pushFramebuffer();
|
||||
pg.setFramebuffer(this);
|
||||
|
||||
glDepthBufferID = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthBufferID);
|
||||
glDepth = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepth);
|
||||
|
||||
int glConst = PGL.GL_DEPTH_COMPONENT16;
|
||||
if (depthBits == 16) {
|
||||
@@ -419,7 +419,7 @@ public class FrameBuffer implements PConstants {
|
||||
pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, glConst, width, height);
|
||||
}
|
||||
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthBufferID);
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepth);
|
||||
|
||||
pg.popFramebuffer();
|
||||
}
|
||||
@@ -435,8 +435,8 @@ public class FrameBuffer implements PConstants {
|
||||
pg.pushFramebuffer();
|
||||
pg.setFramebuffer(this);
|
||||
|
||||
glStencilBufferID = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glStencilBufferID);
|
||||
glStencil = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glStencil);
|
||||
|
||||
int glConst = PGL.GL_STENCIL_INDEX1;
|
||||
if (stencilBits == 1) {
|
||||
@@ -452,7 +452,7 @@ public class FrameBuffer implements PConstants {
|
||||
pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, glConst, width, height);
|
||||
}
|
||||
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glStencilBufferID);
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glStencil);
|
||||
|
||||
pg.popFramebuffer();
|
||||
}
|
||||
|
||||
@@ -238,8 +238,8 @@ class PFontTexture implements PConstants {
|
||||
}
|
||||
if (outdated) {
|
||||
for (int i = 0; i < textures.length; i++) {
|
||||
pg.removeTextureObject(textures[i].glID, textures[i].context.code());
|
||||
textures[i].glID = 0;
|
||||
pg.removeTextureObject(textures[i].glName, textures[i].context.code());
|
||||
textures[i].glName = 0;
|
||||
}
|
||||
}
|
||||
return outdated;
|
||||
|
||||
@@ -738,11 +738,11 @@ public class PGL {
|
||||
// The screen framebuffer is the color FBO just created. We need
|
||||
// to update the screenFramebuffer object so when the framebuffer
|
||||
// is popped back to the screen, the correct id is set.
|
||||
PGraphicsOpenGL.screenFramebuffer.glFboID = glColorFboID[0];
|
||||
PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFboID[0];
|
||||
} else {
|
||||
// To make sure that the default screen buffer is used, specially after
|
||||
// doing screen rendering on an FBO (the OSX 10.7+ above).
|
||||
PGraphicsOpenGL.screenFramebuffer.glFboID = 0;
|
||||
PGraphicsOpenGL.screenFramebuffer.glFbo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -779,14 +779,14 @@ public class PGL {
|
||||
}
|
||||
|
||||
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFboID[0]);
|
||||
PGraphicsOpenGL.screenFramebuffer.glFboID = glColorFboID[0];
|
||||
PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFboID[0];
|
||||
}
|
||||
|
||||
|
||||
public void bindPrimaryMultiFBO() {
|
||||
if (multisample) {
|
||||
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glMultiFboID[0]);
|
||||
PGraphicsOpenGL.screenFramebuffer.glFboID = glMultiFboID[0];
|
||||
PGraphicsOpenGL.screenFramebuffer.glFbo = glMultiFboID[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -831,12 +831,12 @@ public class PGL {
|
||||
gl2x.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0);
|
||||
|
||||
// Now the screen buffer is the multisample FBO.
|
||||
PGraphicsOpenGL.screenFramebuffer.glFboID = glMultiFboID[0];
|
||||
PGraphicsOpenGL.screenFramebuffer.glFbo = glMultiFboID[0];
|
||||
} else {
|
||||
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFboID[0]);
|
||||
if (gl2x != null) gl2x.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0);
|
||||
|
||||
PGraphicsOpenGL.screenFramebuffer.glFboID = glColorFboID[0];
|
||||
PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFboID[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -865,7 +865,7 @@ public class PGL {
|
||||
|
||||
// Leaving the color FBO currently bound as the screen FB.
|
||||
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFboID[0]);
|
||||
PGraphicsOpenGL.screenFramebuffer.glFboID = glColorFboID[0];
|
||||
PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFboID[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1358,10 +1358,30 @@ public class PGL {
|
||||
|
||||
|
||||
public void glVertexAttrib4f(int loc, float value0, float value1, float value2, float value3) {
|
||||
gl2.glVertexAttrib4f(loc, value0, value1, value2, value3);
|
||||
gl2.glVertexAttrib4f(loc, value0, value1, value2, value3);
|
||||
}
|
||||
|
||||
|
||||
public void glVertexAttrib1fv(int loc, float[] v, int offset) {
|
||||
gl2.glVertexAttrib1fv(loc, v, offset);
|
||||
}
|
||||
|
||||
|
||||
public void glVertexAttrib2fv(int loc, float[] v, int offset) {
|
||||
gl2.glVertexAttrib2fv(loc, v, offset);
|
||||
}
|
||||
|
||||
|
||||
public void glVertexAttrib3fv(int loc, float[] v, int offset) {
|
||||
gl2.glVertexAttrib3fv(loc, v, offset);
|
||||
}
|
||||
|
||||
|
||||
public void glVertexAttrib4fv(int loc, float[] v, int offset) {
|
||||
gl2.glVertexAttrib4fv(loc, v, offset);
|
||||
}
|
||||
|
||||
|
||||
public void glShaderSource(int id, String source) {
|
||||
gl2.glShaderSource(id, 1, new String[] { source }, (int[]) null, 0);
|
||||
}
|
||||
@@ -1779,6 +1799,12 @@ public class PGL {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void drawTextureCustom(int target, int id, int width, int height,
|
||||
int X0, int Y0, int X1, int Y1, int program) {
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
public void drawTextureRect(int id, int width, int height,
|
||||
int texX0, int texY0, int texX1, int texY1,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,12 +36,13 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class PShader {
|
||||
// shaders constants
|
||||
static public final int FLAT = 0;
|
||||
static public final int LIT = 1;
|
||||
static public final int TEXTURED = 2;
|
||||
static public final int FULL = 3;
|
||||
static public final int LINE = 4;
|
||||
static public final int POINT = 5;
|
||||
static public final int FILTER = 0;
|
||||
static public final int FLAT = 1;
|
||||
static public final int LIT = 2;
|
||||
static public final int TEXTURED = 3;
|
||||
static public final int FULL = 4;
|
||||
static public final int LINE = 5;
|
||||
static public final int POINT = 6;
|
||||
|
||||
protected PApplet parent;
|
||||
// The main renderer associated to the parent PApplet.
|
||||
@@ -55,9 +56,9 @@ public class PShader {
|
||||
protected PGL pgl;
|
||||
protected PGL.Context context; // The context that created this shader.
|
||||
|
||||
public int glProgramObjectID;
|
||||
public int glVertexShaderID;
|
||||
public int glFragmentShaderID;
|
||||
public int glProgram;
|
||||
public int glVertex;
|
||||
public int glFragment;
|
||||
|
||||
protected URL vertexURL;
|
||||
protected URL fragmentURL;
|
||||
@@ -83,9 +84,9 @@ public class PShader {
|
||||
this.vertexFilename = null;
|
||||
this.fragmentFilename = null;
|
||||
|
||||
glProgramObjectID = 0;
|
||||
glVertexShaderID = 0;
|
||||
glFragmentShaderID = 0;
|
||||
glProgram = 0;
|
||||
glVertex = 0;
|
||||
glFragment = 0;
|
||||
|
||||
bound = false;
|
||||
}
|
||||
@@ -118,9 +119,9 @@ public class PShader {
|
||||
this.vertexFilename = vertFilename;
|
||||
this.fragmentFilename = fragFilename;
|
||||
|
||||
glProgramObjectID = 0;
|
||||
glVertexShaderID = 0;
|
||||
glFragmentShaderID = 0;
|
||||
glProgram = 0;
|
||||
glVertex = 0;
|
||||
glFragment = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,22 +135,22 @@ public class PShader {
|
||||
this.vertexFilename = null;
|
||||
this.fragmentFilename = null;
|
||||
|
||||
glProgramObjectID = 0;
|
||||
glVertexShaderID = 0;
|
||||
glFragmentShaderID = 0;
|
||||
glProgram = 0;
|
||||
glVertex = 0;
|
||||
glFragment = 0;
|
||||
}
|
||||
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (glVertexShaderID != 0) {
|
||||
pgMain.finalizeGLSLVertShaderObject(glVertexShaderID, context.code());
|
||||
if (glVertex != 0) {
|
||||
pgMain.finalizeGLSLVertShaderObject(glVertex, context.code());
|
||||
}
|
||||
if (glFragmentShaderID != 0) {
|
||||
pgMain.finalizeGLSLFragShaderObject(glFragmentShaderID, context.code());
|
||||
if (glFragment != 0) {
|
||||
pgMain.finalizeGLSLFragShaderObject(glFragment, context.code());
|
||||
}
|
||||
if (glProgramObjectID != 0) {
|
||||
pgMain.finalizeGLSLProgramObject(glProgramObjectID, context.code());
|
||||
if (glProgram != 0) {
|
||||
pgMain.finalizeGLSLProgramObject(glProgram, context.code());
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
@@ -182,7 +183,7 @@ public class PShader {
|
||||
*/
|
||||
public void bind() {
|
||||
init();
|
||||
pgl.glUseProgram(glProgramObjectID);
|
||||
pgl.glUseProgram(glProgram);
|
||||
bound = true;
|
||||
consumeUniforms();
|
||||
}
|
||||
@@ -328,9 +329,9 @@ public class PShader {
|
||||
* @param name String
|
||||
* @return int
|
||||
*/
|
||||
protected int getAttribLocation(String name) {
|
||||
protected int getAttributeLoc(String name) {
|
||||
init();
|
||||
return pgl.glGetAttribLocation(glProgramObjectID, name);
|
||||
return pgl.glGetAttribLocation(glProgram, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -340,13 +341,13 @@ public class PShader {
|
||||
* @param name String
|
||||
* @return int
|
||||
*/
|
||||
protected int getUniformLocation(String name) {
|
||||
protected int getUniformLoc(String name) {
|
||||
init();
|
||||
return pgl.glGetUniformLocation(glProgramObjectID, name);
|
||||
return pgl.glGetUniformLocation(glProgram, name);
|
||||
}
|
||||
|
||||
|
||||
protected void setAttribute(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) {
|
||||
protected void setAttributeVBO(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) {
|
||||
if (-1 < loc) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, vboId);
|
||||
pgl.glVertexAttribPointer(loc, size, type, normalized, stride, offset);
|
||||
@@ -354,62 +355,62 @@ public class PShader {
|
||||
}
|
||||
|
||||
|
||||
protected void setIntUniform(int loc, int x) {
|
||||
protected void setUniformValue(int loc, int x) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniform1i(loc, x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setIntUniform(int loc, int x, int y) {
|
||||
protected void setUniformValue(int loc, int x, int y) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniform2i(loc, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setIntUniform(int loc, int x, int y, int z) {
|
||||
protected void setUniformValue(int loc, int x, int y, int z) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniform3i(loc, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setIntUniform(int loc, int x, int y, int z, int w) {
|
||||
protected void setUniformValue(int loc, int x, int y, int z, int w) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniform4i(loc, x, y, z, w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setFloatUniform(int loc, float x) {
|
||||
protected void setUniformValue(int loc, float x) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniform1f(loc, x);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setFloatUniform(int loc, float x, float y) {
|
||||
protected void setUniformValue(int loc, float x, float y) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniform2f(loc, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setFloatUniform(int loc, float x, float y, float z) {
|
||||
protected void setUniformValue(int loc, float x, float y, float z) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniform3f(loc, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setFloatUniform(int loc, float x, float y, float z, float w) {
|
||||
protected void setUniformValue(int loc, float x, float y, float z, float w) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniform4f(loc, x, y, z, w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setIntVecUniform(int loc, int[] vec, int ncoords) {
|
||||
protected void setUniformVector(int loc, int[] vec, int ncoords) {
|
||||
if (-1 < loc) {
|
||||
if (ncoords == 1) {
|
||||
pgl.glUniform1iv(loc, vec.length, vec, 0);
|
||||
@@ -424,7 +425,7 @@ public class PShader {
|
||||
}
|
||||
|
||||
|
||||
protected void setFloatVecUniform(int loc, float[] vec, int ncoords) {
|
||||
protected void setUniformVector(int loc, float[] vec, int ncoords) {
|
||||
if (-1 < loc) {
|
||||
if (ncoords == 1) {
|
||||
pgl.glUniform1fv(loc, vec.length, vec, 0);
|
||||
@@ -439,25 +440,18 @@ public class PShader {
|
||||
}
|
||||
|
||||
|
||||
protected void setMat2Uniform(int loc, float[] mat) {
|
||||
protected void setUniformMatrix(int loc, float[] mat) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniformMatrix2fv(loc, 1, false, mat, 0);
|
||||
if (mat.length == 4) {
|
||||
pgl.glUniformMatrix2fv(loc, 1, false, mat, 0);
|
||||
} else if (mat.length == 9) {
|
||||
pgl.glUniformMatrix3fv(loc, 1, false, mat, 0);
|
||||
} else if (mat.length == 16) {
|
||||
pgl.glUniformMatrix4fv(loc, 1, false, mat, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setMat3Uniform(int loc, float[] mat) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniformMatrix3fv(loc, 1, false, mat, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setMat4Uniform(int loc, float[] mat) {
|
||||
if (-1 < loc) {
|
||||
pgl.glUniformMatrix4fv(loc, 1, false, mat, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@@ -494,7 +488,7 @@ public class PShader {
|
||||
|
||||
|
||||
protected void setUniformImpl(String name, int type, Object value) {
|
||||
int loc = getUniformLocation(name);
|
||||
int loc = getUniformLoc(name);
|
||||
if (-1 < loc) {
|
||||
if (uniformValues == null) {
|
||||
uniformValues = new HashMap<Integer, UniformValue>();
|
||||
@@ -575,9 +569,9 @@ public class PShader {
|
||||
|
||||
|
||||
protected void init() {
|
||||
if (glProgramObjectID == 0 || contextIsOutdated()) {
|
||||
if (glProgram == 0 || contextIsOutdated()) {
|
||||
context = pgl.getCurrentContext();
|
||||
glProgramObjectID = pgMain.createGLSLProgramObject(context.code());
|
||||
glProgram = pgMain.createGLSLProgramObject(context.code());
|
||||
|
||||
boolean hasVert = false;
|
||||
if (vertexFilename != null) {
|
||||
@@ -609,25 +603,25 @@ public class PShader {
|
||||
|
||||
if (vertRes && fragRes) {
|
||||
if (hasVert) {
|
||||
pgl.glAttachShader(glProgramObjectID, glVertexShaderID);
|
||||
pgl.glAttachShader(glProgram, glVertex);
|
||||
}
|
||||
if (hasFrag) {
|
||||
pgl.glAttachShader(glProgramObjectID, glFragmentShaderID);
|
||||
pgl.glAttachShader(glProgram, glFragment);
|
||||
}
|
||||
pgl.glLinkProgram(glProgramObjectID);
|
||||
pgl.glLinkProgram(glProgram);
|
||||
|
||||
int[] linked = new int[1];
|
||||
pgl.glGetProgramiv(glProgramObjectID, PGL.GL_LINK_STATUS, linked, 0);
|
||||
pgl.glGetProgramiv(glProgram, PGL.GL_LINK_STATUS, linked, 0);
|
||||
if (linked[0] == PGL.GL_FALSE) {
|
||||
PGraphics.showException("Cannot link shader program:\n" + pgl.glGetProgramInfoLog(glProgramObjectID));
|
||||
PGraphics.showException("Cannot link shader program:\n" + pgl.glGetProgramInfoLog(glProgram));
|
||||
}
|
||||
|
||||
pgl.glValidateProgram(glProgramObjectID);
|
||||
pgl.glValidateProgram(glProgram);
|
||||
|
||||
int[] validated = new int[1];
|
||||
pgl.glGetProgramiv(glProgramObjectID, PGL.GL_VALIDATE_STATUS, validated, 0);
|
||||
pgl.glGetProgramiv(glProgram, PGL.GL_VALIDATE_STATUS, validated, 0);
|
||||
if (validated[0] == PGL.GL_FALSE) {
|
||||
PGraphics.showException("Cannot validate shader program:\n" + pgl.glGetProgramInfoLog(glProgramObjectID));
|
||||
PGraphics.showException("Cannot validate shader program:\n" + pgl.glGetProgramInfoLog(glProgram));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -637,13 +631,13 @@ public class PShader {
|
||||
protected boolean contextIsOutdated() {
|
||||
boolean outdated = !pgl.contextIsCurrent(context);
|
||||
if (outdated) {
|
||||
pgMain.removeGLSLProgramObject(glProgramObjectID, context.code());
|
||||
pgMain.removeGLSLVertShaderObject(glVertexShaderID, context.code());
|
||||
pgMain.removeGLSLFragShaderObject(glFragmentShaderID, context.code());
|
||||
pgMain.removeGLSLProgramObject(glProgram, context.code());
|
||||
pgMain.removeGLSLVertShaderObject(glVertex, context.code());
|
||||
pgMain.removeGLSLFragShaderObject(glFragment, context.code());
|
||||
|
||||
glProgramObjectID = 0;
|
||||
glVertexShaderID = 0;
|
||||
glFragmentShaderID = 0;
|
||||
glProgram = 0;
|
||||
glVertex = 0;
|
||||
glFragment = 0;
|
||||
}
|
||||
return outdated;
|
||||
}
|
||||
@@ -707,15 +701,15 @@ public class PShader {
|
||||
* @param shaderSource a string containing the shader's code
|
||||
*/
|
||||
protected boolean compileVertexShader() {
|
||||
glVertexShaderID = pgMain.createGLSLVertShaderObject(context.code());
|
||||
glVertex = pgMain.createGLSLVertShaderObject(context.code());
|
||||
|
||||
pgl.glShaderSource(glVertexShaderID, vertexShaderSource);
|
||||
pgl.glCompileShader(glVertexShaderID);
|
||||
pgl.glShaderSource(glVertex, vertexShaderSource);
|
||||
pgl.glCompileShader(glVertex);
|
||||
|
||||
int[] compiled = new int[1];
|
||||
pgl.glGetShaderiv(glVertexShaderID, PGL.GL_COMPILE_STATUS, compiled, 0);
|
||||
pgl.glGetShaderiv(glVertex, PGL.GL_COMPILE_STATUS, compiled, 0);
|
||||
if (compiled[0] == PGL.GL_FALSE) {
|
||||
PGraphics.showException("Cannot compile vertex shader:\n" + pgl.glGetShaderInfoLog(glVertexShaderID));
|
||||
PGraphics.showException("Cannot compile vertex shader:\n" + pgl.glGetShaderInfoLog(glVertex));
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -727,15 +721,15 @@ public class PShader {
|
||||
* @param shaderSource a string containing the shader's code
|
||||
*/
|
||||
protected boolean compileFragmentShader() {
|
||||
glFragmentShaderID = pgMain.createGLSLFragShaderObject(context.code());
|
||||
glFragment = pgMain.createGLSLFragShaderObject(context.code());
|
||||
|
||||
pgl.glShaderSource(glFragmentShaderID, fragmentShaderSource);
|
||||
pgl.glCompileShader(glFragmentShaderID);
|
||||
pgl.glShaderSource(glFragment, fragmentShaderSource);
|
||||
pgl.glCompileShader(glFragment);
|
||||
|
||||
int[] compiled = new int[1];
|
||||
pgl.glGetShaderiv(glFragmentShaderID, PGL.GL_COMPILE_STATUS, compiled, 0);
|
||||
pgl.glGetShaderiv(glFragment, PGL.GL_COMPILE_STATUS, compiled, 0);
|
||||
if (compiled[0] == PGL.GL_FALSE) {
|
||||
PGraphics.showException("Cannot compile fragment shader:\n" + pgl.glGetShaderInfoLog(glFragmentShaderID));
|
||||
PGraphics.showException("Cannot compile fragment shader:\n" + pgl.glGetShaderInfoLog(glFragment));
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -754,17 +748,17 @@ public class PShader {
|
||||
|
||||
|
||||
protected void release() {
|
||||
if (glVertexShaderID != 0) {
|
||||
pgMain.deleteGLSLVertShaderObject(glVertexShaderID, context.code());
|
||||
glVertexShaderID = 0;
|
||||
if (glVertex != 0) {
|
||||
pgMain.deleteGLSLVertShaderObject(glVertex, context.code());
|
||||
glVertex = 0;
|
||||
}
|
||||
if (glFragmentShaderID != 0) {
|
||||
pgMain.deleteGLSLFragShaderObject(glFragmentShaderID, context.code());
|
||||
glFragmentShaderID = 0;
|
||||
if (glFragment != 0) {
|
||||
pgMain.deleteGLSLFragShaderObject(glFragment, context.code());
|
||||
glFragment = 0;
|
||||
}
|
||||
if (glProgramObjectID != 0) {
|
||||
pgMain.deleteGLSLProgramObject(glProgramObjectID, context.code());
|
||||
glProgramObjectID = 0;
|
||||
if (glProgram != 0) {
|
||||
pgMain.deleteGLSLProgramObject(glProgram, context.code());
|
||||
glProgram = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,25 +92,25 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
// OpenGL buffers
|
||||
|
||||
public int glPolyVertexBufferID;
|
||||
public int glPolyColorBufferID;
|
||||
public int glPolyNormalBufferID;
|
||||
public int glPolyTexcoordBufferID;
|
||||
public int glPolyAmbientBufferID;
|
||||
public int glPolySpecularBufferID;
|
||||
public int glPolyEmissiveBufferID;
|
||||
public int glPolyShininessBufferID;
|
||||
public int glPolyIndexBufferID;
|
||||
public int glPolyVertex;
|
||||
public int glPolyColor;
|
||||
public int glPolyNormal;
|
||||
public int glPolyTexcoord;
|
||||
public int glPolyAmbient;
|
||||
public int glPolySpecular;
|
||||
public int glPolyEmissive;
|
||||
public int glPolyShininess;
|
||||
public int glPolyIndex;
|
||||
|
||||
public int glLineVertexBufferID;
|
||||
public int glLineColorBufferID;
|
||||
public int glLineAttribBufferID;
|
||||
public int glLineIndexBufferID;
|
||||
public int glLineVertex;
|
||||
public int glLineColor;
|
||||
public int glLineAttrib;
|
||||
public int glLineIndex;
|
||||
|
||||
public int glPointVertexBufferID;
|
||||
public int glPointColorBufferID;
|
||||
public int glPointAttribBufferID;
|
||||
public int glPointIndexBufferID;
|
||||
public int glPointVertex;
|
||||
public int glPointColor;
|
||||
public int glPointAttrib;
|
||||
public int glPointIndex;
|
||||
|
||||
// ........................................................
|
||||
|
||||
@@ -281,25 +281,25 @@ public class PShapeOpenGL extends PShape {
|
||||
pgl = pg.pgl;
|
||||
context = pgl.createEmptyContext();
|
||||
|
||||
glPolyVertexBufferID = 0;
|
||||
glPolyColorBufferID = 0;
|
||||
glPolyNormalBufferID = 0;
|
||||
glPolyTexcoordBufferID = 0;
|
||||
glPolyAmbientBufferID = 0;
|
||||
glPolySpecularBufferID = 0;
|
||||
glPolyEmissiveBufferID = 0;
|
||||
glPolyShininessBufferID = 0;
|
||||
glPolyIndexBufferID = 0;
|
||||
glPolyVertex = 0;
|
||||
glPolyColor = 0;
|
||||
glPolyNormal = 0;
|
||||
glPolyTexcoord = 0;
|
||||
glPolyAmbient = 0;
|
||||
glPolySpecular = 0;
|
||||
glPolyEmissive = 0;
|
||||
glPolyShininess = 0;
|
||||
glPolyIndex = 0;
|
||||
|
||||
glLineVertexBufferID = 0;
|
||||
glLineColorBufferID = 0;
|
||||
glLineAttribBufferID = 0;
|
||||
glLineIndexBufferID = 0;
|
||||
glLineVertex = 0;
|
||||
glLineColor = 0;
|
||||
glLineAttrib = 0;
|
||||
glLineIndex = 0;
|
||||
|
||||
glPointVertexBufferID = 0;
|
||||
glPointColorBufferID = 0;
|
||||
glPointAttribBufferID = 0;
|
||||
glPointIndexBufferID = 0;
|
||||
glPointVertex = 0;
|
||||
glPointColor = 0;
|
||||
glPointAttrib = 0;
|
||||
glPointIndex = 0;
|
||||
|
||||
this.tessellator = PGraphicsOpenGL.tessellator;
|
||||
this.family = family;
|
||||
@@ -413,78 +413,78 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void finalizePolyBuffers() {
|
||||
if (glPolyVertexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyVertexBufferID, context.code());
|
||||
if (glPolyVertex != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyVertex, context.code());
|
||||
}
|
||||
|
||||
if (glPolyColorBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyColorBufferID, context.code());
|
||||
if (glPolyColor != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyColor, context.code());
|
||||
}
|
||||
|
||||
if (glPolyNormalBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyNormalBufferID, context.code());
|
||||
if (glPolyNormal != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyNormal, context.code());
|
||||
}
|
||||
|
||||
if (glPolyTexcoordBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyTexcoordBufferID, context.code());
|
||||
if (glPolyTexcoord != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyTexcoord, context.code());
|
||||
}
|
||||
|
||||
if (glPolyAmbientBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyAmbientBufferID, context.code());
|
||||
if (glPolyAmbient != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyAmbient, context.code());
|
||||
}
|
||||
|
||||
if (glPolySpecularBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolySpecularBufferID, context.code());
|
||||
if (glPolySpecular != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolySpecular, context.code());
|
||||
}
|
||||
|
||||
if (glPolyEmissiveBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyEmissiveBufferID, context.code());
|
||||
if (glPolyEmissive != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyEmissive, context.code());
|
||||
}
|
||||
|
||||
if (glPolyShininessBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyShininessBufferID, context.code());
|
||||
if (glPolyShininess != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyShininess, context.code());
|
||||
}
|
||||
|
||||
if (glPolyIndexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyIndexBufferID, context.code());
|
||||
if (glPolyIndex != 0) {
|
||||
pg.finalizeVertexBufferObject(glPolyIndex, context.code());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void finalizeLineBuffers() {
|
||||
if (glLineVertexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineVertexBufferID, context.code());
|
||||
if (glLineVertex != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineVertex, context.code());
|
||||
}
|
||||
|
||||
if (glLineColorBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineColorBufferID, context.code());
|
||||
if (glLineColor != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineColor, context.code());
|
||||
}
|
||||
|
||||
if (glLineAttribBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineAttribBufferID, context.code());
|
||||
if (glLineAttrib != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineAttrib, context.code());
|
||||
}
|
||||
|
||||
if (glLineIndexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineIndexBufferID, context.code());
|
||||
if (glLineIndex != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineIndex, context.code());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void finalizePointBuffers() {
|
||||
if (glPointVertexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointVertexBufferID, context.code());
|
||||
if (glPointVertex != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointVertex, context.code());
|
||||
}
|
||||
|
||||
if (glPointColorBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointColorBufferID, context.code());
|
||||
if (glPointColor != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointColor, context.code());
|
||||
}
|
||||
|
||||
if (glPointAttribBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointAttribBufferID, context.code());
|
||||
if (glPointAttrib != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointAttrib, context.code());
|
||||
}
|
||||
|
||||
if (glPointIndexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointIndexBufferID, context.code());
|
||||
if (glPointIndex != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointIndex, context.code());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3114,42 +3114,42 @@ public class PShapeOpenGL extends PShape {
|
||||
int sizef = size * PGL.SIZEOF_FLOAT;
|
||||
int sizei = size * PGL.SIZEOF_INT;
|
||||
|
||||
glPolyVertexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID);
|
||||
glPolyVertex = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.polyVertices, 0, 4 * size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPolyColorBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID);
|
||||
glPolyColor = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyColors, 0, size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPolyNormalBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID);
|
||||
glPolyNormal = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, FloatBuffer.wrap(tessGeo.polyNormals, 0, 3 * size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPolyTexcoordBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID);
|
||||
glPolyTexcoord = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.polyTexcoords, 0, 2 * size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPolyAmbientBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID);
|
||||
glPolyAmbient = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyAmbient, 0, size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPolySpecularBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID);
|
||||
glPolySpecular = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polySpecular, 0, size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPolyEmissiveBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID);
|
||||
glPolyEmissive = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyEmissive, 0, size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPolyShininessBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID);
|
||||
glPolyShininess = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizef, FloatBuffer.wrap(tessGeo.polyShininess, 0, size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glPolyIndexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID);
|
||||
glPolyIndex = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex);
|
||||
pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.polyIndexCount * PGL.SIZEOF_INDEX,
|
||||
ShortBuffer.wrap(tessGeo.polyIndices, 0, tessGeo.polyIndexCount), PGL.GL_STATIC_DRAW);
|
||||
|
||||
@@ -3162,22 +3162,22 @@ public class PShapeOpenGL extends PShape {
|
||||
int sizef = size * PGL.SIZEOF_FLOAT;
|
||||
int sizei = size * PGL.SIZEOF_INT;
|
||||
|
||||
glLineVertexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID);
|
||||
glLineVertex = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineVertices, 0, 4 * size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glLineColorBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID);
|
||||
glLineColor = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.lineColors, 0, size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glLineAttribBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID);
|
||||
glLineAttrib = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineAttribs, 0, 4 * size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glLineIndexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID);
|
||||
glLineIndex = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex);
|
||||
pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.lineIndexCount * PGL.SIZEOF_INDEX,
|
||||
ShortBuffer.wrap(tessGeo.lineIndices, 0, tessGeo.lineIndexCount), PGL.GL_STATIC_DRAW);
|
||||
|
||||
@@ -3190,22 +3190,22 @@ public class PShapeOpenGL extends PShape {
|
||||
int sizef = size * PGL.SIZEOF_FLOAT;
|
||||
int sizei = size * PGL.SIZEOF_INT;
|
||||
|
||||
glPointVertexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID);
|
||||
glPointVertex = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.pointVertices, 0, 4 * size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPointColorBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID);
|
||||
glPointColor = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.pointColors, 0, size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPointAttribBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID);
|
||||
glPointAttrib = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.pointAttribs, 0, 2 * size), PGL.GL_STATIC_DRAW);
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glPointIndexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID);
|
||||
glPointIndex = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex);
|
||||
pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.pointIndexCount * PGL.SIZEOF_INDEX,
|
||||
ShortBuffer.wrap(tessGeo.pointIndices, 0, tessGeo.pointIndexCount), PGL.GL_STATIC_DRAW);
|
||||
|
||||
@@ -3220,49 +3220,49 @@ public class PShapeOpenGL extends PShape {
|
||||
// doesn't get deleted by OpenGL. The VBOs were already
|
||||
// automatically disposed when the old context was
|
||||
// destroyed.
|
||||
pg.removeVertexBufferObject(glPolyVertexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolyColorBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolyNormalBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolyTexcoordBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolyAmbientBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolySpecularBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolyEmissiveBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolyShininessBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolyIndexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPolyVertex, context.code());
|
||||
pg.removeVertexBufferObject(glPolyColor, context.code());
|
||||
pg.removeVertexBufferObject(glPolyNormal, context.code());
|
||||
pg.removeVertexBufferObject(glPolyTexcoord, context.code());
|
||||
pg.removeVertexBufferObject(glPolyAmbient, context.code());
|
||||
pg.removeVertexBufferObject(glPolySpecular, context.code());
|
||||
pg.removeVertexBufferObject(glPolyEmissive, context.code());
|
||||
pg.removeVertexBufferObject(glPolyShininess, context.code());
|
||||
pg.removeVertexBufferObject(glPolyIndex, context.code());
|
||||
|
||||
pg.removeVertexBufferObject(glLineVertexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glLineColorBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glLineAttribBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glLineIndexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glLineVertex, context.code());
|
||||
pg.removeVertexBufferObject(glLineColor, context.code());
|
||||
pg.removeVertexBufferObject(glLineAttrib, context.code());
|
||||
pg.removeVertexBufferObject(glLineIndex, context.code());
|
||||
|
||||
pg.removeVertexBufferObject(glPointVertexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPointColorBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPointAttribBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPointIndexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPointVertex, context.code());
|
||||
pg.removeVertexBufferObject(glPointColor, context.code());
|
||||
pg.removeVertexBufferObject(glPointAttrib, context.code());
|
||||
pg.removeVertexBufferObject(glPointIndex, context.code());
|
||||
|
||||
// The OpenGL resources have been already deleted
|
||||
// when the context changed. We only need to zero
|
||||
// them to avoid deleting them again when the GC
|
||||
// runs the finalizers of the disposed object.
|
||||
glPolyVertexBufferID = 0;
|
||||
glPolyColorBufferID = 0;
|
||||
glPolyNormalBufferID = 0;
|
||||
glPolyTexcoordBufferID = 0;
|
||||
glPolyAmbientBufferID = 0;
|
||||
glPolySpecularBufferID = 0;
|
||||
glPolyEmissiveBufferID = 0;
|
||||
glPolyShininessBufferID = 0;
|
||||
glPolyIndexBufferID = 0;
|
||||
glPolyVertex = 0;
|
||||
glPolyColor = 0;
|
||||
glPolyNormal = 0;
|
||||
glPolyTexcoord = 0;
|
||||
glPolyAmbient = 0;
|
||||
glPolySpecular = 0;
|
||||
glPolyEmissive = 0;
|
||||
glPolyShininess = 0;
|
||||
glPolyIndex = 0;
|
||||
|
||||
glLineVertexBufferID = 0;
|
||||
glLineColorBufferID = 0;
|
||||
glLineAttribBufferID = 0;
|
||||
glLineIndexBufferID = 0;
|
||||
glLineVertex = 0;
|
||||
glLineColor = 0;
|
||||
glLineAttrib = 0;
|
||||
glLineIndex = 0;
|
||||
|
||||
glPointVertexBufferID = 0;
|
||||
glPointColorBufferID = 0;
|
||||
glPointAttribBufferID = 0;
|
||||
glPointIndexBufferID = 0;
|
||||
glPointVertex = 0;
|
||||
glPointColor = 0;
|
||||
glPointAttrib = 0;
|
||||
glPointIndex = 0;
|
||||
}
|
||||
return outdated;
|
||||
}
|
||||
@@ -3283,95 +3283,95 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void deletePolyBuffers() {
|
||||
if (glPolyVertexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyVertexBufferID, context.code());
|
||||
glPolyVertexBufferID = 0;
|
||||
if (glPolyVertex != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyVertex, context.code());
|
||||
glPolyVertex = 0;
|
||||
}
|
||||
|
||||
if (glPolyColorBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyColorBufferID, context.code());
|
||||
glPolyColorBufferID = 0;
|
||||
if (glPolyColor != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyColor, context.code());
|
||||
glPolyColor = 0;
|
||||
}
|
||||
|
||||
if (glPolyNormalBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyNormalBufferID, context.code());
|
||||
glPolyNormalBufferID = 0;
|
||||
if (glPolyNormal != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyNormal, context.code());
|
||||
glPolyNormal = 0;
|
||||
}
|
||||
|
||||
if (glPolyTexcoordBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyTexcoordBufferID, context.code());
|
||||
glPolyTexcoordBufferID = 0;
|
||||
if (glPolyTexcoord != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyTexcoord, context.code());
|
||||
glPolyTexcoord = 0;
|
||||
}
|
||||
|
||||
if (glPolyAmbientBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyAmbientBufferID, context.code());
|
||||
glPolyAmbientBufferID = 0;
|
||||
if (glPolyAmbient != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyAmbient, context.code());
|
||||
glPolyAmbient = 0;
|
||||
}
|
||||
|
||||
if (glPolySpecularBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolySpecularBufferID, context.code());
|
||||
glPolySpecularBufferID = 0;
|
||||
if (glPolySpecular != 0) {
|
||||
pg.deleteVertexBufferObject(glPolySpecular, context.code());
|
||||
glPolySpecular = 0;
|
||||
}
|
||||
|
||||
if (glPolyEmissiveBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyEmissiveBufferID, context.code());
|
||||
glPolyEmissiveBufferID = 0;
|
||||
if (glPolyEmissive != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyEmissive, context.code());
|
||||
glPolyEmissive = 0;
|
||||
}
|
||||
|
||||
if (glPolyShininessBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyShininessBufferID, context.code());
|
||||
glPolyShininessBufferID = 0;
|
||||
if (glPolyShininess != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyShininess, context.code());
|
||||
glPolyShininess = 0;
|
||||
}
|
||||
|
||||
if (glPolyIndexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyIndexBufferID, context.code());
|
||||
glPolyIndexBufferID = 0;
|
||||
if (glPolyIndex != 0) {
|
||||
pg.deleteVertexBufferObject(glPolyIndex, context.code());
|
||||
glPolyIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void deleteLineBuffers() {
|
||||
if (glLineVertexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glLineVertexBufferID, context.code());
|
||||
glLineVertexBufferID = 0;
|
||||
if (glLineVertex != 0) {
|
||||
pg.deleteVertexBufferObject(glLineVertex, context.code());
|
||||
glLineVertex = 0;
|
||||
}
|
||||
|
||||
if (glLineColorBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glLineColorBufferID, context.code());
|
||||
glLineColorBufferID = 0;
|
||||
if (glLineColor != 0) {
|
||||
pg.deleteVertexBufferObject(glLineColor, context.code());
|
||||
glLineColor = 0;
|
||||
}
|
||||
|
||||
if (glLineAttribBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glLineAttribBufferID, context.code());
|
||||
glLineAttribBufferID = 0;
|
||||
if (glLineAttrib != 0) {
|
||||
pg.deleteVertexBufferObject(glLineAttrib, context.code());
|
||||
glLineAttrib = 0;
|
||||
}
|
||||
|
||||
if (glLineIndexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glLineIndexBufferID, context.code());
|
||||
glLineIndexBufferID = 0;
|
||||
if (glLineIndex != 0) {
|
||||
pg.deleteVertexBufferObject(glLineIndex, context.code());
|
||||
glLineIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void deletePointBuffers() {
|
||||
if (glPointVertexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPointVertexBufferID, context.code());
|
||||
glPointVertexBufferID = 0;
|
||||
if (glPointVertex != 0) {
|
||||
pg.deleteVertexBufferObject(glPointVertex, context.code());
|
||||
glPointVertex = 0;
|
||||
}
|
||||
|
||||
if (glPointColorBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPointColorBufferID, context.code());
|
||||
glPointColorBufferID = 0;
|
||||
if (glPointColor != 0) {
|
||||
pg.deleteVertexBufferObject(glPointColor, context.code());
|
||||
glPointColor = 0;
|
||||
}
|
||||
|
||||
if (glPointAttribBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPointAttribBufferID, context.code());
|
||||
glPointAttribBufferID = 0;
|
||||
if (glPointAttrib != 0) {
|
||||
pg.deleteVertexBufferObject(glPointAttrib, context.code());
|
||||
glPointAttrib = 0;
|
||||
}
|
||||
|
||||
if (glPointIndexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPointIndexBufferID, context.code());
|
||||
glPointIndexBufferID = 0;
|
||||
if (glPointIndex != 0) {
|
||||
pg.deleteVertexBufferObject(glPointIndex, context.code());
|
||||
glPointIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3512,7 +3512,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPolyVertices(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(tessGeo.polyVertices, 4 * offset, 4 * size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3520,7 +3520,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPolyColors(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT,
|
||||
IntBuffer.wrap(tessGeo.polyColors, offset, size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3528,7 +3528,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPolyNormals(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 3 * offset * PGL.SIZEOF_FLOAT, 3 * size * PGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(tessGeo.polyNormals, 3 * offset, 3 * size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3536,7 +3536,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPolyTexcoords(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(tessGeo.polyTexcoords, 2 * offset, 2 * size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3544,7 +3544,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPolyAmbient(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT,
|
||||
IntBuffer.wrap(tessGeo.polyAmbient, offset, size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3552,7 +3552,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPolySpecular(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT,
|
||||
IntBuffer.wrap(tessGeo.polySpecular, offset, size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3560,7 +3560,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPolyEmissive(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT,
|
||||
IntBuffer.wrap(tessGeo.polyEmissive, offset, size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3568,7 +3568,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPolyShininess(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_FLOAT, size * PGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(tessGeo.polyShininess, offset, size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3576,7 +3576,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyLineVertices(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(tessGeo.lineVertices, 4 * offset, 4 * size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3584,7 +3584,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyLineColors(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT,
|
||||
IntBuffer.wrap(tessGeo.lineColors, offset, size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3592,7 +3592,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyLineAttributes(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(tessGeo.lineAttribs, 4 * offset, 4 * size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3600,7 +3600,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPointVertices(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(tessGeo.pointVertices, 4 * offset, 4 * size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3608,7 +3608,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPointColors(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT,
|
||||
IntBuffer.wrap(tessGeo.pointColors, offset, size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3616,7 +3616,7 @@ public class PShapeOpenGL extends PShape {
|
||||
|
||||
|
||||
protected void copyPointAttributes(int offset, int size) {
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib);
|
||||
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(tessGeo.pointAttribs, 2 * offset, 2 * size));
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3908,7 +3908,7 @@ public class PShapeOpenGL extends PShape {
|
||||
tex = g.getTexture(textureImage);
|
||||
if (tex != null) {
|
||||
pgl.enableTexturing(tex.glTarget);
|
||||
pgl.glBindTexture(tex.glTarget, tex.glID);
|
||||
pgl.glBindTexture(tex.glTarget, tex.glName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3951,23 +3951,23 @@ public class PShapeOpenGL extends PShape {
|
||||
int icount = cache.indexCount[n];
|
||||
int voffset = cache.vertexOffset[n];
|
||||
|
||||
shader.setVertexAttribute(root.glPolyVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setColorAttribute(root.glPolyColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setVertexAttribute(root.glPolyVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setColorAttribute(root.glPolyColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
|
||||
if (g.lights) {
|
||||
shader.setNormalAttribute(root.glPolyNormalBufferID, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setAmbientAttribute(root.glPolyAmbientBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setSpecularAttribute(root.glPolySpecularBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setEmissiveAttribute(root.glPolyEmissiveBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setShininessAttribute(root.glPolyShininessBufferID, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setNormalAttribute(root.glPolyNormal, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setAmbientAttribute(root.glPolyAmbient, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setSpecularAttribute(root.glPolySpecular, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setEmissiveAttribute(root.glPolyEmissive, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setShininessAttribute(root.glPolyShininess, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT);
|
||||
}
|
||||
|
||||
if (tex != null) {
|
||||
shader.setTexcoordAttribute(root.glPolyTexcoordBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setTexcoordAttribute(root.glPolyTexcoord, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setTexture(tex);
|
||||
}
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPolyIndexBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPolyIndex);
|
||||
pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX);
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
@@ -4082,11 +4082,11 @@ public class PShapeOpenGL extends PShape {
|
||||
int icount = cache.indexCount[n];
|
||||
int voffset = cache.vertexOffset[n];
|
||||
|
||||
shader.setVertexAttribute(root.glLineVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setColorAttribute(root.glLineColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setLineAttribute(root.glLineAttribBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setVertexAttribute(root.glLineVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setColorAttribute(root.glLineColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setLineAttribute(root.glLineAttrib, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glLineIndexBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glLineIndex);
|
||||
pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX);
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
@@ -4176,11 +4176,11 @@ public class PShapeOpenGL extends PShape {
|
||||
int icount = cache.indexCount[n];
|
||||
int voffset = cache.vertexOffset[n];
|
||||
|
||||
shader.setVertexAttribute(root.glPointVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setColorAttribute(root.glPointColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setPointAttribute(root.glPointAttribBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setVertexAttribute(root.glPointVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
|
||||
shader.setColorAttribute(root.glPointColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
|
||||
shader.setPointAttribute(root.glPointAttrib, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT);
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPointIndexBufferID);
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPointIndex);
|
||||
pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX);
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
@@ -71,8 +71,7 @@ public class Texture implements PConstants {
|
||||
|
||||
public int width, height;
|
||||
|
||||
// These are public but use at your own risk!
|
||||
public int glID;
|
||||
public int glName;
|
||||
public int glTarget;
|
||||
public int glFormat;
|
||||
public int glMinFilter;
|
||||
@@ -137,7 +136,7 @@ public class Texture implements PConstants {
|
||||
pgl = pg.pgl;
|
||||
context = pgl.createEmptyContext();
|
||||
|
||||
glID = 0;
|
||||
glName = 0;
|
||||
|
||||
init(width, height, (Parameters)params);
|
||||
}
|
||||
@@ -145,8 +144,8 @@ public class Texture implements PConstants {
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (glID != 0) {
|
||||
pg.finalizeTextureObject(glID, context.code());
|
||||
if (glName != 0) {
|
||||
pg.finalizeTextureObject(glName, context.code());
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
@@ -168,7 +167,7 @@ public class Texture implements PConstants {
|
||||
*/
|
||||
public void init(int width, int height) {
|
||||
Parameters params;
|
||||
if (0 < glID) {
|
||||
if (0 < glName) {
|
||||
// Re-initializing a pre-existing texture.
|
||||
// We use the current parameters as default:
|
||||
params = getParameters();
|
||||
@@ -220,7 +219,7 @@ public class Texture implements PConstants {
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean available() {
|
||||
return 0 < glID;
|
||||
return 0 < glName;
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +277,7 @@ public class Texture implements PConstants {
|
||||
}
|
||||
|
||||
pgl.enableTexturing(glTarget);
|
||||
pgl.glBindTexture(glTarget, glID);
|
||||
pgl.glBindTexture(glTarget, glName);
|
||||
|
||||
if (usingMipmaps) {
|
||||
if (PGraphicsOpenGL.autoMipmapGenSupported) {
|
||||
@@ -508,7 +507,7 @@ public class Texture implements PConstants {
|
||||
|
||||
public void bind() {
|
||||
pgl.enableTexturing(glTarget);
|
||||
pgl.glBindTexture(glTarget, glID);
|
||||
pgl.glBindTexture(glTarget, glName);
|
||||
}
|
||||
|
||||
|
||||
@@ -972,9 +971,9 @@ public class Texture implements PConstants {
|
||||
pgl.enableTexturing(glTarget);
|
||||
|
||||
context = pgl.getCurrentContext();
|
||||
glID = pg.createTextureObject(context.code());
|
||||
glName = pg.createTextureObject(context.code());
|
||||
|
||||
pgl.glBindTexture(glTarget, glID);
|
||||
pgl.glBindTexture(glTarget, glName);
|
||||
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MIN_FILTER, glMinFilter);
|
||||
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MAG_FILTER, glMagFilter);
|
||||
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_WRAP_S, glWrapS);
|
||||
@@ -996,9 +995,9 @@ public class Texture implements PConstants {
|
||||
* Marks the texture object for deletion.
|
||||
*/
|
||||
protected void release() {
|
||||
if (glID != 0) {
|
||||
pg.finalizeTextureObject(glID, context.code());
|
||||
glID = 0;
|
||||
if (glName != 0) {
|
||||
pg.finalizeTextureObject(glName, context.code());
|
||||
glName = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1009,11 +1008,11 @@ public class Texture implements PConstants {
|
||||
// Removing the texture object from the renderer's list so it
|
||||
// doesn't get deleted by OpenGL. The texture object was
|
||||
// automatically disposed when the old context was destroyed.
|
||||
pg.removeTextureObject(glID, context.code());
|
||||
pg.removeTextureObject(glName, context.code());
|
||||
|
||||
// And then set the id to zero, so it doesn't try to be
|
||||
// deleted when the object's finalizer is invoked by the GC.
|
||||
glID = 0;
|
||||
glName = 0;
|
||||
}
|
||||
return outdated;
|
||||
}
|
||||
@@ -1044,14 +1043,14 @@ public class Texture implements PConstants {
|
||||
if (scale) {
|
||||
// Rendering tex into "this", and scaling the source rectangle
|
||||
// to cover the entire destination region.
|
||||
pgl.drawTexture(tex.glTarget, tex.glID, tex.glWidth, tex.glHeight,
|
||||
pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight,
|
||||
x, y, w, h, 0, 0, width, height);
|
||||
|
||||
} else {
|
||||
// Rendering tex into "this" but without scaling so the contents
|
||||
// of the source texture fall in the corresponding texels of the
|
||||
// destination.
|
||||
pgl.drawTexture(tex.glTarget, tex.glID, tex.glWidth, tex.glHeight,
|
||||
pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight,
|
||||
x, y, w, h, x, y, w, h);
|
||||
}
|
||||
pg.popFramebuffer();
|
||||
@@ -1092,7 +1091,7 @@ public class Texture implements PConstants {
|
||||
parent = src.parent;
|
||||
pg = src.pg;
|
||||
|
||||
glID = src.glID;
|
||||
glName = src.glName;
|
||||
glTarget = src.glTarget;
|
||||
glFormat = src.glFormat;
|
||||
glMinFilter = src.glMinFilter;
|
||||
|
||||
Reference in New Issue
Block a user