1
0
forked from 0ad/0ad

More GLES compatibility, mainly around terrain rendering.

This was SVN commit r11059.
This commit is contained in:
Ykkrosh 2012-02-13 14:02:14 +00:00
parent cba82eec2f
commit 4bf59b9a7d
25 changed files with 262 additions and 731 deletions

View File

@ -6,6 +6,9 @@
<uniform name="textureTransform" loc="1" type="vec4"/>
<uniform name="losTransform" loc="2" type="vec2"/>
<uniform name="shadowTransform" loc="3" type="mat4"/>
<stream name="pos"/>
<stream name="color"/>
<stream name="uv0"/>
</vertex>
<fragment file="terrain_common.fp">

View File

@ -8,6 +8,10 @@
<uniform name="textureTransform" loc="1" type="vec4"/>
<uniform name="losTransform" loc="2" type="vec2"/>
<uniform name="shadowTransform" loc="3" type="mat4"/>
<stream name="pos"/>
<stream name="color"/>
<stream name="uv0"/>
<stream name="uv1"/>
</vertex>
<fragment file="terrain_common.fp">

View File

@ -8,6 +8,9 @@
<uniform name="textureTransform" loc="1" type="vec4"/>
<uniform name="losTransform" loc="2" type="vec2"/>
<uniform name="shadowTransform" loc="3" type="mat4"/>
<stream name="pos"/>
<stream name="color"/>
<stream name="uv0"/>
</vertex>
<fragment file="terrain_common.fp">

View File

@ -9,13 +9,17 @@ uniform vec2 translation;
varying vec3 worldPos;
varying float waterDepth;
attribute vec3 a_vertex;
attribute vec4 a_encodedDepth;
void main()
{
worldPos = gl_Vertex.xyz;
waterDepth = dot(gl_Color.xyz, vec3(255.0, -255.0, 1.0));
gl_TexCoord[0].st = gl_Vertex.xz*repeatScale + translation;
gl_TexCoord[1] = reflectionMatrix * gl_Vertex; // projective texturing
gl_TexCoord[2] = refractionMatrix * gl_Vertex;
gl_TexCoord[3] = losMatrix * gl_Vertex;
gl_Position = ftransform();
worldPos = a_vertex.xyz;
waterDepth = dot(a_encodedDepth.xyz, vec3(255.0, -255.0, 1.0));
gl_TexCoord[0].st = a_vertex.xz*repeatScale + translation;
gl_TexCoord[1] = reflectionMatrix * vec4(a_vertex, 1.0); // projective texturing
gl_TexCoord[2] = refractionMatrix * vec4(a_vertex, 1.0);
gl_TexCoord[3] = losMatrix * vec4(a_vertex, 1.0);
gl_Position = gl_ModelViewProjectionMatrix * vec4(a_vertex, 1.0);
}

View File

@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<program type="glsl">
<vertex file="water_high.vs"/>
<vertex file="water_high.vs">
<stream name="pos"/>
<stream name="color"/>
<attrib name="a_vertex" semantics="gl_Vertex"/>
<attrib name="a_encodedDepth" semantics="gl_Color"/>
</vertex>
<fragment file="water_high.fs"/>
</program>

View File

@ -369,6 +369,9 @@ void CCamera::LookAlong(CVector3D camera, CVector3D orientation, CVector3D up)
// Render the camera's frustum
void CCamera::Render(int intermediates) const
{
#if CONFIG2_GLES
#warning TODO: implement camera frustum for GLES
#else
CVector3D nearPoints[4];
CVector3D farPoints[4];
@ -426,4 +429,5 @@ void CCamera::Render(int intermediates) const
glVertex3fv(&intermediatePoints[3].X);
glEnd();
}
#endif
}

View File

@ -91,6 +91,10 @@ void CCinemaPath::DrawSpline(const CVector4D& RGBA, int smoothness, bool lines)
float start = MaxDistance / smoothness;
float time=0;
#if CONFIG2_GLES
#warning TODO: do something about CCinemaPath on GLES
#else
glColor4f( RGBA.m_X, RGBA.m_Y, RGBA.m_Z, RGBA.m_W );
if ( lines )
{
@ -133,7 +137,10 @@ void CCinemaPath::DrawSpline(const CVector4D& RGBA, int smoothness, bool lines)
glPointSize(1.0f);
glDisable(GL_POINT_SMOOTH);
}
#endif
}
void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation)
{
CCamera *Cam = g_Game->GetView()->GetCamera();

View File

@ -120,7 +120,7 @@ void CLOSTexture::ConstructTexture(int unit)
// overwrite with glTexSubImage2D later
u8* texData = new u8[m_TextureSize * m_TextureSize];
memset(texData, 0x00, m_TextureSize * m_TextureSize);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, m_TextureSize, m_TextureSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texData);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, m_TextureSize, m_TextureSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texData);
delete[] texData;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

View File

