Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
igl::opengl Namespace Reference

Namespaces

namespace  glfw
 

Classes

struct  gliGenericImage
 
class  MeshGL
 
struct  TgaHeader
 
class  ViewerCore
 
class  ViewerData
 

Functions

IGL_INLINE bool render_to_tga (const std::string tga_file, const int width, const int height, const bool alpha)
 alpha whether to include alpha channel
 
IGL_INLINE bool texture_from_tga (const std::string tga_file, GLuint &id)
 
IGL_INLINE gliGenericImagegliReadTGA (FILE *fp, char *name, int hflip, int vflip)
 
IGL_INLINE int gli_verbose (int new_verbose)
 
IGL_INLINE int gliVerbose (int newVerbose)
 
IGL_INLINE void writeTGA (gliGenericImage *image, FILE *fp)
 
IGL_INLINE GLint bind_vertex_attrib_array (const GLuint program_shader, const std::string &name, GLuint bufferID, const Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > &M, bool refresh)
 
IGL_INLINE void create_index_vbo (const Eigen::MatrixXi &F, GLuint &F_vbo_id)
 
IGL_INLINE void create_mesh_vbo (const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, GLuint &V_vbo_id, GLuint &F_vbo_id)
 
IGL_INLINE void create_mesh_vbo (const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::MatrixXd &N, GLuint &V_vbo_id, GLuint &F_vbo_id, GLuint &N_vbo_id)
 
IGL_INLINE bool create_shader_program (const std::string &geom_source, const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib, GLuint &id)
 
IGL_INLINE bool create_shader_program (const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib, GLuint &id)
 
IGL_INLINE GLuint create_shader_program (const std::string &geom_source, const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib)
 
IGL_INLINE GLuint create_shader_program (const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib)
 
template<typename T >
IGL_INLINE void create_vector_vbo (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &V, GLuint &V_vbo_id)
 
IGL_INLINE bool destroy_shader_program (const GLuint id)
 
IGL_INLINE int gl_type_size (const GLenum type)
 
IGL_INLINE void init_render_to_texture (const size_t width, const size_t height, const bool depth_texture, GLuint &tex_id, GLuint &fbo_id, GLuint &d_id)
 
IGL_INLINE void init_render_to_texture (const size_t width, const size_t height, GLuint &tex_id, GLuint &fbo_id, GLuint &dfbo_id)
 
IGL_INLINE GLuint load_shader (const std::string &src, const GLenum type)
 
IGL_INLINE void print_program_info_log (const GLuint obj)
 
IGL_INLINE void print_shader_info_log (const GLuint obj)
 
IGL_INLINE GLenum report_gl_error (const std::string id)
 
IGL_INLINE GLenum report_gl_error ()
 
IGL_INLINE std::string uniform_type_to_string (const GLenum type)
 
template<typename DerivedV , typename DerivedF >
IGL_INLINE void vertex_array (const Eigen::PlainObjectBase< DerivedV > &V, const Eigen::PlainObjectBase< DerivedF > &F, GLuint &va_id, GLuint &ab_id, GLuint &eab_id)
 

Class Documentation

◆ igl::opengl::gliGenericImage

struct igl::opengl::gliGenericImage
Class Members
GLubyte * cmap
GLsizei cmapEntries
GLenum cmapFormat
GLint components
GLenum format
GLsizei height
GLubyte * pixels
GLsizei width

◆ igl::opengl::TgaFooter

struct igl::opengl::TgaFooter
Class Members
unsigned int developerDirectoryOffset
char dot
unsigned int extensionAreaOffset
char null
char signature[16]

◆ igl::opengl::TgaHeader

struct igl::opengl::TgaHeader
Class Members
unsigned char bpp
unsigned char colorMapIndexHi
unsigned char colorMapIndexLo
unsigned char colorMapLengthHi
unsigned char colorMapLengthLo
unsigned char colorMapSize
unsigned char colorMapType
unsigned char descriptor
unsigned char heightHi
unsigned char heightLo
unsigned char idLength
unsigned char imageType
unsigned char widthHi
unsigned char widthLo
unsigned char xOriginHi
unsigned char xOriginLo
unsigned char yOriginHi
unsigned char yOriginLo

Function Documentation

◆ bind_vertex_attrib_array()

IGL_INLINE GLint igl::opengl::bind_vertex_attrib_array ( const GLuint  program_shader,
const std::string &  name,
GLuint  bufferID,
const Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > &  M,
bool  refresh 
)
9{
10 GLint id = glGetAttribLocation(program_shader, name.c_str());
11 if (id < 0)
12 return id;
13 if (M.size() == 0)
14 {
15 glDisableVertexAttribArray(id);
16 return id;
17 }
18 glBindBuffer(GL_ARRAY_BUFFER, bufferID);
19 if (refresh)
20 glBufferData(GL_ARRAY_BUFFER, sizeof(float)*M.size(), M.data(), GL_DYNAMIC_DRAW);
21 glVertexAttribPointer(id, M.cols(), GL_FLOAT, GL_FALSE, 0, 0);
22 glEnableVertexAttribArray(id);
23 return id;
24}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
Definition PlainObjectBase.h:153
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Definition PlainObjectBase.h:255
int GLint
Definition glu-libtess.h:58
#define GL_FALSE
Definition glu-libtess.h:71

References Eigen::PlainObjectBase< Derived >::cols(), Eigen::PlainObjectBase< Derived >::data(), and GL_FALSE.

Referenced by igl::opengl::MeshGL::bind_mesh(), igl::opengl::MeshGL::bind_overlay_lines(), and igl::opengl::MeshGL::bind_overlay_points().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_index_vbo()

IGL_INLINE void igl::opengl::create_index_vbo ( const Eigen::MatrixXi &  F,
GLuint F_vbo_id 
)
14{
15 // Generate Buffers
16 glGenBuffers(1,&F_vbo_id);
17 // Bind Buffers
18 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,F_vbo_id);
19 // Copy data to buffers
20 // We expect a matrix with each vertex position on a row, we then want to
21 // pass this data to OpenGL reading across rows (row-major)
22 if(F.Options & Eigen::RowMajor)
23 {
24 glBufferData(
25 GL_ELEMENT_ARRAY_BUFFER,
26 sizeof(int)*F.size(),
27 F.data(),
28 GL_STATIC_DRAW);
29 }else
30 {
31 // Create temporary copy of transpose
32 Eigen::MatrixXi FT = F.transpose();
33 // If its column major then we need to temporarily store a transpose
34 glBufferData(
35 GL_ELEMENT_ARRAY_BUFFER,
36 sizeof(int)*F.size(),
37 FT.data(),
38 GL_STATIC_DRAW);
39 }
40 // bind with 0, so, switch back to normal pointer operation
41 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
42}
@ RowMajor
Definition Constants.h:322

