Skip to content

Commit

Permalink
squash me
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupeyy committed Nov 3, 2023
1 parent ae75b57 commit 061a9c0
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 196 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@ set(EXPECTED_DATA
editor/entities_clear/vanilla.png
editor/front.png
editor/speed_arrow.png
editor/speed_arrow_array.png
editor/speedup.png
editor/switch.png
editor/tele.png
Expand Down
Binary file added data/editor/speed_arrow_array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions data/shader/tile.vert
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
layout (location = 0) in vec2 inVertex;
#ifdef TW_TILE_TEXTURED
layout (location = 1) in vec3 inVertexTexCoord;
layout (location = 1) in uvec4 inVertexTexCoord;
#endif

uniform mat4x2 gPos;
Expand All @@ -14,6 +14,6 @@ void main()
gl_Position = vec4(gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);

#ifdef TW_TILE_TEXTURED
TexCoord = inVertexTexCoord;
TexCoord = vec3(inVertexTexCoord.xyz);
#endif
}
7 changes: 5 additions & 2 deletions data/shader/tile_border.vert
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
layout (location = 0) in vec2 inVertex;
#ifdef TW_TILE_TEXTURED
layout (location = 1) in vec3 inVertexTexCoord;
layout (location = 1) in uvec4 inVertexTexCoord;
#endif

uniform mat4x2 gPos;
Expand All @@ -20,6 +20,9 @@ void main()

#ifdef TW_TILE_TEXTURED
// scale the texture coordinates too
TexCoord = vec3(inVertexTexCoord.xy * gScale, inVertexTexCoord.z);
vec2 TexScale = gScale;
if (float(inVertexTexCoord.w) > 0.0)
TexScale = gScale.yx;
TexCoord = vec3(vec2(inVertexTexCoord.xy) * TexScale, float(inVertexTexCoord.z));
#endif
}
4 changes: 2 additions & 2 deletions data/shader/vulkan/tile.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

layout (location = 0) in vec2 inVertex;
#ifdef TW_TILE_TEXTURED
layout (location = 1) in vec3 inVertexTexCoord;
layout (location = 1) in uvec4 inVertexTexCoord;
#endif

layout(push_constant) uniform SPosBO {
Expand All @@ -19,6 +19,6 @@ void main()
gl_Position = vec4(gPosBO.gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);

#ifdef TW_TILE_TEXTURED
TexCoord = inVertexTexCoord;
TexCoord = vec3(inVertexTexCoord.xyz);
#endif
}
7 changes: 5 additions & 2 deletions data/shader/vulkan/tile_border.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

layout (location = 0) in vec2 inVertex;
#ifdef TW_TILE_TEXTURED
layout (location = 1) in vec3 inVertexTexCoord;
layout (location = 1) in uvec4 inVertexTexCoord;
#endif

layout(push_constant) uniform SPosBO {
Expand All @@ -25,6 +25,9 @@ void main()

#ifdef TW_TILE_TEXTURED
// scale the texture coordinates too
TexCoord = vec3(inVertexTexCoord.xy * gPosBO.gScale, inVertexTexCoord.z);
vec2 TexScale = gPosBO.gScale;
if (inVertexTexCoord.w > 0)
TexScale = gPosBO.gScale.yx;
TexCoord = vec3(vec2(inVertexTexCoord.xy) * TexScale, float(inVertexTexCoord.z));
#endif
}
2 changes: 2 additions & 0 deletions src/base/vmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define BASE_VMATH_H

#include <cmath>
#include <cstdint>

#include "math.h"

Expand Down Expand Up @@ -399,5 +400,6 @@ class vector4_base
typedef vector4_base<float> vec4;
typedef vector4_base<bool> bvec4;
typedef vector4_base<int> ivec4;
typedef vector4_base<uint8_t> ubvec4;

#endif
64 changes: 18 additions & 46 deletions src/engine/client/backend/opengl/backend_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ bool CCommandProcessorFragment_OpenGL::InitOpenGL(const SCommand_Init *pCommand)
pCommand->m_pCapabilities->m_ContextPatch = 0;
}

pCommand->m_pCapabilities->m_TileBuffering = pCommand->m_pCapabilities->m_2DArrayTextures || pCommand->m_pCapabilities->m_3DTextures;
pCommand->m_pCapabilities->m_TileBuffering = pCommand->m_pCapabilities->m_2DArrayTextures;
pCommand->m_pCapabilities->m_QuadBuffering = false;
pCommand->m_pCapabilities->m_TextBuffering = false;
pCommand->m_pCapabilities->m_QuadContainerBuffering = false;
Expand All @@ -464,8 +464,6 @@ bool CCommandProcessorFragment_OpenGL::InitOpenGL(const SCommand_Init *pCommand)
pCommand->m_pCapabilities->m_2DArrayTextures = false;

pCommand->m_pCapabilities->m_ShaderSupport = false;
if(MinorV >= 1)
pCommand->m_pCapabilities->m_ShaderSupport = true;

int Texture3DSize = 0;
glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &Texture3DSize);
Expand All @@ -474,18 +472,6 @@ bool CCommandProcessorFragment_OpenGL::InitOpenGL(const SCommand_Init *pCommand)
pCommand->m_pCapabilities->m_3DTextures = true;
}

// check for array texture extension
if(pCommand->m_pCapabilities->m_ShaderSupport && GLEW_EXT_texture_array)
{
int TextureLayers = 0;
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS_EXT, &TextureLayers);
if(TextureLayers >= 256)
{
pCommand->m_pCapabilities->m_2DArrayTextures = true;
pCommand->m_pCapabilities->m_2DArrayTexturesAsExtension = true;
}
}

pCommand->m_pCapabilities->m_TileBuffering = false;
pCommand->m_pCapabilities->m_QuadBuffering = false;
pCommand->m_pCapabilities->m_TextBuffering = false;
Expand Down Expand Up @@ -815,8 +801,8 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He
glTexImage2D(GL_TEXTURE_2D, 0, GLStoreFormat, Width, Height, 0, GLFormat, GL_UNSIGNED_BYTE, pTexData);
}

int Flag2DArrayTexture = (CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE | CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER);
int Flag3DTexture = (CCommandBuffer::TEXFLAG_TO_3D_TEXTURE | CCommandBuffer::TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER);
int Flag2DArrayTexture = CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE;
int Flag3DTexture = CCommandBuffer::TEXFLAG_TO_3D_TEXTURE;
if((Flags & (Flag2DArrayTexture | Flag3DTexture)) != 0)
{
bool Is3DTexture = (Flags & Flag3DTexture) != 0;
Expand Down Expand Up @@ -882,46 +868,32 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He

uint8_t *p3DImageData = NULL;

bool IsSingleLayer = (Flags & (CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER | CCommandBuffer::TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER)) != 0;

if(!IsSingleLayer)
p3DImageData = (uint8_t *)malloc((size_t)Width * Height * PixelSize);
p3DImageData = (uint8_t *)malloc((size_t)Width * Height * PixelSize);
int Image3DWidth, Image3DHeight;

int ConvertWidth = Width;
int ConvertHeight = Height;

if(!IsSingleLayer)
if(ConvertWidth == 0 || (ConvertWidth % 16) != 0 || ConvertHeight == 0 || (ConvertHeight % 16) != 0)
{
if(ConvertWidth == 0 || (ConvertWidth % 16) != 0 || ConvertHeight == 0 || (ConvertHeight % 16) != 0)
{
dbg_msg("gfx", "3D/2D array texture was resized");
int NewWidth = maximum<int>(HighestBit(ConvertWidth), 16);
int NewHeight = maximum<int>(HighestBit(ConvertHeight), 16);
uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pTexData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, GLFormatToPixelSize(GLFormat));
dbg_msg("gfx", "3D/2D array texture was resized");
int NewWidth = maximum<int>(HighestBit(ConvertWidth), 16);
int NewHeight = maximum<int>(HighestBit(ConvertHeight), 16);
uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pTexData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, GLFormatToPixelSize(GLFormat));

ConvertWidth = NewWidth;
ConvertHeight = NewHeight;
ConvertWidth = NewWidth;
ConvertHeight = NewHeight;

free(pTexData);
pTexData = pNewTexData;
}
free(pTexData);
pTexData = pNewTexData;
}

if(IsSingleLayer || (Texture2DTo3D(pTexData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DImageData, Image3DWidth, Image3DHeight)))
if((Texture2DTo3D(pTexData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DImageData, Image3DWidth, Image3DHeight)))
{
if(IsSingleLayer)
{
glTexImage3D(Target, 0, GLStoreFormat, ConvertWidth, ConvertHeight, 1, 0, GLFormat, GL_UNSIGNED_BYTE, pTexData);
}
else
{
glTexImage3D(Target, 0, GLStoreFormat, Image3DWidth, Image3DHeight, 256, 0, GLFormat, GL_UNSIGNED_BYTE, p3DImageData);
}
glTexImage3D(Target, 0, GLStoreFormat, Image3DWidth, Image3DHeight, 256, 0, GLFormat, GL_UNSIGNED_BYTE, p3DImageData);
}

if(!IsSingleLayer)
free(p3DImageData);
free(p3DImageData);
}
}

