Просмотр исходного кода

Use regular renderer to bind texture image to SDSM shader

scott 2 недель назад
Родитель
Сommit
2e5628ec09

+ 3 - 0
jme3-core/src/main/java/com/jme3/renderer/RendererException.java

@@ -47,4 +47,7 @@ public class RendererException extends RuntimeException {
     public RendererException(String message) {
         super(message);
     }
+    public RendererException(Exception e) {
+        super(e);
+    }
 }

+ 0 - 23
jme3-core/src/main/java/com/jme3/renderer/opengl/ComputeShader.java

@@ -36,7 +36,6 @@ import com.jme3.math.Vector2f;
 import com.jme3.math.Vector3f;
 import com.jme3.math.Vector4f;
 import com.jme3.renderer.RendererException;
-import com.jme3.texture.Texture;
 import com.jme3.util.BufferUtils;
 
 import java.nio.FloatBuffer;
@@ -117,13 +116,6 @@ public class ComputeShader {
         gl.glDispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
     }
 
-    public void bindTexture(int bindingPoint, Texture texture) {
-        gl.glActiveTexture(GL.GL_TEXTURE0 + bindingPoint);
-        int textureId = texture.getImage().getId();
-        int target = convertTextureType(texture);
-        gl.glBindTexture(target, textureId);
-    }
-
     public void setUniform(int location, int value) {
         gl.glUniform1i(location, value);
     }
@@ -166,19 +158,4 @@ public class ComputeShader {
     public void delete() {
         gl.glDeleteProgram(programId);
     }
-
-    private int convertTextureType(Texture texture) {
-        switch (texture.getType()) {
-            case TwoDimensional:
-                return GL.GL_TEXTURE_2D;
-            case ThreeDimensional:
-                return GL2.GL_TEXTURE_3D;
-            case CubeMap:
-                return GL.GL_TEXTURE_CUBE_MAP;
-            case TwoDimensionalArray:
-                return GLExt.GL_TEXTURE_2D_ARRAY_EXT;
-            default:
-                throw new UnsupportedOperationException("Unsupported texture type: " + texture.getType());
-        }
-    }
 }

+ 1 - 1
jme3-core/src/main/java/com/jme3/shadow/SdsmDirectionalLightShadowRenderer.java

@@ -145,7 +145,7 @@ public class SdsmDirectionalLightShadowRenderer extends AbstractShadowRenderer {
             throw new UnsupportedOperationException("SDSM shadows require OpenGL 4.3 or higher");
         }
 
-        sdsmFitter = new SdsmFitter(gl4, assetManager);
+        sdsmFitter = new SdsmFitter(gl4, renderer, assetManager);
         glInitialized = true;
 
     }

+ 15 - 8
jme3-core/src/main/java/com/jme3/shadow/SdsmFitter.java

@@ -36,7 +36,9 @@ import com.jme3.asset.AssetKey;
 import com.jme3.asset.AssetManager;
 import com.jme3.math.Matrix4f;
 import com.jme3.math.Vector2f;
+import com.jme3.renderer.Renderer;
 import com.jme3.renderer.RendererException;
+import com.jme3.renderer.TextureUnitException;
 import com.jme3.renderer.opengl.ComputeShader;
 import com.jme3.renderer.opengl.GL4;
 import com.jme3.renderer.opengl.ShaderStorageBufferObject;
@@ -55,6 +57,7 @@ public class SdsmFitter {
     private static final String FIT_FRUSTUMS_SHADER = "Common/MatDefs/Shadow/Sdsm/FitLightFrustums.comp";
 
     private final GL4 gl4;
+    private final Renderer renderer;
     private int maxFrameLag = 3;
 
     private final ComputeShader depthReduceShader;
@@ -301,13 +304,9 @@ public class SdsmFitter {
         }
     }
 
-    /**
-     * Creates a new SDSM fitter.
-     *
-     * @param gl the GL4 interface
-     */
-    public SdsmFitter(GL4 gl, AssetManager assetManager) {
+    public SdsmFitter(GL4 gl, Renderer renderer, AssetManager assetManager) {
         this.gl4 = gl;
+        this.renderer = renderer;
 
         // Load compute shaders
         String reduceSource = loadShaderSource(assetManager, REDUCE_DEPTH_SHADER);
@@ -348,7 +347,11 @@ public class SdsmFitter {
 
         // Pass 1: Reduce depth to find min/max
         depthReduceShader.makeActive();
-        depthReduceShader.bindTexture(0, depthTexture);
+        try {
+            renderer.setTexture(0, depthTexture);
+        } catch (TextureUnitException e) {
+            throw new RendererException(e);
+        }
         depthReduceShader.bindShaderStorageBuffer(1, holder.minMaxDepthSsbo);
         depthReduceShader.dispatch(xGroups, yGroups, 1);
         gl4.glMemoryBarrier(GL4.GL_SHADER_STORAGE_BARRIER_BIT);
@@ -357,7 +360,11 @@ public class SdsmFitter {
         holder.fitFrustumSsbo.initialize(FIT_FRUSTUM_INIT);
 
         fitFrustumsShader.makeActive();
-        fitFrustumsShader.bindTexture(0, depthTexture);
+        try {
+            renderer.setTexture(0, depthTexture);
+        } catch (TextureUnitException e) {
+            throw new RendererException(e);
+        }
         fitFrustumsShader.bindShaderStorageBuffer(1, holder.minMaxDepthSsbo);
         fitFrustumsShader.bindShaderStorageBuffer(2, holder.fitFrustumSsbo);