diff --git a/CMakeLists.txt b/CMakeLists.txt index f28de957192..024cbda231c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -1550,6 +1551,8 @@ set(EXPECTED_DATA shader/text.vert shader/tile.frag shader/tile.vert + shader/tile_border.frag + shader/tile_border.vert shader/vulkan/prim.frag shader/vulkan/prim.vert shader/vulkan/prim3d.frag @@ -1564,6 +1567,8 @@ set(EXPECTED_DATA shader/vulkan/text.vert shader/vulkan/tile.frag shader/vulkan/tile.vert + shader/vulkan/tile_border.frag + shader/vulkan/tile_border.vert skins/PaladiN.png skins/antiantey.png skins/beast.png diff --git a/cmake/BuildVulkanShaders.cmake b/cmake/BuildVulkanShaders.cmake index 3eeffe55d71..c6cb0d6fe06 100644 --- a/cmake/BuildVulkanShaders.cmake +++ b/cmake/BuildVulkanShaders.cmake @@ -136,18 +136,12 @@ if(NOT FOUND_MATCHING_SHA256_FILE) generate_shader_file("-DTW_TILE_TEXTURED" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.frag" "data/shader/vulkan/tile_textured.frag.spv") generate_shader_file("-DTW_TILE_TEXTURED" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.vert" "data/shader/vulkan/tile_textured.vert.spv") - generate_shader_file("-DTW_TILE_BORDER" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.frag" "data/shader/vulkan/tile_border.frag.spv") - generate_shader_file("-DTW_TILE_BORDER" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.vert" "data/shader/vulkan/tile_border.vert.spv") - - generate_shader_file("-DTW_TILE_BORDER" "-DTW_TILE_TEXTURED" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.frag" "data/shader/vulkan/tile_border_textured.frag.spv") - generate_shader_file("-DTW_TILE_BORDER" "-DTW_TILE_TEXTURED" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.vert" "data/shader/vulkan/tile_border_textured.vert.spv") - - generate_shader_file("-DTW_TILE_BORDER_LINE" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.frag" "data/shader/vulkan/tile_border_line.frag.spv") - generate_shader_file("-DTW_TILE_BORDER_LINE" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.vert" "data/shader/vulkan/tile_border_line.vert.spv") - - generate_shader_file("-DTW_TILE_BORDER_LINE" "-DTW_TILE_TEXTURED" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.frag" "data/shader/vulkan/tile_border_line_textured.frag.spv") - generate_shader_file("-DTW_TILE_BORDER_LINE" "-DTW_TILE_TEXTURED" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile.vert" "data/shader/vulkan/tile_border_line_textured.vert.spv") + generate_shader_file("" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile_border.frag" "data/shader/vulkan/tile_border.frag.spv") + generate_shader_file("" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile_border.vert" "data/shader/vulkan/tile_border.vert.spv") + generate_shader_file("" "-DTW_TILE_TEXTURED" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile_border.frag" "data/shader/vulkan/tile_border_textured.frag.spv") + generate_shader_file("" "-DTW_TILE_TEXTURED" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/tile_border.vert" "data/shader/vulkan/tile_border_textured.vert.spv") + # quad layer generate_shader_file("" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/quad.frag" "data/shader/vulkan/quad.frag.spv") generate_shader_file("" "" "${PROJECT_SOURCE_DIR}/data/shader/vulkan/quad.vert" "data/shader/vulkan/quad.vert.spv") diff --git a/data/editor/speed_arrow_array.png b/data/editor/speed_arrow_array.png new file mode 100644 index 00000000000..f85db1a0f4c Binary files /dev/null and b/data/editor/speed_arrow_array.png differ diff --git a/data/shader/tile.vert b/data/shader/tile.vert index 0d3a4cfa72a..6288371e995 100644 --- a/data/shader/tile.vert +++ b/data/shader/tile.vert @@ -1,44 +1,19 @@ 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; -#if defined(TW_TILE_BORDER) || defined(TW_TILE_BORDER_LINE) -uniform vec2 gDir; -uniform vec2 gOffset; -#endif - -#if defined(TW_TILE_BORDER) -uniform int gJumpIndex; -#endif - #ifdef TW_TILE_TEXTURED noperspective out vec3 TexCoord; #endif void main() { -#if defined(TW_TILE_BORDER) - vec4 VertPos = vec4(inVertex, 0.0, 1.0); - int XCount = gl_InstanceID - (int(gl_InstanceID/gJumpIndex) * gJumpIndex); - int YCount = (int(gl_InstanceID/gJumpIndex)); - VertPos.x += gOffset.x + gDir.x * float(XCount); - VertPos.y += gOffset.y + gDir.y * float(YCount); - - gl_Position = vec4(gPos * VertPos, 0.0, 1.0); -#elif defined(TW_TILE_BORDER_LINE) - vec4 VertPos = vec4(inVertex.x + gOffset.x, inVertex.y + gOffset.y, 0.0, 1.0); - VertPos.x += gDir.x * float(gl_InstanceID); - VertPos.y += gDir.y * float(gl_InstanceID); - - gl_Position = vec4(gPos * VertPos, 0.0, 1.0); -#else gl_Position = vec4(gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0); -#endif #ifdef TW_TILE_TEXTURED - TexCoord = inVertexTexCoord; + TexCoord = vec3(inVertexTexCoord.xyz); #endif } diff --git a/data/shader/tile_border.frag b/data/shader/tile_border.frag new file mode 100644 index 00000000000..a186901c317 --- /dev/null +++ b/data/shader/tile_border.frag @@ -0,0 +1,28 @@ +#ifdef TW_TILE_TEXTURED +#ifdef TW_TILE_3D_TEXTURED +uniform sampler3D gTextureSampler; +#else +uniform sampler2DArray gTextureSampler; +#endif +#endif + +uniform vec4 gVertColor; + +#ifdef TW_TILE_TEXTURED +noperspective in vec3 TexCoord; +#endif + +out vec4 FragClr; + +void main() +{ +#ifdef TW_TILE_TEXTURED + vec3 realTexCoords = vec3(fract(TexCoord.xy), TexCoord.z); + vec2 dx = dFdx(TexCoord.xy); + vec2 dy = dFdy(TexCoord.xy); + vec4 tex = textureGrad(gTextureSampler, realTexCoords, dx, dy); + FragClr = tex * gVertColor; +#else + FragClr = gVertColor; +#endif +} diff --git a/data/shader/tile_border.vert b/data/shader/tile_border.vert new file mode 100644 index 00000000000..f8f71ebda51 --- /dev/null +++ b/data/shader/tile_border.vert @@ -0,0 +1,28 @@ +layout (location = 0) in vec2 inVertex; +#ifdef TW_TILE_TEXTURED +layout (location = 1) in uvec4 inVertexTexCoord; +#endif + +uniform mat4x2 gPos; + +uniform vec2 gOffset; +uniform vec2 gScale; + +#ifdef TW_TILE_TEXTURED +noperspective out vec3 TexCoord; +#endif + +void main() +{ + // scale then position vertex + vec2 VertexPos = (inVertex * gScale) + gOffset; + gl_Position = vec4(gPos * vec4(VertexPos, 0.0, 1.0), 0.0, 1.0); + +#ifdef TW_TILE_TEXTURED + // scale the texture coordinates too + vec2 TexScale = gScale; + if (float(inVertexTexCoord.w) > 0.0) + TexScale = gScale.yx; + TexCoord = vec3(vec2(inVertexTexCoord.xy) * TexScale, float(inVertexTexCoord.z)); +#endif +} diff --git a/data/shader/vulkan/tile.vert b/data/shader/vulkan/tile.vert index 0dfebab9666..7dd9d35fdc3 100644 --- a/data/shader/vulkan/tile.vert +++ b/data/shader/vulkan/tile.vert @@ -3,20 +3,11 @@ 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 { layout(offset = 0) uniform mat4x2 gPos; - -#if defined(TW_TILE_BORDER) || defined(TW_TILE_BORDER_LINE) - layout(offset = 32) uniform vec2 gDir; - layout(offset = 40) uniform vec2 gOffset; -#endif - -#if defined(TW_TILE_BORDER) - layout(offset = 48) uniform int gJumpIndex; -#endif } gPosBO; #ifdef TW_TILE_TEXTURED @@ -25,25 +16,9 @@ layout (location = 0) noperspective out vec3 TexCoord; void main() { -#if defined(TW_TILE_BORDER) - vec4 VertPos = vec4(inVertex, 0.0, 1.0); - int XCount = gl_InstanceIndex - (int(gl_InstanceIndex/gPosBO.gJumpIndex) * gPosBO.gJumpIndex); - int YCount = (int(gl_InstanceIndex/gPosBO.gJumpIndex)); - VertPos.x += gPosBO.gOffset.x + gPosBO.gDir.x * float(XCount); - VertPos.y += gPosBO.gOffset.y + gPosBO.gDir.y * float(YCount); - - gl_Position = vec4(gPosBO.gPos * VertPos, 0.0, 1.0); -#elif defined(TW_TILE_BORDER_LINE) - vec4 VertPos = vec4(inVertex.x + gPosBO.gOffset.x, inVertex.y + gPosBO.gOffset.y, 0.0, 1.0); - VertPos.x += gPosBO.gDir.x * float(gl_InstanceIndex); - VertPos.y += gPosBO.gDir.y * float(gl_InstanceIndex); - - gl_Position = vec4(gPosBO.gPos * VertPos, 0.0, 1.0); -#else gl_Position = vec4(gPosBO.gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0); -#endif #ifdef TW_TILE_TEXTURED - TexCoord = inVertexTexCoord; + TexCoord = vec3(inVertexTexCoord.xyz); #endif } diff --git a/data/shader/vulkan/tile_border.frag b/data/shader/vulkan/tile_border.frag new file mode 100644 index 00000000000..31166b66155 --- /dev/null +++ b/data/shader/vulkan/tile_border.frag @@ -0,0 +1,28 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable + +#ifdef TW_TILE_TEXTURED +layout(binding = 0) uniform sampler2DArray gTextureSampler; +#endif + +layout(push_constant) uniform SVertexColorBO { + layout(offset = 64) uniform vec4 gVertColor; +} gColorBO; + +#ifdef TW_TILE_TEXTURED +layout (location = 0) noperspective in vec3 TexCoord; +#endif + +layout (location = 0) out vec4 FragClr; +void main() +{ +#ifdef TW_TILE_TEXTURED + vec3 realTexCoords = vec3(fract(TexCoord.xy), TexCoord.z); + vec2 dx = dFdx(TexCoord.xy); + vec2 dy = dFdy(TexCoord.xy); + vec4 tex = textureGrad(gTextureSampler, realTexCoords, dx, dy); + FragClr = tex * gColorBO.gVertColor; +#else + FragClr = gColorBO.gVertColor; +#endif +} diff --git a/data/shader/vulkan/tile_border.vert b/data/shader/vulkan/tile_border.vert new file mode 100644 index 00000000000..5463fdf39ed --- /dev/null +++ b/data/shader/vulkan/tile_border.vert @@ -0,0 +1,33 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable + +layout (location = 0) in vec2 inVertex; +#ifdef TW_TILE_TEXTURED +layout (location = 1) in uvec4 inVertexTexCoord; +#endif + +layout(push_constant) uniform SPosBO { + layout(offset = 0) uniform mat4x2 gPos; + + layout(offset = 32) uniform vec2 gOffset; + layout(offset = 40) uniform vec2 gScale; +} gPosBO; + +#ifdef TW_TILE_TEXTURED +layout (location = 0) noperspective out vec3 TexCoord; +#endif + +void main() +{ + // scale then position vertex + vec2 VertexPos = (inVertex * gPosBO.gScale) + gPosBO.gOffset; + gl_Position = vec4(gPosBO.gPos * vec4(VertexPos, 0.0, 1.0), 0.0, 1.0); + +#ifdef TW_TILE_TEXTURED + // scale the texture coordinates too + vec2 TexScale = gPosBO.gScale; + if (inVertexTexCoord.w > 0) + TexScale = gPosBO.gScale.yx; + TexCoord = vec3(vec2(inVertexTexCoord.xy) * TexScale, float(inVertexTexCoord.z)); +#endif +} diff --git a/src/base/vmath.h b/src/base/vmath.h index 37205b108b9..6797e5db1d9 100644 --- a/src/base/vmath.h +++ b/src/base/vmath.h @@ -4,6 +4,7 @@ #define BASE_VMATH_H #include +#include #include "math.h" @@ -399,5 +400,6 @@ class vector4_base typedef vector4_base vec4; typedef vector4_base bvec4; typedef vector4_base ivec4; +typedef vector4_base ubvec4; #endif diff --git a/src/engine/client/backend/opengl/backend_opengl.cpp b/src/engine/client/backend/opengl/backend_opengl.cpp index 176f74b1f33..a599a990377 100644 --- a/src/engine/client/backend/opengl/backend_opengl.cpp +++ b/src/engine/client/backend/opengl/backend_opengl.cpp @@ -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; @@ -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); @@ -474,19 +472,7 @@ 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 = pCommand->m_pCapabilities->m_2DArrayTextures || pCommand->m_pCapabilities->m_3DTextures; + pCommand->m_pCapabilities->m_TileBuffering = false; pCommand->m_pCapabilities->m_QuadBuffering = false; pCommand->m_pCapabilities->m_TextBuffering = false; pCommand->m_pCapabilities->m_QuadContainerBuffering = false; @@ -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; @@ -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(HighestBit(ConvertWidth), 16); - int NewHeight = maximum(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(HighestBit(ConvertWidth), 16); + int NewHeight = maximum(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); } } @@ -1116,7 +1088,6 @@ ERunCommandReturnTypes CCommandProcessorFragment_OpenGL::RunCommand(const CComma case CCommandBuffer::CMD_RENDER_TILE_LAYER: Cmd_RenderTileLayer(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_RENDER_BORDER_TILE: Cmd_RenderBorderTile(static_cast(pBaseCommand)); break; - case CCommandBuffer::CMD_RENDER_BORDER_TILE_LINE: Cmd_RenderBorderTileLine(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_RENDER_QUAD_LAYER: Cmd_RenderQuadLayer(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_RENDER_TEXT: Cmd_RenderText(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_RENDER_QUAD_CONTAINER: Cmd_RenderQuadContainer(static_cast(pBaseCommand)); break; @@ -1283,7 +1254,7 @@ void CCommandProcessorFragment_OpenGL2::SetState(const CCommandBuffer::SState &S } #ifndef BACKEND_GL_MODERN_API -bool CCommandProcessorFragment_OpenGL2::DoAnalyzeStep(size_t StepN, size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize) +bool CCommandProcessorFragment_OpenGL2::DoAnalyzeStep(size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -1291,18 +1262,10 @@ bool CCommandProcessorFragment_OpenGL2::DoAnalyzeStep(size_t StepN, size_t Check if(m_HasShaders) { CGLSLTWProgram *pProgram = m_pPrimitive3DProgramTextured; - if(StepN == 1) - pProgram = m_pTileProgramTextured; UseProgram(pProgram); pProgram->SetUniform(pProgram->m_LocTextureSampler, Slot); - if(StepN == 1) - { - float aColor[4] = {1.f, 1.f, 1.f, 1.f}; - pProgram->SetUniformVec4(((CGLSLTileProgram *)pProgram)->m_LocColor, 1, aColor); - } - float m[2 * 4] = { 1, 0, 0, 0, 0, 1, 0, 0}; @@ -1317,44 +1280,19 @@ bool CCommandProcessorFragment_OpenGL2::DoAnalyzeStep(size_t StepN, size_t Check glOrtho(-1, 1, -1, 1, -10.0f, 10.f); } - GLuint BufferID = 0; - if(StepN == 1 && m_HasShaders) - { - glGenBuffers(1, &BufferID); - glBindBuffer(GL_ARRAY_BUFFER, BufferID); - glBufferData(GL_ARRAY_BUFFER, VerticesCount * sizeof((m_aStreamVertices[0])), m_aStreamVertices, GL_STATIC_DRAW); - - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof((m_aStreamVertices[0])), 0); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 3, GL_FLOAT, false, sizeof((m_aStreamVertices[0])), (GLvoid *)(sizeof(vec4) + sizeof(vec2))); - } - else - { - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(2, GL_FLOAT, sizeof(m_aStreamVertices[0]), m_aStreamVertices); - glColorPointer(4, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2))); - glTexCoordPointer(3, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2) + sizeof(vec4))); - } + glVertexPointer(2, GL_FLOAT, sizeof(m_aStreamVertices[0]), m_aStreamVertices); + glColorPointer(4, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2))); + glTexCoordPointer(3, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2) + sizeof(vec4))); glDrawArrays(GL_QUADS, 0, VerticesCount); - if(StepN == 1 && m_HasShaders) - { - glDisableVertexAttribArray(0); - glDisableVertexAttribArray(1); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glDeleteBuffers(1, &BufferID); - } - else - { - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); if(m_HasShaders) { @@ -1585,9 +1523,7 @@ bool CCommandProcessorFragment_OpenGL2::IsTileMapAnalysisSucceeded() } // everything build up, now do the analyze steps - bool NoError = DoAnalyzeStep(0, CheckCount, VertexCount, pFakeTexture, SingleImageSize); - if(NoError && m_HasShaders) - NoError &= DoAnalyzeStep(1, CheckCount, VertexCount, pFakeTexture, SingleImageSize); + bool NoError = DoAnalyzeStep(CheckCount, VertexCount, pFakeTexture, SingleImageSize); glDeleteTextures(1, &FakeTexture); free(pFakeTexture); @@ -1615,7 +1551,7 @@ bool CCommandProcessorFragment_OpenGL2::Cmd_Init(const SCommand_Init *pCommand) { HasAllFunc &= (glUniformMatrix4x2fv != NULL) && (glGenBuffers != NULL); HasAllFunc &= (glBindBuffer != NULL) && (glBufferData != NULL); - HasAllFunc &= (glEnableVertexAttribArray != NULL) && (glVertexAttribPointer != NULL); + HasAllFunc &= (glEnableVertexAttribArray != NULL) && (glVertexAttribPointer != NULL) && (glVertexAttribIPointer != NULL); HasAllFunc &= (glDisableVertexAttribArray != NULL) && (glDeleteBuffers != NULL); HasAllFunc &= (glUseProgram != NULL) && (glTexImage3D != NULL); HasAllFunc &= (glBindAttribLocation != NULL) && (glTexImage3D != NULL); @@ -1641,6 +1577,8 @@ bool CCommandProcessorFragment_OpenGL2::Cmd_Init(const SCommand_Init *pCommand) { m_pTileProgram = new CGLSLTileProgram; m_pTileProgramTextured = new CGLSLTileProgram; + m_pBorderTileProgram = new CGLSLTileProgram; + m_pBorderTileProgramTextured = new CGLSLTileProgram; m_pPrimitive3DProgram = new CGLSLPrimitiveProgram; m_pPrimitive3DProgramTextured = new CGLSLPrimitiveProgram; @@ -1743,6 +1681,63 @@ bool CCommandProcessorFragment_OpenGL2::Cmd_Init(const SCommand_Init *pCommand) m_pTileProgramTextured->m_LocTextureSampler = m_pTileProgramTextured->GetUniformLoc("gTextureSampler"); m_pTileProgramTextured->m_LocColor = m_pTileProgramTextured->GetUniformLoc("gVertColor"); } + if(pCommand->m_pCapabilities->m_2DArrayTextures) + ShaderCompiler.SetTextureReplaceType(CGLSLCompiler::GLSL_COMPILER_TEXTURE_REPLACE_TYPE_2D_ARRAY); + else + ShaderCompiler.SetTextureReplaceType(CGLSLCompiler::GLSL_COMPILER_TEXTURE_REPLACE_TYPE_3D); + { + CGLSL VertexShader; + CGLSL FragmentShader; + VertexShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile_border.vert", GL_VERTEX_SHADER); + FragmentShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile_border.frag", GL_FRAGMENT_SHADER); + ShaderCompiler.ClearDefines(); + + m_pBorderTileProgram->CreateProgram(); + m_pBorderTileProgram->AddShader(&VertexShader); + m_pBorderTileProgram->AddShader(&FragmentShader); + + glBindAttribLocation(m_pBorderTileProgram->GetProgramID(), 0, "inVertex"); + + m_pBorderTileProgram->LinkProgram(); + + UseProgram(m_pBorderTileProgram); + + m_pBorderTileProgram->m_LocPos = m_pBorderTileProgram->GetUniformLoc("gPos"); + m_pBorderTileProgram->m_LocColor = m_pBorderTileProgram->GetUniformLoc("gVertColor"); + m_pBorderTileProgram->m_LocOffset = m_pBorderTileProgram->GetUniformLoc("gOffset"); + m_pBorderTileProgram->m_LocScale = m_pBorderTileProgram->GetUniformLoc("gScale"); + } + if(pCommand->m_pCapabilities->m_2DArrayTextures) + ShaderCompiler.SetTextureReplaceType(CGLSLCompiler::GLSL_COMPILER_TEXTURE_REPLACE_TYPE_2D_ARRAY); + else + ShaderCompiler.SetTextureReplaceType(CGLSLCompiler::GLSL_COMPILER_TEXTURE_REPLACE_TYPE_3D); + { + CGLSL VertexShader; + CGLSL FragmentShader; + ShaderCompiler.AddDefine("TW_TILE_TEXTURED", ""); + if(!pCommand->m_pCapabilities->m_2DArrayTextures) + ShaderCompiler.AddDefine("TW_TILE_3D_TEXTURED", ""); + VertexShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile_border.vert", GL_VERTEX_SHADER); + FragmentShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile_border.frag", GL_FRAGMENT_SHADER); + ShaderCompiler.ClearDefines(); + + m_pBorderTileProgramTextured->CreateProgram(); + m_pBorderTileProgramTextured->AddShader(&VertexShader); + m_pBorderTileProgramTextured->AddShader(&FragmentShader); + + glBindAttribLocation(m_pBorderTileProgramTextured->GetProgramID(), 0, "inVertex"); + glBindAttribLocation(m_pBorderTileProgramTextured->GetProgramID(), 1, "inVertexTexCoord"); + + m_pBorderTileProgramTextured->LinkProgram(); + + UseProgram(m_pBorderTileProgramTextured); + + m_pBorderTileProgramTextured->m_LocPos = m_pBorderTileProgramTextured->GetUniformLoc("gPos"); + m_pBorderTileProgramTextured->m_LocTextureSampler = m_pBorderTileProgramTextured->GetUniformLoc("gTextureSampler"); + m_pBorderTileProgramTextured->m_LocColor = m_pBorderTileProgramTextured->GetUniformLoc("gVertColor"); + m_pBorderTileProgramTextured->m_LocOffset = m_pBorderTileProgramTextured->GetUniformLoc("gOffset"); + m_pBorderTileProgramTextured->m_LocScale = m_pBorderTileProgramTextured->GetUniformLoc("gScale"); + } glUseProgram(0); } @@ -1850,13 +1845,10 @@ void CCommandProcessorFragment_OpenGL2::Cmd_CreateBufferObject(const CCommandBuf GLuint VertBufferID = 0; - if(m_HasShaders) - { - glGenBuffers(1, &VertBufferID); - glBindBuffer(GL_ARRAY_BUFFER, VertBufferID); - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(pCommand->m_DataSize), pUploadData, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } + glGenBuffers(1, &VertBufferID); + glBindBuffer(GL_ARRAY_BUFFER, VertBufferID); + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(pCommand->m_DataSize), pUploadData, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); SBufferObject &BufferObject = m_vBufferObjectIndices[Index]; BufferObject.m_BufferObjectID = VertBufferID; @@ -1875,12 +1867,9 @@ void CCommandProcessorFragment_OpenGL2::Cmd_RecreateBufferObject(const CCommandB int Index = pCommand->m_BufferIndex; SBufferObject &BufferObject = m_vBufferObjectIndices[Index]; - if(m_HasShaders) - { - glBindBuffer(GL_ARRAY_BUFFER, BufferObject.m_BufferObjectID); - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(pCommand->m_DataSize), pUploadData, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } + glBindBuffer(GL_ARRAY_BUFFER, BufferObject.m_BufferObjectID); + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(pCommand->m_DataSize), pUploadData, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); BufferObject.m_DataSize = pCommand->m_DataSize; free(BufferObject.m_pData); @@ -1898,12 +1887,9 @@ void CCommandProcessorFragment_OpenGL2::Cmd_UpdateBufferObject(const CCommandBuf int Index = pCommand->m_BufferIndex; SBufferObject &BufferObject = m_vBufferObjectIndices[Index]; - if(m_HasShaders) - { - glBindBuffer(GL_ARRAY_BUFFER, BufferObject.m_BufferObjectID); - glBufferSubData(GL_ARRAY_BUFFER, (GLintptr)(pCommand->m_pOffset), (GLsizeiptr)(pCommand->m_DataSize), pUploadData); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } + glBindBuffer(GL_ARRAY_BUFFER, BufferObject.m_BufferObjectID); + glBufferSubData(GL_ARRAY_BUFFER, (GLintptr)(pCommand->m_pOffset), (GLsizeiptr)(pCommand->m_DataSize), pUploadData); + glBindBuffer(GL_ARRAY_BUFFER, 0); if(pUploadData) mem_copy(((uint8_t *)BufferObject.m_pData) + (ptrdiff_t)pCommand->m_pOffset, pUploadData, pCommand->m_DataSize); @@ -1922,12 +1908,9 @@ void CCommandProcessorFragment_OpenGL2::Cmd_CopyBufferObject(const CCommandBuffe mem_copy(((uint8_t *)WriteBufferObject.m_pData) + (ptrdiff_t)pCommand->m_WriteOffset, ((uint8_t *)ReadBufferObject.m_pData) + (ptrdiff_t)pCommand->m_ReadOffset, pCommand->m_CopySize); - if(m_HasShaders) - { - glBindBuffer(GL_ARRAY_BUFFER, WriteBufferObject.m_BufferObjectID); - glBufferSubData(GL_ARRAY_BUFFER, (GLintptr)(pCommand->m_WriteOffset), (GLsizeiptr)(pCommand->m_CopySize), ((uint8_t *)WriteBufferObject.m_pData) + (ptrdiff_t)pCommand->m_WriteOffset); - glBindBuffer(GL_ARRAY_BUFFER, 0); - } + glBindBuffer(GL_ARRAY_BUFFER, WriteBufferObject.m_BufferObjectID); + glBufferSubData(GL_ARRAY_BUFFER, (GLintptr)(pCommand->m_WriteOffset), (GLsizeiptr)(pCommand->m_CopySize), ((uint8_t *)WriteBufferObject.m_pData) + (ptrdiff_t)pCommand->m_WriteOffset); + glBindBuffer(GL_ARRAY_BUFFER, 0); } void CCommandProcessorFragment_OpenGL2::Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) @@ -1935,10 +1918,7 @@ void CCommandProcessorFragment_OpenGL2::Cmd_DeleteBufferObject(const CCommandBuf int Index = pCommand->m_BufferIndex; SBufferObject &BufferObject = m_vBufferObjectIndices[Index]; - if(m_HasShaders) - { - glDeleteBuffers(1, &BufferObject.m_BufferObjectID); - } + glDeleteBuffers(1, &BufferObject.m_BufferObjectID); free(BufferObject.m_pData); BufferObject.m_pData = NULL; @@ -1994,10 +1974,7 @@ void CCommandProcessorFragment_OpenGL2::Cmd_DeleteBufferContainer(const CCommand int VertBufferID = BufferContainer.m_ContainerInfo.m_VertBufferBindingIndex; if(VertBufferID != -1) { - if(m_HasShaders) - { - glDeleteBuffers(1, &m_vBufferObjectIndices[VertBufferID].m_BufferObjectID); - } + glDeleteBuffers(1, &m_vBufferObjectIndices[VertBufferID].m_BufferObjectID); free(m_vBufferObjectIndices[VertBufferID].m_pData); m_vBufferObjectIndices[VertBufferID].m_pData = NULL; @@ -2011,192 +1988,51 @@ void CCommandProcessorFragment_OpenGL2::Cmd_IndicesRequiredNumNotify(const CComm { } -void CCommandProcessorFragment_OpenGL2::RenderBorderTileEmulation(SBufferContainer &BufferContainer, const CCommandBuffer::SState &State, const ColorRGBA &Color, const char *pBuffOffset, unsigned int DrawNum, const vec2 &Offset, const vec2 &Dir, int JumpIndex) +void CCommandProcessorFragment_OpenGL2::Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) { - if(m_HasShaders) - { - CGLSLPrimitiveProgram *pProgram = NULL; - if(IsTexturedState(State)) - { - pProgram = m_pPrimitive3DProgramTextured; - } - else - pProgram = m_pPrimitive3DProgram; + int Index = pCommand->m_BufferContainerIndex; + // if space not there return + if((size_t)Index >= m_vBufferContainers.size()) + return; - UseProgram(pProgram); + SBufferContainer &BufferContainer = m_vBufferContainers[Index]; - SetState(State, pProgram, true); - } + CGLSLTileProgram *pProgram = NULL; + if(IsTexturedState(pCommand->m_State)) + pProgram = m_pBorderTileProgramTextured; else - { - CCommandProcessorFragment_OpenGL::SetState(State, true); - } - - bool IsTextured = BufferContainer.m_ContainerInfo.m_vAttributes.size() == 2; - - SBufferObject &BufferObject = m_vBufferObjectIndices[(size_t)BufferContainer.m_ContainerInfo.m_VertBufferBindingIndex]; - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - if(IsTextured) - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - glVertexPointer(2, GL_FLOAT, sizeof(m_aStreamVertices[0]), m_aStreamVertices); - glColorPointer(4, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2))); - if(IsTextured) - glTexCoordPointer(3, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2) + sizeof(vec4))); - - size_t VertexCount = 0; - for(size_t i = 0; i < DrawNum; ++i) - { - GLint RealOffset = (GLint)((((size_t)(uintptr_t)(pBuffOffset)) / (6 * sizeof(unsigned int))) * 4); - size_t SingleVertSize = (sizeof(vec2) + (IsTextured ? sizeof(vec3) : 0)); - size_t CurBufferOffset = RealOffset * SingleVertSize; - int XCount = i - (size_t)(i / JumpIndex) * JumpIndex; - int YCount = (size_t)(i / JumpIndex); - for(size_t n = 0; n < 4; ++n) - { - ptrdiff_t VertOffset = (ptrdiff_t)(CurBufferOffset + (n * SingleVertSize)); - vec2 *pPos = (vec2 *)((uint8_t *)BufferObject.m_pData + VertOffset); - - GL_SVertexTex3D &Vertex = m_aStreamVertices[VertexCount++]; - Vertex.m_Pos = *pPos; - Vertex.m_Color = Color; - if(IsTextured) - { - vec3 *pTex = (vec3 *)((uint8_t *)BufferObject.m_pData + VertOffset + (ptrdiff_t)sizeof(vec2)); - Vertex.m_Tex = *pTex; - } - - Vertex.m_Pos += Offset + Dir * vec2(XCount, YCount); - - if(VertexCount >= std::size(m_aStreamVertices)) - { - glDrawArrays(GL_QUADS, 0, VertexCount); - VertexCount = 0; - } - } - } - if(VertexCount > 0) - glDrawArrays(GL_QUADS, 0, VertexCount); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - if(IsTextured) - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - - if(m_HasShaders) - { - glUseProgram(0); - } -} - -void CCommandProcessorFragment_OpenGL2::RenderBorderTileLineEmulation(SBufferContainer &BufferContainer, const CCommandBuffer::SState &State, const ColorRGBA &Color, const char *pBuffOffset, unsigned int IndexDrawNum, unsigned int DrawNum, const vec2 &Offset, const vec2 &Dir) -{ - if(m_HasShaders) - { - CGLSLPrimitiveProgram *pProgram = NULL; - if(IsTexturedState(State)) - { - pProgram = m_pPrimitive3DProgramTextured; - } - else - pProgram = m_pPrimitive3DProgram; + pProgram = m_pBorderTileProgram; + UseProgram(pProgram); - UseProgram(pProgram); + SetState(pCommand->m_State, pProgram, true); + pProgram->SetUniformVec4(pProgram->m_LocColor, 1, (float *)&pCommand->m_Color); - SetState(State, pProgram, true); - } - else - { - CCommandProcessorFragment_OpenGL::SetState(State, true); - } + pProgram->SetUniformVec2(pProgram->m_LocOffset, 1, (float *)&pCommand->m_Offset); + pProgram->SetUniformVec2(pProgram->m_LocScale, 1, (float *)&pCommand->m_Scale); bool IsTextured = BufferContainer.m_ContainerInfo.m_vAttributes.size() == 2; SBufferObject &BufferObject = m_vBufferObjectIndices[(size_t)BufferContainer.m_ContainerInfo.m_VertBufferBindingIndex]; - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - if(IsTextured) - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, BufferObject.m_BufferObjectID); - glVertexPointer(2, GL_FLOAT, sizeof(m_aStreamVertices[0]), m_aStreamVertices); - glColorPointer(4, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2))); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 2, GL_FLOAT, false, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[0].m_pOffset); if(IsTextured) - glTexCoordPointer(3, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2) + sizeof(vec4))); - - size_t VertexCount = 0; - for(size_t i = 0; i < DrawNum; ++i) { - GLint RealOffset = (GLint)((((size_t)(uintptr_t)(pBuffOffset)) / (6 * sizeof(unsigned int))) * 4); - size_t SingleVertSize = (sizeof(vec2) + (IsTextured ? sizeof(vec3) : 0)); - size_t CurBufferOffset = (RealOffset)*SingleVertSize; - size_t VerticesPerLine = (size_t)IndexDrawNum / 6; - - for(size_t n = 0; n < 4 * (size_t)VerticesPerLine; ++n) - { - ptrdiff_t VertOffset = (ptrdiff_t)(CurBufferOffset + (n * SingleVertSize)); - vec2 *pPos = (vec2 *)((uint8_t *)BufferObject.m_pData + VertOffset); - - GL_SVertexTex3D &Vertex = m_aStreamVertices[VertexCount++]; - Vertex.m_Pos = *pPos; - Vertex.m_Color = Color; - if(IsTextured) - { - vec3 *pTex = (vec3 *)((uint8_t *)BufferObject.m_pData + VertOffset + (ptrdiff_t)sizeof(vec2)); - Vertex.m_Tex = *pTex; - } - - Vertex.m_Pos += Offset + Dir * i; - - if(VertexCount >= std::size(m_aStreamVertices)) - { - glDrawArrays(GL_QUADS, 0, VertexCount); - VertexCount = 0; - } - } + glEnableVertexAttribArray(1); + glVertexAttribIPointer(1, 4, GL_UNSIGNED_BYTE, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[1].m_pOffset); } - if(VertexCount > 0) - glDrawArrays(GL_QUADS, 0, VertexCount); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); + size_t RealDrawCount = pCommand->m_DrawNum * 4; + GLint RealOffset = (GLint)((((size_t)(uintptr_t)(pCommand->m_pIndicesOffset)) / (6 * sizeof(unsigned int))) * 4); + glDrawArrays(GL_QUADS, RealOffset, RealDrawCount); + glDisableVertexAttribArray(0); if(IsTextured) - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - - if(m_HasShaders) - { - glUseProgram(0); - } -} - -void CCommandProcessorFragment_OpenGL2::Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) -{ - int Index = pCommand->m_BufferContainerIndex; - // if space not there return - if((size_t)Index >= m_vBufferContainers.size()) - return; - - SBufferContainer &BufferContainer = m_vBufferContainers[Index]; - - RenderBorderTileEmulation(BufferContainer, pCommand->m_State, pCommand->m_Color, pCommand->m_pIndicesOffset, pCommand->m_DrawNum, pCommand->m_Offset, pCommand->m_Dir, pCommand->m_JumpIndex); -} - -void CCommandProcessorFragment_OpenGL2::Cmd_RenderBorderTileLine(const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand) -{ - int Index = pCommand->m_BufferContainerIndex; - // if space not there return - if((size_t)Index >= m_vBufferContainers.size()) - return; - - SBufferContainer &BufferContainer = m_vBufferContainers[Index]; - - RenderBorderTileLineEmulation(BufferContainer, pCommand->m_State, pCommand->m_Color, pCommand->m_pIndicesOffset, pCommand->m_IndexDrawNum, pCommand->m_DrawNum, pCommand->m_Offset, pCommand->m_Dir); + glDisableVertexAttribArray(1); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glUseProgram(0); } void CCommandProcessorFragment_OpenGL2::Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) @@ -2213,113 +2049,45 @@ void CCommandProcessorFragment_OpenGL2::Cmd_RenderTileLayer(const CCommandBuffer return; // nothing to draw } - if(m_HasShaders) + CGLSLTileProgram *pProgram = NULL; + if(IsTexturedState(pCommand->m_State)) { - CGLSLTileProgram *pProgram = NULL; - if(IsTexturedState(pCommand->m_State)) - { - pProgram = m_pTileProgramTextured; - } - else - pProgram = m_pTileProgram; - - UseProgram(pProgram); - - SetState(pCommand->m_State, pProgram, true); - pProgram->SetUniformVec4(pProgram->m_LocColor, 1, (float *)&pCommand->m_Color); + pProgram = m_pTileProgramTextured; } else - { - CCommandProcessorFragment_OpenGL::SetState(pCommand->m_State, true); - } + pProgram = m_pTileProgram; - bool IsTextured = BufferContainer.m_ContainerInfo.m_vAttributes.size() == 2; + UseProgram(pProgram); - SBufferObject &BufferObject = m_vBufferObjectIndices[(size_t)BufferContainer.m_ContainerInfo.m_VertBufferBindingIndex]; - if(m_HasShaders) - glBindBuffer(GL_ARRAY_BUFFER, BufferObject.m_BufferObjectID); + SetState(pCommand->m_State, pProgram, true); + pProgram->SetUniformVec4(pProgram->m_LocColor, 1, (float *)&pCommand->m_Color); - if(!m_HasShaders) - { - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + bool IsTextured = BufferContainer.m_ContainerInfo.m_vAttributes.size() == 2; - if(IsTextured) - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - } + SBufferObject &BufferObject = m_vBufferObjectIndices[(size_t)BufferContainer.m_ContainerInfo.m_VertBufferBindingIndex]; - if(m_HasShaders) - { - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 2, GL_FLOAT, false, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[0].m_pOffset); - if(IsTextured) - { - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 3, GL_FLOAT, false, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[1].m_pOffset); - } + glBindBuffer(GL_ARRAY_BUFFER, BufferObject.m_BufferObjectID); - for(int i = 0; i < pCommand->m_IndicesDrawNum; ++i) - { - size_t RealDrawCount = (pCommand->m_pDrawCount[i] / 6) * 4; - GLint RealOffset = (GLint)((((size_t)(uintptr_t)(pCommand->m_pIndicesOffsets[i])) / (6 * sizeof(unsigned int))) * 4); - glDrawArrays(GL_QUADS, RealOffset, RealDrawCount); - } - } - else + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 2, GL_FLOAT, false, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[0].m_pOffset); + if(IsTextured) { - glVertexPointer(2, GL_FLOAT, sizeof(m_aStreamVertices[0]), m_aStreamVertices); - glColorPointer(4, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2))); - if(IsTextured) - glTexCoordPointer(3, GL_FLOAT, sizeof(m_aStreamVertices[0]), (uint8_t *)m_aStreamVertices + (ptrdiff_t)(sizeof(vec2) + sizeof(vec4))); - - size_t VertexCount = 0; - for(int i = 0; i < pCommand->m_IndicesDrawNum; ++i) - { - size_t RealDrawCount = (pCommand->m_pDrawCount[i] / 6) * 4; - GLint RealOffset = (GLint)((((size_t)(uintptr_t)(pCommand->m_pIndicesOffsets[i])) / (6 * sizeof(unsigned int))) * 4); - size_t SingleVertSize = (sizeof(vec2) + (IsTextured ? sizeof(vec3) : 0)); - size_t CurBufferOffset = RealOffset * SingleVertSize; - - for(size_t n = 0; n < RealDrawCount; ++n) - { - ptrdiff_t VertOffset = (ptrdiff_t)(CurBufferOffset + (n * SingleVertSize)); - vec2 *pPos = (vec2 *)((uint8_t *)BufferObject.m_pData + VertOffset); - GL_SVertexTex3D &Vertex = m_aStreamVertices[VertexCount++]; - Vertex.m_Pos = *pPos; - Vertex.m_Color = pCommand->m_Color; - if(IsTextured) - { - vec3 *pTex = (vec3 *)((uint8_t *)BufferObject.m_pData + VertOffset + (ptrdiff_t)sizeof(vec2)); - Vertex.m_Tex = *pTex; - } - - if(VertexCount >= std::size(m_aStreamVertices)) - { - glDrawArrays(GL_QUADS, 0, VertexCount); - VertexCount = 0; - } - } - } - if(VertexCount > 0) - glDrawArrays(GL_QUADS, 0, VertexCount); + glEnableVertexAttribArray(1); + glVertexAttribIPointer(1, 4, GL_UNSIGNED_BYTE, BufferContainer.m_ContainerInfo.m_Stride, BufferContainer.m_ContainerInfo.m_vAttributes[1].m_pOffset); } - if(!m_HasShaders) + for(int i = 0; i < pCommand->m_IndicesDrawNum; ++i) { - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - if(IsTextured) - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - else - { - glDisableVertexAttribArray(0); - if(IsTextured) - glDisableVertexAttribArray(1); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glUseProgram(0); + size_t RealDrawCount = (pCommand->m_pDrawCount[i] / 6) * 4; + GLint RealOffset = (GLint)((((size_t)(uintptr_t)(pCommand->m_pIndicesOffsets[i])) / (6 * sizeof(unsigned int))) * 4); + glDrawArrays(GL_QUADS, RealOffset, RealDrawCount); } + + glDisableVertexAttribArray(0); + if(IsTextured) + glDisableVertexAttribArray(1); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glUseProgram(0); } #undef BACKEND_GL_MODERN_API diff --git a/src/engine/client/backend/opengl/backend_opengl.h b/src/engine/client/backend/opengl/backend_opengl.h index 3b2c844b3a0..2d339c0fdb8 100644 --- a/src/engine/client/backend/opengl/backend_opengl.h +++ b/src/engine/client/backend/opengl/backend_opengl.h @@ -116,7 +116,6 @@ class CCommandProcessorFragment_OpenGL : public CCommandProcessorFragment_GLBase virtual void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderTileLayer"); } virtual void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderBorderTile"); } - virtual void Cmd_RenderBorderTileLine(const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderBorderTileLine"); } virtual void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderQuadLayer"); } virtual void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderText"); } virtual void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand) { dbg_assert(false, "Call of unsupported Cmd_RenderQuadContainer"); } @@ -158,11 +157,8 @@ class CCommandProcessorFragment_OpenGL2 : public CCommandProcessorFragment_OpenG std::vector m_vBufferObjectIndices; #ifndef BACKEND_GL_MODERN_API - bool DoAnalyzeStep(size_t StepN, size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize); + bool DoAnalyzeStep(size_t CheckCount, size_t VerticesCount, uint8_t aFakeTexture[], size_t SingleImageSize); bool IsTileMapAnalysisSucceeded(); - - void RenderBorderTileEmulation(SBufferContainer &BufferContainer, const CCommandBuffer::SState &State, const ColorRGBA &Color, const char *pBuffOffset, unsigned int DrawNum, const vec2 &Offset, const vec2 &Dir, int JumpIndex); - void RenderBorderTileLineEmulation(SBufferContainer &BufferContainer, const CCommandBuffer::SState &State, const ColorRGBA &Color, const char *pBuffOffset, unsigned int IndexDrawNum, unsigned int DrawNum, const vec2 &Offset, const vec2 &Dir); #endif void UseProgram(CGLSLTWProgram *pProgram); @@ -189,11 +185,12 @@ class CCommandProcessorFragment_OpenGL2 : public CCommandProcessorFragment_OpenG void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) override; void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) override; - void Cmd_RenderBorderTileLine(const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand) override; #endif CGLSLTileProgram *m_pTileProgram; CGLSLTileProgram *m_pTileProgramTextured; + CGLSLTileProgram *m_pBorderTileProgram; + CGLSLTileProgram *m_pBorderTileProgramTextured; CGLSLPrimitiveProgram *m_pPrimitive3DProgram; CGLSLPrimitiveProgram *m_pPrimitive3DProgramTextured; }; diff --git a/src/engine/client/backend/opengl/backend_opengl3.cpp b/src/engine/client/backend/opengl/backend_opengl3.cpp index 5fdee8c2c65..315dd887d7d 100644 --- a/src/engine/client/backend/opengl/backend_opengl3.cpp +++ b/src/engine/client/backend/opengl/backend_opengl3.cpp @@ -106,8 +106,6 @@ bool CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand m_pPrimitive3DProgramTextured = new CGLSLPrimitiveProgram; m_pBorderTileProgram = new CGLSLTileProgram; m_pBorderTileProgramTextured = new CGLSLTileProgram; - m_pBorderTileLineProgram = new CGLSLTileProgram; - m_pBorderTileLineProgramTextured = new CGLSLTileProgram; m_pQuadProgram = new CGLSLQuadProgram; m_pQuadProgramTextured = new CGLSLQuadProgram; m_pTextProgram = new CGLSLTextProgram; @@ -237,9 +235,8 @@ bool CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand { CGLSL VertexShader; CGLSL FragmentShader; - ShaderCompiler.AddDefine("TW_TILE_BORDER", ""); - VertexShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile.vert", GL_VERTEX_SHADER); - FragmentShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile.frag", GL_FRAGMENT_SHADER); + VertexShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile_border.vert", GL_VERTEX_SHADER); + FragmentShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile_border.frag", GL_FRAGMENT_SHADER); ShaderCompiler.ClearDefines(); m_pBorderTileProgram->CreateProgram(); @@ -252,16 +249,14 @@ bool CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand m_pBorderTileProgram->m_LocPos = m_pBorderTileProgram->GetUniformLoc("gPos"); m_pBorderTileProgram->m_LocColor = m_pBorderTileProgram->GetUniformLoc("gVertColor"); m_pBorderTileProgram->m_LocOffset = m_pBorderTileProgram->GetUniformLoc("gOffset"); - m_pBorderTileProgram->m_LocDir = m_pBorderTileProgram->GetUniformLoc("gDir"); - m_pBorderTileProgram->m_LocJumpIndex = m_pBorderTileProgram->GetUniformLoc("gJumpIndex"); + m_pBorderTileProgram->m_LocScale = m_pBorderTileProgram->GetUniformLoc("gScale"); } { CGLSL VertexShader; CGLSL FragmentShader; - ShaderCompiler.AddDefine("TW_TILE_BORDER", ""); ShaderCompiler.AddDefine("TW_TILE_TEXTURED", ""); - VertexShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile.vert", GL_VERTEX_SHADER); - FragmentShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile.frag", GL_FRAGMENT_SHADER); + VertexShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile_border.vert", GL_VERTEX_SHADER); + FragmentShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile_border.frag", GL_FRAGMENT_SHADER); ShaderCompiler.ClearDefines(); m_pBorderTileProgramTextured->CreateProgram(); @@ -275,50 +270,7 @@ bool CCommandProcessorFragment_OpenGL3_3::Cmd_Init(const SCommand_Init *pCommand m_pBorderTileProgramTextured->m_LocTextureSampler = m_pBorderTileProgramTextured->GetUniformLoc("gTextureSampler"); m_pBorderTileProgramTextured->m_LocColor = m_pBorderTileProgramTextured->GetUniformLoc("gVertColor"); m_pBorderTileProgramTextured->m_LocOffset = m_pBorderTileProgramTextured->GetUniformLoc("gOffset"); - m_pBorderTileProgramTextured->m_LocDir = m_pBorderTileProgramTextured->GetUniformLoc("gDir"); - m_pBorderTileProgramTextured->m_LocJumpIndex = m_pBorderTileProgramTextured->GetUniformLoc("gJumpIndex"); - } - { - CGLSL VertexShader; - CGLSL FragmentShader; - ShaderCompiler.AddDefine("TW_TILE_BORDER_LINE", ""); - VertexShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile.vert", GL_VERTEX_SHADER); - FragmentShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile.frag", GL_FRAGMENT_SHADER); - ShaderCompiler.ClearDefines(); - - m_pBorderTileLineProgram->CreateProgram(); - m_pBorderTileLineProgram->AddShader(&VertexShader); - m_pBorderTileLineProgram->AddShader(&FragmentShader); - m_pBorderTileLineProgram->LinkProgram(); - - UseProgram(m_pBorderTileLineProgram); - - m_pBorderTileLineProgram->m_LocPos = m_pBorderTileLineProgram->GetUniformLoc("gPos"); - m_pBorderTileLineProgram->m_LocColor = m_pBorderTileLineProgram->GetUniformLoc("gVertColor"); - m_pBorderTileLineProgram->m_LocOffset = m_pBorderTileLineProgram->GetUniformLoc("gOffset"); - m_pBorderTileLineProgram->m_LocDir = m_pBorderTileLineProgram->GetUniformLoc("gDir"); - } - { - CGLSL VertexShader; - CGLSL FragmentShader; - ShaderCompiler.AddDefine("TW_TILE_BORDER_LINE", ""); - ShaderCompiler.AddDefine("TW_TILE_TEXTURED", ""); - VertexShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile.vert", GL_VERTEX_SHADER); - FragmentShader.LoadShader(&ShaderCompiler, pCommand->m_pStorage, "shader/tile.frag", GL_FRAGMENT_SHADER); - ShaderCompiler.ClearDefines(); - - m_pBorderTileLineProgramTextured->CreateProgram(); - m_pBorderTileLineProgramTextured->AddShader(&VertexShader); - m_pBorderTileLineProgramTextured->AddShader(&FragmentShader); - m_pBorderTileLineProgramTextured->LinkProgram(); - - UseProgram(m_pBorderTileLineProgramTextured); - - m_pBorderTileLineProgramTextured->m_LocPos = m_pBorderTileLineProgramTextured->GetUniformLoc("gPos"); - m_pBorderTileLineProgramTextured->m_LocTextureSampler = m_pBorderTileLineProgramTextured->GetUniformLoc("gTextureSampler"); - m_pBorderTileLineProgramTextured->m_LocColor = m_pBorderTileLineProgramTextured->GetUniformLoc("gVertColor"); - m_pBorderTileLineProgramTextured->m_LocOffset = m_pBorderTileLineProgramTextured->GetUniformLoc("gOffset"); - m_pBorderTileLineProgramTextured->m_LocDir = m_pBorderTileLineProgramTextured->GetUniformLoc("gDir"); + m_pBorderTileProgramTextured->m_LocScale = m_pBorderTileProgramTextured->GetUniformLoc("gScale"); } { CGLSL VertexShader; @@ -485,8 +437,6 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Shutdown(const SCommand_Shutdown * m_pPrimitiveProgramTextured->DeleteProgram(); m_pBorderTileProgram->DeleteProgram(); m_pBorderTileProgramTextured->DeleteProgram(); - m_pBorderTileLineProgram->DeleteProgram(); - m_pBorderTileLineProgramTextured->DeleteProgram(); m_pQuadProgram->DeleteProgram(); m_pQuadProgramTextured->DeleteProgram(); m_pTileProgram->DeleteProgram(); @@ -505,8 +455,6 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Shutdown(const SCommand_Shutdown * delete m_pPrimitiveProgramTextured; delete m_pBorderTileProgram; delete m_pBorderTileProgramTextured; - delete m_pBorderTileLineProgram; - delete m_pBorderTileLineProgramTextured; delete m_pQuadProgram; delete m_pQuadProgramTextured; delete m_pTileProgram; @@ -652,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); @@ -672,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(HighestBit(ConvertWidth), 16); - int NewHeight = maximum(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(HighestBit(ConvertWidth), 16); + int NewHeight = maximum(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); } } @@ -1088,9 +1022,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderBorderTile(const CCommandBuf CGLSLTileProgram *pProgram = NULL; if(IsTexturedState(pCommand->m_State)) - { pProgram = m_pBorderTileProgramTextured; - } else pProgram = m_pBorderTileProgram; UseProgram(pProgram); @@ -1099,42 +1031,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderBorderTile(const CCommandBuf pProgram->SetUniformVec4(pProgram->m_LocColor, 1, (float *)&pCommand->m_Color); pProgram->SetUniformVec2(pProgram->m_LocOffset, 1, (float *)&pCommand->m_Offset); - pProgram->SetUniformVec2(pProgram->m_LocDir, 1, (float *)&pCommand->m_Dir); - pProgram->SetUniform(pProgram->m_LocJumpIndex, (int)pCommand->m_JumpIndex); - - glBindVertexArray(BufferContainer.m_VertArrayID); - if(BufferContainer.m_LastIndexBufferBound != m_QuadDrawIndexBufferID) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_QuadDrawIndexBufferID); - BufferContainer.m_LastIndexBufferBound = m_QuadDrawIndexBufferID; - } - glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_INT, pCommand->m_pIndicesOffset, pCommand->m_DrawNum); -} - -void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderBorderTileLine(const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand) -{ - int Index = pCommand->m_BufferContainerIndex; - // if space not there return - if((size_t)Index >= m_vBufferContainers.size()) - return; - - SBufferContainer &BufferContainer = m_vBufferContainers[Index]; - if(BufferContainer.m_VertArrayID == 0) - return; - - CGLSLTileProgram *pProgram = NULL; - if(IsTexturedState(pCommand->m_State)) - { - pProgram = m_pBorderTileLineProgramTextured; - } - else - pProgram = m_pBorderTileLineProgram; - UseProgram(pProgram); - - SetState(pCommand->m_State, pProgram, true); - pProgram->SetUniformVec4(pProgram->m_LocColor, 1, (float *)&pCommand->m_Color); - pProgram->SetUniformVec2(pProgram->m_LocOffset, 1, (float *)&pCommand->m_Offset); - pProgram->SetUniformVec2(pProgram->m_LocDir, 1, (float *)&pCommand->m_Dir); + pProgram->SetUniformVec2(pProgram->m_LocScale, 1, (float *)&pCommand->m_Scale); glBindVertexArray(BufferContainer.m_VertArrayID); if(BufferContainer.m_LastIndexBufferBound != m_QuadDrawIndexBufferID) @@ -1142,7 +1039,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderBorderTileLine(const CComman glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_QuadDrawIndexBufferID); BufferContainer.m_LastIndexBufferBound = m_QuadDrawIndexBufferID; } - glDrawElementsInstanced(GL_TRIANGLES, pCommand->m_IndexDrawNum, GL_UNSIGNED_INT, pCommand->m_pIndicesOffset, pCommand->m_DrawNum); + glDrawElements(GL_TRIANGLES, pCommand->m_DrawNum * 6, GL_UNSIGNED_INT, pCommand->m_pIndicesOffset); } void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) diff --git a/src/engine/client/backend/opengl/backend_opengl3.h b/src/engine/client/backend/opengl/backend_opengl3.h index 4f839564dc4..5b3b8836057 100644 --- a/src/engine/client/backend/opengl/backend_opengl3.h +++ b/src/engine/client/backend/opengl/backend_opengl3.h @@ -28,10 +28,6 @@ class CCommandProcessorFragment_OpenGL3_3 : public CCommandProcessorFragment_Ope CGLSLPrimitiveProgram *m_pPrimitiveProgram; CGLSLPrimitiveProgram *m_pPrimitiveProgramTextured; - CGLSLTileProgram *m_pBorderTileProgram; - CGLSLTileProgram *m_pBorderTileProgramTextured; - CGLSLTileProgram *m_pBorderTileLineProgram; - CGLSLTileProgram *m_pBorderTileLineProgramTextured; CGLSLQuadProgram *m_pQuadProgram; CGLSLQuadProgram *m_pQuadProgramTextured; CGLSLTextProgram *m_pTextProgram; @@ -110,7 +106,6 @@ class CCommandProcessorFragment_OpenGL3_3 : public CCommandProcessorFragment_Ope void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) override; void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) override; - void Cmd_RenderBorderTileLine(const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand) override; void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand) override; void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand) override; void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand) override; diff --git a/src/engine/client/backend/opengl/opengl_sl_program.h b/src/engine/client/backend/opengl/opengl_sl_program.h index 30d35b79acb..75243b6e771 100644 --- a/src/engine/client/backend/opengl/opengl_sl_program.h +++ b/src/engine/client/backend/opengl/opengl_sl_program.h @@ -155,6 +155,7 @@ class CGLSLTileProgram : public CGLSLTWProgram int m_LocColor; int m_LocOffset; int m_LocDir; + int m_LocScale = -1; int m_LocNum; int m_LocJumpIndex; }; diff --git a/src/engine/client/backend/vulkan/backend_vulkan.cpp b/src/engine/client/backend/vulkan/backend_vulkan.cpp index e35b8652a78..63b32af2264 100644 --- a/src/engine/client/backend/vulkan/backend_vulkan.cpp +++ b/src/engine/client/backend/vulkan/backend_vulkan.cpp @@ -721,22 +721,17 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase float m_aPos[4 * 2]; }; - struct SUniformTileGPosBorderLine : public SUniformTileGPos + struct SUniformTileGPosBorder : public SUniformTileGPos { - vec2 m_Dir; vec2 m_Offset; - }; - - struct SUniformTileGPosBorder : public SUniformTileGPosBorderLine - { - int32_t m_JumpIndex; + vec2 m_Scale; }; typedef ColorRGBA SUniformTileGVertColor; struct SUniformTileGVertColorAlign { - float m_aPad[(64 - 52) / 4]; + float m_aPad[(64 - 48) / 4]; }; struct SUniformPrimExGPosRotationless @@ -1011,7 +1006,6 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase SPipelineContainer m_TextPipeline; SPipelineContainer m_TilePipeline; SPipelineContainer m_TileBorderPipeline; - SPipelineContainer m_TileBorderLinePipeline; SPipelineContainer m_PrimExPipeline; SPipelineContainer m_PrimExRotationlessPipeline; SPipelineContainer m_SpriteMultiPipeline; @@ -1274,7 +1268,6 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_RENDER_TILE_LAYER)] = {true, [this](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) { Cmd_RenderTileLayer_FillExecuteBuffer(ExecBuffer, static_cast(pBaseCommand)); }, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_RenderTileLayer(static_cast(pBaseCommand), ExecBuffer); }}; m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_RENDER_BORDER_TILE)] = {true, [this](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) { Cmd_RenderBorderTile_FillExecuteBuffer(ExecBuffer, static_cast(pBaseCommand)); }, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_RenderBorderTile(static_cast(pBaseCommand), ExecBuffer); }}; - m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_RENDER_BORDER_TILE_LINE)] = {true, [this](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) { Cmd_RenderBorderTileLine_FillExecuteBuffer(ExecBuffer, static_cast(pBaseCommand)); }, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_RenderBorderTileLine(static_cast(pBaseCommand), ExecBuffer); }}; m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_RENDER_QUAD_LAYER)] = {true, [this](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) { Cmd_RenderQuadLayer_FillExecuteBuffer(ExecBuffer, static_cast(pBaseCommand)); }, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_RenderQuadLayer(static_cast(pBaseCommand), ExecBuffer); }}; m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_RENDER_TEXT)] = {true, [this](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) { Cmd_RenderText_FillExecuteBuffer(ExecBuffer, static_cast(pBaseCommand)); }, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_RenderText(static_cast(pBaseCommand), ExecBuffer); }}; m_aCommandCallbacks[CommandBufferCMDOff(CCommandBuffer::CMD_RENDER_QUAD_CONTAINER)] = {true, [this](SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand *pBaseCommand) { Cmd_RenderQuadContainer_FillExecuteBuffer(ExecBuffer, static_cast(pBaseCommand)); }, [this](const CCommandBuffer::SCommand *pBaseCommand, SRenderCommandExecuteBuffer &ExecBuffer) { return Cmd_RenderQuadContainer(static_cast(pBaseCommand), ExecBuffer); }}; @@ -2600,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) @@ -2645,44 +2637,32 @@ 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(HighestBit(ConvertWidth), 16); - int NewHeight = maximum(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(HighestBit(ConvertWidth), 16); + int NewHeight = maximum(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) + void *p3DTexData = malloc((size_t)PixelSize * ConvertWidth * ConvertHeight); + if(!Texture2DTo3D(pData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DTexData, Image3DWidth, Image3DHeight)) { - 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 - { - 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) { @@ -3224,24 +3204,20 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase return GetPipeline(m_StandardPipeline, IsTextured, BlendModeIndex, DynamicIndex); } - VkPipelineLayout &GetTileLayerPipeLayout(int Type, bool IsTextured, size_t BlendModeIndex, size_t DynamicIndex) + VkPipelineLayout &GetTileLayerPipeLayout(bool IsBorder, bool IsTextured, size_t BlendModeIndex, size_t DynamicIndex) { - if(Type == 0) + if(!IsBorder) return GetPipeLayout(m_TilePipeline, IsTextured, BlendModeIndex, DynamicIndex); - else if(Type == 1) - return GetPipeLayout(m_TileBorderPipeline, IsTextured, BlendModeIndex, DynamicIndex); else - return GetPipeLayout(m_TileBorderLinePipeline, IsTextured, BlendModeIndex, DynamicIndex); + return GetPipeLayout(m_TileBorderPipeline, IsTextured, BlendModeIndex, DynamicIndex); } - VkPipeline &GetTileLayerPipe(int Type, bool IsTextured, size_t BlendModeIndex, size_t DynamicIndex) + VkPipeline &GetTileLayerPipe(bool IsBorder, bool IsTextured, size_t BlendModeIndex, size_t DynamicIndex) { - if(Type == 0) + if(!IsBorder) return GetPipeline(m_TilePipeline, IsTextured, BlendModeIndex, DynamicIndex); - else if(Type == 1) - return GetPipeline(m_TileBorderPipeline, IsTextured, BlendModeIndex, DynamicIndex); else - return GetPipeline(m_TileBorderLinePipeline, IsTextured, BlendModeIndex, DynamicIndex); + return GetPipeline(m_TileBorderPipeline, IsTextured, BlendModeIndex, DynamicIndex); } void GetStateIndices(const SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SState &State, bool &IsTextured, size_t &BlendModeIndex, size_t &DynamicIndex, size_t &AddressModeIndex) @@ -3372,7 +3348,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase ExecBufferFillDynamicStates(State, ExecBuffer); } - [[nodiscard]] bool RenderTileLayer(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SState &State, int Type, const GL_SColorf &Color, const vec2 &Dir, const vec2 &Off, int32_t JumpIndex, size_t IndicesDrawNum, char *const *pIndicesOffsets, const unsigned int *pDrawCount, size_t InstanceCount) + [[nodiscard]] bool RenderTileLayer(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SState &State, bool IsBorder, const GL_SColorf &Color, const vec2 &Scale, const vec2 &Off, size_t IndicesDrawNum, char *const *pIndicesOffsets, const unsigned int *pDrawCount) { std::array m; GetStateMatrix(State, m); @@ -3382,8 +3358,8 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase size_t DynamicIndex; size_t AddressModeIndex; GetStateIndices(ExecBuffer, State, IsTextured, BlendModeIndex, DynamicIndex, AddressModeIndex); - auto &PipeLayout = GetTileLayerPipeLayout(Type, IsTextured, BlendModeIndex, DynamicIndex); - auto &PipeLine = GetTileLayerPipe(Type, IsTextured, BlendModeIndex, DynamicIndex); + auto &PipeLayout = GetTileLayerPipeLayout(IsBorder, IsTextured, BlendModeIndex, DynamicIndex); + auto &PipeLine = GetTileLayerPipe(IsBorder, IsTextured, BlendModeIndex, DynamicIndex); VkCommandBuffer *pCommandBuffer; if(!GetGraphicCommandBuffer(pCommandBuffer, ExecBuffer.m_ThreadIndex)) @@ -3409,19 +3385,12 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase mem_copy(VertexPushConstants.m_aPos, m.data(), m.size() * sizeof(float)); FragPushConstants = Color; - if(Type == 1) + if(IsBorder) { - VertexPushConstants.m_Dir = Dir; + VertexPushConstants.m_Scale = Scale; VertexPushConstants.m_Offset = Off; - VertexPushConstants.m_JumpIndex = JumpIndex; VertexPushConstantSize = sizeof(SUniformTileGPosBorder); } - else if(Type == 2) - { - VertexPushConstants.m_Dir = Dir; - VertexPushConstants.m_Offset = Off; - VertexPushConstantSize = sizeof(SUniformTileGPosBorderLine); - } vkCmdPushConstants(CommandBuffer, PipeLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, VertexPushConstantSize, &VertexPushConstants); vkCmdPushConstants(CommandBuffer, PipeLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(SUniformTileGPosBorder) + sizeof(SUniformTileGVertColorAlign), FragPushConstantSize, &FragPushConstants); @@ -3432,7 +3401,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase { VkDeviceSize IndexOffset = (VkDeviceSize)((ptrdiff_t)pIndicesOffsets[i] / sizeof(uint32_t)); - vkCmdDrawIndexed(CommandBuffer, static_cast(pDrawCount[i]), InstanceCount, IndexOffset, 0, 0); + vkCmdDrawIndexed(CommandBuffer, static_cast(pDrawCount[i]), 1, IndexOffset, 0, 0); } return true; @@ -4911,21 +4880,19 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase } template - [[nodiscard]] bool CreateTileGraphicsPipelineImpl(const char *pVertName, const char *pFragName, int Type, SPipelineContainer &PipeContainer, EVulkanBackendTextureModes TexMode, EVulkanBackendBlendModes BlendMode, EVulkanBackendClipModes DynamicMode) + [[nodiscard]] bool CreateTileGraphicsPipelineImpl(const char *pVertName, const char *pFragName, bool IsBorder, SPipelineContainer &PipeContainer, EVulkanBackendTextureModes TexMode, EVulkanBackendBlendModes BlendMode, EVulkanBackendClipModes DynamicMode) { std::array 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 aSetLayouts; aSetLayouts[0] = m_Standard3DTexturedDescriptorSetLayout; uint32_t VertPushConstantSize = sizeof(SUniformTileGPos); - if(Type == 1) + if(IsBorder) VertPushConstantSize = sizeof(SUniformTileGPosBorder); - else if(Type == 2) - VertPushConstantSize = sizeof(SUniformTileGPosBorderLine); uint32_t FragPushConstantSize = sizeof(SUniformTileGVertColor); @@ -4933,11 +4900,11 @@ 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(pVertName, pFragName, PipeContainer, HasSampler ? (sizeof(float) * (2 + 3)) : (sizeof(float) * 2), aAttributeDescriptions, aSetLayouts, aPushConstants, TexMode, BlendMode, DynamicMode); + return CreateGraphicsPipeline(pVertName, pFragName, PipeContainer, HasSampler ? (sizeof(float) * 2 + sizeof(uint8_t) * 4) : (sizeof(float) * 2), aAttributeDescriptions, aSetLayouts, aPushConstants, TexMode, BlendMode, DynamicMode); } template - [[nodiscard]] bool CreateTileGraphicsPipeline(const char *pVertName, const char *pFragName, int Type) + [[nodiscard]] bool CreateTileGraphicsPipeline(const char *pVertName, const char *pFragName, bool IsBorder) { bool Ret = true; @@ -4947,7 +4914,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase { for(size_t j = 0; j < VULKAN_BACKEND_CLIP_MODE_COUNT; ++j) { - Ret &= CreateTileGraphicsPipelineImpl(pVertName, pFragName, Type, Type == 0 ? m_TilePipeline : (Type == 1 ? m_TileBorderPipeline : m_TileBorderLinePipeline), TexMode, EVulkanBackendBlendModes(i), EVulkanBackendClipModes(j)); + Ret &= CreateTileGraphicsPipelineImpl(pVertName, pFragName, IsBorder, !IsBorder ? m_TilePipeline : m_TileBorderPipeline, TexMode, EVulkanBackendBlendModes(i), EVulkanBackendClipModes(j)); } } @@ -5429,7 +5396,6 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase m_TextPipeline.Destroy(m_VKDevice); m_TilePipeline.Destroy(m_VKDevice); m_TileBorderPipeline.Destroy(m_VKDevice); - m_TileBorderLinePipeline.Destroy(m_VKDevice); m_PrimExPipeline.Destroy(m_VKDevice); m_PrimExRotationlessPipeline.Destroy(m_VKDevice); m_SpriteMultiPipeline.Destroy(m_VKDevice); @@ -6086,22 +6052,16 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase if(!CreateTextGraphicsPipeline("shader/vulkan/text.vert.spv", "shader/vulkan/text.frag.spv")) return -1; - if(!CreateTileGraphicsPipeline("shader/vulkan/tile.vert.spv", "shader/vulkan/tile.frag.spv", 0)) - return -1; - - if(!CreateTileGraphicsPipeline("shader/vulkan/tile_textured.vert.spv", "shader/vulkan/tile_textured.frag.spv", 0)) - return -1; - - if(!CreateTileGraphicsPipeline("shader/vulkan/tile_border.vert.spv", "shader/vulkan/tile_border.frag.spv", 1)) + if(!CreateTileGraphicsPipeline("shader/vulkan/tile.vert.spv", "shader/vulkan/tile.frag.spv", false)) return -1; - if(!CreateTileGraphicsPipeline("shader/vulkan/tile_border_textured.vert.spv", "shader/vulkan/tile_border_textured.frag.spv", 1)) + if(!CreateTileGraphicsPipeline("shader/vulkan/tile_textured.vert.spv", "shader/vulkan/tile_textured.frag.spv", false)) return -1; - if(!CreateTileGraphicsPipeline("shader/vulkan/tile_border_line.vert.spv", "shader/vulkan/tile_border_line.frag.spv", 2)) + if(!CreateTileGraphicsPipeline("shader/vulkan/tile_border.vert.spv", "shader/vulkan/tile_border.frag.spv", true)) return -1; - if(!CreateTileGraphicsPipeline("shader/vulkan/tile_border_line_textured.vert.spv", "shader/vulkan/tile_border_line_textured.frag.spv", 2)) + if(!CreateTileGraphicsPipeline("shader/vulkan/tile_border_textured.vert.spv", "shader/vulkan/tile_border_textured.frag.spv", true)) return -1; if(!CreatePrimExGraphicsPipeline("shader/vulkan/primex_rotationless.vert.spv", "shader/vulkan/primex_rotationless.frag.spv", false, true)) @@ -7076,11 +7036,9 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase [[nodiscard]] bool Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand, SRenderCommandExecuteBuffer &ExecBuffer) { - int Type = 0; - vec2 Dir{}; + vec2 Scale{}; vec2 Off{}; - int32_t JumpIndex = 0; - return RenderTileLayer(ExecBuffer, pCommand->m_State, Type, pCommand->m_Color, Dir, Off, JumpIndex, (size_t)pCommand->m_IndicesDrawNum, pCommand->m_pIndicesOffsets, pCommand->m_pDrawCount, 1); + 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) @@ -7090,24 +7048,10 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase [[nodiscard]] bool Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand, SRenderCommandExecuteBuffer &ExecBuffer) { - int Type = 1; - vec2 Dir = pCommand->m_Dir; - vec2 Off = pCommand->m_Offset; - unsigned int DrawNum = 6; - return RenderTileLayer(ExecBuffer, pCommand->m_State, Type, pCommand->m_Color, Dir, Off, pCommand->m_JumpIndex, (size_t)1, &pCommand->m_pIndicesOffset, &DrawNum, pCommand->m_DrawNum); - } - - void Cmd_RenderBorderTileLine_FillExecuteBuffer(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand) - { - RenderTileLayer_FillExecuteBuffer(ExecBuffer, 1, pCommand->m_State, pCommand->m_BufferContainerIndex); - } - - [[nodiscard]] bool Cmd_RenderBorderTileLine(const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand, SRenderCommandExecuteBuffer &ExecBuffer) - { - int Type = 2; - vec2 Dir = pCommand->m_Dir; + vec2 Scale = pCommand->m_Scale; vec2 Off = pCommand->m_Offset; - return RenderTileLayer(ExecBuffer, pCommand->m_State, Type, pCommand->m_Color, Dir, Off, 0, (size_t)1, &pCommand->m_pIndicesOffset, &pCommand->m_IndexDrawNum, pCommand->m_DrawNum); + unsigned int DrawNum = pCommand->m_DrawNum * 6; + return RenderTileLayer(ExecBuffer, pCommand->m_State, true, pCommand->m_Color, Scale, Off, 1, &pCommand->m_pIndicesOffset, &DrawNum); } void Cmd_RenderQuadLayer_FillExecuteBuffer(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand_RenderQuadLayer *pCommand) diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index c2c4e07f96e..03d48fd50bc 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -281,7 +281,8 @@ class CGraphicsBackend_SDL_GL : public CGraphicsBackend_Threaded bool HasQuadBuffering() override { return m_Capabilites.m_QuadBuffering; } bool HasTextBuffering() override { return m_Capabilites.m_TextBuffering; } bool HasQuadContainerBuffering() override { return m_Capabilites.m_QuadContainerBuffering; } - bool Has2DTextureArrays() override { return m_Capabilites.m_2DArrayTextures; } + bool Uses2DTextureArrays() override { return m_Capabilites.m_2DArrayTextures; } + bool HasTextureArraysSupport() override { return m_Capabilites.m_2DArrayTextures || m_Capabilites.m_3DTextures; } const char *GetErrorString() override { diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index dbcb10c5eb3..d2c8eef6c55 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -454,10 +454,6 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(size_t Width, size_ Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE; if((Flags & IGraphics::TEXLOAD_TO_3D_TEXTURE) != 0) Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_3D_TEXTURE; - if((Flags & IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER) != 0) - Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER; - if((Flags & IGraphics::TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER) != 0) - Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER; if((Flags & IGraphics::TEXLOAD_NO_2D_TEXTURE) != 0) Cmd.m_Flags |= CCommandBuffer::TEXFLAG_NO_2D_TEXTURE; @@ -1091,7 +1087,7 @@ void CGraphics_Threaded::QuadsTex3DDrawTL(const CQuadItem *pArray, int Num) { for(int n = 0; n < VertNum; ++n) { - if(HasTextureArrays()) + if(Uses2DTextureArrays()) m_aVerticesTex3D[CurNumVert + VertNum * i + n].m_Tex.w = (float)m_CurIndex; else m_aVerticesTex3D[CurNumVert + VertNum * i + n].m_Tex.w = ((float)m_CurIndex + 0.5f) / 256.f; @@ -1561,7 +1557,7 @@ void CGraphics_Threaded::RenderTileLayer(int BufferContainerIndex, const ColorRG // todo max indices group check!! } -void CGraphics_Threaded::RenderBorderTiles(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Dir, int JumpIndex, unsigned int DrawNum) +void CGraphics_Threaded::RenderBorderTiles(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Scale, uint32_t DrawNum) { if(DrawNum == 0) return; @@ -1573,32 +1569,9 @@ void CGraphics_Threaded::RenderBorderTiles(int BufferContainerIndex, const Color Cmd.m_Color = Color; Cmd.m_pIndicesOffset = pIndexBufferOffset; - Cmd.m_JumpIndex = JumpIndex; Cmd.m_Offset = Offset; - Cmd.m_Dir = Dir; - - AddCmd(Cmd); - - m_pCommandBuffer->AddRenderCalls(1); -} - -void CGraphics_Threaded::RenderBorderTileLines(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Dir, unsigned int IndexDrawNum, unsigned int RedrawNum) -{ - if(IndexDrawNum == 0 || RedrawNum == 0) - return; - // Draw a border tile a lot of times - CCommandBuffer::SCommand_RenderBorderTileLine Cmd; - Cmd.m_State = m_State; - Cmd.m_IndexDrawNum = IndexDrawNum; - Cmd.m_DrawNum = RedrawNum; - Cmd.m_BufferContainerIndex = BufferContainerIndex; - Cmd.m_Color = Color; - - Cmd.m_pIndicesOffset = pIndexBufferOffset; - - Cmd.m_Offset = Offset; - Cmd.m_Dir = Dir; + Cmd.m_Scale = Scale; AddCmd(Cmd); @@ -2393,7 +2366,8 @@ int CGraphics_Threaded::IssueInit() m_GLQuadBufferingEnabled = m_pBackend->HasQuadBuffering(); m_GLQuadContainerBufferingEnabled = m_pBackend->HasQuadContainerBuffering(); m_GLTextBufferingEnabled = (m_GLQuadContainerBufferingEnabled && m_pBackend->HasTextBuffering()); - m_GLHasTextureArrays = m_pBackend->Has2DTextureArrays(); + m_GLUses2DTextureArrays = m_pBackend->Uses2DTextureArrays(); + m_GLHasTextureArraysSupport = m_pBackend->HasTextureArraysSupport(); m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth; m_ScreenRefreshRate = g_Config.m_GfxScreenRefreshRate; } @@ -2627,7 +2601,7 @@ int CGraphics_Threaded::Init() mem_copy(&aNullTextureData[(y * InvalidTextureDimension + x) * PixelSize], pColor, PixelSize); } } - const int TextureLoadFlags = HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + const int TextureLoadFlags = Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; m_InvalidTexture.Invalidate(); m_InvalidTexture = LoadTextureRaw(InvalidTextureDimension, InvalidTextureDimension, CImageInfo::FORMAT_RGBA, aNullTextureData, TextureLoadFlags); } diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 9dcf339ea56..5f69b6ca8e2 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -117,7 +117,6 @@ class CCommandBuffer CMD_RENDER_TILE_LAYER, // render a tilelayer CMD_RENDER_BORDER_TILE, // render one tile multiple times - CMD_RENDER_BORDER_TILE_LINE, // render an amount of tiles multiple times CMD_RENDER_QUAD_LAYER, // render a quad layer CMD_RENDER_TEXT, // render text CMD_RENDER_QUAD_CONTAINER, // render a quad buffer container @@ -148,9 +147,7 @@ class CCommandBuffer TEXFLAG_NOMIPMAPS = 1, TEXFLAG_TO_3D_TEXTURE = (1 << 3), TEXFLAG_TO_2D_ARRAY_TEXTURE = (1 << 4), - TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER = (1 << 5), - TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER = (1 << 6), - TEXFLAG_NO_2D_TEXTURE = (1 << 7), + TEXFLAG_NO_2D_TEXTURE = (1 << 5), }; enum @@ -380,28 +377,12 @@ class CCommandBuffer SCommand(CMD_RENDER_BORDER_TILE) {} SState m_State; SColorf m_Color; // the color of the whole tilelayer -- already enveloped - char *m_pIndicesOffset; // you should use the command buffer data to allocate vertices for this command - unsigned int m_DrawNum; - int m_BufferContainerIndex; - - vec2 m_Offset; - vec2 m_Dir; - int m_JumpIndex; - }; - - struct SCommand_RenderBorderTileLine : public SCommand - { - SCommand_RenderBorderTileLine() : - SCommand(CMD_RENDER_BORDER_TILE_LINE) {} - SState m_State; - SColorf m_Color; // the color of the whole tilelayer -- already enveloped - char *m_pIndicesOffset; // you should use the command buffer data to allocate vertices for this command - unsigned int m_IndexDrawNum; - unsigned int m_DrawNum; + char *m_pIndicesOffset; + uint32_t m_DrawNum; int m_BufferContainerIndex; vec2 m_Offset; - vec2 m_Dir; + vec2 m_Scale; }; struct SCommand_RenderQuadLayer : public SCommand @@ -755,7 +736,8 @@ class IGraphicsBackend virtual bool HasQuadBuffering() { return false; } virtual bool HasTextBuffering() { return false; } virtual bool HasQuadContainerBuffering() { return false; } - virtual bool Has2DTextureArrays() { return false; } + virtual bool Uses2DTextureArrays() { return false; } + virtual bool HasTextureArraysSupport() { return false; } virtual const char *GetErrorString() { return NULL; } virtual const char *GetVendorString() = 0; @@ -788,7 +770,8 @@ class CGraphics_Threaded : public IEngineGraphics bool m_GLQuadBufferingEnabled; bool m_GLTextBufferingEnabled; bool m_GLQuadContainerBufferingEnabled; - bool m_GLHasTextureArrays; + bool m_GLUses2DTextureArrays; + bool m_GLHasTextureArraysSupport; bool m_GLUseTrianglesAsQuad; CCommandBuffer *m_apCommandBuffers[NUM_CMDBUFFERS]; @@ -1214,8 +1197,7 @@ class CGraphics_Threaded : public IEngineGraphics void FlushVerticesTex3D() override; void RenderTileLayer(int BufferContainerIndex, const ColorRGBA &Color, char **pOffsets, unsigned int *pIndicedVertexDrawNum, size_t NumIndicesOffset) override; - void RenderBorderTiles(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Dir, int JumpIndex, unsigned int DrawNum) override; - void RenderBorderTileLines(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Dir, unsigned int IndexDrawNum, unsigned int RedrawNum) override; + virtual void RenderBorderTiles(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Scale, uint32_t DrawNum) override; void RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, size_t QuadNum, int QuadOffset) override; void RenderText(int BufferContainerIndex, int TextQuadNum, int TextureSize, int TextureTextIndex, int TextureTextOutlineIndex, const ColorRGBA &TextColor, const ColorRGBA &TextOutlineColor) override; @@ -1286,7 +1268,8 @@ class CGraphics_Threaded : public IEngineGraphics bool IsQuadBufferingEnabled() override { return m_GLQuadBufferingEnabled; } bool IsTextBufferingEnabled() override { return m_GLTextBufferingEnabled; } bool IsQuadContainerBufferingEnabled() override { return m_GLQuadContainerBufferingEnabled; } - bool HasTextureArrays() override { return m_GLHasTextureArrays; } + bool Uses2DTextureArrays() override { return m_GLUses2DTextureArrays; } + bool HasTextureArraysSupport() override { return m_GLHasTextureArraysSupport; } const char *GetVendorString() override; const char *GetVersionString() override; diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 0d164ae5f53..5e1639ba941 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -57,10 +57,10 @@ struct SGraphicTile struct SGraphicTileTexureCoords { - vec3 m_TexCoordTopLeft; - vec3 m_TexCoordTopRight; - vec3 m_TexCoordBottomRight; - vec3 m_TexCoordBottomLeft; + ubvec4 m_TexCoordTopLeft; + ubvec4 m_TexCoordTopRight; + ubvec4 m_TexCoordBottomRight; + ubvec4 m_TexCoordBottomLeft; }; class CImageInfo @@ -246,9 +246,7 @@ class IGraphics : public IInterface TEXLOAD_NO_COMPRESSION = 1 << 2, TEXLOAD_TO_3D_TEXTURE = (1 << 3), TEXLOAD_TO_2D_ARRAY_TEXTURE = (1 << 4), - TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER = (1 << 5), - TEXLOAD_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER = (1 << 6), - TEXLOAD_NO_2D_TEXTURE = (1 << 7), + TEXLOAD_NO_2D_TEXTURE = (1 << 5), }; class CTextureHandle @@ -356,8 +354,7 @@ class IGraphics : public IInterface // specific render functions virtual void RenderTileLayer(int BufferContainerIndex, const ColorRGBA &Color, char **pOffsets, unsigned int *pIndicedVertexDrawNum, size_t NumIndicesOffset) = 0; - virtual void RenderBorderTiles(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Dir, int JumpIndex, unsigned int DrawNum) = 0; - virtual void RenderBorderTileLines(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Dir, unsigned int IndexDrawNum, unsigned int RedrawNum) = 0; + virtual void RenderBorderTiles(int BufferContainerIndex, const ColorRGBA &Color, char *pIndexBufferOffset, const vec2 &Offset, const vec2 &Scale, uint32_t DrawNum) = 0; virtual void RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo *pQuadInfo, size_t QuadNum, int QuadOffset) = 0; virtual void RenderText(int BufferContainerIndex, int TextQuadNum, int TextureSize, int TextureTextIndex, int TextureTextOutlineIndex, const ColorRGBA &TextColor, const ColorRGBA &TextOutlineColor) = 0; @@ -386,7 +383,8 @@ class IGraphics : public IInterface virtual bool IsQuadBufferingEnabled() = 0; virtual bool IsTextBufferingEnabled() = 0; virtual bool IsQuadContainerBufferingEnabled() = 0; - virtual bool HasTextureArrays() = 0; + virtual bool Uses2DTextureArrays() = 0; + virtual bool HasTextureArraysSupport() = 0; virtual const char *GetVendorString() = 0; virtual const char *GetVersionString() = 0; diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp index 54a5bb9a33d..54727939b7d 100644 --- a/src/game/client/components/mapimages.cpp +++ b/src/game/client/components/mapimages.cpp @@ -101,13 +101,13 @@ void CMapImages::OnMapLoadImpl(class CLayers *pLayers, IMap *pMap) } } - const int TextureLoadFlag = Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + const int TextureLoadFlag = Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; // load new textures bool ShowWarning = false; for(int i = 0; i < m_Count; i++) { - const int LoadFlag = (((m_aTextureUsedByTileOrQuadLayerFlag[i] & 1) != 0) ? TextureLoadFlag : 0) | (((m_aTextureUsedByTileOrQuadLayerFlag[i] & 2) != 0) ? 0 : (Graphics()->IsTileBufferingEnabled() ? IGraphics::TEXLOAD_NO_2D_TEXTURE : 0)); + const int LoadFlag = (((m_aTextureUsedByTileOrQuadLayerFlag[i] & 1) != 0) ? TextureLoadFlag : 0) | (((m_aTextureUsedByTileOrQuadLayerFlag[i] & 2) != 0) ? 0 : (Graphics()->HasTextureArraysSupport() ? IGraphics::TEXLOAD_NO_2D_TEXTURE : 0)); const CMapItemImage_v2 *pImg = (CMapItemImage_v2 *)pMap->GetItem(Start + i); const CImageInfo::EImageFormat Format = pImg->m_Version < CMapItemImage_v2::CURRENT_VERSION ? CImageInfo::FORMAT_RGBA : CImageInfo::ImageFormatFromInt(pImg->m_Format); @@ -220,8 +220,8 @@ IGraphics::CTextureHandle CMapImages::GetEntities(EMapImageEntityLayerType Entit bool GameTypeHasTuneLayer = HasTuneLayer(EntitiesModType) || WasUnknown; int TextureLoadFlag = 0; - if(Graphics()->IsTileBufferingEnabled()) - TextureLoadFlag = (Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE) | IGraphics::TEXLOAD_NO_2D_TEXTURE; + if(Graphics()->HasTextureArraysSupport()) + TextureLoadFlag = (Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE) | IGraphics::TEXLOAD_NO_2D_TEXTURE; CImageInfo ImgInfo; bool ImagePNGLoaded = false; @@ -356,8 +356,8 @@ IGraphics::CTextureHandle CMapImages::GetSpeedupArrow() { if(!m_SpeedupArrowIsLoaded) { - int TextureLoadFlag = (Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER : IGraphics::TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER) | IGraphics::TEXLOAD_NO_2D_TEXTURE; - m_SpeedupArrowTexture = Graphics()->LoadTexture(g_pData->m_aImages[IMAGE_SPEEDUP_ARROW].m_pFilename, IStorage::TYPE_ALL, TextureLoadFlag); + int TextureLoadFlag = (Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE) | IGraphics::TEXLOAD_NO_2D_TEXTURE; + m_SpeedupArrowTexture = Graphics()->LoadTexture("editor/speed_arrow_array.png", IStorage::TYPE_ALL, TextureLoadFlag); m_SpeedupArrowIsLoaded = true; } @@ -444,7 +444,7 @@ IGraphics::CTextureHandle CMapImages::UploadEntityLayerText(int TextureSize, int UpdateEntityLayerText(pMem, PixelSize, Width, Height, TextureSize, MaxWidth, YOffset, 1); UpdateEntityLayerText(pMem, PixelSize, Width, Height, TextureSize, MaxWidth, YOffset, 2, 255); - const int TextureLoadFlag = (Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE) | IGraphics::TEXLOAD_NO_2D_TEXTURE; + const int TextureLoadFlag = (Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE) | IGraphics::TEXLOAD_NO_2D_TEXTURE; IGraphics::CTextureHandle Texture = Graphics()->LoadTextureRaw(Width, Height, CImageInfo::FORMAT_RGBA, pMem, TextureLoadFlag); free(pMem); diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index b292e3ec071..ad49f9eb292 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -143,77 +143,7 @@ void CMapLayers::EnvelopeEval(int TimeOffsetMillis, int Env, ColorRGBA &Channels } } -void FillTmpTileSpeedup(SGraphicTile *pTmpTile, SGraphicTileTexureCoords *pTmpTex, bool As3DTextureCoord, unsigned char Flags, unsigned char Index, int x, int y, int Scale, CMapItemGroup *pGroup, short AngleRotate) -{ - if(pTmpTex) - { - unsigned char x0 = 0; - unsigned char y0 = 0; - unsigned char x1 = x0 + 1; - unsigned char y1 = y0; - unsigned char x2 = x0 + 1; - unsigned char y2 = y0 + 1; - unsigned char x3 = x0; - unsigned char y3 = y0 + 1; - - pTmpTex->m_TexCoordTopLeft.x = x0; - pTmpTex->m_TexCoordTopLeft.y = y0; - pTmpTex->m_TexCoordBottomLeft.x = x3; - pTmpTex->m_TexCoordBottomLeft.y = y3; - pTmpTex->m_TexCoordTopRight.x = x1; - pTmpTex->m_TexCoordTopRight.y = y1; - pTmpTex->m_TexCoordBottomRight.x = x2; - pTmpTex->m_TexCoordBottomRight.y = y2; - - if(As3DTextureCoord) - { - pTmpTex->m_TexCoordTopLeft.z = ((float)Index + 0.5f) / 256.f; - pTmpTex->m_TexCoordBottomLeft.z = ((float)Index + 0.5f) / 256.f; - pTmpTex->m_TexCoordTopRight.z = ((float)Index + 0.5f) / 256.f; - pTmpTex->m_TexCoordBottomRight.z = ((float)Index + 0.5f) / 256.f; - } - else - { - pTmpTex->m_TexCoordTopLeft.z = Index; - pTmpTex->m_TexCoordBottomLeft.z = Index; - pTmpTex->m_TexCoordTopRight.z = Index; - pTmpTex->m_TexCoordBottomRight.z = Index; - } - } - - //same as in rotate from Graphics() - float Angle = (float)AngleRotate * (pi / 180.0f); - float c = std::cos(Angle); - float s = std::sin(Angle); - float xR, yR; - int i; - - int ScaleSmaller = 2; - pTmpTile->m_TopLeft.x = x * Scale + ScaleSmaller; - pTmpTile->m_TopLeft.y = y * Scale + ScaleSmaller; - pTmpTile->m_BottomLeft.x = x * Scale + ScaleSmaller; - pTmpTile->m_BottomLeft.y = y * Scale + Scale - ScaleSmaller; - pTmpTile->m_TopRight.x = x * Scale + Scale - ScaleSmaller; - pTmpTile->m_TopRight.y = y * Scale + ScaleSmaller; - pTmpTile->m_BottomRight.x = x * Scale + Scale - ScaleSmaller; - pTmpTile->m_BottomRight.y = y * Scale + Scale - ScaleSmaller; - - float *pTmpTileVertices = (float *)pTmpTile; - - vec2 Center; - Center.x = pTmpTile->m_TopLeft.x + (Scale - ScaleSmaller) / 2.f; - Center.y = pTmpTile->m_TopLeft.y + (Scale - ScaleSmaller) / 2.f; - - for(i = 0; i < 4; i++) - { - xR = pTmpTileVertices[i * 2] - Center.x; - yR = pTmpTileVertices[i * 2 + 1] - Center.y; - pTmpTileVertices[i * 2] = xR * c - yR * s + Center.x; - pTmpTileVertices[i * 2 + 1] = xR * s + yR * c + Center.y; - } -} - -void FillTmpTile(SGraphicTile *pTmpTile, SGraphicTileTexureCoords *pTmpTex, bool As3DTextureCoord, unsigned char Flags, unsigned char Index, int x, int y, int Scale, CMapItemGroup *pGroup) +void FillTmpTile(SGraphicTile *pTmpTile, SGraphicTileTexureCoords *pTmpTex, unsigned char Flags, unsigned char Index, int x, int y, const ivec2 &Offset, int Scale, CMapItemGroup *pGroup) { if(pTmpTex) { @@ -265,30 +195,32 @@ void FillTmpTile(SGraphicTile *pTmpTile, SGraphicTileTexureCoords *pTmpTex, bool pTmpTex->m_TexCoordBottomRight.x = x2; pTmpTex->m_TexCoordBottomRight.y = y2; - if(As3DTextureCoord) - { - pTmpTex->m_TexCoordTopLeft.z = ((float)Index + 0.5f) / 256.f; - pTmpTex->m_TexCoordBottomLeft.z = ((float)Index + 0.5f) / 256.f; - pTmpTex->m_TexCoordTopRight.z = ((float)Index + 0.5f) / 256.f; - pTmpTex->m_TexCoordBottomRight.z = ((float)Index + 0.5f) / 256.f; - } - else - { - pTmpTex->m_TexCoordTopLeft.z = Index; - pTmpTex->m_TexCoordBottomLeft.z = Index; - pTmpTex->m_TexCoordTopRight.z = Index; - pTmpTex->m_TexCoordBottomRight.z = Index; - } + pTmpTex->m_TexCoordTopLeft.z = Index; + pTmpTex->m_TexCoordBottomLeft.z = Index; + pTmpTex->m_TexCoordTopRight.z = Index; + pTmpTex->m_TexCoordBottomRight.z = Index; + + bool HasRotation = (Flags & TILEFLAG_ROTATE) != 0; + pTmpTex->m_TexCoordTopLeft.w = HasRotation; + pTmpTex->m_TexCoordBottomLeft.w = HasRotation; + pTmpTex->m_TexCoordTopRight.w = HasRotation; + pTmpTex->m_TexCoordBottomRight.w = HasRotation; } - pTmpTile->m_TopLeft.x = x * Scale; - pTmpTile->m_TopLeft.y = y * Scale; - pTmpTile->m_BottomLeft.x = x * Scale; - pTmpTile->m_BottomLeft.y = y * Scale + Scale; - pTmpTile->m_TopRight.x = x * Scale + Scale; - pTmpTile->m_TopRight.y = y * Scale; - pTmpTile->m_BottomRight.x = x * Scale + Scale; - pTmpTile->m_BottomRight.y = y * Scale + Scale; + pTmpTile->m_TopLeft.x = x * Scale + Offset.x; + pTmpTile->m_TopLeft.y = y * Scale + Offset.y; + pTmpTile->m_BottomLeft.x = x * Scale + Offset.x; + pTmpTile->m_BottomLeft.y = y * Scale + Scale + Offset.y; + pTmpTile->m_TopRight.x = x * Scale + Scale + Offset.x; + pTmpTile->m_TopRight.y = y * Scale + Offset.y; + pTmpTile->m_BottomRight.x = x * Scale + Scale + Offset.x; + pTmpTile->m_BottomRight.y = y * Scale + Scale + Offset.y; +} + +void FillTmpTileSpeedup(SGraphicTile *pTmpTile, SGraphicTileTexureCoords *pTmpTex, unsigned char Flags, unsigned char Index, int x, int y, const ivec2 &Offset, int Scale, CMapItemGroup *pGroup, short AngleRotate) +{ + int Angle = AngleRotate % 360; + FillTmpTile(pTmpTile, pTmpTex, Angle >= 270 ? ROTATION_270 : (Angle >= 180 ? ROTATION_180 : (Angle >= 90 ? ROTATION_90 : 0)), AngleRotate % 90, x, y, Offset, Scale, pGroup); } bool CMapLayers::STileLayerVisuals::Init(unsigned int Width, unsigned int Height) @@ -303,35 +235,22 @@ bool CMapLayers::STileLayerVisuals::Init(unsigned int Width, unsigned int Height m_pTilesOfLayer = new CMapLayers::STileLayerVisuals::STileVisual[Height * Width]; - if(Width > 2) - { - m_pBorderTop = new CMapLayers::STileLayerVisuals::STileVisual[Width - 2]; - m_pBorderBottom = new CMapLayers::STileLayerVisuals::STileVisual[Width - 2]; - } - if(Height > 2) - { - m_pBorderLeft = new CMapLayers::STileLayerVisuals::STileVisual[Height - 2]; - m_pBorderRight = new CMapLayers::STileLayerVisuals::STileVisual[Height - 2]; - } + m_vBorderTop.resize(Width); + m_vBorderBottom.resize(Width); + + m_vBorderLeft.resize(Height); + m_vBorderRight.resize(Height); return true; } CMapLayers::STileLayerVisuals::~STileLayerVisuals() { delete[] m_pTilesOfLayer; - delete[] m_pBorderTop; - delete[] m_pBorderBottom; - delete[] m_pBorderLeft; - delete[] m_pBorderRight; m_pTilesOfLayer = NULL; - m_pBorderTop = NULL; - m_pBorderBottom = NULL; - m_pBorderLeft = NULL; - m_pBorderRight = NULL; } -bool AddTile(std::vector &vTmpTiles, std::vector &vTmpTileTexCoords, bool As3DTextureCoord, unsigned char Index, unsigned char Flags, int x, int y, CMapItemGroup *pGroup, bool DoTextureCoords, bool FillSpeedup = false, int AngleRotate = -1) +bool AddTile(std::vector &vTmpTiles, std::vector &vTmpTileTexCoords, unsigned char Index, unsigned char Flags, int x, int y, CMapItemGroup *pGroup, bool DoTextureCoords, bool FillSpeedup = false, int AngleRotate = -1, const ivec2 &Offset = ivec2{0, 0}, int Scale = 32) { if(Index) { @@ -345,9 +264,9 @@ bool AddTile(std::vector &vTmpTiles, std::vector vtmpQuads; std::vector vtmpQuadsTextured; - bool As3DTextureCoords = !Graphics()->HasTextureArrays(); - for(int g = 0; g < m_pLayers->NumGroups(); g++) { CMapItemGroup *pGroup = m_pLayers->GetGroup(g); @@ -696,13 +613,13 @@ void CMapLayers::OnMapLoad() //the amount of tiles handled before this tile int TilesHandledCount = vtmpTiles.size(); - Visuals.m_pTilesOfLayer[y * pTMap->m_Width + x].SetIndexBufferByteOffset((offset_ptr32)(TilesHandledCount * 6 * sizeof(unsigned int))); + Visuals.m_pTilesOfLayer[y * pTMap->m_Width + x].SetIndexBufferByteOffset((offset_ptr32)(TilesHandledCount)); bool AddAsSpeedup = false; if(IsSpeedupLayer && CurOverlay == 0) AddAsSpeedup = true; - if(AddTile(vtmpTiles, vtmpTileTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) + if(AddTile(vtmpTiles, vtmpTileTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) Visuals.m_pTilesOfLayer[y * pTMap->m_Width + x].Draw(true); //do the border tiles @@ -710,61 +627,49 @@ void CMapLayers::OnMapLoad() { if(y == 0) { - Visuals.m_BorderTopLeft.SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderCorners.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpBorderCorners, vtmpBorderCornersTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) + Visuals.m_BorderTopLeft.SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderCorners.size())); + if(AddTile(vtmpBorderCorners, vtmpBorderCornersTexCoords, Index, Flags, 0, 0, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate, ivec2{-32, -32})) Visuals.m_BorderTopLeft.Draw(true); } else if(y == pTMap->m_Height - 1) { - Visuals.m_BorderBottomLeft.SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderCorners.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpBorderCorners, vtmpBorderCornersTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) + Visuals.m_BorderBottomLeft.SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderCorners.size())); + if(AddTile(vtmpBorderCorners, vtmpBorderCornersTexCoords, Index, Flags, 0, 0, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate, ivec2{-32, 0})) Visuals.m_BorderBottomLeft.Draw(true); } - else - { - Visuals.m_pBorderLeft[y - 1].SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderLeftTiles.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpBorderLeftTiles, vtmpBorderLeftTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) - Visuals.m_pBorderLeft[y - 1].Draw(true); - } + Visuals.m_vBorderLeft[y].SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderLeftTiles.size())); + if(AddTile(vtmpBorderLeftTiles, vtmpBorderLeftTilesTexCoords, Index, Flags, 0, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate, ivec2{-32, 0})) + Visuals.m_vBorderLeft[y].Draw(true); } else if(x == pTMap->m_Width - 1) { if(y == 0) { - Visuals.m_BorderTopRight.SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderCorners.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpBorderCorners, vtmpBorderCornersTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) + Visuals.m_BorderTopRight.SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderCorners.size())); + if(AddTile(vtmpBorderCorners, vtmpBorderCornersTexCoords, Index, Flags, 0, 0, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate, ivec2{0, -32})) Visuals.m_BorderTopRight.Draw(true); } else if(y == pTMap->m_Height - 1) { - Visuals.m_BorderBottomRight.SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderCorners.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpBorderCorners, vtmpBorderCornersTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) + Visuals.m_BorderBottomRight.SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderCorners.size())); + if(AddTile(vtmpBorderCorners, vtmpBorderCornersTexCoords, Index, Flags, 0, 0, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate, ivec2{0, 0})) Visuals.m_BorderBottomRight.Draw(true); } - else - { - Visuals.m_pBorderRight[y - 1].SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderRightTiles.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpBorderRightTiles, vtmpBorderRightTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) - Visuals.m_pBorderRight[y - 1].Draw(true); - } + Visuals.m_vBorderRight[y].SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderRightTiles.size())); + if(AddTile(vtmpBorderRightTiles, vtmpBorderRightTilesTexCoords, Index, Flags, 0, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate, ivec2{0, 0})) + Visuals.m_vBorderRight[y].Draw(true); } - else if(y == 0) + if(y == 0) { - if(x > 0 && x < pTMap->m_Width - 1) - { - Visuals.m_pBorderTop[x - 1].SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderTopTiles.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpBorderTopTiles, vtmpBorderTopTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) - Visuals.m_pBorderTop[x - 1].Draw(true); - } + Visuals.m_vBorderTop[x].SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderTopTiles.size())); + if(AddTile(vtmpBorderTopTiles, vtmpBorderTopTilesTexCoords, Index, Flags, x, 0, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate, ivec2{0, -32})) + Visuals.m_vBorderTop[x].Draw(true); } else if(y == pTMap->m_Height - 1) { - if(x > 0 && x < pTMap->m_Width - 1) - { - Visuals.m_pBorderBottom[x - 1].SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderBottomTiles.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpBorderBottomTiles, vtmpBorderBottomTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate)) - Visuals.m_pBorderBottom[x - 1].Draw(true); - } + Visuals.m_vBorderBottom[x].SetIndexBufferByteOffset((offset_ptr32)(vtmpBorderBottomTiles.size())); + if(AddTile(vtmpBorderBottomTiles, vtmpBorderBottomTilesTexCoords, Index, Flags, x, 0, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate, ivec2{0, 0})) + Visuals.m_vBorderBottom[x].Draw(true); } } } @@ -772,61 +677,61 @@ void CMapLayers::OnMapLoad() //append one kill tile to the gamelayer if(IsGameLayer) { - Visuals.m_BorderKillTile.SetIndexBufferByteOffset((offset_ptr32)(vtmpTiles.size() * 6 * sizeof(unsigned int))); - if(AddTile(vtmpTiles, vtmpTileTexCoords, As3DTextureCoords, TILE_DEATH, 0, 0, 0, pGroup, DoTextureCoords)) + Visuals.m_BorderKillTile.SetIndexBufferByteOffset((offset_ptr32)(vtmpTiles.size())); + if(AddTile(vtmpTiles, vtmpTileTexCoords, TILE_DEATH, 0, 0, 0, pGroup, DoTextureCoords)) Visuals.m_BorderKillTile.Draw(true); } //add the border corners, then the borders and fix their byte offsets int TilesHandledCount = vtmpTiles.size(); - Visuals.m_BorderTopLeft.AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int)); - Visuals.m_BorderTopRight.AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int)); - Visuals.m_BorderBottomLeft.AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int)); - Visuals.m_BorderBottomRight.AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int)); + Visuals.m_BorderTopLeft.AddIndexBufferByteOffset(TilesHandledCount); + Visuals.m_BorderTopRight.AddIndexBufferByteOffset(TilesHandledCount); + Visuals.m_BorderBottomLeft.AddIndexBufferByteOffset(TilesHandledCount); + Visuals.m_BorderBottomRight.AddIndexBufferByteOffset(TilesHandledCount); //add the Corners to the tiles vtmpTiles.insert(vtmpTiles.end(), vtmpBorderCorners.begin(), vtmpBorderCorners.end()); vtmpTileTexCoords.insert(vtmpTileTexCoords.end(), vtmpBorderCornersTexCoords.begin(), vtmpBorderCornersTexCoords.end()); //now the borders TilesHandledCount = vtmpTiles.size(); - if(pTMap->m_Width > 2) + if(pTMap->m_Width > 0) { - for(int i = 0; i < pTMap->m_Width - 2; ++i) + for(int i = 0; i < pTMap->m_Width; ++i) { - Visuals.m_pBorderTop[i].AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int)); + Visuals.m_vBorderTop[i].AddIndexBufferByteOffset(TilesHandledCount); } } vtmpTiles.insert(vtmpTiles.end(), vtmpBorderTopTiles.begin(), vtmpBorderTopTiles.end()); vtmpTileTexCoords.insert(vtmpTileTexCoords.end(), vtmpBorderTopTilesTexCoords.begin(), vtmpBorderTopTilesTexCoords.end()); TilesHandledCount = vtmpTiles.size(); - if(pTMap->m_Width > 2) + if(pTMap->m_Width > 0) { - for(int i = 0; i < pTMap->m_Width - 2; ++i) + for(int i = 0; i < pTMap->m_Width; ++i) { - Visuals.m_pBorderBottom[i].AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int)); + Visuals.m_vBorderBottom[i].AddIndexBufferByteOffset(TilesHandledCount); } } vtmpTiles.insert(vtmpTiles.end(), vtmpBorderBottomTiles.begin(), vtmpBorderBottomTiles.end()); vtmpTileTexCoords.insert(vtmpTileTexCoords.end(), vtmpBorderBottomTilesTexCoords.begin(), vtmpBorderBottomTilesTexCoords.end()); TilesHandledCount = vtmpTiles.size(); - if(pTMap->m_Height > 2) + if(pTMap->m_Height > 0) { - for(int i = 0; i < pTMap->m_Height - 2; ++i) + for(int i = 0; i < pTMap->m_Height; ++i) { - Visuals.m_pBorderLeft[i].AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int)); + Visuals.m_vBorderLeft[i].AddIndexBufferByteOffset(TilesHandledCount); } } vtmpTiles.insert(vtmpTiles.end(), vtmpBorderLeftTiles.begin(), vtmpBorderLeftTiles.end()); vtmpTileTexCoords.insert(vtmpTileTexCoords.end(), vtmpBorderLeftTilesTexCoords.begin(), vtmpBorderLeftTilesTexCoords.end()); TilesHandledCount = vtmpTiles.size(); - if(pTMap->m_Height > 2) + if(pTMap->m_Height > 0) { - for(int i = 0; i < pTMap->m_Height - 2; ++i) + for(int i = 0; i < pTMap->m_Height; ++i) { - Visuals.m_pBorderRight[i].AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int)); + Visuals.m_vBorderRight[i].AddIndexBufferByteOffset(TilesHandledCount); } } vtmpTiles.insert(vtmpTiles.end(), vtmpBorderRightTiles.begin(), vtmpBorderRightTiles.end()); @@ -842,10 +747,10 @@ void CMapLayers::OnMapLoad() { char *pUploadData = (char *)malloc(sizeof(char) * UploadDataSize); - mem_copy_special(pUploadData, pTmpTiles, sizeof(vec2), vtmpTiles.size() * 4, (DoTextureCoords ? sizeof(vec3) : 0)); + mem_copy_special(pUploadData, pTmpTiles, sizeof(vec2), vtmpTiles.size() * 4, (DoTextureCoords ? sizeof(ubvec4) : 0)); if(DoTextureCoords) { - mem_copy_special(pUploadData + sizeof(vec2), pTmpTileTexCoords, sizeof(vec3), vtmpTiles.size() * 4, sizeof(vec2)); + mem_copy_special(pUploadData + sizeof(vec2), pTmpTileTexCoords, sizeof(ubvec4), vtmpTiles.size() * 4, sizeof(vec2)); } // first create the buffer object @@ -853,7 +758,7 @@ void CMapLayers::OnMapLoad() // then create the buffer container SBufferContainerInfo ContainerInfo; - ContainerInfo.m_Stride = (DoTextureCoords ? (sizeof(float) * 2 + sizeof(vec3)) : 0); + ContainerInfo.m_Stride = (DoTextureCoords ? (sizeof(float) * 2 + sizeof(ubvec4)) : 0); ContainerInfo.m_VertBufferBindingIndex = BufferObjectIndex; ContainerInfo.m_vAttributes.emplace_back(); SBufferContainerInfo::SAttribute *pAttr = &ContainerInfo.m_vAttributes.back(); @@ -866,11 +771,11 @@ void CMapLayers::OnMapLoad() { ContainerInfo.m_vAttributes.emplace_back(); pAttr = &ContainerInfo.m_vAttributes.back(); - pAttr->m_DataTypeCount = 3; - pAttr->m_Type = GRAPHICS_TYPE_FLOAT; + pAttr->m_DataTypeCount = 4; + pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE; pAttr->m_Normalized = false; pAttr->m_pOffset = (void *)(sizeof(vec2)); - pAttr->m_FuncType = 0; + pAttr->m_FuncType = 1; } Visuals.m_BufferContainerIndex = Graphics()->CreateBufferContainer(&ContainerInfo); @@ -1014,10 +919,10 @@ void CMapLayers::RenderTileLayer(int LayerIndex, ColorRGBA &Color, CMapItemLayer int BorderX0, BorderY0, BorderX1, BorderY1; bool DrawBorder = false; - int Y0 = BorderY0 = std::floor((ScreenY0) / 32); - int X0 = BorderX0 = std::floor((ScreenX0) / 32); - int Y1 = BorderY1 = std::floor((ScreenY1) / 32); - int X1 = BorderX1 = std::floor((ScreenX1) / 32); + int Y0 = BorderY0 = std::floor(ScreenY0 / 32); + int X0 = BorderX0 = std::floor(ScreenX0 / 32); + int Y1 = BorderY1 = std::ceil(ScreenY1 / 32); + int X1 = BorderX1 = std::ceil(ScreenX1 / 32); if(X0 <= 0) { @@ -1029,21 +934,21 @@ void CMapLayers::RenderTileLayer(int LayerIndex, ColorRGBA &Color, CMapItemLayer Y0 = 0; DrawBorder = true; } - if(X1 >= pTileLayer->m_Width - 1) + if(X1 >= pTileLayer->m_Width) { - X1 = pTileLayer->m_Width - 1; + X1 = pTileLayer->m_Width; DrawBorder = true; } - if(Y1 >= pTileLayer->m_Height - 1) + if(Y1 >= pTileLayer->m_Height) { - Y1 = pTileLayer->m_Height - 1; + Y1 = pTileLayer->m_Height; DrawBorder = true; } bool DrawLayer = true; - if(X1 < 0) + if(X1 <= 0) DrawLayer = false; - if(Y1 < 0) + if(Y1 <= 0) DrawLayer = false; if(X0 >= pTileLayer->m_Width) DrawLayer = false; @@ -1063,14 +968,15 @@ void CMapLayers::RenderTileLayer(int LayerIndex, ColorRGBA &Color, CMapItemLayer s_vpIndexOffsets.reserve(Reserve); s_vDrawCounts.reserve(Reserve); - for(int y = Y0; y <= Y1; ++y) + for(int y = Y0; y < Y1; ++y) { if(X0 > X1) continue; + int XR = X1 - 1; - dbg_assert(Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + X1].IndexBufferByteOffset() >= Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + X0].IndexBufferByteOffset(), "Tile count wrong."); + dbg_assert(Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + XR].IndexBufferByteOffset() >= Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + X0].IndexBufferByteOffset(), "Tile count wrong."); - unsigned int NumVertices = ((Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + X1].IndexBufferByteOffset() - Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + X0].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + X1].DoDraw() ? 6lu : 0lu); + unsigned int NumVertices = ((Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + XR].IndexBufferByteOffset() - Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + X0].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_pTilesOfLayer[y * pTileLayer->m_Width + XR].DoDraw() ? 6lu : 0lu); if(NumVertices) { @@ -1092,23 +998,10 @@ void CMapLayers::RenderTileLayer(int LayerIndex, ColorRGBA &Color, CMapItemLayer } if(DrawBorder) - RenderTileBorder(LayerIndex, Color, pTileLayer, pGroup, BorderX0, BorderY0, BorderX1, BorderY1, -std::floor(-ScreenX1 / 32.f) - BorderX0, -std::floor(-ScreenY1 / 32.f) - BorderY0); + RenderTileBorder(LayerIndex, Color, pTileLayer, pGroup, BorderX0, BorderY0, BorderX1, BorderY1); } -void CMapLayers::RenderTileBorderCornerTiles(int WidthOffsetToOrigin, int HeightOffsetToOrigin, int TileCountWidth, int TileCountHeight, int BufferContainerIndex, const ColorRGBA &Color, offset_ptr_size IndexBufferOffset, const vec2 &Offset, const vec2 &Dir) -{ - // if border is still in range of the original corner, it doesn't needs to be redrawn - bool CornerVisible = (WidthOffsetToOrigin - 1 < TileCountWidth) && (HeightOffsetToOrigin - 1 < TileCountHeight); - - int CountX = minimum(WidthOffsetToOrigin, TileCountWidth); - int CountY = minimum(HeightOffsetToOrigin, TileCountHeight); - - int Count = (CountX * CountY) - (CornerVisible ? 1 : 0); // Don't draw the corner again - - Graphics()->RenderBorderTiles(BufferContainerIndex, Color, IndexBufferOffset, Offset, Dir, CountX, Count); -} - -void CMapLayers::RenderTileBorder(int LayerIndex, const ColorRGBA &Color, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup, int BorderX0, int BorderY0, int BorderX1, int BorderY1, int ScreenWidthTileCount, int ScreenHeightTileCount) +void CMapLayers::RenderTileBorder(int LayerIndex, const ColorRGBA &Color, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup, int BorderX0, int BorderY0, int BorderX1, int BorderY1) { STileLayerVisuals &Visuals = *m_vpTileLayerVisuals[LayerIndex]; @@ -1117,145 +1010,147 @@ void CMapLayers::RenderTileBorder(int LayerIndex, const ColorRGBA &Color, CMapIt int Y1 = BorderY1; int X1 = BorderX1; - int CountWidth = ScreenWidthTileCount; - int CountHeight = ScreenHeightTileCount; - - if(X0 < 1) - X0 = 1; - if(Y0 < 1) - Y0 = 1; - if(X1 >= pTileLayer->m_Width - 1) - X1 = pTileLayer->m_Width - 2; - if(Y1 >= pTileLayer->m_Height - 1) - Y1 = pTileLayer->m_Height - 2; + if(X0 < 0) + X0 = 0; + if(Y0 < 0) + Y0 = 0; + if(X1 > pTileLayer->m_Width) + X1 = pTileLayer->m_Width; + if(Y1 > pTileLayer->m_Height) + Y1 = pTileLayer->m_Height; - if(BorderX0 <= 0) + // corners + if(BorderX0 < 0) { // Draw corners on left side - if(BorderY0 <= 0) + if(BorderY0 < 0) { if(Visuals.m_BorderTopLeft.DoDraw()) { vec2 Offset; - Offset.x = BorderX0 * 32.f; - Offset.y = BorderY0 * 32.f; - vec2 Dir; - Dir.x = 32.f; - Dir.y = 32.f; + Offset.x = 0; + Offset.y = 0; + vec2 Scale; + Scale.x = absolute(BorderX0); + Scale.y = absolute(BorderY0); - RenderTileBorderCornerTiles(absolute(BorderX0) + 1, absolute(BorderY0) + 1, CountWidth, CountHeight, Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderTopLeft.IndexBufferByteOffset(), Offset, Dir); + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderTopLeft.IndexBufferByteOffset(), Offset, Scale, 1); } } - if(BorderY1 >= pTileLayer->m_Height - 1) + if(BorderY1 >= pTileLayer->m_Height) { if(Visuals.m_BorderBottomLeft.DoDraw()) { vec2 Offset; - Offset.x = BorderX0 * 32.f; - Offset.y = (BorderY1 - (pTileLayer->m_Height - 1)) * 32.f; - vec2 Dir; - Dir.x = 32.f; - Dir.y = -32.f; + Offset.x = 0; + Offset.y = pTileLayer->m_Height * 32.0f; + vec2 Scale; + Scale.x = absolute(BorderX0); + Scale.y = BorderY1 - pTileLayer->m_Height; - RenderTileBorderCornerTiles(absolute(BorderX0) + 1, (BorderY1 - (pTileLayer->m_Height - 1)) + 1, CountWidth, CountHeight, Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderBottomLeft.IndexBufferByteOffset(), Offset, Dir); + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderBottomLeft.IndexBufferByteOffset(), Offset, Scale, 1); } } } - if(BorderX0 < 0) - { - // Draw left border - if(Y0 < pTileLayer->m_Height - 1 && Y1 > 0) - { - unsigned int DrawNum = ((Visuals.m_pBorderLeft[Y1 - 1].IndexBufferByteOffset() - Visuals.m_pBorderLeft[Y0 - 1].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_pBorderLeft[Y1 - 1].DoDraw() ? 6lu : 0lu); - offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_pBorderLeft[Y0 - 1].IndexBufferByteOffset(); - vec2 Offset; - Offset.x = 32.f * BorderX0; - Offset.y = 0.f; - vec2 Dir; - Dir.x = 32.f; - Dir.y = 0.f; - Graphics()->RenderBorderTileLines(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Dir, DrawNum, minimum(absolute(BorderX0), CountWidth)); - } - } - - if(BorderX1 >= pTileLayer->m_Width - 1) + if(BorderX1 >= pTileLayer->m_Width) { // Draw corners on right side - if(BorderY0 <= 0) + if(BorderY0 < 0) { if(Visuals.m_BorderTopRight.DoDraw()) { vec2 Offset; - Offset.x = (BorderX1 - (pTileLayer->m_Width - 1)) * 32.f; - Offset.y = BorderY0 * 32.f; - vec2 Dir; - Dir.x = -32.f; - Dir.y = 32.f; + Offset.x = pTileLayer->m_Width * 32.0f; + Offset.y = 0; + vec2 Scale; + Scale.x = BorderX1 - pTileLayer->m_Width; + Scale.y = absolute(BorderY0); - RenderTileBorderCornerTiles((BorderX1 - (pTileLayer->m_Width - 1)) + 1, absolute(BorderY0) + 1, CountWidth, CountHeight, Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderTopRight.IndexBufferByteOffset(), Offset, Dir); + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderTopRight.IndexBufferByteOffset(), Offset, Scale, 1); } } - if(BorderY1 >= pTileLayer->m_Height - 1) + if(BorderY1 >= pTileLayer->m_Height) { if(Visuals.m_BorderBottomRight.DoDraw()) { vec2 Offset; - Offset.x = (BorderX1 - (pTileLayer->m_Width - 1)) * 32.f; - Offset.y = (BorderY1 - (pTileLayer->m_Height - 1)) * 32.f; - vec2 Dir; - Dir.x = -32.f; - Dir.y = -32.f; + Offset.x = pTileLayer->m_Width * 32.0f; + Offset.y = pTileLayer->m_Height * 32.0f; + vec2 Scale; + Scale.x = BorderX1 - pTileLayer->m_Width; + Scale.y = BorderY1 - pTileLayer->m_Height; - RenderTileBorderCornerTiles((BorderX1 - (pTileLayer->m_Width - 1)) + 1, (BorderY1 - (pTileLayer->m_Height - 1)) + 1, CountWidth, CountHeight, Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderBottomRight.IndexBufferByteOffset(), Offset, Dir); + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderBottomRight.IndexBufferByteOffset(), Offset, Scale, 1); } } } - if(BorderX1 > pTileLayer->m_Width - 1) + + if(BorderX1 >= pTileLayer->m_Width) { // Draw right border - if(Y0 < pTileLayer->m_Height - 1 && Y1 > 0) + if(Y0 < pTileLayer->m_Height && Y1 > 0) { - unsigned int DrawNum = ((Visuals.m_pBorderRight[Y1 - 1].IndexBufferByteOffset() - Visuals.m_pBorderRight[Y0 - 1].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_pBorderRight[Y1 - 1].DoDraw() ? 6lu : 0lu); - offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_pBorderRight[Y0 - 1].IndexBufferByteOffset(); + int YB = Y1 - 1; + unsigned int DrawNum = ((Visuals.m_vBorderRight[YB].IndexBufferByteOffset() - Visuals.m_vBorderRight[Y0].IndexBufferByteOffset()) / (sizeof(unsigned int) * 6)) + (Visuals.m_vBorderRight[YB].DoDraw() ? 1lu : 0lu); + offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_vBorderRight[Y0].IndexBufferByteOffset(); vec2 Offset; - Offset.x = 32.f * (BorderX1 - (pTileLayer->m_Width - 1)); + Offset.x = 32.f * pTileLayer->m_Width; Offset.y = 0.f; - vec2 Dir; - Dir.x = -32.f; - Dir.y = 0.f; - Graphics()->RenderBorderTileLines(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Dir, DrawNum, minimum((BorderX1 - (pTileLayer->m_Width - 1)), CountWidth)); + vec2 Scale; + Scale.x = BorderX1 - pTileLayer->m_Width; + Scale.y = 1.f; + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Scale, DrawNum); + } + } + if(BorderX0 < 0) + { + // Draw left border + if(Y0 < pTileLayer->m_Height && Y1 > 0) + { + int YB = Y1 - 1; + unsigned int DrawNum = ((Visuals.m_vBorderLeft[YB].IndexBufferByteOffset() - Visuals.m_vBorderLeft[Y0].IndexBufferByteOffset()) / (sizeof(unsigned int) * 6)) + (Visuals.m_vBorderLeft[YB].DoDraw() ? 1lu : 0lu); + offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_vBorderLeft[Y0].IndexBufferByteOffset(); + vec2 Offset; + Offset.x = 0; + Offset.y = 0; + vec2 Scale; + Scale.x = absolute(BorderX0); + Scale.y = 1; + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Scale, DrawNum); } } if(BorderY0 < 0) { // Draw top border - if(X0 < pTileLayer->m_Width - 1 && X1 > 0) + if(X0 < pTileLayer->m_Width && X1 > 0) { - unsigned int DrawNum = ((Visuals.m_pBorderTop[X1 - 1].IndexBufferByteOffset() - Visuals.m_pBorderTop[X0 - 1].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_pBorderTop[X1 - 1].DoDraw() ? 6lu : 0lu); - offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_pBorderTop[X0 - 1].IndexBufferByteOffset(); + int XR = X1 - 1; + unsigned int DrawNum = ((Visuals.m_vBorderTop[XR].IndexBufferByteOffset() - Visuals.m_vBorderTop[X0].IndexBufferByteOffset()) / (sizeof(unsigned int) * 6)) + (Visuals.m_vBorderTop[XR].DoDraw() ? 1lu : 0lu); + offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_vBorderTop[X0].IndexBufferByteOffset(); vec2 Offset; Offset.x = 0.f; - Offset.y = 32.f * BorderY0; - vec2 Dir; - Dir.x = 0.f; - Dir.y = 32.f; - Graphics()->RenderBorderTileLines(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Dir, DrawNum, minimum(absolute(BorderY0), CountHeight)); + Offset.y = 0; + vec2 Scale; + Scale.x = 1; + Scale.y = absolute(BorderY0); + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Scale, DrawNum); } } if(BorderY1 >= pTileLayer->m_Height) { // Draw bottom border - if(X0 < pTileLayer->m_Width - 1 && X1 > 0) + if(X0 < pTileLayer->m_Width && X1 > 0) { - unsigned int DrawNum = ((Visuals.m_pBorderBottom[X1 - 1].IndexBufferByteOffset() - Visuals.m_pBorderBottom[X0 - 1].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_pBorderBottom[X1 - 1].DoDraw() ? 6lu : 0lu); - offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_pBorderBottom[X0 - 1].IndexBufferByteOffset(); + int XR = X1 - 1; + unsigned int DrawNum = ((Visuals.m_vBorderBottom[XR].IndexBufferByteOffset() - Visuals.m_vBorderBottom[X0].IndexBufferByteOffset()) / (sizeof(unsigned int) * 6)) + (Visuals.m_vBorderBottom[XR].DoDraw() ? 1lu : 0lu); + offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_vBorderBottom[X0].IndexBufferByteOffset(); vec2 Offset; Offset.x = 0.f; - Offset.y = 32.f * (BorderY1 - (pTileLayer->m_Height - 1)); - vec2 Dir; - Dir.x = 0.f; - Dir.y = -32.f; - Graphics()->RenderBorderTileLines(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Dir, DrawNum, minimum((BorderY1 - (pTileLayer->m_Height - 1)), CountHeight)); + Offset.y = 32.f * pTileLayer->m_Height; + vec2 Scale; + Scale.x = 1; + Scale.y = BorderY1 - pTileLayer->m_Height; + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Scale, DrawNum); } } } @@ -1271,10 +1166,10 @@ void CMapLayers::RenderKillTileBorder(int LayerIndex, const ColorRGBA &Color, CM bool DrawBorder = false; - int BorderY0 = (int)(ScreenY0 / 32) - 1; - int BorderX0 = (int)(ScreenX0 / 32) - 1; - int BorderY1 = (int)(ScreenY1 / 32) + 1; - int BorderX1 = (int)(ScreenX1 / 32) + 1; + int BorderY0 = std::floor(ScreenY0 / 32); + int BorderX0 = std::floor(ScreenX0 / 32); + int BorderY1 = std::ceil(ScreenY1 / 32); + int BorderX1 = std::ceil(ScreenX1 / 32); if(BorderX0 < -201) DrawBorder = true; @@ -1311,64 +1206,54 @@ void CMapLayers::RenderKillTileBorder(int LayerIndex, const ColorRGBA &Color, CM // Draw left kill tile border if(BorderX0 < -201) { + unsigned int DrawNum = 1; + offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(); vec2 Offset; - Offset.x = BorderX0 * 32.f; - Offset.y = BorderY0 * 32.f; - vec2 Dir; - Dir.x = 32.f; - Dir.y = 32.f; - - int Count = (absolute(BorderX0) - 201) * (BorderY1 - BorderY0); - - Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(), Offset, Dir, (absolute(BorderX0) - 201), Count); + Offset.x = 32.f * BorderX0; + Offset.y = 32.f * BorderY0; + vec2 Scale; + Scale.x = -201 - BorderX0; + Scale.y = BorderY1 - BorderY0; + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Scale, DrawNum); } // Draw top kill tile border if(BorderY0 < -201) { + unsigned int DrawNum = 1; + offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(); vec2 Offset; - int OffX0 = (BorderX0 < -201 ? -201 : BorderX0); - int OffX1 = (BorderX1 >= pTileLayer->m_Width + 201 ? pTileLayer->m_Width + 201 : BorderX1); - OffX0 = clamp(OffX0, -201, (int)pTileLayer->m_Width + 201); - OffX1 = clamp(OffX1, -201, (int)pTileLayer->m_Width + 201); - Offset.x = OffX0 * 32.f; - Offset.y = BorderY0 * 32.f; - vec2 Dir; - Dir.x = 32.f; - Dir.y = 32.f; - - int Count = (OffX1 - OffX0) * (absolute(BorderY0) - 201); - - Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(), Offset, Dir, (OffX1 - OffX0), Count); + Offset.x = maximum(BorderX0, -201) * 32.0f; + Offset.y = 32.f * BorderY0; + vec2 Scale; + Scale.x = minimum(BorderX1, pTileLayer->m_Width + 201) - maximum(BorderX0, -201); + Scale.y = -201 - BorderY0; + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Scale, DrawNum); } + // Draw right kill tile border if(BorderX1 >= pTileLayer->m_Width + 201) { + unsigned int DrawNum = 1; + offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(); vec2 Offset; - Offset.x = (pTileLayer->m_Width + 201) * 32.f; - Offset.y = BorderY0 * 32.f; - vec2 Dir; - Dir.x = 32.f; - Dir.y = 32.f; - - int Count = (BorderX1 - (pTileLayer->m_Width + 201)) * (BorderY1 - BorderY0); - - Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(), Offset, Dir, (BorderX1 - (pTileLayer->m_Width + 201)), Count); + Offset.x = 32.0f * (pTileLayer->m_Width + 201); + Offset.y = 32.0f * BorderY0; + vec2 Scale; + Scale.x = BorderX1 - (pTileLayer->m_Width + 201); + Scale.y = BorderY1 - BorderY0; + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Scale, DrawNum); } + // Draw bottom kill tile border if(BorderY1 >= pTileLayer->m_Height + 201) { + unsigned int DrawNum = 1; + offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(); vec2 Offset; - int OffX0 = (BorderX0 < -201 ? -201 : BorderX0); - int OffX1 = (BorderX1 >= pTileLayer->m_Width + 201 ? pTileLayer->m_Width + 201 : BorderX1); - OffX0 = clamp(OffX0, -201, (int)pTileLayer->m_Width + 201); - OffX1 = clamp(OffX1, -201, (int)pTileLayer->m_Width + 201); - Offset.x = OffX0 * 32.f; - Offset.y = (pTileLayer->m_Height + 201) * 32.f; - vec2 Dir; - Dir.x = 32.f; - Dir.y = 32.f; - - int Count = (OffX1 - OffX0) * (BorderY1 - (pTileLayer->m_Height + 201)); - - Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(), Offset, Dir, (OffX1 - OffX0), Count); + Offset.x = maximum(BorderX0, -201) * 32.0f; + Offset.y = 32.0f * (pTileLayer->m_Height + 201); + vec2 Scale; + Scale.x = minimum(BorderX1, pTileLayer->m_Width + 201) - maximum(BorderX0, -201); + Scale.y = BorderY1 - (pTileLayer->m_Height + 201); + Graphics()->RenderBorderTiles(Visuals.m_BufferContainerIndex, Color, pOffset, Offset, Scale, DrawNum); } } @@ -1960,6 +1845,7 @@ void CMapLayers::OnRender() Graphics()->TextureSet(m_pImages->GetSpeedupArrow()); RenderTileLayer(TileLayerCounter - 3, Color, pTMap, pGroup); Graphics()->WrapNormal(); + if(g_Config.m_ClTextEntities) { Graphics()->TextureSet(m_pImages->GetOverlayBottom()); diff --git a/src/game/client/components/maplayers.h b/src/game/client/components/maplayers.h index b6d26023722..6f273976eb8 100644 --- a/src/game/client/components/maplayers.h +++ b/src/game/client/components/maplayers.h @@ -40,7 +40,7 @@ class CMapLayers : public CComponent struct STileLayerVisuals { STileLayerVisuals() : - m_pTilesOfLayer(nullptr), m_pBorderTop(nullptr), m_pBorderLeft(nullptr), m_pBorderRight(nullptr), m_pBorderBottom(nullptr) + m_pTilesOfLayer(nullptr) { m_Width = 0; m_Height = 0; @@ -63,27 +63,27 @@ class CMapLayers : public CComponent public: bool DoDraw() { - return (m_IndexBufferByteOffset & 0x00000001) != 0; + return (m_IndexBufferByteOffset & 0x10000000) != 0; } void Draw(bool SetDraw) { - m_IndexBufferByteOffset = (SetDraw ? 0x00000001 : (offset_ptr32)0) | (m_IndexBufferByteOffset & 0xFFFFFFFE); + m_IndexBufferByteOffset = (SetDraw ? 0x10000000 : (offset_ptr32)0) | (m_IndexBufferByteOffset & 0xEFFFFFFF); } offset_ptr IndexBufferByteOffset() { - return ((offset_ptr)(m_IndexBufferByteOffset & 0xFFFFFFFE)); + return ((offset_ptr)(m_IndexBufferByteOffset & 0xEFFFFFFF) * 6 * sizeof(uint32_t)); } void SetIndexBufferByteOffset(offset_ptr32 IndexBufferByteOff) { - m_IndexBufferByteOffset = IndexBufferByteOff | (m_IndexBufferByteOffset & 0x00000001); + m_IndexBufferByteOffset = IndexBufferByteOff | (m_IndexBufferByteOffset & 0x10000000); } void AddIndexBufferByteOffset(offset_ptr32 IndexBufferByteOff) { - m_IndexBufferByteOffset = ((m_IndexBufferByteOffset & 0xFFFFFFFE) + IndexBufferByteOff) | (m_IndexBufferByteOffset & 0x00000001); + m_IndexBufferByteOffset = ((m_IndexBufferByteOffset & 0xEFFFFFFF) + IndexBufferByteOff) | (m_IndexBufferByteOffset & 0x10000000); } }; STileVisual *m_pTilesOfLayer; @@ -95,10 +95,10 @@ class CMapLayers : public CComponent STileVisual m_BorderKillTile; //end of map kill tile -- game layer only - STileVisual *m_pBorderTop; - STileVisual *m_pBorderLeft; - STileVisual *m_pBorderRight; - STileVisual *m_pBorderBottom; + std::vector m_vBorderTop; + std::vector m_vBorderLeft; + std::vector m_vBorderRight; + std::vector m_vBorderBottom; unsigned int m_Width; unsigned int m_Height; @@ -132,8 +132,6 @@ class CMapLayers : public CComponent void LayersOfGroupCount(CMapItemGroup *pGroup, int &TileLayerCount, int &QuadLayerCount, bool &PassedGameLayer); - void RenderTileBorderCornerTiles(int WidthOffsetToOrigin, int HeightOffsetToOrigin, int TileCountWidth, int TileCountHeight, int BufferContainerIndex, const ColorRGBA &Color, offset_ptr_size IndexBufferOffset, const vec2 &Offset, const vec2 &Dir); - protected: virtual bool CanRenderMenuBackground() { return true; } @@ -155,7 +153,7 @@ class CMapLayers : public CComponent virtual void OnMapLoad() override; void RenderTileLayer(int LayerIndex, ColorRGBA &Color, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup); - void RenderTileBorder(int LayerIndex, const ColorRGBA &Color, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup, int BorderX0, int BorderY0, int BorderX1, int BorderY1, int ScreenWidthTileCount, int ScreenHeightTileCount); + void RenderTileBorder(int LayerIndex, const ColorRGBA &Color, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup, int BorderX0, int BorderY0, int BorderX1, int BorderY1); void RenderKillTileBorder(int LayerIndex, const ColorRGBA &Color, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup); void RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer, CMapItemGroup *pGroup, bool ForceRender = false); diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index b04cbbaa5e0..5e858292d4c 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -459,7 +459,10 @@ void CRenderTools::RenderTileRectangle(int RectX, int RectY, int RectW, int Rect pfnEval(ColorEnvOffset, ColorEnv, Channels, pUser); } - Graphics()->QuadsBegin(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DBegin(); + else + Graphics()->QuadsBegin(); Graphics()->SetColor(Color.r * Channels.r, Color.g * Channels.g, Color.b * Channels.b, Color.a * Channels.a); int StartY = (int)(ScreenY0 / Scale) - 1; @@ -501,15 +504,39 @@ void CRenderTools::RenderTileRectangle(int RectX, int RectY, int RectW, int Rect float x3 = Nudge + Px0 / TexSize + Frac; float y3 = Nudge + Py1 / TexSize - Frac; - Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); - IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); - Graphics()->QuadsDrawTL(&QuadItem, 1); + if(Graphics()->HasTextureArraysSupport()) + { + x0 = 0; + y0 = 0; + x1 = x0 + 1; + y1 = y0; + x2 = x0 + 1; + y2 = y0 + 1; + x3 = x0; + y3 = y0 + 1; + } + + if(Graphics()->HasTextureArraysSupport()) + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3, Index); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsTex3DDrawTL(&QuadItem, 1); + } + else + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsDrawTL(&QuadItem, 1); + } } } } } - Graphics()->QuadsEnd(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DEnd(); + else + Graphics()->QuadsEnd(); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } @@ -530,7 +557,7 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, Color pfnEval(ColorEnvOffset, ColorEnv, Channels, pUser); } - if(Graphics()->IsTileBufferingEnabled()) + if(Graphics()->HasTextureArraysSupport()) Graphics()->QuadsTex3DBegin(); else Graphics()->QuadsBegin(); @@ -613,7 +640,7 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, Color float x3 = Nudge + Px0 / TexSize + Frac; float y3 = Nudge + Py1 / TexSize - Frac; - if(Graphics()->IsTileBufferingEnabled()) + if(Graphics()->HasTextureArraysSupport()) { x0 = 0; y0 = 0; @@ -655,7 +682,7 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, Color y1 = Tmp; } - if(Graphics()->IsTileBufferingEnabled()) + if(Graphics()->HasTextureArraysSupport()) { Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3, Index); IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); @@ -673,7 +700,7 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, Color } } - if(Graphics()->IsTileBufferingEnabled()) + if(Graphics()->HasTextureArraysSupport()) Graphics()->QuadsTex3DEnd(); else Graphics()->QuadsEnd(); @@ -918,7 +945,10 @@ void CRenderTools::RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, Co float FinalTileSize = Scale / (ScreenX1 - ScreenX0) * Graphics()->ScreenWidth(); float FinalTilesetScale = FinalTileSize / TilePixelSize; - Graphics()->QuadsBegin(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DBegin(); + else + Graphics()->QuadsBegin(); Graphics()->SetColor(Color); int StartY = (int)(ScreenY0 / Scale) - 1; @@ -987,14 +1017,38 @@ void CRenderTools::RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, Co float x3 = Nudge + Px0 / TexSize + Frac; float y3 = Nudge + Py1 / TexSize - Frac; - Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); - IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); - Graphics()->QuadsDrawTL(&QuadItem, 1); + if(Graphics()->HasTextureArraysSupport()) + { + x0 = 0; + y0 = 0; + x1 = x0 + 1; + y1 = y0; + x2 = x0 + 1; + y2 = y0 + 1; + x3 = x0; + y3 = y0 + 1; + } + + if(Graphics()->HasTextureArraysSupport()) + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3, Index); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsTex3DDrawTL(&QuadItem, 1); + } + else + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsDrawTL(&QuadItem, 1); + } } } } - Graphics()->QuadsEnd(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DEnd(); + else + Graphics()->QuadsEnd(); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } @@ -1010,7 +1064,10 @@ void CRenderTools::RenderSpeedupmap(CSpeedupTile *pSpeedupTile, int w, int h, fl float FinalTileSize = Scale / (ScreenX1 - ScreenX0) * Graphics()->ScreenWidth(); float FinalTilesetScale = FinalTileSize / TilePixelSize; - Graphics()->QuadsBegin(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DBegin(); + else + Graphics()->QuadsBegin(); Graphics()->SetColor(Color); int StartY = (int)(ScreenY0 / Scale) - 1; @@ -1079,14 +1136,38 @@ void CRenderTools::RenderSpeedupmap(CSpeedupTile *pSpeedupTile, int w, int h, fl float x3 = Nudge + Px0 / TexSize + Frac; float y3 = Nudge + Py1 / TexSize - Frac; - Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); - IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); - Graphics()->QuadsDrawTL(&QuadItem, 1); + if(Graphics()->HasTextureArraysSupport()) + { + x0 = 0; + y0 = 0; + x1 = x0 + 1; + y1 = y0; + x2 = x0 + 1; + y2 = y0 + 1; + x3 = x0; + y3 = y0 + 1; + } + + if(Graphics()->HasTextureArraysSupport()) + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3, Index); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsTex3DDrawTL(&QuadItem, 1); + } + else + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsDrawTL(&QuadItem, 1); + } } } } - Graphics()->QuadsEnd(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DEnd(); + else + Graphics()->QuadsEnd(); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } @@ -1102,7 +1183,10 @@ void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float float FinalTileSize = Scale / (ScreenX1 - ScreenX0) * Graphics()->ScreenWidth(); float FinalTilesetScale = FinalTileSize / TilePixelSize; - Graphics()->QuadsBegin(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DBegin(); + else + Graphics()->QuadsBegin(); Graphics()->SetColor(Color); int StartY = (int)(ScreenY0 / Scale) - 1; @@ -1184,6 +1268,18 @@ void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float float x3 = Nudge + Px0 / TexSize + Frac; float y3 = Nudge + Py1 / TexSize - Frac; + if(Graphics()->HasTextureArraysSupport()) + { + x0 = 0; + y0 = 0; + x1 = x0 + 1; + y1 = y0; + x2 = x0 + 1; + y2 = y0 + 1; + x3 = x0; + y3 = y0 + 1; + } + if(Flags & TILEFLAG_XFLIP) { x0 = x2; @@ -1214,14 +1310,26 @@ void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float y1 = Tmp; } - Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); - IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); - Graphics()->QuadsDrawTL(&QuadItem, 1); + if(Graphics()->HasTextureArraysSupport()) + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3, Index); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsTex3DDrawTL(&QuadItem, 1); + } + else + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsDrawTL(&QuadItem, 1); + } } } } - Graphics()->QuadsEnd(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DEnd(); + else + Graphics()->QuadsEnd(); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } @@ -1235,7 +1343,10 @@ void CRenderTools::RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, Co float FinalTileSize = Scale / (ScreenX1 - ScreenX0) * Graphics()->ScreenWidth(); float FinalTilesetScale = FinalTileSize / TilePixelSize; - Graphics()->QuadsBegin(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DBegin(); + else + Graphics()->QuadsBegin(); Graphics()->SetColor(Color); int StartY = (int)(ScreenY0 / Scale) - 1; @@ -1304,13 +1415,37 @@ void CRenderTools::RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, Co float x3 = Nudge + Px0 / TexSize + Frac; float y3 = Nudge + Py1 / TexSize - Frac; - Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); - IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); - Graphics()->QuadsDrawTL(&QuadItem, 1); + if(Graphics()->HasTextureArraysSupport()) + { + x0 = 0; + y0 = 0; + x1 = x0 + 1; + y1 = y0; + x2 = x0 + 1; + y2 = y0 + 1; + x3 = x0; + y3 = y0 + 1; + } + + if(Graphics()->HasTextureArraysSupport()) + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3, Index); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsTex3DDrawTL(&QuadItem, 1); + } + else + { + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); + IGraphics::CQuadItem QuadItem(x * Scale, y * Scale, Scale, Scale); + Graphics()->QuadsDrawTL(&QuadItem, 1); + } } } } - Graphics()->QuadsEnd(); + if(Graphics()->HasTextureArraysSupport()) + Graphics()->QuadsTex3DEnd(); + else + Graphics()->QuadsEnd(); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index adbf16d2548..951cfee2019 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -3941,7 +3941,7 @@ bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDup } pImg->m_AutoMapper.Load(pImg->m_aName); - int TextureLoadFlag = Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + int TextureLoadFlag = Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; if(ImgInfo.m_Width % 16 != 0 || ImgInfo.m_Height % 16 != 0) TextureLoadFlag = 0; pImg->m_Texture = Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, TextureLoadFlag, pFileName); @@ -4000,7 +4000,7 @@ bool CEditor::AddImage(const char *pFileName, int StorageType, void *pUser) DilateImage((unsigned char *)ImgInfo.m_pData, ImgInfo.m_Width, ImgInfo.m_Height); } - int TextureLoadFlag = pEditor->Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + int TextureLoadFlag = pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; if(ImgInfo.m_Width % 16 != 0 || ImgInfo.m_Height % 16 != 0) TextureLoadFlag = 0; pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, TextureLoadFlag, pFileName); @@ -7561,7 +7561,7 @@ void CEditor::Reset(bool CreateDefault) int CEditor::GetTextureUsageFlag() { - return Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + return Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; } IGraphics::CTextureHandle CEditor::GetFrontTexture() diff --git a/src/game/editor/mapitems/map_io.cpp b/src/game/editor/mapitems/map_io.cpp index e054737e38c..30a88ee40e8 100644 --- a/src/game/editor/mapitems/map_io.cpp +++ b/src/game/editor/mapitems/map_io.cpp @@ -505,7 +505,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio pImg->m_Height = ImgInfo.m_Height; pImg->m_Format = ImgInfo.m_Format; pImg->m_pData = ImgInfo.m_pData; - int TextureLoadFlag = m_pEditor->Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + int TextureLoadFlag = m_pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; if(ImgInfo.m_Width % 16 != 0 || ImgInfo.m_Height % 16 != 0) TextureLoadFlag = 0; pImg->m_Texture = m_pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, TextureLoadFlag, aBuf); @@ -524,7 +524,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio const size_t DataSize = (size_t)pImg->m_Width * pImg->m_Height * CImageInfo::PixelSize(Format); pImg->m_pData = malloc(DataSize); mem_copy(pImg->m_pData, pData, DataSize); - int TextureLoadFlag = m_pEditor->Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + int TextureLoadFlag = m_pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; if(pImg->m_Width % 16 != 0 || pImg->m_Height % 16 != 0) TextureLoadFlag = 0; pImg->m_Texture = m_pEditor->Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, pImg->m_Format, pImg->m_pData, TextureLoadFlag); diff --git a/src/game/editor/tileart.cpp b/src/game/editor/tileart.cpp index e6e88ef975b..da96fdcff53 100644 --- a/src/game/editor/tileart.cpp +++ b/src/game/editor/tileart.cpp @@ -154,7 +154,7 @@ static std::shared_ptr ImageInfoToEditorImage(CEditor *pEditor, co pEditorImage->m_Format = Image.m_Format; pEditorImage->m_pData = Image.m_pData; - int TextureLoadFlag = pEditor->Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + int TextureLoadFlag = pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; pEditorImage->m_Texture = pEditor->Graphics()->LoadTextureRaw(Image.m_Width, Image.m_Height, Image.m_Format, Image.m_pData, TextureLoadFlag, pName); pEditorImage->m_External = 0; str_copy(pEditorImage->m_aName, pName);