GL error logging
This commit is contained in:
committed by
Chris Forbes
parent
0dddf12831
commit
4ca4d7b5dd
479
OpenRA.Gl/GraphicsDevice.cs
Normal file → Executable file
479
OpenRA.Gl/GraphicsDevice.cs
Normal file → Executable file
@@ -6,252 +6,263 @@
|
|||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
* see LICENSE.
|
* see LICENSE.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using OpenRA.FileFormats.Graphics;
|
using OpenRA.FileFormats.Graphics;
|
||||||
using Tao.Cg;
|
using Tao.Cg;
|
||||||
using Tao.OpenGl;
|
using Tao.OpenGl;
|
||||||
using Tao.Sdl;
|
using Tao.Sdl;
|
||||||
|
|
||||||
[assembly: Renderer( typeof( OpenRA.GlRenderer.GraphicsDevice ))]
|
[assembly: Renderer(typeof(OpenRA.GlRenderer.GraphicsDevice))]
|
||||||
|
|
||||||
namespace OpenRA.GlRenderer
|
namespace OpenRA.GlRenderer
|
||||||
{
|
{
|
||||||
public class GraphicsDevice : IGraphicsDevice
|
public class GraphicsDevice : IGraphicsDevice
|
||||||
{
|
{
|
||||||
Size windowSize;
|
Size windowSize;
|
||||||
internal IntPtr cgContext;
|
internal IntPtr cgContext;
|
||||||
internal int vertexProfile, fragmentProfile;
|
internal int vertexProfile, fragmentProfile;
|
||||||
|
|
||||||
IntPtr surf;
|
IntPtr surf;
|
||||||
|
|
||||||
public Size WindowSize { get { return windowSize; } }
|
public Size WindowSize { get { return windowSize; } }
|
||||||
|
|
||||||
internal static void CheckGlError()
|
public enum GlError
|
||||||
{
|
{
|
||||||
var n = Gl.glGetError();
|
GL_NO_ERROR = Gl.GL_NO_ERROR,
|
||||||
if (n != Gl.GL_NO_ERROR)
|
GL_INVALID_ENUM = Gl.GL_INVALID_ENUM,
|
||||||
throw new InvalidOperationException("GL Error");
|
GL_INVALID_VALUE = Gl.GL_INVALID_VALUE,
|
||||||
}
|
GL_STACK_OVERFLOW = Gl.GL_STACK_OVERFLOW,
|
||||||
|
GL_STACK_UNDERFLOW = Gl.GL_STACK_UNDERFLOW,
|
||||||
|
GL_OUT_OF_MEMORY = Gl.GL_OUT_OF_MEMORY,
|
||||||
|
GL_TABLE_TOO_LARGE = Gl.GL_TABLE_TOO_LARGE,
|
||||||
|
}
|
||||||
|
|
||||||
public GraphicsDevice(int width, int height, WindowMode window, bool vsync)
|
internal static void CheckGlError()
|
||||||
{
|
{
|
||||||
Sdl.SDL_Init(Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO);
|
var n = Gl.glGetError();
|
||||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1);
|
if (n != Gl.GL_NO_ERROR)
|
||||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 8);
|
throw new InvalidOperationException("GL Error: " + ((GlError)n).ToString());
|
||||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_GREEN_SIZE, 8);
|
}
|
||||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8);
|
|
||||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 0);
|
|
||||||
|
|
||||||
int windowFlags = 0;
|
|
||||||
switch( window )
|
|
||||||
{
|
|
||||||
case WindowMode.Fullscreen:
|
|
||||||
windowFlags |= Sdl.SDL_FULLSCREEN;
|
|
||||||
break;
|
|
||||||
case WindowMode.PseudoFullscreen:
|
|
||||||
// pseudo-fullscreen only reliably works on windows; fall back to fullscreen for everyone else
|
|
||||||
windowFlags |= ( Environment.OSVersion.Platform == PlatformID.Win32NT ) ? Sdl.SDL_NOFRAME : Sdl.SDL_FULLSCREEN;
|
|
||||||
Environment.SetEnvironmentVariable( "SDL_VIDEO_WINDOW_POS", "0,0" );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | windowFlags);
|
|
||||||
|
|
||||||
Sdl.SDL_WM_SetCaption("OpenRA", "OpenRA");
|
|
||||||
Sdl.SDL_ShowCursor(0);
|
|
||||||
Sdl.SDL_EnableUNICODE(1);
|
|
||||||
Sdl.SDL_EnableKeyRepeat(Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL);
|
|
||||||
|
|
||||||
CheckGlError();
|
public GraphicsDevice(int width, int height, WindowMode window, bool vsync)
|
||||||
|
{
|
||||||
|
Sdl.SDL_Init(Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO);
|
||||||
|
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 8);
|
||||||
|
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_GREEN_SIZE, 8);
|
||||||
|
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8);
|
||||||
|
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 0);
|
||||||
|
|
||||||
windowSize = new Size(width, height);
|
int windowFlags = 0;
|
||||||
|
switch (window)
|
||||||
|
{
|
||||||
|
case WindowMode.Fullscreen:
|
||||||
|
windowFlags |= Sdl.SDL_FULLSCREEN;
|
||||||
|
break;
|
||||||
|
case WindowMode.PseudoFullscreen:
|
||||||
|
// pseudo-fullscreen only reliably works on windows; fall back to fullscreen for everyone else
|
||||||
|
windowFlags |= (Environment.OSVersion.Platform == PlatformID.Win32NT) ? Sdl.SDL_NOFRAME : Sdl.SDL_FULLSCREEN;
|
||||||
|
Environment.SetEnvironmentVariable("SDL_VIDEO_WINDOW_POS", "0,0");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
cgContext = Cg.cgCreateContext();
|
surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | windowFlags);
|
||||||
|
|
||||||
Cg.cgSetErrorCallback(CgErrorCallback);
|
Sdl.SDL_WM_SetCaption("OpenRA", "OpenRA");
|
||||||
|
Sdl.SDL_ShowCursor(0);
|
||||||
|
Sdl.SDL_EnableUNICODE(1);
|
||||||
|
Sdl.SDL_EnableKeyRepeat(Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL);
|
||||||
|
|
||||||
CgGl.cgGLRegisterStates(cgContext);
|
CheckGlError();
|
||||||
CgGl.cgGLSetManageTextureParameters(cgContext, true);
|
|
||||||
vertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX);
|
|
||||||
fragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT);
|
|
||||||
|
|
||||||
//Console.WriteLine("VP Profile: " + vertexProfile);
|
windowSize = new Size(width, height);
|
||||||
//Console.WriteLine("FP Profile: " + fragmentProfile);
|
|
||||||
|
|
||||||
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
|
cgContext = Cg.cgCreateContext();
|
||||||
CheckGlError();
|
|
||||||
Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
|
|
||||||
CheckGlError();
|
|
||||||
|
|
||||||
Sdl.SDL_SetModState(0); // i have had enough.
|
Cg.cgSetErrorCallback(CgErrorCallback);
|
||||||
}
|
|
||||||
|
|
||||||
static Cg.CGerrorCallbackFuncDelegate CgErrorCallback = () =>
|
CgGl.cgGLRegisterStates(cgContext);
|
||||||
{
|
CgGl.cgGLSetManageTextureParameters(cgContext, true);
|
||||||
var err = Cg.cgGetError();
|
vertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX);
|
||||||
var str = Cg.cgGetErrorString(err);
|
fragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT);
|
||||||
throw new InvalidOperationException(
|
|
||||||
string.Format("CG Error: {0}: {1}", err, str));
|
|
||||||
};
|
|
||||||
|
|
||||||
public void EnableScissor(int left, int top, int width, int height)
|
//Console.WriteLine("VP Profile: " + vertexProfile);
|
||||||
{
|
//Console.WriteLine("FP Profile: " + fragmentProfile);
|
||||||
if (width < 0) width = 0;
|
|
||||||
if (height < 0) height = 0;
|
|
||||||
Gl.glScissor(left, windowSize.Height - (top + height), width, height);
|
|
||||||
CheckGlError();
|
|
||||||
Gl.glEnable(Gl.GL_SCISSOR_TEST);
|
|
||||||
CheckGlError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DisableScissor()
|
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
|
||||||
{
|
CheckGlError();
|
||||||
Gl.glDisable(Gl.GL_SCISSOR_TEST);
|
Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
|
||||||
|
|
||||||
public void Begin() { }
|
Sdl.SDL_SetModState(0); // i have had enough.
|
||||||
public void End() { }
|
}
|
||||||
|
|
||||||
public void Clear(Color c)
|
static Cg.CGerrorCallbackFuncDelegate CgErrorCallback = () =>
|
||||||
{
|
{
|
||||||
Gl.glClearColor(0, 0, 0, 0);
|
var err = Cg.cgGetError();
|
||||||
CheckGlError();
|
var str = Cg.cgGetErrorString(err);
|
||||||
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
|
throw new InvalidOperationException(
|
||||||
CheckGlError();
|
string.Format("CG Error: {0}: {1}", err, str));
|
||||||
}
|
};
|
||||||
|
|
||||||
MouseButtons lastButtonBits = (MouseButtons)0;
|
public void EnableScissor(int left, int top, int width, int height)
|
||||||
|
{
|
||||||
|
if (width < 0) width = 0;
|
||||||
|
if (height < 0) height = 0;
|
||||||
|
Gl.glScissor(left, windowSize.Height - (top + height), width, height);
|
||||||
|
CheckGlError();
|
||||||
|
Gl.glEnable(Gl.GL_SCISSOR_TEST);
|
||||||
|
CheckGlError();
|
||||||
|
}
|
||||||
|
|
||||||
static MouseButtons MakeButton(byte b)
|
public void DisableScissor()
|
||||||
{
|
{
|
||||||
return b == Sdl.SDL_BUTTON_LEFT ? MouseButtons.Left
|
Gl.glDisable(Gl.GL_SCISSOR_TEST);
|
||||||
: b == Sdl.SDL_BUTTON_RIGHT ? MouseButtons.Right
|
CheckGlError();
|
||||||
: b == Sdl.SDL_BUTTON_MIDDLE ? MouseButtons.Middle
|
}
|
||||||
: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Modifiers MakeModifiers(int raw)
|
public void Begin() { }
|
||||||
{
|
public void End() { }
|
||||||
return ((raw & Sdl.KMOD_ALT) != 0 ? Modifiers.Alt : 0)
|
|
||||||
| ((raw & Sdl.KMOD_CTRL) != 0 ? Modifiers.Ctrl : 0)
|
|
||||||
| ((raw & Sdl.KMOD_SHIFT) != 0 ? Modifiers.Shift : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HandleSpecialKey(KeyInput k)
|
public void Clear(Color c)
|
||||||
{
|
{
|
||||||
switch (k.VirtKey)
|
Gl.glClearColor(0, 0, 0, 0);
|
||||||
{
|
CheckGlError();
|
||||||
case Sdl.SDLK_F13:
|
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
|
||||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
|
CheckGlError();
|
||||||
+ Path.DirectorySeparatorChar + DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddThhmmssZ") + ".bmp";
|
}
|
||||||
Sdl.SDL_SaveBMP(surf, path);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case Sdl.SDLK_F4:
|
MouseButtons lastButtonBits = (MouseButtons)0;
|
||||||
if (k.Modifiers.HasModifier(Modifiers.Alt))
|
|
||||||
{
|
|
||||||
OpenRA.Game.Exit();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
default:
|
static MouseButtons MakeButton(byte b)
|
||||||
return false;
|
{
|
||||||
}
|
return b == Sdl.SDL_BUTTON_LEFT ? MouseButtons.Left
|
||||||
}
|
: b == Sdl.SDL_BUTTON_RIGHT ? MouseButtons.Right
|
||||||
|
: b == Sdl.SDL_BUTTON_MIDDLE ? MouseButtons.Middle
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
public void Present()
|
static Modifiers MakeModifiers(int raw)
|
||||||
{
|
{
|
||||||
Sdl.SDL_GL_SwapBuffers();
|
return ((raw & Sdl.KMOD_ALT) != 0 ? Modifiers.Alt : 0)
|
||||||
|
| ((raw & Sdl.KMOD_CTRL) != 0 ? Modifiers.Ctrl : 0)
|
||||||
|
| ((raw & Sdl.KMOD_SHIFT) != 0 ? Modifiers.Shift : 0);
|
||||||
|
}
|
||||||
|
|
||||||
var mods = MakeModifiers(Sdl.SDL_GetModState());
|
bool HandleSpecialKey(KeyInput k)
|
||||||
Game.HandleModifierKeys(mods);
|
{
|
||||||
|
switch (k.VirtKey)
|
||||||
|
{
|
||||||
|
case Sdl.SDLK_F13:
|
||||||
|
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
|
||||||
|
+ Path.DirectorySeparatorChar + DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddThhmmssZ") + ".bmp";
|
||||||
|
Sdl.SDL_SaveBMP(surf, path);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case Sdl.SDLK_F4:
|
||||||
|
if (k.Modifiers.HasModifier(Modifiers.Alt))
|
||||||
|
{
|
||||||
|
OpenRA.Game.Exit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Present()
|
||||||
|
{
|
||||||
|
Sdl.SDL_GL_SwapBuffers();
|
||||||
|
|
||||||
|
var mods = MakeModifiers(Sdl.SDL_GetModState());
|
||||||
|
Game.HandleModifierKeys(mods);
|
||||||
MouseEventArgs pendingMotion = null;
|
MouseEventArgs pendingMotion = null;
|
||||||
|
|
||||||
Sdl.SDL_Event e;
|
Sdl.SDL_Event e;
|
||||||
while (Sdl.SDL_PollEvent(out e) != 0)
|
while (Sdl.SDL_PollEvent(out e) != 0)
|
||||||
{
|
{
|
||||||
switch (e.type)
|
switch (e.type)
|
||||||
{
|
{
|
||||||
case Sdl.SDL_QUIT:
|
case Sdl.SDL_QUIT:
|
||||||
OpenRA.Game.Exit();
|
OpenRA.Game.Exit();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEBUTTONDOWN:
|
case Sdl.SDL_MOUSEBUTTONDOWN:
|
||||||
{
|
{
|
||||||
if (pendingMotion != null)
|
if (pendingMotion != null)
|
||||||
{
|
{
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
||||||
pendingMotion = null;
|
pendingMotion = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var button = MakeButton(e.button.button);
|
var button = MakeButton(e.button.button);
|
||||||
lastButtonBits |= button;
|
lastButtonBits |= button;
|
||||||
|
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Down,
|
Game.DispatchMouseInput(MouseInputEvent.Down,
|
||||||
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
|
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
|
||||||
mods);
|
mods);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEBUTTONUP:
|
case Sdl.SDL_MOUSEBUTTONUP:
|
||||||
{
|
{
|
||||||
if (pendingMotion != null)
|
if (pendingMotion != null)
|
||||||
{
|
{
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
||||||
pendingMotion = null;
|
pendingMotion = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var button = MakeButton(e.button.button);
|
var button = MakeButton(e.button.button);
|
||||||
lastButtonBits &= ~button;
|
lastButtonBits &= ~button;
|
||||||
|
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Up,
|
Game.DispatchMouseInput(MouseInputEvent.Up,
|
||||||
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
|
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
|
||||||
mods);
|
mods);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEMOTION:
|
case Sdl.SDL_MOUSEMOTION:
|
||||||
{
|
{
|
||||||
pendingMotion = new MouseEventArgs(lastButtonBits, 0, e.motion.x, e.motion.y, 0);
|
pendingMotion = new MouseEventArgs(lastButtonBits, 0, e.motion.x, e.motion.y, 0);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Sdl.SDL_KEYDOWN:
|
case Sdl.SDL_KEYDOWN:
|
||||||
{
|
{
|
||||||
var keyEvent = new KeyInput
|
var keyEvent = new KeyInput
|
||||||
{
|
{
|
||||||
Event = KeyInputEvent.Down,
|
Event = KeyInputEvent.Down,
|
||||||
Modifiers = mods,
|
Modifiers = mods,
|
||||||
KeyChar = (char) e.key.keysym.unicode,
|
KeyChar = (char)e.key.keysym.unicode,
|
||||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
|
||||||
VirtKey = e.key.keysym.sym
|
VirtKey = e.key.keysym.sym
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!HandleSpecialKey(keyEvent))
|
if (!HandleSpecialKey(keyEvent))
|
||||||
Game.HandleKeyEvent(keyEvent);
|
Game.HandleKeyEvent(keyEvent);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Sdl.SDL_KEYUP:
|
case Sdl.SDL_KEYUP:
|
||||||
{
|
{
|
||||||
var keyEvent = new KeyInput
|
var keyEvent = new KeyInput
|
||||||
{
|
{
|
||||||
Event = KeyInputEvent.Up,
|
Event = KeyInputEvent.Up,
|
||||||
Modifiers = mods,
|
Modifiers = mods,
|
||||||
KeyChar = (char) e.key.keysym.unicode,
|
KeyChar = (char)e.key.keysym.unicode,
|
||||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
|
||||||
VirtKey = e.key.keysym.sym
|
VirtKey = e.key.keysym.sym
|
||||||
};
|
};
|
||||||
|
|
||||||
Game.HandleKeyEvent(keyEvent);
|
Game.HandleKeyEvent(keyEvent);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pendingMotion != null)
|
if (pendingMotion != null)
|
||||||
{
|
{
|
||||||
@@ -259,49 +270,49 @@ namespace OpenRA.GlRenderer
|
|||||||
pendingMotion = null;
|
pendingMotion = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices)
|
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices)
|
||||||
{
|
{
|
||||||
Gl.glDrawElements(ModeFromPrimitiveType(pt), indices.End - indices.Start,
|
Gl.glDrawElements(ModeFromPrimitiveType(pt), indices.End - indices.Start,
|
||||||
Gl.GL_UNSIGNED_SHORT, new IntPtr(indices.Start * 2));
|
Gl.GL_UNSIGNED_SHORT, new IntPtr(indices.Start * 2));
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives)
|
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives)
|
||||||
{
|
{
|
||||||
Gl.glDrawElements(ModeFromPrimitiveType(pt), numPrimitives * IndicesPerPrimitive(pt),
|
Gl.glDrawElements(ModeFromPrimitiveType(pt), numPrimitives * IndicesPerPrimitive(pt),
|
||||||
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero);
|
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero);
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ModeFromPrimitiveType(PrimitiveType pt)
|
static int ModeFromPrimitiveType(PrimitiveType pt)
|
||||||
{
|
{
|
||||||
switch (pt)
|
switch (pt)
|
||||||
{
|
{
|
||||||
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
||||||
case PrimitiveType.LineList: return Gl.GL_LINES;
|
case PrimitiveType.LineList: return Gl.GL_LINES;
|
||||||
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
|
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
|
||||||
}
|
}
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int IndicesPerPrimitive(PrimitiveType pt)
|
static int IndicesPerPrimitive(PrimitiveType pt)
|
||||||
{
|
{
|
||||||
switch (pt)
|
switch (pt)
|
||||||
{
|
{
|
||||||
case PrimitiveType.PointList: return 1;
|
case PrimitiveType.PointList: return 1;
|
||||||
case PrimitiveType.LineList: return 2;
|
case PrimitiveType.LineList: return 2;
|
||||||
case PrimitiveType.TriangleList: return 3;
|
case PrimitiveType.TriangleList: return 3;
|
||||||
}
|
}
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new VertexBuffer<Vertex>(this, size); }
|
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new VertexBuffer<Vertex>(this, size); }
|
||||||
public IIndexBuffer CreateIndexBuffer(int size) { return new IndexBuffer(this, size); }
|
public IIndexBuffer CreateIndexBuffer(int size) { return new IndexBuffer(this, size); }
|
||||||
public ITexture CreateTexture() { return new Texture(this); }
|
public ITexture CreateTexture() { return new Texture(this); }
|
||||||
public ITexture CreateTexture(Bitmap bitmap) { return new Texture(this, bitmap); }
|
public ITexture CreateTexture(Bitmap bitmap) { return new Texture(this, bitmap); }
|
||||||
public IShader CreateShader(Stream stream) { return new Shader(this, stream); }
|
public IShader CreateShader(Stream stream) { return new Shader(this, stream); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user