org.lwjgl.opengl.Pbuffer Java Examples

The following examples show how to use org.lwjgl.opengl.Pbuffer. 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: PbufferRenderer.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
PbufferRenderer(int width, int height, PixelFormat format, boolean use_copyteximage, OffscreenRendererFactory factory) throws LWJGLException {
	super(width, height, use_copyteximage);
	this.factory = factory;
	pbuffer = new Pbuffer(width, height, format, null, null);
	GLStateStack state_stack = new GLStateStack();
	pbuffer.makeCurrent();
	GLStateStack.setCurrent(state_stack);
	try {
		pbuffer.makeCurrent();
		Renderer.dumpWindowInfo();
		init();
		if (!GLUtils.getGLBoolean(GL11.GL_DOUBLEBUFFER)) {
			GL11.glReadBuffer(GL11.GL_FRONT);
			GL11.glDrawBuffer(GL11.GL_FRONT);
		}
	} catch (LWJGLException e) {
		pbuffer.destroy();
		throw e;
	}
}
 
Example #2
Source File: PBufferGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Initialise the PBuffer that will be used to render to
 * 
 * @throws SlickException
 */
private void init() throws SlickException {
	try {
		Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter());
		
		final RenderTexture rt = new RenderTexture(false, true, false, false, RenderTexture.RENDER_TEXTURE_2D, 0);
		pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), rt, null);

		// Initialise state of the pbuffer context.
		pbuffer.makeCurrent();

		initGL();
		GL.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());
		pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER);
		image.draw(0,0);
		image.setTexture(tex);
		
		Display.makeCurrent();
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?");
	}
}
 
Example #3
Source File: PBufferGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.Graphics#disable()
 */
protected void disable() {
	GL.flush();
	
	// Bind the texture after rendering.
	GL.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID());
	pbuffer.bindTexImage(Pbuffer.FRONT_LEFT_BUFFER);
	
	try {
		Display.makeCurrent();
	} catch (LWJGLException e) {
		Log.error(e);
	}
	
	SlickCallable.leaveSafeBlock();
}
 
Example #4
Source File: PBufferGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.Graphics#enable()
 */
protected void enable() {
	SlickCallable.enterSafeBlock();
	
	try {
		if (pbuffer.isBufferLost()) {
			pbuffer.destroy();
			init();
		}

		pbuffer.makeCurrent();
	} catch (Exception e) {
		Log.error("Failed to recreate the PBuffer");
		throw new RuntimeException(e);
	}
	
	// Put the renderer contents to the texture
	GL.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID());
	pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER);
	TextureImpl.unbind();
	initGL();
}
 
Example #5
Source File: GraphicsFactory.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Initialise offscreen rendering by checking what buffers are supported
 * by the card
 * 
 * @throws SlickException Indicates no buffers are supported
 */
private static void init() throws SlickException {
	init = true;
	
	if (fbo) {
		fbo = GLContext.getCapabilities().GL_EXT_framebuffer_object;
	}
	pbuffer = (Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) != 0;
	pbufferRT = (Pbuffer.getCapabilities() & Pbuffer.RENDER_TEXTURE_SUPPORTED) != 0;
	
	if (!fbo && !pbuffer && !pbufferRT) {
		throw new SlickException("Your OpenGL card does not support offscreen buffers and hence can't handle the dynamic images required for this application.");
	}
	
	Log.info("Offscreen Buffers FBO="+fbo+" PBUFFER="+pbuffer+" PBUFFERRT="+pbufferRT);
}
 
Example #6
Source File: PBufferUniqueGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Initialise the PBuffer that will be used to render to
 * 
 * @throws SlickException
 */
private void init() throws SlickException {
	try {
		Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter());

		pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), null, null);
		// Initialise state of the pbuffer context.
		pbuffer.makeCurrent();

		initGL();
		image.draw(0,0);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());
		GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 0, 0, 
							  tex.getTextureWidth(), 
							  tex.getTextureHeight(), 0);
		image.setTexture(tex);
		
		Display.makeCurrent();
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?");
	}
}
 
