mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-23 12:32:13 +00:00
- use explicit vertex attributes for everything.
No more glVertex, glTexCoord or glColor calls anywhere.
This commit is contained in:
parent
0720ad5fd5
commit
3d538b4c8f
7 changed files with 44 additions and 34 deletions
|
@ -71,10 +71,9 @@ bool FShader::Load(const char * name, const char * vert_prog, const char * frag_
|
|||
glAttachShader(hShader, hVertProg);
|
||||
glAttachShader(hShader, hFragProg);
|
||||
|
||||
//glBindAttribLocation(hShader, VATTR_VERTEX, "aPosition");
|
||||
//glBindAttribLocation(hShader, VATTR_TEXCOORD, "aTexCoord");
|
||||
//glBindAttribLocation(hShader, VATTR_COLOR, "aColor");
|
||||
//glBindAttribLocation(hShader, VATTR_VERTEX2, "aVertex2");
|
||||
glBindAttribLocation(hShader, 0, "i_vertPos");
|
||||
glBindAttribLocation(hShader, 1, "i_texCoord");
|
||||
glBindAttribLocation(hShader, 2, "i_color");
|
||||
|
||||
glLinkProgram(hShader);
|
||||
|
||||
|
@ -200,10 +199,7 @@ bool SurfaceShader::Load(const char* name, const char* vert_prog, const char* fr
|
|||
glUniform1i(SamplerLoc, 0);
|
||||
SamplerLoc = glGetUniformLocation(hShader, "s_palette");
|
||||
glUniform1i(SamplerLoc, 1);
|
||||
|
||||
glBindAttribLocation(hShader, 0, "i_vertPos");
|
||||
glBindAttribLocation(hShader, 1, "i_texCoord");
|
||||
|
||||
|
||||
glUseProgram(0);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -172,8 +172,8 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count)
|
|||
auto p = &Buffer[start];
|
||||
for (size_t i = 0; i < count; i++, p++)
|
||||
{
|
||||
glTexCoord2f(p->u, p->v);
|
||||
glVertex3f(p->x, p->y, p->z);
|
||||
glVertexAttrib2f(1, p->u, p->v);
|
||||
glVertexAttrib3f(0, p->x, p->y, p->z);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ void GLInstance::SetCull(int type, int winding)
|
|||
|
||||
void GLInstance::SetColor(float r, float g, float b, float a)
|
||||
{
|
||||
glColor4f(r, g, b, a);
|
||||
glVertexAttrib4f(2, r, g, b, a);
|
||||
}
|
||||
|
||||
void GLInstance::SetDepthFunc(int func)
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
// YUV->RGB conversion fragment shader adapted from
|
||||
// http://www.fourcc.org/fccyvrgb.php: Want some sample code?
|
||||
// direct link: http://www.fourcc.org/source/YUV420P-OpenGL-GLSLang.c
|
||||
#version 120
|
||||
#version 330
|
||||
|
||||
uniform sampler2D tex;
|
||||
in vec2 v_texCoord;
|
||||
out vec4 FragColor;
|
||||
|
||||
void main(void) {
|
||||
|
||||
float r,g,b,y,u,v;
|
||||
vec3 yuv;
|
||||
|
||||
yuv = texture2D(tex, gl_TexCoord[0].st).rgb;
|
||||
yuv = texture2D(tex, v_texCoord.st).rgb;
|
||||
y = yuv.r;
|
||||
u = yuv.g;
|
||||
v = yuv.b;
|
||||
|
@ -23,5 +25,5 @@ void main(void) {
|
|||
g = y - 0.39173*u - 0.81290*v;
|
||||
b = y + 2.017*u;
|
||||
|
||||
gl_FragColor = vec4(r,g,b,1.0);
|
||||
FragColor = vec4(r,g,b,1.0);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
#version 110
|
||||
#version 330
|
||||
|
||||
in vec4 i_vertPos;
|
||||
in vec4 i_texCoord;
|
||||
|
||||
out vec2 v_texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = gl_Vertex;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_Position = i_vertPos;
|
||||
v_texCoord = i_texCoord.st;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ uniform sampler2D s_texture;
|
|||
uniform sampler2D s_palette;
|
||||
|
||||
in vec2 v_texCoord;
|
||||
out vec4 FragColor;
|
||||
|
||||
const float c_paletteScale = 255.0/256.0;
|
||||
const float c_paletteOffset = 0.5/256.0;
|
||||
|
@ -16,5 +17,5 @@ void main()
|
|||
color.r = c_paletteOffset + c_paletteScale*color.r;
|
||||
color.rgb = texture2D(s_palette, color.rg).rgb;
|
||||
|
||||
gl_FragColor = color;
|
||||
FragColor = color;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#version 330
|
||||
|
||||
attribute vec4 i_vertPos;
|
||||
attribute vec2 i_texCoord;
|
||||
in vec4 i_vertPos;
|
||||
in vec4 i_texCoord;
|
||||
|
||||
out vec2 v_texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = i_vertPos;
|
||||
v_texCoord = i_texCoord;
|
||||
v_texCoord = i_texCoord.st;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#version 120
|
||||
#version 330
|
||||
|
||||
varying vec4 v_color;
|
||||
varying float v_distance;
|
||||
varying vec4 v_texCoord;
|
||||
varying vec4 v_detailCoord;
|
||||
varying vec4 v_glowCoord;
|
||||
varying float v_fogCoord;
|
||||
out vec4 v_color;
|
||||
out float v_distance;
|
||||
out vec4 v_texCoord;
|
||||
out vec4 v_detailCoord;
|
||||
out vec4 v_glowCoord;
|
||||
out float v_fogCoord;
|
||||
|
||||
uniform float u_usePalette;
|
||||
uniform mat4 u_rotMatrix;
|
||||
|
@ -14,25 +14,30 @@ uniform mat4 u_projectionMatrix;
|
|||
uniform mat4 u_detailMatrix;
|
||||
uniform mat4 u_glowMatrix;
|
||||
|
||||
in vec4 i_vertPos;
|
||||
in vec4 i_texCoord;
|
||||
in vec4 i_color;
|
||||
|
||||
|
||||
const float c_zero = 0.0;
|
||||
const float c_one = 1.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 vertex = u_rotMatrix * gl_Vertex;
|
||||
vec4 vertex = u_rotMatrix * i_vertPos;
|
||||
vec4 eyeCoordPosition = u_modelMatrix * vertex;
|
||||
gl_Position = u_projectionMatrix * eyeCoordPosition;
|
||||
|
||||
eyeCoordPosition.xyz /= eyeCoordPosition.w;
|
||||
|
||||
v_texCoord = gl_MultiTexCoord0;
|
||||
v_texCoord = i_texCoord;
|
||||
//gl_TexCoord[0] = mix(gl_TexCoord[0].xyzw, gl_TexCoord[0].yxzw, u_usePalette); WTF is this???
|
||||
|
||||
v_detailCoord = u_detailMatrix * gl_MultiTexCoord0;
|
||||
v_glowCoord = u_glowMatrix * gl_MultiTexCoord0;
|
||||
v_detailCoord = u_detailMatrix * i_texCoord;
|
||||
v_glowCoord = u_glowMatrix * i_texCoord;
|
||||
|
||||
v_fogCoord = abs(eyeCoordPosition.z);
|
||||
|
||||
v_color = gl_Color;
|
||||
v_distance = gl_Vertex.z;
|
||||
v_color = i_color;
|
||||
v_distance = i_vertPos.z;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue