Work at 3ds support and backend upgrades
- Track textures (not sure if this is done tbh) - Add lithium formatters and move TextureID, TextureFormat and TextureFilter to lithium - Only include gl-helper if any glDriver is included - Add Li::Rect for UV stuff - Add Li::Texture as Info holder (still thinking of making them to ptrs - Add Check if textures are still loaded on exit
This commit is contained in:
@@ -9,37 +9,43 @@ option(PD_ENABLE_CITRO3D "Enable Citro3D Support (3DS)" OFF)
|
||||
option(PD_ENABLE_VULKAN "Not implemented yet" OFF)
|
||||
|
||||
if(NOT WIN32) # cause we are not on windows...
|
||||
set(PD_ENABLE_DIRECTX9 OFF)
|
||||
set(PD_ENABLE_DIRECTX9 OFF)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
set(PD_ENABLE_OPENGL2 OFF)
|
||||
set(PD_ENABLE_OPENGL3 OFF)
|
||||
set(PD_ENABLE_VULKAN OFF)
|
||||
set(PD_ENABLE_CITRO3D ON)
|
||||
endif()
|
||||
|
||||
add_library(pd-system STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gl-helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl2.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl3.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gl-helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl2.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl3.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp
|
||||
)
|
||||
|
||||
target_include_directories(pd-system
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
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}/include=include
|
||||
>
|
||||
)
|
||||
|
||||
target_compile_definitions(pd-system
|
||||
PUBLIC
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL2}>:PD_ENABLE_OPENGL2>
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL3}>:PD_ENABLE_OPENGL3>
|
||||
$<$<BOOL:${PD_ENABLE_VULKAN}>:PD_ENABLE_VULKAN>
|
||||
$<$<BOOL:${PD_ENABLE_DIRECTX9}>:PD_ENABLE_DIRECTX9>
|
||||
PUBLIC
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL2}>:PD_ENABLE_OPENGL2>
|
||||
$<$<BOOL:${PD_ENABLE_OPENGL3}>:PD_ENABLE_OPENGL3>
|
||||
$<$<BOOL:${PD_ENABLE_VULKAN}>:PD_ENABLE_VULKAN>
|
||||
$<$<BOOL:${PD_ENABLE_DIRECTX9}>:PD_ENABLE_DIRECTX9>
|
||||
$<$<BOOL:${PD_ENABLE_CITRO3D}>:PD_ENABLE_CITRO3D>
|
||||
)
|
||||
|
||||
# Palladium
|
||||
@@ -47,17 +53,20 @@ target_link_libraries(pd-system PUBLIC palladium::palladium)
|
||||
|
||||
# glad (if we have any OpenGL version included)
|
||||
if(PD_ENABLE_OPENGL2 OR PD_ENABLE_OPENGL3)
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC
|
||||
glad
|
||||
)
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC glad
|
||||
)
|
||||
endif()
|
||||
|
||||
# DirectX9
|
||||
if(PD_ENABLE_DIRECTX9)
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC
|
||||
d3d9
|
||||
d3dcompiler
|
||||
)
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC
|
||||
d3d9
|
||||
d3dcompiler
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
target_link_libraries(pd-system PUBLIC pica::pica citro3d ctru)
|
||||
endif()
|
||||
@@ -26,10 +26,11 @@ class GfxCitro3D : public GfxDriverBase<GfxCitro3DConfig> {
|
||||
void Submit(size_t count, size_t start) override;
|
||||
void BindTexture(TextureID id) override;
|
||||
void SysReset() override;
|
||||
TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const TextureID& tex) override;
|
||||
Li::Texture LoadTexture(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const Li::Texture& tex) override;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
|
||||
@@ -26,10 +26,11 @@ class GfxDirectX9 : public GfxDriverBase<GfxDirectX9Config> {
|
||||
void Submit(size_t count, size_t start) override;
|
||||
void BindTexture(TextureID id) override;
|
||||
void SysReset() override;
|
||||
TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const TextureID& tex) override;
|
||||
Li::Texture LoadTexture(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const Li::Texture& tex) override;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
|
||||
@@ -25,10 +25,11 @@ class GfxOpenGL2 : public GfxDriverBase<GfxOpenGL2Config> {
|
||||
void Submit(size_t count, size_t start) override;
|
||||
void BindTexture(TextureID id) override;
|
||||
void SysReset() override;
|
||||
TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const TextureID& tex) override;
|
||||
Li::Texture LoadTexture(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const Li::Texture& tex) override;
|
||||
|
||||
private:
|
||||
void pSetupShaderAttribs(u32 shader);
|
||||
|
||||
@@ -25,10 +25,11 @@ class GfxOpenGL3 : public GfxDriverBase<GfxOpenGL3Config> {
|
||||
void Submit(size_t count, size_t start) override;
|
||||
void BindTexture(TextureID id) override;
|
||||
void SysReset() override;
|
||||
TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const TextureID& tex) override;
|
||||
Li::Texture LoadTexture(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const Li::Texture& tex) override;
|
||||
|
||||
private:
|
||||
u32 pShader = 0;
|
||||
|
||||
@@ -1,25 +1,140 @@
|
||||
// Well yes, i finally try it
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/formatters.hpp>
|
||||
#include <pd_system/gfx_citro3d.hpp>
|
||||
|
||||
#if defined(PD_ENABLE_CITRO3D) // && defined(__3DS__)
|
||||
#if defined(PD_ENABLE_CITRO3D) && defined(__3DS__)
|
||||
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
#include <pica.hpp>
|
||||
|
||||
namespace PD {
|
||||
struct GfxCitro3D::Impl {};
|
||||
const char* LIShaderCTR = R"(
|
||||
; LI7 Shader
|
||||
; Constants
|
||||
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
|
||||
.alias ones myconst.yyyy ; Vector full of ones
|
||||
|
||||
; Uniforms
|
||||
.fvec projection[4]
|
||||
|
||||
; Outputs
|
||||
.out out_position position
|
||||
.out out_color color
|
||||
.out out_uv texcoord0
|
||||
|
||||
; Inputs
|
||||
.alias in_xy v0
|
||||
.alias in_uvc v1
|
||||
.alias in_col v2
|
||||
|
||||
.entry vmain
|
||||
.proc vmain
|
||||
mov r0.xy, in_xy.xy
|
||||
mov r0.w, ones
|
||||
|
||||
dp4 out_position.x, projection[0], r0
|
||||
dp4 out_position.y, projection[1], r0
|
||||
dp4 out_position.z, projection[2], r0
|
||||
dp4 out_position.w, projection[3], r0
|
||||
|
||||
mov out_uv, in_uvc.xy
|
||||
|
||||
mul r1, myconst.zzzz, in_col
|
||||
mov out_color, r1
|
||||
end
|
||||
.end
|
||||
)";
|
||||
|
||||
struct GfxCitro3D::Impl {
|
||||
C3D_AttrInfo pAttr;
|
||||
shaderProgram_s pShader;
|
||||
DVLB_s* pCode;
|
||||
int uLocProjection = 0;
|
||||
std::vector<u8> pShaderRaw;
|
||||
|
||||
GPU_TEXCOLOR TextureTranslateFormat(TextureFormat fmt) {
|
||||
switch (fmt) {
|
||||
case PD::TextureFormat::A8:
|
||||
return GPU_A8;
|
||||
case PD::TextureFormat::RGB24:
|
||||
return GPU_RGB8;
|
||||
case PD::TextureFormat::RGBA32:
|
||||
return GPU_RGBA8;
|
||||
default:
|
||||
return GPU_RGBA8;
|
||||
}
|
||||
}
|
||||
|
||||
int TextureFormat2Bpp(TextureFormat fmt) {
|
||||
switch (fmt) {
|
||||
case PD::TextureFormat::A8:
|
||||
return 1;
|
||||
case PD::TextureFormat::RGB24:
|
||||
return 3;
|
||||
case PD::TextureFormat::RGBA32:
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetupPixelStage(GPU_TEXCOLOR clr) {
|
||||
shaderProgramUse(&pShader);
|
||||
C3D_BindProgram(&pShader);
|
||||
C3D_SetAttrInfo(&pAttr);
|
||||
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
|
||||
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||
C3D_TexEnvInit(env);
|
||||
switch (clr) {
|
||||
case GPU_A4:
|
||||
case GPU_A8:
|
||||
case GPU_L4:
|
||||
case GPU_L8:
|
||||
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
|
||||
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
|
||||
C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE);
|
||||
break;
|
||||
case GPU_RGB565:
|
||||
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
|
||||
C3D_TexEnvFunc(env, C3D_RGB, GPU_MODULATE);
|
||||
C3D_TexEnvFunc(env, C3D_Alpha, GPU_REPLACE);
|
||||
break;
|
||||
|
||||
default:
|
||||
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
|
||||
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void GfxCitro3D::SysInit() {
|
||||
if (impl) return;
|
||||
PDLOG("GfxCitro3D::SysInit();");
|
||||
impl = new Impl();
|
||||
impl->pShaderRaw = Pica::AssembleCode(LIShaderCTR);
|
||||
impl->pCode = DVLB_ParseFile((uint32_t*)impl->pShaderRaw.data(),
|
||||
impl->pShaderRaw.size());
|
||||
shaderProgramInit(&impl->pShader);
|
||||
shaderProgramSetVsh(&impl->pShader, &impl->pCode->DVLE[0]);
|
||||
impl->uLocProjection = shaderInstanceGetUniformLocation(
|
||||
impl->pShader.vertexShader, "projection");
|
||||
|
||||
AttrInfo_Init(&impl->pAttr);
|
||||
AttrInfo_AddLoader(&impl->pAttr, 0, GPU_FLOAT, 2);
|
||||
AttrInfo_AddLoader(&impl->pAttr, 1, GPU_FLOAT, 2);
|
||||
AttrInfo_AddLoader(&impl->pAttr, 2, GPU_UNSIGNED_BYTE, 4);
|
||||
}
|
||||
|
||||
void GfxCitro3D::SysDeinit() {
|
||||
if (!impl) return;
|
||||
shaderProgramFree(&impl->pShader);
|
||||
DVLB_Free(impl->pCode);
|
||||
delete impl;
|
||||
impl = nullptr;
|
||||
PDLOG("GfxCitro3D::SysDeinit()");
|
||||
@@ -31,21 +146,74 @@ void GfxCitro3D::Submit(size_t count, size_t start) {
|
||||
|
||||
void GfxCitro3D::BindTexture(TextureID id) {
|
||||
if (!impl) return;
|
||||
C3D_TexBind(0, (C3D_Tex*)id);
|
||||
}
|
||||
|
||||
void GfxCitro3D::SysReset() {
|
||||
if (!impl) return;
|
||||
}
|
||||
|
||||
TextureID GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
if (!impl) return 0;
|
||||
return 0;
|
||||
Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
if (!impl || w > 1024 || h > 1024) return Li::Texture();
|
||||
// Don't check here as check done before
|
||||
PD::Li::Texture res;
|
||||
int bpp = impl->TextureFormat2Bpp(type);
|
||||
ivec2 tex_size(w, h);
|
||||
// Pow2
|
||||
if (!PD::Bits::IsSingleBit(w)) {
|
||||
tex_size.x = PD::Bits::GetPow2((unsigned int)w);
|
||||
}
|
||||
if (!PD::Bits::IsSingleBit(h)) {
|
||||
tex_size.y = PD::Bits::GetPow2((unsigned int)h);
|
||||
}
|
||||
res.SetSize(w, h);
|
||||
res.SetUV(0.f, 1.f, ((float)w / (float)tex_size.x),
|
||||
1.0 - ((float)h / (float)tex_size.y));
|
||||
|
||||
// Texture Setup
|
||||
auto fltr = (filter == TextureFilter::Linear ? GPU_NEAREST : GPU_LINEAR);
|
||||
auto tex_fmt = impl->TextureTranslateFormat(type);
|
||||
auto tex = new C3D_Tex;
|
||||
C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt);
|
||||
C3D_TexSetFilter(tex, fltr, fltr);
|
||||
|
||||
std::memset((PD::u8*)tex->data, 0x0, tex->size);
|
||||
|
||||
/// Probably Remove this if statement in future
|
||||
/// This are the things confirmed as working
|
||||
if (bpp == 3 || bpp == 4 || bpp == 1) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
for (int y = 0; y < h; y++) {
|
||||
int dst_pos = ((((y >> 3) * ((int)tex_size.x >> 3) + (x >> 3)) << 6) +
|
||||
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
||||
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
||||
bpp;
|
||||
int src_pos = (y * w + x) * bpp;
|
||||
/// Best idea i had
|
||||
for (int i = 0; i < bpp; i++) {
|
||||
((u8*)tex->data)[dst_pos + bpp - 1 - i] = pixels[src_pos + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
C3D_TexFlush(tex);
|
||||
}
|
||||
|
||||
tex->border = 0x00000000;
|
||||
C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT);
|
||||
res.SetID((TextureID)tex);
|
||||
RegisterTexture(res);
|
||||
PDLOG("GfxCitro3D::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
|
||||
return res;
|
||||
}
|
||||
|
||||
void GfxCitro3D::DeleteTexture(const TextureID& tex) {
|
||||
if (!tex) return;
|
||||
void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {
|
||||
if (!tex.GetID()) return;
|
||||
UnRegisterTexture(tex);
|
||||
C3D_Tex* t = reinterpret_cast<C3D_Tex*>(tex.GetID());
|
||||
C3D_TexDelete(t);
|
||||
delete t;
|
||||
}
|
||||
} // namespace PD
|
||||
#else
|
||||
@@ -59,11 +227,11 @@ void GfxCitro3D::SysDeinit() {}
|
||||
void GfxCitro3D::Submit(size_t count, size_t start) {}
|
||||
void GfxCitro3D::BindTexture(TextureID id) {}
|
||||
void GfxCitro3D::SysReset() {}
|
||||
TextureID GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return 0;
|
||||
Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return Li::Texture();
|
||||
}
|
||||
void GfxCitro3D::DeleteTexture(const TextureID& tex) {}
|
||||
void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {}
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
// Well yes, i finally try it
|
||||
|
||||
#include <pd/lithium/formatters.hpp>
|
||||
#include <pd_system/gfx_directx9.hpp>
|
||||
|
||||
// Sicher ist sicher
|
||||
@@ -182,9 +183,9 @@ void GfxDirectX9::SysReset() {
|
||||
impl->Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
}
|
||||
|
||||
TextureID GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
if (!impl || !impl->Device) return 0;
|
||||
IDirect3DTexture9* tex = nullptr;
|
||||
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
|
||||
@@ -234,15 +235,19 @@ TextureID GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
}
|
||||
|
||||
tex->UnlockRect(0);
|
||||
|
||||
PDLOG("GfxDirectX9::LoadTexture -> [{}] 0x{:X}, [{}, {}]", PD::ivec2(w, h),
|
||||
(TextureID)tex, type, filter);
|
||||
return (TextureID)tex;
|
||||
Li::Texture res;
|
||||
res.SetID((TextureID)tex);
|
||||
res.SetSize(w, h);
|
||||
res.SetUV(0.f, 0.f, 1.f, 1.f);
|
||||
RegisterTexture(res);
|
||||
PDLOG("GfxDirectX9::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
|
||||
return res;
|
||||
}
|
||||
|
||||
void GfxDirectX9::DeleteTexture(const TextureID& tex) {
|
||||
if (!tex) return;
|
||||
IDirect3DTexture9* t = (IDirect3DTexture9*)tex;
|
||||
void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {
|
||||
if (!tex.GetID()) return;
|
||||
UnRegisterTexture(tex);
|
||||
IDirect3DTexture9* t = (IDirect3DTexture9*)tex.GetID();
|
||||
t->Release();
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -257,11 +262,11 @@ void GfxDirectX9::SysDeinit() {}
|
||||
void GfxDirectX9::Submit(size_t count, size_t start) {}
|
||||
void GfxDirectX9::BindTexture(TextureID id) {}
|
||||
void GfxDirectX9::SysReset() {}
|
||||
TextureID GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return 0;
|
||||
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return Li::Texture();
|
||||
}
|
||||
void GfxDirectX9::DeleteTexture(const TextureID& tex) {}
|
||||
void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {}
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <pd/lithium/formatters.hpp>
|
||||
#include <pd_system/gfx_opengl2.hpp>
|
||||
|
||||
#if defined(PD_ENABLE_OPENGL2)
|
||||
@@ -128,9 +129,9 @@ void GfxOpenGL2::SysReset() {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
TextureID GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
GLuint texID;
|
||||
glGenTextures(1, &texID);
|
||||
glBindTexture(GL_TEXTURE_2D, texID);
|
||||
@@ -152,13 +153,18 @@ TextureID GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
PDLOG("GfxOpenGL2::LoadTexture -> [{}] {}, [{}, {}]", PD::ivec2(w, h), texID,
|
||||
type, filter);
|
||||
return texID;
|
||||
Li::Texture res;
|
||||
res.SetID(texID);
|
||||
res.SetSize(w, h);
|
||||
res.SetUV(0.f, 0.f, 1.f, 1.f);
|
||||
RegisterTexture(res);
|
||||
PDLOG("GfxOpenGL2::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
|
||||
return res;
|
||||
}
|
||||
|
||||
void GfxOpenGL2::DeleteTexture(const TextureID& tex) {
|
||||
GLuint tex_ = tex;
|
||||
void GfxOpenGL2::DeleteTexture(const Li::Texture& tex) {
|
||||
UnregisterTexture(tex);
|
||||
GLuint tex_ = tex.GetID();
|
||||
glDeleteTextures(1, &tex_);
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -173,12 +179,12 @@ void GfxOpenGL2::SysDeinit() {}
|
||||
void GfxOpenGL2::Submit(size_t count, size_t start) {}
|
||||
void GfxOpenGL2::BindTexture(TextureID id) {}
|
||||
void GfxOpenGL2::SysReset() {}
|
||||
TextureID GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return 0;
|
||||
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return Li::Texture();
|
||||
}
|
||||
void GfxOpenGL2::DeleteTexture(const TextureID& tex) {}
|
||||
void GfxOpenGL2::DeleteTexture(const Li::Texture& tex) {}
|
||||
void GfxOpenGL2::pSetupShaderAttribs(u32 shader) {}
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <pd/lithium/formatters.hpp>
|
||||
#include <pd_system/gfx_opengl3.hpp>
|
||||
|
||||
#if defined(PD_ENABLE_OPENGL3)
|
||||
#include <glad/glad.h>
|
||||
|
||||
@@ -124,9 +126,9 @@ void GfxOpenGL3::SysReset() {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
TextureID GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
GLuint texID;
|
||||
glGenTextures(1, &texID);
|
||||
glBindTexture(GL_TEXTURE_2D, texID);
|
||||
@@ -148,13 +150,18 @@ TextureID GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
PDLOG("GfxOpenGL3::LoadTexture -> [{}] {}, [{}, {}]", PD::ivec2(w, h), texID,
|
||||
type, filter);
|
||||
return texID;
|
||||
Li::Texture res;
|
||||
res.SetID(texID);
|
||||
res.SetSize(w, h);
|
||||
res.SetUV(0.f, 0.f, 1.f, 1.f);
|
||||
RegisterTexture(res);
|
||||
PDLOG("GfxOpenGL3::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
|
||||
return res;
|
||||
}
|
||||
|
||||
void GfxOpenGL3::DeleteTexture(const TextureID& tex) {
|
||||
GLuint tex_ = tex;
|
||||
void GfxOpenGL3::DeleteTexture(const Li::Texture& tex) {
|
||||
UnregisterTexture(tex);
|
||||
GLuint tex_ = tex.GetID();
|
||||
glDeleteTextures(1, &tex_);
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -169,12 +176,11 @@ void GfxOpenGL3::SysDeinit() {}
|
||||
void GfxOpenGL3::Submit(size_t count, size_t start) {}
|
||||
void GfxOpenGL3::BindTexture(TextureID id) {}
|
||||
void GfxOpenGL3::SysReset() {}
|
||||
TextureID GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return 0;
|
||||
Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return Li::Texture();
|
||||
}
|
||||
void GfxOpenGL3::DeleteTexture(const TextureID& tex) {}
|
||||
void GfxOpenGL3::pSetupShaderAttribs(u32 shader) {}
|
||||
void GfxOpenGL3::DeleteTexture(const Li::Texture& tex) {}
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if defined(PD_ENABLE_OPENGL2) || defined(PD_ENABLE_OPENGL3)
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <iostream>
|
||||
@@ -43,4 +44,5 @@ u32 CreateShaderProgram(const char* vert, const char* frag) {
|
||||
|
||||
return shaderProgram;
|
||||
}
|
||||
} // namespace PD
|
||||
} // namespace PD
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user