References Eigen::RowMajor.

Referenced by create_mesh_vbo().

+ Here is the caller graph for this function:

◆ create_mesh_vbo() [1/2]

IGL_INLINE void igl::opengl::create_mesh_vbo ( const Eigen::MatrixXd &  V,
const Eigen::MatrixXi &  F,
const Eigen::MatrixXd &  N,
GLuint V_vbo_id,
GLuint F_vbo_id,
GLuint N_vbo_id 
)
34{
35 // Create VBOs for faces and vertices
36 create_mesh_vbo(V,F,V_vbo_id,F_vbo_id);
37 // Create VBO for normal vectors
38 create_vector_vbo(N,N_vbo_id);
39}
IGL_INLINE void create_vector_vbo(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &V, GLuint &V_vbo_id)
Definition create_vector_vbo.cpp:14
IGL_INLINE void create_mesh_vbo(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, GLuint &V_vbo_id, GLuint &F_vbo_id)
Definition create_mesh_vbo.cpp:14

References create_mesh_vbo(), and create_vector_vbo().

+ Here is the call graph for this function:

◆ create_mesh_vbo() [2/2]

IGL_INLINE void igl::opengl::create_mesh_vbo ( const Eigen::MatrixXd &  V,
const Eigen::MatrixXi &  F,
GLuint V_vbo_id,
GLuint F_vbo_id 
)
19{
20 // Create VBO for vertex position vectors
21 create_vector_vbo(V,V_vbo_id);
22 // Create VBO for face index lists
23 create_index_vbo(F,F_vbo_id);
24}
IGL_INLINE void create_index_vbo(const Eigen::MatrixXi &F, GLuint &F_vbo_id)
Definition create_index_vbo.cpp:11

References create_index_vbo(), and create_vector_vbo().

Referenced by create_mesh_vbo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_shader_program() [1/4]

IGL_INLINE GLuint igl::opengl::create_shader_program ( const std::string &  geom_source,
const std::string &  vert_source,
const std::string &  frag_source,
const std::map< std::string, GLuint > &  attrib 
)
122{
123 GLuint prog_id = 0;
124 create_shader_program(geom_source,vert_source,frag_source,attrib,prog_id);
125 return prog_id;
126}
unsigned int GLuint
Definition glu-libtess.h:62
IGL_INLINE bool create_shader_program(const std::string &geom_source, const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib, GLuint &id)
Definition create_shader_program.cpp:15

References create_shader_program().

+ Here is the call graph for this function:

◆ create_shader_program() [2/4]

IGL_INLINE bool igl::opengl::create_shader_program ( const std::string &  geom_source,
const std::string &  vert_source,
const std::string &  frag_source,
const std::map< std::string, GLuint > &  attrib,
GLuint id 
)
21{
22 using namespace std;
23 if(vert_source == "" && frag_source == "")
24 {
25 cerr<<
26 "create_shader_program() could not create shader program,"
27 " both .vert and .frag source given were empty"<<endl;
28 return false;
29 }
30
31 // create program
32 id = glCreateProgram();
33 if(id == 0)
34 {
35 cerr<<"create_shader_program() could not create shader program."<<endl;
36 return false;
37 }
38 GLuint g = 0,f = 0,v = 0;
39
40 if(geom_source != "")
41 {
42 // load vertex shader
43 g = igl::opengl::load_shader(geom_source.c_str(),GL_GEOMETRY_SHADER);
44 if(g == 0)
45 {
46 cerr<<"geometry shader failed to compile."<<endl;
47 return false;
48 }
49 glAttachShader(id,g);
50 }
51
52 if(vert_source != "")
53 {
54 // load vertex shader
55 v = igl::opengl::load_shader(vert_source.c_str(),GL_VERTEX_SHADER);
56 if(v == 0)
57 {
58 cerr<<"vertex shader failed to compile."<<endl;
59 return false;
60 }
61 glAttachShader(id,v);
62 }
63
64 if(frag_source != "")
65 {
66 // load fragment shader
67 f = igl::opengl::load_shader(frag_source.c_str(),GL_FRAGMENT_SHADER);
68 if(f == 0)
69 {
70 cerr<<"fragment shader failed to compile."<<endl;
71 return false;
72 }
73 glAttachShader(id,f);
74 }
75
76 // loop over attributes
77 for(
78 std::map<std::string,GLuint>::const_iterator ait = attrib.begin();
79 ait != attrib.end();
80 ait++)
81 {
82 glBindAttribLocation(
83 id,
84 (*ait).second,
85 (*ait).first.c_str());
86 }
87 // Link program
88 glLinkProgram(id);
89 const auto & detach = [&id](const GLuint shader)
90 {
91 if(shader)
92 {
93 glDetachShader(id,shader);
94 glDeleteShader(shader);
95 }
96 };
97 detach(g);
98 detach(f);
99 detach(v);
100
101 // print log if any
103
104 return true;
105}
IGL_INLINE void print_program_info_log(const GLuint obj)
Definition print_program_info_log.cpp:13
IGL_INLINE GLuint load_shader(const std::string &src, const GLenum type)
Definition load_shader.cpp:13
STL namespace.

References load_shader(), and print_program_info_log().

Referenced by create_shader_program(), create_shader_program(), and create_shader_program().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_shader_program() [3/4]

IGL_INLINE GLuint igl::opengl::create_shader_program ( const std::string &  vert_source,
const std::string &  frag_source,
const std::map< std::string, GLuint > &  attrib 
)
132{
133 GLuint prog_id = 0;
134 create_shader_program(vert_source,frag_source,attrib,prog_id);
135 return prog_id;
136}

References create_shader_program().

+ Here is the call graph for this function:

◆ create_shader_program() [4/4]

