diff --git a/src/d4/scene/BasicMaterial.d b/src/d4/scene/BasicMaterial.d index 3b71b5a..acf5c5b 100644 --- a/src/d4/scene/BasicMaterial.d +++ b/src/d4/scene/BasicMaterial.d @@ -116,7 +116,8 @@ public: * to draw the material. */ IRasterizer createRasterizer() { - return m_rasterizerFactory.createRasterizer( this ); + return m_rasterizerFactory.createRasterizer( m_wireframe, + m_lighting, m_gouraudShading, m_vertexColors, m_diffuseTexture ); } void prepareForRendering( Renderer renderer ) { diff --git a/src/d4/scene/GenericBasicRasterizerFactory.d b/src/d4/scene/GenericBasicRasterizerFactory.d index 2003d2b..7ac7e4d 100644 --- a/src/d4/scene/GenericBasicRasterizerFactory.d +++ b/src/d4/scene/GenericBasicRasterizerFactory.d @@ -16,10 +16,10 @@ module d4.scene.GenericBasicRasterizerFactory; +import d4.math.Texture; import d4.renderer.IRasterizer; import d4.renderer.SolidRasterizer; import d4.renderer.WireframeRasterizer; -import d4.scene.BasicMaterial; import d4.scene.IBasicRasterizerFactory; import d4.shader.LitVertexColorShader; import d4.shader.LitSingleColorShader; @@ -37,16 +37,17 @@ import d4.shader.VertexColorShader; * (1, -1, -1) is used. */ class GenericBasicRasterizerFactory : IBasicRasterizerFactory { - IRasterizer createRasterizer( BasicMaterial m ) { - if ( m.wireframe ) { + IRasterizer createRasterizer( bool wireframe, bool lighting, + bool gouraudShading, bool vertexColors, Texture diffuseTexture ) { + if ( wireframe ) { // This causes dmd to segfault: // return new WireframeRasterizer!( SingleColorShader, Color() )(); return new WireframeRasterizer!( SingleColorShader )(); } - if ( m.gouraudShading ) { - if ( m.vertexColors ) { - if ( m.lighting ) { + if ( gouraudShading ) { + if ( vertexColors ) { + if ( lighting ) { // Simply doing the following does not work: // return renderer.registerRasterizer( new SolidGouraudRasterizer!( ColorGouraudShader, lightDirection )() ); // @@ -57,18 +58,18 @@ class GenericBasicRasterizerFactory : IBasicRasterizerFactory { } else { return new SolidRasterizer!( true, VertexColorShader )(); } - } else if ( m.diffuseTexture !is null ) { - if ( m.lighting ) { + } else if ( diffuseTexture !is null ) { + if ( lighting ) { auto rasterizer = new SolidRasterizer!( true, LitTextureShader, AMBIENT_LIGHT_LEVEL, 1, -1, -1 )(); - rasterizer.textures = [ m.diffuseTexture ]; + rasterizer.textures = [ diffuseTexture ]; return rasterizer; } else { auto rasterizer = new SolidRasterizer!( true, TextureShader )(); - rasterizer.textures = [ m.diffuseTexture ]; + rasterizer.textures = [ diffuseTexture ]; return rasterizer; } } else { - if ( m.lighting ) { + if ( lighting ) { return new SolidRasterizer!( true, LitSingleColorShader, AMBIENT_LIGHT_LEVEL, 1, -1, -1 )(); } else { // See above. @@ -77,24 +78,24 @@ class GenericBasicRasterizerFactory : IBasicRasterizerFactory { } } } else { - if ( m.vertexColors ) { - if ( m.lighting ) { + if ( vertexColors ) { + if ( lighting ) { return new SolidRasterizer!( false, LitVertexColorShader, AMBIENT_LIGHT_LEVEL, 1, -1, -1 )(); } else { return new SolidRasterizer!( false, VertexColorShader )(); } - } else if ( m.diffuseTexture !is null ) { - if ( m.lighting ) { + } else if ( diffuseTexture !is null ) { + if ( lighting ) { auto rasterizer = new SolidRasterizer!( false, LitTextureShader, AMBIENT_LIGHT_LEVEL, 1, -1, -1 )(); - rasterizer.textures = [ m.diffuseTexture ]; + rasterizer.textures = [ diffuseTexture ]; return rasterizer; } else { auto rasterizer = new SolidRasterizer!( false, TextureShader )(); - rasterizer.textures = [ m.diffuseTexture ]; + rasterizer.textures = [ diffuseTexture ]; return rasterizer; } } else { - if ( m.lighting ) { + if ( lighting ) { return new SolidRasterizer!( false, LitSingleColorShader, AMBIENT_LIGHT_LEVEL, 1, -1, -1 )(); } else { return new SolidRasterizer!( false, SingleColorShader )(); diff --git a/src/d4/scene/IBasicRasterizerFactory.d b/src/d4/scene/IBasicRasterizerFactory.d index 9d4ba19..b51a7e7 100644 --- a/src/d4/scene/IBasicRasterizerFactory.d +++ b/src/d4/scene/IBasicRasterizerFactory.d @@ -16,12 +16,12 @@ module d4.scene.IBasicRasterizerFactory; -import d4.scene.BasicMaterial; +import d4.math.Texture; import d4.renderer.IRasterizer; /** - * Serves as an extra layer of indirection between BasicMaterial and the default - * shader creation. + * Serves as an extra layer of indirection between BasicMaterial and the + * creation of rasterizers for it. * * The rationale behind this is to avoid instancing RasterizerBase several times * for the generic default shaders if they are not nedeed (and so bloating the @@ -29,12 +29,16 @@ import d4.renderer.IRasterizer; */ interface IBasicRasterizerFactory { /** - * Creates a rasterizer fitting the properties of the given BasicMaterial. + * Creates a rasterizer with the given properties. * * Params: - * material = The material to create the IRasterizer for. - * Returns: - * The newly created rasterizer. + * wireframe = Whether wireframe mode is used. + * lighting = Whether lighting is used. + * gouraudShading = Whether Gouraud shading is used. + * vertexColors = Whether vertex colors are used. + * diffuseTexture = The diffuse color textur, null for none. + * Returns: The new rasterizer. */ - IRasterizer createRasterizer( BasicMaterial material ); + IRasterizer createRasterizer( bool wireframe, bool lighting, + bool gouraudShading, bool vertexColors, Texture diffuseTexture ); } diff --git a/src/d4/scene/NullBasicRasterizerFactory.d b/src/d4/scene/NullBasicRasterizerFactory.d index 7de11b9..322ee9a 100644 --- a/src/d4/scene/NullBasicRasterizerFactory.d +++ b/src/d4/scene/NullBasicRasterizerFactory.d @@ -16,8 +16,8 @@ module d4.scene.NullBasicRasterizerFactory; +import d4.math.Texture; import d4.renderer.IRasterizer; -import d4.scene.BasicMaterial; import d4.scene.IBasicRasterizerFactory; /** @@ -27,7 +27,8 @@ import d4.scene.IBasicRasterizerFactory; * importer for rendering. */ class NullBasicRasterizerFactory : IBasicRasterizerFactory { - IRasterizer createRasterizer( BasicMaterial material ) { + IRasterizer createRasterizer( bool wireframe, bool lighting, + bool gouraudShading, bool vertexColors, Texture diffuseTexture ) { return null; } }