Merge branch 'master' into TemporaryHackishBranch

This commit is contained in:
LunaMoo committed 2019-10-25 00:11:51 +02:00
commit 276aee2ad2
41 files changed
+163 -136

No files matched your search

+3
View File
@@ -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);
+2
View File
@@ -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);
+1 -1
View File
@@ -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},
+2
View File
@@ -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) {
+2 -4
View File
@@ -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;
+8 -8
View File
@@ -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() {
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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?
+2
View File
@@ -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");
+40 -42
View File
@@ -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::R4G4B4A4_UNORM_PACK16;
case GE_CMODE_16BIT_ABGR5551:
return GL_UNSIGNED_SHORT_5_5_5_1;
return Draw::DataFormat::R5G5B5A1_UNORM_PACK16;
case GE_CMODE_16BIT_BGR5650:
return GL_UNSIGNED_SHORT_5_6_5;
return Draw::DataFormat::R5G6B5_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::R4G4B4A4_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::R5G5B5A1_UNORM_PACK16:
ConvertRGBA5551ToABGR1555((u16 *)dst, (const u16 *)src, numPixels);
break;
case GL_UNSIGNED_SHORT_5_6_5:
case Draw::DataFormat::R5G6B5_UNORM_PACK16:
ConvertRGB565ToBGR565((u16 *)dst, (const u16 *)src, numPixels);
break;
default:
@@ -513,22 +513,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::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;
}
}
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::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;
}
}
@@ -596,7 +596,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_;
@@ -706,7 +706,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:
@@ -714,30 +714,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::R4G4B4A4_UNORM_PACK16;
case GE_TFMT_5551:
return GL_UNSIGNED_SHORT_5_5_5_1;
return Draw::DataFormat::R5G5B5A1_UNORM_PACK16;
case GE_TFMT_5650:
return GL_UNSIGNED_SHORT_5_6_5;
return Draw::DataFormat::R5G6B5_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::R4G4B4A4_UNORM_PACK16:
res = CheckAlphaABGR4444Basic((const uint32_t *)pixelData, stride, w, h);
break;
case GL_UNSIGNED_SHORT_5_5_5_1:
case Draw::DataFormat::R5G5B5A1_UNORM_PACK16:
res = CheckAlphaABGR1555Basic((const uint32_t *)pixelData, stride, w, h);
break;
case GL_UNSIGNED_SHORT_5_6_5:
case Draw::DataFormat::R5G6B5_UNORM_PACK16:
// Never has any alpha.
res = CHECKALPHA_FULL;
break;
@@ -749,7 +749,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;
@@ -766,7 +766,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");
@@ -774,7 +774,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);
@@ -791,7 +791,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;
@@ -805,21 +807,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) {
+4 -4
View File
@@ -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);
+9 -7
View File
@@ -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::R4G4B4A4_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::R5G6B5_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::R5G5B5A1_UNORM_PACK16:
GlobalThreadPool::Loop(std::bind(&convert5551_gl, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height);
break;
+3 -1
View File
@@ -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);
+1 -1
View File
@@ -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;
+2
View File
@@ -24,6 +24,8 @@
const wchar_t *SimpleGLWindow::windowClass = L"SimpleGLWindow";
using namespace Lin;
void SimpleGLWindow::RegisterClass() {
WNDCLASSEX wndClass;
+2 -2
View File
@@ -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) {
+1 -1
View File
@@ -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<class T>
void RotateRectToDisplayImpl(DisplayRect<T> &rect, T curRTWidth, T curRTHeight) {
+1 -1
View File
@@ -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<class T>
struct DisplayRect {
+1 -1
View File
@@ -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);
+4 -4
View File
@@ -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<Matrix4x4> drawMatrixStack_;
Lin::Matrix4x4 drawMatrix_;
std::vector<Lin::Matrix4x4> drawMatrixStack_;
float alpha_ = 1.0f;
std::vector<float> alphaStack_;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+3 -1
View File
@@ -256,6 +256,8 @@ 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::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
@@ -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++) {
+1 -1
View File
@@ -3,7 +3,7 @@
#include <cmath>
struct Point {
Point() {}
Point() : x(0.0f), y(0.0f) {}
Point(float x_, float y_) : x(x_), y(y_) {}
float x;
+4 -1
View File
@@ -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);
}
}
+4
View File
@@ -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
+3
View File
@@ -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
+4
View File
@@ -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
+4
View File
@@ -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));
}
}
+4
View File
@@ -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
+4
View File
@@ -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
+4
View File
@@ -4,6 +4,8 @@
#include <math.h>
#include <string.h> // 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
+7 -23
View File
@@ -36,50 +36,34 @@ 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;
alignment = 2;
break;
#ifndef USING_GLES2
case DataFormat::A4R4G4B4_UNORM_PACK16:
internalFormat = GL_RGBA;
case DataFormat::R32G32B32A32_FLOAT:
internalFormat = GL_RGBA32F;
format = GL_RGBA;
type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
alignment = 2;
type = GL_FLOAT;
alignment = 16;
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;
}
+10 -2
View File
@@ -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<GLRInitStep> &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) {
+2 -5
View File
@@ -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;
+2 -5
View File
@@ -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;
+2
View File
@@ -14,7 +14,9 @@
#include "base/logging.h"
#include "DataFormat.h"
namespace Lin {
class Matrix4x4;
}
namespace Draw {
+6 -15
View File
@@ -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
@@ -1218,13 +1212,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::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::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;
+2
View File
@@ -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(
+2 -2
View File
@@ -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;
};
+3
View File
@@ -2,9 +2,12 @@
#include <set>
#include "math/lin/vec3.h"
#include "ui/screen.h"
#include "ui/viewgroup.h"
using namespace Lin;
class I18NCategory;
namespace Draw {
class DrawContext;