- Framebuffer can now render to a cube map face, thanks to dflemstr
http://jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/how-do-i-render-to-a-face-of-a-texturecubemap/?#post-171990 git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9363 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
c9d5011555
commit
311242b6d9
@ -92,6 +92,7 @@ public class FrameBuffer extends NativeObject {
|
|||||||
Image.Format format;
|
Image.Format format;
|
||||||
int id = -1;
|
int id = -1;
|
||||||
int slot = -1;
|
int slot = -1;
|
||||||
|
int face = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The image format of the render buffer.
|
* @return The image format of the render buffer.
|
||||||
@ -129,6 +130,10 @@ public class FrameBuffer extends NativeObject {
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getFace() {
|
||||||
|
return face;
|
||||||
|
}
|
||||||
|
|
||||||
public void resetObject(){
|
public void resetObject(){
|
||||||
id = -1;
|
id = -1;
|
||||||
}
|
}
|
||||||
@ -305,8 +310,8 @@ public class FrameBuffer extends NativeObject {
|
|||||||
/**
|
/**
|
||||||
* Set the color texture to use for this framebuffer.
|
* Set the color texture to use for this framebuffer.
|
||||||
* This automatically clears all existing textures added previously
|
* This automatically clears all existing textures added previously
|
||||||
* with {@link FrameBuffer#addColorTexture(com.jme3.texture.Texture2D) }
|
* with {@link FrameBuffer#addColorTexture } and adds this texture as the
|
||||||
* and adds this texture as the only target.
|
* only target.
|
||||||
*
|
*
|
||||||
* @param tex The color texture to set.
|
* @param tex The color texture to set.
|
||||||
*/
|
*/
|
||||||
@ -315,6 +320,20 @@ public class FrameBuffer extends NativeObject {
|
|||||||
addColorTexture(tex);
|
addColorTexture(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the color texture to use for this framebuffer.
|
||||||
|
* This automatically clears all existing textures added previously
|
||||||
|
* with {@link FrameBuffer#addColorTexture } and adds this texture as the
|
||||||
|
* only target.
|
||||||
|
*
|
||||||
|
* @param tex The cube-map texture to set.
|
||||||
|
* @param face The face of the cube-map to render to.
|
||||||
|
*/
|
||||||
|
public void setColorTexture(TextureCubeMap tex, TextureCubeMap.Face face) {
|
||||||
|
clearColorTargets();
|
||||||
|
addColorTexture(tex, face);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all color targets that were set or added previously.
|
* Clears all color targets that were set or added previously.
|
||||||
*/
|
*/
|
||||||
@ -346,6 +365,32 @@ public class FrameBuffer extends NativeObject {
|
|||||||
colorBufs.add(colorBuf);
|
colorBufs.add(colorBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a color texture to use for this framebuffer.
|
||||||
|
* If MRT is enabled, then each subsequently added texture can be
|
||||||
|
* rendered to through a shader that writes to the array <code>gl_FragData</code>.
|
||||||
|
* If MRT is not enabled, then the index set with {@link FrameBuffer#setTargetIndex(int) }
|
||||||
|
* is rendered to by the shader.
|
||||||
|
*
|
||||||
|
* @param tex The cube-map texture to add.
|
||||||
|
* @param face The face of the cube-map to render to.
|
||||||
|
*/
|
||||||
|
public void addColorTexture(TextureCubeMap tex, TextureCubeMap.Face face) {
|
||||||
|
if (id != -1)
|
||||||
|
throw new UnsupportedOperationException("FrameBuffer already initialized.");
|
||||||
|
|
||||||
|
Image img = tex.getImage();
|
||||||
|
checkSetTexture(tex, false);
|
||||||
|
|
||||||
|
RenderBuffer colorBuf = new RenderBuffer();
|
||||||
|
colorBuf.slot = colorBufs.size();
|
||||||
|
colorBuf.tex = tex;
|
||||||
|
colorBuf.format = img.getFormat();
|
||||||
|
colorBuf.face = face.ordinal();
|
||||||
|
|
||||||
|
colorBufs.add(colorBuf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the depth texture to use for this framebuffer.
|
* Set the depth texture to use for this framebuffer.
|
||||||
*
|
*
|
||||||
|
@ -37,6 +37,8 @@ import com.jme3.export.JmeExporter;
|
|||||||
import com.jme3.export.JmeImporter;
|
import com.jme3.export.JmeImporter;
|
||||||
import com.jme3.export.OutputCapsule;
|
import com.jme3.export.OutputCapsule;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes a cubemap texture.
|
* Describes a cubemap texture.
|
||||||
@ -63,9 +65,10 @@ public class TextureCubeMap extends Texture {
|
|||||||
* Face of the Cubemap as described by its directional offset from the
|
* Face of the Cubemap as described by its directional offset from the
|
||||||
* origin.
|
* origin.
|
||||||
*/
|
*/
|
||||||
// public enum Face {
|
public enum Face {
|
||||||
// PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, NegativeZ;
|
|
||||||
// }
|
PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, NegativeZ;
|
||||||
|
}
|
||||||
|
|
||||||
public TextureCubeMap(){
|
public TextureCubeMap(){
|
||||||
super();
|
super();
|
||||||
@ -76,6 +79,20 @@ public class TextureCubeMap extends Texture {
|
|||||||
setImage(img);
|
setImage(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TextureCubeMap(int width, int height, Image.Format format){
|
||||||
|
this(createEmptyLayeredImage(width, height, 6, format));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Image createEmptyLayeredImage(int width, int height,
|
||||||
|
int layerCount, Image.Format format) {
|
||||||
|
ArrayList<ByteBuffer> layers = new ArrayList<ByteBuffer>();
|
||||||
|
for(int i = 0; i < layerCount; i++) {
|
||||||
|
layers.add(null);
|
||||||
|
}
|
||||||
|
Image image = new Image(format, width, height, 0, layers);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
public Texture createSimpleClone() {
|
public Texture createSimpleClone() {
|
||||||
return createSimpleClone(new TextureCubeMap());
|
return createSimpleClone(new TextureCubeMap());
|
||||||
}
|
}
|
||||||
|
@ -1406,7 +1406,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
|
|
||||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
|
||||||
convertAttachmentSlot(rb.getSlot()),
|
convertAttachmentSlot(rb.getSlot()),
|
||||||
convertTextureType(tex.getType(), image.getMultiSamples()),
|
convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()),
|
||||||
image.getId(),
|
image.getId(),
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
@ -1503,7 +1503,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
&& tex.getMinFilter().usesMipMapLevels()) {
|
&& tex.getMinFilter().usesMipMapLevels()) {
|
||||||
setTexture(0, rb.getTexture());
|
setTexture(0, rb.getTexture());
|
||||||
|
|
||||||
int textureType = convertTextureType(tex.getType(), tex.getImage().getMultiSamples());
|
int textureType = convertTextureType(tex.getType(), tex.getImage().getMultiSamples(), rb.getFace());
|
||||||
glEnable(textureType);
|
glEnable(textureType);
|
||||||
glGenerateMipmapEXT(textureType);
|
glGenerateMipmapEXT(textureType);
|
||||||
glDisable(textureType);
|
glDisable(textureType);
|
||||||
@ -1655,7 +1655,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
/*********************************************************************\
|
/*********************************************************************\
|
||||||
|* Textures *|
|
|* Textures *|
|
||||||
\*********************************************************************/
|
\*********************************************************************/
|
||||||
private int convertTextureType(Texture.Type type, int samples) {
|
private int convertTextureType(Texture.Type type, int samples, int face) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TwoDimensional:
|
case TwoDimensional:
|
||||||
if (samples > 1) {
|
if (samples > 1) {
|
||||||
@ -1672,7 +1672,13 @@ public class LwjglRenderer implements Renderer {
|
|||||||
case ThreeDimensional:
|
case ThreeDimensional:
|
||||||
return GL_TEXTURE_3D;
|
return GL_TEXTURE_3D;
|
||||||
case CubeMap:
|
case CubeMap:
|
||||||
|
if (face < 0) {
|
||||||
return GL_TEXTURE_CUBE_MAP;
|
return GL_TEXTURE_CUBE_MAP;
|
||||||
|
} else if (face < 6) {
|
||||||
|
return GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedOperationException("Invalid cube map face index: " + face);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Unknown texture type: " + type);
|
throw new UnsupportedOperationException("Unknown texture type: " + type);
|
||||||
}
|
}
|
||||||
@ -1728,7 +1734,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
@SuppressWarnings("fallthrough")
|
@SuppressWarnings("fallthrough")
|
||||||
private void setupTextureParams(Texture tex) {
|
private void setupTextureParams(Texture tex) {
|
||||||
Image image = tex.getImage();
|
Image image = tex.getImage();
|
||||||
int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1);
|
int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1, -1);
|
||||||
|
|
||||||
// filter things
|
// filter things
|
||||||
int minFilter = convertMinFilter(tex.getMinFilter());
|
int minFilter = convertMinFilter(tex.getMinFilter());
|
||||||
@ -1788,7 +1794,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// bind texture
|
// bind texture
|
||||||
int target = convertTextureType(type, img.getMultiSamples());
|
int target = convertTextureType(type, img.getMultiSamples(), -1);
|
||||||
if (context.boundTextureUnit != unit) {
|
if (context.boundTextureUnit != unit) {
|
||||||
glActiveTexture(GL_TEXTURE0 + unit);
|
glActiveTexture(GL_TEXTURE0 + unit);
|
||||||
context.boundTextureUnit = unit;
|
context.boundTextureUnit = unit;
|
||||||
@ -1893,7 +1899,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
|
|
||||||
Image[] textures = context.boundTextures;
|
Image[] textures = context.boundTextures;
|
||||||
|
|
||||||
int type = convertTextureType(tex.getType(), image.getMultiSamples());
|
int type = convertTextureType(tex.getType(), image.getMultiSamples(), -1);
|
||||||
// if (!context.textureIndexList.moveToNew(unit)) {
|
// if (!context.textureIndexList.moveToNew(unit)) {
|
||||||
// if (context.boundTextureUnit != unit){
|
// if (context.boundTextureUnit != unit){
|
||||||
// glActiveTexture(GL_TEXTURE0 + unit);
|
// glActiveTexture(GL_TEXTURE0 + unit);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user