@Override public NativeObject createDestructableClone() { return new BufferObject(null, getId()); }
/** * Sets the value to the filed by the field's name. * * @param name the field's name. * @param value the value. */ public void setFieldValue(final String name, final Object value) { BufferObjectField field = fields.get(name); if (field == null) { declareField(name, getVarTypeByValue(value)); field = fields.get(name); } field.setValue(value); setUpdateNeeded(); }
final BufferObject.BufferType bufferType = bo.getBufferType(); final ByteBuffer data = bo.computeData(maxSize); if (data == null) { throw new IllegalArgumentException("Can't upload BO without data."); int bufferId = bo.getId(); if (bufferId == -1) { bufferId = intBuf1.get(0); bo.setId(bufferId); bo.clearUpdateNeeded();
/** * Updates the buffer block for the shader. * * @param shader the shader. * @param bufferBlock the storage block. */ protected void updateShaderBufferBlock(final Shader shader, final ShaderBufferBlock bufferBlock) { assert bufferBlock.getName() != null; assert shader.getId() > 0; final BufferObject bufferObject = bufferBlock.getBufferObject(); if (bufferObject.getUniqueId() == -1 || bufferObject.isUpdateNeeded()) { updateBufferData(bufferObject); } if (!bufferBlock.isUpdateNeeded()) { return; } bindProgram(shader); final int shaderId = shader.getId(); final BufferObject.BufferType bufferType = bufferObject.getBufferType(); bindBuffer(bufferBlock, bufferObject, shaderId, bufferType); bufferBlock.clearUpdateNeeded(); }
@Override public void deleteBuffer(final BufferObject bo) { int bufferId = bo.getId(); if (bufferId == -1) { return; } intBuf1.clear(); intBuf1.put(bufferId); intBuf1.flip(); gl.glDeleteBuffers(intBuf1); bo.resetObject(); }
private void bindBuffer(final ShaderBufferBlock bufferBlock, final BufferObject bufferObject, final int shaderId, final BufferObject.BufferType bufferType) { switch (bufferType) { case UniformBufferObject: { final int blockIndex = gl3.glGetUniformBlockIndex(shaderId, bufferBlock.getName()); gl3.glBindBufferBase(GL3.GL_UNIFORM_BUFFER, bufferObject.getBinding(), bufferObject.getId()); gl3.glUniformBlockBinding(GL3.GL_UNIFORM_BUFFER, blockIndex, bufferObject.getBinding()); break; } case ShaderStorageBufferObject: { final int blockIndex = gl4.glGetProgramResourceIndex(shaderId, GL4.GL_SHADER_STORAGE_BLOCK, bufferBlock.getName()); gl4.glShaderStorageBlockBinding(shaderId, blockIndex, bufferObject.getBinding()); gl4.glBindBufferBase(GL4.GL_SHADER_STORAGE_BUFFER, bufferObject.getBinding(), bufferObject.getId()); break; } default: { throw new IllegalArgumentException("Doesn't support binding of " + bufferType); } } }
estimateSize += estimateSize(field); writeField(field, data);
return 16; case IntArray: { return estimate((int[]) field.getValue()); return estimate((float[]) field.getValue()); return estimateArray(field.getValue(), 8); return estimateArray(field.getValue(), multiplier); return estimateArray(field.getValue(), 16); int multiplier = layout == Layout.std140 ? 16 : 12; multiplier = 3 * 3 * multiplier; return estimateArray(field.getValue(), multiplier); return estimateArray(field.getValue(), multiplier);
/** * Sets the buffer's type. * * @param bufferType the buffer's type. */ public void setBufferType(final BufferType bufferType) { if (getId() != -1) { throw new IllegalStateException("Can't change buffer's type when this buffer is already initialized."); } this.bufferType = bufferType; }