texture.cpp 18.9 KB
Newer Older
1
/**********************************************************************
schultezub's avatar
schultezub committed
2
 *                                                                    *
3
 * cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2015               *
4
5
6
 *     Chair for Computer Aided Medical Procedures                    *
 *     Technische Universitaet Muenchen, Germany.                     *
 *     <http://campar.in.tum.de/>                                     *
schultezub's avatar
schultezub committed
7
 *                                                                    *
8
9
10
11
 * forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011   *
 *     Visualization and Computer Graphics Group, Department of       *
 *     Computer Science, University of Muenster, Germany.             *
 *     <http://viscg.uni-muenster.de>                                 *
schultezub's avatar
schultezub committed
12
 *                                                                    *
13
 * This file is part of the cgt library. This library is free         *
schultezub's avatar
schultezub committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * software; you can redistribute it and/or modify it under the terms *
 * of the GNU Lesser General Public License version 2.1 as published  *
 * by the Free Software Foundation.                                   *
 *                                                                    *
 * This library is distributed in the hope that it will be useful,    *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
 * GNU Lesser General Public License for more details.                *
 *                                                                    *
 * You should have received a copy of the GNU Lesser General Public   *
 * License in the file "LICENSE.txt" along with this library.         *
 * If not, see <http://www.gnu.org/licenses/>.                        *
 *                                                                    *
 **********************************************************************/

29
30
#include "cgt/texture.h"
#include "cgt/types.h"
schultezub's avatar
schultezub committed
31

32
33
#include "cgt/gpucapabilities.h"
#include "cgt/filesystem.h"
schultezub's avatar
schultezub committed
34

