Example usage for org.lwjgl.opengl GL11 GL_NONE

List of usage examples for org.lwjgl.opengl GL11 GL_NONE

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 GL_NONE.

Prototype

int GL_NONE

To view the source code for org.lwjgl.opengl GL11 GL_NONE.

Click Source Link

Document

DrawBufferMode

Usage

From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java

License:Open Source License

private void render(final List<? extends Spatial> toDrawA, final Spatial toDrawB, final Scene toDrawC,
        final List<Texture> texs, final int clear) {

    final int maxDrawBuffers = ContextManager.getCurrentContext().getCapabilities().getMaxFBOColorAttachments();

    // if we only support 1 draw buffer at a time anyway, we'll have to render to each texture individually...
    if (maxDrawBuffers == 1 || texs.size() == 1) {
        try {/*from  ww  w .j ava  2s .co  m*/
            ContextManager.getCurrentContext().pushFBOTextureRenderer(this);

            for (int i = 0; i < texs.size(); i++) {
                final Texture tex = texs.get(i);

                setupForSingleTexDraw(tex);

                if (_samples > 0 && _supportsMultisample) {
                    setMSFBO();
                }

                switchCameraIn(clear);
                if (toDrawA != null) {
                    doDraw(toDrawA);
                } else if (toDrawB != null) {
                    doDraw(toDrawB);
                } else {
                    doDraw(toDrawC);
                }
                switchCameraOut();

                if (_samples > 0 && _supportsMultisample) {
                    blitMSFBO();
                }

                takedownForSingleTexDraw(tex);
            }
        } finally {
            ContextManager.getCurrentContext().popFBOTextureRenderer();
        }
        return;
    }
    try {
        ContextManager.getCurrentContext().pushFBOTextureRenderer(this);

        // Otherwise, we can streamline this by rendering to multiple textures at once.
        // first determine how many groups we need
        final LinkedList<Texture> depths = new LinkedList<Texture>();
        final LinkedList<Texture> colors = new LinkedList<Texture>();
        for (int i = 0; i < texs.size(); i++) {
            final Texture tex = texs.get(i);
            if (tex.getTextureStoreFormat().isDepthFormat()) {
                depths.add(tex);
            } else {
                colors.add(tex);
            }
        }
        // we can only render to 1 depth texture at a time, so # groups is at minimum == numDepth
        final int groups = Math.max(depths.size(), (int) Math.ceil(colors.size() / (float) maxDrawBuffers));

        final RenderContext context = ContextManager.getCurrentContext();
        for (int i = 0; i < groups; i++) {
            // First handle colors
            int colorsAdded = 0;
            while (colorsAdded < maxDrawBuffers && !colors.isEmpty()) {
                final Texture tex = colors.removeFirst();
                if (tex.getType() == Type.TwoDimensional) {
                    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                            EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT + colorsAdded, GL11.GL_TEXTURE_2D,
                            tex.getTextureIdForContext(context.getGlContextRep()), 0);
                } else if (tex.getType() == Type.CubeMap) {
                    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                            EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT + colorsAdded,
                            LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()),
                            tex.getTextureIdForContext(context.getGlContextRep()), 0);
                } else {
                    throw new IllegalArgumentException("Invalid texture type: " + tex.getType());
                }
                colorsAdded++;
            }

            // Now take care of depth.
            if (!depths.isEmpty()) {
                final Texture tex = depths.removeFirst();
                // Set up our depth texture
                if (tex.getType() == Type.TwoDimensional) {
                    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                            EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D,
                            tex.getTextureIdForContext(context.getGlContextRep()), 0);
                } else if (tex.getType() == Type.CubeMap) {
                    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                            EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT,
                            LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()),
                            tex.getTextureIdForContext(context.getGlContextRep()), 0);
                } else {
                    throw new IllegalArgumentException("Invalid texture type: " + tex.getType());
                }
                _usingDepthRB = false;
            } else if (!_usingDepthRB) {
                // setup our default depth render buffer if not already set
                EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                        EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                        _depthRBID);
                _usingDepthRB = true;
            }

            setDrawBuffers(colorsAdded);
            setReadBuffer(colorsAdded != 0 ? EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT : GL11.GL_NONE);

            // Check FBO complete
            checkFBOComplete(_fboID);

            switchCameraIn(clear);

            if (toDrawA != null) {
                doDraw(toDrawA);
            } else {
                doDraw(toDrawB);
            }

            switchCameraOut();
        }

        // automatically generate mipmaps for our textures.
        for (int x = 0, max = texs.size(); x < max; x++) {
            if (texs.get(x).getMinificationFilter().usesMipMapLevels()) {
                final Texture tex = texs.get(x);
                if (tex.getMinificationFilter().usesMipMapLevels()) {
                    LwjglTextureStateUtil.doTextureBind(texs.get(x), 0, true);
                    EXTFramebufferObject.glGenerateMipmapEXT(LwjglTextureStateUtil.getGLType(tex.getType()));
                }
            }
        }

    } finally {
        ContextManager.getCurrentContext().popFBOTextureRenderer();
    }
}

