Added limited support for per-vertex colors in meshes.

ver1_5_1
Chris Laurel 2007-04-23 17:39:38 +00:00
parent 35696e1dcd
commit 36d0299d78
4 changed files with 31 additions and 5 deletions

View File

@ -66,10 +66,11 @@ setExtendedVertexArrays(const Mesh::VertexDescription& desc,
RenderContext::RenderContext() :
material(&defaultMaterial),
locked(false),
renderPass(PrimaryPass),
pointScale(1.0f),
usePointSize(false),
useNormals(true),
renderPass(PrimaryPass),
pointScale(1.0f)
useColors(false)
{
}
@ -333,6 +334,14 @@ FixedFunctionRenderContext::setVertexArrays(const Mesh::VertexDescription& desc,
makeCurrent(*getMaterial());
}
bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat);
if (useColorsNow != useColors)
{
useColors = useColorsNow;
if (getMaterial() != NULL)
makeCurrent(*getMaterial());
}
setStandardVertexArrays(desc, vertexData);
}
@ -703,12 +712,15 @@ GLSL_RenderContext::setVertexArrays(const Mesh::VertexDescription& desc,
// or disappear in the new set of vertex arrays.
bool usePointSizeNow = (desc.getAttribute(Mesh::PointSize).format == Mesh::Float1);
bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3);
bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat);
if (usePointSizeNow != usePointSize ||
useNormalsNow != useNormals)
useNormalsNow != useNormals ||
useColorsNow != useColors)
{
usePointSize = usePointSizeNow;
useNormals = useNormalsNow;
useColors = useColorsNow;
if (getMaterial() != NULL)
makeCurrent(*getMaterial());
}
@ -783,8 +795,11 @@ GLSLUnlit_RenderContext::makeCurrent(const Mesh::Material& m)
textures[nTextures++] = baseTex;
}
}
if (usePointSize)
shaderProps.texUsage |= ShaderProperties::PointSprite;
if (useColors)
shaderProps.texUsage |= ShaderProperties::VertexColors;
// Get a shader for the current rendering configuration
CelestiaGLProgram* prog = GetShaderManager().getShader(shaderProps);
@ -855,12 +870,15 @@ GLSLUnlit_RenderContext::setVertexArrays(const Mesh::VertexDescription& desc,
// or disappear in the new set of vertex arrays.
bool usePointSizeNow = (desc.getAttribute(Mesh::PointSize).format == Mesh::Float1);
bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3);
bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat);
if (usePointSizeNow != usePointSize ||
useNormalsNow != useNormals)
useNormalsNow != useNormals ||
useColorsNow != useColors)
{
usePointSize = usePointSizeNow;
useNormals = useNormalsNow;
useColors = useColorsNow;
if (getMaterial() != NULL)
makeCurrent(*getMaterial());
}

View File

@ -53,6 +53,7 @@ class RenderContext
protected:
bool usePointSize;
bool useNormals;
bool useColors;
};

View File

@ -1830,7 +1830,13 @@ ShaderManager::buildEmissiveVertexShader(const ShaderProperties& props)
}
// Set the color.
source += " gl_FrontColor = vec4(" + LightProperty(0, "diffuse") + ", opacity);\n";
string colorSource;
if (props.texUsage & ShaderProperties::VertexColors)
colorSource = "gl_Color.rgb";
else
colorSource = LightProperty(0, "diffuse");
source += " gl_FrontColor = vec4(" + colorSource + ", opacity);\n";
// Optional point size
if ((props.texUsage & ShaderProperties::PointSprite) != 0)

View File

@ -42,6 +42,7 @@ class ShaderProperties
OverlayTexture = 0x40,
CloudShadowTexture = 0x80,
CompressedNormalTexture = 0x100,
VertexColors = 0x1000,
Scattering = 0x2000,
PointSprite = 0x4000,
SharedTextureCoords = 0x8000,