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 00041 extern PFNGLPROGRAMSTRINGARBPROC glProgramStringARB; 00042 extern PFNGLBINDPROGRAMARBPROC glBindProgramARB; 00043 extern PFNGLGENPROGRAMSARBPROC glGenProgramsARB; 00044 extern PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB; 00045 extern PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB; 00046 extern PFNGLGETPROGRAMIVARBPROC glGetProgramivARB; 00047 extern PFNGLTEXIMAGE3DPROC glTexImage3D; 00048 extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; 00049 00050 #else 00051 00052 #define GL_GLEXT_VERBOSE 1 00053 #define GL_GLEXT_PROTOTYPES 1 00054 00055 #ifdef __APPLE__ 00056 #include <OpenGL/OpenGL.h> 00057 #include <OpenGL/gl.h> 00058 #include <OpenGL/glext.h> 00059 #else 00060 #include <GL/gl.h> 00061 #include <GL/glext.h> 00062 #include <GL/glx.h> 00063 //#include <GL/glut.h> 00064 #endif /* __APPLE */ 00065 00066 #endif /* WIN32 */ 00067 00068 namespace shgl { 00069 00070 struct TextureStrategy { 00071 virtual TextureStrategy* create(int context) = 0; 00072 00073 virtual void bindTexture(const SH::ShTextureNodePtr& texture, 00074 GLenum target) = 0; 00075 }; 00076 00077 struct StreamStrategy { 00078 virtual StreamStrategy* create(int context) = 0; 00079 virtual void execute(const SH::ShProgramNodeCPtr& program, SH::ShStream& dest) = 0; 00080 }; 00081 00082 struct CodeStrategy { 00083 virtual CodeStrategy* create(int context) = 0; 00084 virtual SH::ShBackendCodePtr generate(const std::string& target, 00085 const SH::ShProgramNodeCPtr& shader, 00086 TextureStrategy* textures) = 0; 00087 }; 00088 00089 class GlBackend : public SH::ShBackend { 00090 public: 00091 virtual SH::ShBackendCodePtr generateCode(const std::string& target, 00092 const SH::ShProgramNodeCPtr& shader); 00093 00094 // execute a stream program, if supported 00095 virtual void execute(const SH::ShProgramNodeCPtr& program, SH::ShStream& dest); 00096 00097 virtual int newContext(); 00098 virtual int context() const; 00099 virtual void setContext(int context); 00100 virtual void destroyContext(); 00101 00102 protected: 00103 GlBackend(CodeStrategy* code, TextureStrategy* texture, 00104 StreamStrategy* stream); 00105 00106 private: 00107 int m_curContext; 00108 00109 struct Context { 00110 Context(CodeStrategy* code, 00111 TextureStrategy* textures, 00112 StreamStrategy* streams) 00113 : code(code), textures(textures), streams(streams) 00114 { 00115 } 00116 00117 CodeStrategy* code; 00118 TextureStrategy* textures; 00119 StreamStrategy* streams; 00120 }; 00121 00122 std::vector<Context> m_contexts; 00123 00124 // NOT IMPLEMENTED 00125 GlBackend(const GlBackend& other); 00126 GlBackend& operator=(const GlBackend& other); 00127 }; 00128 00129 void shGlCheckError(const char* desc, const char* file, int line); 00130 00131 } 00132 00133 #define SH_GL_CHECK_ERROR(op) \ 00134 op;shGlCheckError( # op, (char*) __FILE__, (int) __LINE__); 00135 00136 00137 00138 #endif

Generated on Mon Oct 18 14:17:38 2004 for Sh by doxygen 1.3.7