21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_RENDER_PSP
26 #include "../SDL_sysrender.h"
28 #include <pspkernel.h>
29 #include <pspdisplay.h>
45 #define PSP_SCREEN_WIDTH 480
46 #define PSP_SCREEN_HEIGHT 272
48 #define PSP_FRAME_BUFFER_WIDTH 512
49 #define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT)
51 static unsigned int __attribute__((aligned(16))) DisplayList[262144];
54 #define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11))
55 #define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0))
56 #define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12))
57 #define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
70 unsigned int currentColor;
82 unsigned int textureWidth;
83 unsigned int textureHeight;
104 #define PI 3.14159265358979f
106 #define radToDeg(x) ((x)*180.f/PI)
107 #define degToRad(x) ((x)*PI/180.f)
109 float MathAbs(
float x)
115 "vabs.s S000, S000\n"
122 void MathSincos(
float r,
float *
s,
float *
c)
126 "vcst.s S003, VFPU_2_PI\n"
127 "vmul.s S002, S002, S003\n"
128 "vrot.p C000, S002, [s, c]\n"
131 :
"=r"(*s),
"=r"(*c):
"r"(
r));
134 void Swap(
float *
a,
float *
b)
143 TextureNextPow2(
unsigned int w)
178 if(
data->displayListAvail)
181 sceGuStart(GU_DIRECT, DisplayList);
187 TextureSwizzle(PSP_TextureData *psp_texture)
189 if(psp_texture->swizzled)
192 int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
193 int height = psp_texture->size / bytewidth;
195 int rowblocks = (bytewidth>>4);
196 int rowblocksadd = (rowblocks-1)<<7;
197 unsigned int blockaddress = 0;
198 unsigned int *
src = (
unsigned int*) psp_texture->data;
205 for(
j = 0;
j <
height;
j++, blockaddress += 16)
209 block = (
unsigned int*)&
data[blockaddress];
213 for(
i = 0;
i < rowblocks;
i++)
223 blockaddress += rowblocksadd;
226 free(psp_texture->data);
227 psp_texture->data =
data;
232 int TextureUnswizzle(PSP_TextureData *psp_texture)
234 if(!psp_texture->swizzled)
239 int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
240 int height = psp_texture->size / bytewidth;
242 int widthblocks = bytewidth/16;
243 int heightblocks =
height/8;
245 int dstpitch = (bytewidth - 16)/4;
246 int dstrow = bytewidth * 8;
248 unsigned int *
src = (
unsigned int*) psp_texture->data;
257 sceKernelDcacheWritebackAll();
261 unsigned char *ydst = (
unsigned char *)
data;
263 for(blocky = 0; blocky < heightblocks; ++blocky)
265 unsigned char *xdst = ydst;
267 for(blockx = 0; blockx < widthblocks; ++blockx)
271 block = (
unsigned int*)xdst;
273 for(
j = 0;
j < 8; ++
j)
275 *(block++) = *(
src++);
276 *(block++) = *(
src++);
277 *(block++) = *(
src++);
278 *(block++) = *(
src++);
288 free(psp_texture->data);
290 psp_texture->data =
data;
307 PSP_TextureData* psp_texture = (PSP_TextureData*)
SDL_calloc(1,
sizeof(*psp_texture));
313 psp_texture->width =
texture->w;
314 psp_texture->height =
texture->h;
315 psp_texture->textureHeight = TextureNextPow2(
texture->h);
316 psp_texture->textureWidth = TextureNextPow2(
texture->w);
317 psp_texture->format = PixelFormatToPSPFMT(
texture->format);
319 switch(psp_texture->format)
324 psp_texture->bits = 16;
328 psp_texture->bits = 32;
336 psp_texture->size = psp_texture->textureHeight*psp_texture->pitch;
337 psp_texture->data =
SDL_calloc(1, psp_texture->size);
339 if(!psp_texture->data)
344 texture->driverdata = psp_texture;
358 PSP_TextureData *psp_texture = (PSP_TextureData *)
texture->driverdata;
364 TextureSwizzle(psp_texture);
367 sceGuEnable(GU_TEXTURE_2D);
368 sceGuTexWrap(GU_REPEAT, GU_REPEAT);
369 sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled);
370 sceGuTexFilter(scaleMode, scaleMode);
372 sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data);
373 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
399 sceKernelDcacheWritebackAll();
407 PSP_TextureData *psp_texture = (PSP_TextureData *)
texture->driverdata;
410 (
void *) ((
Uint8 *) psp_texture->data +
rect->
y * psp_texture->pitch +
412 *pitch = psp_texture->pitch;
419 PSP_TextureData *psp_texture = (PSP_TextureData *)
texture->driverdata;
501 const float x = dstrect->
x;
502 const float y = dstrect->
y;
503 const float width = dstrect->
w;
504 const float height = dstrect->
h;
506 const float u0 = srcrect->
x;
507 const float v0 = srcrect->
y;
508 const float u1 = srcrect->
x + srcrect->
w;
509 const float v1 = srcrect->
y + srcrect->
h;
511 if((MathAbs(
u1) - MathAbs(u0)) < 64.0f)
539 const float endX =
x +
width;
540 const float slice = 64.0f;
543 float ustep = (
u1 - u0)/
width * slice;
558 const float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice;
559 const float sourceWidth = ((curU + ustep) >
u1) ? (
u1 - curU) : ustep;
589 const float centerx = center->
x;
590 const float centery = center->
y;
591 const float x = dstrect->
x + centerx;
592 const float y = dstrect->
y + centery;
593 const float width = dstrect->
w - centerx;
594 const float height = dstrect->
h - centery;
597 float u0 = srcrect->
x;
598 float v0 = srcrect->
y;
599 float u1 = srcrect->
x + srcrect->
w;
600 float v1 = srcrect->
y + srcrect->
h;
609 MathSincos(degToRad(
angle), &
s, &
c);
611 const float cw =
c *
width;
612 const float sw =
s *
width;
626 verts->x =
x - cw + sh;
627 verts->y =
y - sw - ch;
633 verts->x =
x - cw - sh;
634 verts->y =
y - sw + ch;
640 verts->x =
x + cw - sh;
641 verts->y =
y + sw + ch;
647 verts->x =
x + cw + sh;
648 verts->y =
y + sw - ch;
662 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
663 sceGuDisable(GU_BLEND);
666 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
667 sceGuEnable(GU_BLEND);
668 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
671 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
672 sceGuEnable(GU_BLEND);
673 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
676 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
677 sceGuEnable(GU_BLEND);
678 sceGuBlendFunc(GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
681 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
682 sceGuEnable(GU_BLEND);
683 sceGuBlendFunc(GU_ADD, GU_DST_COLOR, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
704 Uint8 *gpumem = (
Uint8 *) sceGuGetMemory(vertsize);
706 return SDL_SetError(
"Couldn't obtain a %d-byte vertex buffer!", (
int) vertsize);
745 sceGuClearColor(
color);
747 sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
753 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.first);
761 sceGuDisable(GU_TEXTURE_2D);
762 sceGuShadeModel(GU_FLAT);
763 sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D,
count, 0, verts);
764 sceGuShadeModel(GU_SMOOTH);
765 sceGuEnable(GU_TEXTURE_2D);
771 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.first);
779 sceGuDisable(GU_TEXTURE_2D);
780 sceGuShadeModel(GU_FLAT);
781 sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D,
count, 0, verts);
782 sceGuShadeModel(GU_SMOOTH);
783 sceGuEnable(GU_TEXTURE_2D);
789 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.first);
797 sceGuDisable(GU_TEXTURE_2D);
798 sceGuShadeModel(GU_FLAT);
799 sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2 *
count, 0, verts);
800 sceGuShadeModel(GU_SMOOTH);
801 sceGuEnable(GU_TEXTURE_2D);
807 const VertTV *verts = (VertTV *) (gpumem + cmd->
data.
draw.first);
809 TextureActivate(cmd->
data.
draw.texture);
813 sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
814 sceGuColor(GU_RGBA(255, 255, 255,
alpha));
816 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
817 sceGuColor(0xFFFFFFFF);
820 sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2 *
count, 0, verts);
823 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
829 const VertTV *verts = (VertTV *) (gpumem + cmd->
data.
draw.first);
831 TextureActivate(cmd->
data.
draw.texture);
835 sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
836 sceGuColor(GU_RGBA(255, 255, 255,
alpha));
838 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
839 sceGuColor(0xFFFFFFFF);
842 sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, verts);
845 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
871 if(!
data->displayListAvail)
879 sceDisplayWaitVblankStart();
881 data->backbuffer =
data->frontbuffer;
882 data->frontbuffer = vabsptr(sceGuSwapBuffers());
890 PSP_TextureData *psp_texture = (PSP_TextureData *)
texture->driverdata;
908 if (!
data->initialized)
929 PSP_RenderData *
data;
947 renderer->SetTextureColorMod = PSP_SetTextureColorMod;
986 data->frontbuffer = (
unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1);
987 data->backbuffer = (
unsigned int *)(0);
989 data->psm = pixelformat;
992 data->frontbuffer = (
unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2);
993 data->backbuffer = (
unsigned int *)(0);
995 data->psm = GU_PSM_8888;
1001 sceGuStart(GU_DIRECT, DisplayList);
1002 sceGuDrawBuffer(
data->psm,
data->frontbuffer, PSP_FRAME_BUFFER_WIDTH);
1003 sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT,
data->backbuffer, PSP_FRAME_BUFFER_WIDTH);
1006 sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1));
1007 sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
1009 data->frontbuffer = vabsptr(
data->frontbuffer);
1010 data->backbuffer = vabsptr(
data->backbuffer);
1013 sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
1014 sceGuEnable(GU_SCISSOR_TEST);
1017 sceGuFrontFace(GU_CCW);
1018 sceGuEnable(GU_CULL_FACE);
1021 sceGuEnable(GU_TEXTURE_2D);
1022 sceGuShadeModel(GU_SMOOTH);
1023 sceGuTexWrap(GU_REPEAT, GU_REPEAT);
1026 sceGuEnable(GU_BLEND);
1027 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
1029 sceGuTexFilter(GU_LINEAR,GU_LINEAR);
1033 sceDisplayWaitVblankStartCB();
1034 sceGuDisplay(GU_TRUE);
1044 .num_texture_formats = 4,
1050 .max_texture_width = 512,
1051 .max_texture_height = 512,
#define SDL_assert(condition)
#define SDL_GetWindowPixelFormat
#define SDL_OutOfMemory()
#define SDL_Unsupported()
int uint32_t uint32_t uint32_t pixel_format
GLint GLint GLint GLint GLint GLint y
GLuint GLuint GLsizei count
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLsizei width
GLdouble GLdouble GLdouble r
GLint GLint GLint GLint GLint x
GLint GLint GLsizei GLsizei height
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
GLboolean GLboolean GLboolean b
GLfixed GLfixed GLint GLint GLfixed points
GLboolean GLboolean GLboolean GLboolean a
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
GLenum GLenum GLuint texture
GLuint GLsizei GLsizei * length
GLfloat GLfloat GLfloat alpha
GLubyte GLubyte GLubyte GLubyte w
#define SDL_BYTESPERPIXEL(X)
@ SDL_PIXELFORMAT_ABGR4444
@ SDL_PIXELFORMAT_ABGR8888
@ SDL_PIXELFORMAT_ABGR1555
void * SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset)
@ SDL_RENDERER_ACCELERATED
@ SDL_RENDERER_PRESENTVSYNC
@ SDL_RENDERER_TARGETTEXTURE
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
SDL_ScaleMode
The scaling mode for a texture.
SDL_RenderDriver PSP_RenderDriver
@ SDL_RENDERCMD_SETCLIPRECT
@ SDL_RENDERCMD_DRAW_LINES
@ SDL_RENDERCMD_SETVIEWPORT
@ SDL_RENDERCMD_DRAW_POINTS
@ SDL_RENDERCMD_FILL_RECTS
@ SDL_RENDERCMD_SETDRAWCOLOR
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)
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)
EGLSurface EGLNativeWindowType * window
EGLSurface EGLint * rects
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
The structure that defines a point (floating point)
A rectangle, with the origin at the upper left (floating point).
A rectangle, with the origin at the upper left (integer).
struct SDL_RenderCommand::@38::@42 color
struct SDL_RenderCommand * next
struct SDL_RenderCommand::@38::@39 viewport
struct SDL_RenderCommand::@38::@41 draw
SDL_RenderCommandType command
union SDL_RenderCommand::@38 data
struct SDL_RenderCommand::@38::@40 cliprect
SDL_Renderer *(* CreateRenderer)(SDL_Window *window, Uint32 flags)
int(* QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
int(* QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
void(* SetTextureScaleMode)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
void(* DestroyRenderer)(SDL_Renderer *renderer)
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
void(* RenderPresent)(SDL_Renderer *renderer)
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
int(* QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
int(* QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count)
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
int(* RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
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)
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
int(* QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
Window state change event data (event.window.*)
The type used to identify a window.
static SDL_Renderer * renderer
static SDL_BlendMode blendMode