diff --git a/CMakeLists.txt b/CMakeLists.txt index fab196650..b4b8042e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1702,6 +1702,7 @@ if(CLIENT) friends.h ghost.cpp ghost.h + graphics_defines.h graphics_threaded.cpp graphics_threaded.h http.cpp diff --git a/src/engine/client/backend/backend_opengl.cpp b/src/engine/client/backend/backend_opengl.cpp index 9f1b4227b..6a6d749a5 100644 --- a/src/engine/client/backend/backend_opengl.cpp +++ b/src/engine/client/backend/backend_opengl.cpp @@ -23,6 +23,16 @@ #include // ------------ CCommandProcessorFragment_OpenGL +void CCommandProcessorFragment_OpenGL::Cmd_Update_Viewport(const CCommandBuffer::SCommand_Update_Viewport *pCommand) +{ + glViewport(pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height); +} + +void CCommandProcessorFragment_OpenGL::Cmd_Finish(const CCommandBuffer::SCommand_Finish *pCommand) +{ + glFinish(); +} + bool CCommandProcessorFragment_OpenGL::Texture2DTo3D(void *pImageBuffer, int ImageWidth, int ImageHeight, int ImageColorChannelCount, int SplitCountWidth, int SplitCountHeight, void *pTarget3DImageData, int &Target3DImageWidth, int &Target3DImageHeight) { Target3DImageWidth = ImageWidth / SplitCountWidth; @@ -1038,6 +1048,12 @@ bool CCommandProcessorFragment_OpenGL::RunCommand(const CCommandBuffer::SCommand case CCommandBuffer::CMD_SCREENSHOT: Cmd_Screenshot(static_cast(pBaseCommand)); break; + case CCommandBuffer::CMD_UPDATE_VIEWPORT: + Cmd_Update_Viewport(static_cast(pBaseCommand)); + break; + case CCommandBuffer::CMD_FINISH: + Cmd_Finish(static_cast(pBaseCommand)); + break; case CCommandBuffer::CMD_CREATE_BUFFER_OBJECT: Cmd_CreateBufferObject(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_UPDATE_BUFFER_OBJECT: Cmd_UpdateBufferObject(static_cast(pBaseCommand)); break; diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 262902d1d..04ad33f5e 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -8,9 +8,6 @@ #ifndef CONF_BACKEND_OPENGL_ES #include -#else -#define GL_GLEXT_PROTOTYPES 1 -#include "SDL_opengles2.h" #endif #include @@ -166,11 +163,6 @@ void CCommandProcessorFragment_SDL::Cmd_Init(const SCommand_Init *pCommand) SDL_GL_MakeCurrent(m_pWindow, m_GLContext); } -void CCommandProcessorFragment_SDL::Cmd_Update_Viewport(const SCommand_Update_Viewport *pCommand) -{ - glViewport(pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height); -} - void CCommandProcessorFragment_SDL::Cmd_Shutdown(const SCommand_Shutdown *pCommand) { SDL_GL_MakeCurrent(NULL, NULL); @@ -179,9 +171,6 @@ void CCommandProcessorFragment_SDL::Cmd_Shutdown(const SCommand_Shutdown *pComma void CCommandProcessorFragment_SDL::Cmd_Swap(const CCommandBuffer::SCommand_Swap *pCommand) { SDL_GL_SwapWindow(m_pWindow); - - if(pCommand->m_Finish) - glFinish(); } void CCommandProcessorFragment_SDL::Cmd_VSync(const CCommandBuffer::SCommand_VSync *pCommand) @@ -189,11 +178,6 @@ void CCommandProcessorFragment_SDL::Cmd_VSync(const CCommandBuffer::SCommand_VSy *pCommand->m_pRetOk = SDL_GL_SetSwapInterval(pCommand->m_VSync) == 0; } -void CCommandProcessorFragment_SDL::Cmd_Resize(const CCommandBuffer::SCommand_Resize *pCommand) -{ - glViewport(0, 0, pCommand->m_Width, pCommand->m_Height); -} - void CCommandProcessorFragment_SDL::Cmd_VideoModes(const CCommandBuffer::SCommand_VideoModes *pCommand) { SDL_DisplayMode mode; @@ -240,11 +224,9 @@ bool CCommandProcessorFragment_SDL::RunCommand(const CCommandBuffer::SCommand *p { case CCommandBuffer::CMD_SWAP: Cmd_Swap(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_VSYNC: Cmd_VSync(static_cast(pBaseCommand)); break; - case CCommandBuffer::CMD_RESIZE: Cmd_Resize(static_cast(pBaseCommand)); break; case CCommandBuffer::CMD_VIDEOMODES: Cmd_VideoModes(static_cast(pBaseCommand)); break; case CMD_INIT: Cmd_Init(static_cast(pBaseCommand)); break; case CMD_SHUTDOWN: Cmd_Shutdown(static_cast(pBaseCommand)); break; - case CMD_UPDATE_VIEWPORT: Cmd_Update_Viewport(static_cast(pBaseCommand)); break; default: return false; } @@ -923,7 +905,7 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt //TODO: current problem is, that the opengl driver knows about the scaled display, //so the viewport cannot be adjusted for resolutions, that are higher than allowed by the display driver - CCommandProcessorFragment_SDL::SCommand_Update_Viewport CmdSDL; + CCommandBuffer::SCommand_Update_Viewport CmdSDL; CmdSDL.m_X = 0; CmdSDL.m_Y = 0; diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index 2912a9035..c70725a99 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -5,13 +5,7 @@ #include -#ifndef CONF_BACKEND_OPENGL_ES -#include -#else -#define GL_GLEXT_PROTOTYPES 1 -#include "SDL_opengles2.h" -#include -#endif +#include "graphics_defines.h" #ifdef CONF_BACKEND_OPENGL_ES3 #define BACKEND_GL_MODERN_API 1 @@ -137,10 +131,10 @@ protected: { } - GLuint m_Tex; - GLuint m_Tex2DArray; //or 3D texture as fallback - GLuint m_Sampler; - GLuint m_Sampler2DArray; //or 3D texture as fallback + TWGLuint m_Tex; + TWGLuint m_Tex2DArray; //or 3D texture as fallback + TWGLuint m_Sampler; + TWGLuint m_Sampler2DArray; //or 3D texture as fallback int m_LastWrapMode; int m_MemSize; @@ -154,11 +148,11 @@ protected: std::vector m_Textures; std::atomic *m_pTextureMemoryUsage; - GLint m_MaxTexSize; + TWGLint m_MaxTexSize; bool m_Has2DArrayTextures; bool m_Has2DArrayTexturesAsExtension; - GLenum m_2DArrayTarget; + TWGLenum m_2DArrayTarget; bool m_Has3DTextures; bool m_HasMipMaps; bool m_HasNPOTTextures; @@ -234,6 +228,9 @@ protected: virtual void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) {} virtual void Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand); + virtual void Cmd_Update_Viewport(const CCommandBuffer::SCommand_Update_Viewport *pCommand); + virtual void Cmd_Finish(const CCommandBuffer::SCommand_Finish *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) {} @@ -275,13 +272,13 @@ class CCommandProcessorFragment_OpenGL2 : public CCommandProcessorFragment_OpenG struct SBufferObject { - SBufferObject(GLuint BufferObjectID) : + SBufferObject(TWGLuint BufferObjectID) : m_BufferObjectID(BufferObjectID) { m_pData = NULL; m_DataSize = 0; } - GLuint m_BufferObjectID; + TWGLuint m_BufferObjectID; void *m_pData; size_t m_DataSize; }; @@ -329,7 +326,7 @@ protected: bool m_UseMultipleTextureUnits; - GLint m_MaxTextureUnits; + TWGLint m_MaxTextureUnits; struct STextureBound { @@ -374,18 +371,18 @@ class CCommandProcessorFragment_OpenGL3_3 : public CCommandProcessorFragment_Ope CGLSLPrimitiveExProgram *m_pPrimitiveExProgramTexturedRotationless; CGLSLSpriteMultipleProgram *m_pSpriteProgramMultiple; - GLuint m_LastProgramID; + TWGLuint m_LastProgramID; - GLuint m_PrimitiveDrawVertexID[MAX_STREAM_BUFFER_COUNT]; - GLuint m_PrimitiveDrawVertexIDTex3D; - GLuint m_PrimitiveDrawBufferID[MAX_STREAM_BUFFER_COUNT]; - GLuint m_PrimitiveDrawBufferIDTex3D; + TWGLuint m_PrimitiveDrawVertexID[MAX_STREAM_BUFFER_COUNT]; + TWGLuint m_PrimitiveDrawVertexIDTex3D; + TWGLuint m_PrimitiveDrawBufferID[MAX_STREAM_BUFFER_COUNT]; + TWGLuint m_PrimitiveDrawBufferIDTex3D; - GLuint m_LastIndexBufferBound[MAX_STREAM_BUFFER_COUNT]; + TWGLuint m_LastIndexBufferBound[MAX_STREAM_BUFFER_COUNT]; int m_LastStreamBuffer; - GLuint m_QuadDrawIndexBufferID; + TWGLuint m_QuadDrawIndexBufferID; unsigned int m_CurrentIndicesInBuffer; void DestroyBufferContainer(int Index, bool DeleteBOs = true); @@ -396,13 +393,13 @@ class CCommandProcessorFragment_OpenGL3_3 : public CCommandProcessorFragment_Ope { SBufferContainer() : m_VertArrayID(0), m_LastIndexBufferBound(0) {} - GLuint m_VertArrayID; - GLuint m_LastIndexBufferBound; + TWGLuint m_VertArrayID; + TWGLuint m_LastIndexBufferBound; SBufferContainerInfo m_ContainerInfo; }; std::vector m_BufferContainers; - std::vector m_BufferObjectIndices; + std::vector m_BufferObjectIndices; CCommandBuffer::SColorf m_ClearColor; @@ -461,7 +458,6 @@ public: enum { CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_SDL, - CMD_UPDATE_VIEWPORT, CMD_SHUTDOWN, }; @@ -473,16 +469,6 @@ public: SDL_GLContext m_GLContext; }; - struct SCommand_Update_Viewport : public CCommandBuffer::SCommand - { - SCommand_Update_Viewport() : - SCommand(CMD_UPDATE_VIEWPORT) {} - int m_X; - int m_Y; - int m_Width; - int m_Height; - }; - struct SCommand_Shutdown : public CCommandBuffer::SCommand { SCommand_Shutdown() : @@ -491,11 +477,9 @@ public: private: void Cmd_Init(const SCommand_Init *pCommand); - void Cmd_Update_Viewport(const SCommand_Update_Viewport *pCommand); void Cmd_Shutdown(const SCommand_Shutdown *pCommand); void Cmd_Swap(const CCommandBuffer::SCommand_Swap *pCommand); void Cmd_VSync(const CCommandBuffer::SCommand_VSync *pCommand); - void Cmd_Resize(const CCommandBuffer::SCommand_Resize *pCommand); void Cmd_VideoModes(const CCommandBuffer::SCommand_VideoModes *pCommand); public: diff --git a/src/engine/client/graphics_defines.h b/src/engine/client/graphics_defines.h new file mode 100644 index 000000000..991b07f6e --- /dev/null +++ b/src/engine/client/graphics_defines.h @@ -0,0 +1,12 @@ +#ifndef ENGINE_CLIENT_GRAPHICS_DEFINES_H +#define ENGINE_CLIENT_GRAPHICS_DEFINES_H + +#include +#include + +typedef uint32_t TWGLuint; +typedef int32_t TWGLint; +typedef uint32_t TWGLenum; +typedef uint8_t TWGLubyte; + +#endif diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index c66506a32..ee7e906d3 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -2332,7 +2332,9 @@ void CGraphics_Threaded::Resize(int w, int h, bool SetWindowSize) if(m_ScreenWidth > 21 * m_ScreenHeight / 9) m_ScreenWidth = 21 * m_ScreenHeight / 9; - CCommandBuffer::SCommand_Resize Cmd; + CCommandBuffer::SCommand_Update_Viewport Cmd; + Cmd.m_X = 0; + Cmd.m_Y = 0; Cmd.m_Width = m_ScreenWidth; Cmd.m_Height = m_ScreenHeight; @@ -2414,13 +2416,24 @@ void CGraphics_Threaded::Swap() m_DoScreenshot = false; } - // add swap command - CCommandBuffer::SCommand_Swap Cmd; - Cmd.m_Finish = g_Config.m_GfxFinish; - if(!AddCmd( - Cmd, [] { return true; }, "failed to add swap command")) { - return; + // add swap command + CCommandBuffer::SCommand_Swap Cmd; + if(!AddCmd( + Cmd, [] { return true; }, "failed to add swap command")) + { + return; + } + } + + if(g_Config.m_GfxFinish) + { + CCommandBuffer::SCommand_Finish Cmd; + if(!AddCmd( + Cmd, [] { return true; }, "failed to add finish command")) + { + return; + } } // kick the command buffer diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 62d46a3f4..6a9943471 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -119,12 +119,13 @@ public: // swap CMD_SWAP, + CMD_FINISH, // misc CMD_VSYNC, CMD_SCREENSHOT, CMD_VIDEOMODES, - CMD_RESIZE, + CMD_UPDATE_VIEWPORT, }; @@ -504,8 +505,12 @@ public: { SCommand_Swap() : SCommand(CMD_SWAP) {} + }; - int m_Finish; + struct SCommand_Finish : public SCommand + { + SCommand_Finish() : + SCommand(CMD_FINISH) {} }; struct SCommand_VSync : public SCommand @@ -517,11 +522,13 @@ public: bool *m_pRetOk; }; - struct SCommand_Resize : public SCommand + struct SCommand_Update_Viewport : public SCommand { - SCommand_Resize() : - SCommand(CMD_RESIZE) {} + SCommand_Update_Viewport() : + SCommand(CMD_UPDATE_VIEWPORT) {} + int m_X; + int m_Y; int m_Width; int m_Height; }; diff --git a/src/engine/client/opengl_sl.cpp b/src/engine/client/opengl_sl.cpp index 2e35fac90..2d50565fc 100644 --- a/src/engine/client/opengl_sl.cpp +++ b/src/engine/client/opengl_sl.cpp @@ -7,6 +7,12 @@ #include +#ifndef CONF_BACKEND_OPENGL_ES +#include +#else +#include +#endif + bool CGLSL::LoadShader(CGLSLCompiler *pCompiler, IStorage *pStorage, const char *pFile, int Type) { if(m_IsLoaded) @@ -88,7 +94,7 @@ bool CGLSL::LoadShader(CGLSLCompiler *pCompiler, IStorage *pStorage, const char ShaderCode[i] = Lines[i].c_str(); } - GLuint shader = glCreateShader(Type); + TWGLuint shader = glCreateShader(Type); glShaderSource(shader, Lines.size(), ShaderCode, NULL); glCompileShader(shader); @@ -102,7 +108,7 @@ bool CGLSL::LoadShader(CGLSLCompiler *pCompiler, IStorage *pStorage, const char { char buff[3000]; - GLint maxLength = 0; + TWGLint maxLength = 0; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); glGetShaderInfoLog(shader, maxLength, &maxLength, buff); @@ -135,7 +141,7 @@ bool CGLSL::IsLoaded() return m_IsLoaded; } -GLuint CGLSL::GetShaderID() +TWGLuint CGLSL::GetShaderID() { return m_ShaderID; } diff --git a/src/engine/client/opengl_sl.h b/src/engine/client/opengl_sl.h index fceee29f1..12ec83da4 100644 --- a/src/engine/client/opengl_sl.h +++ b/src/engine/client/opengl_sl.h @@ -3,12 +3,7 @@ #include -#ifndef CONF_BACKEND_OPENGL_ES -#include -#else -#define GL_GLEXT_PROTOTYPES 1 -#include "SDL_opengles2.h" -#endif +#include "graphics_defines.h" #include #include @@ -22,13 +17,13 @@ public: void DeleteShader(); bool IsLoaded(); - GLuint GetShaderID(); + TWGLuint GetShaderID(); CGLSL(); virtual ~CGLSL(); private: - GLuint m_ShaderID; + TWGLuint m_ShaderID; int m_Type; bool m_IsLoaded; }; diff --git a/src/engine/client/opengl_sl_program.cpp b/src/engine/client/opengl_sl_program.cpp index e521a254c..8687cbe9b 100644 --- a/src/engine/client/opengl_sl_program.cpp +++ b/src/engine/client/opengl_sl_program.cpp @@ -2,6 +2,12 @@ #include "opengl_sl.h" #include +#ifndef CONF_BACKEND_OPENGL_ES +#include +#else +#include +#endif + void CGLSLProgram::CreateProgram() { m_ProgramID = glCreateProgram(); @@ -33,7 +39,7 @@ void CGLSLProgram::DetachShader(CGLSL *pShader) } } -void CGLSLProgram::DetachShaderByID(GLuint ShaderID) +void CGLSLProgram::DetachShaderByID(TWGLuint ShaderID) { glDetachShader(m_ProgramID, ShaderID); } @@ -60,7 +66,7 @@ void CGLSLProgram::LinkProgram() void CGLSLProgram::DetachAllShaders() { - GLuint aShaders[100]; + TWGLuint aShaders[100]; GLsizei ReturnedCount = 0; while(1) { @@ -120,7 +126,7 @@ void CGLSLProgram::UseProgram() glUseProgram(m_ProgramID); } -GLuint CGLSLProgram::GetProgramID() +TWGLuint CGLSLProgram::GetProgramID() { return m_ProgramID; } diff --git a/src/engine/client/opengl_sl_program.h b/src/engine/client/opengl_sl_program.h index 76cc64395..9aff045b5 100644 --- a/src/engine/client/opengl_sl_program.h +++ b/src/engine/client/opengl_sl_program.h @@ -3,12 +3,7 @@ #include -#ifndef CONF_BACKEND_OPENGL_ES -#include -#else -#define GL_GLEXT_PROTOTYPES 1 -#include "SDL_opengles2.h" -#endif +#include class CGLSL; @@ -22,10 +17,10 @@ public: void LinkProgram(); void UseProgram(); - GLuint GetProgramID(); + TWGLuint GetProgramID(); void DetachShader(CGLSL *pShader); - void DetachShaderByID(GLuint ShaderID); + void DetachShaderByID(TWGLuint ShaderID); void DetachAllShaders(); //Support various types @@ -43,7 +38,7 @@ public: virtual ~CGLSLProgram(); protected: - GLuint m_ProgramID; + TWGLuint m_ProgramID; bool m_IsLinked; }; diff --git a/src/engine/client/video.cpp b/src/engine/client/video.cpp index 00f74e0eb..40c0fc212 100644 --- a/src/engine/client/video.cpp +++ b/src/engine/client/video.cpp @@ -6,6 +6,12 @@ #include "video.h" +#ifndef CONF_BACKEND_OPENGL_ES +#include +#else +#include +#endif + // This code is mostly stolen from https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/muxing.c #define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */ @@ -95,7 +101,7 @@ void CVideo::Start() m_pFormat = m_pFormatContext->oformat; size_t NVals = FORMAT_NCHANNELS * m_Width * m_Height; - m_pPixels = (uint8_t *)malloc(NVals * sizeof(GLubyte)); + m_pPixels = (uint8_t *)malloc(NVals * sizeof(TWGLubyte)); m_pRGB = (uint8_t *)malloc(NVals * sizeof(uint8_t)); /* Add the audio and video streams using the default format codecs diff --git a/src/engine/client/video.h b/src/engine/client/video.h index 62a91449c..78168d50a 100644 --- a/src/engine/client/video.h +++ b/src/engine/client/video.h @@ -3,12 +3,7 @@ #include -#if defined(CONF_BACKEND_OPENGL_ES) -#define GL_GLEXT_PROTOTYPES -#include -#define glOrtho glOrthof -#else -#include "SDL_opengl.h" +#include "graphics_defines.h" extern "C" { #include @@ -107,7 +102,7 @@ private: bool m_HasAudio; - GLubyte *m_pPixels; + TWGLubyte *m_pPixels; OutputStream m_VideoStream; OutputStream m_AudioStream;