PR feedback

This commit is contained in:
Brad Davis 2016-05-18 22:29:07 -07:00
parent 3cc08cdcfc
commit 7efcad38d2
16 changed files with 84 additions and 100 deletions

View file

@ -16,7 +16,7 @@
#include <functional> #include <functional>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include "../gl41/GLBackend.h" #include "../gl41/GL41Backend.h"
#if defined(NSIGHT_FOUND) #if defined(NSIGHT_FOUND)
#include "nvToolsExt.h" #include "nvToolsExt.h"
@ -36,11 +36,11 @@ static const QString DEBUG_FLAG("HIFI_ENABLE_OPENGL_45");
static bool enableOpenGL45 = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG); static bool enableOpenGL45 = QProcessEnvironment::systemEnvironment().contains(DEBUG_FLAG);
Backend* GLBackend::createBackend() { Backend* GLBackend::createBackend() {
auto version = QOpenGLContextWrapper::currentContextVersion();
#if 0
// FIXME provide a mechanism to override the backend for testing // FIXME provide a mechanism to override the backend for testing
// Where the gpuContext is initialized and where the TRUE Backend is created and assigned // Where the gpuContext is initialized and where the TRUE Backend is created and assigned
#if 0 auto version = QOpenGLContextWrapper::currentContextVersion();
GLBackend* result; GLBackend* result;
if (enableOpenGL45 && version >= 0x0405) { if (enableOpenGL45 && version >= 0x0405) {
result = new gpu::gl45::GLBackend; result = new gpu::gl45::GLBackend;
@ -48,7 +48,7 @@ Backend* GLBackend::createBackend() {
result = new gpu::gl41::GLBackend; result = new gpu::gl41::GLBackend;
} }
#else #else
GLBackend* result = new gpu::gl41::GLBackend; GLBackend* result = new gpu::gl41::GL41Backend;
#endif #endif
result->initInput(); result->initInput();
result->initTransform(); result->initTransform();

View file

@ -1,12 +0,0 @@
//
// Created by Bradley Austin Davis on 2016/05/15
// Copyright 2013-2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "GLQuery.h"
using namespace gpu;
using namespace gpu::gl;

View file

@ -128,13 +128,6 @@ public:
virtual ~GLObject() { } virtual ~GLObject() { }
// Used by derived classes and helpers to ensure the actual GL object exceeds the lifetime of `this`
GLuint takeOwnership() {
GLuint result = _id;
const_cast<GLuint&>(_id) = 0;
return result;
}
const GPUType& _gpuObject; const GPUType& _gpuObject;
const GLuint _id; const GLuint _id;
}; };
@ -146,7 +139,6 @@ class GLQuery;
class GLState; class GLState;
class GLShader; class GLShader;
class GLTexture; class GLTexture;
class GLTextureTransferHelper;
} } // namespace gpu::gl } } // namespace gpu::gl

View file

@ -182,7 +182,7 @@ GLTexture::~GLTexture() {
if (0 == numTexturesForMipCount) { if (0 == numTexturesForMipCount) {
_textureCountByMips.erase(mipCount); _textureCountByMips.erase(mipCount);
if (mipCount == _currentMaxMipCount) { if (mipCount == _currentMaxMipCount) {
_currentMaxMipCount = _textureCountByMips.rbegin()->first; _currentMaxMipCount = (_textureCountByMips.empty() ? 0 : _textureCountByMips.rbegin()->first);
} }
} }
} }

View file

@ -102,6 +102,13 @@ public:
return result; return result;
} }
// Used by derived classes and helpers to ensure the actual GL object exceeds the lifetime of `this`
GLuint takeOwnership() {
GLuint result = _id;
const_cast<GLuint&>(_id) = 0;
return result;
}
~GLTexture(); ~GLTexture();
const GLuint& _texture { _id }; const GLuint& _texture { _id };

View file

@ -13,6 +13,7 @@
#endif #endif
#include "GLShared.h" #include "GLShared.h"
#include "GLTexture.h"
using namespace gpu; using namespace gpu;
using namespace gpu::gl; using namespace gpu::gl;

