Skip to content

Commit

Permalink
world render mode switch
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-h committed Feb 26, 2022
1 parent 2384a43 commit 4b28a39
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
29 changes: 22 additions & 7 deletions src/MapWindow/MapWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ Satisfactory3DMap::MapWindow::MapWindow()
samplingFactorItem_(4),
metallic_(0.0f),
roughness_(0.5f),
worldRenderMode_(WorldRenderMode::TileMap),
showSelectionMarker_(false),
showHexEdit_(false) {

dataView_ = std::make_shared<DataView>();
pakExplorer_ = std::make_unique<PakExplorer>(dataView_);

// Fallback to HeightMap if no pak file is found.
if (dataView_->pak() == nullptr) {
worldRenderMode_ = WorldRenderMode::HeightMap;
}

fbo_ = std::make_unique<glowl::FramebufferObject>(10, 10, glowl::FramebufferObject::DEPTH32F);
fbo_->createColorAttachment(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE); // color
fbo_->createColorAttachment(GL_RGBA32F, GL_RGBA, GL_FLOAT); // normals
Expand Down Expand Up @@ -237,12 +243,18 @@ void Satisfactory3DMap::MapWindow::renderGui() {
samplingFactor_ = sampling_values[samplingFactorItem_];
ImGui::SliderFloat("Metalic", &metallic_, 0.0f, 1.0f);
ImGui::SliderFloat("Roughness", &roughness_, 0.0f, 1.0f);
ImGui::Checkbox("Use world tex", &worldRenderer_->useWorldTex());
ImGui::Checkbox("Show world", &worldRenderer_->show());
ImGui::Checkbox("Show TileMap", &mapTileRenderer_->show());
ImGui::Checkbox("World wireframe", &worldRenderer_->wireframe());
ImGui::Separator();
const char* world_mode_names[] = {"None", "HeightMap", "TileMap"};
ImGui::Combo("World Mode", reinterpret_cast<int*>(&worldRenderMode_), world_mode_names,
IM_ARRAYSIZE(world_mode_names));
if (worldRenderMode_ == WorldRenderMode::HeightMap) {
ImGui::Checkbox("Use world tex", &worldRenderer_->useWorldTex());
ImGui::Checkbox("World wireframe", &worldRenderer_->wireframe());
} else if (worldRenderMode_ == WorldRenderMode::TileMap) {
ImGui::Checkbox("Tile wireframe", &mapTileRenderer_->wireframe());
}
ImGui::Separator();
ImGui::Checkbox("Models wireframe", &modelRenderer_->wireframe());
ImGui::Checkbox("Tile wireframe", &mapTileRenderer_->wireframe());
ImGui::End();

ImGui::Begin("SaveObject");
Expand Down Expand Up @@ -423,8 +435,11 @@ void Satisfactory3DMap::MapWindow::renderFbo() {
glClearTexImage(fbo_->getColorAttachment(1)->getName(), 0, GL_RGBA, GL_FLOAT, clearColor1);
glClearTexImage(fbo_->getColorAttachment(2)->getName(), 0, GL_RED_INTEGER, GL_INT, clearColor2);

worldRenderer_->render(projMx_, camera_->viewMx());
mapTileRenderer_->render(projMx_, camera_->viewMx());
if (worldRenderMode_ == WorldRenderMode::HeightMap) {
worldRenderer_->render(projMx_, camera_->viewMx());
} else if (worldRenderMode_ == WorldRenderMode::TileMap) {
mapTileRenderer_->render(projMx_, camera_->viewMx());
}

if (dataView_->hasSave()) {
modelRenderer_->render(projMx_, camera_->viewMx(), dataView_->selectedObjectId());
Expand Down
9 changes: 8 additions & 1 deletion src/MapWindow/MapWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ namespace Satisfactory3DMap {
MapWindow();
~MapWindow();

const std::shared_ptr<DataView>& dataView() const {
[[nodiscard]] const std::shared_ptr<DataView>& dataView() const {
return dataView_;
}

protected:
enum WorldRenderMode : int {
None = 0,
HeightMap = 1,
TileMap = 2,
};

void render() override;
void renderTick();
void renderGui();
Expand Down Expand Up @@ -93,6 +99,7 @@ namespace Satisfactory3DMap {
int samplingFactorItem_;
float metallic_;
float roughness_;
WorldRenderMode worldRenderMode_;

std::unique_ptr<GltfModel> selectionMarkerModel_;
std::unique_ptr<glowl::GLSLProgram> selectionMarkerShader_;
Expand Down
8 changes: 1 addition & 7 deletions src/MapWindow/World/MapTileRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ namespace {
}
} // namespace

Satisfactory3DMap::MapTileRenderer::MapTileRenderer(const std::shared_ptr<PakFile>& pak)
: wireframe_(false),
show_(true) {
Satisfactory3DMap::MapTileRenderer::MapTileRenderer(const std::shared_ptr<PakFile>& pak) : wireframe_(false) {

const std::vector<float> x = {
-254000.0f,
Expand Down Expand Up @@ -141,10 +139,6 @@ Satisfactory3DMap::MapTileRenderer::MapTileRenderer(const std::shared_ptr<PakFil
}

void Satisfactory3DMap::MapTileRenderer::render(const glm::mat4& projMx, const glm::mat4& viewMx) {
if (!show_) {
return;
}

if (wireframe_) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDisable(GL_CULL_FACE);
Expand Down
5 changes: 0 additions & 5 deletions src/MapWindow/World/MapTileRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ namespace Satisfactory3DMap {
return wireframe_;
};

bool& show() {
return show_;
}

protected:
struct MapTileInfo {
std::string filename;
Expand All @@ -49,7 +45,6 @@ namespace Satisfactory3DMap {
std::vector<MapTileData> mapTiles_;

bool wireframe_;
bool show_;
};
} // namespace Satisfactory3DMap

Expand Down
7 changes: 1 addition & 6 deletions src/MapWindow/World/WorldRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ Satisfactory3DMap::WorldRenderer::WorldRenderer()
numInstancesX_(16),
numInstancesY_(16),
useWorldTex_(true),
wireframe_(false),
show_(true) {
wireframe_(false) {
try {
shader_ = std::make_unique<glowl::GLSLProgram>(glowl::GLSLProgram::ShaderSourceList{
{glowl::GLSLProgram::ShaderType::Vertex, getStringResource("shaders/world.vert")},
Expand Down Expand Up @@ -65,10 +64,6 @@ Satisfactory3DMap::WorldRenderer::WorldRenderer()
}

void Satisfactory3DMap::WorldRenderer::render(const glm::mat4& projMx, const glm::mat4& viewMx) {
if (!show_) {
return;
}

if (wireframe_) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
Expand Down
5 changes: 0 additions & 5 deletions src/MapWindow/World/WorldRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ namespace Satisfactory3DMap {
return wireframe_;
};

bool& show() {
return show_;
}

protected:
std::unique_ptr<glowl::GLSLProgram> shader_;
GLuint vaEmpty_;
Expand All @@ -47,7 +43,6 @@ namespace Satisfactory3DMap {

bool useWorldTex_;
bool wireframe_;
bool show_;
};
} // namespace Satisfactory3DMap

Expand Down

0 comments on commit 4b28a39

Please sign in to comment.