-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtex.cpp
689 lines (687 loc) · 40.9 KB
/
tex.cpp
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
# include "tex.h"
constexpr GLenum GL_TEXTURE_BINDING(GLenum target)
{
switch(target)
{
case GL_TEXTURE_1D: return GL_TEXTURE_BINDING_1D ;
case GL_TEXTURE_2D: return GL_TEXTURE_BINDING_2D ;
case GL_TEXTURE_3D: return GL_TEXTURE_BINDING_3D ;
case GL_TEXTURE_1D_ARRAY: return GL_TEXTURE_BINDING_1D_ARRAY ;
case GL_TEXTURE_2D_ARRAY: return GL_TEXTURE_BINDING_2D_ARRAY ;
case GL_TEXTURE_CUBE_MAP: return GL_TEXTURE_BINDING_CUBE_MAP ;
case GL_TEXTURE_CUBE_MAP_ARRAY: return GL_TEXTURE_BINDING_CUBE_MAP_ARRAY ;
case GL_TEXTURE_RECTANGLE: return GL_TEXTURE_BINDING_RECTANGLE ;
case GL_TEXTURE_2D_MULTISAMPLE: return GL_TEXTURE_BINDING_2D_MULTISAMPLE ;
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: return GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY ;
case GL_TEXTURE_BUFFER: return GL_TEXTURE_BINDING_BUFFER ;
default: return 0 ; // error
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constexpr GLenum GLformat(GLenum internalformat)
{
switch(internalformat)
{
case GL_R8: // *_SNORM
case GL_R16:
case GL_R16F:
return GL_RED ;
case GL_R8I:
case GL_R8UI:
case GL_R16I:
case GL_R16UI:
return GL_RED_INTEGER ;
case GL_RG8:
case GL_RG16:
case GL_RG16F:
return GL_RG ;
case GL_RG8I:
case GL_RG8UI:
case GL_RG16I:
case GL_RG16UI:
return GL_RG_INTEGER ;
case GL_RGB8:
case GL_RGB16:
case GL_RGB16F:
return GL_RGB ;
case GL_RGB8I:
case GL_RGB8UI:
case GL_RGB16I:
case GL_RGB16UI:
return GL_RGB_INTEGER ;
case GL_RGBA8:
case GL_RGBA16:
case GL_RGBA16F:
return GL_RGBA ;
case GL_RGBA8I:
case GL_RGBA8UI:
case GL_RGBA16I:
case GL_RGBA16UI:
return GL_RGBA_INTEGER ;
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT24:
case GL_DEPTH_COMPONENT32:
return GL_DEPTH_COMPONENT ;
default:
return internalformat;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEX1D::~TEX1D(void)
{
if(texture) GL_ASSERT(glDeleteTextures(1, &texture)), texture = 0;
}
TEX1D::TEX1D(TEX1D &&TEX) noexcept
{
memcpy(this, &TEX, sizeof(TEX1D));
memset(&TEX, 0, sizeof(TEX1D));
}
void TEX1D::operator = (TEX1D &&TEX) noexcept
{
TEX1D::~TEX1D( );
memcpy(this, &TEX, sizeof(TEX1D));
memset(&TEX, 0, sizeof(TEX1D));
}
TEX1D::TEX1D(GLenum format, GLsizei X, const GLbyte *image): TEX1D(GL_TEXTURE_1D, format, X, GLformat(format), GL_BYTE, image) { }
TEX1D::TEX1D(GLenum format, GLsizei X, const GLubyte *image): TEX1D(GL_TEXTURE_1D, format, X, GLformat(format), GL_UNSIGNED_BYTE, image) { }
TEX1D::TEX1D(GLenum format, GLsizei X, const GLshort *image): TEX1D(GL_TEXTURE_1D, format, X, GLformat(format), GL_SHORT, image) { }
TEX1D::TEX1D(GLenum format, GLsizei X, const GLushort *image): TEX1D(GL_TEXTURE_1D, format, X, GLformat(format), GL_UNSIGNED_SHORT, image) { }
TEX1D::TEX1D(GLenum format, GLsizei X, const GLint *image): TEX1D(GL_TEXTURE_1D, format, X, GLformat(format), GL_INT, image) { }
TEX1D::TEX1D(GLenum format, GLsizei X, const GLuint *image): TEX1D(GL_TEXTURE_1D, format, X, GLformat(format), GL_UNSIGNED_INT, image) { }
TEX1D::TEX1D(GLenum format, GLsizei X, const GLfloat *image): TEX1D(GL_TEXTURE_1D, format, X, GLformat(format), GL_FLOAT, image) { }
// ARB_texture_storage 4.2
TEX1D::TEX1D(GLsizei levels, GLenum format, GLsizei X): TEX1D(GL_TEXTURE_1D, levels, format, X) { }
// glTexParameter
void TEX1D::param(GLenum pname, GLint param)
{
if(ASSERT(texture))
GL_ASSERT(glTexParameteri(target, pname, param));
}
// glGenerateMipmap
void TEX1D::mipmap(void)
{
if(ASSERT(texture))
if(ASSERT(target != GL_TEXTURE_BUFFER))
GL_ASSERT(glBindTexture(target, texture)),
GL_ASSERT(glGenerateMipmap(target));
}
// glBindTexture
void TEX1D::bind(GLenum unit)
{
if(!ASSERT(texture)) return;
if(gl_Version < 045)
GL_ASSERT(glActiveTexture(unit)),
GL_ASSERT(glBindTexture(target, texture));
else // ARB_direct_state_access 4.5
GL_ASSERT(glBindTextureUnit(unit, texture));
}
// glTexImage1D
void TEX1D::image(GLint level, GLsizei width, const GLbyte *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage1D(target, level, internalformat, width, 0, GLformat(internalformat), GL_BYTE, image));
}
void TEX1D::image(GLint level, GLsizei width, const GLubyte *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage1D(target, level, internalformat, width, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, image));
}
void TEX1D::image(GLint level, GLsizei width, const GLshort *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage1D(target, level, internalformat, width, 0, GLformat(internalformat), GL_SHORT, image));
}
void TEX1D::image(GLint level, GLsizei width, const GLushort *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage1D(target, level, internalformat, width, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, image));
}
void TEX1D::image(GLint level, GLsizei width, const GLint *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage1D(target, level, internalformat, width, 0, GLformat(internalformat), GL_INT, image));
}
void TEX1D::image(GLint level, GLsizei width, const GLuint *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage1D(target, level, internalformat, width, 0, GLformat(internalformat), GL_UNSIGNED_INT, image));
}
void TEX1D::image(GLint level, GLsizei width, const GLfloat *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage1D(target, level, internalformat, width, 0, GLformat(internalformat), GL_FLOAT, image));
}
// glTexSubImage1D
void TEX1D::sub_image(GLint level, GLint x, GLsizei width, const GLbyte *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage1D(target, level, x, width, GLformat(internalformat), GL_BYTE, image));
}
void TEX1D::sub_image(GLint level, GLint x, GLsizei width, const GLubyte *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage1D(target, level, x, width, GLformat(internalformat), GL_UNSIGNED_BYTE, image));
}
void TEX1D::sub_image(GLint level, GLint x, GLsizei width, const GLshort *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage1D(target, level, x, width, GLformat(internalformat), GL_SHORT, image));
}
void TEX1D::sub_image(GLint level, GLint x, GLsizei width, const GLushort *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage1D(target, level, x, width, GLformat(internalformat), GL_UNSIGNED_SHORT, image));
}
void TEX1D::sub_image(GLint level, GLint x, GLsizei width, const GLint *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage1D(target, level, x, width, GLformat(internalformat), GL_INT, image));
}
void TEX1D::sub_image(GLint level, GLint x, GLsizei width, const GLuint *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage1D(target, level, x, width, GLformat(internalformat), GL_UNSIGNED_INT, image));
}
void TEX1D::sub_image(GLint level, GLint x, GLsizei width, const GLfloat *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage1D(target, level, x, width, GLformat(internalformat), GL_FLOAT, image));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// private
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEX1D::TEX1D(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image): target(target), internalformat(internalformat)
{
if(GL_ASSERT(glGenTextures(1, &texture)))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage1D(target, 0, internalformat, width, 0, format, type, image));
}
// ARB_texture_buffer_object 3.1
TEX1D::TEX1D(GLenum internalformat, const BO<GL_TEXTURE_BUFFER> &buffer): target(GL_TEXTURE_BUFFER), internalformat(internalformat)
{
if(GL_ASSERT(glGenTextures(1, &texture)))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexBuffer(target, internalformat, buffer));
}
// ARB_texture_buffer_range 4.3
TEX1D::TEX1D(GLenum internalformat, const BO<GL_TEXTURE_BUFFER> &buffer, GLintptr offset, GLsizeiptr size): target(GL_TEXTURE_BUFFER), internalformat(internalformat)
{
if(GL_ASSERT(glGenTextures(1, &texture)))
if(GL_ASSERT(glBindTexture(target, texture)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)))
GL_ASSERT(glTexBufferRange(target, internalformat, buffer, offset, size));
}
// ARB_texture_storage 4.2
TEX1D::TEX1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width): target(target), internalformat(internalformat)
{
if(GL_ASSERT(glGenTextures(1, &texture)))
if(GL_ASSERT(glBindTexture(target, texture)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)))
GL_ASSERT(glTexStorage1D(target, levels, internalformat, width));
}
TEX1D::operator GLuint(void) const
{
return texture;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEX2D::~TEX2D(void)
{
if(texture) GL_ASSERT(glDeleteTextures(1, &texture)), texture = 0;
}
TEX2D::TEX2D(TEX2D &&TEX) noexcept
{
memcpy(this, &TEX, sizeof(TEX2D));
memset(&TEX, 0, sizeof(TEX2D));
}
void TEX2D::operator = (TEX2D &&TEX) noexcept
{
TEX2D::~TEX2D( );
memcpy(this, &TEX, sizeof(TEX2D));
memset(&TEX, 0, sizeof(TEX2D));
}
TEX2D::TEX2D(GLenum internalformat, GLsizei X, GLsizei Y, const GLbyte *image): TEX2D(GL_TEXTURE_2D, internalformat, X, Y, GL_BYTE, image) { }
TEX2D::TEX2D(GLenum internalformat, GLsizei X, GLsizei Y, const GLubyte *image): TEX2D(GL_TEXTURE_2D, internalformat, X, Y, GL_UNSIGNED_BYTE, image) { }
TEX2D::TEX2D(GLenum internalformat, GLsizei X, GLsizei Y, const GLshort *image): TEX2D(GL_TEXTURE_2D, internalformat, X, Y, GL_SHORT, image) { }
TEX2D::TEX2D(GLenum internalformat, GLsizei X, GLsizei Y, const GLushort *image): TEX2D(GL_TEXTURE_2D, internalformat, X, Y, GL_UNSIGNED_SHORT, image) { }
TEX2D::TEX2D(GLenum internalformat, GLsizei X, GLsizei Y, const GLint *image): TEX2D(GL_TEXTURE_2D, internalformat, X, Y, GL_INT, image) { }
TEX2D::TEX2D(GLenum internalformat, GLsizei X, GLsizei Y, const GLuint *image): TEX2D(GL_TEXTURE_2D, internalformat, X, Y, GL_UNSIGNED_INT, image) { }
TEX2D::TEX2D(GLenum internalformat, GLsizei X, GLsizei Y, const GLfloat *image): TEX2D(GL_TEXTURE_2D, internalformat, X, Y, GL_FLOAT, image) { }
// ARB_texture_storage 4.2
TEX2D::TEX2D(GLsizei levels, GLenum format, GLsizei X, GLsizei Y): TEX2D(GL_TEXTURE_2D, levels, internalformat, X, Y) { }
// glTexParameter
void TEX2D::param(GLenum pname, GLint param)
{
if(ASSERT(texture))
GL_ASSERT(glTexParameteri(target, pname, param));
}
// glGenerateMipmap
void TEX2D::mipmap(void)
{
if(ASSERT(texture))
if(ASSERT(target != GL_TEXTURE_RECTANGLE))
if(ASSERT(target != GL_TEXTURE_2D_MULTISAMPLE))
GL_ASSERT(glBindTexture(target, texture)),
GL_ASSERT(glGenerateMipmap(target));
}
// glBindTexture
void TEX2D::bind(GLenum unit)
{
if(!ASSERT(texture)) return;
if(gl_Version < 045)
GL_ASSERT(glActiveTexture(unit)),
GL_ASSERT(glBindTexture(target, texture));
else // ARB_direct_state_access 4.5
GL_ASSERT(glBindTextureUnit(unit, texture));
}
// glTexImage2D
void TEX2D::image(GLint level, GLsizei width, GLsizei height, const GLbyte *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage2D(target, level, internalformat, width, height, 0, GLformat(internalformat), GL_BYTE, image));
}
void TEX2D::image(GLint level, GLsizei width, GLsizei height, const GLubyte *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage2D(target, level, internalformat, width, height, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, image));
}
void TEX2D::image(GLint level, GLsizei width, GLsizei height, const GLshort *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage2D(target, level, internalformat, width, height, 0, GLformat(internalformat), GL_SHORT, image));
}
void TEX2D::image(GLint level, GLsizei width, GLsizei height, const GLushort *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage2D(target, level, internalformat, width, height, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, image));
}
void TEX2D::image(GLint level, GLsizei width, GLsizei height, const GLint *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage2D(target, level, internalformat, width, height, 0, GLformat(internalformat), GL_INT, image));
}
void TEX2D::image(GLint level, GLsizei width, GLsizei height, const GLuint *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage2D(target, level, internalformat, width, height, 0, GLformat(internalformat), GL_UNSIGNED_INT, image));
}
void TEX2D::image(GLint level, GLsizei width, GLsizei height, const GLfloat *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexImage2D(target, level, internalformat, width, height, 0, GLformat(internalformat), GL_FLOAT, image));
}
// glTexSubImage2D
void TEX2D::sub_image(GLint level, GLint x, GLint y, GLsizei width, GLsizei height, const GLbyte *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage2D(target, level, x, y, width, height, GLformat(internalformat), GL_BYTE, image));
}
void TEX2D::sub_image(GLint level, GLint x, GLint y, GLsizei width, GLsizei height, const GLubyte *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage2D(target, level, x, y, width, height, GLformat(internalformat), GL_UNSIGNED_BYTE, image));
}
void TEX2D::sub_image(GLint level, GLint x, GLint y, GLsizei width, GLsizei height, const GLshort *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage2D(target, level, x, y, width, height, GLformat(internalformat), GL_SHORT, image));
}
void TEX2D::sub_image(GLint level, GLint x, GLint y, GLsizei width, GLsizei height, const GLushort *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage2D(target, level, x, y, width, height, GLformat(internalformat), GL_UNSIGNED_SHORT, image));
}
void TEX2D::sub_image(GLint level, GLint x, GLint y, GLsizei width, GLsizei height, const GLfloat *image)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
GL_ASSERT(glTexSubImage2D(target, level, x, y, width, height, GLformat(internalformat), GL_FLOAT, image));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// private
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ARB_texture_storage 4.2
TEX2D::TEX2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height): target(target), internalformat(internalformat)
{
if(GL_ASSERT(glGenTextures(1, &texture)))
if(GL_ASSERT(glBindTexture(target, texture)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)))
GL_ASSERT(glTexStorage2D(target, levels, internalformat, width, height));
}
TEX2D::TEX2D(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum type, const void *pixels): target(target), internalformat(internalformat)
{
if(GL_ASSERT(glGenTextures(1, &texture)))
if(GL_ASSERT(glBindTexture(target, texture)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)))
GL_ASSERT(glTexImage2D(target, 0, internalformat, width, height, 0, GLformat(internalformat), type, pixels));
}
TEX2D::operator GLuint(void) const
{
return texture;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEX3D::~TEX3D(void)
{
if(texture) GL_ASSERT(glDeleteTextures(1, &texture)), texture = 0;
}
TEX3D::TEX3D(TEX3D &&TEX) noexcept
{
memcpy(this, &TEX, sizeof(TEX3D));
memset(&TEX, 0, sizeof(TEX3D));
}
void TEX3D::operator = (TEX3D &&TEX) noexcept
{
TEX3D::~TEX3D( );
memcpy(this, &TEX, sizeof(TEX3D));
memset(&TEX, 0, sizeof(TEX3D));
}
TEX3D::TEX3D(GLenum format, GLsizei X, GLsizei Y, GLsizei Z, const GLbyte *image): TEX3D(GL_TEXTURE_3D, format, X, Y, Z, GL_BYTE, image) { }
TEX3D::TEX3D(GLenum format, GLsizei X, GLsizei Y, GLsizei Z, const GLubyte *image): TEX3D(GL_TEXTURE_3D, format, X, Y, Z, GL_UNSIGNED_BYTE, image) { }
TEX3D::TEX3D(GLenum format, GLsizei X, GLsizei Y, GLsizei Z, const GLshort *image): TEX3D(GL_TEXTURE_3D, format, X, Y, Z, GL_SHORT, image) { }
TEX3D::TEX3D(GLenum format, GLsizei X, GLsizei Y, GLsizei Z, const GLushort *image): TEX3D(GL_TEXTURE_3D, format, X, Y, Z, GL_UNSIGNED_SHORT, image) { }
TEX3D::TEX3D(GLenum format, GLsizei X, GLsizei Y, GLsizei Z, const GLint *image): TEX3D(GL_TEXTURE_3D, format, X, Y, Z, GL_INT, image) { }
TEX3D::TEX3D(GLenum format, GLsizei X, GLsizei Y, GLsizei Z, const GLuint *image): TEX3D(GL_TEXTURE_3D, format, X, Y, Z, GL_UNSIGNED_INT, image) { }
TEX3D::TEX3D(GLenum format, GLsizei X, GLsizei Y, GLsizei Z, const GLfloat *image): TEX3D(GL_TEXTURE_3D, format, X, Y, Z, GL_FLOAT, image) { }
// ARB_texture_storage 4.2
TEX3D::TEX3D(GLsizei levels, GLenum format, GLsizei X, GLsizei Y, GLsizei Z): TEX3D(GL_TEXTURE_3D, levels, format, X, Y, Z) { }
// glTexParameter
void TEX3D::param(GLenum pname, GLint param)
{
if(ASSERT(texture))
GL_ASSERT(glTexParameteri(target, pname, param));
}
// glGenerateMipmap
void TEX3D::mipmap(void)
{
if(ASSERT(texture))
if(ASSERT(target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY))
GL_ASSERT(glBindTexture(target, texture)),
GL_ASSERT(glGenerateMipmap(target));
}
// glBindTexture
void TEX3D::bind(GLenum unit)
{
if(!ASSERT(texture)) return;
if(gl_Version < 045)
GL_ASSERT(glActiveTexture(unit)),
GL_ASSERT(glBindTexture(target, texture));
else // ARB_direct_state_access 4.5
GL_ASSERT(glBindTextureUnit(unit, texture));
}
// glTexImage3D
void TEX3D::image(GLint level, GLsizei X, GLsizei Y, GLsizei Z, const GLbyte *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6))
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_BYTE, pixels + X * Y * 0)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_BYTE, pixels + X * Y * 1)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_BYTE, pixels + X * Y * 2)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_BYTE, pixels + X * Y * 3)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_BYTE, pixels + X * Y * 4)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_BYTE, pixels + X * Y * 5));
else
GL_ASSERT(glTexImage3D(target, level, internalformat, X, Y, Z, 0, GLformat(internalformat), GL_BYTE, pixels));
}
void TEX3D::image(GLint level, GLsizei X, GLsizei Y, GLsizei Z, const GLubyte *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6))
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 0)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 1)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 2)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 3)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 4)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 5));
else
GL_ASSERT(glTexImage3D(target, level, internalformat, X, Y, Z, 0, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels));
}
void TEX3D::image(GLint level, GLsizei X, GLsizei Y, GLsizei Z, const GLshort *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6))
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_SHORT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_SHORT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_SHORT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_SHORT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_SHORT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_SHORT, pixels + X * Y * 5));
else
GL_ASSERT(glTexImage3D(target, level, internalformat, X, Y, Z, 0, GLformat(internalformat), GL_SHORT, pixels));
}
void TEX3D::image(GLint level, GLsizei X, GLsizei Y, GLsizei Z, const GLushort *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6))
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 5));
else
GL_ASSERT(glTexImage3D(target, level, internalformat, X, Y, Z, 0, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels));
}
void TEX3D::image(GLint level, GLsizei X, GLsizei Y, GLsizei Z, const GLint *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6))
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_INT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_INT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_INT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_INT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_INT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_INT, pixels + X * Y * 5));
else
GL_ASSERT(glTexImage3D(target, level, internalformat, X, Y, Z, 0, GLformat(internalformat), GL_INT, pixels));
}
void TEX3D::image(GLint level, GLsizei X, GLsizei Y, GLsizei Z, const GLuint *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6))
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 5));
else
GL_ASSERT(glTexImage3D(target, level, internalformat, X, Y, Z, 0, GLformat(internalformat), GL_UNSIGNED_INT, pixels));
}
void TEX3D::image(GLint level, GLsizei X, GLsizei Y, GLsizei Z, const GLfloat *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6))
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, internalformat, X, Y, 0, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, internalformat, X, Y, 0, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, internalformat, X, Y, 0, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 5));
else
GL_ASSERT(glTexImage3D(target, level, internalformat, X, Y, Z, 0, GLformat(internalformat), GL_FLOAT, pixels));
}
// glTexSubImage3D
void TEX3D::sub_image(GLint level, GLint x, GLint y, GLint z, GLsizei X, GLsizei Y, GLsizei Z, const GLbyte *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6) && gl_Version < 045)
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_BYTE, pixels + X * Y * 0)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_BYTE, pixels + X * Y * 1)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_BYTE, pixels + X * Y * 2)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_BYTE, pixels + X * Y * 3)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_BYTE, pixels + X * Y * 4)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_BYTE, pixels + X * Y * 5));
else // case GL_TEXTURE_CUBE_MAP: ARB_direct_state_access 4.5
GL_ASSERT(glTexSubImage3D(target, level, x, y, z, X, Y, Z, GLformat(internalformat), GL_BYTE, pixels));
}
void TEX3D::sub_image(GLint level, GLint x, GLint y, GLint z, GLsizei X, GLsizei Y, GLsizei Z, const GLubyte *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6) && gl_Version < 045)
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 0)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 1)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 2)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 3)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 4)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels + X * Y * 5));
else // case GL_TEXTURE_CUBE_MAP: ARB_direct_state_access 4.5
GL_ASSERT(glTexSubImage3D(target, level, x, y, z, X, Y, Z, GLformat(internalformat), GL_UNSIGNED_BYTE, pixels));
}
void TEX3D::sub_image(GLint level, GLint x, GLint y, GLint z, GLsizei X, GLsizei Y, GLsizei Z, const GLshort *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6) && gl_Version < 045)
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_SHORT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_SHORT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_SHORT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_SHORT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_SHORT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_SHORT, pixels + X * Y * 5));
else // case GL_TEXTURE_CUBE_MAP: ARB_direct_state_access 4.5
GL_ASSERT(glTexSubImage3D(target, level, x, y, z, X, Y, Z, GLformat(internalformat), GL_SHORT, pixels));
}
void TEX3D::sub_image(GLint level, GLint x, GLint y, GLint z, GLsizei X, GLsizei Y, GLsizei Z, const GLushort *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6) && gl_Version < 045)
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels + X * Y * 5));
else // case GL_TEXTURE_CUBE_MAP: ARB_direct_state_access 4.5
GL_ASSERT(glTexSubImage3D(target, level, x, y, z, X, Y, Z, GLformat(internalformat), GL_UNSIGNED_SHORT, pixels));
}
void TEX3D::sub_image(GLint level, GLint x, GLint y, GLint z, GLsizei X, GLsizei Y, GLsizei Z, const GLint *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6) && gl_Version < 045)
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_INT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_INT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_INT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_INT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_INT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_INT, pixels + X * Y * 5));
else // case GL_TEXTURE_CUBE_MAP: ARB_direct_state_access 4.5
GL_ASSERT(glTexSubImage3D(target, level, x, y, z, X, Y, Z, GLformat(internalformat), GL_INT, pixels));
}
void TEX3D::sub_image(GLint level, GLint x, GLint y, GLint z, GLsizei X, GLsizei Y, GLsizei Z, const GLuint *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6) && gl_Version < 045)
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_UNSIGNED_INT, pixels + X * Y * 5));
else // case GL_TEXTURE_CUBE_MAP: ARB_direct_state_access 4.5
GL_ASSERT(glTexSubImage3D(target, level, x, y, z, X, Y, Z, GLformat(internalformat), GL_UNSIGNED_INT, pixels));
}
void TEX3D::sub_image(GLint level, GLint x, GLint y, GLint z, GLsizei X, GLsizei Y, GLsizei Z, const GLfloat *pixels)
{
if(ASSERT(texture) && ASSERT(internalformat))
if(GL_ASSERT(glBindTexture(target, texture)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6) && gl_Version < 045)
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 0)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, x, y, X, Y, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 1)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 2)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, x, y, X, Y, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 3)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 4)) &&
GL_ASSERT(glTexSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, x, y, X, Y, GLformat(internalformat), GL_FLOAT, pixels + X * Y * 5));
else // case GL_TEXTURE_CUBE_MAP: ARB_direct_state_access 4.5
GL_ASSERT(glTexSubImage3D(target, level, x, y, z, X, Y, Z, GLformat(internalformat), GL_FLOAT, pixels));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// private
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ARB_texture_storage 4.2
TEX3D::TEX3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth): target(target), internalformat(internalformat)
{
if(GL_ASSERT(glGenTextures(1, &texture)))
if(GL_ASSERT(glBindTexture(target, texture)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)))
GL_ASSERT(glTexStorage3D(target, levels, internalformat, width, height, depth));
}
TEX3D::TEX3D(GLenum target, GLenum internalformat, GLsizei X, GLsizei Y, GLsizei Z, GLenum type, const void *pixels): target(target), internalformat(internalformat)
{
GLenum format = GLformat(internalformat);
constexpr auto GLsize = [ ](GLenum type) -> GLsizeiptr
{
switch(type)
{
case GL_BYTE: return sizeof(GLbyte);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
case GL_SHORT: return sizeof(GLshort);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_INT: return sizeof(GLint);
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_FLOAT: return sizeof(GLfloat);
default: return 0;
}
};
if(GL_ASSERT(glGenTextures(1, &texture)))
if(GL_ASSERT(glBindTexture(target, texture)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)))
if(GL_ASSERT(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)))
if(target == GL_TEXTURE_CUBE_MAP && ASSERT(Z == 6))
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, internalformat, X, Y, 0, format, type, static_cast<const char *>(pixels) + GLsize(type) * X * Y * 0)),
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, internalformat, X, Y, 0, format, type, static_cast<const char *>(pixels) + GLsize(type) * X * Y * 1)),
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, internalformat, X, Y, 0, format, type, static_cast<const char *>(pixels) + GLsize(type) * X * Y * 2)),
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, internalformat, X, Y, 0, format, type, static_cast<const char *>(pixels) + GLsize(type) * X * Y * 3)),
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, internalformat, X, Y, 0, format, type, static_cast<const char *>(pixels) + GLsize(type) * X * Y * 4)),
GL_ASSERT(glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, internalformat, X, Y, 0, format, type, static_cast<const char *>(pixels) + GLsize(type) * X * Y * 5));
else
GL_ASSERT(glTexImage3D(target, 0, internalformat, X, Y, Z, 0, format, type, pixels));
}
TEX3D::operator GLuint(void) const
{
return texture;
}