6 #ifndef GLVERTEX_CORE_H
7 #define GLVERTEX_CORE_H
19 #include "glvertex_gl.h"
61 LGL_TEXGEN_HEMISPHERE,
63 LGL_TEXGEN_NORMAL_HEMISPHERE,
64 LGL_TEXGEN_NORMAL_HEDGEHOG,
65 LGL_TEXGEN_MIXED_HEMISPHERE,
66 LGL_TEXGEN_MIXED_HEDGEHOG
92 LGL_INTERLACE_NONE = 0,
93 LGL_INTERLACE_HORIZONTAL_LEFT,
94 LGL_INTERLACE_HORIZONTAL_RIGHT,
95 LGL_INTERLACE_VERTICAL_TOP,
96 LGL_INTERLACE_VERTICAL_BOTTOM,
102 LGL_VERBOSITY_NONE = 0,
103 LGL_VERBOSITY_MESSAGES = 1,
104 LGL_VERBOSITY_ERRORS = 2,
105 LGL_VERBOSITY_WARNINGS = 3
108 #define LGL_NUM_BUFFERS 6
110 #ifndef LGL_NUM_ATTRIBUTES
111 # define LGL_NUM_ATTRIBUTES 4
114 #define LGL_VERTEX_BUFFER 0
115 #define LGL_COLOR_BUFFER 1
116 #define LGL_NORMAL_BUFFER 2
117 #define LGL_TEXCOORD_BUFFER 3
118 #define LGL_BARYCENTRIC_BUFFER 4
119 #define LGL_ATTRIBUTE_BUFFER 5
121 #define LGL_VERTEX_LOCATION 0
122 #define LGL_COLOR_LOCATION 1
123 #define LGL_NORMAL_LOCATION 2
124 #define LGL_TEXCOORD_LOCATION 3
125 #define LGL_BARYCENTRIC_LOCATION 4
126 #define LGL_ATTRIBUTE_LOCATION 5
128 #define LGL_NUM_SHADERS 12
131 # define LGL_NUM_CLIPPLANES 6
133 # define LGL_NUM_CLIPPLANES 8
136 #include "glvertex_shaders.h"
155 template <
class VEC4, const GLenum gl_type>
161 lgl(
const std::string &name =
"",
162 bool immediate =
false,
163 bool storagetype =
true)
165 immediate_(immediate),
166 storagetype_(storagetype),
167 vertex_(0), copied_(false), copy_(false),
168 color_(1), normal_(0), texcoord_(0),
169 hascolor_(false), hasnormal_(false), hastexcoord_(false)
194 finalizeStaticOpenGL();
217 lgl& operator = (
const lgl ©) {}
219 union lgl_uniform_union
223 float vec2f_value[2];
224 float vec3f_value[3];
225 float vec4f_value[4];
226 float mat2f_value[4];
227 float mat3f_value[9];
228 float mat4f_value[16];
231 enum lgl_uniform_enum
244 struct lgl_uniform_struct
248 lgl_uniform_enum type;
249 lgl_uniform_union value;
253 typedef std::map<std::string, unsigned int> lgl_uniform_map_type;
254 typedef std::vector<lgl_uniform_struct> lgl_uniform_location_type;
258 void lglVertex(
const vec4 &v)
262 lglError(
"invalid vertex specification");
266 if (!immediate_ && rendered_)
268 lglError(
"invalid vbo modification");
272 if (premodel_matrix_identity_.back())
277 if (primitive_ == LGL_QUAD_STRIP) lglPlainVertex(v);
281 lglPlainVertex(v, color_, texcoord_, normal_);
287 vec4 p = premodel_matrix_.back() * v;
292 if (primitive_ == LGL_QUAD_STRIP) lglPlainVertex(p);
296 lglPlainVertex(p, color_, texcoord_);
300 if (premodel_matrix_recompute_.back())
302 premodel_matrix_it_.back() =
mat3(premodel_matrix_.back().invert().transpose());
303 premodel_matrix_recompute_.back() =
false;
306 vec4 p = premodel_matrix_.back() * v;
307 vec3 n = premodel_matrix_it_.back() * normal_;
312 if (primitive_ == LGL_QUAD_STRIP) lglPlainVertex(p);
316 lglPlainVertex(p, color_, texcoord_, n);
328 void lglPlainVertex(
const vec4 &v,
335 if (!enlarge())
return;
337 if (storagetype_) vertices_[size_] = v;
338 else verticesf_[size_] = v;
343 if (texgen_ != LGL_TEXGEN_NONE)
345 vec4 texcoord = texgen(v, n);
346 if (!pretex_matrix_identity_.back()) texcoord = pretex_matrix_.back() * texcoord;
347 texcoords_[size_] = texcoord;
353 if (!pretex_matrix_identity_.back()) texcoord = pretex_matrix_.back() * texcoord;
354 texcoords_[size_] = texcoord;
358 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
359 if (hasattribute_[i])
360 attributes_[size_*LGL_NUM_ATTRIBUTES+i] = attribute_[i];
366 if (size_%2 == 0) barycentrics_[size_] =
vec3f(1,0,1);
367 else barycentrics_[size_] =
vec3f(0,1,1);
369 case LGL_TRIANGLE_FAN:
370 if (size_ == 0) barycentrics_[size_] =
vec3f(1,0,0);
372 if (size_%2 == 1) barycentrics_[size_] =
vec3f(0,1,0);
373 else barycentrics_[size_] =
vec3f(0,0,1);
378 case 0: barycentrics_[size_] =
vec3f(0,0,0.25);
break;
379 case 1: barycentrics_[size_] =
vec3f(1,0,0.25);
break;
380 case 2: barycentrics_[size_] =
vec3f(1,1,0.75);
break;
381 case 3: barycentrics_[size_] =
vec3f(0,1,0.75);
break;
387 case 0: barycentrics_[size_] =
vec3f(0,0,0.25);
break;
388 case 1: barycentrics_[size_] =
vec3f(1,0,0.25);
break;
389 case 2: barycentrics_[size_] =
vec3f(0,1,0.75);
break;
390 case 3: barycentrics_[size_] =
vec3f(1,1,0.75);
break;
393 case LGL_TRIANGLE_STRIP:
398 case 0: barycentrics_[size_] =
vec3f(1,0,0);
break;
399 case 1: barycentrics_[size_] =
vec3f(0,1,0);
break;
400 case 2: barycentrics_[size_] =
vec3f(0,0,1);
break;
409 bboxmin_ = bboxmax_ = v3;
413 if (v3.x < bboxmin_.x) bboxmin_.x = v3.x;
414 else if (v3.x > bboxmax_.x) bboxmax_.x = v3.x;
415 if (v3.y < bboxmin_.y) bboxmin_.y = v3.y;
416 else if (v3.y > bboxmax_.y) bboxmax_.y = v3.y;
417 if (v3.z < bboxmin_.z) bboxmin_.z = v3.z;
418 else if (v3.z > bboxmax_.z) bboxmax_.z = v3.z;
433 case LGL_TEXGEN_NORMAL:
436 case LGL_TEXGEN_HEMISPHERE:
438 double x = texcoord.x;
439 double y = texcoord.y;
440 double z = texcoord.z;
441 double alpha = atan2(z, x);
442 double beta = atan2(sqrt(x*x+z*z), fabs(y));
443 double r = beta / PI;
445 texcoord.x = r * cos(alpha) + 0.5;
446 texcoord.y = r * sin(alpha) + 0.5;
450 case LGL_TEXGEN_HEDGEHOG:
452 double x = texcoord.x;
453 double y = texcoord.y;
454 double z = texcoord.z;
455 double alpha = atan2(z, x);
456 double beta = atan2(sqrt(x*x+z*z), y);
457 double r = 0.5 * beta / PI;
458 r = (r < 0.5)? 2*(r + r*r)/3 : 2*r - (1 + 2*r*r)/3;
459 texcoord.x = r * cos(alpha) + 0.5;
460 texcoord.y = r * sin(alpha) + 0.5;
464 case LGL_TEXGEN_NORMAL_HEMISPHERE:
467 double x = texcoord.x;
468 double y = texcoord.y;
469 double z = texcoord.z;
470 double alpha = atan2(z, x);
471 double beta = atan2(sqrt(x*x+z*z), fabs(y));
472 double r = beta / PI;
474 texcoord.x = r * cos(alpha) + 0.5;
475 texcoord.y = r * sin(alpha) + 0.5;
479 case LGL_TEXGEN_NORMAL_HEDGEHOG:
482 double x = texcoord.x;
483 double y = texcoord.y;
484 double z = texcoord.z;
485 double alpha = atan2(z, x);
486 double beta = atan2(sqrt(x*x+z*z), y);
487 double r = 0.5 * beta / PI;
488 r = (r < 0.5)? 2*(r + r*r)/3 : 2*r - (1 + 2*r*r)/3;
489 texcoord.x = r * cos(alpha) + 0.5;
490 texcoord.y = r * sin(alpha) + 0.5;
494 case LGL_TEXGEN_MIXED_HEMISPHERE:
496 double x = texcoord.x;
497 double y = texcoord.y;
498 double z = texcoord.z;
499 double alpha = atan2(z, x);
500 double beta = atan2(sqrt(x*x+z*z), fabs(y));
501 double r = beta / PI;
503 texcoord.x = r * cos(alpha) + 0.5;
504 texcoord.y = r * sin(alpha) + 0.5;
511 beta = atan2(sqrt(x*x+z*z), fabs(y));
515 texcoord.x += r * cos(alpha);
516 texcoord.y += r * sin(alpha);
519 case LGL_TEXGEN_MIXED_HEDGEHOG:
521 double x = texcoord.x;
522 double y = texcoord.y;
523 double z = texcoord.z;
524 double alpha = atan2(z, x);
525 double beta = atan2(sqrt(x*x+z*z), y);
526 double r = 0.5 * beta / PI;
527 r = (r < 0.5)? 2*(r + r*r)/3 : 2*r - (1 + 2*r*r)/3;
528 texcoord.x = r * cos(alpha) + 0.5;
529 texcoord.y = r * sin(alpha) + 0.5;
536 beta = atan2(sqrt(x*x+z*z), y);
538 r = (r < 0.5)? 2*(r + r*r)/3 : 2*r - (1 + 2*r*r)/3;
540 texcoord.x += r * cos(alpha);
541 texcoord.y += r * sin(alpha);
557 void *vbuffer = malloc(maxsize_*
sizeof(VEC4));
558 if ((vertices_=(VEC4 *)vbuffer) == NULL)
return(
false);
562 void *vbuffer = malloc(maxsize_*
sizeof(
vec4f));
563 if ((verticesf_=(
vec4f *)vbuffer) == NULL)
return(
false);
566 void *cbuffer = malloc(maxsize_*
sizeof(
vec4f));
567 if ((colors_=(
vec4f *)cbuffer) == NULL)
return(
false);
569 void *nbuffer = malloc(maxsize_*
sizeof(
vec3f));
570 if ((normals_=(
vec3f *)nbuffer) == NULL)
return(
false);
572 void *tbuffer = malloc(maxsize_*
sizeof(
vec4f));
573 if ((texcoords_=(
vec4f *)tbuffer) == NULL)
return(
false);
575 void *bbuffer = malloc(maxsize_*
sizeof(
vec3f));
576 if ((barycentrics_=(
vec3f *)bbuffer) == NULL)
return(
false);
578 void *abuffer = malloc(maxsize_*LGL_NUM_ATTRIBUTES*
sizeof(
vec4f));
579 if ((attributes_=(
vec4f *)abuffer) == NULL)
return(
false);
581 else if (size_ >= maxsize_)
585 void *vbuffer = realloc((
void *)vertices_, 2*maxsize_*
sizeof(VEC4));
586 if ((vertices_=(VEC4 *)vbuffer) == NULL)
return(
false);
590 void *vbuffer = realloc((
void *)verticesf_, 2*maxsize_*
sizeof(
vec4f));
591 if ((verticesf_=(
vec4f *)vbuffer) == NULL)
return(
false);
594 void *cbuffer = realloc((
void *)colors_, 2*maxsize_*
sizeof(
vec4f));
595 if ((colors_=(
vec4f *)cbuffer) == NULL)
return(
false);
597 void *nbuffer = realloc((
void *)normals_, 2*maxsize_*
sizeof(
vec3f));
598 if ((normals_=(
vec3f *)nbuffer) == NULL)
return(
false);
600 void *tbuffer = realloc((
void *)texcoords_, 2*maxsize_*
sizeof(
vec4f));
601 if ((texcoords_=(
vec4f *)tbuffer) == NULL)
return(
false);
603 void *bbuffer = realloc((
void *)barycentrics_, 2*maxsize_*
sizeof(
vec3f));
604 if ((barycentrics_=(
vec3f *)bbuffer) == NULL)
return(
false);
606 void *abuffer = realloc((
void *)attributes_, 2*maxsize_*LGL_NUM_ATTRIBUTES*
sizeof(
vec4f));
607 if ((attributes_=(
vec4f *)abuffer) == NULL)
return(
false);
617 if (maxsize_ != size_)
638 void *vbuffer = realloc((
void *)vertices_, maxsize_*
sizeof(VEC4));
639 vertices_ = (VEC4 *)vbuffer;
643 void *vbuffer = realloc((
void *)verticesf_, maxsize_*
sizeof(
vec4f));
644 verticesf_ = (
vec4f *)vbuffer;
648 if (maxsize_ == 0 || !hascolor_)
655 void *cbuffer = realloc((
void *)colors_, maxsize_*
sizeof(
vec4f));
656 colors_ = (
vec4f *)cbuffer;
659 if (maxsize_ == 0 || !hasnormal_)
666 void *nbuffer = realloc((
void *)normals_, maxsize_*
sizeof(
vec3f));
667 normals_ = (
vec3f *)nbuffer;
670 if (maxsize_ == 0 || !hastexcoord_)
677 void *tbuffer = realloc((
void *)texcoords_, maxsize_*
sizeof(
vec4f));
678 texcoords_ = (
vec4f *)tbuffer;
684 barycentrics_ = NULL;
688 void *bbuffer = realloc((
void *)barycentrics_, maxsize_*
sizeof(
vec3f));
689 barycentrics_ = (
vec3f *)bbuffer;
692 if (maxsize_ == 0 || !hasattributes_)
699 void *abuffer = realloc((
void *)attributes_, maxsize_*LGL_NUM_ATTRIBUTES*
sizeof(
vec4f));
700 attributes_ = (
vec4f *)abuffer;
711 hascolor_ = hasnormal_ = hastexcoord_ =
false;
715 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
716 hasattribute_[i] =
false;
718 hasattributes_ =
false;
724 bboxmin_ = bboxmax_ =
vec3(NAN);
745 void copyVertex(
int index1,
int index2)
747 if (storagetype_) vertices_[index2] = vertices_[index1];
748 else verticesf_[index2] = verticesf_[index1];
750 colors_[index2] = colors_[index1];
751 normals_[index2] = normals_[index1];
752 texcoords_[index2] = texcoords_[index1];
753 barycentrics_[index2] = barycentrics_[index1];
756 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
757 if (hasattribute_[i])
758 attributes_[index2*LGL_NUM_ATTRIBUTES+i] = attributes_[index1*LGL_NUM_ATTRIBUTES+i];
761 void duplicateVertex(
int index)
765 copyVertex(index, size_);
770 void swapVertex(
int index1,
int index2)
774 copyVertex(index1, size_);
775 copyVertex(index2, index1);
776 copyVertex(size_, index2);
780 void rearrangeQuads()
784 swapVertex(size_-1, size_-2);
786 barycentrics_[size_-4] =
vec3f(1,0,0);
787 barycentrics_[size_-3] =
vec3f(0,1,0);
788 barycentrics_[size_-2] =
vec3f(0,0,1);
789 barycentrics_[size_-1] =
vec3f(1,0,0);
793 if ((size_-4)%6 == 1)
795 duplicateVertex(size_-2);
796 swapVertex(size_-2, size_-1);
800 if ((size_-4)%6 == 0)
802 swapVertex(size_-1, size_-2);
804 barycentrics_[size_-4] =
vec3f(1,0,0);
805 barycentrics_[size_-3] =
vec3f(0,1,0);
806 barycentrics_[size_-2] =
vec3f(0,0,1);
807 barycentrics_[size_-1] =
vec3f(1,0,0);
815 void lglVertex(
double x,
double y,
double z,
double w = 1)
817 lglVertex(
vec4(x,y,z,w));
820 void lglColor(
const vec4f &c)
822 if (disable_coloring_)
826 actual_ = color_ = c;
838 void lglColor(
float r,
float g,
float b,
float a = 1)
840 lglColor(
vec4f(r,g,b,a));
852 void lglNormal(
const vec3f &n)
854 if (disable_lighting_)
858 lglError(
"invalid normal specification");
869 lglNormal(
vec3f(x,y,z));
872 void lglTexCoord(
const vec4f &t)
874 if (disable_texturing_)
878 lglError(
"invalid texcoord specification");
889 lglTexCoord(
vec4f(s,t,r,w));
892 void lglAttribute(
const vec4f &a,
unsigned int n = 0)
895 lglError(
"invalid attribute specification");
897 if (size_ > 0 && !hasattribute_[n])
898 lglError(
"mismatching attribute specification");
900 if (n >= LGL_NUM_ATTRIBUTES)
901 lglError(
"invalid attribute number");
905 hasattribute_[n] =
true;
906 hasattributes_ =
true;
911 void lglAttribute(
float x,
float y,
float z,
float w = 1.0f,
unsigned int n = 0)
913 lglAttribute(
vec4f(x,y,z,w), n);
921 lglError(
"invalid begin operation");
930 #if (LGL_OPENGL_VERSION >= 31) || defined(LGL_GLES)
934 if (primitive == LGL_QUAD_STRIP)
935 primitive = LGL_TRIANGLE_STRIP;
939 if (primitive == LGL_QUADS)
941 primitive = LGL_TRIANGLE_STRIP;
943 if (size_ == 0) rearrange_ =
true;
944 else if (!rearrange_)
lglError(
"unmatched primitive type");
950 primitive_ = primitive;
954 primitive_ = primitive;
957 if (primitive != primitive_)
958 lglError(
"unmatched primitive type");
960 if (primitive_ == LGL_LINE_STRIP || primitive_ == LGL_TRIANGLE_FAN)
963 if (primitive_==LGL_TRIANGLE_STRIP || primitive_==LGL_QUAD_STRIP)
968 lglPlainVertex(vertex_);
969 if (primitive_ == LGL_QUAD_STRIP) lglPlainVertex(vertex_);
1006 unsigned int vertices,
1007 const float *vertex_array,
1008 const float *color_array,
1009 const float *normal_array = NULL,
1010 const float *texcoord_array = NULL)
1012 const float *colors = color_array;
1013 const float *normals = normal_array;
1014 const float *texcoords = texcoord_array;
1016 for (
unsigned int i=0; i<vertices; i++)
1018 if (color_array) {lglColor(*colors, *(colors+1), *(colors+2), *(colors+3)); colors+=4;}
1019 if (normal_array) {lglNormal(*normals, *(normals+1), *(normals+2)); normals+=3;}
1020 if (texcoord_array) {lglTexCoord(*texcoords, *(texcoords+1), *(texcoords+2), *(texcoords+3)); texcoords+=4;}
1021 lglVertex(*vertex_array, *(vertex_array+1), *(vertex_array+2)); vertex_array+=3;
1028 const float *interleaved_array,
1029 unsigned int vertices,
1034 const float *array = interleaved_array;
1036 for (
unsigned int i=0; i<vertices; i++)
1038 vec3 vertex(*array, *(array+1), *(array+2)); array+=3;
1039 if (colors == 3) {lglColor(*array, *(array+1), *(array+2)); array+=3;}
1040 else if (colors == 4) {lglColor(*array, *(array+1), *(array+2), *(array+3)); array+=4;}
1041 if (normals == 3) {lglNormal(*array, *(array+1), *(array+2)); array+=3;}
1042 if (texcoords == 1) {lglTexCoord(*array); array++;}
1043 else if (texcoords == 2) {lglTexCoord(*array, *(array+1)); array+=2;}
1044 else if (texcoords == 3) {lglTexCoord(*array, *(array+1), *(array+2)); array+=3;}
1045 else if (texcoords == 4) {lglTexCoord(*array, *(array+1), *(array+2), *(array+3)); array+=4;}
1066 hastexcoord_ =
false;
1072 hasattributes_ =
false;
1074 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
1075 hasattribute_[i] =
false;
1083 lglError(
"invalid render operation");
1089 initializeStaticOpenGL();
1090 initStaticGL_ =
true;
1107 if (!checkMatrixStacks())
return;
1111 if (size_ >= cull_minsize_)
1119 origin = mvi *
vec4(origin);
1131 if (vbo->lglCustomProgram())
1139 GLenum usage = GL_NONE;
1141 if (immediate_) usage = GL_STREAM_DRAW;
1142 else usage = GL_STATIC_DRAW;
1146 #if defined(LGL_GL3) || defined(LGL_GLES3)
1149 glBindVertexArray(array_);
1155 if (modified_ || !vao)
1157 glBindBuffer(GL_ARRAY_BUFFER, buffers_[LGL_VERTEX_BUFFER]);
1160 if (storagetype_) glBufferData(GL_ARRAY_BUFFER, size_*
sizeof(VEC4), vertices_, usage);
1161 else glBufferData(GL_ARRAY_BUFFER, size_*
sizeof(
vec4f), verticesf_, usage);
1163 glVertexAttribPointer(LGL_VERTEX_LOCATION, 4, storagetype_?gl_type:GL_FLOAT, GL_FALSE, 0, 0);
1164 glBindBuffer(GL_ARRAY_BUFFER, 0);
1168 glEnableVertexAttribArray(LGL_VERTEX_LOCATION);
1172 if (modified_ || !vao)
1174 glBindBuffer(GL_ARRAY_BUFFER, buffers_[LGL_COLOR_BUFFER]);
1175 if (modified_) glBufferData(GL_ARRAY_BUFFER, size_*
sizeof(
vec4f), colors_, usage);
1176 glVertexAttribPointer(LGL_COLOR_LOCATION, 4, GL_FLOAT, GL_FALSE, 0, 0);
1177 glBindBuffer(GL_ARRAY_BUFFER, 0);
1182 glEnableVertexAttribArray(LGL_COLOR_LOCATION);
1186 if (modified_ || !vao)
1188 glBindBuffer(GL_ARRAY_BUFFER, buffers_[LGL_NORMAL_BUFFER]);
1189 if (modified_) glBufferData(GL_ARRAY_BUFFER, size_*
sizeof(
vec3f), normals_, usage);
1190 glVertexAttribPointer(LGL_NORMAL_LOCATION, 3, GL_FLOAT, GL_FALSE, 0, 0);
1191 glBindBuffer(GL_ARRAY_BUFFER, 0);
1196 glEnableVertexAttribArray(LGL_NORMAL_LOCATION);
1200 if (modified_ || !vao)
1202 glBindBuffer(GL_ARRAY_BUFFER, buffers_[LGL_TEXCOORD_BUFFER]);
1203 if (modified_) glBufferData(GL_ARRAY_BUFFER, size_*
sizeof(
vec4f), texcoords_, usage);
1204 glVertexAttribPointer(LGL_TEXCOORD_LOCATION, 4, GL_FLOAT, GL_FALSE, 0, 0);
1205 glBindBuffer(GL_ARRAY_BUFFER, 0);
1210 glEnableVertexAttribArray(LGL_TEXCOORD_LOCATION);
1213 if (modified_ || !vao)
1215 glBindBuffer(GL_ARRAY_BUFFER, buffers_[LGL_BARYCENTRIC_BUFFER]);
1216 if (modified_) glBufferData(GL_ARRAY_BUFFER, size_*
sizeof(
vec3f), barycentrics_, usage);
1217 glVertexAttribPointer(LGL_BARYCENTRIC_LOCATION, 3, GL_FLOAT, GL_FALSE, 0, 0);
1218 glBindBuffer(GL_ARRAY_BUFFER, 0);
1222 if (polygonmode_==LGL_LINE || polygonmode_==LGL_BARYCENTRIC)
1223 glEnableVertexAttribArray(LGL_BARYCENTRIC_LOCATION);
1228 if (modified_ || !vao)
1230 glBindBuffer(GL_ARRAY_BUFFER, buffers_[LGL_ATTRIBUTE_BUFFER]);
1231 if (modified_) glBufferData(GL_ARRAY_BUFFER, size_*LGL_NUM_ATTRIBUTES*
sizeof(
vec4f), attributes_, usage);
1232 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
1233 if (hasattribute_[i])
1234 glVertexAttribPointer(LGL_ATTRIBUTE_LOCATION+i, 4, GL_FLOAT, GL_FALSE, LGL_NUM_ATTRIBUTES*
sizeof(
vec4f), (
void *)(i*
sizeof(
vec4f)));
1235 glBindBuffer(GL_ARRAY_BUFFER, 0);
1238 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
1239 if (hasattribute_[i])
1240 glEnableVertexAttribArray(LGL_ATTRIBUTE_LOCATION+i);
1246 if (storagetype_) glVertexPointer(4, gl_type, 0, vertices_);
1247 else glVertexPointer(4, GL_FLOAT, 0, verticesf_);
1248 glEnableClientState(GL_VERTEX_ARRAY);
1253 glColorPointer(4, GL_FLOAT, 0, colors_);
1254 glEnableClientState(GL_COLOR_ARRAY);
1257 glColor4f(actual_.r, actual_.g, actual_.b, actual_.a);
1262 glNormalPointer(GL_FLOAT, 0, normals_);
1263 glEnableClientState(GL_NORMAL_ARRAY);
1269 glTexCoordPointer(4, GL_FLOAT, 0, texcoords_);
1270 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1279 glGetIntegerv(GL_CURRENT_PROGRAM, &prev_program);
1283 glUseProgram(program);
1290 vec4f color = actual_;
1297 mat4 mv = modelview_matrix_.back();
1300 if (!model_matrix_identity_)
1301 mv = mv * model_matrix_;
1304 if (manip_matrix_apply_ && !manip_matrix_identity_)
1305 mv = manip_matrix_ * mv;
1308 mat4 mvp = projection_matrix_.back() * mv;
1314 mat4 tm = texture_matrix_.back();
1317 if (!tex_matrix_identity_)
1318 tm = tm * tex_matrix_;
1321 vec4f light = light_;
1324 if (program != usedprogram_)
1326 usedprogram_ = program;
1329 color_loc_ = glGetUniformLocation(program,
"color");
1332 mvp_loc_ = glGetUniformLocation(program,
"mvp");
1336 lglWarning(
"uniform location not found: model-view-projection matrix (mvp)");
1339 mv_loc_ = glGetUniformLocation(program,
"mv");
1340 mvit_loc_ = glGetUniformLocation(program,
"mvit");
1343 tm_loc_ = glGetUniformLocation(program,
"tm");
1350 light_loc_ = glGetUniformLocation(program,
"light");
1353 lglWarning(
"uniform location not found: light");
1355 kaIa_loc_ = glGetUniformLocation(program,
"kaIa");
1358 lglWarning(
"uniform location not found: lighting term (kaIa)");
1360 kdId_loc_ = glGetUniformLocation(program,
"kdId");
1363 lglWarning(
"uniform location not found: lighting term (kdId)");
1365 ksIs_loc_ = glGetUniformLocation(program,
"ksIs");
1368 lglWarning(
"uniform location not found: lighting term (ksIs)");
1370 exponent_loc_ = glGetUniformLocation(program,
"exponent");
1372 if (exponent_loc_ < 0)
1373 lglWarning(
"uniform location not found: lighting term (exponent)");
1375 falloff_loc_ = glGetUniformLocation(program,
"falloff");
1377 if (falloff_loc_ < 0)
1378 lglWarning(
"uniform location not found: lighting term (falloff)");
1383 sampler_loc_ = glGetUniformLocation(program,
"sampler");
1385 if (sampler_loc_ < 0)
1386 lglWarning(
"uniform location not found: sampler");
1389 alphatest_loc_ = glGetUniformLocation(program,
"alphatest");
1391 if (alphatest_loc_ < 0)
1392 lglWarning(
"uniform location not found: alphatest");
1394 clipping_loc_ = glGetUniformLocation(program,
"clipping");
1396 if (clipping_loc_ < 0)
1397 lglWarning(
"uniform location not found: clipping");
1399 clipplane_loc_ = glGetUniformLocation(program,
"clipplane");
1401 if (clipplane_loc_ < 0)
1402 lglWarning(
"uniform location not found: clipplane");
1404 fogdensity_loc_ = glGetUniformLocation(program,
"fogdensity");
1405 fogcolor_loc_ = glGetUniformLocation(program,
"fogcolor");
1407 if (fogdensity_loc_ < 0)
1408 lglWarning(
"uniform location not found: fogdensity");
1410 if (fogcolor_loc_ < 0)
1411 lglWarning(
"uniform location not found: fogcolor");
1413 wireframe_loc_ = glGetUniformLocation(program,
"wireframe");
1415 if (wireframe_loc_ < 0)
1416 lglWarning(
"uniform location not found: wireframe");
1418 interlacing_loc_ = glGetUniformLocation(program,
"interlacing");
1420 if (interlacing_loc_ < 0)
1421 lglWarning(
"uniform location not found: interlacing");
1426 if (color_loc_ >= 0) glUniform4fv(color_loc_, 1, (
const float *)color);
1429 if (mvp_loc_ >= 0) glUniformMatrix4fv(mvp_loc_, 1, GL_FALSE, (
const float *)
mat4f(mvp));
1432 if (mv_loc_ >= 0) glUniformMatrix4fv(mv_loc_, 1, GL_FALSE, (
const float *)
mat4f(mv));
1433 if (mvit_loc_ >= 0) glUniformMatrix4fv(mvit_loc_, 1, GL_FALSE, (
const float *)
mat4f(mvit));
1436 if (tm_loc_ >= 0) glUniformMatrix4fv(tm_loc_, 1, GL_FALSE, (
const float *)
mat4f(tm));
1444 glUniform4fv(light_loc_, 1, (
const float *)light);
1446 glUniform3fv(kaIa_loc_, 1, (
const float *)
vec3f(ka_*Ia_));
1447 glUniform3fv(kdId_loc_, 1, (
const float *)
vec3f(kd_*Id_));
1448 glUniform3fv(ksIs_loc_, 1, (
const float *)
vec3f(ks_*Is_));
1450 glUniform1f(exponent_loc_, exponent_);
1451 glUniform3fv(falloff_loc_, 1, (
const float *)
vec3f(falloff_));
1457 glUniform1i(sampler_loc_, 0);
1461 glBindTexture(GL_TEXTURE_2D, texid2D_);
1463 #if !defined(LGL_GLES) || defined (LGL_GLES3)
1464 else if (texid3D_ != 0)
1466 glBindTexture(GL_TEXTURE_3D, texid3D_);
1472 glUniform3fv(alphatest_loc_, 1, (
const float *)
vec3f(alphatest_));
1475 glUniform1f(clipping_loc_, (clipping_>0)?1.0f:0.0f);
1477 for (
unsigned int i=0; i<LGL_NUM_CLIPPLANES; i++)
1478 glUniform4fv(clipplane_loc_+i, 1, (
const float *)
vec4f(clipplane_[i]));
1481 glUniform1f(fogdensity_loc_, fogdensity_);
1482 glUniform4fv(fogcolor_loc_, 1, (
const float *)
vec4f(fogcolor_));
1485 glUniform1f(wireframe_loc_, (polygonmode_==LGL_LINE)?1.0f:0.0f);
1488 glUniform4fv(interlacing_loc_, 1, (
const float *)
setupStereoMode(interlacing_));
1492 for (
typename lgl_uniform_location_type::const_iterator i = locations_.begin(); i != locations_.end(); i++)
1498 std::string uniform = i->uniform;
1499 loc = glGetUniformLocation(program, uniform.c_str());
1505 lglWarning(
"uniform location not found: " + i->uniform);
1511 case lgl_int_type: glUniform1i(loc, i->value.int_value);
break;
1512 case lgl_float_type: glUniform1f(loc, i->value.float_value);
break;
1513 case lgl_vec2f_type: glUniform2fv(loc, 1, i->value.vec2f_value);
break;
1514 case lgl_vec3f_type: glUniform3fv(loc, 1, i->value.vec3f_value);
break;
1515 case lgl_vec4f_type: glUniform4fv(loc, 1, i->value.vec4f_value);
break;
1516 case lgl_mat2f_type: glUniformMatrix2fv(loc, 1, GL_FALSE, i->value.mat2f_value);
break;
1517 case lgl_mat3f_type: glUniformMatrix3fv(loc, 1, GL_FALSE, i->value.mat3f_value);
break;
1518 case lgl_mat4f_type: glUniformMatrix4fv(loc, 1, GL_FALSE, i->value.mat4f_value);
break;
1519 case lgl_no_type:
if (i->warn)
lglWarning(
"using undefined uniform: " + i->uniform);
break;
1527 vec4f light = light_;
1530 glMatrixMode(GL_PROJECTION);
1531 glLoadMatrixf((
const float *)
mat4f(projection_matrix_.back()));
1534 glMatrixMode(GL_MODELVIEW);
1536 glLightfv(GL_LIGHT0, GL_POSITION, (
const float *)light);
1538 for (
unsigned int i=0; i<LGL_NUM_CLIPPLANES; i++)
1540 GLdouble clipplane[4] = {clipplane_[i].x, clipplane_[i].y, clipplane_[i].z, clipplane_[i].w};
1541 glClipPlane(GL_CLIP_PLANE0+i, clipplane);
1543 if (model_matrix_identity_)
1544 if (!manip_matrix_apply_ || manip_matrix_identity_)
1545 glLoadMatrixf((
const float *)
mat4f(modelview_matrix_.back()));
1547 glLoadMatrixf((
const float *)
mat4f(manip_matrix_ * modelview_matrix_.back()));
1549 if (!manip_matrix_apply_ || manip_matrix_identity_)
1550 glLoadMatrixf((
const float *)
mat4f(modelview_matrix_.back() * model_matrix_));
1552 glLoadMatrixf((
const float *)
mat4f(manip_matrix_ * modelview_matrix_.back() * model_matrix_));
1555 glMatrixMode(GL_TEXTURE);
1556 if (tex_matrix_identity_)
1557 glLoadMatrixf((
const float *)
mat4f(texture_matrix_.back()));
1559 glLoadMatrixf((
const float *)
mat4f(texture_matrix_.back() * tex_matrix_));
1560 glMatrixMode(GL_MODELVIEW);
1565 glLightfv(GL_LIGHT0, GL_AMBIENT, (
const float *)
vec4f(ka_*Ia_));
1566 glLightfv(GL_LIGHT0, GL_DIFFUSE, (
const float *)
vec4f(kd_*Id_));
1567 glLightfv(GL_LIGHT0, GL_SPECULAR, (
const float *)
vec4f(ks_*Is_));
1568 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, falloff_.x);
1569 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, falloff_.y);
1570 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, falloff_.z);
1571 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (
const float *)
vec4f(1));
1572 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, exponent_);
1573 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
1575 glEnable(GL_COLOR_MATERIAL);
1576 glEnable(GL_LIGHT0);
1577 glEnable(GL_LIGHTING);
1579 glEnable(GL_NORMALIZE);
1587 glBindTexture(GL_TEXTURE_2D, texid2D_);
1588 glEnable(GL_TEXTURE_2D);
1590 else if (texid3D_ != 0)
1592 glBindTexture(GL_TEXTURE_3D, texid3D_);
1593 glEnable(GL_TEXTURE_3D);
1596 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1601 for (
unsigned int i=0; i<LGL_NUM_CLIPPLANES; i++)
1602 if (clipplane_[i] !=
vec4(0,0,0,0))
1603 glEnable(GL_CLIP_PLANE0+i);
1606 if (fogdensity_ > 0.0f)
1610 color[0] = fogcolor_.r;
1611 color[1] = fogcolor_.g;
1612 color[2] = fogcolor_.b;
1613 color[3] = fogcolor_.a;
1615 glFogfv(GL_FOG_COLOR, color);
1616 glFogi(GL_FOG_MODE, GL_EXP2);
1617 glFogf(GL_FOG_DENSITY, fogdensity_);
1623 if (polygonmode_ == LGL_LINE)
1624 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1635 case LGL_LINES: p = GL_LINES;
break;
1636 case LGL_LINE_STRIP: p = GL_LINE_STRIP;
break;
1637 case LGL_TRIANGLES: p = GL_TRIANGLES;
break;
1638 case LGL_TRIANGLE_STRIP: p = GL_TRIANGLE_STRIP;
break;
1639 case LGL_TRIANGLE_FAN: p = GL_TRIANGLE_FAN;
break;
1640 #if (LGL_OPENGL_VERSION < 31) && !defined(LGL_GLES)
1641 case LGL_QUADS: p = GL_QUADS;
break;
1642 case LGL_QUAD_STRIP: p = GL_QUAD_STRIP;
break;
1649 glDrawArrays(p, 0, size_);
1657 glUseProgram(prev_program);
1665 glBindTexture(GL_TEXTURE_2D, 0);
1666 glDisable(GL_TEXTURE_2D);
1668 #if !defined(LGL_GLES) || defined(LGL_GLES3)
1669 else if (texid3D_ != 0)
1671 glBindTexture(GL_TEXTURE_3D, 0);
1672 glDisable(GL_TEXTURE_3D);
1682 glDisable(GL_COLOR_MATERIAL);
1683 glDisable(GL_LIGHT0);
1684 glDisable(GL_LIGHTING);
1685 glDisable(GL_NORMALIZE);
1693 glBindTexture(GL_TEXTURE_2D, 0);
1694 glDisable(GL_TEXTURE_2D);
1696 else if (texid3D_ != 0)
1698 glBindTexture(GL_TEXTURE_3D, 0);
1699 glDisable(GL_TEXTURE_3D);
1705 for (
unsigned int i=0; i<LGL_NUM_CLIPPLANES; i++)
1706 if (clipplane_[i] !=
vec4(0,0,0,0))
1707 glDisable(GL_CLIP_PLANE0+i);
1710 if (fogdensity_ > 0.0f)
1714 if (polygonmode_ == LGL_LINE)
1715 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1722 glDisableVertexAttribArray(LGL_VERTEX_LOCATION);
1726 glDisableVertexAttribArray(LGL_COLOR_LOCATION);
1730 glDisableVertexAttribArray(LGL_NORMAL_LOCATION);
1734 glDisableVertexAttribArray(LGL_TEXCOORD_LOCATION);
1737 if (polygonmode_==LGL_LINE || polygonmode_==LGL_BARYCENTRIC)
1738 glDisableVertexAttribArray(LGL_BARYCENTRIC_LOCATION);
1742 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
1743 if (hasattribute_[i])
1744 glDisableVertexAttribArray(LGL_ATTRIBUTE_LOCATION+i);
1746 #if defined(LGL_GL3) || defined(LGL_GLES3)
1749 glBindVertexArray(0);
1756 glDisableClientState(GL_VERTEX_ARRAY);
1760 glDisableClientState(GL_COLOR_ARRAY);
1764 glDisableClientState(GL_NORMAL_ARRAY);
1768 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1798 return(primitives_);
1821 return(0.5*(bboxmin_+bboxmax_));
1827 return(bboxmax_-bboxmin_);
1834 if (bboxmin_.x <= bboxmax_.x &&
1835 bboxmin_.y <= bboxmax_.y &&
1836 bboxmin_.z <= bboxmax_.z)
1837 return((0.5*(bboxmax_-bboxmin_)).
length());
1846 if (bboxmin_.x <= bboxmax_.x &&
1847 bboxmin_.y <= bboxmax_.y &&
1848 bboxmin_.z <= bboxmax_.z)
1849 return((0.5*(bboxmax_-bboxmin_)).
norm());
1858 if (bboxmin_.x <= bboxmax_.x &&
1859 bboxmin_.y <= bboxmax_.y &&
1860 bboxmin_.z <= bboxmax_.z)
1862 vec3 ext = bboxmax_-bboxmin_;
1863 double maxext = ext.x;
1864 if (ext.y > maxext) maxext = ext.y;
1865 if (ext.z > maxext) maxext = ext.z;
1876 if (bboxmin_.x <= bboxmax_.x &&
1877 bboxmin_.y <= bboxmax_.y &&
1878 bboxmin_.z <= bboxmax_.z)
1880 double maxabs = bboxmax_.x;
1881 if (bboxmax_.y > maxabs) maxabs = bboxmax_.y;
1882 if (bboxmax_.z > maxabs) maxabs = bboxmax_.z;
1883 if (-bboxmin_.x > maxabs) maxabs = -bboxmin_.x;
1884 if (-bboxmin_.y > maxabs) maxabs = -bboxmin_.y;
1885 if (-bboxmin_.z > maxabs) maxabs = -bboxmin_.z;
1895 std::vector<vec4> vertices;
1896 for (
int i=0; i<size_; i++) vertices.push_back(vertices_[i]);
1903 std::vector<vec4f> colors;
1905 for (
int i=0; i<size_; i++) colors.push_back(colors_[i]);
1912 std::vector<vec3f> normals;
1914 for (
int i=0; i<size_; i++) normals.push_back(normals_[i]);
1921 std::vector<vec4f> texcoords;
1923 for (
int i=0; i<size_; i++) texcoords.push_back(texcoords_[i]);
1930 if (size_ == 0)
return;
1932 if (hascolor_) vbo->hascolor_ =
true;
1934 if (vbo->size_ == 0)
1936 vbo->primitive_ = primitive_;
1937 if (hasnormal_) vbo->hasnormal_ =
true;
1938 if (hastexcoord_) vbo->hastexcoord_ =
true;
1939 vbo->primitives_ = primitives_;
1943 if (primitive_ == LGL_LINE_STRIP ||
1944 primitive_ == LGL_TRIANGLE_FAN)
1946 lglError(
"invalid primitive type");
1950 if (primitive_ != vbo->primitive_ ||
1951 hasnormal_ != vbo->hasnormal_ ||
1952 hastexcoord_ != vbo->hastexcoord_ ||
1953 hasattributes_ || vbo->hasattributes_)
1955 lglError(
"unmatched primitive type");
1959 if (primitive_==LGL_TRIANGLE_STRIP || primitive_==LGL_QUAD_STRIP)
1961 vbo->lglPlainVertex(vbo->vertices_[vbo->size_-1]);
1962 if (primitive_ == LGL_QUAD_STRIP)
1964 vbo->lglPlainVertex(vbo->vertices_[vbo->size_-1]);
1965 vbo->lglPlainVertex(vertices_[0]);
1967 vbo->lglPlainVertex(vertices_[0]);
1970 vbo->primitives_ += primitives_;
1973 for (
int i=0; i<size_; i++)
1974 vbo->lglPlainVertex(vertices_[i],
1975 hascolor_?colors_[i]:
vec4f(1),
1976 hastexcoord_?texcoords_[i]:
vec4f(0),
1977 hasnormal_?normals_[i]:
vec3f(0));
1989 return(matrixmode_);
1995 if (!checkVertexScope())
return;
1996 if (!checkMatrixStacks())
return;
1998 if (matrixmode_ == LGL_MODELVIEW)
1999 modelview_matrix_.back() =
mat4(1);
2000 else if (matrixmode_ == LGL_PREMODEL)
2002 premodel_matrix_.back() =
mat4(1);
2003 premodel_matrix_identity_.back() =
true;
2004 premodel_matrix_it_.back() =
mat3(1);
2005 premodel_matrix_recompute_.back() =
false;
2007 else if (matrixmode_ == LGL_PROJECTION)
2008 projection_matrix_.back() =
mat4(1);
2009 else if (matrixmode_ == LGL_TEXTURE)
2010 texture_matrix_.back() =
mat4(1);
2013 pretex_matrix_.back() =
mat4(1);
2014 pretex_matrix_identity_.back() =
true;
2021 if (!checkVertexScope())
return;
2022 if (!checkMatrixStacks())
return;
2024 if (matrixmode_ == LGL_MODELVIEW)
2025 modelview_matrix_.back() = matrix;
2026 else if (matrixmode_ == LGL_PREMODEL)
2028 premodel_matrix_.back() = matrix;
2029 premodel_matrix_identity_.back() =
false;
2030 premodel_matrix_recompute_.back() =
true;
2032 else if (matrixmode_ == LGL_PROJECTION)
2033 projection_matrix_.back() = matrix;
2034 else if (matrixmode_ == LGL_TEXTURE)
2035 texture_matrix_.back() = matrix;
2038 pretex_matrix_.back() = matrix;
2039 pretex_matrix_identity_.back() =
false;
2046 if (!checkVertexScope())
return;
2047 if (!checkMatrixStacks())
return;
2049 if (matrixmode_ == LGL_MODELVIEW)
2050 modelview_matrix_.back() = modelview_matrix_.back() * matrix;
2051 else if (matrixmode_ == LGL_PREMODEL)
2053 premodel_matrix_.back() = premodel_matrix_.back() * matrix;
2054 premodel_matrix_identity_.back() =
false;
2055 premodel_matrix_recompute_.back() =
true;
2057 else if (matrixmode_ == LGL_PROJECTION)
2058 projection_matrix_.back() = projection_matrix_.back() * matrix;
2059 else if (matrixmode_ == LGL_TEXTURE)
2060 texture_matrix_.back() = texture_matrix_.back() * matrix;
2063 pretex_matrix_.back() = pretex_matrix_.back() * matrix;
2064 pretex_matrix_identity_.back() =
false;
2071 if (!checkVertexScope())
return;
2072 if (!checkMatrixStacks())
return;
2074 if (matrixmode_ == LGL_MODELVIEW)
2075 modelview_matrix_.push_back(modelview_matrix_.back());
2076 else if (matrixmode_ == LGL_PREMODEL)
2078 premodel_matrix_.push_back(premodel_matrix_.back());
2079 premodel_matrix_identity_.push_back(premodel_matrix_identity_.back());
2080 premodel_matrix_it_.push_back(premodel_matrix_it_.back());
2081 premodel_matrix_recompute_.push_back(premodel_matrix_recompute_.back());
2083 else if (matrixmode_ == LGL_PROJECTION)
2084 projection_matrix_.push_back(projection_matrix_.back());
2085 else if (matrixmode_ == LGL_TEXTURE)
2086 texture_matrix_.push_back(texture_matrix_.back());
2089 pretex_matrix_.push_back(pretex_matrix_.back());
2090 pretex_matrix_identity_.push_back(pretex_matrix_identity_.back());
2097 if (!checkVertexScope())
return;
2098 if (!checkMatrixStacks())
return;
2100 if (matrixmode_ == LGL_MODELVIEW)
2101 modelview_matrix_.pop_back();
2102 else if (matrixmode_ == LGL_PREMODEL)
2104 premodel_matrix_.pop_back();
2105 premodel_matrix_identity_.pop_back();
2106 premodel_matrix_it_.pop_back();
2107 premodel_matrix_recompute_.pop_back();
2109 else if (matrixmode_ == LGL_PROJECTION)
2110 projection_matrix_.pop_back();
2111 else if (matrixmode_ == LGL_TEXTURE)
2112 texture_matrix_.pop_back();
2115 pretex_matrix_.pop_back();
2116 pretex_matrix_identity_.pop_back();
2119 checkMatrixStacks();
2125 if (!checkMatrixStacks())
return(
mat4(1));
2127 if (matrixmode_ == LGL_MODELVIEW)
2128 return(modelview_matrix_.back());
2129 else if (matrixmode_ == LGL_PREMODEL)
2130 return(premodel_matrix_.back());
2131 else if (matrixmode_ == LGL_PROJECTION)
2132 return(projection_matrix_.back());
2133 else if (matrixmode_ == LGL_TEXTURE)
2134 return(texture_matrix_.back());
2136 return(pretex_matrix_.back());
2142 if (!checkMatrixStacks())
return(
mat4(1));
2145 mat4 p = projection_matrix_.back();
2153 if (!checkMatrixStacks())
return(
mat4(1));
2156 mat4 mv = modelview_matrix_.back();
2159 if (!model_matrix_identity_)
2160 mv = mv * model_matrix_;
2163 if (manip_matrix_apply_ && !manip_matrix_identity_)
2164 mv = manip_matrix_ * mv;
2193 if (!checkMatrixStacks())
return(
mat4(1));
2196 mat4 tm = texture_matrix_.back();
2204 if (c !=
vec4(1,1,1,1))
2209 void lglScale(
double s,
double t,
double r,
double w = 1)
2223 if (v !=
vec4(0,0,0,0))
2241 void lglRotate(
double angle,
double vx,
double vy,
double vz)
2265 void lglOrtho(
double left,
double right,
double bottom,
double top,
double nearp = -1,
double farp = 1)
2271 void lglFrustum(
double left,
double right,
double bottom,
double top,
double nearp,
double farp)
2329 double at_x,
double at_y,
double at_z,
2330 double up_x = 0,
double up_y = 1,
double up_z = 0)
2357 matrixmode_ = LGL_PROJECTION;
2366 matrixmode_ = LGL_PROJECTION;
2372 void lglProjection(
double left,
double right,
double bottom,
double top,
double nearp,
double farp)
2392 matrixmode_ = LGL_MODELVIEW;
2401 matrixmode_ = LGL_MODELVIEW;
2417 void lglView(
double eye_x,
double eye_y,
double eye_z,
2418 double at_x,
double at_y,
double at_z,
2419 double up_x = 0,
double up_y = 1,
double up_z = 0)
2428 matrixmode_ = LGL_TEXTURE;
2437 matrixmode_ = LGL_TEXTURE;
2445 manip_matrix_apply_ = on;
2451 manip_matrix_ = manip * manip_matrix_;
2452 manip_matrix_identity_ =
false;
2453 manip_matrix_apply_ =
true;
2457 static void lglManip(
double focus,
double angle,
double tilt,
double zoom)
2465 static void lglManip(
double dx,
double dy,
double zoom = 1)
2467 double fovy = fovy_;
2468 double aspect = aspect_;
2470 if (fovy == 0) fovy_ = 360;
2471 if (aspect == 0) aspect_ = 1;
2475 if (eye_==at_ || up_==
vec3(0))
2479 manip_matrix_apply_ =
false;
2483 double focus = (at_-eye_).
length();
2501 manip_matrix_ =
mat4(1);
2502 manip_matrix_identity_ =
true;
2503 manip_matrix_apply_ =
false;
2509 return(manip_matrix_);
2515 return(manip_matrix_apply_);
2527 model_matrix_ =
mat4(1);
2528 model_matrix_identity_ =
true;
2534 model_matrix_ = model;
2535 model_matrix_identity_ =
false;
2541 return(model_matrix_);
2564 for (
int i=0; i<size_; i++)
2566 if (hasnormal_) normals_[i] = mit * normals_[i];
2567 vertices_[i] = m * vertices_[i];
2579 tex_matrix_ =
mat4(1);
2580 tex_matrix_identity_ =
true;
2587 tex_matrix_identity_ =
false;
2599 return(tex_matrix_);
2615 for (
int i=0; i<size_; i++)
2616 if (hastexcoord_) texcoords_[i] = m * texcoords_[i];
2638 for (
int i=0; i<size_; i++)
2662 const GLubyte *version = glGetString(GL_SHADING_LANGUAGE_VERSION);
2663 return((
const char *)version);
2675 return(std::string(lgl_plain_vertex_shader_header)+
2676 lgl_plain_vertex_shader);
2682 return(std::string(lgl_plain_fragment_shader_header)+
2683 lgl_plain_fragment_shader);
2698 return(std::string(lgl_default_vertex_shader_header)+
2699 lgl_default_vertex_shader_clipping+
2700 lgl_default_vertex_shader1);
2702 return(std::string(lgl_default_vertex_shader_header)+
2703 lgl_default_vertex_shader_clipping+
2704 lgl_default_vertex_shader2);
2707 return(std::string(lgl_default_vertex_shader_header)+
2708 lgl_default_vertex_shader_lighting+
2709 lgl_default_vertex_shader_clipping+
2710 lgl_default_vertex_shader3);
2712 return(std::string(lgl_default_vertex_shader_header)+
2713 lgl_default_vertex_shader_lighting+
2714 lgl_default_vertex_shader_clipping+
2715 lgl_default_vertex_shader4);
2719 return(std::string(lgl_default_vertex_shader_header)+
2720 lgl_default_vertex_shader_clipping+
2721 lgl_default_vertex_shader5);
2723 return(std::string(lgl_default_vertex_shader_header)+
2724 lgl_default_vertex_shader_clipping+
2725 lgl_default_vertex_shader6);
2728 return(std::string(lgl_default_vertex_shader_header)+
2729 lgl_default_vertex_shader_lighting+
2730 lgl_default_vertex_shader_clipping+
2731 lgl_default_vertex_shader7);
2733 return(std::string(lgl_default_vertex_shader_header)+
2734 lgl_default_vertex_shader_lighting+
2735 lgl_default_vertex_shader_clipping+
2736 lgl_default_vertex_shader8);
2745 return(std::string(lgl_default_fragment_shader_header)+
2746 lgl_default_fragment_shader_alphatesting+
2747 lgl_default_fragment_shader_clipping+
2748 lgl_default_fragment_shader_interlacing+
2749 lgl_default_fragment_shader1);
2751 return(std::string(lgl_default_fragment_shader_header)+
2752 lgl_default_fragment_shader_alphatesting+
2753 lgl_default_fragment_shader_clipping+
2754 lgl_default_fragment_shader_interlacing+
2755 lgl_default_fragment_shader2);
2758 return(std::string(lgl_default_fragment_shader_header)+
2759 lgl_default_fragment_shader_lighting+
2760 lgl_default_fragment_shader_alphatesting+
2761 lgl_default_fragment_shader_clipping+
2762 lgl_default_fragment_shader_interlacing+
2763 lgl_default_fragment_shader3);
2765 return(std::string(lgl_default_fragment_shader_header)+
2766 lgl_default_fragment_shader_lighting+
2767 lgl_default_fragment_shader_alphatesting+
2768 lgl_default_fragment_shader_clipping+
2769 lgl_default_fragment_shader_interlacing+
2770 lgl_default_fragment_shader4);
2775 return(std::string(lgl_default_fragment_shader_header)+
2776 lgl_default_fragment_shader_alphatesting+
2777 lgl_default_fragment_shader_clipping+
2778 lgl_default_fragment_shader_interlacing+
2779 lgl_default_fragment_shader5_2D);
2781 return(std::string(lgl_default_fragment_shader_header)+
2782 lgl_default_fragment_shader_alphatesting+
2783 lgl_default_fragment_shader_clipping+
2784 lgl_default_fragment_shader_interlacing+
2785 lgl_default_fragment_shader6_2D);
2788 return(std::string(lgl_default_fragment_shader_header)+
2789 lgl_default_fragment_shader_lighting+
2790 lgl_default_fragment_shader_alphatesting+
2791 lgl_default_fragment_shader_clipping+
2792 lgl_default_fragment_shader_interlacing+
2793 lgl_default_fragment_shader7_2D);
2795 return(std::string(lgl_default_fragment_shader_header)+
2796 lgl_default_fragment_shader_lighting+
2797 lgl_default_fragment_shader_alphatesting+
2798 lgl_default_fragment_shader_clipping+
2799 lgl_default_fragment_shader_interlacing+
2800 lgl_default_fragment_shader8_2D);
2804 return(std::string(lgl_default_fragment_shader_header)+
2805 lgl_default_fragment_shader_alphatesting+
2806 lgl_default_fragment_shader_clipping+
2807 lgl_default_fragment_shader_interlacing+
2808 lgl_default_fragment_shader5_3D);
2810 return(std::string(lgl_default_fragment_shader_header)+
2811 lgl_default_fragment_shader_alphatesting+
2812 lgl_default_fragment_shader_clipping+
2813 lgl_default_fragment_shader_interlacing+
2814 lgl_default_fragment_shader6_3D);
2817 return(std::string(lgl_default_fragment_shader_header)+
2818 lgl_default_fragment_shader_lighting+
2819 lgl_default_fragment_shader_alphatesting+
2820 lgl_default_fragment_shader_clipping+
2821 lgl_default_fragment_shader_interlacing+
2822 lgl_default_fragment_shader7_3D);
2824 return(std::string(lgl_default_fragment_shader_header)+
2825 lgl_default_fragment_shader_lighting+
2826 lgl_default_fragment_shader_alphatesting+
2827 lgl_default_fragment_shader_clipping+
2828 lgl_default_fragment_shader_interlacing+
2829 lgl_default_fragment_shader8_3D);
2834 static void tweakShader(std::string &shader)
2855 tweakShader(shader);
2857 GLint
length = shader.size();
2858 GLuint shader_id = glCreateShader(GL_VERTEX_SHADER);
2860 const char *source = shader.c_str();
2861 glShaderSource(shader_id, 1, &source, &
length);
2862 glCompileShader(shader_id);
2865 glGetShaderiv(shader_id, GL_COMPILE_STATUS, &status);
2867 if (status == GL_FALSE)
2870 glGetShaderiv(shader_id, GL_INFO_LOG_LENGTH, &infolength);
2871 char *info =
new char[infolength+1];
2872 glGetShaderInfoLog(shader_id, infolength, NULL, info);
2875 lglError(
"GLSL vertex shader errors: " + std::string(info));
2878 glDeleteShader(shader_id);
2886 lglError(
"vertex programs unsupported");
2901 tweakShader(shader);
2903 GLint
length = shader.size();
2904 GLuint shader_id = glCreateShader(GL_FRAGMENT_SHADER);
2906 const char *source = shader.c_str();
2907 glShaderSource(shader_id, 1, &source, &
length);
2908 glCompileShader(shader_id);
2911 glGetShaderiv(shader_id, GL_COMPILE_STATUS, &status);
2913 if (status == GL_FALSE)
2916 glGetShaderiv(shader_id, GL_INFO_LOG_LENGTH, &infolength);
2917 char *info =
new char[infolength+1];
2918 glGetShaderInfoLog(shader_id, infolength, NULL, info);
2921 lglError(
"GLSL fragment shader errors: " + std::string(info));
2924 glDeleteShader(shader_id);
2932 lglError(
"fragment programs unsupported");
2939 static GLuint
lglLinkGLSLProgram(GLuint vertex_shader_id, GLuint fragment_shader_id, GLuint custom_shader_program = 0)
2947 GLuint shader_program = custom_shader_program;
2949 if (vertex_shader_id!=0 && fragment_shader_id!=0)
2951 if (shader_program == 0)
2953 shader_program = glCreateProgram();
2955 glBindAttribLocation(shader_program, LGL_VERTEX_LOCATION,
"vertex_position");
2956 glBindAttribLocation(shader_program, LGL_COLOR_LOCATION,
"vertex_color");
2957 glBindAttribLocation(shader_program, LGL_NORMAL_LOCATION,
"vertex_normal");
2958 glBindAttribLocation(shader_program, LGL_TEXCOORD_LOCATION,
"vertex_texcoord");
2959 glBindAttribLocation(shader_program, LGL_BARYCENTRIC_LOCATION,
"vertex_barycentric");
2962 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
2964 std::ostringstream vertex_attribute;
2965 vertex_attribute <<
"vertex_attribute" << i;
2967 glBindAttribLocation(shader_program, LGL_ATTRIBUTE_LOCATION+i, vertex_attribute.str().c_str());
2970 glAttachShader(shader_program, vertex_shader_id);
2971 glAttachShader(shader_program, fragment_shader_id);
2973 glLinkProgram(shader_program);
2976 glGetProgramiv(shader_program, GL_LINK_STATUS, &status);
2978 if (status == GL_FALSE)
2981 glGetProgramiv(shader_program, GL_INFO_LOG_LENGTH, &infolength);
2982 char *info =
new char[infolength+1];
2983 glGetProgramInfoLog(shader_program, infolength, NULL, info);
2984 lglError(
"GLSL linker errors: " + std::string(info));
2987 glDeleteProgram(shader_program);
2992 glDetachShader(shader_program, vertex_shader_id);
2993 glDetachShader(shader_program, fragment_shader_id);
2997 return(shader_program);
3013 if (vertex_shader_id != 0)
3017 if (fragment_shader_id != 0)
3024 return(shader_program);
3046 std::string vertex_shader = lglReadTextFile(vertex_shader_file);
3047 std::string fragment_shader = lglReadTextFile(fragment_shader_file);
3049 if (!vertex_shader.empty() && !fragment_shader.empty())
3052 lglError(
"unable to load shader file");
3066 return(vertex_shader+
"---\n"+fragment_shader);
3071 std::string &vertex_shader, std::string &fragment_shader)
3073 size_t pos = shader.find(
"---");
3075 if (pos < shader.size())
3079 while (shader[pos1]==
'-' && pos1>0) pos1--;
3081 while ((shader[pos1]==
' ' || shader[pos1]==
'\t' ||
3082 shader[pos1]==
'\n' || shader[pos1]==
'\r') && pos1>0) pos1--;
3084 vertex_shader = shader.substr(0, pos1+1);
3086 if (vertex_shader.size() == 0)
3089 vertex_shader +=
"\n";
3093 while (shader[pos2]==
'-' && pos2+1<shader.size()) pos2++;
3095 while ((shader[pos2]==
' ' || shader[pos2]==
'\t' ||
3096 shader[pos2]==
'\n' || shader[pos2]==
'\r') && pos2+1<shader.size()) pos2++;
3098 fragment_shader = shader.substr(pos2);
3100 if (fragment_shader.size() == 0)
3103 fragment_shader +=
"\n";
3114 std::string vertex_shader;
3115 std::string fragment_shader;
3133 std::string shader = lglReadTextFile(shader_file);
3155 glDeleteShader(shader_id);
3170 glDeleteProgram(program);
3185 if (program != program_)
3228 if (colors) num |= 1;
3229 if (normals) num |= 2;
3230 if (texcoords) num |= 4;
3232 if (texcoords && tex3D) num += 4;
3234 custom_programs_[num] = program;
3273 if (program_>0 && polygonmode_!=LGL_LINE)
3300 if (custom_programs_[num] != 0)
3301 program = custom_programs_[num];
3303 program = programs_[num];
3318 return(hascolor_ && coloring_ && !disable_coloring_);
3324 return(hascolor_ && coloring_ && !disable_coloring_ && applied_);
3330 return(hasnormal_ && lighting_ && !disable_lighting_);
3336 if (!hastexcoord_ || !texturing_ || disable_texturing_)
3346 if (texid2D_!=0 || texid3D_!=0)
3355 if (on != coloring_)
3376 if (on != lighting_)
3397 if (on != texturing_)
3418 disable_coloring_ = off;
3424 disable_lighting_ = off;
3430 disable_texturing_ = off;
3438 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3440 if (i == uniforms_.end())
3442 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3444 lgl_uniform_struct u = {-1, uniform, lgl_no_type, {0}, warn};
3445 locations_.resize(locations_.size()+1, u);
3458 unsigned int lglUniformi(std::string uniform,
int value,
bool warn =
true)
3462 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3464 if (i == uniforms_.end())
3466 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3468 lgl_uniform_struct u = {-1, uniform, lgl_int_type, {0}, warn};
3469 locations_.resize(locations_.size()+1, u);
3488 if (index < locations_.size())
3490 if (locations_[index].type == lgl_no_type)
3492 locations_[index].type = lgl_int_type;
3493 locations_[index].value.int_value = value;
3495 else if (locations_[index].type == lgl_int_type)
3496 locations_[index].value.int_value = value;
3507 unsigned int lglUniformf(std::string uniform,
double value,
bool warn =
true)
3511 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3513 if (i == uniforms_.end())
3515 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3517 lgl_uniform_struct u = {-1, uniform, lgl_float_type, {0}, warn};
3518 locations_.resize(locations_.size()+1, u);
3537 if (index < locations_.size())
3539 if (locations_[index].type == lgl_no_type)
3541 locations_[index].type = lgl_float_type;
3542 locations_[index].value.float_value = float(value);
3544 else if (locations_[index].type == lgl_float_type)
3545 locations_[index].value.float_value = float(value);
3560 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3562 if (i == uniforms_.end())
3564 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3566 lgl_uniform_struct u = {-1, uniform, lgl_vec2f_type, {0}, warn};
3567 locations_.resize(locations_.size()+1, u);
3582 unsigned int lglUniform2fv(std::string uniform,
const float value[2],
bool warn =
true)
3592 if (index < locations_.size())
3594 if (locations_[index].type == lgl_no_type)
3596 locations_[index].type = lgl_vec2f_type;
3597 for (
int n=0; n<2; n++)
3598 locations_[index].value.vec2f_value[n] = ((
const float *)value)[n];
3600 else if (locations_[index].type == lgl_vec2f_type)
3601 for (
int n=0; n<2; n++)
3602 locations_[index].value.vec2f_value[n] = ((
const float *)value)[n];
3612 unsigned int lglUniformfv(std::string uniform,
const vec2 &value,
bool warn =
true)
3623 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3625 if (i == uniforms_.end())
3627 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3629 lgl_uniform_struct u = {-1, uniform, lgl_vec3f_type, {0}, warn};
3630 locations_.resize(locations_.size()+1, u);
3645 unsigned int lglUniform3fv(std::string uniform,
const float value[3],
bool warn =
true)
3655 if (index < locations_.size())
3657 if (locations_[index].type == lgl_no_type)
3659 locations_[index].type = lgl_vec3f_type;
3660 for (
int n=0; n<3; n++)
3661 locations_[index].value.vec3f_value[n] = ((
const float *)value)[n];
3663 else if (locations_[index].type == lgl_vec3f_type)
3664 for (
int n=0; n<3; n++)
3665 locations_[index].value.vec3f_value[n] = ((
const float *)value)[n];
3675 unsigned int lglUniformfv(std::string uniform,
const vec3 &value,
bool warn =
true)
3686 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3688 if (i == uniforms_.end())
3690 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3692 lgl_uniform_struct u = {-1, uniform, lgl_vec4f_type, {0}, warn};
3693 locations_.resize(locations_.size()+1, u);
3708 unsigned int lglUniform4fv(std::string uniform,
const float value[4],
bool warn =
true)
3710 return(
lglUniformfv(uniform,
vec4f(value[0], value[1], value[2], value[3]), warn));
3718 if (index < locations_.size())
3720 if (locations_[index].type == lgl_no_type)
3722 locations_[index].type = lgl_vec4f_type;
3723 for (
int n=0; n<4; n++)
3724 locations_[index].value.vec4f_value[n] = ((
const float *)value)[n];
3726 else if (locations_[index].type == lgl_vec4f_type)
3727 for (
int n=0; n<4; n++)
3728 locations_[index].value.vec4f_value[n] = ((
const float *)value)[n];
3738 unsigned int lglUniformfv(std::string uniform,
const vec4 &value,
bool warn =
true)
3744 unsigned int lglUniformf(std::string uniform,
double x,
double y,
double z,
double w = 1,
bool warn =
true)
3747 void lglUniformf(
unsigned int index,
double x,
double y,
double z,
double w = 1,
bool warn =
true)
3755 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3757 if (i == uniforms_.end())
3759 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3761 lgl_uniform_struct u = {-1, uniform, lgl_mat2f_type, {0}, warn};
3762 locations_.resize(locations_.size()+1, u);
3789 if (index < locations_.size())
3791 if (locations_[index].type == lgl_no_type)
3793 locations_[index].type = lgl_mat2f_type;
3794 for (
int n=0; n<4; n++)
3795 locations_[index].value.mat2f_value[n] = ((
const float *)value)[n];
3797 else if (locations_[index].type == lgl_mat2f_type)
3798 for (
int n=0; n<4; n++)
3799 locations_[index].value.mat2f_value[n] = ((
const float *)value)[n];
3809 unsigned int lglUniformfv(std::string uniform,
const mat2 &value,
bool warn =
true)
3820 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3822 if (i == uniforms_.end())
3824 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3826 lgl_uniform_struct u = {-1, uniform, lgl_mat3f_type, {0}, warn};
3827 locations_.resize(locations_.size()+1, u);
3854 if (index < locations_.size())
3856 if (locations_[index].type == lgl_no_type)
3858 locations_[index].type = lgl_mat3f_type;
3859 for (
int n=0; n<9; n++)
3860 locations_[index].value.mat3f_value[n] = ((
const float *)value)[n];
3862 else if (locations_[index].type == lgl_mat3f_type)
3863 for (
int n=0; n<9; n++)
3864 locations_[index].value.mat3f_value[n] = ((
const float *)value)[n];
3874 unsigned int lglUniformfv(std::string uniform,
const mat3 &value,
bool warn =
true)
3885 lgl_uniform_map_type::iterator i = uniforms_.find(uniform);
3887 if (i == uniforms_.end())
3889 i = uniforms_.insert(std::pair<std::string, unsigned int>(uniform, locations_.size())).first;
3891 lgl_uniform_struct u = {-1, uniform, lgl_mat4f_type, {0}, warn};
3892 locations_.resize(locations_.size()+1, u);
3919 if (index < locations_.size())
3921 if (locations_[index].type == lgl_no_type)
3923 locations_[index].type = lgl_mat4f_type;
3924 for (
int n=0; n<16; n++)
3925 locations_[index].value.mat4f_value[n] = ((
const float *)value)[n];
3927 else if (locations_[index].type == lgl_mat4f_type)
3928 for (
int n=0; n<16; n++)
3929 locations_[index].value.mat4f_value[n] = ((
const float *)value)[n];
3939 unsigned int lglUniformfv(std::string uniform,
const mat4 &value,
bool warn =
true)
3946 unsigned int lglSampler(std::string sampler,
int value = 0,
bool warn =
true)
3952 void lglSampler(
unsigned int index,
int value = 0,
bool warn =
true)
3958 unsigned int lglSampler2D(std::string sampler, GLuint texid2D,
int value = 0,
bool warn =
true)
3964 unsigned int index =
lglUniformi(sampler, value, warn);
3965 #ifdef GL_ARB_multitexture
3966 if (value != 0) glActiveTexture(GL_TEXTURE0_ARB+value);
3968 glBindTexture(GL_TEXTURE_2D, texid2D);
3969 #ifdef GL_ARB_multitexture
3970 if (value != 0) glActiveTexture(GL_TEXTURE0_ARB);
3976 void lglSampler2D(
unsigned int index, GLuint texid2D,
int value = 0,
bool warn =
true)
3983 #ifdef GL_ARB_multitexture
3984 if (value != 0) glActiveTexture(GL_TEXTURE0_ARB+value);
3986 glBindTexture(GL_TEXTURE_2D, texid2D);
3987 #ifdef GL_ARB_multitexture
3988 if (value != 0) glActiveTexture(GL_TEXTURE0_ARB);
3993 unsigned int lglSampler3D(std::string sampler, GLuint texid3D,
int value = 0,
bool warn =
true)
3995 #if !defined(LGL_GLES) || defined(LGL_GLES3)
4001 unsigned int index =
lglUniformi(sampler, value, warn);
4002 #ifdef GL_ARB_multitexture
4003 if (value != 0) glActiveTexture(GL_TEXTURE0_ARB+value);
4005 glBindTexture(GL_TEXTURE_3D, texid3D);
4006 #ifdef GL_ARB_multitexture
4007 if (value != 0) glActiveTexture(GL_TEXTURE0_ARB);
4019 void lglSampler3D(
unsigned int index, GLuint texid3D,
int value = 0,
bool warn =
true)
4021 #if !defined(LGL_GLES) || defined(LGL_GLES3)
4028 #ifdef GL_ARB_multitexture
4029 if (value != 0) glActiveTexture(GL_TEXTURE0_ARB+value);
4031 glBindTexture(GL_TEXTURE_3D, texid3D);
4032 #ifdef GL_ARB_multitexture
4033 if (value != 0) glActiveTexture(GL_TEXTURE0_ARB);
4044 uniforms_ = vbo->uniforms_;
4045 locations_ = vbo->locations_;
4055 for (
typename lgl_uniform_map_type::const_iterator i = vbo->uniforms_.begin(); i != vbo->uniforms_.end(); i++)
4057 std::string uniform = i->first;
4058 unsigned int index = i->second;
4060 switch (vbo->locations_[index].type)
4062 case lgl_int_type:
lglUniformi(uniform, vbo->locations_[index].value.int_value, warn);
break;
4063 case lgl_float_type:
lglUniformf(uniform, vbo->locations_[index].value.float_value, warn);
break;
4064 case lgl_vec2f_type:
lglUniform2fv(uniform, vbo->locations_[index].value.vec2f_value, warn);
break;
4065 case lgl_vec3f_type:
lglUniform3fv(uniform, vbo->locations_[index].value.vec3f_value, warn);
break;
4066 case lgl_vec4f_type:
lglUniform4fv(uniform, vbo->locations_[index].value.vec4f_value, warn);
break;
4067 case lgl_mat2f_type:
lglUniformMatrix2fv(uniform, vbo->locations_[index].value.mat2f_value, warn);
break;
4068 case lgl_mat3f_type:
lglUniformMatrix3fv(uniform, vbo->locations_[index].value.mat3f_value, warn);
break;
4069 case lgl_mat4f_type:
lglUniformMatrix4fv(uniform, vbo->locations_[index].value.mat4f_value, warn);
break;
4070 case lgl_no_type:
if (vbo->locations_[index].warn)
lglWarning(
"copying undefined uniform: " + uniform);
break;
4082 for (
typename lgl_uniform_location_type::const_iterator i = locations_.begin(); i != locations_.end(); i++)
4084 std::cout <<
"uniform \"" << i->uniform <<
"\": ";
4088 case lgl_int_type: std::cout << i->value.int_value;
break;
4089 case lgl_float_type: std::cout << i->value.float_value;
break;
4090 case lgl_vec2f_type: std::cout <<
vec2f(i->value.vec2f_value[0], i->value.vec2f_value[1]);
break;
4091 case lgl_vec3f_type: std::cout <<
vec3f(i->value.vec3f_value[0], i->value.vec3f_value[1], i->value.vec3f_value[2]);
break;
4092 case lgl_vec4f_type: std::cout <<
vec4f(i->value.vec4f_value[0], i->value.vec4f_value[1], i->value.vec4f_value[2], i->value.vec4f_value[3]);
break;
4093 case lgl_mat2f_type: {
mat2f m2f; m2f.
fromOpenGL(i->value.mat2f_value); std::cout << m2f;}
break;
4094 case lgl_mat3f_type: {
mat3f m3f; m3f.
fromOpenGL(i->value.mat3f_value); std::cout << m3f;}
break;
4095 case lgl_mat4f_type: {
mat4f m4f; m4f.
fromOpenGL(i->value.mat4f_value); std::cout << m4f;}
break;
4096 case lgl_no_type: std::cout <<
"undefined";
break;
4099 std::cout << std::endl;
4110 program_ = vbo->program_;
4111 uniforms_ = vbo->uniforms_;
4112 locations_ = vbo->locations_;
4122 program_ = vbo->program_;
4132 float exponent = 30,
vec3f falloff =
vec3f(1,0,0))
4161 light_ =
vec4f((
mat3(mvit) * light.xyz()).normalize(), 0);
4167 light_ = mv * light;
4172 falloff_ =
vec3f(1,0,0);
4184 float exponent = 30,
vec3f falloff =
vec3f(1,0,0))
4194 exponent_ = exponent;
4198 falloff_ =
vec3f(1,0,0);
4204 float &exponent,
vec3f &falloff)
const
4214 exponent = exponent_;
4229 falloff_ =
vec3f(1,0,0);
4234 vec3f &falloff)
const
4245 float exponent = 30)
4251 exponent_ = exponent;
4256 float &exponent)
const
4262 exponent = exponent_;
4272 texid_owner_ = owner;
4288 texid_owner_ = owner;
4302 GLuint GLtexid = texid2D_;
4303 glDeleteTextures(1, &GLtexid);
4313 GLuint GLtexid = texid3D_;
4314 glDeleteTextures(1, &GLtexid);
4359 bool ztest =
true,
bool culling =
false)
4361 lglClearColor(r,g,b,a);
4369 glViewport(ax, ay, bx, by);
4372 static void lglClearColor(
float w,
float a=1)
4374 glClearColor(w,w,w,a);
4380 glClearColor(r,g,b,a);
4384 static void lglClear(GLuint bits = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
4390 static void lglRGBAWrite(
bool r =
true,
bool g =
true,
bool b =
true,
bool a =
true)
4393 glColorMask(r?GL_TRUE:GL_FALSE,
4396 a?GL_TRUE:GL_FALSE);
4402 GLboolean color_write[4];
4403 glGetBooleanv(GL_DEPTH_WRITEMASK, color_write);
4404 return(color_write[0]!=0 && color_write[1]!=0 && color_write[2]!=0 && color_write[3]!=0);
4413 glDepthMask(GL_TRUE);
4418 glDepthMask(GL_FALSE);
4425 GLboolean depth_write;
4426 glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_write);
4427 return(depth_write!=0);
4436 glEnable(GL_DEPTH_TEST);
4441 glDisable(GL_DEPTH_TEST);
4448 GLboolean depth_test;
4449 glGetBooleanv(GL_DEPTH_TEST, &depth_test);
4450 return(depth_test!=0);
4459 glFrontFace(GL_CCW);
4460 glCullFace(GL_BACK);
4461 glEnable(GL_CULL_FACE);
4466 glDisable(GL_CULL_FACE);
4473 GLboolean cull_face;
4474 glGetBooleanv(GL_CULL_FACE, &cull_face);
4475 return(cull_face!=0);
4487 if (mode == LGL_BLEND_NONE)
4490 glDisable(GL_BLEND);
4492 else if (mode == LGL_BLEND_MULT)
4495 glBlendFunc(GL_DST_COLOR, GL_ZERO);
4497 if (glBlendEquation) glBlendEquation(GL_FUNC_ADD);
4499 glBlendEquation(GL_FUNC_ADD);
4503 else if (mode == LGL_BLEND_ALPHA)
4506 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
4508 if (glBlendEquation) glBlendEquation(GL_FUNC_ADD);
4510 glBlendEquation(GL_FUNC_ADD);
4514 else if (mode == LGL_BLEND_ADD)
4517 glBlendFunc(GL_ONE, GL_ONE);
4519 if (glBlendEquation) glBlendEquation(GL_FUNC_ADD);
4521 glBlendEquation(GL_FUNC_ADD);
4525 else if (mode == LGL_BLEND_SUB)
4528 glBlendFunc(GL_ONE, GL_ONE);
4530 if (glBlendEquation) glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
4532 glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
4536 else if (mode == LGL_BLEND_MAX)
4539 glBlendFunc(GL_ONE,GL_ONE);
4541 if (glBlendEquation) glBlendEquation(GL_MAX);
4543 glBlendEquation(GL_MAX);
4547 else if (mode == LGL_BLEND_MIN)
4550 glBlendFunc(GL_ONE,GL_ONE);
4552 if (glBlendEquation) glBlendEquation(GL_MIN);
4554 glBlendEquation(GL_MIN);
4564 glGetBooleanv(GL_BLEND, &blend);
4575 static void lglAlphaTest(
bool on =
false,
float value = 0.0f,
bool greater =
true,
bool equal =
false)
4577 alphavalue_ = value;
4584 if (greater) glAlphaFunc(equal?GL_GEQUAL:GL_GREATER, value);
4585 else glAlphaFunc(equal?GL_LEQUAL:GL_LESS, value);
4586 glEnable(GL_ALPHA_TEST);
4591 glDisable(GL_ALPHA_TEST);
4600 alphatest_ =
vec3f(value, -1, 1);
4602 alphatest_ =
vec3f(value, value, 1);
4605 alphatest_ =
vec3f(-value, 1, -1);
4607 alphatest_ =
vec3f(-value, -value, -1);
4609 alphatest_ =
vec3f(-1,-1,0);
4617 GLboolean alpha_test;
4618 glGetBooleanv(GL_ALPHA_TEST, &alpha_test);
4619 return(alpha_test != 0);
4623 return(alphatest_.z != 0);
4631 return(alphavalue_);
4637 return(alphatest_.z > 0);
4643 return(alphatest_.x != alphatest_.y);
4649 if (n < LGL_NUM_CLIPPLANES)
4651 if (equation !=
vec4(0,0,0,0))
4653 if (clipplane_[n] ==
vec4(0,0,0,0)) clipping_++;
4657 equation = mvit * equation;
4659 clipplane_[n] = equation;
4663 if (clipplane_[n] !=
vec4(0,0,0,0)) clipping_--;
4664 clipplane_[n] =
vec4(0,0,0,0);
4670 void lglClipPlane(
double a,
double b,
double c,
double d,
unsigned int n = 0,
bool camera_plane =
false)
4684 if (n < LGL_NUM_CLIPPLANES)
4685 return(clipplane_[n]!=
vec4(0,0,0,0));
4693 if (n < LGL_NUM_CLIPPLANES)
4694 return(clipplane_[n]);
4696 return(
vec4(0,0,0,0));
4706 return(
vec4(normal.x, normal.y, normal.z, -normal.
dot(point)));
4712 fogdensity_ = density;
4719 return(fogdensity_ > 0.0f);
4725 return(fogdensity_);
4744 glGetFloatv(GL_LINE_WIDTH, &line_width);
4751 polygonmode_ = mode;
4754 static void lglTogglePolygonMode()
4756 if (polygonmode_ == LGL_FILL)
4757 polygonmode_ = LGL_LINE;
4758 else if (polygonmode_ == LGL_LINE)
4759 polygonmode_ = LGL_FILL;
4765 return(polygonmode_);
4771 interlacing_ = mode;
4779 case LGL_INTERLACE_NONE:
break;
4780 case LGL_INTERLACE_HORIZONTAL_LEFT: mode = LGL_INTERLACE_HORIZONTAL_RIGHT;
break;
4781 case LGL_INTERLACE_HORIZONTAL_RIGHT: mode = LGL_INTERLACE_HORIZONTAL_LEFT;
break;
4782 case LGL_INTERLACE_VERTICAL_TOP: mode = LGL_INTERLACE_VERTICAL_BOTTOM;
break;
4783 case LGL_INTERLACE_VERTICAL_BOTTOM: mode = LGL_INTERLACE_VERTICAL_TOP;
break;
4792 return(interlacing_);
4800 unsigned char *pixels;
4804 if ((pixels=(
unsigned char *)malloc(3*width*height)) == NULL)
4810 glReadBuffer(GL_BACK);
4811 glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
4813 for (
int y=1; y<height/2; y++)
4814 for (
int x=1; x<width; x++)
4815 for (
int z=0; z<3; z++)
4817 unsigned char tmp = pixels[3*(x+y*width)+z];
4818 pixels[3*(x+y*width)+z] = pixels[3*(x+(height-y)*width)+z];
4819 pixels[3*(x+(height-y)*width)+z] = tmp;
4832 double dist = DBL_MAX;
4847 case LGL_LINE_STRIP:
4849 case LGL_TRIANGLE_FAN:
4852 vec3 v1 = vertices_[0];
4853 vec3 v2 = vertices_[1];
4854 for (
int i=2; i<size_; i++)
4856 vec3 v3 = vertices_[i];
4857 double td = glslmath::ray_triangle_dist(o, d, v1, v2, v3);
4860 if (td < dist) dist = td;
4867 for (
int i=0; i<size_/4; i++)
4869 vec3 v1 = vertices_[4*i];
4870 vec3 v2 = vertices_[4*i+1];
4871 vec3 v3 = vertices_[4*i+2];
4872 vec3 v4 = vertices_[4*i+3];
4873 double td1 = glslmath::ray_triangle_dist(o, d, v1, v2, v3);
4874 double td2 = glslmath::ray_triangle_dist(o, d, v1, v3, v4);
4876 if (td1 < dist) dist = td1;
4877 if (td2 < dist) dist = td2;
4881 case LGL_QUAD_STRIP:
4884 vec3 v1 = vertices_[0];
4885 vec3 v2 = vertices_[1];
4886 for (
int i=2; i+1<size_; i+=2)
4888 vec3 v3 = vertices_[i];
4889 vec3 v4 = vertices_[i+1];
4890 double td1 = glslmath::ray_triangle_dist(o, d, v1, v2, v4);
4891 double td2 = glslmath::ray_triangle_dist(o, d, v1, v4, v3);
4895 if (td1 < dist) dist = td1;
4896 if (td2 < dist) dist = td2;
4900 case LGL_TRIANGLE_STRIP:
4903 vec3 v1 = vertices_[0];
4904 vec3 v2 = vertices_[1];
4905 for (
int i=2; i<size_; i++)
4907 vec3 v3 = vertices_[i];
4908 double td = glslmath::ray_triangle_dist(o, d, v1, v2, v3);
4912 if (td < dist) dist = td;
4919 for (
int i=0; i<size_/3; i++)
4921 vec3 v1 = vertices_[3*i];
4922 vec3 v2 = vertices_[3*i+1];
4923 vec3 v3 = vertices_[3*i+2];
4924 double td = glslmath::ray_triangle_dist(o, d, v1, v2, v3);
4926 if (td < dist) dist = td;
4933 if (dist != DBL_MAX)
4936 dist = (p-origin).
length();
4955 raycast_origin_ = origin;
4956 raycast_direction_ = direction;
4957 raycast_mindist_ = mindist;
4958 raycast_dist_ = DBL_MAX;
4959 raycast_vbo_ = NULL;
4967 double d = vbo->
lglIntersect(raycast_origin_, raycast_direction_, raycast_mindist_);
4969 if (d < raycast_dist_)
4981 return(raycast_vbo_);
4987 return(raycast_dist_);
4994 cull_minsize_ = minsize;
5011 export_data_ = data;
5012 export_matrix_ = matrix;
5025 if (export_matrix_ !=
mat4(1)) m = export_matrix_ * m;
5033 export_(©, export_data_);
5046 return(LGL_OPENGL_VERSION);
5052 if (glversion < 20)
return(0);
5056 case 20 :
return(11);
5057 case 21 :
return(12);
5058 case 30 :
return(13);
5059 case 31 :
return(14);
5060 case 32 :
return(15);
5061 case 33 :
return(33);
5062 case 40 :
return(40);
5063 case 41 :
return(41);
5064 case 42 :
return(42);
5065 case 43 :
return(43);
5066 case 44 :
return(44);
5067 case 45 :
return(45);
5068 case 46 :
return(46);
5069 default :
return(glversion);
5082 initializeRenderer();
5089 initializeRenderer();
5096 initializeRenderer();
5099 case LGL_NVIDIA:
return(
"NVIDIA");
5100 case LGL_ATI:
return(
"ATI");
5101 case LGL_INTEL:
return(
"Intel");
5102 default:
return(
"unknown");
5111 GLenum error = glGetError();
5113 if (error != GL_NO_ERROR)
5115 if (error == GL_INVALID_ENUM) error_ =
"invalid GL enum";
5116 else if (error == GL_INVALID_VALUE) error_ =
"invalid GL value";
5117 else if (error == GL_INVALID_OPERATION) error_ =
"invalid GL operation";
5118 else error_ =
"unknown GL error";
5120 std::cerr << error_ << std::endl;
5124 std::string e = error_;
5133 std::string w = warning_;
5152 vec4f attribute_[LGL_NUM_ATTRIBUTES];
5157 bool hasattribute_[LGL_NUM_ATTRIBUTES];
5158 bool hasattributes_;
5160 int size_, maxsize_;
5167 vec3f *barycentrics_;
5170 vec3 bboxmin_, bboxmax_;
5186 static bool disable_coloring_;
5187 static bool disable_lighting_;
5188 static bool disable_texturing_;
5190 static std::string renderer_;
5193 static vec4f actual_;
5196 static std::vector<mat4> projection_matrix_;
5197 static std::vector<mat4> modelview_matrix_;
5198 static std::vector<mat4> texture_matrix_;
5200 static std::vector<mat4> premodel_matrix_;
5201 static std::vector<bool> premodel_matrix_identity_;
5202 static std::vector<mat3> premodel_matrix_it_;
5203 static std::vector<bool> premodel_matrix_recompute_;
5205 static std::vector<mat4> pretex_matrix_;
5206 static std::vector<bool> pretex_matrix_identity_;
5208 static mat4 manip_matrix_;
5209 static bool manip_matrix_identity_;
5210 static bool manip_matrix_apply_;
5213 bool model_matrix_identity_;
5216 bool tex_matrix_identity_;
5218 static double fovy_, aspect_, nearp_, farp_;
5219 static vec3 eye_, at_, up_;
5221 static vec4f light_;
5222 vec3f ka_, kd_, ks_;
5223 static vec3f Ia_, Id_, Is_;
5225 static vec3f falloff_;
5236 static float alphavalue_;
5237 static vec3f alphatest_;
5239 static int clipping_;
5240 static vec4 clipplane_[LGL_NUM_CLIPPLANES];
5242 static float fogdensity_;
5243 static vec4f fogcolor_;
5248 static bool raycast_;
5249 static vec3 raycast_origin_;
5250 static vec3 raycast_direction_;
5251 static double raycast_mindist_;
5252 static double raycast_dist_;
5253 static lgl *raycast_vbo_;
5256 static double cull_minsize_;
5258 static void (*export_)(
lgl *vbo,
void *data);
5259 static void *export_data_;
5260 static mat4 export_matrix_;
5262 static std::string error_;
5263 static std::string warning_;
5266 virtual void init_gl_hook() {}
5267 virtual void exit_gl_hook() {}
5269 virtual void pre_render_hook() {}
5270 virtual void post_render_hook() {}
5274 GLuint buffers_[LGL_NUM_BUFFERS];
5278 GLuint usedprogram_;
5286 GLint kaIa_loc_, kdId_loc_, ksIs_loc_;
5287 GLint exponent_loc_;
5290 GLint alphatest_loc_;
5291 GLint clipping_loc_;
5292 GLint clipplane_loc_;
5293 GLint fogdensity_loc_;
5294 GLint fogcolor_loc_;
5295 GLint wireframe_loc_;
5296 GLint interlacing_loc_;
5298 static GLuint programs_[LGL_NUM_SHADERS];
5299 static GLuint custom_programs_[LGL_NUM_SHADERS];
5301 lgl_uniform_map_type uniforms_;
5302 lgl_uniform_location_type locations_;
5308 static int instances_;
5309 static bool initStaticGL_;
5314 #define WGL_MACRO(proc,proctype) static PFN##proctype##PROC proc;
5315 #include "glvertex_wgl.h"
5321 size_ = maxsize_ = 0;
5330 barycentrics_ = NULL;
5333 for (
unsigned int i=0; i<LGL_NUM_ATTRIBUTES; i++)
5335 attribute_[i] =
vec4f(0);
5336 hasattribute_[i] =
false;
5339 hasattributes_ =
false;
5341 bboxmin_ = bboxmax_ =
vec3(NAN);
5343 primitive_ = LGL_NONE;
5356 model_matrix_ =
mat4(1);
5357 model_matrix_identity_ =
true;
5359 tex_matrix_ =
mat4(1);
5360 tex_matrix_identity_ =
true;
5371 texgen_ = LGL_TEXGEN_NONE;
5376 for (
int i=0; i<LGL_NUM_BUFFERS; i++)
5388 kaIa_loc_ = kdId_loc_ = ksIs_loc_ = -1;
5392 alphatest_loc_ = -1;
5394 clipplane_loc_ = -1;
5395 fogdensity_loc_ = -1;
5397 wireframe_loc_ = -1;
5398 interlacing_loc_ = -1;
5405 static void initializeStatic()
5409 for (
int i=0; i<LGL_NUM_SHADERS; i++)
5412 custom_programs_[0] = 0;
5417 for (
int i=0; i<LGL_NUM_CLIPPLANES; i++)
5418 clipplane_[i] =
vec4(0,0,0,0);
5421 static void initializeRenderer()
5423 if (renderer_ ==
"")
5425 char *renderer = (
char *)glGetString(GL_RENDERER);
5427 if (renderer != NULL)
5428 renderer_ = std::string(renderer);
5430 char *vendor = (
char *)glGetString(GL_VENDOR);
5434 if (strstr(vendor,
"NVIDIA")!=NULL) vendor_ = LGL_NVIDIA;
5435 else if (strstr(vendor,
"ATI")!=NULL) vendor_ = LGL_ATI;
5436 else if (strstr(vendor,
"Intel")!=NULL) vendor_ = LGL_INTEL;
5441 void initializeOpenGL()
5445 glGenBuffers(LGL_NUM_BUFFERS, buffers_);
5447 #if defined(LGL_GL3) || defined(LGL_GLES3)
5449 glGenVertexArrays(1, &array_);
5456 static void initializeStaticOpenGL()
5458 initializeRenderer();
5466 unsigned int num = LGL_NUM_SHADERS;
5476 #if !defined(LGL_GLES) || defined(LGL_GLES3)
5485 for (
unsigned int i=0; i<num; i++)
5486 if (programs_[i] == 0)
5487 lglFatal(
"could not compile basic GLSL program");
5492 void finalizeOpenGL()
5496 glDeleteBuffers(LGL_NUM_BUFFERS, buffers_);
5498 #if defined(LGL_GL3) || defined(LGL_GLES3)
5500 glDeleteVertexArrays(1, &array_);
5507 static void finalizeStaticOpenGL()
5511 for (
int i=0; i<8; i++)
5519 if (vertices_) free(vertices_);
5520 if (verticesf_) free(verticesf_);
5522 if (colors_) free(colors_);
5523 if (normals_) free(normals_);
5524 if (texcoords_) free(texcoords_);
5525 if (barycentrics_) free(barycentrics_);
5526 if (attributes_) free(attributes_);
5531 static void finalizeStatic()
5533 checkMatrixStacks();
5535 if (projection_matrix_.size() > 1)
5536 lglError(
"unbalanced projection matrix stack");
5538 if (modelview_matrix_.size() > 1)
5539 lglError(
"unbalanced model-view matrix stack");
5541 if (premodel_matrix_.size() > 1)
5542 lglError(
"unbalanced pre-model matrix stack");
5544 if (texture_matrix_.size() > 1)
5545 lglError(
"unbalanced texture matrix stack");
5547 if (pretex_matrix_.size() > 1)
5548 lglError(
"unbalanced pre-texture matrix stack");
5551 bool checkVertexScope()
5554 if (matrixmode_!=LGL_PREMODEL && matrixmode_!=LGL_PRETEX)
5563 static bool checkMatrixStacks()
5565 if (projection_matrix_.size() == 0)
5567 lglError(
"projection matrix stack underrun");
5571 if (modelview_matrix_.size() == 0)
5573 lglError(
"model-view matrix stack underrun");
5577 if (premodel_matrix_.size() == 0)
5579 lglError(
"pre-model matrix stack underrun");
5583 if (texture_matrix_.size() == 0)
5585 lglError(
"texture matrix stack underrun");
5589 if (pretex_matrix_.size() == 0)
5591 lglError(
"pre-texture matrix stack underrun");
5607 float a=0.0f,b=0.0f,c=0.5f,d=0.5f;
5609 if (mode==LGL_INTERLACE_HORIZONTAL_LEFT) {a=0.5f; c=0.0f;}
5610 else if (mode==LGL_INTERLACE_HORIZONTAL_RIGHT) {a=0.5f; c=0.5f;}
5611 else if (mode==LGL_INTERLACE_VERTICAL_TOP) {b=0.5f; d=0.0f;}
5612 else if (mode==LGL_INTERLACE_VERTICAL_BOTTOM) {b=0.5f; d=0.5f;}
5614 return(
vec4f(a,b,c,d));
5619 static void initWGLprocs()
5621 static bool init =
false;
5625 #define WGL_MACRO(proc,proctype) if ((proc=(PFN##proctype##PROC)wglGetProcAddress(#proc))==NULL) lglWarning(#proc" not supported");
5626 #include "glvertex_wgl.h"
5636 void lglTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type,
const void *pixels)
5642 glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
5646 void lglTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type,
const void *pixels)
5652 #if !defined(LGL_GLES) || defined (LGL_GLES3)
5653 glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
5660 if (verbosity_ >= LGL_VERBOSITY_MESSAGES)
5661 std::cerr << m << std::endl;
5669 if (verbosity_ >= LGL_VERBOSITY_ERRORS)
5670 std::cerr << e << std::endl;
5678 if (verbosity_ >= LGL_VERBOSITY_WARNINGS)
5679 std::cerr << w << std::endl;
5695 template<
class v, const GLenum t>
5696 friend std::ostream& operator << (std::ostream &out,
const lgl<v, t> &vbo);
5785 #define WGL_MACRO(proc,proctype) template<class VEC4, const GLenum gl_type> PFN##proctype##PROC lgl<VEC4, gl_type>::proc = NULL;
5786 #include "glvertex_wgl.h"
5791 template<
class VEC4, const GLenum gl_type>
5794 for (
unsigned int i=0; i<vbo.size_; i++)
5796 if (vbo.storagetype_) out <<
"vertex #" << i+1 <<
": " << vbo.vertices_[i] << std::endl;
5797 else out <<
"vertex #" << i+1 <<
": " << vbo.verticesf_[i] << std::endl;
5799 if (vbo.hascolor_) out <<
"color #" << i+1 <<
": " << vbo.colors_[i] << std::endl;
5800 if (vbo.hasnormal_) out <<
"normal #" << i+1 <<
": " << vbo.normals_[i] << std::endl;
5801 if (vbo.hastexcoord_) out <<
"texcoord #" << i+1 <<
": " << vbo.texcoords_[i] << std::endl;
5809 # define LGL_VEC4 vec4
5810 # define LGL_GL_TYPE GL_DOUBLE
5812 # define LGL_VEC4 vec4f
5813 # define LGL_GL_TYPE GL_FLOAT
5830 lglVBO(
const std::string &name =
"",
bool storagetype =
true)
5838 lglVBOf(
const std::string &name =
"")