javax.media.opengl.GL Java Examples

The following examples show how to use javax.media.opengl.GL. 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: JoglHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public JoglHelper(){
	//TODO: get the current GL and choose the best fitted delegate depending on the hardware (Desktop, Embedded)
    GL gl = GLContext.getCurrentGL();
	if(gl.isGL2ES1()){
		//embedded fixed pipeline
	}
	else{
		if(gl.isGL2ES2()){
			//embedded shader-based
		}
		else{
			if(gl.isGL3()&&!gl.isGL3bc()||gl.isGL4()&&!gl.isGL4bc()){
				//desktop shader-based (forward compatible)
			}
			else{
				//if GLSL is supported, use desktop shader-based (backward compatible)
				//otherwise use desktop fixed pipeline
			}
		}
	}
}
 
Example #2
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void deleteShader(Shader shader) {
    if (glslVer != -1) {
        if (shader.getId() == -1) {
            logger.warning("Shader is not uploaded to GPU, cannot delete.");
            return;
        }
        GL gl = GLContext.getCurrentGL();
        for (ShaderSource source : shader.getSources()) {
            if (source.getId() != -1) {
                gl.getGL2().glDetachShader(shader.getId(), source.getId());
                // the next part is done by the GLObjectManager automatically
                // glDeleteShader(source.getId());
            }
        }
        // kill all references so sources can be collected
        // if needed.
        shader.resetSources();
        gl.getGL2().glDeleteProgram(shader.getId());

        statistics.onDeleteShader();
    }
}
 
Example #3
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) {
    boolean needAttach;
    if (rb.getTexture() == null) {
        // if it hasn't been created yet, then attach is required.
        needAttach = rb.getId() == -1;
        updateRenderBuffer(fb, rb);
    }
    else {
        needAttach = false;
        updateRenderTexture(fb, rb);
    }
    if (needAttach) {
        GL gl = GLContext.getCurrentGL();
        gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, convertAttachmentSlot(rb.getSlot()),
                GL.GL_RENDERBUFFER, rb.getId());
    }
}
 
Example #4
Source File: TextureUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static int convertTextureFormat(Format fmt){
    switch (fmt){
        case Alpha16:
        case Alpha8:
            return GL.GL_ALPHA;
        case Luminance8Alpha8:
        case Luminance16Alpha16:
            return GL.GL_LUMINANCE_ALPHA;
        case Luminance8:
        case Luminance16:
            return GL.GL_LUMINANCE;
        case RGB10:
        case RGB16:
        case BGR8:
        case RGB8:
        case RGB565:
            return GL.GL_RGB;
        case RGB5A1:
        case RGBA16:
        case RGBA8:
            return GL.GL_RGBA;
        default:
            throw new UnsupportedOperationException("Unrecognized format: "+fmt);
    }
}
 
Example #5
Source File: BloomOpenGL.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void renderBlur(GL gl, float width, float height) {
    // Draw into the FBO
    gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBufferObject2);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    enableBlurFragmentProgram(gl, blurShader, width, height);
    gl.glBindTexture(GL.GL_TEXTURE_2D, frameBufferTexture1);

    renderTexturedQuad(gl, width, height, texture.getMustFlipVertically());

    gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
    disableFragmentProgram(gl);

    gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
}
 
Example #6
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) {
    GL gl = GLContext.getCurrentGL();
    if (fb != null) {
        RenderBuffer rb = fb.getColorBuffer();
        if (rb == null) {
            throw new IllegalArgumentException("Specified framebuffer"
                    + " does not have a colorbuffer");
        }
        setFrameBuffer(fb);
        if (context.boundReadBuf != rb.getSlot()) {
            gl.getGL2().glReadBuffer(GL.GL_COLOR_ATTACHMENT0 + rb.getSlot());
            context.boundReadBuf = rb.getSlot();
        }
    }
    else {
        setFrameBuffer(null);
    }
    gl.glReadPixels(vpX, vpY, vpW, vpH, GL2GL3.GL_BGRA, GL.GL_UNSIGNED_BYTE, byteBuf);
}
 
