/** Constructs a new ShaderProgram and immediately compiles it. * * @param vertexShader the vertex shader * @param fragmentShader the fragment shader */ public ShaderProgram (String vertexShader, String fragmentShader) { if (vertexShader == null) throw new IllegalArgumentException("vertex shader must not be null"); if (fragmentShader == null) throw new IllegalArgumentException("fragment shader must not be null"); if (prependVertexCode != null && prependVertexCode.length() > 0) vertexShader = prependVertexCode + vertexShader; if (prependFragmentCode != null && prependFragmentCode.length() > 0) fragmentShader = prependFragmentCode + fragmentShader; this.vertexShaderSource = vertexShader; this.fragmentShaderSource = fragmentShader; this.matrix = BufferUtils.newFloatBuffer(16); compileShaders(vertexShader, fragmentShader); if (isCompiled()) { fetchAttributes(); fetchUniforms(); addManagedShader(Gdx.app, this); } }
/** Constructs a new ShaderProgram and immediately compiles it. * * @param vertexShader the vertex shader * @param fragmentShader the fragment shader */ public ShaderProgram (String vertexShader, String fragmentShader) { if (vertexShader == null) throw new IllegalArgumentException("vertex shader must not be null"); if (fragmentShader == null) throw new IllegalArgumentException("fragment shader must not be null"); if (prependVertexCode != null && prependVertexCode.length() > 0) vertexShader = prependVertexCode + vertexShader; if (prependFragmentCode != null && prependFragmentCode.length() > 0) fragmentShader = prependFragmentCode + fragmentShader; this.vertexShaderSource = vertexShader; this.fragmentShaderSource = fragmentShader; this.matrix = BufferUtils.newFloatBuffer(16); compileShaders(vertexShader, fragmentShader); if (isCompiled()) { fetchAttributes(); fetchUniforms(); addManagedShader(Gdx.app, this); } }
/** * Constructs a new interleaved VertexBufferObjectWithVAO. * * @param isStatic whether the vertex data is static. * @param numVertices the maximum number of vertices * @param attributes the {@link VertexAttributes}. */ public VertexBufferObjectWithVAO (boolean isStatic, int numVertices, VertexAttributes attributes) { this.isStatic = isStatic; this.attributes = attributes; buffer = BufferUtils.newFloatBuffer(this.attributes.vertexSize / 4 * numVertices); buffer.flip(); bufferHandle = Gdx.gl20.glGenBuffer(); usage = isStatic ? GL20.GL_STATIC_DRAW : GL20.GL_DYNAMIC_DRAW; createVAO(); }
/** * Constructs a new interleaved VertexBufferObjectWithVAO. * * @param isStatic whether the vertex data is static. * @param numVertices the maximum number of vertices * @param attributes the {@link VertexAttributes}. */ public VertexBufferObjectWithVAO (boolean isStatic, int numVertices, VertexAttributes attributes) { this.isStatic = isStatic; this.attributes = attributes; buffer = BufferUtils.newFloatBuffer(this.attributes.vertexSize / 4 * numVertices); buffer.flip(); bufferHandle = Gdx.gl20.glGenBuffer(); usage = isStatic ? GL20.GL_STATIC_DRAW : GL20.GL_DYNAMIC_DRAW; createVAO(); }
@Override public void prepare () { if (isPrepared) throw new GdxRuntimeException("Already prepared"); if (!isGpuOnly) { int amountOfFloats = 4; if (Gdx.graphics.getGLVersion().getType().equals(GLVersion.Type.OpenGL)) { if (internalFormat == GL30.GL_RGBA16F || internalFormat == GL30.GL_RGBA32F) amountOfFloats = 4; if (internalFormat == GL30.GL_RGB16F || internalFormat == GL30.GL_RGB32F) amountOfFloats = 3; if (internalFormat == GL30.GL_RG16F || internalFormat == GL30.GL_RG32F) amountOfFloats = 2; if (internalFormat == GL30.GL_R16F || internalFormat == GL30.GL_R32F) amountOfFloats = 1; } this.buffer = BufferUtils.newFloatBuffer(width * height * amountOfFloats); } isPrepared = true; }
@Override public void prepare () { if (isPrepared) throw new GdxRuntimeException("Already prepared"); if (!isGpuOnly) { int amountOfFloats = 4; if (Gdx.graphics.getGLVersion().getType().equals(GLVersion.Type.OpenGL)) { if (internalFormat == GL30.GL_RGBA16F || internalFormat == GL30.GL_RGBA32F) amountOfFloats = 4; if (internalFormat == GL30.GL_RGB16F || internalFormat == GL30.GL_RGB32F) amountOfFloats = 3; if (internalFormat == GL30.GL_RG16F || internalFormat == GL30.GL_RG32F) amountOfFloats = 2; if (internalFormat == GL30.GL_R16F || internalFormat == GL30.GL_R32F) amountOfFloats = 1; } this.buffer = BufferUtils.newFloatBuffer(width * height * amountOfFloats); } isPrepared = true; }
/** Creates a new {@link OcclusionBuffer} * * @param width Width of the buffer image * @param height Height of the buffer image */ public OcclusionBuffer (int width, int height) { bufferWidth = width; bufferHeight = height; bufferHalfExt = new Vector2(width * 0.5f, height * 0.5f); bufferOffset = new Vector2(bufferHalfExt.x + 0.5f, bufferHalfExt.y + 0.5f); buffer = BufferUtils.newFloatBuffer(width * height); for (int i = 0; i < 8; i++) { box[i] = new Vector3(); tmpVertices[i] = new Quaternion(); clippedQuad[i] = new Quaternion(); } for (int i = 0; i < 4; i++) quad[i] = new Quaternion(); }
IntBuffer ib = BufferUtils.newIntBuffer(8); LongBuffer lb = BufferUtils.newLongBuffer(8); FloatBuffer fb = BufferUtils.newFloatBuffer(8); DoubleBuffer db = BufferUtils.newDoubleBuffer(8);
private void benchFloat () { FloatBuffer fb = BufferUtils.newFloatBuffer(1024 * 1024 / 4); float[] floats = new float[1024 * 1024 / 4]; int len = floats.length;
@Nonnull @Override public FloatBuffer createNativeOrderedFloatBuffer(final int numFloats) { return BufferUtils.newFloatBuffer(numFloats); }
@Nonnull @Override public FloatBuffer createNativeOrderedFloatBuffer(final int numFloats) { return BufferUtils.newFloatBuffer(numFloats); }
/** * Constructs a new interleaved VertexBufferObject. * * @param isStatic * whether the vertex data is static. * @param numVertices * the maximum number of vertices * @param attributes * the {@link VertexAttributes}. */ public VertexArrayEmulator(boolean isStatic, int numVertices, VertexAttributes attributes) { this.isStatic = isStatic; this.attributes = attributes; buffer = BufferUtils.newFloatBuffer(this.attributes.vertexSize / 4 * numVertices); buffer.flip(); bufferHandle = Gdx.gl20.glGenBuffer(); usage = isStatic ? GL20.GL_STATIC_DRAW : GL20.GL_DYNAMIC_DRAW; }
/** Constructs a new ShaderProgram and immediately compiles it. * * @param vertexShader the vertex shader * @param fragmentShader the fragment shader */ public ShaderProgram (String vertexShader, String fragmentShader) { if (vertexShader == null) throw new IllegalArgumentException("vertex shader must not be null"); if (fragmentShader == null) throw new IllegalArgumentException("fragment shader must not be null"); if (prependVertexCode != null && prependVertexCode.length() > 0) vertexShader = prependVertexCode + vertexShader; if (prependFragmentCode != null && prependFragmentCode.length() > 0) fragmentShader = prependFragmentCode + fragmentShader; this.vertexShaderSource = vertexShader; this.fragmentShaderSource = fragmentShader; this.matrix = BufferUtils.newFloatBuffer(16); compileShaders(vertexShader, fragmentShader); if (isCompiled()) { fetchAttributes(); fetchUniforms(); addManagedShader(Gdx.app, this); } }
@Override public void prepare () { if (isPrepared) throw new GdxRuntimeException("Already prepared"); if (!isGpuOnly) { int amountOfFloats = 4; if (Gdx.graphics.getGLVersion().getType().equals(GLVersion.Type.OpenGL)) { if (internalFormat == GL30.GL_RGBA16F || internalFormat == GL30.GL_RGBA32F) amountOfFloats = 4; if (internalFormat == GL30.GL_RGB16F || internalFormat == GL30.GL_RGB32F) amountOfFloats = 3; if (internalFormat == GL30.GL_RG16F || internalFormat == GL30.GL_RG32F) amountOfFloats = 2; if (internalFormat == GL30.GL_R16F || internalFormat == GL30.GL_R32F) amountOfFloats = 1; } this.buffer = BufferUtils.newFloatBuffer(width * height * amountOfFloats); } isPrepared = true; }
FloatBuffer workBuffer = BufferUtils.newFloatBuffer(mesh.getVerticesBuffer().capacity()); BufferUtils.copy(mesh.getVerticesBuffer(), workBuffer, mesh.getNumVertices() * mesh.getVertexSize() / 4); BufferUtils.transform(workBuffer, 3, mesh.getVertexSize(), mesh.getNumVertices(), transform);