2012-04-03 20:44:46 +02:00
|
|
|
/* Copyright (C) 2012 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* RenderModifiers can affect the fragment stage behaviour of some
|
|
|
|
* ModelRenderers. This file defines some common RenderModifiers in
|
|
|
|
* addition to the base class.
|
2012-04-03 20:44:46 +02:00
|
|
|
*
|
|
|
|
* TODO: See comment in CRendererInternals::Models - we no longer use multiple
|
|
|
|
* subclasses of RenderModifier, so most of the stuff here is unnecessary
|
|
|
|
* abstraction which should probably be cleaned up.
|
2005-10-25 03:43:07 +02:00
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_RENDERMODIFIERS
|
|
|
|
#define INCLUDED_RENDERMODIFIERS
|
2005-10-25 03:43:07 +02:00
|
|
|
|
|
|
|
#include "ModelRenderer.h"
|
2011-03-26 21:17:21 +01:00
|
|
|
#include "graphics/ShaderTechnique.h"
|
2010-09-10 23:02:10 +02:00
|
|
|
#include "graphics/Texture.h"
|
2005-10-25 03:43:07 +02:00
|
|
|
|
2006-03-26 01:54:20 +01:00
|
|
|
class CLightEnv;
|
|
|
|
class CMatrix3D;
|
2005-10-25 03:43:07 +02:00
|
|
|
class CModel;
|
2006-03-26 01:54:20 +01:00
|
|
|
class ShadowMap;
|
2005-10-25 03:43:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RenderModifier: Some ModelRenderer implementations provide vertex
|
|
|
|
* management behaviour but allow fragment stages to be modified by a plugged in
|
|
|
|
* RenderModifier.
|
|
|
|
*
|
|
|
|
* You should use RenderModifierPtr when referencing RenderModifiers.
|
|
|
|
*/
|
|
|
|
class RenderModifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RenderModifier() { }
|
|
|
|
virtual ~RenderModifier() { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BeginPass: Setup OpenGL for the given rendering pass.
|
|
|
|
*
|
|
|
|
* Must be implemented by derived classes.
|
|
|
|
*
|
|
|
|
* @param pass The current pass number (pass == 0 is the first pass)
|
|
|
|
*
|
|
|
|
* @return The streamflags that indicate which vertex components
|
|
|
|
* are required by the fragment stages (see STREAM_XYZ constants).
|
|
|
|
*/
|
2012-04-03 20:44:46 +02:00
|
|
|
virtual void BeginPass(const CShaderProgramPtr& shader) = 0;
|
2012-02-09 18:55:25 +01:00
|
|
|
|
2005-10-25 03:43:07 +02:00
|
|
|
/**
|
|
|
|
* PrepareModel: Called before rendering the given model.
|
2006-02-13 15:18:20 +01:00
|
|
|
*
|
2005-10-25 03:43:07 +02:00
|
|
|
* Default behaviour does nothing.
|
|
|
|
*
|
|
|
|
* @param pass The current pass number (pass == 0 is the first pass)
|
|
|
|
* @param model The model that is about to be rendered.
|
|
|
|
*/
|
2012-04-03 20:44:46 +02:00
|
|
|
virtual void PrepareModel(const CShaderProgramPtr& shader, CModel* model) = 0;
|
2005-10-25 03:43:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-03-26 01:54:20 +01:00
|
|
|
/**
|
|
|
|
* Class LitRenderModifier: Abstract base class for RenderModifiers that apply
|
|
|
|
* a shadow map.
|
|
|
|
* LitRenderModifiers expect the diffuse brightness in the primary color (instead of ambient + diffuse).
|
|
|
|
*/
|
|
|
|
class LitRenderModifier : public RenderModifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LitRenderModifier();
|
|
|
|
~LitRenderModifier();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetShadowMap: Set the shadow map that will be used for rendering.
|
|
|
|
* Must be called by the user of the RenderModifier.
|
|
|
|
*
|
|
|
|
* The shadow map must be non-null and use depth texturing, or subsequent rendering
|
|
|
|
* using this RenderModifier will fail.
|
|
|
|
*
|
|
|
|
* @param shadow the shadow map
|
|
|
|
*/
|
|
|
|
void SetShadowMap(const ShadowMap* shadow);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetLightEnv: Set the light environment that will be used for rendering.
|
|
|
|
* Must be called by the user of the RenderModifier.
|
|
|
|
*
|
|
|
|
* @param lightenv the light environment (must be non-null)
|
|
|
|
*/
|
|
|
|
void SetLightEnv(const CLightEnv* lightenv);
|
|
|
|
|
|
|
|
const ShadowMap* GetShadowMap() const { return m_Shadow; }
|
|
|
|
const CLightEnv* GetLightEnv() const { return m_LightEnv; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ShadowMap* m_Shadow;
|
|
|
|
const CLightEnv* m_LightEnv;
|
|
|
|
};
|
|
|
|
|
2011-03-26 21:17:21 +01:00
|
|
|
/**
|
2012-04-03 20:44:46 +02:00
|
|
|
* A RenderModifier that sets uniforms and textures appropriately for rendering models.
|
2011-03-26 21:17:21 +01:00
|
|
|
*/
|
|
|
|
class ShaderRenderModifier : public LitRenderModifier
|
|
|
|
{
|
|
|
|
public:
|
2012-04-03 20:44:46 +02:00
|
|
|
ShaderRenderModifier();
|
2011-03-26 21:17:21 +01:00
|
|
|
|
|
|
|
// Implementation
|
2012-04-03 20:44:46 +02:00
|
|
|
void BeginPass(const CShaderProgramPtr& shader);
|
|
|
|
void PrepareModel(const CShaderProgramPtr& shader, CModel* model);
|
2011-03-26 21:17:21 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
CShaderProgram::Binding m_BindingInstancingTransform;
|
|
|
|
CShaderProgram::Binding m_BindingShadingColor;
|
|
|
|
CShaderProgram::Binding m_BindingPlayerColor;
|
|
|
|
};
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_RENDERMODIFIERS
|