Use explicit shader attributes.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
varying vec4 vColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = gl_Color;
|
||||
gl_FragColor = vColor;
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
uniform vec2 Scroll;
|
||||
uniform vec2 r1, r2; // matrix elements
|
||||
uniform vec2 r1, r2;
|
||||
|
||||
attribute vec4 aVertexPosition;
|
||||
attribute vec4 aVertexTexCoord;
|
||||
varying vec4 vColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 p = (gl_Vertex.xy - Scroll.xy)*r1 + r2;
|
||||
vec2 p = (aVertexPosition.xy - Scroll.xy)*r1 + r2;
|
||||
gl_Position = vec4(p.x,p.y,0,1);
|
||||
gl_FrontColor = gl_MultiTexCoord0;
|
||||
vColor = aVertexTexCoord;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
uniform sampler2D DiffuseTexture;
|
||||
varying vec4 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(DiffuseTexture,gl_TexCoord[0].st);
|
||||
gl_FragColor = texture2D(DiffuseTexture, vTexCoord.st);
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
uniform vec2 Scroll;
|
||||
uniform vec2 r1, r2;
|
||||
|
||||
attribute vec4 aVertexPosition;
|
||||
attribute vec4 aVertexTexCoord;
|
||||
varying vec4 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 p = (gl_Vertex.xy - Scroll.xy)*r1 + r2;
|
||||
vec2 p = (aVertexPosition.xy - Scroll.xy)*r1 + r2;
|
||||
gl_Position = vec4(p.x,p.y,0,1);
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
vTexCoord = aVertexTexCoord;
|
||||
}
|
||||
|
||||
@@ -2,23 +2,23 @@ uniform sampler2D DiffuseTexture, Palette;
|
||||
|
||||
uniform bool EnableDepthPreview;
|
||||
|
||||
varying vec4 TexCoord;
|
||||
varying vec4 ChannelMask;
|
||||
varying vec4 DepthMask;
|
||||
varying vec4 vTexCoord;
|
||||
varying vec4 vChannelMask;
|
||||
varying vec4 vDepthMask;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 x = texture2D(DiffuseTexture, TexCoord.st);
|
||||
vec2 p = vec2(dot(x, ChannelMask), TexCoord.p);
|
||||
vec4 x = texture2D(DiffuseTexture, vTexCoord.st);
|
||||
vec2 p = vec2(dot(x, vChannelMask), vTexCoord.p);
|
||||
vec4 c = texture2D(Palette, p);
|
||||
|
||||
// Discard any transparent fragments (both color and depth)
|
||||
if (c.a == 0.0)
|
||||
discard;
|
||||
|
||||
if (EnableDepthPreview && length(DepthMask) > 0.0)
|
||||
if (EnableDepthPreview && length(vDepthMask) > 0.0)
|
||||
{
|
||||
float depth = dot(x, DepthMask);
|
||||
float depth = dot(x, vDepthMask);
|
||||
gl_FragColor = vec4(depth, depth, depth, 1);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
uniform vec2 Scroll;
|
||||
uniform vec2 r1,r2; // matrix elements
|
||||
|
||||
varying vec4 TexCoord;
|
||||
varying vec4 ChannelMask;
|
||||
varying vec4 DepthMask;
|
||||
attribute vec4 aVertexPosition;
|
||||
attribute vec4 aVertexTexCoord;
|
||||
varying vec4 vTexCoord;
|
||||
varying vec4 vChannelMask;
|
||||
varying vec4 vDepthMask;
|
||||
|
||||
vec4 DecodeChannelMask(float x)
|
||||
{
|
||||
@@ -34,9 +36,9 @@ vec4 DecodeDepthChannelMask(float x)
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 p = (gl_Vertex.xy - Scroll.xy) * r1 + r2;
|
||||
vec2 p = (aVertexPosition.xy - Scroll.xy) * r1 + r2;
|
||||
gl_Position = vec4(p.x,p.y,0,1);
|
||||
TexCoord = gl_MultiTexCoord0;
|
||||
ChannelMask = DecodeChannelMask(gl_MultiTexCoord0.w);
|
||||
DepthMask = DecodeDepthChannelMask(gl_MultiTexCoord0.w);
|
||||
vTexCoord = aVertexTexCoord;
|
||||
vChannelMask = DecodeChannelMask(aVertexTexCoord.w);
|
||||
vDepthMask = DecodeDepthChannelMask(aVertexTexCoord.w);
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ uniform vec2 PaletteRows;
|
||||
uniform vec4 LightDirection;
|
||||
uniform vec3 AmbientLight, DiffuseLight;
|
||||
|
||||
varying vec4 TexCoord;
|
||||
varying vec4 ChannelMask;
|
||||
varying vec4 NormalsMask;
|
||||
varying vec4 vTexCoord;
|
||||
varying vec4 vChannelMask;
|
||||
varying vec4 vNormalsMask;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 x = texture2D(DiffuseTexture, TexCoord.st);
|
||||
vec4 color = texture2D(Palette, vec2(dot(x, ChannelMask), PaletteRows.x));
|
||||
vec4 x = texture2D(DiffuseTexture, vTexCoord.st);
|
||||
vec4 color = texture2D(Palette, vec2(dot(x, vChannelMask), PaletteRows.x));
|
||||
if (color.a < 0.01)
|
||||
discard;
|
||||
|
||||
vec4 normal = (2.0 * texture2D(Palette, vec2(dot(x, NormalsMask), PaletteRows.y)) - 1.0);
|
||||
vec4 normal = (2.0 * texture2D(Palette, vec2(dot(x, vNormalsMask), PaletteRows.y)) - 1.0);
|
||||
vec3 intensity = AmbientLight + DiffuseLight * max(dot(normal, LightDirection), 0.0);
|
||||
gl_FragColor = vec4(intensity * color.rgb, color.a);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
uniform mat4 View;
|
||||
uniform mat4 TransformMatrix;
|
||||
|
||||
varying vec4 TexCoord;
|
||||
varying vec4 ChannelMask;
|
||||
varying vec4 NormalsMask;
|
||||
attribute vec4 aVertexPosition;
|
||||
attribute vec4 aVertexTexCoord;
|
||||
varying vec4 vTexCoord;
|
||||
varying vec4 vChannelMask;
|
||||
varying vec4 vNormalsMask;
|
||||
|
||||
vec4 DecodeMask(float x)
|
||||
{
|
||||
@@ -15,8 +17,8 @@ vec4 DecodeMask(float x)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = View*TransformMatrix*gl_Vertex;
|
||||
TexCoord = gl_MultiTexCoord0;
|
||||
ChannelMask = DecodeMask(gl_MultiTexCoord0.z);
|
||||
NormalsMask = DecodeMask(gl_MultiTexCoord0.w);
|
||||
gl_Position = View*TransformMatrix*aVertexPosition;
|
||||
vTexCoord = aVertexTexCoord;
|
||||
vChannelMask = DecodeMask(aVertexTexCoord.z);
|
||||
vNormalsMask = DecodeMask(aVertexTexCoord.w);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user