IGL_INLINE bool igl::opengl::create_shader_program ( const std::string &  vert_source,
const std::string &  frag_source,
const std::map< std::string, GLuint > &  attrib,
GLuint id 
)
112{
113 return create_shader_program("",vert_source,frag_source,attrib,prog_id);
114}

References create_shader_program().

+ Here is the call graph for this function:

◆ create_vector_vbo()

template<typename T >
IGL_INLINE void igl::opengl::create_vector_vbo ( const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  V,
GLuint V_vbo_id 
)
17{
19 //assert(V.cols() == 3);
20
21 // Generate Buffers
22 glGenBuffers(1,&V_vbo_id);
23 // Bind Buffers
24 glBindBuffer(GL_ARRAY_BUFFER,V_vbo_id);
25 // Copy data to buffers
26 // We expect a matrix with each vertex position on a row, we then want to
27 // pass this data to OpenGL reading across rows (row-major)
29 {
30 glBufferData(
31 GL_ARRAY_BUFFER,
32 sizeof(T)*V.size(),
33 V.data(),
34 GL_STATIC_DRAW);
35 }else
36 {
37 // Create temporary copy of transpose
39 // If its column major then we need to temporarily store a transpose
40 glBufferData(
41 GL_ARRAY_BUFFER,
42 sizeof(T)*V.size(),
43 VT.data(),
44 GL_STATIC_DRAW);
45 }
46 // bind with 0, so, switch back to normal pointer operation
47 glBindBuffer(GL_ARRAY_BUFFER, 0);
48}
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
@ Options
Definition Matrix.h:188

References Eigen::PlainObjectBase< Derived >::data(), Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Options, and Eigen::RowMajor.

Referenced by create_mesh_vbo(), and create_mesh_vbo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy_shader_program()

IGL_INLINE bool igl::opengl::destroy_shader_program ( const GLuint  id)
13{
14 // Don't try to destroy id == 0 (no shader program)
15 if(id == 0)
16 {
17 fprintf(stderr,"Error: destroy_shader_program() id = %d"
18 " but must should be positive\n",id);
19 return false;
20 }
21 // Get each attached shader one by one and detach and delete it
23 // shader id
24 GLuint s;
25 do
26 {
27 // Try to get at most *1* attached shader
28 glGetAttachedShaders(id,1,&count,&s);
30 if (GL_NO_ERROR != err)
31 {
32 return false;
33 }
34 // Check that we actually got *1*
35 if(count == 1)
36 {
37 // Detach and delete this shader
38 glDetachShader(id,s);
39 glDeleteShader(s);
40 }
41 }while(count > 0);
42 // Now that all of the shaders are gone we can just delete the program
43 glDeleteProgram(id);
44 return true;
45}
unsigned int GLenum
Definition glu-libtess.h:53
int GLsizei
Definition glu-libtess.h:59
IGL_INLINE GLenum report_gl_error()
Definition report_gl_error.cpp:57
IGL_INLINE void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Definition count.cpp:12

References igl::count(), and report_gl_error().

+ Here is the call graph for this function:

◆ gl_type_size()

IGL_INLINE int igl::opengl::gl_type_size ( const GLenum  type)
12{
13 switch(type)
14 {
15 case GL_DOUBLE:
16 return 8;
17 break;
18 case GL_FLOAT:
19 return 4;
20 break;
21 case GL_INT:
22 return 4;
23 break;
24 default:
25 // should handle all other GL_[types]
26 assert(false && "Implementation incomplete.");
27 break;
28 }
29 return -1;
30}

◆ gli_verbose()

IGL_INLINE int igl::opengl::gli_verbose ( int  new_verbose)
470{
471 _verbose = new_verbose;
472 return _verbose;
473}
static unsigned int _verbose
Definition tga.cpp:51

References _verbose.

◆ gliReadTGA()

