mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
Some more buffer fixes
This commit is contained in:
@@ -927,8 +927,7 @@ public class PGL {
|
||||
GL11.glDisable(target);
|
||||
}
|
||||
|
||||
public void initTexture(int target, int width, int height, int format, int type) {
|
||||
//int[] texels = new int[width * height];
|
||||
public void initTexture(int target, int width, int height, int format, int type) {
|
||||
IntBuffer texels = createIntBuffer(width * height);
|
||||
GL11.glTexSubImage2D(target, 0, 0, 0, width, height, format, type, texels);
|
||||
}
|
||||
|
||||
@@ -1414,9 +1414,9 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
//pg.disableLights();
|
||||
}
|
||||
|
||||
inGeo.reset();
|
||||
tessGeo.reset();
|
||||
texCache.reset();
|
||||
inGeo.clear();
|
||||
tessGeo.clear();
|
||||
texCache.clear();
|
||||
|
||||
// Each frame starts with textures disabled.
|
||||
super.noTexture();
|
||||
@@ -1956,7 +1956,7 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
public void beginShape(int kind) {
|
||||
shape = kind;
|
||||
|
||||
inGeo.reset();
|
||||
inGeo.clear();
|
||||
|
||||
breakShape = false;
|
||||
defaultEdges = true;
|
||||
@@ -2254,8 +2254,8 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
}
|
||||
}
|
||||
|
||||
tessGeo.reset();
|
||||
texCache.reset();
|
||||
tessGeo.clear();
|
||||
texCache.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -4307,8 +4307,8 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
}
|
||||
|
||||
protected void backgroundImpl() {
|
||||
tessGeo.reset();
|
||||
texCache.reset();
|
||||
tessGeo.clear();
|
||||
texCache.clear();
|
||||
|
||||
pgl.glClearColor(0, 0, 0, 0);
|
||||
pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT);
|
||||
@@ -6321,7 +6321,7 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
hasTexture = false;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
public void clear() {
|
||||
java.util.Arrays.fill(textures, 0, count, null);
|
||||
count = 0;
|
||||
hasTexture = false;
|
||||
@@ -6472,7 +6472,7 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
allocate();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
public void clear() {
|
||||
vertexCount = firstVertex = lastVertex = 0;
|
||||
edgeCount = firstEdge = lastEdge = 0;
|
||||
}
|
||||
@@ -6490,7 +6490,7 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
emissive = new int[PGL.DEFAULT_IN_VERTICES];
|
||||
shininess = new float[PGL.DEFAULT_IN_VERTICES];
|
||||
edges = new int[PGL.DEFAULT_IN_EDGES][3];
|
||||
reset();
|
||||
clear();
|
||||
}
|
||||
|
||||
public void trim() {
|
||||
@@ -7197,7 +7197,7 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
allocate();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
public void clear() {
|
||||
firstFillVertex = lastFillVertex = fillVertexCount = 0;
|
||||
firstFillIndex = lastFillIndex = fillIndexCount = 0;
|
||||
|
||||
@@ -7207,25 +7207,25 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
firstPointVertex = lastPointVertex = pointVertexCount = 0;
|
||||
firstPointIndex = lastPointIndex = pointIndexCount = 0;
|
||||
|
||||
fillVertices.rewind();
|
||||
fillColors.rewind();
|
||||
fillNormals.rewind();
|
||||
fillTexcoords.rewind();
|
||||
fillAmbient.rewind();
|
||||
fillSpecular.rewind();
|
||||
fillEmissive.rewind();
|
||||
fillShininess.rewind();
|
||||
fillIndices.rewind();
|
||||
fillVertices.clear();
|
||||
fillColors.clear();
|
||||
fillNormals.clear();
|
||||
fillTexcoords.clear();
|
||||
fillAmbient.clear();
|
||||
fillSpecular.clear();
|
||||
fillEmissive.clear();
|
||||
fillShininess.clear();
|
||||
fillIndices.clear();
|
||||
|
||||
lineVertices.rewind();
|
||||
lineColors.rewind();
|
||||
lineDirWidths.rewind();
|
||||
lineIndices.rewind();
|
||||
lineVertices.clear();
|
||||
lineColors.clear();
|
||||
lineDirWidths.clear();
|
||||
lineIndices.clear();
|
||||
|
||||
pointVertices.rewind();
|
||||
pointColors.rewind();
|
||||
pointSizes.rewind();
|
||||
pointIndices.rewind();
|
||||
pointVertices.clear();
|
||||
pointColors.clear();
|
||||
pointSizes.clear();
|
||||
pointIndices.clear();
|
||||
|
||||
isStroked = false;
|
||||
}
|
||||
@@ -7251,7 +7251,7 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
pointSizes = pgl.createFloatBuffer(2 * PGL.DEFAULT_TESS_VERTICES);
|
||||
pointIndices = pgl.createIntBuffer(PGL.DEFAULT_TESS_VERTICES);
|
||||
|
||||
reset();
|
||||
clear();
|
||||
}
|
||||
|
||||
public void trim() {
|
||||
@@ -7735,8 +7735,8 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
}
|
||||
|
||||
protected void prepareLineIndicesForCopy(int start, int count) {
|
||||
lineIndices.position(3 * start);
|
||||
lineIndices.limit(3 * count);
|
||||
lineIndices.position(start);
|
||||
lineIndices.limit(count);
|
||||
}
|
||||
|
||||
protected void preparePointVerticesForCopy() {
|
||||
@@ -7759,8 +7759,8 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
}
|
||||
|
||||
protected void preparePointIndicesForCopy(int start, int count) {
|
||||
pointIndices.position(3 * start);
|
||||
pointIndices.limit(3 * count);
|
||||
pointIndices.position(start);
|
||||
pointIndices.limit(count);
|
||||
}
|
||||
|
||||
|
||||
@@ -7998,18 +7998,20 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
float ny = in.normals[index++];
|
||||
float nz = in.normals[index ];
|
||||
|
||||
index = 3 * tessIdx;
|
||||
vert[0] = x * mm.m00 + y * mm.m01 + z * mm.m02 + mm.m03;
|
||||
vert[1] = x * mm.m10 + y * mm.m11 + z * mm.m12 + mm.m13;
|
||||
vert[2] = x * mm.m20 + y * mm.m21 + z * mm.m22 + mm.m23;
|
||||
|
||||
index = 3 * tessIdx;
|
||||
|
||||
norm[0] = nx * nm.m00 + ny * nm.m10 + nz * nm.m20;
|
||||
norm[1] = nx * nm.m01 + ny * nm.m11 + nz * nm.m21;
|
||||
norm[2] = nx * nm.m02 + ny * nm.m12 + nz * nm.m22;
|
||||
|
||||
|
||||
fillVertices.position(3 * tessIdx);
|
||||
fillVertices.put(vert);
|
||||
try {
|
||||
fillVertices.put(vert);
|
||||
} catch (java.nio.BufferOverflowException e) {
|
||||
PApplet.println("mama mia " + 3 * tessIdx + " " + fillVertices.position() + " " + fillVertices.limit() + " " + fillVertices.capacity() + " " + 3 * fillVertexCount);
|
||||
}
|
||||
|
||||
fillNormals.position(3 * tessIdx);
|
||||
fillNormals.put(norm);
|
||||
@@ -8072,14 +8074,14 @@ public class PGraphicsLWJGL extends PGraphics {
|
||||
lineVertices.position(3 * tessIdx);
|
||||
lineVertices.put(vert);
|
||||
|
||||
lineVertices.position(4 * tessIdx);
|
||||
lineVertices.put(attr);
|
||||
lineDirWidths.position(4 * tessIdx);
|
||||
lineDirWidths.put(attr);
|
||||
} else {
|
||||
lineVertices.position(3 * tessIdx);
|
||||
lineVertices.put(in.vertices, 3 * inIdx0, 3);
|
||||
|
||||
lineVertices.position(4 * tessIdx);
|
||||
lineVertices.put(in.vertices, 3 * inIdx1, 3);
|
||||
lineDirWidths.position(4 * tessIdx);
|
||||
lineDirWidths.put(in.vertices, 3 * inIdx1, 3);
|
||||
}
|
||||
|
||||
lineColors.position(tessIdx);
|
||||
|
||||
@@ -47,7 +47,6 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
// Notes about geometry update in PShape3D.
|
||||
// 1) When applying a transformation on a group shape
|
||||
@@ -867,20 +866,15 @@ public class PShape3D extends PShape {
|
||||
|
||||
updateTesselation();
|
||||
|
||||
BufferUtils.zeroBuffer(tess.fillColors);
|
||||
|
||||
//Arrays.fill(tess.fillColors, 0, tess.fillVertexCount, fillColor);
|
||||
// int[] temp = new int[tess.fillVertexCount];
|
||||
// Arrays.fill(temp, 0, tess.fillVertexCount, fillColor);
|
||||
// tess.fillColors.position(0);
|
||||
// tess.fillColors.put(temp);
|
||||
Arrays.fill(tess.fillColors.array(), 0, tess.fillVertexCount, fillColor);
|
||||
int[] temp = new int[tess.fillVertexCount];
|
||||
Arrays.fill(temp, 0, tess.fillVertexCount, fillColor);
|
||||
tess.fillColors.rewind();
|
||||
tess.fillColors.put(temp);
|
||||
|
||||
modifiedFillColors = true;
|
||||
modified();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// STROKE COLOR
|
||||
@@ -990,15 +984,19 @@ public class PShape3D extends PShape {
|
||||
updateTesselation();
|
||||
|
||||
if (0 < tess.lineVertexCount) {
|
||||
//Arrays.fill(tess.lineColors, 0, tess.lineVertexCount, strokeColor);
|
||||
Arrays.fill(tess.lineColors.array(), 0, tess.lineVertexCount, strokeColor);
|
||||
int[] temp = new int[tess.lineVertexCount];
|
||||
Arrays.fill(temp, 0, tess.lineVertexCount, strokeColor);
|
||||
tess.lineColors.rewind();
|
||||
tess.lineColors.put(temp);
|
||||
modifiedLineColors = true;
|
||||
modified();
|
||||
}
|
||||
|
||||
if (0 < tess.pointVertexCount) {
|
||||
//Arrays.fill(tess.pointColors, 0, tess.pointVertexCount, strokeColor);
|
||||
Arrays.fill(tess.pointColors.array(), 0, tess.pointVertexCount, strokeColor);
|
||||
int[] temp = new int[tess.pointVertexCount];
|
||||
Arrays.fill(temp, 0, tess.pointVertexCount, strokeColor);
|
||||
tess.pointColors.rewind();
|
||||
tess.pointColors.put(temp);
|
||||
modifiedPointColors = true;
|
||||
modified();
|
||||
}
|
||||
@@ -1117,11 +1115,10 @@ public class PShape3D extends PShape {
|
||||
|
||||
updateTesselation();
|
||||
|
||||
//Arrays.fill(tess.fillColors, 0, tess.pointVertexCount, tintColor);
|
||||
int[] temp = new int[tess.fillVertexCount];
|
||||
Arrays.fill(temp, 0, tess.fillVertexCount, tintColor);
|
||||
tess.fillColors.position(0);
|
||||
tess.fillColors.put(temp);
|
||||
tess.fillColors.rewind();
|
||||
tess.fillColors.put(temp);
|
||||
|
||||
modifiedFillColors = true;
|
||||
modified();
|
||||
@@ -1180,9 +1177,11 @@ public class PShape3D extends PShape {
|
||||
}
|
||||
|
||||
updateTesselation();
|
||||
|
||||
//Arrays.fill(tess.fillAmbient, 0, tess.fillVertexCount, ambientColor);
|
||||
Arrays.fill(tess.fillAmbient.array(), 0, tess.fillVertexCount, ambientColor);
|
||||
|
||||
int[] temp = new int[tess.fillVertexCount];
|
||||
Arrays.fill(temp, 0, tess.fillVertexCount, ambientColor);
|
||||
tess.fillAmbient.rewind();
|
||||
tess.fillAmbient.put(temp);
|
||||
|
||||
modifiedFillAmbient = true;
|
||||
modified();
|
||||
@@ -1243,8 +1242,10 @@ public class PShape3D extends PShape {
|
||||
|
||||
updateTesselation();
|
||||
|
||||
//Arrays.fill(tess.fillSpecular, 0, tess.fillVertexCount, specularColor);
|
||||
Arrays.fill(tess.fillSpecular.array(), 0, tess.fillVertexCount, specularColor);
|
||||
int[] temp = new int[tess.fillVertexCount];
|
||||
Arrays.fill(temp, 0, tess.fillVertexCount, specularColor);
|
||||
tess.fillSpecular.rewind();
|
||||
tess.fillSpecular.put(temp);
|
||||
|
||||
modifiedFillSpecular = true;
|
||||
modified();
|
||||
@@ -1305,8 +1306,10 @@ public class PShape3D extends PShape {
|
||||
|
||||
updateTesselation();
|
||||
|
||||
//Arrays.fill(tess.fillEmissive, 0, tess.fillVertexCount, emissiveColor);
|
||||
Arrays.fill(tess.fillEmissive.array(), 0, tess.fillVertexCount, emissiveColor);
|
||||
int[] temp = new int[tess.fillVertexCount];
|
||||
Arrays.fill(temp, 0, tess.fillVertexCount, emissiveColor);
|
||||
tess.fillEmissive.rewind();
|
||||
tess.fillEmissive.put(temp);
|
||||
|
||||
modifiedFillEmissive = true;
|
||||
modified();
|
||||
@@ -1337,8 +1340,10 @@ public class PShape3D extends PShape {
|
||||
|
||||
updateTesselation();
|
||||
|
||||
//Arrays.fill(tess.fillShininess, 0, tess.fillVertexCount, shininess);
|
||||
Arrays.fill(tess.fillShininess.array(), 0, tess.fillVertexCount, shininess);
|
||||
float[] temp = new float[tess.fillVertexCount];
|
||||
Arrays.fill(temp, 0, tess.fillVertexCount, shininess);
|
||||
tess.fillShininess.rewind();
|
||||
tess.fillShininess.put(temp);
|
||||
|
||||
modifiedFillShininess = true;
|
||||
modified();
|
||||
@@ -2882,7 +2887,7 @@ public class PShape3D extends PShape {
|
||||
// level of the shape hierarchy.
|
||||
protected void aggregateImpl() {
|
||||
if (family == GROUP) {
|
||||
tess.reset();
|
||||
tess.clear();
|
||||
|
||||
boolean firstGeom = true;
|
||||
boolean firstStroke = true;
|
||||
|
||||
@@ -68,6 +68,8 @@ public class PTexture implements PConstants {
|
||||
protected int[] tempPixels = null;
|
||||
protected PFramebuffer tempFbo = null;
|
||||
|
||||
protected IntBuffer texels;
|
||||
|
||||
protected Object bufferSource;
|
||||
protected LinkedList<BufferData> bufferCache = null;
|
||||
protected Method disposeBufferMethod;
|
||||
@@ -845,14 +847,21 @@ public class PTexture implements PConstants {
|
||||
protected void setTexels(int[] pix, int x, int y, int w, int h) {
|
||||
setTexels(pix, 0, x, y, w, h);
|
||||
}
|
||||
|
||||
protected void setTexels(int[] pix, int level, int x, int y, int w, int h) {
|
||||
pgl.glTexSubImage2D(glTarget, level, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, IntBuffer.wrap(pix));
|
||||
}
|
||||
|
||||
protected void setTexels(IntBuffer buffer, int x, int y, int w, int h) {
|
||||
setTexels(buffer, 0, x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setTexels(int[] pix, int level, int x, int y, int w, int h) {
|
||||
if (texels == null || texels.capacity() != width * height) {
|
||||
texels = pgl.createIntBuffer(width * height);
|
||||
}
|
||||
texels.position(0);
|
||||
texels.limit(pix.length);
|
||||
texels.put(pix);
|
||||
texels.flip();
|
||||
pgl.glTexSubImage2D(glTarget, level, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, texels);
|
||||
}
|
||||
|
||||
protected void setTexels(IntBuffer buffer, int level, int x, int y, int w, int h) {
|
||||
pgl.glTexSubImage2D(glTarget, level, x, y, w, h, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
Reference in New Issue
Block a user