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

The following examples show how to use com.jogamp.opengl.GL4#glTextureSubImage2D() . 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_500_primitive_bindless_nv.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));
            assert (!texture.empty());
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());

            gl4.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

            gl4.glCreateTextures(GL_TEXTURE_2D, 1, textureName);
            gl4.glTextureParameteri(textureName.get(0), GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(0), GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl4.glTextureParameteri(textureName.get(0), GL_TEXTURE_SWIZZLE_R, GL_RED);
            gl4.glTextureParameteri(textureName.get(0), GL_TEXTURE_SWIZZLE_G, GL_GREEN);
            gl4.glTextureParameteri(textureName.get(0), GL_TEXTURE_SWIZZLE_B, GL_BLUE);
            gl4.glTextureParameteri(textureName.get(0), GL_TEXTURE_SWIZZLE_A, GL_ALPHA);

            gl4.glTextureStorage2D(textureName.get(0), texture.levels(), format.internal.value, texture.dimensions()[0],
                    texture.dimensions()[1]);

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

                gl4.glTextureSubImage2D(textureName.get(0), level,
                        0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        format.external.value, format.type.value,
                        texture.data(level));
            }

        } catch (IOException ex) {
            Logger.getLogger(Gl_500_primitive_bindless_nv.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 2
Source File: Gl_430_direct_state_access_ext.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));
            jgli.Gl.Format format = jgli.Gl.translate(texture.format());
            jgli.Gl.Swizzles swizzles = jgli.Gl.translate(texture.swizzles());

            textureName.position(Texture.TEXTURE);
            gl4.glCreateTextures(GL_TEXTURE_2D, 1, textureName);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_SWIZZLE_R, swizzles.r.value);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_SWIZZLE_G, swizzles.g.value);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_SWIZZLE_B, swizzles.b.value);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_SWIZZLE_A, swizzles.a.value);

            gl4.glTextureStorage2D(textureName.get(Texture.TEXTURE), texture.levels(), format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1]);

            for (int level = 0; level < texture.levels(); ++level) {
                gl4.glTextureSubImage2D(textureName.get(Texture.TEXTURE),
                        level,
                        0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            textureName.position(Texture.MULTISAMPLE);
            gl4.glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, textureName);
            gl4.glTextureParameteri(textureName.get(Texture.MULTISAMPLE), GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(Texture.MULTISAMPLE), GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTextureStorage2DMultisample(textureName.get(Texture.MULTISAMPLE), 4, GL_RGBA8, FRAMEBUFFER_SIZE.x,
                    FRAMEBUFFER_SIZE.y, false);

            textureName.position(Texture.COLORBUFFER);
            gl4.glCreateTextures(GL_TEXTURE_2D, 1, textureName);
            gl4.glTextureParameteri(textureName.get(Texture.COLORBUFFER), GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(Texture.COLORBUFFER), GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTextureStorage2D(textureName.get(Texture.COLORBUFFER), 1, GL_RGBA8, FRAMEBUFFER_SIZE.x,
                    FRAMEBUFFER_SIZE.y);

            textureName.rewind();

        } catch (IOException ex) {
            Logger.getLogger(Gl_430_direct_state_access_ext.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }
 
Example 3
Source File: Gl_450_direct_state_access.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));
            if (texture.empty()) {
                return false;
            }

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

            textureName.position(Texture.TEXTURE);
            gl4.glCreateTextures(GL_TEXTURE_2D, 1, textureName);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            gl4.glTextureStorage2D(textureName.get(Texture.TEXTURE), texture.levels(), format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1]);
            for (int level = 0; level < texture.levels(); ++level) {
                gl4.glTextureSubImage2D(textureName.get(Texture.TEXTURE), level,
                        0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        format.external.value, format.type.value,
                        texture.data(level));
            }
        } catch (IOException ex) {
            Logger.getLogger(Gl_450_direct_state_access.class.getName()).log(Level.SEVERE, null, ex);
        }

        textureName.position(Texture.MULTISAMPLE);
        gl4.glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, textureName);
        gl4.glTextureParameteri(textureName.get(Texture.MULTISAMPLE), GL_TEXTURE_BASE_LEVEL, 0);
        gl4.glTextureParameteri(textureName.get(Texture.MULTISAMPLE), GL_TEXTURE_MAX_LEVEL, 0);
        gl4.glTextureStorage2DMultisample(textureName.get(Texture.MULTISAMPLE), 4, GL_RGBA8, FRAMEBUFFER_SIZE.x,
                FRAMEBUFFER_SIZE.y, false);

        textureName.position(Texture.COLORBUFFER);
        gl4.glCreateTextures(GL_TEXTURE_2D, 1, textureName);
        gl4.glTextureParameteri(textureName.get(Texture.COLORBUFFER), GL_TEXTURE_BASE_LEVEL, 0);
        gl4.glTextureParameteri(textureName.get(Texture.COLORBUFFER), GL_TEXTURE_MAX_LEVEL, 0);
        gl4.glTextureStorage2D(textureName.get(Texture.COLORBUFFER), 1, GL_RGBA8, FRAMEBUFFER_SIZE.x,
                FRAMEBUFFER_SIZE.y);

        textureName.rewind();

        return true;
    }
 
Example 4
Source File: Gl_500_direct_state_access_gtc.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));
            if (texture.empty()) {
                return false;
            }

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

            textureName.position(Texture.TEXTURE);
            gl4.glCreateTextures(GL_TEXTURE_2D, 1, textureName);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            gl4.glTextureParameteri(textureName.get(Texture.TEXTURE), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            gl4.glTextureStorage2D(textureName.get(Texture.TEXTURE), texture.levels(), format.internal.value,
                    texture.dimensions(0)[0], texture.dimensions(0)[1]);
            for (int level = 0; level < texture.levels(); ++level) {
                gl4.glTextureSubImage2D(textureName.get(Texture.TEXTURE), level,
                        0, 0,
                        texture.dimensions(level)[0], texture.dimensions(level)[1],
                        format.external.value, format.type.value,
                        texture.data(level));
            }

            textureName.position(Texture.MULTISAMPLE);
            gl4.glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, textureName);
            gl4.glTextureParameteri(textureName.get(Texture.MULTISAMPLE), GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(Texture.MULTISAMPLE), GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTextureStorage2DMultisample(textureName.get(Texture.MULTISAMPLE), 4, GL_RGBA8, FRAMEBUFFER_SIZE.x,
                    FRAMEBUFFER_SIZE.y, false);

            textureName.position(Texture.COLORBUFFER);
            gl4.glCreateTextures(GL_TEXTURE_2D, 1, textureName);
            gl4.glTextureParameteri(textureName.get(Texture.COLORBUFFER), GL_TEXTURE_BASE_LEVEL, 0);
            gl4.glTextureParameteri(textureName.get(Texture.COLORBUFFER), GL_TEXTURE_MAX_LEVEL, 0);
            gl4.glTextureStorage2D(textureName.get(Texture.COLORBUFFER), 1, GL_RGBA8, FRAMEBUFFER_SIZE.x,
                    FRAMEBUFFER_SIZE.y);

            textureName.rewind();

        } catch (IOException ex) {
            Logger.getLogger(Gl_500_direct_state_access_gtc.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }