src/render/psp/SDL_render_psp.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 18 May 2013 14:17:52 -0700
changeset 7191 75360622e65f
parent 7096 640f553441e4
child 7663 53fe1b64eb2d
permissions -rw-r--r--
File style cleanup for the SDL 2.0 release
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     1
/*
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     2
  Simple DirectMedia Layer
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     4
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     7
  arising from the use of this software.
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     8
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    12
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    16
     appreciated but is not required.
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    18
     misrepresented as being the original software.
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    20
*/
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    21
#include "SDL_config.h"
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    22
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
    23
#if SDL_VIDEO_RENDER_PSP
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    24
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    25
#include "SDL_hints.h"
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    26
#include "../SDL_sysrender.h"
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    27
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    28
#include <pspkernel.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    29
#include <pspdisplay.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    30
#include <pspgu.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    31
#include <pspgum.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    32
#include <stdio.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    33
#include <string.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    34
#include <math.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    35
#include <pspge.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    36
#include <stdarg.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    37
#include <stdlib.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    38
#include <vram.h>
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    39
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    40
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    41
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    42
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    43
/* PSP renderer implementation, based on the PGE  */
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    44
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    45
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    46
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    47
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    48
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    49
static SDL_Renderer *PSP_CreateRenderer(SDL_Window * window, Uint32 flags);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    50
static void PSP_WindowEvent(SDL_Renderer * renderer,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    51
                             const SDL_WindowEvent *event);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    52
static int PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    53
static int PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    54
                              const SDL_Rect * rect, const void *pixels,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    55
                              int pitch);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    56
static int PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    57
                            const SDL_Rect * rect, void **pixels, int *pitch);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    58
static void PSP_UnlockTexture(SDL_Renderer * renderer,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    59
                               SDL_Texture * texture);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    60
static int PSP_SetRenderTarget(SDL_Renderer * renderer,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    61
                                 SDL_Texture * texture);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    62
static int PSP_UpdateViewport(SDL_Renderer * renderer);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    63
static int PSP_RenderClear(SDL_Renderer * renderer);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    64
static int PSP_RenderDrawPoints(SDL_Renderer * renderer,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    65
                                 const SDL_FPoint * points, int count);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    66
static int PSP_RenderDrawLines(SDL_Renderer * renderer,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    67
                                const SDL_FPoint * points, int count);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    68
static int PSP_RenderFillRects(SDL_Renderer * renderer,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    69
                                const SDL_FRect * rects, int count);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    70
static int PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    71
                           const SDL_Rect * srcrect,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    72
                           const SDL_FRect * dstrect);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    73
static int PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    74
                    Uint32 pixel_format, void * pixels, int pitch);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    75
static int PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    76
                         const SDL_Rect * srcrect, const SDL_FRect * dstrect,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    77
                         const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    78
static void PSP_RenderPresent(SDL_Renderer * renderer);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    79
static void PSP_DestroyTexture(SDL_Renderer * renderer,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    80
                                SDL_Texture * texture);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    81
