Renderer simplification: Remove old vertexshader path.
This was SVN commit r9186.
This commit is contained in:
parent
06903af31f
commit
8753f881ee
@ -1,11 +0,0 @@
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
|
||||
vec3 lighting(vec3 normal)
|
||||
{
|
||||
vec3 color = ambient;
|
||||
float d = max(0.0, -dot(normal, sunDir));
|
||||
color += d * sunColor;
|
||||
return color;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
vec4 InstancingPosition(vec4 position);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 worldPos = InstancingPosition(gl_Vertex);
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * worldPos;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
|
||||
<Program>
|
||||
<Shaders>
|
||||
<Shader type="VERTEX_SHADER">shaders/instancing_base.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/instancing.vs</Shader>
|
||||
</Shaders>
|
||||
</Program>
|
@ -1,29 +0,0 @@
|
||||
|
||||
// 3x4 part of the model-to-world matrix
|
||||
attribute vec4 Instancing1;
|
||||
attribute vec4 Instancing2;
|
||||
attribute vec4 Instancing3;
|
||||
|
||||
// Calculate a normal that has been transformed for instancing
|
||||
vec3 InstancingNormal(vec3 normal)
|
||||
{
|
||||
vec3 tmp;
|
||||
|
||||
tmp.x = dot(vec3(Instancing1), normal);
|
||||
tmp.y = dot(vec3(Instancing2), normal);
|
||||
tmp.z = dot(vec3(Instancing3), normal);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Calculate position, transformed for instancing
|
||||
vec4 InstancingPosition(vec4 position)
|
||||
{
|
||||
vec3 tmp;
|
||||
|
||||
tmp.x = dot(Instancing1, position);
|
||||
tmp.y = dot(Instancing2, position);
|
||||
tmp.z = dot(Instancing3, position);
|
||||
|
||||
return vec4(tmp, 1.0);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
vec3 lighting(vec3 normal);
|
||||
|
||||
vec3 InstancingNormal(vec3 normal);
|
||||
vec4 InstancingPosition(vec4 position);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = InstancingNormal(gl_Normal);
|
||||
vec4 worldPos = InstancingPosition(gl_Vertex);
|
||||
|
||||
gl_FrontColor = clamp(vec4(lighting(normal), 1.0) * gl_Color, 0.0, 1.0);
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * worldPos;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
|
||||
<Program>
|
||||
<Shaders>
|
||||
<Shader type="VERTEX_SHADER">shaders/globallight.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/instancing_base.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/instancing_light.vs</Shader>
|
||||
</Shaders>
|
||||
</Program>
|
@ -1,17 +0,0 @@
|
||||
vec3 lighting(vec3 normal);
|
||||
|
||||
vec3 InstancingNormal(vec3 normal);
|
||||
vec4 InstancingPosition(vec4 position);
|
||||
|
||||
vec4 postouv1(vec4 pos);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = InstancingNormal(gl_Normal);
|
||||
vec4 worldPos = InstancingPosition(gl_Vertex);
|
||||
|
||||
gl_FrontColor = clamp(vec4(lighting(normal), 1.0) * gl_Color, 0.0, 1.0);
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_TexCoord[1] = postouv1(worldPos);
|
||||
gl_Position = gl_ModelViewProjectionMatrix * worldPos;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
|
||||
<Program>
|
||||
<Shaders>
|
||||
<Shader type="VERTEX_SHADER">shaders/globallight.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/postouv1.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/instancing_base.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/instancing_lightp.vs</Shader>
|
||||
</Shaders>
|
||||
</Program>
|
@ -1,12 +0,0 @@
|
||||
vec4 InstancingPosition(vec4 position);
|
||||
vec4 postouv1(vec4 pos);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 worldPos = InstancingPosition(gl_Vertex);
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_TexCoord[1] = postouv1(worldPos);
|
||||
gl_Position = gl_ModelViewProjectionMatrix * worldPos;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
|
||||
<Program>
|
||||
<Shaders>
|
||||
<Shader type="VERTEX_SHADER">shaders/postouv1.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/instancing_base.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/instancingp.vs</Shader>
|
||||
</Shaders>
|
||||
</Program>
|
@ -1,8 +0,0 @@
|
||||
vec3 lighting(vec3 normal);
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FrontColor = clamp(vec4(lighting(gl_Normal), 1.0) * gl_Color, 0.0, 1.0);
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_Position = ftransform();
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
|
||||
<Program>
|
||||
<Shaders>
|
||||
<Shader type="VERTEX_SHADER">shaders/globallight.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/model_light.vs</Shader>
|
||||
</Shaders>
|
||||
</Program>
|
@ -1,10 +0,0 @@
|
||||
vec3 lighting(vec3 normal);
|
||||
vec4 postouv1(vec4 pos);
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FrontColor = clamp(vec4(lighting(gl_Normal), 1.0) * gl_Color, 0.0, 1.0);
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_TexCoord[1] = postouv1(gl_Vertex);
|
||||
gl_Position = ftransform();
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
|
||||
|
||||
<Program>
|
||||
<Shaders>
|
||||
<Shader type="VERTEX_SHADER">shaders/globallight.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/postouv1.vs</Shader>
|
||||
<Shader type="VERTEX_SHADER">shaders/model_lightp.vs</Shader>
|
||||
</Shaders>
|
||||
</Program>
|
@ -1,14 +0,0 @@
|
||||
uniform vec4 TextureMatrix1;
|
||||
uniform vec4 TextureMatrix2;
|
||||
uniform vec4 TextureMatrix3;
|
||||
|
||||
vec4 postouv1(vec4 pos)
|
||||
{
|
||||
vec3 tmp;
|
||||
|
||||
tmp.x = dot(TextureMatrix1, pos);
|
||||
tmp.y = dot(TextureMatrix2, pos);
|
||||
tmp.z = dot(TextureMatrix3, pos);
|
||||
|
||||
return vec4(tmp, 1.0);
|
||||
}
|
@ -15,10 +15,6 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Implementation of HWLightingModelRenderer
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib/ogl.h"
|
||||
@ -34,23 +30,19 @@
|
||||
#include "renderer/HWLightingModelRenderer.h"
|
||||
#include "renderer/Renderer.h"
|
||||
#include "renderer/RenderModifiers.h"
|
||||
#include "renderer/RenderPathVertexShader.h"
|
||||
#include "renderer/VertexArray.h"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// HWLightingModelRenderer implementation
|
||||
|
||||
struct HWLModelDef : public CModelDefRPrivate
|
||||
struct ShaderModelDef : public CModelDefRPrivate
|
||||
{
|
||||
/// Indices are the same for all models, so share them
|
||||
VertexIndexArray m_IndexArray;
|
||||
|
||||
HWLModelDef(const CModelDefPtr& mdef);
|
||||
ShaderModelDef(const CModelDefPtr& mdef);
|
||||
};
|
||||
|
||||
|
||||
HWLModelDef::HWLModelDef(const CModelDefPtr& mdef)
|
||||
ShaderModelDef::ShaderModelDef(const CModelDefPtr& mdef)
|
||||
: m_IndexArray(GL_STATIC_DRAW)
|
||||
{
|
||||
m_IndexArray.SetNumVertices(mdef->GetNumFaces()*3);
|
||||
@ -61,7 +53,7 @@ HWLModelDef::HWLModelDef(const CModelDefPtr& mdef)
|
||||
}
|
||||
|
||||
|
||||
struct HWLModel
|
||||
struct ShaderModel
|
||||
{
|
||||
/// Dynamic per-CModel vertex array
|
||||
VertexArray m_Array;
|
||||
@ -73,267 +65,99 @@ struct HWLModel
|
||||
/// UV is stored per-CModel in order to avoid space wastage due to alignment
|
||||
VertexArray::Attribute m_UV;
|
||||
|
||||
HWLModel() : m_Array(GL_DYNAMIC_DRAW) { }
|
||||
ShaderModel() : m_Array(GL_DYNAMIC_DRAW) { }
|
||||
};
|
||||
|
||||
|
||||
struct HWLightingModelRendererInternals
|
||||
struct ShaderModelRendererInternals
|
||||
{
|
||||
/// Previously prepared modeldef
|
||||
HWLModelDef* hwlmodeldef;
|
||||
|
||||
/// If true, primary color will only contain the diffuse term
|
||||
bool colorIsDiffuseOnly;
|
||||
ShaderModelDef* shadermodeldef;
|
||||
};
|
||||
|
||||
|
||||
// Construction and Destruction
|
||||
HWLightingModelRenderer::HWLightingModelRenderer(bool colorIsDiffuseOnly)
|
||||
ShaderModelRenderer::ShaderModelRenderer()
|
||||
{
|
||||
m = new HWLightingModelRendererInternals;
|
||||
m->hwlmodeldef = 0;
|
||||
m->colorIsDiffuseOnly = colorIsDiffuseOnly;
|
||||
m = new ShaderModelRendererInternals;
|
||||
m->shadermodeldef = 0;
|
||||
}
|
||||
|
||||
HWLightingModelRenderer::~HWLightingModelRenderer()
|
||||
ShaderModelRenderer::~ShaderModelRenderer()
|
||||
{
|
||||
delete m;
|
||||
}
|
||||
|
||||
|
||||
// Check hardware support
|
||||
bool HWLightingModelRenderer::IsAvailable()
|
||||
{
|
||||
return g_Renderer.m_VertexShader != 0;
|
||||
}
|
||||
|
||||
|
||||
// Build model data (and modeldef data if necessary)
|
||||
void* HWLightingModelRenderer::CreateModelData(CModel* model)
|
||||
void* ShaderModelRenderer::CreateModelData(CModel* model)
|
||||
{
|
||||
CModelDefPtr mdef = model->GetModelDef();
|
||||
HWLModelDef* hwlmodeldef = (HWLModelDef*)mdef->GetRenderData(m);
|
||||
ShaderModelDef* shadermodeldef = (ShaderModelDef*)mdef->GetRenderData(m);
|
||||
|
||||
if (!hwlmodeldef)
|
||||
if (!shadermodeldef)
|
||||
{
|
||||
hwlmodeldef = new HWLModelDef(mdef);
|
||||
mdef->SetRenderData(m, hwlmodeldef);
|
||||
shadermodeldef = new ShaderModelDef(mdef);
|
||||
mdef->SetRenderData(m, shadermodeldef);
|
||||
}
|
||||
|
||||
// Build the per-model data
|
||||
HWLModel* hwlmodel = new HWLModel;
|
||||
ShaderModel* shadermodel = new ShaderModel;
|
||||
|
||||
hwlmodel->m_Position.type = GL_FLOAT;
|
||||
hwlmodel->m_Position.elems = 3;
|
||||
hwlmodel->m_Array.AddAttribute(&hwlmodel->m_Position);
|
||||
shadermodel->m_Position.type = GL_FLOAT;
|
||||
shadermodel->m_Position.elems = 3;
|
||||
shadermodel->m_Array.AddAttribute(&shadermodel->m_Position);
|
||||
|
||||
hwlmodel->m_UV.type = GL_FLOAT;
|
||||
hwlmodel->m_UV.elems = 2;
|
||||
hwlmodel->m_Array.AddAttribute(&hwlmodel->m_UV);
|
||||
shadermodel->m_UV.type = GL_FLOAT;
|
||||
shadermodel->m_UV.elems = 2;
|
||||
shadermodel->m_Array.AddAttribute(&shadermodel->m_UV);
|
||||
|
||||
hwlmodel->m_Normal.type = GL_FLOAT;
|
||||
hwlmodel->m_Normal.elems = 3;
|
||||
hwlmodel->m_Array.AddAttribute(&hwlmodel->m_Normal);
|
||||
shadermodel->m_Normal.type = GL_FLOAT;
|
||||
shadermodel->m_Normal.elems = 3;
|
||||
shadermodel->m_Array.AddAttribute(&shadermodel->m_Normal);
|
||||
|
||||
hwlmodel->m_Array.SetNumVertices(mdef->GetNumVertices());
|
||||
hwlmodel->m_Array.Layout();
|
||||
shadermodel->m_Array.SetNumVertices(mdef->GetNumVertices());
|
||||
shadermodel->m_Array.Layout();
|
||||
|
||||
// Fill in static UV coordinates
|
||||
VertexArrayIterator<float[2]> UVit = hwlmodel->m_UV.GetIterator<float[2]>();
|
||||
VertexArrayIterator<float[2]> UVit = shadermodel->m_UV.GetIterator<float[2]>();
|
||||
|
||||
ModelRenderer::BuildUV(mdef, UVit);
|
||||
|
||||
return hwlmodel;
|
||||
return shadermodel;
|
||||
}
|
||||
|
||||
|
||||
// Fill in and upload dynamic vertex array
|
||||
void HWLightingModelRenderer::UpdateModelData(CModel* model, void* data, int updateflags)
|
||||
void ShaderModelRenderer::UpdateModelData(CModel* model, void* data, int updateflags)
|
||||
{
|
||||
HWLModel* hwlmodel = (HWLModel*)data;
|
||||
ShaderModel* shadermodel = (ShaderModel*)data;
|
||||
|
||||
if (updateflags & RENDERDATA_UPDATE_VERTICES)
|
||||
{
|
||||
// build vertices
|
||||
VertexArrayIterator<CVector3D> Position = hwlmodel->m_Position.GetIterator<CVector3D>();
|
||||
VertexArrayIterator<CVector3D> Normal = hwlmodel->m_Normal.GetIterator<CVector3D>();
|
||||
VertexArrayIterator<CVector3D> Position = shadermodel->m_Position.GetIterator<CVector3D>();
|
||||
VertexArrayIterator<CVector3D> Normal = shadermodel->m_Normal.GetIterator<CVector3D>();
|
||||
|
||||
ModelRenderer::BuildPositionAndNormals(model, Position, Normal);
|
||||
|
||||
// upload everything to vertex buffer
|
||||
hwlmodel->m_Array.Upload();
|
||||
shadermodel->m_Array.Upload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Cleanup per-model data.
|
||||
// Note that per-CModelDef data is deleted by the CModelDef itself.
|
||||
void HWLightingModelRenderer::DestroyModelData(CModel* UNUSED(model), void* data)
|
||||
void ShaderModelRenderer::DestroyModelData(CModel* UNUSED(model), void* data)
|
||||
{
|
||||
HWLModel* hwlmodel = (HWLModel*)data;
|
||||
ShaderModel* shadermodel = (ShaderModel*)data;
|
||||
|
||||
delete hwlmodel;
|
||||
delete shadermodel;
|
||||
}
|
||||
|
||||
|
||||
// Setup one rendering pass
|
||||
void HWLightingModelRenderer::BeginPass(int streamflags, const CMatrix3D* texturematrix)
|
||||
{
|
||||
debug_assert(streamflags == (streamflags & (STREAM_POS|STREAM_UV0|STREAM_COLOR|STREAM_TEXGENTOUV1)));
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if (streamflags & STREAM_UV0) glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
if (streamflags & STREAM_COLOR)
|
||||
{
|
||||
RenderPathVertexShader* rpvs = g_Renderer.m_VertexShader;
|
||||
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
|
||||
VS_GlobalLight* lightConfig;
|
||||
|
||||
if (streamflags & STREAM_TEXGENTOUV1)
|
||||
{
|
||||
ogl_program_use(rpvs->m_ModelLightP);
|
||||
lightConfig = &rpvs->m_ModelLightP_Light;
|
||||
|
||||
rpvs->m_ModelLightP_PosToUV1.SetMatrix(*texturematrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
ogl_program_use(rpvs->m_ModelLight);
|
||||
lightConfig = &rpvs->m_ModelLight_Light;
|
||||
}
|
||||
|
||||
if (m->colorIsDiffuseOnly)
|
||||
lightConfig->SetAmbient(RGBColor(0,0,0));
|
||||
else
|
||||
lightConfig->SetAmbient(lightEnv.m_UnitsAmbientColor);
|
||||
lightConfig->SetSunDir(lightEnv.GetSunDir());
|
||||
lightConfig->SetSunColor(lightEnv.m_SunColor);
|
||||
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (streamflags & STREAM_TEXGENTOUV1)
|
||||
{
|
||||
pglActiveTextureARB(GL_TEXTURE1);
|
||||
|
||||
float tmp[4];
|
||||
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
tmp[0] = texturematrix->_11;
|
||||
tmp[1] = texturematrix->_12;
|
||||
tmp[2] = texturematrix->_13;
|
||||
tmp[3] = texturematrix->_14;
|
||||
glTexGenfv(GL_S, GL_OBJECT_PLANE, tmp);
|
||||
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
tmp[0] = texturematrix->_21;
|
||||
tmp[1] = texturematrix->_22;
|
||||
tmp[2] = texturematrix->_23;
|
||||
tmp[3] = texturematrix->_24;
|
||||
glTexGenfv(GL_T, GL_OBJECT_PLANE, tmp);
|
||||
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
tmp[0] = texturematrix->_31;
|
||||
tmp[1] = texturematrix->_32;
|
||||
tmp[2] = texturematrix->_33;
|
||||
tmp[3] = texturematrix->_34;
|
||||
glTexGenfv(GL_R, GL_OBJECT_PLANE, tmp);
|
||||
|
||||
pglActiveTextureARB(GL_TEXTURE0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Cleanup one rendering pass
|
||||
void HWLightingModelRenderer::EndPass(int streamflags)
|
||||
{
|
||||
if (streamflags & STREAM_UV0) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
if (streamflags & STREAM_COLOR)
|
||||
{
|
||||
pglUseProgramObjectARB(0);
|
||||
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (streamflags & STREAM_TEXGENTOUV1)
|
||||
{
|
||||
pglActiveTextureARB(GL_TEXTURE1);
|
||||
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_TEXTURE_GEN_R);
|
||||
|
||||
pglActiveTextureARB(GL_TEXTURE0);
|
||||
}
|
||||
}
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
CVertexBuffer::Unbind();
|
||||
}
|
||||
|
||||
|
||||
// Prepare UV coordinates for this modeldef
|
||||
void HWLightingModelRenderer::PrepareModelDef(int UNUSED(streamflags), const CModelDefPtr& def)
|
||||
{
|
||||
m->hwlmodeldef = (HWLModelDef*)def->GetRenderData(m);
|
||||
|
||||
debug_assert(m->hwlmodeldef);
|
||||
}
|
||||
|
||||
|
||||
// Render one model
|
||||
void HWLightingModelRenderer::RenderModel(int streamflags, CModel* model, void* data)
|
||||
{
|
||||
CModelDefPtr mdldef = model->GetModelDef();
|
||||
HWLModel* hwlmodel = (HWLModel*)data;
|
||||
|
||||
u8* base = hwlmodel->m_Array.Bind();
|
||||
GLsizei stride = (GLsizei)hwlmodel->m_Array.GetStride();
|
||||
|
||||
u8* indexBase = m->hwlmodeldef->m_IndexArray.Bind();
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, stride, base + hwlmodel->m_Position.offset);
|
||||
if (streamflags & STREAM_COLOR)
|
||||
{
|
||||
CColor sc = model->GetShadingColor();
|
||||
glColor3f(sc.r, sc.g, sc.b);
|
||||
|
||||
glNormalPointer(GL_FLOAT, stride, base + hwlmodel->m_Normal.offset);
|
||||
}
|
||||
if (streamflags & STREAM_UV0)
|
||||
{
|
||||
glTexCoordPointer(2, GL_FLOAT, stride, base + hwlmodel->m_UV.offset);
|
||||
}
|
||||
|
||||
// render the lot
|
||||
size_t numFaces = mdldef->GetNumFaces();
|
||||
|
||||
if (!g_Renderer.m_SkipSubmit) {
|
||||
pglDrawRangeElementsEXT(GL_TRIANGLES, 0, (GLuint)mdldef->GetNumVertices()-1,
|
||||
(GLsizei)numFaces*3, GL_UNSIGNED_SHORT, indexBase);
|
||||
}
|
||||
|
||||
// bump stats
|
||||
g_Renderer.m_Stats.m_DrawCalls++;
|
||||
g_Renderer.m_Stats.m_ModelTris += numFaces;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ShaderModelRenderer implementation
|
||||
|
||||
ShaderModelRenderer::ShaderModelRenderer() :
|
||||
HWLightingModelRenderer(false)
|
||||
{
|
||||
}
|
||||
|
||||
void ShaderModelRenderer::BeginPass(int streamflags, const CMatrix3D* UNUSED(texturematrix))
|
||||
{
|
||||
debug_assert(streamflags == (streamflags & (STREAM_POS|STREAM_NORMAL|STREAM_UV0)));
|
||||
@ -348,6 +172,7 @@ void ShaderModelRenderer::BeginPass(int streamflags, const CMatrix3D* UNUSED(tex
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
// Cleanup one rendering pass
|
||||
void ShaderModelRenderer::EndPass(int streamflags)
|
||||
{
|
||||
if (streamflags & STREAM_POS)
|
||||
@ -362,24 +187,35 @@ void ShaderModelRenderer::EndPass(int streamflags)
|
||||
CVertexBuffer::Unbind();
|
||||
}
|
||||
|
||||
|
||||
// Prepare UV coordinates for this modeldef
|
||||
void ShaderModelRenderer::PrepareModelDef(int UNUSED(streamflags), const CModelDefPtr& def)
|
||||
{
|
||||
m->shadermodeldef = (ShaderModelDef*)def->GetRenderData(m);
|
||||
|
||||
debug_assert(m->shadermodeldef);
|
||||
}
|
||||
|
||||
|
||||
// Render one model
|
||||
void ShaderModelRenderer::RenderModel(int streamflags, CModel* model, void* data)
|
||||
{
|
||||
CModelDefPtr mdldef = model->GetModelDef();
|
||||
HWLModel* hwlmodel = (HWLModel*)data;
|
||||
ShaderModel* shadermodel = (ShaderModel*)data;
|
||||
|
||||
u8* base = hwlmodel->m_Array.Bind();
|
||||
GLsizei stride = (GLsizei)hwlmodel->m_Array.GetStride();
|
||||
u8* base = shadermodel->m_Array.Bind();
|
||||
GLsizei stride = (GLsizei)shadermodel->m_Array.GetStride();
|
||||
|
||||
u8* indexBase = m->hwlmodeldef->m_IndexArray.Bind();
|
||||
u8* indexBase = m->shadermodeldef->m_IndexArray.Bind();
|
||||
|
||||
if (streamflags & STREAM_POS)
|
||||
glVertexPointer(3, GL_FLOAT, stride, base + hwlmodel->m_Position.offset);
|
||||
glVertexPointer(3, GL_FLOAT, stride, base + shadermodel->m_Position.offset);
|
||||
|
||||
if (streamflags & STREAM_NORMAL)
|
||||
glNormalPointer(GL_FLOAT, stride, base + hwlmodel->m_Normal.offset);
|
||||
glNormalPointer(GL_FLOAT, stride, base + shadermodel->m_Normal.offset);
|
||||
|
||||
if (streamflags & STREAM_UV0)
|
||||
glTexCoordPointer(2, GL_FLOAT, stride, base + hwlmodel->m_UV.offset);
|
||||
glTexCoordPointer(2, GL_FLOAT, stride, base + shadermodel->m_UV.offset);
|
||||
|
||||
// render the lot
|
||||
size_t numFaces = mdldef->GetNumFaces();
|
||||
@ -394,3 +230,4 @@ void ShaderModelRenderer::RenderModel(int streamflags, CModel* model, void* data
|
||||
g_Renderer.m_Stats.m_DrawCalls++;
|
||||
g_Renderer.m_Stats.m_ModelTris += numFaces;
|
||||
}
|
||||
|
||||
|
@ -25,16 +25,14 @@
|
||||
|
||||
#include "renderer/ModelVertexRenderer.h"
|
||||
|
||||
struct HWLightingModelRendererInternals;
|
||||
struct ShaderModelRendererInternals;
|
||||
|
||||
/**
|
||||
* Class HWLightingModelRenderer: Render animated models using vertex
|
||||
* shaders for lighting.
|
||||
*
|
||||
* @note You should verify hardware capabilities using IsAvailable
|
||||
* before creating this model renderer.
|
||||
* Render animated models using a ShaderRenderModifier.
|
||||
* This just passes through the vertex data directly; the modifier is responsible
|
||||
* for setting any shader uniforms etc.
|
||||
*/
|
||||
class HWLightingModelRenderer : public ModelVertexRenderer
|
||||
class ShaderModelRenderer : public ModelVertexRenderer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@ -43,8 +41,8 @@ public:
|
||||
* @param colorIsDiffuseOnly if true, the primary color sent to the fragment stage
|
||||
* contains only the diffuse term, and not the ambient
|
||||
*/
|
||||
HWLightingModelRenderer(bool colorIsDiffuseOnly);
|
||||
~HWLightingModelRenderer();
|
||||
ShaderModelRenderer();
|
||||
~ShaderModelRenderer();
|
||||
|
||||
// Implementations
|
||||
void* CreateModelData(CModel* model);
|
||||
@ -56,35 +54,8 @@ public:
|
||||
void PrepareModelDef(int streamflags, const CModelDefPtr& def);
|
||||
void RenderModel(int streamflags, CModel* model, void* data);
|
||||
|
||||
/**
|
||||
* IsAvailable: Determines whether this model renderer can be used
|
||||
* given the OpenGL implementation specific limits.
|
||||
*
|
||||
* @note Do not attempt to construct a HWLightingModelRenderer object
|
||||
* when IsAvailable returns false.
|
||||
*
|
||||
* @return true if the OpenGL implementation can support this
|
||||
* model renderer.
|
||||
*/
|
||||
static bool IsAvailable();
|
||||
|
||||
protected:
|
||||
HWLightingModelRendererInternals* m;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render animated models using a ShaderRenderModifier.
|
||||
* This just passes through the vertex data directly; the modifier is responsible
|
||||
* for setting any shader uniforms etc.
|
||||
*/
|
||||
class ShaderModelRenderer : public HWLightingModelRenderer
|
||||
{
|
||||
public:
|
||||
ShaderModelRenderer();
|
||||
|
||||
void BeginPass(int streamflags, const CMatrix3D* texturematrix);
|
||||
void EndPass(int streamflags);
|
||||
void RenderModel(int streamflags, CModel* model, void* data);
|
||||
ShaderModelRendererInternals* m;
|
||||
};
|
||||
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "renderer/InstancingModelRenderer.h"
|
||||
#include "renderer/Renderer.h"
|
||||
#include "renderer/RenderModifiers.h"
|
||||
#include "renderer/RenderPathVertexShader.h"
|
||||
#include "renderer/VertexArray.h"
|
||||
|
||||
|
||||
@ -109,21 +108,14 @@ struct InstancingModelRendererInternals
|
||||
|
||||
/// Index base for imodeldef
|
||||
u8* imodeldefIndexBase;
|
||||
|
||||
/// If true, primary color will only contain the diffuse term
|
||||
bool colorIsDiffuseOnly;
|
||||
|
||||
/// After BeginPass, this points to the instancing matrix interface
|
||||
VS_Instancing* instancingConfig;
|
||||
};
|
||||
|
||||
|
||||
// Construction and Destruction
|
||||
InstancingModelRenderer::InstancingModelRenderer(bool colorIsDiffuseOnly)
|
||||
InstancingModelRenderer::InstancingModelRenderer()
|
||||
{
|
||||
m = new InstancingModelRendererInternals;
|
||||
m->imodeldef = 0;
|
||||
m->colorIsDiffuseOnly = colorIsDiffuseOnly;
|
||||
}
|
||||
|
||||
InstancingModelRenderer::~InstancingModelRenderer()
|
||||
@ -132,13 +124,6 @@ InstancingModelRenderer::~InstancingModelRenderer()
|
||||
}
|
||||
|
||||
|
||||
// Check hardware support
|
||||
bool InstancingModelRenderer::IsAvailable()
|
||||
{
|
||||
return g_Renderer.m_VertexShader != 0;
|
||||
}
|
||||
|
||||
|
||||
// Build modeldef data if necessary - we have no per-CModel data
|
||||
void* InstancingModelRenderer::CreateModelData(CModel* model)
|
||||
{
|
||||
@ -170,134 +155,7 @@ void InstancingModelRenderer::DestroyModelData(CModel* UNUSED(model), void* UNUS
|
||||
|
||||
|
||||
// Setup one rendering pass.
|
||||
void InstancingModelRenderer::BeginPass(int streamflags, const CMatrix3D* texturematrix)
|
||||
{
|
||||
debug_assert(streamflags == (streamflags & (STREAM_POS|STREAM_UV0|STREAM_COLOR|STREAM_TEXGENTOUV1)));
|
||||
|
||||
RenderPathVertexShader* rpvs = g_Renderer.m_VertexShader;
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if (streamflags & STREAM_UV0) glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
if (streamflags & STREAM_COLOR)
|
||||
{
|
||||
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
|
||||
VS_GlobalLight* lightConfig;
|
||||
|
||||
if (streamflags & STREAM_TEXGENTOUV1)
|
||||
{
|
||||
ogl_program_use(rpvs->m_InstancingLightP);
|
||||
lightConfig = &rpvs->m_InstancingLightP_Light;
|
||||
m->instancingConfig = &rpvs->m_InstancingLightP_Instancing;
|
||||
|
||||
rpvs->m_InstancingLightP_PosToUV1.SetMatrix(*texturematrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
ogl_program_use(rpvs->m_InstancingLight);
|
||||
lightConfig = &rpvs->m_InstancingLight_Light;
|
||||
m->instancingConfig = &rpvs->m_InstancingLight_Instancing;
|
||||
}
|
||||
|
||||
if (m->colorIsDiffuseOnly)
|
||||
lightConfig->SetAmbient(RGBColor(0,0,0));
|
||||
else
|
||||
lightConfig->SetAmbient(lightEnv.m_UnitsAmbientColor);
|
||||
lightConfig->SetSunDir(lightEnv.GetSunDir());
|
||||
lightConfig->SetSunColor(lightEnv.m_SunColor);
|
||||
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (streamflags & STREAM_TEXGENTOUV1)
|
||||
{
|
||||
ogl_program_use(rpvs->m_InstancingP);
|
||||
m->instancingConfig = &rpvs->m_InstancingP_Instancing;
|
||||
|
||||
rpvs->m_InstancingP_PosToUV1.SetMatrix(*texturematrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
ogl_program_use(rpvs->m_Instancing);
|
||||
m->instancingConfig = &rpvs->m_Instancing_Instancing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup rendering pass.
|
||||
void InstancingModelRenderer::EndPass(int streamflags)
|
||||
{
|
||||
if (streamflags & STREAM_UV0) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
if (streamflags & STREAM_COLOR) glDisableClientState(GL_NORMAL_ARRAY);
|
||||
|
||||
pglUseProgramObjectARB(0);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
CVertexBuffer::Unbind();
|
||||
}
|
||||
|
||||
|
||||
// Prepare UV coordinates for this modeldef
|
||||
void InstancingModelRenderer::PrepareModelDef(int streamflags, const CModelDefPtr& def)
|
||||
{
|
||||
m->imodeldef = (IModelDef*)def->GetRenderData(m);
|
||||
|
||||
debug_assert(m->imodeldef);
|
||||
|
||||
u8* base = m->imodeldef->m_Array.Bind();
|
||||
GLsizei stride = (GLsizei)m->imodeldef->m_Array.GetStride();
|
||||
|
||||
m->imodeldefIndexBase = m->imodeldef->m_IndexArray.Bind();
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, stride, base + m->imodeldef->m_Position.offset);
|
||||
if (streamflags & STREAM_COLOR)
|
||||
{
|
||||
glNormalPointer(GL_FLOAT, stride, base + m->imodeldef->m_Normal.offset);
|
||||
}
|
||||
if (streamflags & STREAM_UV0)
|
||||
{
|
||||
glTexCoordPointer(2, GL_FLOAT, stride, base + m->imodeldef->m_UV.offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Render one model
|
||||
void InstancingModelRenderer::RenderModel(int streamflags, CModel* model, void* UNUSED(data))
|
||||
{
|
||||
CModelDefPtr mdldef = model->GetModelDef();
|
||||
const CMatrix3D& mat = model->GetTransform();
|
||||
|
||||
if (streamflags & STREAM_COLOR)
|
||||
{
|
||||
CColor sc = model->GetShadingColor();
|
||||
glColor3f(sc.r, sc.g, sc.b);
|
||||
}
|
||||
|
||||
m->instancingConfig->SetMatrix(mat);
|
||||
|
||||
// render the lot
|
||||
size_t numFaces = mdldef->GetNumFaces();
|
||||
|
||||
if (!g_Renderer.m_SkipSubmit) {
|
||||
pglDrawRangeElementsEXT(GL_TRIANGLES, 0, (GLuint)mdldef->GetNumVertices()-1,
|
||||
(GLsizei)numFaces*3, GL_UNSIGNED_SHORT, m->imodeldefIndexBase);
|
||||
}
|
||||
|
||||
// bump stats
|
||||
g_Renderer.m_Stats.m_DrawCalls++;
|
||||
g_Renderer.m_Stats.m_ModelTris += numFaces;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ShaderInstancingModelRenderer implementation
|
||||
|
||||
ShaderInstancingModelRenderer::ShaderInstancingModelRenderer() :
|
||||
InstancingModelRenderer(false)
|
||||
{
|
||||
}
|
||||
|
||||
void ShaderInstancingModelRenderer::BeginPass(int streamflags, const CMatrix3D* UNUSED(texturematrix))
|
||||
void InstancingModelRenderer::BeginPass(int streamflags, const CMatrix3D* UNUSED(texturematrix))
|
||||
{
|
||||
debug_assert(streamflags == (streamflags & (STREAM_POS|STREAM_NORMAL|STREAM_UV0)));
|
||||
|
||||
@ -311,7 +169,8 @@ void ShaderInstancingModelRenderer::BeginPass(int streamflags, const CMatrix3D*
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
void ShaderInstancingModelRenderer::EndPass(int streamflags)
|
||||
// Cleanup rendering pass.
|
||||
void InstancingModelRenderer::EndPass(int streamflags)
|
||||
{
|
||||
if (streamflags & STREAM_POS)
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
@ -325,7 +184,9 @@ void ShaderInstancingModelRenderer::EndPass(int streamflags)
|
||||
CVertexBuffer::Unbind();
|
||||
}
|
||||
|
||||
void ShaderInstancingModelRenderer::PrepareModelDef(int streamflags, const CModelDefPtr& def)
|
||||
|
||||
// Prepare UV coordinates for this modeldef
|
||||
void InstancingModelRenderer::PrepareModelDef(int streamflags, const CModelDefPtr& def)
|
||||
{
|
||||
m->imodeldef = (IModelDef*)def->GetRenderData(m);
|
||||
|
||||
@ -346,7 +207,9 @@ void ShaderInstancingModelRenderer::PrepareModelDef(int streamflags, const CMode
|
||||
glTexCoordPointer(2, GL_FLOAT, stride, base + m->imodeldef->m_UV.offset);
|
||||
}
|
||||
|
||||
void ShaderInstancingModelRenderer::RenderModel(int UNUSED(streamflags), CModel* model, void* UNUSED(data))
|
||||
|
||||
// Render one model
|
||||
void InstancingModelRenderer::RenderModel(int UNUSED(streamflags), CModel* model, void* UNUSED(data))
|
||||
{
|
||||
CModelDefPtr mdldef = model->GetModelDef();
|
||||
|
||||
|
@ -28,22 +28,14 @@
|
||||
struct InstancingModelRendererInternals;
|
||||
|
||||
/**
|
||||
* Class InstancingModelRenderer: Render non-animated (but potentially
|
||||
* moving models) using vertex shaders and minimal state changes.
|
||||
*
|
||||
* @note You should verify hardware capabilities using IsAvailable
|
||||
* before creating this model renderer.
|
||||
* Render non-animated (but potentially moving) models using a ShaderRenderModifier.
|
||||
* This just passes through the vertex data directly; the modifier is responsible
|
||||
* for setting any shader uniforms etc (including the instancing transform).
|
||||
*/
|
||||
class InstancingModelRenderer : public ModelVertexRenderer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* InstancingModelRenderer: Constructor.
|
||||
*
|
||||
* @param colorIsDiffuseOnly if true, the primary color sent to the fragment stage
|
||||
* contains only the diffuse term, and not the ambient
|
||||
*/
|
||||
InstancingModelRenderer(bool colorIsDiffuseOnly);
|
||||
InstancingModelRenderer();
|
||||
~InstancingModelRenderer();
|
||||
|
||||
// Implementations
|
||||
@ -56,36 +48,8 @@ public:
|
||||
void PrepareModelDef(int streamflags, const CModelDefPtr& def);
|
||||
void RenderModel(int streamflags, CModel* model, void* data);
|
||||
|
||||
/**
|
||||
* IsAvailable: Determines whether this model renderer can be used
|
||||
* given the OpenGL implementation specific limits.
|
||||
*
|
||||
* @note Do not attempt to construct a InstancingModelRenderer object
|
||||
* when IsAvailable returns false.
|
||||
*
|
||||
* @return true if the OpenGL implementation can support this
|
||||
* model renderer.
|
||||
*/
|
||||
static bool IsAvailable();
|
||||
|
||||
protected:
|
||||
InstancingModelRendererInternals* m;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render non-animated (but potentially moving) models using a ShaderRenderModifier.
|
||||
* This just passes through the vertex data directly; the modifier is responsible
|
||||
* for setting any shader uniforms etc (including the instancing transform).
|
||||
*/
|
||||
class ShaderInstancingModelRenderer : public InstancingModelRenderer
|
||||
{
|
||||
public:
|
||||
ShaderInstancingModelRenderer();
|
||||
|
||||
void BeginPass(int streamflags, const CMatrix3D* texturematrix);
|
||||
void EndPass(int streamflags);
|
||||
void PrepareModelDef(int streamflags, const CModelDefPtr& def);
|
||||
void RenderModel(int streamflags, CModel* model, void* data);
|
||||
};
|
||||
|
||||
#endif // INCLUDED_INSTANCINGMODELRENDERER
|
||||
|
@ -1,146 +0,0 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/res/graphics/ogl_shader.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/Filesystem.h"
|
||||
#include "renderer/Renderer.h"
|
||||
#include "renderer/RenderPathVertexShader.h"
|
||||
|
||||
|
||||
void VS_GlobalLight::Init(Handle shader)
|
||||
{
|
||||
m_Ambient = ogl_program_get_uniform_location(shader, "ambient");
|
||||
m_SunDir = ogl_program_get_uniform_location(shader, "sunDir");
|
||||
m_SunColor = ogl_program_get_uniform_location(shader, "sunColor");
|
||||
}
|
||||
|
||||
void VS_Instancing::Init(Handle shader)
|
||||
{
|
||||
m_Instancing1 = ogl_program_get_attrib_location(shader, "Instancing1");
|
||||
m_Instancing2 = ogl_program_get_attrib_location(shader, "Instancing2");
|
||||
m_Instancing3 = ogl_program_get_attrib_location(shader, "Instancing3");
|
||||
}
|
||||
|
||||
void VS_PosToUV1::Init(Handle shader)
|
||||
{
|
||||
m_TextureMatrix1 = ogl_program_get_uniform_location(shader, "TextureMatrix1");
|
||||
debug_assert(m_TextureMatrix1 >= 0);
|
||||
m_TextureMatrix2 = ogl_program_get_uniform_location(shader, "TextureMatrix2");
|
||||
debug_assert(m_TextureMatrix2 >= 0);
|
||||
m_TextureMatrix3 = ogl_program_get_uniform_location(shader, "TextureMatrix3");
|
||||
debug_assert(m_TextureMatrix3 >= 0);
|
||||
}
|
||||
|
||||
RenderPathVertexShader::RenderPathVertexShader()
|
||||
{
|
||||
m_ModelLight = 0;
|
||||
m_ModelLightP = 0;
|
||||
m_InstancingLight = 0;
|
||||
m_Instancing = 0;
|
||||
}
|
||||
|
||||
RenderPathVertexShader::~RenderPathVertexShader()
|
||||
{
|
||||
if (m_ModelLight)
|
||||
ogl_program_free(m_ModelLight);
|
||||
if (m_ModelLightP)
|
||||
ogl_program_free(m_ModelLightP);
|
||||
if (m_InstancingLight)
|
||||
ogl_program_free(m_InstancingLight);
|
||||
if (m_Instancing)
|
||||
ogl_program_free(m_Instancing);
|
||||
}
|
||||
|
||||
// Initialize this render path.
|
||||
// Use delayed initialization so that we can fallback to a different render path
|
||||
// if anything went wrong and use the destructor to clean things up.
|
||||
bool RenderPathVertexShader::Init()
|
||||
{
|
||||
if (!g_Renderer.m_Caps.m_VertexShader)
|
||||
return false;
|
||||
|
||||
m_ModelLight = ogl_program_load(g_VFS, L"shaders/model_light.xml");
|
||||
if (m_ModelLight < 0)
|
||||
{
|
||||
LOGWARNING(L"Failed to load shaders/model_light.xml: %i\n", (int)m_ModelLight);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ModelLightP = ogl_program_load(g_VFS, L"shaders/model_lightp.xml");
|
||||
if (m_ModelLightP < 0)
|
||||
{
|
||||
LOGWARNING(L"Failed to load shaders/model_lightp.xml: %i\n", (int)m_ModelLightP);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_InstancingLight = ogl_program_load(g_VFS, L"shaders/instancing_light.xml");
|
||||
if (m_InstancingLight < 0)
|
||||
{
|
||||
LOGWARNING(L"Failed to load shaders/instancing_light.xml: %i\n", (int)m_InstancingLight);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_InstancingLightP = ogl_program_load(g_VFS, L"shaders/instancing_lightp.xml");
|
||||
if (m_InstancingLightP < 0)
|
||||
{
|
||||
LOGWARNING(L"Failed to load shaders/instancing_lightp.xml: %i\n", (int)m_InstancingLightP);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Instancing = ogl_program_load(g_VFS, L"shaders/instancing.xml");
|
||||
if (m_Instancing < 0)
|
||||
{
|
||||
LOGWARNING(L"Failed to load shaders/instancing.xml: %i\n", (int)m_Instancing);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_InstancingP = ogl_program_load(g_VFS, L"shaders/instancingp.xml");
|
||||
if (m_InstancingP < 0)
|
||||
{
|
||||
LOGWARNING(L"Failed to load shaders/instancingp.xml: %i\n", (int)m_InstancingP);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// This is quite the hack, but due to shader reloads,
|
||||
// the uniform locations might have changed under us.
|
||||
void RenderPathVertexShader::BeginFrame()
|
||||
{
|
||||
m_ModelLight_Light.Init(m_ModelLight);
|
||||
|
||||
m_ModelLightP_Light.Init(m_ModelLightP);
|
||||
m_ModelLightP_PosToUV1.Init(m_ModelLightP);
|
||||
|
||||
m_InstancingLight_Light.Init(m_InstancingLight);
|
||||
m_InstancingLight_Instancing.Init(m_InstancingLight);
|
||||
|
||||
m_InstancingLightP_Light.Init(m_InstancingLightP);
|
||||
m_InstancingLightP_Instancing.Init(m_InstancingLightP);
|
||||
m_InstancingLightP_PosToUV1.Init(m_InstancingLightP);
|
||||
|
||||
m_Instancing_Instancing.Init(m_Instancing);
|
||||
|
||||
m_InstancingP_Instancing.Init(m_InstancingP);
|
||||
m_InstancingP_PosToUV1.Init(m_InstancingP);
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_RENDERPATHVERTEXSHADER
|
||||
#define INCLUDED_RENDERPATHVERTEXSHADER
|
||||
|
||||
#include "graphics/LightEnv.h"
|
||||
|
||||
// Interface for globallight.vs
|
||||
struct VS_GlobalLight
|
||||
{
|
||||
public:
|
||||
void Init(Handle shader);
|
||||
|
||||
void SetFromLightEnv(const CLightEnv& lightenv, bool units) const
|
||||
{
|
||||
SetAmbient(units ? lightenv.m_UnitsAmbientColor : lightenv.m_TerrainAmbientColor);
|
||||
SetSunDir(lightenv.GetSunDir());
|
||||
SetSunColor(lightenv.m_SunColor);
|
||||
}
|
||||
|
||||
void SetAmbient(const RGBColor& color) const
|
||||
{
|
||||
pglUniform3fvARB(m_Ambient, 1, &color.X);
|
||||
}
|
||||
|
||||
void SetSunDir(const CVector3D& sundir) const
|
||||
{
|
||||
pglUniform3fvARB(m_SunDir, 1, &sundir.X);
|
||||
}
|
||||
|
||||
void SetSunColor(const RGBColor& color) const
|
||||
{
|
||||
pglUniform3fvARB(m_SunColor, 1, &color.X);
|
||||
}
|
||||
|
||||
private:
|
||||
GLint m_Ambient;
|
||||
GLint m_SunDir;
|
||||
GLint m_SunColor;
|
||||
};
|
||||
|
||||
// Interface for instancing_base.vs
|
||||
struct VS_Instancing
|
||||
{
|
||||
public:
|
||||
void Init(Handle shader);
|
||||
|
||||
void SetMatrix(const CMatrix3D& mat) const
|
||||
{
|
||||
pglVertexAttrib4fARB(m_Instancing1, mat._11, mat._12, mat._13, mat._14);
|
||||
pglVertexAttrib4fARB(m_Instancing2, mat._21, mat._22, mat._23, mat._24);
|
||||
pglVertexAttrib4fARB(m_Instancing3, mat._31, mat._32, mat._33, mat._34);
|
||||
}
|
||||
|
||||
private:
|
||||
GLint m_Instancing1;
|
||||
GLint m_Instancing2;
|
||||
GLint m_Instancing3;
|
||||
};
|
||||
|
||||
|
||||
// Interface for postouv1.vs
|
||||
struct VS_PosToUV1
|
||||
{
|
||||
public:
|
||||
void Init(Handle shader);
|
||||
|
||||
void SetMatrix(const CMatrix3D& mat) const
|
||||
{
|
||||
pglUniform4fARB(m_TextureMatrix1, mat._11, mat._12, mat._13, mat._14);
|
||||
pglUniform4fARB(m_TextureMatrix2, mat._21, mat._22, mat._23, mat._24);
|
||||
pglUniform4fARB(m_TextureMatrix3, mat._31, mat._32, mat._33, mat._34);
|
||||
}
|
||||
|
||||
private:
|
||||
GLint m_TextureMatrix1;
|
||||
GLint m_TextureMatrix2;
|
||||
GLint m_TextureMatrix3;
|
||||
};
|
||||
|
||||
class RenderPathVertexShader
|
||||
{
|
||||
public:
|
||||
RenderPathVertexShader();
|
||||
~RenderPathVertexShader();
|
||||
|
||||
// Initialize this render path.
|
||||
bool Init();
|
||||
|
||||
// Call once per frame to update program stuff
|
||||
void BeginFrame();
|
||||
|
||||
public:
|
||||
Handle m_ModelLight;
|
||||
VS_GlobalLight m_ModelLight_Light;
|
||||
|
||||
Handle m_ModelLightP;
|
||||
VS_GlobalLight m_ModelLightP_Light;
|
||||
VS_PosToUV1 m_ModelLightP_PosToUV1;
|
||||
|
||||
Handle m_InstancingLight;
|
||||
VS_GlobalLight m_InstancingLight_Light;
|
||||
VS_Instancing m_InstancingLight_Instancing;
|
||||
|
||||
Handle m_InstancingLightP;
|
||||
VS_GlobalLight m_InstancingLightP_Light;
|
||||
VS_Instancing m_InstancingLightP_Instancing;
|
||||
VS_PosToUV1 m_InstancingLightP_PosToUV1;
|
||||
|
||||
Handle m_Instancing;
|
||||
VS_Instancing m_Instancing_Instancing;
|
||||
|
||||
Handle m_InstancingP;
|
||||
VS_Instancing m_InstancingP_Instancing;
|
||||
VS_PosToUV1 m_InstancingP_PosToUV1;
|
||||
};
|
||||
|
||||
#endif // INCLUDED_RENDERPATHVERTEXSHADER
|
@ -60,7 +60,6 @@
|
||||
#include "renderer/ParticleRenderer.h"
|
||||
#include "renderer/PlayerRenderer.h"
|
||||
#include "renderer/RenderModifiers.h"
|
||||
#include "renderer/RenderPathVertexShader.h"
|
||||
#include "renderer/ShadowMap.h"
|
||||
#include "renderer/SkyManager.h"
|
||||
#include "renderer/TerrainOverlay.h"
|
||||
@ -272,12 +271,7 @@ public:
|
||||
// rendering and submission; use the aliases above instead.
|
||||
ModelRenderer* pal_NormalFF[NumVertexTypes];
|
||||
ModelRenderer* pal_PlayerFF[NumVertexTypes];
|
||||
ModelRenderer* pal_NormalHWLit[NumVertexTypes];
|
||||
ModelRenderer* pal_PlayerHWLit[NumVertexTypes];
|
||||
ModelRenderer* pal_NormalInstancing[NumVertexTypes];
|
||||
ModelRenderer* pal_PlayerInstancing[NumVertexTypes];
|
||||
ModelRenderer* pal_TranspFF[NumVertexTypes];
|
||||
ModelRenderer* pal_TranspHWLit[NumVertexTypes];
|
||||
ModelRenderer* pal_TranspSortAll;
|
||||
|
||||
ModelRenderer* pal_NormalShader;
|
||||
@ -287,8 +281,6 @@ public:
|
||||
ModelRenderer* pal_TranspShader;
|
||||
|
||||
ModelVertexRendererPtr VertexFF[NumVertexTypes];
|
||||
ModelVertexRendererPtr VertexHWLit[NumVertexTypes];
|
||||
ModelVertexRendererPtr VertexInstancing[NumVertexTypes];
|
||||
ModelVertexRendererPtr VertexPolygonSort;
|
||||
ModelVertexRendererPtr VertexRendererShader;
|
||||
ModelVertexRendererPtr VertexInstancingShader;
|
||||
@ -344,11 +336,6 @@ public:
|
||||
Model.pal_NormalFF[vertexType] = 0;
|
||||
Model.pal_PlayerFF[vertexType] = 0;
|
||||
Model.pal_TranspFF[vertexType] = 0;
|
||||
Model.pal_NormalHWLit[vertexType] = 0;
|
||||
Model.pal_PlayerHWLit[vertexType] = 0;
|
||||
Model.pal_TranspHWLit[vertexType] = 0;
|
||||
Model.pal_NormalInstancing[vertexType] = 0;
|
||||
Model.pal_PlayerInstancing[vertexType] = 0;
|
||||
}
|
||||
Model.pal_TranspSortAll = 0;
|
||||
|
||||
@ -371,18 +358,6 @@ public:
|
||||
delete terrainRenderer;
|
||||
}
|
||||
|
||||
bool CanUseRenderPathVertexShader()
|
||||
{
|
||||
for(int vertexType = 0; vertexType < NumVertexTypes; ++vertexType)
|
||||
{
|
||||
if (!Model.pal_NormalHWLit[vertexType] ||
|
||||
!Model.pal_PlayerHWLit[vertexType])
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the OpenGL projection and modelview matrices and the viewport according
|
||||
* to the given camera.
|
||||
@ -444,8 +419,6 @@ CRenderer::CRenderer()
|
||||
m_FastPlayerColor = true;
|
||||
m_SkipSubmit = false;
|
||||
|
||||
m_VertexShader = 0;
|
||||
|
||||
m_Options.m_NoVBO = false;
|
||||
m_Options.m_NoFramebufferObject = false;
|
||||
m_Options.m_RenderPath = RP_DEFAULT;
|
||||
@ -487,11 +460,6 @@ CRenderer::~CRenderer()
|
||||
delete m->Model.pal_NormalFF[vertexType];
|
||||
delete m->Model.pal_PlayerFF[vertexType];
|
||||
delete m->Model.pal_TranspFF[vertexType];
|
||||
delete m->Model.pal_NormalHWLit[vertexType];
|
||||
delete m->Model.pal_PlayerHWLit[vertexType];
|
||||
delete m->Model.pal_TranspHWLit[vertexType];
|
||||
delete m->Model.pal_NormalInstancing[vertexType];
|
||||
delete m->Model.pal_PlayerInstancing[vertexType];
|
||||
}
|
||||
delete m->Model.pal_TranspSortAll;
|
||||
|
||||
@ -501,10 +469,6 @@ CRenderer::~CRenderer()
|
||||
delete m->Model.pal_PlayerInstancingShader;
|
||||
delete m->Model.pal_TranspShader;
|
||||
|
||||
// general
|
||||
delete m_VertexShader;
|
||||
m_VertexShader = 0;
|
||||
|
||||
// we no longer UnloadAlphaMaps / UnloadWaterTextures here -
|
||||
// that is the responsibility of the module that asked for
|
||||
// them to be loaded (i.e. CGameView).
|
||||
@ -651,47 +615,19 @@ bool CRenderer::Open(int width, int height)
|
||||
EnumCaps();
|
||||
m->shadow->SetUseDepthTexture(true);
|
||||
|
||||
m_VertexShader = new RenderPathVertexShader;
|
||||
if (!m_VertexShader->Init())
|
||||
{
|
||||
delete m_VertexShader;
|
||||
m_VertexShader = 0;
|
||||
}
|
||||
|
||||
|
||||
// model rendering
|
||||
m->Model.VertexFF[AmbientDiffuse] = ModelVertexRendererPtr(new FixedFunctionModelRenderer(false));
|
||||
m->Model.VertexFF[OnlyDiffuse] = ModelVertexRendererPtr(new FixedFunctionModelRenderer(true));
|
||||
if (HWLightingModelRenderer::IsAvailable())
|
||||
{
|
||||
m->Model.VertexHWLit[AmbientDiffuse] = ModelVertexRendererPtr(new HWLightingModelRenderer(false));
|
||||
m->Model.VertexHWLit[OnlyDiffuse] = ModelVertexRendererPtr(new HWLightingModelRenderer(true));
|
||||
}
|
||||
if (InstancingModelRenderer::IsAvailable())
|
||||
{
|
||||
m->Model.VertexInstancing[AmbientDiffuse] = ModelVertexRendererPtr(new InstancingModelRenderer(false));
|
||||
m->Model.VertexInstancing[OnlyDiffuse] = ModelVertexRendererPtr(new InstancingModelRenderer(true));
|
||||
}
|
||||
m->Model.VertexPolygonSort = ModelVertexRendererPtr(new PolygonSortModelRenderer);
|
||||
m->Model.VertexRendererShader = ModelVertexRendererPtr(new ShaderModelRenderer);
|
||||
m->Model.VertexInstancingShader = ModelVertexRendererPtr(new ShaderInstancingModelRenderer);
|
||||
m->Model.VertexInstancingShader = ModelVertexRendererPtr(new InstancingModelRenderer);
|
||||
|
||||
for(int vertexType = 0; vertexType < NumVertexTypes; ++vertexType)
|
||||
{
|
||||
m->Model.pal_NormalFF[vertexType] = new BatchModelRenderer(m->Model.VertexFF[vertexType]);
|
||||
m->Model.pal_PlayerFF[vertexType] = new BatchModelRenderer(m->Model.VertexFF[vertexType]);
|
||||
m->Model.pal_TranspFF[vertexType] = new SortModelRenderer(m->Model.VertexFF[vertexType]);
|
||||
if (m->Model.VertexHWLit[vertexType])
|
||||
{
|
||||
m->Model.pal_NormalHWLit[vertexType] = new BatchModelRenderer(m->Model.VertexHWLit[vertexType]);
|
||||
m->Model.pal_PlayerHWLit[vertexType] = new BatchModelRenderer(m->Model.VertexHWLit[vertexType]);
|
||||
m->Model.pal_TranspHWLit[vertexType] = new SortModelRenderer(m->Model.VertexHWLit[vertexType]);
|
||||
}
|
||||
if (m->Model.VertexInstancing[vertexType])
|
||||
{
|
||||
m->Model.pal_NormalInstancing[vertexType] = new BatchModelRenderer(m->Model.VertexInstancing[vertexType]);
|
||||
m->Model.pal_PlayerInstancing[vertexType] = new BatchModelRenderer(m->Model.VertexInstancing[vertexType]);
|
||||
}
|
||||
}
|
||||
|
||||
m->Model.pal_TranspSortAll = new SortModelRenderer(m->Model.VertexPolygonSort);
|
||||
@ -833,15 +769,6 @@ void CRenderer::SetRenderPath(RenderPath rp)
|
||||
rp = RP_FIXED;
|
||||
}
|
||||
|
||||
if (rp == RP_VERTEXSHADER)
|
||||
{
|
||||
if (!m->CanUseRenderPathVertexShader())
|
||||
{
|
||||
LOGWARNING(L"Falling back to fixed function\n");
|
||||
rp = RP_FIXED;
|
||||
}
|
||||
}
|
||||
|
||||
if (rp == RP_SHADER)
|
||||
{
|
||||
if (!m_Caps.m_ARBProgram)
|
||||
@ -864,7 +791,6 @@ CStr CRenderer::GetRenderPathName(RenderPath rp)
|
||||
switch(rp) {
|
||||
case RP_DEFAULT: return "default";
|
||||
case RP_FIXED: return "fixed";
|
||||
case RP_VERTEXSHADER: return "vertexshader";
|
||||
case RP_SHADER: return "shader";
|
||||
default: return "(invalid)";
|
||||
}
|
||||
@ -874,8 +800,6 @@ CRenderer::RenderPath CRenderer::GetRenderPathByName(const CStr& name)
|
||||
{
|
||||
if (name == "fixed")
|
||||
return RP_FIXED;
|
||||
if (name == "vertexshader")
|
||||
return RP_VERTEXSHADER;
|
||||
if (name == "shader")
|
||||
return RP_SHADER;
|
||||
if (name == "default")
|
||||
@ -958,9 +882,6 @@ void CRenderer::BeginFrame()
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_VertexShader)
|
||||
m_VertexShader->BeginFrame();
|
||||
|
||||
// choose model renderers for this frame
|
||||
int vertexType;
|
||||
|
||||
@ -991,30 +912,11 @@ void CRenderer::BeginFrame()
|
||||
m->Model.ModTransparent = m->Model.ModTransparentUnlit;
|
||||
}
|
||||
|
||||
if (m_Options.m_RenderPath == RP_VERTEXSHADER)
|
||||
{
|
||||
debug_assert(m->Model.pal_NormalHWLit[vertexType] != 0);
|
||||
m->Model.NormalInstancing = m->Model.pal_NormalFF[vertexType];
|
||||
m->Model.Normal = m->Model.pal_NormalFF[vertexType];
|
||||
|
||||
if (m->Model.pal_NormalInstancing)
|
||||
m->Model.NormalInstancing = m->Model.pal_NormalInstancing[vertexType];
|
||||
else
|
||||
m->Model.NormalInstancing = m->Model.pal_NormalHWLit[vertexType];
|
||||
m->Model.Normal = m->Model.pal_NormalHWLit[vertexType];
|
||||
|
||||
if (m->Model.pal_PlayerInstancing)
|
||||
m->Model.PlayerInstancing = m->Model.pal_PlayerInstancing[vertexType];
|
||||
else
|
||||
m->Model.PlayerInstancing = m->Model.pal_PlayerHWLit[vertexType];
|
||||
m->Model.Player = m->Model.pal_PlayerHWLit[vertexType];
|
||||
}
|
||||
else
|
||||
{
|
||||
m->Model.NormalInstancing = m->Model.pal_NormalFF[vertexType];
|
||||
m->Model.Normal = m->Model.pal_NormalFF[vertexType];
|
||||
|
||||
m->Model.PlayerInstancing = m->Model.pal_PlayerFF[vertexType];
|
||||
m->Model.Player = m->Model.pal_PlayerFF[vertexType];
|
||||
}
|
||||
m->Model.PlayerInstancing = m->Model.pal_PlayerFF[vertexType];
|
||||
m->Model.Player = m->Model.pal_PlayerFF[vertexType];
|
||||
|
||||
m->Model.ModSolid = m->Model.ModSolidColor;
|
||||
m->Model.ModSolidInstancing = m->Model.ModSolidColor;
|
||||
@ -1023,8 +925,6 @@ void CRenderer::BeginFrame()
|
||||
|
||||
if (m_SortAllTransparent)
|
||||
m->Model.Transp = m->Model.pal_TranspSortAll;
|
||||
else if (m_Options.m_RenderPath == RP_VERTEXSHADER)
|
||||
m->Model.Transp = m->Model.pal_TranspHWLit[vertexType];
|
||||
else
|
||||
m->Model.Transp = m->Model.pal_TranspFF[vertexType];
|
||||
}
|
||||
|
@ -94,9 +94,6 @@ public:
|
||||
// Classic fixed function.
|
||||
RP_FIXED,
|
||||
|
||||
// Use (GL 2.0) vertex shaders for T&L when possible.
|
||||
RP_VERTEXSHADER,
|
||||
|
||||
// Use new ARB/GLSL system
|
||||
RP_SHADER
|
||||
};
|
||||
@ -424,10 +421,6 @@ protected:
|
||||
// per-frame renderer stats
|
||||
Stats m_Stats;
|
||||
|
||||
// Additional state that is only available when the vertex shader
|
||||
// render path is used (according to m_Options.m_RenderPath)
|
||||
RenderPathVertexShader* m_VertexShader;
|
||||
|
||||
/// If false, use a multipass fallback for player colors.
|
||||
bool m_FastPlayerColor;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user