Changeset f97e638 in opengl-game
- Timestamp:
- Apr 19, 2019, 12:41:18 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- dc19a39
- Parents:
- 14e6918
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r14e6918 rf97e638 184 184 map<GLuint, BufferInfo>& shaderBufferInfo, 185 185 map<ObjectType, ShaderModelGroup>& modelGroups, 186 GLuint points_vbo, 187 GLuint colors_vbo, 188 GLuint texcoords_vbo, 189 GLuint normals_vbo, 190 GLuint ubo, 191 GLuint model_mat_idx_vbo); 186 GLuint ubo); 192 187 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 193 188 … … 208 203 void calculateObjectBoundingBox(SceneObject* obj); 209 204 210 void initializeBuffers(211 GLuint* points_vbo,212 GLuint* colors_vbo,213 GLuint* texcoords_vbo,214 GLuint* normals_vbo,215 GLuint* ubo,216 GLuint* model_mat_idx_vbo);217 218 205 void initializeParticleEffectBuffers(vec3 origin, 219 206 map<GLuint, BufferInfo>& shaderBufferInfo, 220 207 map<ObjectType, ShaderModelGroup>& modelGroups, 221 GLuint points_vbo, 222 GLuint colors_vbo, 223 GLuint texcoords_vbo, 224 GLuint normals_vbo, 225 GLuint ubo, 226 GLuint model_mat_idx_vbo); 208 GLuint ubo); 227 209 228 210 void populateBuffers(vector<SceneObject*>& objects, 229 211 map<GLuint, BufferInfo>& shaderBufferInfo, 230 212 map<ObjectType, ShaderModelGroup>& modelGroups, 231 GLuint points_vbo, 232 GLuint colors_vbo, 233 GLuint texcoords_vbo, 234 GLuint normals_vbo, 235 GLuint ubo, 236 GLuint model_mat_idx_vbo); 213 GLuint ubo); 237 214 238 215 void copyObjectDataToBuffers(SceneObject& obj, … … 497 474 GLfloat curTime, prevTime, elapsedTime; 498 475 499 GLuint 500 points_vbo, 501 colors_vbo, 502 texcoords_vbo, 503 normals_vbo, 504 ubo, 505 model_mat_idx_vbo; 506 507 initializeBuffers( 508 &points_vbo, 509 &colors_vbo, 510 &texcoords_vbo, 511 &normals_vbo, 512 &ubo, 513 &model_mat_idx_vbo); 476 GLuint ubo = 0; 477 glGenBuffers(1, &ubo); 514 478 515 479 map<GLuint, BufferInfo> shaderBufferInfo; … … 612 576 populateBuffers(objects, 613 577 shaderBufferInfo, modelGroups, 614 points_vbo, 615 colors_vbo, 616 texcoords_vbo, 617 normals_vbo, 618 ubo, 619 model_mat_idx_vbo); 578 ubo); 620 579 621 580 float cam_speed = 1.0f; … … 654 613 shaderBufferInfo, 655 614 modelGroups, 656 points_vbo, 657 colors_vbo, 658 texcoords_vbo, 659 normals_vbo, 660 ubo, 661 model_mat_idx_vbo); 615 ubo); 662 616 663 617 /* TODO: Fix the UBO binding code based on the following forum post (in order to support multiple ubos): … … 816 770 if (elapsed_seconds_spawn > 0.5f) { 817 771 SceneObject* obj = createAsteroid(vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f))); 818 addObjectToScene(obj, shaderBufferInfo, modelGroups, 819 points_vbo, 820 colors_vbo, 821 texcoords_vbo, 822 normals_vbo, 823 ubo, 824 model_mat_idx_vbo); 772 addObjectToScene(obj, shaderBufferInfo, modelGroups, ubo); 825 773 826 774 elapsed_seconds_spawn -= 0.5f; … … 876 824 vec3(-0.21f, -1.19f, -3.0f)+offset, 877 825 vec3(0.0f, 1.0f, 0.0f), 0.03f); 878 addObjectToScene(leftLaser, shaderBufferInfo, modelGroups, 879 points_vbo, 880 colors_vbo, 881 texcoords_vbo, 882 normals_vbo, 883 ubo, 884 model_mat_idx_vbo); 826 addObjectToScene(leftLaser, shaderBufferInfo, modelGroups, ubo); 885 827 } else if (key_state[GLFW_KEY_Z] == GLFW_RELEASE) { 886 828 removeObjectFromScene(*leftLaser, ubo); … … 894 836 vec3(0.21f, -1.19f, -3.0f) + offset, 895 837 vec3(0.0f, 1.0f, 0.0f), 0.03f); 896 addObjectToScene(rightLaser, shaderBufferInfo, modelGroups, 897 points_vbo, 898 colors_vbo, 899 texcoords_vbo, 900 normals_vbo, 901 ubo, 902 model_mat_idx_vbo); 838 addObjectToScene(rightLaser, shaderBufferInfo, modelGroups, ubo); 903 839 } else if (key_state[GLFW_KEY_X] == GLFW_RELEASE) { 904 840 removeObjectFromScene(*rightLaser, ubo); … … 1386 1322 map<GLuint, BufferInfo>& shaderBufferInfo, 1387 1323 map<ObjectType, ShaderModelGroup>& modelGroups, 1388 GLuint points_vbo, 1389 GLuint colors_vbo, 1390 GLuint texcoords_vbo, 1391 GLuint normals_vbo, 1392 GLuint ubo, 1393 GLuint model_mat_idx_vbo) { 1324 GLuint ubo) { 1394 1325 objects.push_back(obj); 1395 1326 … … 1408 1339 } 1409 1340 1410 populateBuffers(objects, shaderBufferInfo, modelGroups, 1411 points_vbo, 1412 colors_vbo, 1413 texcoords_vbo, 1414 normals_vbo, 1415 ubo, 1416 model_mat_idx_vbo); 1341 populateBuffers(objects, shaderBufferInfo, modelGroups, ubo); 1417 1342 } else { 1418 1343 copyObjectDataToBuffers(*objects.back(), shaderBufferInfo, modelGroups, ubo); … … 2098 2023 } 2099 2024 2100 void initializeBuffers(2101 GLuint* points_vbo,2102 GLuint* colors_vbo,2103 GLuint* texcoords_vbo,2104 GLuint* normals_vbo,2105 GLuint* ubo,2106 GLuint* model_mat_idx_vbo) {2107 *points_vbo = 0;2108 glGenBuffers(1, points_vbo);2109 2110 *colors_vbo = 0;2111 glGenBuffers(1, colors_vbo);2112 2113 *texcoords_vbo = 0;2114 glGenBuffers(1, texcoords_vbo);2115 2116 *normals_vbo = 0;2117 glGenBuffers(1, normals_vbo);2118 2119 *ubo = 0;2120 glGenBuffers(1, ubo);2121 2122 *model_mat_idx_vbo = 0;2123 glGenBuffers(1, model_mat_idx_vbo);2124 }2125 2126 2025 void initializeParticleEffectBuffers(vec3 origin, 2127 2026 map<GLuint, BufferInfo>& shaderBufferInfo, 2128 2027 map<ObjectType, ShaderModelGroup>& modelGroups, 2129 GLuint points_vbo, 2130 GLuint colors_vbo, 2131 GLuint texcoords_vbo, 2132 GLuint normals_vbo, 2133 GLuint ubo, 2134 GLuint model_mat_idx_vbo) { 2028 GLuint ubo) { 2135 2029 float vv[EXPLOSION_PARTICLE_COUNT * 3]; // initial velocities vec3 2136 2030 float vt[EXPLOSION_PARTICLE_COUNT]; // initial times … … 2167 2061 2168 2062 objExplosion = createExplosion(); 2169 addObjectToScene(objExplosion, shaderBufferInfo, modelGroups, 2170 points_vbo, 2171 colors_vbo, 2172 texcoords_vbo, 2173 normals_vbo, 2174 ubo, 2175 model_mat_idx_vbo); 2063 addObjectToScene(objExplosion, shaderBufferInfo, modelGroups, ubo); 2176 2064 } 2177 2065 … … 2179 2067 map<GLuint, BufferInfo>& shaderBufferInfo, 2180 2068 map<ObjectType, ShaderModelGroup>& modelGroups, 2181 GLuint points_vbo, 2182 GLuint colors_vbo, 2183 GLuint texcoords_vbo, 2184 GLuint normals_vbo, 2185 GLuint ubo, 2186 GLuint ubo_idx_vbo) { 2069 GLuint ubo) { 2187 2070 GLsizeiptr num_points = 0; 2188 2071 GLsizeiptr num_objects = 0; … … 2250 2133 } 2251 2134 2252 /* Since we just want to start with lasers, make a loop that goes through all the laser model group attributes2253 * and allocates data for them. Determine how to go from GLenum (e.g. GL_FLOAT) to typedef (e.g. GLfloat)2254 */2255 2135 map<ObjectType, ShaderModelGroup>::iterator modelGroupIt; 2256 2136 ShaderModelGroup* smg; … … 2310 2190 } 2311 2191 2312 // Allocate all the buffers using the counts calculated above 2313 2314 glBindBuffer(GL_ARRAY_BUFFER, points_vbo); 2315 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 2316 2317 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 2318 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 2319 2320 glBindBuffer(GL_ARRAY_BUFFER, texcoords_vbo); 2321 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 2, NULL, GL_DYNAMIC_DRAW); 2322 2323 glBindBuffer(GL_ARRAY_BUFFER, normals_vbo); 2324 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW); 2192 // Allocate the ubo using the counts calculated above 2325 2193 2326 2194 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 2327 2195 glBufferData(GL_UNIFORM_BUFFER, num_objects * sizeof(mat4), NULL, GL_DYNAMIC_DRAW); 2328 2329 glBindBuffer(GL_ARRAY_BUFFER, ubo_idx_vbo);2330 glBufferData(GL_ARRAY_BUFFER, num_points * sizeof(GLuint), NULL, GL_DYNAMIC_DRAW);2331 2196 2332 2197 for (it = objects.begin(); it != objects.end(); it++) {
Note:
See TracChangeset
for help on using the changeset viewer.