35
namespace cgt {
schultezub's avatar
schultezub committed
36

37
Texture::Texture(GLenum type, const cgt::ivec3& dimensions, GLint internalFormat, Filter filter /*= LINEAR*/) 
schultezub's avatar
schultezub committed
38
    : dimensions_(dimensions)
39
    , internalformat_(internalFormat)
schultezub's avatar
schultezub committed
40
    , filter_(filter)
41
    , wrapping_(CLAMP_TO_EDGE)
42
43
44
    , id_(0)
    , type_(type)
    , bpp_(0)
schultezub's avatar
schultezub committed
45
{
46
47
    init();
    uploadTexture(nullptr, calcMatchingFormat(internalFormat), calcMatchingDataType(internalFormat));
schultezub's avatar
schultezub committed
48
49
}

50
Texture::Texture(GLenum type, const cgt::ivec3& dimensions, GLint internalFormat, GLubyte* data, GLint format, GLenum dataType, Filter filter /*= LINEAR*/) 
schultezub's avatar
schultezub committed
51
    : dimensions_(dimensions)
52
    , internalformat_(internalFormat)
schultezub's avatar
schultezub committed
53
    , filter_(filter)
54
    , wrapping_(CLAMP_TO_EDGE)
55
56
57
    , id_(0)
    , type_(type)
    , bpp_(0)
schultezub's avatar
schultezub committed
58
{
59
60
    init();
    uploadTexture(data, format, dataType);
schultezub's avatar
schultezub committed
61
62
63
}


64
65
Texture::~Texture() {
    if (id_)
66
        glDeleteTextures(1, &id_);
67
68
69
}


70
71
void Texture::init() {
    bpp_ = calcBpp(internalformat_);
schultezub's avatar
schultezub committed
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
    generateId();
    applyFilter();
}

int Texture::calcBpp(GLint format, GLenum dataType) {

    int numChannels = calcNumChannels(format);

    int typeSize = 0;
    switch (dataType) {
        case GL_BYTE:
        case GL_UNSIGNED_BYTE:
            typeSize = 1;
            break;

        case GL_SHORT:
        case GL_UNSIGNED_SHORT:
            typeSize = 2;
            break;

        case GL_INT:
        case GL_UNSIGNED_INT:
        case GL_FLOAT:
            typeSize = 4;
            break;

        default:
99
            LWARNINGC("cgt.Texture", "unknown dataType");
schultezub's avatar
schultezub committed
100
101
102
103
104
105
    }

    return typeSize * numChannels;
}

int Texture::calcBpp(GLint internalformat) {
106
    // supports all formats from https://www.opengl.org/wiki/GLAPI/glTexImage2D
schultezub's avatar
schultezub committed
107
108
109
110
111

    int bpp = 0;
    switch (internalformat) {
        case 1:
        case GL_DEPTH_COMPONENT:
112
113
114
115
116
117
118
        case GL_RED:
        case GL_R8:
        case GL_R8_SNORM:
        case GL_R8I:
        case GL_R8UI:
        case GL_R3_G3_B2:
        case GL_RGBA2:
schultezub's avatar
schultezub committed
119
120
121
122
123
            bpp = 1;
            break;

        case 2:
        case GL_DEPTH_COMPONENT16:
124
        case GL_R16:
125
126
127
128
129
130
131
132
133
134
135
136
137
138
        case GL_R16_SNORM:
        case GL_R16F:
        case GL_R16I:
        case GL_R16UI:
        case GL_DEPTH_STENCIL:
        case GL_RG:
        case GL_RG8:
        case GL_RG8_SNORM:
        case GL_RG8I:
        case GL_RG8UI:
        case GL_RGB4:
        case GL_RGB5:
        case GL_RGBA4:
        case GL_RGB5_A1:
schultezub's avatar
schultezub committed
139
140
141
            bpp = 2;
            break;

142
        case GL_DEPTH_COMPONENT24:
schultezub's avatar
schultezub committed
143
        case GL_RGB:
schultezub's avatar
schultezub committed
144
        case GL_RGB8:
145
146
147
148
        case GL_RGB8_SNORM:
        case GL_SRGB8:
        case GL_RGB8I:
        case GL_RGB8UI:
schultezub's avatar
schultezub committed
149
150
151
            bpp = 3;
            break;

152
153
154
155
156
157
158
159
160
161
162
163
164
        case GL_DEPTH_COMPONENT32:
        case GL_DEPTH_COMPONENT32F:
        case GL_R32F:
        case GL_R32I:
        case GL_R32UI:
        case GL_RG16:
        case GL_RG16_SNORM:
        case GL_RG16F:
        case GL_RG16I:
        case GL_RG16UI:
        case GL_RGB10:
        case GL_R11F_G11F_B10F:
        case GL_RGB9_E5:
schultezub's avatar
schultezub committed
165
166
        case GL_RGBA:
        case GL_RGBA8:
167
168
169
170
171
172
        case GL_RGBA8_SNORM:
        case GL_RGB10_A2:
        case GL_RGB10_A2UI:
        case GL_SRGB8_ALPHA8:
        case GL_RGBA8I:
        case GL_RGBA8UI:
schultezub's avatar
schultezub committed
173
174
175
            bpp = 4;
            break;

176
177
178
179
180
181
182
183
184
        case GL_RGB12:
            bpp = 5;
            break;

        case GL_RGB16_SNORM:
        case GL_RGB16F:
        case GL_RGB16I:
        case GL_RGB16UI:
        case GL_RGBA12:
schultezub's avatar
schultezub committed
185
186
187
            bpp = 6;
            break;

188
189
190
        case GL_RG32F:
        case GL_RG32I:
        case GL_RG32UI:
schultezub's avatar
schultezub committed
191
        case GL_RGBA16:
192
193
194
        case GL_RGBA16F:
        case GL_RGBA16I:
        case GL_RGBA16UI:
schultezub's avatar
schultezub committed
195
196
197
            bpp = 8;
            break;

198
199
200
        case GL_RGB32F:
        case GL_RGB32I:
        case GL_RGB32UI:
schultezub's avatar
schultezub committed
201
202
203
            bpp = 12;
            break;

204
205
206
        case GL_RGBA32F:
        case GL_RGBA32I:
        case GL_RGBA32UI:
schultezub's avatar
schultezub committed
207
208
209
210
            bpp = 16;
            break;

        default:
211
            cgtAssert(false, "Unknown internal format, this should not happen!");
schultezub's avatar
schultezub committed
212
213
214
215
216
217
            break;
    }

    return bpp;
}

218
219
220
int Texture::calcNumChannels(GLint internalFormat) {
    // supports all formats from https://www.opengl.org/wiki/GLAPI/glTexImage2D
    switch (internalFormat) {
221
222
        case 1:
        case GL_DEPTH_COMPONENT:
223
224
225
226
        case GL_DEPTH_COMPONENT16:
        case GL_DEPTH_COMPONENT24:
        case GL_DEPTH_COMPONENT32:
        case GL_DEPTH_COMPONENT32F:
227
228
229
        case GL_RED:
        case GL_R8:
        case GL_R8_SNORM:
230
        case GL_R16:
231
232
233
234
235
236
237
238
239
        case GL_R16_SNORM:
        case GL_R16F:
        case GL_R32F:
        case GL_R8I:
        case GL_R8UI:
        case GL_R16I:
        case GL_R16UI:
        case GL_R32I:
        case GL_R32UI:
240
        case GL_RED_INTEGER:
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
            return 1;
            break;

        case 2:
        case GL_DEPTH_STENCIL:
        case GL_RG:
        case GL_RG8:
        case GL_RG8_SNORM:
        case GL_RG16:
        case GL_RG16_SNORM:
        case GL_RG16F:
        case GL_RG32F:
        case GL_RG8I:
        case GL_RG8UI:
        case GL_RG16I:
        case GL_RG16UI:
        case GL_RG32I:
        case GL_RG32UI:
259
        case GL_RG_INTEGER:
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
            return 2;
            break;

        case 3:
        case GL_RGB:
        case GL_R3_G3_B2:
        case GL_RGB4:
        case GL_RGB5:
        case GL_RGB8:
        case GL_RGB8_SNORM:
        case GL_RGB10:
        case GL_RGB12:
        case GL_RGB16_SNORM:
        case GL_SRGB8:
        case GL_RGB16F:
        case GL_RGB32F:
        case GL_R11F_G11F_B10F:
        case GL_RGB9_E5:
        case GL_RGB8I:
        case GL_RGB8UI:
        case GL_RGB16I:
        case GL_RGB16UI:
        case GL_RGB32I:
        case GL_RGB32UI:
284
        case GL_RGB_INTEGER:
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
            return 3;
            break;

        case 4:
        case GL_RGBA:
        case GL_RGBA2:
        case GL_RGBA4:
        case GL_RGB5_A1:
        case GL_RGBA8:
        case GL_RGBA8_SNORM:
        case GL_RGB10_A2:
        case GL_RGB10_A2UI:
        case GL_RGBA12:
        case GL_RGBA16:
        case GL_SRGB8_ALPHA8:
        case GL_RGBA16F:
        case GL_RGBA32F:
        case GL_RGBA8I:
        case GL_RGBA8UI:
        case GL_RGBA16I:
        case GL_RGBA16UI:
        case GL_RGBA32I:
        case GL_RGBA32UI:
308
        case GL_RGBA_INTEGER:
309
310
311
312
            return 4;
            break;

        default:
313
            cgtAssert(false, "Unknown internal format, this should not happen!");
314
            return 0;
schultezub's avatar
schultezub committed
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
    }
}

int Texture::getSizeOnGPU() const {
    int bpp = calcBpp(internalformat_);
    return bpp * hmul(dimensions_);
}

void Texture::setFilter(Filter filter) {
    filter_ = filter;
    applyFilter();
}

void Texture::applyFilter() {
    bind();

    switch(filter_) {
        case NEAREST:
            glTexParameteri(type_,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
            glTexParameteri(type_,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
            break;

        case LINEAR:
            glTexParameteri(type_, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(type_, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            break;

        case ANISOTROPIC:
            glTexParameterf(type_, GL_TEXTURE_MAX_ANISOTROPY_EXT, GpuCaps.getMaxTextureAnisotropy());

        case MIPMAP:
346
            glTexParameteri(type_,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
347
            glTexParameteri(type_,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST);
schultezub's avatar
schultezub committed
348
349
350
351
352
353
354
355
356
357
358
359
360
            break;
    }
}

void Texture::setWrapping(Wrapping w) {
    wrapping_ = w;
    applyWrapping();
}

void Texture::applyWrapping() {
    bind();
    GLint wrap = wrapping_;

361
    // set wrapping for all diminesions
schultezub's avatar
schultezub committed
362
363
    glTexParameteri(type_, GL_TEXTURE_WRAP_S, wrap);

364
    if (type_ == GL_TEXTURE_2D || type_ == GL_TEXTURE_2D_ARRAY || type_ == GL_TEXTURE_3D )
schultezub's avatar
schultezub committed
365
366
367
368
369
        glTexParameteri(type_, GL_TEXTURE_WRAP_T, wrap);
    if (GL_TEXTURE_3D)
        glTexParameteri(type_, GL_TEXTURE_WRAP_R, wrap);
}

370
void Texture::uploadTexture(const GLubyte* data, GLint format, GLenum dataType) {
schultezub's avatar
schultezub committed
371
372
    bind();

373
    switch (type_) {
schultezub's avatar
schultezub committed
374
        case GL_TEXTURE_1D:
375
            glTexImage1D(type_, 0, internalformat_, dimensions_.x, 0, format, dataType, data);
376
377
            if (filter_ == MIPMAP)
                glGenerateMipmap(GL_TEXTURE_1D);
schultezub's avatar
schultezub committed
378
379
            break;

380
        case GL_TEXTURE_1D_ARRAY: // fallthrough
schultezub's avatar
schultezub committed
381
        case GL_TEXTURE_2D:
382
            glTexImage2D(type_, 0, internalformat_, dimensions_.x, dimensions_.y, 0, format, dataType, data);
383
384
            if (filter_ == MIPMAP)
                glGenerateMipmap(GL_TEXTURE_2D);
schultezub's avatar
schultezub committed
385
386
            break;

387
        case GL_TEXTURE_2D_ARRAY: // fallthrough
schultezub's avatar
schultezub committed
388
        case GL_TEXTURE_3D:
389
            glTexImage3D(type_, 0, internalformat_, dimensions_.x, dimensions_.y, dimensions_.z, 0, format, dataType, data);
390
391
            if (filter_ == MIPMAP)
                glGenerateMipmap(GL_TEXTURE_3D);
schultezub's avatar
schultezub committed
392
393
            break;
    }
394
395

    LGL_ERROR;
schultezub's avatar
schultezub committed
396
397
}

398
399
GLubyte* Texture::downloadTextureToBuffer(GLint format, GLenum dataType) const {
    bind();
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
    int arraySize = hmul(dimensions_) * calcBpp(format, dataType);
    GLubyte* pixels = new GLubyte[arraySize];

    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glGetTexImage(type_, 0, format, dataType, pixels);
    return pixels;
}

bool Texture::isDepthTexture() const {
    return internalformat_ == GL_DEPTH_COMPONENT
        || internalformat_ == GL_DEPTH_COMPONENT16 
        || internalformat_ == GL_DEPTH_COMPONENT24
        || internalformat_ == GL_DEPTH_COMPONENT32
        || internalformat_ == GL_DEPTH_COMPONENT32F;
}

void Texture::setPriority(GLclampf p) {
    glPrioritizeTextures(1, &id_, &p);
}

bool Texture::isResident() const {
    GLboolean resident;
    return glAreTexturesResident(1, &id_, &resident) == GL_TRUE;
}

GLint Texture::calcInternalFormat(GLint format, GLenum dataType) {
    switch (format) {
        case GL_RED:
            switch (dataType) {
430
                case GL_UNSIGNED_BYTE:
431
432
                case GL_BYTE:
                    return GL_R8;
433
                case GL_UNSIGNED_SHORT:
434
435
                case GL_SHORT:
                    return GL_R16;
436
                case GL_UNSIGNED_INT:
437
438
                case GL_INT:
                    return GL_R32F;
schultezub's avatar
schultezub committed
439
                case GL_FLOAT:
440
                    return GL_R32F;
schultezub's avatar
schultezub committed
441
                default:
442
443
                    cgtAssert(false, "Should not reach this - wrong base data type!");
                    return GL_RED;
schultezub's avatar
schultezub committed
444
            }
445
446
        case GL_RG:
            switch (dataType) {
447
                case GL_UNSIGNED_BYTE:
448
449
                case GL_BYTE:
                    return GL_RG8;
450
                case GL_UNSIGNED_SHORT:
451
452
                case GL_SHORT:
                    return GL_RG16;
453
                case GL_UNSIGNED_INT:
454
455
                case GL_INT:
                    return GL_RG32F;
456
                case GL_FLOAT:
457
                    return GL_RG32F;
schultezub's avatar
schultezub committed
458
                default:
459
460
                    cgtAssert(false, "Should not reach this - wrong base data type!");
                    return GL_RG;
schultezub's avatar
schultezub committed
461
            }
462
463
        case GL_RGB:
            switch (dataType) {
464
                case GL_UNSIGNED_BYTE:
465
466
                case GL_BYTE:
                    return GL_RGB8;
467
                case GL_UNSIGNED_SHORT:
468
469
                case GL_SHORT:
                    return GL_RGB16;
470
                case GL_UNSIGNED_INT:
471
472
                case GL_INT:
                    return GL_RGB32F;
473
                case GL_FLOAT:
474
                    return GL_RGB32F;
schultezub's avatar
schultezub committed
475
                default:
476
477
                    cgtAssert(false, "Should not reach this - wrong base data type!");
                    return GL_RGB;
478
            }
479
480
        case GL_RGBA:
            switch (dataType) {
481
                case GL_UNSIGNED_BYTE:
482
483
                case GL_BYTE:
                    return GL_RGBA8;
484
                case GL_UNSIGNED_SHORT:
485
486
                case GL_SHORT:
                    return GL_RGBA16;
487
                case GL_UNSIGNED_INT:
488
489
                case GL_INT:
                    return GL_RGBA32F;
490
                case GL_FLOAT:
491
                    return GL_RGBA32F;
492
                default:
493
494
                    cgtAssert(false, "Should not reach this - wrong base data type!");
                    return GL_RGBA;
495
            }
schultezub's avatar
schultezub committed
496
        default:
497
498
            cgtAssert(false, "Should not reach this, wrong number of channels!");
            return GL_RED;
schultezub's avatar
schultezub committed
499
500
501
    }
}

502
503
504
505
506
507
508
509
510
GLint Texture::calcMatchingFormat(GLint internalFormat) {
    // supports all formats from http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml
    switch (internalFormat) {
        case GL_DEPTH_COMPONENT:
        case GL_DEPTH_COMPONENT16:
        case GL_DEPTH_COMPONENT24:
        case GL_DEPTH_COMPONENT32:
        case GL_DEPTH_COMPONENT32F:
            return GL_DEPTH_COMPONENT;
511

512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
        case GL_RED:
        case GL_R8:
        case GL_R8_SNORM:
        case GL_R16:
        case GL_R16_SNORM:
        case GL_R16F:
        case GL_R32F:
            return GL_RED;
            break;
        case GL_R8I:
        case GL_R8UI:
        case GL_R16I:
        case GL_R16UI:
        case GL_R32I:
        case GL_R32UI:
            return GL_RED_INTEGER;
528
            break;
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
        case 2:
        case GL_DEPTH_STENCIL:
        case GL_RG:
        case GL_RG8:
        case GL_RG8_SNORM:
        case GL_RG16:
        case GL_RG16_SNORM:
        case GL_RG16F:
        case GL_RG32F:
            return GL_RG;
            break;
        case GL_RG8I:
        case GL_RG8UI:
        case GL_RG16I:
        case GL_RG16UI:
        case GL_RG32I:
        case GL_RG32UI:
            return GL_RG_INTEGER;
548
            break;
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
        case 3:
        case GL_RGB:
        case GL_R3_G3_B2:
        case GL_RGB4:
        case GL_RGB5:
        case GL_RGB8:
        case GL_RGB8_SNORM:
        case GL_RGB10:
        case GL_RGB12:
        case GL_RGB16_SNORM:
        case GL_SRGB8:
        case GL_RGB16:
        case GL_RGB16F:
        case GL_RGB32F:
        case GL_R11F_G11F_B10F:
        case GL_RGB9_E5:
            return GL_RGB;
            break;
        case GL_RGB8I:
        case GL_RGB8UI:
        case GL_RGB16I:
        case GL_RGB16UI:
        case GL_RGB32I:
        case GL_RGB32UI:
            return GL_RGB_INTEGER;
575
576
            break;

577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
        case 4:
        case GL_RGBA:
        case GL_RGBA2:
        case GL_RGBA4:
        case GL_RGB5_A1:
        case GL_RGBA8:
        case GL_RGBA8_SNORM:
        case GL_RGB10_A2:
        case GL_RGB10_A2UI:
        case GL_RGBA12:
        case GL_RGBA16:
        case GL_SRGB8_ALPHA8:
        case GL_RGBA16F:
        case GL_RGBA32F:
            return GL_RGBA;
            break;
        case GL_RGBA8I:
        case GL_RGBA8UI:
        case GL_RGBA16I:
        case GL_RGBA16UI:
        case GL_RGBA32I:
        case GL_RGBA32UI:
            return GL_RGBA_INTEGER;
600
            break;
601
602

        default:
603
604
            cgtAssert(false, "Unknown internal format, this should not happen!");
            return 0;
605
606
607
    }
}

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
GLenum Texture::calcMatchingDataType(GLint internalFormat) {
    // supports all formats from http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml
    switch (internalFormat) {
        case GL_R8:
        case GL_R8UI:
        case GL_RG8:
        case GL_RG8UI:
        case GL_RGB8:
        case GL_RGB8UI:
        case GL_RGBA8:
        case GL_RGBA8UI:
        case GL_RGB4:
        case GL_SRGB8:
        case GL_RGBA2:
        case GL_RGBA4:
        case GL_SRGB8_ALPHA8:
            return GL_UNSIGNED_BYTE;
625
            break;
schultezub's avatar
schultezub committed
626
627


628
629
630
631
632
633
634
635
636
637
        case GL_R8_SNORM:
        case GL_R8I:
        case GL_RG8_SNORM:
        case GL_RG8I:
        case GL_RGB8_SNORM:
        case GL_RGB8I:
        case GL_RGBA8_SNORM:
        case GL_RGBA8I:
            return GL_BYTE;
            break;
schultezub's avatar
schultezub committed
638
639


640
641
642
643
644
645
646
647
648
649
        case GL_R16:
        case GL_R16UI:
        case GL_RG16:
        case GL_RG16UI:
        case GL_RGB16:
        case GL_RGB16UI:
        case GL_RGBA16:
        case GL_RGBA16UI:
            return GL_UNSIGNED_SHORT;
            break;
schultezub's avatar
schultezub committed
650
651


652
653
654
655
656
657
658
659
660
661
        case GL_R16_SNORM:
        case GL_R16I:
        case GL_RG16_SNORM:
        case GL_RG16I:
        case GL_RGB16_SNORM:
        case GL_RGB16I:
        case GL_RGBA16_SNORM:
        case GL_RGBA16I:
            return GL_SHORT;
            break;
schultezub's avatar
schultezub committed
662
663


664
665
666
667
668
669
        case GL_R32UI:
        case GL_RG32UI:
        case GL_RGB32UI:
        case GL_RGBA32UI:
            return GL_UNSIGNED_INT;
            break;
schultezub's avatar
schultezub committed
670
671


672
673
674
675
676
677
        case GL_R32I:
        case GL_RG32I:
        case GL_RGB32I:
        case GL_RGBA32I:
            return GL_INT;
            break;
schultezub's avatar
schultezub committed
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
        case GL_DEPTH_COMPONENT:
        case GL_DEPTH_COMPONENT16:
        case GL_DEPTH_COMPONENT24:
        case GL_DEPTH_COMPONENT32:
        case GL_DEPTH_COMPONENT32F:
        case GL_DEPTH_STENCIL:
        case GL_R16F:
        case GL_R32F:
        case GL_RG16F:
        case GL_RG32F:
        case GL_RGB16F:
        case GL_RGB32F:
        case GL_RGBA16F:
        case GL_RGBA32F:
        case GL_R3_G3_B2:
        case GL_RGB5:
        case GL_RGB10:
        case GL_RGB12:
        case GL_R11F_G11F_B10F:
        case GL_RGB9_E5:
        case GL_RGB5_A1:
        case GL_RGB10_A2:
        case GL_RGB10_A2UI:
        case GL_RGBA12:
            return GL_FLOAT;
            break;
schultezub's avatar
schultezub committed
705

706
707
708
709
        default:
            cgtAssert(false, "Unknown internal format, this should not happen!");
            return 0;
    }
710
711
712
}


713
} // namespace cgt