IGL_INLINE igl::opengl::gliGenericImage * igl::opengl::gliReadTGA ( FILE *  fp,
char *  name,
int  hflip,
int  vflip 
)
187{
188 igl::opengl::TgaHeader tgaHeader;
189 igl::opengl::TgaFooter tgaFooter;
190 char horzrev, vertrev;
191 int width, height, bpp;
192 int start, end, dir;
193 int i, j, k;
194 int pelbytes, wbytes;
195 GLenum format;
196 int components;
197 RLEstate rleRec;
198 RLEstate *rleInfo;
199 int rle;
200 int index, colors, length;
201 GLubyte *cmap, *pixels, *data;
202 int (*myfread)(RLEstate *rleInfo, unsigned char*, size_t, size_t, FILE*);
203 igl::opengl::gliGenericImage *genericImage;
204
205 /* Check the footer. */
206 if (fseek(fp, 0L - sizeof(tgaFooter), SEEK_END)
207 || fread(&tgaFooter, sizeof(tgaFooter), 1, fp) != 1) {
208 sprintf(error, "TGA: Cannot read footer from \"%s\"", name);
209 if (_verbose) printf("%s\n", error);
210 return NULL;
211 }
212
213 /* Check the signature. */
214 if (memcmp(tgaFooter.signature, TGA_SIGNATURE,
215 sizeof(tgaFooter.signature)) == 0) {
216 if (_verbose) printf("TGA: found New TGA\n");
217 } else {
218 if (_verbose) printf("TGA: found Original TGA\n");
219 }
220
221 if (fseek(fp, 0, SEEK_SET) ||
222 fread(&tgaHeader, sizeof(tgaHeader), 1, fp) != 1) {
223 sprintf(error, "TGA: Cannot read header from \"%s\"", name);
224 if (_verbose) printf("%s\n", error);
225 return NULL;
226 }
227
228 if (_verbose && tgaHeader.idLength) {
229 char *idString = (char*) malloc(tgaHeader.idLength);
230
231 if (fread(idString, tgaHeader.idLength, 1, fp) != 1) {
232 sprintf(error, "TGA: Cannot read ID field in \"%s\"", name);
233 printf("%s\n", error);
234 } else {
235 printf("TGA: ID field: \"%*s\"\n", tgaHeader.idLength, idString);
236 }
237 free(idString);
238 } else {
239 /* Skip the image ID field. */
240 if (tgaHeader.idLength && fseek(fp, tgaHeader.idLength, SEEK_CUR)) {
241 sprintf(error, "TGA: Cannot skip ID field in \"%s\"", name);
242 if (_verbose) printf("%s\n", error);
243 return NULL;
244 }
245 }
246
247 /* Reassemble the multi-byte values correctly, regardless of
248 host endianness. */
249 width = (tgaHeader.widthHi << 8) | tgaHeader.widthLo;
250 height = (tgaHeader.heightHi << 8) | tgaHeader.heightLo;
251 bpp = tgaHeader.bpp;
252 if (_verbose) {
253 printf("TGA: width=%d, height=%d, bpp=%d\n", width, height, bpp);
254 }
255
256 horzrev = tgaHeader.descriptor & TGA_DESC_HORIZONTAL;
257 vertrev = tgaHeader.descriptor & TGA_DESC_VERTICAL;
258 //vertrev=0;
259
260// // JASON - we can force this stuff if we want
261// if( hflip )
262// horzrev = 1;
263 if( vflip )
264 vertrev = 1;
265
266 if (_verbose && horzrev) printf("TGA: horizontal reversed\n");
267 if (_verbose && vertrev) printf("TGA: vertical reversed\n");
268
269 rle = 0;
270 switch (tgaHeader.imageType) {
272 rle = 1;
273 if (_verbose) printf("TGA: run-length encoded\n");
274 case TGA_TYPE_MAPPED:
275 /* Test for alpha channel. */
276 format = GL_COLOR_INDEX;
277 components = 1;
278 if (_verbose) {
279 printf("TGA: %d bit indexed image (%d bit palette)\n",
280 tgaHeader.colorMapSize, bpp);
281 }
282 break;
283
285 rle = 1;
286 if (_verbose) printf("TGA: run-length encoded\n");
287 case TGA_TYPE_GRAY:
288 format = GL_LUMINANCE;
289 components = 1;
290 if (_verbose) printf("TGA: %d bit grayscale image\n", bpp);
291 break;
292
294 rle = 1;
295 if (_verbose) printf("TGA: run-length encoded\n");
296 case TGA_TYPE_COLOR:
297 /* Test for alpha channel. */
298 if (bpp == 32) {
299 format = GL_BGRA_EXT;
300 components = 4;
301 if (_verbose) {
302 printf("TGA: %d bit color image with alpha channel\n", bpp);
303 }
304 } else {
305 format = GL_BGR_EXT;
306 components = 3;
307 if (_verbose) printf("TGA: %d bit color image\n", bpp);
308 }
309 break;
310
311 default:
312 sprintf(error,
313 "TGA: unrecognized image type %d\n", tgaHeader.imageType);
314 if (_verbose) printf("%s\n", error);
315 return NULL;
316 }
317
318 if ((format == GL_BGRA_EXT && bpp != 32) ||
319 (format == GL_BGR_EXT && bpp != 24) ||
320 ((format == GL_LUMINANCE || format == GL_COLOR_INDEX) && bpp != 8)) {
321 /* FIXME: We haven't implemented bit-packed fields yet. */
322 fprintf(stderr, "bpp %d, format %x\n", bpp, (unsigned int)format);
323 sprintf(error, "TGA: channel sizes other than 8 bits are unimplemented");
324 if (_verbose) printf("%s\n", error);
325 return NULL;
326 }
327
328 /* Check that we have a color map only when we need it. */
329 if (format == GL_COLOR_INDEX) {
330 if (tgaHeader.colorMapType != 1) {
331 sprintf(error, "TGA: indexed image has invalid color map type %d\n",
332 tgaHeader.colorMapType);
333 if (_verbose) printf("%s\n", error);
334 return NULL;
335 }
336 } else if (tgaHeader.colorMapType != 0) {
337 sprintf(error, "TGA: non-indexed image has invalid color map type %d\n",
338 tgaHeader.colorMapType);
339 if (_verbose) printf("%s\n", error);
340 return NULL;
341 }
342
343 if (tgaHeader.colorMapType == 1) {
344 /* We need to read in the colormap. */
345 index = (tgaHeader.colorMapIndexHi << 8) | tgaHeader.colorMapIndexLo;
346 length = (tgaHeader.colorMapLengthHi << 8) | tgaHeader.colorMapLengthLo;
347
348 if (_verbose) {
349 printf("TGA: reading color map (%d + %d) * (%d / 8)\n",
350 index, length, tgaHeader.colorMapSize);
351 }
352 if (length == 0) {
353 sprintf(error, "TGA: invalid color map length %d", length);
354 if (_verbose) printf("%s\n", error);
355 return NULL;
356 }
357 if (tgaHeader.colorMapSize != 24) {
358 /* We haven't implemented bit-packed fields yet. */
359 sprintf(error, "TGA: channel sizes other than 8 bits are unimplemented");
360 if (_verbose) printf("%s\n", error);
361 return NULL;
362 }
363
364 pelbytes = tgaHeader.colorMapSize / 8;
365 colors = length + index;
366 cmap = (GLubyte*)malloc (colors * pelbytes);
367
368 /* Zero the entries up to the beginning of the map. */
369 memset(cmap, 0, index * pelbytes);
370
371 /* Read in the rest of the colormap. */
372 if (fread(cmap, pelbytes, length, fp) != (size_t) length) {
373 sprintf(error, "TGA: error reading colormap (ftell == %ld)\n",
374 ftell (fp));
375 if (_verbose) printf("%s\n", error);
376 return NULL;
377 }
378
379 if (pelbytes >= 3) {
380 /* Rearrange the colors from BGR to RGB. */
381 int tmp;
382 for (j = index; j < length * pelbytes; j += pelbytes) {
383 tmp = cmap[j];
384 cmap[j] = cmap[j + 2];
385 cmap[j + 2] = tmp;
386 }
387 }
388 } else {
389 colors = 0;
390 cmap = NULL;
391 }
392
393 /* Allocate the data. */
394 pelbytes = bpp / 8;
395 pixels = (unsigned char *) malloc (width * height * pelbytes);
396
397 if (rle) {
398 rleRec.statebuf = 0;
399 rleRec.statelen = 0;
400 rleRec.laststate = 0;
401 rleInfo = &rleRec;
402 myfread = rle_fread;
403 } else {
404 rleInfo = NULL;
405 myfread = std_fread;
406 }
407
408 wbytes = width * pelbytes;
409
410 if (vertrev) {
411 start = 0;
412 end = height;
413 dir = 1;
414 } else {
415 /* We need to reverse loading order of rows. */
416 start = height-1;
417 end = -1;
418 dir = -1;
419 }
420
421 for (i = start; i != end; i += dir) {
422 data = pixels + i*wbytes;
423
424 /* Suck in the data one row at a time. */
425 if (myfread(rleInfo, data, pelbytes, width, fp) != width) {
426 /* Probably premature end of file. */
427 if (_verbose) {
428 printf ("TGA: error reading (ftell == %ld, width=%d)\n",
429 ftell(fp), width);
430 }
431 return NULL;
432 }
433
434 if (horzrev) {
435 /* We need to mirror row horizontally. */
436 for (j = 0; j < width/2; j++) {
437 GLubyte tmp;
438
439 for (k = 0; k < pelbytes; k++) {
440 tmp = data[j*pelbytes+k];
441 data[j*pelbytes+k] = data[(width-j-1)*pelbytes+k];
442 data[(width-j-1)*pelbytes+k] = tmp;
443 }
444 }
445 }
446 }
447
448 if (rle) {
449 free(rleInfo->statebuf);
450 }
451
452 if (fgetc (fp) != EOF) {
453 if (_verbose) printf ("TGA: too much input data, ignoring extra...\n");
454 }
455
457 genericImage->width = width;
458 genericImage->height = height;
459 genericImage->format = format;
460 genericImage->components = components;
461 genericImage->cmapEntries = colors;
462 genericImage->cmapFormat = GL_BGR_EXT; // XXX fix me
463 genericImage->cmap = cmap;
464 genericImage->pixels = pixels;
465
466 return genericImage;
467}
void * malloc(YYSIZE_T)
void free(void *)
unsigned char GLubyte
Definition glu-libtess.h:60
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:539
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:540
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:44
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195
double length(std::vector< SurfacePoint > &path)
Definition exact_geodesic.cpp:1682
unsigned char heightLo
Definition tga.h:65
unsigned char idLength
Definition tga.h:41
GLenum cmapFormat
Definition tga.h:33
GLubyte * cmap
Definition tga.h:34
GLsizei height
Definition tga.h:28
unsigned char widthLo
Definition tga.h:64
unsigned char colorMapIndexLo
Definition tga.h:56
GLsizei width
Definition tga.h:27
unsigned char colorMapIndexHi
Definition tga.h:56
GLsizei cmapEntries
Definition tga.h:32
unsigned char heightHi
Definition tga.h:65
unsigned char widthHi
Definition tga.h:64
unsigned char colorMapLengthHi
Definition tga.h:57
unsigned char descriptor
Definition tga.h:78
GLubyte * pixels
Definition tga.h:36
unsigned char colorMapSize
Definition tga.h:58
unsigned char colorMapType
Definition tga.h:42
unsigned char colorMapLengthLo
Definition tga.h:57
unsigned char imageType
Definition tga.h:51
unsigned char bpp
Definition tga.h:67
char signature[16]
Definition tga.h:86
GLint components
Definition tga.h:29
GLenum format
Definition tga.h:30
Definition tga.h:25
Definition tga.h:40
IGL_INLINE void components(const Eigen::SparseMatrix< AScalar > &A, Eigen::PlainObjectBase< DerivedC > &C, Eigen::PlainObjectBase< Derivedcounts > &counts)
Definition components.cpp:14
S::iterator end(S &sh, const PathTag &)
Definition geometry_traits.hpp:620
#define L(s)
Definition I18N.hpp:18
#define SEEK_SET
static IGL_INLINE int rle_fread(RLEstate *rleInfo, unsigned char *vbuf, size_t datasize, size_t nelems, FILE *fp)
Definition tga.cpp:77
int statelen
Definition tga.cpp:56
static char error[256]
Definition tga.cpp:50
int laststate
Definition tga.cpp:57
static IGL_INLINE int std_fread(RLEstate *, unsigned char *buf, size_t datasize, size_t nelems, FILE *fp)
Definition tga.cpp:61
unsigned char * statebuf
Definition tga.cpp:55
Definition tga.cpp:54
#define TGA_DESC_HORIZONTAL
Definition tga.h:76
#define TGA_SIGNATURE
Definition tga.h:85
#define TGA_TYPE_GRAY_RLE
Definition tga.h:50
#define TGA_TYPE_COLOR
Definition tga.h:46
#define TGA_TYPE_COLOR_RLE
Definition tga.h:49
#define TGA_TYPE_GRAY
Definition tga.h:47
#define TGA_TYPE_MAPPED
Definition tga.h:45
#define TGA_DESC_VERTICAL
Definition tga.h:77
#define TGA_TYPE_MAPPED_RLE
Definition tga.h:48

