X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=progs%2Fglsl%2Fsamplers.c;h=87dad5d85752daaeab1632fe2d96aa813bd3dbbf;hb=5ac16495a2772886100789f04e1a7d65068e9a40;hp=d2140097297266688e64401ca2934165d9712bbc;hpb=a3ee0aa1bb7c3f9dfc5b13b4e72522c10a22ad05;p=mesa.git diff --git a/progs/glsl/samplers.c b/progs/glsl/samplers.c index d2140097297..87dad5d8575 100644 --- a/progs/glsl/samplers.c +++ b/progs/glsl/samplers.c @@ -39,9 +39,9 @@ #include #include #include +#include #include "GL/glut.h" #include "readtex.h" -#include "extfuncs.h" #include "shaderutil.h" @@ -211,10 +211,18 @@ InitTextures(void) for (y = 0; y < stripeSize; y++) { for (x = 0; x < size; x++) { GLint k = 4 * ((ypos + y) * size + x); - texImage[k + 0] = intensity; - texImage[k + 1] = intensity; - texImage[k + 2] = 0; - texImage[k + 3] = 255; + if (x < size / 2) { + texImage[k + 0] = intensity; + texImage[k + 1] = intensity; + texImage[k + 2] = 0; + texImage[k + 3] = 255; + } + else { + texImage[k + 0] = 255 - intensity; + texImage[k + 1] = 0; + texImage[k + 2] = 0; + texImage[k + 3] = 255; + } } } @@ -245,14 +253,22 @@ GenFragmentShader(GLint numSamplers) int s; p += sprintf(p, "// Generated fragment shader:\n"); +#ifndef SAMPLERS_ARRAY for (s = 0; s < numSamplers; s++) { p += sprintf(p, "uniform sampler2D tex%d;\n", s); } +#else + p += sprintf(p, "uniform sampler2D tex[%d];\n", numSamplers); +#endif p += sprintf(p, "void main()\n"); p += sprintf(p, "{\n"); p += sprintf(p, " vec4 color = vec4(0.0);\n"); for (s = 0; s < numSamplers; s++) { +#ifndef SAMPLERS_ARRAY p += sprintf(p, " color += texture2D(tex%d, gl_TexCoord[0].xy);\n", s); +#else + p += sprintf(p, " color += texture2D(tex[%d], gl_TexCoord[0].xy);\n", s); +#endif } p += sprintf(p, " gl_FragColor = color;\n"); p += sprintf(p, "}\n"); @@ -282,7 +298,7 @@ CreateProgram(void) assert(vertShader); program = LinkShaders(vertShader, fragShader); - glUseProgram_func(program); + glUseProgram(program); free(fragShaderText); @@ -302,11 +318,15 @@ InitProgram(void) char uname[10]; GLint loc; +#ifndef SAMPLERS_ARRAY sprintf(uname, "tex%d", s); - loc = glGetUniformLocation_func(Program, uname); +#else + sprintf(uname, "tex[%d]", s); +#endif + loc = glGetUniformLocation(Program, uname); assert(loc >= 0); - glUniform1i_func(loc, s); + glUniform1i(loc, s); } } @@ -321,8 +341,6 @@ InitGL(void) printf("GL_RENDERER = %s\n", (const char *) glGetString(GL_RENDERER)); - GetExtensionFuncs(); - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &NumSamplers); if (NumSamplers > MAX_SAMPLERS) NumSamplers = MAX_SAMPLERS; @@ -345,6 +363,7 @@ main(int argc, char *argv[]) glutInitWindowSize(500, 400); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow(Demo); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(key); glutSpecialFunc(specialkey);