Java Code Examples for com.jogamp.opengl.util.GLBuffers#newDirectByteBuffer()

The following examples show how to use com.jogamp.opengl.util.GLBuffers#newDirectByteBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Gl_330_fbo_multisample_explicit_nv.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);

        gl3.glGenBuffers(1, bufferName);
        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0));
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBb(vertexBuffer, i);
        }
        gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(vertexBuffer);

        return checkError(gl3, "initBuffer");
    }
 
Example 2
Source File: Gl_430_interface_matching.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBB(vertexBuffer, i);
        }
        vertexBuffer.rewind();
        gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        BufferUtils.destroyDirectBuffer(vertexBuffer);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        int[] uniformBufferOffset = {0};
        gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0);
        int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset[0]);

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        return true;
    }
 
Example 3
Source File: Gl_400_fbo_multisample.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBb(vertexBuffer, i);
        }
        vertexBuffer.rewind();
        gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(elementBuffer);
        BufferUtils.destroyDirectBuffer(vertexBuffer);

        return true;
    }
 
Example 4
Source File: Gl_400_primitive_smooth_shading.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);

        gl4.glGenBuffers(Buffer.MAX, bufferName);
        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.ARRAY));
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBb(vertexBuffer, i);
        }
        vertexBuffer.rewind();
        gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(elementBuffer);
        BufferUtils.destroyDirectBuffer(vertexBuffer);

        return checkError(gl4, "initBuffer");
    }
 
Example 5
Source File: Gl_500_multi_draw_indirect_arb.java    From jogl-samples with MIT License 6 votes vote down vote up
private void validate(GL4 gl4) {

        int[] status = {0};
        gl4.glValidateProgramPipeline(pipelineName.get(0));
        gl4.glGetProgramPipelineiv(pipelineName.get(0), GL_VALIDATE_STATUS, status, 0);

        if (status[0] != GL_TRUE) {

            int[] lengthMax = {0};
            gl4.glGetProgramPipelineiv(pipelineName.get(0), GL_INFO_LOG_LENGTH, lengthMax, 0);

            IntBuffer lengthQuery = GLBuffers.newDirectIntBuffer(1);
            ByteBuffer infoLog = GLBuffers.newDirectByteBuffer(lengthMax[0] + 1);
            gl4.glGetProgramPipelineInfoLog(pipelineName.get(0), infoLog.capacity(), lengthQuery, infoLog);

            gl4.glDebugMessageInsert(
                    GL_DEBUG_SOURCE_APPLICATION,
                    GL_DEBUG_TYPE_OTHER, 76,
                    GL_DEBUG_SEVERITY_LOW,
                    lengthQuery.get(0), new String(infoLog.array()).trim());
        }
    }
 
Example 6
Source File: Gl_330_sampler_filter.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);

        gl3.glGenBuffers(1, bufferName);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0));
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBb(vertexBuffer, i);
        }
        vertexBuffer.rewind();
        gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(vertexBuffer);

        return checkError(gl3, "initBuffer");
    }
 
Example 7
Source File: Gl_330_sampler_anisotropy_ext.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);

        gl3.glGenBuffers(1, bufferName);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0));
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBb(vertexBuffer, i);
        }
        vertexBuffer.rewind();
        gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(vertexBuffer);

        return checkError(gl3, "initBuffer");
    }
 
Example 8
Source File: Gl_500_buffer_pinned_amd.java    From jogl-samples with MIT License 5 votes vote down vote up
private ByteBuffer initMemoryBuffer() {
        clientBufferAddress = GLBuffers.newDirectByteBuffer(vertexSize + PAGE_SIZE - 1);
//		glm::byte* UnalignAddress = this->ClientBufferAddress.get();
//		glm::byte* AlignAddress = align(UnalignAddress, PAGE_SIZE);
//		memcpy(AlignAddress, VertexData, VertexSize);
//		return reinterpret_cast<void*>(AlignAddress);
        return null;
    }
 
