From b8bde71efebeaf725f8d620fdac1ccbbd1b65d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 22 Jun 2019 22:15:09 +0200 Subject: [PATCH] Address feedback, delete some unused code. --- GPU/Common/FramebufferCommon.cpp | 12 ++--- GPU/Common/FramebufferCommon.h | 4 ++ GPU/Common/ShaderTranslation.cpp | 3 ++ ext/native/math/lin/matrix4x4.cpp | 30 ------------ ext/native/math/lin/matrix4x4.h | 77 ++++++++----------------------- 5 files changed, 32 insertions(+), 94 deletions(-) diff --git a/GPU/Common/FramebufferCommon.cpp b/GPU/Common/FramebufferCommon.cpp index f12f2c3003..0bce2d0fa2 100644 --- a/GPU/Common/FramebufferCommon.cpp +++ b/GPU/Common/FramebufferCommon.cpp @@ -734,7 +734,7 @@ void FramebufferManagerCommon::DrawPixels(VirtualFramebuffer *vfb, int dstX, int // We are drawing to the back buffer so need to flip. if (needBackBufferYSwap_) std::swap(v0, v1); - flags = (DrawTextureFlags)(flags | DRAWTEX_TO_BACKBUFFER); + flags = flags | DRAWTEX_TO_BACKBUFFER; float x, y, w, h; CenterDisplayOutputRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)pixelWidth_, (float)pixelHeight_, ROTATION_LOCKED_HORIZONTAL); SetViewport2D(x, y, w, h); @@ -809,7 +809,7 @@ void FramebufferManagerCommon::DrawFramebufferToOutput(const u8 *srcPixels, GEBu std::swap(v0, v1); DrawTextureFlags flags = g_Config.iBufFilter == SCALE_LINEAR ? DRAWTEX_LINEAR : DRAWTEX_NEAREST; - flags = (DrawTextureFlags)(flags | DRAWTEX_TO_BACKBUFFER); + flags = flags | DRAWTEX_TO_BACKBUFFER; if (cardboardSettings.enabled) { // Left Eye Image SetViewport2D(cardboardSettings.leftEyeXPosition, cardboardSettings.screenYPosition, cardboardSettings.screenWidth, cardboardSettings.screenHeight); @@ -979,7 +979,7 @@ void FramebufferManagerCommon::CopyDisplayToOutput() { draw_->SetScissorRect(0, 0, pixelWidth_, pixelHeight_); Bind2DShader(); DrawTextureFlags flags = g_Config.iBufFilter == SCALE_LINEAR ? DRAWTEX_LINEAR : DRAWTEX_NEAREST; - flags = (DrawTextureFlags)(flags | DRAWTEX_TO_BACKBUFFER); + flags = flags | DRAWTEX_TO_BACKBUFFER; // We are doing the DrawActiveTexture call directly to the backbuffer here. Hence, we must // flip V. if (needBackBufferYSwap_) @@ -1010,7 +1010,7 @@ void FramebufferManagerCommon::CopyDisplayToOutput() { CalculatePostShaderUniforms(vfb->bufferWidth, vfb->bufferHeight, renderWidth_, renderHeight_, &uniforms); BindPostShader(uniforms); DrawTextureFlags flags = g_Config.iBufFilter == SCALE_LINEAR ? DRAWTEX_LINEAR : DRAWTEX_NEAREST; - flags = (DrawTextureFlags)(flags | DRAWTEX_TO_BACKBUFFER); + flags = flags | DRAWTEX_TO_BACKBUFFER; DrawActiveTexture(0, 0, fbo_w, fbo_h, fbo_w, fbo_h, 0.0f, 0.0f, 1.0f, 1.0f, ROTATION_LOCKED_HORIZONTAL, flags); draw_->SetScissorRect(0, 0, pixelWidth_, pixelHeight_); @@ -1030,7 +1030,7 @@ void FramebufferManagerCommon::CopyDisplayToOutput() { std::swap(v0, v1); Bind2DShader(); flags = (!postShaderIsUpscalingFilter_ && g_Config.iBufFilter == SCALE_LINEAR) ? DRAWTEX_LINEAR : DRAWTEX_NEAREST; - flags = (DrawTextureFlags)(flags | DRAWTEX_TO_BACKBUFFER); + flags = flags | DRAWTEX_TO_BACKBUFFER; if (g_Config.bEnableCardboard) { // Left Eye Image SetViewport2D(cardboardSettings.leftEyeXPosition, cardboardSettings.screenYPosition, cardboardSettings.screenWidth, cardboardSettings.screenHeight); @@ -1054,7 +1054,7 @@ void FramebufferManagerCommon::CopyDisplayToOutput() { if (needBackBufferYSwap_) std::swap(v0, v1); DrawTextureFlags flags = (!postShaderIsUpscalingFilter_ && g_Config.iBufFilter == SCALE_LINEAR) ? DRAWTEX_LINEAR : DRAWTEX_NEAREST; - flags = (DrawTextureFlags)(flags | DRAWTEX_TO_BACKBUFFER); + flags = flags | DRAWTEX_TO_BACKBUFFER; PostShaderUniforms uniforms{}; CalculatePostShaderUniforms(vfb->bufferWidth, vfb->bufferHeight, vfb->renderWidth, vfb->renderHeight, &uniforms); diff --git a/GPU/Common/FramebufferCommon.h b/GPU/Common/FramebufferCommon.h index 8cae90e284..3f1d1a49a5 100644 --- a/GPU/Common/FramebufferCommon.h +++ b/GPU/Common/FramebufferCommon.h @@ -158,6 +158,10 @@ enum DrawTextureFlags { DRAWTEX_TO_BACKBUFFER = 8, }; +inline DrawTextureFlags operator | (const DrawTextureFlags &lhs, const DrawTextureFlags &rhs) { + return DrawTextureFlags((u32)lhs | (u32)rhs); +} + enum class TempFBO { DEPAL, BLIT, diff --git a/GPU/Common/ShaderTranslation.cpp b/GPU/Common/ShaderTranslation.cpp index 0b5ffa11a5..363d9544e6 100644 --- a/GPU/Common/ShaderTranslation.cpp +++ b/GPU/Common/ShaderTranslation.cpp @@ -24,6 +24,9 @@ // DbgNew is not compatible with Glslang #ifdef DBG_NEW #undef new +#undef free +#undef malloc +#undef realloc #endif #include "base/logging.h" diff --git a/ext/native/math/lin/matrix4x4.cpp b/ext/native/math/lin/matrix4x4.cpp index 33d2714c6e..60d5c95898 100644 --- a/ext/native/math/lin/matrix4x4.cpp +++ b/ext/native/math/lin/matrix4x4.cpp @@ -234,36 +234,6 @@ void Matrix4x4::setOrthoVulkan(float left, float right, float top, float bottom, ww = 1.0f; } -void Matrix4x4::setProjectionInf(const float near_plane, const float fov_horiz, const float aspect) { - empty(); - float f = fov_horiz*0.5f; - xx = 1.0f / tanf(f); - yy = 1.0f / tanf(f*aspect); - zz = 1; - wz = -near_plane; - zw = 1.0f; -} - -void Matrix4x4::setRotationAxisAngle(const Vec3 &axis, float angle) { - Quaternion quat; - quat.setRotation(axis, angle); - quat.toMatrix(this); -} - -// from a (Position, Rotation, Scale) vec3 quat vec3 tuple -Matrix4x4 Matrix4x4::fromPRS(const Vec3 &positionv, const Quaternion &rotv, const Vec3 &scalev) { - Matrix4x4 newM; - newM.setIdentity(); - Matrix4x4 rot, scale; - rotv.toMatrix(&rot); - scale.setScaling(scalev); - newM = rot * scale; - newM.wx = positionv.x; - newM.wy = positionv.y; - newM.wz = positionv.z; - return newM; -} - void Matrix4x4::toText(char *buffer, int len) const { snprintf(buffer, len, "%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n", xx,xy,xz,xw, diff --git a/ext/native/math/lin/matrix4x4.h b/ext/native/math/lin/matrix4x4.h index db8acde2b9..8d8628bc98 100644 --- a/ext/native/math/lin/matrix4x4.h +++ b/ext/native/math/lin/matrix4x4.h @@ -35,7 +35,6 @@ public: wx = v.x; wy = v.y; wz = v.z; } - const float &operator[](int i) const { return *(((const float *)this) + i); } @@ -56,13 +55,6 @@ public: empty(); xx=yy=zz=f; ww=1.0f; } - void setScaling(const Vec3 f) { - empty(); - xx=f.x; - yy=f.y; - zz=f.z; - ww=1.0f; - } void setIdentity() { setScaling(1.0f); @@ -73,12 +65,6 @@ public: wy = trans.y; wz = trans.z; } - void setTranslationAndScaling(const Vec3 &trans, const Vec3 &scale) { - setScaling(scale); - wx = trans.x; - wy = trans.y; - wz = trans.z; - } Matrix4x4 inverse() const; Matrix4x4 simpleInverse() const; @@ -86,28 +72,28 @@ public: void setRotationX(const float a) { empty(); - float c=cosf(a); - float s=sinf(a); + float c = cosf(a); + float s = sinf(a); xx = 1.0f; - yy = c; yz = s; - zy = -s; zz = c; + yy = c; yz = s; + zy = -s; zz = c; ww = 1.0f; } void setRotationY(const float a) { empty(); - float c=cosf(a); - float s=sinf(a); - xx = c; xz = -s; - yy = 1.0f; - zx = s; zz = c ; + float c = cosf(a); + float s = sinf(a); + xx = c; xz = -s; + yy = 1.0f; + zx = s; zz = c; ww = 1.0f; } void setRotationZ(const float a) { empty(); - float c=cosf(a); - float s=sinf(a); - xx = c; xy = s; - yx = -s; yy = c; + float c = cosf(a); + float s = sinf(a); + xx = c; xy = s; + yx = -s; yy = c; zz = 1.0f; ww = 1.0f; } @@ -116,8 +102,8 @@ public: empty(); float c = 0.0f; float s = 1.0f; - xx = c; xy = s; - yx = -s; yy = c; + xx = c; xy = s; + yx = -s; yy = c; zz = 1.0f; ww = 1.0f; } @@ -125,8 +111,8 @@ public: empty(); float c = -1.0f; float s = 0.0f; - xx = c; xy = s; - yx = -s; yy = c; + xx = c; xy = s; + yx = -s; yy = c; zz = 1.0f; ww = 1.0f; } @@ -134,49 +120,24 @@ public: empty(); float c = 0.0f; float s = -1.0f; - xx = c; xy = s; - yx = -s; yy = c; + xx = c; xy = s; + yx = -s; yy = c; zz = 1.0f; ww = 1.0f; } - void setRotationAxisAngle(const Vec3 &axis, float angle); - void setRotation(float x,float y, float z); void setProjection(float near_plane, float far_plane, float fov_horiz, float aspect = 0.75f); void setProjectionD3D(float near_plane, float far_plane, float fov_horiz, float aspect = 0.75f); - void setProjectionInf(float near_plane, float fov_horiz, float aspect = 0.75f); void setOrtho(float left, float right, float bottom, float top, float near, float far); void setOrthoD3D(float left, float right, float bottom, float top, float near, float far); void setOrthoVulkan(float left, float right, float top, float bottom, float near, float far); - void setShadow(float Lx, float Ly, float Lz, float Lw) { - float Pa=0; - float Pb=1; - float Pc=0; - float Pd=0; - //P = normalize(Plane); - float d = (Pa*Lx + Pb*Ly + Pc*Lz + Pd*Lw); - - xx=Pa * Lx + d; xy=Pa * Ly; xz=Pa * Lz; xw=Pa * Lw; - yx=Pb * Lx; yy=Pb * Ly + d; yz=Pb * Lz; yw=Pb * Lw; - zx=Pc * Lx; zy=Pc * Ly; zz=Pc * Lz + d; zw=Pc * Lw; - wx=Pd * Lx; wy=Pd * Ly; wz=Pd * Lz; ww=Pd * Lw + d; - } void setViewLookAt(const Vec3 &from, const Vec3 &at, const Vec3 &worldup); void setViewLookAtD3D(const Vec3 &from, const Vec3 &at, const Vec3 &worldup); void setViewFrame(const Vec3 &pos, const Vec3 &right, const Vec3 &forward, const Vec3 &up); - void stabilizeOrtho() { - /* - front().normalize(); - right().normalize(); - up() = front() % right(); - right() = up() % front(); - */ - } void toText(char *buffer, int len) const; void print() const; - static Matrix4x4 fromPRS(const Vec3 &position, const Quaternion &normal, const Vec3 &scale); void translateAndScale(const Vec3 &trans, const Vec3 &scale) { xx = xx * scale.x + xw * trans.x;