kick
/Users/morten/Programmering/cpp/kick/src/kick/texture/image_format.cpp
00001 //
00002 //  image_format.cpp
00003 //  UnitTest_KickCPP
00004 //
00005 //  Created by morten on 07/04/14.
00006 //
00007 //
00008 
00009 #include "image_format.h"
00010 
00011 using namespace std;
00012 
00013 namespace kick {
00014     bool ImageFormat::isValid(std::function<void (std::string)> onError){
00015         bool valid = true;
00016 #ifndef GL_ES_VERSION_2_0
00017         // OpenGL 4 glTexImage2D table 1
00018         if (internalFormat != GL_DEPTH_COMPONENT &&
00019             internalFormat != GL_DEPTH_STENCIL &&
00020             internalFormat != GL_RED &&
00021             internalFormat != GL_RG &&
00022             internalFormat != GL_RGB &&
00023             internalFormat != GL_RGBA){
00024             // OpenGL 4 glTexImage2D table 2
00025             if (internalFormat != GL_R8 &&
00026                 internalFormat != GL_R8_SNORM &&
00027                 internalFormat != GL_R16 &&
00028                 internalFormat != GL_R16_SNORM &&
00029                 internalFormat != GL_RG8 &&
00030                 internalFormat != GL_RG8_SNORM &&
00031                 internalFormat != GL_RG16 &&
00032                 internalFormat != GL_RG16_SNORM &&
00033                 internalFormat != GL_R3_G3_B2 &&
00034                 internalFormat != GL_RGB4 &&
00035                 internalFormat != GL_RGB5 &&
00036                 internalFormat != GL_RGB8 &&
00037                 internalFormat != GL_RGB8_SNORM &&
00038                 internalFormat != GL_RGB10 &&
00039                 internalFormat != GL_RGB12 &&
00040                 internalFormat != GL_RGB16_SNORM &&
00041                 internalFormat != GL_RGBA2 &&
00042                 internalFormat != GL_RGBA4 &&
00043                 internalFormat != GL_RGB5_A1 &&
00044                 internalFormat != GL_RGBA8 &&
00045                 internalFormat != GL_RGBA8_SNORM &&
00046                 internalFormat != GL_RGB10_A2 &&
00047                 internalFormat != GL_RGB10_A2UI &&
00048                 internalFormat != GL_RGBA12 &&
00049                 internalFormat != GL_RGBA16 &&
00050                 internalFormat != GL_SRGB8 &&
00051                 internalFormat != GL_SRGB8_ALPHA8 &&
00052                 internalFormat != GL_R16F &&
00053                 internalFormat != GL_RG16F &&
00054                 internalFormat != GL_RGB16F &&
00055                 internalFormat != GL_RGBA16F &&
00056                 internalFormat != GL_R32F &&
00057                 internalFormat != GL_RG32F &&
00058                 internalFormat != GL_RGB32F &&
00059                 internalFormat != GL_RGBA32F &&
00060                 internalFormat != GL_R11F_G11F_B10F &&
00061                 internalFormat != GL_RGB9_E5 &&
00062                 internalFormat != GL_R8I && 
00063                 internalFormat != GL_R8UI && 
00064                 internalFormat != GL_R16I && 
00065                 internalFormat != GL_R16UI && 
00066                 internalFormat != GL_R32I && 
00067                 internalFormat != GL_R32UI && 
00068                 internalFormat != GL_RG8I && 
00069                 internalFormat != GL_RG8UI && 
00070                 internalFormat != GL_RG16I && 
00071                 internalFormat != GL_RG16UI && 
00072                 internalFormat != GL_RG32I && 
00073                 internalFormat != GL_RG32UI && 
00074                 internalFormat != GL_RGB8I && 
00075                 internalFormat != GL_RGB8UI && 
00076                 internalFormat != GL_RGB16I && 
00077                 internalFormat != GL_RGB16UI && 
00078                 internalFormat != GL_RGB32I && 
00079                 internalFormat != GL_RGB32UI && 
00080                 internalFormat != GL_RGBA8I && 
00081                 internalFormat != GL_RGBA8UI && 
00082                 internalFormat != GL_RGBA16I && 
00083                 internalFormat != GL_RGBA16UI && 
00084                 internalFormat != GL_RGBA32I && 
00085                 internalFormat != GL_RGBA32UI){
00086                 
00087                 // OpenGL 4 glTexImage2D table 3
00088                 if (internalFormat != GL_COMPRESSED_RED &&
00089                     internalFormat != GL_COMPRESSED_RG &&
00090                     internalFormat != GL_COMPRESSED_RGB &&
00091                     internalFormat != GL_COMPRESSED_RGBA &&
00092                     internalFormat != GL_COMPRESSED_SRGB &&
00093                     internalFormat != GL_COMPRESSED_SRGB_ALPHA &&
00094                     internalFormat != GL_COMPRESSED_RED_RGTC1 &&
00095                     internalFormat != GL_COMPRESSED_SIGNED_RED_RGTC1 &&
00096                     internalFormat != GL_COMPRESSED_RG_RGTC2 &&
00097                     internalFormat != GL_COMPRESSED_SIGNED_RG_RGTC2
00098                     /*
00099                     &&
00100                     internalFormat != GL_COMPRESSED_RGBA_BPTC_UNORM &&
00101                     internalFormat != GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM && 
00102                     internalFormat != GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT && 
00103                     internalFormat != GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT*/
00104                     ){
00105                     valid = false;
00106                     onError(string{"internalFormat has an invalid value: "}+to_string(internalFormat));
00107                 }
00108                 
00109             }
00110         }
00111         if (format != GL_RED &&
00112             format != GL_RG &&
00113             format != GL_RGB &&
00114             format != GL_BGR &&
00115             format != GL_RGBA &&
00116             format != GL_BGRA &&
00117             format != GL_RED_INTEGER &&
00118             format != GL_RG_INTEGER &&
00119             format != GL_RGB_INTEGER &&
00120             format != GL_BGR_INTEGER &&
00121             format != GL_RGBA_INTEGER &&
00122             format != GL_BGRA_INTEGER &&
00123             format != GL_STENCIL_INDEX && 
00124             format != GL_DEPTH_COMPONENT && 
00125             format != GL_DEPTH_STENCIL){
00126             valid = false;
00127             onError(string{"format has an invalid value: "}+to_string(format));
00128         }
00129         
00130         if (type != GL_UNSIGNED_BYTE &&
00131             type != GL_BYTE &&
00132             type != GL_UNSIGNED_SHORT &&
00133             type != GL_SHORT &&
00134             type != GL_UNSIGNED_INT &&
00135             type != GL_INT &&
00136             type != GL_FLOAT &&
00137             type != GL_UNSIGNED_BYTE_3_3_2 &&
00138             type != GL_UNSIGNED_BYTE_2_3_3_REV &&
00139             type != GL_UNSIGNED_SHORT_5_6_5 &&
00140             type != GL_UNSIGNED_SHORT_5_6_5_REV &&
00141             type != GL_UNSIGNED_SHORT_4_4_4_4 &&
00142             type != GL_UNSIGNED_SHORT_4_4_4_4_REV &&
00143             type != GL_UNSIGNED_SHORT_5_5_5_1 &&
00144             type != GL_UNSIGNED_SHORT_1_5_5_5_REV &&
00145             type != GL_UNSIGNED_INT_8_8_8_8 && 
00146             type != GL_UNSIGNED_INT_8_8_8_8_REV && 
00147             type != GL_UNSIGNED_INT_10_10_10_2 && 
00148             type != GL_UNSIGNED_INT_2_10_10_10_REV){
00149             valid = false;
00150             onError(string{"type has an invalid value: "}+to_string(type));
00151         }
00152 #endif
00153         return valid;
00154     }
00155 };
 All Classes Functions Variables