mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 08:49:05 +02:00
Clean up the new code and adress review comments
This commit is contained in:
parent
e561a33b01
commit
32d675c82b
11 changed files with 33 additions and 28 deletions
|
@ -307,12 +307,12 @@ void Context::create() {
|
||||||
qApp->setProperty(hifi::properties::gl::PRIMARY_CONTEXT, QVariant::fromValue((void*)PRIMARY));
|
qApp->setProperty(hifi::properties::gl::PRIMARY_CONTEXT, QVariant::fromValue((void*)PRIMARY));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (enableDebugLogger) {
|
if (enableDebugLogger) {
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
glDebugMessageCallback(debugMessageCallback, NULL);
|
glDebugMessageCallback(debugMessageCallback, NULL);
|
||||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
||||||
doneCurrent();
|
doneCurrent();
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ Q_LOGGING_CATEGORY(gpugl41logging, "hifi.gpu.gl41")
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
using namespace gpu::gl41;
|
using namespace gpu::gl41;
|
||||||
|
|
||||||
|
const std::string GL41Backend::GL41_VERSION { "GL41" };
|
||||||
|
|
||||||
void GL41Backend::do_draw(const Batch& batch, size_t paramOffset) {
|
void GL41Backend::do_draw(const Batch& batch, size_t paramOffset) {
|
||||||
Primitive primitiveType = (Primitive)batch._params[paramOffset + 2]._uint;
|
Primitive primitiveType = (Primitive)batch._params[paramOffset + 2]._uint;
|
||||||
GLenum mode = gl::PRIMITIVE_TO_GL[primitiveType];
|
GLenum mode = gl::PRIMITIVE_TO_GL[primitiveType];
|
||||||
|
|
|
@ -44,6 +44,9 @@ public:
|
||||||
explicit GL41Backend(bool syncCache) : Parent(syncCache) {}
|
explicit GL41Backend(bool syncCache) : Parent(syncCache) {}
|
||||||
GL41Backend() : Parent() {}
|
GL41Backend() : Parent() {}
|
||||||
|
|
||||||
|
static const std::string GL41_VERSION;
|
||||||
|
const std::string& getVersion() const override { return GL41_VERSION; }
|
||||||
|
|
||||||
class GL41Texture : public GLTexture {
|
class GL41Texture : public GLTexture {
|
||||||
using Parent = GLTexture;
|
using Parent = GLTexture;
|
||||||
friend class GL41Backend;
|
friend class GL41Backend;
|
||||||
|
|
|
@ -310,6 +310,8 @@ void GL41VariableAllocationTexture::syncSampler() const {
|
||||||
|
|
||||||
|
|
||||||
void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) {
|
void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) {
|
||||||
|
// DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT
|
||||||
|
|
||||||
GLuint fbo { 0 };
|
GLuint fbo { 0 };
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||||
|
@ -334,22 +336,8 @@ void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GL
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) {
|
void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) {
|
||||||
#ifdef USE_GL45_COPYIMAGE
|
// DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT
|
||||||
for (uint16_t mip = populatedMips; mip < numMips; ++mip) {
|
|
||||||
auto mipDimensions = texture.evalMipDimensions(mip);
|
|
||||||
uint16_t targetMip = mip - destAllocatedMip;
|
|
||||||
uint16_t sourceMip = mip - srcAllocatedMip;
|
|
||||||
auto faces = GLTexture::getFaceCount(texTarget);
|
|
||||||
for (uint8_t face = 0; face < faces; ++face) {
|
|
||||||
glCopyImageSubData(
|
|
||||||
srcId, texTarget, sourceMip, 0, 0, face,
|
|
||||||
destId, texTarget, targetMip, 0, 0, face,
|
|
||||||
mipDimensions.x, mipDimensions.y, 1
|
|
||||||
);
|
|
||||||
(void)CHECK_GL_ERROR();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
struct MipDesc {
|
struct MipDesc {
|
||||||
GLint _faceSize;
|
GLint _faceSize;
|
||||||
GLint _size;
|
GLint _size;
|
||||||
|
@ -361,7 +349,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui
|
||||||
|
|
||||||
std::vector<GLubyte> bytes;
|
std::vector<GLubyte> bytes;
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT);
|
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT);
|
||||||
glBindTexture(texTarget, srcId);
|
glBindTexture(texTarget, srcId);
|
||||||
const auto& faceTargets = GLTexture::getFaceTargets(texTarget);
|
const auto& faceTargets = GLTexture::getFaceTargets(texTarget);
|
||||||
GLint internalFormat { 0 };
|
GLint internalFormat { 0 };
|
||||||
|
@ -399,7 +387,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui
|
||||||
GLuint pbo { 0 };
|
GLuint pbo { 0 };
|
||||||
glGenBuffers(1, &pbo);
|
glGenBuffers(1, &pbo);
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
|
||||||
glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY);
|
glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STATIC_COPY);
|
||||||
(void)CHECK_GL_ERROR();
|
(void)CHECK_GL_ERROR();
|
||||||
|
|
||||||
// Transfer from source texture to pbo
|
// Transfer from source texture to pbo
|
||||||
|
@ -420,7 +408,6 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT);
|
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT);
|
||||||
glBindTexture(texTarget, destId);
|
|
||||||
|
|
||||||
// Transfer from pbo to new texture
|
// Transfer from pbo to new texture
|
||||||
for (uint16_t mip = populatedMips; mip < numMips; ++mip) {
|
for (uint16_t mip = populatedMips; mip < numMips; ++mip) {
|
||||||
|
@ -443,7 +430,6 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui
|
||||||
|
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
glDeleteBuffers(1, &pbo);
|
glDeleteBuffers(1, &pbo);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GL41VariableAllocationTexture::promote() {
|
void GL41VariableAllocationTexture::promote() {
|
||||||
|
|
|
@ -18,6 +18,8 @@ Q_LOGGING_CATEGORY(gpugl45logging, "hifi.gpu.gl45")
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
using namespace gpu::gl45;
|
using namespace gpu::gl45;
|
||||||
|
|
||||||
|
const std::string GL45Backend::GL45_VERSION { "GL45" };
|
||||||
|
|
||||||
void GL45Backend::recycle() const {
|
void GL45Backend::recycle() const {
|
||||||
Parent::recycle();
|
Parent::recycle();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ public:
|
||||||
explicit GL45Backend(bool syncCache) : Parent(syncCache) {}
|
explicit GL45Backend(bool syncCache) : Parent(syncCache) {}
|
||||||
GL45Backend() : Parent() {}
|
GL45Backend() : Parent() {}
|
||||||
|
|
||||||
|
static const std::string GL45_VERSION;
|
||||||
|
const std::string& getVersion() const override { return GL45_VERSION; }
|
||||||
|
|
||||||
class GL45Texture : public GLTexture {
|
class GL45Texture : public GLTexture {
|
||||||
using Parent = GLTexture;
|
using Parent = GLTexture;
|
||||||
friend class GL45Backend;
|
friend class GL45Backend;
|
||||||
|
|
|
@ -134,7 +134,7 @@ void GL45ResourceTexture::promote() {
|
||||||
|
|
||||||
// copy pre-existing mips
|
// copy pre-existing mips
|
||||||
uint16_t numMips = _gpuObject.getNumMips();
|
uint16_t numMips = _gpuObject.getNumMips();
|
||||||
copyTexGPUMem(_gpuObject, _target, _id, oldId, numMips, oldAllocatedMip, _allocatedMip, _populatedMip);
|
copyTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip);
|
||||||
|
|
||||||
// destroy the old texture
|
// destroy the old texture
|
||||||
glDeleteTextures(1, &oldId);
|
glDeleteTextures(1, &oldId);
|
||||||
|
@ -158,7 +158,7 @@ void GL45ResourceTexture::demote() {
|
||||||
|
|
||||||
// copy pre-existing mips
|
// copy pre-existing mips
|
||||||
uint16_t numMips = _gpuObject.getNumMips();
|
uint16_t numMips = _gpuObject.getNumMips();
|
||||||
copyTexGPUMem(_gpuObject, _target, _id, oldId, numMips, oldAllocatedMip, _allocatedMip, _populatedMip);
|
copyTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip);
|
||||||
|
|
||||||
// destroy the old texture
|
// destroy the old texture
|
||||||
glDeleteTextures(1, &oldId);
|
glDeleteTextures(1, &oldId);
|
||||||
|
|
|
@ -50,6 +50,10 @@ Context::Context(const Context& context) {
|
||||||
Context::~Context() {
|
Context::~Context() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& Context::getBackendVersion() const {
|
||||||
|
return _backend->getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
void Context::beginFrame(const glm::mat4& renderPose) {
|
void Context::beginFrame(const glm::mat4& renderPose) {
|
||||||
assert(!_frameActive);
|
assert(!_frameActive);
|
||||||
_frameActive = true;
|
_frameActive = true;
|
||||||
|
|
|
@ -54,6 +54,9 @@ class Backend {
|
||||||
public:
|
public:
|
||||||
virtual~ Backend() {};
|
virtual~ Backend() {};
|
||||||
|
|
||||||
|
|
||||||
|
virtual const std::string& getVersion() const = 0;
|
||||||
|
|
||||||
void setStereoState(const StereoState& stereo) { _stereo = stereo; }
|
void setStereoState(const StereoState& stereo) { _stereo = stereo; }
|
||||||
|
|
||||||
virtual void render(const Batch& batch) = 0;
|
virtual void render(const Batch& batch) = 0;
|
||||||
|
@ -153,6 +156,8 @@ public:
|
||||||
Context();
|
Context();
|
||||||
~Context();
|
~Context();
|
||||||
|
|
||||||
|
const std::string& getBackendVersion() const;
|
||||||
|
|
||||||
void beginFrame(const glm::mat4& renderPose = glm::mat4());
|
void beginFrame(const glm::mat4& renderPose = glm::mat4());
|
||||||
void appendFrameBatch(Batch& batch);
|
void appendFrameBatch(Batch& batch);
|
||||||
FramePointer endFrame();
|
FramePointer endFrame();
|
||||||
|
|
|
@ -408,7 +408,7 @@ void Texture::setStoredMipFormat(const Element& format) {
|
||||||
_storage->setFormat(format);
|
_storage->setFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Element Texture::getStoredMipFormat() const {
|
Element Texture::getStoredMipFormat() const {
|
||||||
if (_storage) {
|
if (_storage) {
|
||||||
return _storage->getFormat();
|
return _storage->getFormat();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -285,7 +285,7 @@ public:
|
||||||
Stamp bumpStamp() { return ++_stamp; }
|
Stamp bumpStamp() { return ++_stamp; }
|
||||||
|
|
||||||
void setFormat(const Element& format) { _format = format; }
|
void setFormat(const Element& format) { _format = format; }
|
||||||
const Element& getFormat() const { return _format; }
|
Element getFormat() const { return _format; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Stamp _stamp { 0 };
|
Stamp _stamp { 0 };
|
||||||
|
@ -372,7 +372,7 @@ public:
|
||||||
bool isColorRenderTarget() const;
|
bool isColorRenderTarget() const;
|
||||||
bool isDepthStencilRenderTarget() const;
|
bool isDepthStencilRenderTarget() const;
|
||||||
|
|
||||||
const Element getTexelFormat() const { return _texelFormat; }
|
Element getTexelFormat() const { return _texelFormat; }
|
||||||
|
|
||||||
Vec3u getDimensions() const { return Vec3u(_width, _height, _depth); }
|
Vec3u getDimensions() const { return Vec3u(_width, _height, _depth); }
|
||||||
uint16 getWidth() const { return _width; }
|
uint16 getWidth() const { return _width; }
|
||||||
|
@ -468,7 +468,7 @@ public:
|
||||||
|
|
||||||
// Mip storage format is constant across all mips
|
// Mip storage format is constant across all mips
|
||||||
void setStoredMipFormat(const Element& format);
|
void setStoredMipFormat(const Element& format);
|
||||||
const Element getStoredMipFormat() const;
|
Element getStoredMipFormat() const;
|
||||||
|
|
||||||
// Manually allocate the mips down until the specified maxMip
|
// Manually allocate the mips down until the specified maxMip
|
||||||
// this is just allocating the sysmem version of it
|
// this is just allocating the sysmem version of it
|
||||||
|
|
Loading…
Reference in a new issue