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
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
|
diff -Nur a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp
--- a/core/rend/gles/gles.cpp 2015-10-06 21:43:53.047336437 -0300
+++ b/core/rend/gles/gles.cpp 2015-10-06 21:51:21.723570329 -0300
@@ -1,27 +1,3 @@
-#include <math.h>
-#include "gles.h"
-#include "rend/TexCache.h"
-#include "cfg/cfg.h"
-
-#ifdef TARGET_PANDORA
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/fb.h>
-
-#ifndef FBIO_WAITFORVSYNC
- #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
-#endif
-int fbdev = -1;
-#endif
-
-#ifndef GLES
-#if HOST_OS != OS_DARWIN
-#include <GL3/gl3w.c>
-#pragma comment(lib,"Opengl32.lib")
-#endif
-#endif
-
/*
GL|ES 2
Slower, smaller subset of gl2
@@ -54,305 +30,126 @@
*/
+#include <math.h>
+#include "cfg/cfg.h"
#include "oslib/oslib.h"
#include "rend/rend.h"
+#include "rend/TexCache.h"
#include "hw/pvr/Renderer_if.h"
+#include "deps/libpng/png.h"
+#include "gles.h"
+#include "glshaders.h"
-void GenSorted();
-
-float fb_scale_x,fb_scale_y;
-
-#ifndef GLES
-#define attr "in"
-#define vary "out"
-#else
-#define attr "attribute"
-#define vary "varying"
+#ifdef TARGET_PANDORA
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/ioctl.h>
+ #include <linux/fb.h>
#endif
-#if 1
-//Fragment and vertex shaders code
-//pretty much 1:1 copy of the d3d ones for now
-const char* VertexShaderSource =
-#ifndef GLES
- "#version 140 \n"
+#if !defined(GLES) && HOST_OS != OS_DARWIN
+ #include <GL3/gl3w.c>
+ #pragma comment(lib,"Opengl32.lib")
#endif
-"\
-/* Vertex constants*/ \n\
-uniform highp vec4 scale; \n\
-uniform highp vec4 depth_scale; \n\
-uniform highp float sp_FOG_DENSITY; \n\
-/* Vertex input */ \n\
-" attr " highp vec4 in_pos; \n\
-" attr " lowp vec4 in_base; \n\
-" attr " lowp vec4 in_offs; \n\
-" attr " mediump vec2 in_uv; \n\
-/* output */ \n\
-" vary " lowp vec4 vtx_base; \n\
-" vary " lowp vec4 vtx_offs; \n\
-" vary " mediump vec2 vtx_uv; \n\
-" vary " highp vec3 vtx_xyz; \n\
-void main() \n\
-{ \n\
- vtx_base=in_base; \n\
- vtx_offs=in_offs; \n\
- vtx_uv=in_uv; \n\
- vec4 vpos=in_pos; \n\
- vtx_xyz.xy = vpos.xy; \n\
- vtx_xyz.z = vpos.z*sp_FOG_DENSITY; \n\
- vpos.w=1.0/vpos.z; \n\
- vpos.xy=vpos.xy*scale.xy-scale.zw; \n\
- vpos.xy*=vpos.w; \n\
- vpos.z=depth_scale.x+depth_scale.y*vpos.w; \n\
- gl_Position = vpos; \n\
-}";
-
-#else
-
-
-
-const char* VertexShaderSource =
- ""
- "/* Test Projection Matrix */"
- ""
- "uniform highp mat4 Projection;"
- ""
- ""
- "/* Vertex constants */"
- ""
- "uniform highp float sp_FOG_DENSITY;"
- "uniform highp vec4 scale;"
- ""
- "/* Vertex output */"
- ""
- "attribute highp vec4 in_pos;"
- "attribute lowp vec4 in_base;"
- "attribute lowp vec4 in_offs;"
- "attribute mediump vec2 in_uv;"
- ""
- "/* Transformed input */"
- ""
- "varying lowp vec4 vtx_base;"
- "varying lowp vec4 vtx_offs;"
- "varying mediump vec2 vtx_uv;"
- "varying highp vec3 vtx_xyz;"
- ""
- "void main()"
- "{"
- " vtx_base = in_base;"
- " vtx_offs = in_offs;"
- " vtx_uv = in_uv;"
- ""
- " vec4 vpos = in_pos;"
- " vtx_xyz.xy = vpos.xy; "
- " vtx_xyz.z = vpos.z*sp_FOG_DENSITY; "
- ""
- " vpos.w = 1.0/vpos.z; "
- " vpos.z *= -scale.w; "
- " vpos.xy = vpos.xy*scale.xy-sign(scale.xy); "
- " vpos.xy *= vpos.w; "
- ""
- " gl_Position = vpos;"
- // " gl_Position = vpos * Projection;"
- "}"
- ;
+#define OSD_TEX_W 512
+#define OSD_TEX_H 256
+#define key_CONT_C (1 << 0)
+#define key_CONT_B (1 << 1)
+#define key_CONT_A (1 << 2)
+#define key_CONT_START (1 << 3)
+#define key_CONT_DPAD_UP (1 << 4)
+#define key_CONT_DPAD_DOWN (1 << 5)
+#define key_CONT_DPAD_LEFT (1 << 6)
+#define key_CONT_DPAD_RIGHT (1 << 7)
+#define key_CONT_Z (1 << 8)
+#define key_CONT_Y (1 << 9)
+#define key_CONT_X (1 << 10)
+#define key_CONT_D (1 << 11)
+#define key_CONT_DPAD2_UP (1 << 12)
+#define key_CONT_DPAD2_DOWN (1 << 13)
+#define key_CONT_DPAD2_LEFT (1 << 14)
+#define key_CONT_DPAD2_RIGHT (1 << 15)
-#endif
+gl_ctx gl;
+float fb_scale_x;
+float fb_scale_y;
+int screen_width;
+int screen_height;
+GLuint osd_tex;
+extern u16 kcode[4];
+extern u8 rt[4];
+extern u8 lt[4];
+u32 osd_base;
+u32 osd_count;
+#if defined(_ANDROID)
+ extern float vjoy_pos[14][8];
+#else
+ float vjoy_pos[14][8]=
+ {
+ {24+0,24+64,64,64}, //LEFT
+ {24+64,24+0,64,64}, //UP
+ {24+128,24+64,64,64}, //RIGHT
+ {24+64,24+128,64,64}, //DOWN
+
+ {440+0,280+64,64,64}, //X
+ {440+64,280+0,64,64}, //Y
+ {440+128,280+64,64,64}, //B
+ {440+64,280+128,64,64}, //A
+
+ {320-32,360+32,64,64}, //Start
+
+ {440,200,90,64}, //RT
+ {542,200,90,64}, //LT
+
+ {-24,128+224,128,128}, //ANALOG_RING
+ {96,320,64,64}, //ANALOG_POINT
+ {1}
+ };
+#endif // !_ANDROID
-/*
+float vjoy_sz[2][14] = {
+ { 64,64,64,64, 64,64,64,64, 64, 90,90, 128, 64 },
+ { 64,64,64,64, 64,64,64,64, 64, 64,64, 128, 64 },
+};
-cp_AlphaTest 0 1 2 2
-pp_ClipTestMode -1 0 1 3 6
-pp_UseAlpha 0 1 2 12
-pp_Texture 1
- pp_IgnoreTexA 0 1 2 2
- pp_ShadInstr 0 1 2 3 4 8
- pp_Offset 0 1 2 16
- pp_FogCtrl 0 1 2 3 4 64
-pp_Texture 0
- pp_FogCtrl 0 2 3 4 4
-
-pp_Texture: off -> 12*4=48 shaders
-pp_Texture: on -> 12*64=768 shaders
-Total: 816 shaders
-
-highp float fdecp(highp float flt,out highp float e) \n\
-{ \n\
- highp float lg2=log2(flt); //ie , 2.5 \n\
- highp float frc=fract(lg2); //ie , 0.5 \n\
- e=lg2-frc; //ie , 2.5-0.5=2 (exp) \n\
- return pow(2.0,frc); //2^0.5 (manitsa) \n\
-} \n\
-lowp float fog_mode2(highp float invW) \n\
-{ \n\
- highp float foginvW=invW; \n\
- foginvW=clamp(foginvW,1.0,255.0); \n\
- \n\
- highp float fogexp; //0 ... 7 \n\
- highp float fogman=fdecp(foginvW, fogexp); //[1,2) mantissa bits. that is 1.m \n\
- \n\
- highp float fogman_hi=fogman*16.0-16.0; //[16,32) -16 -> [0,16) \n\
- highp float fogman_idx=floor(fogman_hi); //[0,15] \n\
- highp float fogman_blend=fract(fogman_hi); //[0,1) -- can also be fogman_idx-fogman_idx ! \n\
- highp float fog_idx_fr=fogexp*16.0+fogman_idx; //[0,127] \n\
- \n\
- highp float fog_idx_pixel_fr=fog_idx_fr+0.5; \n\
- highp float fog_idx_pixel_n=fog_idx_pixel_fr/128.0;//normalise to [0.5/128,127.5/128) coordinates \n\
- \n\
- //fog is 128x1 texure \n\
- lowp vec2 fog_coefs=texture2D(fog_table,vec2(fog_idx_pixel_n)).rg; \n\
- \n\
- lowp float fog_coef=mix(fog_coefs.r,fog_coefs.g,fogman_blend); \n\
- \n\
- return fog_coef; \n\
-} \n\
-*/
+#ifdef TARGET_PANDORA
+ #ifndef FBIO_WAITFORVSYNC
+ #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
+ #endif
-#ifndef GLES
-#define FRAGCOL "FragColor"
-#define TEXLOOKUP "texture"
-#define vary "in"
-#else
-#define FRAGCOL "gl_FragColor"
-#define TEXLOOKUP "texture2D"
+ int fbdev = -1;
+ char OSD_Info[128];
+ int OSD_Delay = 0;
+ char OSD_Counters[256];
+ int OSD_Counter = 0;
+ GLuint osd_font;
#endif
-
-const char* PixelPipelineShader =
-#ifndef GLES
- "#version 140 \n"
- "out vec4 FragColor; \n"
+#if !defined(_ANDROID) && !defined(TARGET_NACL32) && HOST_OS==OS_LINUX
+ #define SET_AFNT 1
#endif
-"\
-\
-#define cp_AlphaTest %d \n\
-#define pp_ClipTestMode %d.0 \n\
-#define pp_UseAlpha %d \n\
-#define pp_Texture %d \n\
-#define pp_IgnoreTexA %d \n\
-#define pp_ShadInstr %d \n\
-#define pp_Offset %d \n\
-#define pp_FogCtrl %d \n\
-/* Shader program params*/ \n\
-/* gles has no alpha test stage, so its emulated on the shader */ \n\
-uniform lowp float cp_AlphaTestValue; \n\
-uniform lowp vec4 pp_ClipTest; \n\
-uniform lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT; \n\
-uniform highp vec2 sp_LOG_FOG_COEFS; \n\
-uniform sampler2D tex,fog_table; \n\
-/* Vertex input*/ \n\
-" vary " lowp vec4 vtx_base; \n\
-" vary " lowp vec4 vtx_offs; \n\
-" vary " mediump vec2 vtx_uv; \n\
-" vary " highp vec3 vtx_xyz; \n\
-lowp float fog_mode2(highp float val) \n\
-{ \n\
- highp float fog_idx=clamp(val,0.0,127.99); \n\
- return clamp(sp_LOG_FOG_COEFS.y*log2(fog_idx)+sp_LOG_FOG_COEFS.x,0.001,1.0); //the clamp is required due to yet another bug !\n\
-} \n\
-void main() \n\
-{ \n\
- lowp vec4 color=vtx_base; \n\
- #if pp_UseAlpha==0 \n\
- color.a=1.0; \n\
- #endif\n\
- #if pp_FogCtrl==3 \n\
- color=vec4(sp_FOG_COL_RAM.rgb,fog_mode2(vtx_xyz.z)); \n\
- #endif\n\
- #if pp_Texture==1 \n\
- { \n\
- lowp vec4 texcol=" TEXLOOKUP "(tex,vtx_uv); \n\
- \n\
- #if pp_IgnoreTexA==1 \n\
- texcol.a=1.0; \n\
- #endif\n\
- \n\
- #if pp_ShadInstr==0 \n\
- { \n\
- color.rgb=texcol.rgb; \n\
- color.a=texcol.a; \n\
- } \n\
- #endif\n\
- #if pp_ShadInstr==1 \n\
- { \n\
- color.rgb*=texcol.rgb; \n\
- color.a=texcol.a; \n\
- } \n\
- #endif\n\
- #if pp_ShadInstr==2 \n\
- { \n\
- color.rgb=mix(color.rgb,texcol.rgb,texcol.a); \n\
- } \n\
- #endif\n\
- #if pp_ShadInstr==3 \n\
- { \n\
- color*=texcol; \n\
- } \n\
- #endif\n\
- \n\
- #if pp_Offset==1 \n\
- { \n\
- color.rgb+=vtx_offs.rgb; \n\
- if (pp_FogCtrl==1) \n\
- color.rgb=mix(color.rgb,sp_FOG_COL_VERT.rgb,vtx_offs.a); \n\
- } \n\
- #endif\n\
- } \n\
- #endif\n\
- #if pp_FogCtrl==0 \n\
- { \n\
- color.rgb=mix(color.rgb,sp_FOG_COL_RAM.rgb,fog_mode2(vtx_xyz.z)); \n\
- } \n\
- #endif\n\
- #if cp_AlphaTest == 1 \n\
- if (cp_AlphaTestValue>color.a) discard;\n\
- #endif \n\
- //color.rgb=vec3(vtx_xyz.z/255.0);\n\
- " FRAGCOL "=color; \n\
-}";
-const char* ModifierVolumeShader =
-#ifndef GLES
- "#version 140 \n"
- "out vec4 FragColor; \n"
-#endif
-" \
-uniform lowp float sp_ShaderColor; \n\
-/* Vertex input*/ \n\
-void main() \n\
-{ \n\
- " FRAGCOL "=vec4(0.0, 0.0, 0.0, sp_ShaderColor); \n\
-}";
+FILE* pngfile;
-const char* OSD_Shader =
-#ifndef GLES
- "#version 140 \n"
- "out vec4 FragColor; \n"
-#endif
-" \
-" vary " lowp vec4 vtx_base; \n\
-" vary " mediump vec2 vtx_uv; \n\
-/* Vertex input*/ \n\
-uniform sampler2D tex; \n\
-void main() \n\
-{ \n\
- mediump vec2 uv=vtx_uv; \n\
- uv.y=1.0-uv.y; \n\
- " FRAGCOL "=vtx_base*" TEXLOOKUP "(tex,uv.st); \n\n\
-}";
+void GenSorted();
+bool gl_init(void* wind, void* disp);
-gl_ctx gl;
+//swap buffers
+void gl_swap();
+//destroy the gles context and free resources
+void gl_term();
-int screen_width;
-int screen_height;
+GLuint gl_CompileShader(const char* shader,GLuint type);
+
+bool gl_create_resources();
#if (HOST_OS != OS_DARWIN) && !defined(TARGET_NACL32)
#ifdef GLES
@@ -843,11 +640,6 @@
return glIsProgram(s->program)==GL_TRUE;
}
-GLuint osd_tex;
-#ifdef TARGET_PANDORA
-GLuint osd_font;
-#endif
-
bool gl_create_resources()
{
@@ -938,51 +730,8 @@
return true;
}
-bool gl_init(void* wind, void* disp);
-
-//swap buffers
-void gl_swap();
-//destroy the gles context and free resources
-void gl_term();
-
-GLuint gl_CompileShader(const char* shader,GLuint type);
-
-bool gl_create_resources();
-
//setup
-
-bool gles_init()
-{
-
- if (!gl_init((void*)libPvr_GetRenderTarget(),
- (void*)libPvr_GetRenderSurface()))
- return false;
-
- if (!gl_create_resources())
- return false;
-
-#if defined(GLES) && HOST_OS != OS_DARWIN && !defined(TARGET_NACL32)
- #ifdef TARGET_PANDORA
- fbdev=open("/dev/fb0", O_RDONLY);
- #else
- eglSwapInterval(gl.setup.display,1);
- #endif
-#endif
-
- //clean up all buffers ...
- for (int i=0;i<10;i++)
- {
- glClearColor(0.f, 0.f, 0.f, 0.f);
- glClear(GL_COLOR_BUFFER_BIT);
- gl_swap();
- }
-
- return true;
-}
-
-
-
float fog_coefs[]={0,0};
void tryfit(float* x,float* y)
{
@@ -1043,64 +792,6 @@
//printf("%f\n",B*log(maxdev)/log(2.0)+A);
}
-
-
-extern u16 kcode[4];
-extern u8 rt[4],lt[4];
-
-#define key_CONT_C (1 << 0)
-#define key_CONT_B (1 << 1)
-#define key_CONT_A (1 << 2)
-#define key_CONT_START (1 << 3)
-#define key_CONT_DPAD_UP (1 << 4)
-#define key_CONT_DPAD_DOWN (1 << 5)
-#define key_CONT_DPAD_LEFT (1 << 6)
-#define key_CONT_DPAD_RIGHT (1 << 7)
-#define key_CONT_Z (1 << 8)
-#define key_CONT_Y (1 << 9)
-#define key_CONT_X (1 << 10)
-#define key_CONT_D (1 << 11)
-#define key_CONT_DPAD2_UP (1 << 12)
-#define key_CONT_DPAD2_DOWN (1 << 13)
-#define key_CONT_DPAD2_LEFT (1 << 14)
-#define key_CONT_DPAD2_RIGHT (1 << 15)
-
-u32 osd_base;
-u32 osd_count;
-
-
-#if defined(_ANDROID)
-extern float vjoy_pos[14][8];
-#else
-
-float vjoy_pos[14][8]=
-{
- {24+0,24+64,64,64}, //LEFT
- {24+64,24+0,64,64}, //UP
- {24+128,24+64,64,64}, //RIGHT
- {24+64,24+128,64,64}, //DOWN
-
- {440+0,280+64,64,64}, //X
- {440+64,280+0,64,64}, //Y
- {440+128,280+64,64,64}, //B
- {440+64,280+128,64,64}, //A
-
- {320-32,360+32,64,64}, //Start
-
- {440,200,90,64}, //RT
- {542,200,90,64}, //LT
-
- {-24,128+224,128,128}, //ANALOG_RING
- {96,320,64,64}, //ANALOG_POINT
- {1}
-};
-#endif // !_ANDROID
-
-float vjoy_sz[2][14] = {
- { 64,64,64,64, 64,64,64,64, 64, 90,90, 128, 64 },
- { 64,64,64,64, 64,64,64,64, 64, 64,64, 128, 64 },
-};
-
static void DrawButton(float* xy, u32 state)
{
Vertex vtx;
@@ -1139,12 +830,6 @@
osd_count+=4;
}
-static void ClearBG()
-{
-
-}
-
-
void DrawButton2(float* xy, bool state) { DrawButton(xy,state?0:255); }
#ifdef TARGET_PANDORA
static void DrawCenteredText(float yy, float scale, int transparency, const char* text)
@@ -1247,13 +932,6 @@
}
#endif
-#ifdef TARGET_PANDORA
-char OSD_Info[128];
-int OSD_Delay=0;
-char OSD_Counters[256];
-int OSD_Counter=0;
-#endif
-
static void OSD_HOOK()
{
osd_base=pvrrc.verts.used();
@@ -1290,128 +968,95 @@
#endif
}
-extern GLuint osd_tex;
-#ifdef TARGET_PANDORA
-extern GLuint osd_font;
-#endif
-
-#define OSD_TEX_W 512
-#define OSD_TEX_H 256
-
-void OSD_DRAW()
+/*
+bool rend_single_frame()
{
- #ifndef TARGET_PANDORA
- if (osd_tex)
- {
- float u=0;
- float v=0;
-
- for (int i=0;i<13;i++)
- {
- //umin,vmin,umax,vmax
- vjoy_pos[i][4]=(u+1)/OSD_TEX_W;
- vjoy_pos[i][5]=(v+1)/OSD_TEX_H;
-
- vjoy_pos[i][6]=((u+vjoy_sz[0][i]-1))/OSD_TEX_W;
- vjoy_pos[i][7]=((v+vjoy_sz[1][i]-1))/OSD_TEX_H;
-
- u+=vjoy_sz[0][i];
- if (u>=OSD_TEX_W)
- {
- u-=OSD_TEX_W;
- v+=vjoy_sz[1][i];
- }
- //v+=vjoy_pos[i][3];
- }
-
- verify(glIsProgram(gl.OSD_SHADER.program));
+ //wait render start only if no frame pending
+ _pvrrc = DequeueRender();
- glBindTexture(GL_TEXTURE_2D,osd_tex);
- glUseProgram(gl.OSD_SHADER.program);
+ while (!_pvrrc)
+ {
+ rs.Wait();
+ _pvrrc = DequeueRender();
+ }
- //reset rendering scale
-/*
- float dc_width=640;
- float dc_height=480;
+ bool do_swp=false;
+ //if (kcode[0]&(1<<9))
+ {
- float dc2s_scale_h=screen_height/480.0f;
- float ds2s_offs_x=(screen_width-dc2s_scale_h*640)/2;
- //-1 -> too much to left
- ShaderUniforms.scale_coefs[0]=2.0f/(screen_width/dc2s_scale_h);
- ShaderUniforms.scale_coefs[1]=-2/dc_height;
- ShaderUniforms.scale_coefs[2]=1-2*ds2s_offs_x/(screen_width);
- ShaderUniforms.scale_coefs[3]=-1;
+ //clear up & free data ..
+ tactx_Recycle(_pvrrc);
+ _pvrrc=0;
- glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs);
+ return do_swp;
+}
*/
- glEnable(GL_BLEND);
- glDisable(GL_DEPTH_TEST);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glDepthMask(false);
- glDepthFunc(GL_ALWAYS);
-
- glDisable(GL_CULL_FACE);
- glDisable(GL_SCISSOR_TEST);
-
- int dfa=osd_count/4;
-
- for (int i=0;i<dfa;i++)
- glDrawArrays(GL_TRIANGLE_STRIP,osd_base+i*4,4);
- }
-#endif
-#ifdef TARGET_PANDORA
- if (osd_font)
- {
- float u=0;
- float v=0;
-
- verify(glIsProgram(gl.OSD_SHADER.program));
-
- float dc_width=640;
- float dc_height=480;
-
- float dc2s_scale_h=screen_height/480.0f;
- float ds2s_offs_x=(screen_width-dc2s_scale_h*640)/2;
+void rend_set_fb_scale(float x,float y)
+{
+ fb_scale_x=x;
+ fb_scale_y=y;
+}
- glBindTexture(GL_TEXTURE_2D,osd_font);
- glUseProgram(gl.OSD_SHADER.program);
+struct glesrend : Renderer
+{
+ bool Init();
+ void Resize(int width, int height);
+ void Term();
- /*
- //-1 -> too much to left
- ShaderUniforms.scale_coefs[0]=2.0f/(screen_width/dc2s_scale_h);
- ShaderUniforms.scale_coefs[1]=-2/dc_height;
- ShaderUniforms.scale_coefs[2]=1-2*ds2s_offs_x/(screen_width);
- ShaderUniforms.scale_coefs[3]=-1;
+ bool Process(TA_context* ctx);
+ bool Render();
- glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs);
-*/
+ void Present();
- glEnable(GL_BLEND);
- glDisable(GL_DEPTH_TEST);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ void DrawOSD();
+ virtual u32 GetTexture(TSP tsp, TCW tcw);
+};
- glDepthMask(false);
- glDepthFunc(GL_ALWAYS);
+bool glesrend::Init()
+{
+
+ if (!gl_init((void*)libPvr_GetRenderTarget(), (void*)libPvr_GetRenderSurface()))
+ {
+ return false;
+ }
+ if (!gl_create_resources())
+ {
+ return false;
+ }
- glDisable(GL_CULL_FACE);
- glDisable(GL_SCISSOR_TEST);
+ #if defined(GLES) && HOST_OS != OS_DARWIN && !defined(TARGET_NACL32)
+ #ifdef TARGET_PANDORA
+ fbdev = open("/dev/fb0", O_RDONLY);
+ #else
+ eglSwapInterval(gl.setup.display,1);
+ #endif
+ #endif
+ //clean up all buffers ...
+ for (int i=0;i<10;i++)
+ {
+ glClearColor(0.f, 0.f, 0.f, 0.f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ gl_swap();
+ }
- int dfa=osd_count/4;
+ return true;
+}
- for (int i=0;i<dfa;i++)
- glDrawArrays(GL_TRIANGLE_STRIP,osd_base+i*4,4);
- }
-#endif
+void glesrend::Resize(int width, int height)
+{
+ screen_width = width;
+ screen_height = height;
}
-bool ProcessFrame(TA_context* ctx)
+void glesrend::Term() { };
+
+bool glesrend::Process(TA_context* ctx)
{
//disable RTTs for now ..
if (ctx->rend.isRTT)
@@ -1435,7 +1080,7 @@
return true;
}
-bool RenderFrame()
+bool glesrend::Render()
{
DoCleanup();
@@ -1737,10 +1382,10 @@
}
else
{
-#if HOST_OS != OS_DARWIN
- //Fix this in a proper way
- glBindFramebuffer(GL_FRAMEBUFFER,0);
-#endif
+ #if HOST_OS != OS_DARWIN
+ //Fix this in a proper way
+ glBindFramebuffer(GL_FRAMEBUFFER,0);
+ #endif
}
//Clear depth
@@ -1812,68 +1457,93 @@
return !is_rtt;
}
-#if !defined(_ANDROID) && !defined(TARGET_NACL32)
-#if HOST_OS==OS_LINUX
-#define SET_AFNT 1
-#endif
-#endif
-
-extern u16 kcode[4];
+void glesrend::Present()
+{
+ gl_swap();
+ glViewport(0, 0, screen_width, screen_height);
+}
-/*
-bool rend_single_frame()
+void glesrend::DrawOSD()
{
- //wait render start only if no frame pending
- _pvrrc = DequeueRender();
+ #ifdef TARGET_PANDORA
+ GLuint osd_texture = osd_font;
+ #else
+ GLuint osd_texture = osd_tex;
+ #endif
- while (!_pvrrc)
+ if (!osd_texture)
{
- rs.Wait();
- _pvrrc = DequeueRender();
+ return;
}
- bool do_swp=false;
- //if (kcode[0]&(1<<9))
- {
+ verify(glIsProgram(gl.OSD_SHADER.program));
+ #ifndef TARGET_PANDORA
+ float u = 0;
+ float v = 0;
+
+ for (int i = 0; i < 13; i++)
+ {
+ //umin,vmin,umax,vmax
+ vjoy_pos[i][4]=(u+1)/OSD_TEX_W;
+ vjoy_pos[i][5]=(v+1)/OSD_TEX_H;
- //clear up & free data ..
- tactx_Recycle(_pvrrc);
- _pvrrc=0;
+ vjoy_pos[i][6]=((u+vjoy_sz[0][i]-1))/OSD_TEX_W;
+ vjoy_pos[i][7]=((v+vjoy_sz[1][i]-1))/OSD_TEX_H;
- return do_swp;
-}
-*/
+ u+=vjoy_sz[0][i];
+ if (u>=OSD_TEX_W)
+ {
+ u-=OSD_TEX_W;
+ v+=vjoy_sz[1][i];
+ }
+ //v+=vjoy_pos[i][3];
+ }
+ #endif
+ glBindTexture(GL_TEXTURE_2D, osd_texture);
+ glUseProgram(gl.OSD_SHADER.program);
-void rend_set_fb_scale(float x,float y)
-{
- fb_scale_x=x;
- fb_scale_y=y;
-}
+ /*
+ //reset rendering scale
-struct glesrend : Renderer
-{
- bool Init() { return gles_init(); }
- void Resize(int w, int h) { screen_width=w; screen_height=h; }
- void Term() { }
+ float dc_width=640;
+ float dc_height=480;
- bool Process(TA_context* ctx) { return ProcessFrame(ctx); }
- bool Render() { return RenderFrame(); }
+ float dc2s_scale_h=screen_height/480.0f;
+ float ds2s_offs_x=(screen_width-dc2s_scale_h*640)/2;
- void Present() { gl_swap(); glViewport(0, 0, screen_width, screen_height); }
+ //-1 -> too much to left
+ ShaderUniforms.scale_coefs[0]=2.0f/(screen_width/dc2s_scale_h);
+ ShaderUniforms.scale_coefs[1]=-2/dc_height;
+ ShaderUniforms.scale_coefs[2]=1-2*ds2s_offs_x/(screen_width);
+ ShaderUniforms.scale_coefs[3]=-1;
- void DrawOSD() { OSD_DRAW(); }
+ glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs);
+ */
- virtual u32 GetTexture(TSP tsp, TCW tcw) {
- return gl_GetTexture(tsp, tcw);
- }
-};
+ glEnable(GL_BLEND);
+ glDisable(GL_DEPTH_TEST);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDepthMask(false);
+ glDepthFunc(GL_ALWAYS);
-#include "deps/libpng/png.h"
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_SCISSOR_TEST);
-FILE* pngfile;
+ int dfa = osd_count/4;
+
+ for (int i = 0; i < dfa; i++)
+ {
+ glDrawArrays(GL_TRIANGLE_STRIP, osd_base + i*4, 4);
+ }
+}
+
+u32 glesrend::GetTexture(TSP tsp, TCW tcw)
+{
+ return gl_GetTexture(tsp, tcw);
+}
void png_cstd_read(png_structp png_ptr, png_bytep data, png_size_t length)
{
@@ -2021,5 +1691,4 @@
return texture;
}
-
Renderer* rend_GLES2() { return new glesrend(); }
diff -Nur a/core/rend/gles/glshaders.cpp b/core/rend/gles/glshaders.cpp
--- a/core/rend/gles/glshaders.cpp 1969-12-31 21:00:00.000000000 -0300
+++ b/core/rend/gles/glshaders.cpp 2015-10-06 21:51:21.723570329 -0300
@@ -0,0 +1,280 @@
+#ifndef GLES
+#define attr "in"
+#define vary "out"
+#else
+#define attr "attribute"
+#define vary "varying"
+#endif
+#if 1
+
+//Fragment and vertex shaders code
+//pretty much 1:1 copy of the d3d ones for now
+const char* VertexShaderSource =
+#ifndef GLES
+ "#version 140 \n"
+#endif
+"\
+/* Vertex constants*/ \n\
+uniform highp vec4 scale; \n\
+uniform highp vec4 depth_scale; \n\
+uniform highp float sp_FOG_DENSITY; \n\
+/* Vertex input */ \n\
+" attr " highp vec4 in_pos; \n\
+" attr " lowp vec4 in_base; \n\
+" attr " lowp vec4 in_offs; \n\
+" attr " mediump vec2 in_uv; \n\
+/* output */ \n\
+" vary " lowp vec4 vtx_base; \n\
+" vary " lowp vec4 vtx_offs; \n\
+" vary " mediump vec2 vtx_uv; \n\
+" vary " highp vec3 vtx_xyz; \n\
+void main() \n\
+{ \n\
+ vtx_base=in_base; \n\
+ vtx_offs=in_offs; \n\
+ vtx_uv=in_uv; \n\
+ vec4 vpos=in_pos; \n\
+ vtx_xyz.xy = vpos.xy; \n\
+ vtx_xyz.z = vpos.z*sp_FOG_DENSITY; \n\
+ vpos.w=1.0/vpos.z; \n\
+ vpos.xy=vpos.xy*scale.xy-scale.zw; \n\
+ vpos.xy*=vpos.w; \n\
+ vpos.z=depth_scale.x+depth_scale.y*vpos.w; \n\
+ gl_Position = vpos; \n\
+}";
+
+
+#else
+
+
+
+const char* VertexShaderSource =
+ ""
+ "/* Test Projection Matrix */"
+ ""
+ "uniform highp mat4 Projection;"
+ ""
+ ""
+ "/* Vertex constants */"
+ ""
+ "uniform highp float sp_FOG_DENSITY;"
+ "uniform highp vec4 scale;"
+ ""
+ "/* Vertex output */"
+ ""
+ "attribute highp vec4 in_pos;"
+ "attribute lowp vec4 in_base;"
+ "attribute lowp vec4 in_offs;"
+ "attribute mediump vec2 in_uv;"
+ ""
+ "/* Transformed input */"
+ ""
+ "varying lowp vec4 vtx_base;"
+ "varying lowp vec4 vtx_offs;"
+ "varying mediump vec2 vtx_uv;"
+ "varying highp vec3 vtx_xyz;"
+ ""
+ "void main()"
+ "{"
+ " vtx_base = in_base;"
+ " vtx_offs = in_offs;"
+ " vtx_uv = in_uv;"
+ ""
+ " vec4 vpos = in_pos;"
+ " vtx_xyz.xy = vpos.xy; "
+ " vtx_xyz.z = vpos.z*sp_FOG_DENSITY; "
+ ""
+ " vpos.w = 1.0/vpos.z; "
+ " vpos.z *= -scale.w; "
+ " vpos.xy = vpos.xy*scale.xy-sign(scale.xy); "
+ " vpos.xy *= vpos.w; "
+ ""
+ " gl_Position = vpos;"
+ // " gl_Position = vpos * Projection;"
+ "}"
+ ;
+
+
+#endif
+
+/*
+
+cp_AlphaTest 0 1 2 2
+pp_ClipTestMode -1 0 1 3 6
+pp_UseAlpha 0 1 2 12
+pp_Texture 1
+ pp_IgnoreTexA 0 1 2 2
+ pp_ShadInstr 0 1 2 3 4 8
+ pp_Offset 0 1 2 16
+ pp_FogCtrl 0 1 2 3 4 64
+pp_Texture 0
+ pp_FogCtrl 0 2 3 4 4
+
+pp_Texture: off -> 12*4=48 shaders
+pp_Texture: on -> 12*64=768 shaders
+Total: 816 shaders
+
+highp float fdecp(highp float flt,out highp float e) \n\
+{ \n\
+ highp float lg2=log2(flt); //ie , 2.5 \n\
+ highp float frc=fract(lg2); //ie , 0.5 \n\
+ e=lg2-frc; //ie , 2.5-0.5=2 (exp) \n\
+ return pow(2.0,frc); //2^0.5 (manitsa) \n\
+} \n\
+lowp float fog_mode2(highp float invW) \n\
+{ \n\
+ highp float foginvW=invW; \n\
+ foginvW=clamp(foginvW,1.0,255.0); \n\
+ \n\
+ highp float fogexp; //0 ... 7 \n\
+ highp float fogman=fdecp(foginvW, fogexp); //[1,2) mantissa bits. that is 1.m \n\
+ \n\
+ highp float fogman_hi=fogman*16.0-16.0; //[16,32) -16 -> [0,16) \n\
+ highp float fogman_idx=floor(fogman_hi); //[0,15] \n\
+ highp float fogman_blend=fract(fogman_hi); //[0,1) -- can also be fogman_idx-fogman_idx ! \n\
+ highp float fog_idx_fr=fogexp*16.0+fogman_idx; //[0,127] \n\
+ \n\
+ highp float fog_idx_pixel_fr=fog_idx_fr+0.5; \n\
+ highp float fog_idx_pixel_n=fog_idx_pixel_fr/128.0;//normalise to [0.5/128,127.5/128) coordinates \n\
+ \n\
+ //fog is 128x1 texure \n\
+ lowp vec2 fog_coefs=texture2D(fog_table,vec2(fog_idx_pixel_n)).rg; \n\
+ \n\
+ lowp float fog_coef=mix(fog_coefs.r,fog_coefs.g,fogman_blend); \n\
+ \n\
+ return fog_coef; \n\
+} \n\
+*/
+
+#ifndef GLES
+#define FRAGCOL "FragColor"
+#define TEXLOOKUP "texture"
+#define vary "in"
+#else
+#define FRAGCOL "gl_FragColor"
+#define TEXLOOKUP "texture2D"
+#endif
+
+
+const char* PixelPipelineShader =
+#ifndef GLES
+ "#version 140 \n"
+ "out vec4 FragColor; \n"
+#endif
+"\
+\
+#define cp_AlphaTest %d \n\
+#define pp_ClipTestMode %d.0 \n\
+#define pp_UseAlpha %d \n\
+#define pp_Texture %d \n\
+#define pp_IgnoreTexA %d \n\
+#define pp_ShadInstr %d \n\
+#define pp_Offset %d \n\
+#define pp_FogCtrl %d \n\
+/* Shader program params*/ \n\
+/* gles has no alpha test stage, so its emulated on the shader */ \n\
+uniform lowp float cp_AlphaTestValue; \n\
+uniform lowp vec4 pp_ClipTest; \n\
+uniform lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT; \n\
+uniform highp vec2 sp_LOG_FOG_COEFS; \n\
+uniform sampler2D tex,fog_table; \n\
+/* Vertex input*/ \n\
+" vary " lowp vec4 vtx_base; \n\
+" vary " lowp vec4 vtx_offs; \n\
+" vary " mediump vec2 vtx_uv; \n\
+" vary " highp vec3 vtx_xyz; \n\
+lowp float fog_mode2(highp float val) \n\
+{ \n\
+ highp float fog_idx=clamp(val,0.0,127.99); \n\
+ return clamp(sp_LOG_FOG_COEFS.y*log2(fog_idx)+sp_LOG_FOG_COEFS.x,0.001,1.0); //the clamp is required due to yet another bug !\n\
+} \n\
+void main() \n\
+{ \n\
+ lowp vec4 color=vtx_base; \n\
+ #if pp_UseAlpha==0 \n\
+ color.a=1.0; \n\
+ #endif\n\
+ #if pp_FogCtrl==3 \n\
+ color=vec4(sp_FOG_COL_RAM.rgb,fog_mode2(vtx_xyz.z)); \n\
+ #endif\n\
+ #if pp_Texture==1 \n\
+ { \n\
+ lowp vec4 texcol=" TEXLOOKUP "(tex,vtx_uv); \n\
+ \n\
+ #if pp_IgnoreTexA==1 \n\
+ texcol.a=1.0; \n\
+ #endif\n\
+ \n\
+ #if pp_ShadInstr==0 \n\
+ { \n\
+ color.rgb=texcol.rgb; \n\
+ color.a=texcol.a; \n\
+ } \n\
+ #endif\n\
+ #if pp_ShadInstr==1 \n\
+ { \n\
+ color.rgb*=texcol.rgb; \n\
+ color.a=texcol.a; \n\
+ } \n\
+ #endif\n\
+ #if pp_ShadInstr==2 \n\
+ { \n\
+ color.rgb=mix(color.rgb,texcol.rgb,texcol.a); \n\
+ } \n\
+ #endif\n\
+ #if pp_ShadInstr==3 \n\
+ { \n\
+ color*=texcol; \n\
+ } \n\
+ #endif\n\
+ \n\
+ #if pp_Offset==1 \n\
+ { \n\
+ color.rgb+=vtx_offs.rgb; \n\
+ if (pp_FogCtrl==1) \n\
+ color.rgb=mix(color.rgb,sp_FOG_COL_VERT.rgb,vtx_offs.a); \n\
+ } \n\
+ #endif\n\
+ } \n\
+ #endif\n\
+ #if pp_FogCtrl==0 \n\
+ { \n\
+ color.rgb=mix(color.rgb,sp_FOG_COL_RAM.rgb,fog_mode2(vtx_xyz.z)); \n\
+ } \n\
+ #endif\n\
+ #if cp_AlphaTest == 1 \n\
+ if (cp_AlphaTestValue>color.a) discard;\n\
+ #endif \n\
+ //color.rgb=vec3(vtx_xyz.z/255.0);\n\
+ " FRAGCOL "=color; \n\
+}";
+
+const char* ModifierVolumeShader =
+#ifndef GLES
+ "#version 140 \n"
+ "out vec4 FragColor; \n"
+#endif
+" \
+uniform lowp float sp_ShaderColor; \n\
+/* Vertex input*/ \n\
+void main() \n\
+{ \n\
+ " FRAGCOL "=vec4(0.0, 0.0, 0.0, sp_ShaderColor); \n\
+}";
+
+const char* OSD_Shader =
+#ifndef GLES
+ "#version 140 \n"
+ "out vec4 FragColor; \n"
+#endif
+" \
+" vary " lowp vec4 vtx_base; \n\
+" vary " mediump vec2 vtx_uv; \n\
+/* Vertex input*/ \n\
+uniform sampler2D tex; \n\
+void main() \n\
+{ \n\
+ mediump vec2 uv=vtx_uv; \n\
+ uv.y=1.0-uv.y; \n\
+ " FRAGCOL "=vtx_base*" TEXLOOKUP "(tex,uv.st); \n\n\
+}";
diff -Nur a/core/rend/gles/glshaders.h b/core/rend/gles/glshaders.h
--- a/core/rend/gles/glshaders.h 1969-12-31 21:00:00.000000000 -0300
+++ b/core/rend/gles/glshaders.h 2015-10-06 21:51:21.723570329 -0300
@@ -0,0 +1,5 @@
+#pragma once
+extern const char* VertexShaderSource;
+extern const char* PixelPipelineShader;
+extern const char* ModifierVolumeShader;
+extern const char* OSD_Shader;
\ No newline at end of file
|