Skip to content

Commit

Permalink
Merge pull request #1053 from marauder2k9-torque/GLBorder
Browse files Browse the repository at this point in the history
Add border color and clamp to border
  • Loading branch information
Azaezel authored Jul 19, 2023
2 parents ae108d0 + e0119ef commit 9d89e01
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions Engine/source/gfx/D3D11/gfxD3D11StateBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ GFXD3D11StateBlock::GFXD3D11StateBlock(const GFXStateBlockDesc& desc)
else
mSamplerDesc[i].Filter = comparison ? D3D11_FILTER_COMPARISON_ANISOTROPIC : D3D11_FILTER_ANISOTROPIC;

mSamplerDesc[i].BorderColor[0] = 1.0f;
mSamplerDesc[i].BorderColor[1] = 1.0f;
mSamplerDesc[i].BorderColor[2] = 1.0f;
mSamplerDesc[i].BorderColor[3] = 1.0f;
LinearColorF bc = LinearColorF(gfxSamplerState.borderColor);
mSamplerDesc[i].BorderColor[0] = bc.red;
mSamplerDesc[i].BorderColor[1] = bc.green;
mSamplerDesc[i].BorderColor[2] = bc.blue;
mSamplerDesc[i].BorderColor[3] = bc.alpha;
mSamplerDesc[i].ComparisonFunc = GFXD3D11CmpFunc[gfxSamplerState.samplerFunc];

hr = D3D11DEVICE->CreateSamplerState(&mSamplerDesc[i], &mSamplerStates[i]);
Expand Down
1 change: 1 addition & 0 deletions Engine/source/gfx/gfxStateBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ GFXSamplerStateDesc::GFXSamplerStateDesc()
samplerFunc = GFXCmpNever;
maxAnisotropy = 1;
mipLODBias = 0.0f;
borderColor = ColorI::WHITE;
}

GFXSamplerStateDesc GFXSamplerStateDesc::getWrapLinear()
Expand Down
2 changes: 2 additions & 0 deletions Engine/source/gfx/gfxStateBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct GFXSamplerStateDesc

GFXCmpFunc samplerFunc;

ColorI borderColor;

/// The maximum anisotropy used when one of the filter types
/// is set to anisotropic.
///
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/gfx/gl/gfxGLEnumTranslate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void GFXGLEnumTranslate::init()
GFXGLTextureAddress[GFXAddressWrap] = GL_REPEAT;
GFXGLTextureAddress[GFXAddressMirror] = GL_REPEAT;
GFXGLTextureAddress[GFXAddressClamp] = GL_CLAMP_TO_EDGE;
GFXGLTextureAddress[GFXAddressBorder] = GL_REPEAT;
GFXGLTextureAddress[GFXAddressBorder] = GL_CLAMP_TO_BORDER;
GFXGLTextureAddress[GFXAddressMirrorOnce] = GL_REPEAT;

// Stencil ops
Expand Down
11 changes: 10 additions & 1 deletion Engine/source/gfx/gl/gfxGLStateBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ GFXGLStateBlock::GFXGLStateBlock(const GFXStateBlockDesc& desc) :
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GFXGLTextureAddress[ssd.addressModeU]);
glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GFXGLTextureAddress[ssd.addressModeV]);
glSamplerParameteri(id, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);


if (ssd.addressModeU == GFXAddressBorder ||
ssd.addressModeV == GFXAddressBorder ||
ssd.addressModeW == GFXAddressBorder)
{
LinearColorF bc = LinearColorF(ssd.borderColor);
GLfloat color[4] = { bc.red, bc.green, bc.blue, bc.alpha };
glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, color);
}

//compare modes
const bool comparison = ssd.samplerFunc != GFXCmpNever;
glSamplerParameteri(id, GL_TEXTURE_COMPARE_MODE, comparison ? GL_COMPARE_R_TO_TEXTURE_ARB : GL_NONE );
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/gfx/gl/gfxGLTextureObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void GFXGLTextureObject::initSamplerState(const GFXSamplerStateDesc &ssd)
glTexParameteri(mBinding, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);
if(static_cast< GFXGLDevice* >( GFX )->supportsAnisotropic() )
glTexParameterf(mBinding, GL_TEXTURE_MAX_ANISOTROPY_EXT, ssd.maxAnisotropy);

mNeedInitSamplerState = false;
mSampler = ssd;
}
Expand Down
2 changes: 2 additions & 0 deletions Engine/source/gfx/sim/gfxStateBlockData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ void GFXSamplerStateData::initPersistFields()

endGroup( "Filter State" );

addField("borderColor", TypeColorI, Offset(mState.borderColor, GFXSamplerStateData), "");

addField("samplerFunc", TypeGFXCmpFunc, Offset(mState.samplerFunc, GFXSamplerStateData),
"Compares sampled data against existing sampled data. The default is GFXCmpNever.");
}
Expand Down

0 comments on commit 9d89e01

Please sign in to comment.