File indexing completed on 2026-04-09 07:49:37
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 struct SGLFW_GLboolean
0025 {
0026 static constexpr const char* GL_FALSE_ = "GL_FALSE" ;
0027 static constexpr const char* GL_TRUE_ = "GL_TRUE" ;
0028 static GLboolean Value(const char* name);
0029 static const char* Name(GLboolean value);
0030 };
0031 inline GLboolean SGLFW_GLboolean::Value(const char* name)
0032 {
0033 GLboolean value = GL_FALSE ;
0034 if( strcmp( name, GL_FALSE_) == 0 ) value = GL_FALSE ;
0035 if( strcmp( name, GL_TRUE_) == 0 ) value = GL_TRUE ;
0036 return value ;
0037 }
0038 inline const char* SGLFW_GLboolean::Name(GLboolean value)
0039 {
0040 const char* s = nullptr ;
0041 switch(value)
0042 {
0043 case GL_FALSE: s = GL_FALSE_ ; break ;
0044 case GL_TRUE: s = GL_TRUE_ ; break ;
0045 }
0046 return s ;
0047 }
0048
0049
0050 struct SGLFW_bool
0051 {
0052 static constexpr const char* false_ = "false" ;
0053 static constexpr const char* true_ = "true" ;
0054 static bool Value(const char* name);
0055 static const char* Name(bool value);
0056 };
0057 inline bool SGLFW_bool::Value(const char* name)
0058 {
0059 bool value = false ;
0060 if( strcmp( name, false_) == 0 ) value = false ;
0061 if( strcmp( name, true_) == 0 ) value = true ;
0062 return value ;
0063 }
0064 inline const char* SGLFW_bool::Name(bool value)
0065 {
0066 return value ? true_ : false_ ;
0067 }
0068
0069
0070
0071 struct SGLFW_GLenum
0072 {
0073 static constexpr const char* GL_BYTE_ = "GL_BYTE" ;
0074 static constexpr const char* GL_UNSIGNED_BYTE_ = "GL_UNSIGNED_BYTE" ;
0075 static constexpr const char* GL_SHORT_ = "GL_SHORT" ;
0076 static constexpr const char* GL_UNSIGNED_SHORT_ = "GL_UNSIGNED_SHORT" ;
0077 static constexpr const char* GL_INT_ = "GL_INT" ;
0078 static constexpr const char* GL_UNSIGNED_INT_ = "GL_UNSIGNED_INT" ;
0079 static constexpr const char* GL_HALF_FLOAT_ = "GL_HALF_FLOAT" ;
0080 static constexpr const char* GL_FLOAT_ = "GL_FLOAT" ;
0081 static constexpr const char* GL_DOUBLE_ = "GL_DOUBLE" ;
0082
0083 static const char* Name(GLenum type);
0084 static GLenum Type(const char* name);
0085 };
0086
0087 inline const char* SGLFW_GLenum::Name(GLenum type)
0088 {
0089 const char* s = nullptr ;
0090 switch(type)
0091 {
0092 case GL_BYTE: s = GL_BYTE_ ; break ;
0093 case GL_UNSIGNED_BYTE: s = GL_UNSIGNED_BYTE_ ; break ;
0094 case GL_SHORT: s = GL_SHORT_ ; break ;
0095 case GL_UNSIGNED_SHORT: s = GL_UNSIGNED_SHORT_ ; break ;
0096 case GL_INT: s = GL_INT_ ; break ;
0097 case GL_UNSIGNED_INT: s = GL_UNSIGNED_INT_ ; break ;
0098 case GL_HALF_FLOAT: s = GL_HALF_FLOAT_ ; break ;
0099 case GL_FLOAT: s = GL_FLOAT_ ; break ;
0100 case GL_DOUBLE: s = GL_DOUBLE_ ; break ;
0101 default: s = nullptr ; break ;
0102 }
0103 return s ;
0104 }
0105
0106 inline GLenum SGLFW_GLenum::Type(const char* name)
0107 {
0108 GLenum type = 0 ;
0109 if( strcmp( name, GL_BYTE_) == 0 ) type = GL_BYTE ;
0110 if( strcmp( name, GL_UNSIGNED_BYTE_) == 0 ) type = GL_UNSIGNED_BYTE ;
0111 if( strcmp( name, GL_SHORT_) == 0 ) type = GL_SHORT ;
0112 if( strcmp( name, GL_UNSIGNED_SHORT_) == 0 ) type = GL_UNSIGNED_SHORT ;
0113 if( strcmp( name, GL_INT_) == 0 ) type = GL_INT ;
0114 if( strcmp( name, GL_UNSIGNED_INT_) == 0 ) type = GL_UNSIGNED_INT ;
0115 if( strcmp( name, GL_HALF_FLOAT_) == 0 ) type = GL_HALF_FLOAT ;
0116 if( strcmp( name, GL_FLOAT_) == 0 ) type = GL_FLOAT ;
0117 if( strcmp( name, GL_DOUBLE_) == 0 ) type = GL_DOUBLE ;
0118 return type ;
0119 }
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 struct SGLFW_Attrib
0132 {
0133 const char* name ;
0134 const char* spec ;
0135 std::vector<std::string> field ;
0136
0137 GLuint index ;
0138
0139 GLint size ;
0140 GLenum type ;
0141 GLboolean normalized ;
0142 GLsizei stride ;
0143 size_t byte_offset ;
0144 bool integer_attribute ;
0145
0146 void* byte_offset_pointer ;
0147
0148
0149 SGLFW_Attrib( const char* name, const char* spec );
0150 std::string desc() const ;
0151 };
0152
0153
0154 inline SGLFW_Attrib::SGLFW_Attrib(const char* name_, const char* spec_)
0155 :
0156 name(strdup(name_)),
0157 spec(strdup(spec_)),
0158 index(0),
0159 size(0),
0160 type(0),
0161 normalized(false),
0162 stride(0),
0163 byte_offset(0),
0164 integer_attribute(false),
0165 byte_offset_pointer(nullptr)
0166 {
0167 char delim = ',' ;
0168 std::stringstream ss;
0169 ss.str(spec) ;
0170 std::string s;
0171 while (std::getline(ss, s, delim)) field.push_back(s) ;
0172 assert( field.size() == 6 );
0173
0174 size = std::atoi(field[0].c_str()) ; assert( size == 1 || size == 2 || size == 3 || size == 4 ) ;
0175 type = SGLFW_GLenum::Type(field[1].c_str()) ; assert( type > 0 );
0176 normalized = SGLFW_GLboolean::Value(field[2].c_str()) ;
0177 stride = std::atoi( field[3].c_str() ); assert( stride > 0 );
0178 byte_offset = std::atoi( field[4].c_str() ); assert( byte_offset >= 0 );
0179 integer_attribute = SGLFW_bool::Value(field[5].c_str()) ;
0180
0181 byte_offset_pointer = (void*)byte_offset ;
0182 }
0183
0184 inline std::string SGLFW_Attrib::desc() const
0185 {
0186 std::stringstream ss ;
0187 ss << "SGLFW_Attrib::desc" << std::endl
0188 << std::setw(20) << "name" << " : " << name << std::endl
0189 << std::setw(20) << "spec" << " : " << spec << std::endl
0190 << std::setw(20) << "index" << " : " << index << std::endl
0191 << std::setw(20) << "size" << " : " << size << std::endl
0192 << std::setw(20) << "type" << " : " << SGLFW_GLenum::Name(type) << std::endl
0193 << std::setw(20) << "normalized" << " : " << SGLFW_GLboolean::Name(normalized) << std::endl
0194 << std::setw(20) << "stride" << " : " << stride << std::endl
0195 << std::setw(20) << "byte_offset" << " : " << byte_offset << std::endl
0196 << std::setw(20) << "integer_attribute" << " : " << SGLFW_bool::Name(integer_attribute) << std::endl
0197 << std::setw(20) << "byte_offset_pointer" << " : " << byte_offset_pointer << std::endl
0198 ;
0199
0200 for(unsigned i=0 ; i < field.size() ; i++ ) ss << std::setw(20) << i << " : " << field[i] << std::endl ;
0201 std::string s = ss.str();
0202 return s ;
0203 }
0204
0205
0206