/
InteractionPass.h
73 lines (57 loc) · 1.69 KB
/
InteractionPass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "OpenGLShaderPass.h"
#include "glprogram/InteractionProgram.h"
namespace render
{
class OpenGLRenderSystem;
class GLProgramFactory;
/**
* Lighting Interaction pass (Diffuse/Bump/Specular).
*/
class InteractionPass :
public OpenGLShaderPass
{
public:
// An interaction stage prepared for rendering
struct Stage
{
IShaderLayer::Ptr stage;
GLuint texture;
};
private:
std::vector<Stage> _interactionStages;
GLuint _defaultDiffuseTexture;
GLuint _defaultBumpTexture;
GLuint _defaultSpecularTexture;
public:
InteractionPass(OpenGLShader& owner, OpenGLRenderSystem& renderSystem, std::vector<IShaderLayer::Ptr>& stages);
InteractionProgram& getProgram()
{
return *static_cast<InteractionProgram*>(_glState.glProgram);
}
Matrix4 getDiffuseTextureTransform() const
{
return GetTextureTransformFromStage(state().stage0);
}
Matrix4 getBumpTextureTransform() const
{
return GetTextureTransformFromStage(state().stage1);
}
Matrix4 getSpecularTextureTransform() const
{
return GetTextureTransformFromStage(state().stage2);
}
const std::vector<Stage>& getInteractionStages() const
{
return _interactionStages;
}
GLuint getDefaultInteractionTextureBinding(IShaderLayer::Type type);
// Generates the state with all the required flags for drawing interaction passes
static OpenGLState GenerateInteractionState(GLProgramFactory& programFactory);
private:
inline static Matrix4 GetTextureTransformFromStage(const IShaderLayer::Ptr& stage)
{
return stage ? stage->getTextureTransform() : Matrix4::getIdentity();
}
};
}