mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 08:21:24 +02:00
Merging and cleaning up the code path for the 2 flavors of gl
This commit is contained in:
parent
b888af15e4
commit
f3e1ed4b88
7 changed files with 59 additions and 137 deletions
|
@ -221,7 +221,7 @@ protected:
|
||||||
virtual void killInput() final;
|
virtual void killInput() final;
|
||||||
virtual void syncInputStateCache() final;
|
virtual void syncInputStateCache() final;
|
||||||
virtual void resetInputStage();
|
virtual void resetInputStage();
|
||||||
virtual void updateInput();
|
virtual void updateInput() = 0;
|
||||||
|
|
||||||
struct InputStageState {
|
struct InputStageState {
|
||||||
bool _invalidFormat { true };
|
bool _invalidFormat { true };
|
||||||
|
@ -268,8 +268,8 @@ protected:
|
||||||
void killTransform();
|
void killTransform();
|
||||||
// Synchronize the state cache of this Backend with the actual real state of the GL Context
|
// Synchronize the state cache of this Backend with the actual real state of the GL Context
|
||||||
void syncTransformStateCache();
|
void syncTransformStateCache();
|
||||||
void updateTransform(const Batch& batch);
|
virtual void updateTransform(const Batch& batch) = 0;
|
||||||
void resetTransformStage();
|
virtual void resetTransformStage();
|
||||||
|
|
||||||
// Allows for correction of the camera pose to account for changes
|
// Allows for correction of the camera pose to account for changes
|
||||||
// between the time when a was recorded and the time(s) when it is
|
// between the time when a was recorded and the time(s) when it is
|
||||||
|
|
|
@ -95,99 +95,6 @@ void GLBackend::syncInputStateCache() {
|
||||||
glBindVertexArray(_input._defaultVAO);
|
glBindVertexArray(_input._defaultVAO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::updateInput() {
|
|
||||||
if (_input._invalidFormat || _input._invalidBuffers.any()) {
|
|
||||||
|
|
||||||
if (_input._invalidFormat) {
|
|
||||||
InputStageState::ActivationCache newActivation;
|
|
||||||
|
|
||||||
_stats._ISNumFormatChanges++;
|
|
||||||
|
|
||||||
// Check expected activation
|
|
||||||
if (_input._format) {
|
|
||||||
for (auto& it : _input._format->getAttributes()) {
|
|
||||||
const Stream::Attribute& attrib = (it).second;
|
|
||||||
uint8_t locationCount = attrib._element.getLocationCount();
|
|
||||||
for (int i = 0; i < locationCount; ++i) {
|
|
||||||
newActivation.set(attrib._slot + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Manage Activation what was and what is expected now
|
|
||||||
for (unsigned int i = 0; i < newActivation.size(); i++) {
|
|
||||||
bool newState = newActivation[i];
|
|
||||||
if (newState != _input._attributeActivation[i]) {
|
|
||||||
|
|
||||||
if (newState) {
|
|
||||||
glEnableVertexAttribArray(i);
|
|
||||||
} else {
|
|
||||||
glDisableVertexAttribArray(i);
|
|
||||||
}
|
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
|
|
||||||
_input._attributeActivation.flip(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// now we need to bind the buffers and assign the attrib pointers
|
|
||||||
if (_input._format) {
|
|
||||||
const Buffers& buffers = _input._buffers;
|
|
||||||
const Offsets& offsets = _input._bufferOffsets;
|
|
||||||
const Offsets& strides = _input._bufferStrides;
|
|
||||||
|
|
||||||
const Stream::Format::AttributeMap& attributes = _input._format->getAttributes();
|
|
||||||
auto& inputChannels = _input._format->getChannels();
|
|
||||||
_stats._ISNumInputBufferChanges++;
|
|
||||||
|
|
||||||
GLuint boundVBO = 0;
|
|
||||||
for (auto& channelIt : inputChannels) {
|
|
||||||
const Stream::Format::ChannelMap::value_type::second_type& channel = (channelIt).second;
|
|
||||||
if ((channelIt).first < buffers.size()) {
|
|
||||||
int bufferNum = (channelIt).first;
|
|
||||||
|
|
||||||
if (_input._invalidBuffers.test(bufferNum) || _input._invalidFormat) {
|
|
||||||
// GLuint vbo = gpu::GL41Backend::getBufferID((*buffers[bufferNum]));
|
|
||||||
GLuint vbo = _input._bufferVBOs[bufferNum];
|
|
||||||
if (boundVBO != vbo) {
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
boundVBO = vbo;
|
|
||||||
}
|
|
||||||
_input._invalidBuffers[bufferNum] = false;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < channel._slots.size(); i++) {
|
|
||||||
const Stream::Attribute& attrib = attributes.at(channel._slots[i]);
|
|
||||||
GLuint slot = attrib._slot;
|
|
||||||
GLuint count = attrib._element.getLocationScalarCount();
|
|
||||||
uint8_t locationCount = attrib._element.getLocationCount();
|
|
||||||
GLenum type = gl::ELEMENT_TYPE_TO_GL[attrib._element.getType()];
|
|
||||||
// GLenum perLocationStride = strides[bufferNum];
|
|
||||||
GLenum perLocationStride = attrib._element.getLocationSize();
|
|
||||||
GLuint stride = (GLuint)strides[bufferNum];
|
|
||||||
GLuint pointer = (GLuint)(attrib._offset + offsets[bufferNum]);
|
|
||||||
GLboolean isNormalized = attrib._element.isNormalized();
|
|
||||||
|
|
||||||
for (size_t locNum = 0; locNum < locationCount; ++locNum) {
|
|
||||||
glVertexAttribPointer(slot + (GLuint)locNum, count, type, isNormalized, stride,
|
|
||||||
reinterpret_cast<GLvoid*>(pointer + perLocationStride * (GLuint)locNum));
|
|
||||||
glVertexAttribDivisor(slot + (GLuint)locNum, attrib._frequency);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Support properly the IAttrib version
|
|
||||||
|
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// everything format related should be in sync now
|
|
||||||
_input._invalidFormat = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLBackend::resetInputStage() {
|
void GLBackend::resetInputStage() {
|
||||||
// Reset index buffer
|
// Reset index buffer
|
||||||
_input._indexBufferType = UINT32;
|
_input._indexBufferType = UINT32;
|
||||||
|
|
|
@ -138,43 +138,6 @@ void GLBackend::TransformStageState::bindCurrentCamera(int eye) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::updateTransform(const Batch& batch) {
|
|
||||||
_transform.update(_commandIndex, _stereo);
|
|
||||||
|
|
||||||
auto& drawCallInfoBuffer = batch.getDrawCallInfoBuffer();
|
|
||||||
if (batch._currentNamedCall.empty()) {
|
|
||||||
auto& drawCallInfo = drawCallInfoBuffer[_currentDraw];
|
|
||||||
if (_transform._enabledDrawcallInfoBuffer) {
|
|
||||||
glDisableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO); // Make sure attrib array is disabled
|
|
||||||
_transform._enabledDrawcallInfoBuffer = false;
|
|
||||||
}
|
|
||||||
glVertexAttribI2i(gpu::Stream::DRAW_CALL_INFO, drawCallInfo.index, drawCallInfo.unused);
|
|
||||||
} else {
|
|
||||||
#if defined(SUPPORT_VERTEX_ATTRIB_FORMAT)
|
|
||||||
if (!_transform._enabledDrawcallInfoBuffer) {
|
|
||||||
glEnableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO); // Make sure attrib array is enabled
|
|
||||||
glVertexAttribIFormat(gpu::Stream::DRAW_CALL_INFO, 2, GL_UNSIGNED_SHORT, 0);
|
|
||||||
glVertexAttribBinding(gpu::Stream::DRAW_CALL_INFO, gpu::Stream::DRAW_CALL_INFO);
|
|
||||||
glVertexBindingDivisor(gpu::Stream::DRAW_CALL_INFO, 1);
|
|
||||||
_transform._enabledDrawcallInfoBuffer = true;
|
|
||||||
}
|
|
||||||
// NOTE: A stride of zero in BindVertexBuffer signifies that all elements are sourced from the same location,
|
|
||||||
// so we must provide a stride.
|
|
||||||
// This is in contrast to VertexAttrib*Pointer, where a zero signifies tightly-packed elements.
|
|
||||||
glBindVertexBuffer(gpu::Stream::DRAW_CALL_INFO, _transform._drawCallInfoBuffer, (GLintptr)_transform._drawCallInfoOffsets[batch._currentNamedCall], 2 * sizeof(GLushort));
|
|
||||||
#else
|
|
||||||
if (!_transform._enabledDrawcallInfoBuffer) {
|
|
||||||
glEnableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO); // Make sure attrib array is enabled
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _transform._drawCallInfoBuffer);
|
|
||||||
glVertexAttribDivisor(gpu::Stream::DRAW_CALL_INFO, 1);
|
|
||||||
_transform._enabledDrawcallInfoBuffer = true;
|
|
||||||
}
|
|
||||||
glVertexAttribIPointer(gpu::Stream::DRAW_CALL_INFO, 2, GL_UNSIGNED_SHORT, 0, _transform._drawCallInfoOffsets[batch._currentNamedCall]);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLBackend::resetTransformStage() {
|
void GLBackend::resetTransformStage() {
|
||||||
glDisableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO);
|
glDisableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO);
|
||||||
|
|
|
@ -83,8 +83,7 @@ protected:
|
||||||
// Synchronize the state cache of this Backend with the actual real state of the GL Context
|
// Synchronize the state cache of this Backend with the actual real state of the GL Context
|
||||||
void transferTransformState(const Batch& batch) const override;
|
void transferTransformState(const Batch& batch) const override;
|
||||||
void initTransform() override;
|
void initTransform() override;
|
||||||
void updateTransform(const Batch& batch);
|
void updateTransform(const Batch& batch) override;
|
||||||
void resetTransformStage();
|
|
||||||
|
|
||||||
// Output stage
|
// Output stage
|
||||||
void do_blit(const Batch& batch, size_t paramOffset) override;
|
void do_blit(const Batch& batch, size_t paramOffset) override;
|
||||||
|
|
|
@ -79,3 +79,28 @@ void GL41Backend::transferTransformState(const Batch& batch) const {
|
||||||
// Make sure the current Camera offset is unknown before render Draw
|
// Make sure the current Camera offset is unknown before render Draw
|
||||||
_transform._currentCameraOffset = INVALID_OFFSET;
|
_transform._currentCameraOffset = INVALID_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GL41Backend::updateTransform(const Batch& batch) {
|
||||||
|
_transform.update(_commandIndex, _stereo);
|
||||||
|
|
||||||
|
auto& drawCallInfoBuffer = batch.getDrawCallInfoBuffer();
|
||||||
|
if (batch._currentNamedCall.empty()) {
|
||||||
|
auto& drawCallInfo = drawCallInfoBuffer[_currentDraw];
|
||||||
|
if (_transform._enabledDrawcallInfoBuffer) {
|
||||||
|
glDisableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO); // Make sure attrib array is disabled
|
||||||
|
_transform._enabledDrawcallInfoBuffer = false;
|
||||||
|
}
|
||||||
|
glVertexAttribI2i(gpu::Stream::DRAW_CALL_INFO, drawCallInfo.index, drawCallInfo.unused);
|
||||||
|
} else {
|
||||||
|
if (!_transform._enabledDrawcallInfoBuffer) {
|
||||||
|
glEnableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO); // Make sure attrib array is enabled
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, _transform._drawCallInfoBuffer);
|
||||||
|
glVertexAttribDivisor(gpu::Stream::DRAW_CALL_INFO, 1);
|
||||||
|
_transform._enabledDrawcallInfoBuffer = true;
|
||||||
|
}
|
||||||
|
glVertexAttribIPointer(gpu::Stream::DRAW_CALL_INFO, 2, GL_UNSIGNED_SHORT, 0, _transform._drawCallInfoOffsets[batch._currentNamedCall]);
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
}
|
|
@ -136,8 +136,7 @@ protected:
|
||||||
// Synchronize the state cache of this Backend with the actual real state of the GL Context
|
// Synchronize the state cache of this Backend with the actual real state of the GL Context
|
||||||
void transferTransformState(const Batch& batch) const override;
|
void transferTransformState(const Batch& batch) const override;
|
||||||
void initTransform() override;
|
void initTransform() override;
|
||||||
void updateTransform(const Batch& batch);
|
void updateTransform(const Batch& batch) override;
|
||||||
void resetTransformStage();
|
|
||||||
|
|
||||||
// Output stage
|
// Output stage
|
||||||
void do_blit(const Batch& batch, size_t paramOffset) override;
|
void do_blit(const Batch& batch, size_t paramOffset) override;
|
||||||
|
|
|
@ -66,3 +66,32 @@ void GL45Backend::transferTransformState(const Batch& batch) const {
|
||||||
// Make sure the current Camera offset is unknown before render Draw
|
// Make sure the current Camera offset is unknown before render Draw
|
||||||
_transform._currentCameraOffset = INVALID_OFFSET;
|
_transform._currentCameraOffset = INVALID_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GL45Backend::updateTransform(const Batch& batch) {
|
||||||
|
_transform.update(_commandIndex, _stereo);
|
||||||
|
|
||||||
|
auto& drawCallInfoBuffer = batch.getDrawCallInfoBuffer();
|
||||||
|
if (batch._currentNamedCall.empty()) {
|
||||||
|
auto& drawCallInfo = drawCallInfoBuffer[_currentDraw];
|
||||||
|
if (_transform._enabledDrawcallInfoBuffer) {
|
||||||
|
glDisableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO); // Make sure attrib array is disabled
|
||||||
|
_transform._enabledDrawcallInfoBuffer = false;
|
||||||
|
}
|
||||||
|
glVertexAttribI2i(gpu::Stream::DRAW_CALL_INFO, drawCallInfo.index, drawCallInfo.unused);
|
||||||
|
} else {
|
||||||
|
if (!_transform._enabledDrawcallInfoBuffer) {
|
||||||
|
glEnableVertexAttribArray(gpu::Stream::DRAW_CALL_INFO); // Make sure attrib array is enabled
|
||||||
|
glVertexAttribIFormat(gpu::Stream::DRAW_CALL_INFO, 2, GL_UNSIGNED_SHORT, 0);
|
||||||
|
glVertexAttribBinding(gpu::Stream::DRAW_CALL_INFO, gpu::Stream::DRAW_CALL_INFO);
|
||||||
|
glVertexBindingDivisor(gpu::Stream::DRAW_CALL_INFO, 1);
|
||||||
|
_transform._enabledDrawcallInfoBuffer = true;
|
||||||
|
}
|
||||||
|
// NOTE: A stride of zero in BindVertexBuffer signifies that all elements are sourced from the same location,
|
||||||
|
// so we must provide a stride.
|
||||||
|
// This is in contrast to VertexAttrib*Pointer, where a zero signifies tightly-packed elements.
|
||||||
|
glBindVertexBuffer(gpu::Stream::DRAW_CALL_INFO, _transform._drawCallInfoBuffer, (GLintptr)_transform._drawCallInfoOffsets[batch._currentNamedCall], 2 * sizeof(GLushort));
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)CHECK_GL_ERROR();
|
||||||
|
}
|
Loading…
Reference in a new issue