Use explicit shader attributes.

This commit is contained in:
Paul Chote
2015-12-19 23:57:52 +00:00
parent 788def1c31
commit be29ec5342
11 changed files with 64 additions and 38 deletions

View File

@@ -91,9 +91,9 @@ namespace OpenRA.Platforms.Default
throw new InvalidProgramException("Missing OpenGL extension GL_EXT_framebuffer_object. See graphics.log for details.");
}
GL.EnableClientState(ArrayCap.VertexArray);
GL.EnableVertexAttribArray(Shader.VertexPosAttributeIndex);
ErrorHandler.CheckGlError();
GL.EnableClientState(ArrayCap.TextureCoordArray);
GL.EnableVertexAttribArray(Shader.TexCoordAttributeIndex);
ErrorHandler.CheckGlError();
SDL.SDL_SetModState(SDL.SDL_Keymod.KMOD_NONE);

View File

@@ -18,6 +18,9 @@ namespace OpenRA.Platforms.Default
{
class Shader : ThreadAffine, IShader
{
public const int VertexPosAttributeIndex = 0;
public const int TexCoordAttributeIndex = 1;
readonly Dictionary<string, int> samplers = new Dictionary<string, int>();
readonly Dictionary<int, ITexture> textures = new Dictionary<int, ITexture>();
readonly int program;
@@ -62,6 +65,12 @@ namespace OpenRA.Platforms.Default
// Assemble program
program = GL.CreateProgram();
ErrorHandler.CheckGlError();
GL.BindAttribLocation(program, VertexPosAttributeIndex, "aVertexPosition");
ErrorHandler.CheckGlError();
GL.BindAttribLocation(program, TexCoordAttributeIndex, "aVertexTexCoord");
ErrorHandler.CheckGlError();
GL.AttachShader(program, vertexShader);
ErrorHandler.CheckGlError();
GL.AttachShader(program, fragmentShader);

View File

@@ -63,9 +63,9 @@ namespace OpenRA.Platforms.Default
VerifyThreadAffinity();
GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
ErrorHandler.CheckGlError();
GL.VertexPointer(3, VertexPointerType.Float, VertexSize, IntPtr.Zero);
GL.VertexAttribPointer(Shader.VertexPosAttributeIndex, 3, VertexAttribPointerType.Float, false, VertexSize, IntPtr.Zero);
ErrorHandler.CheckGlError();
GL.TexCoordPointer(4, TexCoordPointerType.Float, VertexSize, new IntPtr(12));
GL.VertexAttribPointer(Shader.TexCoordAttributeIndex, 4, VertexAttribPointerType.Float, false, VertexSize, new IntPtr(12));
ErrorHandler.CheckGlError();
}