@@ -63,20 +63,52 @@ typedef struct
63
63
typedef struct
64
64
{
65
65
float x , y , z ;
66
- } VertV ;
66
+ } __attribute__ (( packed )) VertV ;
67
67
68
68
typedef struct
69
69
{
70
70
SDL_Color col ;
71
71
float x , y , z ;
72
- } VertCV ;
72
+ } __attribute__ (( packed )) VertCV ;
73
73
74
74
typedef struct
75
75
{
76
76
float u , v ;
77
77
SDL_Color col ;
78
78
float x , y , z ;
79
- } VertTCV ;
79
+ } __attribute__ ((packed )) VertTCV ;
80
+
81
+ typedef struct
82
+ {
83
+ float u , v ;
84
+ float x , y , z ;
85
+ } __attribute__ ((packed )) VertTV ;
86
+
87
+ typedef struct
88
+ {
89
+ int width ;
90
+ int height ;
91
+ } SliceSize ;
92
+
93
+ typedef enum
94
+ {
95
+ SLICE_PIXEL_BITS_32 ,
96
+ SLICE_PIXEL_BITS_16 ,
97
+ SLICE_PIXEL_BITS_COUNT
98
+ } SlicePixelBits ;
99
+
100
+ #define SLICE_VALUES_COUNT 3
101
+ typedef struct
102
+ {
103
+ SlicePixelBits pixelBits ;
104
+ SliceSize sizes [SLICE_VALUES_COUNT ];
105
+ SliceSize condition ;
106
+ } SliceInfo ;
107
+
108
+ static SliceInfo sliceInfo [SLICE_PIXEL_BITS_COUNT ] = {
109
+ { SLICE_PIXEL_BITS_32 , { { 128 , 16 }, { 64 , 32 }, { 32 , 64 } }, { 32 , 16 } },
110
+ { SLICE_PIXEL_BITS_16 , { { 128 , 32 }, { 64 , 64 }, { 32 , 128 } }, { 32 , 32 } }
111
+ };
80
112
81
113
int SDL_PSP_RenderGetProp (SDL_Renderer * r , enum SDL_PSP_RenderProps which , void * * out )
82
114
{
@@ -171,6 +203,60 @@ static int calculateNextPow2(int value)
171
203
return i ;
172
204
}
173
205
206
+ static int calculateBestSliceSizeForTexture (SDL_Texture * texture , SliceSize * uvSize , SliceSize * sliceSize , SliceSize * sliceDimension ) {
207
+ int i ;
208
+ uint8_t horizontalSlices , verticalSlices ;
209
+ int pixelBits = 0 ;
210
+ int pixelSize = SDL_BYTESPERPIXEL (texture -> format );
211
+ SliceInfo * sliceInfoPtr = NULL ;
212
+ SliceSize * foundSlizeSize = NULL ;
213
+
214
+ switch (pixelSize ) {
215
+ case 4 :
216
+ sliceInfoPtr = & sliceInfo [SLICE_PIXEL_BITS_32 ];
217
+ break ;
218
+ case 2 :
219
+ sliceInfoPtr = & sliceInfo [SLICE_PIXEL_BITS_16 ];
220
+ break ;
221
+ default :
222
+ return -1 ;
223
+ }
224
+
225
+ if (sliceInfoPtr -> condition .width > uvSize -> width && sliceInfoPtr -> condition .height > uvSize -> height ) {
226
+ sliceSize -> width = uvSize -> width ;
227
+ sliceSize -> height = uvSize -> height ;
228
+ sliceDimension -> width = 1 ;
229
+ sliceDimension -> height = 1 ;
230
+ return 0 ;
231
+ }
232
+
233
+ if (uvSize -> width >= uvSize -> height ) {
234
+ for (i = 0 ; i < SLICE_VALUES_COUNT ; i ++ ) {
235
+ if (uvSize -> width >= sliceInfoPtr -> sizes [i ].width ) {
236
+ foundSlizeSize = & sliceInfoPtr -> sizes [i ];
237
+ break ;
238
+ }
239
+ }
240
+ } else {
241
+ for (i = SLICE_VALUES_COUNT - 1 ; i >= 0 ; i -- ) {
242
+ if (uvSize -> height >= sliceInfoPtr -> sizes [i ].height ) {
243
+ foundSlizeSize = & sliceInfoPtr -> sizes [i ];
244
+ break ;
245
+ }
246
+ }
247
+ }
248
+
249
+ if (foundSlizeSize == NULL )
250
+ return -1 ;
251
+
252
+ sliceSize -> width = foundSlizeSize -> width ;
253
+ sliceSize -> height = foundSlizeSize -> height ;
254
+ sliceDimension -> width = ((texture -> w % foundSlizeSize -> width == 0 ) ? 0 : 1 ) + (texture -> w / foundSlizeSize -> width );
255
+ sliceDimension -> height = ((texture -> h % foundSlizeSize -> height == 0 ) ? 0 : 1 ) + (texture -> h / foundSlizeSize -> height );
256
+
257
+ return 0 ;
258
+ }
259
+
174
260
static void PSP_WindowEvent (SDL_Renderer * renderer , const SDL_WindowEvent * event )
175
261
{
176
262
}
0 commit comments