2598: Allow specifying an OpenGL version manually r=def- a=Jupeyy

Ofc don't merge, we'll test it first, and if we want merge it, i'd need to enable shader compability for OpenGL 4+, and general support for OpenGL 3.1 and 3.2(bcs i think they already don't allow some older GL commands).

Also i never really read in the OpenGL 1.x specification, i remember that older OpenGL versions required glBegin and stuff like that

Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2020-08-25 15:35:30 +00:00 committed by GitHub
commit 694db44ee2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 2949 additions and 1150 deletions

View file

@ -1127,20 +1127,12 @@ set(EXPECTED_DATA
maps7/Gold\ Mine.map
maps7/readme.txt
particles.png
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/pipeline.frag
shader/pipeline.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
@ -1149,8 +1141,6 @@ 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

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

View file

@ -1,20 +0,0 @@
#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

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

View file

@ -1,17 +0,0 @@
#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

@ -1,15 +0,0 @@
#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

@ -1,27 +0,0 @@
#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

@ -1,15 +0,0 @@
#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

@ -1,30 +0,0 @@
#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));
}

18
data/shader/pipeline.frag Normal file
View file

@ -0,0 +1,18 @@
#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
}

11
data/shader/pipeline.vert Normal file
View file

@ -0,0 +1,11 @@
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,5 +1,3 @@
#version 330
uniform int isTextured;
uniform sampler2D textureSampler;

View file

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

View file

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

View file

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

View file

@ -1,15 +0,0 @@
#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;
}

View file

@ -1,34 +0,0 @@
#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,5 +1,3 @@
#version 330
uniform sampler2D textureSampler;
uniform vec4 VerticesColor;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,10 +1,44 @@
#version 330
layout (location = 0) in vec2 inVertex;
#ifdef TW_TILE_TEXTURED
layout (location = 1) in vec3 inVertexTexCoord;
#endif
uniform mat4x2 Pos;
uniform mat4x2 gPos;
#if defined(TW_TILE_BORDER) || defined(TW_TILE_BORDER_LINE)
uniform vec2 gDir;
uniform vec2 gOffset;
#endif
#if defined(TW_TILE_BORDER)
uniform int gJumpIndex;
#endif
#ifdef TW_TILE_TEXTURED
noperspective out vec3 TexCoord;
#endif
void main()
{
gl_Position = vec4(Pos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
#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
}

View file

@ -1,15 +0,0 @@
#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

@ -1,20 +0,0 @@
#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,6 +5,8 @@
#include "graphics_threaded.h"
#include <atomic>
# if defined(CONF_PLATFORM_MACOSX)
#include <objc/objc-runtime.h>
@ -73,96 +75,223 @@ public:
bool RunCommand(const CCommandBuffer::SCommand *pBaseCommand);
};
// takes care of opengl related rendering
class CCommandProcessorFragment_OpenGL
struct SBackendCapabilites
{
struct CTexture
{
GLuint m_Tex;
int m_MemSize;
bool m_TileBuffering;
bool m_QuadBuffering;
bool m_TextBuffering;
bool m_QuadContainerBuffering;
int m_Width;
int m_Height;
int m_RescaleCount;
};
CTexture m_aTextures[CCommandBuffer::MAX_TEXTURES];
volatile int *m_pTextureMemoryUsage;
bool m_MipMapping;
bool m_NPOTTextures;
bool m_3DTextures;
bool m_2DArrayTextures;
bool m_2DArrayTexturesAsExtension;
bool m_ShaderSupport;
GLint m_MaxTexSize;
public:
enum
{
CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_OPENGL,
};
struct SCommand_Init : public CCommandBuffer::SCommand
{
SCommand_Init() : SCommand(CMD_INIT) {}
volatile int *m_pTextureMemoryUsage;
};
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);
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);
public:
CCommandProcessorFragment_OpenGL();
bool RunCommand(const CCommandBuffer::SCommand *pBaseCommand);
int m_ContextMajor;
int m_ContextMinor;
int m_ContextPatch;
};
#define MAX_STREAM_BUFFER_COUNT 30
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
// takes care of opengl related rendering
class CCommandProcessorFragment_OpenGL
{
bool m_UseMultipleTextureUnits;
bool m_UsePreinitializedVertexBuffer;
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];
volatile int *m_pTextureMemoryUsage;
std::atomic<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;
};
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; }
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);
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) {}
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;
CGLSLPrimitiveProgram *m_pPrimitiveProgram;
CGLSLTileProgram *m_pTileProgram;
CGLSLTileProgram *m_pTileProgramTextured;
CGLSLBorderTileProgram *m_pBorderTileProgram;
CGLSLBorderTileProgram *m_pBorderTileProgramTextured;
CGLSLBorderTileLineProgram *m_pBorderTileLineProgram;
CGLSLBorderTileLineProgram *m_pBorderTileLineProgramTextured;
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
{
bool m_UsePreinitializedVertexBuffer;
int m_MaxQuadsAtOnce;
static const int m_MaxQuadsPossible = 256;
CGLSLPrimitiveProgram *m_pPrimitiveProgram;
CGLSLTileProgram *m_pBorderTileProgram;
CGLSLTileProgram *m_pBorderTileProgramTextured;
CGLSLTileProgram *m_pBorderTileLineProgram;
CGLSLTileProgram *m_pBorderTileLineProgramTextured;
CGLSLQuadProgram *m_pQuadProgram;
CGLSLQuadProgram *m_pQuadProgramTextured;
CGLSLTextProgram *m_pTextProgram;
@ -180,19 +309,7 @@ class CCommandProcessorFragment_OpenGL3_3
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);
@ -210,68 +327,45 @@ class CCommandProcessorFragment_OpenGL3_3
std::vector<GLuint> m_BufferObjectIndices;
CCommandBuffer::SColorf m_ClearColor;
public:
enum
{
CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_OPENGL3_3,
CMD_SHUTDOWN,
};
protected:
static int TexFormatToNewOpenGLFormat(int TexFormat);
bool IsNewApi() override { return true; }
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);
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_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_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_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);
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_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);
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);
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;
public:
CCommandProcessorFragment_OpenGL3_3();
bool RunCommand(const CCommandBuffer::SCommand *pBaseCommand);
CCommandProcessorFragment_OpenGL3_3() = default;
};
// takes care of sdl related commands
@ -293,6 +387,17 @@ 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
@ -326,14 +431,11 @@ public:
// command processor impelementation, uses the fragments to combine into one processor
class CCommandProcessor_SDL_OpenGL : public CGraphicsBackend_Threaded::ICommandProcessor
{
CCommandProcessorFragment_OpenGL m_OpenGL;
CCommandProcessorFragment_OpenGL3_3 m_OpenGL3_3;
CCommandProcessorFragment_OpenGL *m_pOpenGL;
CCommandProcessorFragment_SDL m_SDL;
CCommandProcessorFragment_General m_General;
bool m_UseOpenGL3_3;
public:
void UseOpenGL3_3(bool Use) { m_UseOpenGL3_3 = Use; }
CCommandProcessor_SDL_OpenGL(int OpenGLMajor, int OpenGLMinor, int OpenGLPatch);
virtual void RunBuffer(CCommandBuffer *pBuffer);
};
@ -343,10 +445,12 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded
SDL_Window *m_pWindow;
SDL_GLContext m_GLContext;
ICommandProcessor *m_pProcessor;
volatile int m_TextureMemoryUsage;
std::atomic<int> m_TextureMemoryUsage;
int m_NumScreens;
SBackendCapabilites m_Capabilites;
bool m_UseOpenGL3_3;
bool m_UseNewOpenGL;
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();
@ -366,7 +470,12 @@ public:
virtual void SetWindowGrab(bool Grab);
virtual void NotifyWindow();
virtual bool IsOpenGL3_3() { return m_UseOpenGL3_3; }
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; }
};
#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_UseOpenGL3_3)
if(g_Config.m_GfxQuadAsTriangle && !m_IsNewOpenGL)
{
Cmd.m_PrimType = CCommandBuffer::PRIMTYPE_TRIANGLES;
Cmd.m_PrimCount = NumVerts/3;
@ -437,6 +437,16 @@ 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;
@ -705,7 +715,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_UseOpenGL3_3)
if(g_Config.m_GfxQuadAsTriangle && !m_IsNewOpenGL)
{
m_aVertices[QuadOffset * 6].m_Color.r = r;
m_aVertices[QuadOffset * 6].m_Color.g = g;
@ -806,7 +816,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_UseOpenGL3_3)
if(g_Config.m_GfxQuadAsTriangle && !m_IsNewOpenGL)
{
for(int i = 0; i < Num; ++i)
{
@ -894,7 +904,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_UseOpenGL3_3)
if(g_Config.m_GfxQuadAsTriangle && !m_IsNewOpenGL)
{
for(int i = 0; i < Num; ++i)
{
@ -1000,15 +1010,6 @@ 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)
@ -1065,16 +1066,6 @@ 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;
@ -1109,16 +1100,6 @@ 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;
@ -1228,7 +1209,7 @@ int CGraphics_Threaded::CreateQuadContainer()
void CGraphics_Threaded::QuadContainerUpload(int ContainerIndex)
{
if(m_UseOpenGL3_3)
if(IsQuadContainerBufferingEnabled())
{
SQuadContainer& Container = m_QuadContainers[ContainerIndex];
if(Container.m_Quads.size() > 0)
@ -1364,7 +1345,7 @@ void CGraphics_Threaded::QuadContainerAddQuads(int ContainerIndex, CFreeformItem
void CGraphics_Threaded::QuadContainerReset(int ContainerIndex)
{
SQuadContainer& Container = m_QuadContainers[ContainerIndex];
if(m_UseOpenGL3_3)
if(IsQuadContainerBufferingEnabled())
{
if(Container.m_QuadBufferContainerIndex != -1)
DeleteBufferContainer(Container.m_QuadBufferContainerIndex, true);
@ -1397,7 +1378,7 @@ void CGraphics_Threaded::RenderQuadContainer(int ContainerIndex, int QuadOffset,
if((int)Container.m_Quads.size() < QuadOffset + QuadDrawNum || QuadDrawNum == 0)
return;
if(m_UseOpenGL3_3)
if(IsQuadContainerBufferingEnabled())
{
if(Container.m_QuadBufferContainerIndex == -1)
return;
@ -1455,7 +1436,7 @@ void CGraphics_Threaded::RenderQuadContainerAsSprite(int ContainerIndex, int Qua
if((int)Container.m_Quads.size() < QuadOffset + 1)
return;
if(m_UseOpenGL3_3)
if(IsQuadContainerBufferingEnabled())
{
if(Container.m_QuadBufferContainerIndex == -1)
return;
@ -1581,7 +1562,7 @@ void CGraphics_Threaded::RenderQuadContainerAsSpriteMultiple(int ContainerIndex,
if(DrawCount == 0)
return;
if(m_UseOpenGL3_3)
if(IsQuadContainerBufferingEnabled())
{
if(Container.m_QuadBufferContainerIndex == -1)
return;
@ -2057,13 +2038,19 @@ 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_UseOpenGL3_3 = m_pBackend->IsOpenGL3_3();
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();
return r;
}
int CGraphics_Threaded::InitWindow()
{
if(IssueInit() == 0)
int ErrorCode = IssueInit();
if(ErrorCode == 0)
return 0;
// try disabling fsaa
@ -2076,18 +2063,85 @@ int CGraphics_Threaded::InitWindow()
else
dbg_msg("gfx", "disabling FSAA and trying again");
if(IssueInit() == 0)
ErrorCode = IssueInit();
if(ErrorCode == 0)
return 0;
}
// try using old opengl context
if(g_Config.m_GfxOpenGL3)
size_t OpenGLInitTryCount = 0;
while(ErrorCode == EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_OPENGL_CONTEXT_FAILED || ErrorCode == EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_OPENGL_VERSION_FAILED)
{
g_Config.m_GfxOpenGL3 = 0;
if(IssueInit() == 0)
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)
{
return 0;
}
if(++OpenGLInitTryCount >= 9)
{
// try something else
break;
}
}
// try lowering the resolution

View file

@ -66,7 +66,6 @@ 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,
@ -86,7 +85,7 @@ public:
CMD_CLEAR,
CMD_RENDER,
//opengl 3.3 commands
//opengl 2.0+ commands (some are just emulated and only exist in opengl 3.3+)
CMD_CREATE_BUFFER_OBJECT, // create vbo
CMD_RECREATE_BUFFER_OBJECT, // recreate vbo
CMD_UPDATE_BUFFER_OBJECT, // update vbo
@ -130,6 +129,11 @@ 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
@ -313,7 +317,6 @@ public:
int m_IndicesDrawNum;
int m_BufferContainerIndex;
int m_LOD;
};
struct SCommand_RenderBorderTile : public SCommand
@ -324,7 +327,6 @@ 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];
@ -340,7 +342,6 @@ public:
unsigned int m_IndexDrawNum;
unsigned int m_DrawNum;
int m_BufferContainerIndex;
int m_LOD;
float m_Offset[2];
float m_Dir[2];
@ -554,6 +555,19 @@ 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
@ -592,7 +606,12 @@ public:
virtual bool IsIdle() const = 0;
virtual void WaitForIdle() = 0;
virtual bool IsOpenGL3_3() { return false; }
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; }
};
class CGraphics_Threaded : public IEngineGraphics
@ -610,7 +629,12 @@ class CGraphics_Threaded : public IEngineGraphics
CCommandBuffer::SState m_State;
IGraphicsBackend *m_pBackend;
bool m_UseOpenGL3_3;
bool m_OpenGLTileBufferingEnabled;
bool m_OpenGLQuadBufferingEnabled;
bool m_OpenGLTextBufferingEnabled;
bool m_OpenGLQuadContainerBufferingEnabled;
bool m_OpenGLHasTextureArrays;
bool m_IsNewOpenGL;
CCommandBuffer *m_apCommandBuffers[NUM_CMDBUFFERS];
CCommandBuffer *m_pCommandBuffer;
@ -827,7 +851,11 @@ public:
virtual bool IsIdle();
virtual void WaitForIdle();
virtual bool IsBufferingEnabled() { return m_UseOpenGL3_3; }
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; }
};
extern IGraphicsBackend *CreateGraphicsBackend();

View file

@ -5,7 +5,7 @@
#include <stdio.h>
#include <string>
bool CGLSL::LoadShader(IStorage *pStorage, const char *pFile, int Type)
bool CGLSL::LoadShader(CGLSLCompiler* pCompiler, IStorage *pStorage, const char *pFile, int Type)
{
if (m_IsLoaded)
return true;
@ -14,13 +14,49 @@ bool CGLSL::LoadShader(IStorage *pStorage, const char *pFile, int Type)
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()))
{
Lines.push_back(ReadLine);
Lines.back().append("\r\n");
std::string Line;
pCompiler->ParseLine(Line, ReadLine, Type);
Line.append("\r\n");
Lines.push_back(Line);
}
io_close(f);
@ -50,7 +86,7 @@ bool CGLSL::LoadShader(IStorage *pStorage, const char *pFile, int Type)
glGetShaderInfoLog(shader, maxLength, &maxLength, buff);
dbg_msg("GLSL", "%s", buff);
dbg_msg("GLSL", "%s: %s", pFile, buff);
glDeleteShader(shader);
return false;
}
@ -91,3 +127,152 @@ 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,10 +2,14 @@
#define ENGINE_CLIENT_OPENGL_SL_H
#include <GL/glew.h>
#include <vector>
#include <string>
class CGLSLCompiler;
class CGLSL {
public:
bool LoadShader(class IStorage *pStorage, const char *pFile, int Type);
bool LoadShader(CGLSLCompiler* pCompiler, class IStorage *pStorage, const char *pFile, int Type);
void DeleteShader();
bool IsLoaded();
@ -19,4 +23,47 @@ 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,14 +77,19 @@ void CGLSLProgram::DetachAllShaders()
}
}
void CGLSLProgram::SetUniformVec4(int Loc, int Count, const float* Value)
void CGLSLProgram::SetUniformVec4(int Loc, int Count, const float *pValues)
{
glUniform4fv(Loc, Count, Value);
glUniform4fv(Loc, Count, pValues);
}
void CGLSLProgram::SetUniformVec2(int Loc, int Count, const float* Value)
void CGLSLProgram::SetUniformVec2(int Loc, int Count, const float *pValues)
{
glUniform2fv(Loc, Count, Value);
glUniform2fv(Loc, Count, pValues);
}
void CGLSLProgram::SetUniform(int Loc, int Count, const float *pValues)
{
glUniform1fv(Loc, Count, pValues);
}
void CGLSLProgram::SetUniform(int Loc, const int Value)

View file

@ -21,12 +21,13 @@ public:
void DetachAllShaders();
//Support various types
void SetUniformVec2(int Loc, int Count, const float* Value);
void SetUniformVec4(int Loc, int Count, const float* Value);
void SetUniformVec2(int Loc, int Count, const float *pValue);
void SetUniformVec4(int Loc, int Count, const float *pValue);
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);
@ -41,7 +42,7 @@ protected:
class CGLSLTWProgram : public CGLSLProgram {
public:
CGLSLTWProgram() : m_LastTextureSampler(-1), m_LastIsTextured(-1)
CGLSLTWProgram() : m_LocPos(-1), m_LocIsTextured(-1), m_LocTextureSampler(-1), m_LastTextureSampler(-1), m_LastIsTextured(-1)
{
m_LastScreen[0] = m_LastScreen[1] = m_LastScreen[2] = m_LastScreen[3] = -1.f;
}
@ -118,33 +119,20 @@ public:
class CGLSLQuadProgram : public CGLSLTWProgram {
public:
int m_LocColor;
int m_LocOffset;
int m_LocRotation;
int m_LocColors;
int m_LocOffsets;
int m_LocRotations;
};
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()->IsBufferingEnabled())
if(Graphics()->IsTextBufferingEnabled())
{
Graphics()->TextureClear();
Graphics()->TextQuadsBegin();
@ -1009,7 +1009,7 @@ public:
if(pCursor->m_Flags&TEXTFLAG_RENDER && m_Color.a != 0.f)
{
if(Graphics()->IsBufferingEnabled())
if(Graphics()->IsTextBufferingEnabled())
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()->IsBufferingEnabled())
if(Graphics()->IsTextBufferingEnabled())
{
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()->IsBufferingEnabled())
if(Graphics()->IsTextBufferingEnabled())
{
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()->IsBufferingEnabled())
if(Graphics()->IsTextBufferingEnabled())
{
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()->IsBufferingEnabled())
if(Graphics()->IsTextBufferingEnabled())
{
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()->IsBufferingEnabled())
if(Graphics()->IsTextBufferingEnabled())
{
Graphics()->TextureClear();
// render buffered text
@ -1755,7 +1755,7 @@ public:
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
virtual void UploadEntityLayerText(IGraphics::CTextureHandle Texture, const char *pText, int Length, float x, float y, int FontSize)
virtual void UploadEntityLayerText(void* pTexBuff, int ImageColorChannelCount, int TexWidth, int TexHeight, const char *pText, int Length, float x, float y, int FontSize)
{
if (FontSize < 1)
return;
@ -1794,17 +1794,36 @@ 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)
{
for(py = 0; py < (unsigned)SlotH; py++) // ignore_convention
for(px = 0; px < (unsigned)SlotW; px++)
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)
{
ms_aGlyphData[(py)*SlotW + px] = pBitmap->buffer[py*pBitmap->width + px]; // ignore_convention
*(pImageBuff + ImageOffset + i) = 255;
}
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;
}

View file

@ -40,6 +40,22 @@ 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:
@ -80,6 +96,7 @@ 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
@ -92,6 +109,13 @@ 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
@ -111,6 +135,11 @@ 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),
};
@ -186,7 +215,11 @@ public:
virtual void UpdateBufferContainer(int ContainerIndex, struct SBufferContainerInfo *pContainerInfo) = 0;
virtual void IndicesNumRequiredNotify(unsigned int RequiredIndicesCount) = 0;
virtual bool IsBufferingEnabled() = 0;
virtual bool IsTileBufferingEnabled() = 0;
virtual bool IsQuadBufferingEnabled() = 0;
virtual bool IsTextBufferingEnabled() = 0;
virtual bool IsQuadContainerBufferingEnabled() = 0;
virtual bool HasTextureArrays() = 0;
struct CLineItem
{

View file

@ -369,7 +369,9 @@ 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(GfxOpenGL3, gfx_opengl3, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use new OpenGL3 with shaders")
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")
#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,6 +6,7 @@
#include <base/color.h>
#include <engine/graphics.h>
#include <stdint.h>
enum
{
@ -100,7 +101,7 @@ 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(IGraphics::CTextureHandle Texture, const char *pText, int Length, float x, float y, int FontHeight) = 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 = -1) = 0;
virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) = 0;

View file

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

View file

@ -19,6 +19,9 @@ 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()
@ -35,27 +38,62 @@ void CMapImages::OnMapLoad()
{
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);
CLayers *pLayers = m_pClient->Layers();
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, 0);
m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, LoadFlag);
}
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);
m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, LoadFlag);
pMap->UnloadData(pImg->m_ImageData);
}
}
@ -63,35 +101,7 @@ void CMapImages::OnMapLoad()
void CMapImages::LoadBackground(class IMap *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;
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);
}
}
CMapImages::OnMapLoad();
}
IGraphics::CTextureHandle CMapImages::GetEntities()
@ -118,13 +128,27 @@ IGraphics::CTextureHandle CMapImages::GetEntities()
if(m_EntitiesTextures >= 0)
Graphics()->UnloadTexture(m_EntitiesTextures);
m_EntitiesTextures = Graphics()->LoadTexture(aPath, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
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_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;
@ -165,18 +189,20 @@ int CMapImages::GetTextureScale()
IGraphics::CTextureHandle CMapImages::UploadEntityLayerText(int TextureSize, int YOffset)
{
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);
void *pMem = calloc(1024 * 1024 * 4, 1);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 0);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 1);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 2, 255);
UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, YOffset, 0);
UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, YOffset, 1);
UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, 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);
free(pMem);
return Texture;
}
void CMapImages::UpdateEntityLayerText(IGraphics::CTextureHandle Texture, int TextureSize, int YOffset, int NumbersPower, int MaxNumber)
void CMapImages::UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCount, int TexWidth, int TexHeight, int TextureSize, int YOffset, int NumbersPower, int MaxNumber)
{
char aBuf[4];
int DigitsCount = NumbersPower+1;
@ -202,7 +228,7 @@ void CMapImages::UpdateEntityLayerText(IGraphics::CTextureHandle Texture, int Te
float x = (CurrentNumber%16)*64;
float y = (CurrentNumber/16)*64;
TextRender()->UploadEntityLayerText(Texture, aBuf, DigitsCount, x+XOffSet, y+YOffset, UniversalSuitableFontSize);
TextRender()->UploadEntityLayerText(pTexBuffer, ImageColorChannelCount, TexWidth, TexHeight, aBuf, DigitsCount, x+XOffSet, y+YOffset, UniversalSuitableFontSize);
}
}