References _verbose, igl::opengl::TgaHeader::bpp, igl::opengl::gliGenericImage::cmap, igl::opengl::gliGenericImage::cmapEntries, igl::opengl::gliGenericImage::cmapFormat, igl::opengl::TgaHeader::colorMapIndexHi, igl::opengl::TgaHeader::colorMapIndexLo, igl::opengl::TgaHeader::colorMapLengthHi, igl::opengl::TgaHeader::colorMapLengthLo, igl::opengl::TgaHeader::colorMapSize, igl::opengl::TgaHeader::colorMapType, igl::components(), igl::opengl::gliGenericImage::components, igl::opengl::TgaHeader::descriptor, error, igl::opengl::gliGenericImage::format, free(), igl::opengl::gliGenericImage::height, igl::opengl::TgaHeader::heightHi, igl::opengl::TgaHeader::heightLo, igl::opengl::TgaHeader::idLength, igl::opengl::TgaHeader::imageType, L, RLEstate::laststate, malloc(), igl::opengl::gliGenericImage::pixels, rle_fread(), SEEK_SET, igl::opengl::TgaFooter::signature, RLEstate::statebuf, RLEstate::statelen, std_fread(), TGA_DESC_HORIZONTAL, TGA_DESC_VERTICAL, TGA_SIGNATURE, TGA_TYPE_COLOR, TGA_TYPE_COLOR_RLE, TGA_TYPE_GRAY, TGA_TYPE_GRAY_RLE, TGA_TYPE_MAPPED, TGA_TYPE_MAPPED_RLE, igl::opengl::gliGenericImage::width, igl::opengl::TgaHeader::widthHi, and igl::opengl::TgaHeader::widthLo.

Referenced by texture_from_tga().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gliVerbose()

