Skip to content

Commit

Permalink
IBasicRasterizerFactory was never intended to depend on BasicMaterial…
Browse files Browse the repository at this point in the history
…, this was just for convenience.
  • Loading branch information
dnadlinger committed Feb 18, 2010
1 parent 052e75b commit 232e66e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/d4/scene/BasicMaterial.d
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
37 changes: 19 additions & 18 deletions src/d4/scene/GenericBasicRasterizerFactory.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 )() );
//
Expand All @@ -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.
Expand All @@ -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 )();
Expand Down
20 changes: 12 additions & 8 deletions src/d4/scene/IBasicRasterizerFactory.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@

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
* resulting binary), but BasicMaterial is used (e.g. in the model loader).
*/
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 );
}
5 changes: 3 additions & 2 deletions src/d4/scene/NullBasicRasterizerFactory.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

module d4.scene.NullBasicRasterizerFactory;

import d4.math.Texture;
import d4.renderer.IRasterizer;
import d4.scene.BasicMaterial;
import d4.scene.IBasicRasterizerFactory;

/**
Expand All @@ -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;
}
}

0 comments on commit 232e66e

Please sign in to comment.