Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

GlBackend.hpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #ifndef GLBACKEND_HPP 00028 #define GLBACKEND_HPP 00029 00030 #include "ShProgram.hpp" 00031 #include "ShStream.hpp" 00032 #include "ShTextureNode.hpp" 00033 00034 #ifdef WIN32 00035 00036 #include <windows.h> 00037 00038 #include <GL/gl.h> 00039 #include <GL/glext.h> 00040 #include <GL/wglext.h> 00041 00042 extern PFNGLPROGRAMSTRINGARBPROC glProgramStringARB; 00043 extern PFNGLBINDPROGRAMARBPROC glBindProgramARB; 00044 extern PFNGLGENPROGRAMSARBPROC glGenProgramsARB; 00045 extern PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB; 00046 extern PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB; 00047 extern PFNGLGETPROGRAMIVARBPROC glGetProgramivARB; 00048 extern PFNGLTEXIMAGE3DPROC glTexImage3D; 00049 extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; 00050 00051 // WGL_ARB_pixel_format 00052 extern PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB; 00053 extern PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB; 00054 extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; 00055 00056 // WGL_ARB_pbuffer 00057 extern PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB; 00058 extern PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB; 00059 extern PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB; 00060 extern PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB; 00061 extern PFNWGLQUERYPBUFFERARBPROC wglQueryPbufferARB; 00062 00063 #else 00064 00065 #define GL_GLEXT_VERBOSE 1 00066 #define GL_GLEXT_PROTOTYPES 1 00067 00068 #ifdef __APPLE__ 00069 #include <OpenGL/OpenGL.h> 00070 #include <OpenGL/gl.h> 00071 #include <OpenGL/glext.h> 00072 #else 00073 #include <GL/gl.h> 00074 #include <GL/glext.h> 00075 #include <GL/glx.h> 00076 #endif /* __APPLE */ 00077 00078 #endif /* WIN32 */ 00079 00080 namespace shgl { 00081 00082 struct TextureStrategy { 00083 virtual TextureStrategy* create(void) = 0; 00084 00085 virtual void bindTexture(const SH::ShTextureNodePtr& texture, 00086 GLenum target) = 0; 00087 }; 00088 00089 struct StreamStrategy { 00090 virtual StreamStrategy* create(void) = 0; 00091 virtual void execute(const SH::ShProgramNodeCPtr& program, SH::ShStream& dest) = 0; 00092 }; 00093 00094 struct CodeStrategy { 00095 virtual CodeStrategy* create(void) = 0; 00096 virtual SH::ShBackendCodePtr generate(const std::string& target, 00097 const SH::ShProgramNodeCPtr& shader, 00098 TextureStrategy* texture) = 0; 00099 }; 00100 00101 class GlBackend : public SH::ShBackend { 00102 public: 00103 virtual SH::ShBackendCodePtr generateCode(const std::string& target, 00104 const SH::ShProgramNodeCPtr& shader); 00105 00106 // execute a stream program, if supported 00107 virtual void execute(const SH::ShProgramNodeCPtr& program, SH::ShStream& dest); 00108 00109 protected: 00110 GlBackend(CodeStrategy* code, TextureStrategy* texture, StreamStrategy* stream); 00111 00112 private: 00113 CodeStrategy* m_code; 00114 TextureStrategy* m_texture; 00115 StreamStrategy* m_stream; 00116 00117 // NOT IMPLEMENTED 00118 GlBackend(const GlBackend& other); 00119 GlBackend& operator=(const GlBackend& other); 00120 }; 00121 00122 void shGlCheckError(const char* desc, const char* file, int line); 00123 00124 } 00125 00126 #define SH_GL_CHECK_ERROR(op) \ 00127 op;shGlCheckError( # op, (char*) __FILE__, (int) __LINE__); 00128 00129 00130 00131 #endif

Generated on Fri Nov 5 16:51:19 2004 for Sh by doxygen 1.3.7