GLSL: enable / disable texturing + shaders

I am looking for a way to access OpenGL states from a shader. The GLSL Quick Reference Guide , an amazing resource, could not help me with this.

In the example I'm working on, I have the following two shaders:

Vertex:

void    main()
{
    gl_FrontColor = gl_Color;
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform();
}

Fragment:

uniform sampler2D   tex;
uniform float   flattening;

void main( void ) 
{
    vec4    texel;
    texel = texture2D(tex, gl_TexCoord[0].st);
    texel.r *= gl_Color.r;
    texel.g *= gl_Color.g;
    texel.b *= gl_Color.b;
    texel.a *= gl_Color.a;
    gl_FragColor = texel;
}

When I process polygons that are not textured, their alpha values ​​are correct, but they are assigned the color black.

1. What conditional check can be set to "texel" variable has been set vec4(1.0, 1.0, 1.0, 1.0), and no sampling of the texture when GL_TEXTURE_2Dturned off?

2, will processing be faster if I write different shaders for different texturing modes and switch between them where I would use glEnable/ glDisable( GL_TEXTURE_2D)?

+3
2

, GLSL, .

, GLSL unforms/attributes, .. automagic gl_ModelViewMatrix, gl_LightPosition, gl_Normal . , gl_Position gl_FragColor.

, #ifdef / , , , .

, , , , , , , . ( , SIMD, , .)

+8

, , - 1x1 (1.0, 1.0, 1.0, 1.0) , . , , 1x1 .

+3

Source: https://habr.com/ru/post/1708686/


All Articles