Skip to content

Commit

Permalink
ImGui Viewports (part 4), refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Jun 15, 2024
1 parent 272c295 commit 97dd38d
Show file tree
Hide file tree
Showing 40 changed files with 285 additions and 199 deletions.
Binary file modified Sources/Icons/Main.ico
Binary file not shown.
Binary file renamed Sources/Icons/Log.ico → Sources/Icons/Window.ico
Binary file not shown.
Binary file added Sources/Icons/WindowImGui.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/ActorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ namespace Jazz2::Actors
_rendererType((ActorRendererType)-1), _rendererTransition(0.0f)
{
_type = ObjectType::Sprite;
renderCommand_.setType(RenderCommand::CommandTypes::Sprite);
renderCommand_.setType(RenderCommand::Type::Sprite);
Initialize(ActorRendererType::Default);
}

Expand All @@ -1204,7 +1204,7 @@ namespace Jazz2::Actors
case ActorRendererType::WhiteMask: shaderChanged = renderCommand_.material().setShader(ContentResolver::Get().GetShader(PrecompiledShader::WhiteMask)); break;
case ActorRendererType::PartialWhiteMask: shaderChanged = renderCommand_.material().setShader(ContentResolver::Get().GetShader(PrecompiledShader::PartialWhiteMask)); break;
case ActorRendererType::FrozenMask: shaderChanged = renderCommand_.material().setShader(ContentResolver::Get().GetShader(PrecompiledShader::FrozenMask)); break;
default: shaderChanged = renderCommand_.material().setShaderProgramType(Material::ShaderProgramType::SPRITE); break;
default: shaderChanged = renderCommand_.material().setShaderProgramType(Material::ShaderProgramType::Sprite); break;
}
if (shaderChanged) {
shaderHasChanged();
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Collectibles/GemRing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace Jazz2::Actors::Collectibles
for (int i = 0; i < length; i++) {
ChainPiece& piece = _pieces.emplace_back();
piece.Scale = 0.8f;
piece.Command = std::make_unique<RenderCommand>();
piece.Command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
piece.Command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
piece.Command->material().setShaderProgramType(Material::ShaderProgramType::Sprite);
piece.Command->material().setBlendingEnabled(true);
piece.Command->material().reserveUniformsDataMemory();
piece.Command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Environment/SwingingVine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ namespace Jazz2::Actors::Environment
}

for (int i = 0; i < ChunkCount; i++) {
_chunks[i] = std::make_unique<RenderCommand>();
_chunks[i]->material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
_chunks[i] = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
_chunks[i]->material().setShaderProgramType(Material::ShaderProgramType::Sprite);
_chunks[i]->material().setBlendingEnabled(true);
_chunks[i]->material().reserveUniformsDataMemory();
_chunks[i]->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
Expand Down
16 changes: 8 additions & 8 deletions Sources/Jazz2/Actors/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,11 +1042,11 @@ namespace Jazz2::Actors
if (res != nullptr) {
auto& command = _weaponFlareCommand;
if (command == nullptr) {
command = std::make_unique<RenderCommand>();
command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
command->material().setBlendingEnabled(true);
}

if (command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE)) {
if (command->material().setShaderProgramType(Material::ShaderProgramType::Sprite)) {
command->material().reserveUniformsDataMemory();
command->material().setBlendingFactors(GL_SRC_ALPHA, GL_ONE);
//command->material().setBlendingFactors(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Expand Down Expand Up @@ -1135,7 +1135,7 @@ namespace Jazz2::Actors
{
auto& command = _shieldRenderCommands[0];
if (command == nullptr) {
command = std::make_unique<RenderCommand>();
command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
command->material().setBlendingEnabled(true);
}

Expand Down Expand Up @@ -1164,7 +1164,7 @@ namespace Jazz2::Actors
{
auto& command = _shieldRenderCommands[1];
if (command == nullptr) {
command = std::make_unique<RenderCommand>();
command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
command->material().setBlendingEnabled(true);
}

Expand Down Expand Up @@ -1202,11 +1202,11 @@ namespace Jazz2::Actors

auto& command = _shieldRenderCommands[1];
if (command == nullptr) {
command = std::make_unique<RenderCommand>();
command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
command->material().setBlendingEnabled(true);
}

if (command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE)) {
if (command->material().setShaderProgramType(Material::ShaderProgramType::Sprite)) {
command->material().reserveUniformsDataMemory();
command->material().setBlendingFactors(GL_SRC_ALPHA, GL_ONE);
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
Expand Down Expand Up @@ -1266,7 +1266,7 @@ namespace Jazz2::Actors
{
auto& command = _shieldRenderCommands[0];
if (command == nullptr) {
command = std::make_unique<RenderCommand>();
command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
command->material().setBlendingEnabled(true);
}

Expand Down Expand Up @@ -1295,7 +1295,7 @@ namespace Jazz2::Actors
{
auto& command = _shieldRenderCommands[1];
if (command == nullptr) {
command = std::make_unique<RenderCommand>();
command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
command->material().setBlendingEnabled(true);
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Solid/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ namespace Jazz2::Actors::Solid
for (int i = 0; widthCovered <= _bridgeWidth + 4; i++) {
BridgePiece& piece = _pieces.emplace_back();
piece.Pos = Vector2f(_pos.X + widthCovered - 16, _pos.Y);
piece.Command = std::make_unique<RenderCommand>();
piece.Command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
piece.Command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
piece.Command->material().setShaderProgramType(Material::ShaderProgramType::Sprite);
piece.Command->material().setBlendingEnabled(true);
piece.Command->material().reserveUniformsDataMemory();
piece.Command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Solid/MovingPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ namespace Jazz2::Actors::Solid

for (int i = 0; i < length; i++) {
ChainPiece& piece = _pieces.emplace_back();
piece.Command = std::make_unique<RenderCommand>();
piece.Command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
piece.Command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
piece.Command->material().setShaderProgramType(Material::ShaderProgramType::Sprite);
piece.Command->material().setBlendingEnabled(true);
piece.Command->material().reserveUniformsDataMemory();
piece.Command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Solid/SpikeBall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace Jazz2::Actors::Solid

for (int i = 0; i < length; i++) {
ChainPiece& piece = _pieces.emplace_back();
piece.Command = std::make_unique<RenderCommand>();
piece.Command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
piece.Command = std::make_unique<RenderCommand>(RenderCommand::Type::Sprite);
piece.Command->material().setShaderProgramType(Material::ShaderProgramType::Sprite);
piece.Command->material().setBlendingEnabled(true);
piece.Command->material().reserveUniformsDataMemory();
piece.Command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Jazz2/LevelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ namespace Jazz2
_renderCommandsCount++;
return command;
} else {
std::unique_ptr<RenderCommand>& command = _renderCommands.emplace_back(std::make_unique<RenderCommand>());
std::unique_ptr<RenderCommand>& command = _renderCommands.emplace_back(std::make_unique<RenderCommand>(RenderCommand::Type::Lighting));
_renderCommandsCount++;
command->material().setShader(_owner->_lightingShader);
command->material().setBlendingEnabled(true);
Expand Down
9 changes: 5 additions & 4 deletions Sources/Jazz2/Tiles/TileMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ namespace Jazz2::Tiles
}

auto command = RentRenderCommand(layer.Description.RendererType);
command->setType(RenderCommand::CommandTypes::TileMap);
command->setType(RenderCommand::Type::TileMap);
command->material().setBlendingFactors(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Vector2i texSize = tileSet->TextureDiffuse->size();
Expand Down Expand Up @@ -821,7 +821,7 @@ namespace Jazz2::Tiles
bool shaderChanged;
switch (type) {
case LayerRendererType::Tinted: shaderChanged = command->material().setShader(ContentResolver::Get().GetShader(PrecompiledShader::Tinted)); break;
default: shaderChanged = command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE); break;
default: shaderChanged = command->material().setShaderProgramType(Material::ShaderProgramType::Sprite); break;
}
if (shaderChanged) {
command->material().reserveUniformsDataMemory();
Expand Down Expand Up @@ -1287,7 +1287,7 @@ namespace Jazz2::Tiles
}

auto command = RentRenderCommand(LayerRendererType::Default);
command->setType(RenderCommand::CommandTypes::Particle);
command->setType(RenderCommand::Type::Particle);

if ((debris.Flags & DebrisFlags::AdditiveBlending) == DebrisFlags::AdditiveBlending) {
command->material().setBlendingFactors(GL_SRC_ALPHA, GL_ONE);
Expand Down Expand Up @@ -1475,7 +1475,7 @@ namespace Jazz2::Tiles
_renderCommands.reserve(renderCommandCount);
for (std::int32_t i = 0; i < renderCommandCount; i++) {
std::unique_ptr<RenderCommand>& command = _renderCommands.emplace_back(std::make_unique<RenderCommand>());
command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
command->material().setShaderProgramType(Material::ShaderProgramType::Sprite);
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);

Expand All @@ -1486,6 +1486,7 @@ namespace Jazz2::Tiles
}

// Prepare output render command
_outputRenderCommand.setType(RenderCommand::Type::TileMap);
_outputRenderCommand.material().setShader(ContentResolver::Get().GetShader(_owner->_layers[_owner->_texturedBackgroundLayer].Description.RendererType == LayerRendererType::Circle
? PrecompiledShader::TexturedBackgroundCircle
: PrecompiledShader::TexturedBackground));
Expand Down
9 changes: 4 additions & 5 deletions Sources/Jazz2/UI/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Jazz2::UI
void Canvas::DrawTexture(const Texture& texture, const Vector2f& pos, uint16_t z, const Vector2f& size, const Vector4f& texCoords, const Colorf& color, bool additiveBlending, float angle)
{
auto command = RentRenderCommand();
if (command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE)) {
if (command->material().setShaderProgramType(Material::ShaderProgramType::Sprite)) {
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
// Required to reset render command properly
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace Jazz2::UI
void Canvas::DrawSolid(const Vector2f& pos, uint16_t z, const Vector2f& size, const Colorf& color, bool additiveBlending)
{
auto command = RentRenderCommand();
if (command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE_NO_TEXTURE)) {
if (command->material().setShaderProgramType(Material::ShaderProgramType::SpriteNoTexture)) {
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
// Required to reset render command properly
Expand Down Expand Up @@ -119,12 +119,11 @@ namespace Jazz2::UI
{
if (_renderCommandsCount < _renderCommands.size()) {
RenderCommand* command = _renderCommands[_renderCommandsCount].get();
command->setType(RenderCommand::CommandTypes::Sprite);
command->setType(RenderCommand::Type::Sprite);
_renderCommandsCount++;
return command;
} else {
std::unique_ptr<RenderCommand>& command = _renderCommands.emplace_back(std::make_unique<RenderCommand>());
command->setType(RenderCommand::CommandTypes::Sprite);
std::unique_ptr<RenderCommand>& command = _renderCommands.emplace_back(std::make_unique<RenderCommand>(RenderCommand::Type::Sprite));
command->material().setBlendingEnabled(true);
_renderCommandsCount++;
return command.get();
Expand Down
3 changes: 2 additions & 1 deletion Sources/Jazz2/UI/Cinematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ namespace Jazz2::UI
void Cinematics::CinematicsCanvas::Initialize()
{
// Prepare output render command
_renderCommand.material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
_renderCommand.setType(RenderCommand::Type::Sprite);
_renderCommand.material().setShaderProgramType(Material::ShaderProgramType::Sprite);
_renderCommand.material().reserveUniformsDataMemory();
_renderCommand.geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);

Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/UI/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ namespace Jazz2::UI
);

auto command = canvas->RentRenderCommand();
command->setType(RenderCommand::CommandTypes::Text);
command->setType(RenderCommand::Type::Text);
bool shaderChanged = (colorizeShader
? command->material().setShader(colorizeShader)
: command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE));
: command->material().setShaderProgramType(Material::ShaderProgramType::Sprite));
if (shaderChanged) {
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/UI/HUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,11 +1186,11 @@ namespace Jazz2::UI
command = _weaponWheelRenderCommands[_weaponWheelRenderCommandsCount].get();
_weaponWheelRenderCommandsCount++;
} else {
command = _weaponWheelRenderCommands.emplace_back(std::make_unique<RenderCommand>()).get();
command = _weaponWheelRenderCommands.emplace_back(std::make_unique<RenderCommand>(RenderCommand::Type::MeshSprite)).get();
command->material().setBlendingEnabled(true);
}

if (command->material().setShaderProgramType(Material::ShaderProgramType::MESH_SPRITE)) {
if (command->material().setShaderProgramType(Material::ShaderProgramType::MeshSprite)) {
command->material().reserveUniformsDataMemory();

GLUniformCache* textureUniform = command->material().uniform(Material::TextureUniformName);
Expand Down
16 changes: 10 additions & 6 deletions Sources/Jazz2/UI/Menu/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ namespace Jazz2::UI::Menu
{
for (auto& debris : _debrisList) {
auto command = _canvasOverlay->RentRenderCommand();
if (command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE)) {
command->setType(RenderCommand::Type::Particle);
if (command->material().setShaderProgramType(Material::ShaderProgramType::Sprite)) {
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
// Required to reset render command properly
Expand Down Expand Up @@ -872,7 +873,8 @@ namespace Jazz2::UI::Menu
Vector2f size = base->FrameDimensions.As<float>() * scale;

auto command = _canvasBackground->RentRenderCommand();
if (command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE)) {
command->setType(RenderCommand::Type::TileMap);
if (command->material().setShaderProgramType(Material::ShaderProgramType::Sprite)) {
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
// Required to reset render command properly
Expand Down Expand Up @@ -917,7 +919,8 @@ namespace Jazz2::UI::Menu
centerBg.Y += 96.0f * cosf(animTime * 0.31f);

auto command = _canvasBackground->RentRenderCommand();
if (command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE)) {
command->setType(RenderCommand::Type::TileMap);
if (command->material().setShaderProgramType(Material::ShaderProgramType::Sprite)) {
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
// Required to reset render command properly
Expand Down Expand Up @@ -962,7 +965,8 @@ namespace Jazz2::UI::Menu
centerBg.Y += 64.0f * cosf(animTime * 0.32f);

auto command = _canvasBackground->RentRenderCommand();
if (command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE)) {
command->setType(RenderCommand::Type::TileMap);
if (command->material().setShaderProgramType(Material::ShaderProgramType::Sprite)) {
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);
// Required to reset render command properly
Expand Down Expand Up @@ -1021,8 +1025,8 @@ namespace Jazz2::UI::Menu
int32_t renderCommandCount = (width * height) / (TileSet::DefaultTileSize * TileSet::DefaultTileSize);
_renderCommands.reserve(renderCommandCount);
for (int32_t i = 0; i < renderCommandCount; i++) {
std::unique_ptr<RenderCommand>& command = _renderCommands.emplace_back(std::make_unique<RenderCommand>());
command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
std::unique_ptr<RenderCommand>& command = _renderCommands.emplace_back(std::make_unique<RenderCommand>(RenderCommand::Type::TileMap));
command->material().setShaderProgramType(Material::ShaderProgramType::Sprite);
command->material().reserveUniformsDataMemory();
command->geometry().setDrawParameters(GL_TRIANGLE_STRIP, 0, 4);

Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/UI/UpscaleRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ namespace Jazz2::UI

bool shaderChanged = (_resizeShader != nullptr
? _renderCommand.material().setShader(_resizeShader)
: _renderCommand.material().setShaderProgramType(Material::ShaderProgramType::SPRITE));
: _renderCommand.material().setShaderProgramType(Material::ShaderProgramType::Sprite));
#else
bool shaderChanged = _renderCommand.material().setShaderProgramType(Material::ShaderProgramType::SPRITE);
bool shaderChanged = _renderCommand.material().setShaderProgramType(Material::ShaderProgramType::Sprite);
#endif
if (shaderChanged) {
_renderCommand.material().reserveUniformsDataMemory();
Expand Down
3 changes: 2 additions & 1 deletion Sources/Resources.rc
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ VS_VERSION_INFO VERSIONINFO
}

GLFW_ICON ICON ".\\Icons\\Main.ico"
LOG_ICON ICON ".\\Icons\\Log.ico"
WINDOW_ICON ICON ".\\Icons\\Window.ico"
IMGUI_ICON ICON ".\\Icons\\WindowImGui.ico"
Loading

0 comments on commit 97dd38d

Please sign in to comment.