From ae286aef86205bf3bfab33eb3f859cbb9ad8c6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 22 Oct 2019 22:07:34 +0200 Subject: [PATCH 1/7] Vulkan+SoftwareRenderer: Fix screen rotation on Android. (Missed this because software rendering is normally disabled on Android) --- GPU/Software/SoftGpu.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index f7e29dd665..76f4a8d7b9 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -15,6 +15,8 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include "base/display.h" + #include "GPU/GPUState.h" #include "GPU/ge_constants.h" #include "GPU/Common/TextureDecoder.h" @@ -285,7 +287,7 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) { }; Draw::VsTexColUB ub{}; - memcpy(ub.WorldViewProj, identity4x4, sizeof(float) * 16); + memcpy(ub.WorldViewProj, g_display_rot_matrix.m, sizeof(float) * 16); draw_->BindPipeline(texColor); draw_->UpdateDynamicUniformBuffer(&ub, sizeof(ub)); draw_->BindVertexBuffers(0, 1, &vdata, nullptr); From 767b1e45b2c9215bbe41c39530eac869b4bf262b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 22 Oct 2019 22:58:10 +0200 Subject: [PATCH 2/7] Fix the build - there's a Vec3 name collision, fixed it using a namespace. --- GPU/Common/ShaderUniforms.cpp | 2 ++ GPU/D3D11/FramebufferManagerD3D11.cpp | 2 +- GPU/Directx9/ShaderManagerDX9.cpp | 2 ++ GPU/GLES/ShaderManagerGLES.cpp | 2 ++ GPU/Vulkan/FramebufferVulkan.cpp | 2 +- Windows/GEDebugger/SimpleGLWindow.cpp | 2 ++ Windows/GEDebugger/VertexPreview.cpp | 4 ++-- ext/native/base/display.cpp | 2 +- ext/native/base/display.h | 2 +- ext/native/gfx_es2/draw_buffer.cpp | 2 +- ext/native/gfx_es2/draw_buffer.h | 8 ++++---- ext/native/math/geom2d.h | 2 +- ext/native/math/lin/matrix4x4.cpp | 5 ++++- ext/native/math/lin/matrix4x4.h | 4 ++++ ext/native/math/lin/plane.cpp | 3 +++ ext/native/math/lin/plane.h | 4 ++++ ext/native/math/lin/quat.cpp | 4 ++++ ext/native/math/lin/quat.h | 4 ++++ ext/native/math/lin/vec3.cpp | 4 ++++ ext/native/math/lin/vec3.h | 4 ++++ ext/native/thin3d/thin3d.h | 2 ++ ext/native/ui/ui_context.cpp | 2 ++ ext/native/ui/ui_context.h | 4 ++-- ext/native/ui/ui_screen.h | 3 +++ 24 files changed, 60 insertions(+), 15 deletions(-) diff --git a/GPU/Common/ShaderUniforms.cpp b/GPU/Common/ShaderUniforms.cpp index ee90163c7d..d0c8e0da76 100644 --- a/GPU/Common/ShaderUniforms.cpp +++ b/GPU/Common/ShaderUniforms.cpp @@ -14,6 +14,8 @@ #include "Core/Reporting.h" #include "Core/Config.h" +using namespace Lin; + static void ConvertProjMatrixToVulkan(Matrix4x4 &in) { const Vec3 trans(0, 0, gstate_c.vpZOffset * 0.5f + 0.5f); const Vec3 scale(gstate_c.vpWidthScale, gstate_c.vpHeightScale, gstate_c.vpDepthScale * 0.5f); diff --git a/GPU/D3D11/FramebufferManagerD3D11.cpp b/GPU/D3D11/FramebufferManagerD3D11.cpp index 52231e4be6..98c9e3256c 100644 --- a/GPU/D3D11/FramebufferManagerD3D11.cpp +++ b/GPU/D3D11/FramebufferManagerD3D11.cpp @@ -348,7 +348,7 @@ void FramebufferManagerD3D11::MakePixelTexture(const u8 *srcPixels, GEBufferForm void FramebufferManagerD3D11::DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags) { struct Coord { - Vec3 pos; float u, v; + Lin::Vec3 pos; float u, v; }; Coord coord[4] = { {{x, y, 0}, u0, v0}, diff --git a/GPU/Directx9/ShaderManagerDX9.cpp b/GPU/Directx9/ShaderManagerDX9.cpp index 0fd16f2b3d..22424d703a 100644 --- a/GPU/Directx9/ShaderManagerDX9.cpp +++ b/GPU/Directx9/ShaderManagerDX9.cpp @@ -42,6 +42,8 @@ #include "GPU/Directx9/DrawEngineDX9.h" #include "GPU/Directx9/FramebufferDX9.h" +using namespace Lin; + namespace DX9 { PSShader::PSShader(LPDIRECT3DDEVICE9 device, FShaderID id, const char *code) : id_(id), shader(nullptr), failed_(false) { diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index fc62801499..2629743f7e 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -48,6 +48,8 @@ #include "GPU/GLES/DrawEngineGLES.h" #include "GPU/GLES/FramebufferManagerGLES.h" +using namespace Lin; + Shader::Shader(GLRenderManager *render, const char *code, const std::string &desc, uint32_t glShaderType, bool useHWTransform, uint32_t attrMask, uint64_t uniformMask) : render_(render), failed_(false), useHWTransform_(useHWTransform), attrMask_(attrMask), uniformMask_(uniformMask) { PROFILE_THIS_SCOPE("shadercomp"); diff --git a/GPU/Vulkan/FramebufferVulkan.cpp b/GPU/Vulkan/FramebufferVulkan.cpp index 40bdea27a9..532c00dfb8 100644 --- a/GPU/Vulkan/FramebufferVulkan.cpp +++ b/GPU/Vulkan/FramebufferVulkan.cpp @@ -317,7 +317,7 @@ void FramebufferManagerVulkan::DrawActiveTexture(float x, float y, float w, floa if ((flags & DRAWTEX_TO_BACKBUFFER) && g_display_rotation != DisplayRotation::ROTATE_0) { for (int i = 0; i < 4; i++) { - Vec3 v(vtx[i].x, vtx[i].y, 0.0f); + Lin::Vec3 v(vtx[i].x, vtx[i].y, 0.0f); // backwards notation, should fix that... v = v * g_display_rot_matrix; vtx[i].x = v.x; diff --git a/Windows/GEDebugger/SimpleGLWindow.cpp b/Windows/GEDebugger/SimpleGLWindow.cpp index c24613711d..07fef48e02 100644 --- a/Windows/GEDebugger/SimpleGLWindow.cpp +++ b/Windows/GEDebugger/SimpleGLWindow.cpp @@ -24,6 +24,8 @@ const wchar_t *SimpleGLWindow::windowClass = L"SimpleGLWindow"; +using namespace Lin; + void SimpleGLWindow::RegisterClass() { WNDCLASSEX wndClass; diff --git a/Windows/GEDebugger/VertexPreview.cpp b/Windows/GEDebugger/VertexPreview.cpp index b608754b66..271302237b 100644 --- a/Windows/GEDebugger/VertexPreview.cpp +++ b/Windows/GEDebugger/VertexPreview.cpp @@ -426,7 +426,7 @@ void CGEDebugger::UpdatePrimPreview(u32 op, int which) { 272.0f / (float)PSP_CoreParameter().renderHeight, }; - Matrix4x4 ortho; + Lin::Matrix4x4 ortho; ortho.setOrtho(-(float)gstate_c.curRTOffsetX, (primaryWindow->TexWidth() - (int)gstate_c.curRTOffsetX) * scale[0], primaryWindow->TexHeight() * scale[1], 0, -1, 1); glUniformMatrix4fv(previewProgram->u_viewproj, 1, GL_FALSE, ortho.getReadPtr()); if (previewVao != 0) { @@ -488,7 +488,7 @@ void CGEDebugger::UpdatePrimPreview(u32 op, int which) { glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(u16), indices.data(), GL_STREAM_DRAW); } - Matrix4x4 ortho; + Lin::Matrix4x4 ortho; ortho.setOrtho(0.0f - (float)gstate_c.curTextureXOffset * invRealTexWidth, 1.0f - (float)gstate_c.curTextureXOffset * invRealTexWidth, 1.0f - (float)gstate_c.curTextureYOffset * invRealTexHeight, 0.0f - (float)gstate_c.curTextureYOffset * invRealTexHeight, -1.0f, 1.0f); glUniformMatrix4fv(texPreviewProgram->u_viewproj, 1, GL_FALSE, ortho.getReadPtr()); if (texPreviewVao != 0) { diff --git a/ext/native/base/display.cpp b/ext/native/base/display.cpp index b0b940c42f..3e912788db 100644 --- a/ext/native/base/display.cpp +++ b/ext/native/base/display.cpp @@ -17,7 +17,7 @@ float pixel_in_dps_y = 1.0f; float display_hz = 60.0f; DisplayRotation g_display_rotation; -Matrix4x4 g_display_rot_matrix; +Lin::Matrix4x4 g_display_rot_matrix; template void RotateRectToDisplayImpl(DisplayRect &rect, T curRTWidth, T curRTHeight) { diff --git a/ext/native/base/display.h b/ext/native/base/display.h index a11a697da4..d91e426931 100644 --- a/ext/native/base/display.h +++ b/ext/native/base/display.h @@ -29,7 +29,7 @@ enum class DisplayRotation { }; extern DisplayRotation g_display_rotation; -extern Matrix4x4 g_display_rot_matrix; +extern Lin::Matrix4x4 g_display_rot_matrix; template struct DisplayRect { diff --git a/ext/native/gfx_es2/draw_buffer.cpp b/ext/native/gfx_es2/draw_buffer.cpp index 603d49ee8e..5d1bb88153 100644 --- a/ext/native/gfx_es2/draw_buffer.cpp +++ b/ext/native/gfx_es2/draw_buffer.cpp @@ -92,7 +92,7 @@ void DrawBuffer::Flush(bool set_blend_state) { draw_->BindPipeline(pipeline_); VsTexColUB ub{}; - memcpy(ub.WorldViewProj, drawMatrix_.getReadPtr(), sizeof(Matrix4x4)); + memcpy(ub.WorldViewProj, drawMatrix_.getReadPtr(), sizeof(Lin::Matrix4x4)); draw_->UpdateDynamicUniformBuffer(&ub, sizeof(ub)); if (vbuf_) { draw_->UpdateBuffer(vbuf_, (const uint8_t *)verts_, 0, sizeof(Vertex) * count_, Draw::UPDATE_DISCARD); diff --git a/ext/native/gfx_es2/draw_buffer.h b/ext/native/gfx_es2/draw_buffer.h index 788e4a125f..d90f8ae774 100644 --- a/ext/native/gfx_es2/draw_buffer.h +++ b/ext/native/gfx_es2/draw_buffer.h @@ -142,7 +142,7 @@ public: static void DoAlign(int flags, float *x, float *y, float *w, float *h); - void PushDrawMatrix(const Matrix4x4 &m) { + void PushDrawMatrix(const Lin::Matrix4x4 &m) { drawMatrixStack_.push_back(drawMatrix_); drawMatrix_ = m; } @@ -152,7 +152,7 @@ public: drawMatrixStack_.pop_back(); } - Matrix4x4 GetDrawMatrix() { + Lin::Matrix4x4 GetDrawMatrix() { return drawMatrix_; } @@ -177,8 +177,8 @@ private: uint32_t rgba; }; - Matrix4x4 drawMatrix_; - std::vector drawMatrixStack_; + Lin::Matrix4x4 drawMatrix_; + std::vector drawMatrixStack_; float alpha_ = 1.0f; std::vector alphaStack_; diff --git a/ext/native/math/geom2d.h b/ext/native/math/geom2d.h index 185aaa5275..1d375fc1d6 100644 --- a/ext/native/math/geom2d.h +++ b/ext/native/math/geom2d.h @@ -3,7 +3,7 @@ #include struct Point { - Point() {} + Point() : x(0.0f), y(0.0f) {} Point(float x_, float y_) : x(x_), y(y_) {} float x; diff --git a/ext/native/math/lin/matrix4x4.cpp b/ext/native/math/lin/matrix4x4.cpp index 60d5c95898..007b8a8d17 100644 --- a/ext/native/math/lin/matrix4x4.cpp +++ b/ext/native/math/lin/matrix4x4.cpp @@ -14,6 +14,8 @@ // See http://code.google.com/p/oolongengine/source/browse/trunk/Oolong+Engine2/Math/neonmath/neon_matrix_impl.cpp?spec=svn143&r=143 when we need speed // no wait. http://code.google.com/p/math-neon/ +namespace Lin { + Matrix4x4 Matrix4x4::simpleInverse() const { Matrix4x4 out; out.xx = xx; @@ -151,7 +153,6 @@ void Matrix4x4::setViewLookAtD3D(const Vec3 &vFrom, const Vec3 &vAt, const Vec3 ww = 1.0f; } - void Matrix4x4::setViewFrame(const Vec3 &pos, const Vec3 &vRight, const Vec3 &vView, const Vec3 &vUp) { xx = vRight.x; xy = vUp.x; xz=vView.x; xw = 0.0f; yx = vRight.y; yy = vUp.y; yz=vView.y; yw = 0.0f; @@ -248,3 +249,5 @@ void Matrix4x4::print() const { toText(buffer, 256); puts(buffer); } + +} diff --git a/ext/native/math/lin/matrix4x4.h b/ext/native/math/lin/matrix4x4.h index 8d8628bc98..c9464384ad 100644 --- a/ext/native/math/lin/matrix4x4.h +++ b/ext/native/math/lin/matrix4x4.h @@ -3,6 +3,8 @@ #include "math/lin/vec3.h" +namespace Lin { + class Quaternion; class Matrix4x4 { @@ -158,5 +160,7 @@ public: } }; +} // namespace Lin + #endif // _MATH_LIN_MATRIX4X4_H diff --git a/ext/native/math/lin/plane.cpp b/ext/native/math/lin/plane.cpp index 2b14c3420d..d62277889d 100644 --- a/ext/native/math/lin/plane.cpp +++ b/ext/native/math/lin/plane.cpp @@ -1,6 +1,7 @@ #include "math/lin/matrix4x4.h" #include "math/lin/plane.h" +namespace Lin { void Plane::TransformByIT(const Matrix4x4 &m, Plane *out) { out->x = x * m.xx + y * m.yx + z * m.zx + d * m.wx; @@ -8,3 +9,5 @@ void Plane::TransformByIT(const Matrix4x4 &m, Plane *out) { out->z = x * m.xz + y * m.yz + z * m.zz + d * m.wz; out->d = x * m.xw + y * m.yw + z * m.zw + d * m.ww; } + +} // namespace Lin diff --git a/ext/native/math/lin/plane.h b/ext/native/math/lin/plane.h index f369ef1259..295c3f250a 100644 --- a/ext/native/math/lin/plane.h +++ b/ext/native/math/lin/plane.h @@ -3,6 +3,8 @@ #include "math/lin/vec3.h" +namespace Lin { + class Matrix4x4; class Plane { @@ -34,4 +36,6 @@ public: void TransformByIT(const Matrix4x4 &matrix, Plane *out); }; +} // namespace Lin + #endif diff --git a/ext/native/math/lin/quat.cpp b/ext/native/math/lin/quat.cpp index 87ce1a94c3..f5479a51f5 100644 --- a/ext/native/math/lin/quat.cpp +++ b/ext/native/math/lin/quat.cpp @@ -1,6 +1,8 @@ #include "math/lin/quat.h" #include "math/lin/matrix4x4.h" +namespace Lin { + void Quaternion::toMatrix(Matrix4x4 *out) const { Matrix4x4 temp; temp.setIdentity(); @@ -123,3 +125,5 @@ Quaternion Quaternion::multiply(const Quaternion &q) const { (w * q.z) + (z * q.w) + (x * q.y) - (y * q.x), (w * q.w) - (x * q.x) - (y * q.y) - (z * q.z)); } + +} diff --git a/ext/native/math/lin/quat.h b/ext/native/math/lin/quat.h index 85b4d94c94..8be9a94f5c 100644 --- a/ext/native/math/lin/quat.h +++ b/ext/native/math/lin/quat.h @@ -3,6 +3,8 @@ #include "math/lin/vec3.h" +namespace Lin { + class Matrix4x4; class Quaternion @@ -89,4 +91,6 @@ public: } }; +} // namespace Lin + #endif // _MATH_LIN_QUAT_H diff --git a/ext/native/math/lin/vec3.cpp b/ext/native/math/lin/vec3.cpp index aaebfc7d02..95c2469fc3 100644 --- a/ext/native/math/lin/vec3.cpp +++ b/ext/native/math/lin/vec3.cpp @@ -3,6 +3,8 @@ #include "math/lin/vec3.h" #include "math/lin/matrix4x4.h" +namespace Lin { + Vec3 Vec3::operator *(const Matrix4x4 &m) const { return Vec3(x*m.xx + y*m.yx + z*m.zx + m.wx, x*m.xy + y*m.yy + z*m.zy + m.wy, @@ -26,3 +28,5 @@ Vec3 Vec3::rotatedBy(const Matrix4x4 &m) const { x*m.xy + y*m.yy + z*m.zy, x*m.xz + y*m.yz + z*m.zz); } + +} // namespace Lin diff --git a/ext/native/math/lin/vec3.h b/ext/native/math/lin/vec3.h index cfc7d2eb89..10096153d7 100644 --- a/ext/native/math/lin/vec3.h +++ b/ext/native/math/lin/vec3.h @@ -4,6 +4,8 @@ #include #include // memset +namespace Lin { + class Matrix4x4; // Hm, doesn't belong in this file. @@ -142,4 +144,6 @@ public: Vec3 max; }; +} // namespace Lin + #endif // _MATH_LIN_VEC3 diff --git a/ext/native/thin3d/thin3d.h b/ext/native/thin3d/thin3d.h index c07b6130b5..7488e5ef47 100644 --- a/ext/native/thin3d/thin3d.h +++ b/ext/native/thin3d/thin3d.h @@ -14,7 +14,9 @@ #include "base/logging.h" #include "DataFormat.h" +namespace Lin { class Matrix4x4; +} namespace Draw { diff --git a/ext/native/ui/ui_context.cpp b/ext/native/ui/ui_context.cpp index b5f7ba204f..aa0bd024ae 100644 --- a/ext/native/ui/ui_context.cpp +++ b/ext/native/ui/ui_context.cpp @@ -222,6 +222,8 @@ void UIContext::FillRect(const UI::Drawable &drawable, const Bounds &bounds) { void UIContext::PushTransform(const UITransform &transform) { Flush(); + using namespace Lin; + Matrix4x4 m = Draw()->GetDrawMatrix(); const Vec3 &t = transform.translate; Vec3 scaledTranslate = Vec3( diff --git a/ext/native/ui/ui_context.h b/ext/native/ui/ui_context.h index d48b5b1dbf..489c0bd67d 100644 --- a/ext/native/ui/ui_context.h +++ b/ext/native/ui/ui_context.h @@ -35,8 +35,8 @@ class DrawBuffer; struct UITransform { // TODO: Or just use a matrix? - Vec3 translate; - Vec3 scale; + Lin::Vec3 translate; + Lin::Vec3 scale; float alpha; }; diff --git a/ext/native/ui/ui_screen.h b/ext/native/ui/ui_screen.h index c45c8b1329..796bd78285 100644 --- a/ext/native/ui/ui_screen.h +++ b/ext/native/ui/ui_screen.h @@ -2,9 +2,12 @@ #include +#include "math/lin/vec3.h" #include "ui/screen.h" #include "ui/viewgroup.h" +using namespace Lin; + class I18NCategory; namespace Draw { class DrawContext; From 8c2e3184168bdedc846b1ab45ea6eaaca62deb3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 24 Oct 2019 22:40:26 +0200 Subject: [PATCH 3/7] OpenGL dataformat cleanup - pass Draw::DataFormat to the GLRenderManager. Avoids triple GLenum all over the place, and also clearly shows that the mapping is wrong. --- GPU/GLES/DepalettizeShaderGLES.cpp | 6 +-- GPU/GLES/DrawEngineGLES.cpp | 16 +++--- GPU/GLES/FragmentTestCacheGLES.cpp | 2 +- GPU/GLES/FramebufferManagerGLES.cpp | 2 +- GPU/GLES/TextureCacheGLES.cpp | 82 ++++++++++++++--------------- GPU/GLES/TextureCacheGLES.h | 8 +-- GPU/GLES/TextureScalerGLES.cpp | 16 +++--- ext/native/thin3d/DataFormatGL.cpp | 7 +++ ext/native/thin3d/GLQueueRunner.cpp | 12 ++++- ext/native/thin3d/GLQueueRunner.h | 7 +-- ext/native/thin3d/GLRenderManager.h | 7 +-- ext/native/thin3d/thin3d_gl.cpp | 12 ++--- 12 files changed, 89 insertions(+), 88 deletions(-) diff --git a/GPU/GLES/DepalettizeShaderGLES.cpp b/GPU/GLES/DepalettizeShaderGLES.cpp index c973909c79..821371a794 100644 --- a/GPU/GLES/DepalettizeShaderGLES.cpp +++ b/GPU/GLES/DepalettizeShaderGLES.cpp @@ -92,17 +92,15 @@ GLRTexture *DepalShaderCacheGLES::GetClutTexture(GEPaletteFormat clutFormat, con return oldtex->second->texture; } - GLuint dstFmt = getClutDestFormat(clutFormat); + Draw::DataFormat dstFmt = getClutDestFormat(clutFormat); int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512; DepalTexture *tex = new DepalTexture(); tex->texture = render_->CreateTexture(GL_TEXTURE_2D); - GLuint components = dstFmt == GL_UNSIGNED_SHORT_5_6_5 ? GL_RGB : GL_RGBA; - GLuint components2 = components; uint8_t *clutCopy = new uint8_t[1024]; memcpy(clutCopy, rawClut, 1024); - render_->TextureImage(tex->texture, 0, texturePixels, 1, components, components2, dstFmt, clutCopy, GLRAllocType::NEW, false); + render_->TextureImage(tex->texture, 0, texturePixels, 1, dstFmt, clutCopy, GLRAllocType::NEW, false); tex->lastFrame = gpuStats.numFlips; texCache_[clutId] = tex; diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index b24be91098..a934a25790 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -669,40 +669,40 @@ void TessellationDataTransferGLES::SendDataToShader(const SimpleVertex *const *p prevSizeV = size_v; if (!data_tex[0]) data_tex[0] = renderManager_->CreateTexture(GL_TEXTURE_2D); - renderManager_->TextureImage(data_tex[0], 0, size_u * 3, size_v, GL_RGBA32F, GL_RGBA, GL_FLOAT, nullptr, GLRAllocType::NONE, false); + renderManager_->TextureImage(data_tex[0], 0, size_u * 3, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, nullptr, GLRAllocType::NONE, false); renderManager_->FinalizeTexture(data_tex[0], 0, false); } renderManager_->BindTexture(TEX_SLOT_SPLINE_POINTS, data_tex[0]); // Position - renderManager_->TextureSubImage(data_tex[0], 0, 0, 0, size_u, size_v, GL_RGBA, GL_FLOAT, (u8 *)pos, GLRAllocType::NEW); + renderManager_->TextureSubImage(data_tex[0], 0, 0, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)pos, GLRAllocType::NEW); // Texcoord if (hasTexCoord) - renderManager_->TextureSubImage(data_tex[0], 0, size_u, 0, size_u, size_v, GL_RGBA, GL_FLOAT, (u8 *)tex, GLRAllocType::NEW); + renderManager_->TextureSubImage(data_tex[0], 0, size_u, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)tex, GLRAllocType::NEW); // Color if (hasColor) - renderManager_->TextureSubImage(data_tex[0], 0, size_u * 2, 0, size_u, size_v, GL_RGBA, GL_FLOAT, (u8 *)col, GLRAllocType::NEW); + renderManager_->TextureSubImage(data_tex[0], 0, size_u * 2, 0, size_u, size_v, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)col, GLRAllocType::NEW); // Weight U if (prevSizeWU < weights.size_u) { prevSizeWU = weights.size_u; if (!data_tex[1]) data_tex[1] = renderManager_->CreateTexture(GL_TEXTURE_2D); - renderManager_->TextureImage(data_tex[1], 0, weights.size_u * 2, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, nullptr, GLRAllocType::NONE, false); + renderManager_->TextureImage(data_tex[1], 0, weights.size_u * 2, 1, Draw::DataFormat::R32G32B32A32_FLOAT, nullptr, GLRAllocType::NONE, false); renderManager_->FinalizeTexture(data_tex[1], 0, false); } renderManager_->BindTexture(TEX_SLOT_SPLINE_WEIGHTS_U, data_tex[1]); - renderManager_->TextureSubImage(data_tex[1], 0, 0, 0, weights.size_u * 2, 1, GL_RGBA, GL_FLOAT, (u8 *)weights.u, GLRAllocType::NONE); + renderManager_->TextureSubImage(data_tex[1], 0, 0, 0, weights.size_u * 2, 1, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)weights.u, GLRAllocType::NONE); // Weight V if (prevSizeWV < weights.size_v) { prevSizeWV = weights.size_v; if (!data_tex[2]) data_tex[2] = renderManager_->CreateTexture(GL_TEXTURE_2D); - renderManager_->TextureImage(data_tex[2], 0, weights.size_v * 2, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, nullptr, GLRAllocType::NONE, false); + renderManager_->TextureImage(data_tex[2], 0, weights.size_v * 2, 1, Draw::DataFormat::R32G32B32A32_FLOAT, nullptr, GLRAllocType::NONE, false); renderManager_->FinalizeTexture(data_tex[2], 0, false); } renderManager_->BindTexture(TEX_SLOT_SPLINE_WEIGHTS_V, data_tex[2]); - renderManager_->TextureSubImage(data_tex[2], 0, 0, 0, weights.size_v * 2, 1, GL_RGBA, GL_FLOAT, (u8 *)weights.v, GLRAllocType::NONE); + renderManager_->TextureSubImage(data_tex[2], 0, 0, 0, weights.size_v * 2, 1, Draw::DataFormat::R32G32B32A32_FLOAT, (u8 *)weights.v, GLRAllocType::NONE); } void TessellationDataTransferGLES::EndFrame() { diff --git a/GPU/GLES/FragmentTestCacheGLES.cpp b/GPU/GLES/FragmentTestCacheGLES.cpp index e870426ffd..a9459cd49a 100644 --- a/GPU/GLES/FragmentTestCacheGLES.cpp +++ b/GPU/GLES/FragmentTestCacheGLES.cpp @@ -145,7 +145,7 @@ GLRTexture *FragmentTestCacheGLES::CreateTestTexture(const GEComparison funcs[4] } GLRTexture *tex = render_->CreateTexture(GL_TEXTURE_2D); - render_->TextureImage(tex, 0, 256, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, data); + render_->TextureImage(tex, 0, 256, 1, Draw::DataFormat::R8G8B8A8_UNORM, data); return tex; } diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index b2d814bb05..cd9bb696f2 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -379,7 +379,7 @@ void FramebufferManagerGLES::MakePixelTexture(const u8 *srcPixels, GEBufferForma break; } } - render_->TextureImage(drawPixelsTex_, 0, width, height, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, convBuf, GLRAllocType::NEW, false); + render_->TextureImage(drawPixelsTex_, 0, width, height, Draw::DataFormat::R8G8B8A8_UNORM, convBuf, GLRAllocType::NEW, false); render_->FinalizeTexture(drawPixelsTex_, 0, false); // TODO: Return instead? diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 9bfc2a6cfa..410f50ea05 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -86,18 +86,18 @@ void TextureCacheGLES::Clear(bool delete_them) { TextureCacheCommon::Clear(delete_them); } -GLenum getClutDestFormat(GEPaletteFormat format) { +Draw::DataFormat getClutDestFormat(GEPaletteFormat format) { switch (format) { case GE_CMODE_16BIT_ABGR4444: - return GL_UNSIGNED_SHORT_4_4_4_4; + return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; case GE_CMODE_16BIT_ABGR5551: - return GL_UNSIGNED_SHORT_5_5_5_1; + return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; case GE_CMODE_16BIT_BGR5650: - return GL_UNSIGNED_SHORT_5_6_5; + return Draw::DataFormat::B5G6R5_UNORM_PACK16; case GE_CMODE_32BIT_ABGR8888: - return GL_UNSIGNED_BYTE; + return Draw::DataFormat::R8G8B8A8_UNORM; } - return 0; + return Draw::DataFormat::UNDEFINED;; } static const GLuint MinFiltGL[8] = { @@ -188,18 +188,18 @@ void TextureCacheGLES::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferH render_->SetTextureSampler(TEX_SLOT_PSP_TEXTURE, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso); } -static void ConvertColors(void *dstBuf, const void *srcBuf, GLuint dstFmt, int numPixels) { +static void ConvertColors(void *dstBuf, const void *srcBuf, Draw::DataFormat dstFmt, int numPixels) { const u32 *src = (const u32 *)srcBuf; u32 *dst = (u32 *)dstBuf; switch (dstFmt) { - case GL_UNSIGNED_SHORT_4_4_4_4: + case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: ConvertRGBA4444ToABGR4444((u16 *)dst, (const u16 *)src, numPixels); break; // Final Fantasy 2 uses this heavily in animated textures. - case GL_UNSIGNED_SHORT_5_5_5_1: + case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: ConvertRGBA5551ToABGR1555((u16 *)dst, (const u16 *)src, numPixels); break; - case GL_UNSIGNED_SHORT_5_6_5: + case Draw::DataFormat::B5G6R5_UNORM_PACK16: ConvertRGB565ToBGR565((u16 *)dst, (const u16 *)src, numPixels); break; default: @@ -514,22 +514,22 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE); } -ReplacedTextureFormat FromGLESFormat(GLenum fmt) { +ReplacedTextureFormat FromDataFormat(Draw::DataFormat fmt) { // TODO: 16-bit formats are incorrect, since swizzled. switch (fmt) { - case GL_UNSIGNED_SHORT_5_6_5: return ReplacedTextureFormat::F_0565_ABGR; - case GL_UNSIGNED_SHORT_5_5_5_1: return ReplacedTextureFormat::F_1555_ABGR; - case GL_UNSIGNED_SHORT_4_4_4_4: return ReplacedTextureFormat::F_4444_ABGR; - case GL_UNSIGNED_BYTE: default: return ReplacedTextureFormat::F_8888; + case Draw::DataFormat::B5G6R5_UNORM_PACK16: return ReplacedTextureFormat::F_0565_ABGR; + case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: return ReplacedTextureFormat::F_1555_ABGR; + case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: return ReplacedTextureFormat::F_4444_ABGR; + case Draw::DataFormat::R8G8B8A8_UNORM: default: return ReplacedTextureFormat::F_8888; } } -GLenum ToGLESFormat(ReplacedTextureFormat fmt) { +Draw::DataFormat ToDataFormat(ReplacedTextureFormat fmt) { switch (fmt) { - case ReplacedTextureFormat::F_5650: return GL_UNSIGNED_SHORT_5_6_5; - case ReplacedTextureFormat::F_5551: return GL_UNSIGNED_SHORT_5_5_5_1; - case ReplacedTextureFormat::F_4444: return GL_UNSIGNED_SHORT_4_4_4_4; - case ReplacedTextureFormat::F_8888: default: return GL_UNSIGNED_BYTE; + case ReplacedTextureFormat::F_5650: return Draw::DataFormat::B5G6R5_UNORM_PACK16; + case ReplacedTextureFormat::F_5551: return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; + case ReplacedTextureFormat::F_4444: return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + case ReplacedTextureFormat::F_8888: default: return Draw::DataFormat::R8G8B8A8_UNORM; } } @@ -592,7 +592,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { } // If GLES3 is available, we can preallocate the storage, which makes texture loading more efficient. - GLenum dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); + Draw::DataFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); int scaleFactor = standardScaleFactor_; @@ -700,7 +700,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { UpdateSamplingParams(*entry, true); } -GLenum TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const { +Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const { switch (format) { case GE_TFMT_CLUT4: case GE_TFMT_CLUT8: @@ -708,30 +708,30 @@ GLenum TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat c case GE_TFMT_CLUT32: return getClutDestFormat(clutFormat); case GE_TFMT_4444: - return GL_UNSIGNED_SHORT_4_4_4_4; + return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; case GE_TFMT_5551: - return GL_UNSIGNED_SHORT_5_5_5_1; + return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; case GE_TFMT_5650: - return GL_UNSIGNED_SHORT_5_6_5; + return Draw::DataFormat::B5G6R5_UNORM_PACK16; case GE_TFMT_8888: case GE_TFMT_DXT1: case GE_TFMT_DXT3: case GE_TFMT_DXT5: default: - return GL_UNSIGNED_BYTE; + return Draw::DataFormat::R8G8B8A8_UNORM; } } -TexCacheEntry::TexStatus TextureCacheGLES::CheckAlpha(const uint8_t *pixelData, GLenum dstFmt, int stride, int w, int h) { +TexCacheEntry::TexStatus TextureCacheGLES::CheckAlpha(const uint8_t *pixelData, Draw::DataFormat dstFmt, int stride, int w, int h) { CheckAlphaResult res; switch (dstFmt) { - case GL_UNSIGNED_SHORT_4_4_4_4: + case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: res = CheckAlphaABGR4444Basic((const uint32_t *)pixelData, stride, w, h); break; - case GL_UNSIGNED_SHORT_5_5_5_1: + case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: res = CheckAlphaABGR1555Basic((const uint32_t *)pixelData, stride, w, h); break; - case GL_UNSIGNED_SHORT_5_6_5: + case Draw::DataFormat::B5G6R5_UNORM_PACK16: // Never has any alpha. res = CHECKALPHA_FULL; break; @@ -743,7 +743,7 @@ TexCacheEntry::TexStatus TextureCacheGLES::CheckAlpha(const uint8_t *pixelData, return (TexCacheEntry::TexStatus)res; } -void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int scaleFactor, GLenum dstFmt) { +void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int scaleFactor, Draw::DataFormat dstFmt) { int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); uint8_t *pixelData; @@ -760,7 +760,7 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r replaced.Load(level, rearrange, decPitch); pixelData = rearrange; - dstFmt = ToGLESFormat(replaced.Format(level)); + dstFmt = ToDataFormat(replaced.Format(level)); } else { PROFILE_THIS_SCOPE("decodetex"); @@ -768,7 +768,7 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r u32 texaddr = gstate.getTextureAddress(level); int bufw = GetTextureBufw(level, texaddr, GETextureFormat(entry.format)); - int pixelSize = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2; + int pixelSize = dstFmt == Draw::DataFormat::R8G8B8A8_UNORM ? 4 : 2; // We leave GL_UNPACK_ALIGNMENT at 4, so this must be at least 4. decPitch = std::max(w * pixelSize, 4); @@ -785,7 +785,9 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r if (scaleFactor > 1) { uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16); - scaler.ScaleAlways((u32 *)rearrange, (u32 *)pixelData, dstFmt, w, h, scaleFactor); + u32 dFmt = (u32)dstFmt; + scaler.ScaleAlways((u32 *)rearrange, (u32 *)pixelData, dFmt, w, h, scaleFactor); + dstFmt = (Draw::DataFormat)dFmt; FreeAlignedMemory(pixelData); pixelData = rearrange; decPitch = w * 4; @@ -799,21 +801,17 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r replacedInfo.isVideo = videos_.find(entry.addr & 0x3FFFFFFF) != videos_.end(); replacedInfo.isFinal = (entry.status & TexCacheEntry::STATUS_TO_SCALE) == 0; replacedInfo.scaleFactor = scaleFactor; - replacedInfo.fmt = FromGLESFormat(dstFmt); + replacedInfo.fmt = FromDataFormat(dstFmt); replacer_.NotifyTextureDecoded(replacedInfo, pixelData, decPitch, level, w, h); } } - - GLuint components = dstFmt == GL_UNSIGNED_SHORT_5_6_5 ? GL_RGB : GL_RGBA; - - GLuint components2 = components; - + PROFILE_THIS_SCOPE("loadtex"); if (IsFakeMipmapChange()) - render_->TextureImage(entry.textureName, 0, w, h, components, components2, dstFmt, pixelData, GLRAllocType::ALIGNED); + render_->TextureImage(entry.textureName, 0, w, h, dstFmt, pixelData, GLRAllocType::ALIGNED); else - render_->TextureImage(entry.textureName, level, w, h, components, components2, dstFmt, pixelData, GLRAllocType::ALIGNED); + render_->TextureImage(entry.textureName, level, w, h, dstFmt, pixelData, GLRAllocType::ALIGNED); } bool TextureCacheGLES::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index be60d7eb77..abb4d2d2fb 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -76,10 +76,10 @@ protected: private: void UpdateSamplingParams(TexCacheEntry &entry, bool force); - void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int scaleFactor, GLenum dstFmt); - GLenum GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; + void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int scaleFactor, Draw::DataFormat dstFmt); + Draw::DataFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; - TexCacheEntry::TexStatus CheckAlpha(const uint8_t *pixelData, GLenum dstFmt, int stride, int w, int h); + TexCacheEntry::TexStatus CheckAlpha(const uint8_t *pixelData, Draw::DataFormat dstFmt, int stride, int w, int h); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override; void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) override; @@ -101,4 +101,4 @@ private: enum { INVALID_TEX = -1 }; }; -GLenum getClutDestFormat(GEPaletteFormat format); +Draw::DataFormat getClutDestFormat(GEPaletteFormat format); diff --git a/GPU/GLES/TextureScalerGLES.cpp b/GPU/GLES/TextureScalerGLES.cpp index d73c2ce944..4d2ae06366 100644 --- a/GPU/GLES/TextureScalerGLES.cpp +++ b/GPU/GLES/TextureScalerGLES.cpp @@ -28,30 +28,32 @@ #include "Common/ColorConv.h" #include "Common/Log.h" #include "Common/ThreadPools.h" +#include "thin3d/DataFormat.h" int TextureScalerGLES::BytesPerPixel(u32 format) { - return (format == GL_UNSIGNED_BYTE) ? 4 : 2; + return ((Draw::DataFormat)format == Draw::DataFormat::R8G8B8A8_UNORM) ? 4 : 2; } u32 TextureScalerGLES::Get8888Format() { - return GL_UNSIGNED_BYTE; + return (u32)Draw::DataFormat::R8G8B8A8_UNORM; } void TextureScalerGLES::ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) { - switch(format) { - case GL_UNSIGNED_BYTE: + Draw::DataFormat fmt = (Draw::DataFormat)format; + switch (fmt) { + case Draw::DataFormat::R8G8B8A8_UNORM: dest = source; // already fine break; - case GL_UNSIGNED_SHORT_4_4_4_4: + case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert4444_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; - case GL_UNSIGNED_SHORT_5_6_5: + case Draw::DataFormat::B5G6R5_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert565_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; - case GL_UNSIGNED_SHORT_5_5_5_1: + case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert5551_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; diff --git a/ext/native/thin3d/DataFormatGL.cpp b/ext/native/thin3d/DataFormatGL.cpp index 5d48f15868..b9d6c5a9a3 100644 --- a/ext/native/thin3d/DataFormatGL.cpp +++ b/ext/native/thin3d/DataFormatGL.cpp @@ -57,6 +57,13 @@ bool Thin3DFormatToFormatAndType(DataFormat fmt, GLuint &internalFormat, GLuint alignment = 2; break; + case DataFormat::R32G32B32A32_FLOAT: + internalFormat = GL_RGBA32F; + format = GL_RGBA; + type = GL_FLOAT; + alignment = 16; + break; + #ifndef USING_GLES2 case DataFormat::A4R4G4B4_UNORM_PACK16: internalFormat = GL_RGBA; diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index 90540eb90a..e42101798b 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -9,6 +9,7 @@ #include "gfx/gl_common.h" #include "gfx/gl_debug_log.h" #include "gfx_es2/gpu_features.h" +#include "thin3d/DataFormatGL.h" #include "math/dataconv.h" #include "math/math_util.h" @@ -315,7 +316,11 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps, bool ski if (!step.texture_image.data && step.texture_image.allocType != GLRAllocType::NONE) Crash(); // For things to show in RenderDoc, need to split into glTexImage2D(..., nullptr) and glTexSubImage. - glTexImage2D(tex->target, step.texture_image.level, step.texture_image.internalFormat, step.texture_image.width, step.texture_image.height, 0, step.texture_image.format, step.texture_image.type, step.texture_image.data); + + GLenum internalFormat, format, type; + int alignment; + Thin3DFormatToFormatAndType(step.texture_image.format, internalFormat, format, type, alignment); + glTexImage2D(tex->target, step.texture_image.level, internalFormat, step.texture_image.width, step.texture_image.height, 0, format, type, step.texture_image.data); allocatedTextures = true; if (step.texture_image.allocType == GLRAllocType::ALIGNED) { FreeAlignedMemory(step.texture_image.data); @@ -1110,7 +1115,10 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { if (!c.texture_subimage.data) Crash(); // For things to show in RenderDoc, need to split into glTexImage2D(..., nullptr) and glTexSubImage. - glTexSubImage2D(tex->target, c.texture_subimage.level, c.texture_subimage.x, c.texture_subimage.y, c.texture_subimage.width, c.texture_subimage.height, c.texture_subimage.format, c.texture_subimage.type, c.texture_subimage.data); + GLuint internalFormat, format, type; + int alignment; + Thin3DFormatToFormatAndType(c.texture_subimage.format, internalFormat, format, type, alignment); + glTexSubImage2D(tex->target, c.texture_subimage.level, c.texture_subimage.x, c.texture_subimage.y, c.texture_subimage.width, c.texture_subimage.height, format, type, c.texture_subimage.data); if (c.texture_subimage.allocType == GLRAllocType::ALIGNED) { FreeAlignedMemory(c.texture_subimage.data); } else if (c.texture_subimage.allocType == GLRAllocType::NEW) { diff --git a/ext/native/thin3d/GLQueueRunner.h b/ext/native/thin3d/GLQueueRunner.h index b7a1586d59..41bceedb20 100644 --- a/ext/native/thin3d/GLQueueRunner.h +++ b/ext/native/thin3d/GLQueueRunner.h @@ -142,8 +142,7 @@ struct GLRRenderData { } texture; struct { GLRTexture *texture; - GLenum format; - GLenum type; + Draw::DataFormat format; int level; int x; int y; @@ -254,9 +253,7 @@ struct GLRInitStep { } buffer_subdata; struct { GLRTexture *texture; - GLenum internalFormat; - GLenum format; - GLenum type; + Draw::DataFormat format; int level; int width; int height; diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index 7fa35e8231..d7d6f54b76 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -525,13 +525,11 @@ public: } // Takes ownership over the data pointer and delete[]-s it. - void TextureImage(GLRTexture *texture, int level, int width, int height, GLenum internalFormat, GLenum format, GLenum type, uint8_t *data, GLRAllocType allocType = GLRAllocType::NEW, bool linearFilter = false) { + void TextureImage(GLRTexture *texture, int level, int width, int height, Draw::DataFormat format, uint8_t *data, GLRAllocType allocType = GLRAllocType::NEW, bool linearFilter = false) { GLRInitStep step{ GLRInitStepType::TEXTURE_IMAGE }; step.texture_image.texture = texture; step.texture_image.data = data; - step.texture_image.internalFormat = internalFormat; step.texture_image.format = format; - step.texture_image.type = type; step.texture_image.level = level; step.texture_image.width = width; step.texture_image.height = height; @@ -540,13 +538,12 @@ public: initSteps_.push_back(step); } - void TextureSubImage(GLRTexture *texture, int level, int x, int y, int width, int height, GLenum format, GLenum type, uint8_t *data, GLRAllocType allocType = GLRAllocType::NEW) { + void TextureSubImage(GLRTexture *texture, int level, int x, int y, int width, int height, Draw::DataFormat format, uint8_t *data, GLRAllocType allocType = GLRAllocType::NEW) { _dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); GLRRenderData _data{ GLRRenderCommand::TEXTURE_SUBIMAGE }; _data.texture_subimage.texture = texture; _data.texture_subimage.data = data; _data.texture_subimage.format = format; - _data.texture_subimage.type = type; _data.texture_subimage.level = level; _data.texture_subimage.x = x; _data.texture_subimage.y = y; diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index c570611fcd..d7387f9c95 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -726,23 +726,17 @@ void OpenGLTexture::SetImageData(int x, int y, int z, int width, int height, int depth_ = depth; } - GLuint internalFormat; - GLuint format; - GLuint type; - int alignment; - if (!Thin3DFormatToFormatAndType(format_, internalFormat, format, type, alignment)) { - return; - } - if (stride == 0) stride = width; + + size_t alignment = DataFormatSizeInBytes(format_); // Make a copy of data with stride eliminated. uint8_t *texData = new uint8_t[(size_t)(width * height * alignment)]; for (int y = 0; y < height; y++) { memcpy(texData + y * width * alignment, data + y * stride * alignment, width * alignment); } - render_->TextureImage(tex_, level, width, height, internalFormat, format, type, texData); + render_->TextureImage(tex_, level, width, height, format_, texData); } #ifdef DEBUG_READ_PIXELS From fcfeda653d227d1cf07411eb7408d381eaa649e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 24 Oct 2019 22:47:22 +0200 Subject: [PATCH 4/7] Reduce GL texture format support to the ES minimum. We have to handle these anyway so let's only have one path. --- ext/native/thin3d/DataFormatGL.cpp | 23 ----------------------- ext/native/thin3d/thin3d_gl.cpp | 6 ++---- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/ext/native/thin3d/DataFormatGL.cpp b/ext/native/thin3d/DataFormatGL.cpp index b9d6c5a9a3..3c7c3f82c5 100644 --- a/ext/native/thin3d/DataFormatGL.cpp +++ b/ext/native/thin3d/DataFormatGL.cpp @@ -64,29 +64,6 @@ bool Thin3DFormatToFormatAndType(DataFormat fmt, GLuint &internalFormat, GLuint alignment = 16; break; -#ifndef USING_GLES2 - case DataFormat::A4R4G4B4_UNORM_PACK16: - internalFormat = GL_RGBA; - format = GL_RGBA; - type = GL_UNSIGNED_SHORT_4_4_4_4_REV; - alignment = 2; - break; - - case DataFormat::R5G6B5_UNORM_PACK16: - internalFormat = GL_RGB; - format = GL_RGB; - type = GL_UNSIGNED_SHORT_5_6_5_REV; - alignment = 2; - break; - - case DataFormat::A1R5G5B5_UNORM_PACK16: - internalFormat = GL_RGBA; - format = GL_RGBA; - type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - alignment = 2; - break; -#endif - default: return false; } diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index d7387f9c95..7593c1b21c 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -1213,12 +1213,10 @@ void OpenGLContext::GetFramebufferDimensions(Framebuffer *fbo, int *w, int *h) { uint32_t OpenGLContext::GetDataFormatSupport(DataFormat fmt) const { switch (fmt) { case DataFormat::B8G8R8A8_UNORM: - return FMT_RENDERTARGET | FMT_TEXTURE | FMT_AUTOGEN_MIPS; case DataFormat::B4G4R4A4_UNORM_PACK16: + case DataFormat::B5G6R5_UNORM_PACK16: + case DataFormat::B5G5R5A1_UNORM_PACK16: return FMT_RENDERTARGET | FMT_TEXTURE | FMT_AUTOGEN_MIPS; // native support - case DataFormat::A4R4G4B4_UNORM_PACK16: - // Can support this if _REV formats are supported. - return gl_extensions.IsGLES ? 0 : FMT_TEXTURE; case DataFormat::R8G8B8A8_UNORM: return FMT_RENDERTARGET | FMT_TEXTURE | FMT_INPUTLAYOUT | FMT_AUTOGEN_MIPS; From 9e607fdeb11075108bebd0be2cebc7af446125c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 24 Oct 2019 22:49:36 +0200 Subject: [PATCH 5/7] GL: remove another unused format --- ext/native/thin3d/thin3d_gl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 7593c1b21c..04e5c5ba4f 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -1212,7 +1212,6 @@ void OpenGLContext::GetFramebufferDimensions(Framebuffer *fbo, int *w, int *h) { uint32_t OpenGLContext::GetDataFormatSupport(DataFormat fmt) const { switch (fmt) { - case DataFormat::B8G8R8A8_UNORM: case DataFormat::B4G4R4A4_UNORM_PACK16: case DataFormat::B5G6R5_UNORM_PACK16: case DataFormat::B5G5R5A1_UNORM_PACK16: From 46447c9e90b845a49aa310defc497eee84d3fce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 24 Oct 2019 23:01:45 +0200 Subject: [PATCH 6/7] Correct the wrong GL DataFormat enums --- Common/ColorConv.h | 3 +++ GPU/GLES/TextureCacheGLES.cpp | 36 ++++++++++++++-------------- GPU/GLES/TextureScalerGLES.cpp | 6 ++--- ext/native/gfx_es2/draw_text_win.cpp | 4 +++- ext/native/thin3d/DataFormatGL.cpp | 6 ++--- ext/native/thin3d/thin3d_gl.cpp | 6 ++--- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Common/ColorConv.h b/Common/ColorConv.h index 3947f8bf52..485bea2ac4 100644 --- a/Common/ColorConv.h +++ b/Common/ColorConv.h @@ -107,6 +107,9 @@ void convert5551_dx9(u16* data, u32* out, int width, int l, int u); // "Complete" set of color conversion functions between the usual formats. +// TODO: Need to revisit the naming convention of these. Seems totally backwards +// now that we've standardized on Draw::DataFormat. + typedef void (*Convert16bppTo16bppFunc)(u16 *dst, const u16 *src, u32 numPixels); typedef void (*Convert16bppTo32bppFunc)(u32 *dst, const u16 *src, u32 numPixels); typedef void (*Convert32bppTo16bppFunc)(u16 *dst, const u32 *src, u32 numPixels); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 410f50ea05..c326123a5a 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -89,11 +89,11 @@ void TextureCacheGLES::Clear(bool delete_them) { Draw::DataFormat getClutDestFormat(GEPaletteFormat format) { switch (format) { case GE_CMODE_16BIT_ABGR4444: - return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + return Draw::DataFormat::R4G4B4A4_UNORM_PACK16; case GE_CMODE_16BIT_ABGR5551: - return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; + return Draw::DataFormat::R5G5B5A1_UNORM_PACK16; case GE_CMODE_16BIT_BGR5650: - return Draw::DataFormat::B5G6R5_UNORM_PACK16; + return Draw::DataFormat::R5G6B5_UNORM_PACK16; case GE_CMODE_32BIT_ABGR8888: return Draw::DataFormat::R8G8B8A8_UNORM; } @@ -192,14 +192,14 @@ static void ConvertColors(void *dstBuf, const void *srcBuf, Draw::DataFormat dst const u32 *src = (const u32 *)srcBuf; u32 *dst = (u32 *)dstBuf; switch (dstFmt) { - case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: + case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: ConvertRGBA4444ToABGR4444((u16 *)dst, (const u16 *)src, numPixels); break; // Final Fantasy 2 uses this heavily in animated textures. - case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: + case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: ConvertRGBA5551ToABGR1555((u16 *)dst, (const u16 *)src, numPixels); break; - case Draw::DataFormat::B5G6R5_UNORM_PACK16: + case Draw::DataFormat::R5G6B5_UNORM_PACK16: ConvertRGB565ToBGR565((u16 *)dst, (const u16 *)src, numPixels); break; default: @@ -517,18 +517,18 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram ReplacedTextureFormat FromDataFormat(Draw::DataFormat fmt) { // TODO: 16-bit formats are incorrect, since swizzled. switch (fmt) { - case Draw::DataFormat::B5G6R5_UNORM_PACK16: return ReplacedTextureFormat::F_0565_ABGR; - case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: return ReplacedTextureFormat::F_1555_ABGR; - case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: return ReplacedTextureFormat::F_4444_ABGR; + case Draw::DataFormat::R5G6B5_UNORM_PACK16: return ReplacedTextureFormat::F_0565_ABGR; + case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: return ReplacedTextureFormat::F_1555_ABGR; + case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: return ReplacedTextureFormat::F_4444_ABGR; case Draw::DataFormat::R8G8B8A8_UNORM: default: return ReplacedTextureFormat::F_8888; } } Draw::DataFormat ToDataFormat(ReplacedTextureFormat fmt) { switch (fmt) { - case ReplacedTextureFormat::F_5650: return Draw::DataFormat::B5G6R5_UNORM_PACK16; - case ReplacedTextureFormat::F_5551: return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; - case ReplacedTextureFormat::F_4444: return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + case ReplacedTextureFormat::F_5650: return Draw::DataFormat::R5G6B5_UNORM_PACK16; + case ReplacedTextureFormat::F_5551: return Draw::DataFormat::R5G5B5A1_UNORM_PACK16; + case ReplacedTextureFormat::F_4444: return Draw::DataFormat::R4G4B4A4_UNORM_PACK16; case ReplacedTextureFormat::F_8888: default: return Draw::DataFormat::R8G8B8A8_UNORM; } } @@ -708,11 +708,11 @@ Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPalet case GE_TFMT_CLUT32: return getClutDestFormat(clutFormat); case GE_TFMT_4444: - return Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + return Draw::DataFormat::R4G4B4A4_UNORM_PACK16; case GE_TFMT_5551: - return Draw::DataFormat::B5G5R5A1_UNORM_PACK16; + return Draw::DataFormat::R5G5B5A1_UNORM_PACK16; case GE_TFMT_5650: - return Draw::DataFormat::B5G6R5_UNORM_PACK16; + return Draw::DataFormat::R5G6B5_UNORM_PACK16; case GE_TFMT_8888: case GE_TFMT_DXT1: case GE_TFMT_DXT3: @@ -725,13 +725,13 @@ Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPalet TexCacheEntry::TexStatus TextureCacheGLES::CheckAlpha(const uint8_t *pixelData, Draw::DataFormat dstFmt, int stride, int w, int h) { CheckAlphaResult res; switch (dstFmt) { - case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: + case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: res = CheckAlphaABGR4444Basic((const uint32_t *)pixelData, stride, w, h); break; - case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: + case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: res = CheckAlphaABGR1555Basic((const uint32_t *)pixelData, stride, w, h); break; - case Draw::DataFormat::B5G6R5_UNORM_PACK16: + case Draw::DataFormat::R5G6B5_UNORM_PACK16: // Never has any alpha. res = CHECKALPHA_FULL; break; diff --git a/GPU/GLES/TextureScalerGLES.cpp b/GPU/GLES/TextureScalerGLES.cpp index 4d2ae06366..73c1b849a7 100644 --- a/GPU/GLES/TextureScalerGLES.cpp +++ b/GPU/GLES/TextureScalerGLES.cpp @@ -45,15 +45,15 @@ void TextureScalerGLES::ConvertTo8888(u32 format, u32* source, u32* &dest, int w dest = source; // already fine break; - case Draw::DataFormat::B4G4R4A4_UNORM_PACK16: + case Draw::DataFormat::R4G4B4A4_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert4444_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; - case Draw::DataFormat::B5G6R5_UNORM_PACK16: + case Draw::DataFormat::R5G6B5_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert565_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; - case Draw::DataFormat::B5G5R5A1_UNORM_PACK16: + case Draw::DataFormat::R5G5B5A1_UNORM_PACK16: GlobalThreadPool::Loop(std::bind(&convert5551_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height); break; diff --git a/ext/native/gfx_es2/draw_text_win.cpp b/ext/native/gfx_es2/draw_text_win.cpp index aaa3b1d859..a84ac84473 100644 --- a/ext/native/gfx_es2/draw_text_win.cpp +++ b/ext/native/gfx_es2/draw_text_win.cpp @@ -258,6 +258,8 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f texFormat = Draw::DataFormat::A4R4G4B4_UNORM_PACK16; else if (draw_->GetDataFormatSupport(Draw::DataFormat::B4G4R4A4_UNORM_PACK16) & FMT_TEXTURE) texFormat = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + else if (draw_->GetDataFormatSupport(Draw::DataFormat::R4G4B4A4_UNORM_PACK16) & FMT_TEXTURE) + texFormat = Draw::DataFormat::R4G4B4A4_UNORM_PACK16; else texFormat = Draw::DataFormat::R8G8B8A8_UNORM; @@ -275,7 +277,7 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f } } desc.initData.push_back((uint8_t *)bitmapData32); - } else if (texFormat == Draw::DataFormat::B4G4R4A4_UNORM_PACK16) { + } else if (texFormat == Draw::DataFormat::B4G4R4A4_UNORM_PACK16 || texFormat == Draw::DataFormat::R4G4B4A4_UNORM_PACK16) { bitmapData16 = new uint16_t[entry->bmWidth * entry->bmHeight]; for (int y = 0; y < entry->bmHeight; y++) { for (int x = 0; x < entry->bmWidth; x++) { diff --git a/ext/native/thin3d/DataFormatGL.cpp b/ext/native/thin3d/DataFormatGL.cpp index 3c7c3f82c5..b3a8092abf 100644 --- a/ext/native/thin3d/DataFormatGL.cpp +++ b/ext/native/thin3d/DataFormatGL.cpp @@ -36,21 +36,21 @@ bool Thin3DFormatToFormatAndType(DataFormat fmt, GLuint &internalFormat, GLuint alignment = 1; break; - case DataFormat::B4G4R4A4_UNORM_PACK16: + case DataFormat::R4G4B4A4_UNORM_PACK16: internalFormat = GL_RGBA; format = GL_RGBA; type = GL_UNSIGNED_SHORT_4_4_4_4; alignment = 2; break; - case DataFormat::B5G6R5_UNORM_PACK16: + case DataFormat::R5G6B5_UNORM_PACK16: internalFormat = GL_RGB; format = GL_RGB; type = GL_UNSIGNED_SHORT_5_6_5; alignment = 2; break; - case DataFormat::B5G5R5A1_UNORM_PACK16: + case DataFormat::R5G5B5A1_UNORM_PACK16: internalFormat = GL_RGBA; format = GL_RGBA; type = GL_UNSIGNED_SHORT_5_5_5_1; diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 04e5c5ba4f..d31e63f892 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -1212,9 +1212,9 @@ void OpenGLContext::GetFramebufferDimensions(Framebuffer *fbo, int *w, int *h) { uint32_t OpenGLContext::GetDataFormatSupport(DataFormat fmt) const { switch (fmt) { - case DataFormat::B4G4R4A4_UNORM_PACK16: - case DataFormat::B5G6R5_UNORM_PACK16: - case DataFormat::B5G5R5A1_UNORM_PACK16: + case DataFormat::R4G4B4A4_UNORM_PACK16: + case DataFormat::R5G6B5_UNORM_PACK16: + case DataFormat::R5G5B5A1_UNORM_PACK16: return FMT_RENDERTARGET | FMT_TEXTURE | FMT_AUTOGEN_MIPS; // native support case DataFormat::R8G8B8A8_UNORM: From 4d6a4beae1f6bb6586d247665c583196adc84aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 24 Oct 2019 23:07:57 +0200 Subject: [PATCH 7/7] Text drawing fixes --- ext/native/gfx_es2/draw_text_android.cpp | 2 +- ext/native/gfx_es2/draw_text_qt.cpp | 2 +- ext/native/gfx_es2/draw_text_win.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/native/gfx_es2/draw_text_android.cpp b/ext/native/gfx_es2/draw_text_android.cpp index a1d453f7ed..b2e15e86e3 100644 --- a/ext/native/gfx_es2/draw_text_android.cpp +++ b/ext/native/gfx_es2/draw_text_android.cpp @@ -201,7 +201,7 @@ void TextDrawerAndroid::DrawString(DrawBuffer &target, const char *str, float x, TextureDesc desc{}; desc.type = TextureType::LINEAR2D; - desc.format = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + desc.format = Draw::DataFormat::R4G4B4A4_UNORM_PACK16; desc.width = entry->bmWidth; desc.height = entry->bmHeight; desc.depth = 1; diff --git a/ext/native/gfx_es2/draw_text_qt.cpp b/ext/native/gfx_es2/draw_text_qt.cpp index a29b363397..41d4009d3a 100644 --- a/ext/native/gfx_es2/draw_text_qt.cpp +++ b/ext/native/gfx_es2/draw_text_qt.cpp @@ -105,7 +105,7 @@ void TextDrawerQt::DrawString(DrawBuffer &target, const char *str, float x, floa TextureDesc desc{}; desc.type = TextureType::LINEAR2D; - desc.format = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + desc.format = Draw::DataFormat::R4G4B4A4_UNORM_PACK16; desc.width = entry->bmWidth; desc.height = entry->bmHeight; desc.depth = 1; diff --git a/ext/native/gfx_es2/draw_text_win.cpp b/ext/native/gfx_es2/draw_text_win.cpp index a84ac84473..f6c1113d5f 100644 --- a/ext/native/gfx_es2/draw_text_win.cpp +++ b/ext/native/gfx_es2/draw_text_win.cpp @@ -256,10 +256,10 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f // For our purposes these are equivalent, so just choose the supported one. D3D can emulate them. if (draw_->GetDataFormatSupport(Draw::DataFormat::A4R4G4B4_UNORM_PACK16) & FMT_TEXTURE) texFormat = Draw::DataFormat::A4R4G4B4_UNORM_PACK16; - else if (draw_->GetDataFormatSupport(Draw::DataFormat::B4G4R4A4_UNORM_PACK16) & FMT_TEXTURE) - texFormat = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; else if (draw_->GetDataFormatSupport(Draw::DataFormat::R4G4B4A4_UNORM_PACK16) & FMT_TEXTURE) texFormat = Draw::DataFormat::R4G4B4A4_UNORM_PACK16; + else if (draw_->GetDataFormatSupport(Draw::DataFormat::B4G4R4A4_UNORM_PACK16) & FMT_TEXTURE) + texFormat = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; else texFormat = Draw::DataFormat::R8G8B8A8_UNORM;