2018-07-06 14:11:38 +00:00
# ifndef ENGINE_CLIENT_BACKEND_SDL_H
# define ENGINE_CLIENT_BACKEND_SDL_H
2012-01-03 20:39:10 +00:00
# include "SDL.h"
Make sure headers compile standalone
Not planning to do this automatically, but at least cleaning it up once
provides some benefit. Every header should include what it uses.
$ for i in src/**/*.h; do j=${i#"src/"}; echo $j; echo "#include <$j>\nint main() { return 0; }" | /usr/bin/c++ -DCONF_OPENSSL -DCONF_SQL -DCONF_VIDEORECORDER -DCONF_WAVPACK_CLOSE_FILE -DCONF_WAVPACK_OPEN_FILE_INPUT_EX -DGAME_RELEASE_VERSION=\"15.0.5\" -DGLEW_STATIC -D_FORTIFY_SOURCE=2 -I/usr/include/freetype2 -I/usr/include/opus -I/usr/include/SDL2 -I/usr/include/wavpack -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -Isrc -I/usr/include/mysql -I/home/deen/sys/include/ -O2 -g -DNDEBUG -fdiagnostics-color=always -fstack-protector-all -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wformat=2 -Wno-nullability-completeness -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -std=gnu++11 -o /dev/null -x c++ -; done
Ignored: tuning.h, variables.h, config_common.h, mapitems_ex_types.h, mapbugs_list.h, protocol7.h, teehistorian_ex_chunks.h, protocol_ex_msgs.h, config.h, config_variables.h, external, keynames.h
2020-09-26 08:23:33 +00:00
# include "SDL_opengl.h"
2012-01-03 20:39:10 +00:00
# include "graphics_threaded.h"
Make sure headers compile standalone
Not planning to do this automatically, but at least cleaning it up once
provides some benefit. Every header should include what it uses.
$ for i in src/**/*.h; do j=${i#"src/"}; echo $j; echo "#include <$j>\nint main() { return 0; }" | /usr/bin/c++ -DCONF_OPENSSL -DCONF_SQL -DCONF_VIDEORECORDER -DCONF_WAVPACK_CLOSE_FILE -DCONF_WAVPACK_OPEN_FILE_INPUT_EX -DGAME_RELEASE_VERSION=\"15.0.5\" -DGLEW_STATIC -D_FORTIFY_SOURCE=2 -I/usr/include/freetype2 -I/usr/include/opus -I/usr/include/SDL2 -I/usr/include/wavpack -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -Isrc -I/usr/include/mysql -I/home/deen/sys/include/ -O2 -g -DNDEBUG -fdiagnostics-color=always -fstack-protector-all -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wformat=2 -Wno-nullability-completeness -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -std=gnu++11 -o /dev/null -x c++ -; done
Ignored: tuning.h, variables.h, config_common.h, mapitems_ex_types.h, mapbugs_list.h, protocol7.h, teehistorian_ex_chunks.h, protocol_ex_msgs.h, config.h, config_variables.h, external, keynames.h
2020-09-26 08:23:33 +00:00
# include <base/tl/threading.h>
2020-08-29 10:10:38 +00:00
# include <atomic>
2020-09-26 19:41:58 +00:00
# if defined(CONF_PLATFORM_MACOSX)
# include <objc/objc-runtime.h>
2012-01-03 21:49:31 +00:00
2020-09-26 19:41:58 +00:00
class CAutoreleasePool
{
private :
id m_Pool ;
2012-08-26 18:02:04 +00:00
2020-09-26 19:41:58 +00:00
public :
CAutoreleasePool ( )
{
Class NSAutoreleasePoolClass = ( Class ) objc_getClass ( " NSAutoreleasePool " ) ;
m_Pool = class_createInstance ( NSAutoreleasePoolClass , 0 ) ;
SEL selector = sel_registerName ( " init " ) ;
( ( id ( * ) ( id , SEL ) ) objc_msgSend ) ( m_Pool , selector ) ;
}
2012-08-26 18:02:04 +00:00
2020-09-26 19:41:58 +00:00
~ CAutoreleasePool ( )
{
SEL selector = sel_registerName ( " drain " ) ;
( ( id ( * ) ( id , SEL ) ) objc_msgSend ) ( m_Pool , selector ) ;
}
} ;
2012-01-03 20:39:10 +00:00
# endif
// basic threaded backend, abstract, missing init and shutdown functions
class CGraphicsBackend_Threaded : public IGraphicsBackend
{
public :
2018-07-10 09:29:02 +00:00
// constructed on the main thread, the rest of the functions is run on the render thread
2012-01-03 20:39:10 +00:00
class ICommandProcessor
{
public :
virtual ~ ICommandProcessor ( ) { }
virtual void RunBuffer ( CCommandBuffer * pBuffer ) = 0 ;
} ;
CGraphicsBackend_Threaded ( ) ;
virtual void RunBuffer ( CCommandBuffer * pBuffer ) ;
virtual bool IsIdle ( ) const ;
virtual void WaitForIdle ( ) ;
2015-07-09 00:08:14 +00:00
2012-01-03 20:39:10 +00:00
protected :
void StartProcessor ( ICommandProcessor * pProcessor ) ;
void StopProcessor ( ) ;
private :
ICommandProcessor * m_pProcessor ;
2020-09-26 19:41:58 +00:00
CCommandBuffer * volatile m_pBuffer ;
2012-01-03 20:39:10 +00:00
volatile bool m_Shutdown ;
semaphore m_Activity ;
semaphore m_BufferDone ;
void * m_pThread ;
static void ThreadFunc ( void * pUser ) ;
} ;
// takes care of implementation independent operations
class CCommandProcessorFragment_General
{
void Cmd_Nop ( ) ;
void Cmd_Signal ( const CCommandBuffer : : SCommand_Signal * pCommand ) ;
2020-09-26 19:41:58 +00:00
2012-01-03 20:39:10 +00:00
public :
2020-09-26 19:41:58 +00:00
bool RunCommand ( const CCommandBuffer : : SCommand * pBaseCommand ) ;
2012-01-03 20:39:10 +00:00
} ;
2020-08-29 10:10:38 +00:00
struct SBackendCapabilites
{
bool m_TileBuffering ;
bool m_QuadBuffering ;
bool m_TextBuffering ;
bool m_QuadContainerBuffering ;
bool m_MipMapping ;
bool m_NPOTTextures ;
bool m_3DTextures ;
bool m_2DArrayTextures ;
bool m_2DArrayTexturesAsExtension ;
bool m_ShaderSupport ;
int m_ContextMajor ;
int m_ContextMinor ;
int m_ContextPatch ;
} ;
class CGLSLProgram ;
class CGLSLTWProgram ;
class CGLSLPrimitiveProgram ;
class CGLSLQuadProgram ;
class CGLSLTileProgram ;
class CGLSLTextProgram ;
class CGLSLSpriteProgram ;
class CGLSLSpriteMultipleProgram ;
2012-01-03 20:39:10 +00:00
// takes care of opengl related rendering
class CCommandProcessorFragment_OpenGL
{
2020-08-29 10:10:38 +00:00
protected :
2012-10-06 21:31:02 +00:00
struct CTexture
{
2020-09-26 19:41:58 +00:00
CTexture ( ) :
m_Tex ( 0 ) , m_Tex2DArray ( 0 ) , m_Sampler ( 0 ) , m_Sampler2DArray ( 0 ) { }
2012-10-06 21:31:02 +00:00
GLuint m_Tex ;
2020-08-29 10:10:38 +00:00
GLuint m_Tex2DArray ; //or 3D texture as fallback
GLuint m_Sampler ;
GLuint m_Sampler2DArray ; //or 3D texture as fallback
int m_LastWrapMode ;
2012-10-06 21:31:02 +00:00
int m_MemSize ;
2018-03-13 20:44:58 +00:00
int m_Width ;
int m_Height ;
int m_RescaleCount ;
2020-08-29 10:10:38 +00:00
float m_ResizeWidth ;
float m_ResizeHeight ;
2012-10-06 21:31:02 +00:00
} ;
CTexture m_aTextures [ CCommandBuffer : : MAX_TEXTURES ] ;
2020-08-29 10:10:38 +00:00
std : : atomic < int > * m_pTextureMemoryUsage ;
2012-10-06 21:31:02 +00:00
2018-03-13 20:44:58 +00:00
GLint m_MaxTexSize ;
2020-08-29 10:10:38 +00:00
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 ;
2020-09-26 19:41:58 +00:00
2012-10-06 21:31:02 +00:00
public :
enum
{
CMD_INIT = CCommandBuffer : : CMDGROUP_PLATFORM_OPENGL ,
2020-08-29 10:10:38 +00:00
CMD_SHUTDOWN = CMD_INIT + 1 ,
2012-10-06 21:31:02 +00:00
} ;
struct SCommand_Init : public CCommandBuffer : : SCommand
{
2020-09-26 19:41:58 +00:00
SCommand_Init ( ) :
SCommand ( CMD_INIT ) { }
2020-08-29 10:10:38 +00:00
class IStorage * m_pStorage ;
std : : atomic < int > * m_pTextureMemoryUsage ;
2020-08-29 15:44:23 +00:00
SBackendCapabilites * m_pCapabilities ;
int * m_pInitError ;
2020-08-22 06:09:10 +00:00
} ;
2020-08-29 10:10:38 +00:00
struct SCommand_Shutdown : public CCommandBuffer : : SCommand
{
2020-09-26 19:41:58 +00:00
SCommand_Shutdown ( ) :
SCommand ( CMD_SHUTDOWN ) { }
2020-08-29 10:10:38 +00:00
} ;
protected :
void SetState ( const CCommandBuffer : : SState & State , bool Use2DArrayTexture = false ) ;
virtual bool IsNewApi ( ) { return false ; }
2020-09-03 08:46:15 +00:00
void DestroyTexture ( int Slot ) ;
2020-08-29 10:10:38 +00:00
2012-01-03 20:39:10 +00:00
static int TexFormatToOpenGLFormat ( int TexFormat ) ;
2020-08-29 10:10:38 +00:00
static int TexFormatToImageColorChannelCount ( int TexFormat ) ;
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 ) ;
2020-09-21 03:57:54 +00:00
virtual void Cmd_RenderTex3D ( const CCommandBuffer : : SCommand_RenderTex3D * pCommand ) { }
2020-08-29 10:10:38 +00:00
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 ) { }
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
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 ) { }
2020-09-26 19:41:58 +00:00
2020-08-22 06:09:10 +00:00
public :
2020-08-26 18:01:32 +00:00
CCommandProcessorFragment_OpenGL ( ) ;
2020-08-22 06:09:10 +00:00
2020-09-26 19:41:58 +00:00
bool RunCommand ( const CCommandBuffer : : SCommand * pBaseCommand ) ;
2020-08-22 06:09:10 +00:00
} ;
2020-09-26 19:41:58 +00:00
class CCommandProcessorFragment_OpenGL2 : public CCommandProcessorFragment_OpenGL
{
2020-08-29 10:10:38 +00:00
struct SBufferContainer
{
SBufferContainer ( ) { }
SBufferContainerInfo m_ContainerInfo ;
} ;
std : : vector < SBufferContainer > m_BufferContainers ;
2020-08-26 18:01:32 +00:00
2020-08-29 10:10:38 +00:00
GL_SVertexTex3D m_aStreamVertices [ 1024 * 4 ] ;
2020-08-22 06:09:10 +00:00
2020-08-29 10:10:38 +00:00
struct SBufferObject
2020-08-26 18:01:32 +00:00
{
2020-09-26 19:41:58 +00:00
SBufferObject ( GLuint BufferObjectID ) :
m_BufferObjectID ( BufferObjectID )
2020-08-29 10:10:38 +00:00
{
m_pData = NULL ;
m_DataSize = 0 ;
}
GLuint m_BufferObjectID ;
2020-09-26 19:41:58 +00:00
void * m_pData ;
2020-08-29 10:10:38 +00:00
size_t m_DataSize ;
} ;
2017-09-02 13:24:07 +00:00
2020-08-29 10:10:38 +00:00
std : : vector < SBufferObject > m_BufferObjectIndices ;
2020-08-26 18:01:32 +00:00
2020-09-05 08:22:24 +00:00
bool DoAnalyzeStep ( size_t StepN , size_t CheckCount , size_t VerticesCount , uint8_t aFakeTexture [ ] , size_t SingleImageSize ) ;
2020-08-29 15:44:23 +00:00
bool IsTileMapAnalysisSucceeded ( ) ;
2020-09-26 19:41:58 +00:00
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 ) ;
2020-08-29 10:10:38 +00:00
void UseProgram ( CGLSLTWProgram * pProgram ) ;
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
protected :
void SetState ( const CCommandBuffer : : SState & State , CGLSLTWProgram * pProgram , bool Use2DArrayTextures = false ) ;
void Cmd_Init ( const SCommand_Init * pCommand ) override ;
2020-09-21 03:57:54 +00:00
void Cmd_RenderTex3D ( const CCommandBuffer : : SCommand_RenderTex3D * pCommand ) override ;
2020-08-29 10:10:38 +00:00
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 ;
2020-09-26 19:41:58 +00:00
void Cmd_RenderTileLayer ( const CCommandBuffer : : SCommand_RenderTileLayer * pCommand ) override ;
2020-08-29 10:10:38 +00:00
void Cmd_RenderBorderTile ( const CCommandBuffer : : SCommand_RenderBorderTile * pCommand ) override ;
void Cmd_RenderBorderTileLine ( const CCommandBuffer : : SCommand_RenderBorderTileLine * pCommand ) override ;
2020-08-19 05:05:51 +00:00
2020-08-26 18:01:32 +00:00
CGLSLTileProgram * m_pTileProgram ;
CGLSLTileProgram * m_pTileProgramTextured ;
2020-08-29 10:10:38 +00:00
CGLSLPrimitiveProgram * m_pPrimitive3DProgram ;
CGLSLPrimitiveProgram * m_pPrimitive3DProgramTextured ;
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
bool m_UseMultipleTextureUnits ;
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
GLint m_MaxTextureUnits ;
2020-09-26 19:41:58 +00:00
struct STextureBound
{
2020-08-29 10:10:38 +00:00
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
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
bool IsAndUpdateTextureSlotBound ( int IDX , int Slot , bool Is2DArray = false ) ;
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
public :
2020-09-26 19:41:58 +00:00
CCommandProcessorFragment_OpenGL2 ( ) :
CCommandProcessorFragment_OpenGL ( ) , m_UseMultipleTextureUnits ( false ) { }
2020-08-29 10:10:38 +00:00
} ;
2020-09-26 19:41:58 +00:00
class CCommandProcessorFragment_OpenGL3 : public CCommandProcessorFragment_OpenGL2
{
2020-08-29 10:10:38 +00:00
} ;
# 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 ;
2018-03-13 20:44:58 +00:00
CGLSLQuadProgram * m_pQuadProgram ;
CGLSLQuadProgram * m_pQuadProgramTextured ;
CGLSLTextProgram * m_pTextProgram ;
CGLSLSpriteProgram * m_pSpriteProgram ;
CGLSLSpriteMultipleProgram * m_pSpriteProgramMultiple ;
GLuint m_LastProgramID ;
GLuint m_PrimitiveDrawVertexID [ MAX_STREAM_BUFFER_COUNT ] ;
2020-09-21 03:57:54 +00:00
GLuint m_PrimitiveDrawVertexIDTex3D ;
2018-03-13 20:44:58 +00:00
GLuint m_PrimitiveDrawBufferID [ MAX_STREAM_BUFFER_COUNT ] ;
2020-09-21 03:57:54 +00:00
GLuint m_PrimitiveDrawBufferIDTex3D ;
2018-03-13 20:44:58 +00:00
GLuint m_LastIndexBufferBound [ MAX_STREAM_BUFFER_COUNT ] ;
int m_LastStreamBuffer ;
2020-09-26 19:41:58 +00:00
2017-09-27 10:16:34 +00:00
GLuint m_QuadDrawIndexBufferID ;
unsigned int m_CurrentIndicesInBuffer ;
2020-08-29 10:10:38 +00:00
2018-03-13 20:44:58 +00:00
void DestroyBufferContainer ( int Index , bool DeleteBOs = true ) ;
2020-09-26 19:41:58 +00:00
2017-09-27 10:16:34 +00:00
void AppendIndices ( unsigned int NewIndicesCount ) ;
2020-09-26 19:41:58 +00:00
2018-03-13 20:44:58 +00:00
struct SBufferContainer
{
2020-09-26 19:41:58 +00:00
SBufferContainer ( ) :
m_VertArrayID ( 0 ) , m_LastIndexBufferBound ( 0 ) { }
2017-09-12 18:07:38 +00:00
GLuint m_VertArrayID ;
2017-10-23 16:02:18 +00:00
GLuint m_LastIndexBufferBound ;
2018-03-13 20:44:58 +00:00
SBufferContainerInfo m_ContainerInfo ;
2017-09-12 18:07:38 +00:00
} ;
2018-03-13 20:44:58 +00:00
std : : vector < SBufferContainer > m_BufferContainers ;
std : : vector < GLuint > m_BufferObjectIndices ;
2020-09-26 19:41:58 +00:00
2017-09-27 10:16:34 +00:00
CCommandBuffer : : SColorf m_ClearColor ;
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
protected :
static int TexFormatToNewOpenGLFormat ( int TexFormat ) ;
bool IsNewApi ( ) override { return true ; }
2020-08-26 18:01:32 +00:00
2018-03-13 20:44:58 +00:00
void UseProgram ( CGLSLTWProgram * pProgram ) ;
2020-09-21 03:57:54 +00:00
void UploadStreamBufferData ( unsigned int PrimitiveType , const void * pVertices , size_t VertSize , unsigned int PrimitiveCount , bool AsTex3D = false ) ;
void RenderText ( const CCommandBuffer : : SState & State , int DrawNum , int TextTextureIndex , int TextOutlineTextureIndex , int TextureSize , const float * pTextColor , const float * pTextOutlineColor ) ;
2017-09-02 13:24:07 +00:00
2020-08-29 10:10:38 +00:00
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 ;
2020-09-21 03:57:54 +00:00
void Cmd_RenderTex3D ( const CCommandBuffer : : SCommand_RenderTex3D * pCommand ) override ;
2020-08-29 10:10:38 +00:00
void Cmd_Screenshot ( const CCommandBuffer : : SCommand_Screenshot * 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 ;
2020-09-26 19:41:58 +00:00
void Cmd_RenderTileLayer ( const CCommandBuffer : : SCommand_RenderTileLayer * pCommand ) override ;
2020-08-29 10:10:38 +00:00
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 ;
2020-09-26 19:41:58 +00:00
2017-09-02 13:24:07 +00:00
public :
2020-08-29 10:10:38 +00:00
CCommandProcessorFragment_OpenGL3_3 ( ) = default ;
2017-09-02 13:24:07 +00:00
} ;
2012-01-03 20:39:10 +00:00
// takes care of sdl related commands
class CCommandProcessorFragment_SDL
{
// SDL stuff
2015-08-24 20:46:28 +00:00
SDL_Window * m_pWindow ;
SDL_GLContext m_GLContext ;
2020-09-26 19:41:58 +00:00
2012-01-03 20:39:10 +00:00
public :
enum
{
2012-10-06 21:31:02 +00:00
CMD_INIT = CCommandBuffer : : CMDGROUP_PLATFORM_SDL ,
2017-10-23 16:02:18 +00:00
CMD_UPDATE_VIEWPORT ,
2012-01-03 20:39:10 +00:00
CMD_SHUTDOWN ,
} ;
struct SCommand_Init : public CCommandBuffer : : SCommand
{
2020-09-26 19:41:58 +00:00
SCommand_Init ( ) :
SCommand ( CMD_INIT ) { }
2015-08-24 20:46:28 +00:00
SDL_Window * m_pWindow ;
SDL_GLContext m_GLContext ;
2020-08-29 15:44:23 +00:00
SBackendCapabilites * m_pCapabilities ;
2020-08-29 10:10:38 +00:00
2020-08-29 15:44:23 +00:00
int * m_pInitError ;
2020-08-29 10:10:38 +00:00
int m_RequestedMajor ;
int m_RequestedMinor ;
int m_RequestedPatch ;
int m_GlewMajor ;
int m_GlewMinor ;
int m_GlewPatch ;
2012-01-03 20:39:10 +00:00
} ;
2017-10-23 16:02:18 +00:00
struct SCommand_Update_Viewport : public CCommandBuffer : : SCommand
{
2020-09-26 19:41:58 +00:00
SCommand_Update_Viewport ( ) :
SCommand ( CMD_UPDATE_VIEWPORT ) { }
2017-10-23 16:02:18 +00:00
int m_X ;
int m_Y ;
int m_Width ;
int m_Height ;
} ;
2012-01-03 20:39:10 +00:00
struct SCommand_Shutdown : public CCommandBuffer : : SCommand
{
2020-09-26 19:41:58 +00:00
SCommand_Shutdown ( ) :
SCommand ( CMD_SHUTDOWN ) { }
2012-01-03 20:39:10 +00:00
} ;
private :
void Cmd_Init ( const SCommand_Init * pCommand ) ;
2017-12-02 21:19:57 +00:00
void Cmd_Update_Viewport ( const SCommand_Update_Viewport * pCommand ) ;
2012-01-03 20:39:10 +00:00
void Cmd_Shutdown ( const SCommand_Shutdown * pCommand ) ;
void Cmd_Swap ( const CCommandBuffer : : SCommand_Swap * pCommand ) ;
2016-04-29 22:34:12 +00:00
void Cmd_VSync ( const CCommandBuffer : : SCommand_VSync * pCommand ) ;
2016-04-30 15:59:58 +00:00
void Cmd_Resize ( const CCommandBuffer : : SCommand_Resize * pCommand ) ;
2012-01-03 20:39:10 +00:00
void Cmd_VideoModes ( const CCommandBuffer : : SCommand_VideoModes * pCommand ) ;
2020-09-26 19:41:58 +00:00
2012-01-03 20:39:10 +00:00
public :
CCommandProcessorFragment_SDL ( ) ;
bool RunCommand ( const CCommandBuffer : : SCommand * pBaseCommand ) ;
} ;
// command processor impelementation, uses the fragments to combine into one processor
class CCommandProcessor_SDL_OpenGL : public CGraphicsBackend_Threaded : : ICommandProcessor
{
2020-08-29 10:10:38 +00:00
CCommandProcessorFragment_OpenGL * m_pOpenGL ;
2015-07-09 00:08:14 +00:00
CCommandProcessorFragment_SDL m_SDL ;
CCommandProcessorFragment_General m_General ;
2020-09-26 19:41:58 +00:00
2015-07-09 00:08:14 +00:00
public :
2020-08-29 10:10:38 +00:00
CCommandProcessor_SDL_OpenGL ( int OpenGLMajor , int OpenGLMinor , int OpenGLPatch ) ;
2012-01-03 20:39:10 +00:00
virtual void RunBuffer ( CCommandBuffer * pBuffer ) ;
} ;
// graphics backend implemented with SDL and OpenGL
class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded
{
2015-08-24 20:46:28 +00:00
SDL_Window * m_pWindow ;
SDL_GLContext m_GLContext ;
2012-01-03 20:39:10 +00:00
ICommandProcessor * m_pProcessor ;
2020-08-29 10:10:38 +00:00
std : : atomic < int > m_TextureMemoryUsage ;
2016-04-29 22:34:12 +00:00
int m_NumScreens ;
2020-08-29 10:10:38 +00:00
SBackendCapabilites m_Capabilites ;
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
bool m_UseNewOpenGL ;
2020-09-26 19:41:58 +00:00
2012-01-03 20:39:10 +00:00
public :
2017-12-02 21:19:57 +00:00
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 ) ;
2012-01-03 20:39:10 +00:00
virtual int Shutdown ( ) ;
2012-10-06 21:31:02 +00:00
virtual int MemoryUsage ( ) const ;
2016-04-29 22:34:12 +00:00
virtual int GetNumScreens ( ) const { return m_NumScreens ; }
2012-01-03 20:39:10 +00:00
virtual void Minimize ( ) ;
virtual void Maximize ( ) ;
2016-04-29 19:07:10 +00:00
virtual bool Fullscreen ( bool State ) ;
2020-09-26 19:41:58 +00:00
virtual void SetWindowBordered ( bool State ) ; // on=true/off=false
2016-04-29 22:34:12 +00:00
virtual bool SetWindowScreen ( int Index ) ;
virtual int GetWindowScreen ( ) ;
2012-01-03 20:39:10 +00:00
virtual int WindowActive ( ) ;
virtual int WindowOpen ( ) ;
2015-08-24 23:01:38 +00:00
virtual void SetWindowGrab ( bool Grab ) ;
2014-10-18 14:17:36 +00:00
virtual void NotifyWindow ( ) ;
2020-09-26 19:41:58 +00:00
2020-08-29 10:10:38 +00:00
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 ; }
2012-01-03 20:39:10 +00:00
} ;
2018-07-06 14:11:38 +00:00
# endif // ENGINE_CLIENT_BACKEND_SDL_H