Example #7
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int convertMinFilter(Texture.MinFilter filter) {
    switch (filter) {
        case Trilinear:
            return GL.GL_LINEAR_MIPMAP_LINEAR;
        case BilinearNearestMipMap:
            return GL.GL_LINEAR_MIPMAP_NEAREST;
        case NearestLinearMipMap:
            return GL.GL_NEAREST_MIPMAP_LINEAR;
        case NearestNearestMipMap:
            return GL.GL_NEAREST_MIPMAP_NEAREST;
        case BilinearNoMipMaps:
            return GL.GL_LINEAR;
        case NearestNoMipMaps:
            return GL.GL_NEAREST;
        default:
            throw new UnsupportedOperationException("Unknown min filter: " + filter);
    }
}
 
Example #8
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int convertWrapMode(Texture.WrapMode mode) {
    switch (mode) {
        case BorderClamp:
            return GL2GL3.GL_CLAMP_TO_BORDER;
        case Clamp:
            return GL2.GL_CLAMP;
        case EdgeClamp:
            return GL.GL_CLAMP_TO_EDGE;
        case Repeat:
            return GL.GL_REPEAT;
        case MirroredRepeat:
            return GL.GL_MIRRORED_REPEAT;
        default:
            throw new UnsupportedOperationException("Unknown wrap mode: " + mode);
    }
}
 
Example #9
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected int convertFormat(Format format) {
    switch (format) {
        case Byte:
            return GL.GL_BYTE;
        case UnsignedByte:
            return GL.GL_UNSIGNED_BYTE;
        case Short:
            return GL.GL_SHORT;
        case UnsignedShort:
            return GL.GL_UNSIGNED_SHORT;
        case Int:
            return GL2ES2.GL_INT;
        case UnsignedInt:
            return GL2ES2.GL_UNSIGNED_INT;
        case Half:
            return GL.GL_HALF_FLOAT;
        case Float:
            return GL.GL_FLOAT;
        case Double:
            return GL2GL3.GL_DOUBLE;
        default:
            throw new RuntimeException("Unknown buffer format.");

    }
}
 
Example #10
Source File: BloomOpenGL.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void display(GLAutoDrawable glAutoDrawable) {
    GL gl = glAutoDrawable.getGL();
    gl.glLoadIdentity(); 
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    viewOrtho(gl, image.getWidth(), image.getHeight());
    gl.glEnable(GL.GL_TEXTURE_2D);

    int width = image.getWidth();
    int height = image.getHeight();

    // Source Image/bright pass on FBO1
    renderBrightPass(gl, width, height);
    // Source image on FBO2
    renderImage(gl, width, height);
    // On screen
    renderTextureOnScreen(gl, width, height);

    //render5x5(gl, width, height);
    render11x11(gl, width, height);
    render21x21(gl, width, height);
    render41x41(gl, width, height);

    gl.glDisable(GL.GL_TEXTURE_2D);
    gl.glFlush();
}
 
Example #11
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected int convertVertexFormat(VertexBuffer.Format fmt) {
    switch (fmt) {
        case Byte:
            return GL.GL_BYTE;
        case Double:
            return GL2GL3.GL_DOUBLE;
        case Float:
            return GL.GL_FLOAT;
        case Half:
            return GL.GL_HALF_FLOAT;
        case Int:
            return GL2ES2.GL_INT;
        case Short:
            return GL.GL_SHORT;
        case UnsignedByte:
            return GL.GL_UNSIGNED_BYTE;
        case UnsignedInt:
            return GL2ES2.GL_UNSIGNED_INT;
        case UnsignedShort:
            return GL.GL_UNSIGNED_SHORT;
        default:
            throw new UnsupportedOperationException("Unrecognized vertex format: " + fmt);
    }
}
 
Example #12
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected int convertElementMode(Mesh.Mode mode) {
    switch (mode) {
        case Points:
            return GL.GL_POINTS;
        case Lines:
            return GL.GL_LINES;
        case LineLoop:
            return GL.GL_LINE_LOOP;
        case LineStrip:
            return GL.GL_LINE_STRIP;
        case Triangles:
            return GL.GL_TRIANGLES;
        case TriangleFan:
            return GL.GL_TRIANGLE_FAN;
        case TriangleStrip:
            return GL.GL_TRIANGLE_STRIP;
        default:
            throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode);
    }
}
 
