Java Code Examples for com.jogamp.opengl.GL4#glTexStorage3D()

The following examples show how to use com.jogamp.opengl.GL4#glTexStorage3D() . 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: TextureManager.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
int initTextureArray(TextureProvider textureProvider, GL4 gl)
{
	if (!allTexturesLoaded(textureProvider))
	{
		return -1;
	}

	Texture[] textures = textureProvider.getTextures();

	int textureArrayId = GLUtil.glGenTexture(gl);
	gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, textureArrayId);
	gl.glTexStorage3D(gl.GL_TEXTURE_2D_ARRAY, 1, gl.GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, textures.length);

	gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST);
	gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST);

	gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE);

	// Set brightness to 1.0d to upload unmodified textures to GPU
	double save = textureProvider.getBrightness();
	textureProvider.setBrightness(1.0d);

	updateTextures(textureProvider, gl, textureArrayId);

	textureProvider.setBrightness(save);

	gl.glActiveTexture(gl.GL_TEXTURE1);
	gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, textureArrayId);
	gl.glActiveTexture(gl.GL_TEXTURE0);

	return textureArrayId;
}
 
Example 2
Source File: TextureManager.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
int initTextureArray(TextureProvider textureProvider, GL4 gl)
{
	if (!allTexturesLoaded(textureProvider))
	{
		return -1;
	}

	Texture[] textures = textureProvider.getTextures();

	int textureArrayId = GLUtil.glGenTexture(gl);
	gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, textureArrayId);
	gl.glTexStorage3D(gl.GL_TEXTURE_2D_ARRAY, 1, gl.GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, textures.length);

	gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST);
	gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST);

	gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE);

	// Set brightness to 1.0d to upload unmodified textures to GPU
	double save = textureProvider.getBrightness();
	textureProvider.setBrightness(1.0d);

	updateTextures(textureProvider, gl, textureArrayId);

	textureProvider.setBrightness(save);

	gl.glActiveTexture(gl.GL_TEXTURE1);
	gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, textureArrayId);
	gl.glActiveTexture(gl.GL_TEXTURE0);

	return textureArrayId;
}
 
Example 3
Source File: Gl_430_texture_storage.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl4.glGenTextures(1, textureName);
            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
            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, texture.levels() - 1);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, texture.levels(),
                    format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1], 1);

            for (int level = 0; level < texture.levels(); ++level) {

                gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                        0, 0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1], 1,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_430_texture_storage.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 4
Source File: Gl_450_clip_control.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl4.glGenTextures(1, textureName);
            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
            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, texture.levels() - 1);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, texture.levels(), format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1], 1);

            for (int level = 0; level < texture.levels(); ++level) {

                gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                        0, 0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1], 1,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_450_clip_control.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 5
Source File: Gl_500_texture_cube_arb.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        jgli.TextureCube texture = new TextureCube(jgli.Format.FORMAT_RGBA8_UNORM_PACK8, new int[]{2, 2}, 1);
        assert (!texture.empty());

        jgli.Gl.Format format = jgli.Gl.translate(texture.format());

        texture.clearFace(0, new byte[]{(byte) 255, (byte) 0, (byte) 0, (byte) 255});

        texture.clearFace(1, new byte[]{(byte) 255, (byte) 128, (byte) 0, (byte) 255});
        texture.clearFace(2, new byte[]{(byte) 255, (byte) 255, (byte) 0, (byte) 255});
        texture.clearFace(3, new byte[]{(byte) 0, (byte) 255, (byte) 0, (byte) 255});
        texture.clearFace(4, new byte[]{(byte) 0, (byte) 255, (byte) 255, (byte) 255});
        texture.clearFace(5, new byte[]{(byte) 0, (byte) 0, (byte) 255, (byte) 255});

        gl4.glGenTextures(1, textureName);
        gl4.glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textureName.get(0));
        gl4.glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
        gl4.glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);

        gl4.glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, texture.levels(),
                format.internal.value, texture.dimensions()[0], texture.dimensions()[1], texture.faces());

        gl4.glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0,
                0, 0, 0,
                texture.dimensions()[0],
                texture.dimensions()[1],
                texture.faces(),
                format.external.value, format.type.value,
                texture.data());

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

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl4.glGenTextures(1, textureName);
            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY,
                    texture.levels(), format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1], 1);

            for (int level = 0; level < texture.levels(); ++level) {
                gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                        0, 0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1], 1,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_420_texture_storage.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 7
