1 // Copyright (C) 2002-2012 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_MATERIAL_RENDERER_H_INCLUDED__
6 #define __C_OPENGL_SHADER_MATERIAL_RENDERER_H_INCLUDED__
7 
8 #include "IrrCompileConfig.h"
9 #ifdef _IRR_COMPILE_WITH_OPENGL_
10 
11 #if defined(_IRR_OPENGL_USE_EXTPOINTER_)
12 	#define GL_GLEXT_LEGACY 1
13 #else
14 	#define GL_GLEXT_PROTOTYPES 1
15 #endif
16 #ifdef _IRR_WINDOWS_API_
17 	#define WIN32_LEAN_AND_MEAN
18 	#include <windows.h>
19 	#include <GL/gl.h>
20 #elif defined(_IRR_OSX_PLATFORM_)
21 	#include <OpenGL/gl.h>
22 #elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
23 	#define NO_SDL_GLEXT
24 	#include <SDL/SDL_video.h>
25 	#include <SDL/SDL_opengl.h>
26 #else
27 	#include <GL/gl.h>
28 #endif
29 
30 #include "IMaterialRenderer.h"
31 
32 namespace irr
33 {
34 namespace video
35 {
36 
37 class COpenGLDriver;
38 class IShaderConstantSetCallBack;
39 class IMaterialRenderer;
40 
41 //! Class for using vertex and pixel shaders with OpenGL
42 class COpenGLShaderMaterialRenderer : public IMaterialRenderer
43 {
44 public:
45 
46 	//! Constructor
47 	COpenGLShaderMaterialRenderer(COpenGLDriver* driver,
48 		s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram,
49 		IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData);
50 
51 	//! Destructor
52 	virtual ~COpenGLShaderMaterialRenderer();
53 
54 	virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
55 		bool resetAllRenderstates, IMaterialRendererServices* services);
56 
57 	virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
58 
59 	virtual void OnUnsetMaterial();
60 
61 	//! Returns if the material is transparent.
62 	virtual bool isTransparent() const;
63 
64 protected:
65 
66 	//! constructor only for use by derived classes who want to
67 	//! create a fall back material for example.
68 	COpenGLShaderMaterialRenderer(COpenGLDriver* driver,
69 					IShaderConstantSetCallBack* callback,
70 					IMaterialRenderer* baseMaterial, s32 userData=0);
71 
72 	// must not be called more than once!
73 	void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram,
74 		const c8* pixelShaderProgram, E_VERTEX_TYPE type);
75 
76 	bool createPixelShader(const c8* pxsh);
77 	bool createVertexShader(const c8* vtxsh);
78 	bool checkError(const irr::c8* type);
79 
80 	COpenGLDriver* Driver;
81 	IShaderConstantSetCallBack* CallBack;
82 	IMaterialRenderer* BaseMaterial;
83 
84 	GLuint VertexShader;
85 	// We have 4 values here, [0] is the non-fog version, the other three are
86 	// ARB_fog_linear, ARB_fog_exp, and ARB_fog_exp2 in that order
87 	core::array<GLuint> PixelShader;
88 	s32 UserData;
89 };
90 
91 
92 } // end namespace video
93 } // end namespace irr
94 
95 #endif
96 #endif
97 
98