/** * Creates a buffer and assumes the buffer will be used for static drawing only. * * @param bufferInfo * @param type * @param target */ public void createBuffer(BufferInfo bufferInfo, BufferType type, int target) { createBuffer(bufferInfo, type, target, bufferInfo.usage); }
public void validateBuffers() { if (!mHaveCreatedBuffers) { createBuffers(); } if (mOriginalGeometry != null) { mOriginalGeometry.validateBuffers(); return; } for (int i = 0, j = mBuffers.size(); i < j; ++i) { final BufferInfo info = mBuffers.get(i); if (info != null && info.bufferHandle == 0) { createBuffer(info); } } }
public void createBuffer(BufferInfo bufferInfo) { createBuffer(bufferInfo, bufferInfo.bufferType, bufferInfo.target, bufferInfo.usage); }
public void validateBuffers() { if (!mHaveCreatedBuffers) { createBuffers(); } if (mOriginalGeometry != null) { mOriginalGeometry.validateBuffers(); return; } if (mVertexBufferInfo != null && mVertexBufferInfo.bufferHandle == 0) { createBuffer(mVertexBufferInfo); } if (mIndexBufferInfo != null && mIndexBufferInfo.bufferHandle == 0) { createBuffer(mIndexBufferInfo); } if (mTexCoordBufferInfo != null && mTexCoordBufferInfo.bufferHandle == 0) { createBuffer(mTexCoordBufferInfo); } if (mColorBufferInfo != null && mColorBufferInfo.bufferHandle == 0) { createBuffer(mColorBufferInfo); } if (mNormalBufferInfo != null && mNormalBufferInfo.bufferHandle == 0) { createBuffer(mNormalBufferInfo); } }
public int addBuffer(BufferInfo bufferInfo, BufferType type, int target, int usage) { createBuffer(bufferInfo, type, target, usage); final int key = mBuffers.size(); bufferInfo.rajawaliHandle = key; mBuffers.add(bufferInfo); return key; }
/** * Creates the vertex and normal buffers only. This is typically used for a * VertexAnimationObject3D's frames. * * @see VertexAnimationObject3D */ public void createVertexAndNormalBuffersOnly() { ((FloatBuffer) mBuffers.get(VERTEX_BUFFER_KEY).buffer).compact().position(0); ((FloatBuffer) mBuffers.get(NORMAL_BUFFER_KEY).buffer).compact().position(0); createBuffer(mBuffers.get(VERTEX_BUFFER_KEY), BufferType.FLOAT_BUFFER, GLES20.GL_ARRAY_BUFFER); createBuffer(mBuffers.get(NORMAL_BUFFER_KEY), BufferType.FLOAT_BUFFER, GLES20.GL_ARRAY_BUFFER); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); }
createBuffer(bufferInfo, bufferInfo.bufferType, bufferInfo.target, usage);
public void setColor(float r, float g, float b, float a, boolean createNewBuffer) { BufferInfo colorInfo = mBuffers.get(COLOR_BUFFER_KEY); if (colorInfo.buffer == null || colorInfo.buffer.limit() == 0) { colorInfo = new BufferInfo(); colorInfo.buffer = ByteBuffer.allocateDirect(mNumVertices * 4 * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()).asFloatBuffer(); createNewBuffer = true; mBuffers.add(COLOR_BUFFER_KEY, colorInfo); } colorInfo.buffer.position(0); while (colorInfo.buffer.remaining() > 3) { ((FloatBuffer) colorInfo.buffer).put(r); ((FloatBuffer) colorInfo.buffer).put(g); ((FloatBuffer) colorInfo.buffer).put(b); ((FloatBuffer) colorInfo.buffer).put(a); } colorInfo.buffer.position(0); if (createNewBuffer) { createBuffer(colorInfo, BufferType.FLOAT_BUFFER, GLES20.GL_ARRAY_BUFFER); } else { GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, colorInfo.bufferHandle); GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, colorInfo.buffer.limit() * FLOAT_SIZE_BYTES, colorInfo.buffer, GLES20.GL_STATIC_DRAW); } GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); }
/** * Creates the actual Buffer objects. */ public void createBuffers() { for (BufferInfo info : mBuffers) { if (info.buffer != null) { if (info.buffer instanceof FloatBuffer) { ((FloatBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof IntBuffer) { ((IntBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof ShortBuffer) { ((ShortBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof ByteBuffer) { ((ByteBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof DoubleBuffer) { ((DoubleBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof LongBuffer) { ((LongBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof CharBuffer) { ((CharBuffer) info.buffer).compact().position(0); } } createBuffer(info); } GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); mHaveCreatedBuffers = true; }
/** * Creates a buffer and assumes the buffer will be used for static drawing only. * * @param bufferInfo * @param type * @param buffer * @param target */ public void createBuffer(BufferInfo bufferInfo, BufferType type, Buffer buffer, int target) { createBuffer(bufferInfo, type, buffer, target, bufferInfo.usage); }
public void createBuffer(BufferInfo bufferInfo) { createBuffer(bufferInfo, bufferInfo.bufferType, bufferInfo.buffer, bufferInfo.target, bufferInfo.usage); }
public void reload() { super.reload(); mGeometry.createBuffer(mboneIndexes1BufferInfo, BufferType.FLOAT_BUFFER, mboneIndexes1, GLES20.GL_ARRAY_BUFFER); mGeometry.createBuffer(mboneWeights1BufferInfo, BufferType.FLOAT_BUFFER, mboneWeights1, GLES20.GL_ARRAY_BUFFER); if (mMaxBoneWeightsPerVertex > 4) { mGeometry.createBuffer(mboneIndexes2BufferInfo, BufferType.FLOAT_BUFFER, mboneIndexes2, GLES20.GL_ARRAY_BUFFER); mGeometry.createBuffer(mboneWeights2BufferInfo, BufferType.FLOAT_BUFFER, mboneWeights2, GLES20.GL_ARRAY_BUFFER); } }
@Override public void reload() { super.reload(); mGeometry.createBuffer(mBoneMatricesBufferInfo, BufferType.FLOAT_BUFFER, mBoneMatrices, GLES20.GL_ARRAY_BUFFER); }
public void setSkeletonMeshData(int numVertices, BoneVertex[] vertices, int numWeights, BoneWeight[] weights) { mNumVertices = numVertices; mVertices = vertices; mWeights = weights; prepareBoneWeightsAndIndices(); mboneIndexes1 = alocateBuffer(mboneIndexes1, boneIndexes1); mboneWeights1 = alocateBuffer(mboneWeights1, boneWeights1); mGeometry.createBuffer(mboneIndexes1BufferInfo, BufferType.FLOAT_BUFFER, mboneIndexes1, GLES20.GL_ARRAY_BUFFER); mGeometry.createBuffer(mboneWeights1BufferInfo, BufferType.FLOAT_BUFFER, mboneWeights1, GLES20.GL_ARRAY_BUFFER); if (mMaxBoneWeightsPerVertex > 4) { mboneIndexes2 = alocateBuffer(mboneIndexes2, boneIndexes2); mboneWeights2 = alocateBuffer(mboneWeights2, boneWeights2); mGeometry.createBuffer(mboneIndexes2BufferInfo, BufferType.FLOAT_BUFFER, mboneIndexes2, GLES20.GL_ARRAY_BUFFER); mGeometry.createBuffer(mboneWeights2BufferInfo, BufferType.FLOAT_BUFFER, mboneWeights2, GLES20.GL_ARRAY_BUFFER); } }
/** * Creates the vertex and normal buffers only. This is typically used for a * VertexAnimationObject3D's frames. * * @see VertexAnimationObject3D */ public void createVertexAndNormalBuffersOnly() { mVertices.compact().position(0); mNormals.compact().position(0); createBuffer(mVertexBufferInfo, BufferType.FLOAT_BUFFER, mVertices, GLES20.GL_ARRAY_BUFFER); createBuffer(mNormalBufferInfo, BufferType.FLOAT_BUFFER, mNormals, GLES20.GL_ARRAY_BUFFER); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); }
public void setJoints(SkeletonJoint[] joints) { if(joints == null) return; mJoints = joints; if (mBoneMatrices == null) { mBoneMatrices = ByteBuffer .allocateDirect(joints.length * DOUBLE_SIZE_BYTES * 16) .order(ByteOrder.nativeOrder()).asDoubleBuffer(); } else mBoneMatrices.clear(); mBoneMatrices.put(uBoneMatrix); mBoneMatrices.position(0); mGeometry.createBuffer(mBoneMatricesBufferInfo, BufferType.FLOAT_BUFFER, mBoneMatrices, GLES20.GL_ARRAY_BUFFER); }
createBuffer(bufferInfo, bufferInfo.bufferType, bufferInfo.buffer, bufferInfo.target);
public void setColor(float r, float g, float b, float a, boolean createNewBuffer) { if (mColors == null || mColors.limit() == 0) { mColorBufferInfo = new BufferInfo(); mColors = ByteBuffer.allocateDirect(mNumVertices * 4 * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()).asFloatBuffer(); createNewBuffer = true; } mColors.position(0); while (mColors.remaining() > 3) { mColors.put(r); mColors.put(g); mColors.put(b); mColors.put(a); } mColors.position(0); if (createNewBuffer == true) { createBuffer(mColorBufferInfo, BufferType.FLOAT_BUFFER, mColors, GLES20.GL_ARRAY_BUFFER); } else { GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mColorBufferInfo.bufferHandle); GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mColors.limit() * FLOAT_SIZE_BYTES, mColors, GLES20.GL_STATIC_DRAW); } GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); }
createBuffer(mVertexBufferInfo, BufferType.FLOAT_BUFFER, mVertices, GLES20.GL_ARRAY_BUFFER); createBuffer(mNormalBufferInfo, BufferType.FLOAT_BUFFER, mNormals, GLES20.GL_ARRAY_BUFFER); createBuffer(mTexCoordBufferInfo, BufferType.FLOAT_BUFFER, mTextureCoords, GLES20.GL_ARRAY_BUFFER); createBuffer(mColorBufferInfo, BufferType.FLOAT_BUFFER, mColors, GLES20.GL_ARRAY_BUFFER); createBuffer(mIndexBufferInfo, BufferType.INT_BUFFER, mIndicesInt, GLES20.GL_ELEMENT_ARRAY_BUFFER); createBuffer(mIndexBufferInfo, BufferType.SHORT_BUFFER, mIndicesShort, GLES20.GL_ELEMENT_ARRAY_BUFFER);