Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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 "ShVariableType.hpp"
00031 #include "ShProgram.hpp"
00032 #include "ShStream.hpp"
00033 #include "ShTextureNode.hpp"
00034 
00035 #ifdef WIN32
00036 
00037 #include <windows.h>
00038 
00039 #include <GL/gl.h>
00040 #include <GL/glext.h>
00041 #include <GL/wglext.h>
00042 
00043 extern PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
00044 extern PFNGLBINDPROGRAMARBPROC glBindProgramARB;
00045 extern PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
00046 extern PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB;
00047 extern PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
00048 extern PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
00049 extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
00050 
00051 extern PFNGLTEXIMAGE3DPROC glTexImage3D;
00052 extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D;
00053 
00054 // WGL_ARB_pixel_format
00055 extern PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB;
00056 extern PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB;
00057 extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
00058 
00059 // WGL_ARB_pbuffer
00060 extern PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB;
00061 extern PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB;
00062 extern PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB;
00063 extern PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB;
00064 extern PFNWGLQUERYPBUFFERARBPROC wglQueryPbufferARB;
00065 
00066 #else
00067 
00068 #define GL_GLEXT_VERBOSE 1
00069 #define GL_GLEXT_PROTOTYPES 1
00070 
00071 #ifdef __APPLE__
00072 #include <OpenGL/OpenGL.h>
00073 #include <OpenGL/gl.h>
00074 #include <OpenGL/glext.h>
00075 #else
00076 #include <GL/gl.h>
00077 #include <GL/glext.h>
00078 #include <GL/glx.h>
00079 #endif /* __APPLE */
00080 
00081 #endif /* WIN32 */
00082 
00083 namespace shgl {
00084 
00085 struct TextureStrategy {
00086   virtual TextureStrategy* create(void) = 0;
00087   
00088   virtual void bindTexture(const SH::ShTextureNodePtr& texture,
00089                            GLenum target) = 0;
00090 };
00091 
00092 struct StreamStrategy {
00093   virtual StreamStrategy* create(void) = 0;
00094   virtual void execute(const SH::ShProgramNodeCPtr& program, SH::ShStream& dest) = 0;
00095 };
00096 
00097 struct CodeStrategy {
00098   virtual CodeStrategy* create(void) = 0;
00099   virtual SH::ShBackendCodePtr generate(const std::string& target,
00100                                         const SH::ShProgramNodeCPtr& shader,
00101                                         TextureStrategy* texture) = 0;
00102 };
00103 
00104 class GlBackend : public SH::ShBackend {
00105 public:
00106   virtual SH::ShBackendCodePtr generateCode(const std::string& target,
00107                                             const SH::ShProgramNodeCPtr& shader);
00108 
00109   // execute a stream program, if supported
00110   virtual void execute(const SH::ShProgramNodeCPtr& program, SH::ShStream& dest);
00111 
00112 protected:
00113   GlBackend(CodeStrategy* code, TextureStrategy* texture, StreamStrategy* stream);
00114   
00115 private:
00116   CodeStrategy* m_code;
00117   TextureStrategy* m_texture;
00118   StreamStrategy* m_stream;
00119 
00120   // NOT IMPLEMENTED
00121   GlBackend(const GlBackend& other);
00122   GlBackend& operator=(const GlBackend& other);
00123 };
00124 
00125 void shGlCheckError(const char* desc, const char* file, int line);
00126 
00127 /* Returns glReadPixels/glTexImage type for a given value type 
00128  * and returns a value type for the temporary buffer
00129  * (or SH_VALUETYPE_END if we can use the original buffer directly) 
00130  */
00131 GLenum shGlType(SH::ShValueType valueType, SH::ShValueType &convertedType); 
00132 
00133 }
00134 
00135 #define SH_GL_CHECK_ERROR(op) \
00136   op;shGlCheckError( # op, (char*) __FILE__, (int) __LINE__);
00137 
00138 
00139 
00140 #endif

Generated on Mon Jan 24 18:36:29 2005 for Sh by  doxygen 1.4.1