* Move certain render context specific fields from Renderer into RenderContext
This commit is contained in:
parent
c55717141e
commit
e225e6ff89
@ -35,6 +35,7 @@ import com.jme3.material.RenderState;
|
|||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.scene.Mesh;
|
import com.jme3.scene.Mesh;
|
||||||
import com.jme3.scene.VertexBuffer;
|
import com.jme3.scene.VertexBuffer;
|
||||||
|
import com.jme3.shader.Shader;
|
||||||
import com.jme3.texture.FrameBuffer;
|
import com.jme3.texture.FrameBuffer;
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
|
|
||||||
@ -138,11 +139,21 @@ public class RenderContext {
|
|||||||
* @see Renderer#setShader(com.jme3.shader.Shader)
|
* @see Renderer#setShader(com.jme3.shader.Shader)
|
||||||
*/
|
*/
|
||||||
public int boundShaderProgram;
|
public int boundShaderProgram;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Renderer#setShader(com.jme3.shader.Shader)
|
||||||
|
*/
|
||||||
|
public Shader boundShader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer)
|
* @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer)
|
||||||
*/
|
*/
|
||||||
public int boundFBO = 0;
|
public int boundFBO = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer)
|
||||||
|
*/
|
||||||
|
public FrameBuffer boundFB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently bound Renderbuffer
|
* Currently bound Renderbuffer
|
||||||
@ -279,6 +290,10 @@ public class RenderContext {
|
|||||||
*/
|
*/
|
||||||
public RenderState.TestFunction alphaFunc = RenderState.TestFunction.Greater;
|
public RenderState.TestFunction alphaFunc = RenderState.TestFunction.Greater;
|
||||||
|
|
||||||
|
|
||||||
|
public int initialDrawBuf;
|
||||||
|
public int initialReadBuf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the RenderContext to default GL state
|
* Reset the RenderContext to default GL state
|
||||||
*/
|
*/
|
||||||
@ -298,7 +313,9 @@ public class RenderContext {
|
|||||||
blendMode = RenderState.BlendMode.Off;
|
blendMode = RenderState.BlendMode.Off;
|
||||||
wireframe = false;
|
wireframe = false;
|
||||||
boundShaderProgram = 0;
|
boundShaderProgram = 0;
|
||||||
|
boundShader = null;
|
||||||
boundFBO = 0;
|
boundFBO = 0;
|
||||||
|
boundFB = null;
|
||||||
boundRB = 0;
|
boundRB = 0;
|
||||||
boundDrawBuf = -1;
|
boundDrawBuf = -1;
|
||||||
boundReadBuf = -1;
|
boundReadBuf = -1;
|
||||||
|
@ -100,10 +100,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
private final RenderContext context = new RenderContext();
|
private final RenderContext context = new RenderContext();
|
||||||
private final NativeObjectManager objManager = new NativeObjectManager();
|
private final NativeObjectManager objManager = new NativeObjectManager();
|
||||||
private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
|
private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
|
||||||
// current state
|
|
||||||
private Shader boundShader;
|
|
||||||
private int initialDrawBuf, initialReadBuf;
|
|
||||||
private int glslVer;
|
|
||||||
private int vertexTextureUnits;
|
private int vertexTextureUnits;
|
||||||
private int fragTextureUnits;
|
private int fragTextureUnits;
|
||||||
private int vertexUniforms;
|
private int vertexUniforms;
|
||||||
@ -119,7 +116,6 @@ public class LwjglRenderer implements Renderer {
|
|||||||
private int maxTriCount;
|
private int maxTriCount;
|
||||||
private int maxColorTexSamples;
|
private int maxColorTexSamples;
|
||||||
private int maxDepthTexSamples;
|
private int maxDepthTexSamples;
|
||||||
private FrameBuffer lastFb = null;
|
|
||||||
private FrameBuffer mainFbOverride = null;
|
private FrameBuffer mainFbOverride = null;
|
||||||
private final Statistics statistics = new Statistics();
|
private final Statistics statistics = new Statistics();
|
||||||
private int vpX, vpY, vpW, vpH;
|
private int vpX, vpY, vpW, vpH;
|
||||||
@ -180,7 +176,6 @@ public class LwjglRenderer implements Renderer {
|
|||||||
versionStr = glGetString(GL_SHADING_LANGUAGE_VERSION);
|
versionStr = glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||||
}
|
}
|
||||||
if (versionStr == null || versionStr.equals("")) {
|
if (versionStr == null || versionStr.equals("")) {
|
||||||
glslVer = -1;
|
|
||||||
throw new UnsupportedOperationException("GLSL and OpenGL2 is "
|
throw new UnsupportedOperationException("GLSL and OpenGL2 is "
|
||||||
+ "required for the LWJGL "
|
+ "required for the LWJGL "
|
||||||
+ "renderer!");
|
+ "renderer!");
|
||||||
@ -188,8 +183,8 @@ public class LwjglRenderer implements Renderer {
|
|||||||
|
|
||||||
// Fix issue in TestRenderToMemory when GL_FRONT is the main
|
// Fix issue in TestRenderToMemory when GL_FRONT is the main
|
||||||
// buffer being used.
|
// buffer being used.
|
||||||
initialDrawBuf = glGetInteger(GL_DRAW_BUFFER);
|
context.initialDrawBuf = glGetInteger(GL_DRAW_BUFFER);
|
||||||
initialReadBuf = glGetInteger(GL_READ_BUFFER);
|
context.initialReadBuf = glGetInteger(GL_READ_BUFFER);
|
||||||
|
|
||||||
// XXX: This has to be GL_BACK for canvas on Mac
|
// XXX: This has to be GL_BACK for canvas on Mac
|
||||||
// Since initialDrawBuf is GL_FRONT for pbuffer, gotta
|
// Since initialDrawBuf is GL_FRONT for pbuffer, gotta
|
||||||
@ -203,7 +198,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float version = Float.parseFloat(versionStr);
|
float version = Float.parseFloat(versionStr);
|
||||||
glslVer = (int) (version * 100);
|
int glslVer = (int) (version * 100);
|
||||||
|
|
||||||
switch (glslVer) {
|
switch (glslVer) {
|
||||||
default:
|
default:
|
||||||
@ -409,11 +404,8 @@ public class LwjglRenderer implements Renderer {
|
|||||||
|
|
||||||
public void invalidateState() {
|
public void invalidateState() {
|
||||||
context.reset();
|
context.reset();
|
||||||
boundShader = null;
|
context.initialDrawBuf = glGetInteger(GL_DRAW_BUFFER);
|
||||||
lastFb = null;
|
context.initialReadBuf = glGetInteger(GL_READ_BUFFER);
|
||||||
|
|
||||||
initialDrawBuf = glGetInteger(GL_DRAW_BUFFER);
|
|
||||||
initialReadBuf = glGetInteger(GL_READ_BUFFER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetGLObjects() {
|
public void resetGLObjects() {
|
||||||
@ -821,7 +813,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
if (context.boundShaderProgram != shaderId) {
|
if (context.boundShaderProgram != shaderId) {
|
||||||
glUseProgram(shaderId);
|
glUseProgram(shaderId);
|
||||||
statistics.onShaderUse(shader, true);
|
statistics.onShaderUse(shader, true);
|
||||||
boundShader = shader;
|
context.boundShader = shader;
|
||||||
context.boundShaderProgram = shaderId;
|
context.boundShaderProgram = shaderId;
|
||||||
} else {
|
} else {
|
||||||
statistics.onShaderUse(shader, false);
|
statistics.onShaderUse(shader, false);
|
||||||
@ -1531,16 +1523,16 @@ public class LwjglRenderer implements Renderer {
|
|||||||
fb = mainFbOverride;
|
fb = mainFbOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastFb == fb) {
|
if (context.boundFB == fb) {
|
||||||
if (fb == null || !fb.isUpdateNeeded()) {
|
if (fb == null || !fb.isUpdateNeeded()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate mipmaps for last FB if needed
|
// generate mipmaps for last FB if needed
|
||||||
if (lastFb != null) {
|
if (context.boundFB != null) {
|
||||||
for (int i = 0; i < lastFb.getNumColorBuffers(); i++) {
|
for (int i = 0; i < context.boundFB.getNumColorBuffers(); i++) {
|
||||||
RenderBuffer rb = lastFb.getColorBuffer(i);
|
RenderBuffer rb = context.boundFB.getColorBuffer(i);
|
||||||
Texture tex = rb.getTexture();
|
Texture tex = rb.getTexture();
|
||||||
if (tex != null
|
if (tex != null
|
||||||
&& tex.getMinFilter().usesMipMapLevels()) {
|
&& tex.getMinFilter().usesMipMapLevels()) {
|
||||||
@ -1564,15 +1556,15 @@ public class LwjglRenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
// select back buffer
|
// select back buffer
|
||||||
if (context.boundDrawBuf != -1) {
|
if (context.boundDrawBuf != -1) {
|
||||||
glDrawBuffer(initialDrawBuf);
|
glDrawBuffer(context.initialDrawBuf);
|
||||||
context.boundDrawBuf = -1;
|
context.boundDrawBuf = -1;
|
||||||
}
|
}
|
||||||
if (context.boundReadBuf != -1) {
|
if (context.boundReadBuf != -1) {
|
||||||
glReadBuffer(initialReadBuf);
|
glReadBuffer(context.initialReadBuf);
|
||||||
context.boundReadBuf = -1;
|
context.boundReadBuf = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastFb = null;
|
context.boundFB = null;
|
||||||
} else {
|
} else {
|
||||||
if (fb.getNumColorBuffers() == 0 && fb.getDepthBuffer() == null) {
|
if (fb.getNumColorBuffers() == 0 && fb.getDepthBuffer() == null) {
|
||||||
throw new IllegalArgumentException("The framebuffer: " + fb
|
throw new IllegalArgumentException("The framebuffer: " + fb
|
||||||
@ -1641,7 +1633,7 @@ public class LwjglRenderer implements Renderer {
|
|||||||
assert fb.getId() >= 0;
|
assert fb.getId() >= 0;
|
||||||
assert context.boundFBO == fb.getId();
|
assert context.boundFBO == fb.getId();
|
||||||
|
|
||||||
lastFb = fb;
|
context.boundFB = fb;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkFrameBufferError();
|
checkFrameBufferError();
|
||||||
@ -2210,8 +2202,9 @@ public class LwjglRenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int programId = context.boundShaderProgram;
|
int programId = context.boundShaderProgram;
|
||||||
|
|
||||||
if (programId > 0) {
|
if (programId > 0) {
|
||||||
Attribute attrib = boundShader.getAttribute(vb.getBufferType());
|
Attribute attrib = context.boundShader.getAttribute(vb.getBufferType());
|
||||||
int loc = attrib.getLocation();
|
int loc = attrib.getLocation();
|
||||||
if (loc == -1) {
|
if (loc == -1) {
|
||||||
return; // not defined
|
return; // not defined
|
||||||
|
Loading…
x
Reference in New Issue
Block a user