Example 9
Source File: Gl_420_texture_cube.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);
        IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toDbb(vertexBuffer, i * Vec2.SIZE);
        }
        gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        gl4.glGetIntegerv(
                GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
                uniformBufferOffset);

        int uniformBlockSize = Math.max(Transform.SIZE, uniformBufferOffset.get(0));

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(vertexBuffer);
        BufferUtils.destroyDirectBuffer(uniformBufferOffset);

        return true;
    }
 
Example 10
Source File: Gl_330_buffer_type.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        FloatBuffer positionF32Buffer = GLBuffers.newDirectFloatBuffer(positionDataF32);
        ByteBuffer positionI8Buffer = GLBuffers.newDirectByteBuffer(positionDataI8);
        IntBuffer positionI32Buffer = GLBuffers.newDirectIntBuffer(positionDataI32);
        IntBuffer positionRGB10A2Buffer = GLBuffers.newDirectIntBuffer(positionDataRGB10A2);

        // Generate a buffer object
        gl3.glGenBuffers(Buffer.MAX, bufferName);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.F32));
        gl3.glBufferData(GL_ARRAY_BUFFER, positionSizeF32, positionF32Buffer, GL_STATIC_DRAW);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.I8));
        gl3.glBufferData(GL_ARRAY_BUFFER, positionSizeI8, positionI8Buffer, GL_STATIC_DRAW);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.I32));
        gl3.glBufferData(GL_ARRAY_BUFFER, positionSizeI32, positionI32Buffer, GL_STATIC_DRAW);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.RGB10A2));
        gl3.glBufferData(GL_ARRAY_BUFFER, positionSizeRGB10A2, positionRGB10A2Buffer, GL_STATIC_DRAW);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(positionF32Buffer);
        BufferUtils.destroyDirectBuffer(positionI8Buffer);
        BufferUtils.destroyDirectBuffer(positionI32Buffer);
        BufferUtils.destroyDirectBuffer(positionRGB10A2Buffer);

        return checkError(gl3, "initBuffer");
    }
 
Example 11
Source File: Test.java    From jogl-samples with MIT License 5 votes vote down vote up
protected void saveImage(GL3 gl3, int width, int height) {

        try {
            BufferedImage screenshot = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics graphics = screenshot.getGraphics();

            ByteBuffer buffer = GLBuffers.newDirectByteBuffer(width * height * 4);

            gl3.glReadBuffer(GL_BACK);
            gl3.glReadPixels(0, 0, width, height, GL3.GL_RGBA, GL3.GL_UNSIGNED_BYTE, buffer);

            for (int h = 0; h < height; h++) {
                for (int w = 0; w < width; w++) {
                    // The color are the three consecutive bytes, it's like referencing
                    // to the next consecutive array elements, so we got red, green, blue..
                    // red, green, blue, and so on..
//                    System.out.println("(" + ((buffer.get() & 0xff) / 255) + ", "
//                            + ((buffer.get() & 0xff) / 255) + ", " + ((buffer.get() & 0xff) / 255)
//                            + ", " + ((buffer.get() & 0xff) / 255) + ")");
                    graphics.setColor(new Color((buffer.get() & 0xff), (buffer.get() & 0xff),
                            (buffer.get() & 0xff)));
                    buffer.get();   // alpha
                    graphics.drawRect(w, height - h, 1, 1); // height - h is for flipping the image
//                    graphics.drawRect(w, h, 1, 1); // height - h is for flipping the image
                }
            }
            BufferUtils.destroyDirectBuffer(buffer);

//            File outputfile = new File("/home/elect/Downloads/texture.jpg");
            File outputfile = new File("D:\\Downloads\\texture.png");
            ImageIO.write(screenshot, "png", outputfile);
        } catch (IOException ex) {
            //  Logger.getLogger(EC_DepthPeeling.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
Example 12
Source File: Gl_320_draw_base_vertex.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData);
        ByteBuffer colorBuffer = GLBuffers.newDirectByteBuffer(colorData);
        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);

        gl3.glGenBuffers(Buffer.MAX, bufferName);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.POSITION));
        gl3.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.COLOR));
        gl3.glBufferData(GL_ARRAY_BUFFER, colorSize, colorBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

        gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        int[] uniformBlockSize = {0};
        gl3.glGetActiveUniformBlockiv(programName, uniformTransform, GL_UNIFORM_BLOCK_DATA_SIZE, uniformBlockSize, 0);
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize[0], null, GL_DYNAMIC_DRAW);
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(positionBuffer);
        BufferUtils.destroyDirectBuffer(colorBuffer);
        BufferUtils.destroyDirectBuffer(elementBuffer);

        return checkError(gl3, "initBuffer");
    }
 