Example #13
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void updateDisplayList(Mesh mesh) {
    GL gl = GLContext.getCurrentGL();
    if (mesh.getId() != -1) {
        // delete list first
        gl.getGL2().glDeleteLists(mesh.getId(), mesh.getId());
        mesh.setId(-1);
    }

    // create new display list
    // first set state to NULL
    applyRenderState(RenderState.NULL);

    // disable lighting
    setLighting(null);

    int id = gl.getGL2().glGenLists(1);
    mesh.setId(id);
    gl.getGL2().glNewList(id, GL2.GL_COMPILE);
    renderMeshDefault(mesh, 0, 1);
    gl.getGL2().glEndList();
}
 
Example #14
Source File: BloomOpenGL.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void renderTexturedQuad(GL gl, float width, float height,
                                       boolean flip) {
    gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2f(0.0f, flip ? 1.0f : 0.0f);
        gl.glVertex2f(0.0f, 0.0f);

        gl.glTexCoord2f(1.0f, flip ? 1.0f : 0.0f);
        gl.glVertex2f(width, 0.0f);

        gl.glTexCoord2f(1.0f, flip ? 0.0f : 1.0f);
        gl.glVertex2f(width, height);

        gl.glTexCoord2f(0.0f, flip ? 0.0f : 1.0f);
        gl.glVertex2f(0.0f, height);
    gl.glEnd();
}
 
Example #15
Source File: BloomOpenGL.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void createFrameBufferObject(GL gl, int[] frameBuffer,
                                            int[] colorBuffer, int width,
                                            int height) {
    gl.glGenFramebuffersEXT(1, frameBuffer, 0);
    gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBuffer[0]);

    gl.glGenTextures(1, colorBuffer, 0);
    gl.glBindTexture(GL.GL_TEXTURE_2D, colorBuffer[0]);
    gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA,
                    width, height,
                    0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
                    BufferUtil.newByteBuffer(width * height * 4));
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT,
                                 GL.GL_COLOR_ATTACHMENT0_EXT,
                                 GL.GL_TEXTURE_2D, colorBuffer[0], 0);
    gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

    int status = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT);
    if (status == GL.GL_FRAMEBUFFER_COMPLETE_EXT) {
        gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
    } else {
        throw new IllegalStateException("Frame Buffer Oject not created.");
    }
}
 
Example #16
Source File: Env.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check current graphic card/drivers OpenGL capabilities to see if they match those required by WorldWind to work
 * @return true if we are good, false otherwise
 */
public boolean isOpenGLAvailable() {
	if (_openGlAvailable == null) {
		synchronized (this) {
			if (_openGlAvailable == null) {
				try {
					// create an offscreen context with the current graphic device
					final GLProfile glProfile = GLProfile.getDefault(GLProfile.getDefaultDevice());
					final GLCapabilities caps = new GLCapabilities(glProfile);
					caps.setOnscreen(false);
					caps.setPBuffer(false);
					final GLDrawable offscreenDrawable = GLDrawableFactory.getFactory(glProfile).createOffscreenDrawable(null, caps,
							new DefaultGLCapabilitiesChooser(), 1, 1);
					offscreenDrawable.setRealized(true);
					final GLContext context = offscreenDrawable.createContext(null);
					final int additionalCtxCreationFlags = 0;
					context.setContextCreationFlags(additionalCtxCreationFlags);
					context.makeCurrent();
					final GL gl = context.getGL();
					// WWJ will need those to render the globe
					_openGlAvailable = gl.isExtensionAvailable(GLExtensions.EXT_texture_compression_s3tc)
							|| gl.isExtensionAvailable(GLExtensions.NV_texture_compression_vtc);
				} catch (final Throwable e) {
					_openGlAvailable = false;
				}
			}
		}
	}
	return _openGlAvailable;
}
 
Example #17
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateBufferData(VertexBuffer vb) {
    GL gl = GLContext.getCurrentGL();
    int bufId = vb.getId();
    if (bufId == -1) {
        // create buffer
        gl.glGenBuffers(1, intBuf1);
        bufId = intBuf1.get(0);
        vb.setId(bufId);
        objManager.registerForCleanup(vb);
    }

    int target;
    if (vb.getBufferType() == VertexBuffer.Type.Index) {
        target = GL.GL_ELEMENT_ARRAY_BUFFER;
        if (context.boundElementArrayVBO != bufId) {
            gl.glBindBuffer(target, bufId);
            context.boundElementArrayVBO = bufId;
        }
    }
    else {
        target = GL.GL_ARRAY_BUFFER;
        if (context.boundArrayVBO != bufId) {
            gl.glBindBuffer(target, bufId);
            context.boundArrayVBO = bufId;
        }
    }

    int usage = convertUsage(vb.getUsage());
    Buffer data = vb.getData();
    data.rewind();

    gl.glBufferData(target, data.capacity() * vb.getFormat().getComponentSize(), data, usage);

    vb.clearUpdateNeeded();
}
 