IGL_INLINE int igl::opengl::gliVerbose ( int  newVerbose)

◆ init_render_to_texture() [1/2]

IGL_INLINE void igl::opengl::init_render_to_texture ( const size_t  width,
const size_t  height,
const bool  depth_texture,
GLuint tex_id,
GLuint fbo_id,
GLuint d_id 
)
19{
20 using namespace std;
21 // http://www.opengl.org/wiki/Framebuffer_Object_Examples#Quick_example.2C_render_to_texture_.282D.29
22 const auto & gen_tex = [](GLuint & tex_id)
23 {
24 glGenTextures(1, &tex_id);
25 glBindTexture(GL_TEXTURE_2D, tex_id);
26 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
27 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
28 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
29 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
30 };
31 gen_tex(tex_id);
32 //NULL means reserve texture memory, but texels are undefined
33 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_BGRA, GL_FLOAT, NULL);
34 glBindTexture(GL_TEXTURE_2D, 0);
35
36 glGenFramebuffers(1, &fbo_id);
37 glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
38 //Attach 2D texture to this FBO
39 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_id, 0);
40 if(depth_texture)
41 {
42 // Generate a depth texture
43 gen_tex(d_id);
44 glTexImage2D(
45 GL_TEXTURE_2D,
46 0,
47 GL_DEPTH_COMPONENT32,
48 width,
49 height,
50 0,
51 GL_DEPTH_COMPONENT,
52 GL_FLOAT,
53 NULL);
54 glFramebufferTexture2D(
55 GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,d_id,0);
56 }else
57 {
58 // Attach a depth buffer
59 glGenRenderbuffers(1, &d_id);
60 glBindRenderbuffer(GL_RENDERBUFFER, d_id);
61 glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24,width,height);
62 glFramebufferRenderbuffer(
63 GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,d_id);
64 }
65
66 //Does the GPU support current FBO configuration?
67 GLenum status;
68 status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
69 assert(status == GL_FRAMEBUFFER_COMPLETE);
70 // Unbind to clean up
71 if(!depth_texture)
72 {
73 glBindRenderbuffer(GL_RENDERBUFFER, 0);
74 }
75 glBindFramebuffer(GL_FRAMEBUFFER, 0);
76}

Referenced by init_render_to_texture().

+ Here is the caller graph for this function:

◆ init_render_to_texture() [2/2]

IGL_INLINE void igl::opengl::init_render_to_texture ( const size_t  width,
const size_t  height,
GLuint tex_id,
GLuint fbo_id,
GLuint dfbo_id 
)
84{
85 return init_render_to_texture(width,height,false,tex_id,fbo_id,dfbo_id);
86}
IGL_INLINE void init_render_to_texture(const size_t width, const size_t height, const bool depth_texture, GLuint &tex_id, GLuint &fbo_id, GLuint &d_id)
Definition init_render_to_texture.cpp:12

References init_render_to_texture().

+ Here is the call graph for this function:

◆ load_shader()

IGL_INLINE GLuint igl::opengl::load_shader ( const std::string &  src,
const GLenum  type 
)
15{
16 if(src.empty())
17 {
18 return (GLuint) 0;
19 }
20
21 GLuint s = glCreateShader(type);
22 if(s == 0)
23 {
24 fprintf(stderr,"Error: load_shader() failed to create shader.\n");
25 return 0;
26 }
27 // Pass shader source string
28 const char *c = src.c_str();
29 glShaderSource(s, 1, &c, NULL);
30 glCompileShader(s);
31 // Print info log (if any)
33 return s;
34}
IGL_INLINE void print_shader_info_log(const GLuint obj)
Definition print_shader_info_log.cpp:13

References print_shader_info_log().

Referenced by create_shader_program().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_program_info_log()

IGL_INLINE void igl::opengl::print_program_info_log ( const GLuint  obj)
14{
15 GLint infologLength = 0;
16 GLint charsWritten = 0;
17 char *infoLog;
18
19 glGetProgramiv(obj, GL_INFO_LOG_LENGTH,&infologLength);
20
21 if (infologLength > 0)
22 {
23 infoLog = (char *)malloc(infologLength);
24 glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog);
25 printf("%s\n",infoLog);
26 free(infoLog);
27 }
28}

References free(), and malloc().

Referenced by create_shader_program().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_shader_info_log()

IGL_INLINE void igl::opengl::print_shader_info_log ( const GLuint  obj)
14{
15 GLint infologLength = 0;
16 GLint charsWritten = 0;
17 char *infoLog;
18
19 // Get shader info log from opengl
20 glGetShaderiv(obj, GL_INFO_LOG_LENGTH,&infologLength);
21 // Only print if there is something in the log
22 if (infologLength > 0)
23 {
24 infoLog = (char *)malloc(infologLength);
25 glGetShaderInfoLog(obj, infologLength, &charsWritten, infoLog);
26 printf("%s\n",infoLog);
27 free(infoLog);
28 }
29}

References free(), and malloc().

Referenced by load_shader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render_to_tga()

IGL_INLINE bool igl::opengl::render_to_tga ( const std::string  tga_file,
const int  width,
const int  height,
const bool  alpha 
)

alpha whether to include alpha channel

20{
21
22 size_t components = 3;
23 GLenum format = GL_BGR;
24 if(alpha)
25 {
26 format = GL_BGRA;
27 components = 4;
28 }
29 GLubyte * cmap = NULL;
30
31 // OpenGL by default tries to read data in multiples of 4, if our data is
32 // only RGB or BGR and the width is not divible by 4 then we need to alert
33 // opengl
34 if((width % 4) != 0 &&
35 (format == GL_RGB ||
36 format == GL_BGR))
37 {
38 glPixelStorei(GL_PACK_ALIGNMENT, 1);
39 }
40 GLubyte *pixels;
41 pixels = (unsigned char *) malloc (width * height * components);
42 glReadPixels(
43 0,
44 0,
45 width,
46 height,
47 format,
48 GL_UNSIGNED_BYTE,
49 pixels);
50
51 // set up generic image struct
52 gliGenericImage * genericImage;
53 genericImage = (gliGenericImage*) malloc(sizeof(gliGenericImage));
54 genericImage->width = width;
55 genericImage->height = height;
56 genericImage->format = format;
57 genericImage->components = components;
58 genericImage->pixels = pixels;
59 // CMAP is not supported, but we need to put something here
60 genericImage->cmapEntries = 0;
61 genericImage->cmapFormat = GL_BGR;
62 genericImage->cmap = cmap;
63
64 // write pixels to tga file
65 FILE * imgFile;
66 // "-" as output file name is code for write to stdout
67 if(tga_file.compare("-") == 0)
68 {
69 imgFile = stdout;
70 }else{
71 imgFile = fopen(tga_file.c_str(),"w");
72 if(NULL==imgFile)
73 {
74 printf("IOError: %s could not be opened...\n",tga_file.c_str());
75 return false;
76 }
77 }
78
79 writeTGA(genericImage,imgFile);
80
81 free(genericImage);
82 return fclose(imgFile) == 0;
83}
IGL_INLINE void writeTGA(gliGenericImage *image, FILE *fp)
Definition tga.cpp:515