View file

@ -9,6 +9,7 @@ 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;
@ -25,6 +26,7 @@ public:
// DDRace
IGraphics::CTextureHandle GetEntities();
IGraphics::CTextureHandle GetSpeedupArrow();
IGraphics::CTextureHandle GetOverlayBottom();
IGraphics::CTextureHandle GetOverlayTop();
@ -34,9 +36,10 @@ 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;
@ -44,7 +47,7 @@ private:
void InitOverlayTextures();
IGraphics::CTextureHandle UploadEntityLayerText(int TextureSize, int YOffset);
void UpdateEntityLayerText(IGraphics::CTextureHandle Texture, int TextureSize, int YOffset, int NumbersPower, int MaxNumber = -1);
void UpdateEntityLayerText(void* pTexBuffer, int ImageColorChannelCount, int TexWidth, int TexHeight, int TextureSize, int YOffset, int NumbersPower, int MaxNumber = -1);
};
#endif

View file

@ -125,71 +125,42 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
}
}
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)
void FillTmpTileSpeedup(SGraphicTile* pTmpTile, SGraphicTileTexureCoords* pTmpTex, bool As3DTextureCoord, unsigned char Flags, unsigned char Index, int x, int y, int Scale, CMapItemGroup* pGroup, short AngleRotate)
{
if(pTmpTex)
{
unsigned char x0 = 0;
unsigned char y0 = 0;
unsigned char x1 = 16;
unsigned char y1 = 0;
unsigned char x2 = 16;
unsigned char y2 = 16;
unsigned char x3 = 0;
unsigned char y3 = 16;
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 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;
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;
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;
if(As3DTextureCoord)
{
pTmpTex->m_TexCoordTopLeft.z = ((float)Index + 0.5f) / 256.f;
pTmpTex->m_TexCoordBottomLeft.z = ((float)Index + 0.5f) / 256.f;
pTmpTex->m_TexCoordTopRight.z = ((float)Index + 0.5f) / 256.f;
pTmpTex->m_TexCoordBottomRight.z = ((float)Index + 0.5f) / 256.f;
}
else
{
pTmpTex->m_TexCoordTopLeft.z = Index;
pTmpTex->m_TexCoordBottomLeft.z = Index;
pTmpTex->m_TexCoordTopRight.z = Index;
pTmpTex->m_TexCoordBottomRight.z = Index;
}
}
//same as in rotate from Graphics()
@ -224,31 +195,18 @@ void FillTmpTileSpeedup(STmpTile* pTmpTile, STmpTileTexCoord* pTmpTex, unsigned
}
}
void FillTmpTile(STmpTile* pTmpTile, STmpTileTexCoord* pTmpTex, unsigned char Flags, unsigned char Index, int x, int y, int Scale, CMapItemGroup* pGroup)
void FillTmpTile(SGraphicTile* pTmpTile, SGraphicTileTexureCoords* pTmpTex, bool As3DTextureCoord, unsigned char Flags, unsigned char Index, int x, int y, int Scale, CMapItemGroup* pGroup)
{
if(pTmpTex)
{
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;
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;
if(Flags&TILEFLAG_VFLIP)
{
@ -256,11 +214,6 @@ void FillTmpTile(STmpTile* pTmpTile, STmpTileTexCoord* pTmpTex, unsigned char Fl
x1 = x3;
x2 = x3;
x3 = x0;
bx0 = bx2;
bx1 = bx3;
bx2 = bx3;
bx3 = bx0;
}
if(Flags&TILEFLAG_HFLIP)
@ -269,11 +222,6 @@ void FillTmpTile(STmpTile* pTmpTile, STmpTileTexCoord* pTmpTex, unsigned char Fl
y2 = y1;
y3 = y1;
y1 = y0;
by0 = by3;
by2 = by1;
by3 = by1;
by1 = by0;
}
if(Flags&TILEFLAG_ROTATE)
@ -288,36 +236,31 @@ void FillTmpTile(STmpTile* pTmpTile, STmpTileTexCoord* pTmpTex, unsigned char Fl
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[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_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_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;
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;
}
}
pTmpTile->m_TopLeft.x = x*Scale;
@ -375,23 +318,23 @@ CMapLayers::STileLayerVisuals::~STileLayerVisuals()
m_BorderRight = NULL;
}
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)
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)
{
if(Index)
{
TmpTiles.push_back(STmpTile());
STmpTile& Tile = TmpTiles.back();
STmpTileTexCoord* pTileTex = NULL;
TmpTiles.push_back(SGraphicTile());
SGraphicTile& Tile = TmpTiles.back();
SGraphicTileTexureCoords* pTileTex = NULL;
if(DoTextureCoords)
{
TmpTileTexCoords.push_back(STmpTileTexCoord());
STmpTileTexCoord& TileTex = TmpTileTexCoords.back();
TmpTileTexCoords.push_back(SGraphicTileTexureCoords());
SGraphicTileTexureCoords& TileTex = TmpTileTexCoords.back();
pTileTex = &TileTex;
}
if(FillSpeedup)
FillTmpTileSpeedup(&Tile, pTileTex, Flags, 0, x, y, 32.f, pGroup, AngleRotate);
FillTmpTileSpeedup(&Tile, pTileTex, As3DTextureCoord, Flags, 0, x, y, 32.f, pGroup, AngleRotate);
else
FillTmpTile(&Tile, pTileTex, Flags, Index, x, y, 32.f, pGroup);
FillTmpTile(&Tile, pTileTex, As3DTextureCoord, Flags, Index, x, y, 32.f, pGroup);
return true;
}
@ -401,8 +344,8 @@ bool AddTile(std::vector<STmpTile>& TmpTiles, std::vector<STmpTileTexCoord>& Tmp
struct STmpQuadVertexTextured
{
float m_X, m_Y, m_CenterX, m_CenterY;
float m_U, m_V;
unsigned char m_R, m_G, m_B, m_A;
float m_U, m_V;
};
struct STmpQuadVertex
@ -433,7 +376,7 @@ void mem_copy_special(void *pDest, void *pSource, size_t Size, size_t Count, siz
void CMapLayers::OnMapLoad()
{
if(!Graphics()->IsBufferingEnabled())
if(!Graphics()->IsTileBufferingEnabled() && !Graphics()->IsQuadBufferingEnabled())
return;
//clear everything and destroy all buffers
if(m_TileLayerVisuals.size() != 0)
@ -459,22 +402,24 @@ void CMapLayers::OnMapLoad()
bool PassedGameLayer = false;
//prepare all visuals for all tile layers
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<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<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);
@ -530,7 +475,7 @@ void CMapLayers::OnMapLoad()
continue;
}
if(pLayer->m_Type == LAYERTYPE_TILES)
if(pLayer->m_Type == LAYERTYPE_TILES && Graphics()->IsTileBufferingEnabled())
{
bool DoTextureCoords = false;
CMapItemLayerTilemap *pTMap = (CMapItemLayerTilemap *)pLayer;
@ -611,6 +556,23 @@ 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)
@ -699,7 +661,7 @@ void CMapLayers::OnMapLoad()
if(IsSpeedupLayer && CurOverlay == 0)
AddAsSpeedup = true;
if(AddTile(tmpTiles, tmpTileTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpTiles, tmpTileTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_TilesOfLayer[y*pTMap->m_Width + x].Draw(true);
//do the border tiles
@ -708,20 +670,20 @@ void CMapLayers::OnMapLoad()
if(y == 0)
{
Visuals.m_BorderTopLeft.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, As3DTextureCoords, 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, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, As3DTextureCoords, 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, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderLeftTiles, tmpBorderLeftTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderLeft[y-1].Draw(true);
}
}
@ -730,21 +692,21 @@ void CMapLayers::OnMapLoad()
if(y == 0)
{
Visuals.m_BorderTopRight.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, As3DTextureCoords, 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, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, As3DTextureCoords, 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, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderRightTiles, tmpBorderRightTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderRight[y-1].Draw(true);
}
}
@ -753,7 +715,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, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderTopTiles, tmpBorderTopTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderTop[x-1].Draw(true);
}
}
@ -762,7 +724,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, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
if(AddTile(tmpBorderBottomTiles, tmpBorderBottomTilesTexCoords, As3DTextureCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderBottom[x-1].Draw(true);
}
}
@ -773,7 +735,7 @@ void CMapLayers::OnMapLoad()
if(IsGameLayer)
{
Visuals.m_BorderKillTile.SetIndexBufferByteOffset((offset_ptr32)(tmpTiles.size() * 6 * sizeof(unsigned int)));
if(AddTile(tmpTiles, tmpTileTexCoords, TILE_DEATH, 0, 0, 0, pGroup, DoTextureCoords))
if(AddTile(tmpTiles, tmpTileTexCoords, As3DTextureCoords, TILE_DEATH, 0, 0, 0, pGroup, DoTextureCoords))
Visuals.m_BorderKillTile.Draw(true);
}
@ -836,60 +798,55 @@ void CMapLayers::OnMapLoad()
float* pTmpTiles = (tmpTiles.size() == 0) ? NULL : (float*)&tmpTiles[0];
unsigned char* pTmpTileTexCoords = (tmpTileTexCoords.size() == 0) ? NULL : (unsigned char*)&tmpTileTexCoords[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)
Visuals.m_BufferContainerIndex = -1;
size_t UploadDataSize = tmpTileTexCoords.size() * sizeof(SGraphicTileTexureCoords) + tmpTiles.size() * sizeof(SGraphicTile);
if(UploadDataSize > 0)
{
mem_copy_special(pUploadData + sizeof(vec2), pTmpTileTexCoords, sizeof(unsigned char) * 2 * 2, tmpTiles.size() * 4, (DoTextureCoords ? (sizeof(vec2)) : 0));
}
char* pUploadData = new char[UploadDataSize];
// first create the buffer object
int BufferObjectIndex = Graphics()->CreateBufferObject(UploadDataSize, pUploadData);
delete[] pUploadData;
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));
}
// 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)
{
// 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);
ContainerInfo.m_Attributes.push_back(SBufferContainerInfo::SAttribute());
pAttr = &ContainerInfo.m_Attributes.back();
SBufferContainerInfo::SAttribute* pAttr = &ContainerInfo.m_Attributes.back();
pAttr->m_DataTypeCount = 2;
pAttr->m_Type = GRAPHICS_TYPE_UNSIGNED_BYTE;
pAttr->m_Type = GRAPHICS_TYPE_FLOAT;
pAttr->m_Normalized = false;
pAttr->m_pOffset = (void*)(sizeof(vec2));
pAttr->m_pOffset = 0;
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;
}
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);
}
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)
else if(pLayer->m_Type == LAYERTYPE_QUADS && Graphics()->IsQuadBufferingEnabled())
{
CMapItemLayerQuads *pQLayer = (CMapItemLayerQuads *)pLayer;
@ -971,6 +928,14 @@ 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());
@ -978,18 +943,10 @@ void CMapLayers::OnMapLoad()
pAttr->m_DataTypeCount = 2;
pAttr->m_Type = GRAPHICS_TYPE_FLOAT;
pAttr->m_Normalized = false;
pAttr->m_pOffset = (void*)(sizeof(float) * 4);
pAttr->m_pOffset = (void*)(sizeof(float) * 4 + sizeof(unsigned char) * 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
@ -1738,7 +1695,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()->IsBufferingEnabled())
if(!Graphics()->IsTileBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE,
@ -1761,7 +1718,8 @@ 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
@ -1791,7 +1749,7 @@ void CMapLayers::OnRender()
{
if(g_Config.m_ClShowQuads)
{
if(!Graphics()->IsBufferingEnabled())
if(!Graphics()->IsQuadBufferingEnabled())
{
//Graphics()->BlendNone();
//RenderTools()->ForceRenderQuads(pQuads, pQLayer->m_NumQuads, LAYERRENDERFLAG_OPAQUE, EnvelopeEval, this, 1.f);
@ -1805,7 +1763,7 @@ void CMapLayers::OnRender()
}
} else
{
if(!Graphics()->IsBufferingEnabled())
if(!Graphics()->IsQuadBufferingEnabled())
{
//Graphics()->BlendNone();
//RenderTools()->RenderQuads(pQuads, pQLayer->m_NumQuads, LAYERRENDERFLAG_OPAQUE, EnvelopeEval, this);
@ -1830,7 +1788,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()->IsBufferingEnabled())
if(!Graphics()->IsTileBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderTilemap(pFrontTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE,
@ -1857,7 +1815,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()->IsBufferingEnabled())
if(!Graphics()->IsTileBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderSwitchmap(pSwitchTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE);
@ -1890,7 +1848,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()->IsBufferingEnabled())
if(!Graphics()->IsTileBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderTelemap(pTeleTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE);
@ -1921,7 +1879,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()->IsBufferingEnabled())
if(!Graphics()->IsTileBufferingEnabled())
{
Graphics()->BlendNone();
RenderTools()->RenderSpeedupmap(pSpeedupTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE);
@ -1935,7 +1893,7 @@ void CMapLayers::OnRender()
// draw arrow -- clamp to the edge of the arrow image
Graphics()->WrapClamp();
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_SPEEDUP_ARROW].m_Id);
Graphics()->TextureSet(m_pImages->GetSpeedupArrow());
RenderTileLayer(TileLayerCounter-3, &Color, pTMap, pGroup);
Graphics()->WrapNormal();
if(g_Config.m_ClTextEntities)
@ -1959,7 +1917,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()->IsBufferingEnabled())
if(!Graphics()->IsTileBufferingEnabled())
{
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_GfxOpenGL3;
static int s_GfxOpenGLVersion = (g_Config.m_GfxOpenGLMajor == 3 && g_Config.m_GfxOpenGLMinor == 3) || g_Config.m_GfxOpenGLMajor >= 4;
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,13 +1033,27 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
g_Config.m_GfxHighDetail ^= 1;
MainView.HSplitTop(20.0f, &Button, &MainView);
if(DoButton_CheckBox(&g_Config.m_GfxOpenGL3, Localize("Use OpenGL 3.3 (experimental)"), g_Config.m_GfxOpenGL3, &Button))
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))
{
CheckSettings = true;
g_Config.m_GfxOpenGL3 ^= 1;
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;
}
}
if(g_Config.m_GfxOpenGL3)
if(IsNewOpenGL)
{
MainView.HSplitTop(20.0f, &Button, &MainView);
if(DoButton_CheckBox(&g_Config.m_GfxUsePreinitBuffer, Localize("Preinit VBO (iGPUs only)"), g_Config.m_GfxUsePreinitBuffer, &Button))
@ -1074,7 +1088,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 == g_Config.m_GfxOpenGL3 &&
s_GfxOpenGLVersion == (int)IsNewOpenGL &&
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()->IsBufferingEnabled())
if(Graphics()->IsQuadContainerBufferingEnabled())
{
int i = m_aFirstPart[Group];