Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_photon_render.c @ 3383:90935231e9b6
Continue working on 2D support in Photon
author | Mike Gorchak <lestat@i.com.ua> |
---|---|
date | Sun, 11 Oct 2009 18:45:39 +0000 |
parents | dd105b317335 |
children | 04af265172f9 |
comparison
equal
deleted
inserted
replaced
3382:294fb5e6f301 | 3383:90935231e9b6 |
---|---|
92 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | | 92 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | |
93 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_PRESENTDISCARD | | 93 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_PRESENTDISCARD | |
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 | | 97 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND), |
98 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), | |
99 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW | | 98 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW | |
100 SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_BEST), | 99 SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_BEST), |
101 10, | 100 10, |
102 {SDL_PIXELFORMAT_INDEX8, | 101 {SDL_PIXELFORMAT_INDEX8, |
103 SDL_PIXELFORMAT_RGB555, | 102 SDL_PIXELFORMAT_RGB555, |
220 { | 219 { |
221 rdata->gc=PgCreateGC(0); | 220 rdata->gc=PgCreateGC(0); |
222 PgDefaultGC(rdata->gc); | 221 PgDefaultGC(rdata->gc); |
223 } | 222 } |
224 | 223 |
224 /* Setup textures supported by current renderer instance */ | |
225 renderer->info.num_texture_formats=1; | |
226 renderer->info.texture_formats[0]=didata->current_mode.format; | |
227 | |
225 return renderer; | 228 return renderer; |
226 } | 229 } |
227 | 230 |
228 void | 231 void |
229 photon_addrenderdriver(_THIS) | 232 photon_addrenderdriver(_THIS) |
341 | 344 |
342 /* Try the hardware accelerated offscreen surfaces first */ | 345 /* Try the hardware accelerated offscreen surfaces first */ |
343 for (it=0; it<rdata->surfaces_count; it++) | 346 for (it=0; it<rdata->surfaces_count; it++) |
344 { | 347 { |
345 rdata->osurfaces[it]=PdCreateOffscreenContext(0, window->w, window->h, | 348 rdata->osurfaces[it]=PdCreateOffscreenContext(0, window->w, window->h, |
346 Pg_OSC_MEM_LINEAR_ACCESSIBLE | | 349 Pg_OSC_MEM_LINEAR_ACCESSIBLE | Pg_OSC_MEM_PAGE_ALIGN | |
347 /* in case if 2D acceleration is not available use CPU optimized surfaces */ | 350 /* in case if 2D acceleration is not available use CPU optimized surfaces */ |
348 Pg_OSC_MEM_HINT_CPU_READ | Pg_OSC_MEM_HINT_CPU_WRITE | | 351 Pg_OSC_MEM_HINT_CPU_READ | Pg_OSC_MEM_HINT_CPU_WRITE | |
349 /* in case if 2D acceleration is available use it */ | 352 /* in case if 2D acceleration is available use it */ |
350 Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE); | 353 Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE); |
351 | 354 |
443 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_UNKNOWN; | 446 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_UNKNOWN; |
444 } | 447 } |
445 } | 448 } |
446 break; | 449 break; |
447 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 450 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
451 default: | |
448 { | 452 { |
449 /* do nothing with surface allocation */ | 453 /* do nothing with surface allocation */ |
450 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_UNKNOWN; | 454 rdata->surfaces_type=SDL_PHOTON_SURFTYPE_UNKNOWN; |
451 } | 455 } |
452 break; | 456 break; |
491 break; | 495 break; |
492 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 496 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
493 PgSetGCCx(rdata->pcontexts[rdata->surface_render_idx], rdata->gc); | 497 PgSetGCCx(rdata->pcontexts[rdata->surface_render_idx], rdata->gc); |
494 break; | 498 break; |
495 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 499 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
500 default: | |
496 break; | 501 break; |
497 } | 502 } |
498 | 503 |
499 return 0; | 504 return 0; |
500 } | 505 } |
518 break; | 523 break; |
519 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 524 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
520 PmMemFlush(rdata->pcontexts[rdata->surface_visible_idx], rdata->psurfaces[rdata->surface_visible_idx]); | 525 PmMemFlush(rdata->pcontexts[rdata->surface_visible_idx], rdata->psurfaces[rdata->surface_visible_idx]); |
521 break; | 526 break; |
522 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 527 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
528 default: | |
523 return; | 529 return; |
524 } | 530 } |
525 } | 531 } |
526 | 532 |
527 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window)); | 533 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window)); |
536 break; | 542 break; |
537 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 543 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
538 PgDrawPhImageRectv(&src_point, rdata->psurfaces[rdata->surface_visible_idx], rect, 0); | 544 PgDrawPhImageRectv(&src_point, rdata->psurfaces[rdata->surface_visible_idx], rect, 0); |
539 break; | 545 break; |
540 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 546 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
547 default: | |
541 break; | 548 break; |
542 } | 549 } |
543 } | 550 } |
544 | 551 |
545 /****************************************************************************/ | 552 /****************************************************************************/ |
565 break; | 572 break; |
566 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 573 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
567 PgSetGCCx(rdata->pcontexts[rdata->surface_render_idx], rdata->gc); | 574 PgSetGCCx(rdata->pcontexts[rdata->surface_render_idx], rdata->gc); |
568 break; | 575 break; |
569 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 576 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
577 default: | |
570 break; | 578 break; |
571 } | 579 } |
572 | 580 |
573 return 0; | 581 return 0; |
574 } | 582 } |
580 } | 588 } |
581 | 589 |
582 static int | 590 static int |
583 photon_createtexture(SDL_Renderer * renderer, SDL_Texture * texture) | 591 photon_createtexture(SDL_Renderer * renderer, SDL_Texture * texture) |
584 { | 592 { |
585 SDL_RenderData *renderdata = (SDL_RenderData *) renderer->driverdata; | 593 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; |
586 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 594 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
587 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 595 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
596 SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata; | |
588 SDL_TextureData *tdata = NULL; | 597 SDL_TextureData *tdata = NULL; |
598 uint32_t it; | |
599 | |
600 /* Check, if it is not initialized */ | |
601 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
602 { | |
603 SDL_SetError("Photon: can't create texture for OpenGL ES window"); | |
604 return -1; | |
605 } | |
606 | |
607 /* Check if requested texture format is supported */ | |
608 for (it=0; it<renderer->info.num_texture_formats; it++) | |
609 { | |
610 if (renderer->info.texture_formats[it]==texture->format) | |
611 { | |
612 break; | |
613 } | |
614 } | |
615 if (it==renderer->info.num_texture_formats) | |
616 { | |
617 SDL_SetError("Photon: requested texture format is not supported"); | |
618 return -1; | |
619 } | |
589 | 620 |
590 /* Allocate texture driver data */ | 621 /* Allocate texture driver data */ |
591 tdata = (SDL_TextureData *) SDL_calloc(1, sizeof(SDL_TextureData)); | 622 tdata = (SDL_TextureData *) SDL_calloc(1, sizeof(SDL_TextureData)); |
592 if (tdata == NULL) { | 623 if (tdata == NULL) { |
593 SDL_OutOfMemory(); | 624 SDL_OutOfMemory(); |
594 return -1; | 625 return -1; |
595 } | 626 } |
596 | 627 |
597 /* Set texture driver data */ | 628 /* Set texture driver data */ |
598 texture->driverdata = tdata; | 629 texture->driverdata = tdata; |
630 | |
631 /* Try offscreen allocation only in case if displayable buffers are also offscreen */ | |
632 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_OFFSCREEN) | |
633 { | |
634 /* Try to allocate offscreen memory first */ | |
635 tdata->osurface=PdCreateOffscreenContext(0, texture->w, texture->h, | |
636 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 */ | |
640 Pg_OSC_MEM_2D_WRITABLE | Pg_OSC_MEM_2D_READABLE); | |
641 } | |
642 | |
643 /* Check if offscreen allocation has been failed */ | |
644 if (tdata->osurface==NULL) | |
645 { | |
646 PhPoint_t translation={0, 0}; | |
647 PhDim_t dimension={texture->w, texture->h}; | |
648 uint32_t image_pfmt=photon_sdl_to_image_pixelformat(didata->current_mode.format); | |
649 | |
650 /* Allocate photon image */ | |
651 if (image_pfmt==Pg_IMAGE_PALETTE_BYTE) | |
652 { | |
653 tdata->psurface=PhCreateImage(NULL, texture->w, texture->h, | |
654 image_pfmt, NULL, 256, 1); | |
655 } | |
656 else | |
657 { | |
658 tdata->psurface=PhCreateImage(NULL, texture->w, texture->h, | |
659 image_pfmt, NULL, 0, 1); | |
660 } | |
661 | |
662 if (tdata->psurface==NULL) | |
663 { | |
664 return -1; | |
665 } | |
666 | |
667 /* Create memory context for PhImage_t */ | |
668 tdata->pcontext=PmMemCreateMC(tdata->psurface, &dimension, &translation); | |
669 if (tdata->pcontext==NULL) | |
670 { | |
671 /* Destroy PhImage */ | |
672 if (tdata->psurface!=NULL) | |
673 { | |
674 if (tdata->psurface->palette!=NULL) | |
675 { | |
676 SDL_free(tdata->psurface->palette); | |
677 tdata->psurface->palette=NULL; | |
678 } | |
679 /* Destroy shared memory for PhImage_t */ | |
680 PgShmemDestroy(tdata->psurface->image); | |
681 tdata->psurface->image=NULL; | |
682 SDL_free(tdata->psurface); | |
683 tdata->psurface=NULL; | |
684 } | |
685 } | |
686 tdata->surface_type=SDL_PHOTON_SURFTYPE_PHIMAGE; | |
687 } | |
688 else | |
689 { | |
690 tdata->surface_type=SDL_PHOTON_SURFTYPE_OFFSCREEN; | |
691 } | |
692 | |
693 return 0; | |
599 } | 694 } |
600 | 695 |
601 static int | 696 static int |
602 photon_querytexturepixels(SDL_Renderer * renderer, SDL_Texture * texture, | 697 photon_querytexturepixels(SDL_Renderer * renderer, SDL_Texture * texture, |
603 void **pixels, int *pitch) | 698 void **pixels, int *pitch) |
604 { | 699 { |
700 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
701 SDL_TextureData* tdata=(SDL_TextureData*)texture->driverdata; | |
702 | |
703 /* Check, if it is not initialized */ | |
704 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
705 { | |
706 SDL_SetError("Photon: can't query texture pixels for OpenGL ES window"); | |
707 return -1; | |
708 } | |
709 | |
710 /* Clear outcoming parameters */ | |
711 *pixels=NULL; | |
712 *pitch=0; | |
713 | |
714 switch (tdata->surface_type) | |
715 { | |
716 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | |
717 *pixels=(void*)PdGetOffscreenContextPtr(tdata->osurface); | |
718 *pitch=tdata->osurface->pitch; | |
719 break; | |
720 case SDL_PHOTON_SURFTYPE_PHIMAGE: | |
721 *pixels=(void*)tdata->psurface->image; | |
722 *pitch=tdata->psurface->bpl; | |
723 break; | |
724 default: | |
725 break; | |
726 } | |
727 | |
728 return 0; | |
605 } | 729 } |
606 | 730 |
607 static int | 731 static int |
608 photon_settexturepalette(SDL_Renderer * renderer, SDL_Texture * texture, | 732 photon_settexturepalette(SDL_Renderer * renderer, SDL_Texture * texture, |
609 const SDL_Color * colors, int firstcolor, | 733 const SDL_Color * colors, int firstcolor, |
610 int ncolors) | 734 int ncolors) |
611 { | 735 { |
736 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
737 SDL_TextureData* tdata=(SDL_TextureData*)texture->driverdata; | |
738 | |
739 /* Check, if it is not initialized */ | |
740 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
741 { | |
742 SDL_SetError("Photon: can't set texture palette for OpenGL ES window"); | |
743 return -1; | |
744 } | |
745 | |
746 if (texture->format!=SDL_PIXELFORMAT_INDEX8) | |
747 { | |
748 SDL_SetError("Photon: can't set palette for non-paletted texture"); | |
749 return -1; | |
750 } | |
751 | |
752 return -1; | |
612 } | 753 } |
613 | 754 |
614 static int | 755 static int |
615 photon_gettexturepalette(SDL_Renderer * renderer, SDL_Texture * texture, | 756 photon_gettexturepalette(SDL_Renderer * renderer, SDL_Texture * texture, |
616 SDL_Color * colors, int firstcolor, int ncolors) | 757 SDL_Color * colors, int firstcolor, int ncolors) |
617 { | 758 { |
759 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
760 SDL_TextureData* tdata=(SDL_TextureData*)texture->driverdata; | |
761 | |
762 /* Check, if it is not initialized */ | |
763 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
764 { | |
765 SDL_SetError("Photon: can't return texture palette for OpenGL ES window"); | |
766 return -1; | |
767 } | |
768 | |
769 if (texture->format!=SDL_PIXELFORMAT_INDEX8) | |
770 { | |
771 SDL_SetError("Photon: can't return palette for non-paletted texture"); | |
772 return -1; | |
773 } | |
774 | |
775 return -1; | |
618 } | 776 } |
619 | 777 |
620 static int | 778 static int |
621 photon_settexturecolormod(SDL_Renderer * renderer, SDL_Texture * texture) | 779 photon_settexturecolormod(SDL_Renderer * renderer, SDL_Texture * texture) |
622 { | 780 { |
781 /* TODO */ | |
782 return -1; | |
623 } | 783 } |
624 | 784 |
625 static int | 785 static int |
626 photon_settexturealphamod(SDL_Renderer * renderer, SDL_Texture * texture) | 786 photon_settexturealphamod(SDL_Renderer * renderer, SDL_Texture * texture) |
627 { | 787 { |
788 /* TODO */ | |
789 return -1; | |
628 } | 790 } |
629 | 791 |
630 static int | 792 static int |
631 photon_settextureblendmode(SDL_Renderer * renderer, SDL_Texture * texture) | 793 photon_settextureblendmode(SDL_Renderer * renderer, SDL_Texture * texture) |
632 { | 794 { |
795 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
796 | |
797 /* Check, if it is not initialized */ | |
798 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
799 { | |
800 SDL_SetError("Photon: can't set texture blend mode for OpenGL ES window"); | |
801 return -1; | |
802 } | |
803 | |
804 switch (texture->blendMode) | |
805 { | |
806 case SDL_BLENDMODE_NONE: | |
807 case SDL_BLENDMODE_MASK: | |
808 case SDL_BLENDMODE_BLEND: | |
809 return 0; | |
810 case SDL_BLENDMODE_ADD: | |
811 case SDL_BLENDMODE_MOD: | |
812 default: | |
813 SDL_Unsupported(); | |
814 texture->blendMode = SDL_BLENDMODE_NONE; | |
815 return -1; | |
816 } | |
633 } | 817 } |
634 | 818 |
635 static int | 819 static int |
636 photon_settexturescalemode(SDL_Renderer * renderer, SDL_Texture * texture) | 820 photon_settexturescalemode(SDL_Renderer * renderer, SDL_Texture * texture) |
637 { | 821 { |
822 /* TODO */ | |
823 return -1; | |
638 } | 824 } |
639 | 825 |
640 static int | 826 static int |
641 photon_updatetexture(SDL_Renderer * renderer, SDL_Texture * texture, | 827 photon_updatetexture(SDL_Renderer * renderer, SDL_Texture * texture, |
642 const SDL_Rect * rect, const void *pixels, int pitch) | 828 const SDL_Rect * rect, const void *pixels, int pitch) |
643 { | 829 { |
830 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
831 SDL_TextureData* tdata=(SDL_TextureData*)texture->driverdata; | |
832 | |
833 uint8_t* src=(uint8_t*)pixels; | |
834 uint8_t* dst; | |
835 uint32_t dst_pitch; | |
836 uint32_t it; | |
837 uint32_t copy_length; | |
838 | |
839 /* Check, if it is not initialized */ | |
840 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
841 { | |
842 SDL_SetError("Photon: can't update texture for OpenGL ES window"); | |
843 return -1; | |
844 } | |
845 | |
846 switch (tdata->surface_type) | |
847 { | |
848 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | |
849 dst=(uint8_t*)PdGetOffscreenContextPtr(tdata->osurface); | |
850 dst_pitch=tdata->osurface->pitch; | |
851 if (dst==NULL) | |
852 { | |
853 SDL_SetError("Photon: can't get pointer to texture surface"); | |
854 return -1; | |
855 } | |
856 break; | |
857 case SDL_PHOTON_SURFTYPE_PHIMAGE: | |
858 dst=(uint8_t*)tdata->psurface->image; | |
859 dst_pitch=tdata->psurface->bpl; | |
860 if (dst==NULL) | |
861 { | |
862 SDL_SetError("Photon: can't get pointer to texture surface"); | |
863 return -1; | |
864 } | |
865 break; | |
866 default: | |
867 SDL_SetError("Photon: invalid internal surface type"); | |
868 return -1; | |
869 } | |
870 | |
871 dst+=rect->y * dst_pitch + rect->x * SDL_BYTESPERPIXEL(texture->format); | |
872 copy_length=rect->w * SDL_BYTESPERPIXEL(texture->format); | |
873 for (it = 0; it < rect->h; it++) | |
874 { | |
875 SDL_memcpy(dst, src, copy_length); | |
876 src+=pitch; | |
877 dst+=dst_pitch; | |
878 } | |
879 | |
880 return 0; | |
644 } | 881 } |
645 | 882 |
646 static int | 883 static int |
647 photon_locktexture(SDL_Renderer * renderer, SDL_Texture * texture, | 884 photon_locktexture(SDL_Renderer * renderer, SDL_Texture * texture, |
648 const SDL_Rect * rect, int markDirty, void **pixels, | 885 const SDL_Rect * rect, int markDirty, void **pixels, |
649 int *pitch) | 886 int *pitch) |
650 { | 887 { |
888 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
889 SDL_TextureData* tdata=(SDL_TextureData*)texture->driverdata; | |
890 | |
891 /* Check, if it is not initialized */ | |
892 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
893 { | |
894 SDL_SetError("Photon: can't lock texture for OpenGL ES window"); | |
895 return -1; | |
896 } | |
897 | |
898 /* Clear outcoming parameters */ | |
899 *pixels=NULL; | |
900 *pitch=0; | |
901 | |
902 switch (tdata->surface_type) | |
903 { | |
904 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | |
905 *pixels=(void*)((uint8_t*)PdGetOffscreenContextPtr(tdata->osurface) + | |
906 rect->y * tdata->osurface->pitch + | |
907 rect->x * SDL_BYTESPERPIXEL(texture->format)); | |
908 *pitch=tdata->osurface->pitch; | |
909 break; | |
910 case SDL_PHOTON_SURFTYPE_PHIMAGE: | |
911 *pixels=(void*)((uint8_t*)tdata->psurface->image + | |
912 rect->y * tdata->osurface->pitch + | |
913 rect->x * SDL_BYTESPERPIXEL(texture->format)); | |
914 *pitch=tdata->psurface->bpl; | |
915 break; | |
916 default: | |
917 break; | |
918 } | |
919 | |
920 return 0; | |
651 } | 921 } |
652 | 922 |
653 static void | 923 static void |
654 photon_unlocktexture(SDL_Renderer * renderer, SDL_Texture * texture) | 924 photon_unlocktexture(SDL_Renderer * renderer, SDL_Texture * texture) |
655 { | 925 { |
926 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
927 | |
928 /* Check, if it is not initialized */ | |
929 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
930 { | |
931 SDL_SetError("Photon: can't unlock texture for OpenGL ES window"); | |
932 return; | |
933 } | |
656 } | 934 } |
657 | 935 |
658 static void | 936 static void |
659 photon_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture, | 937 photon_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture, |
660 int numrects, const SDL_Rect * rects) | 938 int numrects, const SDL_Rect * rects) |
661 { | 939 { |
940 /* TODO */ | |
662 } | 941 } |
663 | 942 |
664 static int | 943 static int |
665 photon_setdrawcolor(SDL_Renderer * renderer) | 944 photon_setdrawcolor(SDL_Renderer * renderer) |
666 { | 945 { |
667 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | 946 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; |
947 | |
948 /* Check, if it is not initialized */ | |
949 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
950 { | |
951 SDL_SetError("Photon: can't set draw color for OpenGL ES window"); | |
952 return -1; | |
953 } | |
668 | 954 |
669 switch (rdata->surfaces_type) | 955 switch (rdata->surfaces_type) |
670 { | 956 { |
671 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | 957 case SDL_PHOTON_SURFTYPE_OFFSCREEN: |
672 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 958 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
673 PgSetFillColorCx(rdata->gc, PgRGB(renderer->r, renderer->g, renderer->b)); | 959 PgSetFillColorCx(rdata->gc, PgRGB(renderer->r, renderer->g, renderer->b)); |
674 PgSetStrokeColorCx(rdata->gc, PgRGB(renderer->r, renderer->g, renderer->b)); | 960 PgSetStrokeColorCx(rdata->gc, PgRGB(renderer->r, renderer->g, renderer->b)); |
675 break; | 961 break; |
676 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 962 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
677 break; | 963 default: |
678 } | 964 break; |
965 } | |
966 | |
967 return 0; | |
679 } | 968 } |
680 | 969 |
681 static int | 970 static int |
682 photon_setdrawblendmode(SDL_Renderer * renderer) | 971 photon_setdrawblendmode(SDL_Renderer * renderer) |
683 { | 972 { |
973 /* TODO */ | |
974 return -1; | |
684 } | 975 } |
685 | 976 |
686 static int | 977 static int |
687 photon_renderpoint(SDL_Renderer * renderer, int x, int y) | 978 photon_renderpoint(SDL_Renderer * renderer, int x, int y) |
688 { | 979 { |
689 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | 980 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; |
981 | |
982 /* Check, if it is not initialized */ | |
983 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
984 { | |
985 SDL_SetError("Photon: can't render point in OpenGL ES window"); | |
986 return -1; | |
987 } | |
690 | 988 |
691 switch (rdata->surfaces_type) | 989 switch (rdata->surfaces_type) |
692 { | 990 { |
693 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | 991 case SDL_PHOTON_SURFTYPE_OFFSCREEN: |
694 PgDrawIPixelCx(rdata->osurfaces[rdata->surface_render_idx], x, y); | 992 PgDrawIPixelCx(rdata->osurfaces[rdata->surface_render_idx], x, y); |
695 break; | 993 break; |
696 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 994 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
697 PgDrawIPixelCx(rdata->pcontexts[rdata->surface_render_idx], x, y); | 995 PgDrawIPixelCx(rdata->pcontexts[rdata->surface_render_idx], x, y); |
698 break; | 996 break; |
699 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 997 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
700 break; | 998 default: |
701 } | 999 break; |
1000 } | |
1001 | |
1002 return 0; | |
702 } | 1003 } |
703 | 1004 |
704 static int | 1005 static int |
705 photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | 1006 photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) |
706 { | 1007 { |
707 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | 1008 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; |
1009 | |
1010 /* Check, if it is not initialized */ | |
1011 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
1012 { | |
1013 SDL_SetError("Photon: can't render line in OpenGL ES window"); | |
1014 return -1; | |
1015 } | |
708 | 1016 |
709 switch (rdata->surfaces_type) | 1017 switch (rdata->surfaces_type) |
710 { | 1018 { |
711 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | 1019 case SDL_PHOTON_SURFTYPE_OFFSCREEN: |
712 PgDrawILineCx(rdata->osurfaces[rdata->surface_render_idx], x1, y1, x2, y2); | 1020 PgDrawILineCx(rdata->osurfaces[rdata->surface_render_idx], x1, y1, x2, y2); |
713 break; | 1021 break; |
714 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 1022 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
715 PgDrawILineCx(rdata->pcontexts[rdata->surface_render_idx], x1, y1, x2, y2); | 1023 PgDrawILineCx(rdata->pcontexts[rdata->surface_render_idx], x1, y1, x2, y2); |
716 break; | 1024 break; |
717 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 1025 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
718 break; | 1026 default: |
719 } | 1027 break; |
1028 } | |
1029 | |
1030 return 0; | |
720 } | 1031 } |
721 | 1032 |
722 static int | 1033 static int |
723 photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect) | 1034 photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect) |
724 { | 1035 { |
725 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | 1036 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; |
1037 | |
1038 /* Check, if it is not initialized */ | |
1039 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
1040 { | |
1041 SDL_SetError("Photon: can't render filled box in OpenGL ES window"); | |
1042 return -1; | |
1043 } | |
726 | 1044 |
727 switch (rdata->surfaces_type) | 1045 switch (rdata->surfaces_type) |
728 { | 1046 { |
729 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | 1047 case SDL_PHOTON_SURFTYPE_OFFSCREEN: |
730 PgDrawIRectCx(rdata->osurfaces[rdata->surface_render_idx], rect->x, rect->y, rect->w+rect->x-1, rect->h+rect->y-1, Pg_DRAW_FILL); | 1048 PgDrawIRectCx(rdata->osurfaces[rdata->surface_render_idx], rect->x, rect->y, rect->w+rect->x-1, rect->h+rect->y-1, Pg_DRAW_FILL); |
731 break; | 1049 break; |
732 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 1050 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
733 PgDrawIRectCx(rdata->pcontexts[rdata->surface_render_idx], rect->x, rect->y, rect->w+rect->x-1, rect->h+rect->y-1, Pg_DRAW_FILL); | 1051 PgDrawIRectCx(rdata->pcontexts[rdata->surface_render_idx], rect->x, rect->y, rect->w+rect->x-1, rect->h+rect->y-1, Pg_DRAW_FILL); |
734 break; | 1052 break; |
735 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 1053 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
1054 default: | |
736 break; | 1055 break; |
737 } | 1056 } |
738 } | 1057 } |
739 | 1058 |
740 static int | 1059 static int |
741 photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture, | 1060 photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture, |
742 const SDL_Rect * srcrect, const SDL_Rect * dstrect) | 1061 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
743 { | 1062 { |
1063 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
1064 SDL_TextureData* tdata=(SDL_TextureData*)texture->driverdata; | |
1065 | |
1066 PhRect_t src_rect; | |
1067 PhRect_t dst_rect; | |
1068 PhPoint_t dst_point; | |
1069 | |
1070 /* Check, if it is not initialized */ | |
1071 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
1072 { | |
1073 SDL_SetError("Photon: can't blit textures in OpenGL ES window"); | |
1074 return -1; | |
1075 } | |
1076 | |
1077 /* Switch on requested graphics context modifiers */ | |
1078 switch(texture->blendMode) | |
1079 { | |
1080 case SDL_BLENDMODE_MASK: | |
1081 /* Enable and set chroma key */ | |
1082 PgChromaOnCx(rdata->gc); | |
1083 PgSetChromaCx(rdata->gc, PgRGB(255, 255, 255), Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW); | |
1084 break; | |
1085 case SDL_BLENDMODE_BLEND: | |
1086 /* TODO */ | |
1087 break; | |
1088 case SDL_BLENDMODE_NONE: | |
1089 default: | |
1090 /* Do nothing */ | |
1091 break; | |
1092 } | |
1093 | |
1094 /* Set source blit area */ | |
1095 src_rect.ul.x = srcrect->x; | |
1096 src_rect.ul.y = srcrect->y; | |
1097 src_rect.lr.x = srcrect->x + srcrect->w - 1; | |
1098 src_rect.lr.y = srcrect->y + srcrect->h - 1; | |
1099 | |
1100 /* Set destination blit area */ | |
1101 dst_rect.ul.x = dstrect->x; | |
1102 dst_rect.ul.y = dstrect->y; | |
1103 dst_rect.lr.x = dstrect->x + dstrect->w - 1; | |
1104 dst_rect.lr.y = dstrect->y + dstrect->h - 1; | |
1105 | |
1106 /* Set destination point */ | |
1107 dst_point.x = dstrect->x; | |
1108 dst_point.y = dstrect->y; | |
1109 | |
1110 /* Do blit */ | |
1111 switch (rdata->surfaces_type) | |
1112 { | |
1113 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | |
1114 /* two possible combinations */ | |
1115 switch (tdata->surface_type) | |
1116 { | |
1117 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | |
1118 /* easiest full accelerated combination: offscreen->offscreen */ | |
1119 PgContextBlitCx(rdata->osurfaces[rdata->surface_render_idx], tdata->osurface, | |
1120 &src_rect, rdata->osurfaces[rdata->surface_render_idx], &dst_rect); | |
1121 break; | |
1122 case SDL_PHOTON_SURFTYPE_PHIMAGE: | |
1123 /* not accelerated combination: PhImage->offscreen */ | |
1124 /* scaling is not supported in this method */ | |
1125 PgDrawPhImageRectCxv(rdata->osurfaces[rdata->surface_render_idx], &dst_point, | |
1126 tdata->psurface, &src_rect, 0); | |
1127 break; | |
1128 default: | |
1129 break; | |
1130 } | |
1131 break; | |
1132 case SDL_PHOTON_SURFTYPE_PHIMAGE: | |
1133 /* two possible combinations */ | |
1134 switch (tdata->surface_type) | |
1135 { | |
1136 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | |
1137 /* not supported combination: offscreen->PhImage */ | |
1138 return -1; | |
1139 case SDL_PHOTON_SURFTYPE_PHIMAGE: | |
1140 /* not accelerated combination, but fast: PhImage->PhImage */ | |
1141 /* scaling is not supported in this method */ | |
1142 PgDrawPhImageRectCxv(rdata->pcontexts[rdata->surface_render_idx], &dst_point, tdata->psurface, &src_rect, 0); | |
1143 break; | |
1144 default: | |
1145 break; | |
1146 } | |
1147 break; | |
1148 } | |
1149 | |
1150 /* Switch off graphics context modifiers */ | |
1151 switch(texture->blendMode) | |
1152 { | |
1153 case SDL_BLENDMODE_MASK: | |
1154 /* Disable chroma key */ | |
1155 PgChromaOffCx(rdata->gc); | |
1156 break; | |
1157 case SDL_BLENDMODE_BLEND: | |
1158 /* TODO */ | |
1159 break; | |
1160 case SDL_BLENDMODE_NONE: | |
1161 default: | |
1162 /* Do nothing */ | |
1163 break; | |
1164 } | |
1165 | |
1166 return 0; | |
744 } | 1167 } |
745 | 1168 |
746 static void | 1169 static void |
747 photon_renderpresent(SDL_Renderer * renderer) | 1170 photon_renderpresent(SDL_Renderer * renderer) |
748 { | 1171 { |
750 SDL_Window *window = window=SDL_GetWindowFromID(renderer->window); | 1173 SDL_Window *window = window=SDL_GetWindowFromID(renderer->window); |
751 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; | 1174 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
752 PhRect_t src_rect; | 1175 PhRect_t src_rect; |
753 PhPoint_t src_point; | 1176 PhPoint_t src_point; |
754 | 1177 |
1178 /* Check, if it is not initialized */ | |
1179 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
1180 { | |
1181 SDL_SetError("Photon: can't render present for OpenGL ES window"); | |
1182 return; | |
1183 } | |
1184 | |
755 /* Flush all undrawn graphics data to surface */ | 1185 /* Flush all undrawn graphics data to surface */ |
756 switch (rdata->surfaces_type) | 1186 switch (rdata->surfaces_type) |
757 { | 1187 { |
758 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | 1188 case SDL_PHOTON_SURFTYPE_OFFSCREEN: |
759 PgFlushCx(rdata->osurfaces[rdata->surface_render_idx]); | 1189 PgFlushCx(rdata->osurfaces[rdata->surface_render_idx]); |
761 break; | 1191 break; |
762 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 1192 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
763 PmMemFlush(rdata->pcontexts[rdata->surface_render_idx], rdata->psurfaces[rdata->surface_render_idx]); | 1193 PmMemFlush(rdata->pcontexts[rdata->surface_render_idx], rdata->psurfaces[rdata->surface_render_idx]); |
764 break; | 1194 break; |
765 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 1195 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
1196 default: | |
766 return; | 1197 return; |
767 } | 1198 } |
768 | 1199 |
769 PgFFlush(Ph_START_DRAW); | 1200 PgFFlush(Ph_START_DRAW); |
770 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window)); | 1201 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window)); |
785 break; | 1216 break; |
786 case SDL_PHOTON_SURFTYPE_PHIMAGE: | 1217 case SDL_PHOTON_SURFTYPE_PHIMAGE: |
787 PgDrawPhImagev(&src_point, rdata->psurfaces[rdata->surface_render_idx], 0); | 1218 PgDrawPhImagev(&src_point, rdata->psurfaces[rdata->surface_render_idx], 0); |
788 break; | 1219 break; |
789 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 1220 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
1221 default: | |
790 break; | 1222 break; |
791 } | 1223 } |
792 | 1224 |
793 /* finish blit */ | 1225 /* finish blit */ |
794 PgFFlush(Ph_DONE_DRAW); | 1226 PgFFlush(Ph_DONE_DRAW); |
796 } | 1228 } |
797 | 1229 |
798 static void | 1230 static void |
799 photon_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture) | 1231 photon_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture) |
800 { | 1232 { |
1233 SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata; | |
1234 SDL_TextureData* tdata=(SDL_TextureData*)texture->driverdata; | |
1235 | |
1236 /* Check if partially created texture must be destroyed */ | |
1237 if (tdata==NULL) | |
1238 { | |
1239 return; | |
1240 } | |
1241 | |
1242 /* Check, if it is not initialized */ | |
1243 if (rdata->surfaces_type==SDL_PHOTON_SURFTYPE_UNKNOWN) | |
1244 { | |
1245 SDL_SetError("Photon: can't destroy texture for OpenGL ES window"); | |
1246 return; | |
1247 } | |
1248 | |
1249 switch (tdata->surface_type) | |
1250 { | |
1251 case SDL_PHOTON_SURFTYPE_OFFSCREEN: | |
1252 if (tdata->osurface!=NULL) | |
1253 { | |
1254 PhDCRelease(tdata->osurface); | |
1255 tdata->osurface = NULL; | |
1256 } | |
1257 break; | |
1258 case SDL_PHOTON_SURFTYPE_PHIMAGE: | |
1259 if (tdata->pcontext!=NULL) | |
1260 { | |
1261 PmMemReleaseMC(tdata->pcontext); | |
1262 tdata->pcontext=NULL; | |
1263 } | |
1264 | |
1265 if (tdata->psurface!=NULL) | |
1266 { | |
1267 if (tdata->psurface->palette!=NULL) | |
1268 { | |
1269 SDL_free(tdata->psurface->palette); | |
1270 tdata->psurface->palette=NULL; | |
1271 } | |
1272 /* Destroy shared memory for PhImage_t */ | |
1273 PgShmemDestroy(tdata->psurface->image); | |
1274 tdata->psurface->image=NULL; | |
1275 SDL_free(tdata->psurface); | |
1276 tdata->psurface=NULL; | |
1277 } | |
1278 break; | |
1279 default: | |
1280 break; | |
1281 } | |
801 } | 1282 } |
802 | 1283 |
803 static void | 1284 static void |
804 photon_destroyrenderer(SDL_Renderer * renderer) | 1285 photon_destroyrenderer(SDL_Renderer * renderer) |
805 { | 1286 { |
855 } | 1336 } |
856 } | 1337 } |
857 } | 1338 } |
858 break; | 1339 break; |
859 case SDL_PHOTON_SURFTYPE_UNKNOWN: | 1340 case SDL_PHOTON_SURFTYPE_UNKNOWN: |
1341 default: | |
860 { | 1342 { |
861 /* nothing to do */ | 1343 /* nothing to do */ |
862 } | 1344 } |
863 break; | 1345 break; |
864 } | 1346 } |