| 1160 | } |
| 1161 | |
| 1162 | int GLInstancingRenderer::registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType, int textureId) |
| 1163 | { |
| 1164 | b3GraphicsInstance* gfxObj = new b3GraphicsInstance; |
| 1165 | |
| 1166 | if (textureId >= 0) |
| 1167 | { |
| 1168 | gfxObj->m_textureIndex = textureId; |
| 1169 | gfxObj->m_flags |= B3_INSTANCE_TEXTURE; |
| 1170 | } |
| 1171 | |
| 1172 | gfxObj->m_primitiveType = primitiveType; |
| 1173 | |
| 1174 | if (m_graphicsInstances.size()) |
| 1175 | { |
| 1176 | b3GraphicsInstance* prevObj = m_graphicsInstances[m_graphicsInstances.size() - 1]; |
| 1177 | gfxObj->m_instanceOffset = prevObj->m_instanceOffset + prevObj->m_numGraphicsInstances; |
| 1178 | gfxObj->m_vertexArrayOffset = prevObj->m_vertexArrayOffset + prevObj->m_numVertices; |
| 1179 | } |
| 1180 | else |
| 1181 | { |
| 1182 | gfxObj->m_instanceOffset = 0; |
| 1183 | } |
| 1184 | |
| 1185 | m_graphicsInstances.push_back(gfxObj); |
| 1186 | gfxObj->m_numIndices = numIndices; |
| 1187 | gfxObj->m_numVertices = numvertices; |
| 1188 | |
| 1189 | int vertexStrideInBytes = 9 * sizeof(float); |
| 1190 | int sz = numvertices * vertexStrideInBytes; |
| 1191 | int totalUsed = vertexStrideInBytes * gfxObj->m_vertexArrayOffset + sz; |
| 1192 | b3Assert(totalUsed < m_data->m_maxShapeCapacityInBytes); |
| 1193 | if (totalUsed >= m_data->m_maxShapeCapacityInBytes) |
| 1194 | { |
| 1195 | return -1; |
| 1196 | } |
| 1197 | |
| 1198 | glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo); |
| 1199 | |
| 1200 | #if 0 |
| 1201 | |
| 1202 | char* dest= (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_WRITE_ONLY);//GL_WRITE_ONLY |
| 1203 | |
| 1204 | #ifdef B3_DEBUG |
| 1205 | |
| 1206 | #endif //B3_DEBUG |
| 1207 | |
| 1208 | memcpy(dest+vertexStrideInBytes*gfxObj->m_vertexArrayOffset,vertices,sz); |
| 1209 | glUnmapBuffer( GL_ARRAY_BUFFER); |
| 1210 | #else |
| 1211 | glBufferSubData(GL_ARRAY_BUFFER, vertexStrideInBytes * gfxObj->m_vertexArrayOffset, sz, |
| 1212 | vertices); |
| 1213 | #endif |
| 1214 | |
| 1215 | glGenBuffers(1, &gfxObj->m_index_vbo); |
| 1216 | |
| 1217 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gfxObj->m_index_vbo); |
| 1218 | int indexBufferSizeInBytes = gfxObj->m_numIndices * sizeof(int); |
| 1219 |
no test coverage detected