Initialize shared Metin2 SDK with rendering optimizations and tests
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace metin2::texture {
|
||||
|
||||
class DxtDecoder {
|
||||
public:
|
||||
static bool DecompressDXT1(const uint8_t* src, uint32_t width, uint32_t height, uint8_t* dst_rgba);
|
||||
static bool DecompressDXT3(const uint8_t* src, uint32_t width, uint32_t height, uint8_t* dst_rgba);
|
||||
static bool DecompressDXT5(const uint8_t* src, uint32_t width, uint32_t height, uint8_t* dst_rgba);
|
||||
|
||||
// Parse complete DDS file header (Magic 'DDS ', DDS_HEADER, pixel format) and decode to RGBA8888
|
||||
static bool DecodeDDS(const uint8_t* dds_data, size_t size, ImageBuffer& out_image);
|
||||
};
|
||||
|
||||
} // namespace metin2::texture
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include <string>
|
||||
|
||||
namespace metin2::texture {
|
||||
|
||||
class SubImage {
|
||||
public:
|
||||
SubImage() = default;
|
||||
~SubImage() = default;
|
||||
|
||||
bool LoadFromString(const std::string& content);
|
||||
bool LoadFromFile(const std::string& file_path);
|
||||
|
||||
const std::string& GetImagePath() const { return m_image_path; }
|
||||
const Rect2D& GetRect() const { return m_rect; }
|
||||
int32_t GetWidth() const { return m_rect.GetWidth(); }
|
||||
int32_t GetHeight() const { return m_rect.GetHeight(); }
|
||||
|
||||
UVRect ComputeUV(uint32_t atlas_width, uint32_t atlas_height) const;
|
||||
|
||||
// Generate 9-Slice mesh for UI window / button rendering
|
||||
NineSliceMesh BuildNineSliceMesh(float x, float y, float width, float height,
|
||||
float border_l, float border_t, float border_r, float border_b,
|
||||
uint32_t atlas_width, uint32_t atlas_height,
|
||||
uint32_t color = 0xFFFFFFFF) const;
|
||||
|
||||
private:
|
||||
std::string m_image_path;
|
||||
Rect2D m_rect;
|
||||
};
|
||||
|
||||
} // namespace metin2::texture
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "dxt.h"
|
||||
#include "tga.h"
|
||||
#include "sub_image.h"
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace metin2::texture {
|
||||
|
||||
class TgaDecoder {
|
||||
public:
|
||||
// Decodes uncompressed and RLE-compressed 24-bit/32-bit TGA to RGBA8888
|
||||
static bool DecodeTGA(const uint8_t* tga_data, size_t size, ImageBuffer& out_image);
|
||||
};
|
||||
|
||||
} // namespace metin2::texture
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace metin2::texture {
|
||||
|
||||
enum class EPixelFormat {
|
||||
Unknown = 0,
|
||||
RGBA8888,
|
||||
RGB888,
|
||||
DXT1,
|
||||
DXT3,
|
||||
DXT5,
|
||||
BGRA8888
|
||||
};
|
||||
|
||||
struct ImageBuffer {
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
EPixelFormat format = EPixelFormat::RGBA8888;
|
||||
std::vector<uint8_t> pixels;
|
||||
|
||||
bool IsValid() const { return width > 0 && height > 0 && !pixels.empty(); }
|
||||
};
|
||||
|
||||
struct Rect2D {
|
||||
int32_t left = 0;
|
||||
int32_t top = 0;
|
||||
int32_t right = 0;
|
||||
int32_t bottom = 0;
|
||||
|
||||
int32_t GetWidth() const { return right - left; }
|
||||
int32_t GetHeight() const { return bottom - top; }
|
||||
};
|
||||
|
||||
struct UVRect {
|
||||
float u0 = 0.0f;
|
||||
float v0 = 0.0f;
|
||||
float u1 = 1.0f;
|
||||
float v1 = 1.0f;
|
||||
};
|
||||
|
||||
struct NineSliceVertex {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float u = 0.0f;
|
||||
float v = 0.0f;
|
||||
uint32_t color = 0xFFFFFFFF;
|
||||
};
|
||||
|
||||
struct NineSliceMesh {
|
||||
std::vector<NineSliceVertex> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
};
|
||||
|
||||
} // namespace metin2::texture
|
||||
Reference in New Issue
Block a user