Revert Jupeyy's OpenGL changes

Emergency-revert for 14.5.1 release, too many problems
This commit is contained in:
def 2020-08-26 20:01:32 +02:00
parent 62d68d24fa
commit 3eab3f5eb7
46 changed files with 1152 additions and 2981 deletions

View file

@ -1140,12 +1140,20 @@ set(EXPECTED_DATA
maps7/Gold\ Mine.map
maps7/readme.txt
particles.png
shader/pipeline.frag
shader/pipeline.vert
shader/bordertile.frag
shader/bordertile.vert
shader/bordertileline.frag
shader/bordertileline.vert
shader/bordertilelinetex.frag
shader/bordertilelinetex.vert
shader/bordertiletex.frag
shader/bordertiletex.vert
shader/prim.frag
shader/prim.vert
shader/quad.frag
shader/quad.vert
shader/quadtex.frag
shader/quadtex.vert
shader/sprite.frag
shader/sprite.vert
shader/spritemulti.frag
@ -1154,6 +1162,8 @@ set(EXPECTED_DATA
shader/text.vert
shader/tile.frag
shader/tile.vert
shader/tiletex.frag
shader/tiletex.vert
"skins/Ablush NeoN.png"
skins/Aoe4leg.png
"skins/Apish Coke.png"

View file

@ -0,0 +1,10 @@
#version 330
uniform vec4 vertColor;
out vec4 FragClr;
void main()
{
FragClr = vertColor;
}

View file

@ -0,0 +1,20 @@
#version 330
layout (location = 0) in vec2 inVertex;
uniform mat4x2 Pos;
uniform vec2 Offset;
uniform vec2 Dir;
uniform int JumpIndex;
void main()
{
vec4 VertPos = vec4(inVertex, 0.0, 1.0);
int XCount = gl_InstanceID - (int(gl_InstanceID/JumpIndex) * JumpIndex);
int YCount = (int(gl_InstanceID/JumpIndex));
VertPos.x += Offset.x + Dir.x * XCount;
VertPos.y += Offset.y + Dir.y * YCount;
gl_Position = vec4(Pos * VertPos, 0.0, 1.0);
}

View file

@ -0,0 +1,9 @@
#version 330
uniform vec4 vertColor;
out vec4 FragClr;
void main()
{
FragClr = vertColor;
}

View file

@ -0,0 +1,17 @@
#version 330
layout (location = 0) in vec2 inVertex;
uniform mat4x2 Pos;
uniform vec2 Dir;
uniform vec2 Offset;
void main()
{
vec4 VertPos = vec4(inVertex.x + Offset.x, inVertex.y + Offset.y, 0.0, 1.0);
VertPos.x += Dir.x * gl_InstanceID;
VertPos.y += Dir.y * gl_InstanceID;
gl_Position = vec4(Pos * VertPos, 0.0, 1.0);
}

View file

@ -0,0 +1,15 @@
#version 330
uniform sampler2D textureSampler;
uniform vec4 vertColor;
uniform float LOD;
noperspective in vec2 texCoord;
out vec4 FragClr;
void main()
{
vec4 tex = textureLod(textureSampler, texCoord, LOD);
FragClr = tex * vertColor;
}

View file

@ -0,0 +1,27 @@
#version 330
layout (location = 0) in vec2 inVertex;
layout (location = 1) in vec2 inVertexTexCoord;
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
uniform mat4x2 Pos;
uniform float TexelOffset;
uniform vec2 Dir;
uniform vec2 Offset;
noperspective out vec2 texCoord;
void main()
{
vec4 VertPos = vec4(inVertex.x + Offset.x, inVertex.y + Offset.y, 0.0, 1.0);
VertPos.x += Dir.x * gl_InstanceID;
VertPos.y += Dir.y * gl_InstanceID;
gl_Position = vec4(Pos * VertPos, 0.0, 1.0);
float tx = (inVertexTexCoord.x/(16.0));
float ty = (inVertexTexCoord.y/(16.0));
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset));
}

View file

@ -0,0 +1,15 @@
#version 330
uniform sampler2D textureSampler;
uniform vec4 vertColor;
uniform float LOD;
noperspective in vec2 texCoord;
out vec4 FragClr;
void main()
{
vec4 tex = textureLod(textureSampler, texCoord, LOD);
FragClr = tex * vertColor;
}

View file

@ -0,0 +1,30 @@
#version 330
layout (location = 0) in vec2 inVertex;
layout (location = 1) in vec2 inVertexTexCoord;
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
uniform mat4x2 Pos;
uniform float TexelOffset;
uniform vec2 Offset;
uniform vec2 Dir;
uniform int JumpIndex;
noperspective out vec2 texCoord;
void main()
{
vec4 VertPos = vec4(inVertex, 0.0, 1.0);
int XCount = gl_InstanceID - (int(gl_InstanceID/JumpIndex) * JumpIndex);
int YCount = (int(gl_InstanceID/JumpIndex));
VertPos.x += Offset.x + Dir.x * XCount;
VertPos.y += Offset.y + Dir.y * YCount;
gl_Position = vec4(Pos * VertPos, 0.0, 1.0);
float tx = (inVertexTexCoord.x/(16.0));
float ty = (inVertexTexCoord.y/(16.0));
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset));
}

View file

@ -1,18 +0,0 @@
#ifdef TW_TEXTURED
#ifdef TW_3D_TEXTURED
uniform sampler3D gTextureSampler;
#else
uniform sampler2DArray gTextureSampler;
#endif
#endif
void main()
{
#ifdef TW_TEXTURED
vec4 TexColor = texture(gTextureSampler, gl_TexCoord[0].xyz).rgba;
gl_FragColor = TexColor.rgba * gl_Color.rgba;
#else
gl_FragColor = gl_Color.rgba;
#endif
}

View file

@ -1,11 +0,0 @@
uniform mat4x2 gPos;
void main()
{
gl_Position = vec4(gPos * vec4(gl_Vertex.xy, 0.0, 1.0), 0.0, 1.0);
#ifdef TW_TEXTURED
gl_TexCoord[0] = gl_MultiTexCoord0;
#endif
gl_FrontColor = gl_Color.rgba;
gl_BackColor = gl_Color.rgba;
}

View file

@ -1,3 +1,5 @@
#version 330
uniform int isTextured;
uniform sampler2D textureSampler;

View file

@ -1,3 +1,5 @@
#version 330
layout (location = 0) in vec2 inVertex;
layout (location = 1) in vec2 inVertexTexCoord;
layout (location = 2) in vec4 inVertexColor;

View file

@ -1,22 +1,11 @@
#ifdef TW_QUAD_TEXTURED
uniform sampler2D gTextureSampler;
#endif
#version 330
uniform vec4 gVertColors[TW_MAX_QUADS];
uniform vec4 vertColor;
noperspective in vec4 QuadColor;
flat in int QuadIndex;
#ifdef TW_QUAD_TEXTURED
noperspective in vec2 TexCoord;
#endif
noperspective in vec4 quadColor;
out vec4 FragClr;
void main()
{
#ifdef TW_QUAD_TEXTURED
vec4 TexColor = texture(gTextureSampler, TexCoord);
FragClr = TexColor * QuadColor * gVertColors[QuadIndex];
#else
FragClr = QuadColor * gVertColors[QuadIndex];
#endif
FragClr = quadColor * vertColor;
}

View file

@ -1,42 +1,31 @@
#version 330
layout (location = 0) in vec4 inVertex;
layout (location = 1) in vec4 inColor;
#ifdef TW_QUAD_TEXTURED
layout (location = 2) in vec2 inVertexTexCoord;
#endif
uniform mat4x2 gPos;
uniform mat4x2 Pos;
uniform vec2 gOffsets[TW_MAX_QUADS];
uniform float gRotations[TW_MAX_QUADS];
uniform vec2 Offset;
uniform float Rotation;
noperspective out vec4 QuadColor;
flat out int QuadIndex;
#ifdef TW_QUAD_TEXTURED
noperspective out vec2 TexCoord;
#endif
noperspective out vec4 quadColor;
void main()
{
vec2 FinalPos = vec2(inVertex.xy);
int TmpQuadIndex = int(gl_VertexID / 4);
if(gRotations[TmpQuadIndex] != 0.0)
if(Rotation != 0.0)
{
float X = FinalPos.x - inVertex.z;
float Y = FinalPos.y - inVertex.w;
FinalPos.x = X * cos(gRotations[TmpQuadIndex]) - Y * sin(gRotations[TmpQuadIndex]) + inVertex.z;
FinalPos.y = X * sin(gRotations[TmpQuadIndex]) + Y * cos(gRotations[TmpQuadIndex]) + inVertex.w;
FinalPos.x = X * cos(Rotation) - Y * sin(Rotation) + inVertex.z;
FinalPos.y = X * sin(Rotation) + Y * cos(Rotation) + inVertex.w;
}
FinalPos.x = FinalPos.x / 1024.0 + gOffsets[TmpQuadIndex].x;
FinalPos.y = FinalPos.y / 1024.0 + gOffsets[TmpQuadIndex].y;
FinalPos.x = FinalPos.x / 1024.0 + Offset.x;
FinalPos.y = FinalPos.y / 1024.0 + Offset.y;
gl_Position = vec4(gPos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
QuadColor = inColor;
QuadIndex = TmpQuadIndex;
#ifdef TW_QUAD_TEXTURED
TexCoord = inVertexTexCoord;
#endif
gl_Position = vec4(Pos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
quadColor = inColor;
}

15
data/shader/quadtex.frag Normal file
View file

@ -0,0 +1,15 @@
#version 330
uniform sampler2D textureSampler;
uniform vec4 vertColor;
noperspective in vec2 texCoord;
noperspective in vec4 quadColor;
out vec4 FragClr;
void main()
{
vec4 tex = texture(textureSampler, texCoord);
FragClr = tex * quadColor * vertColor;
}

34
data/shader/quadtex.vert Normal file
View file

@ -0,0 +1,34 @@
#version 330
layout (location = 0) in vec4 inVertex;
layout (location = 1) in vec2 inVertexTexCoord;
layout (location = 2) in vec4 inColor;
uniform mat4x2 Pos;
uniform vec2 Offset;
uniform float Rotation;
noperspective out vec2 texCoord;
noperspective out vec4 quadColor;
void main()
{
vec2 FinalPos = vec2(inVertex.xy);
if(Rotation != 0.0)
{
float X = FinalPos.x - inVertex.z;
float Y = FinalPos.y - inVertex.w;
FinalPos.x = X * cos(Rotation) - Y * sin(Rotation) + inVertex.z;
FinalPos.y = X * sin(Rotation) + Y * cos(Rotation) + inVertex.w;
}
FinalPos.x = FinalPos.x / 1024.0 + Offset.x;
FinalPos.y = FinalPos.y / 1024.0 + Offset.y;
gl_Position = vec4(Pos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
texCoord = inVertexTexCoord;
quadColor = inColor;
}

View file

@ -1,3 +1,5 @@
#version 330
uniform sampler2D textureSampler;
uniform vec4 VerticesColor;

View file

@ -1,3 +1,5 @@
#version 330
layout (location = 0) in vec2 inVertex;
layout (location = 1) in vec2 inVertexTexCoord;
layout (location = 2) in vec4 inVertexColor;

View file

@ -1,3 +1,5 @@
#version 330
uniform sampler2D textureSampler;
uniform vec4 VerticesColor;

View file

@ -1,3 +1,5 @@
#version 330
layout (location = 0) in vec2 inVertex;
layout (location = 1) in vec2 inVertexTexCoord;
layout (location = 2) in vec4 inVertexColor;

View file

@ -1,3 +1,5 @@
#version 330
uniform sampler2D textSampler;
uniform sampler2D textOutlineSampler;

View file

@ -1,3 +1,5 @@
#version 330
layout (location = 0) in vec2 inVertex;
layout (location = 1) in vec2 inVertexTexCoord;
layout (location = 2) in vec4 inVertexColor;

View file

@ -1,24 +1,10 @@
#ifdef TW_TILE_TEXTURED
#ifdef TW_TILE_3D_TEXTURED
uniform sampler3D gTextureSampler;
#else
uniform sampler2DArray gTextureSampler;
#endif
#endif
#version 330
uniform vec4 gVertColor;
#ifdef TW_TILE_TEXTURED
noperspective in vec3 TexCoord;
#endif
uniform vec4 vertColor;
out vec4 FragClr;
void main()
{
#ifdef TW_TILE_TEXTURED
vec4 TexColor = texture(gTextureSampler, TexCoord.xyz);
FragClr = TexColor * gVertColor;
#else
FragClr = gVertColor;
#endif
FragClr = vertColor;
}

View file

@ -1,44 +1,10 @@
#version 330
layout (location = 0) in vec2 inVertex;
#ifdef TW_TILE_TEXTURED
layout (location = 1) in vec3 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
uniform mat4x2 Pos;
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 * XCount;
VertPos.y += gOffset.y + gDir.y * 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 * gl_InstanceID;
VertPos.y += gDir.y * 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;
#endif
gl_Position = vec4(Pos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
}

15
data/shader/tiletex.frag Normal file
View file

@ -0,0 +1,15 @@
#version 330
uniform sampler2D textureSampler;
uniform vec4 vertColor;
uniform float LOD;
noperspective in vec2 texCoord;
out vec4 FragClr;
void main()
{
vec4 tex = textureLod(textureSampler, texCoord, LOD);
FragClr = tex * vertColor;
}

20
data/shader/tiletex.vert Normal file
View file

@ -0,0 +1,20 @@
#version 330
layout (location = 0) in vec2 inVertex;
layout (location = 1) in vec2 inVertexTexCoord;
layout (location = 2) in ivec2 inVertexTexRightOrBottom;
uniform mat4x2 Pos;
uniform float TexelOffset;
noperspective out vec2 texCoord;
void main()
{
gl_Position = vec4(Pos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
float tx = (inVertexTexCoord.x/(16.0));
float ty = (inVertexTexCoord.y/(16.0));
texCoord = vec2(tx + (inVertexTexRightOrBottom.x == 0 ? TexelOffset : -TexelOffset), ty + (inVertexTexRightOrBottom.y == 0 ? TexelOffset : -TexelOffset));
}

File diff suppressed because it is too large Load diff

View file

@ -5,8 +5,6 @@
#include "graphics_threaded.h"
#include <atomic>
# if defined(CONF_PLATFORM_MACOSX)
#include <objc/objc-runtime.h>
@ -75,223 +73,96 @@ public:
bool RunCommand(const CCommandBuffer::SCommand *pBaseCommand);
};
struct SBackendCapabilites
{
bool m_TileBuffering;
bool m_QuadBuffering;
bool m_TextBuffering;
bool m_QuadContainerBuffering;
bool m_MipMapping;
bool m_NPOTTextures;
bool m_3DTextures;
bool m_2DArrayTextures;
bool m_2DArrayTexturesAsExtension;
bool m_ShaderSupport;
int m_ContextMajor;
int m_ContextMinor;
int m_ContextPatch;
};
class CGLSLProgram;
class CGLSLTWProgram;
class CGLSLPrimitiveProgram;
class CGLSLQuadProgram;
class CGLSLTileProgram;
class CGLSLTextProgram;
class CGLSLSpriteProgram;
class CGLSLSpriteMultipleProgram;
// takes care of opengl related rendering
class CCommandProcessorFragment_OpenGL
{
protected:
struct CTexture
{
CTexture() : m_Tex2DArray(0), m_Sampler2DArray(0) {}
GLuint m_Tex;
GLuint m_Tex2DArray; //or 3D texture as fallback
GLuint m_Sampler;
GLuint m_Sampler2DArray; //or 3D texture as fallback
int m_LastWrapMode;
int m_MemSize;
int m_Width;
int m_Height;
int m_RescaleCount;
float m_ResizeWidth;
float m_ResizeHeight;
};
CTexture m_aTextures[CCommandBuffer::MAX_TEXTURES];
std::atomic<int> *m_pTextureMemoryUsage;
volatile int *m_pTextureMemoryUsage;
GLint m_MaxTexSize;
bool m_Has2DArrayTextures;
bool m_Has2DArrayTexturesAsExtension;
GLenum m_2DArrayTarget;
bool m_Has3DTextures;
bool m_HasMipMaps;
bool m_HasNPOTTextures;
bool m_HasShaders;
int m_LastBlendMode; //avoid all possible opengl state changes
bool m_LastClipEnable;
public:
enum
{
CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_OPENGL,
CMD_SHUTDOWN = CMD_INIT + 1,
};
struct SCommand_Init : public CCommandBuffer::SCommand
{
SCommand_Init() : SCommand(CMD_INIT) {}
class IStorage *m_pStorage;
std::atomic<int> *m_pTextureMemoryUsage;
const SBackendCapabilites* m_pCapabilities;
volatile int *m_pTextureMemoryUsage;
};
struct SCommand_Shutdown : public CCommandBuffer::SCommand
{
SCommand_Shutdown() : SCommand(CMD_SHUTDOWN) {}
};
protected:
void SetState(const CCommandBuffer::SState &State, bool Use2DArrayTexture = false);
virtual bool IsNewApi() { return false; }
private:
static int TexFormatToOpenGLFormat(int TexFormat);
static int TexFormatToImageColorChannelCount(int TexFormat);
static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp);
static void *Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData);
static void *Resize(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData);
virtual void Cmd_Init(const SCommand_Init *pCommand);
virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand) {}
virtual void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand);
virtual void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand);
virtual void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand);
virtual void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand);
virtual void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand);
virtual void Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand);
void SetState(const CCommandBuffer::SState &State);
virtual void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) {}
virtual void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) {}
virtual void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) {}
virtual void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) {}
virtual void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) {}
void Cmd_Init(const SCommand_Init *pCommand);
void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand);
void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand);
void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand);
void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand);
void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand);
void Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand);
virtual void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) {}
virtual void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) {}
virtual void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) {}
virtual void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) {}
virtual void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand) {}
virtual void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand) {}
virtual void Cmd_RenderBorderTileLine(const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand) {}
virtual void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand) {}
virtual void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand) {}
virtual void Cmd_RenderTextStream(const CCommandBuffer::SCommand_RenderTextStream *pCommand) {}
virtual void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand) {}
virtual void Cmd_RenderQuadContainerAsSprite(const CCommandBuffer::SCommand_RenderQuadContainerAsSprite *pCommand) {}
virtual void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand) {}
public:
CCommandProcessorFragment_OpenGL();
bool RunCommand(const CCommandBuffer::SCommand *pBaseCommand);
};
class CCommandProcessorFragment_OpenGL2 : public CCommandProcessorFragment_OpenGL {
struct SBufferContainer
{
SBufferContainer() {}
SBufferContainerInfo m_ContainerInfo;
};
std::vector<SBufferContainer> m_BufferContainers;
GL_SVertexTex3D m_aStreamVertices[1024 * 4];
struct SBufferObject
{
SBufferObject(GLuint BufferObjectID) : m_BufferObjectID(BufferObjectID)
{
m_pData = NULL;
m_DataSize = 0;
}
GLuint m_BufferObjectID;
void* m_pData;
size_t m_DataSize;
};
std::vector<SBufferObject> m_BufferObjectIndices;
void RenderBorderTileEmulation(SBufferContainer& BufferContainer, const CCommandBuffer::SState& State, const float* pColor, const char *pBuffOffset, unsigned int DrawNum, const float* pOffset, const float* pDir, int JumpIndex);
void RenderBorderTileLineEmulation(SBufferContainer& BufferContainer, const CCommandBuffer::SState& State, const float* pColor, const char *pBuffOffset, unsigned int IndexDrawNum, unsigned int DrawNum, const float* pOffset, const float* pDir);
void UseProgram(CGLSLTWProgram *pProgram);
protected:
void SetState(const CCommandBuffer::SState &State, CGLSLTWProgram *pProgram, bool Use2DArrayTextures = false);
void Cmd_Init(const SCommand_Init *pCommand) override;
void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) override;
void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) override;
void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) override;
void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) override;
void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) override;
void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) override;
void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) override;
void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) override;
void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) override;
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;
CGLSLTileProgram *m_pTileProgram;
CGLSLTileProgram *m_pTileProgramTextured;
CGLSLPrimitiveProgram *m_pPrimitive3DProgram;
CGLSLPrimitiveProgram *m_pPrimitive3DProgramTextured;
bool m_UseMultipleTextureUnits;
GLint m_MaxTextureUnits;
struct STextureBound{
int m_TextureSlot;
bool m_Is2DArray;
};
std::vector<STextureBound> m_TextureSlotBoundToUnit; //the texture index generated by loadtextureraw is stored in an index calculated by max texture units
bool IsAndUpdateTextureSlotBound(int IDX, int Slot, bool Is2DArray = false);
public:
CCommandProcessorFragment_OpenGL2() : CCommandProcessorFragment_OpenGL(), m_UseMultipleTextureUnits(false) {}
};
class CCommandProcessorFragment_OpenGL3 : public CCommandProcessorFragment_OpenGL2 {
};
#define MAX_STREAM_BUFFER_COUNT 30
// takes care of opengl 3.3+ related rendering
class CCommandProcessorFragment_OpenGL3_3 : public CCommandProcessorFragment_OpenGL3
class CGLSLProgram;
class CGLSLTWProgram;
class CGLSLPrimitiveProgram;
class CGLSLQuadProgram;
class CGLSLTileProgram;
class CGLSLBorderTileProgram;
class CGLSLBorderTileLineProgram;
class CGLSLTextProgram;
class CGLSLSpriteProgram;
class CGLSLSpriteMultipleProgram;
// takes care of opengl 3.3 related rendering
class CCommandProcessorFragment_OpenGL3_3
{
bool m_UseMultipleTextureUnits;
bool m_UsePreinitializedVertexBuffer;
struct CTexture
{
GLuint m_Tex;
GLuint m_Sampler;
int m_LastWrapMode;
int m_MemSize;
int m_MaxQuadsAtOnce;
static const int m_MaxQuadsPossible = 256;
int m_Width;
int m_Height;
int m_RescaleCount;
};
CTexture m_aTextures[CCommandBuffer::MAX_TEXTURES];
volatile int *m_pTextureMemoryUsage;
CGLSLPrimitiveProgram *m_pPrimitiveProgram;
CGLSLTileProgram *m_pBorderTileProgram;
CGLSLTileProgram *m_pBorderTileProgramTextured;
CGLSLTileProgram *m_pBorderTileLineProgram;
CGLSLTileProgram *m_pBorderTileLineProgramTextured;
CGLSLTileProgram *m_pTileProgram;
CGLSLTileProgram *m_pTileProgramTextured;
CGLSLBorderTileProgram *m_pBorderTileProgram;
CGLSLBorderTileProgram *m_pBorderTileProgramTextured;
CGLSLBorderTileLineProgram *m_pBorderTileLineProgram;
CGLSLBorderTileLineProgram *m_pBorderTileLineProgramTextured;
CGLSLQuadProgram *m_pQuadProgram;
CGLSLQuadProgram *m_pQuadProgramTextured;
CGLSLTextProgram *m_pTextProgram;
@ -309,7 +180,19 @@ class CCommandProcessorFragment_OpenGL3_3 : public CCommandProcessorFragment_Ope
GLuint m_QuadDrawIndexBufferID;
unsigned int m_CurrentIndicesInBuffer;
GLint m_MaxTextureUnits;
GLint m_MaxTexSize;
int m_LastBlendMode; //avoid all possible opengl state changes
bool m_LastClipEnable;
struct STextureBound{
int m_TextureSlot;
};
std::vector<STextureBound> m_TextureSlotBoundToUnit; //the texture index generated by loadtextureraw is stored in an index calculated by max texture units
bool IsAndUpdateTextureSlotBound(int IDX, int Slot);
void DestroyTexture(int Slot);
void DestroyBufferContainer(int Index, bool DeleteBOs = true);
@ -327,45 +210,68 @@ class CCommandProcessorFragment_OpenGL3_3 : public CCommandProcessorFragment_Ope
std::vector<GLuint> m_BufferObjectIndices;
CCommandBuffer::SColorf m_ClearColor;
protected:
static int TexFormatToNewOpenGLFormat(int TexFormat);
bool IsNewApi() override { return true; }
public:
enum
{
CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_OPENGL3_3,
CMD_SHUTDOWN,
};
struct SCommand_Init : public CCommandBuffer::SCommand
{
SCommand_Init() : SCommand(CMD_INIT) {}
class IStorage *m_pStorage;
volatile int *m_pTextureMemoryUsage;
};
struct SCommand_Shutdown : public CCommandBuffer::SCommand
{
SCommand_Shutdown() : SCommand(CMD_SHUTDOWN) {}
};
private:
static int TexFormatToOpenGLFormat(int TexFormat);
static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp);
static void *Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData);
void SetState(const CCommandBuffer::SState &State, CGLSLTWProgram *pProgram);
void UseProgram(CGLSLTWProgram *pProgram);
void UploadStreamBufferData(unsigned int PrimitiveType, const void* pVertices, unsigned int PrimitiveCount);
void RenderText(const CCommandBuffer::SState& State, int DrawNum, int TextTextureIndex, int TextOutlineTextureIndex, int TextureSize, const float* pTextColor, const float* pTextOutlineColor);
void Cmd_Init(const SCommand_Init *pCommand) override;
void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override;
void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand) override;
void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand) override;
void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand) override;
void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand) override;
void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand) override;
void Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand) override;
void Cmd_Init(const SCommand_Init *pCommand);
void Cmd_Shutdown(const SCommand_Shutdown *pCommand);
void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand);
void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand);
void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand);
void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand);
void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand);
void Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand);
void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) override;
void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) override;
void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand) override;
void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand) override;
void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand) override;
void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand);
void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand);
void Cmd_UpdateBufferObject(const CCommandBuffer::SCommand_UpdateBufferObject *pCommand);
void Cmd_CopyBufferObject(const CCommandBuffer::SCommand_CopyBufferObject *pCommand);
void Cmd_DeleteBufferObject(const CCommandBuffer::SCommand_DeleteBufferObject *pCommand);
void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand) override;
void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand) override;
void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand) override;
void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand) override;
void Cmd_CreateBufferContainer(const CCommandBuffer::SCommand_CreateBufferContainer *pCommand);
void Cmd_UpdateBufferContainer(const CCommandBuffer::SCommand_UpdateBufferContainer *pCommand);
void Cmd_DeleteBufferContainer(const CCommandBuffer::SCommand_DeleteBufferContainer *pCommand);
void Cmd_IndicesRequiredNumNotify(const CCommandBuffer::SCommand_IndicesRequiredNumNotify *pCommand);
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_RenderTextStream(const CCommandBuffer::SCommand_RenderTextStream *pCommand) override;
void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand) override;
void Cmd_RenderQuadContainerAsSprite(const CCommandBuffer::SCommand_RenderQuadContainerAsSprite *pCommand) override;
void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand) override;
void Cmd_RenderTileLayer(const CCommandBuffer::SCommand_RenderTileLayer *pCommand);
void Cmd_RenderBorderTile(const CCommandBuffer::SCommand_RenderBorderTile *pCommand);
void Cmd_RenderBorderTileLine(const CCommandBuffer::SCommand_RenderBorderTileLine *pCommand);
void Cmd_RenderQuadLayer(const CCommandBuffer::SCommand_RenderQuadLayer *pCommand);
void Cmd_RenderText(const CCommandBuffer::SCommand_RenderText *pCommand);
void Cmd_RenderTextStream(const CCommandBuffer::SCommand_RenderTextStream *pCommand);
void Cmd_RenderQuadContainer(const CCommandBuffer::SCommand_RenderQuadContainer *pCommand);
void Cmd_RenderQuadContainerAsSprite(const CCommandBuffer::SCommand_RenderQuadContainerAsSprite *pCommand);
void Cmd_RenderQuadContainerAsSpriteMultiple(const CCommandBuffer::SCommand_RenderQuadContainerAsSpriteMultiple *pCommand);
public:
CCommandProcessorFragment_OpenGL3_3() = default;
CCommandProcessorFragment_OpenGL3_3();
bool RunCommand(const CCommandBuffer::SCommand *pBaseCommand);
};
// takes care of sdl related commands
@ -387,17 +293,6 @@ public:
SCommand_Init() : SCommand(CMD_INIT) {}
SDL_Window *m_pWindow;
SDL_GLContext m_GLContext;
SBackendCapabilites* m_pCapabilities;
int* m_pInitError;
int m_RequestedMajor;
int m_RequestedMinor;
int m_RequestedPatch;
int m_GlewMajor;
int m_GlewMinor;
int m_GlewPatch;
};
struct SCommand_Update_Viewport : public CCommandBuffer::SCommand
@ -431,11 +326,14 @@ public:
// command processor impelementation, uses the fragments to combine into one processor
class CCommandProcessor_SDL_OpenGL : public CGraphicsBackend_Threaded::ICommandProcessor
{
CCommandProcessorFragment_OpenGL *m_pOpenGL;
CCommandProcessorFragment_OpenGL m_OpenGL;
CCommandProcessorFragment_OpenGL3_3 m_OpenGL3_3;
CCommandProcessorFragment_SDL m_SDL;
CCommandProcessorFragment_General m_General;
bool m_UseOpenGL3_3;
public:
CCommandProcessor_SDL_OpenGL(int OpenGLMajor, int OpenGLMinor, int OpenGLPatch);
void UseOpenGL3_3(bool Use) { m_UseOpenGL3_3 = Use; }
virtual void RunBuffer(CCommandBuffer *pBuffer);
};
@ -445,12 +343,10 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded
SDL_Window *m_pWindow;
SDL_GLContext m_GLContext;
ICommandProcessor *m_pProcessor;
std::atomic<int> m_TextureMemoryUsage;
volatile int m_TextureMemoryUsage;
int m_NumScreens;
SBackendCapabilites m_Capabilites;
bool m_UseNewOpenGL;
bool m_UseOpenGL3_3;
public:
virtual int Init(const char *pName, int *Screen, int *pWidth, int *pHeight, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight, int *pCurrentWidth, int *pCurrentHeight, class IStorage *pStorage);
virtual int Shutdown();
@ -470,12 +366,7 @@ public:
virtual void SetWindowGrab(bool Grab);
virtual void NotifyWindow();
virtual bool IsNewOpenGL() { return m_UseNewOpenGL; }
virtual bool HasTileBuffering() { return m_Capabilites.m_TileBuffering; }
virtual bool HasQuadBuffering() { return m_Capabilites.m_QuadBuffering; }
virtual bool HasTextBuffering() { return m_Capabilites.m_TextBuffering; }
virtual bool HasQuadContainerBuffering() { return m_Capabilites.m_QuadContainerBuffering; }
virtual bool Has2DTextureArrays() { return m_Capabilites.m_2DArrayTextures; }
virtual bool IsOpenGL3_3() { return m_UseOpenGL3_3; }
};
#endif // ENGINE_CLIENT_BACKEND_SDL_H

View file

@ -68,7 +68,7 @@ void CGraphics_Threaded::FlushVertices(bool KeepVertices)
if(m_Drawing == DRAWING_QUADS)
{
if(g_Config.m_GfxQuadAsTriangle && !m_IsNewOpenGL)
if(g_Config.m_GfxQuadAsTriangle && !m_UseOpenGL3_3)
{
Cmd.m_PrimType = CCommandBuffer::PRIMTYPE_TRIANGLES;
Cmd.m_PrimCount = NumVerts/3;
@ -437,16 +437,6 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(int Width, int Heig
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_COMPRESSED;
if(g_Config.m_GfxTextureQuality || Flags&TEXLOAD_NORESAMPLE)
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_QUALITY;
if((Flags&IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE) != 0)
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;
// copy texture data
int MemSize = Width*Height*Cmd.m_PixelSize;
@ -715,7 +705,7 @@ void CGraphics_Threaded::ChangeColorOfCurrentQuadVertices(float r, float g, floa
void CGraphics_Threaded::ChangeColorOfQuadVertices(int QuadOffset, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
if(g_Config.m_GfxQuadAsTriangle && !m_IsNewOpenGL)
if(g_Config.m_GfxQuadAsTriangle && !m_UseOpenGL3_3)
{
m_aVertices[QuadOffset * 6].m_Color.r = r;
m_aVertices[QuadOffset * 6].m_Color.g = g;
@ -816,7 +806,7 @@ void CGraphics_Threaded::QuadsDrawTL(const CQuadItem *pArray, int Num)
dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsDrawTL without begin");
if(g_Config.m_GfxQuadAsTriangle && !m_IsNewOpenGL)
if(g_Config.m_GfxQuadAsTriangle && !m_UseOpenGL3_3)
{
for(int i = 0; i < Num; ++i)
{
@ -904,7 +894,7 @@ void CGraphics_Threaded::QuadsDrawFreeform(const CFreeformItem *pArray, int Num)
{
dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsDrawFreeform without begin");
if(g_Config.m_GfxQuadAsTriangle && !m_IsNewOpenGL)
if(g_Config.m_GfxQuadAsTriangle && !m_UseOpenGL3_3)
{
for(int i = 0; i < Num; ++i)
{
@ -1010,6 +1000,15 @@ void CGraphics_Threaded::RenderTileLayer(int BufferContainerIndex, float *pColor
Cmd.m_IndicesDrawNum = NumIndicesOffet;
Cmd.m_BufferContainerIndex = BufferContainerIndex;
mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color));
float ScreenZoomRatio = ScreenWidth() / (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x);
//the number of pixels we would skip in the fragment shader -- basically the LOD
float LODFactor = (64.f / (32.f * ScreenZoomRatio));
//log2 gives us the amount of halving the texture for mipmapping
int LOD = (int)log2f(LODFactor);
//5 because log2(1024/(2^5)) is 5 -- 2^5 = 32 which would mean 2 pixels per tile index
if(LOD > 5) LOD = 5;
if(LOD < 0) LOD = 0;
Cmd.m_LOD = LOD;
void *Data = m_pCommandBuffer->AllocData((sizeof(char*) + sizeof(unsigned int))*NumIndicesOffet);
if(Data == 0x0)
@ -1066,6 +1065,16 @@ void CGraphics_Threaded::RenderBorderTiles(int BufferContainerIndex, float *pCol
Cmd.m_DrawNum = DrawNum;
Cmd.m_BufferContainerIndex = BufferContainerIndex;
mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color));
float ScreenZoomRatio = ScreenWidth() / (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x);
//the number of pixels we would skip in the fragment shader -- basically the LOD
float LODFactor = (64.f / (32.f * ScreenZoomRatio));
//log2 gives us the amount of halving the texture for mipmapping
int LOD = (int)log2f(LODFactor);
if(LOD > 5)
LOD = 5;
if(LOD < 0)
LOD = 0;
Cmd.m_LOD = LOD;
Cmd.m_pIndicesOffset = pIndexBufferOffset;
Cmd.m_JumpIndex = JumpIndex;
@ -1100,6 +1109,16 @@ void CGraphics_Threaded::RenderBorderTileLines(int BufferContainerIndex, float *
Cmd.m_DrawNum = RedrawNum;
Cmd.m_BufferContainerIndex = BufferContainerIndex;
mem_copy(&Cmd.m_Color, pColor, sizeof(Cmd.m_Color));
float ScreenZoomRatio = ScreenWidth() / (m_State.m_ScreenBR.x - m_State.m_ScreenTL.x);
//the number of pixels we would skip in the fragment shader -- basically the LOD
float LODFactor = (64.f / (32.f * ScreenZoomRatio));
//log2 gives us the amount of halving the texture for mipmapping
int LOD = (int)log2f(LODFactor);
if(LOD > 5)
LOD = 5;
if(LOD < 0)
LOD = 0;
Cmd.m_LOD = LOD;
Cmd.m_pIndicesOffset = pIndexBufferOffset;
@ -1209,7 +1228,7 @@ int CGraphics_Threaded::CreateQuadContainer()
void CGraphics_Threaded::QuadContainerUpload(int ContainerIndex)
{
if(IsQuadContainerBufferingEnabled())
if(m_UseOpenGL3_3)
{
SQuadContainer& Container = m_QuadContainers[ContainerIndex];
if(Container.m_Quads.size() > 0)
@ -1345,7 +1364,7 @@ void CGraphics_Threaded::QuadContainerAddQuads(int ContainerIndex, CFreeformItem
void CGraphics_Threaded::QuadContainerReset(int ContainerIndex)
{
SQuadContainer& Container = m_QuadContainers[ContainerIndex];
if(IsQuadContainerBufferingEnabled())
if(m_UseOpenGL3_3)
{
if(Container.m_QuadBufferContainerIndex != -1)
DeleteBufferContainer(Container.m_QuadBufferContainerIndex, true);
@ -1378,7 +1397,7 @@ void CGraphics_Threaded::RenderQuadContainer(int ContainerIndex, int QuadOffset,
if((int)Container.m_Quads.size() < QuadOffset + QuadDrawNum || QuadDrawNum == 0)
return;
if(IsQuadContainerBufferingEnabled())
if(m_UseOpenGL3_3)
{
if(Container.m_QuadBufferContainerIndex == -1)
return;
@ -1436,7 +1455,7 @@ void CGraphics_Threaded::RenderQuadContainerAsSprite(int ContainerIndex, int Qua
if((int)Container.m_Quads.size() < QuadOffset + 1)
return;
if(IsQuadContainerBufferingEnabled())
if(m_UseOpenGL3_3)
{
if(Container.m_QuadBufferContainerIndex == -1)
return;
@ -1562,7 +1581,7 @@ void CGraphics_Threaded::RenderQuadContainerAsSpriteMultiple(int ContainerIndex,
if(DrawCount == 0)
return;
if(IsQuadContainerBufferingEnabled())
if(m_UseOpenGL3_3)
{
if(Container.m_QuadBufferContainerIndex == -1)
return;
@ -2038,19 +2057,13 @@ int CGraphics_Threaded::IssueInit()
if(g_Config.m_GfxResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
int r = m_pBackend->Init("DDNet Client", &g_Config.m_GfxScreen, &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &m_DesktopScreenWidth, &m_DesktopScreenHeight, &m_ScreenWidth, &m_ScreenHeight, m_pStorage);
m_IsNewOpenGL = m_pBackend->IsNewOpenGL();
m_OpenGLTileBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasTileBuffering();
m_OpenGLQuadBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasQuadBuffering();
m_OpenGLQuadContainerBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasQuadContainerBuffering();
m_OpenGLTextBufferingEnabled = m_IsNewOpenGL || (m_OpenGLQuadContainerBufferingEnabled && m_pBackend->HasTextBuffering());
m_OpenGLHasTextureArrays = m_IsNewOpenGL || m_pBackend->Has2DTextureArrays();
m_UseOpenGL3_3 = m_pBackend->IsOpenGL3_3();
return r;
}
int CGraphics_Threaded::InitWindow()
{
int ErrorCode = IssueInit();
if(ErrorCode == 0)
if(IssueInit() == 0)
return 0;
// try disabling fsaa
@ -2063,85 +2076,18 @@ int CGraphics_Threaded::InitWindow()
else
dbg_msg("gfx", "disabling FSAA and trying again");
ErrorCode = IssueInit();
if(ErrorCode == 0)
if(IssueInit() == 0)
return 0;
}
size_t OpenGLInitTryCount = 0;
while(ErrorCode == EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_OPENGL_CONTEXT_FAILED || ErrorCode == EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_OPENGL_VERSION_FAILED)
// try using old opengl context
if(g_Config.m_GfxOpenGL3)
{
if(ErrorCode == EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_OPENGL_CONTEXT_FAILED)
{
// try next smaller major/minor or patch version
if(g_Config.m_GfxOpenGLMajor >= 4)
{
g_Config.m_GfxOpenGLMajor = 3;
g_Config.m_GfxOpenGLMinor = 3;
g_Config.m_GfxOpenGLPatch = 0;
}
else if(g_Config.m_GfxOpenGLMajor == 3 && g_Config.m_GfxOpenGLMinor >= 1)
{
g_Config.m_GfxOpenGLMajor = 3;
g_Config.m_GfxOpenGLMinor = 0;
g_Config.m_GfxOpenGLPatch = 0;
}
else if(g_Config.m_GfxOpenGLMajor == 3 && g_Config.m_GfxOpenGLMinor == 0)
{
g_Config.m_GfxOpenGLMajor = 2;
g_Config.m_GfxOpenGLMinor = 1;
g_Config.m_GfxOpenGLPatch = 0;
}
else if(g_Config.m_GfxOpenGLMajor == 2 && g_Config.m_GfxOpenGLMinor >= 1)
{
g_Config.m_GfxOpenGLMajor = 2;
g_Config.m_GfxOpenGLMinor = 0;
g_Config.m_GfxOpenGLPatch = 0;
}
else if(g_Config.m_GfxOpenGLMajor == 2 && g_Config.m_GfxOpenGLMinor == 0)
{
g_Config.m_GfxOpenGLMajor = 1;
g_Config.m_GfxOpenGLMinor = 5;
g_Config.m_GfxOpenGLPatch = 0;
}
else if(g_Config.m_GfxOpenGLMajor == 1 && g_Config.m_GfxOpenGLMinor == 5)
{
g_Config.m_GfxOpenGLMajor = 1;
g_Config.m_GfxOpenGLMinor = 4;
g_Config.m_GfxOpenGLPatch = 0;
}
else if(g_Config.m_GfxOpenGLMajor == 1 && g_Config.m_GfxOpenGLMinor == 4)
{
g_Config.m_GfxOpenGLMajor = 1;
g_Config.m_GfxOpenGLMinor = 3;
g_Config.m_GfxOpenGLPatch = 0;
}
else if(g_Config.m_GfxOpenGLMajor == 1 && g_Config.m_GfxOpenGLMinor == 3)
{
g_Config.m_GfxOpenGLMajor = 1;
g_Config.m_GfxOpenGLMinor = 2;
g_Config.m_GfxOpenGLPatch = 1;
}
else if(g_Config.m_GfxOpenGLMajor == 1 && g_Config.m_GfxOpenGLMinor == 2)
{
g_Config.m_GfxOpenGLMajor = 1;
g_Config.m_GfxOpenGLMinor = 1;
g_Config.m_GfxOpenGLPatch = 0;
}
}
// new opengl version was set by backend, try again
ErrorCode = IssueInit();
if(ErrorCode == 0)
g_Config.m_GfxOpenGL3 = 0;
if(IssueInit() == 0)
{
return 0;
}
if(++OpenGLInitTryCount >= 9)
{
// try something else
break;
}
}
// try lowering the resolution

View file

@ -66,6 +66,7 @@ public:
CMDGROUP_CORE = 0, // commands that everyone has to implement
CMDGROUP_PLATFORM_OPENGL = 10000, // commands specific to a platform
CMDGROUP_PLATFORM_SDL = 20000,
CMDGROUP_PLATFORM_OPENGL3_3 = 30000,
//
CMD_NOP = CMDGROUP_CORE,
@ -85,7 +86,7 @@ public:
CMD_CLEAR,
CMD_RENDER,
//opengl 2.0+ commands (some are just emulated and only exist in opengl 3.3+)
//opengl 3.3 commands
CMD_CREATE_BUFFER_OBJECT, // create vbo
CMD_RECREATE_BUFFER_OBJECT, // recreate vbo
CMD_UPDATE_BUFFER_OBJECT, // update vbo
@ -129,11 +130,6 @@ public:
TEXFLAG_NOMIPMAPS = 1,
TEXFLAG_COMPRESSED = 2,
TEXFLAG_QUALITY = 4,
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),
};
enum
@ -317,6 +313,7 @@ public:
int m_IndicesDrawNum;
int m_BufferContainerIndex;
int m_LOD;
};
struct SCommand_RenderBorderTile : public SCommand
@ -327,6 +324,7 @@ public:
char *m_pIndicesOffset; // you should use the command buffer data to allocate vertices for this command
unsigned int m_DrawNum;
int m_BufferContainerIndex;
int m_LOD;
float m_Offset[2];
float m_Dir[2];
@ -342,6 +340,7 @@ public:
unsigned int m_IndexDrawNum;
unsigned int m_DrawNum;
int m_BufferContainerIndex;
int m_LOD;
float m_Offset[2];
float m_Dir[2];
@ -555,19 +554,6 @@ public:
}
};
enum EGraphicsBackendErrorCodes
{
GRAPHICS_BACKEND_ERROR_CODE_UNKNOWN = -1,
GRAPHICS_BACKEND_ERROR_CODE_NONE = 0,
GRAPHICS_BACKEND_ERROR_CODE_OPENGL_CONTEXT_FAILED,
GRAPHICS_BACKEND_ERROR_CODE_OPENGL_VERSION_FAILED,
GRAPHICS_BACKEND_ERROR_CODE_SDL_INIT_FAILED,
GRAPHICS_BACKEND_ERROR_CODE_SDL_SCREEN_REQUEST_FAILED,
GRAPHICS_BACKEND_ERROR_CODE_SDL_SCREEN_INFO_REQUEST_FAILED,
GRAPHICS_BACKEND_ERROR_CODE_SDL_SCREEN_RESOLUTION_REQUEST_FAILED,
GRAPHICS_BACKEND_ERROR_CODE_SDL_WINDOW_CREATE_FAILED,
};
// interface for the graphics backend
// all these functions are called on the main thread
class IGraphicsBackend
@ -606,12 +592,7 @@ public:
virtual bool IsIdle() const = 0;
virtual void WaitForIdle() = 0;
virtual bool IsNewOpenGL() { return false; }
virtual bool HasTileBuffering() { return false; }
virtual bool HasQuadBuffering() { return false; }
virtual bool HasTextBuffering() { return false; }
virtual bool HasQuadContainerBuffering() { return false; }
virtual bool Has2DTextureArrays() { return false; }
virtual bool IsOpenGL3_3() { return false; }
};
class CGraphics_Threaded : public IEngineGraphics
@ -629,12 +610,7 @@ class CGraphics_Threaded : public IEngineGraphics
CCommandBuffer::SState m_State;
IGraphicsBackend *m_pBackend;
bool m_OpenGLTileBufferingEnabled;
bool m_OpenGLQuadBufferingEnabled;
bool m_OpenGLTextBufferingEnabled;
bool m_OpenGLQuadContainerBufferingEnabled;
bool m_OpenGLHasTextureArrays;
bool m_IsNewOpenGL;
bool m_UseOpenGL3_3;
CCommandBuffer *m_apCommandBuffers[NUM_CMDBUFFERS];
CCommandBuffer *m_pCommandBuffer;
@ -851,11 +827,7 @@ public:
virtual bool IsIdle();
virtual void WaitForIdle();
virtual bool IsTileBufferingEnabled() { return m_OpenGLTileBufferingEnabled; }
virtual bool IsQuadBufferingEnabled() { return m_OpenGLQuadBufferingEnabled; }
virtual bool IsTextBufferingEnabled() { return m_OpenGLTextBufferingEnabled; }
virtual bool IsQuadContainerBufferingEnabled() { return m_OpenGLQuadContainerBufferingEnabled; }
virtual bool HasTextureArrays() { return m_OpenGLHasTextureArrays; }
virtual bool IsBufferingEnabled() { return m_UseOpenGL3_3; }
};
extern IGraphicsBackend *CreateGraphicsBackend();

View file

@ -5,7 +5,7 @@
#include <stdio.h>
#include <string>
bool CGLSL::LoadShader(CGLSLCompiler* pCompiler, IStorage *pStorage, const char *pFile, int Type)
bool CGLSL::LoadShader(IStorage *pStorage, const char *pFile, int Type)
{
if (m_IsLoaded)
return true;
@ -14,49 +14,13 @@ bool CGLSL::LoadShader(CGLSLCompiler* pCompiler, IStorage *pStorage, const char
std::vector<std::string> Lines;
if (f)
{
bool IsNewOpenGL = pCompiler->m_OpenGLVersionMajor >= 4 || (pCompiler->m_OpenGLVersionMajor == 3 && pCompiler->m_OpenGLVersionMinor == 3);
//add compiler specific values
if(IsNewOpenGL)
Lines.push_back(std::string("#version ") + std::string(std::to_string(pCompiler->m_OpenGLVersionMajor)) + std::string(std::to_string(pCompiler->m_OpenGLVersionMinor)) + std::string(std::to_string(pCompiler->m_OpenGLVersionPatch)) + std::string(" core\r\n"));
else
{
if(pCompiler->m_OpenGLVersionMajor == 3)
{
if(pCompiler->m_OpenGLVersionMinor == 0)
Lines.push_back(std::string("#version 130 \r\n"));
if(pCompiler->m_OpenGLVersionMinor == 1)
Lines.push_back(std::string("#version 140 \r\n"));
if(pCompiler->m_OpenGLVersionMinor == 2)
Lines.push_back(std::string("#version 150 \r\n"));
}
else if(pCompiler->m_OpenGLVersionMajor == 2)
{
if(pCompiler->m_OpenGLVersionMinor == 0)
Lines.push_back(std::string("#version 110 \r\n"));
if(pCompiler->m_OpenGLVersionMinor == 1)
Lines.push_back(std::string("#version 120 \r\n"));
}
}
for(CGLSLCompiler::SGLSLCompilerDefine& Define : pCompiler->m_Defines)
{
Lines.push_back(std::string("#define ") + Define.m_DefineName + std::string(" ") + Define.m_DefineValue + std::string("\r\n"));
}
if(Type == GL_FRAGMENT_SHADER && !IsNewOpenGL && pCompiler->m_OpenGLVersionMajor <= 3 && pCompiler->m_HasTextureArray)
{
Lines.push_back(std::string("#extension GL_EXT_texture_array : enable\r\n"));
}
CLineReader LineReader;
LineReader.Init(f);
char* ReadLine = NULL;
while ((ReadLine = LineReader.Get()))
{
std::string Line;
pCompiler->ParseLine(Line, ReadLine, Type);
Line.append("\r\n");
Lines.push_back(Line);
Lines.push_back(ReadLine);
Lines.back().append("\r\n");
}
io_close(f);
@ -86,7 +50,7 @@ bool CGLSL::LoadShader(CGLSLCompiler* pCompiler, IStorage *pStorage, const char
glGetShaderInfoLog(shader, maxLength, &maxLength, buff);
dbg_msg("GLSL", "%s: %s", pFile, buff);
dbg_msg("GLSL", "%s", buff);
glDeleteShader(shader);
return false;
}
@ -127,152 +91,3 @@ CGLSL::~CGLSL()
{
DeleteShader();
}
CGLSLCompiler::CGLSLCompiler(int OpenGLVersionMajor, int OpenGLVersionMinor, int OpenGLVersionPatch)
{
m_OpenGLVersionMajor = OpenGLVersionMajor;
m_OpenGLVersionMinor = OpenGLVersionMinor;
m_OpenGLVersionPatch = OpenGLVersionPatch;
m_HasTextureArray = false;
m_TextureReplaceType = 0;
}
void CGLSLCompiler::AddDefine(const std::string& DefineName, const std::string& DefineValue)
{
m_Defines.emplace_back(SGLSLCompilerDefine(DefineName, DefineValue));
}
void CGLSLCompiler::AddDefine(const char* pDefineName, const char* pDefineValue)
{
AddDefine(std::string(pDefineName), std::string(pDefineValue));
}
void CGLSLCompiler::ClearDefines()
{
m_Defines.clear();
}
void CGLSLCompiler::ParseLine(std::string& Line, const char* pReadLine, int Type)
{
bool IsNewOpenGL = m_OpenGLVersionMajor >= 4 || (m_OpenGLVersionMajor == 3 && m_OpenGLVersionMinor == 3);
if(!IsNewOpenGL)
{
const char* pBuff = pReadLine;
char aTmpStr[1024];
size_t TmpStrSize = 0;
while(*pBuff)
{
while(*pBuff && str_isspace(*pBuff))
{
Line.append(1, *pBuff);
++pBuff;
}
while(*pBuff && !str_isspace(*pBuff) && *pBuff != '(' && *pBuff != '.')
{
aTmpStr[TmpStrSize++] = *pBuff;
++pBuff;
}
if(TmpStrSize > 0)
{
aTmpStr[TmpStrSize] = 0;
TmpStrSize = 0;
if(str_comp(aTmpStr, "layout") == 0)
{
//search for ' in'
while(*pBuff && (*pBuff != ' ' || (*(pBuff + 1) && *(pBuff + 1) != 'i') || *(pBuff + 2) != 'n'))
{
++pBuff;
}
if(*pBuff && *pBuff == ' ' && *(pBuff + 1) && *(pBuff + 1) == 'i' && *(pBuff + 2) == 'n')
{
pBuff += 3;
Line.append("attribute");
Line.append(pBuff);
return;
}
else
{
dbg_msg("Shader compiler", "Fix shader for older OpenGL versions.");
}
}
else if(str_comp(aTmpStr, "noperspective") == 0 || str_comp(aTmpStr, "smooth") == 0 || str_comp(aTmpStr, "flat") == 0)
{
//search for 'in' or 'out'
while(*pBuff && ((*pBuff != 'i' || *(pBuff + 1) != 'n') && (*pBuff != 'o' || (*(pBuff + 1) && *(pBuff + 1) != 'u') || *(pBuff + 2) != 't')))
{
++pBuff;
}
bool Found = false;
if(*pBuff)
{
if(*pBuff == 'i' && *(pBuff + 1) == 'n')
{
pBuff += 2;
Found = true;
}
else if(*pBuff == 'o' && *(pBuff + 1) && *(pBuff + 1) == 'u' && *(pBuff + 2) == 't')
{
pBuff += 3;
Found = true;
}
}
if(!Found)
{
dbg_msg("Shader compiler", "Fix shader for older OpenGL versions.");
}
Line.append("varying");
Line.append(pBuff);
return;
}
else if(str_comp(aTmpStr, "out") == 0 || str_comp(aTmpStr, "in") == 0)
{
if(Type == GL_FRAGMENT_SHADER && str_comp(aTmpStr, "out") == 0)
return;
Line.append("varying");
Line.append(pBuff);
return;
}
else if(str_comp(aTmpStr, "FragClr") == 0)
{
Line.append("gl_FragColor");
Line.append(pBuff);
return;
}
else if(str_comp(aTmpStr, "texture") == 0)
{
if(m_TextureReplaceType == GLSL_COMPILER_TEXTURE_REPLACE_TYPE_2D)
Line.append("texture2D");
else if(m_TextureReplaceType == GLSL_COMPILER_TEXTURE_REPLACE_TYPE_3D)
Line.append("texture3D");
else if(m_TextureReplaceType == GLSL_COMPILER_TEXTURE_REPLACE_TYPE_2D_ARRAY)
Line.append("texture2DArray");
std::string RestLine;
ParseLine(RestLine, pBuff, Type);
Line.append(RestLine);
return;
}
else
{
Line.append(aTmpStr);
}
}
if(*pBuff)
{
Line.append(1, *pBuff);
++pBuff;
}
}
}
else
{
Line = pReadLine;
}
}

View file

@ -2,14 +2,10 @@
#define ENGINE_CLIENT_OPENGL_SL_H
#include <GL/glew.h>
#include <vector>
#include <string>
class CGLSLCompiler;
class CGLSL {
public:
bool LoadShader(CGLSLCompiler* pCompiler, class IStorage *pStorage, const char *pFile, int Type);
bool LoadShader(class IStorage *pStorage, const char *pFile, int Type);
void DeleteShader();
bool IsLoaded();
@ -23,47 +19,4 @@ private:
bool m_IsLoaded;
};
class CGLSLCompiler
{
private:
friend class CGLSL;
struct SGLSLCompilerDefine
{
SGLSLCompilerDefine(const std::string& DefineName, const std::string& DefineValue)
{
m_DefineName = DefineName;
m_DefineValue = DefineValue;
}
std::string m_DefineName;
std::string m_DefineValue;
};
std::vector<SGLSLCompilerDefine> m_Defines;
int m_OpenGLVersionMajor;
int m_OpenGLVersionMinor;
int m_OpenGLVersionPatch;
bool m_HasTextureArray;
int m_TextureReplaceType; // @see EGLSLCompilerTextureReplaceType
public:
CGLSLCompiler(int OpenGLVersionMajor, int OpenGLVersionMinor, int OpenGLVersionPatch);
void SetHasTextureArray(bool TextureArray) { m_HasTextureArray = TextureArray; }
void SetTextureReplaceType(int TextureReplaceType) { m_TextureReplaceType = TextureReplaceType; }
void AddDefine(const std::string& DefineName, const std::string& DefineValue);
void AddDefine(const char* pDefineName, const char* pDefineValue);
void ClearDefines();
void ParseLine(std::string& Line, const char* pReadLine, int Type);
enum EGLSLCompilerTextureReplaceType
{
GLSL_COMPILER_TEXTURE_REPLACE_TYPE_2D = 0,
GLSL_COMPILER_TEXTURE_REPLACE_TYPE_3D,
GLSL_COMPILER_TEXTURE_REPLACE_TYPE_2D_ARRAY,
};
};
#endif // ENGINE_CLIENT_OPENGL_SL_H

View file

@ -77,19 +77,14 @@ void CGLSLProgram::DetachAllShaders()
}
}
void CGLSLProgram::SetUniformVec4(int Loc, int Count, const float *pValues)
void CGLSLProgram::SetUniformVec4(int Loc, int Count, const float* Value)
{
glUniform4fv(Loc, Count, pValues);
glUniform4fv(Loc, Count, Value);
}
void CGLSLProgram::SetUniformVec2(int Loc, int Count, const float *pValues)
void CGLSLProgram::SetUniformVec2(int Loc, int Count, const float* Value)
{
glUniform2fv(Loc, Count, pValues);
}
void CGLSLProgram::SetUniform(int Loc, int Count, const float *pValues)
{
glUniform1fv(Loc, Count, pValues);
glUniform2fv(Loc, Count, Value);
}
void CGLSLProgram::SetUniform(int Loc, const int Value)

View file

@ -21,13 +21,12 @@ public:
void DetachAllShaders();
//Support various types
void SetUniformVec2(int Loc, int Count, const float *pValue);
void SetUniformVec4(int Loc, int Count, const float *pValue);
void SetUniformVec2(int Loc, int Count, const float* Value);
void SetUniformVec4(int Loc, int Count, const float* Value);
void SetUniform(int Loc, const int Value);
void SetUniform(int Loc, const unsigned int Value);
void SetUniform(int Loc, const bool Value);
void SetUniform(int Loc, const float Value);
void SetUniform(int Loc, int Count, const float *pValues);
//for performance reason we do not use SetUniform with using strings... save the Locations of the variables instead
int GetUniformLoc(const char* Name);
@ -42,7 +41,7 @@ protected:
class CGLSLTWProgram : public CGLSLProgram {
public:
CGLSLTWProgram() : m_LocPos(-1), m_LocIsTextured(-1), m_LocTextureSampler(-1), m_LastTextureSampler(-1), m_LastIsTextured(-1)
CGLSLTWProgram() : m_LastTextureSampler(-1), m_LastIsTextured(-1)
{
m_LastScreen[0] = m_LastScreen[1] = m_LastScreen[2] = m_LastScreen[3] = -1.f;
}
@ -119,20 +118,33 @@ public:
class CGLSLQuadProgram : public CGLSLTWProgram {
public:
int m_LocColors;
int m_LocOffsets;
int m_LocRotations;
int m_LocColor;
int m_LocOffset;
int m_LocRotation;
};
class CGLSLTileProgram : public CGLSLTWProgram {
public:
CGLSLTileProgram() : m_LocColor(-1), m_LocOffset(-1), m_LocDir(-1), m_LocNum(-1), m_LocJumpIndex(-1) {}
int m_LocColor;
int m_LocLOD;
int m_LocTexelOffset;
int m_LastLOD;
};
class CGLSLBorderTileProgram : public CGLSLTileProgram {
public:
int m_LocOffset;
int m_LocDir;
int m_LocNum;
int m_LocJumpIndex;
};
class CGLSLBorderTileLineProgram : public CGLSLTileProgram {
public:
int m_LocOffset;
int m_LocDir;
int m_LocNum;
};
#endif // ENGINE_CLIENT_OPENGL_SL_PROGRAM_H

View file

@ -903,7 +903,7 @@ public:
// make sure there are no vertices
Graphics()->FlushVertices();
if(Graphics()->IsTextBufferingEnabled())
if(Graphics()->IsBufferingEnabled())
{
Graphics()->TextureClear();
Graphics()->TextQuadsBegin();
@ -1009,7 +1009,7 @@ public:
if(pCursor->m_Flags&TEXTFLAG_RENDER && m_Color.a != 0.f)
{
if(Graphics()->IsTextBufferingEnabled())
if(Graphics()->IsBufferingEnabled())
Graphics()->QuadsSetSubset(pChr->m_aUVs[0], pChr->m_aUVs[3], pChr->m_aUVs[2], pChr->m_aUVs[1]);
else
Graphics()->QuadsSetSubset(pChr->m_aUVs[0] * UVScale, pChr->m_aUVs[3] * UVScale, pChr->m_aUVs[2] * UVScale, pChr->m_aUVs[1] * UVScale);
@ -1054,7 +1054,7 @@ public:
if(pCursor->m_Flags&TEXTFLAG_RENDER)
{
if(Graphics()->IsTextBufferingEnabled())
if(Graphics()->IsBufferingEnabled())
{
float OutlineColor[4] = { m_OutlineColor.r, m_OutlineColor.g, m_OutlineColor.b, m_OutlineColor.a*m_Color.a };
Graphics()->TextQuadsEnd(pFont->m_CurTextureDimensions[0], pFont->m_aTextures[0], pFont->m_aTextures[1], OutlineColor);
@ -1137,7 +1137,7 @@ public:
else
{
TextContainer.m_StringInfo.m_QuadNum = TextContainer.m_StringInfo.m_CharacterQuads.size();
if(Graphics()->IsTextBufferingEnabled())
if(Graphics()->IsBufferingEnabled())
{
size_t DataSize = TextContainer.m_StringInfo.m_CharacterQuads.size() * sizeof(STextCharQuad);
void *pUploadData = &TextContainer.m_StringInfo.m_CharacterQuads[0];
@ -1392,7 +1392,7 @@ public:
{
TextContainer.m_StringInfo.m_QuadNum = TextContainer.m_StringInfo.m_CharacterQuads.size();
// setup the buffers
if(Graphics()->IsTextBufferingEnabled())
if(Graphics()->IsBufferingEnabled())
{
size_t DataSize = TextContainer.m_StringInfo.m_CharacterQuads.size() * sizeof(STextCharQuad);
void *pUploadData = &TextContainer.m_StringInfo.m_CharacterQuads[0];
@ -1647,7 +1647,7 @@ public:
virtual void DeleteTextContainer(int TextContainerIndex)
{
STextContainer& TextContainer = GetTextContainer(TextContainerIndex);
if(Graphics()->IsTextBufferingEnabled())
if(Graphics()->IsBufferingEnabled())
{
if(TextContainer.m_StringInfo.m_QuadBufferContainerIndex != -1)
Graphics()->DeleteBufferContainer(TextContainer.m_StringInfo.m_QuadBufferContainerIndex, true);
@ -1675,7 +1675,7 @@ public:
s_CursorRenderTime = time_get_microseconds();
}
if(Graphics()->IsTextBufferingEnabled())
if(Graphics()->IsBufferingEnabled())
{
Graphics()->TextureClear();
// render buffered text
@ -1755,7 +1755,7 @@ public:
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
virtual void UploadEntityLayerText(void* pTexBuff, int ImageColorChannelCount, int TexWidth, int TexHeight, const char *pText, int Length, float x, float y, int FontSize)
virtual void UploadEntityLayerText(IGraphics::CTextureHandle Texture, const char *pText, int Length, float x, float y, int FontSize)
{
if (FontSize < 1)
return;
@ -1794,46 +1794,27 @@ public:
mem_zero(ms_aGlyphData, SlotSize);
if(pBitmap->pixel_mode == FT_PIXEL_MODE_GRAY) // ignore_convention
{
for(py = 0; py < (unsigned)SlotH; py++) // ignore_convention
for(px = 0; px < (unsigned)SlotW; px++)
{
ms_aGlyphData[(py)*SlotW + px] = pBitmap->buffer[py*pBitmap->width + px]; // ignore_convention
}
}
uint8_t* pImageBuff = (uint8_t*)pTexBuff;
for(int OffY = 0; OffY < SlotH; ++OffY)
{
for(int OffX = 0; OffX < SlotW; ++OffX)
{
size_t ImageOffset = (y + OffY) * (TexWidth * ImageColorChannelCount) + ((x + OffX) + WidthLastChars) * ImageColorChannelCount;
size_t GlyphOffset = (OffY) * SlotW + OffX;
for(size_t i = 0; i < (size_t)ImageColorChannelCount; ++i)
{
if(i != (size_t)ImageColorChannelCount - 1)
for(py = 0; py < (unsigned)SlotH; py++) // ignore_convention
for(px = 0; px < (unsigned)SlotW; px++)
{
*(pImageBuff + ImageOffset + i) = 255;
ms_aGlyphData[(py)*SlotW + px] = pBitmap->buffer[py*pBitmap->width + px]; // ignore_convention
}
else
{
*(pImageBuff + ImageOffset + i) = *(ms_aGlyphData + GlyphOffset);
}
}
}
}
Graphics()->LoadTextureRawSub(Texture, x + WidthLastChars, y, SlotW, SlotH, CImageInfo::FORMAT_ALPHA, ms_aGlyphData);
WidthLastChars += (SlotW + 1);
}
pCurrent = pTmp;
}
}
virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize, int MaxWidth)
virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize = -1)
{
int WidthOfText = CalculateTextWidth(pText, TextLength, 0, 100);
int FontSize = 100.f / ((float)WidthOfText / (float)MaxWidth);
int FontSize = 100.f / ((float)WidthOfText / (float)MaxSize);
if (MaxSize > 0 && FontSize > MaxSize)
FontSize = MaxSize;

View file

@ -40,22 +40,6 @@ struct SQuadRenderInfo
float m_Rotation;
};
struct SGraphicTile
{
vec2 m_TopLeft;
vec2 m_TopRight;
vec2 m_BottomRight;
vec2 m_BottomLeft;
};
struct SGraphicTileTexureCoords
{
vec3 m_TexCoordTopLeft;
vec3 m_TexCoordTopRight;
vec3 m_TexCoordBottomRight;
vec3 m_TexCoordBottomLeft;
};
class CImageInfo
{
public:
@ -96,7 +80,6 @@ public:
struct GL_SPoint { float x, y; };
struct GL_STexCoord { float u, v; };
struct GL_STexCoord3D { float u, v, w; };
struct GL_SColorf { float r, g, b, a; };
//use normalized color values
@ -109,13 +92,6 @@ struct GL_SVertex
GL_SColor m_Color;
};
struct GL_SVertexTex3D
{
GL_SPoint m_Pos;
GL_SColorf m_Color;
GL_STexCoord3D m_Tex;
};
typedef void(*WINDOW_RESIZE_FUNC)(void *pUser);
class IGraphics : public IInterface
@ -135,11 +111,6 @@ public:
TEXLOAD_NORESAMPLE = 1<<0,
TEXLOAD_NOMIPMAPS = 1<<1,
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),
};
@ -215,11 +186,7 @@ public:
virtual void UpdateBufferContainer(int ContainerIndex, struct SBufferContainerInfo *pContainerInfo) = 0;
virtual void IndicesNumRequiredNotify(unsigned int RequiredIndicesCount) = 0;
virtual bool IsTileBufferingEnabled() = 0;
virtual bool IsQuadBufferingEnabled() = 0;
virtual bool IsTextBufferingEnabled() = 0;
virtual bool IsQuadContainerBufferingEnabled() = 0;
virtual bool HasTextureArrays() = 0;
virtual bool IsBufferingEnabled() = 0;
struct CLineItem
{

View file

@ -374,9 +374,7 @@ MACRO_CONFIG_INT(ClDemoShowSpeed, cl_demo_show_speed, 0, 0, 1, CFGFLAG_SAVE|CFGF
MACRO_CONFIG_INT(ClDemoKeyboardShortcuts, cl_demo_keyboard_shortcuts, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Enable keyboard shortcuts in demo player")
//opengl
MACRO_CONFIG_INT(GfxOpenGLMajor, gfx_opengl_major, 3, 1, 10, CFGFLAG_SAVE|CFGFLAG_CLIENT, "OpenGL major version")
MACRO_CONFIG_INT(GfxOpenGLMinor, gfx_opengl_minor, 0, 0, 10, CFGFLAG_SAVE|CFGFLAG_CLIENT, "OpenGL minor version")
MACRO_CONFIG_INT(GfxOpenGLPatch, gfx_opengl_patch, 0, 0, 10, CFGFLAG_SAVE|CFGFLAG_CLIENT, "OpenGL patch version")
MACRO_CONFIG_INT(GfxOpenGL3, gfx_opengl3, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use new OpenGL3 with shaders")
#if !defined(CONF_PLATFORM_MACOSX)
MACRO_CONFIG_INT(GfxEnableTextureUnitOptimization, gfx_enable_texture_unit_optimization, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use multiple texture units, instead of only one.")
#else

View file

@ -6,7 +6,6 @@
#include <base/color.h>
#include <engine/graphics.h>
#include <stdint.h>
enum
{
@ -101,8 +100,8 @@ public:
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor) = 0;
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor, float X, float Y) = 0;
virtual void UploadEntityLayerText(void* pTexBuff, int ImageColorChannelCount, int TexWidth, int TexHeight, const char *pText, int Length, float x, float y, int FontHeight) = 0;
virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize, int MaxWidth) = 0;
virtual void UploadEntityLayerText(IGraphics::CTextureHandle Texture, const char *pText, int Length, float x, float y, int FontHeight) = 0;
virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize = -1) = 0;
virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) = 0;
// old foolish interface

View file

@ -50,16 +50,14 @@ void CBackground::LoadBackground()
m_pLayers = m_pBackgroundLayers;
m_pImages = m_pBackgroundImages;
bool NeedImageLoading = false;
str_copy(m_aMapName, g_Config.m_ClBackgroundEntities, sizeof(m_aMapName));
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "maps/%s", g_Config.m_ClBackgroundEntities);
if(m_pMap->Load(aBuf))
{
m_pLayers->InitBackground(m_pMap);
m_pImages->LoadBackground(m_pMap);
RenderTools()->RenderTilemapGenerateSkip(m_pLayers);
NeedImageLoading = true;
m_Loaded = true;
}
else if(str_comp(g_Config.m_ClBackgroundEntities, CURRENT) == 0)
@ -73,12 +71,8 @@ void CBackground::LoadBackground()
}
}
if(m_Loaded)
{
if(m_Loaded)
CMapLayers::OnMapLoad();
if(NeedImageLoading)
m_pImages->LoadBackground(m_pLayers, m_pMap);
}
m_LastLoad = time_get();
}

View file

@ -38,7 +38,7 @@ void CCamera::ScaleZoom(float Factor)
void CCamera::ChangeZoom(float Target)
{
if(Target >= (Graphics()->IsTileBufferingEnabled()? 60 : 30))
if(Target >= (Graphics()->IsBufferingEnabled()? 60 : 30))
{
return;
}

View file

@ -19,9 +19,6 @@ CMapImages::CMapImages(int TextureSize)
m_Count = 0;
m_TextureScale = TextureSize;
m_EntitiesIsLoaded = false;
m_SpeedupArrowIsLoaded = false;
mem_zero(m_aTextureUsedByTileOrQuadLayerFlag, sizeof(m_aTextureUsedByTileOrQuadLayerFlag));
}
void CMapImages::OnInit()
@ -29,83 +26,72 @@ void CMapImages::OnInit()
InitOverlayTextures();
}
void CMapImages::OnMapLoadImpl(class CLayers *pLayers, IMap *pMap)
void CMapImages::OnMapLoad()
{
IMap *pMap = Kernel()->RequestInterface<IMap>();
// unload all textures
for(int i = 0; i < m_Count; i++)
{
Graphics()->UnloadTexture(m_aTextures[i]);
m_aTextures[i] = IGraphics::CTextureHandle();
m_aTextureUsedByTileOrQuadLayerFlag[i] = 0;
}
m_Count = 0;
int Start;
pMap->GetType(MAPITEMTYPE_IMAGE, &Start, &m_Count);
for(int g = 0; g < pLayers->NumGroups(); g++)
{
CMapItemGroup *pGroup = pLayers->GetGroup(g);
if(!pGroup)
{
continue;
}
for(int l = 0; l < pGroup->m_NumLayers; l++)
{
CMapItemLayer *pLayer = pLayers->GetLayer(pGroup->m_StartLayer+l);
if(pLayer->m_Type == LAYERTYPE_TILES)
{
CMapItemLayerTilemap *pTLayer = (CMapItemLayerTilemap *)pLayer;
if(pTLayer->m_Image != -1 && pTLayer->m_Image < (int)(sizeof(m_aTextures) / sizeof(m_aTextures[0])))
{
m_aTextureUsedByTileOrQuadLayerFlag[(size_t)pTLayer->m_Image] |= 1;
}
}
else if(pLayer->m_Type == LAYERTYPE_QUADS)
{
CMapItemLayerQuads *pQLayer = (CMapItemLayerQuads *)pLayer;
if(pQLayer->m_Image != -1 && pQLayer->m_Image < (int)(sizeof(m_aTextures) / sizeof(m_aTextures[0])))
{
m_aTextureUsedByTileOrQuadLayerFlag[(size_t)pQLayer->m_Image] |= 2;
}
}
}
}
int TextureLoadFlag = Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE;
// load new textures
for(int i = 0; i < m_Count; i++)
{
int LoadFlag = (((m_aTextureUsedByTileOrQuadLayerFlag[i] & 1) != 0) ? TextureLoadFlag : 0) | (((m_aTextureUsedByTileOrQuadLayerFlag[i] & 2) != 0) ? 0 : (Graphics()->IsTileBufferingEnabled() ? IGraphics::TEXLOAD_NO_2D_TEXTURE : 0));
CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
if(pImg->m_External)
{
char Buf[256];
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
str_format(Buf, sizeof(Buf), "mapres/%s.png", pName);
m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, LoadFlag);
m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
}
else
{
void *pData = pMap->GetData(pImg->m_ImageData);
m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, LoadFlag);
m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, 0);
pMap->UnloadData(pImg->m_ImageData);
}
}
}
void CMapImages::OnMapLoad()
void CMapImages::LoadBackground(class IMap *pMap)
{
IMap *pMap = Kernel()->RequestInterface<IMap>();
CLayers *pLayers = m_pClient->Layers();
OnMapLoadImpl(pLayers, pMap);
}
// unload all textures
for(int i = 0; i < m_Count; i++)
{
Graphics()->UnloadTexture(m_aTextures[i]);
m_aTextures[i] = IGraphics::CTextureHandle();
}
m_Count = 0;
void CMapImages::LoadBackground(class CLayers *pLayers, class IMap *pMap)
{
OnMapLoadImpl(pLayers, pMap);
int Start;
pMap->GetType(MAPITEMTYPE_IMAGE, &Start, &m_Count);
// load new textures
for(int i = 0; i < m_Count; i++)
{
CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
if(pImg->m_External)
{
char Buf[256];
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
str_format(Buf, sizeof(Buf), "mapres/%s.png", pName);
m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
}
else
{
void *pData = pMap->GetData(pImg->m_ImageData);
m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, 0);
pMap->UnloadData(pImg->m_ImageData);
}
}
}
IGraphics::CTextureHandle CMapImages::GetEntities()
@ -132,27 +118,13 @@ IGraphics::CTextureHandle CMapImages::GetEntities()
if(m_EntitiesTextures >= 0)
Graphics()->UnloadTexture(m_EntitiesTextures);
int TextureLoadFlag = Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE;
m_EntitiesTextures = Graphics()->LoadTexture(aPath, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, TextureLoadFlag);
m_EntitiesTextures = Graphics()->LoadTexture(aPath, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
m_EntitiesIsLoaded = true;
m_pEntitiesGameType = pEntities;
}
return m_EntitiesTextures;
}
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, CImageInfo::FORMAT_AUTO, TextureLoadFlag);
m_SpeedupArrowIsLoaded = true;
}
return m_SpeedupArrowTexture;
}
IGraphics::CTextureHandle CMapImages::GetOverlayBottom()
{
return m_OverlayBottomTexture;
@ -191,22 +163,20 @@ int CMapImages::GetTextureScale()
return m_TextureScale;
}
IGraphics::CTextureHandle CMapImages::UploadEntityLayerText(int TextureSize, int MaxWidth, int YOffset)
IGraphics::CTextureHandle CMapImages::UploadEntityLayerText(int TextureSize, int YOffset)
{
void *pMem = calloc(1024 * 1024 * 4, 1);
UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, MaxWidth, YOffset, 0);
UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, MaxWidth, YOffset, 1);
UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, MaxWidth, YOffset, 2, 255);
int TextureLoadFlag = (Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE) | IGraphics::TEXLOAD_NO_2D_TEXTURE;
IGraphics::CTextureHandle Texture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_RGBA, pMem, CImageInfo::FORMAT_RGBA, TextureLoadFlag);
void *pMem = calloc(1024 * 1024, 1);
IGraphics::CTextureHandle Texture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS);
free(pMem);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 0);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 1);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 2, 255);
return Texture;
}
void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCount, int TexWidth, int TexHeight, int TextureSize, int MaxWidth, int YOffset, int NumbersPower, int MaxNumber)
void CMapImages::UpdateEntityLayerText(IGraphics::CTextureHandle Texture, int TextureSize, int YOffset, int NumbersPower, int MaxNumber)
{
char aBuf[4];
int DigitsCount = NumbersPower+1;
@ -218,8 +188,8 @@ void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCo
str_format(aBuf, 4, "%d", CurrentNumber);
int CurrentNumberSuitableFontSize = TextRender()->AdjustFontSize(aBuf, DigitsCount, TextureSize, MaxWidth);
int UniversalSuitableFontSize = CurrentNumberSuitableFontSize*0.95f; // should be smoothed enough to fit any digits combination
int CurrentNumberSuitableFontSize = TextRender()->AdjustFontSize(aBuf, DigitsCount, TextureSize);
int UniversalSuitableFontSize = CurrentNumberSuitableFontSize*0.9; // should be smoothed enough to fit any digits combination
int ApproximateTextWidth = TextRender()->CalculateTextWidth(aBuf, DigitsCount, 0, UniversalSuitableFontSize);
int XOffSet = (64-ApproximateTextWidth)/2;
@ -232,7 +202,7 @@ void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCo
float x = (CurrentNumber%16)*64;
float y = (CurrentNumber/16)*64;
TextRender()->UploadEntityLayerText(pTexBuffer, ImageColorChannelCount, TexWidth, TexHeight, aBuf, DigitsCount, x+XOffSet, y+YOffset, UniversalSuitableFontSize);
TextRender()->UploadEntityLayerText(Texture, aBuf, DigitsCount, x+XOffSet, y+YOffset, UniversalSuitableFontSize);
}
}
@ -243,16 +213,16 @@ void CMapImages::InitOverlayTextures()
if(m_OverlayBottomTexture == -1)
{
m_OverlayBottomTexture = UploadEntityLayerText(TextureSize/2, 64, 32+TextureToVerticalCenterOffset/2);
m_OverlayBottomTexture = UploadEntityLayerText(TextureSize/2, 32+TextureToVerticalCenterOffset/2);
}
if(m_OverlayTopTexture == -1)
{
m_OverlayTopTexture = UploadEntityLayerText(TextureSize/2, 64, TextureToVerticalCenterOffset/2);
m_OverlayTopTexture = UploadEntityLayerText(TextureSize/2, TextureToVerticalCenterOffset/2);
}
if(m_OverlayCenterTexture == -1)
{
m_OverlayCenterTexture = UploadEntityLayerText(TextureSize, 64, TextureToVerticalCenterOffset);
m_OverlayCenterTexture = UploadEntityLayerText(TextureSize, TextureToVerticalCenterOffset);
}
}

View file

@ -9,7 +9,6 @@ class CMapImages : public CComponent
friend class CBackground;
IGraphics::CTextureHandle m_aTextures[64];
int m_aTextureUsedByTileOrQuadLayerFlag[64]; // 0: nothing, 1(as flag): tile layer, 2(as flag): quad layer
int m_Count;
const char *m_pEntitiesGameType;
@ -20,14 +19,12 @@ public:
IGraphics::CTextureHandle Get(int Index) const { return m_aTextures[Index]; }
int Num() const { return m_Count; }
void OnMapLoadImpl(class CLayers *pLayers, class IMap *pMap);
virtual void OnMapLoad();
virtual void OnInit();
void LoadBackground(class CLayers *pLayers, class IMap *pMap);
void LoadBackground(class IMap *pMap);
// DDRace
IGraphics::CTextureHandle GetEntities();
IGraphics::CTextureHandle GetSpeedupArrow();
IGraphics::CTextureHandle GetOverlayBottom();
IGraphics::CTextureHandle GetOverlayTop();
@ -37,18 +34,17 @@ public:
int GetTextureScale();
private:
bool m_EntitiesIsLoaded;
bool m_SpeedupArrowIsLoaded;
IGraphics::CTextureHandle m_EntitiesTextures;
IGraphics::CTextureHandle m_SpeedupArrowTexture;
IGraphics::CTextureHandle m_OverlayBottomTexture;
IGraphics::CTextureHandle m_OverlayTopTexture;
IGraphics::CTextureHandle m_OverlayCenterTexture;
int m_TextureScale;
void InitOverlayTextures();
IGraphics::CTextureHandle UploadEntityLayerText(int TextureSize, int MaxWidth, int YOffset);
void UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCount, int TexWidth, int TexHeight, int TextureSize, int MaxWidth, int YOffset, int NumbersPower, int MaxNumber = -1);
IGraphics::CTextureHandle UploadEntityLayerText(int TextureSize, int YOffset);
void UpdateEntityLayerText(IGraphics::CTextureHandle Texture, int TextureSize, int YOffset, int NumbersPower, int MaxNumber = -1);
};
#endif

