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,
|
||||
TextureFilter filter) {
|
||||
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
|
||||
PD::Li::Texture res;
|
||||
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,
|
||||
TextureFilter filter) {
|
||||
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;
|
||||
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
|
||||
if (type == TextureFormat::RGB24)
|
||||
|
||||
@@ -129,6 +129,13 @@ void GfxOpenGL2::SysReset() {
|
||||
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
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;
|
||||
glGenTextures(1, &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,
|
||||
int h, TextureFormat type,
|
||||
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;
|
||||
glGenTextures(1, &texID);
|
||||
glBindTexture(GL_TEXTURE_2D, texID);
|
||||
|
||||
@@ -16,6 +16,18 @@ enum class TextureFormat {
|
||||
A8,
|
||||
};
|
||||
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 {
|
||||
public:
|
||||
using Ptr = Texture*;
|
||||
|
||||
@@ -75,7 +75,8 @@ PD_API void Drawlist::PathRect(const fvec2& tl, const fvec2& br, float r) {
|
||||
PathAdd(br);
|
||||
PathAdd(vec2(tl.x, br.y));
|
||||
} 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 */
|
||||
float corner = M_PI * 0.5f;
|
||||
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 void ClearViewPort() {}
|
||||
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);
|
||||
}
|
||||
|
||||
PD::fvec2 SizeTranslate(PD::fvec2 in) {
|
||||
return fvec2(in.x * pViewPort.y, in.y * pViewPort.y);
|
||||
}
|
||||
|
||||
protected:
|
||||
PD::ivec2 pViewPort;
|
||||
const Driver pDriver;
|
||||
|
||||
@@ -42,11 +42,12 @@ int main(int argc, char** argv) {
|
||||
while (pOs->Mainloop()) {
|
||||
pOs->ClearViewPort();
|
||||
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.BindTexture(pTex);
|
||||
pList.DrawRectFilled(pOs->SizeTranslate(PD::fvec2(0.02f, 0.5f)),
|
||||
pOs->SizeTranslate(PD::fvec2(0.14, 0.3)), 0xffffffff);
|
||||
pList.DrawRectFilled(pOs->PositionTranslate(PD::fvec2(0.02f, 0.5f)),
|
||||
pOs->SizeTranslate(PD::fvec2(0.3)), 0xffffffff);
|
||||
PD::Gfx::Reset();
|
||||
PD::Gfx::Draw(pList);
|
||||
pList.Clear();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <os/desktopos.hpp>
|
||||
#include <pdsystem>
|
||||
|
||||
#if !defined(__SWITCH__) && !defined(__3DS__)
|
||||
#define GLFW_INCLUDE_NONE
|
||||
@@ -11,8 +12,6 @@
|
||||
#include <GLFW/glfw3native.h>
|
||||
#endif
|
||||
|
||||
#include <pdsystem>
|
||||
|
||||
namespace PD {
|
||||
struct DesktopOS::Impl {
|
||||
GLFWwindow* win = nullptr;
|
||||
@@ -62,9 +61,9 @@ void DesktopOS::Init() {
|
||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
d3dpp.hDeviceWindow = hwnd;
|
||||
|
||||
HRESULT hr = impl->d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
||||
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp,
|
||||
&impl->dx9_device);
|
||||
HRESULT hr = impl->d3d->CreateDevice(
|
||||
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
||||
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &impl->dx9_device);
|
||||
if (FAILED(hr)) {
|
||||
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
|
||||
std::abort();
|
||||
@@ -91,9 +90,19 @@ bool DesktopOS::Mainloop() {
|
||||
|
||||
void DesktopOS::ClearViewPort() {
|
||||
PD::Gfx::SetViewPort(pViewPort);
|
||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, pViewPort.x, pViewPort.y);
|
||||
if (pDriver == Driver::OpenGL3 || pDriver == Driver::OpenGL2) {
|
||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||
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); }
|
||||
|
||||
Reference in New Issue
Block a user