21#include "../../SDL_internal.h"
23#if SDL_VIDEO_RENDER_PSP
27#include "../SDL_sysrender.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)
52static 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)
110float MathAbs(
float x)
116 "vabs.s S000, S000\n"
123void 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));
135void Swap(
float *
a,
float *
b)
144TextureNextPow2(
unsigned int w)
179 if(
data->displayListAvail)
182 sceGuStart(GU_DIRECT, DisplayList);
188TextureSwizzle(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;
233int 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)
345 texture->driverdata = psp_texture;
359 PSP_TextureData *psp_texture = (PSP_TextureData *)
texture->driverdata;
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);
400 sceKernelDcacheWritebackAll();
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;
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.0f)
534 const float endX =
x +
width;
535 const float slice = 64.0f;
538 float ustep = (
u1 - u0)/
width * 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;
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;
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);
694 Uint8 *gpumem = (
Uint8 *) sceGuGetMemory(vertsize);
696 return SDL_SetError(
"Couldn't obtain a %d-byte vertex buffer!", (
int) vertsize);
735 sceGuClearColor(
color);
737 sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
743 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.
first);
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);
761 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.
first);
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);
779 const VertV *verts = (VertV *) (gpumem + cmd->
data.
draw.
first);
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);
797 const VertTV *verts = (VertTV *) (gpumem + cmd->
data.
draw.
first);
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);
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);
861 if(!
data->displayListAvail)
869 sceDisplayWaitVblankStart();
871 data->backbuffer =
data->frontbuffer;
872 data->frontbuffer = vabsptr(sceGuSwapBuffers());
880 PSP_TextureData *psp_texture = (PSP_TextureData *)
texture->driverdata;
898 if (!
data->initialized)
919 PSP_RenderData *
data;
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,
#define SDL_assert(condition)
#define SDL_GetWindowPixelFormat
#define SDL_OutOfMemory()
#define SDL_Unsupported()
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_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 int in j)
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)
EGLSurface EGLNativeWindowType * window
EGLSurface EGLint * rects
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).
union SDL_RenderCommand::@30 data
struct SDL_RenderCommand * next
struct SDL_RenderCommand::@30::@33 draw
struct SDL_RenderCommand::@30::@31 viewport
SDL_RenderCommandType command
struct SDL_RenderCommand::@30::@32 cliprect
struct SDL_RenderCommand::@30::@34 color
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(* 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