Example 13
Source File: Gl_500_primitive_shading_nv.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1);
        gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset);
        int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0));
        BufferUtils.destroyDirectBuffer(uniformBufferOffset);

        gl4.glCreateBuffers(Buffer.MAX, bufferName);

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBb(vertexBuffer, i);
        }
        vertexBuffer.rewind();

        if (bug1287) {

            gl4.glNamedBufferStorage(bufferName.get(Buffer.TRANSFORM), uniformBlockSize, null, GL_MAP_WRITE_BIT);
            gl4.glNamedBufferStorage(bufferName.get(Buffer.ELEMENT), elementSize, elementBuffer, 0);
            gl4.glNamedBufferStorage(bufferName.get(Buffer.VERTEX), vertexSize, vertexBuffer, 0);

        } else {

            gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
            gl4.glBufferStorage(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_MAP_WRITE_BIT);
            gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);
            gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
            gl4.glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, 0);
            gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
            gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
            gl4.glBufferStorage(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, 0);
            gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);
        }

        return true;
    }
 
Example 14
Source File: Gl_500_buffer_pinned_amd.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        boolean validated = true;

        IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1);
        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset);
        int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0));

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

//		void* Pointer = initMemoryBuffer();
        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(Math.max(vertexSize, PAGE_SIZE));
        gl4.glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, bufferName.get(Buffer.VERTEX));
//		gl4.glBufferData(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, vertexSize, Pointer, GL_STREAM_COPY);
        gl4.glBufferData(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, vertexSize, vertexBuffer, GL_STREAM_COPY);
        gl4.glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);
        gl4.glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);

        BufferUtils.destroyDirectBuffer(uniformBufferOffset);

        return validated;
    }
 
Example 15
Source File: Gl_440_interface_matching.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBB(vertexBuffer, i);
        }
        vertexBuffer.rewind();
        gl4.glBufferStorage(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, 0);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        int[] uniformBufferOffset = {0};

        gl4.glGetIntegerv(
                GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
                uniformBufferOffset, 0);

        int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset[0]);

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferStorage(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        return true;
    }
 
Example 16
Source File: Gl_440_buffer_type.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        // Generate a buffer object
        gl4.glGenBuffers(Buffer.MAX, bufferName);

        // Allocate and copy buffers memory
        byte[] data = new byte[positionSizeF32 + positionSizeI8 + positionSizeI32 + positionSizeRGB10A2
                + positionSizeF16 + positionSizeRG11FB10F];
        ByteBuffer dataBuffer = GLBuffers.newDirectByteBuffer(data);

        int currentOffset = 0;
        dataBuffer.asFloatBuffer().put(positionDataF32);

        currentOffset += positionSizeF32;
        dataBuffer.position(currentOffset);
        dataBuffer.put(positionDataI8);

        currentOffset += positionSizeI8;
        dataBuffer.position(currentOffset);
        dataBuffer.asIntBuffer().put(positionDataI32);

        currentOffset += positionSizeI32;
        dataBuffer.position(currentOffset);
        dataBuffer.asIntBuffer().put(positionDataRGB10A2);

        currentOffset += positionSizeRGB10A2;
        dataBuffer.position(currentOffset);
        dataBuffer.asShortBuffer().put(positionDataF16);

        currentOffset += positionSizeF16;
        dataBuffer.position(currentOffset);
        dataBuffer.asIntBuffer().put(positionDataRG11FB10F);

        dataBuffer.rewind();

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        gl4.glBufferStorage(GL_ARRAY_BUFFER, data.length * Byte.BYTES, dataBuffer, 0);

        int[] uniformBufferOffset = {0};
        gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0);
        int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset[0]);

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferStorage(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT
                | GL_MAP_COHERENT_BIT);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        return checkError(gl4, "initBuffer");
    }
 