Example #7
Source File: GameContainer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Enable shared OpenGL context. After calling this all containers created 
 * will shared a single parent context
 * 
 * @throws SlickException Indicates a failure to create the shared drawable
 */
public static void enableSharedContext() throws SlickException {
	try {
		SHARED_DRAWABLE = new Pbuffer(64, 64, new PixelFormat(8, 0, 0), null);
	} catch (LWJGLException e) {
		throw new SlickException("Unable to create the pbuffer used for shard context, buffers not supported", e);
	}
}
 
Example #8
Source File: GameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Enable shared OpenGL context. After calling this all containers created 
 * will shared a single parent context
 * 
 * @throws SlickException Indicates a failure to create the shared drawable
 */
public static void enableSharedContext() throws SlickException {
	try {
		SHARED_DRAWABLE = new Pbuffer(64, 64, new PixelFormat(8, 0, 0), null);
	} catch (LWJGLException e) {
		throw new SlickException("Unable to create the pbuffer used for shard context, buffers not supported", e);
	}
}
 
Example #9
Source File: PBufferGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new graphics context around a pbuffer
 * 
 * @param image The image we're rendering to
 * @throws SlickException Indicates a failure to use pbuffers
 */
public PBufferGraphics(Image image) throws SlickException {
	super(image.getTexture().getTextureWidth(), image.getTexture().getTextureHeight());
	this.image = image;
	
	Log.debug("Creating pbuffer(rtt) "+image.getWidth()+"x"+image.getHeight());
	if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
		throw new SlickException("Your OpenGL card does not support PBuffers and hence can't handle the dynamic images required for this application.");
	}
	if ((Pbuffer.getCapabilities() & Pbuffer.RENDER_TEXTURE_SUPPORTED) == 0) {
		throw new SlickException("Your OpenGL card does not support Render-To-Texture and hence can't handle the dynamic images required for this application.");
	}

	init();
}
 
Example #10
Source File: PBufferUniqueGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new graphics context around a pbuffer
 * 
 * @param image The image we're rendering to
 * @throws SlickException Indicates a failure to use pbuffers
 */
public PBufferUniqueGraphics(Image image) throws SlickException {
	super(image.getTexture().getTextureWidth(), image.getTexture().getTextureHeight());
	this.image = image;
	
	Log.debug("Creating pbuffer(unique) "+image.getWidth()+"x"+image.getHeight());
	if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
		throw new SlickException("Your OpenGL card does not support PBuffers and hence can't handle the dynamic images required for this application.");
	}

	init();
}
 
Example #11
Source File: LwjglOffscreenBuffer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void initInThread(){
    if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0){
        logger.severe("Offscreen surfaces are not supported.");
        return;
    }

    pixelFormat = new PixelFormat(settings.getBitsPerPixel(),
                                  0,
                                  settings.getDepthBits(),
                                  settings.getStencilBits(),
                                  settings.getSamples());
    
    width = settings.getWidth();
    height = settings.getHeight();
    try{
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            public void uncaughtException(Thread thread, Throwable thrown) {
                listener.handleError("Uncaught exception thrown in "+thread.toString(), thrown);
            }
        });

        pbuffer = new Pbuffer(width, height, pixelFormat, null, null, createContextAttribs());
        pbuffer.makeCurrent();

        renderable.set(true);

        logger.info("Offscreen buffer created.");
        printContextInitInfo();
    } catch (LWJGLException ex){
        listener.handleError("Failed to create display", ex);
    } finally {
        // TODO: It is possible to avoid "Failed to find pixel format"
        // error here by creating a default display.
    }
    super.internalCreate();
    listener.initialize();
}
 
Example #12
Source File: Settings.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final boolean usePbuffer() {
	return use_pbuffer && ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) != 0);
}