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 "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
00052
extern PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB;
00053
extern PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB;
00054
extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
00055
00056
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
00077
00078
#endif
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
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
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