2

If I have a simple OpenGL shader that is applied to many cubes at once, then uniform values get slow. I have noticed that things like glColor3f don't slow it down as much (at least from what I have tried) but am currently using glColor3f as a sort of hack so that the shader can read gl_Color and I can use it similarly to a uniform for determing which side of the cube is being rendered for face-indepent flat lighting.

I am using displaylists so I used glColor3f because it baked into the list, and simply did a different color before every face while creating the list. Now, I want to set more values (not in the displaylist this time) before rendering.

What calls from OpenGL can I do that can be read in the shader? I am needing to send 6 ints from 0-8 into the shader before rendering, but I could probably manage to shrink that later on.

  • 2
    This kind of thing is a lot easier if you use modern OpenGL, instead of trying to mix and match the fixed-function pipeline (`glColor3f`) and obsolete APIs (display lists) with newer features (shaders). Typically, you would define a combination of attributes, uniforms, uniform buffers, textures, shader storage buffers, et cetera, and the shader can read all of those. It sounds like you want attributes. – Dietrich Epp Jan 04 '16 at 07:41

1 Answers1

2

I recommend to use uniform blocks or uniforms with datatype ivec2, ivec3 or ivec4, with them you can write 2, 3, or 4 int at once.

Aapart from this there are some built-in uniforms. Apart from the matrices, these are gl_DepthRange, gl_Fog, gl_LightSource[gl_MaxLights], gl_LightModel, gl_FrontLightModelProduct, gl_BackLightModelProduct, gl_FrontLightProduct[gl_MaxLights], gl_BackLightProduct[gl_MaxLights], gl_FrontMaterial, gl_BackMaterial, gl_Point, gl_TextureEnvColor[gl_MaxTextureUnits], gl_ClipPlane[gl_MaxClipPlanes], gl_EyePlaneS[gl_MaxTextureCoords], gl_EyePlaneT[gl_MaxTextureCoords], gl_EyePlaneR[gl_MaxTextureCoords], gl_EyePlaneQ[gl_MaxTextureCoords], gl_ObjectPlaneS[gl_MaxTextureCoords], gl_ObjectPlaneT[gl_MaxTextureCoords], gl_ObjectPlaneR[gl_MaxTextureCoords] and gl_ObjectPlaneQ[gl_MaxTextureCoords].

But the intended manner to read global data from shaders are uniform variables. Another way would be to encode information in textures.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Would using VBO's and other newer rendering methods help speed it up? I am making something similar to Minecraft for fun and learning. I have Frustum Culling and it doesn't render blocks completely surrounded, so without passing uniforms I can get a pretty good framerate. Now that I want to implement flat lighting for individual faces, I did the stuff I said to control a face's lighting. It works, but if I have enough blocks then it lags way more than I would like. If I set a close render distance the system does work, though. – Cello Coder Jan 04 '16 at 15:59
  • @Cello Code I have less experience with VBO's. I recomend to read answer of this question [Does interleaving in VBOs speed up performance when using VAOs](http://stackoverflow.com/questions/18853713/does-interleaving-in-vbos-speed-up-performance-when-using-vaos?rq=1) – Rabbid76 Jan 04 '16 at 16:06