Expand Down Expand Up @@ -2084,7 +2056,7 @@ void CCommandProcessorFragment_OpenGL2::Cmd_RenderBorderTile(const CCommandBuffe
if(IsTextured)
{
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, false, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[1].m_pOffset);
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, false, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[1].m_pOffset);
}

size_t RealDrawCount = pCommand->m_DrawNum * 4;
Expand Down Expand Up @@ -2136,7 +2108,7 @@ void CCommandProcessorFragment_OpenGL2::Cmd_RenderTileLayer(const CCommandBuffer
if(IsTextured)
{
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, false, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[1].m_pOffset);
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, false, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[1].m_pOffset);
}

for(int i = 0; i < pCommand->m_IndicesDrawNum; ++i)
Expand Down
46 changes: 16 additions & 30 deletions src/engine/client/backend/opengl/backend_opengl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int
glGenerateMipmap(GL_TEXTURE_2D);
}

if((Flags & (CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE | CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER)) != 0)
if((Flags & (CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE)) != 0)
{
glGenTextures(1, &m_vTextures[Slot].m_Tex2DArray);
glBindTexture(GL_TEXTURE_2D_ARRAY, m_vTextures[Slot].m_Tex2DArray);
Expand All @@ -620,47 +620,33 @@ void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int

uint8_t *p3DImageData = NULL;

bool IsSingleLayer = (Flags & CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER) != 0;

if(!IsSingleLayer)
p3DImageData = (uint8_t *)malloc((size_t)Width * Height * PixelSize);
p3DImageData = (uint8_t *)malloc((size_t)Width * Height * PixelSize);
int Image3DWidth, Image3DHeight;

int ConvertWidth = Width;
int ConvertHeight = Height;

if(!IsSingleLayer)
if(ConvertWidth == 0 || (ConvertWidth % 16) != 0 || ConvertHeight == 0 || (ConvertHeight % 16) != 0)
{
if(ConvertWidth == 0 || (ConvertWidth % 16) != 0 || ConvertHeight == 0 || (ConvertHeight % 16) != 0)
{
dbg_msg("gfx", "3D/2D array texture was resized");
int NewWidth = maximum<int>(HighestBit(ConvertWidth), 16);
int NewHeight = maximum<int>(HighestBit(ConvertHeight), 16);
uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pTexData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, GLFormatToPixelSize(GLFormat));

ConvertWidth = NewWidth;
ConvertHeight = NewHeight;

free(pTexData);
pTexData = pNewTexData;
}
dbg_msg("gfx", "3D/2D array texture was resized");
int NewWidth = maximum<int>(HighestBit(ConvertWidth), 16);
int NewHeight = maximum<int>(HighestBit(ConvertHeight), 16);
uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pTexData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, GLFormatToPixelSize(GLFormat));

ConvertWidth = NewWidth;
ConvertHeight = NewHeight;

free(pTexData);
pTexData = pNewTexData;
}

if(IsSingleLayer || (Texture2DTo3D(pTexData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DImageData, Image3DWidth, Image3DHeight)))
if((Texture2DTo3D(pTexData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DImageData, Image3DWidth, Image3DHeight)))
{
if(IsSingleLayer)
{
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GLStoreFormat, ConvertWidth, ConvertHeight, 1, 0, GLFormat, GL_UNSIGNED_BYTE, pTexData);
}
else
{
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GLStoreFormat, Image3DWidth, Image3DHeight, 256, 0, GLFormat, GL_UNSIGNED_BYTE, p3DImageData);
}
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GLStoreFormat, Image3DWidth, Image3DHeight, 256, 0, GLFormat, GL_UNSIGNED_BYTE, p3DImageData);
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
}

if(!IsSingleLayer)
free(p3DImageData);
free(p3DImageData);
}
}

Expand Down
52 changes: 20 additions & 32 deletions src/engine/client/backend/vulkan/backend_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2593,8 +2593,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
}

