Changeset 659


Ignore:
Timestamp:
Feb 17, 2011, 7:06:37 PM (9 years ago)
Author:
sam
Message:

Try to factor all the recent GLSL stuff in the new Shader class.

Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r648 r659  
    1010    world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \
    1111    text.cpp text.h emitter.cpp emitter.h numeric.h \
    12     worldentity.cpp worldentity.h \
     12    worldentity.cpp worldentity.h shader.cpp shader.h \
    1313    \
    1414    sdlinput.cpp sdlinput.h \
  • trunk/src/core.h

    r658 r659  
    4343#include "map.h"
    4444#include "layer.h"
     45#include "shader.h"
    4546
    4647// Managers
  • trunk/src/scene.cpp

    r658 r659  
    3737
    3838#if LOL_EXPERIMENTAL
    39 extern GLuint prog;
     39extern Shader *stdshader;
    4040#endif
    4141
     
    161161    {  1.0,  0.0  } };
    162162
    163     GLuint vao, vbo[3];
     163    GLuint vao, vbo[3], attr;
     164
    164165    glGenVertexArrays(1, &vao);
    165166    glBindVertexArray(vao);
    166167    glGenBuffers(3, &vbo[0]);
    167168
     169    attr = stdshader->GetAttribLocation("in_Position");
    168170    glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
    169171    glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
    170     glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    171     glEnableVertexAttribArray(0);
    172 
     172    glVertexAttribPointer(attr, 3, GL_FLOAT, GL_FALSE, 0, 0);
     173    glEnableVertexAttribArray(attr);
     174
     175    attr = stdshader->GetAttribLocation("in_Color");
    173176    glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
    174177    glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), colors, GL_STATIC_DRAW);
    175     glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, 0, 0);
    176     glEnableVertexAttribArray(1);
    177 
     178    glVertexAttribPointer(attr, 3, GL_FLOAT, GL_FALSE, 0, 0);
     179    glEnableVertexAttribArray(attr);
     180
     181    attr = stdshader->GetAttribLocation("in_TexCoord");
    178182    glBindBuffer(GL_ARRAY_BUFFER, vbo[2]);
    179183    glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), tex, GL_STATIC_DRAW);
    180     glVertexAttribPointer((GLuint)2, 2, GL_FLOAT, GL_FALSE, 0, 0);
    181     glEnableVertexAttribArray(2);
     184    glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, 0);
     185    glEnableVertexAttribArray(attr);
    182186
    183187    delete[] vertices;
    184188
    185     glUseProgram(prog);
     189    stdshader->Bind();
    186190    glBindVertexArray(vao);
    187191    Tiler::Bind(1 << 16);
  • trunk/src/video.cpp

    r658 r659  
    3030
    3131#if LOL_EXPERIMENTAL
    32     GLuint prog, sh1, sh2;
    33     GLint uni_m1, uni_m2, uni_m3;
     32Shader *stdshader;
    3433
    3534    float4x4 projection_matrix, view_matrix, model_matrix;
     
    8786
    8887#if LOL_EXPERIMENTAL
    89     sh1 = glCreateShader(GL_VERTEX_SHADER);
    90     glShaderSource(sh1, 1, &vertexshader, NULL);
    91     glCompileShader(sh1);
    92 
    93     char buf[4096];
    94     GLsizei dummy;
    95     glGetShaderInfoLog(sh1, 4096, &dummy, buf);
    96     fprintf(stderr, "sh1 %i: %s", sh1, buf);
    97 
    98     sh2 = glCreateShader(GL_FRAGMENT_SHADER);
    99     glShaderSource(sh2, 1, &fragmentshader, NULL);
    100     glCompileShader(sh2);
    101 
    102     glGetShaderInfoLog(sh2, 4096, &dummy, buf);
    103     fprintf(stderr, "sh2 %i: %s", sh2, buf);
    104 
    105     prog = glCreateProgram();
    106     glAttachShader(prog, sh1);
    107     glAttachShader(prog, sh2);
    108 
    109     glBindAttribLocation(prog, 0, "in_Position");
    110     glBindAttribLocation(prog, 1, "in_Color");
    111     glBindAttribLocation(prog, 2, "in_TexCoord");
    112     glLinkProgram(prog);
    113     glValidateProgram(prog);
    114 
    115     uni_m1 = glGetUniformLocation(prog, "projection_matrix");
    116     uni_m2 = glGetUniformLocation(prog, "view_matrix");
    117     uni_m3 = glGetUniformLocation(prog, "model_matrix");
    118 
    119     glClearColor(0.4f, 0.6f, 0.9f, 0.0f);
     88    stdshader = new Shader(vertexshader, fragmentshader);
    12089#endif
    12190}
     
    200169    model_matrix[2][2] = 0.5f;
    201170
    202     glUniformMatrix4fv(uni_m1, 1, GL_FALSE, &projection_matrix[0][0]);
    203     glUniformMatrix4fv(uni_m2, 1, GL_FALSE, &view_matrix[0][0]);
    204     glUniformMatrix4fv(uni_m3, 1, GL_FALSE, &model_matrix[0][0]);
     171    GLuint uni;
     172    uni = stdshader->GetUniformLocation("projection_matrix");
     173    glUniformMatrix4fv(uni, 1, GL_FALSE, &projection_matrix[0][0]);
     174    uni = stdshader->GetUniformLocation("view_matrix");
     175    glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]);
     176    uni = stdshader->GetUniformLocation("model_matrix");
     177    glUniformMatrix4fv(uni, 1, GL_FALSE, &model_matrix[0][0]);
    205178#else
    206179    glEnable(GL_DEPTH_TEST);
     
    226199{
    227200#if LOL_EXPERIMENTAL
    228     glDetachShader(prog, sh1);
    229     glDetachShader(prog, sh2);
    230     glDeleteShader(sh1);
    231     glDeleteShader(sh2);
    232     glDeleteProgram(prog);
     201    delete stdshader;
    233202#endif
    234203}
  • trunk/win32/deushax.vcxproj

    r658 r659  
    3636    <ClInclude Include="..\src\scene.h" />
    3737    <ClInclude Include="..\src\sdlinput.h" />
     38    <ClInclude Include="..\src\shader.h" />
    3839    <ClInclude Include="..\src\text.h" />
    3940    <ClInclude Include="..\src\ticker.h" />
     
    6869    <ClCompile Include="..\src\scene.cpp" />
    6970    <ClCompile Include="..\src\sdlinput.cpp" />
     71    <ClCompile Include="..\src\shader.cpp" />
    7072    <ClCompile Include="..\src\text.cpp" />
    7173    <ClCompile Include="..\src\ticker.cpp" />
  • trunk/win32/deushax.vcxproj.filters

    r648 r659  
    6262    </ClInclude>
    6363    <ClInclude Include="..\src\sdlinput.h">
     64      <Filter>lolengine</Filter>
     65    </ClInclude>
     66    <ClInclude Include="..\src\shader.h">
    6467      <Filter>lolengine</Filter>
    6568    </ClInclude>
     
    149152      <Filter>lolengine</Filter>
    150153    </ClCompile>
     154    <ClCompile Include="..\src\shader.cpp">
     155      <Filter>lolengine</Filter>
     156    </ClCompile>
    151157    <ClCompile Include="..\src\text.cpp">
    152158      <Filter>lolengine</Filter>
  • trunk/win32/editor.vcxproj

    r658 r659  
    3636    <ClInclude Include="..\src\scene.h" />
    3737    <ClInclude Include="..\src\sdlinput.h" />
     38    <ClInclude Include="..\src\shader.h" />
    3839    <ClInclude Include="..\src\text.h" />
    3940    <ClInclude Include="..\src\ticker.h" />
     
    6869    <ClCompile Include="..\src\scene.cpp" />
    6970    <ClCompile Include="..\src\sdlinput.cpp" />
     71    <ClCompile Include="..\src\shader.cpp" />
    7072    <ClCompile Include="..\src\text.cpp" />
    7173    <ClCompile Include="..\src\ticker.cpp" />
  • trunk/win32/editor.vcxproj.filters

    r648 r659  
    6262    </ClInclude>
    6363    <ClInclude Include="..\src\sdlinput.h">
     64      <Filter>lolengine</Filter>
     65    </ClInclude>
     66    <ClInclude Include="..\src\shader.h">
    6467      <Filter>lolengine</Filter>
    6568    </ClInclude>
     
    149152      <Filter>lolengine</Filter>
    150153    </ClCompile>
     154    <ClCompile Include="..\src\shader.cpp">
     155      <Filter>lolengine</Filter>
     156    </ClCompile>
    151157    <ClCompile Include="..\src\text.cpp">
    152158      <Filter>lolengine</Filter>
  • trunk/win32/monsterz.vcxproj

    r658 r659  
    4141    <ClInclude Include="..\src\scene.h" />
    4242    <ClInclude Include="..\src\sdlinput.h" />
     43    <ClInclude Include="..\src\shader.h" />
    4344    <ClInclude Include="..\src\text.h" />
    4445    <ClInclude Include="..\src\ticker.h" />
     
    7778    <ClCompile Include="..\src\scene.cpp" />
    7879    <ClCompile Include="..\src\sdlinput.cpp" />
     80    <ClCompile Include="..\src\shader.cpp" />
    7981    <ClCompile Include="..\src\text.cpp" />
    8082    <ClCompile Include="..\src\ticker.cpp" />
  • trunk/win32/monsterz.vcxproj.filters

    r648 r659  
    6464      <Filter>lolengine</Filter>
    6565    </ClInclude>
     66    <ClInclude Include="..\src\shader.h">
     67      <Filter>lolengine</Filter>
     68    </ClInclude>
    6669    <ClInclude Include="..\src\text.h">
    6770      <Filter>lolengine</Filter>
     
    152155    </ClCompile>
    153156    <ClCompile Include="..\src\sdlinput.cpp">
     157      <Filter>lolengine</Filter>
     158    </ClCompile>
     159    <ClCompile Include="..\src\shader.cpp">
    154160      <Filter>lolengine</Filter>
    155161    </ClCompile>
Note: See TracChangeset for help on using the changeset viewer.