Changeset 653


Ignore:
Timestamp:
Feb 16, 2011, 7:04:11 PM (10 years ago)
Author:
sam
Message:

More shader crap for GLSL 1.30. Still disabled.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core.h

    r312 r653  
    1616#if !defined __DH_CORE_H__
    1717#define __DH_CORE_H__
     18
     19// Temporary stuff
     20//#define SHADER_CRAP 1
    1821
    1922// Base types
  • trunk/src/scene.cpp

    r650 r653  
    3030#include "core.h"
    3131
    32 #define ATTRIB_POSITION 42 /* arbitrary id */
    33 #define SHADER_CRAP 0
    34 
    3532struct Tile
    3633{
     
    3835    int x, y, z, o;
    3936};
     37
     38#if SHADER_CRAP
     39#   define ATTRIB_POSITION 42 /* arbitrary id */
     40    extern GLuint prog;
     41    extern GLint uni_mvp, uni_color;
     42#endif
    4043
    4144/*
     
    6063    float angle;
    6164
    62 #if SHADER_CRAP
    63     GLuint prog, sh1, sh2;
    64     GLint uni_mvp, uni_color;
    65 #endif
    6665    GLuint *bufs;
    6766    int nbufs;
     
    7170
    7271Scene *SceneData::scene = NULL;
    73 
    74 #if SHADER_CRAP
    75 static 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 
    84 static 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
    9272
    9373/*
     
    10484    data->bufs = 0;
    10585    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     glValidateProgram(data->prog);
    131 
    132     data->uni_mvp = glGetUniformLocation(data->prog, "mvp");
    133     data->uni_color = glGetUniformLocation(data->prog, "color");
    134 #endif
    13586}
    13687
     
    13990    /* FIXME: this must be done while the GL context is still active.
    14091     * Change the architecture to make sure of that. */
    141 #if SHADER_CRAP
    142     glDetachShader(data->prog, data->sh1);
    143     glDetachShader(data->prog, data->sh2);
    144     glDeleteShader(data->sh1);
    145     glDeleteShader(data->sh2);
    146     glDeleteProgram(data->prog);
    147 #endif
    14892    glDeleteBuffers(data->nbufs, data->bufs);
    14993    delete data;
     
    235179        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    236180#if SHADER_CRAP
    237         glUseProgram(data->prog);
    238         float4x4 mvp = float4x4::identity();
    239         mvp = mvp - mvp;
    240         glUniformMatrix4fv(data->uni_mvp, 1, GL_FALSE, (GLfloat *)&mvp[0][0]);
    241         glUniform4f(data->uni_color, 1.0f, 0.0f, 1.0f, 1.0f);
     181        glUseProgram(prog);
     182        //float4x4 mvp(1.0f);
     183        //mvp = mvp - mvp;
     184        //glUniformMatrix4fv(uni_mvp, 1, GL_FALSE, (GLfloat *)&mvp[0][0]);
     185        //glUniform4f(uni_color, 1.0f, 0.0f, 1.0f, 1.0f);
    242186#endif
    243187
  • trunk/src/video.cpp

    r615 r653  
    1414
    1515#include <cmath>
     16#include <cstdio>
    1617
    1718#ifdef WIN32
     
    2728
    2829#include "core.h"
     30
     31#if SHADER_CRAP
     32#   define ATTRIB_POSITION 42 /* arbitrary id */
     33    GLuint prog, sh1, sh2;
     34    GLint uni_m1, uni_m2, uni_m3;
     35
     36    float4x4 projection_matrix, view_matrix, model_matrix;
     37#endif
     38
     39#if SHADER_CRAP
     40static char const *vertexshader =
     41    "#version 130\n"
     42    "\n"
     43    "in vec3 in_Position;\n"
     44    "in vec3 in_Color;\n"
     45    "out vec3 pass_Color;\n"
     46    "//attribute vec4 position;\n"
     47    "uniform mat4 projection_matrix;\n"
     48    "uniform mat4 view_matrix;\n"
     49    "uniform mat4 model_matrix;\n"
     50    "\n"
     51    "void main()\n"
     52    "{\n"
     53    "    gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_Position, 1.0f);\n"
     54    "    pass_Color = in_Color;\n"
     55    "}\n";
     56
     57static char const *fragmentshader =
     58    "#version 130\n"
     59    "\n"
     60    "in vec3 pass_Color;\n"
     61    "out vec4 out_Color;\n"
     62    "\n"
     63    "void main()\n"
     64    "{\n"
     65    "    gl_FragColor = pass_Color;\n"
     66    "}\n";
     67#endif
    2968
    3069/*
     
    4382
    4483    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     84
     85#if SHADER_CRAP
     86    sh1 = glCreateShader(GL_VERTEX_SHADER);
     87    glShaderSource(sh1, 1, &vertexshader, NULL);
     88    glCompileShader(sh1);
     89
     90    char buf[4096];
     91    GLsizei dummy;
     92    glGetShaderInfoLog(sh1, 4096, &dummy, buf);
     93    fprintf(stderr, "sh1 %i: %s", sh1, buf);
     94
     95    sh2 = glCreateShader(GL_FRAGMENT_SHADER);
     96    glShaderSource(sh2, 1, &fragmentshader, NULL);
     97    glCompileShader(sh2);
     98
     99    glGetShaderInfoLog(sh2, 4096, &dummy, buf);
     100    fprintf(stderr, "sh2 %i: %s", sh2, buf);
     101
     102    prog = glCreateProgram();
     103    glAttachShader(prog, sh1);
     104    glAttachShader(prog, sh2);
     105
     106    //glBindAttribLocation(prog, ATTRIB_POSITION, "position");
     107    glBindAttribLocation(prog, 0, "in_Position");
     108    glBindAttribLocation(prog, 1, "in_Color");
     109    glLinkProgram(prog);
     110    glValidateProgram(prog);
     111
     112    uni_m1 = glGetUniformLocation(prog, "projection_matrix");
     113    uni_m2 = glGetUniformLocation(prog, "view_matrix");
     114    uni_m3 = glGetUniformLocation(prog, "model_matrix");
     115
     116    glClearColor(0.4f, 0.6f, 0.9f, 0.0f);
     117#endif
    45118}
    46119
    47120void Video::SetFov(float theta)
    48121{
     122#if SHADER_CRAP
     123    float width = GetWidth();
     124    float height = GetHeight();
     125    float near = -width - height;
     126    float far = width + height;
     127    projection_matrix = float4x4::perspective(theta, width, height, near, far);
     128#else
    49129#undef near /* Fuck Microsoft */
    50130#undef far /* Fuck Microsoft again */
     
    88168    glMatrixMode(GL_MODELVIEW);
    89169    glLoadIdentity();
     170#endif
    90171}
    91172
     
    100181void Video::Clear()
    101182{
     183#if SHADER_CRAP
     184    glViewport(0, 0, GetWidth(), GetHeight());
     185    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     186
     187    view_matrix = float4x4(1.0f);
     188    view_matrix[3][0] = 0.0f;
     189    view_matrix[3][0] = 0.0f;
     190    view_matrix[3][0] = -5.0f;
     191
     192    model_matrix = float4x4(1.0f);
     193    model_matrix[0][0] = 0.5f;
     194    model_matrix[1][1] = 0.5f;
     195    model_matrix[2][2] = 0.5f;
     196
     197    glUniformMatrix4fv(uni_m1, 1, GL_FALSE, &projection_matrix[0][0]);
     198    glUniformMatrix4fv(uni_m2, 1, GL_FALSE, &view_matrix[0][0]);
     199    glUniformMatrix4fv(uni_m3, 1, GL_FALSE, &model_matrix[0][0]);
     200#else
    102201    glEnable(GL_DEPTH_TEST);
    103202    glDepthFunc(GL_LEQUAL);
     
    108207
    109208    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     209#endif
    110210
    111211    SetFov(0.0f);
     212}
     213
     214void Video::Destroy()
     215{
     216#if SHADER_CRAP
     217    glDetachShader(prog, sh1);
     218    glDetachShader(prog, sh2);
     219    glDeleteShader(sh1);
     220    glDeleteShader(sh2);
     221    glDeleteProgram(prog);
     222#endif
    112223}
    113224
  • trunk/src/video.h

    r221 r653  
    2424public:
    2525    static void Setup(int width, int height);
     26    static void Destroy();
    2627    static void SetFov(float theta);
    2728    static void SetDepth(bool set);
Note: See TracChangeset for help on using the changeset viewer.