@ -25,20 +25,9 @@
CMaterial NullMaterial;
// Values as taken straight from the Blue Book (god bless the Blue Book)
static SMaterialColor IdentityDiffuse(0.8f, 0.8f, 0.8f, 1.0f);
static SMaterialColor IdentityAmbient(0.2f, 0.2f, 0.2f, 1.0f);
static SMaterialColor IdentitySpecular(0.0f, 0.0f, 0.0f, 1.0f);
static SMaterialColor IdentityEmissive(0.0f, 0.0f, 0.0f, 1.0f);
static SMaterialColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f);
CMaterial::CMaterial()
: m_Diffuse(IdentityDiffuse),
m_Ambient(IdentityAmbient),
m_Specular(IdentitySpecular),
m_Emissive(IdentityEmissive),
m_SpecularPower(0.0f),
CMaterial::CMaterial() :
m_Alpha(false),
m_PlayerID(INVALID_PLAYER),
m_TextureColor(BrokenColor),
@ -47,41 +36,6 @@ CMaterial::CMaterial()
{
}
void CMaterial::Bind()
{
glMaterialf(GL_FRONT, GL_SHININESS, m_SpecularPower);
glMaterialfv(GL_FRONT, GL_DIFFUSE, &m_Diffuse.r);
glMaterialfv(GL_FRONT, GL_AMBIENT, &m_Ambient.r);
glMaterialfv(GL_FRONT, GL_SPECULAR, &m_Specular.r);
glMaterialfv(GL_FRONT, GL_EMISSION, &m_Emissive.r);
ogl_WarnIfError();
}
void CMaterial::Unbind()
{
}
SMaterialColor CMaterial::GetDiffuse()
{
return m_Diffuse;
}
SMaterialColor CMaterial::GetAmbient()
{
return m_Ambient;
}
SMaterialColor CMaterial::GetSpecular()
{
return m_Specular;
}
SMaterialColor CMaterial::GetEmissive()
{
return m_Emissive;
}
SMaterialColor CMaterial::GetObjectColor()
{
if (m_UseTextureColor)
@ -124,41 +78,6 @@ void CMaterial::SetTexture(const CStr& texture)
m_Texture = texture;
}
void CMaterial::SetVertexProgram(const CStr& prog)
{
m_VertexProgram = prog;
}
void CMaterial::SetFragmentProgram(const CStr& prog)
{
m_FragmentProgram = prog;
}
void CMaterial::SetDiffuse(const SMaterialColor& color)
{
m_Diffuse = color;
}
void CMaterial::SetAmbient(const SMaterialColor& color)
{
m_Ambient = color;
}
void CMaterial::SetSpecular(const SMaterialColor& color)
{
m_Specular = color;
}
void CMaterial::SetEmissive(const SMaterialColor& color)
{
m_Emissive = color;
}
void CMaterial::SetSpecularPower(float power)
{
m_SpecularPower = power;
}
void CMaterial::SetUsesAlpha(bool flag)
{
m_Alpha = flag;

View File

@ -31,17 +31,7 @@ class CMaterial
public:
CMaterial();
void Bind();
void Unbind();
const CStr& GetTexture() { return m_Texture; }
const CStr& GetVertexProgram() { return m_VertexProgram; }
const CStr& GetFragmentProgram() { return m_FragmentProgram; }
SMaterialColor GetDiffuse();
SMaterialColor GetAmbient();
SMaterialColor GetSpecular();
SMaterialColor GetEmissive();
float GetSpecularPower() { return m_SpecularPower; }
bool UsesAlpha() { return m_Alpha; }
@ -60,30 +50,12 @@ public:
void SetUseTextureColor(bool use);
void SetTexture(const CStr& texture);
void SetVertexProgram(const CStr& prog);
void SetFragmentProgram(const CStr& prog);
void SetDiffuse(const SMaterialColor& color);
void SetAmbient(const SMaterialColor& color);
void SetSpecular(const SMaterialColor& color);
void SetEmissive(const SMaterialColor& color);
void SetSpecularPower(float power);
void SetUsesAlpha(bool flag);
private:
// Various reflective color properties
SMaterialColor m_Diffuse;
SMaterialColor m_Ambient;
SMaterialColor m_Specular;
SMaterialColor m_Emissive;
float m_SpecularPower;
// Path to the materials texture
CStr m_Texture;
// Paths to vertex/fragment programs
CStr m_VertexProgram;
CStr m_FragmentProgram;
// Alpha required flag
bool m_Alpha;

View File

@ -21,81 +21,6 @@
#include "ps/XML/Xeromyces.h"
#include "MaterialManager.h"
static float ClampFloat(float value, float min, float max)
{
if(value < min)
return min;
else if(value > max)
return max;
return value;
}
static SMaterialColor ParseColor(const CStr& colorStr_)
{
SMaterialColor color;
CStr colorStr(colorStr_.Trim(PS_TRIM_BOTH));
CStr tmp;
int idx = 0;
long pos = colorStr.Find(' ');
while(colorStr.length())
{
if(pos == -1)
pos = (long)colorStr.length();
tmp = colorStr.substr(0, pos);
colorStr = colorStr.substr(pos);
colorStr = colorStr.Trim(PS_TRIM_LEFT);
pos = colorStr.Find(' ');
float value = 0.0f;
if(tmp.Find('.') != -1)
value = tmp.ToFloat();
else
{
int intValue = tmp.ToInt();
if(intValue > 0)
{
if(intValue > 255)
intValue = 255;
value = ((float)intValue) / 255.0f;
}
}
value = ClampFloat(value, 0.0f, 1.0f);
switch(idx)
{
case 0:
color.r = value;
break;
case 1:
color.g = value;
break;
case 2:
color.b = value;
break;
case 3:
color.a = value;
break;
default:
break;
}
if(idx >= 3)
break;
idx++;
}
return color;
}
static bool ParseUsage(CStr temp)
{
temp = temp.LowerCase().Trim(PS_TRIM_BOTH);
@ -108,80 +33,17 @@ static bool ParseUsage(CStr temp)
return false;
}
#if 0 // unused
static GLenum ParseAlphaFunc(CStr temp)
{
temp = temp.LowerCase().Trim(PS_TRIM_BOTH);
if(temp.empty())
return GL_NONE;
if(temp == CStr("never"))
return GL_NEVER;
else if(temp == CStr("less"))
return GL_LESS;
else if(temp == CStr("lequal"))
return GL_LEQUAL;
else if(temp == CStr("greater"))
return GL_GREATER;
else if(temp == CStr("gequal"))
return GL_GEQUAL;
else if(temp == CStr("equal"))
return GL_EQUAL;
else if(temp == CStr("notequal"))
return GL_NOTEQUAL;
else if(temp == CStr("always"))
return GL_ALWAYS;
else
return GL_NONE;
}
static GLenum ParseBlendFunc(CStr temp)
{
temp = temp.LowerCase().Trim(PS_TRIM_BOTH);
if(temp.empty())
return GL_NONE;
if(temp == CStr("zero"))
return GL_ZERO;
else if(temp == CStr("one"))
return GL_ONE;
else if(temp == CStr("sourcecolor"))
return GL_SRC_COLOR;
else if(temp == CStr("oneminussourcecolor"))
return GL_ONE_MINUS_SRC_COLOR;
else if(temp == CStr("destcolor"))
return GL_DST_COLOR;
else if(temp == CStr("oneminusdestcolor"))
return GL_ONE_MINUS_DST_COLOR;
else if(temp == CStr("sourcealpha"))
return GL_SRC_ALPHA;
else if(temp == CStr("oneminussourcealpha"))
return GL_ONE_MINUS_SRC_ALPHA;
else if(temp == CStr("destalpha"))
return GL_DST_ALPHA;
else if(temp == CStr("oneminusdestalpha"))
return GL_ONE_MINUS_DST_ALPHA;
else if(temp == CStr("sourcealphasaturate"))
return GL_SRC_ALPHA_SATURATE;
return GL_NONE;
}
#endif
CMaterialManager::CMaterialManager()
{
}
CMaterialManager::~CMaterialManager()
{
std::map<VfsPath, CMaterial*>::iterator iter;
for(iter = m_Materials.begin(); iter != m_Materials.end(); iter++)
{
if((*iter).second)
delete (*iter).second;
}
std::map<VfsPath, CMaterial*>::iterator iter;
for(iter = m_Materials.begin(); iter != m_Materials.end(); iter++)
delete (*iter).second;
m_Materials.clear();
m_Materials.clear();
}
CMaterial& CMaterialManager::LoadMaterial(const VfsPath& pathname)
@ -203,19 +65,8 @@ CMaterial& CMaterialManager::LoadMaterial(const VfsPath& pathname)
#define EL(x) int el_##x = xeroFile.GetElementID(#x)
#define AT(x) int at_##x = xeroFile.GetAttributeID(#x)
EL(texture);
EL(vertexprogram);
EL(fragmentprogram);
EL(colors);
AT(diffuse);
AT(ambient);
AT(specular);
//AT(emissive);
AT(specularpower);
EL(alpha);
AT(usage);
#undef AT
#undef EL
@ -237,34 +88,6 @@ CMaterial& CMaterialManager::LoadMaterial(const VfsPath& pathname)
CStr value(node.GetText());
material->SetTexture(value);
}
else if(token == el_vertexprogram)
{
CStr value(node.GetText());
material->SetVertexProgram(value);
}
else if(token == el_fragmentprogram)
{
CStr value(node.GetText());
material->SetFragmentProgram(value);
}
else if(token == el_colors)
{
temp = CStr(attrs.GetNamedItem(at_diffuse));
if(! temp.empty())
material->SetDiffuse(ParseColor(temp));
temp = CStr(attrs.GetNamedItem(at_ambient));
if(! temp.empty())
material->SetAmbient(ParseColor(temp));
temp = CStr(attrs.GetNamedItem(at_specular));
if(! temp.empty())
material->SetSpecular(ParseColor(temp));
temp = CStr(attrs.GetNamedItem(at_specularpower));
if(! temp.empty())
material->SetSpecularPower(ClampFloat(temp.ToFloat(), 0.0f, 1.0f));
}
else if(token == el_alpha)
{
temp = CStr(attrs.GetNamedItem(at_usage));

View File

@ -526,10 +526,16 @@ public:
virtual void NormalPointer(GLenum type, GLsizei stride, void* pointer)
{
pglVertexAttribPointerARB(2, 3, type, GL_FALSE, stride, pointer);
pglVertexAttribPointerARB(2, 3, type, GL_TRUE, stride, pointer);
m_ValidStreams |= STREAM_NORMAL;
}
virtual void ColorPointer(GLint size, GLenum type, GLsizei stride, void* pointer)
{
pglVertexAttribPointerARB(3, size, type, GL_TRUE, stride, pointer);
m_ValidStreams |= STREAM_COLOR;
}
virtual void TexCoordPointer(GLenum texture, GLint size, GLenum type, GLsizei stride, void* pointer)
{
pglVertexAttribPointerARB(8 + texture - GL_TEXTURE0, size, type, GL_FALSE, stride, pointer);
@ -695,10 +701,17 @@ void CShaderProgram::NormalPointer(GLenum type, GLsizei stride, void* pointer)
m_ValidStreams |= STREAM_NORMAL;
}
void CShaderProgram::ColorPointer(GLint size, GLenum type, GLsizei stride, void* pointer)
{
glColorPointer(size, type, stride, pointer);
m_ValidStreams |= STREAM_COLOR;
}
void CShaderProgram::TexCoordPointer(GLenum texture, GLint size, GLenum type, GLsizei stride, void* pointer)
{
pglActiveTextureARB(texture);
pglClientActiveTextureARB(texture);
glTexCoordPointer(size, type, stride, pointer);
pglClientActiveTextureARB(GL_TEXTURE0);
m_ValidStreams |= STREAM_UV0 << (texture - GL_TEXTURE0);
}

View File

@ -178,6 +178,7 @@ public:
virtual void VertexPointer(GLint size, GLenum type, GLsizei stride, void* pointer);
virtual void NormalPointer(GLenum type, GLsizei stride, void* pointer);
virtual void ColorPointer(GLint size, GLenum type, GLsizei stride, void* pointer);
virtual void TexCoordPointer(GLenum texture, GLint size, GLenum type, GLsizei stride, void* pointer);
/**

View File

@ -111,6 +111,32 @@ protected:
//////////////////////////////////////////////////////////////////////////
/**
* A shader that does nothing but provide a shader-compatible interface to
* fixed-function features, for compatibility with existing fixed-function
* code that isn't fully ported to the shader API.
*/
class CShaderProgramFFP_Dummy : public CShaderProgramFFP
{
public:
CShaderProgramFFP_Dummy() :
CShaderProgramFFP(0)
{
}
virtual void Bind()
{
BindClientStates();
}
virtual void Unbind()
{
UnbindClientStates();
}
};
//////////////////////////////////////////////////////////////////////////
class CShaderProgramFFP_OverlayLine : public CShaderProgramFFP
{
// Uniforms
@ -609,6 +635,8 @@ public:
/*static*/ CShaderProgram* CShaderProgram::ConstructFFP(const std::string& id, const std::map<CStr, CStr>& defines)
{
if (id == "dummy")
return new CShaderProgramFFP_Dummy();
if (id == "overlayline")
return new CShaderProgramFFP_OverlayLine(defines);
if (id == "gui_text")

View File

@ -1,212 +0,0 @@
/* Copyright (C) 2010 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 "Sprite.h"
#include "graphics/TextureManager.h"
#include "renderer/Renderer.h"
#include "lib/ogl.h"
#include "lib/res/graphics/ogl_tex.h"
CSprite::CSprite()
{
// default scale 1:1
m_scale.X = m_scale.Y = m_scale.Z = 1.0f;
// default position (0.0f, 0.0f, 0.0f)
m_translation.X = m_translation.Y = m_translation.Z = 0.0f;
// default size 1.0 x 1.0
SetSize(1.0f, 1.0f);
// default colour, white
m_colour[0] = m_colour[1] = m_colour[2] = m_colour[3] = 1.0f;
}
CSprite::~CSprite()
{
}
void CSprite::Render()
{
glPushMatrix();
glTranslatef(m_translation.X, m_translation.Y, m_translation.Z);
glScalef(m_scale.X, m_scale.Y, m_scale.Z);
BeginBillboard();
glDisable(GL_CULL_FACE);
if (m_texture)
m_texture->Bind();
glColor4fv(m_colour);
glBegin(GL_TRIANGLE_STRIP);
// bottom left
glTexCoord2f(0.0f, 0.0f);
glVertex3fv(m_coords[0].GetFloatArray());
// top left
glTexCoord2f(0.0f, 1.0f);
glVertex3fv(m_coords[1].GetFloatArray());
// bottom right
glTexCoord2f(1.0f, 0.0f);
glVertex3fv(m_coords[2].GetFloatArray());
// top left
glTexCoord2f(1.0f, 1.0f);
glVertex3fv(m_coords[3].GetFloatArray());
glEnd();
glEnable(GL_CULL_FACE);
EndBillboard();
}
void CSprite::SetTexture(const CTexturePtr& texture)
{
m_texture = texture;
}
void CSprite::SetSize(float width, float height)
{
m_width = width;
m_height = height;
float xOffset = m_width / 2;
float yOffset = m_height / 2;
// bottom left
m_coords[0].X = - (xOffset);
m_coords[0].Y = - (yOffset);
m_coords[0].Z = 0.0f;
// top left
m_coords[1].X = - (xOffset);
m_coords[1].Y = yOffset;
m_coords[1].Z = 0.0f;
// bottom right
m_coords[2].X = xOffset;
m_coords[2].Y = - (yOffset);
m_coords[2].Z = 0.0f;
// top right
m_coords[3].X = xOffset;
m_coords[3].Y = yOffset;
m_coords[3].Z = 0.0f;
}
float CSprite::GetWidth()
{
return m_width;
}
void CSprite::SetWidth(float width)
{
SetSize(width, m_height);
}
float CSprite::GetHeight()
{
return m_height;
}
void CSprite::SetHeight(float height)
{
SetSize(m_width, height);
}
CVector3D CSprite::GetTranslation()
{
return m_translation;
}
void CSprite::SetTranslation(CVector3D trans)
{
m_translation = trans;
}
void CSprite::SetTranslation(float x, float y, float z)
{
m_translation.X = x;
m_translation.Y = y;
m_translation.Z = z;
}
CVector3D CSprite::GetScale()
{
return m_scale;
}
void CSprite::SetScale(CVector3D scale)
{
m_scale = scale;
}
void CSprite::SetScale(float x, float y, float z)
{
m_scale.X = x;
m_scale.Y = y;
m_scale.Z = z;
}
void CSprite::SetColour(float * colour)
{
m_colour[0] = colour[0];
m_colour[1] = colour[1];
m_colour[2] = colour[2];
m_colour[3] = colour[3];
}
void CSprite::SetColour(float r, float g, float b, float a)
{
m_colour[0] = r;
m_colour[1] = g;
m_colour[2] = b;
m_colour[3] = a;
}
//Must call glPushMatrix() before this. Should be called before any other gl calls
void CSprite::BeginBillboard()
{
float newMatrix[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
float currentMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, currentMatrix);
newMatrix[0] = currentMatrix[0];
newMatrix[1] = currentMatrix[4];
newMatrix[2] = currentMatrix[8];
newMatrix[4] = currentMatrix[1];
newMatrix[5] = currentMatrix[5];
newMatrix[6] = currentMatrix[9];
newMatrix[8] = currentMatrix[2];
newMatrix[9] = currentMatrix[6];
newMatrix[10] = currentMatrix[10];
glMultMatrixf(newMatrix);
}
void CSprite::EndBillboard()
{
glPopMatrix();
}

View File

@ -1,85 +0,0 @@
/* Copyright (C) 2010 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/>.
*/
/*
* Billboarding sprite class - always faces the camera. It does this by
* getting the current model view matrix state.
*/
// Usage: Instantiate, then be sure to pass a loaded
// (using CTextureManager) texture before calling Render().
#ifndef INCLUDED_SPRITE
#define INCLUDED_SPRITE
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "maths/Vector3D.h"
#include "Texture.h"
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
class CSprite
{
public:
CSprite();
~CSprite();
void Render();
void SetTexture(const CTexturePtr& texture);
void SetSize(float width, float height);
float GetWidth();
void SetWidth(float width);
float GetHeight();
void SetHeight(float height);
CVector3D GetTranslation();
void SetTranslation(CVector3D pos);
void SetTranslation(float x, float y, float z);
CVector3D GetScale();
void SetScale(CVector3D scale);
void SetScale(float x, float y, float z);
void SetColour(float * colour);
void SetColour(float r, float g, float b, float a = 1.0f);
private:
void BeginBillboard();
void EndBillboard();
CTexturePtr m_texture;
CVector3D m_coords[4];
float m_width;
float m_height;
CVector3D m_translation;
CVector3D m_scale;
float m_colour[4];
};
#endif // INCLUDED_SPRITE

View File

@ -69,8 +69,10 @@ actually supported).
// some functions that are extensions in GL are core functions in GLES,
// so we should use them without the function pointer indirection
#define pglCompressedTexImage2DARB glCompressedTexImage2D
#define pglActiveTextureARB glActiveTexture
#define pglBlendEquationEXT glBlendEquation
#define pglClientActiveTextureARB glClientActiveTexture
#define pglCompressedTexImage2DARB glCompressedTexImage2D
#define pglAttachObjectARB glAttachShader
#define pglBindAttribLocationARB glBindAttribLocation
@ -97,6 +99,14 @@ actually supported).
#define pglUseProgramObjectARB glUseProgram
#define pglVertexAttribPointerARB glVertexAttribPointer
#define pglBindBufferARB glBindBuffer
#define pglBufferDataARB glBufferData
#define pglBufferSubDataARB glBufferSubData
#define pglDeleteBuffersARB glDeleteBuffers
#define pglGenBuffersARB glGenBuffers
#define GL_CLAMP_TO_BORDER GL_CLAMP_TO_EDGE // TODO: should fix code that relies on GL_CLAMP_TO_BORDER
typedef GLuint GLhandleARB;
#else

View File

@ -66,7 +66,7 @@ void CDecalRData::Update()
}
}
void CDecalRData::Render(const CShaderProgramPtr& shader)
void CDecalRData::Render(const CShaderProgramPtr& shader, bool isDummyShader)
{
m_Decal->m_Decal.m_Texture->Bind(0);
@ -86,14 +86,22 @@ void CDecalRData::Render(const CShaderProgramPtr& shader)
u8* indexBase = m_IndexArray.Bind();
if (!shader)
#if !CONFIG2_GLES
if (isDummyShader)
{
glColor3fv(m_Decal->GetShadingColor().FloatArray());
}
else
#endif
{
shader->Uniform("shadingColor", m_Decal->GetShadingColor());
}
glVertexPointer(3, GL_FLOAT, stride, base + m_Position.offset);
glColorPointer(4, GL_UNSIGNED_BYTE, stride, base + m_DiffuseColor.offset);
glTexCoordPointer(2, GL_FLOAT, stride, base + m_UV.offset);
shader->VertexPointer(3, GL_FLOAT, stride, base + m_Position.offset);
shader->ColorPointer(4, GL_UNSIGNED_BYTE, stride, base + m_DiffuseColor.offset);
shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, stride, base + m_UV.offset);
shader->AssertPointersBound();
if (!g_Renderer.m_SkipSubmit)
{

View File

@ -32,7 +32,7 @@ public:
void Update();
void Render(const CShaderProgramPtr& shader);
void Render(const CShaderProgramPtr& shader, bool isDummyShader);
CModelDecal* GetDecal() { return m_Decal; }

View File

@ -709,7 +709,7 @@ typedef POOLED_BATCH_MAP(CVertexBuffer*, IndexBufferBatches) VertexBufferBatches
// Group batches by texture
typedef POOLED_BATCH_MAP(CTerrainTextureEntry*, VertexBufferBatches) TextureBatches;
void CPatchRData::RenderBases(const std::vector<CPatchRData*>& patches, CShaderProgramPtr shader)
void CPatchRData::RenderBases(const std::vector<CPatchRData*>& patches, CShaderProgramPtr& shader, bool isDummyShader)
{
Allocators::Arena<> arena(ARENA_SIZE);
@ -749,18 +749,20 @@ void CPatchRData::RenderBases(const std::vector<CPatchRData*>& patches, CShaderP
{
itt->first->GetTexture()->Bind();
if (shader)
{
float c = itt->first->GetTextureMatrix()[0];
float ms = itt->first->GetTextureMatrix()[8];
shader->Uniform("textureTransform", c, ms, -ms, 0.f);
}
else
#if !CONFIG2_GLES
if (isDummyShader)
{
glMatrixMode(GL_TEXTURE);
glLoadMatrixf(itt->first->GetTextureMatrix());
glMatrixMode(GL_MODELVIEW);
}
else
#endif
{
float c = itt->first->GetTextureMatrix()[0];
float ms = itt->first->GetTextureMatrix()[8];
shader->Uniform("textureTransform", c, ms, -ms, 0.f);
}
}
else
{
@ -771,9 +773,11 @@ void CPatchRData::RenderBases(const std::vector<CPatchRData*>& patches, CShaderP
{
GLsizei stride = sizeof(SBaseVertex);
SBaseVertex *base = (SBaseVertex *)itv->first->Bind();
glVertexPointer(3, GL_FLOAT, stride, &base->m_Position[0]);
glColorPointer(4, GL_UNSIGNED_BYTE, stride, &base->m_DiffuseColor);
glTexCoordPointer(3, GL_FLOAT, stride, &base->m_Position[0]);
shader->VertexPointer(3, GL_FLOAT, stride, &base->m_Position[0]);
shader->ColorPointer(4, GL_UNSIGNED_BYTE, stride, &base->m_DiffuseColor);
shader->TexCoordPointer(GL_TEXTURE0, 3, GL_FLOAT, stride, &base->m_Position[0]);
shader->AssertPointersBound();
for (IndexBufferBatches::iterator it = itv->second.begin(); it != itv->second.end(); ++it)
{
@ -796,12 +800,14 @@ void CPatchRData::RenderBases(const std::vector<CPatchRData*>& patches, CShaderP
}
}
if (!shader)
#if !CONFIG2_GLES
if (isDummyShader)
{
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
#endif
CVertexBuffer::Unbind();
}
@ -837,7 +843,7 @@ struct SBlendStackItem
SplatStack splats;
};
void CPatchRData::RenderBlends(const std::vector<CPatchRData*>& patches, CShaderProgramPtr shader)
void CPatchRData::RenderBlends(const std::vector<CPatchRData*>& patches, CShaderProgramPtr& shader, bool isDummyShader)
{
Allocators::Arena<> arena(ARENA_SIZE);
@ -928,19 +934,21 @@ void CPatchRData::RenderBlends(const std::vector<CPatchRData*>& patches, CShader
{
itt->m_Texture->GetTexture()->Bind();
if (shader)
{
float c = itt->m_Texture->GetTextureMatrix()[0];
float ms = itt->m_Texture->GetTextureMatrix()[8];
shader->Uniform("textureTransform", c, ms, -ms, 0.f);
}
else
#if !CONFIG2_GLES
if (isDummyShader)
{
pglClientActiveTextureARB(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
glLoadMatrixf(itt->m_Texture->GetTextureMatrix());
glMatrixMode(GL_MODELVIEW);
}
else
#endif
{
float c = itt->m_Texture->GetTextureMatrix()[0];
float ms = itt->m_Texture->GetTextureMatrix()[8];
shader->Uniform("textureTransform", c, ms, -ms, 0.f);
}
}
else
{
@ -956,17 +964,14 @@ void CPatchRData::RenderBlends(const std::vector<CPatchRData*>& patches, CShader
GLsizei stride = sizeof(SBlendVertex);
SBlendVertex *base = (SBlendVertex *)itv->first->Bind();
glVertexPointer(3, GL_FLOAT, stride, &base->m_Position[0]);
glColorPointer(4, GL_UNSIGNED_BYTE, stride, &base->m_DiffuseColor);
pglClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(3, GL_FLOAT, stride, &base->m_Position[0]);
pglClientActiveTextureARB(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, stride, &base->m_AlphaUVs[0]);
shader->VertexPointer(3, GL_FLOAT, stride, &base->m_Position[0]);
shader->ColorPointer(4, GL_UNSIGNED_BYTE, stride, &base->m_DiffuseColor);
shader->TexCoordPointer(GL_TEXTURE0, 3, GL_FLOAT, stride, &base->m_Position[0]);
shader->TexCoordPointer(GL_TEXTURE1, 2, GL_FLOAT, stride, &base->m_AlphaUVs[0]);
}
shader->AssertPointersBound();
for (IndexBufferBatches::iterator it = itv->second.begin(); it != itv->second.end(); ++it)
{
it->first->Bind();
@ -986,19 +991,20 @@ void CPatchRData::RenderBlends(const std::vector<CPatchRData*>& patches, CShader
}
}
pglClientActiveTextureARB(GL_TEXTURE0);
if (!shader)
#if !CONFIG2_GLES
if (isDummyShader)
{
pglClientActiveTextureARB(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
#endif
CVertexBuffer::Unbind();
}
void CPatchRData::RenderStreams(const std::vector<CPatchRData*>& patches, int streamflags)
void CPatchRData::RenderStreams(const std::vector<CPatchRData*>& patches, CShaderProgramPtr& shader, int streamflags)
{
// Each batch has a list of index counts, and a list of pointers-to-first-indexes
typedef std::pair<std::vector<GLint>, std::vector<void*> > BatchElements;
@ -1035,31 +1041,15 @@ void CPatchRData::RenderStreams(const std::vector<CPatchRData*>& patches, int st
GLsizei stride = sizeof(SBaseVertex);
SBaseVertex *base = (SBaseVertex *)itv->first->Bind();
glVertexPointer(3, GL_FLOAT, stride, &base->m_Position);
shader->VertexPointer(3, GL_FLOAT, stride, &base->m_Position);
if (streamflags & STREAM_POSTOUV0)
{
pglClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(3, GL_FLOAT, stride, &base->m_Position);
}
shader->TexCoordPointer(GL_TEXTURE0, 3, GL_FLOAT, stride, &base->m_Position);
if (streamflags & STREAM_POSTOUV1)
{
pglClientActiveTextureARB(GL_TEXTURE1);
glTexCoordPointer(3, GL_FLOAT, stride, &base->m_Position);
}
if (streamflags & STREAM_POSTOUV2)
{
pglClientActiveTextureARB(GL_TEXTURE2);
glTexCoordPointer(3, GL_FLOAT, stride, &base->m_Position);
}
if (streamflags & STREAM_POSTOUV3)
{
pglClientActiveTextureARB(GL_TEXTURE3);
glTexCoordPointer(3, GL_FLOAT, stride, &base->m_Position);
}
shader->TexCoordPointer(GL_TEXTURE1, 3, GL_FLOAT, stride, &base->m_Position);
if (streamflags & STREAM_COLOR)
{
glColorPointer(4, GL_UNSIGNED_BYTE, stride, &base->m_DiffuseColor);
}
shader->ColorPointer(4, GL_UNSIGNED_BYTE, stride, &base->m_DiffuseColor);
shader->AssertPointersBound();
for (IndexBufferBatches::iterator it = itv->second.begin(); it != itv->second.end(); ++it)
{
@ -1078,8 +1068,6 @@ void CPatchRData::RenderStreams(const std::vector<CPatchRData*>& patches, int st
}
}
pglClientActiveTextureARB(GL_TEXTURE0);
CVertexBuffer::Unbind();
}
@ -1115,11 +1103,15 @@ void CPatchRData::RenderOutline()
line.push_back(pos);
}
#if CONFIG2_GLES
#warning TODO: implement CPatchRData::RenderOutlines for GLES
#else
glVertexPointer(3, GL_FLOAT, sizeof(CVector3D), &line[0]);
glDrawArrays(GL_LINE_STRIP, 0, line.size());
#endif
}
void CPatchRData::RenderSides()
void CPatchRData::RenderSides(CShaderProgramPtr& shader)
{
ENSURE(m_UpdateFlags==0);
@ -1130,7 +1122,9 @@ void CPatchRData::RenderSides()
// setup data pointers
GLsizei stride = sizeof(SSideVertex);
glVertexPointer(3, GL_FLOAT, stride, &base->m_Position);
shader->VertexPointer(3, GL_FLOAT, stride, &base->m_Position);
shader->AssertPointersBound();
if (!g_Renderer.m_SkipSubmit)
glDrawArrays(GL_TRIANGLE_STRIP, m_VBSides->m_Index, (GLsizei)m_VBSides->m_Count);
@ -1306,7 +1300,7 @@ void CPatchRData::BuildWater()
m_VBWaterIndices->m_Owner->UpdateChunkVertices(m_VBWaterIndices, &water_indices[0]);
}
void CPatchRData::RenderWater()
void CPatchRData::RenderWater(CShaderProgramPtr& shader)
{
ASSERT(m_UpdateFlags==0);
@ -1317,14 +1311,21 @@ void CPatchRData::RenderWater()
// setup data pointers
GLsizei stride = sizeof(SWaterVertex);
glColorPointer(4, GL_UNSIGNED_BYTE, stride, &base[m_VBWater->m_Index].m_DepthData);
glVertexPointer(3, GL_FLOAT, stride, &base[m_VBWater->m_Index].m_Position);
shader->ColorPointer(4, GL_UNSIGNED_BYTE, stride, &base[m_VBWater->m_Index].m_DepthData);
shader->VertexPointer(3, GL_FLOAT, stride, &base[m_VBWater->m_Index].m_Position);
shader->AssertPointersBound();
// render
if (!g_Renderer.m_SkipSubmit) {
if (!g_Renderer.m_SkipSubmit)
{
u8* indexBase = m_VBWaterIndices->m_Owner->Bind();
#if CONFIG2_GLES
#warning TODO: fix CPatchRData::RenderWater for GLES (avoid GL_QUADS)
#else
glDrawElements(GL_QUADS, (GLsizei) m_VBWaterIndices->m_Count,
GL_UNSIGNED_SHORT, indexBase + sizeof(u16)*(m_VBWaterIndices->m_Index));
#endif
}
// bump stats

View File

@ -40,14 +40,14 @@ public:
void Update();
void RenderOutline();
void RenderSides();
void RenderSides(CShaderProgramPtr& shader);
void RenderPriorities(CTextRenderer& textRenderer);
void RenderWater();
void RenderWater(CShaderProgramPtr& shader);
static void RenderBases(const std::vector<CPatchRData*>& patches, CShaderProgramPtr shader);
static void RenderBlends(const std::vector<CPatchRData*>& patches, CShaderProgramPtr shader);
static void RenderStreams(const std::vector<CPatchRData*>& patches, int streamflags);
static void RenderBases(const std::vector<CPatchRData*>& patches, CShaderProgramPtr& shader, bool isDummyShader);
static void RenderBlends(const std::vector<CPatchRData*>& patches, CShaderProgramPtr& shader, bool isDummyShader);
static void RenderStreams(const std::vector<CPatchRData*>& patches, CShaderProgramPtr& shader, int streamflags);
CPatch* GetPatch() { return m_Patch; }

View File

@ -626,16 +626,20 @@ bool CRenderer::Open(int width, int height)
EnumCaps();
// model rendering
#if !CONFIG2_GLES
m->Model.VertexFF = ModelVertexRendererPtr(new FixedFunctionModelRenderer);
m->Model.VertexPolygonSort = ModelVertexRendererPtr(new PolygonSortModelRenderer);
#endif
m->Model.VertexRendererShader = ModelVertexRendererPtr(new ShaderModelRenderer);
m->Model.VertexInstancingShader = ModelVertexRendererPtr(new InstancingModelRenderer);
#if !CONFIG2_GLES
m->Model.pal_NormalFF = new BatchModelRenderer(m->Model.VertexFF);
m->Model.pal_PlayerFF = new BatchModelRenderer(m->Model.VertexFF);
m->Model.pal_TranspFF = new SortModelRenderer(m->Model.VertexFF);
m->Model.pal_TranspSortAll = new SortModelRenderer(m->Model.VertexPolygonSort);
#endif
m->Model.pal_NormalShader = new BatchModelRenderer(m->Model.VertexRendererShader);
m->Model.pal_NormalInstancingShader = new BatchModelRenderer(m->Model.VertexInstancingShader);
@ -649,9 +653,11 @@ bool CRenderer::Open(int width, int height)
m->Model.ModSolidColor = RenderModifierPtr(new SolidColorRenderModifier);
m->Model.ModSolidPlayerColor = RenderModifierPtr(new SolidPlayerColorRender);
m->Model.ModTransparentUnlit = RenderModifierPtr(new TransparentRenderModifier);
#if !CONFIG2_GLES
m->Model.ModTransparentOpaqueUnlit = RenderModifierPtr(new TransparentOpaqueRenderModifier);
m->Model.ModTransparentBlendUnlit = RenderModifierPtr(new TransparentBlendRenderModifier);
m->Model.ModTransparentDepthShadow = RenderModifierPtr(new TransparentDepthShadowModifier);
#endif
// Dimensions
m_Width = width;
@ -938,18 +944,6 @@ void CRenderer::RenderShadowMap()
float shadowTransp = m_LightEnv->GetTerrainShadowTransparency();
glColor3f(shadowTransp, shadowTransp, shadowTransp);
// Figure out transparent rendering strategy
RenderModifierPtr transparentShadows;
if (GetRenderPath() == RP_SHADER)
{
transparentShadows = m->Model.ModShaderTransparentShadow;
}
else
{
transparentShadows = m->Model.ModTransparentDepthShadow;
}
{
PROFILE("render patches");
m->terrainRenderer->RenderPatches();
@ -965,7 +959,7 @@ void CRenderer::RenderShadowMap()
PROFILE("render transparent models");
// disable face-culling for two-sided models
glDisable(GL_CULL_FACE);
m->Model.Transp->Render(transparentShadows, MODELFLAG_CASTSHADOWS);
m->Model.Transp->Render(m->Model.ModShaderTransparentShadow, MODELFLAG_CASTSHADOWS);
glEnable(GL_CULL_FACE);
}
@ -1012,6 +1006,7 @@ void CRenderer::RenderPatches(const CFrustum* frustum)
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
// setup some renderstate ..
pglActiveTextureARB(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);
glColor3f(0.5f, 0.5f, 1.0f);
glLineWidth(2.0f);

View File

@ -185,6 +185,9 @@ bool TerrainRenderer::CullPatches(const CFrustum* frustum)
// Full-featured terrain rendering with blending and everything
void TerrainRenderer::RenderTerrain(bool filtered)
{
#if CONFIG2_GLES
UNUSED2(filtered);
#else
ENSURE(m->phase == Phase_Render);
std::vector<CPatchRData*>& visiblePatches = filtered ? m->filteredPatches : m->visiblePatches;
@ -192,13 +195,16 @@ void TerrainRenderer::RenderTerrain(bool filtered)
if (visiblePatches.empty() && visibleDecals.empty())
return;
CShaderProgramPtr dummyShader = g_Renderer.GetShaderManager().LoadProgram("fixed:dummy");
dummyShader->Bind();
// render the solid black sides of the map first
g_Renderer.BindTexture(0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glColor3f(0, 0, 0);
PROFILE_START("render terrain sides");
for (size_t i = 0; i < visiblePatches.size(); ++i)
visiblePatches[i]->RenderSides();
visiblePatches[i]->RenderSides(dummyShader);
PROFILE_END("render terrain sides");
// switch on required client states
@ -221,7 +227,7 @@ void TerrainRenderer::RenderTerrain(bool filtered)
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, one);
PROFILE_START("render terrain base");
CPatchRData::RenderBases(visiblePatches, CShaderProgramPtr());
CPatchRData::RenderBases(visiblePatches, dummyShader, true);
PROFILE_END("render terrain base");
// render blends
@ -254,7 +260,7 @@ void TerrainRenderer::RenderTerrain(bool filtered)
// render blend passes for each patch
PROFILE_START("render terrain blends");
CPatchRData::RenderBlends(visiblePatches, CShaderProgramPtr());
CPatchRData::RenderBlends(visiblePatches, dummyShader, true);
PROFILE_END("render terrain blends");
// Disable second texcoord array
@ -279,7 +285,7 @@ void TerrainRenderer::RenderTerrain(bool filtered)
PROFILE_START("render terrain decals");
for (size_t i = 0; i < visibleDecals.size(); ++i)
visibleDecals[i]->Render(CShaderProgramPtr());
visibleDecals[i]->Render(dummyShader, true);
PROFILE_END("render terrain decals");
@ -346,7 +352,7 @@ void TerrainRenderer::RenderTerrain(bool filtered)
pglClientActiveTextureARB(GL_TEXTURE0);
PROFILE_START("render terrain streams");
CPatchRData::RenderStreams(visiblePatches, streamflags);
CPatchRData::RenderStreams(visiblePatches, dummyShader, streamflags);
PROFILE_END("render terrain streams");
glMatrixMode(GL_TEXTURE);
@ -370,8 +376,10 @@ void TerrainRenderer::RenderTerrain(bool filtered)
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
dummyShader->Unbind();
#endif
}
///////////////////////////////////////////////////////////////////
@ -380,6 +388,8 @@ void TerrainRenderer::RenderTerrain(bool filtered)
*/
void TerrainRenderer::PrepareShader(const CShaderProgramPtr& shader, ShadowMap* shadow)
{
shader->Uniform("transform", g_Renderer.GetViewCamera().GetViewProjection());
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
if (shadow)
@ -429,23 +439,24 @@ void TerrainRenderer::RenderTerrainShader(ShadowMap* shadow, bool filtered)
CShaderProgramPtr shaderDecal(shaderManager.LoadProgram("terrain_decal", defBasic));
// render the solid black sides of the map first
g_Renderer.BindTexture(0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glColor3f(0, 0, 0);
CShaderTechniquePtr techSolid = g_Renderer.GetShaderManager().LoadEffect("solid");
techSolid->BeginPass();
CShaderProgramPtr shaderSolid = techSolid->GetShader();
shaderSolid->Uniform("transform", g_Renderer.GetViewCamera().GetViewProjection());
shaderSolid->Uniform("color", 0.0f, 0.0f, 0.0f, 1.0f);
PROFILE_START("render terrain sides");
for (size_t i = 0; i < visiblePatches.size(); ++i)
visiblePatches[i]->RenderSides();
visiblePatches[i]->RenderSides(shaderSolid);
PROFILE_END("render terrain sides");
// switch on required client states
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); // diffuse lighting colours
techSolid->EndPass();
shaderBase->Bind();
PrepareShader(shaderBase, shadow);
PROFILE_START("render terrain base");
CPatchRData::RenderBases(visiblePatches, shaderBase);
CPatchRData::RenderBases(visiblePatches, shaderBase, false);
PROFILE_END("render terrain base");
shaderBase->Unbind();
@ -458,10 +469,6 @@ void TerrainRenderer::RenderTerrainShader(ShadowMap* shadow, bool filtered)
// switch on the composite alpha map texture
(void)ogl_tex_bind(g_Renderer.m_hCompositeAlphaMap, 1);
// switch on second uv set
pglClientActiveTextureARB(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// switch on blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -471,13 +478,9 @@ void TerrainRenderer::RenderTerrainShader(ShadowMap* shadow, bool filtered)
// render blend passes for each patch
PROFILE_START("render terrain blends");
CPatchRData::RenderBlends(visiblePatches, shaderBlend);
CPatchRData::RenderBlends(visiblePatches, shaderBlend, false);
PROFILE_END("render terrain blends");
// Disable second texcoord array
pglClientActiveTextureARB(GL_TEXTURE1);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
shaderBlend->Unbind();
// Render terrain decals
@ -485,13 +488,9 @@ void TerrainRenderer::RenderTerrainShader(ShadowMap* shadow, bool filtered)
shaderDecal->Bind();
PrepareShader(shaderDecal, shadow);
g_Renderer.BindTexture(1, 0);
pglActiveTextureARB(GL_TEXTURE0);
pglClientActiveTextureARB(GL_TEXTURE0);
PROFILE_START("render terrain decals");
for (size_t i = 0; i < visibleDecals.size(); ++i)
visibleDecals[i]->Render(shaderDecal);
visibleDecals[i]->Render(shaderDecal, false);
PROFILE_END("render terrain decals");
shaderDecal->Unbind();
@ -501,14 +500,9 @@ void TerrainRenderer::RenderTerrainShader(ShadowMap* shadow, bool filtered)
g_Renderer.BindTexture(2, 0);
g_Renderer.BindTexture(3, 0);
pglClientActiveTextureARB(GL_TEXTURE0);
pglActiveTextureARB(GL_TEXTURE0);
glDepthMask(1);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
@ -522,9 +516,18 @@ void TerrainRenderer::RenderPatches(bool filtered)
if (visiblePatches.empty())
return;
#if CONFIG2_GLES
#warning TODO: implement TerrainRenderer::RenderPatches for GLES
#else
CShaderProgramPtr dummyShader = g_Renderer.GetShaderManager().LoadProgram("fixed:dummy");
dummyShader->Bind();
glEnableClientState(GL_VERTEX_ARRAY);
CPatchRData::RenderStreams(visiblePatches, STREAM_POS);
CPatchRData::RenderStreams(visiblePatches, dummyShader, STREAM_POS);
glDisableClientState(GL_VERTEX_ARRAY);
dummyShader->Unbind();
#endif
}
@ -538,10 +541,14 @@ void TerrainRenderer::RenderOutlines(bool filtered)
if (visiblePatches.empty())
return;
#if CONFIG2_GLES
#warning TODO: implement TerrainRenderer::RenderOutlines for GLES
#else
glEnableClientState(GL_VERTEX_ARRAY);
for (size_t i = 0; i < visiblePatches.size(); ++i)
visiblePatches[i]->RenderOutline();
glDisableClientState(GL_VERTEX_ARRAY);
#endif
}
@ -637,7 +644,9 @@ bool TerrainRenderer::RenderFancyWater()
float repeatPeriod = WaterMgr->m_RepeatPeriod;
// Set the proper LOD bias
#if !CONFIG2_GLES
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, g_Renderer.m_Options.m_LodBias);
#endif
const CCamera& camera = g_Renderer.GetViewCamera();
CVector3D camPos = camera.m_Orientation.GetTranslation();
@ -667,21 +676,15 @@ bool TerrainRenderer::RenderFancyWater()
m->fancyWaterShader->Uniform("losMatrix", losTexture.GetTextureMatrix());
m->fancyWaterShader->Uniform("cameraPos", camPos);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
for (size_t i = 0; i < m->visiblePatches.size(); ++i)
{
CPatchRData* data = m->visiblePatches[i];
data->RenderWater();
data->RenderWater(m->fancyWaterShader);
}
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
m->fancyWaterShader->Unbind();
pglActiveTextureARB(GL_TEXTURE0_ARB);
pglActiveTextureARB(GL_TEXTURE0);
glDisable(GL_BLEND);
@ -690,6 +693,7 @@ bool TerrainRenderer::RenderFancyWater()
void TerrainRenderer::RenderSimpleWater()
{
#if !CONFIG2_GLES
PROFILE3_GPU("simple water");
WaterManager* WaterMgr = g_Renderer.GetWaterManager();
@ -759,18 +763,23 @@ void TerrainRenderer::RenderSimpleWater()
// Set the proper LOD bias
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, g_Renderer.m_Options.m_LodBias);
CShaderProgramPtr dummyShader = g_Renderer.GetShaderManager().LoadProgram("fixed:dummy");
dummyShader->Bind();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
for (size_t i = 0; i < m->visiblePatches.size(); ++i)
{
CPatchRData* data = m->visiblePatches[i];
data->RenderWater();
data->RenderWater(dummyShader);
}
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
dummyShader->Unbind();
g_Renderer.BindTexture(1, 0);
glDisable(GL_TEXTURE_GEN_S);
@ -786,6 +795,7 @@ void TerrainRenderer::RenderSimpleWater()
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
#endif
}
///////////////////////////////////////////////////////////////////

View File

@ -48,6 +48,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// PolygonSortModelRenderer implementation
#if !CONFIG2_GLES
/**
* Struct PSModelDef: Per-CModelDef data for the polygon sort vertex renderer
@ -373,6 +374,7 @@ void PolygonSortModelRenderer::RenderModel(CShaderProgramPtr& UNUSED(shader), in
g_Renderer.m_Stats.m_ModelTris += numFaces;
}
#endif // !CONFIG2_GLES
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -589,6 +591,8 @@ void SortModelRenderer::Filter(CModelFilter& filter, int passed, int flags)
///////////////////////////////////////////////////////////////////////////////////////////////////
// TransparentRenderModifier implementation
#if !CONFIG2_GLES
TransparentRenderModifier::TransparentRenderModifier()
{
}
@ -717,6 +721,7 @@ void TransparentOpaqueRenderModifier::PrepareModel(int UNUSED(pass), CModel* UNU
// No per-model setup necessary
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// TransparentBlendRenderModifier implementation
@ -829,3 +834,5 @@ void TransparentDepthShadowModifier::PrepareModel(int UNUSED(pass), CModel* UNUS
{
// No per-model setup necessary
}
#endif // !CONFIG2_GLES

View File

@ -30,6 +30,8 @@
struct PolygonSortModelRendererInternals;
#if !CONFIG2_GLES
/**
* Class PolygonSortModelRenderer: Render animated models using only
* OpenGL fixed function, sorting polygons from back to front.
@ -58,9 +60,11 @@ private:
PolygonSortModelRendererInternals* m;
};
struct SortModelRendererInternals;
#endif
struct SortModelRendererInternals;
/**
* Class SortModelRenderer: Render models back-to-front from the
* camera's point of view.
@ -109,6 +113,8 @@ public:
void PrepareModel(int pass, CModel* model);
};
#if !CONFIG2_GLES
/**
* Class TransparentOpaqueRenderModifier: Modifier for transparent models,
* including alpha blending and lighting, Opaque pass only.
@ -161,4 +167,6 @@ public:
void PrepareModel(int pass, CModel* model);
};
#endif // !CONFIG2_GLES
#endif