1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__
6
#define __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__
8
#include "IrrCompileConfig.h"
9
#ifdef _IRR_COMPILE_WITH_OPENGL_
11
#ifdef _IRR_WINDOWS_API_
12
#define WIN32_LEAN_AND_MEAN
17
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
18
#define GL_GLEXT_LEGACY 1
20
#define GL_GLEXT_PROTOTYPES 1
22
#if defined(_IRR_OSX_PLATFORM_)
23
#include <OpenGL/gl.h>
27
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
33
#include "IMaterialRenderer.h"
34
#include "IMaterialRendererServices.h"
35
#include "IGPUProgrammingServices.h"
37
#include "irrString.h"
45
class IShaderConstantSetCallBack;
47
//! Class for using GLSL shaders with OpenGL
48
//! Please note: This renderer implements its own IMaterialRendererServices
49
class COpenGLSLMaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices
54
COpenGLSLMaterialRenderer(
55
COpenGLDriver* driver,
56
s32& outMaterialTypeNr,
57
const c8* vertexShaderProgram = 0,
58
const c8* vertexShaderEntryPointName = 0,
59
E_VERTEX_SHADER_TYPE vsCompileTarget = video::EVST_VS_1_1,
60
const c8* pixelShaderProgram = 0,
61
const c8* pixelShaderEntryPointName = 0,
62
E_PIXEL_SHADER_TYPE psCompileTarget = video::EPST_PS_1_1,
63
const c8* geometryShaderProgram = 0,
64
const c8* geometryShaderEntryPointName = "main",
65
E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
66
scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
67
scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
69
IShaderConstantSetCallBack* callback = 0,
70
IMaterialRenderer* baseMaterial = 0,
74
virtual ~COpenGLSLMaterialRenderer();
76
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
77
bool resetAllRenderstates, IMaterialRendererServices* services);
79
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
81
virtual void OnUnsetMaterial();
83
//! Returns if the material is transparent.
84
virtual bool isTransparent() const;
86
// implementations for the render services
87
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates);
88
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
89
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
90
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
91
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
92
virtual IVideoDriver* getVideoDriver();
96
//! constructor only for use by derived classes who want to
97
//! create a fall back material for example.
98
COpenGLSLMaterialRenderer(COpenGLDriver* driver,
99
IShaderConstantSetCallBack* callback,
100
IMaterialRenderer* baseMaterial,
103
void init(s32& outMaterialTypeNr,
104
const c8* vertexShaderProgram,
105
const c8* pixelShaderProgram,
106
const c8* geometryShaderProgram,
107
scene::E_PRIMITIVE_TYPE inType=scene::EPT_TRIANGLES,
108
scene::E_PRIMITIVE_TYPE outType=scene::EPT_TRIANGLE_STRIP,
111
bool createProgram();
112
bool createShader(GLenum shaderType, const char* shader);
115
COpenGLDriver* Driver;
116
IShaderConstantSetCallBack* CallBack;
117
IMaterialRenderer* BaseMaterial;
127
core::array<SUniformInfo> UniformInfo;
132
} // end namespace video
133
} // end namespace irr
135
#endif // compile with OpenGL
136
#endif // if included