/** * Sets the fog buffer. * * @param fogBuffer * the new fog buffer */ public void setFogBuffer(final FloatBuffer fogBuffer) { if (fogBuffer == null) { _fogCoords = null; } else { _fogCoords = new FloatBufferData(fogBuffer, 3); } }
private void saveFloatBufferData(final FloatBufferData data, final PrintWriter objPw, final String keyword, final int expectedTupleCount) { if (data != null) { if (keyword == null || keyword.isEmpty()) { throw new IllegalArgumentException("null or empty keyword not supported"); } else { final int tupleSize = data.getValuesPerTuple(); final int tupleCount = data.getTupleCount(); if (tupleCount < expectedTupleCount) { throw new IllegalArgumentException( "[" + keyword + "] not enough data to match with the vertex count: " + tupleCount + " < " + expectedTupleCount); } else { if (tupleCount > expectedTupleCount) { ObjExporter.logger.warning("[" + keyword + "] too much data to match with the vertex count: " + tupleCount + " > " + expectedTupleCount + ". Skips useless tuple(s)"); } } for (int tupleIndex = 0; tupleIndex < expectedTupleCount; tupleIndex++) { objPw.print(keyword); for (int valueIndex = 0; valueIndex < tupleSize; valueIndex++) { objPw.print(" " + data.getBuffer().get(tupleIndex * tupleSize + valueIndex)); } objPw.println(); } } } } }
private void refreshInterleaved() { if (_interleaved != null) { _interleaved.setNeedsRefresh(true); } }
/** * Check an incoming TexCoords object for null and correct size. * * @param tc * @param vertexCount * @param perVert * @return tc if it is not null and the right size, otherwise it will be a new TexCoords object. */ public static FloatBufferData ensureSize(final FloatBufferData tc, final int vertexCount, final int coordsPerVertex) { if (tc == null) { return new FloatBufferData(BufferUtils.createFloatBuffer(vertexCount * coordsPerVertex), coordsPerVertex); } if (tc.getBuffer().limit() == coordsPerVertex * vertexCount && tc.getValuesPerTuple() == coordsPerVertex) { tc.getBuffer().rewind(); return tc; } else if (tc.getBuffer().limit() == coordsPerVertex * vertexCount) { tc.setValuesPerTuple(coordsPerVertex); } else { return new FloatBufferData(BufferUtils.createFloatBuffer(vertexCount * coordsPerVertex), coordsPerVertex); } return tc; } }
/** * Set the basic data for this mesh such as texture coordinates, index mode and our vertex buffer. */ private void initialize() { final FloatBufferData vbuf = new FloatBufferData(BufferUtils.createVector2Buffer(4), 2); vbuf.setVboAccessMode(VBOAccessMode.DynamicDraw); _meshData.setVertexCoords(vbuf); final FloatBuffer tbuf = BufferUtils.createVector2Buffer(4); _meshData.setTextureBuffer(tbuf, 0); _meshData.getTextureCoords(0).setVboAccessMode(VBOAccessMode.DynamicDraw); tbuf.put(0).put(1); tbuf.put(0).put(0); tbuf.put(1).put(0); tbuf.put(1).put(1); _meshData.setIndexMode(IndexMode.TriangleFan); }
if (interleaved.getBufferCapacity() != 1) { final FloatBuffer buffer = BufferUtils.createFloatBufferOnHeap(1); interleaved.setBuffer(buffer); interleaved.getBuffer().rewind(); interleaved.getBuffer().put(bufferSize); interleaved.setVBOID(context.getGlContextRep(), vboID); gl.glBufferData(GL.GL_ARRAY_BUFFER, bufferSize, null, getGLVBOAccessMode(interleaved.getVboAccessMode())); normalCoords.getBuffer().rewind(); gl.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, normalCoords.getBufferLimit() * 4, normalCoords.getBuffer()); offset += normalCoords.getBufferLimit() * 4; colorCoords.getBuffer().rewind(); gl.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, colorCoords.getBufferLimit() * 4, colorCoords.getBuffer()); offset += colorCoords.getBufferLimit() * 4; final FloatBuffer textureBuffer = textureBufferData != null ? textureBufferData.getBuffer() : null; if (textureBuffer != null) { textureBuffer.rewind(); gl.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, textureBufferData.getBufferLimit() * 4, textureBuffer); offset += textureBufferData.getBufferLimit() * 4; vertexCoords.getBuffer().rewind(); gl.glBufferSubData(GL.GL_ARRAY_BUFFER, offset, vertexCoords.getBufferLimit() * 4, vertexCoords.getBuffer());
if (dest == null || dest.getBuffer().capacity() != src.getBuffer().limit()) { dest = new FloatBufferData(BufferUtils.createFloatBuffer(src.getBuffer().capacity()), src.getValuesPerTuple()); _textureCoords.set(toIndex, dest); dest.getBuffer().clear(); final int oldLimit = src.getBuffer().limit(); src.getBuffer().clear(); for (int i = 0, len = dest.getBuffer().capacity(); i < len; i++) { if (i % 2 == 0) { dest.getBuffer().put(factorS * src.getBuffer().get()); } else { dest.getBuffer().put(factorT * src.getBuffer().get()); src.getBuffer().limit(oldLimit); dest.getBuffer().limit(oldLimit);
/** * Gets the color buffer. * * @return the color buffer */ public FloatBuffer getColorBuffer() { if (_colorCoords == null) { return null; } return _colorCoords.getBuffer(); }
public static FloatBufferData convertQuadVerticesToTriangles(final FloatBufferData vertices) { final int dims = vertices.getValuesPerTuple(); if (dims != 2 && dims != 3) { throw new IllegalArgumentException( final FloatBuffer srcBuffer = vertices.getBuffer(); final int qVerts = vertices.getTupleCount(); final int tVerts = tris * 3; final FloatBufferData rVal = new FloatBufferData(tVerts * dims, dims); final FloatBuffer dstBuffer = rVal.getBuffer();
if (interleaved.getBufferLimit() > 0) { interleaved.getBuffer().rewind(); currLengthBytes = Math.round(interleaved.getBuffer().get()); if (lengthBytes != currLengthBytes || interleaved.getVBOID(context.getGlContextRep()) == 0 || interleaved.isNeedsRefresh()) { initializeInterleavedVBO(context, interleaved, vertexCoords, normalCoords, colorCoords, textureCoords, lengthBytes); final int vboID = interleaved.getVBOID(context.getGlContextRep()); LwjglRendererUtil.setBoundVBO(rendRecord, vboID); GL11.glNormalPointer(GL11.GL_FLOAT, 0, offsetBytes); GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY); offsetBytes += normalCoords.getBufferLimit() * 4; } else { GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY); GL11.glColorPointer(colorCoords.getValuesPerTuple(), GL11.GL_FLOAT, 0, offsetBytes); GL11.glEnableClientState(GL11.GL_COLOR_ARRAY); offsetBytes += colorCoords.getBufferLimit() * 4; } else { GL11.glDisableClientState(GL11.GL_COLOR_ARRAY); GL11.glTexCoordPointer(textureBufferData.getValuesPerTuple(), GL11.GL_FLOAT, 0, offsetBytes); offsetBytes += textureBufferData.getBufferLimit() * 4; GL11.glVertexPointer(vertexCoords.getValuesPerTuple(), GL11.GL_FLOAT, 0, offsetBytes); GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
public void setupColorData(final FloatBufferData colorBufferData) { final FloatBuffer colorBuffer = colorBufferData != null ? colorBufferData.getBuffer() : null; if (colorBuffer == null) { GL11.glDisableClientState(GL11.GL_COLOR_ARRAY); } else { GL11.glEnableClientState(GL11.GL_COLOR_ARRAY); colorBuffer.rewind(); GL11.glColorPointer(colorBufferData.getValuesPerTuple(), 0, colorBuffer); } }
final FloatBufferData verts = new FloatBufferData(vertexCount * 3, 3); final FloatBufferData norms = new FloatBufferData(vertexCount * 3, 3); final FloatBufferData texs = new FloatBufferData(vertexCount * 3, 2); mData.setVertexCoords(verts); mData.setNormalCoords(norms); mData.setTextureCoords(texs, 0); verts.setVboAccessMode(VBOAccessMode.DynamicDraw); norms.setVboAccessMode(VBOAccessMode.DynamicDraw); texs.setVboAccessMode(VBOAccessMode.DynamicDraw); norms.getBuffer().put(0).put(0).put(0); texs.getBuffer().put(0).put(0); texs.getBuffer().put(cmd.texCoords); norms.getBuffer().put(0).put(0).put(0); texs.getBuffer().put(0).put(0); if (cmd.vertIndices.length % 2 == 1) { norms.getBuffer().put(0).put(0).put(0); texs.getBuffer().put(0).put(0); texs.getBuffer().put(cmd.texCoords[0]).put(cmd.texCoords[1]); addNormal(cmd, frame, 0, norms); addVert(cmd, frame, 0, verts); for (int k = cmd.vertIndices.length; --k >= 1;) { texs.getBuffer().put(cmd.texCoords[k * 2]).put(cmd.texCoords[k * 2 + 1]); addNormal(cmd, frame, k, norms); addVert(cmd, frame, k, verts);
/** * Initializes the vertices and indices. */ private void initialize() { final MeshData meshData = getMeshData(); meshData.setIndexMode(IndexMode.TriangleStrip); // clipSideSize is the number of vertices per clipmapside, so number of all vertices is clipSideSize * // clipSideSize final FloatBufferData vertices = new FloatBufferData( BufferUtils.createVector4Buffer(clipSideSize * clipSideSize), 4); vertices.setVboAccessMode(VBOAccessMode.DynamicDraw); meshData.setVertexCoords(vertices); final int indicesSize = 4 * (3 * frameSize * frameSize + clipSideSize * clipSideSize / 2 + 4 * frameSize - 10); final IndexBufferData<?> indices = BufferUtils.createIndexBufferData(indicesSize, vertices.getBufferCapacity() - 1); indices.setVboAccessMode(VBOAccessMode.DynamicDraw); tmpIndices = new int[indicesSize]; meshData.setIndices(indices); // Go through all rows and fill them with vertexindices. for (int z = 0; z < clipSideSize - 1; z++) { fillRow(0, clipSideSize - 1, z, z + 1); } }
_meshData.setVertexBuffer(BufferUtils.createVector3Buffer(verts)); } else { vertsData.setBuffer(BufferUtils.createVector3Buffer(vertsData.getBuffer(), verts)); vertsData.markDirty(); _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(verts)); } else { normsData.setBuffer(BufferUtils.createVector3Buffer(normsData.getBuffer(), verts)); normsData.markDirty(); _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(verts), 0); } else { texData.setBuffer(BufferUtils.createVector2Buffer(texData.getBuffer(), verts)); texData.markDirty(); _meshData.getTextureCoords(0).getBuffer().put((float) fRadialFraction) .put((float) (0.5 * (fZFraction + 1.0))); } else if (_textureMode == TextureMode.Projected) { _meshData.getTextureCoords(0).getBuffer().put((float) fRadialFraction) .put((float) (MathUtils.INV_PI * (MathUtils.HALF_PI + Math.asin(fZFraction)))); } else if (_textureMode == TextureMode.Polar) { final double u = r * afCos[iR] + 0.5; final double v = r * afSin[iR] + 0.5; _meshData.getTextureCoords(0).getBuffer().put((float) u).put((float) v); _meshData.getTextureCoords(0).getBuffer().put(1.0f).put((float) (0.5 * (fZFraction + 1.0))); } else if (_textureMode == TextureMode.Projected) { _meshData.getTextureCoords(0).getBuffer().put(1.0f)
_meshData.setVertexBuffer(BufferUtils.createVector3Buffer(verts)); } else { vertsData.setBuffer(BufferUtils.createVector3Buffer(vertsData.getBuffer(), verts)); _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(verts)); } else { normsData.setBuffer(BufferUtils.createVector3Buffer(normsData.getBuffer(), verts)); _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(verts), 0); } else { texData.setBuffer(BufferUtils.createVector2Buffer(texData.getBuffer(), verts)); _meshData.getTextureCoords(0).getBuffer().put((float) fRadialFraction) .put((float) (0.5 * (fZFraction + 1.0))); } else if (_textureMode == TextureMode.Projected) { _meshData.getTextureCoords(0).getBuffer().put((float) fRadialFraction) .put((float) (MathUtils.INV_PI * (MathUtils.HALF_PI + Math.asin(fZFraction)))); } else if (_textureMode == TextureMode.Polar) { final double u = r * afCos[iR] + 0.5; final double v = r * afSin[iR] + 0.5; _meshData.getTextureCoords(0).getBuffer().put((float) u).put((float) v); _meshData.getTextureCoords(0).getBuffer().put(1.0f).put((float) (0.5 * (fZFraction + 1.0))); } else if (_textureMode == TextureMode.Projected) { _meshData.getTextureCoords(0).getBuffer().put(1.0f) .put((float) (MathUtils.INV_PI * (MathUtils.HALF_PI + Math.asin(fZFraction)))); } else if (_textureMode == TextureMode.Polar) { final float r = (float) ((MathUtils.HALF_PI - Math.abs(fAFraction)) / MathUtils.PI);
if (first) { vertCoords = md.getVertexCoords().getValuesPerTuple(); volumeType = mesh.getModelBound(null); states = mesh.getLocalRenderStates(); first = false; } else if (vertCoords != md.getVertexCoords().getValuesPerTuple()) { throw new IllegalArgumentException("all MeshData vertex coords must use same tuple size."); if (!useTextures) { useTextures = true; texCoords = md.getTextureCoords(0).getValuesPerTuple(); } else if (md.getTextureCoords(0) != null && texCoords != md.getTextureCoords(0).getValuesPerTuple()) { throw new IllegalArgumentException("all MeshData objects with texcoords must use same tuple size.");
/** * Update the vertex count based on the current limit of the vertex buffer. */ public void updateVertexCount() { if (_vertexCoords == null) { _vertexCount = 0; } else { _vertexCount = _vertexCoords.getTupleCount(); } // update primitive count if we are using arrays if (_indexBuffer == null) { updatePrimitiveCounts(); } }
/** * */ public void updateGeometry() { final int numPairs = _tessSteps + 1; final int totalVerts = _tessRings * numPairs * 2; final MeshData meshData = getMeshData(); FloatBuffer crdBuf = meshData.getVertexBuffer(); if (crdBuf == null || totalVerts != crdBuf.limit() / 3) { // allocate new buffers meshData.setVertexBuffer(BufferUtils.createVector3Buffer(totalVerts)); meshData.setNormalBuffer(BufferUtils.createVector3Buffer(totalVerts)); meshData.setTextureBuffer(BufferUtils.createVector2Buffer(totalVerts), 0); crdBuf = meshData.getVertexBuffer(); meshData.getVertexCoords().setVboAccessMode(VBOAccessMode.DynamicDraw); meshData.getNormalCoords().setVboAccessMode(VBOAccessMode.DynamicDraw); meshData.getTextureCoords(0).setVboAccessMode(VBOAccessMode.DynamicDraw); } final FloatBuffer nrmBuf = meshData.getNormalBuffer(); final FloatBuffer txcBuf = meshData.getTextureBuffer(0); calculateVertexData(_tessRings, numPairs, totalVerts, crdBuf, nrmBuf, txcBuf); // mark our data as needing updates meshData.markBufferDirty(MeshData.KEY_VertexCoords); meshData.markBufferDirty(MeshData.KEY_NormalCoords); meshData.markBufferDirty(MeshData.KEY_TextureCoords0); updateModelBound(); }
public int getTupleCount() { return getBufferLimit() / _valuesPerTuple; }
if (interleaved.getBufferCapacity() != 1) { final FloatBuffer buffer = BufferUtils.createFloatBufferOnHeap(1); interleaved.setBuffer(buffer); interleaved.getBuffer().rewind(); interleaved.getBuffer().put(bufferSize); interleaved.setVBOID(context.getGlContextRep(), vboID); getGLVBOAccessMode(interleaved.getVboAccessMode())); normalCoords.getBuffer().rewind(); ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, normalCoords.getBuffer()); offsetBytes += normalCoords.getBufferLimit() * 4; colorCoords.getBuffer().rewind(); ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, colorCoords.getBuffer()); offsetBytes += colorCoords.getBufferLimit() * 4; final FloatBuffer textureBuffer = textureBufferData != null ? textureBufferData.getBuffer() : null; if (textureBuffer != null) { textureBuffer.rewind(); ARBBufferObject.glBufferSubDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, offsetBytes, textureBuffer); offsetBytes += textureBufferData.getBufferLimit() * 4; vertexCoords.getBuffer().rewind();