Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
glResources.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_GL_RESOURCES_H_
34#define DVD_GL_RESOURCES_H_
35
36#include <glbinding/gl46core/gl.h>
37
38struct SDL_Window;
39typedef void* SDL_GLContext;
40
41namespace NS_GLIM {
42 enum class GLIM_ENUM : int;
43}; //namespace NS_GLIM
44
45namespace Divide {
46
47struct GenericDrawCommand;
48
49class DisplayWindow;
50class glBufferImpl;
51
53{
55 size_t _offset = 0u;
56 size_t _length = 0u;
57};
58
60{
61 gl46core::GLuint _texture = 0;
62 gl46core::GLint _level = 0;
63 gl46core::GLint _layer = 0;
64 gl46core::GLenum _access = gl46core::GL_NONE;
65 gl46core::GLenum _format = gl46core::GL_NONE;
66 gl46core::GLboolean _layered = gl46core::GL_FALSE;
67
68 bool operator==( const ImageBindSettings&) const = default;
69};
70
72{
73public:
75 {
76 gl46core::GLuint _id{0u};
77 size_t _offset{0u};
78 size_t _stride{0u};
79
80 bool operator==( const BufferBindingParams&) const = default;
81 };
82
83private:
86 using VAOData = std::pair<VAOBufferData, VAODivisors>;
87
88public:
89 void init(U32 maxBindings) noexcept;
90
91 const BufferBindingParams& bindingParams( gl46core::GLuint index);
92
93 bool instanceDivisorFlag( gl46core::GLuint index);
94 void instanceDivisorFlag( gl46core::GLuint index, bool perInstanceDivisor);
95
96 void bindingParams( gl46core::GLuint index, const BufferBindingParams& newParams);
97
98private:
99
102};
103
105constexpr gl46core::GLuint GL_NULL_HANDLE = gl46core::GL_INVALID_INDEX;
106
107namespace GLUtil {
108
109// Not thread-safe!
111{
112private:
113 enum class State : U8 {
114 USED = 0,
115 FREE,
116 CLEAN
117 };
118public:
119 void onFrameEnd();
120 void init(U32 poolSize);
121 void destroy();
122
123 std::pair<gl46core::GLuint, bool> allocate(size_t hash, bool retry = false);
124 // no-hash version
125 gl46core::GLuint allocate(bool retry = false);
126 void deallocate( gl46core::GLuint handle, U32 frameDelay = 1);
127
128private:
133
134 static constexpr size_t InitialCacheSize = 128u;
136 {
137 size_t _hash = 0u;
139 };
140 eastl::fixed_vector<CacheEntry, InitialCacheSize, true> _cache;
141
142 //Heavy-handed general purpose lock
144};
145
147template<typename T = gl46core::GLint>
148void getGLValue( gl46core::GLenum param, T& value, gl46core::GLint index = -1);
149
150template<typename T = gl46core::GLint>
151void getGLValue( gl46core::GLenum param, T* value);
152
153template<typename T = gl46core::GLint>
154T getGLValue( gl46core::GLenum param);
155
156template<typename T = gl46core::GLint>
157T getGLValueIndexed( gl46core::GLenum param, gl46core::GLint index = -1);
158
160void DebugCallback( gl46core::GLenum source, gl46core::GLenum type, gl46core::GLuint id, gl46core::GLenum severity,
161 gl46core::GLsizei length, const gl46core::GLchar* message, const void* userParam);
162
163
164extern gl46core::GLuint s_lastQueryResult;
166extern thread_local SDL_GLContext s_glSecondaryContext;
167
168
170
171bool ValidateSDL( const I32 errCode, bool assert = true );
172
174void SubmitRenderCommand(const GenericDrawCommand& drawCommand, gl46core::GLenum internalFormat);
175
177void OnStartup();
178
180{
181 gl46core::GLenum _format{ gl46core::GL_NONE};
182 gl46core::GLenum _internalFormat{ gl46core::GL_NONE};
183 gl46core::GLenum _dataType{ gl46core::GL_NONE};
184};
185
186FormatAndDataType InternalFormatAndDataType(GFXImageFormat baseFormat, GFXDataFormat dataType, GFXImagePacking packing) noexcept;
187gl46core::GLenum internalTextureType(TextureType type, U8 msaaSamples);
188
189extern std::array<gl46core::GLenum, to_base(BlendProperty::COUNT)> glBlendTable;
190extern std::array<gl46core::GLenum, to_base(BlendOperation::COUNT)> glBlendOpTable;
191extern std::array<gl46core::GLenum, to_base(ComparisonFunction::COUNT)> glCompareFuncTable;
192extern std::array<gl46core::GLenum, to_base(StencilOperation::COUNT)> glStencilOpTable;
193extern std::array<gl46core::GLenum, to_base(CullMode::COUNT)> glCullModeTable;
194extern std::array<gl46core::GLenum, to_base(FillMode::COUNT)> glFillModeTable;
195extern std::array<gl46core::GLenum, to_base(TextureType::COUNT)> glTextureTypeTable;
196extern std::array<gl46core::GLenum, to_base(PrimitiveTopology::COUNT)> glPrimitiveTypeTable;
197extern std::array<gl46core::GLenum, to_base(GFXDataFormat::COUNT)> glDataFormatTable;
198extern std::array<gl46core::GLenum, to_base(TextureWrap::COUNT)> glWrapTable;
199extern std::array<gl46core::GLenum, to_base(ShaderType::COUNT)> glShaderStageTable;
200extern std::array<gl46core::GLenum, to_base( QueryType::COUNT )> glQueryTypeTable;
201
202}; // namespace GLUtil
203}; // namespace Divide
204
205#endif //DVD_GL_RESOURCES_H_
206
207#include "glResources.inl"
SDL_Window SDL_Window
Definition: DisplayWindow.h:42
eastl::fixed_vector< CacheEntry, InitialCacheSize, true > _cache
Definition: glResources.h:140
std::pair< gl46core::GLuint, bool > allocate(size_t hash, bool retry=false)
void deallocate(gl46core::GLuint handle, U32 frameDelay=1)
vector< gl46core::GLuint > _tempBuffer
Definition: glResources.h:132
vector< gl46core::GLuint > _handles
Definition: glResources.h:131
static constexpr size_t InitialCacheSize
Definition: glResources.h:134
std::pair< VAOBufferData, VAODivisors > VAOData
Definition: glResources.h:86
void init(U32 maxBindings) noexcept
Definition: glResources.cpp:27
vector< bool > VAODivisors
Definition: glResources.h:85
const BufferBindingParams & bindingParams(gl46core::GLuint index)
Definition: glResources.cpp:54
bool instanceDivisorFlag(gl46core::GLuint index)
Definition: glResources.cpp:32
vector< BufferBindingParams > VAOBufferData
Definition: glResources.h:84
void * SDL_GLContext
Definition: glResources.h:39
std::array< gl46core::GLenum, to_base(QueryType::COUNT)> glQueryTypeTable
Definition: glResources.cpp:97
NO_DESTROY Mutex s_glSecondaryContextMutex
Definition: glResources.cpp:84
gl46core::GLuint s_lastQueryResult
Definition: glResources.cpp:80
std::array< gl46core::GLenum, to_base(StencilOperation::COUNT)> glStencilOpTable
Definition: glResources.cpp:89
std::array< gl46core::GLenum, to_base(PrimitiveTopology::COUNT)> glPrimitiveTypeTable
Definition: glResources.cpp:93
std::array< gl46core::GLenum, to_base(ShaderType::COUNT)> glShaderStageTable
Definition: glResources.cpp:96
std::array< gl46core::GLenum, to_base(BlendOperation::COUNT)> glBlendOpTable
Definition: glResources.cpp:87
thread_local SDL_GLContext s_glSecondaryContext
Definition: glResources.cpp:83
std::array< gl46core::GLenum, to_base(GFXDataFormat::COUNT)> glDataFormatTable
Definition: glResources.cpp:94
const DisplayWindow * s_glMainRenderWindow
Definition: glResources.cpp:82
void getGLValue(gl46core::GLenum param, T &value, gl46core::GLint index=-1)
Wrapper for glGetIntegerv.
Definition: glResources.inl:40
void SubmitRenderCommand(const GenericDrawCommand &drawCommand, const gl46core::GLenum internalFormat)
Note: If internal format is not GL_NONE, an indexed draw is issued!
bool ValidateSDL(const I32 errCode, bool assert)
std::array< gl46core::GLenum, to_base(TextureWrap::COUNT)> glWrapTable
Definition: glResources.cpp:95
T getGLValueIndexed(gl46core::GLenum param, gl46core::GLint index=-1)
void OnStartup()
Populate enumeration tables with appropriate API values.
Definition: glResources.cpp:99
std::array< gl46core::GLenum, to_base(BlendProperty::COUNT)> glBlendTable
Definition: glResources.cpp:86
std::array< gl46core::GLenum, to_base(FillMode::COUNT)> glFillModeTable
Definition: glResources.cpp:91
gl46core::GLenum internalTextureType(const TextureType type, const U8 msaaSamples)
void DebugCallback(const gl46core::GLenum source, const gl46core::GLenum type, const gl46core::GLuint id, const gl46core::GLenum severity, const gl46core::GLsizei length, const gl46core::GLchar *message, const void *userParam)
Print OpenGL specific messages.
std::array< gl46core::GLenum, to_base(CullMode::COUNT)> glCullModeTable
Definition: glResources.cpp:90
std::array< gl46core::GLenum, to_base(TextureType::COUNT)> glTextureTypeTable
Definition: glResources.cpp:92
std::array< gl46core::GLenum, to_base(ComparisonFunction::COUNT)> glCompareFuncTable
Definition: glResources.cpp:88
FormatAndDataType InternalFormatAndDataType(const GFXImageFormat baseFormat, const GFXDataFormat dataType, const GFXImagePacking packing) noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::mutex Mutex
Definition: SharedMutex.h:40
int32_t I32
uint8_t U8
std::shared_mutex SharedMutex
Definition: SharedMutex.h:43
@ COUNT
Place all properties above this.
@ COUNT
Place all properties above this.
constexpr gl46core::GLuint GL_NULL_HANDLE
Invalid object value. Used to compare handles and determine if they were properly created.
Definition: glResources.h:105
@ COUNT
Place all properties above this.
eastl::vector< Type > vector
Definition: Vector.h:42
@ COUNT
Place all properties above this.
@ COUNT
Place all properties above this.
constexpr U32 U32_MAX
@ COUNT
Place all properties above this.
uint32_t U32
constexpr auto to_base(const Type value) -> Type
GLIM_ENUM
The enum holding all important GLIM configuration values.
Definition: Declarations.h:17
Definition: glResources.h:53
glBufferImpl * _buffer
Definition: glResources.h:54
size_t _length
Definition: glResources.h:56
size_t _offset
Definition: glResources.h:55
Definition: glResources.h:136
size_t _hash
Definition: glResources.h:137
U32 _idx
Definition: glResources.h:138
bool operator==(const ImageBindSettings &) const =default
gl46core::GLenum _format
Definition: glResources.h:65
gl46core::GLuint _texture
Definition: glResources.h:61
gl46core::GLenum _access
Definition: glResources.h:64
gl46core::GLint _layer
Definition: glResources.h:63
gl46core::GLint _level
Definition: glResources.h:62
gl46core::GLboolean _layered
Definition: glResources.h:66
bool operator==(const BufferBindingParams &) const =default