Implement special colormap support for softpoly
This commit is contained in:
parent
bdb4bdeb09
commit
e68b46cb6a
11 changed files with 185 additions and 14 deletions
|
|
@ -85,6 +85,9 @@ PolyFrameBuffer::~PolyFrameBuffer()
|
|||
PolyBuffer::ResetAll();
|
||||
PPResource::ResetAll();
|
||||
|
||||
delete mScreenQuad.VertexBuffer;
|
||||
delete mScreenQuad.IndexBuffer;
|
||||
|
||||
delete mVertexData;
|
||||
delete mSkyData;
|
||||
delete mViewpoints;
|
||||
|
|
@ -111,6 +114,21 @@ void PolyFrameBuffer::InitializeState()
|
|||
mViewpoints = new HWViewpointBuffer;
|
||||
mLights = new FLightBuffer();
|
||||
|
||||
static const FVertexBufferAttribute format[] =
|
||||
{
|
||||
{ 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(ScreenQuadVertex, x) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(ScreenQuadVertex, u) },
|
||||
{ 0, VATTR_COLOR, VFmt_Byte4, (int)myoffsetof(ScreenQuadVertex, color0) }
|
||||
};
|
||||
|
||||
uint32_t indices[6] = { 0, 1, 2, 1, 3, 2 };
|
||||
|
||||
mScreenQuad.VertexBuffer = screen->CreateVertexBuffer();
|
||||
mScreenQuad.VertexBuffer->SetFormat(1, 3, sizeof(ScreenQuadVertex), format);
|
||||
|
||||
mScreenQuad.IndexBuffer = screen->CreateIndexBuffer();
|
||||
mScreenQuad.IndexBuffer->SetData(6 * sizeof(uint32_t), indices, false);
|
||||
|
||||
CheckCanvas();
|
||||
}
|
||||
|
||||
|
|
@ -436,9 +454,54 @@ void PolyFrameBuffer::DrawScene(HWDrawInfo *di, int drawmode)
|
|||
di->RenderTranslucent(*GetRenderState());
|
||||
}
|
||||
|
||||
static uint8_t ToIntColorComponent(float v)
|
||||
{
|
||||
return clamp((int)(v * 255.0f + 0.5f), 0, 255);
|
||||
}
|
||||
|
||||
void PolyFrameBuffer::PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D)
|
||||
{
|
||||
afterBloomDrawEndScene2D();
|
||||
|
||||
if (fixedcm >= CM_FIRSTSPECIALCOLORMAP && fixedcm < CM_MAXCOLORMAP)
|
||||
{
|
||||
FSpecialColormap* scm = &SpecialColormaps[fixedcm - CM_FIRSTSPECIALCOLORMAP];
|
||||
|
||||
mRenderState->SetViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
|
||||
screen->mViewpoints->Set2D(*mRenderState, screen->GetWidth(), screen->GetHeight());
|
||||
|
||||
ScreenQuadVertex vertices[4] =
|
||||
{
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ (float)mScreenViewport.width, 0.0f, 1.0f, 0.0f },
|
||||
{ 0.0f, (float)mScreenViewport.height, 0.0f, 1.0f },
|
||||
{ (float)mScreenViewport.width, (float)mScreenViewport.height, 1.0f, 1.0f }
|
||||
};
|
||||
mScreenQuad.VertexBuffer->SetData(4 * sizeof(ScreenQuadVertex), vertices, false);
|
||||
|
||||
mRenderState->SetVertexBuffer(mScreenQuad.VertexBuffer, 0, 0);
|
||||
mRenderState->SetIndexBuffer(mScreenQuad.IndexBuffer);
|
||||
|
||||
mRenderState->SetObjectColor(PalEntry(255, int(scm->ColorizeStart[0] * 127.5f), int(scm->ColorizeStart[1] * 127.5f), int(scm->ColorizeStart[2] * 127.5f)));
|
||||
mRenderState->SetAddColor(PalEntry(255, int(scm->ColorizeEnd[0] * 127.5f), int(scm->ColorizeEnd[1] * 127.5f), int(scm->ColorizeEnd[2] * 127.5f)));
|
||||
|
||||
mRenderState->EnableDepthTest(false);
|
||||
mRenderState->EnableMultisampling(false);
|
||||
mRenderState->SetCulling(Cull_None);
|
||||
|
||||
mRenderState->SetScissor(-1, -1, -1, -1);
|
||||
mRenderState->SetColor(1, 1, 1, 1);
|
||||
mRenderState->AlphaFunc(Alpha_GEqual, 0.f);
|
||||
mRenderState->EnableTexture(false);
|
||||
mRenderState->SetColormapShader(true);
|
||||
mRenderState->DrawIndexed(DT_Triangles, 0, 6);
|
||||
mRenderState->SetColormapShader(false);
|
||||
mRenderState->SetObjectColor(0xffffffff);
|
||||
mRenderState->SetAddColor(0);
|
||||
mRenderState->SetVertexBuffer(screen->mVertexData);
|
||||
mRenderState->EnableTexture(true);
|
||||
mRenderState->ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t PolyFrameBuffer::GetCaps()
|
||||
|
|
|
|||
|
|
@ -84,6 +84,22 @@ private:
|
|||
std::unique_ptr<PolyCommandBuffer> mDrawCommands;
|
||||
RenderMemory mFrameMemory;
|
||||
|
||||
struct ScreenQuadVertex
|
||||
{
|
||||
float x, y, z;
|
||||
float u, v;
|
||||
PalEntry color0;
|
||||
|
||||
ScreenQuadVertex() = default;
|
||||
ScreenQuadVertex(float x, float y, float u, float v) : x(x), y(y), z(1.0f), u(u), v(v), color0(0xffffffff) { }
|
||||
};
|
||||
|
||||
struct ScreenQuad
|
||||
{
|
||||
IVertexBuffer* VertexBuffer = nullptr;
|
||||
IIndexBuffer* IndexBuffer = nullptr;
|
||||
} mScreenQuad;
|
||||
|
||||
bool cur_vsync = false;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -204,6 +204,12 @@ void PolyRenderState::EnableDrawBuffers(int count)
|
|||
{
|
||||
}
|
||||
|
||||
void PolyRenderState::SetColormapShader(bool enable)
|
||||
{
|
||||
mNeedApply = true;
|
||||
mColormapShader = enable;
|
||||
}
|
||||
|
||||
void PolyRenderState::EndRenderPass()
|
||||
{
|
||||
mDrawCommands = nullptr;
|
||||
|
|
@ -260,14 +266,18 @@ void PolyRenderState::Apply()
|
|||
mDrawCommands->SetInputAssembly(static_cast<PolyVertexBuffer*>(mVertexBuffer)->VertexFormat);
|
||||
mDrawCommands->SetRenderStyle(mRenderStyle);
|
||||
|
||||
if (mSpecialEffect > EFF_NONE)
|
||||
if (mColormapShader)
|
||||
{
|
||||
mDrawCommands->SetShader(mSpecialEffect, 0, false);
|
||||
mDrawCommands->SetShader(EFF_NONE, 0, false, true);
|
||||
}
|
||||
else if (mSpecialEffect > EFF_NONE)
|
||||
{
|
||||
mDrawCommands->SetShader(mSpecialEffect, 0, false, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
int effectState = mMaterial.mOverrideShader >= 0 ? mMaterial.mOverrideShader : (mMaterial.mMaterial ? mMaterial.mMaterial->GetShaderIndex() : 0);
|
||||
mDrawCommands->SetShader(EFF_NONE, mTextureEnabled ? effectState : SHADER_NoTexture, mAlphaThreshold >= 0.f);
|
||||
mDrawCommands->SetShader(EFF_NONE, mTextureEnabled ? effectState : SHADER_NoTexture, mAlphaThreshold >= 0.f, false);
|
||||
}
|
||||
|
||||
PolyPushConstants constants;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ public:
|
|||
PolyVertexInputAssembly *GetVertexFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs);
|
||||
void EndRenderPass();
|
||||
|
||||
void SetColormapShader(bool enable);
|
||||
|
||||
private:
|
||||
void Apply();
|
||||
void ApplyMaterial();
|
||||
|
|
@ -92,6 +94,7 @@ private:
|
|||
int mStencilOp = SOP_Keep;
|
||||
int mCulling = Cull_None;
|
||||
bool mColorMask[4] = { true, true, true, true };
|
||||
bool mColormapShader = false;
|
||||
|
||||
PolyCommandBuffer* mDrawCommands = nullptr;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue