2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_RENDER_PSP
25 #include "SDL_hints.h"
26 #include "../SDL_sysrender.h"
28 #include <pspkernel.h>
29 #include <pspdisplay.h>
43 /* PSP renderer implementation, based on the PGE */
46 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
49 static SDL_Renderer *PSP_CreateRenderer(SDL_Window * window, Uint32 flags);
50 static void PSP_WindowEvent(SDL_Renderer * renderer,
51 const SDL_WindowEvent *event);
52 static int PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
53 static int PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
54 const SDL_Rect * rect, const void *pixels,
56 static int PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
57 const SDL_Rect * rect, void **pixels, int *pitch);
58 static void PSP_UnlockTexture(SDL_Renderer * renderer,
59 SDL_Texture * texture);
60 static int PSP_SetRenderTarget(SDL_Renderer * renderer,
61 SDL_Texture * texture);
62 static int PSP_UpdateViewport(SDL_Renderer * renderer);
63 static int PSP_RenderClear(SDL_Renderer * renderer);
64 static int PSP_RenderDrawPoints(SDL_Renderer * renderer,
65 const SDL_FPoint * points, int count);
66 static int PSP_RenderDrawLines(SDL_Renderer * renderer,
67 const SDL_FPoint * points, int count);
68 static int PSP_RenderFillRects(SDL_Renderer * renderer,
69 const SDL_FRect * rects, int count);
70 static int PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
71 const SDL_Rect * srcrect,
72 const SDL_FRect * dstrect);
73 static int PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
74 Uint32 pixel_format, void * pixels, int pitch);
75 static int PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
76 const SDL_Rect * srcrect, const SDL_FRect * dstrect,
77 const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
78 static void PSP_RenderPresent(SDL_Renderer * renderer);
79 static void PSP_DestroyTexture(SDL_Renderer * renderer,
80 SDL_Texture * texture);
81 static void PSP_DestroyRenderer(SDL_Renderer * renderer);
84 SDL_RenderDriver PSP_RenderDriver = {
88 (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
90 {SDL_PIXELFORMAT_ABGR8888},
95 SDL_RenderDriver PSP_RenderDriver = {
96 .CreateRenderer = PSP_CreateRenderer,
99 .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE,
100 .num_texture_formats = 4,
101 .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565,
102 [1] = SDL_PIXELFORMAT_ABGR1555,
103 [2] = SDL_PIXELFORMAT_ABGR4444,
104 [3] = SDL_PIXELFORMAT_ABGR8888,
106 .max_texture_width = 512,
107 .max_texture_height = 512,
111 #define PSP_SCREEN_WIDTH 480
112 #define PSP_SCREEN_HEIGHT 272
114 #define PSP_FRAME_BUFFER_WIDTH 512
115 #define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT)
117 static unsigned int __attribute__((aligned(16))) DisplayList[262144];
120 #define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11))
121 #define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0))
122 #define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12))
123 #define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
130 SDL_bool initialized ;
131 SDL_bool displayListAvail ;
136 unsigned int currentColor;
137 int currentBlendMode;
144 void *data; /**< Image data. */
145 unsigned int size; /**< Size of data in bytes. */
146 unsigned int width; /**< Image width. */
147 unsigned int height; /**< Image height. */
148 unsigned int textureWidth; /**< Texture width (power of two). */
149 unsigned int textureHeight; /**< Texture height (power of two). */
150 unsigned int bits; /**< Image bits per pixel. */
151 unsigned int format; /**< Image format - one of ::pgePixelFormat. */
153 SDL_bool swizzled; /**< Is image swizzled. */
171 /* Return next power of 2 */
173 TextureNextPow2(unsigned int w)
188 GetScaleQuality(void)
190 const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
192 if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
193 return GU_NEAREST; /* GU_NEAREST good for tile-map */
195 return GU_LINEAR; /* GU_LINEAR good for scaling */
200 PixelFormatToPSPFMT(Uint32 format)
203 case SDL_PIXELFORMAT_BGR565:
205 case SDL_PIXELFORMAT_ABGR1555:
207 case SDL_PIXELFORMAT_ABGR4444:
209 case SDL_PIXELFORMAT_ABGR8888:
217 StartDrawing(SDL_Renderer * renderer)
219 PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
220 if(data->displayListAvail)
223 sceGuStart(GU_DIRECT, DisplayList);
224 data->displayListAvail = SDL_TRUE;
229 TextureSwizzle(PSP_TextureData *psp_texture)
231 if(psp_texture->swizzled)
234 int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
235 int height = psp_texture->size / bytewidth;
237 int rowblocks = (bytewidth>>4);
238 int rowblocksadd = (rowblocks-1)<<7;
239 unsigned int blockaddress = 0;
240 unsigned int *src = (unsigned int*) psp_texture->data;
242 unsigned char *data = NULL;
243 data = malloc(psp_texture->size);
247 for(j = 0; j < height; j++, blockaddress += 16)
251 block = (unsigned int*)&data[blockaddress];
255 for(i = 0; i < rowblocks; i++)
265 blockaddress += rowblocksadd;
268 free(psp_texture->data);
269 psp_texture->data = data;
270 psp_texture->swizzled = SDL_TRUE;
274 int TextureUnswizzle(PSP_TextureData *psp_texture)
276 if(!psp_texture->swizzled)
281 int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
282 int height = psp_texture->size / bytewidth;
284 int widthblocks = bytewidth/16;
285 int heightblocks = height/8;
287 int dstpitch = (bytewidth - 16)/4;
288 int dstrow = bytewidth * 8;
290 unsigned int *src = (unsigned int*) psp_texture->data;
292 unsigned char *data = NULL;
294 data = malloc(psp_texture->size);
299 sceKernelDcacheWritebackAll();
303 unsigned char *ydst = (unsigned char *)data;
305 for(blocky = 0; blocky < heightblocks; ++blocky)
307 unsigned char *xdst = ydst;
309 for(blockx = 0; blockx < widthblocks; ++blockx)
313 block = (unsigned int*)xdst;
315 for(j = 0; j < 8; ++j)
317 *(block++) = *(src++);
318 *(block++) = *(src++);
319 *(block++) = *(src++);
320 *(block++) = *(src++);
330 free(psp_texture->data);
332 psp_texture->data = data;
334 psp_texture->swizzled = SDL_FALSE;
340 PSP_CreateRenderer(SDL_Window * window, Uint32 flags)
343 SDL_Renderer *renderer;
344 PSP_RenderData *data;
346 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
352 data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data));
354 PSP_DestroyRenderer(renderer);
360 renderer->WindowEvent = PSP_WindowEvent;
361 renderer->CreateTexture = PSP_CreateTexture;
362 renderer->UpdateTexture = PSP_UpdateTexture;
363 renderer->LockTexture = PSP_LockTexture;
364 renderer->UnlockTexture = PSP_UnlockTexture;
365 renderer->SetRenderTarget = PSP_SetRenderTarget;
366 renderer->UpdateViewport = PSP_UpdateViewport;
367 renderer->RenderClear = PSP_RenderClear;
368 renderer->RenderDrawPoints = PSP_RenderDrawPoints;
369 renderer->RenderDrawLines = PSP_RenderDrawLines;
370 renderer->RenderFillRects = PSP_RenderFillRects;
371 renderer->RenderCopy = PSP_RenderCopy;
372 renderer->RenderReadPixels = PSP_RenderReadPixels;
373 renderer->RenderCopyEx = PSP_RenderCopyEx;
374 renderer->RenderPresent = PSP_RenderPresent;
375 renderer->DestroyTexture = PSP_DestroyTexture;
376 renderer->DestroyRenderer = PSP_DestroyRenderer;
377 renderer->info = PSP_RenderDriver.info;
378 renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
379 renderer->driverdata = data;
380 renderer->window = window;
382 if (data->initialized != SDL_FALSE)
384 data->initialized = SDL_TRUE;
386 if (flags & SDL_RENDERER_PRESENTVSYNC) {
387 data->vsync = SDL_TRUE;
389 data->vsync = SDL_FALSE;
392 pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window));
398 data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1);
399 data->backbuffer = (unsigned int *)(0);
401 data->psm = pixelformat;
404 data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2);
405 data->backbuffer = (unsigned int *)(0);
407 data->psm = GU_PSM_8888;
413 sceGuStart(GU_DIRECT, DisplayList);
414 sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH);
415 sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH);
418 sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1));
419 sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
421 data->frontbuffer = vabsptr(data->frontbuffer);
422 data->backbuffer = vabsptr(data->backbuffer);
425 sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
426 sceGuEnable(GU_SCISSOR_TEST);
428 /* Backface culling */
429 sceGuFrontFace(GU_CCW);
430 sceGuEnable(GU_CULL_FACE);
433 sceGuEnable(GU_TEXTURE_2D);
434 sceGuShadeModel(GU_SMOOTH);
435 sceGuTexWrap(GU_REPEAT, GU_REPEAT);
438 sceGuEnable(GU_BLEND);
439 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
441 sceGuTexFilter(GU_LINEAR,GU_LINEAR);
445 sceDisplayWaitVblankStartCB();
446 sceGuDisplay(GU_TRUE);
452 PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
459 PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
461 /* PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; */
462 PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));
467 psp_texture->swizzled = SDL_FALSE;
468 psp_texture->width = texture->w;
469 psp_texture->height = texture->h;
470 psp_texture->textureHeight = TextureNextPow2(texture->h);
471 psp_texture->textureWidth = TextureNextPow2(texture->w);
472 psp_texture->format = PixelFormatToPSPFMT(texture->format);
474 switch(psp_texture->format)
479 psp_texture->bits = 16;
483 psp_texture->bits = 32;
490 psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format);
491 psp_texture->size = psp_texture->textureHeight*psp_texture->pitch;
492 psp_texture->data = SDL_calloc(1, psp_texture->size);
494 if(!psp_texture->data)
496 SDL_free(psp_texture);
497 return SDL_OutOfMemory();
499 texture->driverdata = psp_texture;
506 TextureActivate(SDL_Texture * texture)
508 PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
509 int scaleMode = GetScaleQuality();
511 /* Swizzling is useless with small textures. */
512 if (texture->w >= 16 || texture->h >= 16)
514 TextureSwizzle(psp_texture);
517 sceGuEnable(GU_TEXTURE_2D);
518 sceGuTexWrap(GU_REPEAT, GU_REPEAT);
519 sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled);
520 sceGuTexFilter(scaleMode, scaleMode); /* GU_NEAREST good for tile-map */
521 /* GU_LINEAR good for scaling */
522 sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data);
523 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
528 PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
529 const SDL_Rect * rect, const void *pixels, int pitch)
531 /* PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; */
534 int row, length,dpitch;
537 PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch);
538 length = rect->w * SDL_BYTESPERPIXEL(texture->format);
539 if (length == pitch && length == dpitch) {
540 SDL_memcpy(dst, src, length*rect->h);
542 for (row = 0; row < rect->h; ++row) {
543 SDL_memcpy(dst, src, length);
549 sceKernelDcacheWritebackAll();
554 PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
555 const SDL_Rect * rect, void **pixels, int *pitch)
557 PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
560 (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch +
561 rect->x * SDL_BYTESPERPIXEL(texture->format));
562 *pitch = psp_texture->pitch;
567 PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
569 PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
572 /* We do whole texture updates, at least for now */
577 PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch);
581 PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
588 PSP_UpdateViewport(SDL_Renderer * renderer)
596 PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode)
598 PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
599 if (blendMode != data-> currentBlendMode) {
601 case SDL_BLENDMODE_NONE:
602 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
603 sceGuDisable(GU_BLEND);
605 case SDL_BLENDMODE_BLEND:
606 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
607 sceGuEnable(GU_BLEND);
608 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
610 case SDL_BLENDMODE_ADD:
611 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
612 sceGuEnable(GU_BLEND);
613 sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
615 case SDL_BLENDMODE_MOD:
616 sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
617 sceGuEnable(GU_BLEND);
618 sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
621 data->currentBlendMode = blendMode;
628 PSP_RenderClear(SDL_Renderer * renderer)
631 StartDrawing(renderer);
632 int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
633 sceGuClearColor(color);
635 sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
641 PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
644 int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
646 StartDrawing(renderer);
647 VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
649 for (i = 0; i < count; ++i) {
650 vertices[i].x = points[i].x;
651 vertices[i].y = points[i].y;
652 vertices[i].z = 0.0f;
654 sceGuDisable(GU_TEXTURE_2D);
656 sceGuShadeModel(GU_FLAT);
657 sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
658 sceGuShadeModel(GU_SMOOTH);
659 sceGuEnable(GU_TEXTURE_2D);
665 PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
668 int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
670 StartDrawing(renderer);
671 VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
673 for (i = 0; i < count; ++i) {
674 vertices[i].x = points[i].x;
675 vertices[i].y = points[i].y;
676 vertices[i].z = 0.0f;
679 sceGuDisable(GU_TEXTURE_2D);
681 sceGuShadeModel(GU_FLAT);
682 sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
683 sceGuShadeModel(GU_SMOOTH);
684 sceGuEnable(GU_TEXTURE_2D);
690 PSP_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
693 int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
695 StartDrawing(renderer);
697 for (i = 0; i < count; ++i) {
698 const SDL_FRect *rect = &rects[i];
699 VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1));
700 vertices[0].x = rect->x;
701 vertices[0].y = rect->y;
702 vertices[0].z = 0.0f;
704 vertices[1].x = rect->x + rect->w;
705 vertices[1].y = rect->y + rect->h;
706 vertices[1].z = 0.0f;
708 sceGuDisable(GU_TEXTURE_2D);
710 sceGuShadeModel(GU_FLAT);
711 sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
712 sceGuShadeModel(GU_SMOOTH);
713 sceGuEnable(GU_TEXTURE_2D);
720 #define PI 3.14159265358979f
722 #define radToDeg(x) ((x)*180.f/PI)
723 #define degToRad(x) ((x)*PI/180.f)
725 float MathAbs(float x)
731 "vabs.s S000, S000\n"
733 : "=r"(result) : "r"(x));
738 void MathSincos(float r, float *s, float *c)
742 "vcst.s S003, VFPU_2_PI\n"
743 "vmul.s S002, S002, S003\n"
744 "vrot.p C000, S002, [s, c]\n"
747 : "=r"(*s), "=r"(*c): "r"(r));
750 void Swap(float *a, float *b)
758 PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
759 const SDL_Rect * srcrect, const SDL_FRect * dstrect)
761 float x, y, width, height;
762 float u0, v0, u1, v1;
772 u1 = srcrect->x + srcrect->w;
773 v1 = srcrect->y + srcrect->h;
777 StartDrawing(renderer);
778 TextureActivate(texture);
779 PSP_SetBlendMode(renderer, renderer->blendMode);
783 sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
784 sceGuColor(GU_RGBA(255, 255, 255, alpha));
786 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
787 sceGuColor(0xFFFFFFFF);
790 if((MathAbs(u1) - MathAbs(u0)) < 64.0f)
792 VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
802 vertices[1].x = x + width;
803 vertices[1].y = y + height;
806 sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
813 float endX = x + width;
815 float ustep = (u1 - u0)/width * slice;
820 for(start = 0, end = width; start < end; start += slice)
822 VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
824 float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice;
825 float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep;
827 vertices[0].u = curU;
829 vertices[0].x = curX;
836 vertices[1].u = curU;
838 vertices[1].x = curX;
839 vertices[1].y = (y + height);
842 sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
847 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
852 PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
853 Uint32 pixel_format, void * pixels, int pitch)
861 PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
862 const SDL_Rect * srcrect, const SDL_FRect * dstrect,
863 const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
865 float x, y, width, height;
866 float u0, v0, u1, v1;
868 float centerx, centery;
877 u1 = srcrect->x + srcrect->w;
878 v1 = srcrect->y + srcrect->h;
885 StartDrawing(renderer);
886 TextureActivate(texture);
887 PSP_SetBlendMode(renderer, renderer->blendMode);
891 sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
892 sceGuColor(GU_RGBA(255, 255, 255, alpha));
894 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
895 sceGuColor(0xFFFFFFFF);
898 /* x += width * 0.5f; */
899 /* y += height * 0.5f; */
905 MathSincos(degToRad(angle), &s, &c);
908 /* height *= 0.5f; */
918 VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2);
922 vertices[0].x = x - cw + sh;
923 vertices[0].y = y - sw - ch;
928 vertices[1].x = x - cw - sh;
929 vertices[1].y = y - sw + ch;
934 vertices[2].x = x + cw - sh;
935 vertices[2].y = y + sw + ch;
940 vertices[3].x = x + cw + sh;
941 vertices[3].y = y + sw - ch;
944 if (flip & SDL_FLIP_HORIZONTAL) {
945 Swap(&vertices[0].v, &vertices[2].v);
946 Swap(&vertices[1].v, &vertices[3].v);
948 if (flip & SDL_FLIP_VERTICAL) {
949 Swap(&vertices[0].u, &vertices[2].u);
950 Swap(&vertices[1].u, &vertices[3].u);
953 sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices);
956 sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
961 PSP_RenderPresent(SDL_Renderer * renderer)
963 PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
964 if(!data->displayListAvail)
967 data->displayListAvail = SDL_FALSE;
971 /* if(data->vsync) */
972 sceDisplayWaitVblankStart();
974 data->backbuffer = data->frontbuffer;
975 data->frontbuffer = vabsptr(sceGuSwapBuffers());
980 PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
982 PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
983 PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
991 SDL_free(psp_texture->data);
992 SDL_free(psp_texture);
993 texture->driverdata = NULL;
997 PSP_DestroyRenderer(SDL_Renderer * renderer)
999 PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
1001 if (!data->initialized)
1004 StartDrawing(renderer);
1007 /* vfree(data->backbuffer); */
1008 /* vfree(data->frontbuffer); */
1010 data->initialized = SDL_FALSE;
1011 data->displayListAvail = SDL_FALSE;
1017 #endif /* SDL_VIDEO_RENDER_PSP */
1019 /* vi: set ts=4 sw=4 expandtab: */