Does OpenGL3 + open a specific state for rendering 2D graphics?

I am currently working on 2D graphics, and as far as I can tell, each vertex is ultimately processed as a 4D point in uniform space. Therefore, I tell myself: what a waste of resources! I understand that the hardware is mainly designed to handle 3D scenes and, as such, can be hard-coded into 4d linear algebra. Nevertheless, is there a way to write shaders (or enable a set of parameters) so that only the original 2d coordinates are used in the hard memory? I know that it was possible to embed two 2x2 matrices into a 4x4 matrix, but the variable gl_Positionbeing vec4seems to end the track here. I'm not looking for some “workaround” hack like this, but rather a canonical way to make OpenGL such as a specific mode / state.

I was not able to find a code sample or even just mention this fact on the network, so I think that this is simply impossible / undesirable, for example, for performance reasons. This is true?

+3
source share
2 answers

All credit belongs to Andon M. Coleman, who answered the question perfectly as a comment. I just quote it here to complete:

" . / 4- . , push GPGPU ( NV GPU pre-GeForce 8xxx ALU). , , 16 (float * 4) . , vec2 vec4 vertex, a vec4. , - vec4 - GL Z = 0.0 W = 1.0.

, 2D- 2D-. . , . GL , , . 4D ( Z , ). "

0

. GLSL . vec2 , , size glVertexAttribPointer

Anon M. Coleman, OpenGL vec4(v, [0, [0]], 1) , < 4.

vec4 - gl_Position. a vec2 vec4:

vec2 v2;
gl_Position = vec4(v2, 0, 1);

, gl_Position vec4, - , OpenGL . .

+1
source

All Articles