Source File: Gl_420_texture_array.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        int[] maxTextureArrayLayers = {0};
        gl4.glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, maxTextureArrayLayers, 0);

        gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        gl4.glGenTextures(1, textureName);

        gl4.glActiveTexture(GL_TEXTURE0);
        gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));

        jgli.Texture2dArray texture = new Texture2dArray(jgli.Format.FORMAT_RGBA8_UNORM_PACK32, new int[]{4, 4}, 15, 1);
        for (int layerIndex = 0, layerCount = texture.layers(); layerIndex < layerCount; layerIndex++) {
            float progress = (float) layerIndex / layerCount;
            Vec4u8 color = new Vec4u8(new Vec4(progress, 0.5f + progress * 0.5f, 1f - progress, 1f).mul(255f));
            texture.clear(layerIndex, 0, 0, color.toBa_());
        }

        jgli.Gl.Format format = jgli.Gl.translate(texture.format());

        gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, texture.levels(),
                format.internal.value,
                texture.dimensions()[0], texture.dimensions()[1], texture.layers());

        for (int array = 0; array < texture.layers(); ++array) {
            for (int level = 0; level < texture.levels(); ++level) {
                gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                        0, 0, array,
                        texture.dimensions(level)[0], texture.dimensions(level)[1], 1,
                        format.external.value, format.type.value,
                        texture.data(array, 0, level));
            }
        }

        gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
        return true;
    }
 
Example 8
Source File: Gl_440_buffer_storage.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl4.glGenTextures(1, textureName);
            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
            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, texture.levels() - 1);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, texture.levels(),
                    format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1], 1);

            for (int level = 0; level < texture.levels(); ++level) {

                gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                        0, 0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1], 1,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_440_buffer_storage.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 9
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;
    }
 
Example 10
Source File: Gl_430_fbo_srgb_decode.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        try {
            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            assert (!texture.empty());
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl4.glGenTextures(Texture.MAX, textureName);

            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.DIFFUSE_SRGB));
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY,
                    texture.levels(), format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1], 1);

            for (int level = 0; level < texture.levels(); ++level) {
                gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                        0, 0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1], 1,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl4.glTextureView(textureName.get(Texture.DIFFUSE_RGB), GL_TEXTURE_2D_ARRAY,
                    textureName.get(Texture.DIFFUSE_SRGB), GL_RGBA8, 0, texture.levels(), 0, 1);

            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER));
            gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl4.glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, windowSize.x * framebufferScale,
                    windowSize.y * framebufferScale);

            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RENDERBUFFER));
            gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT24, windowSize.x * framebufferScale,
                    windowSize.y * framebufferScale);

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_430_fbo_srgb_decode.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 11
Source File: Gl_450_query_statistics_arb.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        boolean validated = true;

        try {

            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl4.glGenTextures(1, textureName);
            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
            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, texture.levels() - 1);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, texture.levels(),
                    format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1], 1);

            for (int level = 0; level < texture.levels(); ++level) {
                gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                        0, 0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1], 1,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_450_query_statistics_arb.class.getName()).log(Level.SEVERE, null, ex);
        }
        return validated;
    }
 
Example 12
Source File: Gl_500_texture_sparse_arb.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        int size = 16384;
        // TODO, implement jgli levels (int i)
        int levels = jgli.Util.levels(new int[]{size});
        int maxLevels = 4;

        gl4.glGenTextures(1, textureName);
        gl4.glActiveTexture(GL_TEXTURE0);
        gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
        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, maxLevels - 1);
        gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
        gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SPARSE_ARB, GL_TRUE);
        gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, levels, GL_RGBA8, size, size, 1);

        Vec3i pageSize = new Vec3i();
        IntBuffer params = GLBuffers.newDirectIntBuffer(1);
        gl4.glGetInternalformativ(GL_TEXTURE_2D_ARRAY, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_X_ARB, 1, params);
        pageSize.x = params.get(0);
        gl4.glGetInternalformativ(GL_TEXTURE_2D_ARRAY, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_Y_ARB, 1, params);
        pageSize.y = params.get(0);
        gl4.glGetInternalformativ(GL_TEXTURE_2D_ARRAY, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_Z_ARB, 1, params);
        pageSize.z = params.get(0);
        BufferUtils.destroyDirectBuffer(params);

        ByteBuffer page = GLBuffers.newDirectByteBuffer(pageSize.x * pageSize.y * pageSize.z * 4);

        for (int level = 0; level < 1; ++level) {

            int levelSize = (size >> level);
            int tileCountY = levelSize / pageSize.y;
            int tileCountX = levelSize / pageSize.x;

            for (int j = 0; j < tileCountY; ++j) {

                for (int i = 0; i < tileCountX; ++i) {

                    if (Math.abs(new Vec2(i, j).div(new Vec2(tileCountX, tileCountY)).mul(2.0f).sub(1.0f).length()) > 1.0f) {
                        continue;
                    }
//                    byte a = (byte) ((float) i / (levelSize / pageSize.x) * 255);
//                    byte b = (byte) ((float) j / (levelSize / pageSize.y) * 255);
//                    byte c = (byte) ((float) level / maxLevels * 255);
//                    byte d = (byte) 255;
                    for (int p = 0; p < page.capacity(); p += 4) {
                        page.put(p + 0, (byte) ((float) i / (levelSize / pageSize.x) * 255));
                        page.put(p + 1, (byte) ((float) j / (levelSize / pageSize.y) * 255));
                        page.put(p + 2, (byte) ((float) level / maxLevels * 255));
                        page.put(p + 3, (byte) 255);
                    }

                    gl4.glTexPageCommitmentARB(GL_TEXTURE_2D_ARRAY, level,
                            pageSize.x * i, pageSize.y * j, 0,
                            pageSize.x, pageSize.y, 1,
                            true);

                    gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                            pageSize.x * i, pageSize.y * j, 0,
                            pageSize.x, pageSize.y, 1,
                            GL_RGBA, GL_UNSIGNED_BYTE,
                            page.rewind());
                }
            }
        }

        gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

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

        boolean validated = true;
        try {

            jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE));

            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl4.glGenTextures(1, textureName);
            gl4.glActiveTexture(GL_TEXTURE0);
            gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, format.swizzles.r.value);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, format.swizzles.g.value);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, format.swizzles.b.value);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, format.swizzles.a.value);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            gl4.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            gl4.glTexStorage3D(GL_TEXTURE_2D_ARRAY, texture.levels(),
                    format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1], 1);

            for (int level = 0; level < texture.levels(); ++level) {
                gl4.glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level,
                        0, 0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1], 1,
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

        } catch (IOException ex) {
            Logger.getLogger(Gl_500_buffer_pinned_amd.class.getName()).log(Level.SEVERE, null, ex);
        }
        return validated;
    }
 
