comparison src/video/photon/SDL_photon_render.c @ 3384:04af265172f9

Continue working on 2D support in Photon.
author Mike Gorchak <lestat@i.com.ua>
date Mon, 12 Oct 2009 08:21:43 +0000
parents 90935231e9b6
children fff074de9675
comparison
equal deleted inserted replaced
3383:90935231e9b6 3384:04af265172f9
94 SDL_RENDERER_ACCELERATED), 94 SDL_RENDERER_ACCELERATED),
95 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | 95 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
96 SDL_TEXTUREMODULATE_ALPHA), 96 SDL_TEXTUREMODULATE_ALPHA),
97 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND), 97 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND),
98 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW | 98 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW |
99 SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_BEST), 99 SDL_TEXTURESCALEMODE_FAST),
100 10, 100 10,
101 {SDL_PIXELFORMAT_INDEX8, 101 {SDL_PIXELFORMAT_INDEX8,
102 SDL_PIXELFORMAT_RGB555, 102 SDL_PIXELFORMAT_RGB555,
103 SDL_PIXELFORMAT_RGB565, 103 SDL_PIXELFORMAT_RGB565,
104 SDL_PIXELFORMAT_RGB24, 104 SDL_PIXELFORMAT_RGB24,
165 165
166 /* Set render acceleration flag in case it is accelerated */ 166 /* Set render acceleration flag in case it is accelerated */
167 if ((didata->caps & SDL_PHOTON_ACCELERATED) == SDL_PHOTON_ACCELERATED) { 167 if ((didata->caps & SDL_PHOTON_ACCELERATED) == SDL_PHOTON_ACCELERATED) {
168 renderer->info.flags = SDL_RENDERER_ACCELERATED; 168 renderer->info.flags = SDL_RENDERER_ACCELERATED;
169 } else { 169 } else {
170 renderer->info.flags &= ~(SDL_RENDERER_ACCELERATED); 170 renderer->info.flags = 0;
171 } 171 }
172 172
173 /* Check if upper level requested synchronization on vsync signal */ 173 /* Check if upper level requested synchronization on vsync signal */
174 if ((flags & SDL_RENDERER_PRESENTVSYNC) == SDL_RENDERER_PRESENTVSYNC) { 174 if ((flags & SDL_RENDERER_PRESENTVSYNC) == SDL_RENDERER_PRESENTVSYNC) {
175 rdata->enable_vsync = SDL_TRUE; 175 rdata->enable_vsync = SDL_TRUE;
212 rdata->surface_render_idx = 0; 212 rdata->surface_render_idx = 0;
213 } 213 }
214 } 214 }
215 } 215 }
216 216
217 /* Create new graphics context */ 217 /* Create new graphics context for the renderer */
218 if (rdata->gc==NULL) 218 if (rdata->gc==NULL)
219 { 219 {
220 rdata->gc=PgCreateGC(0); 220 rdata->gc=PgCreateGC(0);
221 PgDefaultGC(rdata->gc); 221 PgDefaultGC(rdata->gc);
222 } 222 }
223 223
224 /* Setup textures supported by current renderer instance */ 224 /* Setup textures supported by current renderer instance */
225 renderer->info.num_texture_formats=1; 225 renderer->info.num_texture_formats=1;
226 renderer->info.texture_formats[0]=didata->current_mode.format; 226 renderer->info.texture_formats[0]=didata->current_mode.format;
227
228 /* Initialize surfaces */
229 _photon_recreate_surfaces(renderer);
230
231 /* Set current scale blitting capabilities */
232 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_OFFSCREEN)
233 {
234 renderer->info.scale_modes=SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW;
235 if ((didata->mode_2dcaps & SDL_VIDEO_CAP_SCALED_BLIT)==SDL_VIDEO_CAP_SCALED_BLIT)
236 {
237 /* This video mode supports hardware scaling */
238 renderer->info.scale_modes|=SDL_TEXTURESCALEMODE_FAST;
239 }
240 }
241 else
242 {
243 /* PhImage blit functions do not support scaling */
244 renderer->info.scale_modes=SDL_TEXTURESCALEMODE_NONE;
245 }
227 246
228 return renderer; 247 return renderer;
229 } 248 }
230 249
231 void 250 void
345 /* Try the hardware accelerated offscreen surfaces first */ 364 /* Try the hardware accelerated offscreen surfaces first */
346 for (it=0; it<rdata->surfaces_count; it++) 365 for (it=0; it<rdata->surfaces_count; it++)
347 { 366 {
348 rdata->osurfaces[it]=PdCreateOffscreenContext(0, window->w, window->h, 367 rdata->osurfaces[it]=PdCreateOffscreenContext(0, window->w, window->h,
349 Pg_OSC_MEM_LINEAR_ACCESSIBLE | Pg_OSC_MEM_PAGE_ALIGN | 368 Pg_OSC_MEM_LINEAR_ACCESSIBLE | Pg_OSC_MEM_PAGE_ALIGN |
350 /* in case if 2D acceleration is not available use CPU optimized surfaces */
351 Pg_OSC_MEM_HINT_CPU_READ | Pg_OSC_MEM_HINT_CPU_WRITE |
352 /* in case if 2D acceleration is available use it */ 369 /* in case if 2D acceleration is available use it */
353 Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE); 370 Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE);
354
355 /* If we can't create an offscreen surface, then fallback to software */ 371 /* If we can't create an offscreen surface, then fallback to software */
356 if (rdata->osurfaces[it]==NULL) 372 if (rdata->osurfaces[it]==NULL)
357 { 373 {
358 /* Destroy previously allocated surface(s) */ 374 /* Destroy previously allocated surface(s) */
359 for (jt = it - 1; jt > 0; jt--) 375 for (jt = it - 1; jt > 0; jt--)
632 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_OFFSCREEN) 648 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_OFFSCREEN)
633 { 649 {
634 /* Try to allocate offscreen memory first */ 650 /* Try to allocate offscreen memory first */
635 tdata->osurface=PdCreateOffscreenContext(0, texture->w, texture->h, 651 tdata->osurface=PdCreateOffscreenContext(0, texture->w, texture->h,
636 Pg_OSC_MEM_LINEAR_ACCESSIBLE | Pg_OSC_MEM_PAGE_ALIGN | 652 Pg_OSC_MEM_LINEAR_ACCESSIBLE | Pg_OSC_MEM_PAGE_ALIGN |
637 /* in case if 2D acceleration is not available use CPU optimized surfaces */
638 Pg_OSC_MEM_HINT_CPU_READ | Pg_OSC_MEM_HINT_CPU_WRITE |
639 /* in case if 2D acceleration is available use it */ 653 /* in case if 2D acceleration is available use it */
640 Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE); 654 Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE);
641 } 655 }
642 656
643 /* Check if offscreen allocation has been failed */ 657 /* Check if offscreen allocation has been failed or not performed */
644 if (tdata->osurface==NULL) 658 if (tdata->osurface==NULL)
645 { 659 {
646 PhPoint_t translation={0, 0}; 660 PhPoint_t translation={0, 0};
647 PhDim_t dimension={texture->w, texture->h}; 661 PhDim_t dimension={texture->w, texture->h};
648 uint32_t image_pfmt=photon_sdl_to_image_pixelformat(didata->current_mode.format); 662 uint32_t image_pfmt=photon_sdl_to_image_pixelformat(didata->current_mode.format);
817 } 831 }
818 832
819 static int 833 static int
820 photon_settexturescalemode(SDL_Renderer * renderer, SDL_Texture * texture) 834 photon_settexturescalemode(SDL_Renderer * renderer, SDL_Texture * texture)
821 { 835 {
822 /* TODO */ 836 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
837
838 switch (texture->scaleMode)
839 {
840 case SDL_TEXTURESCALEMODE_NONE:
841 return 0;
842 case SDL_TEXTURESCALEMODE_FAST:
843 if ((renderer->info.scale_modes & SDL_TEXTURESCALEMODE_FAST)==SDL_TEXTURESCALEMODE_FAST)
844 {
845 return 0;
846 }
847 else
848 {
849 SDL_Unsupported();
850 texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
851 return -1;
852 }
853 break;
854 case SDL_TEXTURESCALEMODE_SLOW:
855 if ((renderer->info.scale_modes & SDL_TEXTURESCALEMODE_SLOW)==SDL_TEXTURESCALEMODE_SLOW)
856 {
857 return 0;
858 }
859 else
860 {
861 SDL_Unsupported();
862 texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
863 return -1;
864 }
865 break;
866 case SDL_TEXTURESCALEMODE_BEST:
867 SDL_Unsupported();
868 texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
869 return -1;
870 default:
871 SDL_Unsupported();
872 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
873 return -1;
874 }
875
823 return -1; 876 return -1;
824 } 877 }
825 878
826 static int 879 static int
827 photon_updatetexture(SDL_Renderer * renderer, SDL_Texture * texture, 880 photon_updatetexture(SDL_Renderer * renderer, SDL_Texture * texture,
935 988
936 static void 989 static void
937 photon_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture, 990 photon_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture,
938 int numrects, const SDL_Rect * rects) 991 int numrects, const SDL_Rect * rects)
939 { 992 {
940 /* TODO */ 993 /* Check, if it is not initialized */
994 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN)
995 {
996 SDL_SetError("Photon: can't update dirty texture for OpenGL ES window");
997 return;
998 }
941 } 999 }
942 1000
943 static int 1001 static int
944 photon_setdrawcolor(SDL_Renderer * renderer) 1002 photon_setdrawcolor(SDL_Renderer * renderer)
945 { 1003 {