GLRenderer: fix texture update regression introduced in 9f3a145dd7

experimental
Kirill Vainer 9 years ago
parent e552fb1101
commit edd183a2be
  1. 54
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java

@ -1950,6 +1950,28 @@ public class GLRenderer implements Renderer {
} }
} }
/**
* Ensures that the texture is bound to the given unit
* and that the unit is currently active (for modification).
*
* @param target The texture target, one of GL_TEXTURE_***
* @param img The image texture to bind
* @param unit At what unit to bind the texture.
*/
private void bindTextureAndUnit(int target, Image img, int unit) {
if (context.boundTextureUnit != unit) {
gl.glActiveTexture(GL.GL_TEXTURE0 + unit);
context.boundTextureUnit = unit;
}
if (context.boundTextures[unit] != img) {
gl.glBindTexture(target, img.getId());
context.boundTextures[unit] = img;
statistics.onTextureUse(img, true);
} else {
statistics.onTextureUse(img, false);
}
}
/** /**
* Uploads the given image to the GL driver. * Uploads the given image to the GL driver.
* *
@ -1973,17 +1995,7 @@ public class GLRenderer implements Renderer {
// bind texture // bind texture
int target = convertTextureType(type, img.getMultiSamples(), -1); int target = convertTextureType(type, img.getMultiSamples(), -1);
if (context.boundTextures[unit] != img) { bindTextureAndUnit(target, img, unit);
if (context.boundTextureUnit != unit) {
gl.glActiveTexture(GL.GL_TEXTURE0 + unit);
context.boundTextureUnit = unit;
}
gl.glBindTexture(target, texId);
context.boundTextures[unit] = img;
statistics.onTextureUse(img, true);
}
if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) { if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
// Image does not have mipmaps, but they are required. // Image does not have mipmaps, but they are required.
@ -2092,6 +2104,7 @@ public class GLRenderer implements Renderer {
img.clearUpdateNeeded(); img.clearUpdateNeeded();
} }
@Override
public void setTexture(int unit, Texture tex) { public void setTexture(int unit, Texture tex) {
Image image = tex.getImage(); Image image = tex.getImage();
if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) { if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) {
@ -2118,23 +2131,8 @@ public class GLRenderer implements Renderer {
int texId = image.getId(); int texId = image.getId();
assert texId != -1; assert texId != -1;
Image[] textures = context.boundTextures; int target = convertTextureType(tex.getType(), image.getMultiSamples(), -1);
bindTextureAndUnit(target, image, unit);
int type = convertTextureType(tex.getType(), image.getMultiSamples(), -1);
if (textures[unit] != image) {
if (context.boundTextureUnit != unit) {
gl.glActiveTexture(GL.GL_TEXTURE0 + unit);
context.boundTextureUnit = unit;
}
gl.glBindTexture(type, texId);
textures[unit] = image;
statistics.onTextureUse(image, true);
} else {
statistics.onTextureUse(image, false);
}
setupTextureParams(tex); setupTextureParams(tex);
} }

Loading…
Cancel
Save