Skip to content

Commit 6274688

Browse files
committed
Create function for calculate the proper slice size
1 parent aeac20f commit 6274688

File tree

1 file changed

+89
-3
lines changed

1 file changed

+89
-3
lines changed

src/render/psp/SDL_render_psp.c

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,52 @@ typedef struct
6363
typedef struct
6464
{
6565
float x, y, z;
66-
} VertV;
66+
} __attribute__ ((packed)) VertV;
6767

6868
typedef struct
6969
{
7070
SDL_Color col;
7171
float x, y, z;
72-
} VertCV;
72+
} __attribute__ ((packed)) VertCV;
7373

7474
typedef struct
7575
{
7676
float u, v;
7777
SDL_Color col;
7878
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+
};
80112

81113
int SDL_PSP_RenderGetProp(SDL_Renderer *r, enum SDL_PSP_RenderProps which, void** out)
82114
{
@@ -171,6 +203,60 @@ static int calculateNextPow2(int value)
171203
return i;
172204
}
173205

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+
174260
static void PSP_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
175261
{
176262
}

0 commit comments

Comments
 (0)