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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/toolx/sg/gl (Version 11.3.0) and /externals/g4tools/include/toolx/sg/gl (Version 11.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef toolx_sg_gl                                 4 #ifndef toolx_sg_gl
  5 #define toolx_sg_gl                                 5 #define toolx_sg_gl
  6                                                     6 
  7 #include "../OpenGL"                                7 #include "../OpenGL"
  8                                                     8 
  9 #include <tools/platform> //for APPLE TargetCo      9 #include <tools/platform> //for APPLE TargetConditionals.h
 10 #include <tools/img>                               10 #include <tools/img>
 11                                                    11 
 12 #include <ostream>                                 12 #include <ostream>
 13 #include <sstream>                                 13 #include <sstream>
 14                                                    14 
 15 namespace toolx {                                  15 namespace toolx {
 16 namespace sg {                                     16 namespace sg {
 17 //namespace gl : no, problem with g4tools.         17 //namespace gl : no, problem with g4tools.
 18                                                    18 
 19 inline void gl_clear_errors() {                    19 inline void gl_clear_errors() {
 20   GLenum glerror = ::glGetError();                 20   GLenum glerror = ::glGetError();
 21   while(glerror!=GL_NO_ERROR) {                    21   while(glerror!=GL_NO_ERROR) {
 22     glerror = ::glGetError();                      22     glerror = ::glGetError();
 23   }                                                23   }
 24 }                                                  24 }
 25                                                    25 
 26 inline bool gl_dump_if_errors(std::ostream& a_     26 inline bool gl_dump_if_errors(std::ostream& a_out,const std::string& a_head) {
 27   bool retval = false;                             27   bool retval = false;
 28   GLenum glerror = ::glGetError();                 28   GLenum glerror = ::glGetError();
 29   if(glerror!=GL_NO_ERROR) {                       29   if(glerror!=GL_NO_ERROR) {
 30     a_out << a_head                                30     a_out << a_head
 31           << " we have gl errors :"                31           << " we have gl errors :"
 32           << std::endl;                            32           << std::endl;
 33     retval = true;                                 33     retval = true;
 34   }                                                34   }
 35   while(glerror!=GL_NO_ERROR) {                    35   while(glerror!=GL_NO_ERROR) {
 36     //#define GL_NO_ERROR                          36     //#define GL_NO_ERROR                       0
 37     //#define GL_INVALID_ENUM                      37     //#define GL_INVALID_ENUM                   0x0500
 38     //#define GL_INVALID_VALUE                     38     //#define GL_INVALID_VALUE                  0x0501
 39     //#define GL_INVALID_OPERATION                 39     //#define GL_INVALID_OPERATION              0x0502
 40     //#define GL_STACK_OVERFLOW                    40     //#define GL_STACK_OVERFLOW                 0x0503
 41     //#define GL_STACK_UNDERFLOW                   41     //#define GL_STACK_UNDERFLOW                0x0504
 42     //#define GL_OUT_OF_MEMORY                     42     //#define GL_OUT_OF_MEMORY                  0x0505
 43                                                    43 
 44     //#define GL_INVALID_FRAMEBUFFER_OPERATION     44     //#define GL_INVALID_FRAMEBUFFER_OPERATION  0x0506
 45                                                    45 
 46     std::ostringstream oss;                        46     std::ostringstream oss;
 47     oss << "0x" << std::hex << glerror;            47     oss << "0x" << std::hex << glerror;
 48     a_out << oss.str() << std::endl;               48     a_out << oss.str() << std::endl;
 49                                                    49 
 50     glerror = ::glGetError();                      50     glerror = ::glGetError();
 51   }                                                51   }
 52   return retval;                                   52   return retval;
 53 }                                                  53 }
 54                                                    54 
 55 inline void gl_dump_infos(std::ostream& a_out)     55 inline void gl_dump_infos(std::ostream& a_out) {
 56     std::string gl_version;                        56     std::string gl_version;
 57    {const char* _sv = (const char*)::glGetStri     57    {const char* _sv = (const char*)::glGetString(GL_VERSION);
 58     if(_sv) gl_version = _sv;}                     58     if(_sv) gl_version = _sv;}
 59                                                    59 
 60     std::string gl_vendor;                         60     std::string gl_vendor;
 61    {const char* _sv = (const char*)::glGetStri     61    {const char* _sv = (const char*)::glGetString(GL_VENDOR);
 62     if(_sv) gl_vendor = _sv;}                      62     if(_sv) gl_vendor = _sv;}
 63                                                    63 
 64     std::string gl_renderer;                       64     std::string gl_renderer;
 65    {const char* _sv = (const char*)::glGetStri     65    {const char* _sv = (const char*)::glGetString(GL_RENDERER);
 66     if(_sv) gl_renderer = _sv;}                    66     if(_sv) gl_renderer = _sv;}
 67                                                    67 
 68     std::string gl_extensions;                     68     std::string gl_extensions;
 69    {const char* _sv = (const char*)::glGetStri     69    {const char* _sv = (const char*)::glGetString(GL_EXTENSIONS);
 70     if(_sv) gl_extensions = _sv;}                  70     if(_sv) gl_extensions = _sv;}
 71                                                    71 
 72     GLint gl_texture_size;                         72     GLint gl_texture_size;
 73     ::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_t     73     ::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_texture_size);
 74                                                    74 
 75     //GLint gl_buffer_size;                        75     //GLint gl_buffer_size;
 76     //::glGetIntegerv(GL_BUFFER_SIZE, &gl_buff     76     //::glGetIntegerv(GL_BUFFER_SIZE, &gl_buffer_size);
 77                                                    77 
 78     a_out << "toolx::sg::gl::dump_infos :" <<      78     a_out << "toolx::sg::gl::dump_infos :" << std::endl;
 79     a_out << " GL_VERSION " << gl_version << s     79     a_out << " GL_VERSION " << gl_version << std::endl;
 80     a_out << " GL_VENDOR " << gl_vendor << std     80     a_out << " GL_VENDOR " << gl_vendor << std::endl;
 81     a_out << " GL_RENDERER " << gl_renderer <<     81     a_out << " GL_RENDERER " << gl_renderer << std::endl;
 82     a_out << " GL_EXTENSIONS " << gl_extension     82     a_out << " GL_EXTENSIONS " << gl_extensions << std::endl;
 83     a_out << " GL_MAX_TEXTURE_SIZE " << gl_tex     83     a_out << " GL_MAX_TEXTURE_SIZE " << gl_texture_size << std::endl;
 84     //a_out << " GL_BUFFER_SIZE " << gl_buffer     84     //a_out << " GL_BUFFER_SIZE " << gl_buffer_size << std::endl;
 85 }                                                  85 }
 86                                                    86 
 87 inline bool gl_tex_img(std::ostream& a_out,con     87 inline bool gl_tex_img(std::ostream& a_out,const tools::img_byte& a_img) {
 88     if(a_img.bpp()==1) {                           88     if(a_img.bpp()==1) {
 89       //to pass eiffel-tower.png                   89       //to pass eiffel-tower.png
 90 #if defined(ANDROID) || TARGET_OS_IPHONE           90 #if defined(ANDROID) || TARGET_OS_IPHONE
 91       tools::img_byte res;                         91       tools::img_byte res;
 92       if(!a_img.bw2x(3,res)) {                     92       if(!a_img.bw2x(3,res)) {
 93         a_out << "toolx::sg::gl::tex_img : too     93         a_out << "toolx::sg::gl::tex_img : tools::img.bw2x() failed." << std::endl;
 94         return false;                              94         return false;
 95       }                                            95       }
 96       ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,re     96       ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,res.width(),res.height(),0,GL_RGB,GL_UNSIGNED_BYTE,res.buffer());
 97 #else                                              97 #else
 98       ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,a_     98       ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,a_img.width(),a_img.height(),0,GL_LUMINANCE,GL_UNSIGNED_BYTE,a_img.buffer());
 99 #endif                                             99 #endif
100     } else if(a_img.bpp()==3) {                   100     } else if(a_img.bpp()==3) {
101       ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,a_    101       ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,a_img.width(),a_img.height(),0,GL_RGB,GL_UNSIGNED_BYTE,a_img.buffer());
102     } else if(a_img.bpp()==4) {                   102     } else if(a_img.bpp()==4) {
103       ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,a    103       ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,a_img.width(),a_img.height(),0,GL_RGBA,GL_UNSIGNED_BYTE,a_img.buffer());
104     } else {                                      104     } else {
105       a_out << "toolx::sg::gl::tex_img : img.b    105       a_out << "toolx::sg::gl::tex_img : img.bpp() " << a_img.bpp() << " not treated." << std::endl;
106       return false;                               106       return false;
107     }                                             107     }
108     return true;                                  108     return true;
109 }                                                 109 }
110                                                   110 
111 }}                                                111 }}
112                                                   112 
113                                                   113 
114 #endif                                            114 #endif