Add a PositionTranslate func and add Errors for TextureSize mismatch
This commit is contained in:
@@ -174,6 +174,13 @@ Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
|||||||
int h, TextureFormat type,
|
int h, TextureFormat type,
|
||||||
TextureFilter filter) {
|
TextureFilter filter) {
|
||||||
if (!impl || w > 1024 || h > 1024) return Li::Texture();
|
if (!impl || w > 1024 || h > 1024) return Li::Texture();
|
||||||
|
if (pixels.size() !=
|
||||||
|
static_cast<size_t>(w * h * Li::TextureFormat2Bpp(type))) {
|
||||||
|
PDERR("Failed to load Texture due to Size mismatch: {} != {}",
|
||||||
|
pixels.size(),
|
||||||
|
static_cast<size_t>(w * h * Li::TextureFormat2Bpp(type)));
|
||||||
|
return Li::Texture();
|
||||||
|
}
|
||||||
// Don't check here as check done before
|
// Don't check here as check done before
|
||||||
PD::Li::Texture res;
|
PD::Li::Texture res;
|
||||||
int bpp = impl->TextureFormat2Bpp(type);
|
int bpp = impl->TextureFormat2Bpp(type);
|
||||||
|
|||||||
@@ -209,6 +209,13 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
|||||||
int h, TextureFormat type,
|
int h, TextureFormat type,
|
||||||
TextureFilter filter) {
|
TextureFilter filter) {
|
||||||
if (!impl || !impl->Device) return Li::Texture();
|
if (!impl || !impl->Device) return Li::Texture();
|
||||||
|
if (pixels.size() !=
|
||||||
|
static_cast<size_t>(w * h * Li::TextureFormat2Bpp(type))) {
|
||||||
|
PDERR("Failed to load Texture due to Size mismatch: {} != {}",
|
||||||
|
pixels.size(),
|
||||||
|
static_cast<size_t>(w * h * Li::TextureFormat2Bpp(type)));
|
||||||
|
return Li::Texture();
|
||||||
|
}
|
||||||
IDirect3DTexture9* tex = nullptr;
|
IDirect3DTexture9* tex = nullptr;
|
||||||
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
|
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
|
||||||
if (type == TextureFormat::RGB24)
|
if (type == TextureFormat::RGB24)
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ void GfxOpenGL2::SysReset() {
|
|||||||
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
int h, TextureFormat type,
|
int h, TextureFormat type,
|
||||||
TextureFilter filter) {
|
TextureFilter filter) {
|
||||||
|
if (pixels.size() !=
|
||||||
|
static_cast<size_t>(w * h * Li::TextureFormat2Bpp(type))) {
|
||||||
|
PDERR("Failed to load Texture due to Size mismatch: {} != {}",
|
||||||
|
pixels.size(),
|
||||||
|
static_cast<size_t>(w * h * Li::TextureFormat2Bpp(type)));
|
||||||
|
return Li::Texture();
|
||||||
|
}
|
||||||
GLuint texID;
|
GLuint texID;
|
||||||
glGenTextures(1, &texID);
|
glGenTextures(1, &texID);
|
||||||
glBindTexture(GL_TEXTURE_2D, texID);
|
glBindTexture(GL_TEXTURE_2D, texID);
|
||||||
|
|||||||
@@ -99,6 +99,13 @@ void GfxOpenGL3::SysReset() {
|
|||||||
Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
int h, TextureFormat type,
|
int h, TextureFormat type,
|
||||||
TextureFilter filter) {
|
TextureFilter filter) {
|
||||||
|
if (pixels.size() !=
|
||||||
|
static_cast<size_t>(w * h * Li::TextureFormat2Bpp(type))) {
|
||||||
|
PDERR("Failed to load Texture due to Size mismatch: {} != {}",
|
||||||
|
pixels.size(),
|
||||||
|
static_cast<size_t>(w * h * Li::TextureFormat2Bpp(type)));
|
||||||
|
return Li::Texture();
|
||||||
|
}
|
||||||
GLuint texID;
|
GLuint texID;
|
||||||
glGenTextures(1, &texID);
|
glGenTextures(1, &texID);
|
||||||
glBindTexture(GL_TEXTURE_2D, texID);
|
glBindTexture(GL_TEXTURE_2D, texID);
|
||||||
|
|||||||
@@ -16,6 +16,18 @@ enum class TextureFormat {
|
|||||||
A8,
|
A8,
|
||||||
};
|
};
|
||||||
namespace Li {
|
namespace Li {
|
||||||
|
static 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
class Texture {
|
class Texture {
|
||||||
public:
|
public:
|
||||||
using Ptr = Texture*;
|
using Ptr = Texture*;
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ PD_API void Drawlist::PathRect(const fvec2& tl, const fvec2& br, float r) {
|
|||||||
PathAdd(br);
|
PathAdd(br);
|
||||||
PathAdd(vec2(tl.x, br.y));
|
PathAdd(vec2(tl.x, br.y));
|
||||||
} else {
|
} else {
|
||||||
float r = std::min({r, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
float r = 0.f;
|
||||||
|
r = std::min({r, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
||||||
/** Calculate Optimal segment count automatically */
|
/** Calculate Optimal segment count automatically */
|
||||||
float corner = M_PI * 0.5f;
|
float corner = M_PI * 0.5f;
|
||||||
int segments = std::max(3, int(std::ceil(corner / (6.0f * M_PI / 180.0f))));
|
int segments = std::max(3, int(std::ceil(corner / (6.0f * M_PI / 180.0f))));
|
||||||
|
|||||||
@@ -21,10 +21,14 @@ class OsCtx {
|
|||||||
virtual bool Mainloop() { return false; }
|
virtual bool Mainloop() { return false; }
|
||||||
virtual void ClearViewPort() {}
|
virtual void ClearViewPort() {}
|
||||||
virtual void SwapBuffers() {}
|
virtual void SwapBuffers() {}
|
||||||
PD::fvec2 SizeTranslate(PD::fvec2 in) {
|
PD::fvec2 PositionTranslate(PD::fvec2 in) {
|
||||||
return fvec2(in.x * pViewPort.x, in.y * pViewPort.y);
|
return fvec2(in.x * pViewPort.x, in.y * pViewPort.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PD::fvec2 SizeTranslate(PD::fvec2 in) {
|
||||||
|
return fvec2(in.x * pViewPort.y, in.y * pViewPort.y);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PD::ivec2 pViewPort;
|
PD::ivec2 pViewPort;
|
||||||
const Driver pDriver;
|
const Driver pDriver;
|
||||||
|
|||||||
@@ -42,11 +42,12 @@ int main(int argc, char** argv) {
|
|||||||
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->PositionTranslate(0.05), pOs->PositionTranslate(0.4f),
|
||||||
|
10.f);
|
||||||
pList.PathFill(0xff00ffff);
|
pList.PathFill(0xff00ffff);
|
||||||
pList.BindTexture(pTex);
|
pList.BindTexture(pTex);
|
||||||
pList.DrawRectFilled(pOs->SizeTranslate(PD::fvec2(0.02f, 0.5f)),
|
pList.DrawRectFilled(pOs->PositionTranslate(PD::fvec2(0.02f, 0.5f)),
|
||||||
pOs->SizeTranslate(PD::fvec2(0.14, 0.3)), 0xffffffff);
|
pOs->SizeTranslate(PD::fvec2(0.3)), 0xffffffff);
|
||||||
PD::Gfx::Reset();
|
PD::Gfx::Reset();
|
||||||
PD::Gfx::Draw(pList);
|
PD::Gfx::Draw(pList);
|
||||||
pList.Clear();
|
pList.Clear();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <os/desktopos.hpp>
|
#include <os/desktopos.hpp>
|
||||||
|
#include <pdsystem>
|
||||||
|
|
||||||
#if !defined(__SWITCH__) && !defined(__3DS__)
|
#if !defined(__SWITCH__) && !defined(__3DS__)
|
||||||
#define GLFW_INCLUDE_NONE
|
#define GLFW_INCLUDE_NONE
|
||||||
@@ -11,8 +12,6 @@
|
|||||||
#include <GLFW/glfw3native.h>
|
#include <GLFW/glfw3native.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <pdsystem>
|
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
struct DesktopOS::Impl {
|
struct DesktopOS::Impl {
|
||||||
GLFWwindow* win = nullptr;
|
GLFWwindow* win = nullptr;
|
||||||
@@ -62,9 +61,9 @@ void DesktopOS::Init() {
|
|||||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||||
d3dpp.hDeviceWindow = hwnd;
|
d3dpp.hDeviceWindow = hwnd;
|
||||||
|
|
||||||
HRESULT hr = impl->d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
HRESULT hr = impl->d3d->CreateDevice(
|
||||||
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp,
|
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
||||||
&impl->dx9_device);
|
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &impl->dx9_device);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
|
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
|
||||||
std::abort();
|
std::abort();
|
||||||
@@ -91,9 +90,19 @@ bool DesktopOS::Mainloop() {
|
|||||||
|
|
||||||
void DesktopOS::ClearViewPort() {
|
void DesktopOS::ClearViewPort() {
|
||||||
PD::Gfx::SetViewPort(pViewPort);
|
PD::Gfx::SetViewPort(pViewPort);
|
||||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
if (pDriver == Driver::OpenGL3 || pDriver == Driver::OpenGL2) {
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||||
glViewport(0, 0, pViewPort.x, pViewPort.y);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
glViewport(0, 0, pViewPort.x, pViewPort.y);
|
||||||
|
} else if (pDriver == Driver::DirectX9) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (impl->dx9_device) {
|
||||||
|
impl->dx9_device->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
|
||||||
|
D3DCOLOR_XRGB(25, 25, 25), 1.0f, 0);
|
||||||
|
impl->dx9_device->BeginScene();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopOS::SwapBuffers() { glfwSwapBuffers(impl->win); }
|
void DesktopOS::SwapBuffers() { glfwSwapBuffers(impl->win); }
|
||||||
|
|||||||
Reference in New Issue
Block a user