* Fix issue where setting texture on renderer with no mipmaps and then setting the same texture with mipmaps would prevent them from being generated (fixed for desktop GL1/GL2 and android)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9617 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 13 years ago
parent e78474a5b1
commit ac0f3a107c
  1. 12
      engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java
  2. 9
      engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java
  3. 25
      engine/src/lwjgl/com/jme3/renderer/lwjgl/LwjglRenderer.java

@ -1472,7 +1472,7 @@ public class OGLESShaderRenderer implements Renderer {
* @param type * @param type
* @param needMips * @param needMips
*/ */
public void updateTexImageData(Image img, Texture.Type type, boolean needMips) { public void updateTexImageData(Image img, Texture.Type type) {
int texId = img.getId(); int texId = img.getId();
if (texId == -1) { if (texId == -1) {
// create texture // create texture
@ -1495,6 +1495,12 @@ public class OGLESShaderRenderer implements Renderer {
GLES20.glBindTexture(target, texId); GLES20.glBindTexture(target, texId);
context.boundTextures[0] = img; context.boundTextures[0] = img;
} }
boolean needMips = false;
if (img.isGeneratedMipmapsRequired()) {
needMips = true;
img.setMipmapsGenerated(true);
}
if (target == GLES20.GL_TEXTURE_CUBE_MAP) { if (target == GLES20.GL_TEXTURE_CUBE_MAP) {
// Upload a cube map / sky box // Upload a cube map / sky box
@ -1534,8 +1540,8 @@ public class OGLESShaderRenderer implements Renderer {
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()) { if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) {
updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels()); updateTexImageData(image, tex.getType());
} }
int texId = image.getId(); int texId = image.getId();

@ -702,7 +702,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
} }
} }
public void updateTexImageData(Image img, Texture.Type type, boolean mips, int unit) { public void updateTexImageData(Image img, Texture.Type type, int unit) {
int texId = img.getId(); int texId = img.getId();
if (texId == -1) { if (texId == -1) {
// create texture // create texture
@ -740,7 +740,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
} }
} }
if (!img.hasMipmaps() && mips) { if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
// No pregenerated mips available, // No pregenerated mips available,
// generate from base level if required // generate from base level if required
@ -750,6 +750,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
} else { } else {
MipMapGenerator.generateMipMaps(img); MipMapGenerator.generateMipMaps(img);
} }
img.setMipmapsGenerated(true);
} else { } else {
} }
@ -787,8 +788,8 @@ public class LwjglGL1Renderer implements GL1Renderer {
} }
Image image = tex.getImage(); Image image = tex.getImage();
if (image.isUpdateNeeded()) { if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) {
updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels(), unit); updateTexImageData(image, tex.getType(), unit);
} }
int texId = image.getId(); int texId = image.getId();

@ -1385,7 +1385,7 @@ public class LwjglRenderer implements Renderer {
Texture tex = rb.getTexture(); Texture tex = rb.getTexture();
Image image = tex.getImage(); Image image = tex.getImage();
if (image.isUpdateNeeded()) { if (image.isUpdateNeeded()) {
updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels(), 0); updateTexImageData(image, tex.getType(), 0);
// NOTE: For depth textures, sets nearest/no-mips mode // NOTE: For depth textures, sets nearest/no-mips mode
// Required to fix "framebuffer unsupported" // Required to fix "framebuffer unsupported"
@ -1775,7 +1775,15 @@ public class LwjglRenderer implements Renderer {
} }
} }
public void updateTexImageData(Image img, Texture.Type type, boolean mips, int unit) { /**
* Uploads the given image to the GL driver.
*
* @param img The image to upload
* @param type How the data in the image argument should be interpreted.
* @param updateMipsOnly If true, then texture data is already updated for this image, only
* @param unit The texture slot to be used to upload the image, not important
*/
public void updateTexImageData(Image img, Texture.Type type, int unit) {
int texId = img.getId(); int texId = img.getId();
if (texId == -1) { if (texId == -1) {
// create texture // create texture
@ -1800,13 +1808,15 @@ public class LwjglRenderer implements Renderer {
statistics.onTextureUse(img, true); statistics.onTextureUse(img, true);
} }
if (!img.hasMipmaps() && mips) { if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
// No pregenerated mips available, // No pregenerated mips available,
// generate from base level if required // generate from base level if required
if (!GLContext.getCapabilities().OpenGL30) { if (!GLContext.getCapabilities().OpenGL30) {
glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE); glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE);
img.setMipmapsGenerated(true);
} }
} else { } else {
// Image already has mipmaps or no mipmap generation desired.
// glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0 ); // glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0 );
if (img.getMipMapSizes() != null) { if (img.getMipMapSizes() != null) {
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, img.getMipMapSizes().length - 1); glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, img.getMipMapSizes().length - 1);
@ -1871,21 +1881,22 @@ public class LwjglRenderer implements Renderer {
} }
if (GLContext.getCapabilities().OpenGL30) { if (GLContext.getCapabilities().OpenGL30) {
if (!img.hasMipmaps() && mips && img.getData() != null) { if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired() && img.getData() != null) {
// XXX: Required for ATI // XXX: Required for ATI
glEnable(target); glEnable(target);
glGenerateMipmapEXT(target); glGenerateMipmapEXT(target);
glDisable(target); glDisable(target);
img.setMipmapsGenerated(true);
} }
} }
img.clearUpdateNeeded(); img.clearUpdateNeeded();
} }
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()) { if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) {
updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels(), unit); updateTexImageData(image, tex.getType(), unit);
} }
int texId = image.getId(); int texId = image.getId();

Loading…
Cancel
Save