this repo has no description
0
fork

Configure Feed

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

Reverted changes to implicit state for matrix modifications. Added a separate view matrix stack for all targets. Moved context data's last_target into GPU_Context.

GPU_MODELVIEW was replaced with GPU_VIEW and GPU_MODEL. GPU_MatrixMode() now sets the active target.

Added a few more functions to control matrix state. GPU_GetActiveTarget(), GPU_SetActiveTarget(), GPU_Perspective(), GPU_LookAt(), GPU_SetProjection(), GPU_SetView(), GPU_SetModel(), GPU_SetProjectionFromStack() etc.

+432 -191
+18 -13
demos/3d/main.c
··· 17 17 GPU_FlushBlitBuffer(); 18 18 19 19 20 - GPU_MatrixMode(screen, GPU_MODELVIEW); 21 - GPU_PushMatrix(screen); 22 - GPU_LoadIdentity(screen); 20 + GPU_MatrixMode(screen, GPU_MODEL); 21 + GPU_PushMatrix(); 22 + GPU_LoadIdentity(); 23 + GPU_MatrixMode(screen, GPU_VIEW); 24 + GPU_PushMatrix(); 25 + GPU_LoadIdentity(); 23 26 GPU_MatrixMode(screen, GPU_PROJECTION); 24 - GPU_PushMatrix(screen); 25 - GPU_LoadIdentity(screen); 27 + GPU_PushMatrix(); 28 + GPU_LoadIdentity(); 26 29 } 27 30 28 31 void end_3d(GPU_Target* screen) 29 32 { 30 33 GPU_ResetRendererState(); 31 34 32 - GPU_MatrixMode(screen, GPU_MODELVIEW); 33 - GPU_PopMatrix(screen); 35 + GPU_MatrixMode(screen, GPU_MODEL); 36 + GPU_PopMatrix(); 37 + GPU_MatrixMode(screen, GPU_VIEW); 38 + GPU_PopMatrix(); 34 39 GPU_MatrixMode(screen, GPU_PROJECTION); 35 - GPU_PopMatrix(screen); 40 + GPU_PopMatrix(); 36 41 } 37 42 38 43 void draw_spinning_triangle(GPU_Target* screen) ··· 41 46 float mvp[16]; 42 47 float t = SDL_GetTicks()/1000.0f; 43 48 44 - GPU_Rotate(screen, 100*t, 0, 0.707, 0.707); 45 - GPU_Rotate(screen, 20*t, 0.707, 0.707, 0); 49 + GPU_Rotate(100*t, 0, 0.707, 0.707); 50 + GPU_Rotate(20*t, 0.707, 0.707, 0); 46 51 47 52 48 53 gldata[0] = 0; ··· 75 80 76 81 glUseProgram(p); 77 82 78 - GPU_GetModelViewProjection(screen, mvp); 83 + GPU_GetModelViewProjection(mvp); 79 84 glUniformMatrix4fv(modelViewProjection_loc, 1, 0, mvp); 80 85 81 86 ··· 124 129 begin_3d(screen); 125 130 126 131 t = SDL_GetTicks()/1000.0f; 127 - GPU_Rotate(screen, t*60, 0, 0, 1); 128 - GPU_Translate(screen, 0.4f, 0.4f, 0); 132 + GPU_Rotate(t*60, 0, 0, 1); 133 + GPU_Translate(0.4f, 0.4f, 0); 129 134 draw_spinning_triangle(screen); 130 135 131 136 end_3d(screen);
+74 -24
include/SDL_gpu.h
··· 353 353 354 354 355 355 356 - #define GPU_MODELVIEW 0 357 - #define GPU_PROJECTION 1 356 + #define GPU_MODEL 0 357 + #define GPU_VIEW 1 358 + #define GPU_PROJECTION 2 358 359 359 360 /*! \ingroup Matrix 360 361 * Matrix stack data structure for global vertex transforms. */ ··· 388 389 /*! Window dimensions for restoring windowed mode after GPU_SetFullscreen(1,1). */ 389 390 int stored_window_w; 390 391 int stored_window_h; 392 + 393 + 394 + /*! Last target used */ 395 + GPU_Target* active_target; 391 396 392 397 /*! Internal state */ 393 398 Uint32 current_shader_program; ··· 438 443 /*! Perspective and object viewing transforms. */ 439 444 int matrix_mode; 440 445 GPU_MatrixStack projection_matrix; 441 - GPU_MatrixStack modelview_matrix; 446 + GPU_MatrixStack view_matrix; 447 + GPU_MatrixStack model_matrix; 442 448 443 449 GPU_Camera camera; 444 450 GPU_bool use_camera; ··· 981 987 /*! Returns true if the current context target's window is in fullscreen mode. */ 982 988 DECLSPEC GPU_bool SDLCALL GPU_GetFullscreen(void); 983 989 990 + /*! \return Returns the last active target. */ 991 + DECLSPEC GPU_Target* SDLCALL GPU_GetActiveTarget(void); 992 + 993 + /*! \return Sets the currently active target for matrix modification functions. */ 994 + DECLSPEC GPU_bool SDLCALL GPU_SetActiveTarget(GPU_Target* target); 995 + 984 996 /*! Enables/disables alpha blending for shape rendering on the current window. */ 985 997 DECLSPEC void SDLCALL GPU_SetShapeBlending(GPU_bool enable); 986 998 ··· 1014 1026 1015 1027 /*! \ingroup TargetControls 1016 1028 * @{ */ 1029 + 1030 + 1017 1031 1018 1032 /*! Creates a target that aliases the given target. Aliases can be used to store target settings (e.g. viewports) for easy switching. 1019 1033 * GPU_FreeTarget() frees the alias's memory, but does not affect the original. */ ··· 1366 1380 /*! Returns an internal string that represents the contents of matrix A. */ 1367 1381 DECLSPEC const char* SDLCALL GPU_GetMatrixString(const float* A); 1368 1382 1383 + /*! Returns the current matrix from the active target. Returns NULL if stack is empty. */ 1384 + DECLSPEC float* SDLCALL GPU_GetCurrentMatrix(void); 1385 + 1369 1386 /*! Returns the current matrix from the top of the matrix stack. Returns NULL if stack is empty. */ 1370 - DECLSPEC float* SDLCALL GPU_GetCurrentMatrix(GPU_Target* target); 1387 + DECLSPEC float* SDLCALL GPU_GetTopMatrix(GPU_MatrixStack* stack); 1388 + 1389 + /*! Returns the current model matrix from the active target. Returns NULL if stack is empty. */ 1390 + DECLSPEC float* SDLCALL GPU_GetModel(void); 1371 1391 1372 - /*! Returns the current modelview matrix from the top of the matrix stack. Returns NULL if stack is empty. */ 1373 - DECLSPEC float* SDLCALL GPU_GetModelView(GPU_Target* target); 1392 + /*! Returns the current view matrix from the active target. Returns NULL if stack is empty. */ 1393 + DECLSPEC float* SDLCALL GPU_GetView(void); 1374 1394 1375 - /*! Returns the current projection matrix from the top of the matrix stack. Returns NULL if stack is empty. */ 1376 - DECLSPEC float* SDLCALL GPU_GetProjection(GPU_Target* target); 1395 + /*! Returns the current projection matrix from the active target. Returns NULL if stack is empty. */ 1396 + DECLSPEC float* SDLCALL GPU_GetProjection(void); 1377 1397 1378 - /*! Copies the current modelview-projection matrix into the given 'result' matrix (result = P*M). */ 1379 - DECLSPEC void SDLCALL GPU_GetModelViewProjection(GPU_Target* target, float* result); 1398 + /*! Copies the current modelview-projection matrix from the active target into the given 'result' matrix (result = P*V*M). */ 1399 + DECLSPEC void SDLCALL GPU_GetModelViewProjection(float* result); 1380 1400 1381 1401 1382 1402 // Matrix stack manipulators 1383 1403 1404 + /*! Returns a newly allocated matrix stack that has already been initialized. */ 1405 + DECLSPEC GPU_MatrixStack* SDLCALL GPU_CreateMatrixStack(void); 1406 + 1407 + /*! Frees the memory for the matrix stack and any matrices it contains. */ 1408 + DECLSPEC void SDLCALL GPU_FreeMatrixStack(GPU_MatrixStack* stack); 1409 + 1384 1410 /*! Allocate new matrices for the given stack. */ 1385 1411 DECLSPEC void SDLCALL GPU_InitMatrixStack(GPU_MatrixStack* stack); 1386 1412 1387 1413 /*! Copies matrices from one stack to another. */ 1388 - DECLSPEC void SDLCALL GPU_CopyMatrixStack(GPU_MatrixStack* source, GPU_MatrixStack* dest); 1414 + DECLSPEC void SDLCALL GPU_CopyMatrixStack(const GPU_MatrixStack* source, GPU_MatrixStack* dest); 1389 1415 1390 1416 /*! Deletes matrices in the given stack. */ 1391 1417 DECLSPEC void SDLCALL GPU_ClearMatrixStack(GPU_MatrixStack* stack); ··· 1393 1419 /*! Reapplies the default orthographic projection matrix, based on camera and coordinate settings. */ 1394 1420 DECLSPEC void SDLCALL GPU_ResetProjection(GPU_Target* target); 1395 1421 1396 - /*! Changes matrix mode to either GPU_PROJECTION or GPU_MODELVIEW. Further matrix stack operations manipulate that particular stack. */ 1422 + /*! Sets the active target and changes matrix mode to GPU_PROJECTION, GPU_VIEW, or GPU_MODEL. Further matrix stack operations manipulate that particular stack. */ 1397 1423 DECLSPEC void SDLCALL GPU_MatrixMode(GPU_Target* target, int matrix_mode); 1398 1424 1399 - /*! Pushes the current matrix as a new matrix stack item. */ 1400 - DECLSPEC void SDLCALL GPU_PushMatrix(GPU_Target* target); 1425 + /*! Copies the given matrix to the active target's projection matrix. */ 1426 + DECLSPEC void SDLCALL GPU_SetProjection(const float* A); 1427 + 1428 + /*! Copies the given matrix to the active target's view matrix. */ 1429 + DECLSPEC void SDLCALL GPU_SetView(const float* A); 1430 + 1431 + /*! Copies the given matrix to the active target's model matrix. */ 1432 + DECLSPEC void SDLCALL GPU_SetModel(const float* A); 1433 + 1434 + /*! Copies the given matrix to the active target's projection matrix. */ 1435 + DECLSPEC void SDLCALL GPU_SetProjectionFromStack(GPU_MatrixStack* stack); 1436 + 1437 + /*! Copies the given matrix to the active target's view matrix. */ 1438 + DECLSPEC void SDLCALL GPU_SetViewFromStack(GPU_MatrixStack* stack); 1401 1439 1402 - /*! Removes the current matrix from the stack. */ 1403 - DECLSPEC void SDLCALL GPU_PopMatrix(GPU_Target* target); 1440 + /*! Copies the given matrix to the active target's model matrix. */ 1441 + DECLSPEC void SDLCALL GPU_SetModelFromStack(GPU_MatrixStack* stack); 1442 + 1443 + /*! Pushes the current matrix as a new matrix stack item to be restored later. */ 1444 + DECLSPEC void SDLCALL GPU_PushMatrix(void); 1445 + 1446 + /*! Removes the current matrix from the stack, restoring the previously pushed matrix. */ 1447 + DECLSPEC void SDLCALL GPU_PopMatrix(void); 1404 1448 1405 1449 /*! Fills current matrix with the identity matrix. */ 1406 - DECLSPEC void SDLCALL GPU_LoadIdentity(GPU_Target* target); 1450 + DECLSPEC void SDLCALL GPU_LoadIdentity(void); 1407 1451 1408 1452 /*! Copies a given matrix to be the current matrix. */ 1409 - DECLSPEC void SDLCALL GPU_LoadMatrix(GPU_Target* target, const float* matrix4x4); 1453 + DECLSPEC void SDLCALL GPU_LoadMatrix(const float* matrix4x4); 1410 1454 1411 1455 /*! Multiplies an orthographic projection matrix into the current matrix. */ 1412 - DECLSPEC void SDLCALL GPU_Ortho(GPU_Target* target, float left, float right, float bottom, float top, float z_near, float z_far); 1456 + DECLSPEC void SDLCALL GPU_Ortho(float left, float right, float bottom, float top, float z_near, float z_far); 1413 1457 1414 1458 /*! Multiplies a perspective projection matrix into the current matrix. */ 1415 - DECLSPEC void SDLCALL GPU_Frustum(GPU_Target* target, float left, float right, float bottom, float top, float z_near, float z_far); 1459 + DECLSPEC void SDLCALL GPU_Frustum(float left, float right, float bottom, float top, float z_near, float z_far); 1460 + 1461 + /*! Multiplies a perspective projection matrix into the current matrix. */ 1462 + DECLSPEC void SDLCALL GPU_Perspective(float fovy, float aspect, float z_near, float z_far); 1463 + 1464 + /*! Multiplies a view matrix into the current matrix. */ 1465 + DECLSPEC void SDLCALL GPU_LookAt(float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z); 1416 1466 1417 1467 /*! Adds a translation into the current matrix. */ 1418 - DECLSPEC void SDLCALL GPU_Translate(GPU_Target* target, float x, float y, float z); 1468 + DECLSPEC void SDLCALL GPU_Translate(float x, float y, float z); 1419 1469 1420 1470 /*! Multiplies a scaling matrix into the current matrix. */ 1421 - DECLSPEC void SDLCALL GPU_Scale(GPU_Target* target, float sx, float sy, float sz); 1471 + DECLSPEC void SDLCALL GPU_Scale(float sx, float sy, float sz); 1422 1472 1423 1473 /*! Multiplies a rotation matrix into the current matrix. */ 1424 - DECLSPEC void SDLCALL GPU_Rotate(GPU_Target* target, float degrees, float x, float y, float z); 1474 + DECLSPEC void SDLCALL GPU_Rotate(float degrees, float x, float y, float z); 1425 1475 1426 1476 /*! Multiplies a given matrix into the current matrix. */ 1427 - DECLSPEC void SDLCALL GPU_MultMatrix(GPU_Target* target, const float* matrix4x4); 1477 + DECLSPEC void SDLCALL GPU_MultMatrix(const float* matrix4x4); 1428 1478 1429 1479 // End of Matrix 1430 1480 /*! @} */
-1
include/SDL_gpu_GLES_1.h
··· 72 72 GPU_ComparisonEnum last_depth_function; 73 73 74 74 GPU_Image* last_image; 75 - GPU_Target* last_target; 76 75 float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]). 77 76 unsigned short blit_buffer_num_vertices; 78 77 unsigned short blit_buffer_max_num_vertices;
-1
include/SDL_gpu_GLES_2.h
··· 127 127 GPU_ComparisonEnum last_depth_function; 128 128 129 129 GPU_Image* last_image; 130 - GPU_Target* last_target; 131 130 float* blit_buffer; // Holds sets of 4 vertices, each with interleaved position, tex coords, and colors (e.g. [x0, y0, z0, s0, t0, r0, g0, b0, a0, ...]). 132 131 unsigned short blit_buffer_num_vertices; 133 132 unsigned short blit_buffer_max_num_vertices;
-1
include/SDL_gpu_GLES_3.h
··· 131 131 GPU_ComparisonEnum last_depth_function; 132 132 133 133 GPU_Image* last_image; 134 - GPU_Target* last_target; 135 134 float* blit_buffer; // Holds sets of 4 vertices, each with interleaved position, tex coords, and colors (e.g. [x0, y0, z0, s0, t0, r0, g0, b0, a0, ...]). 136 135 unsigned short blit_buffer_num_vertices; 137 136 unsigned short blit_buffer_max_num_vertices;
-1
include/SDL_gpu_OpenGL_1.h
··· 237 237 GPU_ComparisonEnum last_depth_function; 238 238 239 239 GPU_Image* last_image; 240 - GPU_Target* last_target; 241 240 float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]). 242 241 unsigned short blit_buffer_num_vertices; 243 242 unsigned short blit_buffer_max_num_vertices;
-1
include/SDL_gpu_OpenGL_1_BASE.h
··· 52 52 GPU_ComparisonEnum last_depth_function; 53 53 54 54 GPU_Image* last_image; 55 - GPU_Target* last_target; 56 55 float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]). 57 56 unsigned short blit_buffer_num_vertices; 58 57 unsigned short blit_buffer_max_num_vertices;
-1
include/SDL_gpu_OpenGL_2.h
··· 108 108 GPU_ComparisonEnum last_depth_function; 109 109 110 110 GPU_Image* last_image; 111 - GPU_Target* last_target; 112 111 float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]). 113 112 unsigned short blit_buffer_num_vertices; 114 113 unsigned short blit_buffer_max_num_vertices;
-1
include/SDL_gpu_OpenGL_3.h
··· 171 171 GPU_ComparisonEnum last_depth_function; 172 172 173 173 GPU_Image* last_image; 174 - GPU_Target* last_target; 175 174 float* blit_buffer; // Holds sets of 4 vertices, each with interleaved position, tex coords, and colors (e.g. [x0, y0, z0, s0, t0, r0, g0, b0, a0, ...]). 176 175 unsigned short blit_buffer_num_vertices; 177 176 unsigned short blit_buffer_max_num_vertices;
-1
include/SDL_gpu_OpenGL_4.h
··· 109 109 GPU_ComparisonEnum last_depth_function; 110 110 111 111 GPU_Image* last_image; 112 - GPU_Target* last_target; 113 112 float* blit_buffer; // Holds sets of 4 vertices, each with interleaved position, tex coords, and colors (e.g. [x0, y0, z0, s0, t0, r0, g0, b0, a0, ...]). 114 113 unsigned short blit_buffer_num_vertices; 115 114 unsigned short blit_buffer_max_num_vertices;
+3
include/SDL_gpu_RendererImpl.h
··· 25 25 * The extra parameter is used internally to reuse/reinit a target. */ 26 26 GPU_Target* (SDLCALL *CreateTargetFromWindow)(GPU_Renderer* renderer, Uint32 windowID, GPU_Target* target); 27 27 28 + /*! \see GPU_SetActiveTarget() */ 29 + GPU_bool (SDLCALL *SetActiveTarget)(GPU_Renderer* renderer, GPU_Target* target); 30 + 28 31 /*! \see GPU_CreateAliasTarget() */ 29 32 GPU_Target* (SDLCALL *CreateAliasTarget)(GPU_Renderer* renderer, GPU_Target* target); 30 33
+19
src/SDL_gpu.c
··· 483 483 return _gpu_current_renderer->impl->CreateTargetFromWindow(_gpu_current_renderer, windowID, NULL); 484 484 } 485 485 486 + 487 + 486 488 GPU_Target* GPU_CreateAliasTarget(GPU_Target* target) 487 489 { 488 490 if(!CHECK_RENDERER) ··· 524 526 return GPU_FALSE; 525 527 return (surf->flags & SDL_FULLSCREEN) != 0; 526 528 #endif 529 + } 530 + 531 + GPU_Target* GPU_GetActiveTarget(void) 532 + { 533 + GPU_Target* context_target = GPU_GetContextTarget(); 534 + if(context_target == NULL) 535 + return NULL; 536 + 537 + return context_target->context->active_target; 538 + } 539 + 540 + GPU_bool GPU_SetActiveTarget(GPU_Target* target) 541 + { 542 + if(_gpu_current_renderer == NULL) 543 + return GPU_FALSE; 544 + 545 + return _gpu_current_renderer->impl->SetActiveTarget(_gpu_current_renderer, target); 527 546 } 528 547 529 548 GPU_bool GPU_AddDepthBuffer(GPU_Target* target)
+162 -49
src/SDL_gpu_matrix.c
··· 54 54 55 55 56 56 57 + GPU_MatrixStack* GPU_CreateMatrixStack(void) 58 + { 59 + GPU_MatrixStack* stack = (GPU_MatrixStack*)SDL_malloc(sizeof(GPU_MatrixStack)); 60 + stack->matrix = NULL; 61 + stack->size = 0; 62 + stack->storage_size = 0; 63 + GPU_InitMatrixStack(stack); 64 + return stack; 65 + } 66 + 67 + 68 + void GPU_FreeMatrixStack(GPU_MatrixStack* stack) 69 + { 70 + GPU_ClearMatrixStack(stack); 71 + SDL_free(stack); 72 + } 73 + 57 74 void GPU_InitMatrixStack(GPU_MatrixStack* stack) 58 75 { 59 76 if(stack == NULL) ··· 70 87 GPU_MatrixIdentity(stack->matrix[0]); 71 88 } 72 89 73 - void GPU_CopyMatrixStack(GPU_MatrixStack* source, GPU_MatrixStack* dest) 90 + void GPU_CopyMatrixStack(const GPU_MatrixStack* source, GPU_MatrixStack* dest) 74 91 { 75 92 int i; 76 93 unsigned int matrix_size = sizeof(float) * 16; ··· 109 126 GPU_bool invert = (target->image != NULL); 110 127 111 128 // Set up default projection 112 - float* projection_matrix = GPU_GetProjection(target); 129 + float* projection_matrix = GPU_GetTopMatrix(&target->projection_matrix); 113 130 GPU_MatrixIdentity(projection_matrix); 114 131 115 132 if(!invert ^ GPU_GetCoordinateMode()) ··· 466 483 467 484 void GPU_MatrixMode(GPU_Target* target, int matrix_mode) 468 485 { 486 + GPU_Target* context_target; 469 487 if(target == NULL) 470 488 return; 471 489 490 + GPU_FlushBlitBuffer(); 472 491 target->matrix_mode = matrix_mode; 492 + 493 + context_target = GPU_GetContextTarget(); 494 + if(context_target != NULL && context_target == target->context_target) 495 + context_target->context->active_target = target; 473 496 } 474 497 475 - float* GPU_GetModelView(GPU_Target* target) 498 + float* GPU_GetModel(void) 476 499 { 477 - GPU_MatrixStack* stack; 478 - 500 + GPU_Target* target = GPU_GetActiveTarget(); 479 501 if(target == NULL) 480 502 return NULL; 481 - stack = &target->modelview_matrix; 482 - if(stack->size == 0) 483 - return NULL; 484 - return stack->matrix[stack->size-1]; 503 + return GPU_GetTopMatrix(&target->model_matrix); 485 504 } 486 505 487 - float* GPU_GetProjection(GPU_Target* target) 506 + float* GPU_GetView(void) 488 507 { 489 - GPU_MatrixStack* stack; 490 - 508 + GPU_Target* target = GPU_GetActiveTarget(); 491 509 if(target == NULL) 492 510 return NULL; 493 - stack = &target->projection_matrix; 494 - if(stack->size == 0) 511 + return GPU_GetTopMatrix(&target->view_matrix); 512 + } 513 + 514 + float* GPU_GetProjection(void) 515 + { 516 + GPU_Target* target = GPU_GetActiveTarget(); 517 + if(target == NULL) 495 518 return NULL; 496 - return stack->matrix[stack->size-1]; 519 + return GPU_GetTopMatrix(&target->projection_matrix); 497 520 } 498 521 499 - float* GPU_GetCurrentMatrix(GPU_Target* target) 522 + float* GPU_GetCurrentMatrix(void) 500 523 { 501 524 GPU_MatrixStack* stack; 502 - 525 + GPU_Target* target = GPU_GetActiveTarget(); 503 526 if(target == NULL) 504 527 return NULL; 505 - if(target->matrix_mode == GPU_MODELVIEW) 506 - stack = &target->modelview_matrix; 507 - else 528 + if(target->matrix_mode == GPU_MODEL) 529 + stack = &target->model_matrix; 530 + else if(target->matrix_mode == GPU_VIEW) 531 + stack = &target->view_matrix; 532 + else// if(target->matrix_mode == GPU_PROJECTION) 508 533 stack = &target->projection_matrix; 509 534 510 - if(stack->size == 0) 511 - return NULL; 512 - return stack->matrix[stack->size-1]; 535 + return GPU_GetTopMatrix(stack); 513 536 } 514 537 515 - void GPU_PushMatrix(GPU_Target* target) 538 + void GPU_PushMatrix(void) 516 539 { 517 540 GPU_MatrixStack* stack; 518 - 541 + GPU_Target* target = GPU_GetActiveTarget(); 519 542 if(target == NULL) 520 543 return; 521 544 522 - stack = (target->matrix_mode == GPU_MODELVIEW? &target->modelview_matrix : &target->projection_matrix); 545 + if(target->matrix_mode == GPU_MODEL) 546 + stack = &target->model_matrix; 547 + else if(target->matrix_mode == GPU_VIEW) 548 + stack = &target->view_matrix; 549 + else// if(target->matrix_mode == GPU_PROJECTION) 550 + stack = &target->projection_matrix; 551 + 523 552 if(stack->size + 1 >= stack->storage_size) 524 553 { 525 554 // Grow matrix stack (1, 6, 16, 36, ...) ··· 552 581 stack->size++; 553 582 } 554 583 555 - void GPU_PopMatrix(GPU_Target* target) 584 + void GPU_PopMatrix(void) 556 585 { 557 586 GPU_MatrixStack* stack; 558 587 588 + GPU_Target* target = GPU_GetActiveTarget(); 559 589 if(target == NULL) 560 590 return; 561 591 562 592 // FIXME: Flushing here is not always necessary if this isn't the last target 563 593 GPU_FlushBlitBuffer(); 564 - stack = (target->matrix_mode == GPU_MODELVIEW? &target->modelview_matrix : &target->projection_matrix); 594 + 595 + if(target->matrix_mode == GPU_MODEL) 596 + stack = &target->model_matrix; 597 + else if(target->matrix_mode == GPU_VIEW) 598 + stack = &target->view_matrix; 599 + else //if(target->matrix_mode == GPU_PROJECTION) 600 + stack = &target->projection_matrix; 601 + 565 602 if(stack->size == 0) 566 603 { 567 604 GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Matrix stack is empty."); ··· 574 611 stack->size--; 575 612 } 576 613 577 - void GPU_LoadIdentity(GPU_Target* target) 614 + void GPU_SetProjection(const float* A) 615 + { 616 + GPU_Target* target = GPU_GetActiveTarget(); 617 + if(target == NULL || A == NULL) 618 + return; 619 + 620 + GPU_FlushBlitBuffer(); 621 + GPU_MatrixCopy(GPU_GetProjection(), A); 622 + } 623 + 624 + void GPU_SetModel(const float* A) 625 + { 626 + GPU_Target* target = GPU_GetActiveTarget(); 627 + if(target == NULL || A == NULL) 628 + return; 629 + 630 + GPU_FlushBlitBuffer(); 631 + GPU_MatrixCopy(GPU_GetModel(), A); 632 + } 633 + 634 + void GPU_SetView(const float* A) 578 635 { 579 - float* result = GPU_GetCurrentMatrix(target); 636 + GPU_Target* target = GPU_GetActiveTarget(); 637 + if(target == NULL || A == NULL) 638 + return; 639 + 640 + GPU_FlushBlitBuffer(); 641 + GPU_MatrixCopy(GPU_GetView(), A); 642 + } 643 + 644 + void GPU_SetProjectionFromStack(GPU_MatrixStack* stack) 645 + { 646 + GPU_Target* target = GPU_GetActiveTarget(); 647 + if(target == NULL || stack == NULL) 648 + return; 649 + 650 + GPU_SetProjection(GPU_GetTopMatrix(stack)); 651 + } 652 + 653 + void GPU_SetModelFromStack(GPU_MatrixStack* stack) 654 + { 655 + GPU_Target* target = GPU_GetActiveTarget(); 656 + if(target == NULL || stack == NULL) 657 + return; 658 + 659 + GPU_SetModel(GPU_GetTopMatrix(stack)); 660 + } 661 + 662 + void GPU_SetViewFromStack(GPU_MatrixStack* stack) 663 + { 664 + GPU_Target* target = GPU_GetActiveTarget(); 665 + if(target == NULL || stack == NULL) 666 + return; 667 + 668 + GPU_SetView(GPU_GetTopMatrix(stack)); 669 + } 670 + 671 + float* GPU_GetTopMatrix(GPU_MatrixStack* stack) 672 + { 673 + if(stack == NULL || stack->size == 0) 674 + return NULL; 675 + return stack->matrix[stack->size-1]; 676 + } 677 + 678 + void GPU_LoadIdentity(void) 679 + { 680 + float* result = GPU_GetCurrentMatrix(); 580 681 if(result == NULL) 581 682 return; 582 683 ··· 584 685 GPU_MatrixIdentity(result); 585 686 } 586 687 587 - void GPU_LoadMatrix(GPU_Target* target, const float* A) 688 + void GPU_LoadMatrix(const float* A) 588 689 { 589 - float* result = GPU_GetCurrentMatrix(target); 690 + float* result = GPU_GetCurrentMatrix(); 590 691 if(result == NULL) 591 692 return; 592 693 GPU_FlushBlitBuffer(); 593 694 GPU_MatrixCopy(result, A); 594 695 } 595 696 596 - void GPU_Ortho(GPU_Target* target, float left, float right, float bottom, float top, float z_near, float z_far) 697 + void GPU_Ortho(float left, float right, float bottom, float top, float z_near, float z_far) 597 698 { 598 699 GPU_FlushBlitBuffer(); 599 - GPU_MatrixOrtho(GPU_GetCurrentMatrix(target), left, right, bottom, top, z_near, z_far); 700 + GPU_MatrixOrtho(GPU_GetCurrentMatrix(), left, right, bottom, top, z_near, z_far); 600 701 } 601 702 602 - void GPU_Frustum(GPU_Target* target, float left, float right, float bottom, float top, float z_near, float z_far) 703 + void GPU_Frustum(float left, float right, float bottom, float top, float z_near, float z_far) 603 704 { 604 705 GPU_FlushBlitBuffer(); 605 - GPU_MatrixFrustum(GPU_GetCurrentMatrix(target), left, right, bottom, top, z_near, z_far); 706 + GPU_MatrixFrustum(GPU_GetCurrentMatrix(), left, right, bottom, top, z_near, z_far); 606 707 } 607 708 608 - void GPU_Translate(GPU_Target* target, float x, float y, float z) 709 + void GPU_Perspective(float fovy, float aspect, float z_near, float z_far) 710 + { 711 + GPU_FlushBlitBuffer(); 712 + GPU_MatrixPerspective(GPU_GetCurrentMatrix(), fovy, aspect, z_near, z_far); 713 + } 714 + 715 + void GPU_LookAt(float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z) 716 + { 717 + GPU_FlushBlitBuffer(); 718 + GPU_MatrixLookAt(GPU_GetCurrentMatrix(), eye_x, eye_y, eye_z, target_x, target_y, target_z, up_x, up_y, up_z); 719 + } 720 + 721 + 722 + void GPU_Translate(float x, float y, float z) 609 723 { 610 724 GPU_FlushBlitBuffer(); 611 - GPU_MatrixTranslate(GPU_GetCurrentMatrix(target), x, y, z); 725 + GPU_MatrixTranslate(GPU_GetCurrentMatrix(), x, y, z); 612 726 } 613 727 614 - void GPU_Scale(GPU_Target* target, float sx, float sy, float sz) 728 + void GPU_Scale(float sx, float sy, float sz) 615 729 { 616 730 GPU_FlushBlitBuffer(); 617 - GPU_MatrixScale(GPU_GetCurrentMatrix(target), sx, sy, sz); 731 + GPU_MatrixScale(GPU_GetCurrentMatrix(), sx, sy, sz); 618 732 } 619 733 620 - void GPU_Rotate(GPU_Target* target, float degrees, float x, float y, float z) 734 + void GPU_Rotate(float degrees, float x, float y, float z) 621 735 { 622 736 GPU_FlushBlitBuffer(); 623 - GPU_MatrixRotate(GPU_GetCurrentMatrix(target), degrees, x, y, z); 737 + GPU_MatrixRotate(GPU_GetCurrentMatrix(), degrees, x, y, z); 624 738 } 625 739 626 - void GPU_MultMatrix(GPU_Target* target, const float* A) 740 + void GPU_MultMatrix(const float* A) 627 741 { 628 - float* result = GPU_GetCurrentMatrix(target); 742 + float* result = GPU_GetCurrentMatrix(); 629 743 if(result == NULL) 630 744 return; 631 745 GPU_FlushBlitBuffer(); 632 - // BIG FIXME: All of these matrix stack manipulators should be flushing the blit buffer. 633 - // A better solution would be to minimize the matrix stack API and make it clear that MultMatrix flushes. 634 746 GPU_MultiplyAndAssign(result, A); 635 747 } 636 748 637 - void GPU_GetModelViewProjection(GPU_Target* target, float* result) 749 + void GPU_GetModelViewProjection(float* result) 638 750 { 639 - // MVP = P * MV 640 - GPU_MatrixMultiply(result, GPU_GetProjection(target), GPU_GetModelView(target)); 751 + // MVP = P * V * M 752 + GPU_MatrixMultiply(result, GPU_GetProjection(), GPU_GetView()); 753 + GPU_MultiplyAndAssign(result, GPU_GetModel()); 641 754 }
+68 -40
src/renderer_GL_common.inl
··· 637 637 ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_image = NULL; 638 638 } 639 639 640 - // Returns false if it can't be bound 641 - static GPU_bool bindFramebuffer(GPU_Renderer* renderer, GPU_Target* target) 640 + // Binds the target's framebuffer. Returns false if it can't be bound. 641 + static GPU_bool SetActiveTarget(GPU_Renderer* renderer, GPU_Target* target) 642 642 { 643 643 if(renderer->enabled_features & GPU_FEATURE_RENDER_TARGETS) 644 644 { 645 645 // Bind the FBO 646 - if(target != ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target) 646 + if(target != renderer->current_context_target->context->active_target) 647 647 { 648 648 GLuint handle = 0; 649 649 if(target != NULL) ··· 651 651 renderer->impl->FlushBlitBuffer(renderer); 652 652 653 653 extBindFramebuffer(renderer, handle); 654 - ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target = target; 654 + renderer->current_context_target->context->active_target = target; 655 655 } 656 656 return GPU_TRUE; 657 657 } ··· 661 661 // Note: Could check against the default framebuffer value (((GPU_TARGET_DATA*)target->data)->handle versus result of GL_FRAMEBUFFER_BINDING)... 662 662 if(target != NULL) 663 663 { 664 - ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target = target; 664 + renderer->current_context_target->context->active_target = target; 665 665 return GPU_TRUE; 666 666 } 667 667 return GPU_FALSE; ··· 674 674 renderer->impl->FlushBlitBuffer(renderer); 675 675 676 676 extBindFramebuffer(renderer, handle); 677 - ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target = NULL; 677 + renderer->current_context_target->context->active_target = NULL; 678 678 } 679 679 680 680 static_inline void flushBlitBufferIfCurrentTexture(GPU_Renderer* renderer, GPU_Image* image) ··· 696 696 697 697 static_inline GPU_bool isCurrentTarget(GPU_Renderer* renderer, GPU_Target* target) 698 698 { 699 - return (target == ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target 700 - || ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target == NULL); 699 + return (target == renderer->current_context_target->context->active_target 700 + || renderer->current_context_target->context->active_target == NULL); 701 701 } 702 702 703 703 static_inline void flushAndClearBlitBufferIfCurrentFramebuffer(GPU_Renderer* renderer, GPU_Target* target) 704 704 { 705 - if(target == ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target 706 - || ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target == NULL) 705 + if(target == renderer->current_context_target->context->active_target 706 + || renderer->current_context_target->context->active_target == NULL) 707 707 { 708 708 renderer->impl->FlushBlitBuffer(renderer); 709 - ((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target = NULL; 709 + renderer->current_context_target->context->active_target = NULL; 710 710 } 711 711 } 712 712 ··· 1194 1194 #ifdef SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK 1195 1195 static void applyTransforms(GPU_Target* target) 1196 1196 { 1197 - float* p = GPU_GetProjection(target); 1198 - float* m = GPU_GetModelView(target); 1197 + float* p = GPU_GetTopMatrix(&target->projection_matrix); 1198 + float* m = GPU_GetTopMatrix(&target->model_matrix); 1199 + float mv[16]; 1200 + GPU_MatrixIdentity(mv); 1199 1201 1200 - float cam_matrix[16]; 1201 - get_camera_matrix(target, cam_matrix); 1202 + if(target->use_camera) 1203 + { 1204 + float cam_matrix[16]; 1205 + get_camera_matrix(target, cam_matrix); 1206 + 1207 + GPU_MultiplyAndAssign(mv, cam_matrix); 1208 + } 1209 + else 1210 + { 1211 + GPU_MultiplyAndAssign(mv, GPU_GetTopMatrix(&target->view_matrix)); 1212 + } 1202 1213 1203 - GPU_MultiplyAndAssign(cam_matrix, m); 1214 + GPU_MultiplyAndAssign(mv, m); 1204 1215 1205 1216 glMatrixMode(GL_PROJECTION); 1206 1217 glLoadMatrixf(p); 1207 1218 glMatrixMode(GL_MODELVIEW); 1208 - glLoadMatrixf(m); 1219 + glLoadMatrixf(mv); 1209 1220 } 1210 1221 #endif 1211 1222 ··· 1506 1517 target->context->context = NULL; 1507 1518 1508 1519 cdata->last_image = NULL; 1509 - cdata->last_target = NULL; 1510 1520 // Initialize the blit buffer 1511 1521 cdata->blit_buffer_max_num_vertices = GPU_BLIT_BUFFER_INIT_MAX_NUM_VERTICES; 1512 1522 cdata->blit_buffer_num_vertices = 0; ··· 1579 1589 ((GPU_TARGET_DATA*)target->data)->format = GL_RGBA; 1580 1590 1581 1591 target->renderer = renderer; 1582 - target->context_target = renderer->current_context_target; 1592 + target->context_target = target; // This target is a context target 1583 1593 target->w = (Uint16)target->context->drawable_w; 1584 1594 target->h = (Uint16)target->context->drawable_h; 1585 1595 target->base_w = (Uint16)target->context->drawable_w; ··· 1595 1605 target->viewport = GPU_MakeRect(0, 0, (float)target->context->drawable_w, (float)target->context->drawable_h); 1596 1606 1597 1607 1598 - target->matrix_mode = GPU_MODELVIEW; 1608 + target->matrix_mode = GPU_MODEL; 1599 1609 GPU_InitMatrixStack(&target->projection_matrix); 1600 - GPU_InitMatrixStack(&target->modelview_matrix); 1610 + GPU_InitMatrixStack(&target->view_matrix); 1611 + GPU_InitMatrixStack(&target->model_matrix); 1601 1612 1602 1613 target->camera = GPU_GetDefaultCamera(); 1603 1614 target->use_camera = GPU_TRUE; ··· 1875 1886 *result = *target; 1876 1887 1877 1888 // Deep copies 1889 + result->projection_matrix.matrix = NULL; 1890 + result->view_matrix.matrix = NULL; 1891 + result->model_matrix.matrix = NULL; 1892 + result->projection_matrix.size = result->projection_matrix.storage_size = 0; 1893 + result->view_matrix.size = result->view_matrix.storage_size = 0; 1894 + result->model_matrix.size = result->model_matrix.storage_size = 0; 1878 1895 GPU_CopyMatrixStack(&target->projection_matrix, &result->projection_matrix); 1879 - GPU_CopyMatrixStack(&target->modelview_matrix, &result->modelview_matrix); 1896 + GPU_CopyMatrixStack(&target->view_matrix, &result->view_matrix); 1897 + GPU_CopyMatrixStack(&target->model_matrix, &result->model_matrix); 1880 1898 1881 1899 // Alias info 1882 1900 if(target->image != NULL) ··· 1932 1950 } 1933 1951 1934 1952 // Reset the camera for this window 1935 - applyTargetCamera(((GPU_CONTEXT_DATA*)renderer->current_context_target->context->data)->last_target); 1953 + applyTargetCamera(renderer->current_context_target->context->active_target); 1936 1954 } 1937 1955 } 1938 1956 } ··· 1997 2015 if(cdata->last_image != NULL) 1998 2016 glBindTexture(GL_TEXTURE_2D, ((GPU_IMAGE_DATA*)(cdata->last_image)->data)->handle); 1999 2017 2000 - if(cdata->last_target != NULL) 2001 - extBindFramebuffer(renderer, ((GPU_TARGET_DATA*)cdata->last_target->data)->handle); 2018 + if(target->context->active_target != NULL) 2019 + extBindFramebuffer(renderer, ((GPU_TARGET_DATA*)target->context->active_target->data)->handle); 2002 2020 else 2003 2021 extBindFramebuffer(renderer, ((GPU_TARGET_DATA*)target->data)->handle); 2004 2022 } ··· 2023 2041 if(isCurrentTarget(renderer, target)) 2024 2042 renderer->impl->FlushBlitBuffer(renderer); 2025 2043 2026 - if(!bindFramebuffer(renderer, target)) 2044 + if(!SetActiveTarget(renderer, target)) 2027 2045 { 2028 2046 GPU_PushErrorCode("GPU_AddDepthBuffer", GPU_ERROR_BACKEND_ERROR, "Failed to bind target framebuffer."); 2029 2047 return GPU_FALSE; ··· 2727 2745 if(isCurrentTarget(renderer, source)) 2728 2746 renderer->impl->FlushBlitBuffer(renderer); 2729 2747 2730 - if(bindFramebuffer(renderer, source)) 2748 + if(SetActiveTarget(renderer, source)) 2731 2749 { 2732 2750 glReadPixels(0, 0, source->base_w, source->base_h, format, GL_UNSIGNED_BYTE, pixels); 2733 2751 return GPU_TRUE; ··· 3987 4005 3988 4006 result->viewport = GPU_MakeRect(0, 0, result->w, result->h); 3989 4007 3990 - result->matrix_mode = GPU_MODELVIEW; 4008 + result->matrix_mode = GPU_MODEL; 3991 4009 GPU_InitMatrixStack(&result->projection_matrix); 3992 - GPU_InitMatrixStack(&result->modelview_matrix); 4010 + GPU_InitMatrixStack(&result->view_matrix); 4011 + GPU_InitMatrixStack(&result->model_matrix); 3993 4012 3994 4013 result->camera = GPU_GetDefaultCamera(); 3995 4014 result->use_camera = GPU_TRUE; 4015 + 4016 + // Set up default projection matrix 4017 + GPU_ResetProjection(result); 3996 4018 3997 4019 result->use_depth_test = GPU_FALSE; 3998 4020 result->use_depth_write = GPU_TRUE; ··· 4110 4132 4111 4133 if(target->image != NULL && target->image->target == target) 4112 4134 target->image->target = NULL; 4113 - 4135 + 4114 4136 // Delete matrices 4115 4137 GPU_ClearMatrixStack(&target->projection_matrix); 4116 - GPU_ClearMatrixStack(&target->modelview_matrix); 4138 + GPU_ClearMatrixStack(&target->view_matrix); 4139 + GPU_ClearMatrixStack(&target->model_matrix); 4117 4140 4118 4141 SDL_free(target); 4119 4142 } ··· 4252 4275 bindTexture(renderer, image); 4253 4276 4254 4277 // Bind the FBO 4255 - if(!bindFramebuffer(renderer, target)) 4278 + if(!SetActiveTarget(renderer, target)) 4256 4279 { 4257 4280 GPU_PushErrorCode("GPU_Blit", GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); 4258 4281 return; ··· 4475 4498 bindTexture(renderer, image); 4476 4499 4477 4500 // Bind the FBO 4478 - if(!bindFramebuffer(renderer, target)) 4501 + if(!SetActiveTarget(renderer, target)) 4479 4502 { 4480 4503 GPU_PushErrorCode("GPU_BlitTransformX", GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); 4481 4504 return; ··· 4818 4841 // MVP = P * V * M 4819 4842 4820 4843 // P 4821 - GPU_MatrixCopy(mvp, GPU_GetProjection(dest)); 4844 + GPU_MatrixCopy(mvp, GPU_GetTopMatrix(&dest->projection_matrix)); 4822 4845 4823 4846 4824 4847 // V ··· 4828 4851 get_camera_matrix(dest, cam_matrix); 4829 4852 4830 4853 GPU_MultiplyAndAssign(mvp, cam_matrix); 4854 + } 4855 + else 4856 + { 4857 + GPU_MultiplyAndAssign(mvp, GPU_GetTopMatrix(&dest->view_matrix)); 4831 4858 } 4832 4859 4833 4860 // M 4834 - GPU_MultiplyAndAssign(mvp, GPU_GetModelView(dest)); 4861 + GPU_MultiplyAndAssign(mvp, GPU_GetTopMatrix(&dest->model_matrix)); 4835 4862 4836 4863 glUniformMatrix4fv(context->current_shader_block.modelViewProjection_loc, 1, 0, mvp); 4837 4864 } ··· 4877 4904 bindTexture(renderer, image); 4878 4905 4879 4906 // Bind the FBO 4880 - if(!bindFramebuffer(renderer, target)) 4907 + if(!SetActiveTarget(renderer, target)) 4881 4908 { 4882 4909 GPU_PushErrorCode("GPU_PrimitiveBatchX", GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); 4883 4910 return; ··· 5311 5338 5312 5339 if(isCurrentTarget(renderer, target)) 5313 5340 renderer->impl->FlushBlitBuffer(renderer); 5314 - if(bindFramebuffer(renderer, target)) 5341 + if(SetActiveTarget(renderer, target)) 5315 5342 { 5316 5343 unsigned char pixels[4]; 5317 5344 GLenum format = ((GPU_TARGET_DATA*)target->data)->format; ··· 5462 5489 5463 5490 if(isCurrentTarget(renderer, target)) 5464 5491 renderer->impl->FlushBlitBuffer(renderer); 5465 - if(bindFramebuffer(renderer, target)) 5492 + if(SetActiveTarget(renderer, target)) 5466 5493 { 5467 5494 setClipRect(renderer, target); 5468 5495 ··· 5679 5706 5680 5707 context = renderer->current_context_target->context; 5681 5708 cdata = (GPU_CONTEXT_DATA*)context->data; 5682 - if(cdata->blit_buffer_num_vertices > 0 && cdata->last_target != NULL) 5709 + if(cdata->blit_buffer_num_vertices > 0 && context->active_target != NULL) 5683 5710 { 5684 - GPU_Target* dest = cdata->last_target; 5711 + GPU_Target* dest = context->active_target; 5685 5712 int num_vertices; 5686 5713 int num_indices; 5687 5714 float* blit_buffer; ··· 6893 6920 #define SET_COMMON_FUNCTIONS(impl) \ 6894 6921 impl->Init = &Init; \ 6895 6922 impl->CreateTargetFromWindow = &CreateTargetFromWindow; \ 6923 + impl->SetActiveTarget = &SetActiveTarget; \ 6896 6924 impl->CreateAliasTarget = &CreateAliasTarget; \ 6897 6925 impl->MakeCurrent = &MakeCurrent; \ 6898 6926 impl->SetAsCurrent = &SetAsCurrent; \
+1 -1
src/renderer_shapes_GL_common.inl
··· 37 37 return; \ 38 38 } \ 39 39 \ 40 - if(!bindFramebuffer(renderer, target)) \ 40 + if(!SetActiveTarget(renderer, target)) \ 41 41 { \ 42 42 GPU_PushErrorCode(function_name, GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); \ 43 43 return; \
+28 -11
tests/camera-matrix/main.c
··· 97 97 } 98 98 else if(event.key.keysym.sym == SDLK_o) 99 99 { 100 - GPU_MatrixMode(screen, GPU_PROJECTION); 101 - GPU_LoadIdentity(screen); 100 + GPU_MatrixMode(target, GPU_PROJECTION); 101 + GPU_LoadIdentity(); 102 102 103 103 camera.x = 0; 104 104 camera.y = 0; 105 105 camera.z = 0.0f; 106 - GPU_Ortho(screen, 0, target->w, target->h, 0, target->camera.z_near, target->camera.z_far); 106 + 107 + if(target->image == NULL) 108 + GPU_Ortho(0, target->w, target->h, 0, target->camera.z_near, target->camera.z_far); 109 + else 110 + GPU_Ortho(0, target->w, 0, target->h, target->camera.z_near, target->camera.z_far); 107 111 108 - GPU_MatrixMode(screen, GPU_MODELVIEW); 112 + GPU_MatrixMode(target, GPU_MODEL); 109 113 } 110 114 else if(event.key.keysym.sym == SDLK_p) 111 115 { 112 - GPU_MatrixMode(screen, GPU_PROJECTION); 113 - GPU_LoadIdentity(screen); 116 + GPU_MatrixMode(target, GPU_PROJECTION); 117 + GPU_LoadIdentity(); 114 118 115 119 camera.x = target->w/2; 116 120 camera.y = target->h/2; 117 121 camera.z = 1000.0f; 118 - GPU_Frustum(screen, -400, 400, 300, -300, 1000.0f, 10000.0f); 122 + 123 + if(target->image == NULL) 124 + GPU_Frustum(-400, 400, 300, -300, 1000.0f, 10000.0f); 125 + else 126 + GPU_Frustum(-400, 400, -300, 300, 1000.0f, 10000.0f); 119 127 120 - GPU_MatrixMode(screen, GPU_MODELVIEW); 128 + GPU_MatrixMode(target, GPU_MODEL); 121 129 } 122 130 } 123 131 } ··· 165 173 camera.angle += 100*dt; 166 174 } 167 175 168 - GPU_ClearRGBA(screen, 0, 0, 0, 255); 176 + GPU_ClearRGBA(target, 0, 0, 0, 255); 169 177 170 178 // No camera view 171 - GPU_SetCamera(screen, NULL); 179 + GPU_SetCamera(target, NULL); 172 180 173 181 GPU_Circle(target, 0, 0, 25, GPU_MakeColor(255, 255, 255, 255)); 174 182 GPU_Circle(target, target->w, 0, 25, GPU_MakeColor(255, 0, 0, 255)); ··· 188 196 GPU_CircleFilled(target, 0, target->h, 15, GPU_MakeColor(0, 0, 255, 255)); 189 197 190 198 GPU_RectangleFilled(target, target->w/2 - 20, target->h/2 - 20, target->w/2 + 20, target->h/2 + 20, GPU_MakeColor(255, 0, 0, 255)); 191 - 199 + 200 + if(target != screen) 201 + { 202 + GPU_ResetProjection(screen); 203 + GPU_SetCamera(screen, NULL); 204 + 205 + GPU_ClearRGBA(screen, 0, 0, 0, 255); 206 + GPU_BlitRect(buffer, NULL, screen, NULL); 207 + } 208 + 192 209 GPU_Flip(screen); 193 210 194 211 frameCount++;
+11 -10
tests/depth/main.c
··· 64 64 65 65 GPU_ClearRGB(screen, 200, 200, 200); 66 66 67 + GPU_MatrixMode(screen, GPU_MODEL); 67 68 if(!mode) 68 69 { 69 70 // Draw to screen directly ··· 71 72 // Images drawn left to right, but layered alternating. Positive z values are on top. 72 73 GPU_Blit(image, NULL, screen, 150, 300); 73 74 74 - GPU_PushMatrix(screen); 75 - GPU_Translate(screen, 0, 0, 5); 75 + GPU_PushMatrix(); 76 + GPU_Translate(0, 0, 5); 76 77 GPU_Blit(image, NULL, screen, 300, 300); 77 78 78 - GPU_Translate(screen, 0, 0, -10); 79 + GPU_Translate(0, 0, -10); 79 80 GPU_Blit(image, NULL, screen, 450, 300); 80 81 81 - GPU_Translate(screen, 0, 0, 10); 82 + GPU_Translate(0, 0, 10); 82 83 GPU_Blit(image, NULL, screen, 600, 300); 83 - GPU_PopMatrix(screen); 84 + GPU_PopMatrix(); 84 85 } 85 86 else 86 87 { ··· 90 91 // Images drawn left to right, but layered alternating. Positive z values are on top. 91 92 GPU_Blit(image, NULL, target, 150, 300); 92 93 93 - GPU_PushMatrix(screen); 94 - GPU_Translate(screen, 0, 0, 5); 94 + GPU_PushMatrix(); 95 + GPU_Translate(0, 0, 5); 95 96 GPU_Blit(image, NULL, target, 300, 300); 96 97 97 - GPU_Translate(screen, 0, 0, -10); 98 + GPU_Translate(0, 0, -10); 98 99 GPU_Blit(image, NULL, target, 450, 300); 99 100 100 - GPU_Translate(screen, 0, 0, 10); 101 + GPU_Translate(0, 0, 10); 101 102 GPU_Blit(image, NULL, target, 600, 300); 102 - GPU_PopMatrix(screen); 103 + GPU_PopMatrix(); 103 104 104 105 GPU_Blit(target_image, NULL, screen, 0, 0); 105 106 }
+23 -5
tests/renderer/main.c
··· 142 142 143 143 144 144 GPU_InitMatrixStack(&target->projection_matrix); 145 - GPU_InitMatrixStack(&target->modelview_matrix); 145 + GPU_InitMatrixStack(&target->view_matrix); 146 + GPU_InitMatrixStack(&target->model_matrix); 146 147 147 - target->matrix_mode = GPU_MODELVIEW; 148 + target->matrix_mode = GPU_MODEL; 148 149 149 150 150 151 renderer->impl->SetLineThickness(renderer, 1.0f); ··· 173 174 174 175 // Deep copies 175 176 GPU_CopyMatrixStack(&target->projection_matrix, &result->projection_matrix); 176 - GPU_CopyMatrixStack(&target->modelview_matrix, &result->modelview_matrix); 177 + GPU_CopyMatrixStack(&target->view_matrix, &result->view_matrix); 178 + GPU_CopyMatrixStack(&target->model_matrix, &result->model_matrix); 177 179 178 180 // Alias info 179 181 if(target->image != NULL) ··· 221 223 return; 222 224 223 225 renderer->impl->MakeCurrent(renderer, renderer->current_context_target, renderer->current_context_target->context->windowID); 226 + } 227 + 228 + static GPU_bool SetActiveTarget(GPU_Renderer* renderer, GPU_Target* target) 229 + { 230 + GPU_Log(" %s (dummy)\n", __func__); 231 + if(renderer->current_context_target == NULL) 232 + return GPU_FALSE; 233 + 234 + if(renderer->current_context_target->context->active_target != target) 235 + { 236 + renderer->impl->FlushBlitBuffer(renderer); 237 + renderer->current_context_target->context->active_target = target; 238 + } 239 + return GPU_TRUE; 224 240 } 225 241 226 242 static void ResetRendererState(GPU_Renderer* renderer) ··· 646 662 result->viewport = GPU_MakeRect(0, 0, result->w, result->h); 647 663 648 664 GPU_InitMatrixStack(&result->projection_matrix); 649 - GPU_InitMatrixStack(&result->modelview_matrix); 665 + GPU_InitMatrixStack(&result->view_matrix); 666 + GPU_InitMatrixStack(&result->model_matrix); 650 667 651 - result->matrix_mode = GPU_MODELVIEW; 668 + result->matrix_mode = GPU_MODEL; 652 669 653 670 result->camera = GPU_GetDefaultCamera(); 654 671 ··· 1190 1207 impl->CreateAliasTarget = &CreateAliasTarget; 1191 1208 impl->MakeCurrent = &MakeCurrent; 1192 1209 impl->SetAsCurrent = &SetAsCurrent; 1210 + impl->SetActiveTarget = &SetActiveTarget; 1193 1211 impl->ResetRendererState = &ResetRendererState; 1194 1212 impl->AddDepthBuffer = &AddDepthBuffer; 1195 1213 impl->SetWindowResolution = &SetWindowResolution;
+21 -26
tests/transform-matrix/main.c
··· 26 26 SDL_Event event; 27 27 28 28 GPU_Camera camera = GPU_GetDefaultCamera(); 29 - float matrix[16]; 30 29 31 30 GPU_Image* image = GPU_LoadImage("data/test.bmp"); 32 31 if(image == NULL) ··· 41 40 Uint8 rotate_stuff = 0; 42 41 43 42 GPU_EnableCamera(screen, use_camera); 44 - GPU_MatrixIdentity(matrix); 45 43 46 44 startTime = SDL_GetTicks(); 47 45 frameCount = 0; ··· 109 107 110 108 if (!use_camera) 111 109 { 112 - GPU_LoadIdentity(screen); 110 + GPU_LoadIdentity(); 113 111 // Apply projection matrix 114 - GPU_MatrixIdentity(matrix); 115 112 116 113 if (use_perspective) 117 114 { 118 - GPU_MatrixPerspective(matrix, 90, screen->w / (float)screen->h, 0.1, 2000); 115 + GPU_Perspective(90, screen->w / (float)screen->h, 0.1, 2000); 119 116 } 120 117 else 121 118 { 122 - GPU_MatrixOrtho(matrix, 0, 800, 600, 0, -1000, 1000); 119 + GPU_Ortho(0, 800, 600, 0, -1000, 1000); 123 120 } 124 - 125 - GPU_MultMatrix(screen, matrix); 126 121 } 127 122 128 123 129 - GPU_MatrixMode(screen, GPU_MODELVIEW); 130 - GPU_LoadIdentity(screen); 124 + GPU_MatrixMode(screen, GPU_VIEW); 125 + GPU_LoadIdentity(); 131 126 132 127 if (!use_camera) 133 128 { 134 129 // Apply view matrix 135 - GPU_MatrixIdentity(matrix); 136 130 137 131 if(use_perspective) 138 132 { 139 - GPU_MatrixLookAt(matrix, screen->w/2, screen->h/2, 300, // eye 133 + GPU_LookAt(screen->w/2, screen->h/2, 300, // eye 140 134 screen->w/2, screen->h/2, 0, // target 141 135 0, 1, 0); // up 142 136 } 143 137 else 144 138 { 145 - GPU_MatrixLookAt(matrix, 0, 0, 0.1, // eye 139 + GPU_LookAt(0, 0, 0.1, // eye 146 140 0, 0, 0, // target 147 141 0, 1, 0); // up 148 142 } 149 - GPU_MultMatrix(screen, matrix); 150 143 } 151 144 152 145 153 146 154 147 // Apply model matrix 155 - GPU_MatrixIdentity(matrix); 148 + GPU_MatrixMode(screen, GPU_MODEL); 149 + GPU_LoadIdentity(); 156 150 157 - GPU_MatrixTranslate(matrix, x, y, z); 151 + GPU_Translate(x, y, z); 158 152 159 153 // Rotate 160 154 if(rotate_stuff) 161 155 { 162 156 float a = SDL_GetTicks() / 10.0f; 163 - GPU_MatrixRotate(matrix, a, 0.57, 0.57, 0.57); 157 + GPU_Rotate(a, 0.57, 0.57, 0.57); 164 158 } 165 159 166 - GPU_MultMatrix(screen, matrix); 167 - 168 160 GPU_SetCamera(screen, &camera); 169 161 170 162 GPU_Blit(image, NULL, screen, 0, 0); ··· 179 171 GPU_BlitScale(image, NULL, screen, 200, 200, 0.5f, 0.5f); 180 172 181 173 float scale = 200; 182 - GPU_MatrixMode(screen, GPU_MODELVIEW); 183 - GPU_PushMatrix(screen); 174 + GPU_MatrixMode(screen, GPU_MODEL); 175 + GPU_PushMatrix(); 184 176 GPU_SetLineThickness(4.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); 177 + GPU_Translate(40, 40, 0.0f); 178 + GPU_Rotate(90, 0.0f, 0.0f, 1.0f); 179 + //GPU_Translate(-screen->w/2, -screen->h/2, 0.0f); 180 + GPU_Translate(-40, -40, 0.0f); 181 + 182 + 189 183 GPU_Line(screen, 0, 0, scale, 0, GPU_MakeColor(255, 0, 0, 255)); 190 184 GPU_CircleFilled(screen, 0, 0, scale/16, GPU_MakeColor(255, 0, 0, 255)); 191 185 GPU_Circle(screen, 0, 0, scale, GPU_MakeColor(255, 0, 0, 255)); 192 186 GPU_Circle(screen, 0, 0, scale*4, GPU_MakeColor(0, 255, 0, 255)); 193 187 GPU_SetLineThickness(1.0f); 194 - GPU_PopMatrix(screen); 188 + 189 + GPU_PopMatrix(); 195 190 196 191 GPU_Flip(screen); 197 192
+4 -4
tests/triangle-batch/main.c
··· 418 418 1, 3, 7, 419 419 3, 5, 7}; 420 420 421 - GPU_MatrixMode(screen, GPU_MODELVIEW); 422 - GPU_PushMatrix(screen); 423 - GPU_Translate(screen, 300, 300, 0); 421 + GPU_MatrixMode(screen, GPU_MODEL); 422 + GPU_PushMatrix(); 423 + GPU_Translate(300, 300, 0); 424 424 GPU_TriangleBatch(image, screen, n_v, v, n_i, i, GPU_BATCH_XY_ST); 425 - GPU_PopMatrix(screen); 425 + GPU_PopMatrix(); 426 426 } 427 427 428 428 GPU_Flip(screen);