Add ClampToEdgeNearest texture mode

This commit is contained in:
Jack Andersen 2018-02-01 13:12:42 -10:00
parent c314730d51
commit 72c9809655
3 changed files with 22 additions and 5 deletions

View File

@ -71,7 +71,8 @@ enum class TextureClampMode
{
Repeat,
ClampToWhite,
ClampToEdge
ClampToEdge,
ClampToEdgeNearest
};
/** Typeless texture */

View File

@ -257,6 +257,15 @@ static void SetClampMode(GLenum target, TextureClampMode clampMode)
glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
break;
}
case TextureClampMode::ClampToEdgeNearest:
{
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
break;
}
}
}
@ -274,7 +283,7 @@ class GLTextureS : public GraphicsDataNode<ITextureS>
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (mips > 1)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mips-1);
}
else

View File

@ -1129,7 +1129,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue
IGraphicsContext* m_parent;
id<MTLCommandBuffer> m_cmdBuf;
id<MTLRenderCommandEncoder> m_enc;
id<MTLSamplerState> m_samplers[3];
id<MTLSamplerState> m_samplers[4];
bool m_running = true;
int m_fillBuf = 0;
@ -1162,6 +1162,13 @@ struct MetalCommandQueue : IGraphicsCommandQueue
sampDesc.sAddressMode = MTLSamplerAddressModeClampToEdge;
sampDesc.tAddressMode = MTLSamplerAddressModeClampToEdge;
m_samplers[2] = [ctx->m_dev newSamplerStateWithDescriptor:sampDesc];
sampDesc.rAddressMode = MTLSamplerAddressModeClampToEdge;
sampDesc.sAddressMode = MTLSamplerAddressModeClampToEdge;
sampDesc.tAddressMode = MTLSamplerAddressModeClampToEdge;
sampDesc.minFilter = MTLSamplerMinMagFilterNearest;
sampDesc.magFilter = MTLSamplerMinMagFilterNearest;
m_samplers[3] = [ctx->m_dev newSamplerStateWithDescriptor:sampDesc];
}
}
@ -1192,7 +1199,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue
cbind->bind(m_enc, m_fillBuf);
m_boundData = cbind;
m_currentPrimitive = cbind->m_pipeline.cast<MetalShaderPipeline>()->m_drawPrim;
[m_enc setFragmentSamplerStates:m_samplers withRange:NSMakeRange(0, 3)];
[m_enc setFragmentSamplerStates:m_samplers withRange:NSMakeRange(0, 4)];
}
}
@ -1493,7 +1500,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue
MetalShaderDataBinding* gammaBinding = gfxF->m_gammaBinding.cast<MetalShaderDataBinding>();
gammaBinding->m_texs[0].tex = m_needsDisplay.get();
gammaBinding->bind(enc, m_drawBuf);
[enc setFragmentSamplerStates:m_samplers withRange:NSMakeRange(0, 3)];
[enc setFragmentSamplerStates:m_samplers withRange:NSMakeRange(0, 4)];
[enc drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
gammaBinding->m_texs[0].tex.reset();
[enc endEncoding];