Michael Ludwig avatar Michael Ludwig committed 4de1656

Add back in tests from screwed-up copy.

Comments (0)

Files changed (2)

ferox-renderer/ferox-renderer-lwjgl/src/test/java/com/ferox/renderer/impl/lwjgl/FixedFunctionRenderTest.java

+package com.ferox.renderer.impl.lwjgl;
+
+import com.ferox.input.logic.InputManager;
+import com.ferox.math.Matrix4;
+import com.ferox.math.Vector3;
+import com.ferox.math.Vector4;
+import com.ferox.math.bounds.Frustum;
+import com.ferox.renderer.Context;
+import com.ferox.renderer.FixedFunctionRenderer;
+import com.ferox.renderer.FixedFunctionRenderer.TexCoord;
+import com.ferox.renderer.FixedFunctionRenderer.TexCoordSource;
+import com.ferox.renderer.HardwareAccessLayer;
+import com.ferox.renderer.OnscreenSurface;
+import com.ferox.renderer.Renderer.DrawStyle;
+import com.ferox.renderer.Surface;
+import com.ferox.renderer.Task;
+import com.ferox.resource.BufferData;
+import com.ferox.resource.Mipmap;
+import com.ferox.resource.Texture;
+import com.ferox.resource.Texture.Filter;
+import com.ferox.resource.Texture.Target;
+import com.ferox.resource.TextureFormat;
+import com.ferox.resource.VertexBufferObject.StorageMode;
+import com.ferox.util.ApplicationStub;
+import com.ferox.util.geom.Geometry;
+import com.ferox.util.geom.Sphere;
+
+public class FixedFunctionRenderTest extends ApplicationStub {
+    private FixedFunctionPass pass;
+    
+    public FixedFunctionRenderTest() {
+        super(LwjglFramework.create());
+    }
+    
+    @Override
+    protected void installInputHandlers(InputManager io) { }
+
+    @Override
+    protected void init(OnscreenSurface surface) {
+        pass = new FixedFunctionPass(surface);
+    }
+
+    @Override
+    protected void renderFrame(OnscreenSurface surface) {
+        surface.getFramework().queue(pass);
+    }
+    
+    private static class FixedFunctionPass implements Task<Void> {
+        final Geometry shape;
+        
+        final Texture volume;
+        
+        final Frustum f;
+        
+        boolean statusChecked;
+        final Surface surface;
+        
+        public FixedFunctionPass(Surface surface) {
+            this.surface = surface;
+            
+            shape = Sphere.create(2f, 32, StorageMode.GPU_STATIC);
+            
+            f = new Frustum(60f, surface.getWidth() / (float) surface.getHeight(), 1f, 100f);
+            f.setOrientation(new Vector3(0f, 3f, 10f), new Vector3(0f, 0f, -1f), new Vector3(0f, 1f, 0f));
+            
+            int width = 256;
+            int height = 256;
+            int depth = 256;
+            
+            byte[] volumeBuffer = new byte[width * height * depth * 4];
+            for (int z = 0; z < depth; z++) {
+                for (int y = 0; y < height; y++) {
+                    for (int x = 0; x < width; x++) {
+                        int index = z * width * height * 4 + y * width * 4 + x * 4;
+
+                        volumeBuffer[index] = (byte) (z / (float) depth * 256);
+                        volumeBuffer[index + 1] = (byte) (y / (float) height * 256);
+                        volumeBuffer[index + 2] = (byte) (x / (float) width * 256);
+                        volumeBuffer[index + 3] = (byte) 127;
+                    }
+                }
+            }
+            
+            Mipmap data = new Mipmap(new BufferData(volumeBuffer), width, height, depth, TextureFormat.RGBA);
+            volume = new Texture(Target.T_3D, data);
+            volume.setFilter(Filter.NEAREST);
+        }
+        
+        @Override
+        public Void run(HardwareAccessLayer access) {
+            Context context = access.setActiveSurface(surface);
+            if (context == null)
+                return null;
+            
+            FixedFunctionRenderer g = context.getFixedFunctionRenderer();
+            if (g != null) {
+                g.clear(true, true, true, new Vector4(.2f, .2f, .2f, 1f), 1, 0);
+                
+                g.setDrawStyle(DrawStyle.SOLID);
+                
+                g.setVertices(shape.getVertices());
+                g.setNormals(shape.getNormals());
+                g.setTextureCoordinates(0, shape.getTextureCoordinates());
+                
+                g.setTexture(0, volume);
+                g.setTextureCoordGeneration(0, TexCoord.R, TexCoordSource.OBJECT);
+                
+                g.setProjectionMatrix(f.getProjectionMatrix());
+                
+                Matrix4 t = new Matrix4();
+                int rendered = 0;
+                for (int i = 0; i < 10000; i++) {
+                    t.setIdentity();
+                    t.set(0, 3, (float) Math.random() * 100 - 50);
+                    t.set(1, 3, (float) Math.random() * 100 - 50);
+                    t.set(2, 3, (float) Math.random() * 100 - 50);
+
+                    g.setModelViewMatrix(f.getViewMatrix().mul(t, t));
+                    
+                    if (shape.getIndices() != null)
+                        rendered += g.render(shape.getPolygonType(), shape.getIndices(), shape.getIndexOffset(), shape.getIndexCount());
+                    else
+                        rendered += g.render(shape.getPolygonType(), shape.getIndexOffset(), shape.getIndexCount());
+                }   
+                
+                if (!statusChecked) {
+                    statusChecked = true;
+                    
+                    System.out.println("Rendered count: " + rendered);
+                    
+                    System.out.println("\nvertices status: " + surface.getFramework().getStatus(shape.getVertices().getData()));
+                    System.out.println("\nnormals status: " + surface.getFramework().getStatus(shape.getNormals().getData()));
+                    System.out.println("\ntexcoords status: " + surface.getFramework().getStatus(shape.getTextureCoordinates().getData()));
+
+                    System.out.println("\ntexture status: " + surface.getFramework().getStatus(volume) + " " + surface.getFramework().getStatusMessage(volume));
+                }
+            }
+            
+            return null;
+        }
+    }
+    
+    public static void main(String[] args){
+        new FixedFunctionRenderTest().run();
+    }
+}

