21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_RENDER_PSP 27 #include "../SDL_sysrender.h" 29 #include <pspkernel.h> 30 #include <pspdisplay.h> 46 #define PSP_SCREEN_WIDTH 480 47 #define PSP_SCREEN_HEIGHT 272 49 #define PSP_FRAME_BUFFER_WIDTH 512 50 #define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT) 52 static unsigned int __attribute__((aligned(16))) DisplayList[262144];
55 #define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11)) 56 #define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0)) 57 #define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12)) 58 #define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24)) 71 unsigned int currentColor;
83 unsigned int textureWidth;
84 unsigned int textureHeight;
105 #define PI 3.14159265358979f 107 #define radToDeg(x) ((x)*180.f/PI) 108 #define degToRad(x) ((x)*PI/180.f) 110 float MathAbs(
float x)
116 "vabs.s S000, S000\n" 123 void MathSincos(
float r,
float *
s,
float *
c)
127 "vcst.s S003, VFPU_2_PI\n" 128 "vmul.s S002, S002, S003\n" 129 "vrot.p C000, S002, [s, c]\n" 132 :
"=r"(*s),
"=r"(*c):
"r"(
r));
135 void Swap(
float *
a,
float *
b)
144 TextureNextPow2(
unsigned int w)
179 if(data->displayListAvail)
182 sceGuStart(GU_DIRECT, DisplayList);
188 TextureSwizzle(PSP_TextureData *psp_texture)
190 if(psp_texture->swizzled)
193 int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
194 int height = psp_texture->size / bytewidth;
196 int rowblocks = (bytewidth>>4);
197 int rowblocksadd = (rowblocks-1)<<7;
198 unsigned int blockaddress = 0;
199 unsigned int *
src = (
unsigned int*) psp_texture->data;
206 for(j = 0; j <
height; j++, blockaddress += 16)
210 block = (
unsigned int*)&
data[blockaddress];
214 for(i = 0; i < rowblocks; i++)
224 blockaddress += rowblocksadd;
227 free(psp_texture->data);
228 psp_texture->data =
data;
233 int TextureUnswizzle(PSP_TextureData *psp_texture)
235 if(!psp_texture->swizzled)
240 int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
241 int height = psp_texture->size / bytewidth;
243 int widthblocks = bytewidth/16;
244 int heightblocks = height/8;
246 int dstpitch = (bytewidth - 16)/4;
247 int dstrow = bytewidth * 8;
249 unsigned int *src = (
unsigned int*) psp_texture->data;
258 sceKernelDcacheWritebackAll();
262 unsigned char *ydst = (
unsigned char *)
data;
264 for(blocky = 0; blocky < heightblocks; ++blocky)
266 unsigned char *xdst = ydst;
268 for(blockx = 0; blockx < widthblocks; ++blockx)
272 block = (
unsigned int*)xdst;
274 for(j = 0; j < 8; ++
j)
276 *(block++) = *(src++);
277 *(block++) = *(src++);
278 *(block++) = *(src++);
279 *(block++) = *(src++);
289 free(psp_texture->data);
291 psp_texture->data =
data;
308 PSP_TextureData* psp_texture = (PSP_TextureData*)
SDL_calloc(1,
sizeof(*psp_texture));
314 psp_texture->width = texture->
w;
315 psp_texture->height = texture->
h;
316 psp_texture->textureHeight = TextureNextPow2(texture->
h);
317 psp_texture->textureWidth = TextureNextPow2(texture->
w);
318 psp_texture->format = PixelFormatToPSPFMT(texture->
format);
320 switch(psp_texture->format)
325 psp_texture->bits = 16;
329 psp_texture->bits = 32;
337 psp_texture->size = psp_texture->textureHeight*psp_texture->pitch;
338 psp_texture->data =
SDL_calloc(1, psp_texture->size);
340 if(!psp_texture->data)
359 PSP_TextureData *psp_texture = (PSP_TextureData *) texture->
driverdata;
363 if (texture->
w >= 16 || texture->
h >= 16)
365 TextureSwizzle(psp_texture);
368 sceGuEnable(GU_TEXTURE_2D);
369 sceGuTexWrap(GU_REPEAT, GU_REPEAT);
370 sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled);
371 sceGuTexFilter(scaleMode, scaleMode);
373 sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data);
374 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
388 PSP_LockTexture(renderer, texture,rect,(
void **)&dst, &dpitch);
390 if (length == pitch && length == dpitch) {
393 for (row = 0; row < rect->
h; ++
row) {
400 sceKernelDcacheWritebackAll();
406 const SDL_Rect * rect,
void **pixels,
int *pitch)
408 PSP_TextureData *psp_texture = (PSP_TextureData *) texture->
driverdata;
411 (
void *) ((
Uint8 *) psp_texture->data + rect->
y * psp_texture->pitch +
413 *pitch = psp_texture->pitch;
420 PSP_TextureData *psp_texture = (PSP_TextureData *) texture->
driverdata;
428 PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch);
455 for (i = 0; i <
count; i++, verts++, points++) {
456 verts->x = points->
x;
457 verts->y = points->
y;
475 for (i = 0; i <
count; i++, rects++) {
482 verts->x = rect->
x + rect->
w;
483 verts->y = rect->
y + rect->
h;
496 const float x = dstrect->
x;
497 const float y = dstrect->
y;
498 const float width = dstrect->
w;
499 const float height = dstrect->
h;
501 const float u0 = srcrect->
x;
502 const float v0 = srcrect->
y;
503 const float u1 = srcrect->
x + srcrect->
w;
504 const float v1 = srcrect->
y + srcrect->
h;
506 if((MathAbs(u1) - MathAbs(u0)) < 64.0
f)
524 verts->x = x +
width;
534 const float endX = x +
width;
535 const float slice = 64.0f;
536 const size_t count =
SDL_ceilf(width / slice);
538 float ustep = (u1 - u0)/width * slice;
551 for(i = 0, start = 0, end = width; i <
count; i++, start += slice)
553 const float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice;
554 const float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep;
584 const float centerx = center->
x;
585 const float centery = center->
y;
586 const float x = dstrect->
x + centerx;
587 const float y = dstrect->
y + centery;
588 const float width = dstrect->
w - centerx;
589 const float height = dstrect->
h - centery;
592 float u0 = srcrect->
x;
593 float v0 = srcrect->
y;
594 float u1 = srcrect->
x + srcrect->
w;
595 float v1 = srcrect->
y + srcrect->
h;
604 MathSincos(degToRad(angle), &s, &c);
606 const float cw = c *
width;
607 const float sw = s *
width;
608 const float ch = c *
height;
609 const float sh = s *
height;
621 verts->x = x - cw + sh;
622 verts->y = y - sw - ch;
628 verts->x = x - cw - sh;
629 verts->y = y - sw + ch;
635 verts->x = x + cw - sh;
636 verts->y = y + sw + ch;
642 verts->x = x + cw + sh;
643 verts->y = y + sw - ch;
654 if (blendMode != data-> currentBlendMode) {
657 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
658 sceGuDisable(GU_BLEND);
661 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
662 sceGuEnable(GU_BLEND);
663 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
666 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
667 sceGuEnable(GU_BLEND);
668 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
671 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
672 sceGuEnable(GU_BLEND);
673 sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
683 PSP_RenderData *data = (PSP_RenderData *) renderer->
driverdata;
686 StartDrawing(renderer);
694 Uint8 *gpumem = (
Uint8 *) sceGuGetMemory(vertsize);
696 return SDL_SetError(
"Couldn't obtain a %d-byte vertex buffer!", (
int) vertsize);
710 data->drawstate.viewport_dirty =
SDL_TRUE;
717 if (data->drawstate.cliprect_enabled != cmd->
data.
cliprect.enabled) {
718 data->drawstate.cliprect_enabled = cmd->
data.
cliprect.enabled;
719 data->drawstate.cliprect_enabled_dirty =
SDL_TRUE;
723 data->drawstate.cliprect_dirty =
SDL_TRUE;
733 const Uint32 color = ((a << 24) | (b << 16) | (g << 8) | r);
735 sceGuClearColor(color);
737 sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
742 const size_t count = cmd->
data.
draw.count;
743 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.first);
748 const Uint32 color = ((a << 24) | (b << 16) | (g << 8) | r);
751 sceGuDisable(GU_TEXTURE_2D);
752 sceGuShadeModel(GU_FLAT);
753 sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, verts);
754 sceGuShadeModel(GU_SMOOTH);
755 sceGuEnable(GU_TEXTURE_2D);
760 const size_t count = cmd->
data.
draw.count;
761 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.first);
766 const Uint32 color = ((a << 24) | (b << 16) | (g << 8) | r);
769 sceGuDisable(GU_TEXTURE_2D);
770 sceGuShadeModel(GU_FLAT);
771 sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, verts);
772 sceGuShadeModel(GU_SMOOTH);
773 sceGuEnable(GU_TEXTURE_2D);
778 const size_t count = cmd->
data.
draw.count;
779 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.first);
784 const Uint32 color = ((a << 24) | (b << 16) | (g << 8) | r);
787 sceGuDisable(GU_TEXTURE_2D);
788 sceGuShadeModel(GU_FLAT);
789 sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2 * count, 0, verts);
790 sceGuShadeModel(GU_SMOOTH);
791 sceGuEnable(GU_TEXTURE_2D);
796 const size_t count = cmd->
data.
draw.count;
797 const VertTV *verts = (VertTV *) (gpumem + cmd->
data.
draw.first);
799 TextureActivate(cmd->
data.
draw.texture);
800 PSP_SetBlendMode(renderer, cmd->
data.
draw.blend);
803 sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
804 sceGuColor(GU_RGBA(255, 255, 255, alpha));
806 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
807 sceGuColor(0xFFFFFFFF);
810 sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2 * count, 0, verts);
813 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
819 const VertTV *verts = (VertTV *) (gpumem + cmd->
data.
draw.first);
821 TextureActivate(cmd->
data.
draw.texture);
822 PSP_SetBlendMode(renderer, cmd->
data.
draw.blend);
825 sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
826 sceGuColor(GU_RGBA(255, 255, 255, alpha));
828 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
829 sceGuColor(0xFFFFFFFF);
832 sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, verts);
835 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
852 Uint32 pixel_format,
void * pixels,
int pitch)
860 PSP_RenderData *data = (PSP_RenderData *) renderer->
driverdata;
861 if(!data->displayListAvail)
869 sceDisplayWaitVblankStart();
871 data->backbuffer = data->frontbuffer;
872 data->frontbuffer = vabsptr(sceGuSwapBuffers());
879 PSP_RenderData *renderdata = (PSP_RenderData *) renderer->
driverdata;
880 PSP_TextureData *psp_texture = (PSP_TextureData *) texture->
driverdata;
896 PSP_RenderData *data = (PSP_RenderData *) renderer->
driverdata;
898 if (!data->initialized)
901 StartDrawing(renderer);
919 PSP_RenderData *
data;
927 data = (PSP_RenderData *)
SDL_calloc(1,
sizeof(*data));
929 PSP_DestroyRenderer(renderer);
937 renderer->SetTextureColorMod = PSP_SetTextureColorMod;
975 data->frontbuffer = (
unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1);
976 data->backbuffer = (
unsigned int *)(0);
978 data->psm = pixelformat;
981 data->frontbuffer = (
unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2);
982 data->backbuffer = (
unsigned int *)(0);
984 data->psm = GU_PSM_8888;
990 sceGuStart(GU_DIRECT, DisplayList);
991 sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH);
992 sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH);
995 sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1));
996 sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
998 data->frontbuffer = vabsptr(data->frontbuffer);
999 data->backbuffer = vabsptr(data->backbuffer);
1002 sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
1003 sceGuEnable(GU_SCISSOR_TEST);
1006 sceGuFrontFace(GU_CCW);
1007 sceGuEnable(GU_CULL_FACE);
1010 sceGuEnable(GU_TEXTURE_2D);
1011 sceGuShadeModel(GU_SMOOTH);
1012 sceGuTexWrap(GU_REPEAT, GU_REPEAT);
1015 sceGuEnable(GU_BLEND);
1016 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
1018 sceGuTexFilter(GU_LINEAR,GU_LINEAR);
1022 sceDisplayWaitVblankStartCB();
1023 sceGuDisplay(GU_TRUE);
1033 .num_texture_formats = 4,
1039 .max_texture_width = 512,
1040 .max_texture_height = 512,
GLdouble GLdouble GLdouble r
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
struct SDL_RenderCommand::@30::@31 viewport
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
GLint GLint GLint GLint GLint x
struct SDL_RenderCommand::@30::@32 cliprect
GLuint GLuint GLsizei count
void * SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset)
struct SDL_RenderCommand::@30::@34 color
int(* QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
SDL_RenderDriver PSP_RenderDriver
int(* QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
#define SDL_BYTESPERPIXEL(X)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
GLfloat GLfloat GLfloat alpha
void(* DestroyRenderer)(SDL_Renderer *renderer)
GLint GLint GLsizei width
GLfixed GLfixed GLint GLint GLfixed points
static SDL_BlendMode blendMode
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
int(* QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
GLenum GLenum GLuint texture
struct SDL_RenderCommand::@30::@33 draw
static SDL_Renderer * renderer
int(* QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
GLubyte GLubyte GLubyte GLubyte w
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_Renderer *(* CreateRenderer)(SDL_Window *window, Uint32 flags)
GLint GLint GLint GLint GLint GLint y
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
int(* QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
int(* RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Window state change event data (event.window.*)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
GLint GLint GLsizei GLsizei height
int(* QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
EGLSurface EGLNativeWindowType * window
SDL_RenderCommandType command
The type used to identify a window.
union SDL_RenderCommand::@30 data
#define SDL_GetWindowPixelFormat
int(* QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count)
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
void(* RenderPresent)(SDL_Renderer *renderer)
EGLSurface EGLint * rects
GLuint GLsizei GLsizei * length
struct SDL_RenderCommand * next
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b
#define SDL_Unsupported()
A rectangle, with the origin at the upper left (floating point).
The structure that defines a point (floating point)
A rectangle, with the origin at the upper left (integer).