Changeset e165b85 in opengl-game


Ignore:
Timestamp:
May 18, 2018, 11:04:10 PM (7 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
14ff67c
Parents:
cffca4d
Message:

Start incorporating UBOs

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • color.vert

    rcffca4d re165b85  
    22
    33uniform mat4 model, view, proj;
     4
     5layout (std140) uniform shader_data {
     6  mat4 model_mat;
     7};
    48
    59layout(location = 0) in vec3 vertex_position;
  • new-game.cpp

    rcffca4d re165b85  
    395395   GLsizeiptr points_buffer_size = 0;
    396396   GLsizeiptr textures_buffer_size = 0;
     397   GLsizeiptr ubo_buffer_size = 0;
    397398
    398399   for (obj_it = objects.begin(); obj_it != objects.end(); obj_it++) {
    399400      points_buffer_size += obj_it->points.size() * sizeof(GLfloat);
    400401      textures_buffer_size += obj_it->texcoords.size() * sizeof(GLfloat);
     402      ubo_buffer_size += 16 * sizeof(GLfloat);
    401403   }
    402404
     
    455457      offset += obj_it->normals.size() * sizeof(GLfloat);
    456458   }
     459
     460   /*
     461   GLuint ubo = 0;
     462   glGenBuffers(1, &ubo);
     463
     464   //glBindBuffer(GL_UNIFORM_BUFFER, ubo);
     465   //glBufferData(GL_UNIFORM_BUFFER, ubo_buffer_size/2, NULL, GL_DYNAMIC_DRAW);
     466
     467   offset = 0;
     468   for (obj_it = objects.begin(); obj_it != objects.end(); obj_it++) {
     469      //glBufferSubData(GL_UNIFORM_BUFFER, offset, sizeof(obj_it->model_mat), value_ptr(obj_it->model_mat));
     470      //glBufferSubData(GL_UNIFORM_BUFFER, offset, sizeof(obj_it->model_mat), value_ptr(objects[0].model_mat));
     471      offset += 16 * sizeof(GLfloat);
     472   }
     473   //glBindBuffer(GL_UNIFORM_BUFFER, 0);
     474   */
    457475
    458476   GLuint vao = 0;
     
    523541   GLuint view_test_loc = glGetUniformLocation(color_sp, "view");
    524542   GLuint proj_test_loc = glGetUniformLocation(color_sp, "proj");
     543   GLuint ub_index = glGetUniformBlockIndex(color_sp, "shader_data");
     544   cout << "UBO index: " << ub_index << endl;
    525545
    526546   GLuint model_mat_loc = glGetUniformLocation(texture_sp, "model");
     
    529549
    530550   glUseProgram(color_sp);
    531    glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(objects[0].model_mat));
    532551   glUniformMatrix4fv(view_test_loc, 1, GL_FALSE, value_ptr(view_mat));
    533552   glUniformMatrix4fv(proj_test_loc, 1, GL_FALSE, value_ptr(proj_mat));
    534553
     554   //glUniformBlockBinding(color_sp, ub_index, 0);
     555
    535556   glUseProgram(texture_sp);
    536    glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objects[1].model_mat));
    537557   glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat));
    538558   glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat));
Note: See TracChangeset for help on using the changeset viewer.