this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Some breaking changes to make matrix stuff less dependent on implicit state. Moved matrix stacks into GPU_Target so that image targets can use their own (esp. inverted projection), independent of the context target.

+211 -169
+18 -18
demos/3d/main.c
··· 17 17 GPU_FlushBlitBuffer(); 18 18 19 19 20 - GPU_MatrixMode(GPU_MODELVIEW); 21 - GPU_PushMatrix(); 22 - GPU_LoadIdentity(); 23 - GPU_MatrixMode(GPU_PROJECTION); 24 - GPU_PushMatrix(); 25 - GPU_LoadIdentity(); 20 + GPU_MatrixMode(screen, GPU_MODELVIEW); 21 + GPU_PushMatrix(screen); 22 + GPU_LoadIdentity(screen); 23 + GPU_MatrixMode(screen, GPU_PROJECTION); 24 + GPU_PushMatrix(screen); 25 + GPU_LoadIdentity(screen); 26 26 } 27 27 28 28 void end_3d(GPU_Target* screen) 29 29 { 30 30 GPU_ResetRendererState(); 31 31 32 - GPU_MatrixMode(GPU_MODELVIEW); 33 - GPU_PopMatrix(); 34 - GPU_MatrixMode(GPU_PROJECTION); 35 - GPU_PopMatrix(); 32 + GPU_MatrixMode(screen, GPU_MODELVIEW); 33 + GPU_PopMatrix(screen); 34 + GPU_MatrixMode(screen, GPU_PROJECTION); 35 + GPU_PopMatrix(screen); 36 36 } 37 37 38 - void draw_spinning_triangle() 38 + void draw_spinning_triangle(GPU_Target* screen) 39 39 { 40 40 GLfloat gldata[21]; 41 41 float mvp[16]; 42 42 float t = SDL_GetTicks()/1000.0f; 43 43 44 - GPU_Rotate(100*t, 0, 0.707, 0.707); 45 - GPU_Rotate(20*t, 0.707, 0.707, 0); 44 + GPU_Rotate(screen, 100*t, 0, 0.707, 0.707); 45 + GPU_Rotate(screen, 20*t, 0.707, 0.707, 0); 46 46 47 47 48 48 gldata[0] = 0; ··· 75 75 76 76 glUseProgram(p); 77 77 78 - GPU_GetModelViewProjection(mvp); 78 + GPU_GetModelViewProjection(screen, mvp); 79 79 glUniformMatrix4fv(modelViewProjection_loc, 1, 0, mvp); 80 80 81 81 ··· 113 113 { 114 114 begin_3d(screen); 115 115 116 - draw_spinning_triangle(); 116 + draw_spinning_triangle(screen); 117 117 118 118 end_3d(screen); 119 119 } ··· 124 124 begin_3d(screen); 125 125 126 126 t = SDL_GetTicks()/1000.0f; 127 - GPU_Rotate(t*60, 0, 0, 1); 128 - GPU_Translate(0.4f, 0.4f, 0); 129 - draw_spinning_triangle(); 127 + GPU_Rotate(screen, t*60, 0, 0, 1); 128 + GPU_Translate(screen, 0.4f, 0.4f, 0); 129 + draw_spinning_triangle(screen); 130 130 131 131 end_3d(screen); 132 132 }
+27 -20
include/SDL_gpu.h
··· 402 402 GPU_BlendMode shapes_blend_mode; 403 403 float line_thickness; 404 404 GPU_bool use_texturing; 405 - 406 - int matrix_mode; 407 - GPU_MatrixStack projection_matrix; 408 - GPU_MatrixStack modelview_matrix; 409 405 410 406 int refcount; 411 407 ··· 440 436 GPU_Rect viewport; 441 437 442 438 /*! Perspective and object viewing transforms. */ 439 + int matrix_mode; 440 + GPU_MatrixStack projection_matrix; 441 + GPU_MatrixStack modelview_matrix; 442 + 443 443 GPU_Camera camera; 444 444 GPU_bool use_camera; 445 + 445 446 446 447 GPU_bool use_depth_test; 447 448 GPU_bool use_depth_write; ··· 1366 1367 DECLSPEC const char* SDLCALL GPU_GetMatrixString(const float* A); 1367 1368 1368 1369 /*! Returns the current matrix from the top of the matrix stack. Returns NULL if stack is empty. */ 1369 - DECLSPEC float* SDLCALL GPU_GetCurrentMatrix(void); 1370 + DECLSPEC float* SDLCALL GPU_GetCurrentMatrix(GPU_Target* target); 1370 1371 1371 1372 /*! Returns the current modelview matrix from the top of the matrix stack. Returns NULL if stack is empty. */ 1372 - DECLSPEC float* SDLCALL GPU_GetModelView(void); 1373 + DECLSPEC float* SDLCALL GPU_GetModelView(GPU_Target* target); 1373 1374 1374 1375 /*! Returns the current projection matrix from the top of the matrix stack. Returns NULL if stack is empty. */ 1375 - DECLSPEC float* SDLCALL GPU_GetProjection(void); 1376 + DECLSPEC float* SDLCALL GPU_GetProjection(GPU_Target* target); 1376 1377 1377 1378 /*! Copies the current modelview-projection matrix into the given 'result' matrix (result = P*M). */ 1378 - DECLSPEC void SDLCALL GPU_GetModelViewProjection(float* result); 1379 + DECLSPEC void SDLCALL GPU_GetModelViewProjection(GPU_Target* target, float* result); 1379 1380 1380 1381 1381 1382 // Matrix stack manipulators ··· 1383 1384 /*! Allocate new matrices for the given stack. */ 1384 1385 DECLSPEC void SDLCALL GPU_InitMatrixStack(GPU_MatrixStack* stack); 1385 1386 1387 + /*! Copies matrices from one stack to another. */ 1388 + DECLSPEC void SDLCALL GPU_CopyMatrixStack(GPU_MatrixStack* source, GPU_MatrixStack* dest); 1389 + 1390 + /*! Deletes matrices in the given stack. */ 1391 + DECLSPEC void SDLCALL GPU_ClearMatrixStack(GPU_MatrixStack* stack); 1392 + 1386 1393 /*! Reapplies the default orthographic projection matrix, based on camera and coordinate settings. */ 1387 - DECLSPEC void SDLCALL GPU_ResetProjection(void); 1394 + DECLSPEC void SDLCALL GPU_ResetProjection(GPU_Target* target); 1388 1395 1389 1396 /*! Changes matrix mode to either GPU_PROJECTION or GPU_MODELVIEW. Further matrix stack operations manipulate that particular stack. */ 1390 - DECLSPEC void SDLCALL GPU_MatrixMode(int matrix_mode); 1397 + DECLSPEC void SDLCALL GPU_MatrixMode(GPU_Target* target, int matrix_mode); 1391 1398 1392 1399 /*! Pushes the current matrix as a new matrix stack item. */ 1393 - DECLSPEC void SDLCALL GPU_PushMatrix(void); 1400 + DECLSPEC void SDLCALL GPU_PushMatrix(GPU_Target* target); 1394 1401 1395 1402 /*! Removes the current matrix from the stack. */ 1396 - DECLSPEC void SDLCALL GPU_PopMatrix(void); 1403 + DECLSPEC void SDLCALL GPU_PopMatrix(GPU_Target* target); 1397 1404 1398 1405 /*! Fills current matrix with the identity matrix. */ 1399 - DECLSPEC void SDLCALL GPU_LoadIdentity(void); 1406 + DECLSPEC void SDLCALL GPU_LoadIdentity(GPU_Target* target); 1400 1407 1401 1408 /*! Copies a given matrix to be the current matrix. */ 1402 - DECLSPEC void SDLCALL GPU_LoadMatrix(const float* matrix4x4); 1409 + DECLSPEC void SDLCALL GPU_LoadMatrix(GPU_Target* target, const float* matrix4x4); 1403 1410 1404 1411 /*! Multiplies an orthographic projection matrix into the current matrix. */ 1405 - DECLSPEC void SDLCALL GPU_Ortho(float left, float right, float bottom, float top, float z_near, float z_far); 1412 + DECLSPEC void SDLCALL GPU_Ortho(GPU_Target* target, float left, float right, float bottom, float top, float z_near, float z_far); 1406 1413 1407 1414 /*! Multiplies a perspective projection matrix into the current matrix. */ 1408 - DECLSPEC void SDLCALL GPU_Frustum(float left, float right, float bottom, float top, float z_near, float z_far); 1415 + DECLSPEC void SDLCALL GPU_Frustum(GPU_Target* target, float left, float right, float bottom, float top, float z_near, float z_far); 1409 1416 1410 1417 /*! Adds a translation into the current matrix. */ 1411 - DECLSPEC void SDLCALL GPU_Translate(float x, float y, float z); 1418 + DECLSPEC void SDLCALL GPU_Translate(GPU_Target* target, float x, float y, float z); 1412 1419 1413 1420 /*! Multiplies a scaling matrix into the current matrix. */ 1414 - DECLSPEC void SDLCALL GPU_Scale(float sx, float sy, float sz); 1421 + DECLSPEC void SDLCALL GPU_Scale(GPU_Target* target, float sx, float sy, float sz); 1415 1422 1416 1423 /*! Multiplies a rotation matrix into the current matrix. */ 1417 - DECLSPEC void SDLCALL GPU_Rotate(float degrees, float x, float y, float z); 1424 + DECLSPEC void SDLCALL GPU_Rotate(GPU_Target* target, float degrees, float x, float y, float z); 1418 1425 1419 1426 /*! Multiplies a given matrix into the current matrix. */ 1420 - DECLSPEC void SDLCALL GPU_MultMatrix(const float* matrix4x4); 1427 + DECLSPEC void SDLCALL GPU_MultMatrix(GPU_Target* target, const float* matrix4x4); 1421 1428 1422 1429 // End of Matrix 1423 1430 /*! @} */
+75 -48
src/SDL_gpu_matrix.c
··· 59 59 if(stack == NULL) 60 60 return; 61 61 62 + if (stack->storage_size != 0) 63 + GPU_ClearMatrixStack(stack); 64 + 62 65 stack->storage_size = 1; 63 66 stack->size = 1; 64 67 ··· 67 70 GPU_MatrixIdentity(stack->matrix[0]); 68 71 } 69 72 73 + void GPU_CopyMatrixStack(GPU_MatrixStack* source, GPU_MatrixStack* dest) 74 + { 75 + int i; 76 + unsigned int matrix_size = sizeof(float) * 16; 77 + if (source == NULL || dest == NULL) 78 + return; 70 79 71 - void GPU_ResetProjection(void) 80 + GPU_ClearMatrixStack(dest); 81 + dest->matrix = (float**)SDL_malloc(sizeof(float*) * source->storage_size); 82 + for (i = 0; i < source->storage_size; ++i) 83 + { 84 + dest->matrix[i] = (float*)SDL_malloc(matrix_size); 85 + memcpy(dest->matrix[i], source->matrix[i], matrix_size); 86 + } 87 + dest->storage_size = source->storage_size; 88 + } 89 + 90 + void GPU_ClearMatrixStack(GPU_MatrixStack* stack) 72 91 { 73 - GPU_Target* target = GPU_GetContextTarget(); 92 + int i; 93 + for (i = 0; i < stack->storage_size; ++i) 94 + { 95 + SDL_free(stack->matrix[i]); 96 + } 97 + SDL_free(stack->matrix); 98 + 99 + stack->matrix = NULL; 100 + stack->storage_size = 0; 101 + } 102 + 103 + 104 + void GPU_ResetProjection(GPU_Target* target) 105 + { 74 106 if(target == NULL) 75 107 return; 76 108 77 109 GPU_bool invert = (target->image != NULL); 78 110 79 111 // Set up default projection 80 - float* projection_matrix = GPU_GetProjection(); 112 + float* projection_matrix = GPU_GetProjection(target); 81 113 GPU_MatrixIdentity(projection_matrix); 82 114 83 115 if(!invert ^ GPU_GetCoordinateMode()) ··· 432 464 return b; 433 465 } 434 466 435 - void GPU_MatrixMode(int matrix_mode) 467 + void GPU_MatrixMode(GPU_Target* target, int matrix_mode) 436 468 { 437 - GPU_Target* target = GPU_GetContextTarget(); 438 - if(target == NULL || target->context == NULL) 469 + if(target == NULL) 439 470 return; 440 471 441 - target->context->matrix_mode = matrix_mode; 472 + target->matrix_mode = matrix_mode; 442 473 } 443 474 444 - float* GPU_GetModelView(void) 475 + float* GPU_GetModelView(GPU_Target* target) 445 476 { 446 - GPU_Target* target = GPU_GetContextTarget(); 447 477 GPU_MatrixStack* stack; 448 478 449 - if(target == NULL || target->context == NULL) 479 + if(target == NULL) 450 480 return NULL; 451 - stack = &target->context->modelview_matrix; 481 + stack = &target->modelview_matrix; 452 482 if(stack->size == 0) 453 483 return NULL; 454 484 return stack->matrix[stack->size-1]; 455 485 } 456 486 457 - float* GPU_GetProjection(void) 487 + float* GPU_GetProjection(GPU_Target* target) 458 488 { 459 - GPU_Target* target = GPU_GetContextTarget(); 460 489 GPU_MatrixStack* stack; 461 490 462 - if(target == NULL || target->context == NULL) 491 + if(target == NULL) 463 492 return NULL; 464 - stack = &target->context->projection_matrix; 493 + stack = &target->projection_matrix; 465 494 if(stack->size == 0) 466 495 return NULL; 467 496 return stack->matrix[stack->size-1]; 468 497 } 469 498 470 - float* GPU_GetCurrentMatrix(void) 499 + float* GPU_GetCurrentMatrix(GPU_Target* target) 471 500 { 472 - GPU_Target* target = GPU_GetContextTarget(); 473 501 GPU_MatrixStack* stack; 474 502 475 - if(target == NULL || target->context == NULL) 503 + if(target == NULL) 476 504 return NULL; 477 - if(target->context->matrix_mode == GPU_MODELVIEW) 478 - stack = &target->context->modelview_matrix; 505 + if(target->matrix_mode == GPU_MODELVIEW) 506 + stack = &target->modelview_matrix; 479 507 else 480 - stack = &target->context->projection_matrix; 508 + stack = &target->projection_matrix; 481 509 482 510 if(stack->size == 0) 483 511 return NULL; 484 512 return stack->matrix[stack->size-1]; 485 513 } 486 514 487 - void GPU_PushMatrix(void) 515 + void GPU_PushMatrix(GPU_Target* target) 488 516 { 489 - GPU_Target* target = GPU_GetContextTarget(); 490 517 GPU_MatrixStack* stack; 491 518 492 - if(target == NULL || target->context == NULL) 519 + if(target == NULL) 493 520 return; 494 521 495 - stack = (target->context->matrix_mode == GPU_MODELVIEW? &target->context->modelview_matrix : &target->context->projection_matrix); 522 + stack = (target->matrix_mode == GPU_MODELVIEW? &target->modelview_matrix : &target->projection_matrix); 496 523 if(stack->size + 1 >= stack->storage_size) 497 524 { 498 525 // Grow matrix stack (1, 6, 16, 36, ...) ··· 525 552 stack->size++; 526 553 } 527 554 528 - void GPU_PopMatrix(void) 555 + void GPU_PopMatrix(GPU_Target* target) 529 556 { 530 - GPU_Target* target = GPU_GetContextTarget(); 531 557 GPU_MatrixStack* stack; 532 558 533 - if(target == NULL || target->context == NULL) 559 + if(target == NULL) 534 560 return; 535 - 561 + 562 + // FIXME: Flushing here is not always necessary if this isn't the last target 536 563 GPU_FlushBlitBuffer(); 537 - stack = (target->context->matrix_mode == GPU_MODELVIEW? &target->context->modelview_matrix : &target->context->projection_matrix); 564 + stack = (target->matrix_mode == GPU_MODELVIEW? &target->modelview_matrix : &target->projection_matrix); 538 565 if(stack->size == 0) 539 566 { 540 567 GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Matrix stack is empty."); ··· 547 574 stack->size--; 548 575 } 549 576 550 - void GPU_LoadIdentity(void) 577 + void GPU_LoadIdentity(GPU_Target* target) 551 578 { 552 - float* result = GPU_GetCurrentMatrix(); 579 + float* result = GPU_GetCurrentMatrix(target); 553 580 if(result == NULL) 554 581 return; 555 582 ··· 557 584 GPU_MatrixIdentity(result); 558 585 } 559 586 560 - void GPU_LoadMatrix(const float* A) 587 + void GPU_LoadMatrix(GPU_Target* target, const float* A) 561 588 { 562 - float* result = GPU_GetCurrentMatrix(); 589 + float* result = GPU_GetCurrentMatrix(target); 563 590 if(result == NULL) 564 591 return; 565 592 GPU_FlushBlitBuffer(); 566 593 GPU_MatrixCopy(result, A); 567 594 } 568 595 569 - void GPU_Ortho(float left, float right, float bottom, float top, float z_near, float z_far) 596 + void GPU_Ortho(GPU_Target* target, float left, float right, float bottom, float top, float z_near, float z_far) 570 597 { 571 598 GPU_FlushBlitBuffer(); 572 - GPU_MatrixOrtho(GPU_GetCurrentMatrix(), left, right, bottom, top, z_near, z_far); 599 + GPU_MatrixOrtho(GPU_GetCurrentMatrix(target), left, right, bottom, top, z_near, z_far); 573 600 } 574 601 575 - void GPU_Frustum(float left, float right, float bottom, float top, float z_near, float z_far) 602 + void GPU_Frustum(GPU_Target* target, float left, float right, float bottom, float top, float z_near, float z_far) 576 603 { 577 604 GPU_FlushBlitBuffer(); 578 - GPU_MatrixFrustum(GPU_GetCurrentMatrix(), left, right, bottom, top, z_near, z_far); 605 + GPU_MatrixFrustum(GPU_GetCurrentMatrix(target), left, right, bottom, top, z_near, z_far); 579 606 } 580 607 581 - void GPU_Translate(float x, float y, float z) 608 + void GPU_Translate(GPU_Target* target, float x, float y, float z) 582 609 { 583 610 GPU_FlushBlitBuffer(); 584 - GPU_MatrixTranslate(GPU_GetCurrentMatrix(), x, y, z); 611 + GPU_MatrixTranslate(GPU_GetCurrentMatrix(target), x, y, z); 585 612 } 586 613 587 - void GPU_Scale(float sx, float sy, float sz) 614 + void GPU_Scale(GPU_Target* target, float sx, float sy, float sz) 588 615 { 589 616 GPU_FlushBlitBuffer(); 590 - GPU_MatrixScale(GPU_GetCurrentMatrix(), sx, sy, sz); 617 + GPU_MatrixScale(GPU_GetCurrentMatrix(target), sx, sy, sz); 591 618 } 592 619 593 - void GPU_Rotate(float degrees, float x, float y, float z) 620 + void GPU_Rotate(GPU_Target* target, float degrees, float x, float y, float z) 594 621 { 595 622 GPU_FlushBlitBuffer(); 596 - GPU_MatrixRotate(GPU_GetCurrentMatrix(), degrees, x, y, z); 623 + GPU_MatrixRotate(GPU_GetCurrentMatrix(target), degrees, x, y, z); 597 624 } 598 625 599 - void GPU_MultMatrix(const float* A) 626 + void GPU_MultMatrix(GPU_Target* target, const float* A) 600 627 { 601 - float* result = GPU_GetCurrentMatrix(); 628 + float* result = GPU_GetCurrentMatrix(target); 602 629 if(result == NULL) 603 630 return; 604 631 GPU_FlushBlitBuffer(); ··· 607 634 GPU_MultiplyAndAssign(result, A); 608 635 } 609 636 610 - void GPU_GetModelViewProjection(float* result) 637 + void GPU_GetModelViewProjection(GPU_Target* target, float* result) 611 638 { 612 639 // MVP = P * MV 613 - GPU_MatrixMultiply(result, GPU_GetProjection(), GPU_GetModelView()); 640 + GPU_MatrixMultiply(result, GPU_GetProjection(target), GPU_GetModelView(target)); 614 641 }
+40 -40
src/renderer_GL_common.inl
··· 43 43 #endif 44 44 #endif 45 45 46 - #if defined ( WIN32 ) 46 + #if defined ( WIN32 ) && defined(_MSC_VER) 47 47 #define __func__ __FUNCTION__ 48 48 #endif 49 49 ··· 1167 1167 } 1168 1168 } 1169 1169 1170 - static void get_camera_matrix(float* result) 1170 + static void get_camera_matrix(GPU_Target* target, float* result) 1171 1171 { 1172 - GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)GPU_GetContextTarget()->context->data; 1173 - GPU_Target* target = cdata->last_target; 1174 1172 float offsetX, offsetY; 1175 1173 1176 1174 GPU_MatrixIdentity(result); ··· 1194 1192 1195 1193 1196 1194 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK 1197 - static void applyTransforms(void) 1195 + static void applyTransforms(GPU_Target* target) 1198 1196 { 1199 - float* p = GPU_GetProjection(); 1200 - float* m = GPU_GetModelView(); 1197 + float* p = GPU_GetProjection(target); 1198 + float* m = GPU_GetModelView(target); 1201 1199 1202 1200 float cam_matrix[16]; 1203 - get_camera_matrix(cam_matrix); 1201 + get_camera_matrix(target, cam_matrix); 1204 1202 1205 1203 GPU_MultiplyAndAssign(cam_matrix, m); 1206 1204 ··· 1340 1338 return NULL; 1341 1339 1342 1340 // If the dimensions of the window don't match what we asked for, then set up a virtual resolution to pretend like they are. 1343 - if(!(GPU_flags & GPU_INIT_DISABLE_AUTO_VIRTUAL_RESOLUTION) && w != 0 && h != 0 && (w != renderer->current_context_target->w || h != renderer->current_context_target->h)) 1344 - renderer->impl->SetVirtualResolution(renderer, renderer->current_context_target, w, h); 1341 + if (!(GPU_flags & GPU_INIT_DISABLE_AUTO_VIRTUAL_RESOLUTION) && w != 0 && h != 0 && (w != renderer->current_context_target->w || h != renderer->current_context_target->h)) 1342 + { 1343 + renderer->impl->SetVirtualResolution(renderer, renderer->current_context_target, w, h); 1344 + } 1345 1345 1346 1346 // Init glVertexAttrib workaround 1347 1347 #ifdef SDL_GPU_USE_OPENGL ··· 1505 1505 target->context->data = cdata; 1506 1506 target->context->context = NULL; 1507 1507 1508 - GPU_InitMatrixStack(&target->context->projection_matrix); 1509 - GPU_InitMatrixStack(&target->context->modelview_matrix); 1510 - 1511 - target->context->matrix_mode = GPU_MODELVIEW; 1512 - 1513 1508 cdata->last_image = NULL; 1514 1509 cdata->last_target = NULL; 1515 1510 // Initialize the blit buffer ··· 1598 1593 target->use_color = GPU_FALSE; 1599 1594 1600 1595 target->viewport = GPU_MakeRect(0, 0, (float)target->context->drawable_w, (float)target->context->drawable_h); 1596 + 1597 + 1598 + target->matrix_mode = GPU_MODELVIEW; 1599 + GPU_InitMatrixStack(&target->projection_matrix); 1600 + GPU_InitMatrixStack(&target->modelview_matrix); 1601 + 1601 1602 target->camera = GPU_GetDefaultCamera(); 1602 1603 target->use_camera = GPU_TRUE; 1603 1604 ··· 1710 1711 // Set up camera 1711 1712 applyTargetCamera(target); 1712 1713 1713 - // Set up default projection 1714 - // Maybe replace with GPU_ResetProjection()? 1715 - float* projection_matrix = target->context->projection_matrix.matrix[0]; 1716 - if(!cdata->last_camera_inverted ^ GPU_GetCoordinateMode()) 1717 - GPU_MatrixOrtho(projection_matrix, 0, target->w, target->h, 0, target->camera.z_near, target->camera.z_far); 1718 - else 1719 - GPU_MatrixOrtho(projection_matrix, 0, target->w, 0, target->h, target->camera.z_near, target->camera.z_far); // Special inverted orthographic projection because tex coords are inverted already for render-to-texture 1714 + // Set up default projection matrix 1715 + GPU_ResetProjection(target); 1720 1716 1721 1717 1722 1718 renderer->impl->SetLineThickness(renderer, 1.0f); ··· 1878 1874 // Copy the members 1879 1875 *result = *target; 1880 1876 1877 + // Deep copies 1878 + GPU_CopyMatrixStack(&target->projection_matrix, &result->projection_matrix); 1879 + GPU_CopyMatrixStack(&target->modelview_matrix, &result->modelview_matrix); 1880 + 1881 1881 // Alias info 1882 1882 if(target->image != NULL) 1883 1883 target->image->refcount++; ··· 2108 2108 if(isCurrent) 2109 2109 applyTargetCamera(target); 2110 2110 2111 + GPU_ResetProjection(target); 2112 + 2111 2113 return 1; 2112 2114 } 2113 2115 ··· 2128 2130 2129 2131 if(isCurrent) 2130 2132 applyTargetCamera(target); 2133 + 2134 + GPU_ResetProjection(target); 2131 2135 } 2132 2136 2133 2137 static void UnsetVirtualResolution(GPU_Renderer* renderer, GPU_Target* target) ··· 2148 2152 2149 2153 if(isCurrent) 2150 2154 applyTargetCamera(target); 2155 + 2156 + GPU_ResetProjection(target); 2151 2157 } 2152 2158 2153 2159 static void Quit(GPU_Renderer* renderer) ··· 3981 3987 3982 3988 result->viewport = GPU_MakeRect(0, 0, result->w, result->h); 3983 3989 3990 + result->matrix_mode = GPU_MODELVIEW; 3991 + GPU_InitMatrixStack(&result->projection_matrix); 3992 + GPU_InitMatrixStack(&result->modelview_matrix); 3993 + 3984 3994 result->camera = GPU_GetDefaultCamera(); 3985 3995 result->use_camera = GPU_TRUE; 3986 3996 ··· 4024 4034 static void FreeContext(GPU_Context* context) 4025 4035 { 4026 4036 GPU_CONTEXT_DATA* cdata; 4027 - unsigned int i; 4028 4037 4029 4038 if(context == NULL) 4030 4039 return; ··· 4058 4067 SDL_GL_DeleteContext(context->context); 4059 4068 #endif 4060 4069 4061 - for(i = 0; i < context->projection_matrix.storage_size; ++i) 4062 - { 4063 - SDL_free(context->projection_matrix.matrix[i]); 4064 - } 4065 - SDL_free(context->projection_matrix.matrix); 4066 - 4067 - for(i = 0; i < context->modelview_matrix.storage_size; ++i) 4068 - { 4069 - SDL_free(context->modelview_matrix.matrix[i]); 4070 - } 4071 - SDL_free(context->modelview_matrix.matrix); 4072 - 4073 4070 4074 4071 SDL_free(cdata); 4075 4072 SDL_free(context); ··· 4114 4111 if(target->image != NULL && target->image->target == target) 4115 4112 target->image->target = NULL; 4116 4113 4114 + // Delete matrices 4115 + GPU_ClearMatrixStack(&target->projection_matrix); 4116 + GPU_ClearMatrixStack(&target->modelview_matrix); 4117 4117 4118 4118 SDL_free(target); 4119 4119 } ··· 4818 4818 // MVP = P * V * M 4819 4819 4820 4820 // P 4821 - GPU_MatrixCopy(mvp, GPU_GetProjection()); 4821 + GPU_MatrixCopy(mvp, GPU_GetProjection(dest)); 4822 4822 4823 4823 4824 4824 // V 4825 4825 if(dest->use_camera) 4826 4826 { 4827 4827 float cam_matrix[16]; 4828 - get_camera_matrix(cam_matrix); 4828 + get_camera_matrix(dest, cam_matrix); 4829 4829 4830 4830 GPU_MultiplyAndAssign(mvp, cam_matrix); 4831 4831 } 4832 4832 4833 4833 // M 4834 - GPU_MultiplyAndAssign(mvp, GPU_GetModelView()); 4834 + GPU_MultiplyAndAssign(mvp, GPU_GetModelView(dest)); 4835 4835 4836 4836 glUniformMatrix4fv(context->current_shader_block.modelViewProjection_loc, 1, 0, mvp); 4837 4837 } ··· 4898 4898 4899 4899 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK 4900 4900 if(!IsFeatureEnabled(renderer, GPU_FEATURE_VERTEX_SHADER)) 4901 - applyTransforms(); 4901 + applyTransforms(target); 4902 4902 #endif 4903 4903 4904 4904 ··· 5694 5694 5695 5695 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK 5696 5696 if(!IsFeatureEnabled(renderer, GPU_FEATURE_VERTEX_SHADER)) 5697 - applyTransforms(); 5697 + applyTransforms(dest); 5698 5698 #endif 5699 5699 5700 5700 setClipRect(renderer, dest);
+8 -8
tests/camera-matrix/main.c
··· 97 97 } 98 98 else if(event.key.keysym.sym == SDLK_o) 99 99 { 100 - GPU_MatrixMode(GPU_PROJECTION); 101 - GPU_LoadIdentity(); 100 + GPU_MatrixMode(screen, GPU_PROJECTION); 101 + GPU_LoadIdentity(screen); 102 102 103 103 camera.x = 0; 104 104 camera.y = 0; 105 105 camera.z = 0.0f; 106 - GPU_Ortho(0, target->w, target->h, 0, target->camera.z_near, target->camera.z_far); 106 + GPU_Ortho(screen, 0, target->w, target->h, 0, target->camera.z_near, target->camera.z_far); 107 107 108 - GPU_MatrixMode(GPU_MODELVIEW); 108 + GPU_MatrixMode(screen, GPU_MODELVIEW); 109 109 } 110 110 else if(event.key.keysym.sym == SDLK_p) 111 111 { 112 - GPU_MatrixMode(GPU_PROJECTION); 113 - GPU_LoadIdentity(); 112 + GPU_MatrixMode(screen, GPU_PROJECTION); 113 + GPU_LoadIdentity(screen); 114 114 115 115 camera.x = target->w/2; 116 116 camera.y = target->h/2; 117 117 camera.z = 1000.0f; 118 - GPU_Frustum(-400, 400, 300, -300, 1000.0f, 10000.0f); 118 + GPU_Frustum(screen, -400, 400, 300, -300, 1000.0f, 10000.0f); 119 119 120 - GPU_MatrixMode(GPU_MODELVIEW); 120 + GPU_MatrixMode(screen, GPU_MODELVIEW); 121 121 } 122 122 } 123 123 }
+10 -10
tests/depth/main.c
··· 71 71 // Images drawn left to right, but layered alternating. Positive z values are on top. 72 72 GPU_Blit(image, NULL, screen, 150, 300); 73 73 74 - GPU_PushMatrix(); 75 - GPU_Translate(0, 0, 5); 74 + GPU_PushMatrix(screen); 75 + GPU_Translate(screen, 0, 0, 5); 76 76 GPU_Blit(image, NULL, screen, 300, 300); 77 77 78 - GPU_Translate(0, 0, -10); 78 + GPU_Translate(screen, 0, 0, -10); 79 79 GPU_Blit(image, NULL, screen, 450, 300); 80 80 81 - GPU_Translate(0, 0, 10); 81 + GPU_Translate(screen, 0, 0, 10); 82 82 GPU_Blit(image, NULL, screen, 600, 300); 83 - GPU_PopMatrix(); 83 + GPU_PopMatrix(screen); 84 84 } 85 85 else 86 86 { ··· 90 90 // Images drawn left to right, but layered alternating. Positive z values are on top. 91 91 GPU_Blit(image, NULL, target, 150, 300); 92 92 93 - GPU_PushMatrix(); 94 - GPU_Translate(0, 0, 5); 93 + GPU_PushMatrix(screen); 94 + GPU_Translate(screen, 0, 0, 5); 95 95 GPU_Blit(image, NULL, target, 300, 300); 96 96 97 - GPU_Translate(0, 0, -10); 97 + GPU_Translate(screen, 0, 0, -10); 98 98 GPU_Blit(image, NULL, target, 450, 300); 99 99 100 - GPU_Translate(0, 0, 10); 100 + GPU_Translate(screen, 0, 0, 10); 101 101 GPU_Blit(image, NULL, target, 600, 300); 102 - GPU_PopMatrix(); 102 + GPU_PopMatrix(screen); 103 103 104 104 GPU_Blit(target_image, NULL, screen, 0, 0); 105 105 }
+14 -6
tests/renderer/main.c
··· 105 105 target->context->windowID = windowID; 106 106 target->context->data = NULL; // Allocate a data structure as needed for other context data 107 107 target->context->context = NULL; 108 - 109 - GPU_InitMatrixStack(&target->context->projection_matrix); 110 - GPU_InitMatrixStack(&target->context->modelview_matrix); 111 - 112 - target->context->matrix_mode = GPU_MODELVIEW; 113 108 } 114 109 else 115 110 { ··· 145 140 target->context->shapes_use_blending = 1; 146 141 target->context->shapes_blend_mode = GPU_GetBlendModeFromPreset(GPU_BLEND_NORMAL); 147 142 148 - target->context->matrix_mode = GPU_MODELVIEW; 143 + 144 + GPU_InitMatrixStack(&target->projection_matrix); 145 + GPU_InitMatrixStack(&target->modelview_matrix); 146 + 147 + target->matrix_mode = GPU_MODELVIEW; 149 148 150 149 151 150 renderer->impl->SetLineThickness(renderer, 1.0f); ··· 171 170 172 171 // Copy the members 173 172 *result = *target; 173 + 174 + // Deep copies 175 + GPU_CopyMatrixStack(&target->projection_matrix, &result->projection_matrix); 176 + GPU_CopyMatrixStack(&target->modelview_matrix, &result->modelview_matrix); 174 177 175 178 // Alias info 176 179 if(target->image != NULL) ··· 641 644 result->base_h = image->texture_h; 642 645 643 646 result->viewport = GPU_MakeRect(0, 0, result->w, result->h); 647 + 648 + GPU_InitMatrixStack(&result->projection_matrix); 649 + GPU_InitMatrixStack(&result->modelview_matrix); 650 + 651 + result->matrix_mode = GPU_MODELVIEW; 644 652 645 653 result->camera = GPU_GetDefaultCamera(); 646 654
+15 -15
tests/transform-matrix/main.c
··· 97 97 { 98 98 use_camera = 1; 99 99 GPU_EnableCamera(screen, use_camera); 100 - GPU_ResetProjection(); 100 + GPU_ResetProjection(screen); 101 101 } 102 102 103 103 } ··· 105 105 106 106 GPU_Clear(screen); 107 107 108 - GPU_MatrixMode(GPU_PROJECTION); 108 + GPU_MatrixMode(screen, GPU_PROJECTION); 109 109 110 110 if (!use_camera) 111 111 { 112 - GPU_LoadIdentity(); 112 + GPU_LoadIdentity(screen); 113 113 // Apply projection matrix 114 114 GPU_MatrixIdentity(matrix); 115 115 ··· 122 122 GPU_MatrixOrtho(matrix, 0, 800, 600, 0, -1000, 1000); 123 123 } 124 124 125 - GPU_MultMatrix(matrix); 125 + GPU_MultMatrix(screen, matrix); 126 126 } 127 127 128 128 129 - GPU_MatrixMode(GPU_MODELVIEW); 130 - GPU_LoadIdentity(); 129 + GPU_MatrixMode(screen, GPU_MODELVIEW); 130 + GPU_LoadIdentity(screen); 131 131 132 132 if (!use_camera) 133 133 { ··· 146 146 0, 0, 0, // target 147 147 0, 1, 0); // up 148 148 } 149 - GPU_MultMatrix(matrix); 149 + GPU_MultMatrix(screen, matrix); 150 150 } 151 151 152 152 ··· 163 163 GPU_MatrixRotate(matrix, a, 0.57, 0.57, 0.57); 164 164 } 165 165 166 - GPU_MultMatrix(matrix); 166 + GPU_MultMatrix(screen, matrix); 167 167 168 168 GPU_SetCamera(screen, &camera); 169 169 ··· 179 179 GPU_BlitScale(image, NULL, screen, 200, 200, 0.5f, 0.5f); 180 180 181 181 float scale = 200; 182 - GPU_MatrixMode(GPU_MODELVIEW); 183 - GPU_PushMatrix(); 182 + GPU_MatrixMode(screen, GPU_MODELVIEW); 183 + GPU_PushMatrix(screen); 184 184 GPU_SetLineThickness(4.0f); 185 - GPU_Translate(40, 40, 0.0f); 186 - GPU_Rotate(90, 0.0f, 0.0f, 1.0f); 187 - //GPU_Translate(-screen->w/2, -screen->h/2, 0.0f); 188 - GPU_Translate(-40, -40, 0.0f); 185 + GPU_Translate(screen, 40, 40, 0.0f); 186 + GPU_Rotate(screen, 90, 0.0f, 0.0f, 1.0f); 187 + //GPU_Translate(screen, -screen->w/2, -screen->h/2, 0.0f); 188 + GPU_Translate(screen, -40, -40, 0.0f); 189 189 GPU_Line(screen, 0, 0, scale, 0, GPU_MakeColor(255, 0, 0, 255)); 190 190 GPU_CircleFilled(screen, 0, 0, scale/16, GPU_MakeColor(255, 0, 0, 255)); 191 191 GPU_Circle(screen, 0, 0, scale, GPU_MakeColor(255, 0, 0, 255)); 192 192 GPU_Circle(screen, 0, 0, scale*4, GPU_MakeColor(0, 255, 0, 255)); 193 193 GPU_SetLineThickness(1.0f); 194 - GPU_PopMatrix(); 194 + GPU_PopMatrix(screen); 195 195 196 196 GPU_Flip(screen); 197 197
+4 -4
tests/triangle-batch/main.c
··· 418 418 1, 3, 7, 419 419 3, 5, 7}; 420 420 421 - GPU_MatrixMode(GPU_MODELVIEW); 422 - GPU_PushMatrix(); 423 - GPU_Translate(300, 300, 0); 421 + GPU_MatrixMode(screen, GPU_MODELVIEW); 422 + GPU_PushMatrix(screen); 423 + GPU_Translate(screen, 300, 300, 0); 424 424 GPU_TriangleBatch(image, screen, n_v, v, n_i, i, GPU_BATCH_XY_ST); 425 - GPU_PopMatrix(); 425 + GPU_PopMatrix(screen); 426 426 } 427 427 428 428 GPU_Flip(screen);