Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Game/assets/textures/block_atlas.png
Binary file not shown.
156 changes: 0 additions & 156 deletions Game/assets/textures/generate_atlas.py

This file was deleted.

12 changes: 6 additions & 6 deletions Game/include/World/TextureAtlas.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef _TEXTURE_ATLAS_HPP_
#define _TEXTURE_ATLAS_HPP_

#include <Memory/RefPtr.hpp>
#include <Runtime/Texture.hpp>
#include <cstdint>
#include <vector>
#include <string>

namespace Sleak { class Texture; }
#include <vector>

/// UV rectangle for one atlas tile's content, inside its gutter-padded cell.
struct AtlasUV {
Expand All @@ -21,9 +21,9 @@ class TextureAtlas {
public:
static constexpr int TILES_PER_ROW = 4;

/// Loads every block texture (in BlockTile enum order, must match),
/// resamples each to a common tile size, and packs them into one atlas.
static Sleak::Texture* BuildAtlas();
/// Loads every block texture in BlockTile order, packs the gutter-padded
/// atlas and uploads it with its mip chain; null if the upload fails.
static Sleak::RefPtr<Sleak::Texture> BuildAtlas();

/// UVs address the tile content inside its gutter-padded cell.
static AtlasUV GetTileUV(uint8_t tileIndex) {
Expand Down
23 changes: 8 additions & 15 deletions Game/src/MainScene.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "MainScene.hpp"

#include <Events/Event.hpp>
#include <Input/KeyCodes.hpp>

#include <Camera/Camera.hpp>
#include <Core/Application.hpp>
#include <Core/CommandLine.hpp>
#include <Core/GameObject.hpp>
#include <Core/Logger.hpp>
#include <Culling/CullingSystem.hpp>
#include <ECS/Components/FirstPersonController.hpp>
#include <Events/Event.hpp>
#include <Input/KeyCodes.hpp>
#include <Lighting/DirectionalLight.hpp>
#include <Lighting/LightManager.hpp>
#include <Math/Vector.hpp>
Expand Down Expand Up @@ -347,16 +347,14 @@ void MainScene::SetupMaterial() {
Sleak::TextureFilter texFilter = m_settingsPanel.GetTextureFilter();

// Build runtime atlas from individual block textures
auto* atlasTex = TextureAtlas::BuildAtlas();
if (atlasTex) {
RefPtr<Texture> atlasTex = TextureAtlas::BuildAtlas();
if (atlasTex.IsValid()) {
atlasTex->SetFilter(texFilter);
atlasTex->SetWrapMode(TextureWrapMode::ClampToEdge);
mat->SetDiffuseTexture(atlasTex);
} else {
// Fallback to old atlas file
mat->SetDiffuseTexture("assets/textures/block_atlas.png");
mat->GetDiffuseTexture()->SetFilter(texFilter);
mat->GetDiffuseTexture()->SetWrapMode(TextureWrapMode::ClampToEdge);
SLEAK_ERROR(
"Block atlas could not be created; terrain renders untextured");
}
mat->SetDiffuseColor((uint8_t)255, (uint8_t)255, (uint8_t)255);
mat->SetSpecularColor((uint8_t)0, (uint8_t)0, (uint8_t)0);
Expand All @@ -371,12 +369,7 @@ void MainScene::SetupMaterial() {
// Water material
auto* waterMat = new Material();
waterMat->SetShader("assets/shaders/water_shader.hlsl");
auto* waterAtlasTex = TextureAtlas::BuildAtlas();
if (waterAtlasTex) {
waterAtlasTex->SetFilter(texFilter);
waterAtlasTex->SetWrapMode(TextureWrapMode::ClampToEdge);
waterMat->SetDiffuseTexture(waterAtlasTex);
}
if (atlasTex.IsValid()) waterMat->SetDiffuseTexture(atlasTex);
waterMat->SetDiffuseColor((uint8_t)255, (uint8_t)255, (uint8_t)255);
waterMat->SetOpacity(0.7f);
waterMat->SetRenderMode(MaterialRenderMode::Transparent);
Expand Down
10 changes: 8 additions & 2 deletions Game/src/World/TextureAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void ResampleNearest(const unsigned char* src, int srcW, int srcH,
}
}

Texture* TextureAtlas::BuildAtlas() {
Sleak::RefPtr<Sleak::Texture> TextureAtlas::BuildAtlas() {
constexpr int tileCount = TILE_COUNT;
s_rows = (tileCount + TILES_PER_ROW - 1) / TILES_PER_ROW;

Expand Down Expand Up @@ -125,5 +125,11 @@ Texture* TextureAtlas::BuildAtlas() {
// Cap mips so the gutter stays >=1px at the deepest level
uint32_t maxMips = 1;
for (int p = pad; p > 1; p >>= 1) ++maxMips;
return CreateTextureFromPixels(atlasW, atlasH, atlas.data(), maxMips);

Sleak::TextureDesc desc;
desc.width = static_cast<uint32_t>(atlasW);
desc.height = static_cast<uint32_t>(atlasH);
desc.mipLevels = maxMips;
const Sleak::TextureMipLevel level0{atlas.data(), atlas.size()};
return Sleak::CreateTexture(desc, &level0, 1);
}
Loading