static void PSP_DestroyRenderer(SDL_Renderer * renderer);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    82
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    83
/*
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    84
SDL_RenderDriver PSP_RenderDriver = {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    85
    PSP_CreateRenderer,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    86
    {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    87
     "PSP",
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    88
     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    89
     1,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    90
     {SDL_PIXELFORMAT_ABGR8888},
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    91
     0,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    92
     0}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    93
};
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    94
*/
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    95
SDL_RenderDriver PSP_RenderDriver = {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
    96
    .CreateRenderer = PSP_CreateRenderer,
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
    97
    .info = {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
    98
        .name = "PSP",
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
    99
        .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   100
        .num_texture_formats = 4,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   101
        .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   102
                                                 [1] = SDL_PIXELFORMAT_ABGR1555,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   103
                                                 [2] = SDL_PIXELFORMAT_ABGR4444,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   104
                                                 [3] = SDL_PIXELFORMAT_ABGR8888,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   105
        },
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   106
        .max_texture_width = 512,
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   107
        .max_texture_height = 512,
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   108
     }
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   109
};
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   110
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   111
#define PSP_SCREEN_WIDTH    480
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   112
#define PSP_SCREEN_HEIGHT   272
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   113
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   114
#define PSP_FRAME_BUFFER_WIDTH  512
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   115
#define PSP_FRAME_BUFFER_SIZE   (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT)
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   116
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   117
static unsigned int __attribute__((aligned(16))) DisplayList[262144];
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   118
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   119
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   120
#define COL5650(r,g,b,a)    ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11))
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   121
#define COL5551(r,g,b,a)    ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0))
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   122
#define COL4444(r,g,b,a)    ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12))
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   123
#define COL8888(r,g,b,a)    ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   124
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   125
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   126
typedef struct
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   127
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   128
    void*           frontbuffer ;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   129
    void*           backbuffer ;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   130
    SDL_bool        initialized ;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   131
    SDL_bool        displayListAvail ;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   132
    unsigned int    psm ;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   133
    unsigned int    bpp ;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   134
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   135
    SDL_bool        vsync;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   136
    unsigned int    currentColor;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   137
    int             currentBlendMode;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   138
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   139
} PSP_RenderData;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   140
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   141
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   142
typedef struct
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   143
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   144
    void                *data;                              /**< Image data. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   145
    unsigned int        size;                               /**< Size of data in bytes. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   146
    unsigned int        width;                              /**< Image width. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   147
    unsigned int        height;                             /**< Image height. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   148
    unsigned int        textureWidth;                       /**< Texture width (power of two). */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   149
    unsigned int        textureHeight;                      /**< Texture height (power of two). */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   150
    unsigned int        bits;                               /**< Image bits per pixel. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   151
    unsigned int        format;                             /**< Image format - one of ::pgePixelFormat. */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   152
    unsigned int        pitch;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   153
    SDL_bool            swizzled;                           /**< Is image swizzled. */
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   154
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   155
} PSP_TextureData;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   156
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   157
typedef struct
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   158
{
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   159
    float   x, y, z;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   160
} VertV;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   161
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   162
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   163
typedef struct
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   164
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   165
    float   u, v;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   166
    float   x, y, z;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   167
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   168
} VertTV;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   169
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   170
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   171
/* Return next power of 2 */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   172
static int
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   173
TextureNextPow2(unsigned int w)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   174
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   175
    if(w == 0)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   176
        return 0;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   177
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   178
    unsigned int n = 2;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   179
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   180
    while(w > n)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   181
        n <<= 1;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   182
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   183
    return n;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   184
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   185
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   186
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   187
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   188
GetScaleQuality(void)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   189
{
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   190
    const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   191
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   192
    if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   193
        return GU_NEAREST; /* GU_NEAREST good for tile-map */
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   194
    } else {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   195
        return GU_LINEAR; /* GU_LINEAR good for scaling */
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   196
    }
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   197
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   198
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   199
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   200
PixelFormatToPSPFMT(Uint32 format)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   201
{
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   202
    switch (format) {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   203
    case SDL_PIXELFORMAT_BGR565:
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   204
        return GU_PSM_5650;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   205
    case SDL_PIXELFORMAT_ABGR1555:
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   206
        return GU_PSM_5551;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   207
    case SDL_PIXELFORMAT_ABGR4444:
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   208
        return GU_PSM_4444;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   209
    case SDL_PIXELFORMAT_ABGR8888:
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   210
        return GU_PSM_8888;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   211
    default:
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   212
        return GU_PSM_8888;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   213
    }
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   214
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   215
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   216
void
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   217
StartDrawing(SDL_Renderer * renderer)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   218
{
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   219
    PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   220
    if(data->displayListAvail)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   221
        return;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   222
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   223
    sceGuStart(GU_DIRECT, DisplayList);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   224
    data->displayListAvail = SDL_TRUE;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   225
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   226
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   227
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   228
int
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   229
TextureSwizzle(PSP_TextureData *psp_texture)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   230
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   231
    if(psp_texture->swizzled)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   232
        return 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   233
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   234
    int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   235
    int height = psp_texture->size / bytewidth;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   236
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   237
    int rowblocks = (bytewidth>>4);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   238
    int rowblocksadd = (rowblocks-1)<<7;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   239
    unsigned int blockaddress = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   240
    unsigned int *src = (unsigned int*) psp_texture->data;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   241
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   242
    unsigned char *data = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   243
    data = malloc(psp_texture->size);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   244
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   245
    int j;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   246
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   247
    for(j = 0; j < height; j++, blockaddress += 16)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   248
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   249
        unsigned int *block;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   250
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   251
        block = (unsigned int*)&data[blockaddress];
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   252
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   253
        int i;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   254
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   255
        for(i = 0; i < rowblocks; i++)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   256
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   257
            *block++ = *src++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   258
            *block++ = *src++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   259
            *block++ = *src++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   260
            *block++ = *src++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   261
            block += 28;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   262
        }
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   263
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   264
        if((j & 0x7) == 0x7)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   265
            blockaddress += rowblocksadd;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   266
    }
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   267
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   268
    free(psp_texture->data);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   269
    psp_texture->data = data;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   270
    psp_texture->swizzled = SDL_TRUE;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   271
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   272
    return 1;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   273
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   274
int TextureUnswizzle(PSP_TextureData *psp_texture)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   275
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   276
    if(!psp_texture->swizzled)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   277
        return 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   278
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   279
    int blockx, blocky;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   280
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   281
    int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   282
    int height = psp_texture->size / bytewidth;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   283
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   284
    int widthblocks = bytewidth/16;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   285
    int heightblocks = height/8;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   286
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   287
    int dstpitch = (bytewidth - 16)/4;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   288
    int dstrow = bytewidth * 8;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   289
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   290
    unsigned int *src = (unsigned int*) psp_texture->data;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   291
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   292
    unsigned char *data = NULL;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   293
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   294
    data = malloc(psp_texture->size);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   295
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   296
    if(!data)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   297
        return 0;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   298
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   299
    sceKernelDcacheWritebackAll();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   300
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   301
    int j;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   302
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   303
    unsigned char *ydst = (unsigned char *)data;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   304
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   305
    for(blocky = 0; blocky < heightblocks; ++blocky)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   306
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   307
        unsigned char *xdst = ydst;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   308
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   309
        for(blockx = 0; blockx < widthblocks; ++blockx)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   310
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   311
            unsigned int *block;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   312
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   313
            block = (unsigned int*)xdst;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   314
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   315
            for(j = 0; j < 8; ++j)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   316
            {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   317
                *(block++) = *(src++);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   318
                *(block++) = *(src++);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   319
                *(block++) = *(src++);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   320
                *(block++) = *(src++);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   321
                block += dstpitch;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   322
            }
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   323
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   324
            xdst += 16;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   325
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   326
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   327
        ydst += dstrow;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   328
    }
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   329
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   330
    free(psp_texture->data);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   331
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   332
    psp_texture->data = data;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   333
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   334
    psp_texture->swizzled = SDL_FALSE;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   335
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   336
    return 1;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   337
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   338
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   339
SDL_Renderer *
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   340
PSP_CreateRenderer(SDL_Window * window, Uint32 flags)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   341
{
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   342
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   343
    SDL_Renderer *renderer;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   344
    PSP_RenderData *data;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   345
        int pixelformat;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   346
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   347
    if (!renderer) {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   348
        SDL_OutOfMemory();
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   349
        return NULL;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   350
    }
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   351
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   352
    data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data));
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   353
    if (!data) {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   354
        PSP_DestroyRenderer(renderer);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   355
        SDL_OutOfMemory();
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   356
        return NULL;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   357
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   358
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   359
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   360
    renderer->WindowEvent = PSP_WindowEvent;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   361
    renderer->CreateTexture = PSP_CreateTexture;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   362
    renderer->UpdateTexture = PSP_UpdateTexture;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   363
    renderer->LockTexture = PSP_LockTexture;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   364
    renderer->UnlockTexture = PSP_UnlockTexture;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   365
    renderer->SetRenderTarget = PSP_SetRenderTarget;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   366
    renderer->UpdateViewport = PSP_UpdateViewport;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   367
    renderer->RenderClear = PSP_RenderClear;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   368
    renderer->RenderDrawPoints = PSP_RenderDrawPoints;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   369
    renderer->RenderDrawLines = PSP_RenderDrawLines;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   370
    renderer->RenderFillRects = PSP_RenderFillRects;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   371
    renderer->RenderCopy = PSP_RenderCopy;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   372
    renderer->RenderReadPixels = PSP_RenderReadPixels;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   373
    renderer->RenderCopyEx = PSP_RenderCopyEx;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   374
    renderer->RenderPresent = PSP_RenderPresent;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   375
    renderer->DestroyTexture = PSP_DestroyTexture;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   376
    renderer->DestroyRenderer = PSP_DestroyRenderer;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   377
    renderer->info = PSP_RenderDriver.info;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   378
    renderer->info.flags = SDL_RENDERER_ACCELERATED;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   379
    renderer->driverdata = data;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   380
    renderer->window = window;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   381
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   382
    if (data->initialized != SDL_FALSE)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   383
        return 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   384
    data->initialized = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   385
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   386
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   387
        data->vsync = SDL_TRUE;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   388
    } else {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   389
        data->vsync = SDL_FALSE;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   390
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   391
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   392
    pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window));
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   393
    switch(pixelformat)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   394
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   395
        case GU_PSM_4444:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   396
        case GU_PSM_5650:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   397
        case GU_PSM_5551:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   398
            data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   399
            data->backbuffer =  (unsigned int *)(0);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   400
            data->bpp = 2;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   401
            data->psm = pixelformat;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   402
            break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   403
        default:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   404
            data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   405
            data->backbuffer =  (unsigned int *)(0);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   406
            data->bpp = 4;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   407
            data->psm = GU_PSM_8888;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   408
            break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   409
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   410
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   411
    sceGuInit();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   412
    /* setup GU */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   413
    sceGuStart(GU_DIRECT, DisplayList);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   414
    sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   415
    sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   416
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   417
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   418
    sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1));
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   419
    sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   420
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   421
    data->frontbuffer = vabsptr(data->frontbuffer);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   422
    data->backbuffer = vabsptr(data->backbuffer);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   423
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   424
    /* Scissoring */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   425
    sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   426
    sceGuEnable(GU_SCISSOR_TEST);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   427
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   428
    /* Backface culling */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   429
    sceGuFrontFace(GU_CCW);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   430
    sceGuEnable(GU_CULL_FACE);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   431
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   432
    /* Texturing */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   433
    sceGuEnable(GU_TEXTURE_2D);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   434
    sceGuShadeModel(GU_SMOOTH);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   435
    sceGuTexWrap(GU_REPEAT, GU_REPEAT);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   436
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   437
    /* Blending */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   438
    sceGuEnable(GU_BLEND);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   439
    sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   440
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   441
    sceGuTexFilter(GU_LINEAR,GU_LINEAR);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   442
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   443
    sceGuFinish();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   444
    sceGuSync(0,0);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   445
    sceDisplayWaitVblankStartCB();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   446
    sceGuDisplay(GU_TRUE);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   447
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   448
    return renderer;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   449
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   450
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   451
static void
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   452
PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   453
{
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   454
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   455
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   456
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   457
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   458
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   459
PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   460
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   461
//      PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   462
    PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   463
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   464
    if(!psp_texture)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   465
        return -1;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   466
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   467
    psp_texture->swizzled = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   468
    psp_texture->width = texture->w;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   469
    psp_texture->height = texture->h;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   470
    psp_texture->textureHeight = TextureNextPow2(texture->h);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   471
    psp_texture->textureWidth = TextureNextPow2(texture->w);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   472
    psp_texture->format = PixelFormatToPSPFMT(texture->format);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   473
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   474
    switch(psp_texture->format)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   475
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   476
        case GU_PSM_5650:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   477
        case GU_PSM_5551:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   478
        case GU_PSM_4444:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   479
            psp_texture->bits = 16;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   480
            break;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   481
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   482
        case GU_PSM_8888:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   483
            psp_texture->bits = 32;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   484
            break;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   485
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   486
        default:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   487
            return -1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   488
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   489
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   490
    psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   491
    psp_texture->size = psp_texture->textureHeight*psp_texture->pitch;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   492
    psp_texture->data = SDL_calloc(1, psp_texture->size);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   493
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   494
    if(!psp_texture->data)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   495
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   496
        SDL_free(psp_texture);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   497
        return SDL_OutOfMemory();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   498
    }
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   499
    texture->driverdata = psp_texture;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   500
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   501
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   502
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   503
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   504
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   505
void
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   506
TextureActivate(SDL_Texture * texture)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   507
{
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   508
    PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   509
    int scaleMode = GetScaleQuality();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   510
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   511
    /* Swizzling is useless with small textures. */
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   512
    if (texture->w >= 16 || texture->h >= 16)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   513
    {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   514
        TextureSwizzle(psp_texture);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   515
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   516
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   517
    sceGuEnable(GU_TEXTURE_2D);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   518
    sceGuTexWrap(GU_REPEAT, GU_REPEAT);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   519
    sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   520
    sceGuTexFilter(scaleMode, scaleMode); /* GU_NEAREST good for tile-map */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   521
                                          /* GU_LINEAR good for scaling */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   522
    sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   523
    sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   524
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   525
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   526
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   527
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   528
PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   529
                   const SDL_Rect * rect, const void *pixels, int pitch)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   530
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   531
//  PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   532
    const Uint8 *src;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   533
    Uint8 *dst;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   534
    int row, length,dpitch;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   535
    src = pixels;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   536
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   537
    PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   538
    length = rect->w * SDL_BYTESPERPIXEL(texture->format);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   539
    if (length == pitch && length == dpitch) {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   540
        SDL_memcpy(dst, src, length*rect->h);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   541
    } else {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   542
        for (row = 0; row < rect->h; ++row) {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   543
            SDL_memcpy(dst, src, length);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   544
            src += pitch;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   545
            dst += dpitch;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   546
        }
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   547
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   548
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   549
    sceKernelDcacheWritebackAll();
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   550
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   551
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   552
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   553
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   554
PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   555
                 const SDL_Rect * rect, void **pixels, int *pitch)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   556
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   557
    PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   558
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   559
    *pixels =
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   560
        (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch +
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   561
                  rect->x * SDL_BYTESPERPIXEL(texture->format));
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   562
    *pitch = psp_texture->pitch;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   563
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   564
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   565
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   566
static void
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   567
PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   568
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   569
    PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   570
    SDL_Rect rect;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   571
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   572
    /* We do whole texture updates, at least for now */
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   573
    rect.x = 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   574
    rect.y = 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   575
    rect.w = texture->w;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   576
    rect.h = texture->h;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   577
    PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   578
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   579
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   580
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   581
PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   582
{
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   583
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   584
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   585
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   586
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   587
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   588
PSP_UpdateViewport(SDL_Renderer * renderer)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   589
{
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   590
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   591
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   592
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   593
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   594
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   595
static void
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   596
PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   597
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   598
    PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   599
    if (blendMode != data-> currentBlendMode) {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   600
        switch (blendMode) {
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   601
        case SDL_BLENDMODE_NONE:
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   602
                sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   603
                sceGuDisable(GU_BLEND);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   604
            break;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   605
        case SDL_BLENDMODE_BLEND:
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   606
                sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   607
                sceGuEnable(GU_BLEND);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   608
                sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   609
            break;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   610
        case SDL_BLENDMODE_ADD:
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   611
                sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   612
                sceGuEnable(GU_BLEND);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   613
                sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   614
            break;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   615
        case SDL_BLENDMODE_MOD:
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   616
                sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   617
                sceGuEnable(GU_BLEND);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   618
                sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   619
            break;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   620
        }
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   621
        data->currentBlendMode = blendMode;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   622
    }
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   623
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   624
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   625
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   626
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   627
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   628
PSP_RenderClear(SDL_Renderer * renderer)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   629
{
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   630
    /* start list */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   631
    StartDrawing(renderer);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   632
    int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   633
    sceGuClearColor(color);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   634
    sceGuClearDepth(0);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   635
    sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   636
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   637
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   638
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   639
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   640
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   641
PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   642
                      int count)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   643
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   644
    int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   645
    int i;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   646
    StartDrawing(renderer);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   647
    VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   648
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   649
    for (i = 0; i < count; ++i) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   650
            vertices[i].x = points[i].x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   651
            vertices[i].y = points[i].y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   652
            vertices[i].z = 0.0f;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   653
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   654
    sceGuDisable(GU_TEXTURE_2D);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   655
    sceGuColor(color);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   656
    sceGuShadeModel(GU_FLAT);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   657
    sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   658
    sceGuShadeModel(GU_SMOOTH);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   659
    sceGuEnable(GU_TEXTURE_2D);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   660
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   661
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   662
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   663
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   664
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   665
PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   666
                     int count)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   667
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   668
    int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   669
    int i;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   670
    StartDrawing(renderer);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   671
    VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   672
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   673
    for (i = 0; i < count; ++i) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   674
            vertices[i].x = points[i].x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   675
            vertices[i].y = points[i].y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   676
            vertices[i].z = 0.0f;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   677
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   678
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   679
    sceGuDisable(GU_TEXTURE_2D);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   680
    sceGuColor(color);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   681
    sceGuShadeModel(GU_FLAT);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   682
    sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   683
    sceGuShadeModel(GU_SMOOTH);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   684
    sceGuEnable(GU_TEXTURE_2D);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   685
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   686
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   687
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   688
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   689
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   690
PSP_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   691
                     int count)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   692
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   693
    int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   694
    int i;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   695
    StartDrawing(renderer);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   696
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   697
    for (i = 0; i < count; ++i) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   698
        const SDL_FRect *rect = &rects[i];
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   699
        VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1));
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   700
        vertices[0].x = rect->x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   701
        vertices[0].y = rect->y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   702
        vertices[0].z = 0.0f;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   703
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   704
        vertices[1].x = rect->x + rect->w;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   705
        vertices[1].y = rect->y + rect->h;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   706
        vertices[1].z = 0.0f;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   707
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   708
        sceGuDisable(GU_TEXTURE_2D);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   709
        sceGuColor(color);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   710
        sceGuShadeModel(GU_FLAT);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   711
        sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   712
        sceGuShadeModel(GU_SMOOTH);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   713
        sceGuEnable(GU_TEXTURE_2D);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   714
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   715
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   716
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   717
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   718
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   719
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   720
#define PI   3.14159265358979f
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   721
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   722
#define radToDeg(x) ((x)*180.f/PI)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   723
#define degToRad(x) ((x)*PI/180.f)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   724
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   725
float MathAbs(float x)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   726
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   727
    float result;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   728
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   729
    __asm__ volatile (
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   730
        "mtv      %1, S000\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   731
        "vabs.s   S000, S000\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   732
        "mfv      %0, S000\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   733
    : "=r"(result) : "r"(x));
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   734
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   735
    return result;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   736
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   737
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   738
void MathSincos(float r, float *s, float *c)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   739
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   740
    __asm__ volatile (
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   741
        "mtv      %2, S002\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   742
        "vcst.s   S003, VFPU_2_PI\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   743
        "vmul.s   S002, S002, S003\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   744
        "vrot.p   C000, S002, [s, c]\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   745
        "mfv      %0, S000\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   746
        "mfv      %1, S001\n"
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   747
    : "=r"(*s), "=r"(*c): "r"(r));
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   748
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   749
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   750
void Swap(float *a, float *b)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   751
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   752
    float n=*a;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   753
    *a = *b;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   754
    *b = n;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   755
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   756
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   757
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   758
PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   759
                const SDL_Rect * srcrect, const SDL_FRect * dstrect)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   760
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   761
    float x, y, width, height;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   762
    float u0, v0, u1, v1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   763
    unsigned char alpha;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   764
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   765
    x = dstrect->x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   766
    y = dstrect->y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   767
    width = dstrect->w;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   768
    height = dstrect->h;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   769
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   770
    u0 = srcrect->x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   771
    v0 = srcrect->y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   772
    u1 = srcrect->x + srcrect->w;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   773
    v1 = srcrect->y + srcrect->h;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   774
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   775
    alpha = texture->a;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   776
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   777
    StartDrawing(renderer);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   778
    TextureActivate(texture);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   779
    PSP_SetBlendMode(renderer, renderer->blendMode);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   780
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   781
    if(alpha != 255)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   782
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   783
        sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   784
        sceGuColor(GU_RGBA(255, 255, 255, alpha));
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   785
    }else{
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   786
        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   787
        sceGuColor(0xFFFFFFFF);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   788
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   789
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   790
    if((MathAbs(u1) - MathAbs(u0)) < 64.0f)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   791
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   792
        VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   793
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   794
        vertices[0].u = u0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   795
        vertices[0].v = v0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   796
        vertices[0].x = x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   797
        vertices[0].y = y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   798
        vertices[0].z = 0;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   799
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   800
        vertices[1].u = u1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   801
        vertices[1].v = v1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   802
        vertices[1].x = x + width;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   803
        vertices[1].y = y + height;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   804
        vertices[1].z = 0;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   805
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   806
        sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   807
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   808
    else
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   809
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   810
        float start, end;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   811
        float curU = u0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   812
        float curX = x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   813
        float endX = x + width;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   814
        float slice = 64.0f;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   815
        float ustep = (u1 - u0)/width * slice;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   816
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   817
        if(ustep < 0.0f)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   818
            ustep = -ustep;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   819
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   820
        for(start = 0, end = width; start < end; start += slice)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   821
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   822
            VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   823
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   824
            float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   825
            float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   826
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   827
            vertices[0].u = curU;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   828
            vertices[0].v = v0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   829
            vertices[0].x = curX;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   830
            vertices[0].y = y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   831
            vertices[0].z = 0;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   832
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   833
            curU += sourceWidth;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   834
            curX += polyWidth;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   835
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   836
            vertices[1].u = curU;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   837
            vertices[1].v = v1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   838
            vertices[1].x = curX;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   839
            vertices[1].y = (y + height);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   840
            vertices[1].z = 0;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   841
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   842
            sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   843
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   844
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   845
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   846
    if(alpha != 255)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   847
        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   848
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   849
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   850
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   851
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   852
PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   853
                    Uint32 pixel_format, void * pixels, int pitch)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   854
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   855
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   856
        return 0;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   857
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   858
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   859
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   860
static int
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   861
PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   862
                const SDL_Rect * srcrect, const SDL_FRect * dstrect,
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   863
                const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   864
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   865
    float x, y, width, height;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   866
    float u0, v0, u1, v1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   867
    unsigned char alpha;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   868
    float centerx, centery;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   869
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   870
    x = dstrect->x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   871
    y = dstrect->y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   872
    width = dstrect->w;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   873
    height = dstrect->h;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   874
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   875
    u0 = srcrect->x;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   876
    v0 = srcrect->y;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   877
    u1 = srcrect->x + srcrect->w;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   878
    v1 = srcrect->y + srcrect->h;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   879
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   880
    centerx = center->x;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   881
    centery = center->y;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   882
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   883
    alpha = texture->a;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   884
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   885
    StartDrawing(renderer);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   886
    TextureActivate(texture);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   887
    PSP_SetBlendMode(renderer, renderer->blendMode);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   888
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   889
    if(alpha != 255)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   890
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   891
        sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   892
        sceGuColor(GU_RGBA(255, 255, 255, alpha));
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   893
    }else{
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   894
        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   895
        sceGuColor(0xFFFFFFFF);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   896
    }
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   897
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   898
//      x += width * 0.5f;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   899
//      y += height * 0.5f;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   900
    x += centerx;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   901
    y += centery;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   902
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   903
    float c, s;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   904
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   905
    MathSincos(degToRad(angle), &s, &c);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   906
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   907
//      width *= 0.5f;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   908
//      height *= 0.5f;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   909
    width  -= centerx;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   910
    height -= centery;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   911
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   912
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   913
    float cw = c*width;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   914
    float sw = s*width;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   915
    float ch = c*height;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   916
    float sh = s*height;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   917
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   918
    VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   919
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   920
    vertices[0].u = u0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   921
    vertices[0].v = v0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   922
    vertices[0].x = x - cw + sh;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   923
    vertices[0].y = y - sw - ch;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   924
    vertices[0].z = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   925
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   926
    vertices[1].u = u0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   927
    vertices[1].v = v1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   928
    vertices[1].x = x - cw - sh;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   929
    vertices[1].y = y - sw + ch;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   930
    vertices[1].z = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   931
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   932
    vertices[2].u = u1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   933
    vertices[2].v = v1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   934
    vertices[2].x = x + cw - sh;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   935
    vertices[2].y = y + sw + ch;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   936
    vertices[2].z = 0;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   937
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   938
    vertices[3].u = u1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   939
    vertices[3].v = v0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   940
    vertices[3].x = x + cw + sh;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   941
    vertices[3].y = y + sw - ch;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   942
    vertices[3].z = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   943
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   944
    if (flip & SDL_FLIP_HORIZONTAL) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   945
                Swap(&vertices[0].v, &vertices[2].v);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   946
                Swap(&vertices[1].v, &vertices[3].v);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   947
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   948
    if (flip & SDL_FLIP_VERTICAL) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   949
                Swap(&vertices[0].u, &vertices[2].u);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   950
                Swap(&vertices[1].u, &vertices[3].u);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   951
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   952
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   953
    sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   954
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   955
    if(alpha != 255)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   956
        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   957
    return 0;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   958
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   959
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   960
static void
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   961
PSP_RenderPresent(SDL_Renderer * renderer)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   962
{
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   963
    PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   964
    if(!data->displayListAvail)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   965
        return;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   966
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   967
    data->displayListAvail = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   968
    sceGuFinish();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   969
    sceGuSync(0,0);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   970
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   971
//  if(data->vsync)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   972
        sceDisplayWaitVblankStart();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   973
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   974
    data->backbuffer = data->frontbuffer;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   975
    data->frontbuffer = vabsptr(sceGuSwapBuffers());
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   976
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   977
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   978
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   979
static void
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   980
PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   981
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   982
    PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   983
    PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   984
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   985
    if (renderdata == 0)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   986
        return;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   987
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   988
    if(psp_texture == 0)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   989
        return;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   990
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   991
    if(psp_texture->data != 0)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   992
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   993
        SDL_free(psp_texture->data);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   994
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   995
    SDL_free(psp_texture);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
   996
    texture->driverdata = NULL;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   997
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   998
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
   999
static void
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1000
PSP_DestroyRenderer(SDL_Renderer * renderer)
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1001
{
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1002
    PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1003
    if (data) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1004
        if (!data->initialized)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1005
            return;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1006
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1007
        StartDrawing(renderer);
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1008
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1009
        sceGuTerm();
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1010
//      vfree(data->backbuffer);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1011
//      vfree(data->frontbuffer);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1012
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1013
        data->initialized = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7096
diff changeset
  1014
        data->displayListAvail = SDL_FALSE;
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1015
        SDL_free(data);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1016
    }
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1017
    SDL_free(renderer);
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1018
}
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1019
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1020
#endif /* SDL_VIDEO_RENDER_PSP */
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1021
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1022
/* vi: set ts=4 sw=4 expandtab: */
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents:
diff changeset
  1023