Showing the changes to interface/src/gpu/Batch.cpp (1 of 7 files). Show all
Unified · Split
| @@ -12,19 +12,13 @@ · 11 unmodified lines | |||
| 12 | 12 | ||
| 13 | #include <QDebug> | 13 | #include <QDebug> |
| 14 | 14 | ||
| 15 | #define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandCalls.push_back(&gpu::Batch::do_##call); _commandOffsets.push_back(_params.size()); | 15 | //#define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandCalls.push_back(&gpu::Batch::do_##call); _commandOffsets.push_back(_params.size()); |
| 16 | 16 | #define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandOffsets.push_back(_params.size()); | |
| 17 | //#define DO_IT_NOW(call, offset) runLastCommand(); | ||
| 18 | #define DO_IT_NOW(call, offset) | ||
| 19 | |||
| 20 | //#define CHECK_GL_ERROR() ::gpu::backend::checkGLError() | ||
| 21 | #define CHECK_GL_ERROR() | ||
| 22 | 17 | ||
| 23 | using namespace gpu; | 18 | using namespace gpu; |
| 24 | 19 | ||
| 25 | Batch::Batch() : | 20 | Batch::Batch() : |
| 26 | _commands(), | 21 | _commands(), |
| 27 | _commandCalls(), | ||
| 28 | _commandOffsets(), | 22 | _commandOffsets(), |
| 29 | _params(), | 23 | _params(), |
| 30 | _resources(), | 24 | _resources(), |
| @@ -36,7 +30,6 @@ Batch::~Batch() { · 5 unmodified lines | |||
| 36 | 30 | ||
| 37 | void Batch::clear() { | 31 | void Batch::clear() { |
| 38 | _commands.clear(); | 32 | _commands.clear(); |
| 39 | _commandCalls.clear(); | ||
| 40 | _commandOffsets.clear(); | 33 | _commandOffsets.clear(); |
| 41 | _params.clear(); | 34 | _params.clear(); |
| 42 | _resources.clear(); | 35 | _resources.clear(); |
| @@ -66,54 +59,6 @@ uint32 Batch::cacheData(uint32 size, const void* data) { · 23 unmodified lines | |||
| 66 | return offset; | 59 | return offset; |
| 67 | } | 60 | } |
| 68 | 61 | ||
| 69 | #define CASE_COMMAND(call) case COMMAND_##call: { do_##call(offset); } break; | ||
| 70 | |||
| 71 | void Batch::runCommand(Command com, uint32 offset) { | ||
| 72 | switch (com) { | ||
| 73 | CASE_COMMAND(draw); | ||
| 74 | CASE_COMMAND(drawIndexed); | ||
| 75 | CASE_COMMAND(drawInstanced); | ||
| 76 | CASE_COMMAND(drawIndexedInstanced); | ||
| 77 | CASE_COMMAND(glEnable); | ||
| 78 | CASE_COMMAND(glDisable); | ||
| 79 | CASE_COMMAND(glEnableClientState); | ||
| 80 | CASE_COMMAND(glDisableClientState); | ||
| 81 | CASE_COMMAND(glCullFace); | ||
| 82 | CASE_COMMAND(glAlphaFunc); | ||
| 83 | CASE_COMMAND(glDepthFunc); | ||
| 84 | CASE_COMMAND(glDepthMask); | ||
| 85 | CASE_COMMAND(glDepthRange); | ||
| 86 | CASE_COMMAND(glBindBuffer); | ||
| 87 | CASE_COMMAND(glBindTexture); | ||
| 88 | CASE_COMMAND(glActiveTexture); | ||
| 89 | CASE_COMMAND(glDrawBuffers); | ||
| 90 | CASE_COMMAND(glUseProgram); | ||
| 91 | CASE_COMMAND(glUniform1f); | ||
| 92 | CASE_COMMAND(glUniformMatrix4fv); | ||
| 93 | CASE_COMMAND(glMatrixMode); | ||
| 94 | CASE_COMMAND(glPushMatrix); | ||
| 95 | CASE_COMMAND(glPopMatrix); | ||
| 96 | CASE_COMMAND(glMultMatrixf); | ||
| 97 | CASE_COMMAND(glLoadMatrixf); | ||
| 98 | CASE_COMMAND(glLoadIdentity); | ||
| 99 | CASE_COMMAND(glRotatef); | ||
| 100 | CASE_COMMAND(glScalef); | ||
| 101 | CASE_COMMAND(glTranslatef); | ||
| 102 | CASE_COMMAND(glDrawArrays); | ||
| 103 | CASE_COMMAND(glDrawRangeElements); | ||
| 104 | CASE_COMMAND(glColorPointer); | ||
| 105 | CASE_COMMAND(glNormalPointer); | ||
| 106 | CASE_COMMAND(glTexCoordPointer); | ||
| 107 | CASE_COMMAND(glVertexPointer); | ||
| 108 | CASE_COMMAND(glVertexAttribPointer); | ||
| 109 | CASE_COMMAND(glEnableVertexAttribArray); | ||
| 110 | CASE_COMMAND(glDisableVertexAttribArray); | ||
| 111 | CASE_COMMAND(glColor4f); | ||
| 112 | CASE_COMMAND(glMaterialf); | ||
| 113 | CASE_COMMAND(glMaterialfv); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | void Batch::draw(Primitive primitiveType, int nbVertices, int startVertex) { | 62 | void Batch::draw(Primitive primitiveType, int nbVertices, int startVertex) { |
| 118 | ADD_COMMAND(draw); | 63 | ADD_COMMAND(draw); |
| 119 | 64 | ||
| @@ -150,605 +95,5 @@ void Batch::drawIndexedInstanced(uint32 nbInstances, Primitive primitiveType, in · 30 unmodified lines | |||
| 150 | _params.push_back(nbInstances); | 95 | _params.push_back(nbInstances); |
| 151 | } | 96 | } |
| 152 | 97 | ||
| 153 | // TODO: As long as we have gl calls explicitely issued from interface | ||
| 154 | // code, we need to be able to record and batch these calls. THe long | ||
| 155 | // term strategy is to get rid of any GL calls in favor of the HIFI GPU API | ||
| 156 | |||
| 157 | void Batch::_glEnable(GLenum cap) { | ||
| 158 | ADD_COMMAND(glEnable); | ||
| 159 | |||
| 160 | _params.push_back(cap); | ||
| 161 | |||
| 162 | DO_IT_NOW(_glEnable, 1); | ||
| 163 | } | ||
| 164 | void Batch::do_glEnable(uint32 paramOffset) { | ||
| 165 | glEnable(_params[paramOffset]._uint); | ||
| 166 | CHECK_GL_ERROR(); | ||
| 167 | } | ||
| 168 | |||
| 169 | void Batch::_glDisable(GLenum cap) { | ||
| 170 | ADD_COMMAND(glDisable); | ||
| 171 | |||
| 172 | _params.push_back(cap); | ||
| 173 | |||
| 174 | DO_IT_NOW(_glDisable, 1); | ||
| 175 | } | ||
| 176 | void Batch::do_glDisable(uint32 paramOffset) { | ||
| 177 | glDisable(_params[paramOffset]._uint); | ||
| 178 | CHECK_GL_ERROR(); | ||
| 179 | } | ||
| 180 | |||
| 181 | void Batch::_glEnableClientState(GLenum array) { | ||
| 182 | ADD_COMMAND(glEnableClientState); | ||
| 183 | |||
| 184 | _params.push_back(array); | ||
| 185 | |||
| 186 | DO_IT_NOW(_glEnableClientState, 1 ); | ||
| 187 | } | ||
| 188 | void Batch::do_glEnableClientState(uint32 paramOffset) { | ||
| 189 | glEnableClientState(_params[paramOffset]._uint); | ||
| 190 | CHECK_GL_ERROR(); | ||
| 191 | } | ||
| 192 | |||
| 193 | void Batch::_glDisableClientState(GLenum array) { | ||
| 194 | ADD_COMMAND(glDisableClientState); | ||
| 195 | |||
| 196 | _params.push_back(array); | ||
| 197 | |||
| 198 | DO_IT_NOW(_glDisableClientState, 1); | ||
| 199 | } | ||
| 200 | void Batch::do_glDisableClientState(uint32 paramOffset) { | ||
| 201 | glDisableClientState(_params[paramOffset]._uint); | ||
| 202 | CHECK_GL_ERROR(); | ||
| 203 | } | ||
| 204 | |||
| 205 | void Batch::_glCullFace(GLenum mode) { | ||
| 206 | ADD_COMMAND(glCullFace); | ||
| 207 | |||
| 208 | _params.push_back(mode); | ||
| 209 | |||
| 210 | DO_IT_NOW(_glCullFace, 1); | ||
| 211 | } | ||
| 212 | void Batch::do_glCullFace(uint32 paramOffset) { | ||
| 213 | glCullFace(_params[paramOffset]._uint); | ||
| 214 | CHECK_GL_ERROR(); | ||
| 215 | } | ||
| 216 | |||
| 217 | void Batch::_glAlphaFunc(GLenum func, GLclampf ref) { | ||
| 218 | ADD_COMMAND(glAlphaFunc); | ||
| 219 | |||
| 220 | _params.push_back(ref); | ||
| 221 | _params.push_back(func); | ||
| 222 | |||
| 223 | DO_IT_NOW(_glAlphaFunc, 2); | ||
| 224 | } | ||
| 225 | void Batch::do_glAlphaFunc(uint32 paramOffset) { | ||
| 226 | glAlphaFunc( | ||
| 227 | _params[paramOffset + 1]._uint, | ||
| 228 | _params[paramOffset + 0]._float); | ||
| 229 | CHECK_GL_ERROR(); | ||
| 230 | } | ||
| 231 | |||
| 232 | void Batch::_glDepthFunc(GLenum func) { | ||
| 233 | ADD_COMMAND(glDepthFunc); | ||
| 234 | |||
| 235 | _params.push_back(func); | ||
| 236 | |||
| 237 | DO_IT_NOW(_glDepthFunc, 1); | ||
| 238 | } | ||
| 239 | void Batch::do_glDepthFunc(uint32 paramOffset) { | ||
| 240 | glDepthFunc(_params[paramOffset]._uint); | ||
| 241 | CHECK_GL_ERROR(); | ||
| 242 | } | ||
| 243 | |||
| 244 | void Batch::_glDepthMask(GLboolean flag) { | ||
| 245 | ADD_COMMAND(glDepthMask); | ||
| 246 | |||
| 247 | _params.push_back(flag); | ||
| 248 | |||
| 249 | DO_IT_NOW(_glDepthMask, 1); | ||
| 250 | } | ||
| 251 | void Batch::do_glDepthMask(uint32 paramOffset) { | ||
| 252 | glDepthMask(_params[paramOffset]._uint); | ||
| 253 | CHECK_GL_ERROR(); | ||
| 254 | } | ||
| 255 | |||
| 256 | void Batch::_glDepthRange(GLclampd zNear, GLclampd zFar) { | ||
| 257 | ADD_COMMAND(glDepthRange); | ||
| 258 | |||
| 259 | _params.push_back(zFar); | ||
| 260 | _params.push_back(zNear); | ||
| 261 | |||
| 262 | DO_IT_NOW(_glDepthRange, 2); | ||
| 263 | } | ||
| 264 | void Batch::do_glDepthRange(uint32 paramOffset) { | ||
| 265 | glDepthRange( | ||
| 266 | _params[paramOffset + 1]._double, | ||
| 267 | _params[paramOffset + 0]._double); | ||
| 268 | CHECK_GL_ERROR(); | ||
| 269 | } | ||
| 270 | |||
| 271 | void Batch::_glBindBuffer(GLenum target, GLuint buffer) { | ||
| 272 | ADD_COMMAND(glBindBuffer); | ||
| 273 | |||
| 274 | _params.push_back(buffer); | ||
| 275 | _params.push_back(target); | ||
| 276 | |||
| 277 | DO_IT_NOW(_glBindBuffer, 2); | ||
| 278 | } | ||
| 279 | void Batch::do_glBindBuffer(uint32 paramOffset) { | ||
| 280 | glBindBuffer( | ||
| 281 | _params[paramOffset + 1]._uint, | ||
| 282 | _params[paramOffset + 0]._uint); | ||
| 283 | CHECK_GL_ERROR(); | ||
| 284 | } | ||
| 285 | |||
| 286 | void Batch::_glBindTexture(GLenum target, GLuint texture) { | ||
| 287 | ADD_COMMAND(glBindTexture); | ||
| 288 | |||
| 289 | _params.push_back(texture); | ||
| 290 | _params.push_back(target); | ||
| 291 | |||
| 292 | DO_IT_NOW(_glBindTexture, 2); | ||
| 293 | } | ||
| 294 | void Batch::do_glBindTexture(uint32 paramOffset) { | ||
| 295 | glBindTexture( | ||
| 296 | _params[paramOffset + 1]._uint, | ||
| 297 | _params[paramOffset + 0]._uint); | ||
| 298 | CHECK_GL_ERROR(); | ||
| 299 | } | ||
| 300 | |||
| 301 | void Batch::_glActiveTexture(GLenum texture) { | ||
| 302 | ADD_COMMAND(glActiveTexture); | ||
| 303 | |||
| 304 | _params.push_back(texture); | ||
| 305 | |||
| 306 | DO_IT_NOW(_glActiveTexture, 1); | ||
| 307 | } | ||
| 308 | void Batch::do_glActiveTexture(uint32 paramOffset) { | ||
| 309 | glActiveTexture(_params[paramOffset]._uint); | ||
| 310 | CHECK_GL_ERROR(); | ||
| 311 | } | ||
| 312 | |||
| 313 | void Batch::_glDrawBuffers(GLsizei n, const GLenum* bufs) { | ||
| 314 | ADD_COMMAND(glDrawBuffers); | ||
| 315 | |||
| 316 | _params.push_back(cacheData(n * sizeof(GLenum), bufs)); | ||
| 317 | _params.push_back(n); | ||
| 318 | |||
| 319 | DO_IT_NOW(_glDrawBuffers, 2); | ||
| 320 | } | ||
| 321 | void Batch::do_glDrawBuffers(uint32 paramOffset) { | ||
| 322 | glDrawBuffers( | ||
| 323 | _params[paramOffset + 1]._uint, | ||
| 324 | (const GLenum*) editData(_params[paramOffset + 0]._uint)); | ||
| 325 | CHECK_GL_ERROR(); | ||
| 326 | } | ||
| 327 | |||
| 328 | void Batch::_glUseProgram(GLuint program) { | ||
| 329 | ADD_COMMAND(glUseProgram); | ||
| 330 | |||
| 331 | _params.push_back(program); | ||
| 332 | |||
| 333 | DO_IT_NOW(_glUseProgram, 1); | ||
| 334 | } | ||
| 335 | void Batch::do_glUseProgram(uint32 paramOffset) { | ||
| 336 | glUseProgram(_params[paramOffset]._uint); | ||
| 337 | CHECK_GL_ERROR(); | ||
| 338 | } | ||
| 339 | |||
| 340 | void Batch::_glUniform1f(GLint location, GLfloat v0) { | ||
| 341 | ADD_COMMAND(glUniform1f); | ||
| 342 | |||
| 343 | _params.push_back(v0); | ||
| 344 | _params.push_back(location); | ||
| 345 | |||
| 346 | DO_IT_NOW(_glUniform1f, 1); | ||
| 347 | } | ||
| 348 | void Batch::do_glUniform1f(uint32 paramOffset) { | ||
| 349 | glUniform1f( | ||
| 350 | _params[paramOffset + 1]._int, | ||
| 351 | _params[paramOffset + 0]._float); | ||
| 352 | CHECK_GL_ERROR(); | ||
| 353 | } | ||
| 354 | |||
| 355 | void Batch::_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { | ||
| 356 | ADD_COMMAND(glUniformMatrix4fv); | ||
| 357 | |||
| 358 | const int MATRIX4_SIZE = 16 * sizeof(float); | ||
| 359 | _params.push_back(cacheData(count * MATRIX4_SIZE, value)); | ||
| 360 | _params.push_back(transpose); | ||
| 361 | _params.push_back(count); | ||
| 362 | _params.push_back(location); | ||
| 363 | |||
| 364 | DO_IT_NOW(_glUniformMatrix4fv, 4); | ||
| 365 | } | ||
| 366 | void Batch::do_glUniformMatrix4fv(uint32 paramOffset) { | ||
| 367 | glUniformMatrix4fv( | ||
| 368 | _params[paramOffset + 3]._int, | ||
| 369 | _params[paramOffset + 2]._uint, | ||
| 370 | _params[paramOffset + 1]._uint, | ||
| 371 | (const GLfloat*) editData(_params[paramOffset + 0]._uint)); | ||
| 372 | CHECK_GL_ERROR(); | ||
| 373 | } | ||
| 374 | |||
| 375 | void Batch::_glMatrixMode(GLenum mode) { | ||
| 376 | ADD_COMMAND(glMatrixMode); | ||
| 377 | |||
| 378 | _params.push_back(mode); | ||
| 379 | |||
| 380 | DO_IT_NOW(_glMatrixMode, 1); | ||
| 381 | } | ||
| 382 | void Batch::do_glMatrixMode(uint32 paramOffset) { | ||
| 383 | glMatrixMode(_params[paramOffset]._uint); | ||
| 384 | CHECK_GL_ERROR(); | ||
| 385 | } | ||
| 386 | |||
| 387 | void Batch::_glPushMatrix() { | ||
| 388 | ADD_COMMAND(glPushMatrix); | ||
| 389 | |||
| 390 | DO_IT_NOW(_glPushMatrix, 0); | ||
| 391 | } | ||
| 392 | void Batch::do_glPushMatrix(uint32 paramOffset) { | ||
| 393 | glPushMatrix(); | ||
| 394 | CHECK_GL_ERROR(); | ||
| 395 | } | ||
| 396 | |||
| 397 | void Batch::_glPopMatrix() { | ||
| 398 | ADD_COMMAND(glPopMatrix); | ||
| 399 | |||
| 400 | DO_IT_NOW(_glPopMatrix, 0); | ||
| 401 | } | ||
| 402 | void Batch::do_glPopMatrix(uint32 paramOffset) { | ||
| 403 | glPopMatrix(); | ||
| 404 | CHECK_GL_ERROR(); | ||
| 405 | } | ||
| 406 | |||
| 407 | void Batch::_glMultMatrixf(const GLfloat *m) { | ||
| 408 | ADD_COMMAND(glMultMatrixf); | ||
| 409 | |||
| 410 | const int MATRIX4_SIZE = 16 * sizeof(float); | ||
| 411 | _params.push_back(cacheData(MATRIX4_SIZE, m)); | ||
| 412 | |||
| 413 | DO_IT_NOW(_glMultMatrixf, 1); | ||
| 414 | } | ||
| 415 | void Batch::do_glMultMatrixf(uint32 paramOffset) { | ||
| 416 | glMultMatrixf((const GLfloat*) editData(_params[paramOffset]._uint)); | ||
| 417 | CHECK_GL_ERROR(); | ||
| 418 | } | ||
| 419 | |||
| 420 | void Batch::_glLoadMatrixf(const GLfloat *m) { | ||
| 421 | ADD_COMMAND(glLoadMatrixf); | ||
| 422 | |||
| 423 | const int MATRIX4_SIZE = 16 * sizeof(float); | ||
| 424 | _params.push_back(cacheData(MATRIX4_SIZE, m)); | ||
| 425 | |||
| 426 | DO_IT_NOW(_glLoadMatrixf, 1); | ||
| 427 | } | ||
| 428 | void Batch::do_glLoadMatrixf(uint32 paramOffset) { | ||
| 429 | glLoadMatrixf((const GLfloat*)editData(_params[paramOffset]._uint)); | ||
| 430 | CHECK_GL_ERROR(); | ||
| 431 | } | ||
| 432 | |||
| 433 | void Batch::_glLoadIdentity(void) { | ||
| 434 | ADD_COMMAND(glLoadIdentity); | ||
| 435 | |||
| 436 | DO_IT_NOW(_glLoadIdentity, 0); | ||
| 437 | } | ||
| 438 | void Batch::do_glLoadIdentity(uint32 paramOffset) { | ||
| 439 | glLoadIdentity(); | ||
| 440 | CHECK_GL_ERROR(); | ||
| 441 | } | ||
| 442 | |||
| 443 | void Batch::_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { | ||
| 444 | ADD_COMMAND(glRotatef); | ||
| 445 | |||
| 446 | _params.push_back(z); | ||
| 447 | _params.push_back(y); | ||
| 448 | _params.push_back(x); | ||
| 449 | _params.push_back(angle); | ||
| 450 | |||
| 451 | DO_IT_NOW(_glRotatef, 4); | ||
| 452 | } | ||
| 453 | void Batch::do_glRotatef(uint32 paramOffset) { | ||
| 454 | glRotatef( | ||
| 455 | _params[paramOffset + 3]._float, | ||
| 456 | _params[paramOffset + 2]._float, | ||
| 457 | _params[paramOffset + 1]._float, | ||
| 458 | _params[paramOffset + 0]._float); | ||
| 459 | CHECK_GL_ERROR(); | ||
| 460 | } | ||
| 461 | |||
| 462 | void Batch::_glScalef(GLfloat x, GLfloat y, GLfloat z) { | ||
| 463 | ADD_COMMAND(glScalef); | ||
| 464 | |||
| 465 | _params.push_back(z); | ||
| 466 | _params.push_back(y); | ||
| 467 | _params.push_back(x); | ||
| 468 | |||
| 469 | DO_IT_NOW(_glScalef, 3); | ||
| 470 | } | ||
| 471 | void Batch::do_glScalef(uint32 paramOffset) { | ||
| 472 | glScalef( | ||
| 473 | _params[paramOffset + 2]._float, | ||
| 474 | _params[paramOffset + 1]._float, | ||
| 475 | _params[paramOffset + 0]._float); | ||
| 476 | CHECK_GL_ERROR(); | ||
| 477 | } | ||
| 478 | |||
| 479 | void Batch::_glTranslatef(GLfloat x, GLfloat y, GLfloat z) { | ||
| 480 | ADD_COMMAND(glTranslatef); | ||
| 481 | |||
| 482 | _params.push_back(z); | ||
| 483 | _params.push_back(y); | ||
| 484 | _params.push_back(x); | ||
| 485 | |||
| 486 | DO_IT_NOW(_glTranslatef, 3); | ||
| 487 | } | ||
| 488 | void Batch::do_glTranslatef(uint32 paramOffset) { | ||
| 489 | glTranslatef( | ||
| 490 | _params[paramOffset + 2]._float, | ||
| 491 | _params[paramOffset + 1]._float, | ||
| 492 | _params[paramOffset + 0]._float); | ||
| 493 | CHECK_GL_ERROR(); | ||
| 494 | } | ||
| 495 | |||
| 496 | void Batch::_glDrawArrays(GLenum mode, GLint first, GLsizei count) { | ||
| 497 | ADD_COMMAND(glDrawArrays); | ||
| 498 | |||
| 499 | _params.push_back(count); | ||
| 500 | _params.push_back(first); | ||
| 501 | _params.push_back(mode); | ||
| 502 | |||
| 503 | DO_IT_NOW(_glDrawArrays, 3); | ||
| 504 | } | ||
| 505 | void Batch::do_glDrawArrays(uint32 paramOffset) { | ||
| 506 | glDrawArrays( | ||
| 507 | _params[paramOffset + 2]._uint, | ||
| 508 | _params[paramOffset + 1]._int, | ||
| 509 | _params[paramOffset + 0]._int); | ||
| 510 | CHECK_GL_ERROR(); | ||
| 511 | } | ||
| 512 | |||
| 513 | void Batch::_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices) { | ||
| 514 | ADD_COMMAND(glDrawRangeElements); | ||
| 515 | |||
| 516 | _params.push_back(cacheResource(indices)); | ||
| 517 | _params.push_back(type); | ||
| 518 | _params.push_back(count); | ||
| 519 | _params.push_back(end); | ||
| 520 | _params.push_back(start); | ||
| 521 | _params.push_back(mode); | ||
| 522 | |||
| 523 | DO_IT_NOW(_glDrawRangeElements, 6); | ||
| 524 | } | ||
| 525 | void Batch::do_glDrawRangeElements(uint32 paramOffset) { | ||
| 526 | glDrawRangeElements( | ||
| 527 | _params[paramOffset + 5]._uint, | ||
| 528 | _params[paramOffset + 4]._uint, | ||
| 529 | _params[paramOffset + 3]._uint, | ||
| 530 | _params[paramOffset + 2]._int, | ||
| 531 | _params[paramOffset + 1]._uint, | ||
| 532 | editResource(_params[paramOffset + 0]._uint)->_pointer); | ||
| 533 | CHECK_GL_ERROR(); | ||
| 534 | } | ||
| 535 | |||
| 536 | void Batch::_glColorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) { | ||
| 537 | ADD_COMMAND(glColorPointer); | ||
| 538 | |||
| 539 | _params.push_back(cacheResource(pointer)); | ||
| 540 | _params.push_back(stride); | ||
| 541 | _params.push_back(type); | ||
| 542 | _params.push_back(size); | ||
| 543 | |||
| 544 | DO_IT_NOW(_glColorPointer, 4); | ||
| 545 | } | ||
| 546 | void Batch::do_glColorPointer(uint32 paramOffset) { | ||
| 547 | glColorPointer( | ||
| 548 | _params[paramOffset + 3]._int, | ||
| 549 | _params[paramOffset + 2]._uint, | ||
| 550 | _params[paramOffset + 1]._int, | ||
| 551 | editResource(_params[paramOffset + 0]._uint)->_pointer); | ||
| 552 | CHECK_GL_ERROR(); | ||
| 553 | } | ||
| 554 | |||
| 555 | void Batch::_glNormalPointer(GLenum type, GLsizei stride, const void *pointer) { | ||
| 556 | ADD_COMMAND(glNormalPointer); | ||
| 557 | |||
| 558 | _params.push_back(cacheResource(pointer)); | ||
| 559 | _params.push_back(stride); | ||
| 560 | _params.push_back(type); | ||
| 561 | |||
| 562 | DO_IT_NOW(_glNormalPointer, 3); | ||
| 563 | } | ||
| 564 | void Batch::do_glNormalPointer(uint32 paramOffset) { | ||
| 565 | glNormalPointer( | ||
| 566 | _params[paramOffset + 2]._uint, | ||
| 567 | _params[paramOffset + 1]._int, | ||
| 568 | editResource(_params[paramOffset + 0]._uint)->_pointer); | ||
| 569 | CHECK_GL_ERROR(); | ||
| 570 | } | ||
| 571 | |||
| 572 | void Batch::_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) { | ||
| 573 | ADD_COMMAND(glTexCoordPointer); | ||
| 574 | |||
| 575 | _params.push_back(cacheResource(pointer)); | ||
| 576 | _params.push_back(stride); | ||
| 577 | _params.push_back(type); | ||
| 578 | _params.push_back(size); | ||
| 579 | |||
| 580 | DO_IT_NOW(_glTexCoordPointer, 4); | ||
| 581 | } | ||
| 582 | void Batch::do_glTexCoordPointer(uint32 paramOffset) { | ||
| 583 | glTexCoordPointer( | ||
| 584 | _params[paramOffset + 3]._int, | ||
| 585 | _params[paramOffset + 2]._uint, | ||
| 586 | _params[paramOffset + 1]._int, | ||
| 587 | editResource(_params[paramOffset + 0]._uint)->_pointer); | ||
| 588 | CHECK_GL_ERROR(); | ||
| 589 | } | ||
| 590 | |||
| 591 | void Batch::_glVertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer) { | ||
| 592 | ADD_COMMAND(glVertexPointer); | ||
| 593 | |||
| 594 | _params.push_back(cacheResource(pointer)); | ||
| 595 | _params.push_back(stride); | ||
| 596 | _params.push_back(type); | ||
| 597 | _params.push_back(size); | ||
| 598 | |||
| 599 | DO_IT_NOW(_glVertexPointer, 4); | ||
| 600 | } | ||
| 601 | void Batch::do_glVertexPointer(uint32 paramOffset) { | ||
| 602 | glVertexPointer( | ||
| 603 | _params[paramOffset + 3]._int, | ||
| 604 | _params[paramOffset + 2]._uint, | ||
| 605 | _params[paramOffset + 1]._int, | ||
| 606 | editResource(_params[paramOffset + 0]._uint)->_pointer); | ||
| 607 | CHECK_GL_ERROR(); | ||
| 608 | } | ||
| 609 | |||
| 610 | |||
| 611 | void Batch::_glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) { | ||
| 612 | ADD_COMMAND(glVertexAttribPointer); | ||
| 613 | |||
| 614 | _params.push_back(cacheResource(pointer)); | ||
| 615 | _params.push_back(stride); | ||
| 616 | _params.push_back(normalized); | ||
| 617 | _params.push_back(type); | ||
| 618 | _params.push_back(size); | ||
| 619 | _params.push_back(index); | ||
| 620 | |||
| 621 | DO_IT_NOW(_glVertexAttribPointer, 6); | ||
| 622 | } | ||
| 623 | void Batch::do_glVertexAttribPointer(uint32 paramOffset) { | ||
| 624 | glVertexAttribPointer( | ||
| 625 | _params[paramOffset + 5]._uint, | ||
| 626 | _params[paramOffset + 4]._int, | ||
| 627 | _params[paramOffset + 3]._uint, | ||
| 628 | _params[paramOffset + 2]._uint, | ||
| 629 | _params[paramOffset + 1]._int, | ||
| 630 | editResource(_params[paramOffset + 0]._uint)->_pointer); | ||
| 631 | CHECK_GL_ERROR(); | ||
| 632 | } | ||
| 633 | |||
| 634 | void Batch::_glEnableVertexAttribArray(GLint location) { | ||
| 635 | ADD_COMMAND(glEnableVertexAttribArray); | ||
| 636 | |||
| 637 | _params.push_back(location); | ||
| 638 | |||
| 639 | DO_IT_NOW(_glEnableVertexAttribArray, 1); | ||
| 640 | } | ||
| 641 | void Batch::do_glEnableVertexAttribArray(uint32 paramOffset) { | ||
| 642 | glEnableVertexAttribArray(_params[paramOffset]._uint); | ||
| 643 | CHECK_GL_ERROR(); | ||
| 644 | } | ||
| 645 | |||
| 646 | void Batch::_glDisableVertexAttribArray(GLint location) { | ||
| 647 | ADD_COMMAND(glDisableVertexAttribArray); | ||
| 648 | |||
| 649 | _params.push_back(location); | ||
| 650 | |||
| 651 | DO_IT_NOW(_glDisableVertexAttribArray, 1); | ||
| 652 | } | ||
| 653 | void Batch::do_glDisableVertexAttribArray(uint32 paramOffset) { | ||
| 654 | glDisableVertexAttribArray(_params[paramOffset]._uint); | ||
| 655 | CHECK_GL_ERROR(); | ||
| 656 | } | ||
| 657 | |||
| 658 | void Batch::_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { | ||
| 659 | ADD_COMMAND(glColor4f); | ||
| 660 | |||
| 661 | _params.push_back(alpha); | ||
| 662 | _params.push_back(blue); | ||
| 663 | _params.push_back(green); | ||
| 664 | _params.push_back(red); | ||
| 665 | |||
| 666 | DO_IT_NOW(_glColor4f, 4); | ||
| 667 | } | ||
| 668 | void Batch::do_glColor4f(uint32 paramOffset) { | ||
| 669 | glColor4f( | ||
| 670 | _params[paramOffset + 3]._float, | ||
| 671 | _params[paramOffset + 2]._float, | ||
| 672 | _params[paramOffset + 1]._float, | ||
| 673 | _params[paramOffset + 0]._float); | ||
| 674 | CHECK_GL_ERROR(); | ||
| 675 | } | ||
| 676 | |||
| 677 | void Batch::_glMaterialf(GLenum face, GLenum pname, GLfloat param) { | ||
| 678 | ADD_COMMAND(glMaterialf); | ||
| 679 | |||
| 680 | _params.push_back(param); | ||
| 681 | _params.push_back(pname); | ||
| 682 | _params.push_back(face); | ||
| 683 | 98 | ||
| 684 | DO_IT_NOW(_glMaterialf, 3); | ||
| 685 | } | ||
| 686 | void Batch::do_glMaterialf(uint32 paramOffset) { | ||
| 687 | glMaterialf( | ||
| 688 | _params[paramOffset + 2]._uint, | ||
| 689 | _params[paramOffset + 1]._uint, | ||
| 690 | _params[paramOffset + 0]._float); | ||
| 691 | CHECK_GL_ERROR(); | ||
| 692 | } | ||
| 693 | |||
| 694 | void Batch::_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) { | ||
| 695 | ADD_COMMAND(glMaterialfv); | ||
| 696 | |||
| 697 | _params.push_back(cacheData(4 * sizeof(float), params)); | ||
| 698 | _params.push_back(pname); | ||
| 699 | _params.push_back(face); | ||
| 700 | |||
| 701 | DO_IT_NOW(_glMaterialfv, 3); | ||
| 702 | } | ||
| 703 | void Batch::do_glMaterialfv(uint32 paramOffset) { | ||
| 704 | glMaterialfv( | ||
| 705 | _params[paramOffset + 2]._uint, | ||
| 706 | _params[paramOffset + 1]._uint, | ||
| 707 | (const GLfloat*) editData(_params[paramOffset + 0]._uint)); | ||
| 708 | CHECK_GL_ERROR(); | ||
| 709 | } | ||
| 710 | |||
| 711 | |||
| 712 | |||
| 713 | void backend::renderBatch(Batch& batch) { | ||
| 714 | uint32 numCommands = batch._commands.size(); | ||
| 715 | Batch::CommandCall* call = batch._commandCalls.data(); | ||
| 716 | Batch::CommandOffsets::value_type* offset = batch._commandOffsets.data(); | ||
| 717 | |||
| 718 | for (int i = 0; i < numCommands; i++) { | ||
| 719 | (batch.*(*call))(*offset); | ||
| 720 | call++; | ||
| 721 | offset++; | ||
| 722 | } | ||
| 723 | } | ||
| 724 | 99 | ||
| 725 | void backend::checkGLError() { | ||
| 726 | GLenum error = glGetError(); | ||
| 727 | if (!error) { | ||
| 728 | return; | ||
| 729 | } else { | ||
| 730 | switch (error) { | ||
| 731 | case GL_INVALID_ENUM: | ||
| 732 | qDebug() << "An unacceptable value is specified for an enumerated argument.The offending command is ignored and has no other side effect than to set the error flag."; | ||
| 733 | break; | ||
| 734 | case GL_INVALID_VALUE: | ||
| 735 | qDebug() << "A numeric argument is out of range.The offending command is ignored and has no other side effect than to set the error flag"; | ||
| 736 | break; | ||
| 737 | case GL_INVALID_OPERATION: | ||
| 738 | qDebug() << "The specified operation is not allowed in the current state.The offending command is ignored and has no other side effect than to set the error flag.."; | ||
| 739 | break; | ||
| 740 | case GL_INVALID_FRAMEBUFFER_OPERATION: | ||
| 741 | qDebug() << "The framebuffer object is not complete.The offending command is ignored and has no other side effect than to set the error flag."; | ||
| 742 | break; | ||
| 743 | case GL_OUT_OF_MEMORY: | ||
| 744 | qDebug() << "There is not enough memory left to execute the command.The state of the GL is undefined, except for the state of the error flags, after this error is recorded."; | ||
| 745 | break; | ||
| 746 | case GL_STACK_UNDERFLOW: | ||
| 747 | qDebug() << "An attempt has been made to perform an operation that would cause an internal stack to underflow."; | ||
| 748 | break; | ||
| 749 | case GL_STACK_OVERFLOW: | ||
| 750 | qDebug() << "An attempt has been made to perform an operation that would cause an internal stack to overflow."; | ||
| 751 | break; | ||
| 752 | } | ||
| 753 | } | ||
| 754 | } | ||