mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 17:17:09 -04:00
Use device.SetRenderState directly instead of RenderStateManager.
This commit is contained in:
parent
27d9d3d8a5
commit
506e3b8dba
@ -18,7 +18,6 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
public Device device;
|
public Device device;
|
||||||
Caps caps;
|
Caps caps;
|
||||||
RenderStateManager state;
|
|
||||||
const int texBufferSize = 512;
|
const int texBufferSize = 512;
|
||||||
const int iBufferSize = 1024;
|
const int iBufferSize = 1024;
|
||||||
const int vBufferSize = 2048;
|
const int vBufferSize = 2048;
|
||||||
@ -52,25 +51,24 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
device = new Device( adapter, DeviceType.Hardware, windowHandle, flags, args );
|
device = new Device( adapter, DeviceType.Hardware, windowHandle, flags, args );
|
||||||
|
|
||||||
caps = device.DeviceCaps;
|
caps = device.DeviceCaps;
|
||||||
state = device.RenderState;
|
|
||||||
viewStack = new MatrixStack( 32, device, TransformType.View );
|
viewStack = new MatrixStack( 32, device, TransformType.View );
|
||||||
projStack = new MatrixStack( 4, device, TransformType.Projection );
|
projStack = new MatrixStack( 4, device, TransformType.Projection );
|
||||||
texStack = new MatrixStack( 4, device, TransformType.Texture1 ); // TODO: Texture0?
|
texStack = new MatrixStack( 4, device, TransformType.Texture1 ); // TODO: Texture0?
|
||||||
|
|
||||||
state.ColorVertex = false;
|
SetFillType( FillType.Solid );
|
||||||
state.Lighting = false;
|
FaceCulling = false;
|
||||||
state.CullMode = Cull.None;
|
device.SetRenderState( RenderStates.ColorVertex, false );
|
||||||
state.FillMode = FillMode.Solid;
|
device.SetRenderState( RenderStates.Lighting, false );
|
||||||
state.SpecularEnable = false;
|
device.SetRenderState( RenderStates.SpecularEnable, false );
|
||||||
state.DebugMonitorTokenEnabled = false;
|
device.SetRenderState( RenderStates.DebugMonitorToken, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool AlphaTest {
|
public override bool AlphaTest {
|
||||||
set { state.AlphaTestEnable = value; }
|
set { device.SetRenderState( RenderStates.AlphaTestEnable, value ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool AlphaBlending {
|
public override bool AlphaBlending {
|
||||||
set { state.AlphaBlendEnable = value; }
|
set { device.SetRenderState( RenderStates.AlphaBlendEnable, value ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
Compare[] compareFuncs = {
|
Compare[] compareFuncs = {
|
||||||
@ -78,8 +76,8 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
Compare.LessEqual, Compare.Equal, Compare.GreaterEqual, Compare.Greater,
|
Compare.LessEqual, Compare.Equal, Compare.GreaterEqual, Compare.Greater,
|
||||||
};
|
};
|
||||||
public override void AlphaTestFunc( CompareFunc func, float value ) {
|
public override void AlphaTestFunc( CompareFunc func, float value ) {
|
||||||
state.AlphaFunction = compareFuncs[(int)func];
|
device.SetRenderState( RenderStates.AlphaFunction, (int)compareFuncs[(int)func] );
|
||||||
state.ReferenceAlpha = (int)( value * 255f );
|
device.SetRenderState( RenderStates.ReferenceAlpha, (int)( value * 255 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Blend[] blendFuncs = {
|
Blend[] blendFuncs = {
|
||||||
@ -87,46 +85,45 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
Blend.SourceAlpha, Blend.InvSourceAlpha,
|
Blend.SourceAlpha, Blend.InvSourceAlpha,
|
||||||
Blend.DestinationAlpha, Blend.InvDestinationAlpha,
|
Blend.DestinationAlpha, Blend.InvDestinationAlpha,
|
||||||
};
|
};
|
||||||
public override void AlphaBlendFunc( BlendFunc srcFunc, BlendFunc destFunc ) {
|
public override void AlphaBlendFunc( BlendFunc srcFunc, BlendFunc dstFunc ) {
|
||||||
state.SourceBlend = blendFuncs[(int)srcFunc];
|
device.SetRenderState( RenderStates.SourceBlend, (int)blendFuncs[(int)srcFunc] );
|
||||||
state.DestinationBlend = blendFuncs[(int)destFunc];
|
device.SetRenderState( RenderStates.DestinationBlend, (int)blendFuncs[(int)dstFunc] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Fog {
|
public override bool Fog {
|
||||||
set { state.FogEnable = value; }
|
set { device.SetRenderState( RenderStates.FogEnable, value ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFogColour( FastColour col ) {
|
public override void SetFogColour( FastColour col ) {
|
||||||
state.FogColor = col.ToColor();
|
device.SetRenderState( RenderStates.FogColor, col.ToColor().ToArgb() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFogDensity( float value ) {
|
public override void SetFogDensity( float value ) {
|
||||||
state.FogDensity = value;
|
device.SetRenderState( RenderStates.FogDensity, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetFogStart( float value ) {
|
||||||
|
device.SetRenderState( RenderStates.FogStart, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFogEnd( float value ) {
|
public override void SetFogEnd( float value ) {
|
||||||
state.FogEnd = value;
|
device.SetRenderState( RenderStates.FogEnd, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
FogMode[] modes = { FogMode.Linear, FogMode.Exp, FogMode.Exp2 };
|
FogMode[] modes = { FogMode.Linear, FogMode.Exp, FogMode.Exp2 };
|
||||||
public override void SetFogMode( Fog mode ) {
|
public override void SetFogMode( Fog mode ) {
|
||||||
state.FogTableMode = modes[(int)mode];
|
device.SetRenderState( RenderStates.FogTableMode, (int)modes[(int)mode] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFogStart( float value ) {
|
|
||||||
state.FogStart = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool FaceCulling {
|
public override bool FaceCulling {
|
||||||
set {
|
set {
|
||||||
state.CullMode = value ? Cull.Clockwise : Cull.None;
|
Cull mode = value ? Cull.Clockwise : Cull.None;
|
||||||
|
device.SetRenderState( RenderStates.CullMode, (int)mode );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int MaxTextureDimensions {
|
public override int MaxTextureDimensions {
|
||||||
get {
|
get { return Math.Min( caps.MaxTextureHeight, caps.MaxTextureWidth ); }
|
||||||
return Math.Min( caps.MaxTextureHeight, caps.MaxTextureWidth );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int LoadTexture( int width, int height, IntPtr scan0 ) {
|
public override int LoadTexture( int width, int height, IntPtr scan0 ) {
|
||||||
@ -157,32 +154,29 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
return texId < textures.Length && textures[texId] != null;
|
return texId < textures.Length && textures[texId] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color lastClearCol = Color.Black;
|
int lastClearCol = 0;
|
||||||
public override void Clear() {
|
public override void Clear() {
|
||||||
device.Clear( ClearFlags.Target | ClearFlags.ZBuffer, lastClearCol, 1f, 0 );
|
device.Clear( ClearFlags.Target | ClearFlags.ZBuffer, lastClearCol, 1f, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ClearColour( FastColour col ) {
|
public override void ClearColour( FastColour col ) {
|
||||||
lastClearCol = col.ToColor();
|
lastClearCol = col.ToColor().ToArgb();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool ColourWrite {
|
public override bool ColourWrite {
|
||||||
set {
|
set { device.SetRenderState( RenderStates.ColorWriteEnable, value ? 0xF : 0x0 ); }
|
||||||
ColorWriteEnable flags = value ? ColorWriteEnable.RedGreenBlueAlpha : 0;
|
|
||||||
state.ColorWriteEnable = flags;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DepthTestFunc( CompareFunc func ) {
|
public override void DepthTestFunc( CompareFunc func ) {
|
||||||
state.ZBufferFunction = compareFuncs[(int)func];
|
device.SetRenderState( RenderStates.ZBufferFunction, (int)compareFuncs[(int)func] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool DepthTest {
|
public override bool DepthTest {
|
||||||
set { state.ZBufferEnable = value; }
|
set { device.SetRenderState( RenderStates.ZEnable, value ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool DepthWrite {
|
public override bool DepthWrite {
|
||||||
set { state.ZBufferWriteEnable = value; }
|
set { device.SetRenderState( RenderStates.ZBufferWriteEnable, value ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int CreateDynamicVb( VertexFormat format, int maxVertices ) {
|
public override int CreateDynamicVb( VertexFormat format, int maxVertices ) {
|
||||||
@ -199,7 +193,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
FillMode[] fillModes = { FillMode.Point, FillMode.WireFrame, FillMode.Solid };
|
FillMode[] fillModes = { FillMode.Point, FillMode.WireFrame, FillMode.Solid };
|
||||||
public override void SetFillType( FillType type ) {
|
public override void SetFillType( FillType type ) {
|
||||||
state.FillMode = fillModes[(int)type];
|
device.SetRenderState( RenderStates.FillMode, (int)fillModes[(int)type] );
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Vertex buffers
|
#region Vertex buffers
|
||||||
|
@ -61,11 +61,11 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
public abstract void SetFogDensity( float value );
|
public abstract void SetFogDensity( float value );
|
||||||
|
|
||||||
|
public abstract void SetFogStart( float value );
|
||||||
|
|
||||||
public abstract void SetFogEnd( float value );
|
public abstract void SetFogEnd( float value );
|
||||||
|
|
||||||
public abstract void SetFogMode( Fog fogMode );
|
public abstract void SetFogMode( Fog fogMode );
|
||||||
|
|
||||||
public abstract void SetFogStart( float value );
|
|
||||||
|
|
||||||
public abstract bool FaceCulling { set; }
|
public abstract bool FaceCulling { set; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user