aboutsummaryrefslogtreecommitdiff
path: root/source/Irrlicht/OpenGL/MaterialRenderer.h
blob: f9282ccb36f8fa2f7d0a435ee0a93647b7e35b6e (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (C) 2014 Patryk Nadrowski
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#pragma once

#include "EMaterialTypes.h"
#include "IMaterialRenderer.h"
#include "IMaterialRendererServices.h"
#include "IGPUProgrammingServices.h"
#include "irrArray.h"
#include "irrString.h"

#include "Common.h"

namespace irr
{
namespace video
{

class COpenGL3DriverBase;

class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices
{
public:

	COpenGL3MaterialRenderer(
		COpenGL3DriverBase* driver,
		s32& outMaterialTypeNr,
		const c8* vertexShaderProgram = 0,
		const c8* pixelShaderProgram = 0,
		IShaderConstantSetCallBack* callback = 0,
		E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
		s32 userData = 0);

	virtual ~COpenGL3MaterialRenderer();

	GLuint getProgram() const;

	virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
		bool resetAllRenderstates, IMaterialRendererServices* services);

	virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);

	virtual void OnUnsetMaterial();

	virtual bool isTransparent() const;

	virtual s32 getRenderCapability() const;

	void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) override;

	s32 getVertexShaderConstantID(const c8* name) override;
	s32 getPixelShaderConstantID(const c8* name) override;
	void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override;
	void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) override;
	bool setVertexShaderConstant(s32 index, const f32* floats, int count) override;
	bool setVertexShaderConstant(s32 index, const s32* ints, int count) override;
	bool setVertexShaderConstant(s32 index, const u32* ints, int count) override;
	bool setPixelShaderConstant(s32 index, const f32* floats, int count) override;
	bool setPixelShaderConstant(s32 index, const s32* ints, int count) override;
	bool setPixelShaderConstant(s32 index, const u32* ints, int count) override;

	IVideoDriver* getVideoDriver() override;

protected:

	COpenGL3MaterialRenderer(COpenGL3DriverBase* driver,
					IShaderConstantSetCallBack* callback = 0,
					E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
					s32 userData = 0);

	void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, bool addMaterial = true);

	bool createShader(GLenum shaderType, const char* shader);
	bool linkProgram();

	COpenGL3DriverBase* Driver;
	IShaderConstantSetCallBack* CallBack;

	bool Alpha;
	bool Blending;
	bool FixedBlending;

	struct SUniformInfo
	{
		core::stringc name;
		GLenum type;
		GLint location;
	};

	GLuint Program;
	core::array<SUniformInfo> UniformInfo;
	s32 UserData;
};


}
}