mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 23:53:54 +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));
|
||||
}
|
||||
|
||||
// if (enableDebugLogger) {
|
||||
if (enableDebugLogger) {
|
||||
makeCurrent();
|
||||
glDebugMessageCallback(debugMessageCallback, NULL);
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
||||
doneCurrent();
|
||||
// }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ Q_LOGGING_CATEGORY(gpugl41logging, "hifi.gpu.gl41")
|
|||
using namespace gpu;
|
||||
using namespace gpu::gl41;
|
||||
|
||||
const std::string GL41Backend::GL41_VERSION { "GL41" };
|
||||
|
||||
void GL41Backend::do_draw(const Batch& batch, size_t paramOffset) {
|
||||
Primitive primitiveType = (Primitive)batch._params[paramOffset + 2]._uint;
|
||||
GLenum mode = gl::PRIMITIVE_TO_GL[primitiveType];
|
||||
|
|
|
@ -44,6 +44,9 @@ public:
|
|||
explicit GL41Backend(bool syncCache) : Parent(syncCache) {}
|
||||
GL41Backend() : Parent() {}
|
||||
|
||||
static const std::string GL41_VERSION;
|
||||
const std::string& getVersion() const override { return GL41_VERSION; }
|
||||
|
||||
class GL41Texture : public GLTexture {
|
||||
using Parent = GLTexture;
|
||||
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) {
|
||||
// DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT
|
||||
|
||||
GLuint fbo { 0 };
|
||||
glGenFramebuffers(1, &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) {
|
||||
#ifdef USE_GL45_COPYIMAGE
|
||||
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
|
||||
// DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT
|
||||
|
||||
struct MipDesc {
|
||||
GLint _faceSize;
|
||||
GLint _size;
|
||||
|
@ -361,7 +349,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui
|
|||
|
||||
std::vector<GLubyte> bytes;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT);
|
||||
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT);
|
||||
glBindTexture(texTarget, srcId);
|
||||
const auto& faceTargets = GLTexture::getFaceTargets(texTarget);
|
||||
GLint internalFormat { 0 };
|
||||
|
@ -399,7 +387,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui
|
|||
GLuint pbo { 0 };
|
||||
glGenBuffers(1, &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();
|
||||
|
||||
// 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);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT);
|
||||
glBindTexture(texTarget, destId);
|
||||
|
||||
// Transfer from pbo to new texture
|
||||
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);
|
||||
glDeleteBuffers(1, &pbo);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GL41VariableAllocationTexture::promote() {
|
||||
|
|
|
@ -18,6 +18,8 @@ Q_LOGGING_CATEGORY(gpugl45logging, "hifi.gpu.gl45")
|
|||
using namespace gpu;
|
||||
using namespace gpu::gl45;
|
||||
|
||||
const std::string GL45Backend::GL45_VERSION { "GL45" };
|
||||
|
||||
void GL45Backend::recycle() const {
|
||||
Parent::recycle();
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ public:
|
|||
explicit GL45Backend(bool syncCache) : Parent(syncCache) {}
|
||||
GL45Backend() : Parent() {}
|
||||
|
||||
static const std::string GL45_VERSION;
|
||||
const std::string& getVersion() const override { return GL45_VERSION; }
|
||||
|
||||
class GL45Texture : public GLTexture {
|
||||
using Parent = GLTexture;
|
||||
friend class GL45Backend;
|
||||
|
|
|
@ -134,7 +134,7 @@ void GL45ResourceTexture::promote() {
|
|||
|
||||
// copy pre-existing mips
|
||||
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
|
||||
glDeleteTextures(1, &oldId);
|
||||
|
@ -158,7 +158,7 @@ void GL45ResourceTexture::demote() {
|
|||
|
||||
// copy pre-existing mips
|
||||
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
|
||||
glDeleteTextures(1, &oldId);
|
||||
|
|
|
@ -50,6 +50,10 @@ Context::Context(const Context& context) {
|
|||
Context::~Context() {
|
||||
}
|
||||
|
||||
const std::string& Context::getBackendVersion() const {
|
||||
return _backend->getVersion();
|
||||
}
|
||||
|
||||
void Context::beginFrame(const glm::mat4& renderPose) {
|
||||
assert(!_frameActive);
|
||||
_frameActive = true;
|
||||
|
|
|
@ -54,6 +54,9 @@ class Backend {
|
|||
public:
|
||||
virtual~ Backend() {};
|
||||
|
||||
|
||||
virtual const std::string& getVersion() const = 0;
|
||||
|
||||
void setStereoState(const StereoState& stereo) { _stereo = stereo; }
|
||||
|
||||
virtual void render(const Batch& batch) = 0;
|
||||
|
@ -153,6 +156,8 @@ public:
|
|||
Context();
|
||||
~Context();
|
||||
|
||||
const std::string& getBackendVersion() const;
|
||||
|
||||
void beginFrame(const glm::mat4& renderPose = glm::mat4());
|
||||
void appendFrameBatch(Batch& batch);
|
||||
FramePointer endFrame();
|
||||
|
|
|
@ -408,7 +408,7 @@ void Texture::setStoredMipFormat(const Element& format) {
|
|||
_storage->setFormat(format);
|
||||
}
|
||||
|
||||
const Element Texture::getStoredMipFormat() const {
|
||||
Element Texture::getStoredMipFormat() const {
|
||||
if (_storage) {
|
||||
return _storage->getFormat();
|
||||
} else {
|
||||
|
|
|
@ -285,7 +285,7 @@ public:
|
|||
Stamp bumpStamp() { return ++_stamp; }
|
||||
|
||||
void setFormat(const Element& format) { _format = format; }
|
||||
const Element& getFormat() const { return _format; }
|
||||
Element getFormat() const { return _format; }
|
||||
|
||||
private:
|
||||
Stamp _stamp { 0 };
|
||||
|
@ -372,7 +372,7 @@ public:
|
|||
bool isColorRenderTarget() const;
|
||||
bool isDepthStencilRenderTarget() const;
|
||||
|
||||
const Element getTexelFormat() const { return _texelFormat; }
|
||||
Element getTexelFormat() const { return _texelFormat; }
|
||||
|
||||
Vec3u getDimensions() const { return Vec3u(_width, _height, _depth); }
|
||||
uint16 getWidth() const { return _width; }
|
||||
|
@ -468,7 +468,7 @@ public:
|
|||
|
||||
// Mip storage format is constant across all mips
|
||||
void setStoredMipFormat(const Element& format);
|
||||
const Element getStoredMipFormat() const;
|
||||
Element getStoredMipFormat() const;
|
||||
|
||||
// Manually allocate the mips down until the specified maxMip
|
||||
// this is just allocating the sysmem version of it
|
||||
|
|
Loading…
Reference in a new issue