Recently I plan to switch my old fix function rendering method to GLSL, but the GLSL method is a lot slower than the fix function.
Here is my Vertex Shader
#version 330 core
uniform mat4 u_MVPMatrix; // A constant representing the combined model/view/projection matrix.
layout(location = 0) in vec4 a_Position; // Per-vertex position information we will pass in.
// The entry point for our vertex shader.
void main()
{
// gl_Position is a special variable used to store the final position.
// Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
gl_Position = u_MVPMatrix * a_Position;
}
Fragment Shader
#version 330 core
precision mediump float; // Set the default precision to medium. We don't need as high of a
// precision in the fragment shader.
out vec4 v_Color; // This is the color from the vertex shader interpolated across the
// triangle per fragment.
uniform vec4 LineColor;
// The entry point for our fragment shader.
void main()
{
// Pass through the color
v_Color=LineColor;
}
ShaderSelect tempS = SelectShaders;
//Buffer
tempS.UseProgram();
EnableVertexAttribArrayARB(0);
VertexAttribPointerfARB(0, 3, 0, 0, vertices);
glUniform4fARB(tempS.mLineColor, color[0], color[1], color[2], color[3]);
glUniformMatrix4fvARB(tempS.mMVPMatrixHandle, 1, 0, CombineMatrix); // Fix combine matrix
Gl.glDrawArrays(Gl.GL_LINE_LOOP, 0, num);
DisableVertexAttribArray(0);
tempS.Disable();
This is the Fix Function
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glVertexPointer(3, Gl.GL_DOUBLE, 0, point);
if (closed)
Gl.glDrawArrays(Gl.GL_LINE_LOOP, 0, num);
else
Gl.glDrawArrays(Gl.GL_LINE_STRIP, 0, num);
// Gl.glFinish();
Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
By rendering 100000 of circle and each circle with 40 points.
Fix function give 7 to 8 fps.
GLSL give only 1 to 2 fps.
Is it by design? Or do I did anything wrong on the code?