References igl::opengl::gliGenericImage::cmap, igl::opengl::gliGenericImage::cmapEntries, igl::opengl::gliGenericImage::cmapFormat, igl::components(), igl::opengl::gliGenericImage::components, igl::opengl::gliGenericImage::format, free(), igl::opengl::gliGenericImage::height, malloc(), igl::opengl::gliGenericImage::pixels, igl::opengl::gliGenericImage::width, and writeTGA().

+ Here is the call graph for this function:

◆ report_gl_error() [1/2]

IGL_INLINE GLenum igl::opengl::report_gl_error ( )
58{
59 return igl::opengl::report_gl_error(std::string(""));
60}

References report_gl_error().

Referenced by destroy_shader_program(), and report_gl_error().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ report_gl_error() [2/2]

IGL_INLINE GLenum igl::opengl::report_gl_error ( const std::string  id)
13{
14 // http://stackoverflow.com/q/28485180/148668
15
16 // gluErrorString was deprecated
17 const auto gluErrorString = [](GLenum errorCode)->const char *
18 {
19 switch(errorCode)
20 {
21 default:
22 return "unknown error code";
23 case GL_NO_ERROR:
24 return "no error";
25 case GL_INVALID_ENUM:
26 return "invalid enumerant";
27 case GL_INVALID_VALUE:
28 return "invalid value";
29 case GL_INVALID_OPERATION:
30 return "invalid operation";
31#ifndef GL_VERSION_3_0
32 case GL_STACK_OVERFLOW:
33 return "stack overflow";
34 case GL_STACK_UNDERFLOW:
35 return "stack underflow";
36 case GL_TABLE_TOO_LARGE:
37 return "table too large";
38#endif
39 case GL_OUT_OF_MEMORY:
40 return "out of memory";
41#ifdef GL_EXT_framebuffer_object
42 case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
43 return "invalid framebuffer operation";
44#endif
45 }
46 };
47
48 GLenum err = glGetError();
49 if(GL_NO_ERROR != err)
50 {
51 verbose("GL_ERROR: ");
52 fprintf(stderr,"%s%s\n",id.c_str(),gluErrorString(err));
53 }
54 return err;
55}
int verbose
Definition main.c:198

References verbose.

◆ texture_from_tga()

IGL_INLINE bool igl::opengl::texture_from_tga ( const std::string  tga_file,
GLuint id 
)
13{
14 using namespace std;
15
16 // read pixels to tga file
17 FILE * imgFile;
18 // "-" as input file name is code for read from stdin
19 imgFile = fopen(tga_file.c_str(),"r");
20 if(NULL==imgFile)
21 {
22 printf("IOError: %s could not be opened...",tga_file.c_str());
23 return false;
24 }
25
26 // gliReadTGA annoyingly uses char * instead of const char *
27 size_t len = tga_file.length();
28 char* tga_file_char = new char [ len + 1 ];
29 strcpy( tga_file_char, tga_file.c_str() );
30 // read image
31 gliGenericImage* img = gliReadTGA(imgFile, tga_file_char, 0, 0);
32 // clean up filename buffer
33 delete[] tga_file_char;
34 fclose( imgFile );
35
36 // set up texture mapping parameters and generate texture id
37 glGenTextures(1,&id);
38 glBindTexture(GL_TEXTURE_2D, id);
39 // Texture parameters
40 float empty[] = {1.0f,1.0f,1.0f,0.0f};
41 glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR,empty);
42 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
43 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
44 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
45 // GL_LINEAR_MIPMAP_NEAREST);
46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
47 GL_LINEAR);
48
49 // OpenGL by default tries to read data in multiples of 4, if our data is
50 // only RGB or BGR and the width is not divible by 4 then we need to alert
51 // opengl
52 if((img->width % 4) != 0 &&
53 (img->format == GL_RGB ||
54 img->format == GL_BGR))
55 {
56 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
57 }
58
59 // Load texture
60 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->width,
61 img->height, 0, img->format, GL_UNSIGNED_BYTE,
62 img->pixels);
63 return id;
64}

References igl::opengl::gliGenericImage::format, gliReadTGA(), igl::opengl::gliGenericImage::height, igl::opengl::gliGenericImage::pixels, and igl::opengl::gliGenericImage::width.

+ Here is the call graph for this function:

◆ uniform_type_to_string()