From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java

License:Open Source License

@Override
protected void setupForSingleTexDraw(final Texture tex) {
    final RenderContext context = ContextManager.getCurrentContext();
    final int textureId = tex.getTextureIdForContext(context.getGlContextRep());

    if (tex.getTextureStoreFormat().isDepthFormat()) {
        // No color buffer
        EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);

        // Setup depth texture into FBO
        if (tex.getType() == Type.TwoDimensional) {
            EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                    EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, GL11.GL_TEXTURE_2D, textureId, 0);
        } else if (tex.getType() == Type.CubeMap) {
            EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                    EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT,
                    LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()),
                    textureId, 0);/* www .j  a  v  a  2s . co m*/
        } else {
            throw new IllegalArgumentException("Can not render to texture of type: " + tex.getType());
        }

        setDrawBuffer(GL11.GL_NONE);
        setReadBuffer(GL11.GL_NONE);
    } else {
        // Set color texture into FBO
        if (tex.getType() == Type.TwoDimensional) {
            EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                    EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, textureId, 0);
        } else if (tex.getType() == Type.CubeMap) {
            EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                    EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT,
                    LwjglTextureStateUtil.getGLCubeMapFace(((TextureCubeMap) tex).getCurrentRTTFace()),
                    textureId, 0);
        } else {
            throw new IllegalArgumentException("Can not render to texture of type: " + tex.getType());
        }

        // setup depth RB
        EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                _depthRBID);

        setDrawBuffer(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT);
        setReadBuffer(EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT);
    }

    // Check FBO complete
    checkFBOComplete(_fboID);
}

From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java

License:Open Source License

private void setDrawBuffers(final int maxEntry) {
    if (maxEntry <= 1) {
        setDrawBuffer(maxEntry != 0 ? EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT : GL11.GL_NONE);
    } else {/*from ww w. j  a  v  a  2s .c  o  m*/
        // We should only get to this point if we support ARBDrawBuffers.
        _attachBuffer.clear();
        _attachBuffer.limit(maxEntry);
        ARBDrawBuffers.glDrawBuffersARB(_attachBuffer);
    }
}

From source file:com.ardor3d.scene.state.lwjgl.LwjglMaterialStateUtil.java

License:Open Source License

/**
 * Converts the color material setting of this state to a GL constant.
 * //  ww w .j a  v a 2 s .c  om
 * @return the GL constant
 */
private static int getGLColorMaterial(final ColorMaterial material) {
    switch (material) {
    case None:
        return GL11.GL_NONE;
    case Ambient:
        return GL11.GL_AMBIENT;
    case Diffuse:
        return GL11.GL_DIFFUSE;
    case AmbientAndDiffuse:
        return GL11.GL_AMBIENT_AND_DIFFUSE;
    case Emissive:
        return GL11.GL_EMISSION;
    case Specular:
        return GL11.GL_SPECULAR;
    }
    throw new IllegalArgumentException("invalid color material setting: " + material);
}

From source file:com.ardor3d.scene.state.lwjgl.util.LwjglTextureUtil.java

License:Open Source License

public static int getGLDepthTextureCompareMode(final DepthTextureCompareMode mode) {
    switch (mode) {
    case RtoTexture:
        return ARBShadow.GL_COMPARE_R_TO_TEXTURE_ARB;
    case None://from ww  w .  ja  va2s. c o m
    default:
        return GL11.GL_NONE;
    }
}

From source file:com.flowpowered.caustic.lwjgl.gl20.GL20FrameBuffer.java

License:MIT License

