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