OpenBarnyard
 
Loading...
Searching...
No Matches
T2Render_GL.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef TRENDERINTERFACE_GL
5# include "T2RenderBuffer_GL.h"
6# include "T2Shader_GL.h"
7# include "T2RenderContext_GL.h"
9
10# include <SDL/SDL.h>
11
12struct DrawElementsIndirectCommand
13{
14 DrawElementsIndirectCommand() = default;
15 DrawElementsIndirectCommand( TUINT a_uiCount, TUINT a_uiInstanceCount, TUINT a_uiFirstIndex, TINT a_iBaseVertex, TUINT a_uiBaseInstance )
16 : count( a_uiCount )
17 , instanceCount( a_uiInstanceCount )
18 , firstIndex( a_uiFirstIndex )
19 , baseVertex( a_iBaseVertex )
20 , baseInstance( a_uiBaseInstance )
21 {}
22
23 TUINT count;
24 TUINT instanceCount;
25 TUINT firstIndex;
26 TINT baseVertex;
27 TUINT baseInstance;
28};
29
31
32//-----------------------------------------------------------------------------
33// Note: This is a custom class which is not the same as the one used in TOSHI 2.0
34// since it was never actually used in any games but in some tools like TXSViewer
35// which is not publicly available, so it's not possible to match this class.
36//-----------------------------------------------------------------------------
37class T2Render
38 : public TSingleton<T2Render>
39{
40public:
41 inline static constexpr T2RenderAPI API = T2RenderAPI::OpenGL;
42
43 struct WindowParams
44 {
45 const TCHAR* pchTitle;
46 TUINT uiWidth;
47 TUINT uiHeight;
48 TBOOL bIsWindowed;
49 };
50
51public:
52 T2Render();
53 ~T2Render();
54
55 // Creates renderer and it's resources. Returns TTRUE if succeded
56 TBOOL Create( const WindowParams& a_rcWindowParams );
57
58 // Destroys renderer and everything it manages
59 void Destroy();
60
61 void Update( TFLOAT a_fDeltaTime );
62 void BeginScene();
63 void EndScene();
64
65 T2Window* GetWindow() const { return m_pWindow; }
66 const WindowParams& GetWindowParams() const { return m_oWindowParams; }
67 SDL_GLContext GetGLContext() const { return m_pGLContext; }
68
69public:
70 static T2RenderContext& GetRenderContext() { return GetSingleton()->m_oRenderContext; }
71 static TBOOL SetShaderProgram( const T2Shader& a_rcShaderProgram ) { return GetRenderContext().SetShaderProgram( a_rcShaderProgram ); }
72 static GLuint GetTexture2D( TINT a_iTextureIndex ) { return GetRenderContext().GetTexture2D( a_iTextureIndex ); }
73 static void SetTexture2D( TINT a_iTextureIndex, const T2GLTexture& a_rcTexture ) { GetRenderContext().SetTexture2D( a_iTextureIndex, a_rcTexture ); }
74 static void SetTexture2D( TINT a_iTextureIndex, T2GLTexture* a_pTexture ) { GetRenderContext().SetTexture2D( a_iTextureIndex, *a_pTexture ); }
75 static void SetTexture2D( TINT a_iTextureIndex, GLuint a_uiTexture ) { GetRenderContext().SetTexture2D( a_iTextureIndex, a_uiTexture ); }
76 static void ResetTexture2D( TINT a_iTextureIndex ) { GetRenderContext().ResetTexture2D( a_iTextureIndex ); }
77
78 static GLuint CreateTexture( GLsizei a_iWidth, GLsizei a_iHeight, GLenum a_eInternalFormat, GLenum a_eFormat, GLenum a_ePixelType, TBOOL a_bGenerateMipmap, const void* a_pData );
79 static void DestroyTexture( GLuint a_iId );
80
81 static T2CompiledShader CompileShader( GLenum a_eShader, const TCHAR* a_szSource );
82 static T2CompiledShader CompileShaderFromFile( GLenum a_eShader, const TCHAR* a_szFileName );
83 static T2Shader CreateShaderProgram( T2CompiledShader a_VertexShader, T2CompiledShader a_FragmentShader );
84 static T2VertexBuffer CreateVertexBuffer( const void* a_pData, GLuint a_uiSize, GLenum a_eUsage );
85 static T2IndexBuffer CreateIndexBuffer( const TUINT16* a_pIndices, GLuint a_uiCount, GLenum a_eUsage );
86 static T2IndirectBuffer CreateIndirectBuffer( const void* a_pData, GLuint a_uiSize, GLenum a_eUsage );
87 static T2ShaderStorageBuffer CreateShaderStorageBuffer( const void* a_pData, GLuint a_uiSize, GLenum a_eUsage );
88 static T2UniformBuffer CreateUniformBuffer( const void* a_pData, GLuint a_uiSize, GLenum a_eUsage );
89 static T2VertexArray CreateVertexArray();
90 static T2VertexArray CreateVertexArray( T2VertexBuffer a_VertexBuffer, T2IndexBuffer a_IndexBuffer );
91
92 static void DestroyVertexBuffer( const T2VertexBuffer& a_VertexBuffer );
93 static void DestroyIndexBuffer( const T2IndexBuffer& a_IndexBuffer );
94 static void DestroyIndirectBuffer( const T2IndirectBuffer& a_IndirectBuffer );
95 static void DestroyShaderStorageBuffer( const T2IndirectBuffer& a_IndirectBuffer );
96 static void DestroyUniformBuffer( const T2IndirectBuffer& a_IndirectBuffer );
97
98private:
99 void OnDeviceReset();
100
101private:
102 T2Window* m_pWindow = TNULL;
103 SDL_GLContext m_pGLContext = TNULL;
104 WindowParams m_oWindowParams;
105 T2RenderContext m_oRenderContext;
106
107 TBOOL m_bIsInScene = TFALSE;
108};
109
111
112#endif // TRENDERINTERFACE_GL
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
uint16_t TUINT16
Definition Typedefs.h:15
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
bool TBOOL
Definition Typedefs.h:6
static TFORCEINLINE T * GetSingleton()
Definition TSingleton.h:49