Add PD::Image and add a setter for logfilter
This commit is contained in:
+13
-1
@@ -12,6 +12,7 @@ include(cmake/palladium.cmake)
|
|||||||
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
|
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
|
||||||
option(PD_BUILD_SHARED "Build Shared Library" OFF)
|
option(PD_BUILD_SHARED "Build Shared Library" OFF)
|
||||||
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
|
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
|
||||||
|
option(PD_INCLUDE_STB_IMAGE "Inlude stb image symbols in palladium" ON)
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||||
add_compile_options(-Wno-psabi)
|
add_compile_options(-Wno-psabi)
|
||||||
@@ -37,6 +38,9 @@ set(PD_SOURCES
|
|||||||
source/core/timer.cpp
|
source/core/timer.cpp
|
||||||
source/core/timetrace.cpp
|
source/core/timetrace.cpp
|
||||||
|
|
||||||
|
# Image
|
||||||
|
source/image/image.cpp
|
||||||
|
|
||||||
# Drivers
|
# Drivers
|
||||||
source/drivers/os.cpp
|
source/drivers/os.cpp
|
||||||
source/drivers/gfx.cpp
|
source/drivers/gfx.cpp
|
||||||
@@ -55,7 +59,15 @@ else()
|
|||||||
target_compile_definitions(palladium PUBLIC PD_BUILD_STATIC)
|
target_compile_definitions(palladium PUBLIC PD_BUILD_STATIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(palladium PUBLIC PD_DEBUG)
|
target_link_libraries(palladium
|
||||||
|
PUBLIC stb
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(palladium
|
||||||
|
PUBLIC
|
||||||
|
PD_DEBUG
|
||||||
|
$<$<OR:$<BOOL:${PD_INCLUDE_STB_IMAGE}>,$<BOOL:${PD_BUILD_SHARED}>>:PD_INCLUDE_STB_IMAGE> # Always on in shared build
|
||||||
|
)
|
||||||
target_compile_options(palladium
|
target_compile_options(palladium
|
||||||
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
|
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
|
||||||
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/source=source
|
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/source=source
|
||||||
|
|||||||
@@ -25,4 +25,5 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include <pd/core/core.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/drivers/drivers.hpp>
|
#include <pd/drivers/drivers.hpp>
|
||||||
|
#include <pd/image/image.hpp>
|
||||||
#include <pd/lithium/lithium.hpp>
|
#include <pd/lithium/lithium.hpp>
|
||||||
@@ -44,6 +44,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
enum class LogLevel {
|
enum class LogLevel {
|
||||||
|
None,
|
||||||
Info,
|
Info,
|
||||||
Warning,
|
Warning,
|
||||||
Error,
|
Error,
|
||||||
@@ -56,6 +57,7 @@ using u16 = unsigned short;
|
|||||||
using u32 = unsigned int;
|
using u32 = unsigned int;
|
||||||
using u64 = unsigned long long;
|
using u64 = unsigned long long;
|
||||||
using ptr = uintptr_t;
|
using ptr = uintptr_t;
|
||||||
|
PD_API void LogFilter(LogLevel minimum);
|
||||||
PD_API void Log(const std::string& txt, LogLevel lvl = LogLevel::Info);
|
PD_API void Log(const std::string& txt, LogLevel lvl = LogLevel::Info);
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void Log(std::format_string<Args...> fmt, Args&&... args) {
|
void Log(std::format_string<Args...> fmt, Args&&... args) {
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
class PD_API Image {
|
||||||
|
public:
|
||||||
|
enum class Format {
|
||||||
|
RGBA, // bpp == 4
|
||||||
|
RGB, // bpp == 3
|
||||||
|
RGB565, // bpp == 2 (not supported in laoding)
|
||||||
|
BGR, // bpp == 3
|
||||||
|
ABGR, // bpp == 4
|
||||||
|
BGRA, // bpp == 4
|
||||||
|
};
|
||||||
|
Image();
|
||||||
|
Image(const std::string& path);
|
||||||
|
Image(const std::vector<u8>& buf);
|
||||||
|
Image(const std::vector<u8>& pixels, int w, int h, int bpp = 4);
|
||||||
|
~Image();
|
||||||
|
|
||||||
|
void Load(const std::string& path);
|
||||||
|
void Load(const std::vector<u8>& buf);
|
||||||
|
void Load(const u8* buf, size_t size);
|
||||||
|
void Copy(const std::vector<u8>& pixels, int w, int h, int bpp = 4);
|
||||||
|
|
||||||
|
const int& Width() const { return pSize.x; }
|
||||||
|
const int& Height() const { return pSize.x; }
|
||||||
|
const ivec2& Size() const { return pSize; }
|
||||||
|
|
||||||
|
const std::vector<u8>& data() const { return pData; }
|
||||||
|
std::vector<u8>& data() { return pData; }
|
||||||
|
operator const std::vector<u8>&() const { return pData; }
|
||||||
|
operator std::vector<u8>&() { return pData; }
|
||||||
|
operator const ivec2&() const { return pSize; }
|
||||||
|
operator const Format&() const { return pFormat; }
|
||||||
|
|
||||||
|
void Flip(bool horizontal = true, bool vertical = true);
|
||||||
|
|
||||||
|
static int Format2Bpp(Format fmt);
|
||||||
|
static Format GuessFmtFromBpp(int bpp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<u8> pData;
|
||||||
|
ivec2 pSize;
|
||||||
|
Format pFormat = Format::RGBA;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
||||||
@@ -6,6 +6,11 @@ constexpr const char* pColorNo = "\033[0m";
|
|||||||
constexpr const char* pColorYellow = "\033[33m";
|
constexpr const char* pColorYellow = "\033[33m";
|
||||||
constexpr const char* pColorRed = "\033[31m";
|
constexpr const char* pColorRed = "\033[31m";
|
||||||
static LogLevel pFilter = LogLevel::Info;
|
static LogLevel pFilter = LogLevel::Info;
|
||||||
|
|
||||||
|
PD_API void LogFilter(LogLevel lvl) {
|
||||||
|
pFilter = lvl;
|
||||||
|
}
|
||||||
|
|
||||||
PD_API void Log(const std::string& txt, LogLevel lvl) {
|
PD_API void Log(const std::string& txt, LogLevel lvl) {
|
||||||
if ((int)lvl < (int)pFilter) return;
|
if ((int)lvl < (int)pFilter) return;
|
||||||
const char* clr = pColorNo;
|
const char* clr = pColorNo;
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#include <pd/image/image.hpp>
|
||||||
|
|
||||||
|
#if defined(PD_INCLUDE_STB_IMAGE)
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#endif
|
||||||
|
#include <stb_image.h>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
PD_API Image::Image() {}
|
||||||
|
|
||||||
|
PD_API Image::Image(const std::string& path) { Load(path); }
|
||||||
|
|
||||||
|
PD_API Image::Image(const std::vector<u8>& buf) { Load(buf); }
|
||||||
|
|
||||||
|
PD_API Image::Image(const std::vector<u8>& pixels, int w, int h, int bpp) {
|
||||||
|
Copy(pixels, w, h, bpp);
|
||||||
|
}
|
||||||
|
|
||||||
|
PD_API Image::~Image() {}
|
||||||
|
|
||||||
|
PD_API void Image::Load(const u8* buf, size_t size) {
|
||||||
|
int w = 0, h = 0, c = 0;
|
||||||
|
u8* img = stbi_load_from_memory(buf, size, &w, &h, &c, 4);
|
||||||
|
if (c == 3) {
|
||||||
|
stbi_image_free(img);
|
||||||
|
img = stbi_load_from_memory(buf, size, &w, &h, &c, 3);
|
||||||
|
pFormat = Format::RGB;
|
||||||
|
}
|
||||||
|
pData.assign(img, img + (w * h * c));
|
||||||
|
pSize = ivec2(w, h);
|
||||||
|
stbi_image_free(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
PD_API void Image::Load(const std::string& path) {
|
||||||
|
int w = 0, h = 0, c = 0;
|
||||||
|
u8* img = stbi_load(path.c_str(), &w, &h, &c, 4);
|
||||||
|
if (c == 3) {
|
||||||
|
stbi_image_free(img);
|
||||||
|
img = stbi_load(path.c_str(), &w, &h, &c, 3);
|
||||||
|
pFormat = Format::RGB;
|
||||||
|
}
|
||||||
|
pData.assign(img, img + (w * h * c));
|
||||||
|
pSize = ivec2(w, h);
|
||||||
|
stbi_image_free(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
PD_API void Image::Load(const std::vector<u8>& buf) {
|
||||||
|
Load(buf.data(), buf.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
PD_API void Image::Copy(const std::vector<u8>& pixels, int w, int h, int bpp) {
|
||||||
|
pData = pixels;
|
||||||
|
pSize = ivec2(w, h);
|
||||||
|
pFormat = GuessFmtFromBpp(bpp);
|
||||||
|
}
|
||||||
|
|
||||||
|
PD_API int Image::Format2Bpp(Format fmt) {
|
||||||
|
switch (fmt) {
|
||||||
|
case Format::RGBA:
|
||||||
|
case Format::ABGR:
|
||||||
|
case Format::BGRA:
|
||||||
|
return 4;
|
||||||
|
case Format::BGR:
|
||||||
|
case Format::RGB:
|
||||||
|
return 3;
|
||||||
|
case Format::RGB565:
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PD_API Image::Format Image::GuessFmtFromBpp(int bpp) {
|
||||||
|
/** Only return defaults here */
|
||||||
|
switch (bpp) {
|
||||||
|
case 4:
|
||||||
|
return Format::RGBA;
|
||||||
|
case 3:
|
||||||
|
return Format::RGB;
|
||||||
|
case 2:
|
||||||
|
return Format::RGB565;
|
||||||
|
default:
|
||||||
|
return Format::RGBA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PD_API void Image::Flip(bool hz, bool vt) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace PD
|
||||||
@@ -16,6 +16,7 @@ const char* ResourcePath(const char* in) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
PD::LogFilter(PD::LogLevel::Warning);
|
||||||
Driver drv = Driver::OpenGL3;
|
Driver drv = Driver::OpenGL3;
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if (std::string(argv[1]) == "gl2") {
|
if (std::string(argv[1]) == "gl2") {
|
||||||
@@ -36,16 +37,22 @@ int main(int argc, char** argv) {
|
|||||||
pOs->Init();
|
pOs->Init();
|
||||||
PD::Gfx::Init();
|
PD::Gfx::Init();
|
||||||
PD::Li::Drawlist pList;
|
PD::Li::Drawlist pList;
|
||||||
|
PD::Image img(ResourcePath("icon.png"));
|
||||||
|
auto pTex = PD::Gfx::LoadTexture(img, img.Width(), img.Height());
|
||||||
while (pOs->Mainloop()) {
|
while (pOs->Mainloop()) {
|
||||||
pOs->ClearViewPort();
|
pOs->ClearViewPort();
|
||||||
PD::Li::ResetPools();
|
PD::Li::ResetPools();
|
||||||
pList.PathRect(pOs->SizeTranslate(0.05), pOs->SizeTranslate(0.4f), 10.f);
|
pList.PathRect(pOs->SizeTranslate(0.05), pOs->SizeTranslate(0.4f), 10.f);
|
||||||
pList.PathFill(0xff00ffff);
|
pList.PathFill(0xff00ffff);
|
||||||
|
pList.BindTexture(pTex);
|
||||||
|
pList.DrawRectFilled(pOs->SizeTranslate(PD::fvec2(0.02f, 0.5f)),
|
||||||
|
pOs->SizeTranslate(PD::fvec2(0.14, 0.3)), 0xffffffff);
|
||||||
PD::Gfx::Reset();
|
PD::Gfx::Reset();
|
||||||
PD::Gfx::Draw(pList);
|
PD::Gfx::Draw(pList);
|
||||||
pList.Clear();
|
pList.Clear();
|
||||||
pOs->SwapBuffers();
|
pOs->SwapBuffers();
|
||||||
}
|
}
|
||||||
|
PD::Gfx::DeleteTexture(pTex);
|
||||||
PD::Gfx::Deinit();
|
PD::Gfx::Deinit();
|
||||||
pOs->Deinit();
|
pOs->Deinit();
|
||||||
delete pOs;
|
delete pOs;
|
||||||
|
|||||||
Vendored
+9
-1
@@ -14,7 +14,15 @@ endif()
|
|||||||
|
|
||||||
# STB
|
# STB
|
||||||
add_library(stb INTERFACE)
|
add_library(stb INTERFACE)
|
||||||
target_include_directories(stb INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/stb)
|
target_include_directories(stb
|
||||||
|
INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/stb>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
|
install(TARGETS stb
|
||||||
|
EXPORT palladiumTargets
|
||||||
|
INCLUDES DESTINATION include
|
||||||
|
)
|
||||||
|
|
||||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS" AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "NintendoSwitch")
|
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS" AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "NintendoSwitch")
|
||||||
# GLFW
|
# GLFW
|
||||||
|
|||||||
Reference in New Issue
Block a user