Example #18
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected boolean isShaderValid(Shader shader) {
    GL gl = GLContext.getCurrentGL();
    gl.getGL2().glValidateProgram(shader.getId());
    gl.getGL2().glGetProgramiv(shader.getId(), GL2ES2.GL_VALIDATE_STATUS, intBuf1);
    return intBuf1.get(0) == GL.GL_TRUE;
}
 
Example #19
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0,
        int dstY0, int dstX1, int dstY1, int mask, int filter) {
    GL gl = GLContext.getCurrentGL();
    gl.getGL2().glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask,
            filter);
}
 
Example #20
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int convertAttachmentSlot(int attachmentSlot) {
    // can also add support for stencil here
    if (attachmentSlot == -100) {
        return GL.GL_DEPTH_ATTACHMENT;
    }
    else if (attachmentSlot < 0 || attachmentSlot >= 16) {
        throw new UnsupportedOperationException("Invalid FBO attachment slot: "
                + attachmentSlot);
    }

    return GL.GL_COLOR_ATTACHMENT0 + attachmentSlot;
}
 
Example #21
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
    GL gl = GLContext.getCurrentGL();
    Texture tex = rb.getTexture();
    if (tex.isUpdateNeeded()) {
        updateTextureData(tex);
    }

    gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, convertAttachmentSlot(rb.getSlot()),
            convertTextureType(tex.getType()), tex.getId(), 0);
}
 
Example #22
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void checkFrameBufferError() {
    GL gl = GLContext.getCurrentGL();
    int status = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER);
    switch (status) {
        case GL.GL_FRAMEBUFFER_COMPLETE:
            break;
        case GL.GL_FRAMEBUFFER_UNSUPPORTED:
            // Choose different formats
            throw new IllegalStateException("Framebuffer object format is "
                    + "unsupported by the video hardware.");
        case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
            throw new IllegalStateException("Framebuffer has erronous attachment.");
        case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
            throw new IllegalStateException("Framebuffer is missing required attachment.");
        case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
            throw new IllegalStateException(
                    "Framebuffer attachments must have same dimensions.");
        case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
            throw new IllegalStateException("Framebuffer attachments must have same formats.");
        case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
            throw new IllegalStateException("Incomplete draw buffer.");
        case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
            throw new IllegalStateException("Incomplete read buffer.");
        case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
            throw new IllegalStateException("Incomplete multisample buffer.");
        default:
            // Programming error; will fail on all hardware
            throw new IllegalStateException("Some video driver error "
                    + "or programming error occured. "
                    + "Framebuffer object status is invalid. ");
    }
}
 
Example #23
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void renderMesh(Mesh mesh, int lod, int count) {
    GL gl = GLContext.getCurrentGL();
    if (context.pointSize != mesh.getPointSize()) {
        gl.getGL2().glPointSize(mesh.getPointSize());
        context.pointSize = mesh.getPointSize();
    }
    if (context.lineWidth != mesh.getLineWidth()) {
        gl.glLineWidth(mesh.getLineWidth());
        context.lineWidth = mesh.getLineWidth();
    }

    checkTexturingUsed();

    if (vbo) {
        renderMeshVBO(mesh, lod, count);
    }
    else {
        boolean dynamic = false;
        if (mesh.getNumLodLevels() == 0) {
            IntMap<VertexBuffer> bufs = mesh.getBuffers();
            for (Entry<VertexBuffer> entry : bufs) {
                if (entry.getValue().getUsage() != VertexBuffer.Usage.Static) {
                    dynamic = true;
                    break;
                }
            }
        }
        else {
            dynamic = true;
        }

        if (!dynamic) {
            // dealing with a static object, generate display list
            renderMeshDisplayList(mesh);
        }
        else {
            renderMeshDefault(mesh, lod, count);
        }
    }
}
 
