00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00055 extern PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB;
00056 extern PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB;
00057 extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
00058
00059
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
00080
00081 #endif
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
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
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
00128
00129
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