~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/COpenGLSLMaterialRenderer.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 
 
5
#ifndef __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__
 
6
#define __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__
 
7
 
 
8
#include "IrrCompileConfig.h"
 
9
#ifdef _IRR_COMPILE_WITH_OPENGL_
 
10
 
 
11
#ifdef _IRR_WINDOWS_API_
 
12
        #define WIN32_LEAN_AND_MEAN
 
13
        #include <windows.h>
 
14
        #include <GL/gl.h>
 
15
        #include "glext.h"
 
16
#else
 
17
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
 
18
        #define GL_GLEXT_LEGACY 1
 
19
#else
 
20
        #define GL_GLEXT_PROTOTYPES 1
 
21
#endif
 
22
#if defined(_IRR_OSX_PLATFORM_)
 
23
        #include <OpenGL/gl.h>
 
24
#else
 
25
        #include <GL/gl.h>
 
26
#endif
 
27
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
 
28
        #include "glext.h"
 
29
#endif
 
30
#endif
 
31
 
 
32
 
 
33
#include "IMaterialRenderer.h"
 
34
#include "IMaterialRendererServices.h"
 
35
#include "IGPUProgrammingServices.h"
 
36
#include "irrArray.h"
 
37
#include "irrString.h"
 
38
 
 
39
namespace irr
 
40
{
 
41
namespace video  
 
42
{
 
43
 
 
44
class COpenGLDriver;
 
45
class IShaderConstantSetCallBack;
 
46
 
 
47
//! Class for using GLSL shaders with OpenGL
 
48
//! Please note: This renderer implements its own IMaterialRendererServices
 
49
class COpenGLSLMaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices
 
50
{
 
51
public:
 
52
 
 
53
        //! Constructor
 
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,
 
68
                u32 verticesOut = 0,
 
69
                IShaderConstantSetCallBack* callback = 0,
 
70
                IMaterialRenderer* baseMaterial = 0,
 
71
                s32 userData = 0);
 
72
 
 
73
        //! Destructor
 
74
        virtual ~COpenGLSLMaterialRenderer();
 
75
 
 
76
        virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
 
77
                bool resetAllRenderstates, IMaterialRendererServices* services);
 
78
 
 
79
        virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
 
80
 
 
81
        virtual void OnUnsetMaterial();
 
82
 
 
83
        //! Returns if the material is transparent.
 
84
        virtual bool isTransparent() const;
 
85
 
 
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();
 
93
 
 
94
protected:
 
95
 
 
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,
 
101
                                        s32 userData=0);
 
102
 
 
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,
 
109
                u32 verticesOut=0);
 
110
 
 
111
        bool createProgram();
 
112
        bool createShader(GLenum shaderType, const char* shader);
 
113
        bool linkProgram();
 
114
        
 
115
        COpenGLDriver* Driver;
 
116
        IShaderConstantSetCallBack* CallBack;
 
117
        IMaterialRenderer* BaseMaterial;
 
118
 
 
119
        struct SUniformInfo
 
120
        {
 
121
                core::stringc name;
 
122
                GLenum type;
 
123
        };
 
124
 
 
125
        GLhandleARB Program;
 
126
        GLuint Program2;
 
127
        core::array<SUniformInfo> UniformInfo;
 
128
        s32 UserData;
 
129
};
 
130
 
 
131
 
 
132
} // end namespace video
 
133
} // end namespace irr
 
134
 
 
135
#endif // compile with OpenGL
 
136
#endif // if included
 
137