TombEngine/TR5Main/Renderer/Renderer11Draw2D.cpp

194 lines
6.9 KiB
C++
Raw Normal View History

#include "framework.h"
#include "Renderer11.h"
#include "camera.h"
#include "spotcam.h"
#include "lara.h"
2021-08-28 13:27:58 +02:00
#include "control.h"
2021-08-30 18:03:21 +03:00
TEN::Renderer::RendererHUDBar* g_HealthBar;
TEN::Renderer::RendererHUDBar* g_AirBar;
TEN::Renderer::RendererHUDBar* g_DashBar;
TEN::Renderer::RendererHUDBar* g_MusicVolumeBar;
TEN::Renderer::RendererHUDBar* g_SFXVolumeBar;
2021-08-30 18:03:21 +03:00
namespace TEN::Renderer {
2020-01-12 23:10:38 +01:00
2020-08-09 15:25:56 +02:00
void Renderer11::initialiseBars()
Merge branch 'master' into item_data # Conflicts: # TR5Main/Game/Lara/lara.cpp # TR5Main/Game/Lara/lara_collide.cpp # TR5Main/Game/Lara/lara_monkey.cpp # TR5Main/Game/Lara/lara_struct.h # TR5Main/Game/Lara/lara_tests.cpp # TR5Main/Game/collide.h # TR5Main/Game/control.h # TR5Main/Game/effect.h # TR5Main/Game/effect2.cpp # TR5Main/Game/flipeffect.cpp # TR5Main/Game/floordata.h # TR5Main/Game/hair.cpp # TR5Main/Game/health.cpp # TR5Main/Game/items.cpp # TR5Main/Game/newinv2.cpp # TR5Main/Game/spotcam.cpp # TR5Main/Objects/Effects/tr4_bubbles.cpp # TR5Main/Objects/TR1/Entity/tr1_ape.cpp # TR5Main/Objects/TR1/Entity/tr1_bigrat.cpp # TR5Main/Objects/TR1/Entity/tr1_doppelganger.cpp # TR5Main/Objects/TR2/Entity/tr2_birdmonster.cpp # TR5Main/Objects/TR2/Entity/tr2_shark.cpp # TR5Main/Objects/TR2/Entity/tr2_spider.cpp # TR5Main/Objects/TR2/Entity/tr2_yeti.cpp # TR5Main/Objects/TR3/Entity/tr3_fishemitter.cpp # TR5Main/Objects/TR3/Entity/tr3_flamethrower.cpp # TR5Main/Objects/TR3/Entity/tr3_monkey.cpp # TR5Main/Objects/TR3/Entity/tr3_raptor.cpp # TR5Main/Objects/TR3/Entity/tr3_scuba.cpp # TR5Main/Objects/TR3/Entity/tr3_trex.cpp # TR5Main/Objects/TR3/Vehicles/kayak.cpp # TR5Main/Objects/TR3/Vehicles/minecart.cpp # TR5Main/Objects/TR4/Entity/tr4_bat.cpp # TR5Main/Objects/TR4/Entity/tr4_big_beetle.cpp # TR5Main/Objects/TR4/Entity/tr4_bigscorpion.cpp # TR5Main/Objects/TR4/Entity/tr4_demigod.cpp # TR5Main/Objects/TR4/Entity/tr4_dog.cpp # TR5Main/Objects/TR4/Entity/tr4_hammerhead.cpp # TR5Main/Objects/TR4/Entity/tr4_harpy.cpp # TR5Main/Objects/TR4/Entity/tr4_mutant.cpp # TR5Main/Objects/TR4/Entity/tr4_smallscorpion.cpp # TR5Main/Objects/TR4/Entity/tr4_troops.cpp # TR5Main/Objects/TR4/Entity/tr4_wildboar.cpp # TR5Main/Objects/TR4/Trap/tr4_joby_spikes.cpp # TR5Main/Objects/TR4/Vehicles/motorbike.cpp # TR5Main/Objects/TR5/Entity/tr5_doberman.cpp # TR5Main/Objects/TR5/Entity/tr5_imp.cpp # TR5Main/Objects/TR5/Entity/tr5_larson.cpp # TR5Main/Objects/TR5/Entity/tr5_lion.cpp # TR5Main/Objects/TR5/Entity/tr5_reaper.cpp # TR5Main/Objects/TR5/Object/tr5_pushableblock.cpp # TR5Main/Objects/TR5/Object/tr5_rollingball.cpp # TR5Main/Objects/TR5/Trap/tr5_fallingceiling.cpp # TR5Main/Renderer/Renderer11Draw2D.cpp # TR5Main/Specific/input.cpp # TR5Main/Specific/level.cpp # TR5Main/TombEngine.vcxproj.filters
2021-08-31 17:37:15 +02:00
{
std::array<Vector4, 5> healthColors = {
//top
Vector4(82 / 255.0f,0,0,1),
Vector4(0,82 / 255.0f,0,1),
//center
Vector4(78 / 255.0f,81 / 255.0f,0,1),
//bottom
Vector4(82 / 255.0f,0,0,1),
Vector4(0,82 / 255.0f,0,1),
};
std::array<Vector4, 5> airColors = {
//top
Vector4(0 ,0,90 / 255.0f,1),
Vector4(0 ,47 / 255.0f,96 / 255.0f,1),
//center
Vector4(0,39 / 255,155 / 255.0f,1),
//bottom
Vector4(0 ,0,90 / 255.0f,1),
Vector4(0 ,47 / 255.0f,96 / 255.0f,1),
};
std::array<Vector4, 5> dashColors = {
//top
Vector4(78 / 255.0f,4 / 255.0f,0,1),
Vector4(136 / 255.0f,117 / 255.0f,5 / 255.0f,1),
//center
Vector4(245 / 255.0f,119 / 255,24 / 255.0f,1),
//bottom
Vector4(78 / 255.0f,4 / 255.0f,0,1),
Vector4(136 / 255.0f,117 / 255.0f,5 / 255.0f,1),
};
std::array<Vector4, 5> soundSettingColors = {
//top
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
//center
Vector4(0.18f,0.3f,0.72f,1),
//bottom
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
};
2020-08-09 22:15:32 +02:00
g_HealthBar = new RendererHUDBar(m_device.Get(), 20, 32, 150, 8, 1, healthColors);
g_AirBar = new RendererHUDBar(m_device.Get(), 630, 32, 150, 8, 1, airColors);
g_DashBar = new RendererHUDBar(m_device.Get(), 630, 32 + 8 + 4, 150, 8, 1, dashColors);
g_MusicVolumeBar = new RendererHUDBar(m_device.Get(), 400, 194, 150, 8, 1, soundSettingColors);
g_SFXVolumeBar = new RendererHUDBar(m_device.Get(), 400, 212, 150, 8, 1, soundSettingColors);
}
void Renderer11::drawBar(float percent, const RendererHUDBar* const bar,GAME_OBJECT_ID textureSlot,int frame, bool poison) {
UINT strides = sizeof(RendererVertex);
UINT offset = 0;
float color[] = { 0,0,0,1.0f };
m_context->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xFF);
2020-08-09 22:15:32 +02:00
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetVertexBuffers(0, 1, bar->vertexBufferBorder.Buffer.GetAddressOf(), &strides, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetIndexBuffer(bar->indexBufferBorder.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
2020-07-23 21:40:07 +02:00
m_context->VSSetConstantBuffers(0, 1, m_cbHUD.get());
2020-08-09 22:15:32 +02:00
m_context->VSSetShader(m_vsHUD.Get(), NULL, 0);
m_context->PSSetShaderResources(0, 1, m_sprites[Objects[ID_BAR_BORDER_GRAPHIC].meshIndex].Texture->ShaderResourceView.GetAddressOf());
ID3D11SamplerState* sampler = m_states->LinearClamp();
m_context->PSSetSamplers(0, 1, &sampler);
2020-08-09 22:15:32 +02:00
m_context->PSSetShader(m_psHUDTexture.Get(), NULL, 0);
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthNone(), NULL);
m_context->RSSetState(m_states->CullNone());
m_context->DrawIndexed(56, 0, 0);
m_context->PSSetShaderResources(0, 1, m_sprites[Objects[textureSlot].meshIndex].Texture->ShaderResourceView.GetAddressOf());
m_context->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xFF);
2020-08-09 22:15:32 +02:00
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetVertexBuffers(0, 1, bar->vertexBuffer.Buffer.GetAddressOf(), &strides, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetIndexBuffer(bar->indexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
m_stHUDBar.Percent = percent;
m_stHUDBar.Poisoned = poison;
m_stHUDBar.Frame = frame;
2020-08-09 22:15:32 +02:00
m_cbHUDBar.updateData(m_stHUDBar, m_context.Get());
2020-07-23 21:40:07 +02:00
m_context->VSSetConstantBuffers(0, 1, m_cbHUD.get());
m_context->PSSetConstantBuffers(0, 1, m_cbHUDBar.get());
2020-08-09 22:15:32 +02:00
m_context->VSSetShader(m_vsHUD.Get(), NULL, 0);
m_context->PSSetShader(m_psHUDBarColor.Get(), NULL, 0);
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthNone(), NULL);
m_context->RSSetState(m_states->CullNone());
m_context->DrawIndexed(12, 0, 0);
}
2020-08-09 15:25:56 +02:00
void Renderer11::addLine2D(int x1, int y1, int x2, int y2, byte r, byte g, byte b, byte a) {
RendererLine2D* line = &m_lines2DBuffer[m_nextLine2D++];
line->Vertices[0] = Vector2(x1, y1);
line->Vertices[1] = Vector2(x2, y2);
line->Color = Vector4(r, g, b, a);
m_lines2DToDraw.push_back(line);
}
2021-09-14 19:53:09 +03:00
void Renderer11::addQuad2D(RECT rect, byte r, byte g, byte b, byte a)
{
RendererRect2D* quad = &m_rects2DBuffer[m_nextRect2D++];
quad->Rectangle = rect;
quad->Color = Vector4(r, g, b, a);
m_rects2DToDraw.push_back(quad);
}
2020-10-11 16:47:36 +02:00
void Renderer11::drawOverlays(RenderView& view)
{
if (CurrentLevel == 0)
return;
if (!BinocularRange && !SpotcamOverlay)
2020-08-09 15:25:56 +02:00
return;
m_context->OMSetBlendState(m_states->AlphaBlend(), NULL, 0xFFFFFFFF);
if (BinocularRange && !LaserSight)
{
drawFullScreenQuad(m_sprites[Objects[ID_BINOCULAR_GRAPHIC].meshIndex].Texture->ShaderResourceView.Get(), Vector3::One, false);
}
else if (BinocularRange && LaserSight)
{
drawFullScreenQuad(m_sprites[Objects[ID_LASER_SIGHT_GRAPHIC].meshIndex].Texture->ShaderResourceView.Get(), Vector3::One, false);
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
// Draw the aiming point
RendererVertex vertices[4];
vertices[0].Position.x = -4.0f / ScreenWidth;
vertices[0].Position.y = 4.0f / ScreenHeight;
vertices[0].Position.z = 0.0f;
vertices[0].UV.x = 0.0f;
vertices[0].UV.y = 0.0f;
vertices[0].Color = Vector4(1.0f, 0.0f, 0.0f, 1.0f);
vertices[1].Position.x = 4.0f / ScreenWidth;
vertices[1].Position.y = 4.0f / ScreenHeight;
vertices[1].Position.z = 0.0f;
vertices[1].UV.x = 1.0f;
vertices[1].UV.y = 0.0f;
vertices[1].Color = Vector4(1.0f, 0.0f, 0.0f, 1.0f);
vertices[2].Position.x = 4.0f / ScreenWidth;
vertices[2].Position.y = -4.0f / ScreenHeight;
vertices[2].Position.z = 0.0f;
vertices[2].UV.x = 1.0f;
vertices[2].UV.y = 1.0f;
vertices[2].Color = Vector4(1.0f, 0.0f, 0.0f, 1.0f);
vertices[3].Position.x = -4.0f / ScreenWidth;
vertices[3].Position.y = -4.0f / ScreenHeight;
vertices[3].Position.z = 0.0f;
vertices[3].UV.x = 0.0f;
vertices[3].UV.y = 1.0f;
vertices[3].Color = Vector4(1.0f, 0.0f, 0.0f, 1.0f);
2020-08-09 22:15:32 +02:00
m_context->VSSetShader(m_vsFullScreenQuad.Get(), NULL, 0);
m_context->PSSetShader(m_psFullScreenQuad.Get(), NULL, 0);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
2020-08-09 22:15:32 +02:00
m_context->IASetInputLayout(m_inputLayout.Get());
m_primitiveBatch->Begin();
m_primitiveBatch->DrawQuad(vertices[0], vertices[1], vertices[2], vertices[3]);
m_primitiveBatch->End();
}
else
{
// TODO: Vignette goes here! -- Lwmte, 21.08.21
}
}
}