ferox-renderer/ferox-renderer-lwjgl/src/test/java/com/ferox/renderer/impl/lwjgl/GlslRenderTest.java

+package com.ferox.renderer.impl.lwjgl;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import com.ferox.input.logic.InputManager;
+import com.ferox.math.Vector3;
+import com.ferox.math.Vector4;
+import com.ferox.math.bounds.Frustum;
+import com.ferox.renderer.Context;
+import com.ferox.renderer.Framework;
+import com.ferox.renderer.GlslRenderer;
+import com.ferox.renderer.HardwareAccessLayer;
+import com.ferox.renderer.OnscreenSurface;
+import com.ferox.renderer.Surface;
+import com.ferox.renderer.Task;
+import com.ferox.resource.BufferData;
+import com.ferox.resource.GlslShader;
+import com.ferox.resource.GlslShader.ShaderType;
+import com.ferox.resource.GlslUniform;
+import com.ferox.resource.Mipmap;
+import com.ferox.resource.Resource.Status;
+import com.ferox.resource.Texture;
+import com.ferox.resource.Texture.Filter;
+import com.ferox.resource.Texture.Target;
+import com.ferox.resource.TextureFormat;
+import com.ferox.util.ApplicationStub;
+import com.ferox.util.geom.Box;
+import com.ferox.util.geom.Geometry;
+
+public class GlslRenderTest extends ApplicationStub {
+    private static final String VERTEX_SHADER = 
+        "uniform mat4 projection;" + 
+        "uniform mat4 modelview;" + 
+        "uniform vec2 transform;" + 
+        
+        "attribute vec3 vertex;" + 
+        "varying vec3 tcs;" +
+        
+        "void main() {" +
+        "   tcs = vec3((vertex.x + transform.x) * transform.y, (vertex.y + transform.x) * transform.y, (vertex.z + transform.x) * transform.y);" +
+        "   gl_Position = projection * modelview * vec4(vertex, 1.0);" +
+        "}";
+    private static final String FRAGMENT_SHADER = 
+        "uniform vec4 color;" +
+        "uniform sampler3D texture;" +
+        
+        "varying vec3 tcs;" +
+        
+        "void main() {" +
+        "   gl_FragColor = texture3D(texture, tcs) * color;" +
+        "}";
+    
+    private GlslPass pass;
+    
+    public GlslRenderTest() {
+        super(LwjglFramework.create());
+    }
+    
+    @Override
+    protected void installInputHandlers(InputManager io) { }
+
+    @Override
+    protected void init(OnscreenSurface surface) {
+        Framework framework = surface.getFramework();
+        pass = new GlslPass(surface);
+        Status status = framework.update(pass.shader);
+        if (status != Status.READY) {
+            System.out.println("Shader: " + status + " " + framework.getStatusMessage(pass.shader));
+            framework.destroy();
+            System.exit(0);
+        }
+    }
+
+    @Override
+    protected void renderFrame(OnscreenSurface surface) {
+        surface.getFramework().queue(pass);
+    }
+    
+    public static void main(String[] args) throws Exception {
+        new GlslRenderTest().run();
+    }
+    
+    private static class GlslPass implements Task<Void> {
+        final GlslShader shader;
+        final Geometry shape;
+        
+        final Texture volume;
+        
+        final Frustum f;
+        
+        boolean statusChecked;
+        final Surface surface;
+        
+        public GlslPass(Surface surface) {
+            this.surface = surface;
+            
+            shape = Box.create(4.0);
+            shader = new GlslShader();
+            
+            shader.setShader(ShaderType.VERTEX, VERTEX_SHADER);
+            shader.setShader(ShaderType.FRAGMENT, FRAGMENT_SHADER);
+            
+            f = new Frustum(60f, surface.getWidth() / (float) surface.getHeight(), 1f, 100f);
+            f.setOrientation(new Vector3(0f, 3f, 10f), new Vector3(0f, 0f, -1f), new Vector3(0f, 1f, 0f));
+            
+            int width = 256;
+            int height = 256;
+            int depth = 256;
+            
+            byte[] volumeBuffer = new byte[width * height * depth * 4];
+            for (int z = 0; z < depth; z++) {
+                for (int y = 0; y < height; y++) {
+                    for (int x = 0; x < width; x++) {
+                        int index = z * width * height * 4 + y * width * 4 + x * 4;
+
+                        volumeBuffer[index] = (byte) (z / (float) depth * 256);
+                        volumeBuffer[index + 1] = (byte) (y / (float) height * 256);
+                        volumeBuffer[index + 2] = (byte) (x / (float) width * 256);
+                        volumeBuffer[index + 3] = (byte) 127;
+                    }
+                }
+            }
+            
+            Mipmap data = new Mipmap(new BufferData(volumeBuffer), width, height, depth, TextureFormat.RGBA);
+            volume = new Texture(Target.T_3D, data);
+            volume.setFilter(Filter.NEAREST);
+        }
+        
+        @Override
+        public Void run(HardwareAccessLayer access) {
+            Context context = access.setActiveSurface(surface);
+            if (context == null)
+                return null;
+            
+            GlslRenderer g = context.getGlslRenderer();
+            if (g != null) {
+                g.clear(true, true, true, new Vector4(.2f, .2f, .2f, 1f), 1, 0);
+                
+                g.setShader(shader);
+                g.bindAttribute("vertex", shape.getVertices());
+                
+                g.setUniform("projection", f.getProjectionMatrix());
+                g.setUniform("modelview", f.getViewMatrix());
+                
+                g.setUniform("color", new Vector4(1f, 1f, 1f, 1f));
+                g.setUniform("texture", volume);
+                
+                g.setUniform("transform", 2f, .25f);
+                
+                int rendered = g.render(shape.getPolygonType(), shape.getIndexOffset(), shape.getIndexCount());
+                
+                if (!statusChecked) {
+                    statusChecked = true;
+                    
+                    System.out.println("Rendered count: " + rendered);
+                    
+                    Status shaderStatus = surface.getFramework().getStatus(shader);
+                    String shaderMsg = surface.getFramework().getStatusMessage(shader);
+                    
+                    System.out.println(shaderStatus + " " + shaderMsg);
+                    
+                    System.out.println("uniforms:");
+                    Map<String, GlslUniform> uniforms = g.getUniforms();
+                    for (Entry<String, GlslUniform> u: uniforms.entrySet()) {
+                        GlslUniform uniform = u.getValue();
+                        System.out.println(uniform.getName() + " " + uniform.getType() + " " + uniform.getLength());
+                    }
+                    
+                    System.out.println("\nattributes:");
+                    System.out.println(g.getAttributes());
+                    
+                    System.out.println("\ntexture status: " + surface.getFramework().getStatus(volume) + " " + surface.getFramework().getStatusMessage(volume));
+                }
+            }
+            
+            return null;
+        }
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.