Example 14
Source File: Gl_420_texture_cube.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initTexture(GL4 gl4) {

        gl4.glActiveTexture(GL_TEXTURE0);
        gl4.glGenTextures(1, textureName);
        gl4.glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textureName.get(0));
        gl4.glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
        gl4.glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);

        jgli.TextureCube textureA = new TextureCube(jgli.Format.FORMAT_RGBA8_UNORM_PACK32, new int[]{512, 512}, 1);
        assert (!textureA.empty());
        textureA.clear(0, 0, 0, new byte[]{(byte) 255, (byte) 0, (byte) 0, (byte) 255});
        textureA.clear(0, 1, 0, new byte[]{(byte) 255, (byte) 128, (byte) 0, (byte) 255});
        textureA.clear(0, 2, 0, new byte[]{(byte) 255, (byte) 255, (byte) 0, (byte) 255});
        textureA.clear(0, 3, 0, new byte[]{(byte) 0, (byte) 255, (byte) 0, (byte) 255});
        textureA.clear(0, 4, 0, new byte[]{(byte) 0, (byte) 255, (byte) 255, (byte) 255});
        textureA.clear(0, 5, 0, new byte[]{(byte) 0, (byte) 0, (byte) 255, (byte) 255});

        jgli.TextureCube textureB = new TextureCube(jgli.Format.FORMAT_RGBA8_UNORM_PACK32, new int[]{256, 256}, 1);
        assert (!textureB.empty());
        textureB.clear(0, 0, 0, new byte[]{(byte) 255, (byte) 128, (byte) 128, (byte) 255});
        textureB.clear(0, 1, 0, new byte[]{(byte) 255, (byte) 192, (byte) 128, (byte) 255});
        textureB.clear(0, 2, 0, new byte[]{(byte) 255, (byte) 255, (byte) 128, (byte) 255});
        textureB.clear(0, 3, 0, new byte[]{(byte) 128, (byte) 255, (byte) 128, (byte) 255});
        textureB.clear(0, 4, 0, new byte[]{(byte) 128, (byte) 255, (byte) 255, (byte) 255});
        textureB.clear(0, 5, 0, new byte[]{(byte) 128, (byte) 128, (byte) 255, (byte) 255});

        jgli.TextureCube textureC = new TextureCube(jgli.Format.FORMAT_RGBA8_UNORM_PACK32, new int[]{128, 128}, 1);
        assert (!textureC.empty());
        textureC.clear(0, 0, 0, new byte[]{(byte) 255, (byte) 192, (byte) 192, (byte) 255});
        textureC.clear(0, 1, 0, new byte[]{(byte) 255, (byte) 224, (byte) 192, (byte) 255});
        textureC.clear(0, 2, 0, new byte[]{(byte) 255, (byte) 255, (byte) 192, (byte) 255});
        textureC.clear(0, 3, 0, new byte[]{(byte) 192, (byte) 255, (byte) 192, (byte) 255});
        textureC.clear(0, 4, 0, new byte[]{(byte) 192, (byte) 255, (byte) 255, (byte) 255});
        textureC.clear(0, 5, 0, new byte[]{(byte) 192, (byte) 192, (byte) 255, (byte) 255});

        gl4.glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 3,
                GL_RGBA8, textureA.dimensions()[0], textureA.dimensions()[1], textureA.faces());

        gl4.glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0,
                0, 0, 0,
                textureA.dimensions()[0],
                textureA.dimensions()[1],
                textureA.faces(),
                GL_RGBA, GL_UNSIGNED_BYTE,
                textureA.data());

        gl4.glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 1,
                0, 0, 0,
                textureB.dimensions()[0],
                textureB.dimensions()[1],
                textureB.faces(),
                GL_RGBA, GL_UNSIGNED_BYTE,
                textureB.data());

        gl4.glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 2,
                0, 0, 0,
                textureC.dimensions()[0],
                textureC.dimensions()[1],
                textureC.faces(),
                GL_RGBA, GL_UNSIGNED_BYTE,
                textureC.data());

        //glGenerateMipmap(GL_TEXTURE_CUBE_MAP_ARRAY);
        return true;
    }