bool Requires2DTexture = (Flags & CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0;
bool Requires2DTextureArray = (Flags & (CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE | CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER)) != 0;
bool Is2DTextureSingleLayer = (Flags & CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER) != 0;
bool Requires2DTextureArray = (Flags & (CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE)) != 0;
bool RequiresMipMaps = (Flags & CCommandBuffer::TEXFLAG_NOMIPMAPS) == 0;
size_t MipMapLevelCount = 1;
if(RequiresMipMaps)
Expand Down Expand Up @@ -2638,44 +2637,33 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
int ConvertWidth = Width;
int ConvertHeight = Height;

if(!Is2DTextureSingleLayer)
if(ConvertWidth == 0 || (ConvertWidth % 16) != 0 || ConvertHeight == 0 || (ConvertHeight % 16) != 0)
{
if(ConvertWidth == 0 || (ConvertWidth % 16) != 0 || ConvertHeight == 0 || (ConvertHeight % 16) != 0)
{
dbg_msg("vulkan", "3D/2D array texture was resized");
int NewWidth = maximum<int>(HighestBit(ConvertWidth), 16);
int NewHeight = maximum<int>(HighestBit(ConvertHeight), 16);
uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, PixelSize);
dbg_msg("vulkan", "3D/2D array texture was resized");
int NewWidth = maximum<int>(HighestBit(ConvertWidth), 16);
int NewHeight = maximum<int>(HighestBit(ConvertHeight), 16);
uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, PixelSize);

ConvertWidth = NewWidth;
ConvertHeight = NewHeight;
ConvertWidth = NewWidth;
ConvertHeight = NewHeight;

free(pData);
pData = pNewTexData;
}
free(pData);
pData = pNewTexData;
}

void *p3DTexData = pData;
bool Needs3DTexDel = false;
if(!Is2DTextureSingleLayer)
{
p3DTexData = malloc((size_t)PixelSize * ConvertWidth * ConvertHeight);
if(!Texture2DTo3D(pData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DTexData, Image3DWidth, Image3DHeight))
{
free(p3DTexData);
p3DTexData = nullptr;
}
Needs3DTexDel = true;
}
else
p3DTexData = malloc((size_t)PixelSize * ConvertWidth * ConvertHeight);
if(!Texture2DTo3D(pData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DTexData, Image3DWidth, Image3DHeight))
{
Image3DWidth = ConvertWidth;
Image3DHeight = ConvertHeight;
free(p3DTexData);
p3DTexData = nullptr;
}
Needs3DTexDel = true;

if(p3DTexData != nullptr)
{
const size_t ImageDepth2DArray = Is2DTextureSingleLayer ? 1 : ((size_t)16 * 16);
const size_t ImageDepth2DArray = (size_t)16 * 16;
VkExtent3D ImgSize{(uint32_t)Image3DWidth, (uint32_t)Image3DHeight, 1};
if(RequiresMipMaps)
{
Expand Down Expand Up @@ -4898,7 +4886,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
std::array<VkVertexInputAttributeDescription, HasSampler ? 2 : 1> aAttributeDescriptions = {};
aAttributeDescriptions[0] = {0, 0, VK_FORMAT_R32G32_SFLOAT, 0};
if(HasSampler)
aAttributeDescriptions[1] = {1, 0, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 2};
aAttributeDescriptions[1] = {1, 0, VK_FORMAT_R8G8B8A8_UINT, sizeof(float) * 2};

std::array<VkDescriptorSetLayout, 1> aSetLayouts;
aSetLayouts[0] = m_Standard3DTexturedDescriptorSetLayout;
Expand All @@ -4913,7 +4901,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
aPushConstants[0] = {VK_SHADER_STAGE_VERTEX_BIT, 0, VertPushConstantSize};
aPushConstants[1] = {VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(SUniformTileGPosBorder) + sizeof(SUniformTileGVertColorAlign), FragPushConstantSize};

return CreateGraphicsPipeline<false>(pVertName, pFragName, PipeContainer, HasSampler ? (sizeof(float) * (2 + 3)) : (sizeof(float) * 2), aAttributeDescriptions, aSetLayouts, aPushConstants, TexMode, BlendMode, DynamicMode);
return CreateGraphicsPipeline<false>(pVertName, pFragName, PipeContainer, HasSampler ? (sizeof(float) * 2 + sizeof(uint8_t) * 4) : (sizeof(float) * 2), aAttributeDescriptions, aSetLayouts, aPushConstants, TexMode, BlendMode, DynamicMode);
}

template<bool HasSampler>
Expand Down Expand Up @@ -7049,9 +7037,9 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase

[[nodiscard]] bool Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand, SRenderCommandExecuteBuffer &ExecBuffer)
{
vec2 Dir{};
vec2 Scale{};
vec2 Off{};
return RenderTileLayer(ExecBuffer, pCommand->m_State, false, pCommand->m_Color, Dir, Off, (size_t)pCommand->m_IndicesDrawNum, pCommand->m_pIndicesOffsets, pCommand->m_pDrawCount);
return RenderTileLayer(ExecBuffer, pCommand->m_State, false, pCommand->m_Color, Scale, Off, (size_t)pCommand->m_IndicesDrawNum, pCommand->m_pIndicesOffsets, pCommand->m_pDrawCount);
}

void Cmd_RenderBorderTile_FillExecuteBuffer(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand_RenderBorderTile *pCommand)
Expand Down
Loading

0 comments on commit 061a9c0

Please sign in to comment.