DuctTaped_GL/DGL/DGL_Buffers.hpp

140 lines
3.2 KiB
C++
Raw Normal View History

/*
Title : Ducktaped GL: Buffers
Author: Edward R. Gonzalez
Description:
Contains wrappers to buffer related functionality.
*/
2020-02-12 00:29:35 -08:00
#pragma once
// GLEW
#include <glew.h>
// DGL
#include "DGL_Enum.hpp"
#include "DGL_Types.hpp"
2020-02-12 00:29:35 -08:00
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace DGL
2020-02-12 00:29:35 -08:00
{
sfn BindBuffer(EBufferTarget _targetType, ID<VertexBuffer> _buffer)
2020-02-12 00:29:35 -08:00
{
glBindBuffer(GLenum(_targetType), _buffer);
2020-02-12 00:29:35 -08:00
return;
}
sfn BindVertexArray(gUInt _referenceToTrackArray)
2020-02-12 00:29:35 -08:00
{
glBindVertexArray(_referenceToTrackArray);
2020-02-12 00:29:35 -08:00
return;
}
template<typename TypeOfData>
sfn BufferData(ro Ref(TypeOfData) _data, EBufferTarget _targetType, EBufferUsage _usageType)
2020-02-12 00:29:35 -08:00
{
glBufferData(GLenum(_targetType), sizeof(TypeOfData), Address(_data), GLenum(_usageType));
2020-02-12 00:29:35 -08:00
return;
}
template<typename Type>
sfn BufferData(ro Ref(Type) _data, gSize _sizeOfData, EBufferTarget _targetType, EBufferUsage _usageType)
{
glBufferData(GLenum(_targetType), _sizeOfData, Address(_data), GLenum(_usageType));
}
template<typename... Type, typename = EFrameBuffer>
sfn ClearBuffer(Type... _buffersToClear)
2020-02-12 00:29:35 -08:00
{
glClear( (gBitfield(_buffersToClear) | ...) );
2020-02-12 00:29:35 -08:00
return;
}
sfn DisableVertexAttributeArray(gInt _vertexAttributeArrayIndex)
{
glDisableVertexAttribArray(_vertexAttributeArrayIndex);
}
sfn DrawArrays(EPrimitives _primitive, gInt _startingIndex, gInt _numToRender)
{
glDrawArrays(GLenum(_primitive), _startingIndex, _numToRender); // Starting from vertex 0; 3 vertices total -> 1 triangle.
}
sfn DrawElements(EPrimitives _primitive, gSize _numElements, EDataType _dataType, ro DataPtr _offfsetAddressFromFirstIndex)
{
glDrawElements(GLenum(_primitive), _numElements, GLenum(_dataType), _offfsetAddressFromFirstIndex);
}
sfn EnableVertexAttributeArray(gInt _vertexAttributeArrayIndex)
{
glEnableVertexAttribArray(_vertexAttributeArrayIndex);
}
2020-02-12 00:29:35 -08:00
template<typename VertType>
sfn FormatVertexAttributes
(
gUInt _attributeIndex ,
EDataType _vertexComponenetType ,
ro ptr<void> _firstVertexComponentLocation,
gInt _numberOfVertexComponents ,
gBoolean _shouldNormalize
2020-02-12 00:29:35 -08:00
)
{
glVertexAttribPointer
(
_attributeIndex ,
_numberOfVertexComponents ,
GLenum(_vertexComponenetType),
_shouldNormalize ,
2020-02-12 00:29:35 -08:00
sizeof(VertType ),
_firstVertexComponentLocation
);
}
sfn GenerateBuffers(Ref(gUInt) _bufferReferencer, gSize _numberOfBuffersToReserve)
2020-02-12 00:29:35 -08:00
{
glGenBuffers(_numberOfBuffersToReserve, Address(_bufferReferencer));
2020-02-12 00:29:35 -08:00
return;
}
sfn GenerateVertexBuffers(Ref(gUInt) __referenceRetainerToBuffer, gSize _numOfObjectsToReserveFor)
2020-02-12 00:29:35 -08:00
{
glGenVertexArrays(_numOfObjectsToReserveFor, Address(__referenceRetainerToBuffer));
2020-02-12 00:29:35 -08:00
return;
}
sfn GetBufferParameterIV(EBufferTarget _target, EBufferParam _param, Ref(gInt) _dataStore)
{
glGetBufferParameteriv(GLenum(_target), GLenum(_param), Address(_dataStore));
return;
}
// Used to get an offset from a specified location.
sfn Offset(uInt64 _offsetAmount)
{
return DataPtr(_offsetAmount);
}
sfn UnbindVertexArray()
{
BindVertexArray(0);
}
// Provides an zero offset pointer specifier.
constexpr sfn ZeroOffset() -> ptr<void>
{
return 0;
}
2020-02-12 00:29:35 -08:00
}