Changeset a9d191a in opengl-game for new-game.cpp


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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.