Changeset 0b1b52d in opengl-game for graphics-pipeline_opengl.cpp
- Timestamp:
- Oct 4, 2019, 8:27:07 PM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 771b33a
- Parents:
- 83b5b4b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_opengl.cpp
r83b5b4b r0b1b52d 6 6 using namespace std; 7 7 8 GraphicsPipeline_OpenGL::GraphicsPipeline_OpenGL() { 8 GraphicsPipeline_OpenGL::GraphicsPipeline_OpenGL(Viewport viewport) { 9 this->viewport = viewport; 9 10 } 10 11 … … 12 13 } 13 14 15 void GraphicsPipeline_OpenGL::addVaryingAttribute(VaryingAttribType attribType, GLint size, GLenum type, 16 size_t fieldOffset) { 17 // TODO: Throw an exception instead 18 if (type != GL_FLOAT && type != GL_UNSIGNED_INT) { 19 cout << "Unknown shader program attribute type: " << type << endl; 20 return; 21 } 22 23 VaryingAttribInfo attributeDesc; 24 25 attributeDesc.attribType = attribType; 26 attributeDesc.index = this->varyingAttribs.size(); 27 attributeDesc.size = size; 28 attributeDesc.type = type; 29 attributeDesc.fieldOffset = fieldOffset; 30 31 this->varyingAttribs.push_back(attributeDesc); 32 } 33 14 34 void GraphicsPipeline_OpenGL::createPipeline(string vertShaderFile, string fragShaderFile) { 15 35 shaderProgram = loadShaderProgram(vertShaderFile, fragShaderFile); 16 36 17 glGenVertexArrays(1, &vao); 18 numPoints = 0; 37 this->numPoints = 0; 38 glGenVertexArrays(1, &this->vao); 39 glBindVertexArray(this->vao); 40 41 vector<VaryingAttribInfo>::iterator it; 42 for (it = this->varyingAttribs.begin(); it != this->varyingAttribs.end(); it++) { 43 glEnableVertexAttribArray(it->index); 44 45 glGenBuffers(1, &it->buffer); 46 glBindBuffer(GL_ARRAY_BUFFER, it->buffer); 47 48 switch (it->type) { 49 case GL_FLOAT: { 50 glVertexAttribPointer(it->index, it->size, it->type, GL_FALSE, 0, NULL); 51 break; 52 } 53 case GL_UNSIGNED_INT: { 54 glVertexAttribIPointer(it->index, it->size, it->type, 0, NULL); 55 break; 56 } 57 } 58 } 19 59 } 20 60
Note:
See TracChangeset
for help on using the changeset viewer.