generated from asmaloney/GDExtensionTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
443 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "extern/godot-cpp"] | ||
path = extern/godot-cpp | ||
url = https://github.com/godotengine/godot-cpp.git | ||
[submodule "extern/DirectXTex"] | ||
path = extern/DirectXTex | ||
url = https://github.com/microsoft/DirectXTex.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
namespace SWBF2 | ||
{ | ||
typedef uint32_t FNVHash; | ||
|
||
constexpr FNVHash FNVGenerateHash(const std::string &str) | ||
{ | ||
constexpr uint32_t FNV_prime = 16777619; | ||
constexpr uint32_t offset_basis = 2166136261; | ||
|
||
uint32_t hash = offset_basis; | ||
|
||
const char *buffer = str.data(); | ||
for (size_t i = 0; i < str.length(); ++i) | ||
{ | ||
char c = buffer[i]; | ||
c |= 0x20; | ||
|
||
hash ^= c; | ||
hash *= FNV_prime; | ||
} | ||
|
||
return hash; | ||
} | ||
|
||
constexpr FNVHash operator""_fnv(const char *str, const std::size_t length) | ||
{ | ||
return FNVGenerateHash({ str, length }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <godot_cpp/variant/utility_functions.hpp> | ||
|
||
#include "Native/Chunks/StreamReader.hpp" | ||
#include "Native/Chunks/TextureChunk.hpp" | ||
|
||
#include "Native/Texture/TextureUtils.hpp" | ||
#include "Native/Level.hpp" | ||
|
||
namespace SWBF2::Native | ||
{ | ||
void TextureChunk::ProcessChunk(StreamReader &streamReader) | ||
{ | ||
std::unique_ptr<Texture> tex = std::make_unique<Texture>(); | ||
|
||
auto texNameReaderChild = streamReader.ReadChildWithHeader<"NAME"_m>(); | ||
{ | ||
*texNameReaderChild >> tex->m_name; | ||
} | ||
|
||
auto infoReaderChild = streamReader.ReadChildWithHeader<"INFO"_m>(); | ||
{ | ||
*infoReaderChild >> tex->m_formatCount; | ||
|
||
tex->m_d3dFormats.resize(tex->m_formatCount); | ||
*infoReaderChild >> tex->m_d3dFormats; | ||
|
||
std::optional<StreamReader> fmtReaderChild; | ||
while ((fmtReaderChild = streamReader.ReadChild()).has_value()) | ||
{ | ||
switch (fmtReaderChild->GetHeader().m_Magic) | ||
{ | ||
case "FMT_"_m: { | ||
StreamReader r{ *fmtReaderChild }; | ||
TextureChunk::ProcessFMTChunk(r, tex.get()); | ||
break; | ||
} | ||
|
||
default: | ||
godot::UtilityFunctions::printerr(__FILE__, ":", __LINE__, ": ", fmtReaderChild->GetHeader().ToString().c_str(), " not implemented"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
Level::m_tex.try_emplace(tex->m_name, std::move(tex)); | ||
} | ||
|
||
void TextureChunk::ProcessFMTChunk(StreamReader &streamReader, Texture *tex) | ||
{ | ||
auto infoReaderChild = streamReader.ReadChildWithHeader<"INFO"_m>(); | ||
|
||
auto &fmt = tex->m_formats.emplace_back(TextureFormat()); | ||
{ | ||
*infoReaderChild >> fmt.m_format; | ||
*infoReaderChild >> fmt.m_width; | ||
*infoReaderChild >> fmt.m_height; | ||
*infoReaderChild >> fmt.m_depth; | ||
*infoReaderChild >> fmt.m_mipmapCount; | ||
*infoReaderChild >> fmt.m_typeDetailBias; | ||
} | ||
|
||
auto faceReaderChild = streamReader.ReadChildWithHeader<"FACE"_m>(); | ||
{ | ||
std::optional<StreamReader> lvlReaderChild; | ||
while ((lvlReaderChild = faceReaderChild->ReadChild()).has_value()) | ||
{ | ||
switch (lvlReaderChild->GetHeader().m_Magic) | ||
{ | ||
case "LVL_"_m: { | ||
StreamReader r{ *lvlReaderChild }; | ||
TextureChunk::ProcessTextureLevelChunk(r, fmt); | ||
break; | ||
} | ||
|
||
default: | ||
godot::UtilityFunctions::printerr(__FILE__, ":", __LINE__, ": ", lvlReaderChild->GetHeader().ToString().c_str(), " not implemented"); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void TextureChunk::ProcessTextureLevelChunk(StreamReader &streamReader, TextureFormat &fmt) | ||
{ | ||
TextureFormatFaceLevel lvl; | ||
|
||
auto infoReaderChild = streamReader.ReadChildWithHeader<"INFO"_m>(); | ||
{ | ||
*infoReaderChild >> lvl.m_mipLevel; | ||
*infoReaderChild >> lvl.m_bodySize; | ||
} | ||
|
||
auto bodyReaderChild = streamReader.ReadChildWithHeader<"BODY"_m>(); | ||
{ | ||
lvl.m_imageInBytes.resize(lvl.m_bodySize); | ||
|
||
*bodyReaderChild >> lvl.m_imageInBytes; | ||
} | ||
|
||
if (TextureUtils::IsD3DFormatSupported(fmt.m_format)) | ||
{ | ||
godot::PackedByteArray imageBuf; | ||
imageBuf.resize(lvl.m_bodySize); | ||
std::copy(lvl.m_imageInBytes.begin(), lvl.m_imageInBytes.end(), (std::byte *)imageBuf.ptrw()); | ||
godot::Ref<godot::Image> image{ godot::Image::create_from_data(fmt.m_width, fmt.m_height, fmt.m_mipmapCount > 1, TextureUtils::D3DToGLFormat(fmt.m_format), imageBuf) }; | ||
|
||
lvl.m_gdImageTexture.instantiate(); | ||
lvl.m_gdImageTexture->create_from_image(image); | ||
} | ||
|
||
fmt.m_faceLevels.push_back(lvl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "Native/Chunks/StreamReader.hpp" | ||
|
||
#include "Native/Texture/Texture.hpp" | ||
|
||
namespace SWBF2::Native | ||
{ | ||
class TextureChunk { | ||
public: | ||
static void ProcessChunk(StreamReader &streamReader); | ||
static void ProcessFMTChunk(StreamReader &streamReader, Texture *tex); | ||
static void ProcessTextureLevelChunk(StreamReader &streamReader, TextureFormat &fmt); | ||
}; | ||
|
||
} |
Oops, something went wrong.