splitting the GLBackend.cpp in several files and fixing the build for mac

This commit is contained in:
dev 2015-01-22 12:38:24 -08:00
parent ea37d7cfd0
commit 03a5c398ec
6 changed files with 214 additions and 201 deletions

View file

@ -140,20 +140,19 @@ public:
uint16 getRaw() const { return *((uint16*) (this)); } uint16 getRaw() const { return *((uint16*) (this)); }
bool operator ==(const Element& right) const {
return getRaw() == right.getRaw();
}
bool operator !=(const Element& right) const {
return getRaw() != right.getRaw();
}
protected: protected:
uint8 _semantic; uint8 _semantic;
uint8 _dimension : 4; uint8 _dimension : 4;
uint8 _type : 4; uint8 _type : 4;
}; };
static bool operator ==(const Element& left, const Element& right) {
return left.getRaw() == right.getRaw();
}
static bool operator !=(const Element& left, const Element& right) {
return left.getRaw() != right.getRaw();
}
}; };

View file

@ -8,13 +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 "GLBackendShared.h"
#include <QDebug>
#include "Batch.h"
using namespace gpu;
GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
{ {
@ -85,35 +79,6 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
(&::gpu::GLBackend::do_glColor4f), (&::gpu::GLBackend::do_glColor4f),
}; };
static const GLenum _primitiveToGLmode[NUM_PRIMITIVES] = {
GL_POINTS,
GL_LINES,
GL_LINE_STRIP,
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_QUADS,
};
static const GLenum _elementTypeToGLType[NUM_TYPES]= {
GL_FLOAT,
GL_INT,
GL_UNSIGNED_INT,
GL_HALF_FLOAT,
GL_SHORT,
GL_UNSIGNED_SHORT,
GL_BYTE,
GL_UNSIGNED_BYTE,
GL_FLOAT,
GL_INT,
GL_UNSIGNED_INT,
GL_HALF_FLOAT,
GL_SHORT,
GL_UNSIGNED_SHORT,
GL_BYTE,
GL_UNSIGNED_BYTE
};
GLBackend::GLBackend() : GLBackend::GLBackend() :
_input(), _input(),
_transform() _transform()
@ -172,9 +137,6 @@ void GLBackend::checkGLError() {
} }
} }
#define CHECK_GL_ERROR() ::gpu::GLBackend::checkGLError()
//#define CHECK_GL_ERROR()
void GLBackend::do_draw(Batch& batch, uint32 paramOffset) { void GLBackend::do_draw(Batch& batch, uint32 paramOffset) {
updateInput(); updateInput();
updateTransform(); updateTransform();
@ -509,13 +471,11 @@ void GLBackend::do_setUniformBuffer(Batch& batch, uint32 paramOffset) {
void GLBackend::do_setUniformTexture(Batch& batch, uint32 paramOffset) { void GLBackend::do_setUniformTexture(Batch& batch, uint32 paramOffset) {
GLuint slot = batch._params[paramOffset + 1]._uint; GLuint slot = batch._params[paramOffset + 1]._uint;
TexturePointer uniformTexture = batch._textures.get(batch._params[paramOffset + 0]._uint); TexturePointer uniformTexture = batch._textures.get(batch._params[paramOffset + 0]._uint);
#if defined(Q_OS_MAC)
#elif defined(Q_OS_WIN)
GLuint to = getTextureID(*uniformTexture); GLuint to = getTextureID(*uniformTexture);
glActiveTexture(GL_TEXTURE0 + slot); glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(GL_TEXTURE_2D, to); glBindTexture(GL_TEXTURE_2D, to);
#else
#endif
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }

View file

@ -0,0 +1,53 @@
//
// GLBackendShared.h
// libraries/gpu/src/gpu
//
// Created by Sam Gateau on 1/22/2014.
// Copyright 2014 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
//
#ifndef hifi_gpu_GLBackend_Shared_h
#define hifi_gpu_GLBackend_Shared_h
#include "GLBackend.h"
#include <QDebug>
#include "Batch.h"
using namespace gpu;
static const GLenum _primitiveToGLmode[NUM_PRIMITIVES] = {
GL_POINTS,
GL_LINES,
GL_LINE_STRIP,
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_QUADS,
};
static const GLenum _elementTypeToGLType[NUM_TYPES]= {
GL_FLOAT,
GL_INT,
GL_UNSIGNED_INT,
GL_HALF_FLOAT,
GL_SHORT,
GL_UNSIGNED_SHORT,
GL_BYTE,
GL_UNSIGNED_BYTE,
GL_FLOAT,
GL_INT,
GL_UNSIGNED_INT,
GL_HALF_FLOAT,
GL_SHORT,
GL_UNSIGNED_SHORT,
GL_BYTE,
GL_UNSIGNED_BYTE
};
#define CHECK_GL_ERROR() ::gpu::GLBackend::checkGLError()
//#define CHECK_GL_ERROR()
#endif

View file

@ -8,7 +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
// //
#include "GLBackend.cpp" #include "GLBackendShared.h"
GLBackend::GLTexture::GLTexture() : GLBackend::GLTexture::GLTexture() :
_storageStamp(0), _storageStamp(0),
@ -234,11 +235,11 @@ void GLBackend::syncGPUObject(const Texture& texture) {
if (needUpdate) { if (needUpdate) {
if (texture.isStoredMipAvailable(0)) { if (texture.isStoredMipAvailable(0)) {
GLint boundTex = -1; GLint boundTex = -1;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTex); glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTex);
Texture::PixelsPointer mip = texture.accessStoredMip(0); Texture::PixelsPointer mip = texture.accessStoredMip(0);
const GLvoid* bytes = mip->_sysmem.read<Resource::Byte>(); const GLvoid* bytes = mip->_sysmem.read<Resource::Byte>();
Element srcFormat = mip->_format; Element srcFormat = mip->_format;
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat); GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat);

View file

@ -1,20 +1,20 @@
// //
// Texture.cpp // Texture.cpp
// libraries/gpu/src/gpu // libraries/gpu/src/gpu
// //
// Created by Sam Gateau on 1/17/2015. // Created by Sam Gateau on 1/17/2015.
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// 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 "Texture.h" #include "Texture.h"
#include <math.h>
#include <QDebug> #include <QDebug>
using namespace gpu; using namespace gpu;
Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) : Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) :
_sysmem(size, bytes), _sysmem(size, bytes),
_format(format) { _format(format) {

View file

@ -35,7 +35,7 @@ public:
Texture* _texture; Texture* _texture;
std::vector<PixelsPointer> _mips; std::vector<PixelsPointer> _mips;
public: public:
Storage() {} Storage() {}
virtual ~Storage() {} virtual ~Storage() {}
virtual void reset(); virtual void reset();
@ -55,13 +55,13 @@ public:
TEX_3D, TEX_3D,
TEX_CUBE, TEX_CUBE,
}; };
static Texture* create1D(const Element& texelFormat, uint16 width);
static Texture* create2D(const Element& texelFormat, uint16 width, uint16 height);
static Texture* create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth);
static Texture* createCube(const Element& texelFormat, uint16 width);
static Texture* createFromStorage(Storage* storage); static Texture* create1D(const Element& texelFormat, uint16 width);
static Texture* create2D(const Element& texelFormat, uint16 width, uint16 height);
static Texture* create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth);
static Texture* createCube(const Element& texelFormat, uint16 width);
static Texture* createFromStorage(Storage* storage);
Texture(const Texture& buf); // deep copy of the sysmem texture Texture(const Texture& buf); // deep copy of the sysmem texture
Texture& operator=(const Texture& buf); // deep copy of the sysmem texture Texture& operator=(const Texture& buf); // deep copy of the sysmem texture
@ -72,134 +72,134 @@ public:
// The size in bytes of data stored in the texture // The size in bytes of data stored in the texture
Size getSize() const { return _size; } Size getSize() const { return _size; }
// Resize, unless auto mips mode would destroy all the sub mips
Size resize1D(uint16 width, uint16 numSamples);
Size resize2D(uint16 width, uint16 height, uint16 numSamples);
Size resize3D(uint16 width, uint16 height, uint16 depth, uint16 numSamples);
Size resizeCube(uint16 width, uint16 numSamples);
// Reformat, unless auto mips mode would destroy all the sub mips
Size reformat(const Element& texelFormat);
// Size and format
Type getType() const { return _type; }
bool isColorRenderTarget() const;
bool isDepthStencilRenderTarget() const;
const Element& getTexelFormat() const { return _texelFormat; }
bool hasBorder() const { return false; }
uint16 getWidth() const { return _width; }
uint16 getHeight() const { return _height; }
uint16 getDepth() const { return _depth; }
uint32 getRowPitch() const { return getWidth() * getTexelFormat().getSize(); } // Resize, unless auto mips mode would destroy all the sub mips
uint32 getNumTexels() const { return _width * _height * _depth; } Size resize1D(uint16 width, uint16 numSamples);
Size resize2D(uint16 width, uint16 height, uint16 numSamples);
uint16 getNumSlices() const { return _numSlices; } Size resize3D(uint16 width, uint16 height, uint16 depth, uint16 numSamples);
uint16 getNumSamples() const { return _numSamples; } Size resizeCube(uint16 width, uint16 numSamples);
// NumSamples can only have certain values based on the hw // Reformat, unless auto mips mode would destroy all the sub mips
static uint16 evalNumSamplesUsed(uint16 numSamplesTried); Size reformat(const Element& texelFormat);
// Mips size evaluation // Size and format
Type getType() const { return _type; }
// The number mips that a dimension could haves
// = 1 + log2(size) bool isColorRenderTarget() const;
static uint16 evalDimNumMips(uint16 size); bool isDepthStencilRenderTarget() const;
// The number mips that the texture could have if all existed const Element& getTexelFormat() const { return _texelFormat; }
// = 1 + log2(max(width, height, depth)) bool hasBorder() const { return false; }
uint16 evalNumMips() const;
uint16 getWidth() const { return _width; }
// Eval the size that the mips level SHOULD have uint16 getHeight() const { return _height; }
// not the one stored in the Texture uint16 getDepth() const { return _depth; }
uint16 evalMipWidth(uint16 level) const { return std::max(_width >> level, 1); }
uint16 evalMipHeight(uint16 level) const { return std::max(_height >> level, 1); } uint32 getRowPitch() const { return getWidth() * getTexelFormat().getSize(); }
uint16 evalMipDepth(uint16 level) const { return std::max(_depth >> level, 1); } uint32 getNumTexels() const { return _width * _height * _depth; }
uint32 evalMipNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level); }
uint32 evalMipSize(uint16 level) const { return evalMipNumTexels(level) * getTexelFormat().getSize(); } uint16 getNumSlices() const { return _numSlices; }
uint32 evalStoredMipSize(uint16 level, const Element& format) const { return evalMipNumTexels(level) * format.getSize(); } uint16 getNumSamples() const { return _numSamples; }
uint32 evalTotalSize() const { // NumSamples can only have certain values based on the hw
uint32 size = 0; static uint16 evalNumSamplesUsed(uint16 numSamplesTried);
uint16 minMipLevel = 0;
uint16 maxMipLevel = maxMip(); // Mips size evaluation
for (uint16 l = minMipLevel; l <= maxMipLevel; l++) {
size += evalMipSize(l); // The number mips that a dimension could haves
} // = 1 + log2(size)
return size * getNumSlices(); static uint16 evalDimNumMips(uint16 size);
}
// The number mips that the texture could have if all existed
// max mip is in the range [ 1 if no sub mips, log2(max(width, height, depth))] // = 1 + log2(max(width, height, depth))
// if autoGenerateMip is on => will provide the maxMIp level specified uint16 evalNumMips() const;
// else provide the deepest mip level provided through assignMip
uint16 maxMip() const; // Eval the size that the mips level SHOULD have
// not the one stored in the Texture
// Generate the mips automatically uint16 evalMipWidth(uint16 level) const { return std::max(_width >> level, 1); }
// But the sysmem version is not available uint16 evalMipHeight(uint16 level) const { return std::max(_height >> level, 1); }
// Only works for the standard formats uint16 evalMipDepth(uint16 level) const { return std::max(_depth >> level, 1); }
// Specify the maximum Mip level available uint32 evalMipNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level); }
// 0 is the default one uint32 evalMipSize(uint16 level) const { return evalMipNumTexels(level) * getTexelFormat().getSize(); }
// 1 is the first level uint32 evalStoredMipSize(uint16 level, const Element& format) const { return evalMipNumTexels(level) * format.getSize(); }
// ...
// nbMips - 1 is the last mip level uint32 evalTotalSize() const {
// uint32 size = 0;
// If -1 then all the mips are generated uint16 minMipLevel = 0;
// uint16 maxMipLevel = maxMip();
// Return the totalnumber of mips that will be available for (uint16 l = minMipLevel; l <= maxMipLevel; l++) {
uint16 autoGenerateMips(uint16 maxMip); size += evalMipSize(l);
bool isAutogenerateMips() const { return _autoGenerateMips; } }
return size * getNumSlices();
// Managing Storage and mips }
// Manually allocate the mips down until the specified maxMip // max mip is in the range [ 1 if no sub mips, log2(max(width, height, depth))]
// this is just allocating the sysmem version of it // if autoGenerateMip is on => will provide the maxMIp level specified
// in case autoGen is on, this doesn't allocate // else provide the deepest mip level provided through assignMip
// Explicitely assign mip data for a certain level uint16 maxMip() const;
// If Bytes is NULL then simply allocate the space so mip sysmem can be accessed
bool assignStoredMip(uint16 level, const Element& format, Size size, const Byte* bytes); // Generate the mips automatically
// But the sysmem version is not available
// Access the the sub mips // Only works for the standard formats
bool isStoredMipAvailable(uint16 level) const { return _storage->isMipAvailable(level); } // Specify the maximum Mip level available
const PixelsPointer accessStoredMip(uint16 level) const { return _storage->getMip(level); } // 0 is the default one
// 1 is the first level
// access sizes for the stored mips // ...
uint16 getStoredMipWidth(uint16 level) const; // nbMips - 1 is the last mip level
uint16 getStoredMipHeight(uint16 level) const; //
uint16 getStoredMipDepth(uint16 level) const; // If -1 then all the mips are generated
uint32 getStoredMipNumTexels(uint16 level) const; //
uint32 getStoredMipSize(uint16 level) const; // Return the totalnumber of mips that will be available
uint16 autoGenerateMips(uint16 maxMip);
bool isAutogenerateMips() const { return _autoGenerateMips; }
// Managing Storage and mips
// Manually allocate the mips down until the specified maxMip
// this is just allocating the sysmem version of it
// in case autoGen is on, this doesn't allocate
// Explicitely assign mip data for a certain level
// If Bytes is NULL then simply allocate the space so mip sysmem can be accessed
bool assignStoredMip(uint16 level, const Element& format, Size size, const Byte* bytes);
// Access the the sub mips
bool isStoredMipAvailable(uint16 level) const { return _storage->isMipAvailable(level); }
const PixelsPointer accessStoredMip(uint16 level) const { return _storage->getMip(level); }
// access sizes for the stored mips
uint16 getStoredMipWidth(uint16 level) const;
uint16 getStoredMipHeight(uint16 level) const;
uint16 getStoredMipDepth(uint16 level) const;
uint32 getStoredMipNumTexels(uint16 level) const;
uint32 getStoredMipSize(uint16 level) const;
bool isDefined() const { return _defined; } bool isDefined() const { return _defined; }
protected: protected:
std::unique_ptr< Storage > _storage; std::unique_ptr< Storage > _storage;
Stamp _stamp; Stamp _stamp;
uint32 _size; uint32 _size;
Element _texelFormat; Element _texelFormat;
uint16 _width; uint16 _width;
uint16 _height; uint16 _height;
uint16 _depth; uint16 _depth;
uint16 _numSlices; uint16 _numSamples;
uint16 _numSamples; uint16 _numSlices;
uint16 _maxMip; uint16 _maxMip;
Type _type; Type _type;
bool _autoGenerateMips; bool _autoGenerateMips;
bool _defined; bool _defined;
static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices); static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices);
Texture(); Texture();
Size resize(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices); Size resize(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices);
mutable GPUObject* _gpuObject = NULL; mutable GPUObject* _gpuObject = NULL;