mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Now get Direct3D device to create properly.
This commit is contained in:
parent
01de650f67
commit
3035b3583b
@ -10,6 +10,7 @@ using Microsoft.DirectX;
|
|||||||
using Microsoft.DirectX.Direct3D;
|
using Microsoft.DirectX.Direct3D;
|
||||||
using D3D = Microsoft.DirectX.Direct3D;
|
using D3D = Microsoft.DirectX.Direct3D;
|
||||||
using Matrix4 = OpenTK.Matrix4;
|
using Matrix4 = OpenTK.Matrix4;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace ClassicalSharp.GraphicsAPI {
|
namespace ClassicalSharp.GraphicsAPI {
|
||||||
|
|
||||||
@ -17,12 +18,14 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
public Device device;
|
public Device device;
|
||||||
Caps caps;
|
Caps caps;
|
||||||
D3D.Texture[] textures;
|
RenderStateManager state;
|
||||||
VertexBuffer[] vBuffers;
|
|
||||||
IndexBuffer[] iBuffers;
|
|
||||||
const int texBufferSize = 512;
|
const int texBufferSize = 512;
|
||||||
const int iBufferSize = 1024;
|
const int iBufferSize = 1024;
|
||||||
const int vBufferSize = 2048;
|
const int vBufferSize = 2048;
|
||||||
|
|
||||||
|
D3D.Texture[] textures = new D3D.Texture[texBufferSize];
|
||||||
|
VertexBuffer[] vBuffers = new VertexBuffer[vBufferSize];
|
||||||
|
IndexBuffer[] iBuffers = new IndexBuffer[iBufferSize];
|
||||||
MatrixStack viewStack, projStack, texStack;
|
MatrixStack viewStack, projStack, texStack;
|
||||||
MatrixStack curStack;
|
MatrixStack curStack;
|
||||||
PrimitiveType[] modeMappings = {
|
PrimitiveType[] modeMappings = {
|
||||||
@ -30,12 +33,36 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
PrimitiveType.TriangleStrip,
|
PrimitiveType.TriangleStrip,
|
||||||
};
|
};
|
||||||
|
|
||||||
public DirectXApi( Device device ) {
|
public DirectXApi( Game game ) {
|
||||||
this.device = device;
|
PresentParameters args = new PresentParameters();
|
||||||
|
args.Windowed = true;
|
||||||
|
args.SwapEffect = SwapEffect.Discard;
|
||||||
|
args.PresentationInterval = PresentInterval.Immediate;
|
||||||
|
args.EnableAutoDepthStencil = true;
|
||||||
|
args.AutoDepthStencilFormat = DepthFormat.D24X8; // D32 doesn't work
|
||||||
|
|
||||||
|
// Code to get window handle from WinWindowInfo class
|
||||||
|
OpenTK.Platform.IWindowInfo info = game.WindowInfo;
|
||||||
|
Type type = info.GetType();
|
||||||
|
FieldInfo getWindowHandle = type.GetField( "handle", BindingFlags.NonPublic | BindingFlags.Instance );
|
||||||
|
IntPtr windowHandle = (IntPtr)getWindowHandle.GetValue( info );
|
||||||
|
|
||||||
|
int adapter = Manager.Adapters.Default.Adapter;
|
||||||
|
CreateFlags flags = CreateFlags.HardwareVertexProcessing;
|
||||||
|
device = new Device( adapter, DeviceType.Hardware, windowHandle, flags, args );
|
||||||
|
|
||||||
caps = device.DeviceCaps;
|
caps = device.DeviceCaps;
|
||||||
|
state = device.RenderState;
|
||||||
viewStack = new MatrixStack( 32, m => device.SetTransform( TransformType.View, m ) );
|
viewStack = new MatrixStack( 32, m => device.SetTransform( TransformType.View, m ) );
|
||||||
projStack = new MatrixStack( 4, m => device.SetTransform( TransformType.Projection, m ) );
|
projStack = new MatrixStack( 4, m => device.SetTransform( TransformType.Projection, m ) );
|
||||||
texStack = new MatrixStack( 4, m => device.SetTransform( TransformType.Texture1, m ) ); // TODO: Texture0?
|
texStack = new MatrixStack( 4, m => device.SetTransform( TransformType.Texture1, m ) ); // TODO: Texture0?
|
||||||
|
|
||||||
|
state.ColorVertex = false;
|
||||||
|
state.Lighting = false;
|
||||||
|
state.CullMode = Cull.None;
|
||||||
|
state.FillMode = FillMode.Solid;
|
||||||
|
state.SpecularEnable = false;
|
||||||
|
state.DebugMonitorTokenEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool AlphaTest {
|
public override bool AlphaTest {
|
||||||
@ -453,11 +480,11 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void PrintApiSpecificInfo() {
|
public override void PrintApiSpecificInfo() {
|
||||||
Console.WriteLine( "D3D tex memory available: " + device.AvailableTextureMemory );
|
Console.WriteLine( "D3D tex memory available: " + (uint)device.AvailableTextureMemory );
|
||||||
Console.WriteLine( "D3D software vertex processing: " + device.SoftwareVertexProcessing );
|
Console.WriteLine( "D3D software vertex processing: " + device.SoftwareVertexProcessing );
|
||||||
Console.WriteLine( "D3D hardware rasterization: " + device.DeviceCaps.DeviceCaps.SupportsHardwareRasterization );
|
Console.WriteLine( "D3D hardware rasterization: " + caps.DeviceCaps.SupportsHardwareRasterization );
|
||||||
Console.WriteLine( "D3D hardware T & L: " + device.DeviceCaps.DeviceCaps.SupportsHardwareTransformAndLight );
|
Console.WriteLine( "D3D hardware T & L: " + caps.DeviceCaps.SupportsHardwareTransformAndLight );
|
||||||
Console.WriteLine( "D3D hardware pure: " + device.DeviceCaps.DeviceCaps.SupportsPureDevice );
|
Console.WriteLine( "D3D hardware pure: " + caps.DeviceCaps.SupportsPureDevice );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void TakeScreenshot( string output, Size size ) {
|
public override void TakeScreenshot( string output, Size size ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user