Changeset a9d191a in opengl-game


Ignore:
Timestamp:
Apr 12, 2019, 3:22:33 PM (6 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
14e6918
Parents:
c4c205e
Message:

Fix the buffer resizing algorithm for model groups (this fixes the laser rendering issue)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TODO.txt

    rc4c205e ra9d191a  
    1616==========
    1717-Unbind buffers (by binding to 0) once I'm done using them. This will help catch errors faster where I'm using a different buffer than I expect.
    18 -Show the fps in a gui component instead of printing it to the console
    1918
    2019NEW DONE
     
    2221-Move buffer memory allocation code into populateBuffers()
    2322-Go through the large design comment blocks and clean them up. Turn them into documentation for the code that's been written since I wrote the designs.
     23-Show the fps in a gui component instead of printing it to the console
    2424
    2525MAJOR TASKS TODO
    2626==================
    2727-Figure out why rendering doesn't work on the Windows laptop
    28 -Implement lasers
    2928
    3029MAJOR TASKS DONE
     
    3433  -I don't think ImGui would work with SFML
    3534  -When the time comes, maybe just try using the networking and audio components of SFML
     35-Implement lasers
     36
     37STEPS TO SWITCH OFF OF GLOBAL VBOS
     38===================================
     39
     401. Remove buffer re-assignment when creating shader model groups
     412. Inside populateBuffers, check for the object type and resize all buffers of that type (will eventually do this in a loop)
     423. In copyObjectData, set vertex_vbo_offset for the object type only using numPoints, not vbo_base
     434. in renderScene, change the glDrawArrays call to use an offset of 0
  • new-game.cpp

    rc4c205e ra9d191a  
    261261void renderSceneGui(map<string, vector<UIValue>> valueLists);
    262262
     263void initGuiValueLists(map<string, vector<UIValue>> valueLists);
    263264void renderGuiValueList(vector<UIValue>& values);
    264265
     
    308309SceneObject* objExplosion;
    309310SceneObject* objFirst;
     311
     312map<string, vector<UIValue>> valueLists;
    310313
    311314/*
     
    589592   initModelGroupAttribs(modelGroups[TYPE_LASER]);
    590593
    591    glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
    592    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    593    modelGroups[TYPE_LASER].attribs["vertex_position"].buffer = points_vbo;
    594 
    595    glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo);
    596    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL);
    597    modelGroups[TYPE_LASER].attribs["vt"].buffer = texcoords_vbo;
    598 
    599    glBindBuffer(GL_ARRAY_BUFFER, model_mat_idx_vbo);
    600    glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, 0, NULL);
    601    modelGroups[TYPE_LASER].attribs["ubo_index"].buffer = model_mat_idx_vbo;
    602 
    603594   modelGroups[TYPE_EXPLOSION] = createModelGroup(
    604595      loadShaderProgram("./explosion.vert", "./explosion.frag"));
     
    606597
    607598   // The last parameter (offset) is only used for populating the buffers since the distance
    608    // between each item is needed there. However, that code isn't run for explosions right now anyway,
    609    // so I may as well pass in 0 here.
     599   // between each item is needed there. However, the explosion vbos are populated using different
     600   // code anyway and don't use that argument, so I may as well pass in 0 here.
    610601   defineModelGroupAttrib(modelGroups[TYPE_EXPLOSION], "v_i", ATTRIB_POINT_VARYING,
    611602      3, GL_FLOAT, 0);
     
    783774   State curState = STATE_MAIN_MENU;
    784775
    785    map<string, vector<UIValue>> valueLists;
    786 
    787    valueLists["stats value list"] = vector<UIValue>();
     776   initGuiValueLists(valueLists);
     777
    788778   valueLists["stats value list"].push_back(UIValue(UIVALUE_INT, "Score", &score));
    789779   valueLists["stats value list"].push_back(UIValue(UIVALUE_DOUBLE, "FPS", &fps));
    790 
    791    valueLists["debug value list"] = vector<UIValue>();
    792 
    793    //valueLists["debug value list"].push_back(UIValue(UIVALUE_INT, "Buffer offset", &bufferOffset));
    794780
    795781   while (!glfwWindowShouldClose(window) && isRunning) {
     
    22912277      smg->vboCapacity = shaderCounts[smg->shaderProgram] * 2;
    22922278
     2279      AttribInfo* attrib;
     2280
    22932281      if (modelGroupIt->first == TYPE_SHIP) {
    2294          int numPoints = shaderCounts[smg->shaderProgram];
    2295          AttribInfo* attrib;
    2296 
    22972282         attrib = &smg->attribs["vertex_position"];
    22982283         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
    2299          glBufferData(GL_ARRAY_BUFFER, numPoints * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2284         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
    23002285
    23012286         attrib = &smg->attribs["vertex_color"];
    23022287         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
    2303          glBufferData(GL_ARRAY_BUFFER, numPoints * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2288         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
    23042289
    23052290         attrib = &smg->attribs["vertex_normal"];
    23062291         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
    2307          glBufferData(GL_ARRAY_BUFFER, numPoints * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2292         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
    23082293
    23092294         attrib = &smg->attribs["ubo_index"];
    23102295         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
    2311          glBufferData(GL_ARRAY_BUFFER, numPoints * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2296         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2297      } else if (modelGroupIt->first == TYPE_LASER) {
     2298         attrib = &smg->attribs["vertex_position"];
     2299         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
     2300         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2301
     2302         attrib = &smg->attribs["vt"];
     2303         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
     2304         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2305
     2306         attrib = &smg->attribs["ubo_index"];
     2307         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
     2308         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
    23122309      }
    23132310   }
     
    23442341   BufferInfo* bufferInfo = &shaderBufferInfo[modelGroups[obj.type].shaderProgram];
    23452342
    2346    if (obj.type == TYPE_SHIP) {
     2343   if (obj.type == TYPE_SHIP || obj.type == TYPE_LASER) {
    23472344      obj.vertex_vbo_offset = modelGroups[obj.type].numPoints;
    23482345   } else {
     
    25742571   glBindVertexArray(modelGroups[TYPE_LASER].vao);
    25752572
    2576    glDrawArrays(GL_TRIANGLES, shaderBufferInfo[modelGroups[TYPE_LASER].shaderProgram].vbo_base, modelGroups[TYPE_LASER].numPoints);
     2573   glDrawArrays(GL_TRIANGLES, 0, modelGroups[TYPE_LASER].numPoints);
    25772574
    25782575   glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram);
     
    26992696}
    27002697
     2698void initGuiValueLists(map<string, vector<UIValue>> valueLists) {
     2699   valueLists["stats value list"] = vector<UIValue>();
     2700   valueLists["debug value list"] = vector<UIValue>();
     2701}
     2702
    27012703void renderGuiValueList(vector<UIValue>& values) {
    27022704   float maxWidth = 0.0f;
Note: See TracChangeset for help on using the changeset viewer.