MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / genBuffers

Method genBuffers

src/Scene/CarModel.cpp:115–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115bool CarModel::genBuffers() {
116 if(Config::get().vulkanRender) return true;
117
118 glGenVertexArrays(1, &VertexArrayID);
119 glBindVertexArray(VertexArrayID);
120
121 // Verts
122 glGenBuffers(1, &vertexBuffer);
123 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
124 glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * sizeof(glm::vec3), &m_vertices[0], GL_STATIC_DRAW);
125 glVertexAttribPointer(
126 0, // attribute
127 3, // size
128 GL_FLOAT, // type
129 GL_FALSE, // normalized?
130 0, // stride
131 (void *) 0 // array buffer offset
132 );
133 // 1st attribute buffer : Vertices
134 glEnableVertexAttribArray(0);
135 // UVs
136 glGenBuffers(1, &uvBuffer);
137 glBindBuffer(GL_ARRAY_BUFFER, uvBuffer);
138 glBufferData(GL_ARRAY_BUFFER, m_uvs.size() * sizeof(glm::vec2), &m_uvs[0], GL_STATIC_DRAW);
139 glVertexAttribPointer(
140 1, // attribute
141 2, // size
142 GL_FLOAT, // type
143 GL_FALSE, // normalized?
144 0, // stride
145 (void *) 0 // array buffer offset
146 );
147 // 2nd attribute buffer : UVs
148 glEnableVertexAttribArray(1);
149 // Normals
150 glGenBuffers(1, &normalBuffer);
151 glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
152 glBufferData(GL_ARRAY_BUFFER, m_normals.size() * sizeof(glm::vec3), &m_normals[0], GL_STATIC_DRAW);
153 glVertexAttribPointer(
154 2, // attribute
155 3, // size
156 GL_FLOAT, // type
157 GL_TRUE, // normalized?
158 0, // stride
159 (void *) 0 // array buffer offset
160 );
161 // 3rd attribute buffer : Normals
162 glEnableVertexAttribArray(2);
163 // Texture Indices
164 glGenBuffers(1, &textureIndexBuffer);
165 glBindBuffer(GL_ARRAY_BUFFER, textureIndexBuffer);
166 glBufferData(GL_ARRAY_BUFFER, m_texture_indices.size() * sizeof(unsigned int), &m_texture_indices[0], GL_STATIC_DRAW);
167 glVertexAttribIPointer(
168 3,
169 1,
170 GL_UNSIGNED_INT,
171 0,
172 (void *) 0

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected