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