From 463251908b9958e85ce4c560bd1fb4dd2eb18217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 25 Dec 2016 18:52:05 +0100 Subject: [PATCH] Rename things to closer match another project which I plan to share some code with --- GPU/Directx9/GPU_DX9.cpp | 4 +- GPU/Software/SoftGpu.cpp | 24 +++--- UI/DevScreens.cpp | 10 +-- UI/EmuScreen.cpp | 6 +- UI/GameInfoCache.cpp | 2 +- UI/MiscScreens.cpp | 2 +- UI/NativeApp.cpp | 2 +- ext/native/gfx_es2/draw_buffer.cpp | 12 +-- ext/native/gfx_es2/draw_text.cpp | 4 +- ext/native/thin3d/thin3d.cpp | 30 +++---- ext/native/thin3d/thin3d.h | 128 +++++++++++++++------------- ext/native/thin3d/thin3d_d3d9.cpp | 126 ++++++++++++++------------- ext/native/thin3d/thin3d_gl.cpp | 102 ++++++++++++---------- ext/native/thin3d/thin3d_vulkan.cpp | 123 +++++++++++++++----------- ext/native/ui/ui_context.cpp | 10 +-- ext/native/ui/ui_context.h | 4 +- ext/native/ui/ui_screen.cpp | 2 +- 17 files changed, 328 insertions(+), 263 deletions(-) diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 191105d967..e51c9c83bb 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -515,8 +515,8 @@ void GPU_DX9::BuildReportingInfo() { using namespace Draw; Thin3DContext *thin3d = gfxCtx_->CreateThin3DContext(); - reportingPrimaryInfo_ = thin3d->GetInfoString(T3DInfo::VENDORSTRING); - reportingFullInfo_ = reportingPrimaryInfo_ + " - " + System_GetProperty(SYSPROP_GPUDRIVER_VERSION) + " - " + thin3d->GetInfoString(T3DInfo::SHADELANGVERSION); + reportingPrimaryInfo_ = thin3d->GetInfoString(InfoField::VENDORSTRING); + reportingFullInfo_ = reportingPrimaryInfo_ + " - " + System_GetProperty(SYSPROP_GPUDRIVER_VERSION) + " - " + thin3d->GetInfoString(InfoField::SHADELANGVERSION); thin3d->Release(); } diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index d0ccabc656..a4d5c0d0f3 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -45,7 +45,7 @@ u32 clut[4096]; static Draw::Thin3DVertexFormat *vformat = nullptr; static Draw::Thin3DDepthStencilState *depth = nullptr; static Draw::Thin3DRasterState *rasterNoCull = nullptr; -static Draw::Thin3DBlendState *blendstateOff = nullptr; +static Draw::BlendState *blendstateOff = nullptr; static Draw::Thin3DSamplerState *samplerNearest = nullptr; static Draw::Thin3DSamplerState *samplerLinear = nullptr; static Draw::Thin3DBuffer *vdata = nullptr; @@ -55,22 +55,22 @@ SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::Thin3DContext *_thin3D) : gfxCtx_(gfxCtx), thin3d(_thin3D) { using namespace Draw; - fbTex = thin3d->CreateTexture(LINEAR2D, T3DDataFormat::R8A8G8B8_UNORM, 480, 272, 1, 1); + fbTex = thin3d->CreateTexture(LINEAR2D, DataFormat::R8A8G8B8_UNORM, 480, 272, 1, 1); std::vector components; - components.push_back(Thin3DVertexComponent("Position", SEM_POSITION, T3DDataFormat::FLOATx3, 0)); - components.push_back(Thin3DVertexComponent("TexCoord0", SEM_TEXCOORD0, T3DDataFormat::FLOATx2, 12)); - components.push_back(Thin3DVertexComponent("Color0", SEM_COLOR0, T3DDataFormat::UNORM8x4, 20)); + components.push_back(Thin3DVertexComponent("Position", SEM_POSITION, DataFormat::FLOATx3, 0)); + components.push_back(Thin3DVertexComponent("TexCoord0", SEM_TEXCOORD0, DataFormat::FLOATx2, 12)); + components.push_back(Thin3DVertexComponent("Color0", SEM_COLOR0, DataFormat::UNORM8x4, 20)); Thin3DShader *vshader = thin3d->GetVshaderPreset(VS_TEXTURE_COLOR_2D); vformat = thin3d->CreateVertexFormat(components, 24, vshader); - vdata = thin3d->CreateBuffer(24 * 4, T3DBufferUsage::DYNAMIC | T3DBufferUsage::VERTEXDATA); - idata = thin3d->CreateBuffer(sizeof(int) * 6, T3DBufferUsage::DYNAMIC | T3DBufferUsage::INDEXDATA); - depth = thin3d->CreateDepthStencilState(false, false, T3DComparison::LESS); + vdata = thin3d->CreateBuffer(24 * 4, BufferUsageFlag::DYNAMIC | BufferUsageFlag::VERTEXDATA); + idata = thin3d->CreateBuffer(sizeof(int) * 6, BufferUsageFlag::DYNAMIC | BufferUsageFlag::INDEXDATA); + depth = thin3d->CreateDepthStencilState(false, false, Comparison::LESS); blendstateOff = thin3d->CreateBlendState({ false }); - samplerNearest = thin3d->CreateSamplerState({ T3DTextureFilter::NEAREST, T3DTextureFilter::NEAREST, T3DTextureFilter::NEAREST }); - samplerLinear = thin3d->CreateSamplerState({ T3DTextureFilter::LINEAR, T3DTextureFilter::LINEAR, T3DTextureFilter::LINEAR }); + samplerNearest = thin3d->CreateSamplerState({ TextureFilter::NEAREST, TextureFilter::NEAREST, TextureFilter::NEAREST }); + samplerLinear = thin3d->CreateSamplerState({ TextureFilter::LINEAR, TextureFilter::LINEAR, TextureFilter::LINEAR }); fb.data = Memory::GetPointer(0x44000000); // TODO: correct default address? depthbuf.data = Memory::GetPointer(0x44000000); // TODO: correct default address? @@ -132,7 +132,7 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) { float dstwidth = (float)PSP_CoreParameter().pixelWidth; float dstheight = (float)PSP_CoreParameter().pixelHeight; - T3DViewport viewport = {0.0f, 0.0f, dstwidth, dstheight, 0.0f, 1.0f}; + Viewport viewport = {0.0f, 0.0f, dstwidth, dstheight, 0.0f, 1.0f}; thin3d->SetViewports(1, &viewport); thin3d->SetBlendState(blendstateOff); Thin3DSamplerState *sampler; @@ -242,7 +242,7 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) { }; texColor->SetMatrix4x4("WorldViewProj", identity4x4); - thin3d->DrawIndexed(T3DPrimitive::PRIM_TRIANGLES, texColor, vformat, vdata, idata, 6, 0); + thin3d->DrawIndexed(Primitive::TRIANGLE_LIST, texColor, vformat, vdata, idata, 6, 0); } void SoftGPU::CopyDisplayToOutput() diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 2f8ccc06f7..555a7509a0 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -355,9 +355,9 @@ void SystemInfoScreen::CreateViews() { Thin3DContext *thin3d = screenManager()->getThin3DContext(); - deviceSpecs->Add(new InfoItem("3D API", thin3d->GetInfoString(T3DInfo::APINAME))); - deviceSpecs->Add(new InfoItem("Vendor", std::string(thin3d->GetInfoString(T3DInfo::VENDORSTRING)) + " (" + thin3d->GetInfoString(T3DInfo::VENDOR) + ")")); - deviceSpecs->Add(new InfoItem("Model", thin3d->GetInfoString(T3DInfo::RENDERER))); + deviceSpecs->Add(new InfoItem("3D API", thin3d->GetInfoString(InfoField::APINAME))); + deviceSpecs->Add(new InfoItem("Vendor", std::string(thin3d->GetInfoString(InfoField::VENDORSTRING)) + " (" + thin3d->GetInfoString(InfoField::VENDOR) + ")")); + deviceSpecs->Add(new InfoItem("Model", thin3d->GetInfoString(InfoField::RENDERER))); #ifdef _WIN32 deviceSpecs->Add(new InfoItem("Driver Version", System_GetProperty(SYSPROP_GPUDRIVER_VERSION))); if (GetGPUBackend() == GPUBackend::DIRECT3D9) { @@ -389,12 +389,12 @@ void SystemInfoScreen::CreateViews() { apiVersion = StringFromFormat("v%d.%d.%d", gl_extensions.ver[0], gl_extensions.ver[1], gl_extensions.ver[2]); } } else { - apiVersion = thin3d->GetInfoString(T3DInfo::APIVERSION); + apiVersion = thin3d->GetInfoString(InfoField::APIVERSION); if (apiVersion.size() > 30) apiVersion.resize(30); } deviceSpecs->Add(new InfoItem("API Version", apiVersion)); - deviceSpecs->Add(new InfoItem("Shading Language", thin3d->GetInfoString(T3DInfo::SHADELANGVERSION))); + deviceSpecs->Add(new InfoItem("Shading Language", thin3d->GetInfoString(InfoField::SHADELANGVERSION))); #ifdef __ANDROID__ std::string moga = System_GetProperty(SYSPROP_MOGA_VERSION); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 2f70342c89..d8a3abfbb0 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -992,9 +992,9 @@ void EmuScreen::render() { if (!useBufferedRendering) { Thin3DContext *thin3d = screenManager()->getThin3DContext(); - thin3d->Clear(T3DClear::COLOR | T3DClear::DEPTH | T3DClear::STENCIL, 0xFF000000, 0.0f, 0); + thin3d->Clear(ClearFlag::COLOR | ClearFlag::DEPTH | ClearFlag::STENCIL, 0xFF000000, 0.0f, 0); - T3DViewport viewport; + Viewport viewport; viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = pixel_xres; @@ -1037,7 +1037,7 @@ void EmuScreen::render() { // This sets up some important states but not the viewport. screenManager()->getUIContext()->Begin(); - T3DViewport viewport; + Viewport viewport; viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = pixel_xres; diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 19cbaa6124..b21ddd5986 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -785,7 +785,7 @@ void GameInfoCache::SetupTexture(GameInfo *info, std::string &textureData, Draw: using namespace Draw; if (textureData.size()) { if (!tex) { - tex = thin3d->CreateTextureFromFileData((const uint8_t *)textureData.data(), (int)textureData.size(), T3DImageType::DETECT); + tex = thin3d->CreateTextureFromFileData((const uint8_t *)textureData.data(), (int)textureData.size(), ImageFileType::DETECT); if (tex) { loadTime = time_now_d(); } diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index c2425c3f2f..4cdb466fbf 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -475,7 +475,7 @@ void LogoScreen::render() { } #ifdef _WIN32 - dc.DrawText(screenManager()->getThin3DContext()->GetInfoString(T3DInfo::APINAME).c_str(), bounds.centerX(), bounds.y2() - 100, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER); + dc.DrawText(screenManager()->getThin3DContext()->GetInfoString(InfoField::APINAME).c_str(), bounds.centerX(), bounds.y2() - 100, colorAlpha(0xFFFFFFFF, alphaText), ALIGN_CENTER); #endif dc.End(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 14c2009bb4..d32e8c47e9 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -579,7 +579,7 @@ void NativeInitGraphics(GraphicsContext *graphicsContext) { ui_draw2d.Init(thin3d); ui_draw2d_front.Init(thin3d); - uiTexture = thin3d->CreateTextureFromFile("ui_atlas.zim", T3DImageType::ZIM); + uiTexture = thin3d->CreateTextureFromFile("ui_atlas.zim", ImageFileType::ZIM); if (!uiTexture) { PanicAlert("Failed to load ui_atlas.zim.\n\nPlace it in the directory \"assets\" under your PPSSPP directory."); ELOG("Failed to load ui_atlas.zim"); diff --git a/ext/native/gfx_es2/draw_buffer.cpp b/ext/native/gfx_es2/draw_buffer.cpp index e5af9e81f0..64a45c2139 100644 --- a/ext/native/gfx_es2/draw_buffer.cpp +++ b/ext/native/gfx_es2/draw_buffer.cpp @@ -42,15 +42,15 @@ void DrawBuffer::Init(Draw::Thin3DContext *t3d) { inited_ = true; std::vector components; - components.push_back(Thin3DVertexComponent("Position", SEM_POSITION, T3DDataFormat::FLOATx3, 0)); - components.push_back(Thin3DVertexComponent("TexCoord0", SEM_TEXCOORD0, T3DDataFormat::FLOATx2, 12)); - components.push_back(Thin3DVertexComponent("Color0", SEM_COLOR0, T3DDataFormat::UNORM8x4, 20)); + components.push_back(Thin3DVertexComponent("Position", SEM_POSITION, DataFormat::FLOATx3, 0)); + components.push_back(Thin3DVertexComponent("TexCoord0", SEM_TEXCOORD0, DataFormat::FLOATx2, 12)); + components.push_back(Thin3DVertexComponent("Color0", SEM_COLOR0, DataFormat::UNORM8x4, 20)); Thin3DShader *vshader = t3d_->GetVshaderPreset(VS_TEXTURE_COLOR_2D); vformat_ = t3d_->CreateVertexFormat(components, 24, vshader); if (vformat_->RequiresBuffer()) { - vbuf_ = t3d_->CreateBuffer(MAX_VERTS * sizeof(Vertex), T3DBufferUsage::DYNAMIC | T3DBufferUsage::VERTEXDATA); + vbuf_ = t3d_->CreateBuffer(MAX_VERTS * sizeof(Vertex), BufferUsageFlag::DYNAMIC | BufferUsageFlag::VERTEXDATA); } else { vbuf_ = nullptr; } @@ -90,9 +90,9 @@ void DrawBuffer::Flush(bool set_blend_state) { if (vbuf_) { vbuf_->SubData((const uint8_t *)verts_, 0, sizeof(Vertex) * count_); int offset = 0; - t3d_->Draw(mode_ == DBMODE_NORMAL ? PRIM_TRIANGLES : PRIM_LINES, shaderSet_, vformat_, vbuf_, count_, offset); + t3d_->Draw(mode_ == DBMODE_NORMAL ? Primitive::TRIANGLE_LIST : Primitive::LINE_LIST, shaderSet_, vformat_, vbuf_, count_, offset); } else { - t3d_->DrawUP(mode_ == DBMODE_NORMAL ? PRIM_TRIANGLES : PRIM_LINES, shaderSet_, vformat_, (const void *)verts_, count_); + t3d_->DrawUP(mode_ == DBMODE_NORMAL ? Primitive::TRIANGLE_LIST : Primitive::LINE_LIST, shaderSet_, vformat_, (const void *)verts_, count_); } count_ = 0; } diff --git a/ext/native/gfx_es2/draw_text.cpp b/ext/native/gfx_es2/draw_text.cpp index d732c5e531..158b4cbc44 100644 --- a/ext/native/gfx_es2/draw_text.cpp +++ b/ext/native/gfx_es2/draw_text.cpp @@ -271,7 +271,7 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float entry->bmWidth = (size.cx + 3) & ~3; entry->bmHeight = (size.cy + 3) & ~3; entry->lastUsedFrame = frameCount_; - entry->texture = thin3d_->CreateTexture(LINEAR2D, T3DDataFormat::R4G4B4A4_UNORM, entry->bmWidth, entry->bmHeight, 1, 1); + entry->texture = thin3d_->CreateTexture(LINEAR2D, DataFormat::R4G4B4A4_UNORM, entry->bmWidth, entry->bmHeight, 1, 1); // Convert the bitmap to a gl-compatible array of pixels. uint16_t *bitmapData = new uint16_t[entry->bmWidth * entry->bmHeight]; @@ -422,7 +422,7 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float entry->bmWidth = entry->width = image.width(); entry->bmHeight = entry->height = image.height(); entry->lastUsedFrame = frameCount_; - entry->texture = thin3d_->CreateTexture(LINEAR2D, T3DDataFormat::R4G4B4A4_UNORM, entry->bmWidth, entry->bmHeight, 1, 0); + entry->texture = thin3d_->CreateTexture(LINEAR2D, DataFormat::R4G4B4A4_UNORM, entry->bmWidth, entry->bmHeight, 1, 0); uint16_t *bitmapData = new uint16_t[entry->bmWidth * entry->bmHeight]; for (int x = 0; x < entry->bmWidth; x++) { diff --git a/ext/native/thin3d/thin3d.cpp b/ext/native/thin3d/thin3d.cpp index a515ad59b1..d6ed333515 100644 --- a/ext/native/thin3d/thin3d.cpp +++ b/ext/native/thin3d/thin3d.cpp @@ -176,16 +176,16 @@ Thin3DContext::~Thin3DContext() { } } -static T3DDataFormat ZimToT3DFormat(int zim) { +static DataFormat ZimToT3DFormat(int zim) { switch (zim) { - case ZIM_ETC1: return T3DDataFormat::ETC1; - case ZIM_RGBA8888: return T3DDataFormat::R8A8G8B8_UNORM; - case ZIM_LUMINANCE: return T3DDataFormat::LUMINANCE; - default: return T3DDataFormat::R8A8G8B8_UNORM; + case ZIM_ETC1: return DataFormat::ETC1; + case ZIM_RGBA8888: return DataFormat::R8A8G8B8_UNORM; + case ZIM_LUMINANCE: return DataFormat::LUMINANCE; + default: return DataFormat::R8A8G8B8_UNORM; } } -static T3DImageType DetectImageFileType(const uint8_t *data, size_t size) { +static ImageFileType DetectImageFileType(const uint8_t *data, size_t size) { if (!memcmp(data, "ZIMG", 4)) { return ZIM; } else if (!memcmp(data, "\x89\x50\x4E\x47", 4)) { @@ -197,7 +197,7 @@ static T3DImageType DetectImageFileType(const uint8_t *data, size_t size) { } } -static bool LoadTextureLevels(const uint8_t *data, size_t size, T3DImageType type, int width[16], int height[16], int *num_levels, T3DDataFormat *fmt, uint8_t *image[16], int *zim_flags) { +static bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType type, int width[16], int height[16], int *num_levels, DataFormat *fmt, uint8_t *image[16], int *zim_flags) { if (type == DETECT) { type = DetectImageFileType(data, size); } @@ -220,7 +220,7 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, T3DImageType typ case PNG: if (1 == pngLoadPtr((const unsigned char *)data, size, &width[0], &height[0], &image[0], false)) { *num_levels = 1; - *fmt = T3DDataFormat::R8A8G8B8_UNORM; + *fmt = DataFormat::R8A8G8B8_UNORM; } break; @@ -230,7 +230,7 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, T3DImageType typ unsigned char *jpegBuf = jpgd::decompress_jpeg_image_from_memory(data, (int)size, &width[0], &height[0], &actual_components, 4); if (jpegBuf) { *num_levels = 1; - *fmt = T3DDataFormat::R8A8G8B8_UNORM; + *fmt = DataFormat::R8A8G8B8_UNORM; image[0] = (uint8_t *)jpegBuf; } } @@ -244,13 +244,13 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, T3DImageType typ return *num_levels > 0; } -bool Thin3DTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, T3DImageType type) { +bool Thin3DTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type) { int width[16], height[16]; uint8_t *image[16] = { nullptr }; int num_levels; int zim_flags; - T3DDataFormat fmt; + DataFormat fmt; if (!LoadTextureLevels(data, dataSize, type, width, height, &num_levels, &fmt, image, &zim_flags)) { return false; @@ -275,7 +275,7 @@ bool Thin3DTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, T3DIm return true; } -bool Thin3DTexture::LoadFromFile(const std::string &filename, T3DImageType type) { +bool Thin3DTexture::LoadFromFile(const std::string &filename, ImageFileType type) { filename_ = ""; size_t fileSize; uint8_t *buffer = VFSReadFile(filename.c_str(), &fileSize); @@ -292,7 +292,7 @@ bool Thin3DTexture::LoadFromFile(const std::string &filename, T3DImageType type) return retval; } -Thin3DTexture *Thin3DContext::CreateTextureFromFile(const char *filename, T3DImageType type) { +Thin3DTexture *Thin3DContext::CreateTextureFromFile(const char *filename, ImageFileType type) { Thin3DTexture *tex = CreateTexture(); if (!tex->LoadFromFile(filename, type)) { tex->Release(); @@ -302,11 +302,11 @@ Thin3DTexture *Thin3DContext::CreateTextureFromFile(const char *filename, T3DIma } // TODO: Remove the code duplication between this and LoadFromFileData -Thin3DTexture *Thin3DContext::CreateTextureFromFileData(const uint8_t *data, int size, T3DImageType type) { +Thin3DTexture *Thin3DContext::CreateTextureFromFileData(const uint8_t *data, int size, ImageFileType type) { int width[16], height[16]; int num_levels = 0; int zim_flags = 0; - T3DDataFormat fmt; + DataFormat fmt; uint8_t *image[16] = { nullptr }; if (!LoadTextureLevels(data, size, type, width, height, &num_levels, &fmt, image, &zim_flags)) { diff --git a/ext/native/thin3d/thin3d.h b/ext/native/thin3d/thin3d.h index 05d765b866..cc0ec4e4b0 100644 --- a/ext/native/thin3d/thin3d.h +++ b/ext/native/thin3d/thin3d.h @@ -28,7 +28,10 @@ class VulkanContext; namespace Draw { -enum T3DBlendEquation : int { +// Useful in UBOs +typedef int bool32; + +enum BlendOp : int { ADD, SUBTRACT, REV_SUBTRACT, @@ -36,7 +39,7 @@ enum T3DBlendEquation : int { MAX, }; -enum T3DComparison : int { +enum Comparison : int { NEVER, LESS, EQUAL, @@ -48,7 +51,7 @@ enum T3DComparison : int { }; // Had to prefix with LOGIC, too many clashes -enum T3DLogicOp : int { +enum class LogicOp : int { LOGIC_CLEAR, LOGIC_SET, LOGIC_COPY, @@ -67,7 +70,7 @@ enum T3DLogicOp : int { LOGIC_OR_INVERTED, }; -enum T3DBlendFactor : int { +enum BlendFactor : int { ZERO, ONE, SRC_COLOR, @@ -81,17 +84,17 @@ enum T3DBlendFactor : int { FIXED_COLOR, }; -enum class T3DTextureWrap : int { +enum class TextureAddressMode : int { REPEAT, CLAMP, }; -enum class T3DTextureFilter : int { +enum class TextureFilter : int { NEAREST, LINEAR, }; -enum T3DBufferUsage : int { +enum BufferUsageFlag : int { VERTEXDATA = 1, INDEXDATA = 2, GENERIC = 4, @@ -99,7 +102,7 @@ enum T3DBufferUsage : int { DYNAMIC = 16, }; -enum T3DSemantic : int { +enum Semantic : int { SEM_POSITION, SEM_COLOR0, SEM_TEXCOORD0, @@ -110,10 +113,19 @@ enum T3DSemantic : int { SEM_MAX, }; -enum T3DPrimitive : int { - PRIM_POINTS, - PRIM_LINES, - PRIM_TRIANGLES, +enum class Primitive { + POINT_LIST, + LINE_LIST, + LINE_STRIP, + TRIANGLE_LIST, + TRIANGLE_STRIP, + TRIANGLE_FAN, + PATCH_LIST, + // These are for geometry shaders only. + LINE_LIST_ADJ, + LINE_STRIP_ADJ, + TRIANGLE_LIST_ADJ, + TRIANGLE_STRIP_ADJ, }; enum T3DVertexShaderPreset : int { @@ -135,13 +147,13 @@ enum T3DShaderSetPreset : int { SS_MAX_PRESET, }; -enum T3DClear : int { +enum ClearFlag : int { COLOR = 1, DEPTH = 2, STENCIL = 4, }; -enum T3DTextureType : uint8_t { +enum TextureType : uint8_t { UNKNOWN, LINEAR1D, LINEAR2D, @@ -151,7 +163,7 @@ enum T3DTextureType : uint8_t { ARRAY2D, }; -enum class T3DDataFormat : uint8_t { +enum class DataFormat : uint8_t { UNKNOWN, LUMINANCE, R8A8G8B8_UNORM, @@ -168,11 +180,7 @@ enum class T3DDataFormat : uint8_t { D24X8, }; -enum T3DRenderState : uint8_t { - CULL_MODE, -}; - -enum T3DImageType { +enum ImageFileType { PNG, JPEG, ZIM, @@ -180,7 +188,7 @@ enum T3DImageType { TYPE_UNKNOWN, }; -enum T3DInfo { +enum InfoField { APINAME, APIVERSION, VENDORSTRING, @@ -190,7 +198,7 @@ enum T3DInfo { }; // Binary compatible with D3D11 viewport. -struct T3DViewport { +struct Viewport { float TopLeftX; float TopLeftY; float Width; @@ -223,7 +231,7 @@ private: int refcount_; }; -class Thin3DBlendState : public Thin3DObject { +class BlendState : public Thin3DObject { public: }; @@ -243,10 +251,10 @@ public: class Thin3DTexture : public Thin3DObject { public: - bool LoadFromFile(const std::string &filename, T3DImageType type = T3DImageType::DETECT); - bool LoadFromFileData(const uint8_t *data, size_t dataSize, T3DImageType type = T3DImageType::DETECT); + bool LoadFromFile(const std::string &filename, ImageFileType type = ImageFileType::DETECT); + bool LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type = ImageFileType::DETECT); - virtual bool Create(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) = 0; + virtual bool Create(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) = 0; virtual void SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) = 0; virtual void AutoGenMipmaps() = 0; virtual void Finalize(int zim_flags) = 0; // TODO: Tidy up @@ -260,8 +268,8 @@ protected: }; struct Thin3DVertexComponent { - Thin3DVertexComponent() : name(nullptr), type(T3DDataFormat::UNKNOWN), semantic(255), offset(255) {} - Thin3DVertexComponent(const char *name, T3DSemantic semantic, T3DDataFormat dataType, uint8_t offset) { + Thin3DVertexComponent() : name(nullptr), type(DataFormat::UNKNOWN), semantic(255), offset(255) {} + Thin3DVertexComponent(const char *name, Semantic semantic, DataFormat dataType, uint8_t offset) { this->name = name; this->semantic = semantic; this->type = dataType; @@ -269,7 +277,7 @@ struct Thin3DVertexComponent { } const char *name; uint8_t semantic; - T3DDataFormat type; + DataFormat type; uint8_t offset; }; @@ -296,6 +304,10 @@ public: enum class ShaderStage { VERTEX, FRAGMENT, + GEOMETRY, + CONTROL, // HULL + EVALUATION, // DOMAIN + COMPUTE, }; enum class ShaderLanguage { @@ -307,42 +319,42 @@ enum class ShaderLanguage { HLSL_D3D11, }; -struct T3DBlendStateDesc { +struct BlendStateDesc { bool enabled; - T3DBlendFactor srcCol; - T3DBlendFactor dstCol; - T3DBlendEquation eqCol; - T3DBlendFactor srcAlpha; - T3DBlendFactor dstAlpha; - T3DBlendEquation eqAlpha; + BlendFactor srcCol; + BlendFactor dstCol; + BlendOp eqCol; + BlendFactor srcAlpha; + BlendFactor dstAlpha; + BlendOp eqAlpha; bool logicEnabled; - T3DLogicOp logicOp; + LogicOp logicOp; // int colorMask; }; struct T3DSamplerStateDesc { - T3DTextureFilter magFilt; - T3DTextureFilter minFilt; - T3DTextureFilter mipFilt; - T3DTextureWrap wrapS; - T3DTextureWrap wrapT; + TextureFilter magFilt; + TextureFilter minFilt; + TextureFilter mipFilt; + TextureAddressMode wrapS; + TextureAddressMode wrapT; }; -enum class T3DCullMode : uint8_t { - NO_CULL, +enum class CullMode : uint8_t { + NONE, FRONT, BACK, FRONT_AND_BACK, // Not supported on D3D9 }; -enum class T3DFacing { +enum class Facing { CCW, CW, }; struct T3DRasterStateDesc { - T3DCullMode cull; - T3DFacing facing; + CullMode cull; + Facing facing; }; class Thin3DContext : public Thin3DObject { @@ -351,8 +363,8 @@ public: virtual std::vector GetFeatureList() { return std::vector(); } - virtual Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, T3DComparison depthCompare) = 0; - virtual Thin3DBlendState *CreateBlendState(const T3DBlendStateDesc &desc) = 0; + virtual Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, Comparison depthCompare) = 0; + virtual BlendState *CreateBlendState(const BlendStateDesc &desc) = 0; virtual Thin3DSamplerState *CreateSamplerState(const T3DSamplerStateDesc &desc) = 0; virtual Thin3DRasterState *CreateRasterState(const T3DRasterStateDesc &desc) = 0; virtual Thin3DBuffer *CreateBuffer(size_t size, uint32_t usageFlags) = 0; @@ -360,11 +372,11 @@ public: virtual Thin3DVertexFormat *CreateVertexFormat(const std::vector &components, int stride, Thin3DShader *vshader) = 0; virtual Thin3DTexture *CreateTexture() = 0; // To be later filled in by ->LoadFromFile or similar. - virtual Thin3DTexture *CreateTexture(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) = 0; + virtual Thin3DTexture *CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) = 0; // Common Thin3D function, uses CreateTexture - Thin3DTexture *CreateTextureFromFile(const char *filename, T3DImageType fileType); - Thin3DTexture *CreateTextureFromFileData(const uint8_t *data, int size, T3DImageType fileType); + Thin3DTexture *CreateTextureFromFile(const char *filename, ImageFileType fileType); + Thin3DTexture *CreateTextureFromFileData(const uint8_t *data, int size, ImageFileType fileType); // Note that these DO NOT AddRef so you must not ->Release presets unless you manually AddRef them. Thin3DShader *GetVshaderPreset(T3DVertexShaderPreset preset) { return fsPresets_[preset]; } @@ -375,7 +387,7 @@ public: virtual Thin3DShader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) = 0; // Bound state objects. Too cumbersome to add them all as parameters to Draw. - virtual void SetBlendState(Thin3DBlendState *state) = 0; + virtual void SetBlendState(BlendState *state) = 0; virtual void SetSamplerStates(int start, int count, Thin3DSamplerState **state) = 0; virtual void SetDepthStencilState(Thin3DDepthStencilState *state) = 0; virtual void SetRasterState(Thin3DRasterState *state) = 0; @@ -388,12 +400,12 @@ public: // Raster state virtual void SetScissorEnabled(bool enable) = 0; virtual void SetScissorRect(int left, int top, int width, int height) = 0; - virtual void SetViewports(int count, T3DViewport *viewports) = 0; + virtual void SetViewports(int count, Viewport *viewports) = 0; // TODO: Add more sophisticated draws with buffer offsets, and multidraws. - virtual void Draw(T3DPrimitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) = 0; - virtual void DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) = 0; - virtual void DrawUP(T3DPrimitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, const void *vdata, int vertexCount) = 0; + virtual void Draw(Primitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) = 0; + virtual void DrawIndexed(Primitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) = 0; + virtual void DrawUP(Primitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, const void *vdata, int vertexCount) = 0; // Render pass management. Default implementations here. virtual void Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) { @@ -409,7 +421,7 @@ public: targetHeight_ = h; } - virtual std::string GetInfoString(T3DInfo info) const = 0; + virtual std::string GetInfoString(InfoField info) const = 0; protected: void CreatePresets(); diff --git a/ext/native/thin3d/thin3d_d3d9.cpp b/ext/native/thin3d/thin3d_d3d9.cpp index 338cbecfd6..61c0c69597 100644 --- a/ext/native/thin3d/thin3d_d3d9.cpp +++ b/ext/native/thin3d/thin3d_d3d9.cpp @@ -68,17 +68,27 @@ static const D3DTEXTUREFILTERTYPE texFilterToD3D9[] = { D3DTEXF_LINEAR, }; -static const D3DPRIMITIVETYPE primToD3D9[] = { - D3DPT_POINTLIST, - D3DPT_LINELIST, - D3DPT_TRIANGLELIST, -}; +inline D3DPRIMITIVETYPE PrimToD3D9(Primitive prim) { + switch (prim) { + case Primitive::POINT_LIST: return D3DPT_POINTLIST; + case Primitive::LINE_LIST: return D3DPT_LINELIST; + case Primitive::LINE_STRIP: return D3DPT_LINESTRIP; + case Primitive::TRIANGLE_LIST: return D3DPT_TRIANGLELIST; + case Primitive::TRIANGLE_STRIP: return D3DPT_TRIANGLESTRIP; + case Primitive::TRIANGLE_FAN: return D3DPT_TRIANGLEFAN; + } +} -static const int primCountDivisor[] = { - 1, - 2, - 3, -}; +inline int PrimCountDivisor(Primitive prim) { + switch (prim) { + case Primitive::POINT_LIST: return 1; + case Primitive::LINE_LIST: return 2; + case Primitive::LINE_STRIP: return 2; + case Primitive::TRIANGLE_LIST: return 3; + case Primitive::TRIANGLE_STRIP: return 3; + case Primitive::TRIANGLE_FAN: return 3; + } +} class Thin3DDX9DepthStencilState : public Thin3DDepthStencilState { public: @@ -104,7 +114,7 @@ public: }; -class Thin3DDX9BlendState : public Thin3DBlendState { +class Thin3DDX9BlendState : public BlendState { public: bool enabled; D3DBLENDOP eqCol, eqAlpha; @@ -140,7 +150,7 @@ public: class Thin3DDX9Buffer : public Thin3DBuffer { public: Thin3DDX9Buffer(LPDIRECT3DDEVICE9 device, size_t size, uint32_t flags) : vbuffer_(nullptr), ibuffer_(nullptr), maxSize_(size) { - if (flags & T3DBufferUsage::INDEXDATA) { + if (flags & BufferUsageFlag::INDEXDATA) { DWORD usage = D3DUSAGE_DYNAMIC; device->CreateIndexBuffer((UINT)size, usage, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &ibuffer_, NULL); } else { @@ -278,11 +288,11 @@ private: class Thin3DDX9Texture : public Thin3DTexture { public: - Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx) : device_(device), deviceEx_(deviceEx), type_(T3DTextureType::UNKNOWN), fmt_(D3DFMT_UNKNOWN), tex_(NULL), volTex_(NULL), cubeTex_(NULL) { + Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx) : device_(device), deviceEx_(deviceEx), type_(TextureType::UNKNOWN), fmt_(D3DFMT_UNKNOWN), tex_(NULL), volTex_(NULL), cubeTex_(NULL) { } - Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels); + Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels); ~Thin3DDX9Texture(); - bool Create(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) override; + bool Create(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override; void SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) override; void AutoGenMipmaps() override {} void SetToSampler(LPDIRECT3DDEVICE9 device, int sampler); @@ -291,24 +301,24 @@ public: private: LPDIRECT3DDEVICE9 device_; LPDIRECT3DDEVICE9EX deviceEx_; - T3DTextureType type_; + TextureType type_; D3DFORMAT fmt_; LPDIRECT3DTEXTURE9 tex_; LPDIRECT3DVOLUMETEXTURE9 volTex_; LPDIRECT3DCUBETEXTURE9 cubeTex_; }; -D3DFORMAT FormatToD3D(T3DDataFormat fmt) { +D3DFORMAT FormatToD3D(DataFormat fmt) { switch (fmt) { - case T3DDataFormat::R8A8G8B8_UNORM: return D3DFMT_A8R8G8B8; - case T3DDataFormat::R4G4B4A4_UNORM: return D3DFMT_A4R4G4B4; - case T3DDataFormat::D24S8: return D3DFMT_D24S8; - case T3DDataFormat::D16: return D3DFMT_D16; + case DataFormat::R8A8G8B8_UNORM: return D3DFMT_A8R8G8B8; + case DataFormat::R4G4B4A4_UNORM: return D3DFMT_A4R4G4B4; + case DataFormat::D24S8: return D3DFMT_D24S8; + case DataFormat::D16: return D3DFMT_D16; default: return D3DFMT_UNKNOWN; } } -Thin3DDX9Texture::Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) +Thin3DDX9Texture::Thin3DDX9Texture(LPDIRECT3DDEVICE9 device, LPDIRECT3DDEVICE9EX deviceEx, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) : device_(device), deviceEx_(deviceEx), type_(type), tex_(NULL), volTex_(NULL), cubeTex_(NULL) { Create(type, format, width, height, depth, mipLevels); } @@ -325,7 +335,7 @@ Thin3DDX9Texture::~Thin3DDX9Texture() { } } -bool Thin3DDX9Texture::Create(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) { +bool Thin3DDX9Texture::Create(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) { width_ = width; height_ = height; depth_ = depth; @@ -438,19 +448,19 @@ public: Thin3DDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx); ~Thin3DDX9Context(); - Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, T3DComparison depthCompare); - Thin3DBlendState *CreateBlendState(const T3DBlendStateDesc &desc) override; + Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, Comparison depthCompare); + BlendState *CreateBlendState(const BlendStateDesc &desc) override; Thin3DSamplerState *CreateSamplerState(const T3DSamplerStateDesc &desc) override; Thin3DRasterState *CreateRasterState(const T3DRasterStateDesc &desc) override; Thin3DBuffer *CreateBuffer(size_t size, uint32_t usageFlags) override; Thin3DShaderSet *CreateShaderSet(Thin3DShader *vshader, Thin3DShader *fshader) override; Thin3DVertexFormat *CreateVertexFormat(const std::vector &components, int stride, Thin3DShader *vshader) override; Thin3DTexture *CreateTexture() override; - Thin3DTexture *CreateTexture(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) override; + Thin3DTexture *CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override; Thin3DShader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override; // Bound state objects. Too cumbersome to add them all as parameters to Draw. - void SetBlendState(Thin3DBlendState *state) { + void SetBlendState(BlendState *state) { Thin3DDX9BlendState *bs = static_cast(state); bs->Apply(device_); } @@ -474,14 +484,14 @@ public: // Raster state void SetScissorEnabled(bool enable); void SetScissorRect(int left, int top, int width, int height); - void SetViewports(int count, T3DViewport *viewports); + void SetViewports(int count, Viewport *viewports); - void Draw(T3DPrimitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) override; - void DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) override; - void DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) override; + void Draw(Primitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) override; + void DrawIndexed(Primitive prim, Thin3DShaderSet *pipeline, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) override; + void DrawUP(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) override; void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal); - std::string GetInfoString(T3DInfo info) const override { + std::string GetInfoString(InfoField info) const override { switch (info) { case APIVERSION: return "DirectX 9.0"; case VENDORSTRING: return identifier_.Description; @@ -539,7 +549,7 @@ Thin3DShaderSet *Thin3DDX9Context::CreateShaderSet(Thin3DShader *vshader, Thin3D return shaderSet; } -Thin3DDepthStencilState *Thin3DDX9Context::CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, T3DComparison depthCompare) { +Thin3DDepthStencilState *Thin3DDX9Context::CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, Comparison depthCompare) { Thin3DDX9DepthStencilState *ds = new Thin3DDX9DepthStencilState(); ds->depthCompare = compareToD3D9[depthCompare]; ds->depthTestEnabled = depthTestEnabled; @@ -552,7 +562,7 @@ Thin3DVertexFormat *Thin3DDX9Context::CreateVertexFormat(const std::vectorenabled = desc.enabled; bs->eqCol = blendEqToD3D9[desc.eqCol]; @@ -578,19 +588,19 @@ Thin3DSamplerState *Thin3DDX9Context::CreateSamplerState(const T3DSamplerStateDe Thin3DRasterState *Thin3DDX9Context::CreateRasterState(const T3DRasterStateDesc &desc) { Thin3DDX9RasterState *rs = new Thin3DDX9RasterState(); rs->cullMode = D3DCULL_NONE; - if (desc.cull == T3DCullMode::NO_CULL) { + if (desc.cull == CullMode::NONE) { return rs; } switch (desc.facing) { - case T3DFacing::CW: + case Facing::CW: switch (desc.cull) { - case T3DCullMode::FRONT: rs->cullMode = D3DCULL_CCW; break; - case T3DCullMode::BACK: rs->cullMode = D3DCULL_CW; break; + case CullMode::FRONT: rs->cullMode = D3DCULL_CCW; break; + case CullMode::BACK: rs->cullMode = D3DCULL_CW; break; } - case T3DFacing::CCW: + case Facing::CCW: switch (desc.cull) { - case T3DCullMode::FRONT: rs->cullMode = D3DCULL_CW; break; - case T3DCullMode::BACK: rs->cullMode = D3DCULL_CCW; break; + case CullMode::FRONT: rs->cullMode = D3DCULL_CW; break; + case CullMode::BACK: rs->cullMode = D3DCULL_CCW; break; } } return rs; @@ -601,7 +611,7 @@ Thin3DTexture *Thin3DDX9Context::CreateTexture() { return tex; } -Thin3DTexture *Thin3DDX9Context::CreateTexture(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) { +Thin3DTexture *Thin3DDX9Context::CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) { Thin3DDX9Texture *tex = new Thin3DDX9Texture(device_, deviceEx_, type, format, width, height, depth, mipLevels); return tex; } @@ -613,7 +623,7 @@ void Thin3DDX9Context::BindTextures(int start, int count, Thin3DTexture **textur } } -void SemanticToD3D9UsageAndIndex(int semantic, BYTE *usage, BYTE *index) { +static void SemanticToD3D9UsageAndIndex(int semantic, BYTE *usage, BYTE *index) { *index = 0; switch (semantic) { case SEM_POSITION: @@ -641,12 +651,12 @@ void SemanticToD3D9UsageAndIndex(int semantic, BYTE *usage, BYTE *index) { } } -static int VertexDataTypeToD3DType(T3DDataFormat type) { +static int VertexDataTypeToD3DType(DataFormat type) { switch (type) { - case T3DDataFormat::FLOATx2: return D3DDECLTYPE_FLOAT2; - case T3DDataFormat::FLOATx3: return D3DDECLTYPE_FLOAT3; - case T3DDataFormat::FLOATx4: return D3DDECLTYPE_FLOAT4; - case T3DDataFormat::UNORM8x4: return D3DDECLTYPE_UBYTE4N; // D3DCOLOR? + case DataFormat::FLOATx2: return D3DDECLTYPE_FLOAT2; + case DataFormat::FLOATx3: return D3DDECLTYPE_FLOAT3; + case DataFormat::FLOATx4: return D3DDECLTYPE_FLOAT4; + case DataFormat::UNORM8x4: return D3DDECLTYPE_UBYTE4N; // D3DCOLOR? default: return D3DDECLTYPE_UNUSED; } } @@ -682,7 +692,7 @@ void Thin3DDX9ShaderSet::Apply(LPDIRECT3DDEVICE9 device) { pshader->Apply(device); } -void Thin3DDX9Context::Draw(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) { +void Thin3DDX9Context::Draw(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) { Thin3DDX9Buffer *vbuf = static_cast(vdata); Thin3DDX9VertexFormat *fmt = static_cast(format); Thin3DDX9ShaderSet *ss = static_cast(shaderSet); @@ -690,10 +700,10 @@ void Thin3DDX9Context::Draw(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3 vbuf->BindAsVertexBuf(device_, fmt->GetStride(), offset); ss->Apply(device_); fmt->Apply(device_); - device_->DrawPrimitive(primToD3D9[prim], offset, vertexCount / 3); + device_->DrawPrimitive(PrimToD3D9(prim), offset, vertexCount / 3); } -void Thin3DDX9Context::DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) { +void Thin3DDX9Context::DrawIndexed(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) { Thin3DDX9Buffer *vbuf = static_cast(vdata); Thin3DDX9Buffer *ibuf = static_cast(idata); Thin3DDX9VertexFormat *fmt = static_cast(format); @@ -703,16 +713,16 @@ void Thin3DDX9Context::DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *shaderSet fmt->Apply(device_); vbuf->BindAsVertexBuf(device_, fmt->GetStride(), offset); ibuf->BindAsIndexBuf(device_); - device_->DrawIndexedPrimitive(primToD3D9[prim], 0, 0, vertexCount, 0, vertexCount / primCountDivisor[prim]); + device_->DrawIndexedPrimitive(PrimToD3D9(prim), 0, 0, vertexCount, 0, vertexCount / PrimCountDivisor(prim)); } -void Thin3DDX9Context::DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) { +void Thin3DDX9Context::DrawUP(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) { Thin3DDX9VertexFormat *fmt = static_cast(format); Thin3DDX9ShaderSet *ss = static_cast(shaderSet); ss->Apply(device_); fmt->Apply(device_); - device_->DrawPrimitiveUP(primToD3D9[prim], vertexCount / 3, vdata, fmt->GetStride()); + device_->DrawPrimitiveUP(PrimToD3D9(prim), vertexCount / 3, vdata, fmt->GetStride()); } static uint32_t SwapRB(uint32_t c) { @@ -721,9 +731,9 @@ static uint32_t SwapRB(uint32_t c) { void Thin3DDX9Context::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) { UINT d3dMask = 0; - if (mask & T3DClear::COLOR) d3dMask |= D3DCLEAR_TARGET; - if (mask & T3DClear::DEPTH) d3dMask |= D3DCLEAR_ZBUFFER; - if (mask & T3DClear::STENCIL) d3dMask |= D3DCLEAR_STENCIL; + if (mask & ClearFlag::COLOR) d3dMask |= D3DCLEAR_TARGET; + if (mask & ClearFlag::DEPTH) d3dMask |= D3DCLEAR_ZBUFFER; + if (mask & ClearFlag::STENCIL) d3dMask |= D3DCLEAR_STENCIL; device_->Clear(0, NULL, d3dMask, (D3DCOLOR)SwapRB(colorval), depthVal, stencilVal); } @@ -741,7 +751,7 @@ void Thin3DDX9Context::SetScissorRect(int left, int top, int width, int height) device_->SetScissorRect(&rc); } -void Thin3DDX9Context::SetViewports(int count, T3DViewport *viewports) { +void Thin3DDX9Context::SetViewports(int count, Viewport *viewports) { D3DVIEWPORT9 vp; vp.X = (DWORD)viewports[0].TopLeftX; vp.Y = (DWORD)viewports[0].TopLeftY; diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index f56ae018d5..5632b702e7 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -83,6 +83,22 @@ static const unsigned short logicOpToGL[] = { }; #endif +inline GLuint PrimToGL(Primitive prim) { + switch (prim) { + case Primitive::POINT_LIST: return GL_POINTS; + case Primitive::LINE_LIST: return GL_LINES; + case Primitive::LINE_LIST_ADJ: return GL_LINES_ADJACENCY; + case Primitive::LINE_STRIP: return GL_LINE_STRIP; + case Primitive::LINE_STRIP_ADJ: return GL_LINE_STRIP_ADJACENCY; + case Primitive::TRIANGLE_LIST: return GL_TRIANGLES; + case Primitive::TRIANGLE_LIST_ADJ: return GL_TRIANGLES_ADJACENCY; + case Primitive::TRIANGLE_STRIP: return GL_TRIANGLE_STRIP; + case Primitive::TRIANGLE_STRIP_ADJ: return GL_TRIANGLES_ADJACENCY; + case Primitive::TRIANGLE_FAN: return GL_TRIANGLE_FAN; + case Primitive::PATCH_LIST: return GL_PATCHES; + default: return GL_POINTS; + } +} static const unsigned short primToGL[] = { GL_POINTS, GL_LINES, @@ -94,7 +110,7 @@ static const char *glsl_fragment_prelude = "precision mediump float;\n" "#endif\n"; -class Thin3DGLBlendState : public Thin3DBlendState { +class Thin3DGLBlendState : public BlendState { public: bool enabled; GLuint eqCol, eqAlpha; @@ -193,9 +209,9 @@ class Thin3DGLBuffer : public Thin3DBuffer, GfxResourceHolder { public: Thin3DGLBuffer(size_t size, uint32_t flags) { glGenBuffers(1, &buffer_); - target_ = (flags & T3DBufferUsage::INDEXDATA) ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER; + target_ = (flags & BufferUsageFlag::INDEXDATA) ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER; usage_ = 0; - if (flags & T3DBufferUsage::DYNAMIC) + if (flags & BufferUsageFlag::DYNAMIC) usage_ = GL_STREAM_DRAW; else usage_ = GL_STATIC_DRAW; @@ -376,18 +392,18 @@ public: Thin3DGLContext(); virtual ~Thin3DGLContext(); - Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, T3DComparison depthCompare) override; - Thin3DBlendState *CreateBlendState(const T3DBlendStateDesc &desc) override; + Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, Comparison depthCompare) override; + BlendState *CreateBlendState(const BlendStateDesc &desc) override; Thin3DSamplerState *CreateSamplerState(const T3DSamplerStateDesc &desc) override; Thin3DRasterState *CreateRasterState(const T3DRasterStateDesc &desc) override; Thin3DBuffer *CreateBuffer(size_t size, uint32_t usageFlags) override; Thin3DShaderSet *CreateShaderSet(Thin3DShader *vshader, Thin3DShader *fshader) override; Thin3DVertexFormat *CreateVertexFormat(const std::vector &components, int stride, Thin3DShader *vshader) override; - Thin3DTexture *CreateTexture(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) override; + Thin3DTexture *CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override; Thin3DTexture *CreateTexture() override; // Bound state objects - void SetBlendState(Thin3DBlendState *state) override { + void SetBlendState(BlendState *state) override { Thin3DGLBlendState *s = static_cast(state); s->Apply(); } @@ -439,7 +455,7 @@ public: glScissor(left, targetHeight_ - (top + height), width, height); } - void SetViewports(int count, T3DViewport *viewports) override { + void SetViewports(int count, Viewport *viewports) override { // TODO: Add support for multiple viewports. glViewport(viewports[0].TopLeftX, viewports[0].TopLeftY, viewports[0].Width, viewports[0].Height); #if defined(USING_GLES2) @@ -452,12 +468,12 @@ public: void BindTextures(int start, int count, Thin3DTexture **textures) override; // TODO: Add more sophisticated draws. - void Draw(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) override; - void DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) override; - void DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) override; + void Draw(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) override; + void DrawIndexed(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) override; + void DrawUP(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) override; void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override; - std::string GetInfoString(T3DInfo info) const override { + std::string GetInfoString(InfoField info) const override { // TODO: Make these actually query the right information switch (info) { case APINAME: @@ -512,7 +528,7 @@ Thin3DVertexFormat *Thin3DGLContext::CreateVertexFormat(const std::vectordepthTestEnabled = depthTestEnabled; ds->depthWriteEnabled = depthWriteEnabled; @@ -719,7 +735,7 @@ Thin3DDepthStencilState *Thin3DGLContext::CreateDepthStencilState(bool depthTest return ds; } -Thin3DBlendState *Thin3DGLContext::CreateBlendState(const T3DBlendStateDesc &desc) { +BlendState *Thin3DGLContext::CreateBlendState(const BlendStateDesc &desc) { Thin3DGLBlendState *bs = new Thin3DGLBlendState(); bs->enabled = desc.enabled; bs->eqCol = blendEqToGL[desc.eqCol]; @@ -730,7 +746,7 @@ Thin3DBlendState *Thin3DGLContext::CreateBlendState(const T3DBlendStateDesc &des bs->dstAlpha = blendFactorToGL[desc.dstAlpha]; #ifndef USING_GLES2 bs->logicEnabled = desc.logicEnabled; - bs->logicOp = logicOpToGL[desc.logicOp]; + bs->logicOp = logicOpToGL[(int)desc.logicOp]; #endif return bs; } @@ -747,27 +763,27 @@ Thin3DSamplerState *Thin3DGLContext::CreateSamplerState(const T3DSamplerStateDes Thin3DRasterState *Thin3DGLContext::CreateRasterState(const T3DRasterStateDesc &desc) { Thin3DGLRasterState *rs = new Thin3DGLRasterState(); - if (desc.cull == T3DCullMode::NO_CULL) { + if (desc.cull == CullMode::NONE) { rs->cullEnable = GL_FALSE; return rs; } rs->cullEnable = GL_TRUE; switch (desc.facing) { - case T3DFacing::CW: + case Facing::CW: rs->frontFace = GL_CW; break; - case T3DFacing::CCW: + case Facing::CCW: rs->frontFace = GL_CCW; break; } switch (desc.cull) { - case T3DCullMode::FRONT: + case CullMode::FRONT: rs->cullMode = GL_FRONT; break; - case T3DCullMode::BACK: + case CullMode::BACK: rs->cullMode = GL_BACK; break; - case T3DCullMode::FRONT_AND_BACK: + case CullMode::FRONT_AND_BACK: rs->cullMode = GL_FRONT_AND_BACK; break; } @@ -911,7 +927,7 @@ void Thin3DGLShaderSet::Unapply() { glUseProgram(0); } -void Thin3DGLContext::Draw(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) { +void Thin3DGLContext::Draw(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) { Thin3DGLShaderSet *ss = static_cast(shaderSet); Thin3DGLBuffer *vbuf = static_cast(vdata); Thin3DGLVertexFormat *fmt = static_cast(format); @@ -920,13 +936,13 @@ void Thin3DGLContext::Draw(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3D fmt->Apply(); ss->Apply(); - glDrawArrays(primToGL[prim], offset, vertexCount); + glDrawArrays(PrimToGL(prim), offset, vertexCount); ss->Unapply(); fmt->Unapply(); } -void Thin3DGLContext::DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) { +void Thin3DGLContext::DrawIndexed(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) { Thin3DGLShaderSet *ss = static_cast(shaderSet); Thin3DGLBuffer *vbuf = static_cast(vdata); Thin3DGLBuffer *ibuf = static_cast(idata); @@ -938,13 +954,13 @@ void Thin3DGLContext::DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *shaderSet, // Note: ibuf binding is stored in the VAO, so call this after binding the fmt. ibuf->Bind(); - glDrawElements(primToGL[prim], vertexCount, GL_UNSIGNED_INT, (const void *)(size_t)offset); + glDrawElements(PrimToGL(prim), vertexCount, GL_UNSIGNED_INT, (const void *)(size_t)offset); ss->Unapply(); fmt->Unapply(); } -void Thin3DGLContext::DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) { +void Thin3DGLContext::DrawUP(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) { Thin3DGLShaderSet *ss = static_cast(shaderSet); Thin3DGLVertexFormat *fmt = static_cast(format); @@ -953,7 +969,7 @@ void Thin3DGLContext::DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glDrawArrays(primToGL[prim], 0, vertexCount); + glDrawArrays(PrimToGL(prim), 0, vertexCount); ss->Unapply(); fmt->Unapply(); @@ -963,11 +979,11 @@ void Thin3DGLContext::Clear(int mask, uint32_t colorval, float depthVal, int ste float col[4]; Uint8x4ToFloat4(col, colorval); GLuint glMask = 0; - if (mask & T3DClear::COLOR) { + if (mask & ClearFlag::COLOR) { glClearColor(col[0], col[1], col[2], col[3]); glMask |= GL_COLOR_BUFFER_BIT; } - if (mask & T3DClear::DEPTH) { + if (mask & ClearFlag::DEPTH) { #if defined(USING_GLES2) glClearDepthf(depthVal); #else @@ -975,7 +991,7 @@ void Thin3DGLContext::Clear(int mask, uint32_t colorval, float depthVal, int ste #endif glMask |= GL_DEPTH_BUFFER_BIT; } - if (mask & T3DClear::STENCIL) { + if (mask & ClearFlag::STENCIL) { glClearStencil(stencilVal); glMask |= GL_STENCIL_BUFFER_BIT; } @@ -1006,19 +1022,19 @@ void Thin3DGLVertexFormat::Apply(const void *base) { if (b != lastBase_) { for (size_t i = 0; i < components_.size(); i++) { switch (components_[i].type) { - case T3DDataFormat::FLOATx2: + case DataFormat::FLOATx2: glVertexAttribPointer(components_[i].semantic, 2, GL_FLOAT, GL_FALSE, stride_, (void *)(b + (intptr_t)components_[i].offset)); break; - case T3DDataFormat::FLOATx3: + case DataFormat::FLOATx3: glVertexAttribPointer(components_[i].semantic, 3, GL_FLOAT, GL_FALSE, stride_, (void *)(b + (intptr_t)components_[i].offset)); break; - case T3DDataFormat::FLOATx4: + case DataFormat::FLOATx4: glVertexAttribPointer(components_[i].semantic, 4, GL_FLOAT, GL_FALSE, stride_, (void *)(b + (intptr_t)components_[i].offset)); break; - case T3DDataFormat::UNORM8x4: + case DataFormat::UNORM8x4: glVertexAttribPointer(components_[i].semantic, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride_, (void *)(b + (intptr_t)components_[i].offset)); break; - case T3DDataFormat::UNKNOWN: + case DataFormat::UNKNOWN: default: ELOG("Thin3DGLVertexFormat: Invalid or unknown component type applied."); break; @@ -1032,7 +1048,7 @@ void Thin3DGLVertexFormat::Apply(const void *base) { void Thin3DGLVertexFormat::Unapply() { if (id_ == 0) { - for (int i = 0; i < SEM_MAX; i++) { + for (int i = 0; i < (int)SEM_MAX; i++) { if (semanticsMask_ & (1 << i)) { glDisableVertexAttribArray(i); } diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index f2ff7faf8f..5160c59987 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -100,7 +100,16 @@ static const VkLogicOp logicOpToVK[] = { static const VkPrimitiveTopology primToVK[] = { VK_PRIMITIVE_TOPOLOGY_POINT_LIST, VK_PRIMITIVE_TOPOLOGY_LINE_LIST, + VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN, + VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, + // These are for geometry shaders only. + VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY, + VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY, }; static inline void Uint8x4ToFloat4(uint32_t u, float f[4]) { @@ -111,7 +120,7 @@ static inline void Uint8x4ToFloat4(uint32_t u, float f[4]) { } -class Thin3DVKBlendState : public Thin3DBlendState { +class Thin3DVKBlendState : public BlendState { public: bool blendEnabled; VkBlendOp eqCol, eqAlpha; @@ -160,18 +169,18 @@ public: cullFace = desc.cull; frontFace = desc.facing; } - T3DFacing frontFace; - T3DCullMode cullFace; + Facing frontFace; + CullMode cullFace; void ToVulkan(VkPipelineRasterizationStateCreateInfo *info) { memset(info, 0, sizeof(*info)); info->sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; - info->frontFace = frontFace == T3DFacing::CCW ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE; + info->frontFace = frontFace == Facing::CCW ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE; switch (cullFace) { - case T3DCullMode::BACK: info->cullMode = VK_CULL_MODE_BACK_BIT; break; - case T3DCullMode::FRONT: info->cullMode = VK_CULL_MODE_FRONT_BIT; break; - case T3DCullMode::FRONT_AND_BACK: info->cullMode = VK_CULL_MODE_FRONT_AND_BACK; break; - case T3DCullMode::NO_CULL: info->cullMode = VK_CULL_MODE_NONE; break; + case CullMode::BACK: info->cullMode = VK_CULL_MODE_BACK_BIT; break; + case CullMode::FRONT: info->cullMode = VK_CULL_MODE_FRONT_BIT; break; + case CullMode::FRONT_AND_BACK: info->cullMode = VK_CULL_MODE_FRONT_AND_BACK; break; + case CullMode::NONE: info->cullMode = VK_CULL_MODE_NONE; break; } info->polygonMode = VK_POLYGON_MODE_FILL; info->lineWidth = 1.0f; @@ -262,12 +271,12 @@ bool Thin3DVKShader::Compile(VulkanContext *vulkan, const char *source) { } -inline VkFormat ConvertVertexDataTypeToVk(T3DDataFormat type) { +inline VkFormat ConvertVertexDataTypeToVk(DataFormat type) { switch (type) { - case T3DDataFormat::FLOATx2: return VK_FORMAT_R32G32_SFLOAT; - case T3DDataFormat::FLOATx3: return VK_FORMAT_R32G32B32_SFLOAT; - case T3DDataFormat::FLOATx4: return VK_FORMAT_R32G32B32A32_SFLOAT; - case T3DDataFormat::UNORM8x4: return VK_FORMAT_R8G8B8A8_UNORM; + case DataFormat::FLOATx2: return VK_FORMAT_R32G32_SFLOAT; + case DataFormat::FLOATx3: return VK_FORMAT_R32G32B32_SFLOAT; + case DataFormat::FLOATx4: return VK_FORMAT_R32G32B32A32_SFLOAT; + case DataFormat::UNORM8x4: return VK_FORMAT_R8G8B8A8_UNORM; default: return VK_FORMAT_UNDEFINED; } } @@ -381,18 +390,18 @@ public: Thin3DVKContext(VulkanContext *vulkan); virtual ~Thin3DVKContext(); - Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, T3DComparison depthCompare) override; - Thin3DBlendState *CreateBlendState(const T3DBlendStateDesc &desc) override; + Thin3DDepthStencilState *CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, Comparison depthCompare) override; + BlendState *CreateBlendState(const BlendStateDesc &desc) override; Thin3DBuffer *CreateBuffer(size_t size, uint32_t usageFlags) override; Thin3DShaderSet *CreateShaderSet(Thin3DShader *vshader, Thin3DShader *fshader) override; Thin3DVertexFormat *CreateVertexFormat(const std::vector &components, int stride, Thin3DShader *vshader) override; Thin3DSamplerState *CreateSamplerState(const T3DSamplerStateDesc &desc) override; Thin3DRasterState *CreateRasterState(const T3DRasterStateDesc &desc) override; - Thin3DTexture *CreateTexture(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) override; + Thin3DTexture *CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override; Thin3DTexture *CreateTexture() override; // Bound state objects - void SetBlendState(Thin3DBlendState *state) override { + void SetBlendState(BlendState *state) override { Thin3DVKBlendState *s = static_cast(state); curBlendState_ = s; } @@ -419,23 +428,23 @@ public: void SetScissorRect(int left, int top, int width, int height) override; - void SetViewports(int count, T3DViewport *viewports) override; + void SetViewports(int count, Viewport *viewports) override; void BindTextures(int start, int count, Thin3DTexture **textures) override; void SetSamplerStates(int start, int count, Thin3DSamplerState **state) override; // TODO: Add more sophisticated draws. - void Draw(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) override; - void DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) override; - void DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) override; + void Draw(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) override; + void DrawIndexed(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) override; + void DrawUP(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) override; void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override; void Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) override; void End() override; - std::string GetInfoString(T3DInfo info) const override { + std::string GetInfoString(InfoField info) const override { // TODO: Make these actually query the right information switch (info) { case APINAME: return "Vulkan"; @@ -513,12 +522,12 @@ private: VulkanPushBuffer *push_; }; -VkFormat FormatToVulkan(T3DDataFormat fmt, int *bpp) { +VkFormat FormatToVulkan(DataFormat fmt, int *bpp) { switch (fmt) { - case T3DDataFormat::R8A8G8B8_UNORM: *bpp = 32; return VK_FORMAT_R8G8B8A8_UNORM; - case T3DDataFormat::R4G4B4A4_UNORM: *bpp = 16; return VK_FORMAT_R4G4B4A4_UNORM_PACK16; - case T3DDataFormat::D24S8: *bpp = 32; return VK_FORMAT_D24_UNORM_S8_UINT; - case T3DDataFormat::D16: *bpp = 16; return VK_FORMAT_D16_UNORM; + case DataFormat::R8A8G8B8_UNORM: *bpp = 32; return VK_FORMAT_R8G8B8A8_UNORM; + case DataFormat::R4G4B4A4_UNORM: *bpp = 16; return VK_FORMAT_R4G4B4A4_UNORM_PACK16; + case DataFormat::D24S8: *bpp = 32; return VK_FORMAT_D24_UNORM_S8_UINT; + case DataFormat::D16: *bpp = 16; return VK_FORMAT_D16_UNORM; default: return VK_FORMAT_UNDEFINED; } } @@ -527,11 +536,11 @@ class Thin3DVKSamplerState : public Thin3DSamplerState { public: Thin3DVKSamplerState(VulkanContext *vulkan, const T3DSamplerStateDesc &desc) : vulkan_(vulkan) { VkSamplerCreateInfo s = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO }; - s.addressModeU = desc.wrapS == T3DTextureWrap::REPEAT ? VK_SAMPLER_ADDRESS_MODE_REPEAT : VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - s.addressModeV = desc.wrapT == T3DTextureWrap::REPEAT ? VK_SAMPLER_ADDRESS_MODE_REPEAT : VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - s.magFilter = desc.magFilt == T3DTextureFilter::LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; - s.minFilter = desc.minFilt == T3DTextureFilter::LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; - s.mipmapMode = desc.mipFilt == T3DTextureFilter::LINEAR ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST; + s.addressModeU = desc.wrapS == TextureAddressMode::REPEAT ? VK_SAMPLER_ADDRESS_MODE_REPEAT : VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + s.addressModeV = desc.wrapT == TextureAddressMode::REPEAT ? VK_SAMPLER_ADDRESS_MODE_REPEAT : VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + s.magFilter = desc.magFilt == TextureFilter::LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; + s.minFilter = desc.minFilt == TextureFilter::LINEAR ? VK_FILTER_LINEAR : VK_FILTER_NEAREST; + s.mipmapMode = desc.mipFilt == TextureFilter::LINEAR ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST; s.maxLod = 0.0; // TODO: Actually support mipmaps VkResult res = vkCreateSampler(vulkan_->GetDevice(), &s, nullptr, &sampler_); @@ -574,7 +583,7 @@ public: Thin3DVKTexture(VulkanContext *vulkan) : vulkan_(vulkan), vkTex_(nullptr) { } - Thin3DVKTexture(VulkanContext *vulkan, T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) + Thin3DVKTexture(VulkanContext *vulkan, TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) : vulkan_(vulkan), format_(format), mipLevels_(mipLevels) { Create(type, format, width, height, depth, mipLevels); } @@ -583,7 +592,7 @@ public: Destroy(); } - bool Create(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) override { + bool Create(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override { format_ = format; mipLevels_ = mipLevels; width_ = width; @@ -613,7 +622,7 @@ private: int mipLevels_; - T3DDataFormat format_; + DataFormat format_; }; Thin3DVKContext::Thin3DVKContext(VulkanContext *vulkan) @@ -914,7 +923,7 @@ void Thin3DVKContext::SetScissorRect(int left, int top, int width, int height) { scissorDirty_ = true; } -void Thin3DVKContext::SetViewports(int count, T3DViewport *viewports) { +void Thin3DVKContext::SetViewports(int count, Viewport *viewports) { viewport_.x = viewports[0].TopLeftX; viewport_.y = viewports[0].TopLeftY; viewport_.width = viewports[0].Width; @@ -955,7 +964,7 @@ Thin3DTexture *Thin3DVKContext::CreateTexture() { return new Thin3DVKTexture(vulkan_); } -Thin3DTexture *Thin3DVKContext::CreateTexture(T3DTextureType type, T3DDataFormat format, int width, int height, int depth, int mipLevels) { +Thin3DTexture *Thin3DVKContext::CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) { return new Thin3DVKTexture(vulkan_, type, format, width, height, depth, mipLevels); } @@ -976,7 +985,7 @@ void Thin3DVKTexture::Finalize(int zim_flags) { // TODO } -Thin3DDepthStencilState *Thin3DVKContext::CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, T3DComparison depthCompare) { +Thin3DDepthStencilState *Thin3DVKContext::CreateDepthStencilState(bool depthTestEnabled, bool depthWriteEnabled, Comparison depthCompare) { Thin3DVKDepthStencilState *ds = new Thin3DVKDepthStencilState(); ds->depthTestEnabled = depthTestEnabled; ds->depthWriteEnabled = depthWriteEnabled; @@ -984,7 +993,7 @@ Thin3DDepthStencilState *Thin3DVKContext::CreateDepthStencilState(bool depthTest return ds; } -Thin3DBlendState *Thin3DVKContext::CreateBlendState(const T3DBlendStateDesc &desc) { +BlendState *Thin3DVKContext::CreateBlendState(const BlendStateDesc &desc) { Thin3DVKBlendState *bs = new Thin3DVKBlendState(); bs->blendEnabled = desc.enabled; bs->eqCol = blendEqToGL[desc.eqCol]; @@ -994,7 +1003,7 @@ Thin3DBlendState *Thin3DVKContext::CreateBlendState(const T3DBlendStateDesc &des bs->srcAlpha = blendFactorToVk[desc.srcAlpha]; bs->dstAlpha = blendFactorToVk[desc.dstAlpha]; bs->logicEnabled = desc.logicEnabled; - bs->logicOp = logicOpToVK[desc.logicOp]; + bs->logicOp = logicOpToVK[(int)desc.logicOp]; return bs; } @@ -1064,10 +1073,28 @@ void Thin3DVKShaderSet::SetMatrix4x4(const char *name, const float value[16]) { } } -void Thin3DVKContext::Draw(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) { +inline VkPrimitiveTopology PrimToVK(Primitive prim) { + switch (prim) { + case Primitive::POINT_LIST: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST; + case Primitive::LINE_LIST: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST; + case Primitive::LINE_LIST_ADJ: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY; + case Primitive::LINE_STRIP: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP; + case Primitive::LINE_STRIP_ADJ: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY; + case Primitive::TRIANGLE_LIST: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + case Primitive::TRIANGLE_LIST_ADJ: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY; + case Primitive::TRIANGLE_STRIP: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + case Primitive::TRIANGLE_STRIP_ADJ: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY; + case Primitive::TRIANGLE_FAN: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN; + case Primitive::PATCH_LIST: return VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; + default: + return VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; + } +} + +void Thin3DVKContext::Draw(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, int vertexCount, int offset) { ApplyDynamicState(); - curPrim_ = primToVK[prim]; + curPrim_ = PrimToVK(prim); curShaderSet_ = (Thin3DVKShaderSet *)shaderSet; curVertexFormat_ = (Thin3DVKVertexFormat *)format; Thin3DVKBuffer *vbuf = static_cast(vdata); @@ -1087,10 +1114,10 @@ void Thin3DVKContext::Draw(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3D vkCmdDraw(cmd_, vertexCount, 1, offset, 0); } -void Thin3DVKContext::DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) { +void Thin3DVKContext::DrawIndexed(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, Thin3DBuffer *vdata, Thin3DBuffer *idata, int vertexCount, int offset) { ApplyDynamicState(); - curPrim_ = primToVK[prim]; + curPrim_ = PrimToVK(prim); curShaderSet_ = (Thin3DVKShaderSet *)shaderSet; curVertexFormat_ = (Thin3DVKVertexFormat *)format; @@ -1116,10 +1143,10 @@ void Thin3DVKContext::DrawIndexed(T3DPrimitive prim, Thin3DShaderSet *shaderSet, vkCmdDrawIndexed(cmd_, vertexCount, 1, 0, offset, 0); } -void Thin3DVKContext::DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) { +void Thin3DVKContext::DrawUP(Primitive prim, Thin3DShaderSet *shaderSet, Thin3DVertexFormat *format, const void *vdata, int vertexCount) { ApplyDynamicState(); - curPrim_ = primToVK[prim]; + curPrim_ = PrimToVK(prim); curShaderSet_ = (Thin3DVKShaderSet *)shaderSet; curVertexFormat_ = (Thin3DVKVertexFormat *)format; @@ -1140,7 +1167,7 @@ void Thin3DVKContext::DrawUP(T3DPrimitive prim, Thin3DShaderSet *shaderSet, Thin } void Thin3DVKContext::Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) { - if (mask & T3DClear::COLOR) { + if (mask & ClearFlag::COLOR) { VkClearColorValue col; Uint8x4ToFloat4(colorval, col.float32); @@ -1150,7 +1177,7 @@ void Thin3DVKContext::Clear(int mask, uint32_t colorval, float depthVal, int ste vkCmdClearColorAttachment(cmdBuf_, 0, imageLayout_, &col, 1, nullptr); */ } - if (mask & (T3DClear::DEPTH | T3DClear::STENCIL)) { + if (mask & (ClearFlag::DEPTH | ClearFlag::STENCIL)) { } } diff --git a/ext/native/ui/ui_context.cpp b/ext/native/ui/ui_context.cpp index 4bd670e5d7..0f53b939bd 100644 --- a/ext/native/ui/ui_context.cpp +++ b/ext/native/ui/ui_context.cpp @@ -26,12 +26,12 @@ UIContext::~UIContext() { void UIContext::Init(Draw::Thin3DContext *thin3d, Draw::Thin3DShaderSet *uishader, Draw::Thin3DShaderSet *uishadernotex, Draw::Thin3DTexture *uitexture, DrawBuffer *uidrawbuffer, DrawBuffer *uidrawbufferTop) { using namespace Draw; thin3d_ = thin3d; - blendNormal_ = thin3d_->CreateBlendState({ true, T3DBlendFactor::SRC_ALPHA, T3DBlendFactor::ONE_MINUS_SRC_ALPHA }); - sampler_ = thin3d_->CreateSamplerState({ T3DTextureFilter::LINEAR, T3DTextureFilter::LINEAR,T3DTextureFilter::LINEAR }); - depth_ = thin3d_->CreateDepthStencilState(false, false, T3DComparison::LESS); + blendNormal_ = thin3d_->CreateBlendState({ true, BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA }); + sampler_ = thin3d_->CreateSamplerState({ TextureFilter::LINEAR, TextureFilter::LINEAR,TextureFilter::LINEAR }); + depth_ = thin3d_->CreateDepthStencilState(false, false, Comparison::LESS); T3DRasterStateDesc desc; - desc.cull = T3DCullMode::NO_CULL; - desc.facing = T3DFacing::CCW; + desc.cull = CullMode::NONE; + desc.facing = Facing::CCW; rasterNoCull_ = thin3d_->CreateRasterState(desc); uishader_ = uishader; uishadernotex_ = uishadernotex; diff --git a/ext/native/ui/ui_context.h b/ext/native/ui/ui_context.h index 9b1af40439..5a6b507710 100644 --- a/ext/native/ui/ui_context.h +++ b/ext/native/ui/ui_context.h @@ -14,7 +14,7 @@ namespace Draw { class Thin3DShaderSet; class Thin3DDepthStencilState; class Thin3DTexture; - class Thin3DBlendState; + class BlendState; class Thin3DSamplerState; class Thin3DRasterState; } @@ -89,7 +89,7 @@ private: Draw::Thin3DDepthStencilState *depth_; Draw::Thin3DSamplerState *sampler_; Draw::Thin3DRasterState *rasterNoCull_; - Draw::Thin3DBlendState *blendNormal_; + Draw::BlendState *blendNormal_; Draw::Thin3DShaderSet *uishader_; Draw::Thin3DShaderSet *uishadernotex_; Draw::Thin3DTexture *uitexture_; diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index 2bbac86287..c612f749b4 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -65,7 +65,7 @@ void UIScreen::preRender() { } thin3d->Begin(true, 0xFF000000, 0.0f, 0); - Draw::T3DViewport viewport; + Draw::Viewport viewport; viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = pixel_xres;