IGL_INLINE std::string igl::opengl::uniform_type_to_string ( const GLenum  type)
11{
12 switch(type)
13 {
14 case GL_FLOAT:
15 return "GL_FLOAT";
16 case GL_FLOAT_VEC2:
17 return "GL_FLOAT_VEC2";
18 case GL_FLOAT_VEC3:
19 return "GL_FLOAT_VEC3";
20 case GL_FLOAT_VEC4:
21 return "GL_FLOAT_VEC4";
22 case GL_INT:
23 return "GL_INT";
24 case GL_INT_VEC2:
25 return "GL_INT_VEC2";
26 case GL_INT_VEC3:
27 return "GL_INT_VEC3";
28 case GL_INT_VEC4:
29 return "GL_INT_VEC4";
30 case GL_BOOL:
31 return "GL_BOOL";
32 case GL_BOOL_VEC2:
33 return "GL_BOOL_VEC2";
34 case GL_BOOL_VEC3:
35 return "GL_BOOL_VEC3";
36 case GL_BOOL_VEC4:
37 return "GL_BOOL_VEC4";
38 case GL_FLOAT_MAT2:
39 return "GL_FLOAT_MAT2";
40 case GL_FLOAT_MAT3:
41 return "GL_FLOAT_MAT3";
42 case GL_FLOAT_MAT4:
43 return "GL_FLOAT_MAT4";
44 case GL_FLOAT_MAT2x3:
45 return "GL_FLOAT_MAT2x3";
46 case GL_FLOAT_MAT2x4:
47 return "GL_FLOAT_MAT2x4";
48 case GL_FLOAT_MAT3x2:
49 return "GL_FLOAT_MAT3x2";
50 case GL_FLOAT_MAT3x4:
51 return "GL_FLOAT_MAT3x4";
52 case GL_FLOAT_MAT4x2:
53 return "GL_FLOAT_MAT4x2";
54 case GL_FLOAT_MAT4x3:
55 return "GL_FLOAT_MAT4x3";
56 case GL_SAMPLER_1D:
57 return "GL_SAMPLER_1D";
58 case GL_SAMPLER_2D:
59 return "GL_SAMPLER_2D";
60 case GL_SAMPLER_3D:
61 return "GL_SAMPLER_3D";
62 case GL_SAMPLER_CUBE:
63 return "GL_SAMPLER_CUBE";
64 case GL_SAMPLER_1D_SHADOW:
65 return "GL_SAMPLER_1D_SHADOW";
66 case GL_SAMPLER_2D_SHADOW:
67 return "GL_SAMPLER_2D_SHADOW";
68 default:
69 return "UNKNOWN_TYPE";
70 }
71}

◆ vertex_array()

template<typename DerivedV , typename DerivedF >
IGL_INLINE void igl::opengl::vertex_array ( const Eigen::PlainObjectBase< DerivedV > &  V,
const Eigen::PlainObjectBase< DerivedF > &  F,
GLuint va_id,
GLuint ab_id,
GLuint eab_id 
)
13{
14 // Inputs should be in RowMajor storage. If not, we have no choice but to
15 // create a copy.
16 if(!(V.Options & Eigen::RowMajor))
17 {
19 typename DerivedV::Scalar,
20 DerivedV::RowsAtCompileTime,
21 DerivedV::ColsAtCompileTime,
22 Eigen::RowMajor> VR = V;
23 return vertex_array(VR,F,va_id,ab_id,eab_id);
24 }
25 if(!(F.Options & Eigen::RowMajor))
26 {
28 typename DerivedF::Scalar,
29 DerivedF::RowsAtCompileTime,
30 DerivedF::ColsAtCompileTime,
31 Eigen::RowMajor> FR = F;
32 return vertex_array(V,FR,va_id,ab_id,eab_id);
33 }
34 // Generate and attach buffers to vertex array
35 glGenVertexArrays(1, &va_id);
36 glGenBuffers(1, &ab_id);
37 glGenBuffers(1, &eab_id);
38 glBindVertexArray(va_id);
39 glBindBuffer(GL_ARRAY_BUFFER, ab_id);
40 const auto size_VScalar = sizeof(typename DerivedV::Scalar);
41 const auto size_FScalar = sizeof(typename DerivedF::Scalar);
42 glBufferData(GL_ARRAY_BUFFER,size_VScalar*V.size(),V.data(),GL_STATIC_DRAW);
43 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eab_id);
44 assert(sizeof(GLuint) == size_FScalar && "F type does not match GLuint");
45 glBufferData(
46 GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*F.size(), F.data(), GL_STATIC_DRAW);
47 glVertexAttribPointer(
48 0,
49 V.cols(),
50 size_VScalar==sizeof(float)?GL_FLOAT:GL_DOUBLE,
52 V.cols()*size_VScalar,
53 (GLvoid*)0);
54 glEnableVertexAttribArray(0);
55 glBindBuffer(GL_ARRAY_BUFFER, 0);
56 glBindVertexArray(0);
57}
@ Options
Definition PlainObjectBase.h:102
void GLvoid
Definition glu-libtess.h:67
IGL_INLINE void vertex_array(const Eigen::PlainObjectBase< DerivedV > &V, const Eigen::PlainObjectBase< DerivedF > &F, GLuint &va_id, GLuint &ab_id, GLuint &eab_id)
Definition vertex_array.cpp:7

References Eigen::PlainObjectBase< Derived >::cols(), Eigen::PlainObjectBase< Derived >::data(), GL_FALSE, Eigen::PlainObjectBase< Derived >::Options, Eigen::RowMajor, and vertex_array().

Referenced by vertex_array().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeTGA()

IGL_INLINE void igl::opengl::writeTGA ( gliGenericImage image,
FILE *  fp 
)
515 {
516
517 assert(!image->cmap); // we do not deal with color map images
518
519 if(image->components == 3 || image->components == 4)
520 fwrite(TGAHeaderColor, 12, sizeof(unsigned char),fp);
521 else {
522 if(image->components == 1 )
523 fwrite(TGAHeaderBW, 12, sizeof(unsigned char),fp);
524 else { fprintf(stderr,"Supported component number: 1,3 or 4\n"); exit(1); }
525 }
526
527 write16bit(image->width,fp);
528 write16bit(image->height,fp);
529 switch (image->components ) {
530 case 1:
531 putc(8,fp);
532 break;
533 case 3:
534 putc(24,fp);
535 break;
536 case 4:
537 putc(32,fp);
538 break;
539 default: fprintf(stderr,"Supported component number: 1,3 or 4\n"); exit(1);
540 };
541
542 if(image-> components == 4)
543 putc(0x04,fp); // bottom left image (0x00) + 8 bit alpha (0x4)
544 else
545 putc(0x00,fp);
546
547 fwrite(image->pixels, image->height*image->width*image->components, sizeof(char),fp);
548}
unsigned char TGAHeaderColor[12]
Definition tga.cpp:487
IGL_INLINE void write16bit(int n, FILE *fp)
Definition tga.cpp:508
unsigned char TGAHeaderBW[12]
Definition tga.cpp:496

References igl::opengl::gliGenericImage::cmap, igl::components(), igl::opengl::gliGenericImage::components, igl::opengl::gliGenericImage::height, igl::opengl::gliGenericImage::pixels, TGAHeaderBW, TGAHeaderColor, igl::opengl::gliGenericImage::width, and write16bit().

Referenced by render_to_tga().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: