fixed a merge issue in GL-RenderSystem

This commit is contained in:
Glatzemann 2011-11-10 07:12:04 +00:00
parent 0a8bdbb9b0
commit 25d2c8dce4
3 changed files with 222 additions and 229 deletions

View File

@ -57,260 +57,248 @@ namespace ANX.Framework.Windows.GL3
/// <summary> /// <summary>
/// Native OpenGL implementation for a graphics device. /// Native OpenGL implementation for a graphics device.
/// </summary> /// </summary>
public class GraphicsDeviceWindowsGL3 : INativeGraphicsDevice public class GraphicsDeviceWindowsGL3 : INativeGraphicsDevice
{ {
#region Constants #region Constants
private const float ColorMultiplier = 1f / 255f; private const float ColorMultiplier = 1f / 255f;
#endregion #endregion
#region Private #region Private
/// <summary> /// <summary>
/// Native graphics context. /// Native graphics context.
/// </summary> /// </summary>
private GraphicsContext nativeContext; private GraphicsContext nativeContext;
/// <summary> /// <summary>
/// The OpenTK window info helper class to provide window informations /// The OpenTK window info helper class to provide window informations
/// to the graphics device. /// to the graphics device.
/// </summary> /// </summary>
private IWindowInfo nativeWindowInfo; private IWindowInfo nativeWindowInfo;
#endregion #endregion
#region Constructor #region Constructor
/// <summary> /// <summary>
/// Create a new OpenGL graphics context. /// Create a new OpenGL graphics context.
/// </summary> /// </summary>
/// <param name="presentationParameters">Parameters for the window /// <param name="presentationParameters">Parameters for the window
/// and graphics context.</param> /// and graphics context.</param>
internal GraphicsDeviceWindowsGL3( internal GraphicsDeviceWindowsGL3(
PresentationParameters presentationParameters) PresentationParameters presentationParameters)
{ {
ResetDevice(presentationParameters); ResetDevice(presentationParameters);
} }
#endregion #endregion
#region ResetDevice #region ResetDevice
/// <summary> /// <summary>
/// Reset the graphics device with the given presentation paramters. /// Reset the graphics device with the given presentation paramters.
/// If a device is currently set, then we dispose the old one. /// If a device is currently set, then we dispose the old one.
/// </summary> /// </summary>
/// <param name="presentationParameters">Parameters for the /// <param name="presentationParameters">Parameters for the
/// graphics device.</param> /// graphics device.</param>
private void ResetDevice(PresentationParameters presentationParameters) private void ResetDevice(PresentationParameters presentationParameters)
{ {
#region Validation #region Validation
if (nativeContext != null) if (nativeContext != null)
{ {
nativeContext.Dispose(); nativeContext.Dispose();
nativeContext = null; nativeContext = null;
} }
if (nativeWindowInfo != null) if (nativeWindowInfo != null)
{ {
nativeWindowInfo.Dispose(); nativeWindowInfo.Dispose();
nativeWindowInfo = null; nativeWindowInfo = null;
} }
#endregion #endregion
// OpenGL Depth Buffer Size: 0/16/24/32 // OpenGL Depth Buffer Size: 0/16/24/32
int depth = 0; int depth = 0;
int stencil = 0; int stencil = 0;
switch (presentationParameters.DepthStencilFormat) switch (presentationParameters.DepthStencilFormat)
{ {
case DepthFormat.None: case DepthFormat.None:
break; break;
case DepthFormat.Depth16: case DepthFormat.Depth16:
depth = 16; depth = 16;
break; break;
case DepthFormat.Depth24: case DepthFormat.Depth24:
depth = 24; depth = 24;
break; break;
case DepthFormat.Depth24Stencil8: case DepthFormat.Depth24Stencil8:
depth = 24; depth = 24;
stencil = 8; stencil = 8;
break; break;
} }
nativeWindowInfo = Utilities.CreateWindowsWindowInfo( nativeWindowInfo = Utilities.CreateWindowsWindowInfo(
presentationParameters.DeviceWindowHandle); presentationParameters.DeviceWindowHandle);
GraphicsMode graphicsMode = new GraphicsMode( GraphicsMode graphicsMode = new GraphicsMode(
DatatypesMapping.SurfaceToColorFormat( DatatypesMapping.SurfaceToColorFormat(
presentationParameters.BackBufferFormat), presentationParameters.BackBufferFormat),
depth, stencil, depth, stencil,
// AntiAlias Samples: 2/4/8/16/32 // AntiAlias Samples: 2/4/8/16/32
presentationParameters.MultiSampleCount); presentationParameters.MultiSampleCount);
nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo); nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo);
nativeContext.MakeCurrent(nativeWindowInfo); nativeContext.MakeCurrent(nativeWindowInfo);
nativeContext.LoadAll(); nativeContext.LoadAll();
} }
#endregion #endregion
#region SetViewport #region SetViewport
/// <summary> /// <summary>
/// Set the OpenGL viewport. /// Set the OpenGL viewport.
/// </summary> /// </summary>
/// <param name="viewport">Viewport data to set natively.</param> /// <param name="viewport">Viewport data to set natively.</param>
public void SetViewport(Viewport viewport) public void SetViewport(Viewport viewport)
{ {
GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height); GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
} }
#endregion #endregion
#region Clear #region Clear
private uint lastClearColor; private uint lastClearColor;
/// <summary> /// <summary>
/// Clear the current screen by the specified clear color. /// Clear the current screen by the specified clear color.
/// </summary> /// </summary>
/// <param name="color">Clear color.</param> /// <param name="color">Clear color.</param>
public void Clear(ref Color color) public void Clear(ref Color color)
{ {
uint newClearColor = color.PackedValue; uint newClearColor = color.PackedValue;
if (lastClearColor != newClearColor) if (lastClearColor != newClearColor)
{ {
lastClearColor = newClearColor; lastClearColor = newClearColor;
GL.ClearColor(color.R * ColorMultiplier, color.G * ColorMultiplier, GL.ClearColor(color.R * ColorMultiplier, color.G * ColorMultiplier,
color.B * ColorMultiplier, color.A * ColorMultiplier); color.B * ColorMultiplier, color.A * ColorMultiplier);
} }
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
} }
#endregion
#region Clear /// <summary>
/// <summary> /// Clear the current screen by the specified clear color and options.
/// Clear the current screen by the specified clear color and options. /// </summary>
/// </summary> /// <param name="options">Clear options defining which components
/// <param name="options">Clear options defining which components /// should be cleared.</param>
/// should be cleared.</param> /// <param name="color">Clear color.</param>
/// <param name="color">Clear color.</param> /// <param name="depth">Depth value.</param>
/// <param name="depth">Depth value.</param> /// <param name="stencil">Stencil value.</param>
/// <param name="stencil">Stencil value.</param> public void Clear(ClearOptions options, Vector4 color, float depth,
public void Clear(ClearOptions options, Vector4 color, float depth, int stencil)
int stencil) {
{ Color anxColor;
Color anxColor; DatatypesMapping.Convert(ref color, out anxColor);
DatatypesMapping.Convert(ref color, out anxColor); uint newClearColor = anxColor.PackedValue;
uint newClearColor = anxColor.PackedValue; if (lastClearColor != newClearColor)
if (lastClearColor != newClearColor) {
{ lastClearColor = newClearColor;
lastClearColor = newClearColor; GL.ClearColor(anxColor.R * ColorMultiplier, anxColor.G * ColorMultiplier,
GL.ClearColor(anxColor.R * ColorMultiplier, anxColor.G * ColorMultiplier, anxColor.B * ColorMultiplier, anxColor.A * ColorMultiplier);
anxColor.B * ColorMultiplier, anxColor.A * ColorMultiplier); }
}
ClearBufferMask mask = (ClearBufferMask)0; ClearBufferMask mask = (ClearBufferMask)0;
if ((options | ClearOptions.Target) == options) if ((options | ClearOptions.Target) == options)
{ {
mask |= ClearBufferMask.ColorBufferBit; mask |= ClearBufferMask.ColorBufferBit;
} }
if ((options | ClearOptions.Stencil) == options) if ((options | ClearOptions.Stencil) == options)
{ {
mask |= ClearBufferMask.StencilBufferBit; mask |= ClearBufferMask.StencilBufferBit;
} }
if ((options | ClearOptions.DepthBuffer) == options) if ((options | ClearOptions.DepthBuffer) == options)
{ {
mask |= ClearBufferMask.DepthBufferBit; mask |= ClearBufferMask.DepthBufferBit;
} }
GL.ClearDepth(depth); GL.ClearDepth(depth);
GL.ClearStencil(stencil); GL.ClearStencil(stencil);
GL.Clear(mask); GL.Clear(mask);
} }
#endregion #endregion
#region Present #region Present
/// <summary> /// <summary>
/// Swap the graphics buffers. /// Swap the graphics buffers.
/// </summary> /// </summary>
public void Present() public void Present()
{ {
nativeContext.SwapBuffers(); nativeContext.SwapBuffers();
} }
#endregion #endregion
public void DrawIndexedPrimitives(PrimitiveType primitiveType, public void DrawIndexedPrimitives(PrimitiveType primitiveType,
int baseVertex, int minVertexIndex, int numVertices, int startIndex, int baseVertex, int minVertexIndex, int numVertices, int startIndex,
int primitiveCount) int primitiveCount)
{
throw new NotImplementedException();
}
public void DrawInstancedPrimitives(PrimitiveType primitiveType,
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
int primitiveCount, int instanceCount)
{
throw new NotImplementedException();
}
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType,
T[] vertexData, int vertexOffset, int numVertices, Array indexData,
int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration,
IndexElementSize indexFormat) where T : struct, IVertexType
{
throw new NotImplementedException();
}
public void DrawUserPrimitives<T>(PrimitiveType primitiveType,
T[] vertexData, int vertexOffset, int primitiveCount,
VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
}
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset,
int primitiveCount)
{
throw new NotImplementedException();
}
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
{
throw new NotImplementedException();
}
public void SetIndexBuffer(IndexBuffer indexBuffer)
{
throw new NotImplementedException();
}
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
{
throw new NotImplementedException();
}
public void GetBackBufferData<T>(Rectangle? rect, T[] data,
int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
public void GetBackBufferData<T>(T[] data) where T : struct
{
throw new NotImplementedException();
}
<<<<<<< .mine
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void DrawInstancedPrimitives(PrimitiveType primitiveType,
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
int primitiveCount, int instanceCount)
{
throw new NotImplementedException();
}
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType,
T[] vertexData, int vertexOffset, int numVertices, Array indexData,
int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration,
IndexElementSize indexFormat) where T : struct, IVertexType
{
throw new NotImplementedException();
}
public void DrawUserPrimitives<T>(PrimitiveType primitiveType,
T[] vertexData, int vertexOffset, int primitiveCount,
VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
}
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset,
int primitiveCount)
{
throw new NotImplementedException();
}
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
{
throw new NotImplementedException();
}
public void SetIndexBuffer(IndexBuffer indexBuffer)
{
throw new NotImplementedException();
}
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
{
throw new NotImplementedException();
}
public void GetBackBufferData<T>(Rectangle? rect, T[] data,
int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
public void GetBackBufferData<T>(T[] data) where T : struct
{
throw new NotImplementedException();
}
public void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
public void ResizeBuffers(PresentationParameters presentationParameters) public void ResizeBuffers(PresentationParameters presentationParameters)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
=======
public void GetBackBufferData<T>(T[] data, int startIndex,
int elementCount) where T : struct
{
throw new NotImplementedException();
}
}
>>>>>>> .r12199
} }

View File

@ -35,4 +35,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyVersion("0.4.1.*")] [assembly: AssemblyVersion("0.4.1.*")]
[assembly: AssemblyFileVersion("0.4.1.0")] [assembly: AssemblyFileVersion("0.4.1.0")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.DX10")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.DX11.1")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.GL3")] [assembly:InternalsVisibleTo("ANX.Framework.Windows.GL3")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.Kinect")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.XInput")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.XAudio")]

View File

@ -89,7 +89,7 @@ namespace WindowsGame1
protected override void LoadContent() protected override void LoadContent()
{ {
// Create a new SpriteBatch, which can be used to draw textures. // Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice); //TODO: spriteBatch = new SpriteBatch(GraphicsDevice);
} }
/// <summary> /// <summary>