View file

@ -125,42 +125,71 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
}
}
void FillTmpTileSpeedup(SGraphicTile* pTmpTile, SGraphicTileTexureCoords* pTmpTex, bool As3DTextureCoord, unsigned char Flags, unsigned char Index, int x, int y, int Scale, CMapItemGroup* pGroup, short AngleRotate)
struct STmpTile
{
vec2 m_TopLeft;
vec2 m_TopRight;
vec2 m_BottomRight;
vec2 m_BottomLeft;
};
struct STmpTileTexCoord
{
STmpTileTexCoord()
{
m_TexCoordTopLeftRightOrBottom[0] = m_TexCoordTopLeftRightOrBottom[1] = 0;
m_TexCoordBottomLeftRightOrBottom[0] = 0; m_TexCoordBottomLeftRightOrBottom[1] = 1;
m_TexCoordTopRightRightOrBottom[0] = 1; m_TexCoordTopRightRightOrBottom[1] = 0;
m_TexCoordBottomRightRightOrBottom[0] = m_TexCoordBottomRightRightOrBottom[1] = 1;
}
unsigned char m_TexCoordTopLeft[2];
unsigned char m_TexCoordTopLeftRightOrBottom[2];
unsigned char m_TexCoordTopRight[2];
unsigned char m_TexCoordTopRightRightOrBottom[2];
unsigned char m_TexCoordBottomRight[2];
unsigned char m_TexCoordBottomRightRightOrBottom[2];
unsigned char m_TexCoordBottomLeft[2];
unsigned char m_TexCoordBottomLeftRightOrBottom[2];
};
void FillTmpTileSpeedup(STmpTile* pTmpTile, STmpTileTexCoord* pTmpTex, 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;
unsigned char x1 = 16;
unsigned char y1 = 0;
unsigned char x2 = 16;
unsigned char y2 = 16;
unsigned char x3 = 0;
unsigned char y3 = 16;
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;
unsigned char bx0 = 0;
unsigned char by0 = 0;
unsigned char bx1 = 1;
unsigned char by1 = 0;
unsigned char bx2 = 1;
unsigned char by2 = 1;
unsigned char bx3 = 0;
unsigned char by3 = 1;
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[0] = x0;
pTmpTex->m_TexCoordTopLeft[1] = y0;
pTmpTex->m_TexCoordBottomLeft[0] = x3;
pTmpTex->m_TexCoordBottomLeft[1] = y3;
pTmpTex->m_TexCoordTopRight[0] = x1;
pTmpTex->m_TexCoordTopRight[1] = y1;
pTmpTex->m_TexCoordBottomRight[0] = x2;
pTmpTex->m_TexCoordBottomRight[1] = y2;
pTmpTex->m_TexCoordTopLeftRightOrBottom[0] = bx0;
pTmpTex->m_TexCoordTopLeftRightOrBottom[1] = by0;
pTmpTex->m_TexCoordBottomLeftRightOrBottom[0] = bx3;
pTmpTex->m_TexCoordBottomLeftRightOrBottom[1] = by3;
pTmpTex->m_TexCoordTopRightRightOrBottom[0] = bx1;
pTmpTex->m_TexCoordTopRightRightOrBottom[1] = by1;
pTmpTex->m_TexCoordBottomRightRightOrBottom[0] = bx2;
pTmpTex->m_TexCoordBottomRightRightOrBottom[1] = by2;
}
//same as in rotate from Graphics()
@ -195,18 +224,31 @@ void FillTmpTileSpeedup(SGraphicTile* pTmpTile, SGraphicTileTexureCoords* pTmpTe
}
}
void FillTmpTile(SGraphicTile* pTmpTile, SGraphicTileTexureCoords* pTmpTex, bool As3DTextureCoord, unsigned char Flags, unsigned char Index, int x, int y, int Scale, CMapItemGroup* pGroup)
void FillTmpTile(STmpTile* pTmpTile, STmpTileTexCoord* pTmpTex, unsigned char Flags, unsigned char Index, int x, int y, int Scale, CMapItemGroup* pGroup)
{
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;
unsigned char tx = Index%16;
unsigned char ty = Index/16;
unsigned char x0 = tx;
unsigned char y0 = ty;
unsigned char x1 = tx+1;
unsigned char y1 = ty;
unsigned char x2 = tx+1;
unsigned char y2 = ty+1;
unsigned char x3 = tx;
unsigned char y3 = ty+1;
unsigned char bx0 = 0;
unsigned char by0 = 0;
unsigned char bx1 = 1;
unsigned char by1 = 0;
unsigned char bx2 = 1;
unsigned char by2 = 1;
unsigned char bx3 = 0;
unsigned char by3 = 1;
if(Flags&TILEFLAG_VFLIP)
{
@ -214,6 +256,11 @@ void FillTmpTile(SGraphicTile* pTmpTile, SGraphicTileTexureCoords* pTmpTex, bool
x1 = x3;
x2 = x3;
x3 = x0;
bx0 = bx2;
bx1 = bx3;
bx2 = bx3;
bx3 = bx0;
}
if(Flags&TILEFLAG_HFLIP)
@ -222,6 +269,11 @@ void FillTmpTile(SGraphicTile* pTmpTile, SGraphicTileTexureCoords* pTmpTex, bool
y2 = y1;
y3 = y1;
y1 = y0;
by0 = by3;
by2 = by1;
by3 = by1;
by1 = by0;
}
if(Flags&TILEFLAG_ROTATE)
@ -236,31 +288,36 @@ void FillTmpTile(SGraphicTile* pTmpTile, SGraphicTileTexureCoords* pTmpTex, bool
y3 = y2;
y2 = y1;
y1 = Tmp;
Tmp = bx0;
bx0 = bx3;
bx3 = bx2;
bx2 = bx1;
bx1 = Tmp;
Tmp = by0;
by0 = by3;
by3 = by2;
by2 = by1;
by1 = Tmp;
}
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;
pTmpTex->m_TexCoordTopLeft[0] = x0;
pTmpTex->m_TexCoordTopLeft[1] = y0;
pTmpTex->m_TexCoordBottomLeft[0] = x3;
pTmpTex->m_TexCoordBottomLeft[1] = y3;
pTmpTex->m_TexCoordTopRight[0] = x1;
pTmpTex->m_TexCoordTopRight[1] = y1;
pTmpTex->m_TexCoordBottomRight[0] = x2;
pTmpTex->m_TexCoordBottomRight[1] = 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_TexCoordTopLeftRightOrBottom[0] = bx0;
pTmpTex->m_TexCoordTopLeftRightOrBottom[1] = by0;
pTmpTex->m_TexCoordBottomLeftRightOrBottom[0] = bx3;
pTmpTex->m_TexCoordBottomLeftRightOrBottom[1] = by3;
pTmpTex->m_TexCoordTopRightRightOrBottom[0] = bx1;
pTmpTex->m_TexCoordTopRightRightOrBottom[1] = by1;
pTmpTex->m_TexCoordBottomRightRightOrBottom[0] = bx2;
pTmpTex->m_TexCoordBottomRightRightOrBottom[1] = by2;
}
pTmpTile->m_TopLeft.x = x*Scale;
@ -318,23 +375,23 @@ CMapLayers::STileLayerVisuals::~STileLayerVisuals()
m_BorderRight = NULL;
}
bool AddTile(std::vector<SGraphicTile>& TmpTiles, std::vector<SGraphicTileTexureCoords>& TmpTileTexCoords, 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<STmpTile>& TmpTiles, std::vector<STmpTileTexCoord>& TmpTileTexCoords, unsigned char Index, unsigned char Flags, int x, int y, CMapItemGroup* pGroup, bool DoTextureCoords, bool FillSpeedup = false, int AngleRotate = -1)
{
if(Index)
{
TmpTiles.push_back(SGraphicTile());
SGraphicTile& Tile = TmpTiles.back();
SGraphicTileTexureCoords* pTileTex = NULL;
TmpTiles.push_back(STmpTile());
STmpTile& Tile = TmpTiles.back();
STmpTileTexCoord* pTileTex = NULL;
if(DoTextureCoords)
{
TmpTileTexCoords.push_back(SGraphicTileTexureCoords());
SGraphicTileTexureCoords& TileTex = TmpTileTexCoords.back();
TmpTileTexCoords.push_back(STmpTileTexCoord());
STmpTileTexCoord& TileTex = TmpTileTexCoords.back();
pTileTex = &TileTex;
}
if(FillSpeedup)
FillTmpTileSpeedup(&Tile, pTileTex, As3DTextureCoord, Flags, 0, x, y, 32.f, pGroup, AngleRotate);
FillTmpTileSpeedup(&Tile, pTileTex, Flags, 0, x, y, 32.f, pGroup, AngleRotate);
else
FillTmpTile(&Tile, pTileTex, As3DTextureCoord, Flags, Index, x, y, 32.f, pGroup);
FillTmpTile(&Tile, pTileTex, Flags, Index, x, y, 32.f, pGroup);
return true;
}
@ -344,8 +401,8 @@ bool AddTile(std::vector<SGraphicTile>& TmpTiles, std::vector<SGraphicTileTexure
struct STmpQuadVertexTextured
{
float m_X, m_Y, m_CenterX, m_CenterY;
unsigned char m_R, m_G, m_B, m_A;
float m_U, m_V;
unsigned char m_R, m_G, m_B, m_A;
};
struct STmpQuadVertex
@ -376,7 +433,7 @@ void mem_copy_special(void *pDest, void *pSource, size_t Size, size_t Count, siz
void CMapLayers::OnMapLoad()
{
if(!Graphics()->IsTileBufferingEnabled() && !Graphics()->IsQuadBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
return;
//clear everything and destroy all buffers
if(m_TileLayerVisuals.size() != 0)
@ -402,24 +459,22 @@ void CMapLayers::OnMapLoad()
bool PassedGameLayer = false;
//prepare all visuals for all tile layers
std::vector<SGraphicTile> tmpTiles;
std::vector<SGraphicTileTexureCoords> tmpTileTexCoords;
std::vector<SGraphicTile> tmpBorderTopTiles;
std::vector<SGraphicTileTexureCoords> tmpBorderTopTilesTexCoords;
std::vector<SGraphicTile> tmpBorderLeftTiles;
std::vector<SGraphicTileTexureCoords> tmpBorderLeftTilesTexCoords;
std::vector<SGraphicTile> tmpBorderRightTiles;
std::vector<SGraphicTileTexureCoords> tmpBorderRightTilesTexCoords;
std::vector<SGraphicTile> tmpBorderBottomTiles;
std::vector<SGraphicTileTexureCoords> tmpBorderBottomTilesTexCoords;
std::vector<SGraphicTile> tmpBorderCorners;
std::vector<SGraphicTileTexureCoords> tmpBorderCornersTexCoords;
std::vector<STmpTile> tmpTiles;
std::vector<STmpTileTexCoord> tmpTileTexCoords;
std::vector<STmpTile> tmpBorderTopTiles;
std::vector<STmpTileTexCoord> tmpBorderTopTilesTexCoords;
std::vector<STmpTile> tmpBorderLeftTiles;
std::vector<STmpTileTexCoord> tmpBorderLeftTilesTexCoords;
std::vector<STmpTile> tmpBorderRightTiles;
std::vector<STmpTileTexCoord> tmpBorderRightTilesTexCoords;
std::vector<STmpTile> tmpBorderBottomTiles;
std::vector<STmpTileTexCoord> tmpBorderBottomTilesTexCoords;
std::vector<STmpTile> tmpBorderCorners;
std::vector<STmpTileTexCoord> tmpBorderCornersTexCoords;
std::vector<STmpQuad> tmpQuads;
std::vector<STmpQuadTextured> tmpQuadsTextured;
bool As3DTextureCoords = !Graphics()->HasTextureArrays();
for(int g = 0; g < m_pLayers->NumGroups(); g++)
{
CMapItemGroup *pGroup = m_pLayers->GetGroup(g);
@ -475,7 +530,7 @@ void CMapLayers::OnMapLoad()
continue;
}
if(pLayer->m_Type == LAYERTYPE_TILES && Graphics()->IsTileBufferingEnabled())
if(pLayer->m_Type == LAYERTYPE_TILES)
{
bool DoTextureCoords = false;
CMapItemLayerTilemap *pTMap = (CMapItemLayerTilemap *)pLayer;
@ -556,23 +611,6 @@ void CMapLayers::OnMapLoad()
tmpBorderBottomTilesTexCoords.clear();
tmpBorderCornersTexCoords.clear();
if(!DoTextureCoords) {
tmpTiles.reserve((size_t)(pTMap->m_Width*pTMap->m_Height));
tmpBorderTopTiles.reserve((size_t)pTMap->m_Width);
tmpBorderBottomTiles.reserve((size_t)pTMap->m_Width);
tmpBorderLeftTiles.reserve((size_t)pTMap->m_Height);
tmpBorderRightTiles.reserve((size_t)pTMap->m_Height);
tmpBorderCorners.reserve((size_t)4);
}
else {
tmpTileTexCoords.reserve((size_t)(pTMap->m_Width*pTMap->m_Height));
tmpBorderTopTilesTexCoords.reserve((size_t)pTMap->m_Width);
tmpBorderBottomTilesTexCoords.reserve((size_t)pTMap->m_Width);
tmpBorderLeftTilesTexCoords.reserve((size_t)pTMap->m_Height);
tmpBorderRightTilesTexCoords.reserve((size_t)pTMap->m_Height);
tmpBorderCornersTexCoords.reserve((size_t)4);
}
int x = 0;
int y = 0;
for(y = 0; y < pTMap->m_Height; ++y)
@ -661,7 +699,7 @@ void CMapLayers::OnMapLoad()
if(IsSpeedupLayer && CurOverlay == 0)
AddAsSpeedup = true;
if(AddTile(tmpTiles, tmpTileTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpTiles, tmpTileTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_TilesOfLayer[y*pTMap->m_Width + x].Draw(true);
//do the border tiles
@ -670,20 +708,20 @@ void CMapLayers::OnMapLoad()
if(y == 0)
{
Visuals.m_BorderTopLeft.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderTopLeft.Draw(true);
}
else if(y == pTMap->m_Height - 1)
{
Visuals.m_BorderBottomLeft.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderBottomLeft.Draw(true);
}
else
{
Visuals.m_BorderLeft[y-1].SetIndexBufferByteOffset((offset_ptr32)(tmpBorderLeftTiles.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderLeftTiles, tmpBorderLeftTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderLeftTiles, tmpBorderLeftTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderLeft[y-1].Draw(true);
}
}
@ -692,21 +730,21 @@ void CMapLayers::OnMapLoad()
if(y == 0)
{
Visuals.m_BorderTopRight.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderTopRight.Draw(true);
}
else if(y == pTMap->m_Height - 1)
{
Visuals.m_BorderBottomRight.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderBottomRight.Draw(true);
}
else
{
Visuals.m_BorderRight[y-1].SetIndexBufferByteOffset((offset_ptr32)(tmpBorderRightTiles.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderRightTiles, tmpBorderRightTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderRightTiles, tmpBorderRightTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderRight[y-1].Draw(true);
}
}
@ -715,7 +753,7 @@ void CMapLayers::OnMapLoad()
if(x > 0 && x < pTMap->m_Width - 1)
{
Visuals.m_BorderTop[x-1].SetIndexBufferByteOffset((offset_ptr32)(tmpBorderTopTiles.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderTopTiles, tmpBorderTopTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderTopTiles, tmpBorderTopTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderTop[x-1].Draw(true);
}
}
@ -724,7 +762,7 @@ void CMapLayers::OnMapLoad()
if(x > 0 && x < pTMap->m_Width - 1)
{
Visuals.m_BorderBottom[x-1].SetIndexBufferByteOffset((offset_ptr32)(tmpBorderBottomTiles.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderBottomTiles, tmpBorderBottomTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderBottomTiles, tmpBorderBottomTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderBottom[x-1].Draw(true);
}
}
@ -735,7 +773,7 @@ void CMapLayers::OnMapLoad()
if(IsGameLayer)
{
Visuals.m_BorderKillTile.SetIndexBufferByteOffset((offset_ptr32)(tmpTiles.size() * 6 * sizeof(unsigned int)));
if(AddTile(tmpTiles, tmpTileTexCoords, As3DTextureCoords, TILE_DEATH, 0, 0, 0, pGroup, DoTextureCoords))
if(AddTile(tmpTiles, tmpTileTexCoords, TILE_DEATH, 0, 0, 0, pGroup, DoTextureCoords))
Visuals.m_BorderKillTile.Draw(true);
}
@ -798,55 +836,60 @@ void CMapLayers::OnMapLoad()
float* pTmpTiles = (tmpTiles.size() == 0) ? NULL : (float*)&tmpTiles[0];
unsigned char* pTmpTileTexCoords = (tmpTileTexCoords.size() == 0) ? NULL : (unsigned char*)&tmpTileTexCoords[0];
Visuals.m_BufferContainerIndex = -1;
size_t UploadDataSize = tmpTileTexCoords.size() * sizeof(SGraphicTileTexureCoords) + tmpTiles.size() * sizeof(SGraphicTile);
if(UploadDataSize > 0)
size_t UploadDataSize = tmpTileTexCoords.size() * sizeof(STmpTileTexCoord) + tmpTiles.size() * sizeof(STmpTile);
char* pUploadData = new char[UploadDataSize];
mem_copy_special(pUploadData, pTmpTiles, sizeof(vec2), tmpTiles.size() * 4, (DoTextureCoords ? (sizeof(unsigned char) * 2 * 2) : 0));
if(DoTextureCoords)
{
char* pUploadData = new char[UploadDataSize];
mem_copy_special(pUploadData + sizeof(vec2), pTmpTileTexCoords, sizeof(unsigned char) * 2 * 2, tmpTiles.size() * 4, (DoTextureCoords ? (sizeof(vec2)) : 0));
}
mem_copy_special(pUploadData, pTmpTiles, sizeof(vec2), tmpTiles.size() * 4, (DoTextureCoords ? sizeof(vec3) : 0));
if(DoTextureCoords)
{
mem_copy_special(pUploadData + sizeof(vec2), pTmpTileTexCoords, sizeof(vec3), tmpTiles.size() * 4, (DoTextureCoords ? (sizeof(vec2)) : 0));
}
// first create the buffer object
int BufferObjectIndex = Graphics()->CreateBufferObject(UploadDataSize, pUploadData);
delete[] pUploadData;
// first create the buffer object
int BufferObjectIndex = Graphics()->CreateBufferObject(UploadDataSize, pUploadData);
delete[] pUploadData;
// then create the buffer container
SBufferContainerInfo ContainerInfo;
ContainerInfo.m_Stride = (DoTextureCoords ? (sizeof(float) * 2 + sizeof(vec3)) : 0);
// then create the buffer container
SBufferContainerInfo ContainerInfo;
ContainerInfo.m_Stride = (DoTextureCoords ? (sizeof(float) * 2 + sizeof(unsigned char) * 2 * 2) : 0);
ContainerInfo.m_Attributes.push_back(SBufferContainerInfo::SAttribute());
SBufferContainerInfo::SAttribute* pAttr = &ContainerInfo.m_Attributes.back();
pAttr->m_DataTypeCount = 2;
pAttr->m_Type = GRAPHICS_TYPE_FLOAT;
pAttr->m_Normalized = false;
pAttr->m_pOffset = 0;
pAttr->m_FuncType = 0;
pAttr->m_VertBufferBindingIndex = BufferObjectIndex;
if(DoTextureCoords)
{
ContainerInfo.m_Attributes.push_back(SBufferContainerInfo::SAttribute());
SBufferContainerInfo::SAttribute* pAttr = &ContainerInfo.m_Attributes.back();
pAttr = &ContainerInfo.m_Attributes.back();
pAttr->m_DataTypeCount = 2;
pAttr->m_Type = GRAPHICS_TYPE_FLOAT;
pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE;
pAttr->m_Normalized = false;
pAttr->m_pOffset = 0;
pAttr->m_pOffset = (void*)(sizeof(vec2));
pAttr->m_FuncType = 0;
pAttr->m_VertBufferBindingIndex = BufferObjectIndex;
if(DoTextureCoords)
{
ContainerInfo.m_Attributes.push_back(SBufferContainerInfo::SAttribute());
pAttr = &ContainerInfo.m_Attributes.back();
pAttr->m_DataTypeCount = 3;
pAttr->m_Type = GRAPHICS_TYPE_FLOAT;
pAttr->m_Normalized = false;
pAttr->m_pOffset = (void*)(sizeof(vec2));
pAttr->m_FuncType = 0;
pAttr->m_VertBufferBindingIndex = BufferObjectIndex;
}
Visuals.m_BufferContainerIndex = Graphics()->CreateBufferContainer(&ContainerInfo);
// and finally inform the backend how many indices are required
Graphics()->IndicesNumRequiredNotify(tmpTiles.size() * 6);
ContainerInfo.m_Attributes.push_back(SBufferContainerInfo::SAttribute());
pAttr = &ContainerInfo.m_Attributes.back();
pAttr->m_DataTypeCount = 2;
pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE;
pAttr->m_Normalized = false;
pAttr->m_pOffset = (void*)(sizeof(vec2) + sizeof(unsigned char) * 2);
pAttr->m_FuncType = 1;
pAttr->m_VertBufferBindingIndex = BufferObjectIndex;
}
Visuals.m_BufferContainerIndex = Graphics()->CreateBufferContainer(&ContainerInfo);
// and finally inform the backend how many indices are required
Graphics()->IndicesNumRequiredNotify(tmpTiles.size() * 6);
++CurOverlay;
}
}
}
else if(pLayer->m_Type == LAYERTYPE_QUADS && Graphics()->IsQuadBufferingEnabled())
else if(pLayer->m_Type == LAYERTYPE_QUADS)
{
CMapItemLayerQuads *pQLayer = (CMapItemLayerQuads *)pLayer;
@ -928,14 +971,6 @@ void CMapLayers::OnMapLoad()
pAttr->m_pOffset = 0;
pAttr->m_FuncType = 0;
pAttr->m_VertBufferBindingIndex = BufferObjectIndex;
ContainerInfo.m_Attributes.push_back(SBufferContainerInfo::SAttribute());
pAttr = &ContainerInfo.m_Attributes.back();
pAttr->m_DataTypeCount = 4;
pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE;
pAttr->m_Normalized = true;
pAttr->m_pOffset = (void*)(sizeof(float) * 4);
pAttr->m_FuncType = 0;
pAttr->m_VertBufferBindingIndex = BufferObjectIndex;
if(Textured)
{
ContainerInfo.m_Attributes.push_back(SBufferContainerInfo::SAttribute());
@ -943,10 +978,18 @@ void CMapLayers::OnMapLoad()
pAttr->m_DataTypeCount = 2;
pAttr->m_Type = GRAPHICS_TYPE_FLOAT;
pAttr->m_Normalized = false;
pAttr->m_pOffset = (void*)(sizeof(float) * 4 + sizeof(unsigned char) * 4);
pAttr->m_pOffset = (void*)(sizeof(float) * 4);
pAttr->m_FuncType = 0;
pAttr->m_VertBufferBindingIndex = BufferObjectIndex;
}
ContainerInfo.m_Attributes.push_back(SBufferContainerInfo::SAttribute());
pAttr = &ContainerInfo.m_Attributes.back();
pAttr->m_DataTypeCount = 4;
pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE;
pAttr->m_Normalized = true;
pAttr->m_pOffset = (void*)(sizeof(float) * 4 + (Textured ? (sizeof(float) * 2) : 0));
pAttr->m_FuncType = 0;
pAttr->m_VertBufferBindingIndex = BufferObjectIndex;
pQLayerVisuals->m_BufferContainerIndex = Graphics()->CreateBufferContainer(&ContainerInfo);
// and finally inform the backend how many indices are required
@ -1695,7 +1738,7 @@ void CMapLayers::OnRender()
Color = ColorRGBA(pTMap->m_Color.r/255.0f, pTMap->m_Color.g/255.0f, pTMap->m_Color.b/255.0f, pTMap->m_Color.a/255.0f*g_Config.m_ClOverlayEntities/100.0f);
else if(!IsGameLayer && g_Config.m_ClOverlayEntities && !(m_Type == TYPE_BACKGROUND_FORCE))
Color = ColorRGBA(pTMap->m_Color.r/255.0f, pTMap->m_Color.g/255.0f, pTMap->m_Color.b/255.0f, pTMap->m_Color.a/255.0f*(100-g_Config.m_ClOverlayEntities)/100.0f);
if(!Graphics()->IsTileBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE,
@ -1718,8 +1761,7 @@ void CMapLayers::OnRender()
RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT,
EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset);
}
else
} else
{
Graphics()->BlendNormal();
// draw kill tiles outside the entity clipping rectangle
@ -1749,7 +1791,7 @@ void CMapLayers::OnRender()
{
if(g_Config.m_ClShowQuads)
{
if(!Graphics()->IsQuadBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
{
//Graphics()->BlendNone();
//RenderTools()->ForceRenderQuads(pQuads, pQLayer->m_NumQuads, LAYERRENDERFLAG_OPAQUE, EnvelopeEval, this, 1.f);
@ -1763,7 +1805,7 @@ void CMapLayers::OnRender()
}
} else
{
if(!Graphics()->IsQuadBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
{
//Graphics()->BlendNone();
//RenderTools()->RenderQuads(pQuads, pQLayer->m_NumQuads, LAYERRENDERFLAG_OPAQUE, EnvelopeEval, this);
@ -1788,7 +1830,7 @@ void CMapLayers::OnRender()
if(Size >= pTMap->m_Width*pTMap->m_Height*sizeof(CTile))
{
ColorRGBA Color = ColorRGBA(pTMap->m_Color.r/255.0f, pTMap->m_Color.g/255.0f, pTMap->m_Color.b/255.0f, pTMap->m_Color.a/255.0f*g_Config.m_ClOverlayEntities/100.0f);
if(!Graphics()->IsTileBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderTilemap(pFrontTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE,
@ -1815,7 +1857,7 @@ void CMapLayers::OnRender()
if(Size >= pTMap->m_Width*pTMap->m_Height*sizeof(CSwitchTile))
{
ColorRGBA Color = ColorRGBA(pTMap->m_Color.r/255.0f, pTMap->m_Color.g/255.0f, pTMap->m_Color.b/255.0f, pTMap->m_Color.a/255.0f*g_Config.m_ClOverlayEntities/100.0f);
if(!Graphics()->IsTileBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderSwitchmap(pSwitchTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE);
@ -1848,7 +1890,7 @@ void CMapLayers::OnRender()
if(Size >= pTMap->m_Width*pTMap->m_Height*sizeof(CTeleTile))
{
ColorRGBA Color = ColorRGBA(pTMap->m_Color.r/255.0f, pTMap->m_Color.g/255.0f, pTMap->m_Color.b/255.0f, pTMap->m_Color.a/255.0f*g_Config.m_ClOverlayEntities/100.0f);
if(!Graphics()->IsTileBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderTelemap(pTeleTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE);
@ -1879,7 +1921,7 @@ void CMapLayers::OnRender()
if(Size >= pTMap->m_Width*pTMap->m_Height*sizeof(CSpeedupTile))
{
ColorRGBA Color = ColorRGBA(pTMap->m_Color.r/255.0f, pTMap->m_Color.g/255.0f, pTMap->m_Color.b/255.0f, pTMap->m_Color.a/255.0f*g_Config.m_ClOverlayEntities/100.0f);
if(!Graphics()->IsTileBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderSpeedupmap(pSpeedupTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE);
@ -1893,7 +1935,7 @@ void CMapLayers::OnRender()
// draw arrow -- clamp to the edge of the arrow image
Graphics()->WrapClamp();
Graphics()->TextureSet(m_pImages->GetSpeedupArrow());
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_SPEEDUP_ARROW].m_Id);
RenderTileLayer(TileLayerCounter-3, &Color, pTMap, pGroup);
Graphics()->WrapNormal();
if(g_Config.m_ClTextEntities)
@ -1917,7 +1959,7 @@ void CMapLayers::OnRender()
if(Size >= pTMap->m_Width*pTMap->m_Height*sizeof(CTuneTile))
{
ColorRGBA Color = ColorRGBA(pTMap->m_Color.r/255.0f, pTMap->m_Color.g/255.0f, pTMap->m_Color.b/255.0f, pTMap->m_Color.a/255.0f*g_Config.m_ClOverlayEntities/100.0f);
if(!Graphics()->IsTileBufferingEnabled())
if(!Graphics()->IsBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderTunemap(pTuneTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE);

View file

@ -907,7 +907,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
static int s_GfxFsaaSamples = g_Config.m_GfxFsaaSamples;
static int s_GfxTextureQuality = g_Config.m_GfxTextureQuality;
static int s_GfxTextureCompression = g_Config.m_GfxTextureCompression;
static int s_GfxOpenGLVersion = (g_Config.m_GfxOpenGLMajor == 3 && g_Config.m_GfxOpenGLMinor == 3) || g_Config.m_GfxOpenGLMajor >= 4;
static int s_GfxOpenGLVersion = g_Config.m_GfxOpenGL3;
static int s_GfxEnableTextureUnitOptimization = g_Config.m_GfxEnableTextureUnitOptimization;
static int s_GfxUsePreinitBuffer = g_Config.m_GfxUsePreinitBuffer;
static int s_GfxHighdpi = g_Config.m_GfxHighdpi;
@ -1033,27 +1033,13 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
g_Config.m_GfxHighDetail ^= 1;
MainView.HSplitTop(20.0f, &Button, &MainView);
bool IsNewOpenGL = (g_Config.m_GfxOpenGLMajor == 3 && g_Config.m_GfxOpenGLMinor == 3) || g_Config.m_GfxOpenGLMajor >= 4;
if(DoButton_CheckBox(&g_Config.m_GfxOpenGLMajor, Localize("Use OpenGL 3.3 (experimental)"), IsNewOpenGL, &Button))
if(DoButton_CheckBox(&g_Config.m_GfxOpenGL3, Localize("Use OpenGL 3.3 (experimental)"), g_Config.m_GfxOpenGL3, &Button))
{
CheckSettings = true;
if(IsNewOpenGL)
{
g_Config.m_GfxOpenGLMajor = 2;
g_Config.m_GfxOpenGLMinor = 1;
g_Config.m_GfxOpenGLPatch = 0;
IsNewOpenGL = false;
}
else
{
g_Config.m_GfxOpenGLMajor = 3;
g_Config.m_GfxOpenGLMinor = 3;
g_Config.m_GfxOpenGLPatch = 0;
IsNewOpenGL = true;
}
g_Config.m_GfxOpenGL3 ^= 1;
}
if(IsNewOpenGL)
if(g_Config.m_GfxOpenGL3)
{
MainView.HSplitTop(20.0f, &Button, &MainView);
if(DoButton_CheckBox(&g_Config.m_GfxUsePreinitBuffer, Localize("Preinit VBO (iGPUs only)"), g_Config.m_GfxUsePreinitBuffer, &Button))
@ -1088,7 +1074,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
s_GfxFsaaSamples == g_Config.m_GfxFsaaSamples &&
s_GfxTextureQuality == g_Config.m_GfxTextureQuality &&
s_GfxTextureCompression == g_Config.m_GfxTextureCompression &&
s_GfxOpenGLVersion == (int)IsNewOpenGL &&
s_GfxOpenGLVersion == g_Config.m_GfxOpenGL3 &&
s_GfxUsePreinitBuffer == g_Config.m_GfxUsePreinitBuffer &&
s_GfxEnableTextureUnitOptimization == g_Config.m_GfxEnableTextureUnitOptimization &&
s_GfxHighdpi == g_Config.m_GfxHighdpi)

View file

@ -178,7 +178,7 @@ void CParticles::RenderGroup(int Group)
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_PARTICLES].m_Id);
// don't use the buffer methods here, else the old renderer gets many draw calls
if(Graphics()->IsQuadContainerBufferingEnabled())
if(Graphics()->IsBufferingEnabled())
{
int i = m_aFirstPart[Group];