@Override
public void create() {
    checkNotCreated();// w ww.  j av  a  2  s .  co m
    // Generate and bind the frame buffer
    id = EXTFramebufferObject.glGenFramebuffersEXT();
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, id);
    // Disable input buffers
    GL11.glReadBuffer(GL11.GL_NONE);
    // Unbind the frame buffer
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
    // Update the state
    super.create();
    // Check for errors
    LWJGLUtil.checkForGLError();
}

From source file:com.flowpowered.caustic.lwjgl.gl20.GL20FrameBuffer.java

License:MIT License

private void updateOutputBuffers() {
    // Set the output to the proper buffers
    if (outputBuffers.isEmpty()) {
        // No color to output
        GL20.glDrawBuffers(GL11.GL_NONE);
    } else {//  www. j a v  a  2 s. co m
        // Keep track of the buffers to output
        final int[] outputBuffersArray = outputBuffers.toArray();
        // Sorting the array ensures that attachments are in order n, n + 1, n + 2...
        // This is important!
        Arrays.sort(outputBuffersArray);
        final IntBuffer buffer = CausticUtil.createIntBuffer(outputBuffers.size());
        buffer.put(outputBuffersArray);
        buffer.flip();
        GL20.glDrawBuffers(buffer);
    }
}

From source file:com.flowpowered.caustic.lwjgl.gl30.GL30FrameBuffer.java

License:MIT License

@Override
public void create() {
    checkNotCreated();//from   w w w. j ava2s .c  om
    // Generate and bind the frame buffer
    id = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, id);
    // Disable input buffers
    GL11.glReadBuffer(GL11.GL_NONE);
    // Unbind the frame buffer
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    // Update the state
    super.create();
    // Check for errors
    LWJGLUtil.checkForGLError();
}

From source file:com.grillecube.engine.renderer.world.WorldRenderer.java

private void createShadowFBO() {

    this._shadow_fbo = GLH.glhGenFBO();
    this._shadow_fbo.bind();
    this._shadow_fbo.createDrawBuffer(GL11.GL_NONE);

    this._shadow_map = GLH.glhGenTexture();
    this._shadow_map.bind(GL11.GL_TEXTURE_2D);

    this._shadow_map.image2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16, SHADOW_FBO_WIDTH,
            SHADOW_FBO_HEIGHT, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null);
    this._shadow_map.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    this._shadow_map.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    this._shadow_map.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    this._shadow_map.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    this._shadow_fbo.createTextureAttachment(this._shadow_map, GL30.GL_DEPTH_ATTACHMENT);

    this._shadow_fbo.unbind();
}

From source file:com.opengrave.og.light.Depth2DFramebuffer.java

License:Open Source License

public Depth2DFramebuffer(int size) {
    framebufferSize = size;/*from ww w  . j av a 2  s  .c  o  m*/
    framebuffer = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
    shadowMap = new Texture2DShadowMap(framebufferSize);

    shadowMap.bindToFrameBuffer();

    // GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0);
    GL11.glDrawBuffer(GL11.GL_NONE);
    Util.checkErr();
    GL11.glReadBuffer(GL11.GL_NONE);
    int i = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);
    if (i != GL30.GL_FRAMEBUFFER_COMPLETE) {
        throw new RuntimeException("Framebuffer creation failed with code: " + i);
    }
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

    // TESTING STUFF
    count = 2;
    FloatBuffer pos = BufferUtils.createFloatBuffer(3 * 3 * count);
    FloatBuffer tex = BufferUtils.createFloatBuffer(2 * 3 * count);
    pos.put(0.75f).put(0.75f).put(0f);
    pos.put(0.75f).put(0.25f).put(0f);
    pos.put(0.25f).put(0.75f).put(0f);
    pos.put(0.25f).put(0.25f).put(0f);

    pos.put(0.75f).put(0.25f).put(0f);
    pos.put(0.25f).put(0.75f).put(0f);
    pos.flip();
    tex.put(1f).put(1f);
    tex.put(1f).put(0f);
    tex.put(0f).put(1f);
    tex.put(0f).put(0f);
    tex.put(1f).put(0f);

    tex.put(0f).put(1f);
    tex.flip();
    vao_ID = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vao_ID);
    int vbo_pos_ID = GL15.glGenBuffers();
    int vbo_tex_ID = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_pos_ID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, pos, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_tex_ID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tex, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 0, 0);
}