Allow turning off individual channels in gfx api

This commit is contained in:
UnknownShadow200 2018-03-10 17:07:38 +11:00
parent cd7bea891d
commit c61f3cb326
7 changed files with 15 additions and 12 deletions

View File

@ -247,8 +247,9 @@ namespace ClassicalSharp.GraphicsAPI {
lastClearCol = col.Pack();
}
public override bool ColourWrite {
set { device.SetRenderState(RenderState.ColorWriteEnable, value ? 0xF : 0x0); }
public override void ColourWriteMask(bool r, bool g, bool b, bool a) {
int flags = (r ? 1 : 0) | (g ? 2 : 0) | (b ? 4 : 0) | (a ? 8 : 0);
device.SetRenderState(RenderState.ColorWriteEnable, flags);
}
Compare depthTestFunc;

View File

@ -144,7 +144,7 @@ namespace ClassicalSharp.GraphicsAPI {
public abstract void DepthTestFunc(CompareFunc func);
/// <summary> Whether writing to the colour buffer is enabled. </summary>
public abstract bool ColourWrite { set; }
public abstract void ColourWriteMask(bool r, bool g, bool b, bool a);
/// <summary> Whether writing to the depth buffer is enabled. </summary>
public abstract bool DepthWrite { set; }

View File

@ -138,7 +138,9 @@ namespace ClassicalSharp.GraphicsAPI {
}
}
public override bool ColourWrite { set { GL.ColorMask(value, value, value, value); } }
public override void ColourWriteMask(bool r, bool g, bool b, bool a) {
GL.ColorMask(r, g, b, a);
}
public override void DepthTestFunc(CompareFunc func) {
GL.DepthFunc(compareFuncs[(int)func]);

View File

@ -146,7 +146,7 @@ namespace ClassicalSharp.Renderers {
gfx.SetBatchFormat(VertexFormat.P3fT2fC4b);
gfx.Texturing = false;
gfx.AlphaBlending = false;
gfx.ColourWrite = false;
gfx.ColourWriteMask(false, false, false, false);
for (int batch = 0; batch < _1DUsed; batch++) {
if (translucentPartsCount[batch] <= 0) continue;
if (pendingTranslucent[batch] || usedTranslucent[batch]) {
@ -159,7 +159,7 @@ namespace ClassicalSharp.Renderers {
// Then actually draw the transluscent blocks
gfx.AlphaBlending = true;
gfx.Texturing = true;
gfx.ColourWrite = true;
gfx.ColourWriteMask(true, true, true, true);
gfx.DepthWrite = false; // we already calculated depth values in depth pass
int[] texIds = game.TerrainAtlas1D.TexIds;

View File

@ -411,8 +411,8 @@ void Gfx_SetDepthTestFunc(Int32 compareFunc) {
D3D9_SetRenderState(d3d9_alphaTestFunc, D3DRS_ZFUNC, "D3D9_SetDepthTestFunc");
}
void Gfx_SetColourWrite(bool enabled) {
UInt32 channels = enabled ? 0xF : 0x0;
void Gfx_SetColourWriteMask(bool r, bool g, bool b, bool a) {
UInt32 channels = (r ? 1u : 0u) | (g ? 2u : 0u) | (b ? 4u : 0u) | (a ? 8u : 0u);
D3D9_SetRenderState(channels, D3DRS_COLORWRITEENABLE, "D3D9_SetColourWrite");
}

View File

@ -214,7 +214,7 @@ void MapRenderer_RenderTranslucent(Real64 deltaTime) {
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetTexturing(false);
Gfx_SetAlphaBlending(false);
Gfx_SetColourWrite(false);
Gfx_SetColourWriteMask(false, false, false, false);
UInt32 batch;
for (batch = 0; batch < MapRenderer_1DUsedCount; batch++) {
@ -229,7 +229,7 @@ void MapRenderer_RenderTranslucent(Real64 deltaTime) {
/* Then actually draw the transluscent blocks */
Gfx_SetAlphaBlending(true);
Gfx_SetTexturing(true);
Gfx_SetColourWrite(true);
Gfx_SetColourWriteMask(true, true, true, true);
Gfx_SetDepthWrite(false); /* we already calculated depth values in depth pass */
Gfx_EnableMipmaps();

View File

@ -230,8 +230,8 @@ void Gfx_ClearColour(PackedCol col) {
gl_lastClearCol = col;
}
void Gfx_SetColourWrite(bool enabled) {
glColorMask(enabled, enabled, enabled, enabled);
void Gfx_SetColourWriteMask(bool r, bool g, bool b, bool a) {
glColorMask(r, g, b, a);
}
void Gfx_SetDepthWrite(bool enabled) {