mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Add VSync support to Direct3D api.
This commit is contained in:
parent
062758a7b0
commit
1dc09ca9f3
@ -48,7 +48,7 @@ namespace ClassicalSharp {
|
||||
MakeKeys( KeyMapping.Forward, descriptionsLeft, 10, out keysLeft );
|
||||
leftEnd = CalculateMaxWidth( keysLeft );
|
||||
|
||||
string[] descriptionsRight = { "Take screenshot", "Toggle fullscreen", "Toggle 3rd person camera", "Toggle VSync",
|
||||
string[] descriptionsRight = { "Take screenshot", "Toggle fullscreen", "Toggle VSync", "Toggle 3rd person camera",
|
||||
"Change view distance", "Toggle fly", "Speed", "Toggle noclip", "Fly up", "Fly down", "Display player list" };
|
||||
MakeKeys( KeyMapping.Screenshot, descriptionsRight, leftEnd + 30, out keysRight );
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ namespace ClassicalSharp {
|
||||
bool useThirdPerson = Camera is FirstPersonCamera;
|
||||
SetCamera( useThirdPerson );
|
||||
} else if( key == Keys[KeyMapping.VSync] ) {
|
||||
VSync = VSync == VSyncMode.Off ? VSyncMode.On : VSyncMode.Off;
|
||||
Graphics.SetVSync( this, VSync == VSyncMode.Off );
|
||||
} else if( key == Keys[KeyMapping.ViewDistance] ) {
|
||||
for( int i = 0; i < viewDistances.Length; i++ ) {
|
||||
int newDist = viewDistances[i];
|
||||
|
@ -148,7 +148,7 @@ namespace ClassicalSharp {
|
||||
WeatherRenderer = new WeatherRenderer( this );
|
||||
WeatherRenderer.Init();
|
||||
|
||||
VSync = VSyncMode.On;
|
||||
Graphics.SetVSync( this, true );
|
||||
Graphics.DepthTest = true;
|
||||
Graphics.DepthTestFunc( CompareFunc.LessEqual );
|
||||
//Graphics.DepthWrite = true;
|
||||
@ -274,7 +274,6 @@ namespace ClassicalSharp {
|
||||
Picking.Dispose();
|
||||
ParticleManager.Dispose();
|
||||
Players.Dispose();
|
||||
Graphics.CheckResources();
|
||||
AsyncDownloader.Dispose();
|
||||
if( writer != null ) {
|
||||
writer.Close();
|
||||
@ -294,7 +293,7 @@ namespace ClassicalSharp {
|
||||
|
||||
protected override void OnResize( EventArgs e ) {
|
||||
base.OnResize( e );
|
||||
Graphics.OnWindowResize( Width, Height );
|
||||
Graphics.OnWindowResize( this );
|
||||
UpdateProjection();
|
||||
if( activeScreen != null ) {
|
||||
activeScreen.OnResize( width, height, Width, Height );
|
||||
|
@ -392,8 +392,19 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
device.Present();
|
||||
}
|
||||
|
||||
public override void OnWindowResize( int newWidth, int newHeight ) {
|
||||
PresentParameters args = GetPresentArgs( newWidth, newHeight );
|
||||
bool vsync = false;
|
||||
public override void SetVSync( Game game, bool value ) {
|
||||
vsync = value;
|
||||
game.VSync = value ? OpenTK.VSyncMode.On : OpenTK.VSyncMode.Off;
|
||||
RecreateDevice( game );
|
||||
}
|
||||
|
||||
public override void OnWindowResize( Game game ) {
|
||||
RecreateDevice( game );
|
||||
}
|
||||
|
||||
void RecreateDevice( Game game ) {
|
||||
PresentParameters args = GetPresentArgs( game.Width, game.Height );
|
||||
device.Reset( args );
|
||||
SetDefaultRenderStates();
|
||||
device.SetRenderState( RenderStates.AlphaTestEnable, alphaTest );
|
||||
@ -428,7 +439,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
args.BackBufferWidth = width;
|
||||
args.BackBufferHeight = height;
|
||||
args.EnableAutoDepthStencil = true;
|
||||
args.PresentationInterval = PresentInterval.Immediate;
|
||||
args.PresentationInterval = vsync ? PresentInterval.One : PresentInterval.Immediate;
|
||||
args.SwapEffect = SwapEffect.Discard;
|
||||
args.Windowed = true;
|
||||
return args;
|
||||
|
@ -153,9 +153,6 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
public abstract void TakeScreenshot( string output, Size size );
|
||||
|
||||
public virtual void CheckResources() {
|
||||
}
|
||||
|
||||
public virtual void PrintApiSpecificInfo() {
|
||||
}
|
||||
|
||||
@ -163,7 +160,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
public abstract void EndFrame( Game game );
|
||||
|
||||
public abstract void OnWindowResize( int newWidth, int newHeight );
|
||||
public abstract void SetVSync( Game game, bool value );
|
||||
|
||||
public abstract void OnWindowResize( Game game );
|
||||
|
||||
protected void InitDynamicBuffers() {
|
||||
quadVb = CreateDynamicVb( VertexFormat.Pos3fCol4b, 4 );
|
||||
|
@ -374,6 +374,10 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
game.SwapBuffers();
|
||||
}
|
||||
|
||||
public override void SetVSync( Game game, bool value ) {
|
||||
game.VSync = value ? VSyncMode.On : VSyncMode.Off;
|
||||
}
|
||||
|
||||
public unsafe override void PrintApiSpecificInfo() {
|
||||
Console.WriteLine( "OpenGL vendor: " + new String( (sbyte*)Gl.glGetString( StringName.Vendor ) ) );
|
||||
Console.WriteLine( "OpenGL renderer: " + new String( (sbyte*)Gl.glGetString( StringName.Renderer ) ) );
|
||||
@ -400,8 +404,8 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnWindowResize( int newWidth, int newHeight ) {
|
||||
Gl.glViewport( 0, 0, newWidth, newHeight );
|
||||
public override void OnWindowResize( Game game ) {
|
||||
Gl.glViewport( 0, 0, game.Width, game.Height );
|
||||
}
|
||||
|
||||
static void ToggleCap( EnableCap cap, bool value ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user