PSP: add implementation for RenderGeometry
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c
index 6a6f585..c1e0e6d 100644
--- a/src/render/psp/SDL_render_psp.c
+++ b/src/render/psp/SDL_render_psp.c
@@ -108,9 +108,22 @@ typedef struct
{
float u, v;
float x, y, z;
-
} VertTV;
+typedef struct
+{
+ int col;
+ float x, y, z;
+} VertCV;
+
+
+typedef struct
+{
+ float u, v;
+ int col;
+ float x, y, z;
+} VertTCV;
+
#define PI 3.14159265358979f
#define radToDeg(x) ((x)*180.f/PI)
@@ -474,6 +487,94 @@ PSP_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
}
static int
+PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
+ const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
+ int num_vertices, const void *indices, int num_indices, int size_indices,
+ float scale_x, float scale_y)
+{
+ int i;
+ int count = indices ? num_indices : num_vertices;
+
+ cmd->data.draw.count = count;
+ size_indices = indices ? size_indices : 0;
+
+ if (texture == NULL) {
+ VertCV *verts;
+ verts = (VertCV *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertCV), 4, &cmd->data.draw.first);
+ if (!verts) {
+ return -1;
+ }
+
+ for (i = 0; i < count; i++) {
+ int j;
+ float *xy_;
+ int col_;
+ if (size_indices == 4) {
+ j = ((const Uint32 *)indices)[i];
+ } else if (size_indices == 2) {
+ j = ((const Uint16 *)indices)[i];
+ } else if (size_indices == 1) {
+ j = ((const Uint8 *)indices)[i];
+ } else {
+ j = i;
+ }
+
+ xy_ = (float *)((char*)xy + j * xy_stride);
+ col_ = *(int *)((char*)color + j * color_stride);
+
+ verts->x = xy_[0] * scale_x;
+ verts->y = xy_[1] * scale_y;
+ verts->z = 0;
+
+ verts->col = col_;
+
+ verts++;
+ }
+ } else {
+ PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
+ VertTCV *verts;
+ verts = (VertTCV *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertTCV), 4, &cmd->data.draw.first);
+ if (!verts) {
+ return -1;
+ }
+
+ for (i = 0; i < count; i++) {
+ int j;
+ float *xy_;
+ int col_;
+ float *uv_;
+
+ if (size_indices == 4) {
+ j = ((const Uint32 *)indices)[i];
+ } else if (size_indices == 2) {
+ j = ((const Uint16 *)indices)[i];
+ } else if (size_indices == 1) {
+ j = ((const Uint8 *)indices)[i];
+ } else {
+ j = i;
+ }
+
+ xy_ = (float *)((char*)xy + j * xy_stride);
+ col_ = *(int *)((char*)color + j * color_stride);
+ uv_ = (float *)((char*)uv + j * uv_stride);
+
+ verts->x = xy_[0] * scale_x;
+ verts->y = xy_[1] * scale_y;
+ verts->z = 0;
+
+ verts->col = col_;
+
+ verts->u = uv_[0] * psp_texture->textureWidth;
+ verts->v = uv_[1] * psp_texture->textureHeight;
+
+ verts++;
+ }
+ }
+
+ return 0;
+}
+
+static int
PSP_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
VertV *verts = (VertV *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (VertV), 4, &cmd->data.draw.first);
@@ -853,6 +954,25 @@ PSP_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
break;
}
+ case SDL_RENDERCMD_GEOMETRY: {
+ const size_t count = cmd->data.draw.count;
+ if (cmd->data.draw.texture == NULL) {
+ const VertCV *verts = (VertCV *) (gpumem + cmd->data.draw.first);
+ sceGuDisable(GU_TEXTURE_2D);
+ /* In GU_SMOOTH mode */
+ sceGuDrawArray(GU_TRIANGLES, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, verts);
+ sceGuEnable(GU_TEXTURE_2D);
+ } else {
+ const VertTCV *verts = (VertTCV *) (gpumem + cmd->data.draw.first);
+ TextureActivate(cmd->data.draw.texture);
+ /* Need to force refresh of blending mode, probably something to FIXME */
+ PSP_SetBlendMode(renderer, SDL_BLENDMODE_INVALID);
+ PSP_SetBlendMode(renderer, cmd->data.draw.blend);
+ sceGuDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, verts);
+ }
+ break;
+ }
+
case SDL_RENDERCMD_NO_OP:
break;
}
@@ -967,6 +1087,7 @@ PSP_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->QueueSetDrawColor = PSP_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueDrawPoints = PSP_QueueDrawPoints;
renderer->QueueDrawLines = PSP_QueueDrawPoints; /* lines and points queue vertices the same way. */
+ renderer->QueueGeometry = PSP_QueueGeometry;
renderer->QueueFillRects = PSP_QueueFillRects;
renderer->QueueCopy = PSP_QueueCopy;
renderer->QueueCopyEx = PSP_QueueCopyEx;
@@ -1028,8 +1149,11 @@ PSP_CreateRenderer(SDL_Window * window, Uint32 flags)
sceGuEnable(GU_SCISSOR_TEST);
/* Backface culling */
+ /*
+ FIXME: Culling probably un-needed ? It can conflict with SDL_RENDERCMD_GEOMETRY
sceGuFrontFace(GU_CCW);
sceGuEnable(GU_CULL_FACE);
+ */
/* Texturing */
sceGuEnable(GU_TEXTURE_2D);