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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.