forked from khanhduytran0/android-gl-streaming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientgles.c
1755 lines (1411 loc) · 45.7 KB
/
clientgles.c
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
// This file declare OpenGL ES methods for streaming
#include "gls_command_gles2.h"
#include "glclient.h"
#include "fastlog.h"
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// Define core API functions as __GLS_##FUNC with FUNC exported as alias
#define GLS_DEF_CORE_API(RET, FUNC, ...) \
__asm__(".global " #FUNC "; .set " #FUNC ", __GLS_"#FUNC); \
static GL_APICALL RET GL_APIENTRY __GLS_##FUNC (__VA_ARGS__)
#define ATTRIBPOINTER_ARRAY_SIZE 16
static struct
{
GLuint vbo, ibo, ibo_emu;
struct attrib_pointer_t
{
GLboolean isenabled;
GLint size;
GLenum type;
GLsizei stride;
GLboolean normalized;
const GLvoid* ptr;
GLuint vbo_id;
GLuint emul_vbo_id;
} attrib_pointer[ATTRIBPOINTER_ARRAY_SIZE]; // FIXME: GL_MAX_VERTEX_ATTRIBS has no upper limit
} buffer_objs;
static unsigned _type_bytesize(GLenum type)
{
switch (type) {
case GL_BOOL: return sizeof(GLboolean);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
case GL_BYTE: return sizeof(GLbyte);
case GL_SHORT: return sizeof(GLshort);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_INT: return sizeof(GLint);
case GL_FIXED: return sizeof(GLfixed);
case GL_FLOAT: return sizeof(GLfloat);
default:
LOGE("%s: unhandled data type %x\n", __FUNCTION__, type);
assert(0);
}
}
static unsigned _pixelformat_to_bytes(GLenum format, GLenum type)
{
switch (type) {
case GL_UNSIGNED_BYTE:
switch (format) {
case GL_ALPHA:
return 1;
case GL_RGB:
return 3;
case GL_RGBA:
return 4;
case GL_LUMINANCE:
return 1;
case GL_LUMINANCE_ALPHA:
return 2;
case GL_BGRA_EXT:
return 4;
default:
LOGW("unhandled pixel format %x\n", format);
return 4;
}
case GL_UNSIGNED_SHORT_5_6_5:
return 2;
case GL_UNSIGNED_SHORT_4_4_4_4:
return 2;
case GL_UNSIGNED_SHORT_5_5_5_1:
return 2;
default:
LOGW("unhandled pixel type %x\n", type);
return 4;
}
}
GLS_DEF_CORE_API(void, glActiveTexture, GLenum texture)
{
GLS_SET_COMMAND_PTR(c, glActiveTexture);
c->texture = texture;
GLS_SEND_PACKET(glActiveTexture);
}
GLS_DEF_CORE_API(void, glAttachShader, GLuint program, GLuint shader)
{
GLS_SET_COMMAND_PTR(c, glAttachShader);
c->program = program;
c->shader = shader;
GLS_SEND_PACKET(glAttachShader);
}
GLS_DEF_CORE_API(void, glBindAttribLocation, GLuint program, GLuint index, const GLchar* name)
{
GLS_SET_COMMAND_PTR(c, glBindAttribLocation);
c->program = program;
c->index = index;
if (strlen(name) + 1 > sizeof(c->name)) {
LOGE("%s passed a name too long for protocol, len(%s) > %zu\n",
__FUNCTION__, name, sizeof(c->name));
client_gles_error = GL_INVALID_OPERATION;
return;
}
strcpy(c->name, name);
GLS_SEND_PACKET(glBindAttribLocation);
}
GLS_DEF_CORE_API(void, glBindBuffer, GLenum target, GLuint buffer)
{
GLS_SET_COMMAND_PTR(c, glBindBuffer);
c->target = target;
c->buffer = buffer;
GLS_SEND_PACKET(glBindBuffer);
// FIXME: should we wait and check for error ?
if (target == GL_ARRAY_BUFFER) {
buffer_objs.vbo = buffer;
} else if (target == GL_ELEMENT_ARRAY_BUFFER) {
buffer_objs.ibo = buffer;
} else
LOGE("unsupported buffer type!\n");
}
GLS_DEF_CORE_API(void, glBindFramebuffer, GLenum target, GLuint framebuffer)
{
GLS_SET_COMMAND_PTR(c, glBindFramebuffer);
c->target = target;
c->framebuffer = framebuffer;
GLS_SEND_PACKET(glBindFramebuffer);
}
GLS_DEF_CORE_API(void, glBindRenderbuffer, GLenum target, GLuint renderbuffer)
{
GLS_SET_COMMAND_PTR(c, glBindRenderbuffer);
c->target = target;
c->renderbuffer = renderbuffer;
GLS_SEND_PACKET(glBindRenderbuffer);
}
GLS_DEF_CORE_API(void, glBindTexture, GLenum target, GLuint texture)
{
GLS_SET_COMMAND_PTR(c, glBindTexture);
c->target = target;
c->texture = texture;
GLS_SEND_PACKET(glBindTexture);
}
GLS_DEF_CORE_API(void, glBlendColor, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
(void)red; (void)green; (void)blue; (void)alpha;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glBlendEquation, GLenum mode )
{
(void)mode;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glBlendEquationSeparate, GLenum modeRGB, GLenum modeAlpha)
{
GLS_SET_COMMAND_PTR(c, glBlendEquationSeparate);
c->modeRGB = modeRGB;
c->modeAlpha = modeAlpha;
GLS_SEND_PACKET(glBlendEquationSeparate);
}
GLS_DEF_CORE_API(void, glBlendFunc, GLenum sfactor, GLenum dfactor)
{
GLS_SET_COMMAND_PTR(c, glBlendFunc);
c->sfactor = sfactor;
c->dfactor = dfactor;
GLS_SEND_PACKET(glBlendFunc);
}
GLS_DEF_CORE_API(void, glBlendFuncSeparate, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
{
GLS_SET_COMMAND_PTR(c, glBlendFuncSeparate);
c->srcRGB = srcRGB;
c->dstRGB = dstRGB;
c->srcAlpha = srcAlpha;
c->dstAlpha = dstAlpha;
GLS_SEND_PACKET(glBlendFuncSeparate);
}
GLS_DEF_CORE_API(void, glBufferData, GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
{
if (data)
gls_cmd_send_data((uint32_t)size, (void*)data);
GLS_SET_COMMAND_PTR(c, glBufferData);
c->target = target;
c->size = size;
c->usage = usage;
c->has_data = (data != NULL);
GLS_SEND_PACKET(glBufferData);
}
GLS_DEF_CORE_API(void, glBufferSubData, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
{
if (data)
gls_cmd_send_data((uint32_t)size, (void*)data);
GLS_SET_COMMAND_PTR(c, glBufferSubData);
c->target = target;
c->offset = offset;
c->size = size;
c->has_data = (data != NULL);
GLS_SEND_PACKET(glBufferSubData);
}
GLS_DEF_CORE_API(GLenum, glCheckFramebufferStatus, GLenum target)
{
GLS_SET_COMMAND_PTR(c, glCheckFramebufferStatus);
c->target = target;
GLS_SEND_PACKET(glCheckFramebufferStatus);
GLS_WAIT_SET_RET_PTR(ret, glCheckFramebufferStatus);
GLS_RELEASE_RETURN_RET(GLenum, ret, status);
}
GLS_DEF_CORE_API(void, glClear, GLbitfield mask)
{
GLS_SET_COMMAND_PTR(c, glClear);
c->mask = mask;
GLS_SEND_PACKET(glClear);
}
GLS_DEF_CORE_API(void, glClearColor, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
GLS_SET_COMMAND_PTR(c, glClearColor);
c->red = red;
c->green = green;
c->blue = blue;
c->alpha = alpha;
GLS_SEND_PACKET(glClearColor);
}
GLS_DEF_CORE_API(void, glClearDepthf, GLclampf depth)
{
GLS_SET_COMMAND_PTR(c, glClearDepthf);
c->depth = depth;
GLS_SEND_PACKET(glClearDepthf);
}
GLS_DEF_CORE_API(void, glClearStencil, GLint s)
{
GLS_SET_COMMAND_PTR(c, glClearStencil);
c->s = s;
GLS_SEND_PACKET(glClearStencil);
}
GLS_DEF_CORE_API(void, glColorMask, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
{
GLS_SET_COMMAND_PTR(c, glColorMask);
c->red = red;
c->green = green;
c->blue = blue;
c->alpha = alpha;
GLS_SEND_PACKET(glColorMask);
}
GLS_DEF_CORE_API(void, glCompileShader, GLuint shader)
{
GLS_SET_COMMAND_PTR(c, glCompileShader);
c->shader = shader;
GLS_SEND_PACKET(glCompileShader);
}
GLS_DEF_CORE_API(void, glCompressedTexImage2D, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data)
{
(void) target; (void) level; (void) internalformat; (void) width; (void) height;
(void) border; (void) imageSize; (void) data;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glCompressedTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data)
{
(void) target; (void) level; (void) xoffset; (void)yoffset; (void) width; (void) height;
(void) format; (void) imageSize; (void) data;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glCopyTexImage2D, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
{
(void) target; (void) level; (void) internalformat; (void) x; (void) y;
(void) width; (void) height; (void) border;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glCopyTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
{
GLS_SET_COMMAND_PTR(c, glCopyTexSubImage2D);
c->target = target;
c->level = level;
c->xoffset = xoffset;
c->yoffset = yoffset;
c->x = x;
c->y = y;
c->width = width;
c->height = height;
GLS_SEND_PACKET(glCopyTexSubImage2D);
}
GLS_DEF_CORE_API(GLuint, glCreateProgram, void)
{
GLS_SET_COMMAND_PTR(c, glCreateProgram);
GLS_SEND_PACKET(glCreateProgram);
GLS_WAIT_SET_RET_PTR(ret, glCreateProgram);
GLS_RELEASE_RETURN_RET(GLuint, ret, program);
}
GLS_DEF_CORE_API(GLuint, glCreateShader, GLenum type)
{
GLS_SET_COMMAND_PTR(c, glCreateShader);
c->type = type;
GLS_SEND_PACKET(glCreateShader);
GLS_WAIT_SET_RET_PTR(ret, glCreateShader);
GLS_RELEASE_RETURN_RET(GLuint, ret, obj);
}
GLS_DEF_CORE_API(void, glCullFace, GLenum mode)
{
GLS_SET_COMMAND_PTR(c, glCullFace);
c->mode = mode;
GLS_SEND_PACKET(glCullFace);
}
GLS_DEF_CORE_API(void, glDeleteBuffers, GLsizei n, const GLuint* buffers)
{
_Static_assert(sizeof(GLuint) == sizeof(uint32_t), "int size mismatch");
if (buffer_objs.vbo || buffer_objs.ibo)
for (int i = 0; i < n; i++) {
// deleting a buffer causes bindings to be reset to 0, record that
if (buffers[i] == buffer_objs.vbo) buffer_objs.vbo = 0;
if (buffers[i] == buffer_objs.ibo) buffer_objs.ibo = 0;
}
uint32_t size = n * sizeof(uint32_t);
gls_cmd_send_data(size, (void*)buffers);
GLS_SET_COMMAND_PTR(c, glDeleteBuffers);
c->n = n;
GLS_SEND_PACKET(glDeleteBuffers);
}
GLS_DEF_CORE_API(void, glDeleteFramebuffers, GLsizei n, const GLuint* framebuffers)
{
uint32_t datasize = n * sizeof(uint32_t);
GLS_SET_COMMAND_PTR(c, glDeleteFramebuffers);
c->n = n;
GLS_VARIABLE_PAYLOAD(c, framebuffers, datasize);
send_packet();
}
GLS_DEF_CORE_API(void, glDeleteProgram, GLuint program)
{
GLS_SET_COMMAND_PTR(c, glDeleteProgram);
c->program = program;
GLS_SEND_PACKET(glDeleteProgram);
}
GLS_DEF_CORE_API(void, glDeleteRenderbuffers, GLsizei n, const GLuint* renderbuffers)
{
uint32_t datasize = n * sizeof(uint32_t);
GLS_SET_COMMAND_PTR(c, glDeleteRenderbuffers);
c->n = n;
GLS_VARIABLE_PAYLOAD(c, renderbuffers, datasize);
send_packet();
}
GLS_DEF_CORE_API(void, glDeleteShader, GLuint shader)
{
GLS_SET_COMMAND_PTR(c, glDeleteShader);
c->shader = shader;
GLS_SEND_PACKET(glDeleteShader);
}
GLS_DEF_CORE_API(void, glDeleteTextures, GLsizei n, const GLuint* textures)
{
uint32_t datasize = n * sizeof(uint32_t);
GLS_SET_COMMAND_PTR(c, glDeleteTextures);
c->n = n;
GLS_VARIABLE_PAYLOAD(c, textures, datasize);
send_packet();
}
GLS_DEF_CORE_API(void, glDepthFunc, GLenum func)
{
GLS_SET_COMMAND_PTR(c, glDepthFunc);
c->func = func;
GLS_SEND_PACKET(glDepthFunc);
}
GLS_DEF_CORE_API(void, glDepthMask, GLboolean flag)
{
GLS_SET_COMMAND_PTR(c, glDepthMask);
c->flag = flag;
GLS_SEND_PACKET(glDepthMask);
}
GLS_DEF_CORE_API(void, glDepthRangef, GLclampf zNear, GLclampf zFar)
{
GLS_SET_COMMAND_PTR(c, glDepthRangef);
c->zNear = zNear;
c->zFar = zFar;
GLS_SEND_PACKET(glDepthRangef);
}
GLS_DEF_CORE_API(void, glDetachShader, GLuint program, GLuint shader)
{
(void)program; (void)shader;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glDisable, GLenum cap)
{
GLS_SET_COMMAND_PTR(c, glDisable);
c->cap = cap;
GLS_SEND_PACKET(glDisable);
}
GLS_DEF_CORE_API(void, glDisableVertexAttribArray, GLuint index)
{
GLS_SET_COMMAND_PTR(c, glDisableVertexAttribArray);
c->index = index;
GLS_SEND_PACKET(glDisableVertexAttribArray);
// FIXME: should we wait and check for error ?
buffer_objs.attrib_pointer[index].isenabled = GL_FALSE;
}
/*
* Send defered glVertexAttribPointer after we set up a VBO
*/
static void _send_glVertexAttribPointer(
GLuint indx, GLint size, GLenum type, GLboolean normalized,
GLsizei stride, const GLvoid* ptr)
{
GLS_SET_COMMAND_PTR(c, glVertexAttribPointer);
c->indx = indx;
c->size = size;
c->type = type;
c->normalized = normalized;
c->stride = stride;
c->ptr_uint = (uint64_t)ptr;
GLS_SEND_PACKET(glVertexAttribPointer);
}
static void defered_vertex_attrib_pointer(int i, int count)
{
int stride;
struct attrib_pointer_t* const attrib = &buffer_objs.attrib_pointer[i];
if (!attrib->isenabled)
return;
if (attrib->vbo_id)
// uses a VBO, already sent
return;
if (buffer_objs.ibo && !attrib->vbo_id)
// FIXME: could be done, would require scanning scanning IBO,
// which requires work in in glBuffer(Sub)Data ... but who needs
// that for real ?
WARN_ONCE("%s use of client-data vertex buffer together with an IBO is not implemented\n", __FUNCTION__);
if (!attrib->emul_vbo_id)
glGenBuffers(1, &attrib->emul_vbo_id);
stride = attrib->stride;
if (stride == 0)
stride = attrib->size * _type_bytesize(attrib->type);
if (glsc_global.is_debug)
LOGD("%s: uploading %u bytes to emulation VBO\n", __FUNCTION__,
count * stride);
glBindBuffer(GL_ARRAY_BUFFER, attrib->emul_vbo_id);
glBufferData(GL_ARRAY_BUFFER, count * stride, (void*)attrib->ptr, GL_STREAM_DRAW);
_send_glVertexAttribPointer(i, attrib->size, attrib->type, attrib->normalized, attrib->stride, 0);
}
GLS_DEF_CORE_API(void, glDrawArrays, GLenum mode, GLint first, GLsizei count)
{
if (glsc_global.is_debug)
LOGD("preparing %s\n", "glDrawArrays");
GLuint vbo_bkp = buffer_objs.vbo;
int i;
if (!buffer_objs.vbo)
WARN_ONCE("%s uses client-data vertex buffer, consider using a VBO\n", __FUNCTION__);
for (i = 0; i < ATTRIBPOINTER_ARRAY_SIZE; i++)
defered_vertex_attrib_pointer(i, first + count);
if (vbo_bkp != buffer_objs.vbo)
glBindBuffer( GL_ARRAY_BUFFER, vbo_bkp );
GLS_SET_COMMAND_PTR(c, glDrawArrays);
c->mode = mode;
c->first = first;
c->count = count;
GLS_SEND_PACKET(glDrawArrays);
// FIXME should free VBO's emulating client arrays
}
GLS_DEF_CORE_API(void, glDrawElements, GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
{
if (glsc_global.is_debug)
LOGD("preparing %s\n", "glDrawElements");
uint32_t sizeoftype = _type_bytesize(type);
GLuint vbo_bkp = buffer_objs.vbo;
GLuint ibo_bkp = buffer_objs.ibo;
int i;
// how much client-data is needed depends on max index in indices
int max_idx = -1;
if (!buffer_objs.ibo) {
for (i = 0; i < count; i++) {
int idx = GL_UNSIGNED_BYTE ? ((unsigned char*)indices)[i] : ((unsigned short*)indices)[i];
if (idx > max_idx) max_idx = idx;
}
if (max_idx < 0) {
client_gles_error = GL_INVALID_OPERATION;
LOGE("%s: failed to compute max index in IBO\n", __FUNCTION__);
return;
}
}
// transfer client-data
for (i = 0; i < ATTRIBPOINTER_ARRAY_SIZE; i++) {
defered_vertex_attrib_pointer(i, max_idx + 1);
}
if (!buffer_objs.ibo) {
WARN_ONCE("%s uses client-data index buffer, consider using an IBO\n", __FUNCTION__);
if ( !buffer_objs.ibo_emu ) {
glGenBuffers(1, &buffer_objs.ibo_emu);
}
if (glsc_global.is_debug)
LOGD("%s: uploading %u bytes to emulation IBO\n", __FUNCTION__,
count * sizeoftype);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer_objs.ibo_emu);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeoftype, indices, GL_STREAM_DRAW);
}
GLS_SET_COMMAND_PTR(c, glDrawElements);
c->mode = mode;
c->count = count;
c->type = type;
if (buffer_objs.ibo) {
// offset into IBO
c->indices = (uint32_t)(GLintptr)indices;
assert((GLvoid*)(GLintptr)c->indices == indices);
} else
c->indices = 0;
GLS_SEND_PACKET(glDrawElements);
if (ibo_bkp != buffer_objs.ibo)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_bkp);
if (vbo_bkp != buffer_objs.vbo)
glBindBuffer(GL_ARRAY_BUFFER, vbo_bkp);
// FIXME should free VBO's and IBO emulating client arrays
}
GLS_DEF_CORE_API(void, glEnable, GLenum cap)
{
GLS_SET_COMMAND_PTR(c, glEnable);
c->cap = cap;
GLS_SEND_PACKET(glEnable);
}
GLS_DEF_CORE_API(void, glEnableVertexAttribArray, GLuint index)
{
GLS_SET_COMMAND_PTR(c, glEnableVertexAttribArray);
c->index = index;
GLS_SEND_PACKET(glEnableVertexAttribArray);
// FIXME: should we wait and check for error ?
buffer_objs.attrib_pointer[index].isenabled = GL_TRUE;
}
GLS_DEF_CORE_API(void, glFinish, void)
{
WARN_STUBBED(); // wrong semantics
GLS_SET_COMMAND_PTR(c, glFinish);
GLS_SEND_PACKET(glFinish);
}
GLS_DEF_CORE_API(void, glFlush, void)
{
GLS_SET_COMMAND_PTR(c, glFlush);
GLS_SEND_PACKET(glFlush);
}
GLS_DEF_CORE_API(void, glFramebufferRenderbuffer, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
{
GLS_SET_COMMAND_PTR(c, glFramebufferRenderbuffer);
c->target = target;
c->attachment = attachment;
c->renderbuffertarget = renderbuffertarget;
c->renderbuffer = renderbuffer;
GLS_SEND_PACKET(glFramebufferRenderbuffer);
}
GLS_DEF_CORE_API(void, glFramebufferTexture2D, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
GLS_SET_COMMAND_PTR(c, glFramebufferTexture2D);
c->target = target;
c->attachment = attachment;
c->textarget = textarget;
c->texture = texture;
c->level = level;
GLS_SEND_PACKET(glFramebufferTexture2D);
}
GLS_DEF_CORE_API(void, glFrontFace, GLenum mode)
{
(void)mode;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glGenBuffers, GLsizei n, GLuint* buffers)
{
GLS_SET_COMMAND_PTR(c, glGenBuffers);
c->n = n;
GLS_SEND_PACKET(glGenBuffers);
GLS_WAIT_SET_RAWRET_PTR(ret, void, glGenBuffers);
_Static_assert(sizeof(GLuint) == sizeof(uint32_t), "int size mismatch");
memcpy(buffers, ret, c->n * sizeof(uint32_t));
}
GLS_DEF_CORE_API(void, glGenerateMipmap, GLenum target)
{
GLS_SET_COMMAND_PTR(c, glGenerateMipmap);
c->target = target;
GLS_SEND_PACKET(glGenerateMipmap);
}
GLS_DEF_CORE_API(void, glGenFramebuffers, GLsizei n, GLuint* framebuffers)
{
GLS_SET_COMMAND_PTR(c, glGenFramebuffers);
c->n = n;
GLS_SEND_PACKET(glGenFramebuffers);
GLS_WAIT_SET_RAWRET_PTR(ret, void, glGenFramebuffers);
_Static_assert(sizeof(GLuint) == sizeof(uint32_t), "int size mismatch");
memcpy(framebuffers, ret, c->n * sizeof(uint32_t));
}
GLS_DEF_CORE_API(void, glGenRenderbuffers, GLsizei n, GLuint* renderbuffers)
{
GLS_SET_COMMAND_PTR(c, glGenRenderbuffers);
c->n = n;
GLS_SEND_PACKET(glGenRenderbuffers);
GLS_WAIT_SET_RAWRET_PTR(ret, void, glGenRenderbuffers);
_Static_assert(sizeof(GLuint) == sizeof(uint32_t), "int size mismatch");
memcpy(renderbuffers, ret, c->n * sizeof(uint32_t));
}
GLS_DEF_CORE_API(void, glGenTextures, GLsizei n, GLuint* textures)
{
GLS_SET_COMMAND_PTR(c, glGenTextures);
c->n = n;
GLS_SEND_PACKET(glGenTextures);
GLS_WAIT_SET_RAWRET_PTR(ret, void, glGenTextures);
_Static_assert(sizeof(GLuint) == sizeof(uint32_t), "int size mismatch");
memcpy(textures, ret, c->n * sizeof(uint32_t));
}
GLS_DEF_CORE_API(void, glGetActiveAttrib, GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
{
WARN_UNTESTED();
GLS_SET_COMMAND_PTR(c, glGetActiveAttrib);
c->program = program;
c->index = index;
c->bufsize = bufsize;
GLS_SET_RET_PTR(ret, glGetActiveAttrib);
if ((unsigned)bufsize > sizeof(ret->name)) {
c->bufsize = sizeof(ret->name);
LOGW("%s: buffer for attrib name limited by protocol: %u => %u\n",
__FUNCTION__, bufsize, c->bufsize);
}
GLS_SEND_PACKET(glGetActiveAttrib);
GLS_WAIT_RET(GLSC_glGetActiveAttrib, glGetActiveAttrib);
if (length != NULL) {
*length = ret->length;
}
*size = ret->size;
*type = ret->type;
if (ret->length == 0) {
ret->name[0] = '\0';
}
strncpy(name, ret->name, (size_t)bufsize);
GLS_RELEASE_RET();
}
GLS_DEF_CORE_API(void, glGetActiveUniform, GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
{
WARN_UNTESTED();
GLS_SET_COMMAND_PTR(c, glGetActiveUniform);
c->program = program;
c->index = index;
c->bufsize = bufsize;
GLS_SET_RET_PTR(ret, glGetActiveUniform);
if ((unsigned)bufsize > sizeof(ret->name)) {
c->bufsize = sizeof(ret->name);
LOGW("%s: buffer for uniform name limited by protocol: %u => %u\n",
__FUNCTION__, bufsize, c->bufsize);
}
GLS_SEND_PACKET(glGetActiveUniform);
GLS_WAIT_RET(GLSC_glGetActiveUniform, glGetActiveUniform);
if (length != NULL) {
*length = ret->length;
}
*size = ret->size;
*type = ret->type;
if (ret->length == 0) {
ret->name[0] = '\0';
}
strncpy(name, ret->name, (size_t)bufsize);
GLS_RELEASE_RET();
}
GLS_DEF_CORE_API(void, glGetAttachedShaders, GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
{
(void)program; (void)maxcount; (void)count; (void)shaders;
WARN_STUBBED();
}
GLS_DEF_CORE_API(GLint, glGetAttribLocation, GLuint program, const GLchar* name)
{
GLS_SET_COMMAND_PTR(c, glGetAttribLocation);
c->program = program;
if (strlen(name) + 1 > sizeof(c->name)) {
LOGE("%s passed a name too long for protocol, len(%s) > %zu\n",
__FUNCTION__, name, sizeof(c->name));
client_gles_error = GL_INVALID_OPERATION;
return -1;
}
strcpy(c->name, name);
GLS_SEND_PACKET(glGetAttribLocation);
GLS_WAIT_SET_RET_PTR(ret, glGetAttribLocation);
GLS_RELEASE_RETURN_RET(GLint, ret, index);
}
GLS_DEF_CORE_API(void, glGetBooleanv, GLenum pname, GLboolean* params)
{
(void)pname; (void)params;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glGetBufferParameteriv, GLenum target, GLenum pname, GLint* params)
{
(void)target; (void)pname; (void)params;
WARN_STUBBED();
}
GLS_DEF_CORE_API(GLenum, glGetError, void)
{
if (client_gles_error != GL_NO_ERROR)
return client_gles_error;
GLS_SET_COMMAND_PTR(c, glGetError);
GLS_SEND_PACKET(glGetError);
GLS_WAIT_SET_RET_PTR(ret, glGetError);
GLS_RELEASE_RETURN_RET(GLenum, ret, error);
}
GLS_DEF_CORE_API(void, glGetFloatv, GLenum name, GLfloat* params)
{
GLS_SET_COMMAND_PTR(c, glGetFloatv);
c->name = name;
GLS_SEND_PACKET(glGetFloatv);
GLS_WAIT_SET_RET_PTR(ret, glGetFloatv);
*params = ret->params;
GLS_RELEASE_RET();
}
GLS_DEF_CORE_API(void, glGetFramebufferAttachmentParameteriv, GLenum target, GLenum attachment, GLenum pname, GLint* params)
{
(void)target; (void)attachment; (void)pname; (void)params;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glGetIntegerv, GLenum name, GLint* params)
{
GLS_SET_COMMAND_PTR(c, glGetIntegerv);
c->name = name;
GLS_SEND_PACKET(glGetIntegerv);
GLS_WAIT_SET_RET_PTR(ret, glGetIntegerv);
*params = ret->params;
GLS_RELEASE_RET();
}
GLS_DEF_CORE_API(void, glGetProgramiv, GLuint program, GLenum pname, GLint* params)
{
GLS_SET_COMMAND_PTR(c, glGetProgramiv);
c->program = program;
c->pname = pname;
GLS_SEND_PACKET(glGetProgramiv);
GLS_WAIT_SET_RET_PTR(ret, glGetProgramiv);
*params = ret->params;
GLS_RELEASE_RET();
}
GLS_DEF_CORE_API(void, glGetProgramInfoLog, GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
{
WARN_UNTESTED();
GLS_SET_COMMAND_PTR(c, glGetProgramInfoLog);
c->program = program;
c->bufsize = bufsize;
GLS_SEND_PACKET(glGetProgramInfoLog);
GLS_WAIT_SET_RET_PTR(ret, glGetProgramInfoLog);
if (ret->length > bufsize - 1) {
client_gles_error = GL_INVALID_VALUE;
GLS_RELEASE_RET();
return;
}
if (length != NULL)
*length = ret->length;
memcpy(infolog, ret->infolog, ret->length);
ret->infolog[ret->length] = '\0';
GLS_RELEASE_RET();
}
GLS_DEF_CORE_API(void, glGetRenderbufferParameteriv, GLenum target, GLenum pname, GLint* params)
{
(void)target; (void)pname; (void)params;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glGetShaderiv, GLuint shader, GLenum pname, GLint* params)
{
GLS_SET_COMMAND_PTR(c, glGetShaderiv);
c->shader = shader;
c->pname = pname;
GLS_SEND_PACKET(glGetShaderiv);
GLS_WAIT_SET_RET_PTR(ret, glGetShaderiv);
*params = ret->params;
}
GLS_DEF_CORE_API(void, glGetShaderInfoLog, GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
{
WARN_UNTESTED();
GLS_SET_COMMAND_PTR(c, glGetShaderInfoLog);
c->shader = shader;
c->bufsize = bufsize;
GLS_SEND_PACKET(glGetShaderInfoLog);
GLS_WAIT_SET_RET_PTR(ret, glGetShaderInfoLog);
if (ret->length > bufsize - 1) {
client_gles_error = GL_INVALID_VALUE;
GLS_RELEASE_RET();
return;
}
if (length != NULL)
*length = ret->length;
strncpy(infolog, ret->infolog, (size_t)bufsize);
ret->infolog[ret->length] = '\0';
GLS_RELEASE_RET();
}
GLS_DEF_CORE_API(void, glGetShaderPrecisionFormat, GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
{
(void)shadertype; (void)precisiontype; (void)range; (void)precision;
WARN_STUBBED();
}
GLS_DEF_CORE_API(void, glGetShaderSource, GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
{
(void)shader; (void)bufsize; (void)length; (void)source;
WARN_STUBBED();
}
// glGetString (with caching)
static const GLubyte* GL_APIENTRY _real_glGetString(GLenum name)
{
GLS_SET_COMMAND_PTR(c, glGetString);
c->name = name;
GLS_SEND_PACKET(glGetString);
GLS_WAIT_SET_RET_PTR(ret, glGetString);
if (!ret->success) {
GLS_RELEASE_RET();
return NULL;
}
// emulating static buffer: must defer freeing until after copied
return (GLubyte*)ret->params;
}
#define GLS_GLESGETSTRING_ITEMS() \
EMPTY() \
X(VENDOR) \
X(RENDERER) \
X(VERSION) \
X(SHADING_LANGUAGE_VERSION) \
X(EXTENSIONS) \
//
static struct
{