24 case gl46core::GL_TEXTURE_BUFFER:
return 0;
25 case gl46core::GL_UNIFORM_BUFFER:
return 1;
26 case gl46core::GL_SHADER_STORAGE_BUFFER:
return 2;
27 case gl46core::GL_PIXEL_UNPACK_BUFFER:
return 3;
28 case gl46core::GL_DRAW_INDIRECT_BUFFER:
return 4;
29 case gl46core::GL_ARRAY_BUFFER:
return 5;
30 case gl46core::GL_PARAMETER_BUFFER:
return 6;
31 case gl46core::GL_ELEMENT_ARRAY_BUFFER:
return 7;
32 case gl46core::GL_PIXEL_PACK_BUFFER:
return 8;
33 case gl46core::GL_TRANSFORM_FEEDBACK_BUFFER:
return 9;
34 case gl46core::GL_COPY_READ_BUFFER:
return 10;
35 case gl46core::GL_COPY_WRITE_BUFFER:
return 11;
36 case gl46core::GL_QUERY_BUFFER:
return 12;
37 case gl46core::GL_ATOMIC_COUNTER_BUFFER:
return 13;
38 case gl46core::GL_NONE:
return 14;
132 gl46core::glDisableVertexAttribArray( idx );
136 gl46core::glEnableVertexAttribArray( idx );
142 gl46core::glVertexAttribFormat( idx,
145 descriptor.
_normalized ? gl46core::GL_TRUE : gl46core::GL_FALSE,
150 gl46core::glVertexAttribIFormat( idx,
165 gl46core::glVertexBindingDivisor( vertBinding.
_bufferBindIndex, perInstanceDivisor ? 1u : 0u );
190 bool changed =
false;
193 gl46core::glPixelStorei( gl46core::GL_PACK_ALIGNMENT, (gl46core::GLint)pixelPackAlignment.
_alignment );
199 gl46core::glPixelStorei( gl46core::GL_PACK_ROW_LENGTH, (gl46core::GLint)pixelPackAlignment.
_rowLength );
205 gl46core::glPixelStorei( gl46core::GL_PACK_SKIP_ROWS, (gl46core::GLint)pixelPackAlignment.
_skipRows );
211 gl46core::glPixelStorei( gl46core::GL_PACK_SKIP_PIXELS, (gl46core::GLint)pixelPackAlignment.
_skipPixels );
230 bool changed =
false;
233 gl46core::glPixelStorei( gl46core::GL_UNPACK_ALIGNMENT, (gl46core::GLint)pixelUnpackAlignment.
_alignment );
239 gl46core::glPixelStorei( gl46core::GL_UNPACK_ROW_LENGTH, (gl46core::GLint)pixelUnpackAlignment.
_rowLength );
245 gl46core::glPixelStorei( gl46core::GL_UNPACK_SKIP_ROWS, (gl46core::GLint)pixelUnpackAlignment.
_skipRows );
251 gl46core::glPixelStorei( gl46core::GL_UNPACK_SKIP_PIXELS, (gl46core::GLint)pixelUnpackAlignment.
_skipPixels );
264 const gl46core::GLuint samplerCount,
265 const gl46core::GLuint*
const samplerHandles )
273 if ( samplerCount == 1 )
276 const gl46core::GLuint targetHandle = samplerHandles ? samplerHandles[0] : 0u;
277 if ( handle != targetHandle )
279 gl46core::glBindSampler( unitOffset, targetHandle );
280 handle = targetHandle;
288 bool newBinding =
false;
289 for ( gl46core::GLubyte idx = 0u; idx < samplerCount; ++idx )
291 const U8 slot = unitOffset + idx;
292 const gl46core::GLuint targetHandle = samplerHandles ? samplerHandles[idx] : 0u;
294 if ( crtHandle != targetHandle )
296 crtHandle = targetHandle;
307 gl46core::glBindSamplers( unitOffset, samplerCount, samplerHandles );
325 gl46core::glBindTextureUnit( idx, 0u );
361 if ( crtEntry != handle )
364 gl46core::glBindTextureUnit( unit, handle );
369 if ( crtSampler != samplerHandle )
371 crtSampler = samplerHandle;
372 gl46core::glBindSampler( unit, samplerHandle );
380 const gl46core::GLuint textureCount,
381 const gl46core::GLuint*
const textureHandles,
382 const gl46core::GLuint*
const samplerHandles )
386 if ( textureCount == 1 )
389 textureHandles ==
nullptr ? 0u : textureHandles[0],
390 samplerHandles ==
nullptr ? 0u : samplerHandles[0] );
397 bool newBinding =
false;
398 for ( gl46core::GLubyte idx = 0u; idx < textureCount; ++idx )
400 const U8 slot = unitOffset + idx;
401 const gl46core::GLuint targetHandle = textureHandles ? textureHandles[idx] : 0u;
403 if ( crtHandle != targetHandle )
405 crtHandle = targetHandle;
416 gl46core::glBindTextures( unitOffset, textureCount, textureHandles );
424 result = samplerResult;
432 const bool layered,
const gl46core::GLint layer,
const gl46core::GLenum access,
433 const gl46core::GLenum format )
446 ._layered = layered ? gl46core::GL_TRUE : gl46core::GL_FALSE
450 if ( settings != tempSettings )
452 glBindImageTexture( unit, handle, level, layered ? gl46core::GL_TRUE : gl46core::GL_FALSE, layer, access, format );
453 settings = tempSettings;
473 if ( bindings != currentParams )
476 gl46core::glBindVertexBuffer( location, bufferID,
static_cast<gl46core::GLintptr
>(offset),
static_cast<gl46core::GLsizei
>(stride) );
489 bool needsBind =
false;
490 for ( gl46core::GLsizei i = 0u; i < count; ++i )
496 ._offset =
to_size(offsets[i]),
499 if ( bindings != currentParams )
507 gl46core::glBindVertexBuffers( location, count, bufferIDs, offsets, strides );
516 gl46core::GLuint temp = 0;
560 gl46core::glBindFramebuffer( gl46core::GL_FRAMEBUFFER, ID );
567 gl46core::glBindFramebuffer( gl46core::GL_READ_FRAMEBUFFER, ID );
571 gl46core::glBindFramebuffer( gl46core::GL_DRAW_FRAMEBUFFER, ID );
587 gl46core::GLuint& crtBinding = target != gl46core::GL_ELEMENT_ARRAY_BUFFER
590 previousID = crtBinding;
593 if ( previousID == bufferHandle )
599 crtBinding = bufferHandle;
601 glBindBuffer( target, bufferHandle );
607 gl46core::GLuint temp = 0u;
620 if (
entry._handle != bufferHandle ||
621 entry._offset != offsetInBytes ||
622 entry._range != rangeInBytes )
624 previousID =
entry._handle;
625 entry = { bufferHandle, offsetInBytes, rangeInBytes };
626 if ( offsetInBytes == 0u && rangeInBytes == 0u )
628 gl46core::glBindBufferBase( target, bindIndex, bufferHandle );
632 gl46core::glBindBufferRange( target, bindIndex, bufferHandle, offsetInBytes, rangeInBytes );
642 gl46core::GLuint temp = 0u;
653 gl46core::GLuint temp = 0u;
674 gl46core::glUseProgram( programHandle );
675 if ( programHandle == 0u )
702 gl46core::glBindProgramPipeline( pipelineHandle );
703 if ( pipelineHandle == 0u )
720 gl46core::glBlendColor( floatColour.
r, floatColour.
g, floatColour.
b, floatColour.
a );
728 const bool enable = blendingProperties.enabled();
732 enable ? gl46core::glEnable( gl46core::GL_BLEND ) : gl46core::glDisable( gl46core::GL_BLEND );
756 ?
to_base( blendingProperties.blendOp() )
772 ?
to_base( blendingProperties.blendOp() )
788 const bool enable = blendingProperties.enabled();
792 if (
_blendEnabled[drawBufferIdx] == gl46core::GL_TRUE != enable )
794 enable ? gl46core::glEnablei( gl46core::GL_BLEND, drawBufferIdx ) : gl46core::glDisablei( gl46core::GL_BLEND, drawBufferIdx );
795 _blendEnabled[drawBufferIdx] = enable ? gl46core::GL_TRUE : gl46core::GL_FALSE;
804 if ( enable && crtProperties != blendingProperties )
808 if ( blendingProperties.blendSrc() != crtProperties.blendSrc() ||
809 blendingProperties.blendDest() != crtProperties.blendDest() ||
810 blendingProperties.blendSrcAlpha() != crtProperties.blendSrcAlpha() ||
811 blendingProperties.blendDestAlpha() != crtProperties.blendDestAlpha() )
813 gl46core::glBlendFuncSeparatei( drawBufferIdx,
825 if ( blendingProperties.blendOp() != crtProperties.blendOp() ||
826 blendingProperties.blendOpAlpha() != crtProperties.blendOpAlpha() )
828 gl46core::glBlendEquationSeparatei( drawBufferIdx,
830 ?
to_base( blendingProperties.blendOp() )
840 if ( blendingProperties.blendSrc() != crtProperties.blendSrc() ||
841 blendingProperties.blendDest() != crtProperties.blendDest() )
843 gl46core::glBlendFunci( drawBufferIdx,
851 if ( blendingProperties.blendOp() != crtProperties.blendOp() )
853 gl46core::glBlendEquationi( drawBufferIdx,
855 ?
to_base( blendingProperties.blendOp() )
861 crtProperties = blendingProperties;
870 gl46core::glViewport( viewport.
x, viewport.
y, viewport.
z, viewport.
w );
882 gl46core::glClearColor( colour.
r, colour.
g, colour.
b, colour.
a );
894 gl46core::glClearDepth( value );
906 gl46core::glScissor( rect.
x, rect.
y, rect.
z, rect.
w );
921 gl46core::glEnable( gl46core::GL_SAMPLE_ALPHA_TO_COVERAGE );
925 gl46core::glDisable( gl46core::GL_SAMPLE_ALPHA_TO_COVERAGE );
936 return _textureBoundMap[slot];
941 return _samplerBoundMap[slot];
951 size_t offset, range;
952 return getBoundBuffer( target, bindIndex, offset, range );
955 gl46core::GLuint
GLStateTracker::getBoundBuffer(
const gl46core::GLenum target,
const gl46core::GLuint bindIndex,
size_t& offsetOut,
size_t& rangeOut )
const noexcept
958 offsetOut =
entry._offset;
959 rangeOut =
entry._range;
960 return entry._handle;
965 viewportOut = _activeViewport;
972 gl46core::glDepthMask( state ? gl46core::GL_TRUE : gl46core::GL_FALSE );
988 newBlock.
_stencilEnabled ? gl46core::glEnable( gl46core::GL_STENCIL_TEST ) : gl46core::glDisable( gl46core::GL_STENCIL_TEST );
994 newBlock.
_depthTestEnabled ? gl46core::glEnable( gl46core::GL_DEPTH_TEST ) : gl46core::glDisable( gl46core::GL_DEPTH_TEST );
1000 newBlock.
_scissorTestEnabled ? gl46core::glEnable( gl46core::GL_SCISSOR_TEST ) : gl46core::glDisable( gl46core::GL_SCISSOR_TEST );
1013 : gl46core::glEnable( gl46core::GL_RASTERIZER_DISCARD );
1021 : gl46core::glDisable( gl46core::GL_PRIMITIVE_RESTART_FIXED_INDEX );
1031 gl46core::glEnable( gl46core::GL_CULL_FACE );
1038 gl46core::glDisable( gl46core::GL_CULL_FACE );
1045 gl46core::glFrontFace( newBlock.
_frontFaceCCW ? gl46core::GL_CCW : gl46core::GL_CW );
1058 gl46core::glPatchParameteri( gl46core::GL_PATCH_VERTICES, newBlock.
_tessControlPoints );
1102 gl46core::glDisable( gl46core::GL_POLYGON_OFFSET_FILL );
1106 gl46core::glEnable( gl46core::GL_POLYGON_OFFSET_FILL );
1109 gl46core::glPolygonOffset( newBlock.
_zBias, newBlock.
_zUnits );
1119 gl46core::glColorMask( cWrite.
b[0] == 1 ? gl46core::GL_TRUE : gl46core::GL_FALSE,
1120 cWrite.
b[1] == 1 ? gl46core::GL_TRUE : gl46core::GL_FALSE,
1121 cWrite.
b[2] == 1 ? gl46core::GL_TRUE : gl46core::GL_FALSE,
1122 cWrite.
b[3] == 1 ? gl46core::GL_TRUE : gl46core::GL_FALSE );
#define PROFILE_SCOPE_AUTO(CATEGORY)
static const DeviceInformation & GetDeviceInformation() noexcept
void init(U32 maxBindings) noexcept
const BufferBindingParams & bindingParams(gl46core::GLuint index)
bool instanceDivisorFlag(gl46core::GLuint index)
void set(const T *v) noexcept
set the 4 components of the vector manually using a source pointer to a (large enough) array
std::array< gl46core::GLenum, to_base(StencilOperation::COUNT)> glStencilOpTable
std::array< gl46core::GLenum, to_base(BlendOperation::COUNT)> glBlendOpTable
std::array< gl46core::GLenum, to_base(GFXDataFormat::COUNT)> glDataFormatTable
std::array< gl46core::GLenum, to_base(BlendProperty::COUNT)> glBlendTable
std::array< gl46core::GLenum, to_base(FillMode::COUNT)> glFillModeTable
std::array< gl46core::GLenum, to_base(CullMode::COUNT)> glCullModeTable
std::array< gl46core::GLenum, to_base(ComparisonFunction::COUNT)> glCompareFuncTable
constexpr Optick::Category::Type Graphics
FColour4 ToFloatColour(const UColour4 &byteColour) noexcept
FORCE_INLINE gl46core::GLint GetBufferTargetIndex(const gl46core::GLenum target) noexcept
Handle console commands that start with a forward slash.
bool IS_ZERO(const T X) noexcept
constexpr U32 to_U32(const T value)
constexpr gl46core::GLuint GL_NULL_HANDLE
Invalid object value. Used to compare handles and determine if they were properly created.
@ COUNT
Place all properties above this.
constexpr RenderTargetID INVALID_RENDER_TARGET_ID
constexpr size_t to_size(const T value)
bool COMPARE(T X, U Y) noexcept
Project const SceneEntry & entry
constexpr auto to_base(const Type value) -> Type
VertexBindings _vertexBindings
gl46core::GLuint getBoundBuffer(gl46core::GLenum target, gl46core::GLuint bindIndex) const noexcept
RenderTargetID _activeRenderTargetID
size_t _drawIndirectBufferOffset
gl46core::GLuint getBoundProgramHandle() const noexcept
void setVertexFormat(const AttributeMap &attributes, const size_t attributeHash)
BindResult setActiveBufferIndex(gl46core::GLenum target, gl46core::GLuint bufferHandle, gl46core::GLuint bindIndex)
BlendingSettings _blendPropertiesGlobal
eastl::queue< std::pair< gl46core::GLsync, U64 > > _endFrameFences
static constexpr U8 MAX_BOUND_TEXTURE_UNITS
bool setAlphaToCoverage(bool state)
FColour4 _activeClearColour
BindResult setActiveBuffer(gl46core::GLenum target, gl46core::GLuint bufferHandle)
Single place to change buffer objects for every target available.
vector< gl46core::GLboolean > _blendEnabled
RenderStateBlock _activeState
BindResult bindTextureImage(gl46core::GLubyte unit, gl46core::GLuint handle, gl46core::GLint level, bool layered, gl46core::GLint layer, gl46core::GLenum access, gl46core::GLenum format)
void setBlendColour(const UColour4 &blendColour)
bool setViewport(const Rect< I32 > &viewport)
Change the current viewport area. Redundancy check is performed in GFXDevice class.
Rect< I32 > _activeViewport
Pipeline const * _activePipeline
PerBufferConfig _currentBindConfig
Rect< I32 > _activeScissor
void setBlending(const BlendingSettings &blendingProperties)
BindResult setStateBlock(const RenderStateBlock &stateBlock)
bool unbindTexture(TextureType type, gl46core::GLuint handle)
Returns true if the texture was bound. If the texture was not bound, no state is changed.
BindResult bindActiveBuffer(gl46core::GLuint location, gl46core::GLuint bufferID, size_t offset, size_t stride)
Modify buffer bindings for the active vao.
gl46core::GLuint _activeShaderPipelineHandle
gl46core::GLuint _activeFBID[3]
0 - current framebuffer, 1 - current read only framebuffer, 2 - current write only framebuffer
BindResult setActiveBufferIndexRange(gl46core::GLenum target, gl46core::GLuint bufferHandle, gl46core::GLuint bindIndex, size_t offsetInBytes, size_t rangeInBytes)
Same as normal setActiveBuffer but handles proper binding of different ranges.
PixelAlignment _unpackAlignment
gl46core::GLboolean _blendEnabledGlobal
bool activateStateBlock(const RenderStateBlock &newBlock)
glShaderProgram * _activeShaderProgram
bool setPixelPackAlignment(const PixelAlignment &pixelPackAlignment)
Pixel pack alignment is usually changed by textures, PBOs, etc.
TextureBoundMapDef _textureBoundMap
gl46core::GLuint _activeVAOIB
BindResult bindActiveBuffers(gl46core::GLuint location, gl46core::GLsizei count, gl46core::GLuint *bufferIDs, gl46core::GLintptr *offset, gl46core::GLsizei *strides)
PrimitiveTopology _activeTopology
bool setScissor(const Rect< I32 > &newScissorRect)
void getActiveViewport(Rect< I32 > &viewportOut) const noexcept
void setPrimitiveTopology(PrimitiveTopology topology)
vec2< U16 > _activeRenderTargetDimensions
BindResult bindSamplers(gl46core::GLubyte unitOffset, gl46core::GLuint samplerCount, const gl46core::GLuint *samplerHandles)
gl46core::GLuint _activeShaderProgramHandle
VAOBindings _vaoBufferData
ImageBoundMapDef _imageBoundMap
bool setPixelUnpackAlignment(const PixelAlignment &pixelUnpackAlignment)
Pixel unpack alignment is usually changed by textures, PBOs, etc.
bool _alphaToCoverageEnabled
AttributeSettings _currentAttributes
gl46core::GLuint getBoundTextureHandle(U8 slot) const noexcept
BindResult bindTexture(gl46core::GLubyte unit, gl46core::GLuint handle, gl46core::GLuint samplerHandle=0u)
Bind a texture specified by a GL handle and GL type to the specified unit using the sampler object de...
SamplerBoundMapDef _samplerBoundMap
BindResult setActiveShaderPipeline(gl46core::GLuint pipelineHandle)
Change the currently active shader pipeline. Returns false if the pipeline was already bound.
bool setDepthWrite(bool state)
DebugScope _debugScope[Config::MAX_DEBUG_SCOPE_DEPTH]
std::array< BindConfigEntry, 32 > BindConfig
std::array< gl46core::GLuint, 13 > _activeBufferID
VB, IB, SB, TB, UB, PUB, DIB.
vector< BlendingSettings > _blendProperties
PixelAlignment _packAlignment
BindResult bindTextures(gl46core::GLubyte unitOffset, gl46core::GLuint textureCount, const gl46core::GLuint *textureHandles, const gl46core::GLuint *samplerHandles)
Bind multiple textures specified by an array of handles and an offset unit.
BindResult setActiveProgram(gl46core::GLuint programHandle)
Change the currently active shader program. Returns false if the program was already bound.
bool setClearColour(const FColour4 &colour)
BindResult setActiveFB(RenderTarget::Usage usage, gl46core::GLuint ID)
glFramebuffer * _activeRenderTarget
U64 _lastSyncedFrameNumber
bool setClearDepth(F32 value)
gl46core::GLuint getBoundSamplerHandle(U8 slot) const noexcept
gl46core::GLuint _texture
bool _primitiveRestartEnabled
StencilOperation _stencilZFailOp
StencilOperation _stencilFailOp
bool _rasterizationEnabled
ComparisonFunction _stencilFunc
StencilOperation _stencilPassOp
ComparisonFunction _zFunc