Example 17
Source File: Gl_430_buffer_uniform.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
        FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
        ByteBuffer lightBuffer = GLBuffers.newDirectByteBuffer(Light.SIZE);
        ByteBuffer materialBuffer = GLBuffers.newDirectByteBuffer(Material.SIZE);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        {
            gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.PER_DRAW));
            gl4.glBufferData(GL_UNIFORM_BUFFER, Transform.SIZE, null, GL_DYNAMIC_DRAW);
            gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);
        }

        {
            new Light(new Vec3(0.0f, 0.0f, 100.f)).toDbb(lightBuffer);

            gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.PER_PASS));
            gl4.glBufferData(GL_UNIFORM_BUFFER, Light.SIZE, lightBuffer, GL_STATIC_DRAW);
            gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);
        }

        {
            new Material(new Vec3(0.7f, 0.0f, 0.0f), new Vec3(0.0f, 0.5f, 0.0f), new Vec3(0.0f, 0.0f, 0.5f), 128.0f)
                    .toDbb(materialBuffer);

            gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.PER_SCENE));
            gl4.glBufferData(GL_UNIFORM_BUFFER, Material.SIZE, materialBuffer, GL_STATIC_DRAW);
            gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);
        }

        BufferUtils.destroyDirectBuffer(elementBuffer);
        BufferUtils.destroyDirectBuffer(vertexBuffer);
        BufferUtils.destroyDirectBuffer(lightBuffer);
        BufferUtils.destroyDirectBuffer(materialBuffer);

        return true;
    }
 
Example 18
Source File: Gl_410_buffer_uniform_array.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
        ByteBuffer positionBuffer = GLBuffers.newDirectByteBuffer(positionSize);
        IntBuffer instanceBuffer = GLBuffers.newDirectIntBuffer(new int[]{0, 1});
        FloatBuffer diffuseBuffer = GLBuffers.newDirectFloatBuffer(
                new float[]{1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f});

        gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferAlignment);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        for (int i = 0; i < vertexCount; i++) {
            positionData[i].toDbb(positionBuffer, i * Vec2.SIZE);
        }
        gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.INSTANCE));
        gl4.glBufferData(GL_ARRAY_BUFFER, instanceBuffer.capacity() * Integer.BYTES, instanceBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        int uniformBufferSize = Math.max(uniformBufferAlignment.get(0), Mat4.SIZE) * 2;

        {
            gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
            gl4.glBufferData(GL_UNIFORM_BUFFER, uniformBufferSize, null, GL_DYNAMIC_DRAW);
            gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);
        }

        {

            gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.MATERIAL));
            gl4.glBufferData(GL_UNIFORM_BUFFER, diffuseBuffer.capacity() * Float.BYTES, diffuseBuffer, GL_STATIC_DRAW);
            gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);
        }

        BufferUtils.destroyDirectBuffer(elementBuffer);
        BufferUtils.destroyDirectBuffer(positionBuffer);
        BufferUtils.destroyDirectBuffer(instanceBuffer);
        BufferUtils.destroyDirectBuffer(diffuseBuffer);

        return true;
    }
 
