use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class GLRenderer method updateRenderTexture.
public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
Texture tex = rb.getTexture();
Image image = tex.getImage();
if (image.isUpdateNeeded()) {
// Check NPOT requirements
checkNonPowerOfTwo(tex);
updateTexImageData(image, tex.getType(), 0, false);
// NOTE: For depth textures, sets nearest/no-mips mode
// Required to fix "framebuffer unsupported"
// for old NVIDIA drivers!
setupTextureParams(0, tex);
}
if (rb.getLayer() < 0) {
glfbo.glFramebufferTexture2DEXT(GLFbo.GL_FRAMEBUFFER_EXT, convertAttachmentSlot(rb.getSlot()), convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()), image.getId(), 0);
} else {
gl3.glFramebufferTextureLayer(GLFbo.GL_FRAMEBUFFER_EXT, convertAttachmentSlot(rb.getSlot()), image.getId(), 0, rb.getLayer());
}
}
use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class GLRenderer method setReadDrawBuffers.
public void setReadDrawBuffers(FrameBuffer fb) {
if (gl2 == null) {
return;
}
final int NONE = -2;
final int INITIAL = -1;
final int MRT_OFF = 100;
if (fb == null) {
// Set Read/Draw buffers to initial value.
if (context.boundDrawBuf != INITIAL) {
gl2.glDrawBuffer(context.initialDrawBuf);
context.boundDrawBuf = INITIAL;
}
if (context.boundReadBuf != INITIAL) {
gl2.glReadBuffer(context.initialReadBuf);
context.boundReadBuf = INITIAL;
}
} else {
if (fb.getNumColorBuffers() == 0) {
// no color buffer attached.
if (context.boundDrawBuf != NONE) {
gl2.glDrawBuffer(GL.GL_NONE);
context.boundDrawBuf = NONE;
}
if (context.boundReadBuf != NONE) {
gl2.glReadBuffer(GL.GL_NONE);
context.boundReadBuf = NONE;
}
} else {
if (fb.getNumColorBuffers() > limits.get(Limits.FrameBufferAttachments)) {
throw new RendererException("Framebuffer has more color " + "attachments than are supported" + " by the video hardware!");
}
if (fb.isMultiTarget()) {
if (!caps.contains(Caps.FrameBufferMRT)) {
throw new RendererException("Multiple render targets " + " are not supported by the video hardware");
}
if (fb.getNumColorBuffers() > limits.get(Limits.FrameBufferMrtAttachments)) {
throw new RendererException("Framebuffer has more" + " multi targets than are supported" + " by the video hardware!");
}
intBuf16.clear();
for (int i = 0; i < fb.getNumColorBuffers(); i++) {
intBuf16.put(GLFbo.GL_COLOR_ATTACHMENT0_EXT + i);
}
intBuf16.flip();
glext.glDrawBuffers(intBuf16);
context.boundDrawBuf = MRT_OFF + fb.getNumColorBuffers();
} else {
RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex());
// select this draw buffer
if (context.boundDrawBuf != rb.getSlot()) {
gl2.glDrawBuffer(GLFbo.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
context.boundDrawBuf = rb.getSlot();
}
}
}
}
}
use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class GLRenderer method updateFrameBuffer.
public void updateFrameBuffer(FrameBuffer fb) {
if (fb.getNumColorBuffers() == 0 && fb.getDepthBuffer() == null) {
throw new IllegalArgumentException("The framebuffer: " + fb + "\nDoesn't have any color/depth buffers");
}
int id = fb.getId();
if (id == -1) {
glfbo.glGenFramebuffersEXT(intBuf1);
id = intBuf1.get(0);
fb.setId(id);
objManager.registerObject(fb);
statistics.onNewFrameBuffer();
}
bindFrameBuffer(fb);
FrameBuffer.RenderBuffer depthBuf = fb.getDepthBuffer();
if (depthBuf != null) {
updateFrameBufferAttachment(fb, depthBuf);
}
for (int i = 0; i < fb.getNumColorBuffers(); i++) {
FrameBuffer.RenderBuffer colorBuf = fb.getColorBuffer(i);
updateFrameBufferAttachment(fb, colorBuf);
}
setReadDrawBuffers(fb);
checkFrameBufferError();
fb.clearUpdateNeeded();
}
use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class AwtPanel method reshapeInThread.
private void reshapeInThread(int width, int height) {
byteBuf = BufferUtils.ensureLargeEnough(byteBuf, width * height * 4);
intBuf = byteBuf.asIntBuffer();
if (fb != null) {
fb.dispose();
fb = null;
}
fb = new FrameBuffer(width, height, 1);
fb.setDepthBuffer(Format.Depth);
fb.setColorBuffer(Format.RGB8);
fb.setSrgb(srgb);
if (attachAsMain) {
rm.getRenderer().setMainFrameBufferOverride(fb);
}
synchronized (lock) {
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
}
// synchronized (lock){
// img = (BufferedImage) getGraphicsConfiguration().createCompatibleImage(width, height);
// }
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -img.getHeight());
transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
for (ViewPort vp : viewPorts) {
if (!attachAsMain) {
vp.setOutputFrameBuffer(fb);
}
vp.getCamera().resize(width, height, true);
// Main framebuffer should use RenderManager.notifyReshape().
for (SceneProcessor sp : vp.getProcessors()) {
sp.reshape(vp, width, height);
}
}
}
use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.
the class TestRenderToCubemap method setupOffscreenView.
public Texture setupOffscreenView() {
Camera offCamera = new Camera(512, 512);
offView = renderManager.createPreView("Offscreen View", offCamera);
offView.setClearFlags(true, true, true);
offView.setBackgroundColor(ColorRGBA.DarkGray);
// create offscreen framebuffer
FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);
//setup framebuffer's cam
offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
offCamera.setLocation(new Vector3f(0f, 0f, -5f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
//setup framebuffer's texture
TextureCubeMap offTex = new TextureCubeMap(512, 512, Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.Trilinear);
offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setMultiTarget(true);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeX);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveX);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeY);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveY);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeZ);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveZ);
//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer's scene
Box boxMesh = new Box(1, 1, 1);
Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
offBox = new Geometry("box", boxMesh);
offBox.setMaterial(material);
// attach the scene to the viewport to be rendered
offView.attachScene(offBox);
return offTex;
}
Aggregations