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
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
00064
#endif
00065
00066
#endif
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
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
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