Example 19
Source File: Gl_430_perf_monitor_amd.java    From jogl-samples with MIT License 4 votes vote down vote up
public Monitor(GL2 gl2, Gl_430_perf_monitor_amd app) {

            name = GLBuffers.newDirectIntBuffer(1);

            int GROUP_NAME_SIZE = 256;

            IntBuffer groupSize = GLBuffers.newDirectIntBuffer(1);
            gl2.glGetPerfMonitorGroupsAMD(groupSize, 0, null);

            IntBuffer groups_ = GLBuffers.newDirectIntBuffer(groupSize.get(0));
            gl2.glGetPerfMonitorGroupsAMD(null, groupSize.get(0), groups_);

            for (int groupIndex = 0; groupIndex < groups_.capacity(); groupIndex++) {

                ByteBuffer groupName = GLBuffers.newDirectByteBuffer(GROUP_NAME_SIZE);
                gl2.glGetPerfMonitorGroupStringAMD(groups_.get(groupIndex), GROUP_NAME_SIZE, null, groupName);

                IntBuffer numCounters = GLBuffers.newDirectIntBuffer(1);
                IntBuffer maxActiveCounters = GLBuffers.newDirectIntBuffer(1);
                gl2.glGetPerfMonitorCountersAMD(groups_.get(groupIndex), numCounters, maxActiveCounters, 0, null);

                IntBuffer counters = GLBuffers.newDirectIntBuffer(numCounters.get(0));
                gl2.glGetPerfMonitorCountersAMD(groups_.get(groupIndex), null, null, numCounters.get(0), counters);

                for (int counterIndex = 0; counterIndex < counters.capacity(); counterIndex++) {

                    ByteBuffer counterName = GLBuffers.newDirectByteBuffer(GROUP_NAME_SIZE);

                    gl2.glGetPerfMonitorCounterStringAMD(groups_.get(groupIndex), counters.get(counterIndex),
                            GROUP_NAME_SIZE, null, counterName);

                    BufferUtils.destroyDirectBuffer(counterName);
                }

                String groupString = "";
                for (int i = 0; i < groupName.capacity(); ++i) {
                    if ((char) (groupName.get(i) & 0xff) == '\0') {
                        break;
                    } else {
                        groupString += (char) (groupName.get(i) & 0xff);
                    }
                }

                groups.put(groups_.get(groupIndex), new Group(groupString, counters));
                stringToGroup.put(groupString, groups_.get(groupIndex));

                BufferUtils.destroyDirectBuffer(groupName);
                BufferUtils.destroyDirectBuffer(numCounters);
                BufferUtils.destroyDirectBuffer(maxActiveCounters);
                BufferUtils.destroyDirectBuffer(counters);
            }

            gl2.glGenPerfMonitorsAMD(1, name);
        }
 
Example 20
Source File: Gl_430_texture_fetch_dependent.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        gl4.glGenTextures(Texture.MAX, textureName);

        {
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.DIFFUSE));
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

            byte[] colors = new byte[4 * 2048];
            for (int colorIndex = 0; colorIndex < colors.length / 4; ++colorIndex) {
                colors[colorIndex * 4 + 0] = (byte) (glm.linearRand(0, 1) * 255f);
                colors[colorIndex * 4 + 1] = (byte) (glm.linearRand(0, 1) * 255f);
                colors[colorIndex * 4 + 2] = (byte) (glm.linearRand(0, 1) * 255f);
                colors[colorIndex * 4 + 3] = (byte) 1;
            }
            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 1, 1, colors.length / 4 * Byte.BYTES);
            ByteBuffer colorsBuffer = GLBuffers.newDirectByteBuffer(colors);
            gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
                    0, 0, 0,
                    1, 1, 2048,
                    GL_RGBA, GL_UNSIGNED_BYTE, colorsBuffer);
            BufferUtils.destroyDirectBuffer(colorsBuffer);
        }

        {
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.INDIRECTION));
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

            int[] data = new int[windowSize.x * windowSize.y];
            for (int index = 0; index < data.length; ++index) {
                //Data[Index] = glm::u32vec1(glm::linearRand(glm::vec1(0), glm::vec1(1)) * 255.0f);
                long signedInt = (long) (glm.linearRand(0, 1) * data.length - 1);
                data[index] = Integer.parseUnsignedInt("" + signedInt);
            }
            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_R32UI, windowSize.x, windowSize.y, 1);
            IntBuffer dataBuffer = GLBuffers.newDirectIntBuffer(data);
            gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
                    0, 0, 0,
                    windowSize.x, windowSize.y, 1,
                    GL_RED_INTEGER, GL_UNSIGNED_INT, dataBuffer);
            BufferUtils.destroyDirectBuffer(dataBuffer);
        }

        return true;
    }