Include anf fix vita2d renderer
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
diff --git a/Makefile.vita.dolce b/Makefile.vita.dolce
deleted file mode 100644
index d646d43..0000000
--- a/Makefile.vita.dolce
+++ /dev/null
@@ -1,58 +0,0 @@
-# Based on port by xerpi
-# Makefile to build the SDL library
-
-TARGET_LIB = libSDL2.a
-
-SOURCES = \
- src/*.c \
- src/atomic/*.c \
- src/audio/*.c \
- src/audio/vita/*.c \
- src/cpuinfo/*.c \
- src/events/*.c \
- src/file/*.c \
- src/haptic/*.c \
- src/haptic/dummy/*.c \
- src/joystick/*.c \
- src/joystick/vita/*.c \
- src/loadso/dummy/*.c \
- src/power/*.c \
- src/power/vita/*.c \
- src/filesystem/vita/*.c \
- src/render/*.c \
- src/render/software/*.c \
- src/render/vitagles2/*.c \
- src/sensor/*.c \
- src/sensor/dummy/*.c \
- src/stdlib/*.c \
- src/thread/*.c \
- src/thread/generic/SDL_systls.c \
- src/thread/vita/*.c \
- src/timer/*.c \
- src/timer/vita/*.c \
- src/video/*.c \
- src/video/vita/*.c \
- src/video/yuv2rgb/*.c \
-
-OBJS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
-
-PREFIX = arm-dolce-eabi
-CC = $(PREFIX)-gcc
-AR = $(PREFIX)-ar
-CFLAGS = -g -Wl,-q -Wall -O3 -Iinclude \
- -D__VITA__ -D__ARM_ARCH=7 -D__ARM_ARCH_7A__ \
- -mfpu=neon -mcpu=cortex-a9 -mfloat-abi=hard
-ASFLAGS = $(CFLAGS)
-
-$(TARGET_LIB): $(OBJS)
- $(AR) rcs $@ $^
-
-clean:
- @rm -f $(TARGET_LIB) $(OBJS)
-
-install: $(TARGET_LIB)
- @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/lib"
- @cp $(TARGET_LIB) $(DOLCESDK)/arm-dolce-eabi/lib
- @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
- @cp include/*.h "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
- @echo "Installed!"
diff --git a/Makefile.vita.gles2.dolce b/Makefile.vita.gles2.dolce
new file mode 100644
index 0000000..d646d43
--- /dev/null
+++ b/Makefile.vita.gles2.dolce
@@ -0,0 +1,58 @@
+# Based on port by xerpi
+# Makefile to build the SDL library
+
+TARGET_LIB = libSDL2.a
+
+SOURCES = \
+ src/*.c \
+ src/atomic/*.c \
+ src/audio/*.c \
+ src/audio/vita/*.c \
+ src/cpuinfo/*.c \
+ src/events/*.c \
+ src/file/*.c \
+ src/haptic/*.c \
+ src/haptic/dummy/*.c \
+ src/joystick/*.c \
+ src/joystick/vita/*.c \
+ src/loadso/dummy/*.c \
+ src/power/*.c \
+ src/power/vita/*.c \
+ src/filesystem/vita/*.c \
+ src/render/*.c \
+ src/render/software/*.c \
+ src/render/vitagles2/*.c \
+ src/sensor/*.c \
+ src/sensor/dummy/*.c \
+ src/stdlib/*.c \
+ src/thread/*.c \
+ src/thread/generic/SDL_systls.c \
+ src/thread/vita/*.c \
+ src/timer/*.c \
+ src/timer/vita/*.c \
+ src/video/*.c \
+ src/video/vita/*.c \
+ src/video/yuv2rgb/*.c \
+
+OBJS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
+
+PREFIX = arm-dolce-eabi
+CC = $(PREFIX)-gcc
+AR = $(PREFIX)-ar
+CFLAGS = -g -Wl,-q -Wall -O3 -Iinclude \
+ -D__VITA__ -D__ARM_ARCH=7 -D__ARM_ARCH_7A__ \
+ -mfpu=neon -mcpu=cortex-a9 -mfloat-abi=hard
+ASFLAGS = $(CFLAGS)
+
+$(TARGET_LIB): $(OBJS)
+ $(AR) rcs $@ $^
+
+clean:
+ @rm -f $(TARGET_LIB) $(OBJS)
+
+install: $(TARGET_LIB)
+ @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/lib"
+ @cp $(TARGET_LIB) $(DOLCESDK)/arm-dolce-eabi/lib
+ @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
+ @cp include/*.h "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
+ @echo "Installed!"
diff --git a/Makefile.vita.gxm.dolce b/Makefile.vita.gxm.dolce
new file mode 100644
index 0000000..62699e4
--- /dev/null
+++ b/Makefile.vita.gxm.dolce
@@ -0,0 +1,58 @@
+# Based on port by xerpi
+# Makefile to build the SDL library
+
+TARGET_LIB = libSDL2.a
+
+SOURCES = \
+ src/*.c \
+ src/atomic/*.c \
+ src/audio/*.c \
+ src/audio/vita/*.c \
+ src/cpuinfo/*.c \
+ src/events/*.c \
+ src/file/*.c \
+ src/haptic/*.c \
+ src/haptic/dummy/*.c \
+ src/joystick/*.c \
+ src/joystick/vita/*.c \
+ src/loadso/dummy/*.c \
+ src/power/*.c \
+ src/power/vita/*.c \
+ src/filesystem/vita/*.c \
+ src/render/*.c \
+ src/render/software/*.c \
+ src/render/vitagxm/*.c \
+ src/sensor/*.c \
+ src/sensor/dummy/*.c \
+ src/stdlib/*.c \
+ src/thread/*.c \
+ src/thread/generic/SDL_systls.c \
+ src/thread/vita/*.c \
+ src/timer/*.c \
+ src/timer/vita/*.c \
+ src/video/*.c \
+ src/video/vita/*.c \
+ src/video/yuv2rgb/*.c \
+
+OBJS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
+
+PREFIX = arm-dolce-eabi
+CC = $(PREFIX)-gcc
+AR = $(PREFIX)-ar
+CFLAGS = -g -Wl,-q -Wall -O3 -Iinclude \
+ -D__VITA__ -D__ARM_ARCH=7 -D__ARM_ARCH_7A__ \
+ -mfpu=neon -mcpu=cortex-a9 -mfloat-abi=hard
+ASFLAGS = $(CFLAGS)
+
+$(TARGET_LIB): $(OBJS)
+ $(AR) rcs $@ $^
+
+clean:
+ @rm -f $(TARGET_LIB) $(OBJS)
+
+install: $(TARGET_LIB)
+ @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/lib"
+ @cp $(TARGET_LIB) $(DOLCESDK)/arm-dolce-eabi/lib
+ @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
+ @cp include/*.h "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
+ @echo "Installed!"
diff --git a/Makefile.vita.vita2d.dolce b/Makefile.vita.vita2d.dolce
new file mode 100644
index 0000000..4325b4a
--- /dev/null
+++ b/Makefile.vita.vita2d.dolce
@@ -0,0 +1,58 @@
+# Based on port by xerpi
+# Makefile to build the SDL library
+
+TARGET_LIB = libSDL2.a
+
+SOURCES = \
+ src/*.c \
+ src/atomic/*.c \
+ src/audio/*.c \
+ src/audio/vita/*.c \
+ src/cpuinfo/*.c \
+ src/events/*.c \
+ src/file/*.c \
+ src/haptic/*.c \
+ src/haptic/dummy/*.c \
+ src/joystick/*.c \
+ src/joystick/vita/*.c \
+ src/loadso/dummy/*.c \
+ src/power/*.c \
+ src/power/vita/*.c \
+ src/filesystem/vita/*.c \
+ src/render/*.c \
+ src/render/software/*.c \
+ src/render/vita2d/*.c \
+ src/sensor/*.c \
+ src/sensor/dummy/*.c \
+ src/stdlib/*.c \
+ src/thread/*.c \
+ src/thread/generic/SDL_systls.c \
+ src/thread/vita/*.c \
+ src/timer/*.c \
+ src/timer/vita/*.c \
+ src/video/*.c \
+ src/video/vita/*.c \
+ src/video/yuv2rgb/*.c \
+
+OBJS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
+
+PREFIX = arm-dolce-eabi
+CC = $(PREFIX)-gcc
+AR = $(PREFIX)-ar
+CFLAGS = -g -Wl,-q -Wall -O3 -Iinclude \
+ -D__VITA__ -D__ARM_ARCH=7 -D__ARM_ARCH_7A__ \
+ -mfpu=neon -mcpu=cortex-a9 -mfloat-abi=hard
+ASFLAGS = $(CFLAGS)
+
+$(TARGET_LIB): $(OBJS)
+ $(AR) rcs $@ $^
+
+clean:
+ @rm -f $(TARGET_LIB) $(OBJS)
+
+install: $(TARGET_LIB)
+ @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/lib"
+ @cp $(TARGET_LIB) $(DOLCESDK)/arm-dolce-eabi/lib
+ @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
+ @cp include/*.h "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
+ @echo "Installed!"
diff --git a/include/SDL_config_vita.h b/include/SDL_config_vita.h
index 88fe344..5c14b50 100644
--- a/include/SDL_config_vita.h
+++ b/include/SDL_config_vita.h
@@ -139,10 +139,11 @@
#define SDL_FILESYSTEM_VITA 1
-#define SDL_VIDEO_RENDER_VITA_GLES2 1
+//#define SDL_VIDEO_RENDER_VITA_GLES2 1
//#define SDL_VIDEO_RENDER_VITA_GXM 1
+#define SDL_VIDEO_RENDER_VITA_VITA2D 1
-#if defined(SDL_VIDEO_RENDER_VITA_GLES2)
+#if defined(SDL_VIDEO_RENDER_VITA_GLES2) || defined(SDL_VIDEO_RENDER_VITA_GXM)
#define SDL_VIDEO_OPENGL_ES2 1
#endif
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 2a9868a..40f7f5a 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -95,12 +95,6 @@ static const SDL_RenderDriver *render_drivers[] = {
#if SDL_VIDEO_RENDER_OGL_ES2
&GLES2_RenderDriver,
#endif
-#if SDL_VIDEO_RENDER_VITA_GLES2
- &VITA_GLES2_RenderDriver,
-#endif
-#if SDL_VIDEO_RENDER_VITA_GXM
- &VITA_GXM__RenderDriver,
-#endif
#if SDL_VIDEO_RENDER_OGL_ES
&GLES_RenderDriver,
#endif
@@ -110,6 +104,15 @@ static const SDL_RenderDriver *render_drivers[] = {
#if SDL_VIDEO_RENDER_PSP
&PSP_RenderDriver,
#endif
+#if SDL_VIDEO_RENDER_VITA_GLES2
+ &VITA_GLES2_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_VITA_GXM
+ &VITA_GXM_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_VITA_VITA2D
+ &VITA_VITA2D_RenderDriver,
+#endif
#if SDL_VIDEO_RENDER_SW
&SW_RenderDriver
#endif
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index b38252d..31bdb8e 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -245,13 +245,14 @@ extern SDL_RenderDriver D3D_RenderDriver;
extern SDL_RenderDriver D3D11_RenderDriver;
extern SDL_RenderDriver GL_RenderDriver;
extern SDL_RenderDriver GLES2_RenderDriver;
-extern SDL_RenderDriver VITA_GLES2_RenderDriver;
-extern SDL_RenderDriver VITA_GXM_RenderDriver;
extern SDL_RenderDriver GLES_RenderDriver;
extern SDL_RenderDriver DirectFB_RenderDriver;
extern SDL_RenderDriver METAL_RenderDriver;
extern SDL_RenderDriver PSP_RenderDriver;
extern SDL_RenderDriver SW_RenderDriver;
+extern SDL_RenderDriver VITA_GLES2_RenderDriver;
+extern SDL_RenderDriver VITA_GXM_RenderDriver;
+extern SDL_RenderDriver VITA_VITA2D_RenderDriver;
/* Blend mode functions */
extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
diff --git a/src/render/vita2d/SDL_render_vita_vita2d.c b/src/render/vita2d/SDL_render_vita_vita2d.c
new file mode 100644
index 0000000..8e49f94
--- /dev/null
+++ b/src/render/vita2d/SDL_render_vita_vita2d.c
@@ -0,0 +1,713 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_VITA_VITA2D
+
+#include "SDL_hints.h"
+#include "../SDL_sysrender.h"
+
+#include <psp2/types.h>
+#include <psp2/display.h>
+#include <psp2/gxm.h>
+#include <psp2/kernel/processmgr.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include <vita2d.h>
+
+#define sceKernelDcacheWritebackAll() (void)0
+
+/* VITA renderer implementation, based on the vita2d lib */
+
+extern int SDL_RecreateWindow(SDL_Window *window, Uint32 flags);
+
+static SDL_Renderer *VITA_VITA2D_CreateRenderer(SDL_Window *window, Uint32 flags);
+static void VITA_VITA2D_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event);
+static SDL_bool VITA_VITA2D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode);
+static int VITA_VITA2D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture);
+static int VITA_VITA2D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
+ const SDL_Rect *rect, const void *pixels, int pitch);
+static int VITA_VITA2D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+
+static int VITA_VITA2D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
+ const SDL_Rect *rect, void **pixels, int *pitch);
+
+static void VITA_VITA2D_UnlockTexture(SDL_Renderer *renderer,
+ SDL_Texture *texture);
+
+static void VITA_VITA2D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode);
+
+static int VITA_VITA2D_SetRenderTarget(SDL_Renderer *renderer,
+ SDL_Texture *texture);
+
+static int VITA_VITA2D_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd);
+
+static int VITA_VITA2D_QueueSetDrawColor(SDL_Renderer * renderer, SDL_RenderCommand *cmd);
+
+static int VITA_VITA2D_RenderClear(SDL_Renderer *renderer);
+
+static int VITA_VITA2D_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count);
+
+static int VITA_VITA2D_RenderDrawPoints(SDL_Renderer *renderer,
+ const SDL_FPoint *points, int count);
+
+static int VITA_VITA2D_RenderDrawLines(SDL_Renderer *renderer,
+ const SDL_FPoint *points, int count);
+
+static int VITA_VITA2D_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count);
+
+static int VITA_VITA2D_RenderFillRects(SDL_Renderer *renderer,
+ const SDL_FRect *rects, int count);
+
+static int VITA_VITA2D_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect);
+
+static int VITA_VITA2D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
+
+static int VITA_VITA2D_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
+ Uint32 pixel_format, void *pixels, int pitch);
+
+static int VITA_VITA2D_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
+ const SDL_Rect * srcquad, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
+
+static void VITA_VITA2D_RenderPresent(SDL_Renderer *renderer);
+static void VITA_VITA2D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture);
+static void VITA_VITA2D_DestroyRenderer(SDL_Renderer *renderer);
+
+
+SDL_RenderDriver VITA_VITA2D_RenderDriver = {
+ .CreateRenderer = VITA_VITA2D_CreateRenderer,
+ .info = {
+ .name = "VITA",
+ .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC,
+ .num_texture_formats = 1,
+ .texture_formats = {
+ [0] = SDL_PIXELFORMAT_ABGR8888,
+ },
+ .max_texture_width = 1024,
+ .max_texture_height = 1024,
+ }
+};
+
+#define VITA_VITA2D_SCREEN_WIDTH 960
+#define VITA_VITA2D_SCREEN_HEIGHT 544
+
+#define VITA_VITA2D_FRAME_BUFFER_WIDTH 1024
+#define VITA_VITA2D_FRAME_BUFFER_SIZE (VITA_VITA2D_FRAME_BUFFER_WIDTH*VITA_VITA2D_SCREEN_HEIGHT)
+
+#define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11))
+#define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0))
+#define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12))
+#define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
+
+typedef struct
+{
+ void *frontbuffer;
+ void *backbuffer;
+ SDL_bool initialized;
+ SDL_bool displayListAvail;
+ unsigned int psm;
+ unsigned int bpp;
+ SDL_bool vsync;
+ unsigned int currentColor;
+ int currentBlendMode;
+
+} VITA_VITA2D_RenderData;
+
+
+typedef struct
+{
+ vita2d_texture *tex;
+ unsigned int pitch;
+ unsigned int w;
+ unsigned int h;
+} VITA_VITA2D_TextureData;
+
+typedef struct
+{
+ SDL_Rect srcRect;
+ SDL_FRect dstRect;
+} VITA_VITA2D_CopyData;
+
+void
+StartDrawing(SDL_Renderer *renderer)
+{
+ VITA_VITA2D_RenderData *data = (VITA_VITA2D_RenderData *) renderer->driverdata;
+ if(data->displayListAvail)
+ return;
+
+ vita2d_start_drawing();
+
+ data->displayListAvail = SDL_TRUE;
+}
+
+SDL_Renderer *
+VITA_VITA2D_CreateRenderer(SDL_Window *window, Uint32 flags)
+{
+
+ SDL_Renderer *renderer;
+ VITA_VITA2D_RenderData *data;
+
+ renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ data = (VITA_VITA2D_RenderData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ VITA_VITA2D_DestroyRenderer(renderer);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ renderer->WindowEvent = VITA_VITA2D_WindowEvent;
+ renderer->SupportsBlendMode = VITA_VITA2D_SupportsBlendMode;
+ renderer->CreateTexture = VITA_VITA2D_CreateTexture;
+ renderer->UpdateTexture = VITA_VITA2D_UpdateTexture;
+ renderer->UpdateTextureYUV = VITA_VITA2D_UpdateTextureYUV;
+ renderer->LockTexture = VITA_VITA2D_LockTexture;
+ renderer->UnlockTexture = VITA_VITA2D_UnlockTexture;
+ renderer->SetTextureScaleMode = VITA_VITA2D_SetTextureScaleMode;
+ renderer->SetRenderTarget = VITA_VITA2D_SetRenderTarget;
+ renderer->QueueSetViewport = VITA_VITA2D_QueueSetViewport;
+ renderer->QueueSetDrawColor = VITA_VITA2D_QueueSetDrawColor;
+ renderer->QueueDrawPoints = VITA_VITA2D_QueueDrawPoints;
+ renderer->QueueDrawLines = VITA_VITA2D_QueueDrawPoints; // lines and points queue the same way.
+ renderer->QueueFillRects = VITA_VITA2D_QueueFillRects;
+ renderer->QueueCopy = VITA_VITA2D_QueueCopy;
+ renderer->QueueCopyEx = VITA_VITA2D_QueueCopyEx;
+ renderer->RunCommandQueue = VITA_VITA2D_RunCommandQueue;
+ renderer->RenderReadPixels = VITA_VITA2D_RenderReadPixels;
+ renderer->RenderPresent = VITA_VITA2D_RenderPresent;
+ renderer->DestroyTexture = VITA_VITA2D_DestroyTexture;
+ renderer->DestroyRenderer = VITA_VITA2D_DestroyRenderer;
+ renderer->info = VITA_VITA2D_RenderDriver.info;
+ renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
+ renderer->driverdata = data;
+ renderer->window = window;
+
+ if (data->initialized != SDL_FALSE)
+ return 0;
+ data->initialized = SDL_TRUE;
+
+ if (flags & SDL_RENDERER_PRESENTVSYNC) {
+ data->vsync = SDL_TRUE;
+ } else {
+ data->vsync = SDL_FALSE;
+ }
+
+ vita2d_init();
+ vita2d_set_vblank_wait(data->vsync);
+
+ return renderer;
+}
+
+static void
+VITA_VITA2D_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
+{
+
+}
+
+static SDL_bool
+VITA_VITA2D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ return SDL_FALSE;
+}
+
+static int
+VITA_VITA2D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ VITA_VITA2D_TextureData* vita_texture = (VITA_VITA2D_TextureData*) SDL_calloc(1, sizeof(*vita_texture));
+
+ if(!vita_texture)
+ return -1;
+
+ vita_texture->tex = vita2d_create_empty_texture(texture->w, texture->h);
+
+ if(!vita_texture->tex)
+ {
+ SDL_free(vita_texture);
+ return SDL_OutOfMemory();
+ }
+
+ texture->driverdata = vita_texture;
+
+ VITA_VITA2D_SetTextureScaleMode(renderer, texture, texture->scaleMode);
+
+ vita_texture->w = vita2d_texture_get_width(vita_texture->tex);
+ vita_texture->h = vita2d_texture_get_height(vita_texture->tex);
+ vita_texture->pitch = vita2d_texture_get_stride(vita_texture->tex);
+
+ return 0;
+}
+
+
+static int
+VITA_VITA2D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
+ const SDL_Rect *rect, const void *pixels, int pitch)
+{
+ const Uint8 *src;
+ Uint8 *dst;
+ int row, length,dpitch;
+ src = pixels;
+
+ VITA_VITA2D_LockTexture(renderer, texture, rect, (void **)&dst, &dpitch);
+ length = rect->w * SDL_BYTESPERPIXEL(texture->format);
+ if (length == pitch && length == dpitch) {
+ SDL_memcpy(dst, src, length*rect->h);
+ } else {
+ for (row = 0; row < rect->h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += dpitch;
+ }
+ }
+
+ sceKernelDcacheWritebackAll();
+ return 0;
+}
+
+static int
+VITA_VITA2D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{
+ return 0;
+}
+
+static int
+VITA_VITA2D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
+ const SDL_Rect *rect, void **pixels, int *pitch)
+{
+ VITA_VITA2D_TextureData *vita_texture = (VITA_VITA2D_TextureData *) texture->driverdata;
+
+ *pixels =
+ (void *) ((Uint8 *) vita2d_texture_get_datap(vita_texture->tex)
+ + (rect->y * vita_texture->pitch) + rect->x * SDL_BYTESPERPIXEL(texture->format));
+ *pitch = vita_texture->pitch;
+ return 0;
+}
+
+static void
+VITA_VITA2D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ // no needs to update texture data on ps vita. VITA_VITA2D_LockTexture
+ // already return a pointer to the vita2d texture pixels buffer.
+ // This really improve framerate when using lock/unlock.
+
+ /*
+ VITA_VITA2D_TextureData *vita_texture = (VITA_VITA2D_TextureData *) texture->driverdata;
+ SDL_Rect rect;
+
+ // We do whole texture updates, at least for now
+ rect.x = 0;
+ rect.y = 0;
+ rect.w = texture->w;
+ rect.h = texture->h;
+ VITA_VITA2D_UpdateTexture(renderer, texture, &rect, vita_texture->data, vita_texture->pitch);
+ */
+}
+
+static void
+VITA_VITA2D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
+{
+ VITA_VITA2D_TextureData *vita_texture = (VITA_VITA2D_TextureData *) texture->driverdata;
+
+ /*
+ set texture filtering according to scaleMode
+ suported hint values are nearest (0, default) or linear (1)
+ vitaScaleMode is either SCE_GXM_TEXTURE_FILTER_POINT (good for tile-map)
+ or SCE_GXM_TEXTURE_FILTER_LINEAR (good for scaling)
+ */
+
+ int vitaScaleMode = (scaleMode == SDL_ScaleModeNearest
+ ? SCE_GXM_TEXTURE_FILTER_POINT
+ : SCE_GXM_TEXTURE_FILTER_LINEAR);
+ vita2d_texture_set_filters(vita_texture->tex, vitaScaleMode, vitaScaleMode);
+
+ return;
+}
+
+static int
+VITA_VITA2D_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ return 0;
+}
+
+static int
+VITA_VITA2D_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
+{
+ return 0;
+}
+
+static int
+VITA_VITA2D_QueueSetDrawColor(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
+{
+ return 0;
+}
+
+
+static void
+VITA_VITA2D_SetBlendMode(SDL_Renderer *renderer, int blendMode)
+{
+ /*VITA_VITA2D_RenderData *data = (VITA_VITA2D_RenderData *) renderer->driverdata;
+ if (blendMode != data-> currentBlendMode) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_NONE:
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
+ sceGuDisable(GU_BLEND);
+ break;
+ case SDL_BLENDMODE_BLEND:
+ sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
+ sceGuEnable(GU_BLEND);
+ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
+ break;
+ case SDL_BLENDMODE_ADD:
+ sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
+ sceGuEnable(GU_BLEND);
+ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
+ break;
+ case SDL_BLENDMODE_MOD:
+ sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
+ sceGuEnable(GU_BLEND);
+ sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
+ break;
+ }
+ data->currentBlendMode = blendMode;
+ }*/
+}
+
+
+
+static int
+VITA_VITA2D_RenderClear(SDL_Renderer *renderer)
+{
+ int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
+ vita2d_set_clear_color(color);
+
+ vita2d_clear_screen();
+
+ return 0;
+}
+
+static int
+VITA_VITA2D_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
+{
+ const size_t vertlen = (sizeof (float) * 2) * count;
+ float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
+ if (!verts) {
+ return -1;
+ }
+ cmd->data.draw.count = count;
+ SDL_memcpy(verts, points, vertlen);
+ return 0;
+}
+
+static int
+VITA_VITA2D_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points,
+ int count)
+{
+ int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
+ int i;
+
+ for (i = 0; i < count; ++i) {
+ vita2d_draw_pixel(points[i].x, points[i].y, color);
+ }
+
+ return 0;
+}
+
+static int
+VITA_VITA2D_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points,
+ int count)
+{
+ int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
+ int i;
+
+ for (i = 0; i < count; ++i) {
+ if (i < count -1) {
+ vita2d_draw_line(points[i].x, points[i].y, points[i+1].x, points[i+1].y, color);
+ }
+ }
+
+ return 0;
+}
+
+static int
+VITA_VITA2D_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
+{
+ const size_t outLen = count * sizeof (SDL_FRect);
+ SDL_FRect *outRects = (SDL_FRect *) SDL_AllocateRenderVertices(renderer, outLen, 0, &cmd->data.draw.first);
+
+ if (!outRects) {
+ return -1;
+ }
+ cmd->data.draw.count = count;
+ SDL_memcpy(outRects, rects, outLen);
+
+ return 0;
+}
+
+static int
+VITA_VITA2D_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects,
+ int count)
+{
+ int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
+ int i;
+
+ for (i = 0; i < count; ++i) {
+ const SDL_FRect *rect = &rects[i];
+
+ vita2d_draw_rectangle(rect->x, rect->y, rect->w, rect->h, color);
+ }
+
+ return 0;
+}
+
+
+#define PI 3.14159265358979f
+
+#define radToDeg(x) ((x)*180.f/PI)
+#define degToRad(x) ((x)*PI/180.f)
+
+float MathAbs(float x)
+{
+ return (x < 0) ? -x : x;
+}
+
+void MathSincos(float r, float *s, float *c)
+{
+ *s = sinf(r);
+ *c = cosf(r);
+}
+
+void Swap(float *a, float *b)
+{
+ float n=*a;
+ *a = *b;
+ *b = n;
+}
+
+static int
+VITA_VITA2D_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{
+ const size_t outLen = sizeof (VITA_VITA2D_CopyData);
+ VITA_VITA2D_CopyData *outData = (VITA_VITA2D_CopyData *) SDL_AllocateRenderVertices(renderer, outLen, 0, &cmd->data.draw.first);
+
+ if (!outData) {
+ return -1;
+ }
+ cmd->data.draw.count = 1;
+
+ SDL_memcpy(&outData->srcRect, srcrect, sizeof(SDL_Rect));
+ SDL_memcpy(&outData->dstRect, dstrect, sizeof(SDL_FRect));
+
+ Uint8 r, g, b, a;
+ SDL_GetTextureColorMod(texture, &r, &g, &b);
+ SDL_GetTextureAlphaMod(texture, &a);
+
+ cmd->data.draw.r = r;
+ cmd->data.draw.g = g;
+ cmd->data.draw.b = b;
+ cmd->data.draw.a = a;
+ cmd->data.draw.blend = renderer->blendMode;
+
+ return 0;
+}
+
+
+static int
+VITA_VITA2D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
+{
+ StartDrawing(renderer);
+
+ while (cmd) {
+ switch (cmd->command) {
+ case SDL_RENDERCMD_SETDRAWCOLOR: {
+ break;
+ }
+
+ case SDL_RENDERCMD_SETVIEWPORT: {
+ break;
+ }
+
+ case SDL_RENDERCMD_SETCLIPRECT: {
+ break;
+ }
+
+ case SDL_RENDERCMD_CLEAR: {
+ VITA_VITA2D_RenderClear(renderer);
+ break;
+ }
+
+ case SDL_RENDERCMD_DRAW_POINTS: {
+ const size_t count = cmd->data.draw.count;
+ const size_t first = cmd->data.draw.first;
+ const SDL_FPoint *points = (SDL_FPoint *) (((Uint8 *) vertices) + first);
+ VITA_VITA2D_RenderDrawPoints(renderer, points, count);
+ break;
+ }
+
+ case SDL_RENDERCMD_DRAW_LINES: {
+ const size_t count = cmd->data.draw.count;
+ const size_t first = cmd->data.draw.first;
+ const SDL_FPoint *points = (SDL_FPoint *) (((Uint8 *) vertices) + first);
+
+ VITA_VITA2D_RenderDrawLines(renderer, points, count);
+ break;
+ }
+
+ case SDL_RENDERCMD_FILL_RECTS: {
+ const size_t count = cmd->data.draw.count;
+ const size_t first = cmd->data.draw.first;
+ const SDL_FRect *rects = (SDL_FRect *) (((Uint8 *) vertices) + first);
+
+ VITA_VITA2D_RenderFillRects(renderer, rects, count);
+ break;
+ }
+
+ case SDL_RENDERCMD_COPY: {
+ const size_t first = cmd->data.draw.first;
+ const VITA_VITA2D_CopyData *copyData = (VITA_VITA2D_CopyData *) (((Uint8 *) vertices) + first);
+
+ VITA_VITA2D_TextureData *vita_texture = (VITA_VITA2D_TextureData *) cmd->data.draw.texture->driverdata;
+
+ const SDL_Rect *srcrect = ©Data->srcRect;
+ const SDL_FRect *dstrect = ©Data->dstRect;
+
+ float scaleX = dstrect->w == srcrect->w ? 1 : (float)(dstrect->w/srcrect->w);
+ float scaleY = dstrect->h == srcrect->h ? 1 : (float)(dstrect->h/srcrect->h);
+
+ Uint8 r, g, b, a;
+ r = cmd->data.draw.r;
+ g = cmd->data.draw.g;
+ b = cmd->data.draw.b;
+ a = cmd->data.draw.a;
+
+ VITA_VITA2D_SetBlendMode(renderer, cmd->data.draw.blend);
+
+ if(r == 255 && g == 255 && b == 255 && a == 255)
+ {
+ vita2d_draw_texture_part_scale(vita_texture->tex, dstrect->x, dstrect->y,
+ srcrect->x, srcrect->y, srcrect->w, srcrect->h, scaleX, scaleY);
+ } else {
+ vita2d_draw_texture_tint_part_scale(vita_texture->tex, dstrect->x, dstrect->y,
+ srcrect->x, srcrect->y, srcrect->w, srcrect->h, scaleX, scaleY, (a << 24) + (b << 16) + (g << 8) + r);
+ }
+
+ break;
+ }
+
+ case SDL_RENDERCMD_COPY_EX: {
+ break;
+ }
+
+ case SDL_RENDERCMD_NO_OP:
+ break;
+ }
+
+ cmd = cmd->next;
+ }
+
+ return 0;
+}
+
+static int
+VITA_VITA2D_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
+ Uint32 pixel_format, void *pixels, int pitch)
+{
+ return 0;
+}
+
+static int
+VITA_VITA2D_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
+ const SDL_Rect * srcquad, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
+{
+ return 0;
+}
+
+static void
+VITA_VITA2D_RenderPresent(SDL_Renderer *renderer)
+{
+ VITA_VITA2D_RenderData *data = (VITA_VITA2D_RenderData *) renderer->driverdata;
+ if(!data->displayListAvail)
+ return;
+
+ vita2d_end_drawing();
+ vita2d_wait_rendering_done();
+ vita2d_swap_buffers();
+
+ data->displayListAvail = SDL_FALSE;
+}
+
+static void
+VITA_VITA2D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ VITA_VITA2D_RenderData *renderdata = (VITA_VITA2D_RenderData *) renderer->driverdata;
+ VITA_VITA2D_TextureData *vita_texture = (VITA_VITA2D_TextureData *) texture->driverdata;
+
+ if (renderdata == 0)
+ return;
+
+ if(vita_texture == 0)
+ return;
+
+ vita2d_wait_rendering_done();
+ vita2d_free_texture(vita_texture->tex);
+ SDL_free(vita_texture);
+ texture->driverdata = NULL;
+}
+
+static void
+VITA_VITA2D_DestroyRenderer(SDL_Renderer *renderer)
+{
+ VITA_VITA2D_RenderData *data = (VITA_VITA2D_RenderData *) renderer->driverdata;
+ if (data) {
+ if (!data->initialized)
+ return;
+
+ vita2d_fini();
+
+ data->initialized = SDL_FALSE;
+ data->displayListAvail = SDL_FALSE;
+ SDL_free(data);
+ }
+ SDL_free(renderer);
+}
+
+#endif /* SDL_VIDEO_RENDER_VITA_VITA2D */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c
index 26a219a..96cae73 100644
--- a/src/video/vita/SDL_vitavideo.c
+++ b/src/video/vita/SDL_vitavideo.c
@@ -332,7 +332,7 @@ void VITA_PumpEvents(_THIS)
{
VITA_PollTouch();
VITA_PollKeyboard();
- VITA_PollMouse();
+ VITA_PollMouse();
}
#endif /* SDL_VIDEO_DRIVER_VITA */