Bladeren bron

* Added checking for image format

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7376 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
sha..rd 14 jaren geleden
bovenliggende
commit
b5a8080f61

+ 2 - 2
engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java

@@ -518,7 +518,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
         }
 
         // Check sizes if graphics card doesn't support NPOT
-        if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two){
+//        if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two){
             if (img.getWidth() != 0 && img.getHeight() != 0){
                 if (!FastMath.isPowerOfTwo(img.getWidth())
                     || !FastMath.isPowerOfTwo(img.getHeight())
@@ -529,7 +529,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
 
                 }
             }
-        }
+//        }
 
         if (!img.hasMipmaps() && mips) {
             // No pregenerated mips available,

+ 10 - 8
engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java

@@ -906,7 +906,7 @@ public class LwjglRenderer implements Renderer {
 //            case Geometry:
 //                return ARBGeometryShader4.GL_GEOMETRY_SHADER_ARB;
             default:
-                throw new RuntimeException("Unrecognized shader type.");
+                throw new UnsupportedOperationException("Unrecognized shader type.");
         }
     }
 
@@ -1219,7 +1219,7 @@ public class LwjglRenderer implements Renderer {
                 throw ex;
             }
         } else {
-            throw new UnsupportedOperationException("EXT_framebuffer_blit required.");
+            throw new RendererException("EXT_framebuffer_blit required.");
             // TODO: support non-blit copies?
         }
     }
@@ -1269,10 +1269,12 @@ public class LwjglRenderer implements Renderer {
         }
 
         if (fb.getWidth() > maxRBSize || fb.getHeight() > maxRBSize) {
-            throw new UnsupportedOperationException("Resolution " + fb.getWidth()
+            throw new RendererException("Resolution " + fb.getWidth()
                     + ":" + fb.getHeight() + " is not supported.");
         }
 
+        TextureUtil.checkFormatSupported(rb.getFormat());
+
         if (fb.getSamples() > 1 && GLContext.getCapabilities().GL_EXT_framebuffer_multisample) {
             int samples = fb.getSamples();
             if (maxFBOSamples < samples) {
@@ -1457,7 +1459,7 @@ public class LwjglRenderer implements Renderer {
             } else {
                 if (fb.isMultiTarget()) {
                     if (fb.getNumColorBuffers() > maxMRTFBOAttachs) {
-                        throw new UnsupportedOperationException("Framebuffer has more"
+                        throw new RendererException("Framebuffer has more"
                                 + " targets than are supported"
                                 + " on the system!");
                     }
@@ -1843,7 +1845,7 @@ public class LwjglRenderer implements Renderer {
             case Stream:
                 return GL_STREAM_DRAW;
             default:
-                throw new RuntimeException("Unknown usage type.");
+                throw new UnsupportedOperationException("Unknown usage type.");
         }
     }
 
@@ -1869,7 +1871,7 @@ public class LwjglRenderer implements Renderer {
             case Double:
                 return GL_DOUBLE;
             default:
-                throw new RuntimeException("Unknown buffer format.");
+                throw new UnsupportedOperationException("Unknown buffer format.");
 
         }
     }
@@ -1929,7 +1931,7 @@ public class LwjglRenderer implements Renderer {
                     glBufferData(target, (DoubleBuffer) vb.getData(), usage);
                     break;
                 default:
-                    throw new RuntimeException("Unknown buffer format.");
+                    throw new UnsupportedOperationException("Unknown buffer format.");
             }
         } else {
             switch (vb.getFormat()) {
@@ -1952,7 +1954,7 @@ public class LwjglRenderer implements Renderer {
                     glBufferSubData(target, 0, (DoubleBuffer) vb.getData());
                     break;
                 default:
-                    throw new RuntimeException("Unknown buffer format.");
+                    throw new UnsupportedOperationException("Unknown buffer format.");
             }
         }
 //        }else{

+ 49 - 1
engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/TextureUtil.java

@@ -32,6 +32,8 @@
 
 package com.jme3.renderer.lwjgl;
 
+import org.lwjgl.opengl.GLContext;
+import com.jme3.renderer.RendererException;
 import org.lwjgl.opengl.EXTAbgr;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
@@ -40,6 +42,7 @@ import org.lwjgl.opengl.ARBDepthBufferFloat;
 import org.lwjgl.opengl.ARBHalfFloatPixel;
 import org.lwjgl.opengl.ARBTextureFloat;
 import org.lwjgl.opengl.ARBTextureMultisample;
+import org.lwjgl.opengl.ContextCapabilities;
 import org.lwjgl.opengl.EXTPackedFloat;
 import org.lwjgl.opengl.EXTTextureArray;
 import org.lwjgl.opengl.EXTTextureSharedExponent;
@@ -54,6 +57,49 @@ import static org.lwjgl.opengl.GL14.*;
 
 public class TextureUtil {
 
+    private static boolean isFormatSupported(Format fmt, ContextCapabilities caps){
+        switch (fmt){
+            case ARGB4444:
+                return false;
+            case BGR8:
+                return caps.OpenGL12 || caps.GL_EXT_bgra;
+            case DXT1:
+            case DXT1A:
+            case DXT3:
+            case DXT5:
+                return caps.GL_EXT_texture_compression_s3tc;
+            case Depth:
+            case Depth16:
+            case Depth24:
+            case Depth32:
+                return caps.OpenGL14 || caps.GL_ARB_depth_texture;
+            case Depth32F:
+            case Luminance16F:
+            case Luminance16FAlpha16F:
+            case Luminance32F:
+            case RGBA16F:
+            case RGBA32F:
+                return caps.OpenGL30 || caps.GL_ARB_texture_float;
+            case LATC:
+            case LTC:
+                return caps.GL_EXT_texture_compression_latc;
+            case RGB9E5:
+            case RGB16F_to_RGB9E5:
+                return caps.OpenGL30 || caps.GL_EXT_texture_shared_exponent;
+            case RGB111110F:
+            case RGB16F_to_RGB111110F:
+                return caps.OpenGL30 || caps.GL_EXT_packed_float;
+            default:
+                return true;
+        }
+    }
+
+    public static void checkFormatSupported(Format fmt) {
+        if (!isFormatSupported(fmt, GLContext.getCapabilities())) {
+            throw new RendererException("Image format '" + fmt + "' is unsupported by the video hardware.");
+        }
+    }
+
     public static int convertTextureFormat(Format fmt){
         switch (fmt){
             case Alpha16:
@@ -132,8 +178,10 @@ public class TextureUtil {
                                      int index,
                                      int border,
                                      boolean tdc){
-
         Image.Format fmt = img.getFormat();
+
+        checkFormatSupported(fmt);
+
         ByteBuffer data;
         if (index >= 0 && img.getData() != null && img.getData().size() > 0){
             data = img.getData(index);