|
|
|
@ -35,12 +35,18 @@ namespace
|
|
|
|
|
// to an equivalent fragment shader. The generated code can certainly
|
|
|
|
|
// be optimized more.
|
|
|
|
|
////////////////////////////////////////////
|
|
|
|
|
StdStrBuf TextureUnitSourceToCode(int index, StdMeshMaterialTextureUnit::BlendOpSourceType source, const float manualColor[3], float manualAlpha)
|
|
|
|
|
StdStrBuf Texture2DToCode(int index, bool hasTextureAnimation)
|
|
|
|
|
{
|
|
|
|
|
if (hasTextureAnimation) return FormatString("texture2D(oc_Texture%d, (oc_TextureMatrix%d * vec4(texcoord, 0.0, 1.0)).xy)", index, index);
|
|
|
|
|
return FormatString("texture2D(oc_Texture%d, texcoord)", index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StdStrBuf TextureUnitSourceToCode(int index, StdMeshMaterialTextureUnit::BlendOpSourceType source, const float manualColor[3], float manualAlpha, bool hasTextureAnimation)
|
|
|
|
|
{
|
|
|
|
|
switch(source)
|
|
|
|
|
{
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOS_Current: return StdStrBuf("currentColor");
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOS_Texture: return FormatString("texture2D(oc_Texture%d, texcoord)", index);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOS_Texture: return Texture2DToCode(index, hasTextureAnimation);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOS_Diffuse: return StdStrBuf("diffuse");
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOS_Specular: return StdStrBuf("diffuse"); // TODO: Should be specular
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOS_PlayerColor: return StdStrBuf("vec4(oc_PlayerColor, 1.0)");
|
|
|
|
@ -49,7 +55,7 @@ namespace
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StdStrBuf TextureUnitBlendToCode(int index, StdMeshMaterialTextureUnit::BlendOpExType blend_type, const char* source1, const char* source2, float manualFactor)
|
|
|
|
|
StdStrBuf TextureUnitBlendToCode(int index, StdMeshMaterialTextureUnit::BlendOpExType blend_type, const char* source1, const char* source2, float manualFactor, bool hasTextureAnimation)
|
|
|
|
|
{
|
|
|
|
|
switch(blend_type)
|
|
|
|
|
{
|
|
|
|
@ -63,10 +69,10 @@ namespace
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_AddSmooth: return FormatString("%s + %s - %s*%s", source1, source2, source1, source2);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_Subtract: return FormatString("%s - %s", source1, source2);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_BlendDiffuseAlpha: return FormatString("diffuse.a * %s + (1.0 - diffuse.a) * %s", source1, source2);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_BlendTextureAlpha: return FormatString("texture2D(oc_Texture%d, texcoord).a * %s + (1.0 - texture2D(oc_Texture%d, texcoord).a) * %s", index, source1, index, source2);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_BlendTextureAlpha: return FormatString("%s.a * %s + (1.0 - %s.a) * %s", Texture2DToCode(index, hasTextureAnimation).getData(), source1, Texture2DToCode(index, hasTextureAnimation).getData(), source2);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_BlendCurrentAlpha: return FormatString("currentColor.a * %s + (1.0 - currentColor.a) * %s", source1, source2);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_BlendManual: return FormatString("%f * %s + (1.0 - %f) * %s", manualFactor, source1, manualFactor, source2);
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_Dotproduct: return FormatString("vec3(4.0 * dot(%s - 0.5, %s - 0.5), 4.0 * dot(%s - 0.5, %s - 0.5), 4.0 * dot(%s - 0.5, %s - 0.5));", source1, source2, source1, source2, source1, source2); // TODO: Needs special handling for the case of alpha
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_Dotproduct: return FormatString("vec3(4.0 * dot(%s - 0.5, %s - 0.5), 4.0 * dot(%s - 0.5, %s - 0.5), 4.0 * dot(%s - 0.5, %s - 0.5))", source1, source2, source1, source2, source1, source2); // TODO: Needs special handling for the case of alpha
|
|
|
|
|
case StdMeshMaterialTextureUnit::BOX_BlendDiffuseColor: return FormatString("diffuse.rgb * %s + (1.0 - diffuse.rgb) * %s", source1, source2);
|
|
|
|
|
default: assert(false); return StdStrBuf(source1);
|
|
|
|
|
}
|
|
|
|
@ -74,12 +80,14 @@ namespace
|
|
|
|
|
|
|
|
|
|
StdStrBuf TextureUnitToCode(int index, const StdMeshMaterialTextureUnit& texunit)
|
|
|
|
|
{
|
|
|
|
|
StdStrBuf color_source1 = FormatString("%s.rgb", TextureUnitSourceToCode(index, texunit.ColorOpSources[0], texunit.ColorOpManualColor1, texunit.AlphaOpManualAlpha1).getData());
|
|
|
|
|
StdStrBuf color_source2 = FormatString("%s.rgb", TextureUnitSourceToCode(index, texunit.ColorOpSources[1], texunit.ColorOpManualColor2, texunit.AlphaOpManualAlpha2).getData());
|
|
|
|
|
StdStrBuf alpha_source1 = FormatString("%s.a", TextureUnitSourceToCode(index, texunit.AlphaOpSources[0], texunit.ColorOpManualColor1, texunit.AlphaOpManualAlpha1).getData());
|
|
|
|
|
StdStrBuf alpha_source2 = FormatString("%s.a", TextureUnitSourceToCode(index, texunit.AlphaOpSources[1], texunit.ColorOpManualColor2, texunit.AlphaOpManualAlpha2).getData());
|
|
|
|
|
const bool hasTextureAnimation = texunit.HasTexCoordAnimation();
|
|
|
|
|
|
|
|
|
|
return FormatString("currentColor = vec4(%s, %s);\n", TextureUnitBlendToCode(index, texunit.ColorOpEx, color_source1.getData(), color_source2.getData(), texunit.ColorOpManualFactor).getData(), TextureUnitBlendToCode(index, texunit.AlphaOpEx, alpha_source1.getData(), alpha_source2.getData(), texunit.AlphaOpManualFactor).getData());
|
|
|
|
|
StdStrBuf color_source1 = FormatString("%s.rgb", TextureUnitSourceToCode(index, texunit.ColorOpSources[0], texunit.ColorOpManualColor1, texunit.AlphaOpManualAlpha1, hasTextureAnimation).getData());
|
|
|
|
|
StdStrBuf color_source2 = FormatString("%s.rgb", TextureUnitSourceToCode(index, texunit.ColorOpSources[1], texunit.ColorOpManualColor2, texunit.AlphaOpManualAlpha2, hasTextureAnimation).getData());
|
|
|
|
|
StdStrBuf alpha_source1 = FormatString("%s.a", TextureUnitSourceToCode(index, texunit.AlphaOpSources[0], texunit.ColorOpManualColor1, texunit.AlphaOpManualAlpha1, hasTextureAnimation).getData());
|
|
|
|
|
StdStrBuf alpha_source2 = FormatString("%s.a", TextureUnitSourceToCode(index, texunit.AlphaOpSources[1], texunit.ColorOpManualColor2, texunit.AlphaOpManualAlpha2, hasTextureAnimation).getData());
|
|
|
|
|
|
|
|
|
|
return FormatString("currentColor = vec4(%s, %s);\n", TextureUnitBlendToCode(index, texunit.ColorOpEx, color_source1.getData(), color_source2.getData(), texunit.ColorOpManualFactor, hasTextureAnimation).getData(), TextureUnitBlendToCode(index, texunit.AlphaOpEx, alpha_source1.getData(), alpha_source2.getData(), texunit.AlphaOpManualFactor, hasTextureAnimation).getData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StdStrBuf AlphaTestToCode(const StdMeshMaterialPass& pass)
|
|
|
|
@ -136,10 +144,13 @@ namespace
|
|
|
|
|
// Fall back just in case
|
|
|
|
|
buf.Copy(
|
|
|
|
|
"varying vec3 normalDir;\n"
|
|
|
|
|
"uniform mat4 projectionMatrix;\n"
|
|
|
|
|
"uniform mat4 modelviewMatrix;\n"
|
|
|
|
|
"uniform mat3 normalMatrix;\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"slice(position)\n"
|
|
|
|
|
"{\n"
|
|
|
|
|
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
|
|
|
|
" gl_Position = projectionMatrix * modelviewMatrix * gl_Vertex;\n"
|
|
|
|
|
"}\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"slice(texcoord)\n"
|
|
|
|
@ -149,7 +160,7 @@ namespace
|
|
|
|
|
"\n"
|
|
|
|
|
"slice(normal)\n"
|
|
|
|
|
"{\n"
|
|
|
|
|
" normalDir = normalize(gl_NormalMatrix * gl_Normal);\n"
|
|
|
|
|
" normalDir = normalize(normalMatrix * gl_Normal);\n"
|
|
|
|
|
"}\n"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
@ -180,6 +191,15 @@ namespace
|
|
|
|
|
{
|
|
|
|
|
textureUnitDeclCode.Append(FormatString("uniform sampler2D oc_Texture%u;\n", texIndex).getData());
|
|
|
|
|
params.AddParameter(FormatString("oc_Texture%u", texIndex).getData(), StdMeshMaterialShaderParameter::INT).GetInt() = texIndex;
|
|
|
|
|
|
|
|
|
|
// If the texture unit has texture coordinate transformations,
|
|
|
|
|
// add a corresponding texture matrix uniform.
|
|
|
|
|
if(texunit.HasTexCoordAnimation())
|
|
|
|
|
{
|
|
|
|
|
textureUnitDeclCode.Append(FormatString("uniform mat4 oc_TextureMatrix%u;\n", texIndex).getData());
|
|
|
|
|
params.AddParameter(FormatString("oc_TextureMatrix%u", texIndex).getData(), StdMeshMaterialShaderParameter::AUTO_TEXTURE_MATRIX).GetInt() = texIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++texIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -331,21 +351,6 @@ bool CStdGL::PrepareMaterial(StdMeshMatManager& mat_manager, StdMeshMaterialLoad
|
|
|
|
|
technique.Available = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned int m = 0; m < texunit.Transformations.size(); ++m)
|
|
|
|
|
{
|
|
|
|
|
StdMeshMaterialTextureUnit::Transformation& trans = texunit.Transformations[m];
|
|
|
|
|
if (trans.TransformType == StdMeshMaterialTextureUnit::Transformation::T_TRANSFORM)
|
|
|
|
|
{
|
|
|
|
|
// transpose so we can directly pass it to glMultMatrixf
|
|
|
|
|
std::swap(trans.Transform.M[ 1], trans.Transform.M[ 4]);
|
|
|
|
|
std::swap(trans.Transform.M[ 2], trans.Transform.M[ 8]);
|
|
|
|
|
std::swap(trans.Transform.M[ 3], trans.Transform.M[12]);
|
|
|
|
|
std::swap(trans.Transform.M[ 6], trans.Transform.M[ 9]);
|
|
|
|
|
std::swap(trans.Transform.M[ 7], trans.Transform.M[13]);
|
|
|
|
|
std::swap(trans.Transform.M[11], trans.Transform.M[14]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // loop over textures
|
|
|
|
|
} // loop over texture units
|
|
|
|
|
|
|
|
|
@ -418,27 +423,44 @@ namespace
|
|
|
|
|
{
|
|
|
|
|
// Apply Zoom and Transformation to the current matrix stack. Return
|
|
|
|
|
// parity of the transformation.
|
|
|
|
|
bool ApplyZoomAndTransform(float ZoomX, float ZoomY, float Zoom, C4BltTransform* pTransform)
|
|
|
|
|
bool ApplyZoomAndTransform(float ZoomX, float ZoomY, float Zoom, C4BltTransform* pTransform, StdProjectionMatrix& projection)
|
|
|
|
|
{
|
|
|
|
|
// Apply zoom
|
|
|
|
|
glTranslatef(ZoomX, ZoomY, 0.0f);
|
|
|
|
|
glScalef(Zoom, Zoom, 1.0f);
|
|
|
|
|
glTranslatef(-ZoomX, -ZoomY, 0.0f);
|
|
|
|
|
Translate(projection, ZoomX, ZoomY, 0.0f);
|
|
|
|
|
Scale(projection, Zoom, Zoom, 1.0f);
|
|
|
|
|
Translate(projection, -ZoomX, -ZoomY, 0.0f);
|
|
|
|
|
|
|
|
|
|
// Apply transformation
|
|
|
|
|
if (pTransform)
|
|
|
|
|
{
|
|
|
|
|
const GLfloat transform[16] = { pTransform->mat[0], pTransform->mat[3], 0, pTransform->mat[6], pTransform->mat[1], pTransform->mat[4], 0, pTransform->mat[7], 0, 0, 1, 0, pTransform->mat[2], pTransform->mat[5], 0, pTransform->mat[8] };
|
|
|
|
|
glMultMatrixf(transform);
|
|
|
|
|
StdProjectionMatrix transform;
|
|
|
|
|
transform(0, 0) = pTransform->mat[0];
|
|
|
|
|
transform(0, 1) = pTransform->mat[1];
|
|
|
|
|
transform(0, 2) = 0.0f;
|
|
|
|
|
transform(0, 3) = pTransform->mat[2];
|
|
|
|
|
transform(1, 0) = pTransform->mat[3];
|
|
|
|
|
transform(1, 1) = pTransform->mat[4];
|
|
|
|
|
transform(1, 2) = 0.0f;
|
|
|
|
|
transform(1, 3) = pTransform->mat[5];
|
|
|
|
|
transform(2, 0) = 0.0f;
|
|
|
|
|
transform(2, 1) = 0.0f;
|
|
|
|
|
transform(2, 2) = 1.0f;
|
|
|
|
|
transform(2, 3) = 0.0f;
|
|
|
|
|
transform(3, 0) = pTransform->mat[6];
|
|
|
|
|
transform(3, 1) = pTransform->mat[7];
|
|
|
|
|
transform(3, 2) = 0.0f;
|
|
|
|
|
transform(3, 3) = pTransform->mat[8];
|
|
|
|
|
projection *= transform;
|
|
|
|
|
|
|
|
|
|
// Compute parity of the transformation matrix - if parity is swapped then
|
|
|
|
|
// we need to cull front faces instead of back faces.
|
|
|
|
|
const float det = transform[0]*transform[5]*transform[15]
|
|
|
|
|
+ transform[4]*transform[13]*transform[3]
|
|
|
|
|
+ transform[12]*transform[1]*transform[7]
|
|
|
|
|
- transform[0]*transform[13]*transform[7]
|
|
|
|
|
- transform[4]*transform[1]*transform[15]
|
|
|
|
|
- transform[12]*transform[5]*transform[3];
|
|
|
|
|
const float det = transform(0,0)*transform(1,1)*transform(3,3)
|
|
|
|
|
+ transform(1,0)*transform(3,1)*transform(0,3)
|
|
|
|
|
+ transform(3,0)*transform(0,1)*transform(1,3)
|
|
|
|
|
- transform(0,0)*transform(3,1)*transform(1,3)
|
|
|
|
|
- transform(1,0)*transform(0,1)*transform(3,3)
|
|
|
|
|
- transform(3,0)*transform(1,1)*transform(0,3);
|
|
|
|
|
|
|
|
|
|
return det > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -493,7 +515,70 @@ namespace
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderSubMeshImpl(const StdMeshInstance& mesh_instance, const StdSubMeshInstance& instance, DWORD dwModClr, DWORD dwBlitMode, DWORD dwPlayerColor, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect, bool parity)
|
|
|
|
|
StdProjectionMatrix ResolveAutoTextureMatrix(const StdSubMeshInstance& instance, const StdMeshMaterialTechnique& technique, unsigned int passIndex, unsigned int texUnitIndex)
|
|
|
|
|
{
|
|
|
|
|
assert(passIndex < technique.Passes.size());
|
|
|
|
|
const StdMeshMaterialPass& pass = technique.Passes[passIndex];
|
|
|
|
|
|
|
|
|
|
assert(texUnitIndex < pass.TextureUnits.size());
|
|
|
|
|
const StdMeshMaterialTextureUnit& texunit = pass.TextureUnits[texUnitIndex];
|
|
|
|
|
|
|
|
|
|
StdProjectionMatrix matrix = StdProjectionMatrix::Identity();
|
|
|
|
|
const double Position = instance.GetTexturePosition(passIndex, texUnitIndex);
|
|
|
|
|
|
|
|
|
|
for (unsigned int k = 0; k < texunit.Transformations.size(); ++k)
|
|
|
|
|
{
|
|
|
|
|
const StdMeshMaterialTextureUnit::Transformation& trans = texunit.Transformations[k];
|
|
|
|
|
StdProjectionMatrix temp_matrix;
|
|
|
|
|
switch (trans.TransformType)
|
|
|
|
|
{
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_SCROLL:
|
|
|
|
|
Translate(matrix, trans.Scroll.X, trans.Scroll.Y, 0.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_SCROLL_ANIM:
|
|
|
|
|
Translate(matrix, trans.GetScrollX(Position), trans.GetScrollY(Position), 0.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_ROTATE:
|
|
|
|
|
Rotate(matrix, trans.Rotate.Angle, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_ROTATE_ANIM:
|
|
|
|
|
Rotate(matrix, trans.GetRotate(Position), 0.0f, 0.0f, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_SCALE:
|
|
|
|
|
Scale(matrix, trans.Scale.X, trans.Scale.Y, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_TRANSFORM:
|
|
|
|
|
for (int i = 0; i < 16; ++i)
|
|
|
|
|
temp_matrix(i / 4, i % 4) = trans.Transform.M[i];
|
|
|
|
|
matrix *= temp_matrix;
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_WAVE_XFORM:
|
|
|
|
|
switch (trans.WaveXForm.XForm)
|
|
|
|
|
{
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_SCROLL_X:
|
|
|
|
|
Translate(matrix, trans.GetWaveXForm(Position), 0.0f, 0.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_SCROLL_Y:
|
|
|
|
|
Translate(matrix, 0.0f, trans.GetWaveXForm(Position), 0.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_ROTATE:
|
|
|
|
|
Rotate(matrix, trans.GetWaveXForm(Position), 0.0f, 0.0f, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_SCALE_X:
|
|
|
|
|
Scale(matrix, trans.GetWaveXForm(Position), 1.0f, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_SCALE_Y:
|
|
|
|
|
Scale(matrix, 1.0f, trans.GetWaveXForm(Position), 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return matrix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderSubMeshImpl(const StdProjectionMatrix& projectionMatrix, const StdMeshMatrix& modelviewMatrix, const StdMeshInstance& mesh_instance, const StdSubMeshInstance& instance, DWORD dwModClr, DWORD dwBlitMode, DWORD dwPlayerColor, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect, bool parity)
|
|
|
|
|
{
|
|
|
|
|
const StdMeshMaterial& material = instance.GetMaterial();
|
|
|
|
|
assert(material.BestTechniqueIndex != -1);
|
|
|
|
@ -535,6 +620,9 @@ namespace
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Modelview matrix does not change between passes, so cache it here
|
|
|
|
|
const StdMeshMatrix normalMatrixTranspose = StdMeshMatrix::Inverse(modelviewMatrix);
|
|
|
|
|
|
|
|
|
|
// Render each pass
|
|
|
|
|
for (unsigned int i = 0; i < technique.Passes.size(); ++i)
|
|
|
|
|
{
|
|
|
|
@ -602,11 +690,9 @@ namespace
|
|
|
|
|
glBlendFunc(OgreBlendTypeToGL(pass.SceneBlendFactors[0]), GL_ONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
|
|
|
|
|
|
assert(pass.Program.get() != NULL);
|
|
|
|
|
|
|
|
|
|
// Upload all parameters to the shader (keep GL_TEXTURE matrix mode for this)
|
|
|
|
|
// Upload all parameters to the shader
|
|
|
|
|
int ssc = 0;
|
|
|
|
|
if(dwBlitMode & C4GFXBLIT_MOD2) ssc |= C4SSC_MOD2;
|
|
|
|
|
if(pFoW != NULL) ssc |= C4SSC_LIGHT;
|
|
|
|
@ -615,6 +701,11 @@ namespace
|
|
|
|
|
C4ShaderCall call(shader);
|
|
|
|
|
call.Start();
|
|
|
|
|
|
|
|
|
|
// Upload projection, modelview and normal matrices
|
|
|
|
|
call.SetUniformMatrix4x4(C4SSU_ProjectionMatrix, projectionMatrix);
|
|
|
|
|
call.SetUniformMatrix4x4(C4SSU_ModelViewMatrix, modelviewMatrix);
|
|
|
|
|
call.SetUniformMatrix3x3Transpose(C4SSU_NormalMatrix, normalMatrixTranspose);
|
|
|
|
|
|
|
|
|
|
// Upload the current bone transformation matrixes (if there are any)
|
|
|
|
|
if (!bones.empty())
|
|
|
|
|
{
|
|
|
|
@ -641,6 +732,7 @@ namespace
|
|
|
|
|
}
|
|
|
|
|
#undef VERTEX_OFFSET
|
|
|
|
|
|
|
|
|
|
// Bind textures
|
|
|
|
|
for (unsigned int j = 0; j < pass.TextureUnits.size(); ++j)
|
|
|
|
|
{
|
|
|
|
|
const StdMeshMaterialTextureUnit& texunit = pass.TextureUnits[j];
|
|
|
|
@ -649,66 +741,17 @@ namespace
|
|
|
|
|
call.AllocTexUnit(-1);
|
|
|
|
|
const unsigned int Phase = instance.GetTexturePhase(i, j);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texunit.GetTexture(Phase).texName);
|
|
|
|
|
|
|
|
|
|
// Setup texture coordinate transform
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
const double Position = instance.GetTexturePosition(i, j);
|
|
|
|
|
for (unsigned int k = 0; k < texunit.Transformations.size(); ++k)
|
|
|
|
|
{
|
|
|
|
|
const StdMeshMaterialTextureUnit::Transformation& trans = texunit.Transformations[k];
|
|
|
|
|
switch (trans.TransformType)
|
|
|
|
|
{
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_SCROLL:
|
|
|
|
|
glTranslatef(trans.Scroll.X, trans.Scroll.Y, 0.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_SCROLL_ANIM:
|
|
|
|
|
glTranslatef(trans.GetScrollX(Position), trans.GetScrollY(Position), 0.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_ROTATE:
|
|
|
|
|
glRotatef(trans.Rotate.Angle, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_ROTATE_ANIM:
|
|
|
|
|
glRotatef(trans.GetRotate(Position), 0.0f, 0.0f, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_SCALE:
|
|
|
|
|
glScalef(trans.Scale.X, trans.Scale.Y, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_TRANSFORM:
|
|
|
|
|
glMultMatrixf(trans.Transform.M);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::T_WAVE_XFORM:
|
|
|
|
|
switch (trans.WaveXForm.XForm)
|
|
|
|
|
{
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_SCROLL_X:
|
|
|
|
|
glTranslatef(trans.GetWaveXForm(Position), 0.0f, 0.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_SCROLL_Y:
|
|
|
|
|
glTranslatef(0.0f, trans.GetWaveXForm(Position), 0.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_ROTATE:
|
|
|
|
|
glRotatef(trans.GetWaveXForm(Position), 0.0f, 0.0f, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_SCALE_X:
|
|
|
|
|
glScalef(trans.GetWaveXForm(Position), 1.0f, 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialTextureUnit::Transformation::XF_SCALE_Y:
|
|
|
|
|
glScalef(1.0f, trans.GetWaveXForm(Position), 1.0f);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set uniforms and instance parameters
|
|
|
|
|
SetStandardUniforms(call, dwModClr, dwPlayerColor, dwBlitMode, pass.CullHardware != StdMeshMaterialPass::CH_None, pFoW, clipRect, outRect);
|
|
|
|
|
for(unsigned int i = 0; i < pass.Program->Parameters.size(); ++i)
|
|
|
|
|
for(unsigned int j = 0; j < pass.Program->Parameters.size(); ++j)
|
|
|
|
|
{
|
|
|
|
|
const int uniform = pass.Program->Parameters[i].UniformIndex;
|
|
|
|
|
const int uniform = pass.Program->Parameters[j].UniformIndex;
|
|
|
|
|
if(!shader->HaveUniform(uniform)) continue; // optimized out
|
|
|
|
|
|
|
|
|
|
const StdMeshMaterialShaderParameter* parameter = pass.Program->Parameters[i].Parameter;
|
|
|
|
|
const StdMeshMaterialShaderParameter* parameter = pass.Program->Parameters[j].Parameter;
|
|
|
|
|
|
|
|
|
|
StdMeshMaterialShaderParameter auto_resolved;
|
|
|
|
|
if(parameter->GetType() == StdMeshMaterialShaderParameter::AUTO)
|
|
|
|
@ -720,6 +763,9 @@ namespace
|
|
|
|
|
|
|
|
|
|
switch(parameter->GetType())
|
|
|
|
|
{
|
|
|
|
|
case StdMeshMaterialShaderParameter::AUTO_TEXTURE_MATRIX:
|
|
|
|
|
call.SetUniformMatrix4x4(uniform, ResolveAutoTextureMatrix(instance, technique, i, parameter->GetInt()));
|
|
|
|
|
break;
|
|
|
|
|
case StdMeshMaterialShaderParameter::INT:
|
|
|
|
|
call.SetUniform1i(uniform, parameter->GetInt());
|
|
|
|
|
break;
|
|
|
|
@ -744,7 +790,6 @@ namespace
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
size_t vertex_count = 3 * instance.GetNumFaces();
|
|
|
|
|
glDrawElements(GL_TRIANGLES, vertex_count, GL_UNSIGNED_INT, instance.GetFaces());
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
@ -760,21 +805,12 @@ namespace
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderMeshImpl(StdMeshInstance& instance, DWORD dwModClr, DWORD dwBlitMode, DWORD dwPlayerColor, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect, bool parity); // Needed by RenderAttachedMesh
|
|
|
|
|
void RenderMeshImpl(const StdProjectionMatrix& projectionMatrix, const StdMeshMatrix& modelviewMatrix, StdMeshInstance& instance, DWORD dwModClr, DWORD dwBlitMode, DWORD dwPlayerColor, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect, bool parity); // Needed by RenderAttachedMesh
|
|
|
|
|
|
|
|
|
|
void RenderAttachedMesh(StdMeshInstance::AttachedMesh* attach, DWORD dwModClr, DWORD dwBlitMode, DWORD dwPlayerColor, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect, bool parity)
|
|
|
|
|
void RenderAttachedMesh(const StdProjectionMatrix& projectionMatrix, const StdMeshMatrix& modelviewMatrix, StdMeshInstance::AttachedMesh* attach, DWORD dwModClr, DWORD dwBlitMode, DWORD dwPlayerColor, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect, bool parity)
|
|
|
|
|
{
|
|
|
|
|
const StdMeshMatrix& FinalTrans = attach->GetFinalTransformation();
|
|
|
|
|
|
|
|
|
|
// Convert matrix to column-major order, add fourth row
|
|
|
|
|
const float attach_trans_gl[16] =
|
|
|
|
|
{
|
|
|
|
|
FinalTrans(0,0), FinalTrans(1,0), FinalTrans(2,0), 0,
|
|
|
|
|
FinalTrans(0,1), FinalTrans(1,1), FinalTrans(2,1), 0,
|
|
|
|
|
FinalTrans(0,2), FinalTrans(1,2), FinalTrans(2,2), 0,
|
|
|
|
|
FinalTrans(0,3), FinalTrans(1,3), FinalTrans(2,3), 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Take the player color from the C4Object, if the attached object is not a definition
|
|
|
|
|
// This is a bit unfortunate because it requires access to C4Object which is otherwise
|
|
|
|
|
// avoided in this code. It could be replaced by virtual function calls to StdMeshDenumerator
|
|
|
|
@ -787,13 +823,11 @@ namespace
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Take attach transform's parity into account
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glMultMatrixf(attach_trans_gl);
|
|
|
|
|
RenderMeshImpl(*attach->Child, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
StdMeshMatrix newModelviewMatrix = modelviewMatrix * FinalTrans;
|
|
|
|
|
RenderMeshImpl(projectionMatrix, newModelviewMatrix, *attach->Child, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderMeshImpl(StdMeshInstance& instance, DWORD dwModClr, DWORD dwBlitMode, DWORD dwPlayerColor, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect, bool parity)
|
|
|
|
|
void RenderMeshImpl(const StdProjectionMatrix& projectionMatrix, const StdMeshMatrix& modelviewMatrix, StdMeshInstance& instance, DWORD dwModClr, DWORD dwBlitMode, DWORD dwPlayerColor, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect, bool parity)
|
|
|
|
|
{
|
|
|
|
|
const StdMesh& mesh = instance.GetMesh();
|
|
|
|
|
|
|
|
|
@ -801,7 +835,7 @@ namespace
|
|
|
|
|
StdMeshInstance::AttachedMeshIter attach_iter = instance.AttachedMeshesBegin();
|
|
|
|
|
|
|
|
|
|
for (; attach_iter != instance.AttachedMeshesEnd() && ((*attach_iter)->GetFlags() & StdMeshInstance::AM_DrawBefore); ++attach_iter)
|
|
|
|
|
RenderAttachedMesh(*attach_iter, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
RenderAttachedMesh(projectionMatrix, modelviewMatrix, *attach_iter, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
|
|
|
|
|
GLint modes[2];
|
|
|
|
|
// Check if we should draw in wireframe or normal mode
|
|
|
|
@ -814,7 +848,7 @@ namespace
|
|
|
|
|
|
|
|
|
|
// Render each submesh
|
|
|
|
|
for (unsigned int i = 0; i < mesh.GetNumSubMeshes(); ++i)
|
|
|
|
|
RenderSubMeshImpl(instance, instance.GetSubMeshOrdered(i), dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
RenderSubMeshImpl(projectionMatrix, modelviewMatrix, instance, instance.GetSubMeshOrdered(i), dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
|
|
|
|
|
// reset old mode to prevent rendering errors
|
|
|
|
|
if(dwBlitMode & C4GFXBLIT_WIREFRAME)
|
|
|
|
@ -825,7 +859,7 @@ namespace
|
|
|
|
|
|
|
|
|
|
// Render non-AM_DrawBefore attached meshes
|
|
|
|
|
for (; attach_iter != instance.AttachedMeshesEnd(); ++attach_iter)
|
|
|
|
|
RenderAttachedMesh(*attach_iter, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
RenderAttachedMesh(projectionMatrix, modelviewMatrix, *attach_iter, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -867,23 +901,21 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
|
|
|
|
|
//int iAdditive = dwBlitMode & C4GFXBLIT_ADDITIVE;
|
|
|
|
|
//glBlendFunc(GL_SRC_ALPHA, iAdditive ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
// Set up projection matrix first. We do transform and Zoom with the
|
|
|
|
|
// projection matrix, so that lighting is applied to the untransformed/unzoomed
|
|
|
|
|
// mesh.
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
|
|
|
|
|
// Mesh extents
|
|
|
|
|
const float b = fabs(v2.x - v1.x)/2.0f;
|
|
|
|
|
const float h = fabs(v2.y - v1.y)/2.0f;
|
|
|
|
|
const float l = fabs(v2.z - v1.z)/2.0f;
|
|
|
|
|
|
|
|
|
|
// Set up projection matrix first. We do transform and Zoom with the
|
|
|
|
|
// projection matrix, so that lighting is applied to the untransformed/unzoomed
|
|
|
|
|
// mesh.
|
|
|
|
|
StdProjectionMatrix projectionMatrix;
|
|
|
|
|
if (!fUsePerspective)
|
|
|
|
|
{
|
|
|
|
|
// Orthographic projection. The orthographic projection matrix
|
|
|
|
|
// is already loaded in the GL matrix stack.
|
|
|
|
|
// Load the orthographic projection
|
|
|
|
|
projectionMatrix = ProjectionMatrix;
|
|
|
|
|
|
|
|
|
|
if (!ApplyZoomAndTransform(ZoomX, ZoomY, Zoom, pTransform))
|
|
|
|
|
if (!ApplyZoomAndTransform(ZoomX, ZoomY, Zoom, pTransform, projectionMatrix))
|
|
|
|
|
parity = !parity;
|
|
|
|
|
|
|
|
|
|
// Scale so that the mesh fits in (tx,ty,twdt,thgt)
|
|
|
|
@ -913,24 +945,22 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
|
|
|
|
|
// there are attached meshes.
|
|
|
|
|
const float scz = 1.0/(mesh.GetBoundingRadius());
|
|
|
|
|
|
|
|
|
|
glTranslatef(dx, dy, 0.0f);
|
|
|
|
|
glScalef(1.0f, 1.0f, scz);
|
|
|
|
|
Translate(projectionMatrix, dx, dy, 0.0f);
|
|
|
|
|
Scale(projectionMatrix, 1.0f, 1.0f, scz);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Perspective projection. We need current viewport size.
|
|
|
|
|
const int iWdt=std::min(iClipX2, RenderTarget->Wdt-1)-iClipX1+1;
|
|
|
|
|
const int iHgt=std::min(iClipY2, RenderTarget->Hgt-1)-iClipY1+1;
|
|
|
|
|
|
|
|
|
|
// Get away with orthographic projection matrix currently loaded
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
// Perspective projection. This code transforms the projected
|
|
|
|
|
// 3D model into the target area.
|
|
|
|
|
const C4Rect clipRect = GetClipRect();
|
|
|
|
|
projectionMatrix = StdProjectionMatrix::Identity();
|
|
|
|
|
|
|
|
|
|
// Back to GL device coordinates
|
|
|
|
|
glTranslatef(-1.0f, 1.0f, 0.0f);
|
|
|
|
|
glScalef(2.0f/iWdt, -2.0f/iHgt, 1.0f);
|
|
|
|
|
Translate(projectionMatrix, -1.0f, 1.0f, 0.0f);
|
|
|
|
|
Scale(projectionMatrix, 2.0f/clipRect.Wdt, -2.0f/clipRect.Hgt, 1.0f);
|
|
|
|
|
|
|
|
|
|
glTranslatef(-iClipX1, -iClipY1, 0.0f);
|
|
|
|
|
if (!ApplyZoomAndTransform(ZoomX, ZoomY, Zoom, pTransform))
|
|
|
|
|
Translate(projectionMatrix, -clipRect.x, -clipRect.y, 0.0f);
|
|
|
|
|
if (!ApplyZoomAndTransform(ZoomX, ZoomY, Zoom, pTransform, projectionMatrix))
|
|
|
|
|
parity = !parity;
|
|
|
|
|
|
|
|
|
|
// Move to target location and compensate for 1.0f aspect
|
|
|
|
@ -946,87 +976,66 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
|
|
|
|
|
ttwdt = thgt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glTranslatef(ttx, tty, 0.0f);
|
|
|
|
|
glScalef(((float)ttwdt)/iWdt, ((float)tthgt)/iHgt, 1.0f);
|
|
|
|
|
Translate(projectionMatrix, ttx, tty, 0.0f);
|
|
|
|
|
Scale(projectionMatrix, ((float)ttwdt)/clipRect.Wdt, ((float)tthgt)/clipRect.Hgt, 1.0f);
|
|
|
|
|
|
|
|
|
|
// Return to Clonk coordinate frame
|
|
|
|
|
glScalef(iWdt/2.0, -iHgt/2.0, 1.0f);
|
|
|
|
|
glTranslatef(1.0f, -1.0f, 0.0f);
|
|
|
|
|
Scale(projectionMatrix, clipRect.Wdt/2.0, -clipRect.Hgt/2.0, 1.0f);
|
|
|
|
|
Translate(projectionMatrix, 1.0f, -1.0f, 0.0f);
|
|
|
|
|
|
|
|
|
|
// Fix for the case when we have a non-square target
|
|
|
|
|
// Fix for the case when we have different aspect ratios
|
|
|
|
|
const float ta = twdt / thgt;
|
|
|
|
|
const float ma = b / h;
|
|
|
|
|
if(ta <= 1 && ta/ma <= 1)
|
|
|
|
|
glScalef(std::max(ta, ta/ma), std::max(ta, ta/ma), 1.0f);
|
|
|
|
|
Scale(projectionMatrix, std::max(ta, ta/ma), std::max(ta, ta/ma), 1.0f);
|
|
|
|
|
else if(ta >= 1 && ta/ma >= 1)
|
|
|
|
|
glScalef(std::max(1.0f/ta, ma/ta), std::max(1.0f/ta, ma/ta), 1.0f);
|
|
|
|
|
Scale(projectionMatrix, std::max(1.0f/ta, ma/ta), std::max(1.0f/ta, ma/ta), 1.0f);
|
|
|
|
|
|
|
|
|
|
// Apply perspective projection. After this, x and y range from
|
|
|
|
|
// -1 to 1, and this is mapped into tx/ty/twdt/thgt by the above code.
|
|
|
|
|
// Aspect is 1.0f which is accounted for above.
|
|
|
|
|
gluPerspective(FOV, 1.0f, 0.1f, 100.0f);
|
|
|
|
|
// Aspect is 1.0f which is changed above as well.
|
|
|
|
|
Perspective(projectionMatrix, 1.0f/TAN_FOV, 1.0f, 0.1f, 100.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now set up modelview matrix
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
|
|
// Now set up the modelview matrix
|
|
|
|
|
StdMeshMatrix modelviewMatrix;
|
|
|
|
|
if (fUsePerspective)
|
|
|
|
|
{
|
|
|
|
|
// Setup camera position so that the mesh with uniform transformation
|
|
|
|
|
// fits well into a square target (without distortion).
|
|
|
|
|
const float EyeR = l + std::max(b/TAN_FOV, h/TAN_FOV);
|
|
|
|
|
const float EyeX = MeshCenter.x;
|
|
|
|
|
const float EyeY = MeshCenter.y;
|
|
|
|
|
const float EyeZ = MeshCenter.z + EyeR;
|
|
|
|
|
const StdMeshVector Eye = StdMeshVector::Translate(MeshCenter.x, MeshCenter.y, MeshCenter.z + EyeR);
|
|
|
|
|
|
|
|
|
|
// Up vector is unit vector in theta direction
|
|
|
|
|
const float UpX = 0;//-sinEyePhi * sinEyeTheta;
|
|
|
|
|
const float UpY = -1;//-cosEyeTheta;
|
|
|
|
|
const float UpZ = 0;//-cosEyePhi * sinEyeTheta;
|
|
|
|
|
const StdMeshVector Up = StdMeshVector::Translate(0.0f, -1.0f, 0.0f);
|
|
|
|
|
|
|
|
|
|
// Fix X axis (???)
|
|
|
|
|
glScalef(-1.0f, 1.0f, 1.0f);
|
|
|
|
|
modelviewMatrix = StdMeshMatrix::Scale(-1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
// center on mesh's bounding box, so that the mesh is really in the center of the viewport
|
|
|
|
|
gluLookAt(EyeX, EyeY, EyeZ, MeshCenter.x, MeshCenter.y, MeshCenter.z, UpX, UpY, UpZ);
|
|
|
|
|
modelviewMatrix *= StdMeshMatrix::LookAt(Eye, MeshCenter, Up);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
modelviewMatrix = StdMeshMatrix::Identity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply mesh transformation matrix
|
|
|
|
|
if (MeshTransform)
|
|
|
|
|
{
|
|
|
|
|
// Convert to column-major order
|
|
|
|
|
const float Matrix[16] =
|
|
|
|
|
{
|
|
|
|
|
(*MeshTransform)(0,0), (*MeshTransform)(1,0), (*MeshTransform)(2,0), 0,
|
|
|
|
|
(*MeshTransform)(0,1), (*MeshTransform)(1,1), (*MeshTransform)(2,1), 0,
|
|
|
|
|
(*MeshTransform)(0,2), (*MeshTransform)(1,2), (*MeshTransform)(2,2), 0,
|
|
|
|
|
(*MeshTransform)(0,3), (*MeshTransform)(1,3), (*MeshTransform)(2,3), 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const float det = MeshTransform->Determinant();
|
|
|
|
|
if (det < 0) parity = !parity;
|
|
|
|
|
|
|
|
|
|
// Renormalize if transformation resizes the mesh
|
|
|
|
|
// for lighting to be correct.
|
|
|
|
|
// TODO: Also needs to check for orthonormality to be correct
|
|
|
|
|
if (det != 1 && det != -1)
|
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
|
|
|
|
|
|
// Apply MeshTransformation (in the Mesh's coordinate system)
|
|
|
|
|
glMultMatrixf(Matrix);
|
|
|
|
|
modelviewMatrix *= *MeshTransform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DWORD dwModClr = BlitModulated ? BlitModulateClr : 0xffffffff;
|
|
|
|
|
|
|
|
|
|
const C4Rect clipRect = GetClipRect();
|
|
|
|
|
const C4Rect outRect = GetOutRect();
|
|
|
|
|
RenderMeshImpl(instance, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
RenderMeshImpl(projectionMatrix, modelviewMatrix, instance, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
|
|
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); // switch back to default
|
|
|
|
|
glClientActiveTexture(GL_TEXTURE0); // switch back to default
|
|
|
|
@ -1036,7 +1045,6 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
|
|
|
|
|
glDisableClientState(GL_NORMAL_ARRAY);
|
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
|
|
|
|
|
glDisable(GL_NORMALIZE);
|
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
|
glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
|
|
|
|
|