Warning, /include/Geant4/toolx/sg/gl is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef toolx_sg_gl
0005 #define toolx_sg_gl
0006
0007 #include "../OpenGL"
0008
0009 #include <tools/platform> //for APPLE TargetConditionals.h
0010 #include <tools/img>
0011
0012 #include <ostream>
0013 #include <sstream>
0014
0015 namespace toolx {
0016 namespace sg {
0017 //namespace gl : no, problem with g4tools.
0018
0019 inline void gl_clear_errors() {
0020 GLenum glerror = ::glGetError();
0021 while(glerror!=GL_NO_ERROR) {
0022 glerror = ::glGetError();
0023 }
0024 }
0025
0026 inline bool gl_dump_if_errors(std::ostream& a_out,const std::string& a_head) {
0027 bool retval = false;
0028 GLenum glerror = ::glGetError();
0029 if(glerror!=GL_NO_ERROR) {
0030 a_out << a_head
0031 << " we have gl errors :"
0032 << std::endl;
0033 retval = true;
0034 }
0035 while(glerror!=GL_NO_ERROR) {
0036 //#define GL_NO_ERROR 0
0037 //#define GL_INVALID_ENUM 0x0500
0038 //#define GL_INVALID_VALUE 0x0501
0039 //#define GL_INVALID_OPERATION 0x0502
0040 //#define GL_STACK_OVERFLOW 0x0503
0041 //#define GL_STACK_UNDERFLOW 0x0504
0042 //#define GL_OUT_OF_MEMORY 0x0505
0043
0044 //#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
0045
0046 std::ostringstream oss;
0047 oss << "0x" << std::hex << glerror;
0048 a_out << oss.str() << std::endl;
0049
0050 glerror = ::glGetError();
0051 }
0052 return retval;
0053 }
0054
0055 inline void gl_dump_infos(std::ostream& a_out) {
0056 std::string gl_version;
0057 {const char* _sv = (const char*)::glGetString(GL_VERSION);
0058 if(_sv) gl_version = _sv;}
0059
0060 std::string gl_vendor;
0061 {const char* _sv = (const char*)::glGetString(GL_VENDOR);
0062 if(_sv) gl_vendor = _sv;}
0063
0064 std::string gl_renderer;
0065 {const char* _sv = (const char*)::glGetString(GL_RENDERER);
0066 if(_sv) gl_renderer = _sv;}
0067
0068 std::string gl_extensions;
0069 {const char* _sv = (const char*)::glGetString(GL_EXTENSIONS);
0070 if(_sv) gl_extensions = _sv;}
0071
0072 GLint gl_texture_size;
0073 ::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_texture_size);
0074
0075 //GLint gl_buffer_size;
0076 //::glGetIntegerv(GL_BUFFER_SIZE, &gl_buffer_size);
0077
0078 a_out << "toolx::sg::gl::dump_infos :" << std::endl;
0079 a_out << " GL_VERSION " << gl_version << std::endl;
0080 a_out << " GL_VENDOR " << gl_vendor << std::endl;
0081 a_out << " GL_RENDERER " << gl_renderer << std::endl;
0082 a_out << " GL_EXTENSIONS " << gl_extensions << std::endl;
0083 a_out << " GL_MAX_TEXTURE_SIZE " << gl_texture_size << std::endl;
0084 //a_out << " GL_BUFFER_SIZE " << gl_buffer_size << std::endl;
0085 }
0086
0087 inline bool gl_tex_img(std::ostream& a_out,const tools::img_byte& a_img) {
0088 if(a_img.bpp()==1) {
0089 //to pass eiffel-tower.png
0090 #if defined(ANDROID) || TARGET_OS_IPHONE
0091 tools::img_byte res;
0092 if(!a_img.bw2x(3,res)) {
0093 a_out << "toolx::sg::gl::tex_img : tools::img.bw2x() failed." << std::endl;
0094 return false;
0095 }
0096 ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,res.width(),res.height(),0,GL_RGB,GL_UNSIGNED_BYTE,res.buffer());
0097 #else
0098 ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,a_img.width(),a_img.height(),0,GL_LUMINANCE,GL_UNSIGNED_BYTE,a_img.buffer());
0099 #endif
0100 } else if(a_img.bpp()==3) {
0101 ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,a_img.width(),a_img.height(),0,GL_RGB,GL_UNSIGNED_BYTE,a_img.buffer());
0102 } else if(a_img.bpp()==4) {
0103 ::glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,a_img.width(),a_img.height(),0,GL_RGBA,GL_UNSIGNED_BYTE,a_img.buffer());
0104 } else {
0105 a_out << "toolx::sg::gl::tex_img : img.bpp() " << a_img.bpp() << " not treated." << std::endl;
0106 return false;
0107 }
0108 return true;
0109 }
0110
0111 }}
0112
0113
0114 #endif