diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 0c6ab93..87c86d5 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -276,16 +276,16 @@ void CNew3D::RenderFrame(void) } } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + glEnableVertexAttribArray(3); // before draw, specify vertex and index arrays with their offsets, offsetof is maybe evil .. - glVertexPointer (3, GL_FLOAT, sizeof(Vertex), 0); - glNormalPointer (GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, normal)); - glTexCoordPointer (2, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, texcoords)); - glColorPointer (4, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, color)); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, normal)); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texcoords)); + glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, color)); m_r3dShader.SetShader(true); @@ -315,10 +315,10 @@ void CNew3D::RenderFrame(void) glDisable(GL_STENCIL_TEST); glDisable(GL_CULL_FACE); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); + glDisableVertexAttribArray(0); + glDisableVertexAttribArray(1); + glDisableVertexAttribArray(2); + glDisableVertexAttribArray(3); } void CNew3D::BeginFrame(void) diff --git a/Src/Graphics/New3D/R3DScrollFog.cpp b/Src/Graphics/New3D/R3DScrollFog.cpp index 989f50f..e693bc8 100644 --- a/Src/Graphics/New3D/R3DScrollFog.cpp +++ b/Src/Graphics/New3D/R3DScrollFog.cpp @@ -7,10 +7,11 @@ namespace New3D { static const char *vertexShaderFog = R"glsl( uniform mat4 mvp; +attribute vec3 inVertex; void main(void) { - gl_Position = mvp * gl_Vertex; + gl_Position = mvp * vec4(inVertex,1.0); }; )glsl"; @@ -106,10 +107,10 @@ void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient glUniform4f (m_locSpotEllipse, spotEllipse[0], spotEllipse[1], spotEllipse[2], spotEllipse[3]); glUniformMatrix4fv (m_locMVP, 1, GL_FALSE, mvp); - glEnableClientState (GL_VERTEX_ARRAY); - glVertexPointer (3, GL_FLOAT, sizeof(SFVertex), 0); - glDrawArrays (GL_TRIANGLES, 0, 6); - glDisableClientState(GL_VERTEX_ARRAY); + glEnableVertexAttribArray (0); + glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, sizeof(SFVertex), 0); + glDrawArrays (GL_TRIANGLES, 0, 6); + glDisableVertexAttribArray (0); glUseProgram (0); m_vbo.Bind (false); @@ -129,6 +130,8 @@ void R3DScrollFog::AllocResources() m_locSpotFogColor = glGetUniformLocation(m_shaderProgram, "spotFogColor"); m_locSpotEllipse = glGetUniformLocation(m_shaderProgram, "spotEllipse"); + glBindAttribLocation(m_shaderProgram, 0, "inVertex"); + m_vbo.Create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, sizeof(SFTriangle) * (2), m_triangles); } diff --git a/Src/Graphics/New3D/R3DShader.cpp b/Src/Graphics/New3D/R3DShader.cpp index 9f5ee3a..4a016a7 100644 --- a/Src/Graphics/New3D/R3DShader.cpp +++ b/Src/Graphics/New3D/R3DShader.cpp @@ -13,22 +13,29 @@ uniform float fogDensity; uniform float fogStart; uniform float modelScale; +// attributes +attribute vec3 inVertex; +attribute vec3 inNormal; +attribute vec2 inTexCoord; +attribute vec4 inColour; + // outputs to fragment shader varying float fsFogFactor; varying vec3 fsViewVertex; varying vec3 fsViewNormal; // per vertex normal vector +varying vec2 fsTexCoord; varying vec4 fsColor; void main(void) { - fsViewVertex = vec3(gl_ModelViewMatrix * gl_Vertex); - fsViewNormal = (mat3(gl_ModelViewMatrix) * gl_Normal) / modelScale; + fsViewVertex = vec3(gl_ModelViewMatrix * vec4(inVertex,1.0)); + fsViewNormal = (mat3(gl_ModelViewMatrix) * inNormal) / modelScale; float z = length(fsViewVertex); fsFogFactor = fogIntensity * clamp(fogStart + z * fogDensity, 0.0, 1.0); - fsColor = gl_Color; - gl_TexCoord[0] = gl_MultiTexCoord0; - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + fsColor = inColour; + fsTexCoord = inTexCoord; + gl_Position = gl_ModelViewProjectionMatrix * vec4(inVertex,1.0); } )glsl"; @@ -69,10 +76,11 @@ varying float fsFogFactor; varying vec3 fsViewVertex; varying vec3 fsViewNormal; // per vertex normal vector varying vec4 fsColor; +varying vec2 fsTexCoord; vec4 GetTextureValue() { - vec4 tex1Data = texture2D( tex1, gl_TexCoord[0].st); + vec4 tex1Data = texture2D( tex1, fsTexCoord.st); if(textureInverted) { tex1Data.rgb = vec3(1.0) - vec3(tex1Data.rgb); @@ -80,7 +88,7 @@ vec4 GetTextureValue() if (microTexture) { vec2 scale = baseTexSize/256.0; - vec4 tex2Data = texture2D( tex2, gl_TexCoord[0].st * scale * microTextureScale); + vec4 tex2Data = texture2D( tex2, fsTexCoord.st * scale * microTextureScale); tex1Data = (tex1Data+tex2Data)/2.0; } @@ -299,8 +307,12 @@ bool R3DShader::LoadShader(const char* vertexShader, const char* fragmentShader) m_locSpotColor = glGetUniformLocation(m_shaderProgram, "spotColor"); m_locSpotFogColor = glGetUniformLocation(m_shaderProgram, "spotFogColor"); m_locModelScale = glGetUniformLocation(m_shaderProgram, "modelScale"); - + glBindAttribLocation(m_shaderProgram, 0, "inVertex"); + glBindAttribLocation(m_shaderProgram, 1, "inNormal"); + glBindAttribLocation(m_shaderProgram, 2, "inTexCoord"); + glBindAttribLocation(m_shaderProgram, 3, "inColour"); + return success; } diff --git a/Src/Graphics/New3D/R3DShader.h b/Src/Graphics/New3D/R3DShader.h index dbeb463..d3175c9 100644 --- a/Src/Graphics/New3D/R3DShader.h +++ b/Src/Graphics/New3D/R3DShader.h @@ -32,29 +32,29 @@ private: GLint m_locTexture2Enabled; GLint m_locTextureAlpha; GLint m_locAlphaTest; - GLint m_locMicroTexScale; - GLint m_locBaseTexSize; - GLint m_locTextureInverted; - - // cached mesh values - bool m_textured1; + GLint m_locMicroTexScale; + GLint m_locBaseTexSize; + GLint m_locTextureInverted; + + // cached mesh values + bool m_textured1; bool m_textured2; bool m_textureAlpha; // use alpha in texture bool m_alphaTest; // discard fragment based on alpha (ogl does this with fixed function) float m_fogIntensity; - bool m_doubleSided; - bool m_lightEnabled; - float m_shininess; - float m_specularValue; - bool m_specularEnabled; - - bool m_layered; - float m_microTexScale; - float m_baseTexSize[2]; - bool m_textureInverted; - - // cached model values - enum class MatDet { notset, negative, positive, zero }; + bool m_doubleSided; + bool m_lightEnabled; + float m_shininess; + float m_specularValue; + bool m_specularEnabled; + + bool m_layered; + float m_microTexScale; + float m_baseTexSize[2]; + bool m_textureInverted; + + // cached model values + enum class MatDet { notset, negative, positive, zero }; MatDet m_matDet; float m_modelScale; @@ -73,19 +73,19 @@ private: // lighting / other GLint m_locLighting; GLint m_locLightEnabled; - GLint m_locSunClamp; - GLint m_locIntensityClamp; - GLint m_locShininess; - GLint m_locSpecularValue; - GLint m_locSpecularEnabled; - - GLint m_locSpotEllipse; - GLint m_locSpotRange; - GLint m_locSpotColor; - GLint m_locSpotFogColor; - - // model uniforms - GLint m_locModelScale; + GLint m_locSunClamp; + GLint m_locIntensityClamp; + GLint m_locShininess; + GLint m_locSpecularValue; + GLint m_locSpecularEnabled; + + GLint m_locSpotEllipse; + GLint m_locSpotRange; + GLint m_locSpotColor; + GLint m_locSpotFogColor; + + // model uniforms + GLint m_locModelScale; }; } // New3D