View file

@ -14,7 +14,6 @@
#include <GenericQueueThread.h> #include <GenericQueueThread.h>
#include "GLShared.h" #include "GLShared.h"
#include "GLTexture.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#define THREADED_TEXTURE_TRANSFER #define THREADED_TEXTURE_TRANSFER

View file

@ -5,7 +5,7 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "GLBackend.h" #include "GL41Backend.h"
#include <mutex> #include <mutex>
#include <queue> #include <queue>
@ -18,7 +18,7 @@ Q_LOGGING_CATEGORY(gpugl41logging, "hifi.gpu.gl41")
using namespace gpu; using namespace gpu;
using namespace gpu::gl41; using namespace gpu::gl41;
void GLBackend::do_draw(Batch& batch, size_t paramOffset) { void GL41Backend::do_draw(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];
uint32 numVertices = batch._params[paramOffset + 1]._uint; uint32 numVertices = batch._params[paramOffset + 1]._uint;
@ -43,7 +43,7 @@ void GLBackend::do_draw(Batch& batch, size_t paramOffset) {
(void) CHECK_GL_ERROR(); (void) CHECK_GL_ERROR();
} }
void GLBackend::do_drawIndexed(Batch& batch, size_t paramOffset) { void GL41Backend::do_drawIndexed(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];
uint32 numIndices = batch._params[paramOffset + 1]._uint; uint32 numIndices = batch._params[paramOffset + 1]._uint;
@ -72,7 +72,7 @@ void GLBackend::do_drawIndexed(Batch& batch, size_t paramOffset) {
(void) CHECK_GL_ERROR(); (void) CHECK_GL_ERROR();
} }
void GLBackend::do_drawInstanced(Batch& batch, size_t paramOffset) { void GL41Backend::do_drawInstanced(Batch& batch, size_t paramOffset) {
GLint numInstances = batch._params[paramOffset + 4]._uint; GLint numInstances = batch._params[paramOffset + 4]._uint;
Primitive primitiveType = (Primitive)batch._params[paramOffset + 3]._uint; Primitive primitiveType = (Primitive)batch._params[paramOffset + 3]._uint;
GLenum mode = gl::PRIMITIVE_TO_GL[primitiveType]; GLenum mode = gl::PRIMITIVE_TO_GL[primitiveType];
@ -108,7 +108,7 @@ void glbackend_glDrawElementsInstancedBaseVertexBaseInstance(GLenum mode, GLsize
#endif #endif
} }
void GLBackend::do_drawIndexedInstanced(Batch& batch, size_t paramOffset) { void GL41Backend::do_drawIndexedInstanced(Batch& batch, size_t paramOffset) {
GLint numInstances = batch._params[paramOffset + 4]._uint; GLint numInstances = batch._params[paramOffset + 4]._uint;
GLenum mode = gl::PRIMITIVE_TO_GL[(Primitive)batch._params[paramOffset + 3]._uint]; GLenum mode = gl::PRIMITIVE_TO_GL[(Primitive)batch._params[paramOffset + 3]._uint];
uint32 numIndices = batch._params[paramOffset + 2]._uint; uint32 numIndices = batch._params[paramOffset + 2]._uint;
@ -143,7 +143,7 @@ void GLBackend::do_drawIndexedInstanced(Batch& batch, size_t paramOffset) {
} }
void GLBackend::do_multiDrawIndirect(Batch& batch, size_t paramOffset) { void GL41Backend::do_multiDrawIndirect(Batch& batch, size_t paramOffset) {
#if (GPU_INPUT_PROFILE == GPU_CORE_43) #if (GPU_INPUT_PROFILE == GPU_CORE_43)
uint commandCount = batch._params[paramOffset + 0]._uint; uint commandCount = batch._params[paramOffset + 0]._uint;
GLenum mode = gl::PRIMITIVE_TO_GL[(Primitive)batch._params[paramOffset + 1]._uint]; GLenum mode = gl::PRIMITIVE_TO_GL[(Primitive)batch._params[paramOffset + 1]._uint];
@ -159,7 +159,7 @@ void GLBackend::do_multiDrawIndirect(Batch& batch, size_t paramOffset) {
} }
void GLBackend::do_multiDrawIndexedIndirect(Batch& batch, size_t paramOffset) { void GL41Backend::do_multiDrawIndexedIndirect(Batch& batch, size_t paramOffset) {
#if (GPU_INPUT_PROFILE == GPU_CORE_43) #if (GPU_INPUT_PROFILE == GPU_CORE_43)
uint commandCount = batch._params[paramOffset + 0]._uint; uint commandCount = batch._params[paramOffset + 0]._uint;
GLenum mode = gl::PRIMITIVE_TO_GL[(Primitive)batch._params[paramOffset + 1]._uint]; GLenum mode = gl::PRIMITIVE_TO_GL[(Primitive)batch._params[paramOffset + 1]._uint];

View file

@ -1,5 +1,5 @@
// //
// GLBackend.h // GL41Backend.h
// libraries/gpu/src/gpu // libraries/gpu/src/gpu
// //
// Created by Sam Gateau on 10/27/2014. // Created by Sam Gateau on 10/27/2014.
@ -8,8 +8,8 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_gpu_41_GLBackend_h #ifndef hifi_gpu_41_GL41Backend_h
#define hifi_gpu_41_GLBackend_h #define hifi_gpu_41_GL41Backend_h
#include <gl/Config.h> #include <gl/Config.h>
@ -27,21 +27,21 @@
namespace gpu { namespace gl41 { namespace gpu { namespace gl41 {
class GLBackend : public gl::GLBackend { class GL41Backend : public gl::GLBackend {
using Parent = gl::GLBackend; using Parent = gl::GLBackend;
// Context Backend static interface required // Context Backend static interface required
friend class Context; friend class Context;
public: public:
explicit GLBackend(bool syncCache) : Parent(syncCache) {} explicit GL41Backend(bool syncCache) : Parent(syncCache) {}
GLBackend() : Parent() {} GL41Backend() : Parent() {}
class GLTexture : public gpu::gl::GLTexture { class GL41Texture : public gpu::gl::GLTexture {
using Parent = gpu::gl::GLTexture; using Parent = gpu::gl::GLTexture;
GLuint allocate(); GLuint allocate();
public: public:
GLTexture(const Texture& buffer, bool transferrable); GL41Texture(const Texture& buffer, bool transferrable);
GLTexture(const Texture& buffer, GLTexture* original); GL41Texture(const Texture& buffer, GL41Texture* original);
protected: protected:
void transferMip(uint16_t mipLevel, uint8_t face = 0) const; void transferMip(uint16_t mipLevel, uint8_t face = 0) const;

View file

@ -5,13 +5,13 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "GLBackend.h" #include "GL41Backend.h"
#include "../gl/GLBuffer.h" #include "../gl/GLBuffer.h"
using namespace gpu; using namespace gpu;
using namespace gpu::gl41; using namespace gpu::gl41;
class GLBuffer : public gl::GLBuffer { class GL41Buffer : public gl::GLBuffer {
using Parent = gpu::gl::GLBuffer; using Parent = gpu::gl::GLBuffer;
static GLuint allocate() { static GLuint allocate() {
GLuint result; GLuint result;
@ -20,7 +20,7 @@ class GLBuffer : public gl::GLBuffer {
} }
public: public:
GLBuffer(const Buffer& buffer, GLBuffer* original) : Parent(buffer, allocate()) { GL41Buffer(const Buffer& buffer, GL41Buffer* original) : Parent(buffer, allocate()) {
glBindBuffer(GL_ARRAY_BUFFER, _buffer); glBindBuffer(GL_ARRAY_BUFFER, _buffer);
glBufferData(GL_ARRAY_BUFFER, _size, nullptr, GL_DYNAMIC_DRAW); glBufferData(GL_ARRAY_BUFFER, _size, nullptr, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -53,10 +53,10 @@ public:
} }
}; };
GLuint GLBackend::getBufferID(const Buffer& buffer) { GLuint GL41Backend::getBufferID(const Buffer& buffer) {
return GLBuffer::getId<GLBuffer>(buffer); return GL41Buffer::getId<GL41Buffer>(buffer);
} }
gl::GLBuffer* GLBackend::syncGPUObject(const Buffer& buffer) { gl::GLBuffer* GL41Backend::syncGPUObject(const Buffer& buffer) {
return GLBuffer::sync<GLBuffer>(buffer); return GL41Buffer::sync<GL41Buffer>(buffer);
} }

View file

@ -1,5 +1,5 @@
// //
// GLBackendInput.cpp // GL41BackendInput.cpp
// libraries/gpu/src/gpu // libraries/gpu/src/gpu
// //
// Created by Sam Gateau on 3/8/2015. // Created by Sam Gateau on 3/8/2015.
@ -8,7 +8,7 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "GLBackend.h" #include "GL41Backend.h"
using namespace gpu; using namespace gpu;
using namespace gpu::gl41; using namespace gpu::gl41;
@ -22,7 +22,7 @@ using namespace gpu::gl41;
#define SUPPORT_VERTEX_ATTRIB_FORMAT #define SUPPORT_VERTEX_ATTRIB_FORMAT
#endif #endif
void GLBackend::updateInput() { void GL41Backend::updateInput() {
#if defined(SUPPORT_VERTEX_ATTRIB_FORMAT) #if defined(SUPPORT_VERTEX_ATTRIB_FORMAT)
if (_input._invalidFormat) { if (_input._invalidFormat) {
@ -36,7 +36,7 @@ void GLBackend::updateInput() {
GLuint slot = attrib._slot; GLuint slot = attrib._slot;
GLuint count = attrib._element.getLocationScalarCount(); GLuint count = attrib._element.getLocationScalarCount();
uint8_t locationCount = attrib._element.getLocationCount(); uint8_t locationCount = attrib._element.getLocationCount();
GLenum type = _elementTypeToGLType[attrib._element.getType()]; GLenum type = _elementTypeToGL41Type[attrib._element.getType()];
GLuint offset = attrib._offset;; GLuint offset = attrib._offset;;
GLboolean isNormalized = attrib._element.isNormalized(); GLboolean isNormalized = attrib._element.isNormalized();
@ -142,7 +142,7 @@ void GLBackend::updateInput() {
int bufferNum = (channelIt).first; int bufferNum = (channelIt).first;
if (_input._invalidBuffers.test(bufferNum) || _input._invalidFormat) { if (_input._invalidBuffers.test(bufferNum) || _input._invalidFormat) {
// GLuint vbo = gpu::GLBackend::getBufferID((*buffers[bufferNum])); // GLuint vbo = gpu::GL41Backend::getBufferID((*buffers[bufferNum]));
GLuint vbo = _input._bufferVBOs[bufferNum]; GLuint vbo = _input._bufferVBOs[bufferNum];
if (boundVBO != vbo) { if (boundVBO != vbo) {
glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo);

View file

@ -1,5 +1,5 @@
// //
// GLBackendTexture.cpp // GL41BackendTexture.cpp
// libraries/gpu/src/gpu // libraries/gpu/src/gpu
// //
// Created by Sam Gateau on 1/19/2015. // Created by Sam Gateau on 1/19/2015.
@ -8,7 +8,7 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "GLBackend.h" #include "GL41Backend.h"
#include <QtGui/QImage> #include <QtGui/QImage>
@ -17,7 +17,7 @@
namespace gpu { namespace gl41 { namespace gpu { namespace gl41 {
class GLFramebuffer : public gl::GLFramebuffer { class GL41Framebuffer : public gl::GLFramebuffer {
using Parent = gl::GLFramebuffer; using Parent = gl::GLFramebuffer;
static GLuint allocate() { static GLuint allocate() {
GLuint result; GLuint result;
@ -56,7 +56,7 @@ public:
for (auto& b : _gpuObject.getRenderBuffers()) { for (auto& b : _gpuObject.getRenderBuffers()) {
surface = b._texture; surface = b._texture;
if (surface) { if (surface) {
gltexture = gl::GLTexture::sync<GLBackend::GLTexture>(surface, false); // Grab the gltexture and don't transfer gltexture = gl::GLTexture::sync<GL41Backend::GL41Texture>(surface, false); // Grab the gltexture and don't transfer
} else { } else {
gltexture = nullptr; gltexture = nullptr;
} }
@ -83,7 +83,7 @@ public:
if (_gpuObject.getDepthStamp() != _depthStamp) { if (_gpuObject.getDepthStamp() != _depthStamp) {
auto surface = _gpuObject.getDepthStencilBuffer(); auto surface = _gpuObject.getDepthStencilBuffer();
if (_gpuObject.hasDepthStencil() && surface) { if (_gpuObject.hasDepthStencil() && surface) {
gltexture = gl::GLTexture::sync<GLBackend::GLTexture>(surface, false); // Grab the gltexture and don't transfer gltexture = gl::GLTexture::sync<GL41Backend::GL41Texture>(surface, false); // Grab the gltexture and don't transfer
} }
if (gltexture) { if (gltexture) {
@ -115,19 +115,19 @@ public:
public: public:
GLFramebuffer(const gpu::Framebuffer& framebuffer) GL41Framebuffer(const gpu::Framebuffer& framebuffer)
: Parent(framebuffer, allocate()) { } : Parent(framebuffer, allocate()) { }
}; };
gl::GLFramebuffer* GLBackend::syncGPUObject(const Framebuffer& framebuffer) { gl::GLFramebuffer* GL41Backend::syncGPUObject(const Framebuffer& framebuffer) {
return GLFramebuffer::sync<GLFramebuffer>(framebuffer); return GL41Framebuffer::sync<GL41Framebuffer>(framebuffer);
} }
GLuint GLBackend::getFramebufferID(const FramebufferPointer& framebuffer) { GLuint GL41Backend::getFramebufferID(const FramebufferPointer& framebuffer) {
return framebuffer ? GLFramebuffer::getId<GLFramebuffer>(*framebuffer) : 0; return framebuffer ? GL41Framebuffer::getId<GL41Framebuffer>(*framebuffer) : 0;
} }
void GLBackend::do_blit(Batch& batch, size_t paramOffset) { void GL41Backend::do_blit(Batch& batch, size_t paramOffset) {
auto srcframebuffer = batch._framebuffers.get(batch._params[paramOffset]._uint); auto srcframebuffer = batch._framebuffers.get(batch._params[paramOffset]._uint);
Vec4i srcvp; Vec4i srcvp;
for (auto i = 0; i < 4; ++i) { for (auto i = 0; i < 4; ++i) {

View file

@ -1,5 +1,5 @@
// //
// GLBackendQuery.cpp // GL41BackendQuery.cpp
// libraries/gpu/src/gpu // libraries/gpu/src/gpu
// //
// Created by Sam Gateau on 7/7/2015. // Created by Sam Gateau on 7/7/2015.
@ -8,14 +8,14 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "GLBackend.h" #include "GL41Backend.h"
#include "../gl/GLQuery.h" #include "../gl/GLQuery.h"
using namespace gpu; using namespace gpu;
using namespace gpu::gl41; using namespace gpu::gl41;
class GLQuery : public gpu::gl::GLQuery { class GL41Query : public gpu::gl::GLQuery {
using Parent = gpu::gl::GLBuffer; using Parent = gpu::gl::GLBuffer;
public: public:
static GLuint allocateQuery() { static GLuint allocateQuery() {
@ -24,14 +24,14 @@ public:
return result; return result;
} }
GLQuery(const Query& query) GL41Query(const Query& query)
: gl::GLQuery(query, allocateQuery()) { } : gl::GLQuery(query, allocateQuery()) { }
}; };
gl::GLQuery* GLBackend::syncGPUObject(const Query& query) { gl::GLQuery* GL41Backend::syncGPUObject(const Query& query) {
return GLQuery::sync<GLQuery>(query); return GL41Query::sync<GL41Query>(query);
} }
GLuint GLBackend::getQueryID(const QueryPointer& query) { GLuint GL41Backend::getQueryID(const QueryPointer& query) {
return GLQuery::getId<GLQuery>(query); return GL41Query::getId<GL41Query>(query);
} }

View file

@ -1,5 +1,5 @@
// //
// GLBackendTexture.cpp // GL41BackendTexture.cpp
// libraries/gpu/src/gpu // libraries/gpu/src/gpu
// //
// Created by Sam Gateau on 1/19/2015. // Created by Sam Gateau on 1/19/2015.
@ -8,7 +8,7 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "GLBackend.h" #include "GL41Backend.h"
#include <unordered_set> #include <unordered_set>
#include <unordered_map> #include <unordered_map>
@ -19,29 +19,29 @@
using namespace gpu; using namespace gpu;
using namespace gpu::gl41; using namespace gpu::gl41;
using GLTexelFormat = gl::GLTexelFormat; using GL41TexelFormat = gl::GLTexelFormat;
using GLTexture = GLBackend::GLTexture; using GL41Texture = GL41Backend::GL41Texture;
GLuint GLTexture::allocate() { GLuint GL41Texture::allocate() {
Backend::incrementTextureGPUCount(); Backend::incrementTextureGPUCount();
GLuint result; GLuint result;
glGenTextures(1, &result); glGenTextures(1, &result);
return result; return result;
} }
GLuint GLBackend::getTextureID(const TexturePointer& texture, bool transfer) { GLuint GL41Backend::getTextureID(const TexturePointer& texture, bool transfer) {
return GLTexture::getId<GLTexture>(texture, transfer); return GL41Texture::getId<GL41Texture>(texture, transfer);
} }
gl::GLTexture* GLBackend::syncGPUObject(const TexturePointer& texture, bool transfer) { gl::GLTexture* GL41Backend::syncGPUObject(const TexturePointer& texture, bool transfer) {
return GLTexture::sync<GLTexture>(texture, transfer); return GL41Texture::sync<GL41Texture>(texture, transfer);
} }
GLTexture::GLTexture(const Texture& texture, bool transferrable) : gl::GLTexture(texture, allocate(), transferrable) {} GL41Texture::GL41Texture(const Texture& texture, bool transferrable) : gl::GLTexture(texture, allocate(), transferrable) {}
GLTexture::GLTexture(const Texture& texture, GLTexture* original) : gl::GLTexture(texture, allocate(), original) {} GL41Texture::GL41Texture(const Texture& texture, GL41Texture* original) : gl::GLTexture(texture, allocate(), original) {}
void GLBackend::GLTexture::withPreservedTexture(std::function<void()> f) const { void GL41Backend::GL41Texture::withPreservedTexture(std::function<void()> f) const {
GLint boundTex = -1; GLint boundTex = -1;
switch (_target) { switch (_target) {
case GL_TEXTURE_2D: case GL_TEXTURE_2D:
@ -63,14 +63,14 @@ void GLBackend::GLTexture::withPreservedTexture(std::function<void()> f) const
(void)CHECK_GL_ERROR(); (void)CHECK_GL_ERROR();
} }
void GLBackend::GLTexture::generateMips() const { void GL41Backend::GL41Texture::generateMips() const {
withPreservedTexture([&] { withPreservedTexture([&] {
glGenerateMipmap(_target); glGenerateMipmap(_target);
}); });
(void)CHECK_GL_ERROR(); (void)CHECK_GL_ERROR();
} }
void GLBackend::GLTexture::allocateStorage() const { void GL41Backend::GL41Texture::allocateStorage() const {
gl::GLTexelFormat texelFormat = gl::GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat()); gl::GLTexelFormat texelFormat = gl::GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat());
glTexParameteri(_target, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(_target, GL_TEXTURE_BASE_LEVEL, 0);
(void)CHECK_GL_ERROR(); (void)CHECK_GL_ERROR();
@ -93,7 +93,7 @@ void GLBackend::GLTexture::allocateStorage() const {
} }
} }
void GLBackend::GLTexture::updateSize() const { void GL41Backend::GL41Texture::updateSize() const {
setSize(_virtualSize); setSize(_virtualSize);
if (!_id) { if (!_id) {
return; return;
@ -129,7 +129,7 @@ void GLBackend::GLTexture::updateSize() const {
} }
// Move content bits from the CPU to the GPU for a given mip / face // Move content bits from the CPU to the GPU for a given mip / face
void GLBackend::GLTexture::transferMip(uint16_t mipLevel, uint8_t face) const { void GL41Backend::GL41Texture::transferMip(uint16_t mipLevel, uint8_t face) const {
auto mip = _gpuObject.accessStoredMipFace(mipLevel, face); auto mip = _gpuObject.accessStoredMipFace(mipLevel, face);
gl::GLTexelFormat texelFormat = gl::GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat(), mip->getFormat()); gl::GLTexelFormat texelFormat = gl::GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat(), mip->getFormat());
//GLenum target = getFaceTargets()[face]; //GLenum target = getFaceTargets()[face];
@ -141,7 +141,7 @@ void GLBackend::GLTexture::transferMip(uint16_t mipLevel, uint8_t face) const {
// This should never happen on the main thread // This should never happen on the main thread
// Move content bits from the CPU to the GPU // Move content bits from the CPU to the GPU
void GLBackend::GLTexture::transfer() const { void GL41Backend::GL41Texture::transfer() const {
PROFILE_RANGE(__FUNCTION__); PROFILE_RANGE(__FUNCTION__);
//qDebug() << "Transferring texture: " << _privateTexture; //qDebug() << "Transferring texture: " << _privateTexture;
// Need to update the content of the GPU object from the source sysmem of the texture // Need to update the content of the GPU object from the source sysmem of the texture
@ -208,11 +208,8 @@ void GLBackend::GLTexture::transfer() const {
} }
} }
void GLBackend::GLTexture::syncSampler() const { void GL41Backend::GL41Texture::syncSampler() const {
const Sampler& sampler = _gpuObject.getSampler(); const Sampler& sampler = _gpuObject.getSampler();
Texture::Type type = _gpuObject.getType();
auto object = this;
const auto& fm = FILTER_MODES[sampler.getFilter()]; const auto& fm = FILTER_MODES[sampler.getFilter()];
glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, fm.minFilter); glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, fm.minFilter);
glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, fm.magFilter); glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, fm.magFilter);

View file

@ -1,5 +1,5 @@
// //
// GLBackendTransform.cpp // GL41BackendTransform.cpp
// libraries/gpu/src/gpu // libraries/gpu/src/gpu
// //
// Created by Sam Gateau on 3/8/2015. // Created by Sam Gateau on 3/8/2015.
@ -8,12 +8,12 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "GLBackend.h" #include "GL41Backend.h"
using namespace gpu; using namespace gpu;
using namespace gpu::gl41; using namespace gpu::gl41;
void GLBackend::initTransform() { void GL41Backend::initTransform() {
glGenBuffers(1, &_transform._objectBuffer); glGenBuffers(1, &_transform._objectBuffer);
glGenBuffers(1, &_transform._cameraBuffer); glGenBuffers(1, &_transform._cameraBuffer);
glGenBuffers(1, &_transform._drawCallInfoBuffer); glGenBuffers(1, &_transform._drawCallInfoBuffer);
@ -24,7 +24,7 @@ void GLBackend::initTransform() {
} }
} }
void GLBackend::transferTransformState(const Batch& batch) const { void GL41Backend::transferTransformState(const Batch& batch) const {
// FIXME not thread safe // FIXME not thread safe
static std::vector<uint8_t> bufferData; static std::vector<uint8_t> bufferData;
if (!_transform._cameras.empty()) { if (!_transform._cameras.empty()) {

View file

@ -87,11 +87,11 @@ namespace gpu {
} }
namespace gl41 { namespace gl41 {
class GLBackend; class GL41Backend;
} }
namespace gl45 { namespace gl45 {
class GLBackend; class GL45Backend;
} }
} }