comparison src/video/photon/SDL_photon_render.c @ 3396:d6b79fc83362

All 2D operations in Photon driver have been finished. The driver is ready to use. There fullscreen modes and YUV textures are rest only.
author Mike Gorchak <lestat@i.com.ua>
date Tue, 13 Oct 2009 11:26:40 +0000
parents 05499ec8c022
children d15a4daa4a58
comparison
equal deleted inserted replaced
3395:45f140dd4b08 3396:d6b79fc83362
268 SDL_AddRenderDriver(it, &photon_renderdriver); 268 SDL_AddRenderDriver(it, &photon_renderdriver);
269 } 269 }
270 } 270 }
271 271
272 /****************************************************************************/ 272 /****************************************************************************/
273 /* Render helper functions */ 273 /* Renderer helper functions */
274 /****************************************************************************/ 274 /****************************************************************************/
275 275
276 static int _photon_recreate_surfaces(SDL_Renderer * renderer) 276 static int _photon_recreate_surfaces(SDL_Renderer * renderer)
277 { 277 {
278 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; 278 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
575 default: 575 default:
576 break; 576 break;
577 } 577 }
578 } 578 }
579 579
580 int _photon_set_blending(SDL_Renderer* renderer, uint32_t blendmode, uint32_t globalalpha, uint32_t blendsource)
581 {
582 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
583
584 /* Switch on requested graphics context modifiers */
585 switch (blendmode)
586 {
587 case SDL_BLENDMODE_MASK:
588 /* Enable and set chroma key */
589 if (blendsource==SDL_PHOTON_TEXTURE_BLEND)
590 {
591 PgSetChromaCx(rdata->gc, PgRGB(255, 255, 255), Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
592 PgChromaOnCx(rdata->gc);
593 }
594 break;
595 case SDL_BLENDMODE_BLEND:
596 /* Enable and set chroma key and alpha blending */
597 if (blendsource==SDL_PHOTON_TEXTURE_BLEND)
598 {
599 PgSetChromaCx(rdata->gc, PgRGB(255, 255, 255), Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
600 PgChromaOnCx(rdata->gc);
601 }
602 PgSetAlphaCx(rdata->gc, Pg_ALPHA_OP_SRC_GLOBAL | Pg_BLEND_SRC_As | Pg_BLEND_DST_1mAs, NULL, NULL, globalalpha, 0);
603 PgAlphaOnCx(rdata->gc);
604 break;
605 case SDL_BLENDMODE_ADD:
606 /* Enable and set chroma key and alpha blending */
607 if (blendsource==SDL_PHOTON_TEXTURE_BLEND)
608 {
609 PgSetChromaCx(rdata->gc, PgRGB(255, 255, 255), Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
610 PgChromaOnCx(rdata->gc);
611 }
612 PgSetAlphaCx(rdata->gc, Pg_ALPHA_OP_SRC_GLOBAL | Pg_BLEND_SRC_As | Pg_BLEND_DST_1, NULL, NULL, globalalpha, 0);
613 PgAlphaOnCx(rdata->gc);
614 break;
615 case SDL_BLENDMODE_MOD:
616 /* Enable and set alpha blending */
617 PgSetAlphaCx(rdata->gc, Pg_BLEND_SRC_0 | Pg_BLEND_DST_S, NULL, NULL, 0, 0);
618 PgAlphaOnCx(rdata->gc);
619 break;
620 case SDL_BLENDMODE_NONE:
621 /* Do nothing */
622 break;
623 default:
624 return -1;
625 }
626
627 return 0;
628 }
629
630 int _photon_reset_blending(SDL_Renderer* renderer, uint32_t blendmode, uint32_t blendsource)
631 {
632 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
633
634 /* Switch off graphics context modifiers */
635 switch (blendmode)
636 {
637 case SDL_BLENDMODE_MASK:
638 /* Disable chroma key */
639 if (blendsource==SDL_PHOTON_TEXTURE_BLEND)
640 {
641 PgChromaOffCx(rdata->gc);
642 }
643 break;
644 case SDL_BLENDMODE_BLEND:
645 /* Disable chroma key and alpha blending */
646 if (blendsource==SDL_PHOTON_TEXTURE_BLEND)
647 {
648 PgChromaOffCx(rdata->gc);
649 }
650 PgAlphaOffCx(rdata->gc);
651 break;
652 case SDL_BLENDMODE_ADD:
653 /* Disable chroma key and alpha blending */
654 if (blendsource==SDL_PHOTON_TEXTURE_BLEND)
655 {
656 PgChromaOffCx(rdata->gc);
657 }
658 PgAlphaOffCx(rdata->gc);
659 break;
660 case SDL_BLENDMODE_MOD:
661 /* Disable chroma key and alpha blending */
662 PgAlphaOffCx(rdata->gc);
663 break;
664 case SDL_BLENDMODE_NONE:
665 /* Do nothing */
666 break;
667 default:
668 return -1;
669 }
670
671 return 0;
672 }
673
580 /****************************************************************************/ 674 /****************************************************************************/
581 /* SDL render interface */ 675 /* SDL render interface */
582 /****************************************************************************/ 676 /****************************************************************************/
583 677
584 static int 678 static int
1067 } 1161 }
1068 1162
1069 static int 1163 static int
1070 photon_setdrawblendmode(SDL_Renderer * renderer) 1164 photon_setdrawblendmode(SDL_Renderer * renderer)
1071 { 1165 {
1072 /* TODO */ 1166 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
1073 SDL_Unsupported(); 1167
1074 return -1; 1168 /* Check, if it is not initialized */
1169 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN)
1170 {
1171 SDL_SetError("Photon: can't set texture blend mode for OpenGL ES window");
1172 return -1;
1173 }
1174
1175 switch (renderer->blendMode)
1176 {
1177 case SDL_BLENDMODE_NONE:
1178 case SDL_BLENDMODE_MASK:
1179 case SDL_BLENDMODE_BLEND:
1180 case SDL_BLENDMODE_ADD:
1181 case SDL_BLENDMODE_MOD:
1182 return 0;
1183 default:
1184 SDL_Unsupported();
1185 renderer->blendMode = SDL_BLENDMODE_NONE;
1186 return -1;
1187 }
1188
1189 return 0;
1075 } 1190 }
1076 1191
1077 static int 1192 static int
1078 photon_renderpoint(SDL_Renderer * renderer, int x, int y) 1193 photon_renderpoint(SDL_Renderer * renderer, int x, int y)
1079 { 1194 {
1084 { 1199 {
1085 SDL_SetError("Photon: can't render point in OpenGL ES window"); 1200 SDL_SetError("Photon: can't render point in OpenGL ES window");
1086 return -1; 1201 return -1;
1087 } 1202 }
1088 1203
1204 /* Enable blending, if requested */
1205 _photon_set_blending(renderer, renderer->blendMode, renderer->a, SDL_PHOTON_DRAW_BLEND);
1206
1089 switch (rdata->surfaces_type) 1207 switch (rdata->surfaces_type)
1090 { 1208 {
1091 case SDL_PHOTON_SURFTYPE_OFFSCREEN: 1209 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
1092 PgDrawIPixelCx(rdata->osurfaces[rdata->surface_render_idx], x, y); 1210 PgDrawIPixelCx(rdata->osurfaces[rdata->surface_render_idx], x, y);
1093 break; 1211 break;
1097 case SDL_PHOTON_SURFTYPE_UNKNOWN: 1215 case SDL_PHOTON_SURFTYPE_UNKNOWN:
1098 default: 1216 default:
1099 break; 1217 break;
1100 } 1218 }
1101 1219
1220 /* Disable blending, if it was enabled */
1221 _photon_reset_blending(renderer, renderer->blendMode, SDL_PHOTON_DRAW_BLEND);
1222
1102 return 0; 1223 return 0;
1103 } 1224 }
1104 1225
1105 static int 1226 static int
1106 photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) 1227 photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
1112 { 1233 {
1113 SDL_SetError("Photon: can't render line in OpenGL ES window"); 1234 SDL_SetError("Photon: can't render line in OpenGL ES window");
1114 return -1; 1235 return -1;
1115 } 1236 }
1116 1237
1238 /* Enable blending, if requested */
1239 _photon_set_blending(renderer, renderer->blendMode, renderer->a, SDL_PHOTON_DRAW_BLEND);
1240
1117 switch (rdata->surfaces_type) 1241 switch (rdata->surfaces_type)
1118 { 1242 {
1119 case SDL_PHOTON_SURFTYPE_OFFSCREEN: 1243 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
1120 PgDrawILineCx(rdata->osurfaces[rdata->surface_render_idx], x1, y1, x2, y2); 1244 PgDrawILineCx(rdata->osurfaces[rdata->surface_render_idx], x1, y1, x2, y2);
1121 break; 1245 break;
1125 case SDL_PHOTON_SURFTYPE_UNKNOWN: 1249 case SDL_PHOTON_SURFTYPE_UNKNOWN:
1126 default: 1250 default:
1127 break; 1251 break;
1128 } 1252 }
1129 1253
1254 /* Disable blending, if it was enabled */
1255 _photon_reset_blending(renderer, renderer->blendMode, SDL_PHOTON_DRAW_BLEND);
1256
1130 return 0; 1257 return 0;
1131 } 1258 }
1132 1259
1133 static int 1260 static int
1134 photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect) 1261 photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect)
1140 { 1267 {
1141 SDL_SetError("Photon: can't render filled box in OpenGL ES window"); 1268 SDL_SetError("Photon: can't render filled box in OpenGL ES window");
1142 return -1; 1269 return -1;
1143 } 1270 }
1144 1271
1272 /* Enable blending, if requested */
1273 _photon_set_blending(renderer, renderer->blendMode, renderer->a, SDL_PHOTON_DRAW_BLEND);
1274
1145 switch (rdata->surfaces_type) 1275 switch (rdata->surfaces_type)
1146 { 1276 {
1147 case SDL_PHOTON_SURFTYPE_OFFSCREEN: 1277 case SDL_PHOTON_SURFTYPE_OFFSCREEN:
1148 PgDrawIRectCx(rdata->osurfaces[rdata->surface_render_idx], rect->x, rect->y, rect->w+rect->x-1, rect->h+rect->y-1, Pg_DRAW_FILL); 1278 PgDrawIRectCx(rdata->osurfaces[rdata->surface_render_idx], rect->x, rect->y, rect->w+rect->x-1, rect->h+rect->y-1, Pg_DRAW_FILL);
1149 break; 1279 break;
1152 break; 1282 break;
1153 case SDL_PHOTON_SURFTYPE_UNKNOWN: 1283 case SDL_PHOTON_SURFTYPE_UNKNOWN:
1154 default: 1284 default:
1155 break; 1285 break;
1156 } 1286 }
1287
1288 /* Disable blending, if it was enabled */
1289 _photon_reset_blending(renderer, renderer->blendMode, SDL_PHOTON_DRAW_BLEND);
1290
1291 return 0;
1157 } 1292 }
1158 1293
1159 static int 1294 static int
1160 photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture, 1295 photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
1161 const SDL_Rect * srcrect, const SDL_Rect * dstrect) 1296 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
1172 { 1307 {
1173 SDL_SetError("Photon: can't blit textures in OpenGL ES window"); 1308 SDL_SetError("Photon: can't blit textures in OpenGL ES window");
1174 return -1; 1309 return -1;
1175 } 1310 }
1176 1311
1177 /* Switch on requested graphics context modifiers */ 1312 _photon_set_blending(renderer, texture->blendMode, texture->a, SDL_PHOTON_TEXTURE_BLEND);
1178 switch(texture->blendMode)
1179 {
1180 case SDL_BLENDMODE_MASK:
1181 /* Enable and set chroma key */
1182 PgSetChromaCx(rdata->gc, PgRGB(255, 255, 255), Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
1183 PgChromaOnCx(rdata->gc);
1184 break;
1185 case SDL_BLENDMODE_BLEND:
1186 /* Enable and set chroma key and alpha blending */
1187 PgSetChromaCx(rdata->gc, PgRGB(255, 255, 255), Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
1188 PgChromaOnCx(rdata->gc);
1189 PgSetAlphaCx(rdata->gc, Pg_ALPHA_OP_SRC_GLOBAL | Pg_BLEND_SRC_As | Pg_BLEND_DST_1mAs, NULL, NULL, texture->a, 0);
1190 PgAlphaOnCx(rdata->gc);
1191 break;
1192 case SDL_BLENDMODE_ADD:
1193 /* Enable and set chroma key and alpha blending */
1194 PgSetChromaCx(rdata->gc, PgRGB(255, 255, 255), Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
1195 PgChromaOnCx(rdata->gc);
1196 PgSetAlphaCx(rdata->gc, Pg_ALPHA_OP_SRC_GLOBAL | Pg_BLEND_SRC_As | Pg_BLEND_DST_1, NULL, NULL, texture->a, 0);
1197 PgAlphaOnCx(rdata->gc);
1198 break;
1199 case SDL_BLENDMODE_MOD:
1200 /* Enable and set alpha blending */
1201 PgSetAlphaCx(rdata->gc, Pg_BLEND_SRC_0 | Pg_BLEND_DST_S, NULL, NULL, 0, 0);
1202 PgAlphaOnCx(rdata->gc);
1203 break;
1204 case SDL_BLENDMODE_NONE:
1205 default:
1206 /* Do nothing */
1207 break;
1208 }
1209 1313
1210 /* Set source blit area */ 1314 /* Set source blit area */
1211 src_rect.ul.x = srcrect->x; 1315 src_rect.ul.x = srcrect->x;
1212 src_rect.ul.y = srcrect->y; 1316 src_rect.ul.y = srcrect->y;
1213 src_rect.lr.x = srcrect->x + srcrect->w - 1; 1317 src_rect.lr.x = srcrect->x + srcrect->w - 1;
1261 break; 1365 break;
1262 } 1366 }
1263 break; 1367 break;
1264 } 1368 }
1265 1369
1266 /* Switch off graphics context modifiers */ 1370 _photon_reset_blending(renderer, texture->blendMode, SDL_PHOTON_TEXTURE_BLEND);
1267 switch(texture->blendMode)
1268 {
1269 case SDL_BLENDMODE_MASK:
1270 /* Disable chroma key */
1271 PgChromaOffCx(rdata->gc);
1272 break;
1273 case SDL_BLENDMODE_BLEND:
1274 /* Disable chroma key and alpha blending */
1275 PgChromaOffCx(rdata->gc);
1276 PgAlphaOffCx(rdata->gc);
1277 break;
1278 case SDL_BLENDMODE_ADD:
1279 /* Disable chroma key and alpha blending */
1280 PgChromaOffCx(rdata->gc);
1281 PgAlphaOffCx(rdata->gc);
1282 break;
1283 case SDL_BLENDMODE_MOD:
1284 /* Disable chroma key and alpha blending */
1285 PgAlphaOffCx(rdata->gc);
1286 break;
1287 case SDL_BLENDMODE_NONE:
1288 default:
1289 /* Do nothing */
1290 break;
1291 }
1292 1371
1293 return 0; 1372 return 0;
1294 } 1373 }
1295 1374
1296 static void 1375 static void
1350 } 1429 }
1351 1430
1352 /* finish blit */ 1431 /* finish blit */
1353 PgFFlush(Ph_DONE_DRAW); 1432 PgFFlush(Ph_DONE_DRAW);
1354 PgWaitHWIdle(); 1433 PgWaitHWIdle();
1434
1435 /* Check if we are using double buffering */
1436 if ((renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) == SDL_RENDERER_PRESENTFLIP2)
1437 {
1438 rdata->surface_visible_idx=rdata->surface_render_idx;
1439 rdata->surface_render_idx=(rdata->surface_render_idx + 1) % 2;
1440 }
1441
1442 /* Check if we are using triple buffering */
1443 if ((renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) == SDL_RENDERER_PRESENTFLIP3)
1444 {
1445 rdata->surface_visible_idx=rdata->surface_render_idx;
1446 rdata->surface_render_idx=(rdata->surface_render_idx + 1) % 3;
1447 }
1355 } 1448 }
1356 1449
1357 static void 1450 static void
1358 photon_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture) 1451 photon_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture)
1359 { 1452 {