-
Notifications
You must be signed in to change notification settings - Fork 5
/
glesmodule.c
5506 lines (4605 loc) · 171 KB
/
glesmodule.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
/**
* ====================================================================
* glesmodule.cpp
*
* Copyright (c) 2006 Nokia Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "glesmodule.h"
PyTypeObject *array_type;
#define GLES_ARRAY_TYPE array_type
PyObject *new_array_object(PyObject *self, PyObject *args)
{
array_object *op = NULL;
PyObject *sequence;
void *arrdata = NULL;
int type;
int dimension;
#ifdef DEBUG_GLES
DEBUGMSG("new_array_object()");
#endif
if (!PyArg_ParseTuple(args, "iiO:array", &type, &dimension, &sequence)) {
return NULL;
}
if (!PySequence_Check(sequence) ) {
PyErr_SetString(PyExc_TypeError, "Expecting a sequence");
return NULL;
}
op = PyObject_New(array_object, GLES_ARRAY_TYPE);
if (!op) {
return PyErr_NoMemory();
}
sequence = gles_PySequence_Collapse(type, sequence, NULL);
if(sequence==NULL) {
// There should be an exception
assert(PyErr_Occurred() != NULL);
// Delete the object since we're not going to use it anymore anyways
PyObject_Del(op);
return NULL;
}
switch(type) {
case GL_FLOAT:
arrdata = gles_PySequence_AsGLfloatArray(sequence);
op->item_size = sizeof(GLfloat);
break;
case GL_BYTE:
arrdata = gles_PySequence_AsGLbyteArray(sequence);
op->item_size = sizeof(GLbyte);
break;
case GL_UNSIGNED_BYTE:
arrdata = gles_PySequence_AsGLubyteArray(sequence);
op->item_size = sizeof(GLubyte);
break;
case GL_SHORT:
arrdata = gles_PySequence_AsGLshortArray(sequence);
op->item_size = sizeof(GLshort);
break;
case GL_UNSIGNED_SHORT:
arrdata = gles_PySequence_AsGLushortArray(sequence);
op->item_size = sizeof(GLushort);
break;
case GL_FIXED:
arrdata = gles_PySequence_AsGLfixedArray(sequence);
op->item_size = sizeof(GLfixed);
break;
default:
PyErr_SetString(PyExc_ValueError, "Invalid array type specified");
return NULL;
}
// We should have an exception from the previous functions if arrdata==NULL
if(arrdata == NULL) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
op->arrdata = arrdata;
op->len = PySequence_Length(sequence);
// Calculate the length in memory
op->real_len = op->item_size * op->len;
op->arrtype = type;
op->dimension = dimension;
if (!op->arrdata) {
PyObject_Del(op);
return PyErr_NoMemory();
}
return (PyObject*)op;
}
int array_length(PyObject *self) {
array_object *op = (array_object*)self;
return op->len;
}
PyObject *array_getitem(PyObject *self, int idx) {
array_object *op = (array_object*)self;
PyObject *ret = NULL;
if(idx > op->len-1 ) {
PyErr_SetString(PyExc_IndexError, "list index out of range");
return NULL;
}
switch(op->arrtype) {
case GL_FLOAT:
ret = PyFloat_FromDouble(*((GLfloat*)op->arrdata+idx));
break;
case GL_BYTE:
ret = PyInt_FromLong(*((GLbyte*)op->arrdata+idx));
break;
case GL_UNSIGNED_BYTE:
/// Python 2.2.2 does not have PyInt_FromUnsignedLong()
ret = PyLong_FromUnsignedLong(*((GLubyte*)op->arrdata+idx));
break;
case GL_SHORT:
ret = PyInt_FromLong(*((GLshort*)op->arrdata+idx));
break;
case GL_UNSIGNED_SHORT:
ret = PyLong_FromUnsignedLong(*((GLushort*)op->arrdata+idx));
break;
case GL_FIXED:
ret = PyInt_FromLong(*((GLfixed*)op->arrdata+idx));
break;
default:
// This should never happen, but it's never too safe not to check
PyErr_SetString(PyExc_RuntimeError, "Unknown type of array");
return NULL;
}
return ret;
}
int array_setitem(PyObject *self, int idx, PyObject *v) {
array_object *op = (array_object*)self;
if(idx > op->len-1 ) {
PyErr_SetString(PyExc_IndexError, "list index out of range");
return -1;
}
if(!PyNumber_Check(v)) {
PyErr_SetString(PyExc_TypeError, "Expecting a number");
return -1;
}
switch(op->arrtype) {
case GL_FLOAT:
*((GLfloat*)op->arrdata+idx) = (GLfloat)PyFloat_AsDouble(v);
break;
case GL_BYTE:
*((GLbyte*)op->arrdata+idx) = (GLbyte)PyInt_AsLong(v);
break;
case GL_UNSIGNED_BYTE:
*((GLubyte*)op->arrdata+idx) = (GLubyte)PyInt_AsLong(v);
break;
case GL_SHORT:
*((GLshort*)op->arrdata+idx) = (GLshort)PyInt_AsLong(v);
break;
case GL_UNSIGNED_SHORT:
*((GLushort*)op->arrdata+idx) = (GLushort)PyInt_AsLong(v);
break;
case GL_FIXED:
*((GLfixed*)op->arrdata+idx) = (GLfixed)PyInt_AsLong(v);
break;
default:
// This should never happen, but it's never too safe not to check
PyErr_SetString(PyExc_RuntimeError, "Unknown type of array");
return 0;
}
return 0;
}
//{
static void
array_dealloc(array_object *op)
{
#ifdef DEBUG_GLES
DEBUGMSG("array_dealloc\n");
#endif
if(op->arrdata) {
gles_free(op->arrdata);
}
PyObject_Del(op);
}
PyMethodDef array_methods[] = {
{NULL, NULL} // sentinel
};
PySequenceMethods array_as_sequence = {
(inquiry)array_length, /* sq_length */
/*(binaryfunc)*/0, /* sq_concat */
/*(intargfunc)*/0, /* sq_repeat */
(intargfunc)array_getitem, /* sq_item */
/*(intintargfunc)*/0, /* sq_slice */
(intobjargproc)array_setitem, /* sq_ass_item */
0, /* sq_ass_slice */
/*(objobjproc)*/0, /* sq_contains */
};
static PyObject *
array_getattr(array_object *op, char *name)
{
PyObject *ret;
if (!strcmp(name,"len")) {
ret = PyInt_FromLong(op->len);
return ret;
}
return Py_FindMethod((PyMethodDef*)array_methods,
(PyObject*)op, name);
}
static int
array_setattr(array_object *op, char *name, PyObject *v )
{
PyErr_SetString(PyExc_AttributeError, "no such attribute");
return -1;
}
static PyTypeObject c_array_type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"GLESArray", /*tp_name*/
sizeof(array_object), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)array_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)array_getattr, /*tp_getattr*/
(setattrfunc)array_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
&array_as_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
};
//} // extern "C"
/***********************************************
* The bindings code starts here *
***********************************************/
PyObject *gles_glActiveTexture(PyObject *self, PyObject *args) {
GLenum texture;
if( !PyArg_ParseTuple(args, "i:glActiveTexture", &texture) ) {
return NULL;
}
glActiveTexture(texture);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glAlphaFunc(PyObject *self, PyObject *args) {
GLenum func;
GLclampf ref;
if( !PyArg_ParseTuple(args, "if:glAlphaFunc", &func, &ref) ) {
return NULL;
}
glAlphaFunc(func, ref);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glAlphaFuncx(PyObject *self, PyObject *args) {
GLenum func;
GLclampx ref;
if( !PyArg_ParseTuple(args, "ii:glAlphaFuncx", &func, &ref) ) {
return NULL;
}
glAlphaFuncx(func, ref);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glBindTexture(PyObject *self, PyObject *args) {
GLenum target;
GLuint texture;
if( !PyArg_ParseTuple(args, "ii:glBindTexture", &target, &texture)) {
return NULL;
}
glBindTexture(target, texture);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glBlendFunc(PyObject *self, PyObject *args) {
GLenum sfactor;
GLenum dfactor;
if( !PyArg_ParseTuple(args, "ii:glBlendFunc", &sfactor, &dfactor) ) {
return NULL;
}
glBlendFunc(sfactor, dfactor);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glClear (PyObject *self, PyObject *args) {
unsigned int mask;
if ( !PyArg_ParseTuple(args, "i:glClear", &mask) ) {
return NULL;
}
glClear(mask);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glClearColor (PyObject *self, PyObject *args) {
GLclampf red;
GLclampf green;
GLclampf blue;
GLclampf alpha;
if ( !PyArg_ParseTuple(args, "ffff:glClearColor", &red, &green, &blue, &alpha ) ) {
return NULL;
}
glClearColor(red, green, blue, alpha);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glClearColorx(PyObject *self, PyObject *args) {
GLclampx red;
GLclampx green;
GLclampx blue;
GLclampx alpha;
if ( !PyArg_ParseTuple(args, "iiii:glClearColorx", &red, &green, &blue, &alpha ) ) {
return NULL;
}
glClearColorx(red, green, blue, alpha);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glClearDepthf(PyObject *self, PyObject *args) {
GLclampf depth;
if ( !PyArg_ParseTuple(args, "f:glClearDepthf", &depth) ) {
return NULL;
}
glClearDepthf(depth);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glClearDepthx(PyObject *self, PyObject *args) {
GLclampx depth;
if ( !PyArg_ParseTuple(args, "i:glClearDepthx", &depth) ) {
return NULL;
}
glClearDepthx(depth);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glClearStencil(PyObject *self, PyObject *args) {
GLint s;
if ( !PyArg_ParseTuple(args, "i:glClearStencil", &s) ) {
return NULL;
}
glClearStencil(s);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glClientActiveTexture(PyObject *self, PyObject *args) {
GLenum texture;
if ( !PyArg_ParseTuple(args, "i:glClientActiveTexture", &texture) ) {
return NULL;
}
glClientActiveTexture(texture);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glColor4f(PyObject *self, PyObject *args) {
GLfloat red;
GLfloat green;
GLfloat blue;
GLfloat alpha;
if ( !PyArg_ParseTuple(args, "ffff:glColor4f", &red, &green, &blue, &alpha) ) {
return NULL;
}
glColor4f(red, green, blue, alpha);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glColor4x(PyObject *self, PyObject *args) {
GLfixed red;
GLfixed green;
GLfixed blue;
GLfixed alpha;
if ( !PyArg_ParseTuple(args, "iiii:glColor4x", &red, &green, &blue, &alpha) ) {
return NULL;
}
glColor4x(red, green, blue, alpha);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glColorMask(PyObject *self, PyObject *args) {
GLboolean red;
GLboolean green;
GLboolean blue;
GLboolean alpha;
if ( !PyArg_ParseTuple(args, "iiii:glColorMask", &red, &green, &blue, &alpha) ) {
return NULL;
}
glColorMask(red, green, blue, alpha);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_wrap_glColorPointer(GLint size, GLenum type, GLsizei stride, PyObject *pointerPy) {
void *cptr = NULL;
array_object *arrobj=NULL;
// We can use either the array type or a sequence
// Check the array type first
if(PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) {
arrobj = (array_object*)pointerPy;
cptr = arrobj->arrdata;
}
#ifdef GL_OES_VERSION_1_1
else if(pointerPy == Py_None) {
cptr = NULL;
}
#endif
// Try to convert it as a sequence
else {
pointerPy = gles_PySequence_Collapse(type, pointerPy, NULL);
if(pointerPy == NULL) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
// glColorPointer accepts only GL_UNSIGNED_BYTE, GL_FLOAT or GL_FIXED types
switch(type) {
case GL_UNSIGNED_BYTE:
cptr = gles_PySequence_AsGLubyteArray(pointerPy);
break;
case GL_FLOAT:
cptr = gles_PySequence_AsGLfloatArray(pointerPy);
break;
case GL_FIXED:
cptr = gles_PySequence_AsGLfixedArray(pointerPy);
break;
default:
PyErr_SetString(PyExc_ValueError, "Unsupported array type");
return NULL;
}
if(cptr == NULL) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
}
#ifndef GL_OES_VERSION_1_1
if(cptr == NULL) {
// Something went horribly wrong
// However, we should have an exception already
assert(PyErr_Occurred() != NULL);
return NULL;
}
#endif
gles_assign_array(GL_COLOR_ARRAY, cptr, arrobj);
glColorPointer(size, type, stride, cptr);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glColorPointer(PyObject *self, PyObject *args) {
GLint size;
GLenum type;
GLsizei stride;
PyObject * pointerPy;
if ( !PyArg_ParseTuple(args, "iiiO:glColorPointer", &size, &type, &stride, &pointerPy) ) {
return NULL;
}
return gles_wrap_glColorPointer(size, type, stride, pointerPy);
}
PyObject *gles_glColorPointerub(PyObject *self, PyObject *args) {
GLint size;
PyObject * pointerPy;
if ( !PyArg_ParseTuple(args, "O:glColorPointerub", &pointerPy) ) {
return NULL;
}
if(pointerPy == Py_None) {
gles_free_array(GL_COLOR_ARRAY);
RETURN_PYNONE;
}
if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) {
size = ((array_object*)pointerPy)->dimension;
} else {
size = gles_PySequence_Dimension(pointerPy);
}
return gles_wrap_glColorPointer(size, /*type*/ GL_UNSIGNED_BYTE, /*stride*/ 0, pointerPy);
}
PyObject *gles_glColorPointerf(PyObject *self, PyObject *args) {
GLint size;
PyObject * pointerPy;
if ( !PyArg_ParseTuple(args, "O:glColorPointerf", &pointerPy) ) {
return NULL;
}
if(pointerPy == Py_None) {
gles_free_array(GL_COLOR_ARRAY);
RETURN_PYNONE;
}
if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) {
size = ((array_object*)pointerPy)->dimension;
} else {
size = gles_PySequence_Dimension(pointerPy);
}
return gles_wrap_glColorPointer(size, /*type*/ GL_FLOAT, /*stride*/ 0, pointerPy);
}
PyObject *gles_glColorPointerx(PyObject *self, PyObject *args) {
GLint size;
PyObject * pointerPy;
if ( !PyArg_ParseTuple(args, "O:glColorPointerx", &pointerPy) ) {
return NULL;
}
if(pointerPy == Py_None) {
gles_free_array(GL_COLOR_ARRAY);
RETURN_PYNONE;
}
if( PyObject_TypeCheck(pointerPy, GLES_ARRAY_TYPE) ) {
size = ((array_object*)pointerPy)->dimension;
} else {
size = gles_PySequence_Dimension(pointerPy);
}
return gles_wrap_glColorPointer(size, /*type*/ GL_FIXED, /*stride*/ 0, pointerPy);
}
PyObject *gles_glCompressedTexImage2D(PyObject *self, PyObject *args) {
GLenum target;
GLint level;
GLenum internalformat;
GLsizei width;
GLsizei height;
GLint border;
GLsizei imageSize;
GLvoid *data;
PyObject *pixelsPy;
if( !PyArg_ParseTuple(args, "iiiiiiiO:glCompressedTexImage2D", &target, &level, &internalformat, &width, &height, &border, &imageSize, &pixelsPy) ) {
return NULL;
}
// Only accepting array or string objects
if( PyObject_TypeCheck(pixelsPy, GLES_ARRAY_TYPE) ) {
array_object *arr = (array_object*)pixelsPy;
data = arr->arrdata;
} else if( PyString_Check(pixelsPy) ) {
// "Convert" the string object into an array.
// The returned pointer points to the raw C string
// data held by the object, so no actual conversion needed.
data = PyString_AsString(pixelsPy);
if(data == NULL) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
} else {
PyErr_SetString(PyExc_TypeError,"Only strings and gles.array objects supported");
return NULL;
}
glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
RETURN_PYNONE;
}
PyObject *gles_glCompressedTexSubImage2D(PyObject *self, PyObject *args) {
GLenum target;
GLint level;
GLint xoffset;
GLint yoffset;
GLsizei width;
GLsizei height;
GLenum format;
GLsizei imageSize;
GLvoid *data;
PyObject *pixelsPy;
if( !PyArg_ParseTuple(args, "iiiiiiiiO:glCompressedTexSubImage2D", &target, &level, &xoffset, &yoffset, &width, &height, &format, &imageSize, &pixelsPy) ) {
return NULL;
}
if( PyObject_TypeCheck(pixelsPy, GLES_ARRAY_TYPE) ) {
array_object *arr = (array_object*)pixelsPy;
data = arr->arrdata;
} else if( PyString_Check(pixelsPy) ) {
// "Convert" the string object into an array.
// The returned pointer points to the raw C string
// data held by the object, so no actual conversion needed.
data = PyString_AsString(pixelsPy);
if(data == NULL) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
} // The last resort is to check if the given object is an Image object
else {
PyErr_SetString(PyExc_TypeError,"Only strings and gles.array objects supported");
return NULL;
}
glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
RETURN_PYNONE;
}
PyObject *gles_glCopyTexImage2D(PyObject *self, PyObject *args) {
GLenum target;
GLint level;
GLenum internalformat;
GLint x;
GLint y;
GLsizei width;
GLsizei height;
GLint border;
if ( !PyArg_ParseTuple(args, "iiiiiiii:glCopyTexImage2D", &target, &level, &internalformat, &x, &y, &width, &height, &border) ) {
return NULL;
}
glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glCopyTexSubImage2D(PyObject *self, PyObject *args) {
GLenum target;
GLint level;
GLint xoffset;
GLint yoffset;
GLint x;
GLint y;
GLsizei width;
GLsizei height;
if ( !PyArg_ParseTuple(args, "iiiiiiii:glCopyTexSubImage2D", &target, &level, &xoffset, &yoffset, &x, &y, &width, &height) ) {
return NULL;
}
glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glCullFace(PyObject *self, PyObject *args) {
GLenum mode;
if ( !PyArg_ParseTuple(args, "i:glCullFace", &mode) ) {
return NULL;
}
glCullFace(mode);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDeleteTextures(PyObject *self, PyObject *args) {
GLsizei n;
GLuint *textures = NULL;
PyObject *texturesPy = NULL;
if( !PyArg_ParseTuple(args, "O:glDeleteTextures", &texturesPy) ) {
return NULL;
}
if(! PySequence_Check(texturesPy) ) {
PyErr_SetString(PyExc_TypeError, "Expecting a sequence");
return NULL;
}
textures = gles_PySequence_AsGLuintArray(texturesPy);
if( textures == NULL ) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
n = PySequence_Length(texturesPy);
glDeleteTextures(n, textures);
gles_free(textures);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDepthFunc(PyObject *self, PyObject *args) {
GLenum func;
if ( !PyArg_ParseTuple(args, "i:glDepthFunc", &func) ) {
return NULL;
}
glDepthFunc(func);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDepthMask(PyObject *self, PyObject *args) {
GLboolean flag;
if ( !PyArg_ParseTuple(args, "i:glDepthMask", &flag) ) {
return NULL;
}
glDepthMask(flag);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDepthRangef(PyObject *self, PyObject *args) {
GLclampf zNear;
GLclampf zFar;
if ( !PyArg_ParseTuple(args, "ff:glDepthRangef", &zNear, &zFar) ) {
return NULL;
}
glDepthRangef(zNear, zFar);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDepthRangex(PyObject *self, PyObject *args) {
GLclampx zNear;
GLclampx zFar;
if ( !PyArg_ParseTuple(args, "ii:glDepthRangex", &zNear, &zFar) ) {
return NULL;
}
glDepthRangex(zNear, zFar);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDisable(PyObject *self, PyObject *args) {
GLenum cap;
if ( !PyArg_ParseTuple(args, "i:glDisable", &cap) ) {
return NULL;
}
glDisable(cap);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDisableClientState(PyObject *self, PyObject *args) {
GLenum array;
if ( !PyArg_ParseTuple(args, "i:glDisableClientState", &array) ) {
return NULL;
}
glDisableClientState(array);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDrawArrays(PyObject *self, PyObject *args) {
GLenum mode;
GLint first;
GLsizei count;
if ( !PyArg_ParseTuple(args, "iii:glDrawArrays", &mode, &first, &count) ) {
return NULL;
}
glDrawArrays(mode, first, count);
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDrawElements(PyObject *self, PyObject *args) {
GLenum mode;
GLsizei count = 0;
GLenum type;
void *eptr = NULL;
array_object *arrobj = NULL;
PyObject *indicesPy;
if ( !PyArg_ParseTuple(args, "iiiO:glDrawElements", &mode, &count, &type, &indicesPy) ) {
return NULL;
}
// We can use either the array type or a sequence.
// Check for gles.array type first.
if(PyObject_TypeCheck(indicesPy, GLES_ARRAY_TYPE) ) {
arrobj=(array_object*)indicesPy;
eptr = (GLubyte*)arrobj->arrdata;
} // We can also use None as an argument.
else if(indicesPy == Py_None) {
eptr = NULL;
} // Try to feed the object as a sequence.
else {
indicesPy = gles_PySequence_Collapse(type, indicesPy, NULL);
if(indicesPy == NULL) {
// We should have an exception from PySequence_Collapse if something went wrong
assert(PyErr_Occurred() != NULL);
return NULL;
}
// glDrawElements accepts only GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT types
switch(type) {
case GL_UNSIGNED_BYTE:
eptr = gles_PySequence_AsGLubyteArray(indicesPy);
break;
case GL_UNSIGNED_SHORT:
eptr = gles_PySequence_AsGLushortArray(indicesPy);
break;
default:
PyErr_SetString(PyExc_ValueError, "Invalid array type");
return NULL;
}
if(eptr == NULL) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
}
glDrawElements(mode, count, type, eptr);
if(arrobj == NULL && eptr != NULL) {
gles_free(eptr);
}
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDrawElementsub(PyObject *self, PyObject *args) {
GLenum mode;
GLsizei count = 0;
GLenum type = GL_UNSIGNED_BYTE;
GLubyte *eptr;
array_object *arrobj = NULL;
PyObject *indicesPy;
if ( !PyArg_ParseTuple(args, "iO:glDrawElementsub", &mode, &indicesPy) ) {
return NULL;
}
// We can use either the array type or a sequence.
// Check for gles.array type first.
if(PyObject_TypeCheck(indicesPy, GLES_ARRAY_TYPE) ) {
arrobj=(array_object*)indicesPy;
if(arrobj->arrtype != type) {
PyErr_SetString(PyExc_TypeError, "Invalid type; expected GL_UNSIGNED_BYTE");
return NULL;
}
eptr = (GLubyte*)arrobj->arrdata;
count = arrobj->len;
} // We can also use None as an argument.
else if(indicesPy == Py_None) {
eptr = NULL;
} // Try to feed the object as a sequence.
else {
indicesPy = gles_PySequence_Collapse(type, indicesPy, NULL);
if(indicesPy == NULL) {
// We should have an exception from PySequence_Collapse if something went wrong
assert(PyErr_Occurred() != NULL);
return NULL;
}
eptr = gles_PySequence_AsGLubyteArray(indicesPy);
if(eptr == NULL) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
count = PySequence_Length(indicesPy);
}
glDrawElements(mode, count, type, eptr);
if(arrobj == NULL && eptr != NULL) {
gles_free(eptr);
}
RETURN_IF_GLERROR;
RETURN_PYNONE;
}
PyObject *gles_glDrawElementsus (PyObject *self, PyObject *args) {
GLenum mode;
GLsizei count = 0;
GLenum type = GL_UNSIGNED_SHORT;
GLushort *eptr;
array_object *arrobj = NULL;
PyObject *indicesPy;
if ( !PyArg_ParseTuple(args, "iO:glDrawElementsus", &mode, &indicesPy) ) {
return NULL;
}
// We can use either the array type or a sequence.
// Check for gles.array type first.
if(PyObject_TypeCheck(indicesPy, GLES_ARRAY_TYPE) ) {
arrobj = (array_object*)indicesPy;
if(arrobj->arrtype != type) {
PyErr_SetString(PyExc_TypeError, "Invalid type; expected GL_UNSIGNED_SHORT");
return NULL;
}
eptr = (GLushort*)arrobj->arrdata;
count = arrobj->len;
} // We can also use None as an argument.
else if(indicesPy == Py_None) {
eptr = NULL;
} // Try to feed the object as a sequence.
else {
indicesPy = gles_PySequence_Collapse(type, indicesPy, NULL);
if(indicesPy == NULL) {
// We should have an exception from PySequence_Collapse if something went wrong
assert(PyErr_Occurred() != NULL);
return NULL;
}
eptr = gles_PySequence_AsGLushortArray(indicesPy);
if(eptr == NULL) {
assert(PyErr_Occurred() != NULL);
return NULL;
}
count = PySequence_Length(indicesPy);
}
glDrawElements(mode, count, type, eptr);
if(arrobj == NULL && eptr != NULL) {