1 // rendcontext.h 2 // 3 // Copyright (C) 2004-2006, Chris Laurel <claurel@shatters.net> 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 2 8 // of the License, or (at your option) any later version. 9 10 #ifndef _CELENGINE_RENDCONTEXT_H_ 11 #define _CELENGINE_RENDCONTEXT_H_ 12 13 #include <celmath/quaternion.h> 14 #include "mesh.h" 15 #include "shadermanager.h" 16 17 18 class RenderContext 19 { 20 public: 21 RenderContext(const Mesh::Material*); 22 RenderContext(); ~RenderContext()23 virtual ~RenderContext() {}; 24 25 virtual void makeCurrent(const Mesh::Material&) = 0; 26 virtual void setVertexArrays(const Mesh::VertexDescription& desc, 27 void* vertexData) = 0; 28 virtual void drawGroup(const Mesh::PrimitiveGroup& group); 29 30 const Mesh::Material* getMaterial() const; 31 void setMaterial(const Mesh::Material*); lock()32 void lock() { locked = true; } unlock()33 void unlock() { locked = false; } isLocked()34 bool isLocked() const { return locked; } 35 36 enum RenderPass 37 { 38 PrimaryPass, 39 EmissivePass, 40 }; 41 getRenderPass()42 RenderPass getRenderPass() const { return renderPass; } setRenderPass(RenderPass rp)43 void setRenderPass(RenderPass rp) { renderPass = rp; } 44 45 void setPointScale(float); 46 float getPointScale() const; 47 48 void setCameraOrientation(const Quatf& q); 49 Quatf getCameraOrientation() const; 50 51 private: 52 const Mesh::Material* material; 53 bool locked; 54 RenderPass renderPass; 55 float pointScale; 56 Quatf cameraOrientation; // required for drawing billboards 57 58 protected: 59 bool usePointSize; 60 bool useNormals; 61 bool useColors; 62 bool useTexCoords; 63 }; 64 65 66 class FixedFunctionRenderContext : public RenderContext 67 { 68 public: 69 FixedFunctionRenderContext(const Mesh::Material*); 70 FixedFunctionRenderContext(); 71 virtual ~FixedFunctionRenderContext(); 72 73 virtual void makeCurrent(const Mesh::Material&); 74 virtual void setVertexArrays(const Mesh::VertexDescription& desc, 75 void* vertexData); 76 void setLighting(bool); 77 78 private: 79 Mesh::BlendMode blendMode; 80 bool specularOn; 81 bool lightingEnabled; 82 }; 83 84 85 class VP_FP_RenderContext : public RenderContext 86 { 87 public: 88 VP_FP_RenderContext(); 89 VP_FP_RenderContext(const Mesh::Material*); 90 91 virtual void makeCurrent(const Mesh::Material&); 92 virtual void setVertexArrays(const Mesh::VertexDescription& desc, 93 void* vertexData); 94 }; 95 96 97 class VP_Combiner_RenderContext : public RenderContext 98 { 99 public: 100 VP_Combiner_RenderContext(); 101 VP_Combiner_RenderContext(const Mesh::Material*); 102 103 virtual void makeCurrent(const Mesh::Material&); 104 virtual void setVertexArrays(const Mesh::VertexDescription& desc, 105 void* vertexData); 106 }; 107 108 109 class GLSL_RenderContext : public RenderContext 110 { 111 public: 112 GLSL_RenderContext(const LightingState& ls, float _objRadius, const Mat4f& _xform); 113 virtual ~GLSL_RenderContext(); 114 115 virtual void makeCurrent(const Mesh::Material&); 116 virtual void setVertexArrays(const Mesh::VertexDescription& desc, 117 void* vertexData); 118 119 virtual void setLunarLambert(float); 120 virtual void setAtmosphere(const Atmosphere*); 121 122 private: 123 void initLightingEnvironment(); 124 void setLightingParameters(CelestiaGLProgram& prog, Color diffuseColor, Color specularColor); 125 void setShadowParameters(CelestiaGLProgram& prog); 126 127 private: 128 const LightingState& lightingState; 129 const Atmosphere* atmosphere; 130 Mesh::BlendMode blendMode; 131 float objRadius; 132 Mat4f xform; 133 134 // extended material properties 135 float lunarLambert; 136 137 ShaderProperties shaderProps; 138 }; 139 140 141 class GLSLUnlit_RenderContext : public RenderContext 142 { 143 public: 144 GLSLUnlit_RenderContext(float _objRadius); 145 virtual ~GLSLUnlit_RenderContext(); 146 147 virtual void makeCurrent(const Mesh::Material&); 148 virtual void setVertexArrays(const Mesh::VertexDescription& desc, 149 void* vertexData); 150 151 private: 152 void initLightingEnvironment(); 153 void setLightingParameters(CelestiaGLProgram& prog, Color diffuseColor, Color specularColor); 154 155 private: 156 Mesh::BlendMode blendMode; 157 float objRadius; 158 159 ShaderProperties shaderProps; 160 }; 161 162 163 #endif // _CELENGINE_RENDCONTEXT_H_ 164 165