this repo has no description
0
fork

Configure Feed

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

Removed GPU_BlitTransformMatrix(), which was made somewhat redundant by the inclusion of the matrix functions.

+3 -267
+1
common/common.c
··· 1 1 #include "common.h" 2 2 #include <string.h> 3 + #include <stdlib.h> 3 4 4 5 void printRenderers(void) 5 6 {
+2
common/demo-font.c
··· 1 1 #include "demo-font.h" 2 + #include <stdlib.h> 3 + #include <string.h> 2 4 3 5 static Uint32 _GetPixel(SDL_Surface *Surface, int x, int y) 4 6 {
-7
include/SDL_gpu.h
··· 1213 1213 * \param scaleY Vertical stretch factor */ 1214 1214 DECLSPEC void SDLCALL GPU_BlitTransformX(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float pivot_x, float pivot_y, float degrees, float scaleX, float scaleY); 1215 1215 1216 - /*! Transforms and draws the given image to the given render target. 1217 - * \param src_rect The region of the source image to use. 1218 - * \param x Destination x-position 1219 - * \param y Destination y-position 1220 - * \param matrix3x3 3x3 matrix in column-major order (index = row + column*numColumns) */ 1221 - DECLSPEC void SDLCALL GPU_BlitTransformMatrix(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float* matrix3x3); 1222 - 1223 1216 /*! Renders triangles from the given set of vertices. This lets you render arbitrary 2D geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1224 1217 * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0. Pass NULL to render with only custom shader attributes. 1225 1218 * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array).
-3
include/SDL_gpu_RendererImpl.h
··· 115 115 /*! \see GPU_BlitTransformX() */ 116 116 void (SDLCALL *BlitTransformX)(GPU_Renderer* renderer, GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float pivot_x, float pivot_y, float degrees, float scaleX, float scaleY); 117 117 118 - /*! \see GPU_BlitTransformMatrix() */ 119 - void (SDLCALL *BlitTransformMatrix)(GPU_Renderer* renderer, GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float* matrix3x3); 120 - 121 118 /*! \see GPU_TriangleBatch() */ 122 119 void (SDLCALL *TriangleBatch)(GPU_Renderer* renderer, GPU_Image* image, GPU_Target* target, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 123 120
-19
src/SDL_gpu.c
··· 1209 1209 _gpu_current_renderer->impl->BlitTransformX(_gpu_current_renderer, image, src_rect, target, x, y, pivot_x, pivot_y, angle, scaleX, scaleY); 1210 1210 } 1211 1211 1212 - void GPU_BlitTransformMatrix(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float* matrix3x3) 1213 - { 1214 - if(!CHECK_RENDERER) 1215 - RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer"); 1216 - MAKE_CURRENT_IF_NONE(target); 1217 - if(!CHECK_CONTEXT) 1218 - RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL context"); 1219 - 1220 - if(image == NULL) 1221 - RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "image"); 1222 - if(target == NULL) 1223 - RETURN_ERROR(GPU_ERROR_NULL_ARGUMENT, "target"); 1224 - 1225 - if(matrix3x3 == NULL) 1226 - return; 1227 - 1228 - _gpu_current_renderer->impl->BlitTransformMatrix(_gpu_current_renderer, image, src_rect, target, x, y, matrix3x3); 1229 - } 1230 - 1231 1212 void GPU_TriangleBatch(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 1232 1213 { 1233 1214 if(!CHECK_RENDERER)
-61
src/renderer_GL_common.inl
··· 3979 3979 cdata->blit_buffer_num_vertices += GPU_BLIT_BUFFER_VERTICES_PER_SPRITE; 3980 3980 } 3981 3981 3982 - static void BlitTransformMatrix(GPU_Renderer* renderer, GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float* matrix3x3) 3983 - { 3984 - if(image == NULL) 3985 - { 3986 - GPU_PushErrorCode("GPU_BlitTransformMatrix", GPU_ERROR_NULL_ARGUMENT, "image"); 3987 - return; 3988 - } 3989 - if(target == NULL) 3990 - { 3991 - GPU_PushErrorCode("GPU_BlitTransformMatrix", GPU_ERROR_NULL_ARGUMENT, "target"); 3992 - return; 3993 - } 3994 - if(renderer != image->renderer || renderer != target->renderer) 3995 - { 3996 - GPU_PushErrorCode("GPU_BlitTransformMatrix", GPU_ERROR_USER_ERROR, "Mismatched renderer"); 3997 - return; 3998 - } 3999 - 4000 - // TODO: See below. 4001 - renderer->impl->FlushBlitBuffer(renderer); 4002 - 4003 - GPU_PushMatrix(); 4004 - 4005 - // column-major 3x3 to column-major 4x4 (and scooting the 2D translations to the homogeneous column) 4006 - // FIXME: Should index 8 replace the homogeneous 1? This looks like it adjusts the z-value... 4007 - { 4008 - float matrix[16]; 4009 - matrix[0] = matrix3x3[0]; 4010 - matrix[1] = matrix3x3[1]; 4011 - matrix[2] = matrix3x3[2]; 4012 - matrix[3] = 0; 4013 - 4014 - matrix[4] = matrix3x3[3]; 4015 - matrix[5] = matrix3x3[4]; 4016 - matrix[6] = matrix3x3[5]; 4017 - matrix[7] = 0; 4018 - 4019 - matrix[8] = 0; 4020 - matrix[9] = 0; 4021 - matrix[10] = matrix3x3[8]; 4022 - matrix[11] = 0; 4023 - 4024 - matrix[12] = matrix3x3[6]; 4025 - matrix[13] = matrix3x3[7]; 4026 - matrix[14] = 0; 4027 - matrix[15] = 1; 4028 - 4029 - GPU_Translate(x, y, 0); 4030 - GPU_MultMatrix(matrix); 4031 - } 4032 - 4033 - renderer->impl->Blit(renderer, image, src_rect, target, 0, 0); 4034 - 4035 - // Popping the matrix will revert the transform before it can be used, so we have to flush for now. 4036 - // TODO: Do the matrix math myself on the vertex coords. 4037 - renderer->impl->FlushBlitBuffer(renderer); 4038 - 4039 - GPU_PopMatrix(); 4040 - } 4041 - 4042 3982 4043 3983 4044 3984 #ifdef SDL_GPU_USE_BUFFER_PIPELINE ··· 6181 6121 impl->BlitScale = &BlitScale; \ 6182 6122 impl->BlitTransform = &BlitTransform; \ 6183 6123 impl->BlitTransformX = &BlitTransformX; \ 6184 - impl->BlitTransformMatrix = &BlitTransformMatrix; \ 6185 6124 impl->TriangleBatch = &TriangleBatch; \ 6186 6125 \ 6187 6126 impl->GenerateMipmaps = &GenerateMipmaps; \
-3
tests/CMakeLists.txt
··· 57 57 add_executable(transformx-test transformx/main.c) 58 58 target_link_libraries (transformx-test ${TEST_LIBS}) 59 59 60 - add_executable(transform-matrix-test transform-matrix/main.c) 61 - target_link_libraries (transform-matrix-test ${TEST_LIBS}) 62 - 63 60 add_executable(copy-test copy/main.c) 64 61 target_link_libraries (copy-test ${TEST_LIBS}) 65 62
-7
tests/renderer/main.c
··· 731 731 } 732 732 733 733 734 - static void BlitTransformMatrix(GPU_Renderer* renderer, GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float* matrix3x3) 735 - { 736 - GPU_Log(" %s (dummy)\n", __func__); 737 - } 738 - 739 - 740 734 static void TriangleBatch(GPU_Renderer* renderer, GPU_Image* image, GPU_Target* target, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 741 735 { 742 736 GPU_Log(" %s (dummy)\n", __func__); ··· 1217 1211 impl->BlitScale = &BlitScale; 1218 1212 impl->BlitTransform = &BlitTransform; 1219 1213 impl->BlitTransformX = &BlitTransformX; 1220 - impl->BlitTransformMatrix = &BlitTransformMatrix; 1221 1214 impl->TriangleBatch = &TriangleBatch; 1222 1215 1223 1216 impl->GenerateMipmaps = &GenerateMipmaps;
-167
tests/transform-matrix/main.c
··· 1 - #include "SDL.h" 2 - #include "SDL_gpu.h" 3 - #include <math.h> 4 - #include "compat.h" 5 - #include "common.h" 6 - 7 - #ifndef M_PI 8 - #define M_PI 3.14159 9 - #endif 10 - 11 - 12 - // Post-multiply 13 - void scale(float* matrix3x3, float scale_x, float scale_y) 14 - { 15 - matrix3x3[0] *= scale_x; 16 - matrix3x3[1] *= scale_x; 17 - matrix3x3[2] *= scale_x; 18 - matrix3x3[3] *= scale_y; 19 - matrix3x3[4] *= scale_y; 20 - matrix3x3[5] *= scale_y; 21 - } 22 - 23 - void translate(float* matrix3x3, float dx, float dy) 24 - { 25 - matrix3x3[6] += matrix3x3[0]*dx + matrix3x3[3]*dy; 26 - matrix3x3[7] += matrix3x3[1]*dx + matrix3x3[4]*dy; 27 - matrix3x3[8] += matrix3x3[2]*dx + matrix3x3[5]*dy; 28 - } 29 - 30 - void rotate(float* matrix3x3, float radians) 31 - { 32 - float cosT = cos(radians); 33 - float sinT = sin(radians); 34 - float a = matrix3x3[0]; 35 - float b = matrix3x3[3]; 36 - float d = matrix3x3[1]; 37 - float e = matrix3x3[4]; 38 - float g = matrix3x3[2]; 39 - float h = matrix3x3[5]; 40 - matrix3x3[0] = a*cosT+b*sinT; 41 - matrix3x3[1] = d*cosT+e*sinT; 42 - matrix3x3[2] = g*cosT+h*sinT; 43 - matrix3x3[3] = -a*sinT+b*cosT; 44 - matrix3x3[4] = -d*sinT+e*cosT; 45 - matrix3x3[5] = -g*sinT+h*cosT; 46 - } 47 - 48 - int main(int argc, char* argv[]) 49 - { 50 - GPU_Target* screen; 51 - 52 - printRenderers(); 53 - 54 - screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); 55 - if(screen == NULL) 56 - return -1; 57 - 58 - printCurrentRenderer(); 59 - 60 - { 61 - Uint32 startTime; 62 - long frameCount; 63 - Uint8 done; 64 - SDL_Event event; 65 - 66 - GPU_Image* screen2_image = GPU_CreateImage(800, 600, GPU_FORMAT_RGBA); 67 - GPU_Target* screen2 = GPU_LoadTarget(screen2_image); 68 - 69 - float angle = 0.0f; 70 - float dx = 0.0f; 71 - float dy = 0.0f; 72 - float scale_x = 1.0f; 73 - float scale_y = 1.0f; 74 - 75 - float dt = 0.010f; 76 - 77 - GPU_Target* target = screen; 78 - float x = 400.0f; 79 - float y = 300.0f; 80 - SDL_Color red = {255, 0, 0, 255}; 81 - const Uint8* keystates = SDL_GetKeyState(NULL); 82 - 83 - GPU_Image* image = GPU_LoadImage("data/test.bmp"); 84 - if(image == NULL) 85 - return -1; 86 - 87 - startTime = SDL_GetTicks(); 88 - frameCount = 0; 89 - 90 - done = 0; 91 - while(!done) 92 - { 93 - while(SDL_PollEvent(&event)) 94 - { 95 - if(event.type == SDL_QUIT) 96 - done = 1; 97 - else if(event.type == SDL_KEYDOWN) 98 - { 99 - if(event.key.keysym.sym == SDLK_ESCAPE) 100 - done = 1; 101 - else if(event.key.keysym.sym == SDLK_SPACE) 102 - { 103 - if(target == screen) 104 - target = screen2; 105 - else 106 - target = screen; 107 - } 108 - } 109 - } 110 - 111 - if(keystates[KEY_UP]) 112 - dy -= 100*dt; 113 - else if(keystates[KEY_DOWN]) 114 - dy += 100*dt; 115 - if(keystates[KEY_LEFT]) 116 - dx -= 100*dt; 117 - else if(keystates[KEY_RIGHT]) 118 - dx += 100*dt; 119 - if(keystates[KEY_COMMA]) 120 - angle -= 100*dt; 121 - else if(keystates[KEY_PERIOD]) 122 - angle += 100*dt; 123 - if(keystates[KEY_a]) 124 - scale_x -= 1*dt; 125 - else if(keystates[KEY_s]) 126 - scale_x += 1*dt; 127 - if(keystates[KEY_z]) 128 - scale_y -= 1*dt; 129 - else if(keystates[KEY_x]) 130 - scale_y += 1*dt; 131 - 132 - GPU_Clear(screen); 133 - GPU_Clear(screen2); 134 - 135 - GPU_BlitScale(image, NULL, target, x, y, 0.1f, 0.1f); 136 - 137 - { 138 - float matrix[9] = {1,0,0,0,1,0,0,0,1}; 139 - translate(matrix, dx, dy); 140 - scale(matrix, scale_x, scale_y); 141 - rotate(matrix, angle*M_PI/180); 142 - GPU_BlitTransformMatrix(image, NULL, target, x, y, matrix); 143 - } 144 - 145 - 146 - if(target == screen2) 147 - GPU_CircleFilled(screen2, 0, 0, 100, red); 148 - 149 - GPU_Blit(screen2_image, NULL, screen, 400, 300); 150 - GPU_Flip(screen); 151 - 152 - frameCount++; 153 - if(frameCount%500 == 0) 154 - printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); 155 - } 156 - 157 - printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); 158 - 159 - GPU_FreeImage(image); 160 - } 161 - 162 - GPU_Quit(); 163 - 164 - return 0; 165 - } 166 - 167 -