Changeset 649


Ignore:
Timestamp:
Feb 14, 2011, 2:26:43 AM (10 years ago)
Author:
sam
Message:

Shader tests. Disabled for now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scene.cpp

    r645 r649  
    1414
    1515#include <cstdlib>
     16#include <cstdio>
    1617#include <cmath>
    1718
     
    2930#include "core.h"
    3031
     32#define ATTRIB_POSITION 42 /* arbitrary id */
     33#define SHADER_CRAP 0
     34
    3135struct Tile
    3236{
     
    5660    float angle;
    5761
     62#if SHADER_CRAP
     63    GLuint prog, sh1, sh2;
     64    GLint uni_mvp, uni_color;
     65#endif
    5866    GLuint *bufs;
    5967    int nbufs;
     
    6371
    6472Scene *SceneData::scene = NULL;
     73
     74#if SHADER_CRAP
     75static char const *vertexshader =
     76    "attribute vec4 position;\n"
     77    "uniform mat4 mvp;\n"
     78    "\n"
     79    "void main()\n"
     80    "{\n"
     81    "    gl_Position = mvp * position;\n"
     82    "}\n";
     83
     84static char const *fragmentshader =
     85    "uniform lowp vec4 color;\n"
     86    "\n"
     87    "void main()\n"
     88    "{\n"
     89    "    gl_FragColor = color;\n"
     90    "}\n";
     91#endif
    6592
    6693/*
     
    77104    data->bufs = 0;
    78105    data->nbufs = 0;
     106
     107#if SHADER_CRAP
     108    data->sh1 = glCreateShader(GL_VERTEX_SHADER);
     109    glShaderSource(data->sh1, 1, &vertexshader, NULL);
     110    glCompileShader(data->sh1);
     111
     112    char buf[4096];
     113    GLsizei dummy;
     114    glGetShaderInfoLog(data->sh1, 4096, &dummy, buf);
     115    fprintf(stderr, "sh1 %i: %s", data->sh1, buf);
     116
     117    data->sh2 = glCreateShader(GL_FRAGMENT_SHADER);
     118    glShaderSource(data->sh2, 1, &fragmentshader, NULL);
     119    glCompileShader(data->sh2);
     120
     121    glGetShaderInfoLog(data->sh2, 4096, &dummy, buf);
     122    fprintf(stderr, "sh2 %i: %s", data->sh2, buf);
     123
     124    data->prog = glCreateProgram();
     125    glAttachShader(data->prog, data->sh1);
     126    glAttachShader(data->prog, data->sh2);
     127
     128    glBindAttribLocation(data->prog, ATTRIB_POSITION, "position");
     129    glLinkProgram(data->prog);
     130
     131    data->uni_mvp = glGetUniformLocation(data->prog, "mvp");
     132    data->uni_color = glGetUniformLocation(data->prog, "color");
     133#endif
    79134}
    80135
     
    83138    /* FIXME: this must be done while the GL context is still active.
    84139     * Change the architecture to make sure of that. */
     140#if SHADER_CRAP
     141    glDetachShader(data->prog, data->sh1);
     142    glDetachShader(data->prog, data->sh2);
     143    glDeleteShader(data->sh1);
     144    glDeleteShader(data->sh2);
     145    glDeleteProgram(data->prog);
     146#endif
    85147    glDeleteBuffers(data->nbufs, data->bufs);
    86148    delete data;
     
    171233        glEnableClientState(GL_VERTEX_ARRAY);
    172234        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     235#if SHADER_CRAP
     236        glUseProgram(data->prog);
     237        float4x4 mvp = float4x4::identity();
     238        mvp = mvp - mvp;
     239        glUniformMatrix4fv(data->uni_mvp, 1, GL_FALSE, (GLfloat *)&mvp[0][0]);
     240        glUniform4f(data->uni_color, 1.0f, 0.0f, 1.0f, 1.0f);
     241#endif
    173242
    174243        glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]);
     
    176245                     vertex, GL_DYNAMIC_DRAW);
    177246        glVertexPointer(3, GL_FLOAT, 0, NULL);
     247#if SHADER_CRAP
     248        glVertexAttribPointer(ATTRIB_POSITION, (n - i) * 6, GL_FLOAT, false, 0, vertex);
     249        glEnableVertexAttribArray(ATTRIB_POSITION);
     250#endif
    178251
    179252        glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]);
Note: See TracChangeset for help on using the changeset viewer.