Example #24
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void updateRenderBuffer(FrameBuffer fb, RenderBuffer rb) {
    GL gl = GLContext.getCurrentGL();
    int id = rb.getId();
    if (id == -1) {
        gl.glGenRenderbuffers(1, intBuf1);
        id = intBuf1.get(0);
        rb.setId(id);
    }

    if (context.boundRB != id) {
        gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, id);
        context.boundRB = id;
    }

    if (fb.getWidth() > maxRBSize || fb.getHeight() > maxRBSize) {
        throw new UnsupportedOperationException("Resolution " + fb.getWidth() + ":"
                + fb.getHeight() + " is not supported.");
    }

    if (fb.getSamples() > 0 && renderbufferStorageMultisample) {
        int samples = fb.getSamples();
        if (maxFBOSamples < samples) {
            samples = maxFBOSamples;
        }
        gl.getGL2()
                .glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, samples,
                        TextureUtil.convertTextureFormat(rb.getFormat()), fb.getWidth(),
                        fb.getHeight());
    }
    else {
        gl.glRenderbufferStorage(GL.GL_RENDERBUFFER,
                TextureUtil.convertTextureFormat(rb.getFormat()), fb.getWidth(), fb.getHeight());
    }
}
 
Example #25
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected int convertTextureType(Texture.Type type) {
    switch (type) {
        case TwoDimensional:
            return GL.GL_TEXTURE_2D;
        case TwoDimensionalArray:
            return GL.GL_TEXTURE_2D_ARRAY;
        case ThreeDimensional:
            return GL2GL3.GL_TEXTURE_3D;
        case CubeMap:
            return GL.GL_TEXTURE_CUBE_MAP;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + type);
    }
}
 
Example #26
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void checkTexturingUsed() {
    IDList textureList = context.textureIndexList;
    GL gl = GLContext.getCurrentGL();
    // old mesh used texturing, new mesh doesn't use it
    // should actually go through entire oldLen and
    // disable texturing for each unit.. but that's for later.
    if (textureList.oldLen > 0 && textureList.newLen == 0) {
        gl.glDisable(GL.GL_TEXTURE_2D);
    }
}
 
Example #27
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int convertUsage(Usage usage) {
    switch (usage) {
        case Static:
            return GL.GL_STATIC_DRAW;
        case Dynamic:
            return GL.GL_DYNAMIC_DRAW;
        case Stream:
            return GL2ES2.GL_STREAM_DRAW;
        default:
            throw new RuntimeException("Unknown usage type: " + usage);
    }
}
 
Example #28
Source File: BloomOpenGL.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void renderImage(GL gl, float width, float height) {
    // Draw into the FBO
    gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBufferObject2);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    gl.glBindTexture(GL.GL_TEXTURE_2D, texture.getTextureObject());
    renderTexturedQuad(gl, width, height, texture.getMustFlipVertically());
    gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

    gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
}
 
Example #29
Source File: BloomOpenGL.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void init(GLAutoDrawable glAutoDrawable) {
    GL gl = glAutoDrawable.getGL();

    if (texture == null) {
        texture = TextureIO.newTexture(image, false);
    }

    // create the blur shader
    blurShader = createFragmentProgram(gl, new String[] { blurShaderSource });
    gl.glUseProgramObjectARB(blurShader);
    int loc = gl.glGetUniformLocationARB(blurShader, "baseImage");
    gl.glUniform1iARB(loc, 0);
    gl.glUseProgramObjectARB(0);

    // create the bright-pass shader
    brightPassShader = createFragmentProgram(gl, new String[] { brightPassShaderSource });
    gl.glUseProgramObjectARB(brightPassShader);
    loc = gl.glGetUniformLocationARB(brightPassShader, "baseImage");
    gl.glUniform1iARB(loc, 0);
    gl.glUseProgramObjectARB(0);

    // create the FBOs
    if (gl.isExtensionAvailable("GL_EXT_framebuffer_object")) {
        int[] fboId = new int[1];
        int[] texId = new int[1];

        createFrameBufferObject(gl, fboId, texId,
                                image.getWidth(), image.getHeight());
        frameBufferObject1 = fboId[0];
        frameBufferTexture1 = texId[0];

        createFrameBufferObject(gl, fboId, texId,
                                image.getWidth(), image.getHeight());
        frameBufferObject2 = fboId[0];
        frameBufferTexture2 = texId[0];
    }
}
 
Example #30
Source File: BloomOpenGL.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void viewOrtho(GL gl, int width, int height) {
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glOrtho(0, width, height, 0, -1, 1);
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
}