mirror of
https://github.com/overte-org/overte.git
synced 2025-06-25 00:29:32 +02:00
Clean up the includes in gpu, make the skybox shader works
This commit is contained in:
parent
50012ee9de
commit
06e1330e42
14 changed files with 572 additions and 560 deletions
|
@ -27,6 +27,8 @@ typedef short int16;
|
||||||
typedef unsigned char uint8;
|
typedef unsigned char uint8;
|
||||||
typedef char int8;
|
typedef char int8;
|
||||||
|
|
||||||
|
typedef unsigned char Byte;
|
||||||
|
|
||||||
typedef uint32 Offset;
|
typedef uint32 Offset;
|
||||||
|
|
||||||
typedef glm::mat4 Mat4;
|
typedef glm::mat4 Mat4;
|
||||||
|
@ -182,18 +184,18 @@ public:
|
||||||
uint8 _type : 4;
|
uint8 _type : 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum ComparisonFunction {
|
enum ComparisonFunction {
|
||||||
NEVER = 0,
|
NEVER = 0,
|
||||||
LESS,
|
LESS,
|
||||||
EQUAL,
|
EQUAL,
|
||||||
LESS_EQUAL,
|
LESS_EQUAL,
|
||||||
GREATER,
|
GREATER,
|
||||||
NOT_EQUAL,
|
NOT_EQUAL,
|
||||||
GREATER_EQUAL,
|
GREATER_EQUAL,
|
||||||
ALWAYS,
|
ALWAYS,
|
||||||
|
|
||||||
NUM_COMPARISON_FUNCS,
|
NUM_COMPARISON_FUNCS,
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -297,7 +297,7 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) {
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
if (texture.isStoredMipAvailable(0)) {
|
if (texture.isStoredMipAvailable(0)) {
|
||||||
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<Byte>();
|
||||||
Element srcFormat = mip->_format;
|
Element srcFormat = mip->_format;
|
||||||
|
|
||||||
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat);
|
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat);
|
||||||
|
@ -328,7 +328,7 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) {
|
||||||
if (texture.isStoredMipAvailable(0)) {
|
if (texture.isStoredMipAvailable(0)) {
|
||||||
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
||||||
|
|
||||||
bytes = mip->_sysmem.read<Resource::Byte>();
|
bytes = mip->_sysmem.read<Byte>();
|
||||||
srcFormat = mip->_format;
|
srcFormat = mip->_format;
|
||||||
|
|
||||||
object->_contentStamp = texture.getDataStamp();
|
object->_contentStamp = texture.getDataStamp();
|
||||||
|
@ -386,7 +386,7 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) {
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, object->_texture);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, object->_texture);
|
||||||
for (int f = 0; f < NUM_FACES; f++) {
|
for (int f = 0; f < NUM_FACES; f++) {
|
||||||
glTexSubImage2D(FACE_LAYOUT[f], 0, texelFormat.internalFormat, width, width, 0,
|
glTexSubImage2D(FACE_LAYOUT[f], 0, texelFormat.internalFormat, width, width, 0,
|
||||||
texelFormat.format, texelFormat.type, (GLvoid*) (mip->_sysmem.read<Resource::Byte>() + f * faceSize));
|
texelFormat.format, texelFormat.type, (GLvoid*) (mip->_sysmem.read<Byte>() + f * faceSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texture.isAutogenerateMips()) {
|
if (texture.isAutogenerateMips()) {
|
||||||
|
@ -404,7 +404,7 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) {
|
||||||
object->_contentStamp = texture.getDataStamp();
|
object->_contentStamp = texture.getDataStamp();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const gpu::Resource::Byte* bytes = 0;
|
const gpu::Byte* bytes = 0;
|
||||||
Element srcFormat = texture.getTexelFormat();
|
Element srcFormat = texture.getTexelFormat();
|
||||||
uint16 width = texture.getWidth();
|
uint16 width = texture.getWidth();
|
||||||
int faceSize = 0;
|
int faceSize = 0;
|
||||||
|
@ -412,7 +412,7 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) {
|
||||||
if (texture.isStoredMipAvailable(0)) {
|
if (texture.isStoredMipAvailable(0)) {
|
||||||
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
||||||
|
|
||||||
bytes = mip->_sysmem.read<Resource::Byte>();
|
bytes = mip->_sysmem.read<Byte>();
|
||||||
srcFormat = mip->_format;
|
srcFormat = mip->_format;
|
||||||
faceSize = mip->_sysmem.getSize() / NUM_FACES;
|
faceSize = mip->_sysmem.getSize() / NUM_FACES;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ namespace gpu {
|
||||||
|
|
||||||
class Resource {
|
class Resource {
|
||||||
public:
|
public:
|
||||||
typedef unsigned char Byte;
|
|
||||||
typedef unsigned int Size;
|
typedef unsigned int Size;
|
||||||
|
|
||||||
static const Size NOT_ALLOCATED = -1;
|
static const Size NOT_ALLOCATED = -1;
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
//
|
//
|
||||||
// Texture.h
|
// Texture.h
|
||||||
// libraries/gpu/src/gpu
|
// libraries/gpu/src/gpu
|
||||||
//
|
//
|
||||||
// Created by Sam Gateau on 1/16/2015.
|
// Created by Sam Gateau on 1/16/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
|
||||||
//
|
//
|
||||||
#ifndef hifi_gpu_Texture_h
|
#ifndef hifi_gpu_Texture_h
|
||||||
#define hifi_gpu_Texture_h
|
#define hifi_gpu_Texture_h
|
||||||
|
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
#include <memory>
|
|
||||||
|
#include <algorithm> //min max
|
||||||
namespace gpu {
|
|
||||||
|
namespace gpu {
|
||||||
class Sampler {
|
|
||||||
public:
|
class Sampler {
|
||||||
|
public:
|
||||||
|
|
||||||
enum Filter {
|
enum Filter {
|
||||||
FILTER_MIN_MAG_POINT, // top mip only
|
FILTER_MIN_MAG_POINT, // top mip only
|
||||||
FILTER_MIN_POINT_MAG_LINEAR, // top mip only
|
FILTER_MIN_POINT_MAG_LINEAR, // top mip only
|
||||||
|
@ -46,7 +47,7 @@ public:
|
||||||
WRAP_MIRROR_ONCE,
|
WRAP_MIRROR_ONCE,
|
||||||
|
|
||||||
NUM_WRAP_MODES
|
NUM_WRAP_MODES
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8 MAX_MIP_LEVEL = 0xFF;
|
static const uint8 MAX_MIP_LEVEL = 0xFF;
|
||||||
|
|
||||||
|
@ -92,273 +93,273 @@ public:
|
||||||
uint8 getMaxMip() const { return _desc._maxMip; }
|
uint8 getMaxMip() const { return _desc._maxMip; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Desc _desc;
|
Desc _desc;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Texture : public Resource {
|
class Texture : public Resource {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class Pixels {
|
class Pixels {
|
||||||
public:
|
public:
|
||||||
Pixels() {}
|
Pixels() {}
|
||||||
Pixels(const Pixels& pixels) = default;
|
Pixels(const Pixels& pixels) = default;
|
||||||
Pixels(const Element& format, Size size, const Byte* bytes);
|
Pixels(const Element& format, Size size, const Byte* bytes);
|
||||||
~Pixels();
|
~Pixels();
|
||||||
|
|
||||||
Sysmem _sysmem;
|
Sysmem _sysmem;
|
||||||
Element _format;
|
Element _format;
|
||||||
bool _isGPULoaded;
|
bool _isGPULoaded;
|
||||||
};
|
};
|
||||||
typedef std::shared_ptr< Pixels > PixelsPointer;
|
typedef std::shared_ptr< Pixels > PixelsPointer;
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
public:
|
public:
|
||||||
Storage() {}
|
Storage() {}
|
||||||
virtual ~Storage() {}
|
virtual ~Storage() {}
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual PixelsPointer editMip(uint16 level);
|
virtual PixelsPointer editMip(uint16 level);
|
||||||
virtual const PixelsPointer getMip(uint16 level) const;
|
virtual const PixelsPointer getMip(uint16 level) const;
|
||||||
virtual Stamp getStamp(uint16 level) const;
|
virtual Stamp getStamp(uint16 level) const;
|
||||||
virtual bool allocateMip(uint16 level);
|
virtual bool allocateMip(uint16 level);
|
||||||
virtual bool assignMipData(uint16 level, const Element& format, Size size, const Byte* bytes);
|
virtual bool assignMipData(uint16 level, const Element& format, Size size, const Byte* bytes);
|
||||||
virtual bool isMipAvailable(uint16 level) const;
|
virtual bool isMipAvailable(uint16 level) const;
|
||||||
virtual void notifyGPULoaded(uint16 level) const;
|
virtual void notifyGPULoaded(uint16 level) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Texture* _texture;
|
Texture* _texture;
|
||||||
std::vector<PixelsPointer> _mips;
|
std::vector<PixelsPointer> _mips;
|
||||||
|
|
||||||
virtual void assignTexture(Texture* tex);
|
virtual void assignTexture(Texture* tex);
|
||||||
|
|
||||||
friend class Texture;
|
friend class Texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
TEX_1D = 0,
|
TEX_1D = 0,
|
||||||
TEX_2D,
|
TEX_2D,
|
||||||
TEX_3D,
|
TEX_3D,
|
||||||
TEX_CUBE,
|
TEX_CUBE,
|
||||||
|
|
||||||
NUM_TYPES,
|
NUM_TYPES,
|
||||||
};
|
};
|
||||||
|
|
||||||
static Texture* create1D(const Element& texelFormat, uint16 width, const Sampler& sampler = Sampler());
|
static Texture* create1D(const Element& texelFormat, uint16 width, const Sampler& sampler = Sampler());
|
||||||
static Texture* create2D(const Element& texelFormat, uint16 width, uint16 height, const Sampler& sampler = Sampler());
|
static Texture* create2D(const Element& texelFormat, uint16 width, uint16 height, const Sampler& sampler = Sampler());
|
||||||
static Texture* create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth, const Sampler& sampler = Sampler());
|
static Texture* create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth, const Sampler& sampler = Sampler());
|
||||||
static Texture* createCube(const Element& texelFormat, uint16 width, const Sampler& sampler = Sampler());
|
static Texture* createCube(const Element& texelFormat, uint16 width, const Sampler& sampler = Sampler());
|
||||||
|
|
||||||
static Texture* createFromStorage(Storage* storage);
|
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
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
Stamp getStamp() const { return _stamp; }
|
Stamp getStamp() const { return _stamp; }
|
||||||
Stamp getDataStamp(uint16 level = 0) const { return _storage->getStamp(level); }
|
Stamp getDataStamp(uint16 level = 0) const { return _storage->getStamp(level); }
|
||||||
|
|
||||||
// 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
|
// Resize, unless auto mips mode would destroy all the sub mips
|
||||||
Size resize1D(uint16 width, uint16 numSamples);
|
Size resize1D(uint16 width, uint16 numSamples);
|
||||||
Size resize2D(uint16 width, uint16 height, uint16 numSamples);
|
Size resize2D(uint16 width, uint16 height, uint16 numSamples);
|
||||||
Size resize3D(uint16 width, uint16 height, uint16 depth, uint16 numSamples);
|
Size resize3D(uint16 width, uint16 height, uint16 depth, uint16 numSamples);
|
||||||
Size resizeCube(uint16 width, uint16 numSamples);
|
Size resizeCube(uint16 width, uint16 numSamples);
|
||||||
|
|
||||||
// Reformat, unless auto mips mode would destroy all the sub mips
|
// Reformat, unless auto mips mode would destroy all the sub mips
|
||||||
Size reformat(const Element& texelFormat);
|
Size reformat(const Element& texelFormat);
|
||||||
|
|
||||||
// Size and format
|
// Size and format
|
||||||
Type getType() const { return _type; }
|
Type getType() const { return _type; }
|
||||||
|
|
||||||
bool isColorRenderTarget() const;
|
bool isColorRenderTarget() const;
|
||||||
bool isDepthStencilRenderTarget() const;
|
bool isDepthStencilRenderTarget() const;
|
||||||
|
|
||||||
const Element& getTexelFormat() const { return _texelFormat; }
|
const Element& getTexelFormat() const { return _texelFormat; }
|
||||||
bool hasBorder() const { return false; }
|
bool hasBorder() const { return false; }
|
||||||
|
|
||||||
uint16 getWidth() const { return _width; }
|
uint16 getWidth() const { return _width; }
|
||||||
uint16 getHeight() const { return _height; }
|
uint16 getHeight() const { return _height; }
|
||||||
uint16 getDepth() const { return _depth; }
|
uint16 getDepth() const { return _depth; }
|
||||||
|
|
||||||
uint32 getRowPitch() const { return getWidth() * getTexelFormat().getSize(); }
|
uint32 getRowPitch() const { return getWidth() * getTexelFormat().getSize(); }
|
||||||
|
|
||||||
// The number of faces is mostly used for cube map, and maybe for stereo ? otherwise it's 1
|
// The number of faces is mostly used for cube map, and maybe for stereo ? otherwise it's 1
|
||||||
// For cube maps, this means the pixels of the different faces are supposed to be packed back to back in a mip
|
// For cube maps, this means the pixels of the different faces are supposed to be packed back to back in a mip
|
||||||
// as if the height was NUM_FACES time bigger.
|
// as if the height was NUM_FACES time bigger.
|
||||||
static uint8 NUM_FACES_PER_TYPE[NUM_TYPES];
|
static uint8 NUM_FACES_PER_TYPE[NUM_TYPES];
|
||||||
uint8 getNumFaces() const { return NUM_FACES_PER_TYPE[getType()]; }
|
uint8 getNumFaces() const { return NUM_FACES_PER_TYPE[getType()]; }
|
||||||
|
|
||||||
uint32 getNumTexels() const { return _width * _height * _depth * getNumFaces(); }
|
uint32 getNumTexels() const { return _width * _height * _depth * getNumFaces(); }
|
||||||
|
|
||||||
uint16 getNumSlices() const { return _numSlices; }
|
uint16 getNumSlices() const { return _numSlices; }
|
||||||
uint16 getNumSamples() const { return _numSamples; }
|
uint16 getNumSamples() const { return _numSamples; }
|
||||||
|
|
||||||
|
|
||||||
// NumSamples can only have certain values based on the hw
|
// NumSamples can only have certain values based on the hw
|
||||||
static uint16 evalNumSamplesUsed(uint16 numSamplesTried);
|
static uint16 evalNumSamplesUsed(uint16 numSamplesTried);
|
||||||
|
|
||||||
// Mips size evaluation
|
// Mips size evaluation
|
||||||
|
|
||||||
// The number mips that a dimension could haves
|
// The number mips that a dimension could haves
|
||||||
// = 1 + log2(size)
|
// = 1 + log2(size)
|
||||||
static uint16 evalDimNumMips(uint16 size);
|
static uint16 evalDimNumMips(uint16 size);
|
||||||
|
|
||||||
// The number mips that the texture could have if all existed
|
// The number mips that the texture could have if all existed
|
||||||
// = 1 + log2(max(width, height, depth))
|
// = 1 + log2(max(width, height, depth))
|
||||||
uint16 evalNumMips() const;
|
uint16 evalNumMips() const;
|
||||||
|
|
||||||
// Eval the size that the mips level SHOULD have
|
// Eval the size that the mips level SHOULD have
|
||||||
// not the one stored in the Texture
|
// not the one stored in the Texture
|
||||||
uint16 evalMipWidth(uint16 level) const { return std::max(_width >> level, 1); }
|
uint16 evalMipWidth(uint16 level) const { return std::max(_width >> level, 1); }
|
||||||
uint16 evalMipHeight(uint16 level) const { return std::max(_height >> level, 1); }
|
uint16 evalMipHeight(uint16 level) const { return std::max(_height >> level, 1); }
|
||||||
uint16 evalMipDepth(uint16 level) const { return std::max(_depth >> level, 1); }
|
uint16 evalMipDepth(uint16 level) const { return std::max(_depth >> level, 1); }
|
||||||
uint32 evalMipNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level) * getNumFaces(); }
|
uint32 evalMipNumTexels(uint16 level) const { return evalMipWidth(level) * evalMipHeight(level) * evalMipDepth(level) * getNumFaces(); }
|
||||||
uint32 evalMipSize(uint16 level) const { return evalMipNumTexels(level) * getTexelFormat().getSize(); }
|
uint32 evalMipSize(uint16 level) const { return evalMipNumTexels(level) * getTexelFormat().getSize(); }
|
||||||
uint32 evalStoredMipSize(uint16 level, const Element& format) const { return evalMipNumTexels(level) * format.getSize(); }
|
uint32 evalStoredMipSize(uint16 level, const Element& format) const { return evalMipNumTexels(level) * format.getSize(); }
|
||||||
|
|
||||||
uint32 evalTotalSize() const {
|
uint32 evalTotalSize() const {
|
||||||
uint32 size = 0;
|
uint32 size = 0;
|
||||||
uint16 minMipLevel = 0;
|
uint16 minMipLevel = 0;
|
||||||
uint16 maxMipLevel = maxMip();
|
uint16 maxMipLevel = maxMip();
|
||||||
for (uint16 l = minMipLevel; l <= maxMipLevel; l++) {
|
for (uint16 l = minMipLevel; l <= maxMipLevel; l++) {
|
||||||
size += evalMipSize(l);
|
size += evalMipSize(l);
|
||||||
}
|
}
|
||||||
return size * getNumSlices();
|
return size * getNumSlices();
|
||||||
}
|
}
|
||||||
|
|
||||||
// max mip is in the range [ 1 if no sub mips, log2(max(width, height, depth))]
|
// max mip is in the range [ 1 if no sub mips, log2(max(width, height, depth))]
|
||||||
// if autoGenerateMip is on => will provide the maxMIp level specified
|
// if autoGenerateMip is on => will provide the maxMIp level specified
|
||||||
// else provide the deepest mip level provided through assignMip
|
// else provide the deepest mip level provided through assignMip
|
||||||
uint16 maxMip() const;
|
uint16 maxMip() const;
|
||||||
|
|
||||||
// Generate the mips automatically
|
// Generate the mips automatically
|
||||||
// But the sysmem version is not available
|
// But the sysmem version is not available
|
||||||
// Only works for the standard formats
|
// Only works for the standard formats
|
||||||
// Specify the maximum Mip level available
|
// Specify the maximum Mip level available
|
||||||
// 0 is the default one
|
// 0 is the default one
|
||||||
// 1 is the first level
|
// 1 is the first level
|
||||||
// ...
|
// ...
|
||||||
// nbMips - 1 is the last mip level
|
// nbMips - 1 is the last mip level
|
||||||
//
|
//
|
||||||
// If -1 then all the mips are generated
|
// If -1 then all the mips are generated
|
||||||
//
|
//
|
||||||
// Return the totalnumber of mips that will be available
|
// Return the totalnumber of mips that will be available
|
||||||
uint16 autoGenerateMips(uint16 maxMip);
|
uint16 autoGenerateMips(uint16 maxMip);
|
||||||
bool isAutogenerateMips() const { return _autoGenerateMips; }
|
bool isAutogenerateMips() const { return _autoGenerateMips; }
|
||||||
|
|
||||||
// Managing Storage and mips
|
// Managing Storage and mips
|
||||||
|
|
||||||
// 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
|
||||||
// in case autoGen is on, this doesn't allocate
|
// in case autoGen is on, this doesn't allocate
|
||||||
// Explicitely assign mip data for a certain level
|
// Explicitely assign mip data for a certain level
|
||||||
// If Bytes is NULL then simply allocate the space so mip sysmem can be accessed
|
// 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);
|
bool assignStoredMip(uint16 level, const Element& format, Size size, const Byte* bytes);
|
||||||
|
|
||||||
// Access the the sub mips
|
// Access the the sub mips
|
||||||
bool isStoredMipAvailable(uint16 level) const { return _storage->isMipAvailable(level); }
|
bool isStoredMipAvailable(uint16 level) const { return _storage->isMipAvailable(level); }
|
||||||
const PixelsPointer accessStoredMip(uint16 level) const { return _storage->getMip(level); }
|
const PixelsPointer accessStoredMip(uint16 level) const { return _storage->getMip(level); }
|
||||||
void notifyGPULoaded(uint16 level) const { return _storage->notifyGPULoaded(level); }
|
void notifyGPULoaded(uint16 level) const { return _storage->notifyGPULoaded(level); }
|
||||||
|
|
||||||
// access sizes for the stored mips
|
// access sizes for the stored mips
|
||||||
uint16 getStoredMipWidth(uint16 level) const;
|
uint16 getStoredMipWidth(uint16 level) const;
|
||||||
uint16 getStoredMipHeight(uint16 level) const;
|
uint16 getStoredMipHeight(uint16 level) const;
|
||||||
uint16 getStoredMipDepth(uint16 level) const;
|
uint16 getStoredMipDepth(uint16 level) const;
|
||||||
uint32 getStoredMipNumTexels(uint16 level) const;
|
uint32 getStoredMipNumTexels(uint16 level) const;
|
||||||
uint32 getStoredMipSize(uint16 level) const;
|
uint32 getStoredMipSize(uint16 level) const;
|
||||||
|
|
||||||
bool isDefined() const { return _defined; }
|
bool isDefined() const { return _defined; }
|
||||||
|
|
||||||
|
|
||||||
// Own sampler
|
// Own sampler
|
||||||
void setSampler(const Sampler& sampler);
|
void setSampler(const Sampler& sampler);
|
||||||
const Sampler& getSampler() const { return _sampler; }
|
const Sampler& getSampler() const { return _sampler; }
|
||||||
Stamp getSamplerStamp() const { return _samplerStamp; }
|
Stamp getSamplerStamp() const { return _samplerStamp; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr< Storage > _storage;
|
std::unique_ptr< Storage > _storage;
|
||||||
|
|
||||||
Stamp _stamp = 0;
|
Stamp _stamp = 0;
|
||||||
|
|
||||||
Sampler _sampler;
|
Sampler _sampler;
|
||||||
Stamp _samplerStamp;
|
Stamp _samplerStamp;
|
||||||
|
|
||||||
uint32 _size = 0;
|
uint32 _size = 0;
|
||||||
Element _texelFormat;
|
Element _texelFormat;
|
||||||
|
|
||||||
uint16 _width = 1;
|
uint16 _width = 1;
|
||||||
uint16 _height = 1;
|
uint16 _height = 1;
|
||||||
uint16 _depth = 1;
|
uint16 _depth = 1;
|
||||||
|
|
||||||
uint16 _numSamples = 1;
|
uint16 _numSamples = 1;
|
||||||
uint16 _numSlices = 1;
|
uint16 _numSlices = 1;
|
||||||
|
|
||||||
uint16 _maxMip = 0;
|
uint16 _maxMip = 0;
|
||||||
|
|
||||||
Type _type = TEX_1D;
|
Type _type = TEX_1D;
|
||||||
bool _autoGenerateMips = false;
|
bool _autoGenerateMips = false;
|
||||||
bool _defined = false;
|
bool _defined = false;
|
||||||
|
|
||||||
static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices, const Sampler& sampler);
|
static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices, const Sampler& sampler);
|
||||||
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);
|
||||||
|
|
||||||
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
// This shouldn't be used by anything else than the Backend class with the proper casting.
|
||||||
mutable GPUObject* _gpuObject = NULL;
|
mutable GPUObject* _gpuObject = NULL;
|
||||||
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; }
|
||||||
GPUObject* getGPUObject() const { return _gpuObject; }
|
GPUObject* getGPUObject() const { return _gpuObject; }
|
||||||
friend class Backend;
|
friend class Backend;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Texture> TexturePointer;
|
typedef std::shared_ptr<Texture> TexturePointer;
|
||||||
typedef std::vector< TexturePointer > Textures;
|
typedef std::vector< TexturePointer > Textures;
|
||||||
|
|
||||||
|
|
||||||
// TODO: For now TextureView works with Buffer as a place holder for the Texture.
|
// TODO: For now TextureView works with Buffer as a place holder for the Texture.
|
||||||
// The overall logic should be about the same except that the Texture will be a real GL Texture under the hood
|
// The overall logic should be about the same except that the Texture will be a real GL Texture under the hood
|
||||||
class TextureView {
|
class TextureView {
|
||||||
public:
|
public:
|
||||||
typedef Resource::Size Size;
|
typedef Resource::Size Size;
|
||||||
|
|
||||||
TexturePointer _texture = TexturePointer(NULL);
|
TexturePointer _texture = TexturePointer(NULL);
|
||||||
uint16 _subresource = 0;
|
uint16 _subresource = 0;
|
||||||
Element _element = Element(gpu::VEC4, gpu::UINT8, gpu::RGBA);
|
Element _element = Element(gpu::VEC4, gpu::UINT8, gpu::RGBA);
|
||||||
|
|
||||||
TextureView() {};
|
TextureView() {};
|
||||||
|
|
||||||
TextureView(const Element& element) :
|
TextureView(const Element& element) :
|
||||||
_element(element)
|
_element(element)
|
||||||
{};
|
{};
|
||||||
|
|
||||||
// create the TextureView and own the Texture
|
// create the TextureView and own the Texture
|
||||||
TextureView(Texture* newTexture, const Element& element) :
|
TextureView(Texture* newTexture, const Element& element) :
|
||||||
_texture(newTexture),
|
_texture(newTexture),
|
||||||
_subresource(0),
|
_subresource(0),
|
||||||
_element(element)
|
_element(element)
|
||||||
{};
|
{};
|
||||||
TextureView(const TexturePointer& texture, uint16 subresource, const Element& element) :
|
TextureView(const TexturePointer& texture, uint16 subresource, const Element& element) :
|
||||||
_texture(texture),
|
_texture(texture),
|
||||||
_subresource(subresource),
|
_subresource(subresource),
|
||||||
_element(element)
|
_element(element)
|
||||||
{};
|
{};
|
||||||
|
|
||||||
TextureView(const TexturePointer& texture, uint16 subresource) :
|
TextureView(const TexturePointer& texture, uint16 subresource) :
|
||||||
_texture(texture),
|
_texture(texture),
|
||||||
_subresource(subresource)
|
_subresource(subresource)
|
||||||
{};
|
{};
|
||||||
|
|
||||||
~TextureView() {}
|
~TextureView() {}
|
||||||
TextureView(const TextureView& view) = default;
|
TextureView(const TextureView& view) = default;
|
||||||
TextureView& operator=(const TextureView& view) = default;
|
TextureView& operator=(const TextureView& view) = default;
|
||||||
|
|
||||||
explicit operator bool() const { return bool(_texture); }
|
explicit operator bool() const { return bool(_texture); }
|
||||||
bool operator !() const { return (!_texture); }
|
bool operator !() const { return (!_texture); }
|
||||||
};
|
};
|
||||||
typedef std::vector<TextureView> TextureViews;
|
typedef std::vector<TextureView> TextureViews;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -127,13 +127,13 @@ TransformCamera getTransformCamera() {
|
||||||
<$worldDir$> = vec3(<$cameraTransform$>._viewInverse * vec4(<$eyeDir$>.xyz, 0.0));
|
<$worldDir$> = vec3(<$cameraTransform$>._viewInverse * vec4(<$eyeDir$>.xyz, 0.0));
|
||||||
}
|
}
|
||||||
<@else@>
|
<@else@>
|
||||||
<$worldDir$> = vec3(gl_ModelViewMatrixInverseTranspose * vec4(<$eyeDir$>.xyz, 0.0));
|
<$worldDir$> = vec3(gl_ModelViewMatrixInverse * vec4(<$eyeDir$>.xyz, 0.0));
|
||||||
<@endif@>
|
<@endif@>
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
<@func transformClipToEyeDir(cameraTransform, clipPos, eyeDir)@>
|
<@func transformClipToEyeDir(cameraTransform, clipPos, eyeDir)@>
|
||||||
<@if GPU_TRANSFORM_PROFILE == GPU_CORE@>
|
<@if GPU_TRANSFORM_PROFILE == GPU_CORE@>
|
||||||
{ // transformClipToEyedDir
|
{ // transformClipToEyeDir
|
||||||
<$eyeDir$> = vec3(<$cameraTransform$>._projectionInverse * vec4(<$clipPos$>.xyz, 1.0));
|
<$eyeDir$> = vec3(<$cameraTransform$>._projectionInverse * vec4(<$clipPos$>.xyz, 1.0));
|
||||||
}
|
}
|
||||||
<@else@>
|
<@else@>
|
||||||
|
|
|
@ -18,7 +18,7 @@ Light::Light() :
|
||||||
_transform() {
|
_transform() {
|
||||||
// only if created from nothing shall we create the Buffer to store the properties
|
// only if created from nothing shall we create the Buffer to store the properties
|
||||||
Schema schema;
|
Schema schema;
|
||||||
_schemaBuffer = gpu::BufferView(new gpu::Buffer(sizeof(Schema), (const gpu::Buffer::Byte*) &schema));
|
_schemaBuffer = gpu::BufferView(new gpu::Buffer(sizeof(Schema), (const gpu::Byte*) &schema));
|
||||||
}
|
}
|
||||||
|
|
||||||
Light::Light(const Light& light) :
|
Light::Light(const Light& light) :
|
||||||
|
|
|
@ -20,7 +20,7 @@ Material::Material() :
|
||||||
|
|
||||||
// only if created from nothing shall we create the Buffer to store the properties
|
// only if created from nothing shall we create the Buffer to store the properties
|
||||||
Schema schema;
|
Schema schema;
|
||||||
_schemaBuffer = gpu::BufferView(new gpu::Buffer(sizeof(Schema), (const gpu::Buffer::Byte*) &schema));
|
_schemaBuffer = gpu::BufferView(new gpu::Buffer(sizeof(Schema), (const gpu::Byte*) &schema));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,26 +17,26 @@
|
||||||
#include "skybox_vert.h"
|
#include "skybox_vert.h"
|
||||||
#include "skybox_frag.h"
|
#include "skybox_frag.h"
|
||||||
|
|
||||||
using namespace model;
|
using namespace model;
|
||||||
|
|
||||||
Skybox::Skybox() {
|
Skybox::Skybox() {
|
||||||
|
|
||||||
_cubemap.reset( gpu::Texture::createCube(gpu::Element::COLOR_RGBA_32, 1));
|
_cubemap.reset( gpu::Texture::createCube(gpu::Element::COLOR_RGBA_32, 1));
|
||||||
unsigned char texels[] = {
|
unsigned char texels[] = {
|
||||||
255, 0, 0, 255,
|
255, 0, 0, 255,
|
||||||
0, 255, 255, 255,
|
0, 255, 255, 255,
|
||||||
0, 0, 255, 255,
|
0, 0, 255, 255,
|
||||||
255, 255, 0, 255,
|
255, 255, 0, 255,
|
||||||
0, 255, 0, 255,
|
0, 255, 0, 255,
|
||||||
255, 0, 255, 255,
|
255, 0, 255, 255,
|
||||||
};
|
};
|
||||||
_cubemap->assignStoredMip(0, gpu::Element::COLOR_RGBA_32, sizeof(texels), texels);
|
_cubemap->assignStoredMip(0, gpu::Element::COLOR_RGBA_32, sizeof(texels), texels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skybox::setColor(const Color& color) {
|
void Skybox::setColor(const Color& color) {
|
||||||
_color = color;
|
_color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skybox::setCubemap(const gpu::TexturePointer& cubemap) {
|
void Skybox::setCubemap(const gpu::TexturePointer& cubemap) {
|
||||||
_cubemap = cubemap;
|
_cubemap = cubemap;
|
||||||
}
|
}
|
||||||
|
@ -44,23 +44,32 @@ void Skybox::setCubemap(const gpu::TexturePointer& cubemap) {
|
||||||
void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) {
|
void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) {
|
||||||
|
|
||||||
if (skybox.getCubemap()) {
|
if (skybox.getCubemap()) {
|
||||||
|
|
||||||
static gpu::PipelinePointer thePipeline;
|
static gpu::PipelinePointer thePipeline;
|
||||||
if (!thePipeline) {
|
static gpu::BufferPointer theBuffer;
|
||||||
auto skyVS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(Skybox_vert)));
|
static gpu::Stream::FormatPointer theFormat;
|
||||||
auto skyFS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(Skybox_frag)));
|
if (!thePipeline) {
|
||||||
auto skyShader = gpu::ShaderPointer(gpu::Shader::createProgram(skyVS, skyFS));
|
auto skyVS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(Skybox_vert)));
|
||||||
|
auto skyFS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(Skybox_frag)));
|
||||||
gpu::Shader::BindingSet bindings;
|
auto skyShader = gpu::ShaderPointer(gpu::Shader::createProgram(skyVS, skyFS));
|
||||||
bindings.insert(gpu::Shader::Binding(std::string("cubeMap"), 0));
|
|
||||||
|
gpu::Shader::BindingSet bindings;
|
||||||
if (!gpu::Shader::makeProgram(*skyShader, bindings)) {
|
bindings.insert(gpu::Shader::Binding(std::string("cubeMap"), 0));
|
||||||
|
|
||||||
}
|
if (!gpu::Shader::makeProgram(*skyShader, bindings)) {
|
||||||
|
|
||||||
auto skyState = gpu::StatePointer(new gpu::State());
|
}
|
||||||
|
|
||||||
|
auto skyState = gpu::StatePointer(new gpu::State());
|
||||||
|
|
||||||
thePipeline = gpu::PipelinePointer(gpu::Pipeline::create(skyShader, skyState));
|
thePipeline = gpu::PipelinePointer(gpu::Pipeline::create(skyShader, skyState));
|
||||||
|
|
||||||
|
const float CLIP = 1.0;
|
||||||
|
const glm::vec2 vertices[4] = { {-CLIP, -CLIP}, {CLIP, -CLIP}, {-CLIP, CLIP}, {CLIP, CLIP}};
|
||||||
|
theBuffer.reset(new gpu::Buffer(sizeof(vertices), (const gpu::Byte*) vertices));
|
||||||
|
|
||||||
|
theFormat.reset(new gpu::Stream::Format());
|
||||||
|
theFormat->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 projMat;
|
glm::mat4 projMat;
|
||||||
|
@ -71,7 +80,10 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky
|
||||||
|
|
||||||
batch.setProjectionTransform(projMat);
|
batch.setProjectionTransform(projMat);
|
||||||
batch.setViewTransform(viewTransform);
|
batch.setViewTransform(viewTransform);
|
||||||
|
batch.setModelTransform(Transform()); // only for Mac
|
||||||
batch.setPipeline(thePipeline);
|
batch.setPipeline(thePipeline);
|
||||||
|
batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8);
|
||||||
|
batch.setInputFormat(theFormat);
|
||||||
batch.setUniformTexture(0, skybox.getCubemap());
|
batch.setUniformTexture(0, skybox.getCubemap());
|
||||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,7 +18,7 @@ varying vec3 color;
|
||||||
|
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
vec4 texel = texture(cubeMap, normalize(normal));
|
vec4 texel = textureCube(cubeMap, normalize(normal));
|
||||||
gl_FragData[0] = texel;
|
gl_FragData[0] = texel;
|
||||||
// gl_FragData[0] = vec4(normal, 1.0);
|
// gl_FragData[0] = vec4(normal, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,7 @@ varying vec2 texcoord;
|
||||||
varying vec3 color;
|
varying vec3 color;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
const float CLIP = 1.0;
|
texcoord = gl_Vertex.xy;
|
||||||
const vec2 vertices[4] = vec2[4](vec2(-CLIP, -CLIP), vec2(CLIP, -CLIP), vec2(-CLIP, CLIP), vec2(CLIP, CLIP));
|
|
||||||
texcoord = vertices[gl_VertexID];
|
|
||||||
|
|
||||||
// pass along the diffuse color
|
// pass along the diffuse color
|
||||||
color = vec3(texcoord, 0.0);
|
color = vec3(texcoord, 0.0);
|
||||||
|
|
|
@ -138,7 +138,7 @@ void EarthSunModel::setSunLongitude(float lon) {
|
||||||
Atmosphere::Atmosphere() {
|
Atmosphere::Atmosphere() {
|
||||||
// only if created from nothing shall we create the Buffer to store the properties
|
// only if created from nothing shall we create the Buffer to store the properties
|
||||||
Data data;
|
Data data;
|
||||||
_dataBuffer = gpu::BufferView(new gpu::Buffer(sizeof(Data), (const gpu::Buffer::Byte*) &data));
|
_dataBuffer = gpu::BufferView(new gpu::Buffer(sizeof(Data), (const gpu::Byte*) &data));
|
||||||
|
|
||||||
setScatteringWavelength(_scatteringWavelength);
|
setScatteringWavelength(_scatteringWavelength);
|
||||||
setRayleighScattering(_rayleighScattering);
|
setRayleighScattering(_rayleighScattering);
|
||||||
|
@ -246,7 +246,7 @@ void SunSkyStage::setOriginLocation(float longitude, float latitude, float altit
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setSunModelEnable(bool isEnabled) {
|
void SunSkyStage::setSunModelEnable(bool isEnabled) {
|
||||||
_sunModelEnable = isEnabled;
|
_sunModelEnable = isEnabled;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ void SunSkyStage::setSunAmbientIntensity(float intensity) {
|
||||||
_sunLight->setAmbientIntensity(intensity);
|
_sunLight->setAmbientIntensity(intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setSunDirection(const Vec3& direction) {
|
void SunSkyStage::setSunDirection(const Vec3& direction) {
|
||||||
if (!isSunModelEnabled()) {
|
if (!isSunModelEnabled()) {
|
||||||
_sunLight->setDirection(direction);
|
_sunLight->setDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
//
|
//
|
||||||
// Stage.h
|
// Stage.h
|
||||||
// libraries/model/src/model
|
// libraries/model/src/model
|
||||||
//
|
//
|
||||||
// Created by Sam Gateau on 2/24/2015.
|
// Created by Sam Gateau on 2/24/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
|
||||||
//
|
//
|
||||||
#ifndef hifi_model_Stage_h
|
#ifndef hifi_model_Stage_h
|
||||||
#define hifi_model_Stage_h
|
#define hifi_model_Stage_h
|
||||||
|
|
||||||
#include "gpu/Pipeline.h"
|
#include "gpu/Pipeline.h"
|
||||||
|
|
||||||
#include "Light.h"
|
#include "Light.h"
|
||||||
#include "Skybox.h"
|
#include "Skybox.h"
|
||||||
|
|
||||||
namespace model {
|
namespace model {
|
||||||
|
|
||||||
typedef glm::dvec3 Vec3d;
|
typedef glm::dvec3 Vec3d;
|
||||||
typedef glm::dvec4 Vec4d;
|
typedef glm::dvec4 Vec4d;
|
||||||
typedef glm::dmat4 Mat4d;
|
typedef glm::dmat4 Mat4d;
|
||||||
typedef glm::mat4 Mat4;
|
typedef glm::mat4 Mat4;
|
||||||
|
|
||||||
class EarthSunModel {
|
class EarthSunModel {
|
||||||
public:
|
public:
|
||||||
|
@ -100,40 +100,40 @@ protected:
|
||||||
void updateSun() const;
|
void updateSun() const;
|
||||||
|
|
||||||
mutable bool _invalid = true;
|
mutable bool _invalid = true;
|
||||||
void invalidate() const { _invalid = true; }
|
void invalidate() const { _invalid = true; }
|
||||||
void valid() const { if (_invalid) { updateAll(); _invalid = false; } }
|
void valid() const { if (_invalid) { updateAll(); _invalid = false; } }
|
||||||
void updateAll() const;
|
void updateAll() const;
|
||||||
|
|
||||||
static Mat4d evalWorldToGeoLocationMat(double longitude, double latitude, double altitude, double scale);
|
static Mat4d evalWorldToGeoLocationMat(double longitude, double latitude, double altitude, double scale);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Atmosphere {
|
class Atmosphere {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Atmosphere();
|
Atmosphere();
|
||||||
Atmosphere(const Atmosphere& atmosphere);
|
Atmosphere(const Atmosphere& atmosphere);
|
||||||
Atmosphere& operator= (const Atmosphere& atmosphere);
|
Atmosphere& operator= (const Atmosphere& atmosphere);
|
||||||
virtual ~Atmosphere() {};
|
virtual ~Atmosphere() {};
|
||||||
|
|
||||||
|
|
||||||
void setScatteringWavelength(Vec3 wavelength);
|
void setScatteringWavelength(Vec3 wavelength);
|
||||||
const Vec3& getScatteringWavelength() const { return _scatteringWavelength; }
|
const Vec3& getScatteringWavelength() const { return _scatteringWavelength; }
|
||||||
|
|
||||||
void setRayleighScattering(float scattering);
|
void setRayleighScattering(float scattering);
|
||||||
float getRayleighScattering() const { return _rayleighScattering; }
|
float getRayleighScattering() const { return _rayleighScattering; }
|
||||||
|
|
||||||
void setMieScattering(float scattering);
|
void setMieScattering(float scattering);
|
||||||
float getMieScattering() const { return _mieScattering; }
|
float getMieScattering() const { return _mieScattering; }
|
||||||
|
|
||||||
void setSunBrightness(float brightness);
|
void setSunBrightness(float brightness);
|
||||||
float getSunBrightness() const { return _sunBrightness; }
|
float getSunBrightness() const { return _sunBrightness; }
|
||||||
|
|
||||||
void setInnerOuterRadiuses(float inner, float outer);
|
void setInnerOuterRadiuses(float inner, float outer);
|
||||||
float getInnerRadius() const { return getData()._radiuses.x; }
|
float getInnerRadius() const { return getData()._radiuses.x; }
|
||||||
float getOuterRadius() const { return getData()._radiuses.y; }
|
float getOuterRadius() const { return getData()._radiuses.y; }
|
||||||
|
|
||||||
// Data to access the attribute values of the atmosphere
|
// Data to access the attribute values of the atmosphere
|
||||||
class Data {
|
class Data {
|
||||||
public:
|
public:
|
||||||
Vec4 _invWaveLength = Vec4(0.0f);
|
Vec4 _invWaveLength = Vec4(0.0f);
|
||||||
|
@ -143,107 +143,107 @@ public:
|
||||||
Vec4 _control = Vec4(2.0f, -0.990f, -0.990f*-0.990f, 0.f);
|
Vec4 _control = Vec4(2.0f, -0.990f, -0.990f*-0.990f, 0.f);
|
||||||
|
|
||||||
Data() {}
|
Data() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const UniformBufferView& getDataBuffer() const { return _dataBuffer; }
|
const UniformBufferView& getDataBuffer() const { return _dataBuffer; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UniformBufferView _dataBuffer;
|
UniformBufferView _dataBuffer;
|
||||||
Vec3 _scatteringWavelength = Vec3(0.650f, 0.570f, 0.475f);
|
Vec3 _scatteringWavelength = Vec3(0.650f, 0.570f, 0.475f);
|
||||||
float _rayleighScattering = 0.0025f;
|
float _rayleighScattering = 0.0025f;
|
||||||
float _mieScattering = 0.0010f;
|
float _mieScattering = 0.0010f;
|
||||||
float _sunBrightness = 20.0f;
|
float _sunBrightness = 20.0f;
|
||||||
|
|
||||||
const Data& getData() const { return _dataBuffer.get<Data>(); }
|
const Data& getData() const { return _dataBuffer.get<Data>(); }
|
||||||
Data& editData() { return _dataBuffer.edit<Data>(); }
|
Data& editData() { return _dataBuffer.edit<Data>(); }
|
||||||
|
|
||||||
void updateScattering();
|
void updateScattering();
|
||||||
};
|
};
|
||||||
typedef std::shared_ptr< Atmosphere > AtmospherePointer;
|
typedef std::shared_ptr< Atmosphere > AtmospherePointer;
|
||||||
|
|
||||||
// Sun sky stage generates the rendering primitives to display a scene realistically
|
// Sun sky stage generates the rendering primitives to display a scene realistically
|
||||||
// at the specified location and time around earth
|
// at the specified location and time around earth
|
||||||
class SunSkyStage {
|
class SunSkyStage {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SunSkyStage();
|
SunSkyStage();
|
||||||
~SunSkyStage();
|
~SunSkyStage();
|
||||||
|
|
||||||
// time of the day (local to the position) expressed in decimal hour in the range [0.0, 24.0]
|
// time of the day (local to the position) expressed in decimal hour in the range [0.0, 24.0]
|
||||||
void setDayTime(float hour);
|
void setDayTime(float hour);
|
||||||
float getDayTime() const { return _dayTime; }
|
float getDayTime() const { return _dayTime; }
|
||||||
|
|
||||||
// time of the year expressed in day in the range [0, 365]
|
// time of the year expressed in day in the range [0, 365]
|
||||||
void setYearTime(unsigned int day);
|
void setYearTime(unsigned int day);
|
||||||
unsigned int getYearTime() const { return _yearTime; }
|
unsigned int getYearTime() const { return _yearTime; }
|
||||||
|
|
||||||
// Origin orientation used to modify the cardinal axis alignement used.
|
// Origin orientation used to modify the cardinal axis alignement used.
|
||||||
// THe default is north along +Z axis and west along +X axis. this orientation gets added
|
// THe default is north along +Z axis and west along +X axis. this orientation gets added
|
||||||
// to the transform stack producing the sun light direction.
|
// to the transform stack producing the sun light direction.
|
||||||
void setOriginOrientation(const Quat& orientation);
|
void setOriginOrientation(const Quat& orientation);
|
||||||
const Quat& getOriginOrientation() const { return _earthSunModel.getSurfaceOrientation(); }
|
const Quat& getOriginOrientation() const { return _earthSunModel.getSurfaceOrientation(); }
|
||||||
|
|
||||||
// Location used to define the sun & sky is a longitude and latitude [rad] and a earth surface altitude [km]
|
// Location used to define the sun & sky is a longitude and latitude [rad] and a earth surface altitude [km]
|
||||||
void setOriginLocation(float longitude, float latitude, float surfaceAltitude);
|
void setOriginLocation(float longitude, float latitude, float surfaceAltitude);
|
||||||
float getOriginLatitude() const { return _earthSunModel.getLatitude(); }
|
float getOriginLatitude() const { return _earthSunModel.getLatitude(); }
|
||||||
float getOriginLongitude() const { return _earthSunModel.getLongitude(); }
|
float getOriginLongitude() const { return _earthSunModel.getLongitude(); }
|
||||||
float getOriginSurfaceAltitude() const { return _earthSunModel.getAltitude(); }
|
float getOriginSurfaceAltitude() const { return _earthSunModel.getAltitude(); }
|
||||||
|
|
||||||
// Enable / disable the effect of the time and location on the sun direction and color
|
// Enable / disable the effect of the time and location on the sun direction and color
|
||||||
void setSunModelEnable(bool isEnabled);
|
void setSunModelEnable(bool isEnabled);
|
||||||
bool isSunModelEnabled() const { return _sunModelEnable; }
|
bool isSunModelEnabled() const { return _sunModelEnable; }
|
||||||
|
|
||||||
// Sun properties
|
// Sun properties
|
||||||
void setSunColor(const Vec3& color);
|
void setSunColor(const Vec3& color);
|
||||||
const Vec3& getSunColor() const { return getSunLight()->getColor(); }
|
const Vec3& getSunColor() const { return getSunLight()->getColor(); }
|
||||||
void setSunIntensity(float intensity);
|
void setSunIntensity(float intensity);
|
||||||
float getSunIntensity() const { return getSunLight()->getIntensity(); }
|
float getSunIntensity() const { return getSunLight()->getIntensity(); }
|
||||||
void setSunAmbientIntensity(float intensity);
|
void setSunAmbientIntensity(float intensity);
|
||||||
float getSunAmbientIntensity() const { return getSunLight()->getAmbientIntensity(); }
|
float getSunAmbientIntensity() const { return getSunLight()->getAmbientIntensity(); }
|
||||||
|
|
||||||
// The sun direction is expressed in the world space
|
// The sun direction is expressed in the world space
|
||||||
void setSunDirection(const Vec3& direction);
|
void setSunDirection(const Vec3& direction);
|
||||||
const Vec3& getSunDirection() const { return getSunLight()->getDirection(); }
|
const Vec3& getSunDirection() const { return getSunLight()->getDirection(); }
|
||||||
|
|
||||||
LightPointer getSunLight() const { valid(); return _sunLight; }
|
LightPointer getSunLight() const { valid(); return _sunLight; }
|
||||||
AtmospherePointer getAtmosphere() const { valid(); return _atmosphere; }
|
AtmospherePointer getAtmosphere() const { valid(); return _atmosphere; }
|
||||||
|
|
||||||
enum BackgroundMode {
|
enum BackgroundMode {
|
||||||
NO_BACKGROUND = 0,
|
NO_BACKGROUND = 0,
|
||||||
SKY_DOME,
|
SKY_DOME,
|
||||||
SKY_BOX,
|
SKY_BOX,
|
||||||
|
|
||||||
NUM_BACKGROUND_MODES,
|
NUM_BACKGROUND_MODES,
|
||||||
};
|
};
|
||||||
void setBackgroundMode(BackgroundMode mode);
|
void setBackgroundMode(BackgroundMode mode);
|
||||||
BackgroundMode getBackgroundMode() const { return _backgroundMode; }
|
BackgroundMode getBackgroundMode() const { return _backgroundMode; }
|
||||||
|
|
||||||
// Skybox
|
// Skybox
|
||||||
void setSkybox(const SkyboxPointer& skybox);
|
void setSkybox(const SkyboxPointer& skybox);
|
||||||
const SkyboxPointer& getSkybox() const { valid(); return _skybox; }
|
const SkyboxPointer& getSkybox() const { valid(); return _skybox; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BackgroundMode _backgroundMode = SKY_DOME;
|
BackgroundMode _backgroundMode = SKY_BOX;
|
||||||
|
|
||||||
LightPointer _sunLight;
|
LightPointer _sunLight;
|
||||||
AtmospherePointer _atmosphere;
|
AtmospherePointer _atmosphere;
|
||||||
SkyboxPointer _skybox;
|
SkyboxPointer _skybox;
|
||||||
|
|
||||||
gpu::PipelinePointer _skyPipeline;
|
gpu::PipelinePointer _skyPipeline;
|
||||||
|
|
||||||
float _dayTime = 12.0f;
|
float _dayTime = 12.0f;
|
||||||
int _yearTime = 0;
|
int _yearTime = 0;
|
||||||
mutable EarthSunModel _earthSunModel;
|
mutable EarthSunModel _earthSunModel;
|
||||||
bool _sunModelEnable = true;
|
bool _sunModelEnable = true;
|
||||||
|
|
||||||
mutable bool _invalid = true;
|
mutable bool _invalid = true;
|
||||||
void invalidate() const { _invalid = true; }
|
void invalidate() const { _invalid = true; }
|
||||||
void valid() const { if (_invalid) { updateGraphicsObject(); _invalid = false; } }
|
void valid() const { if (_invalid) { updateGraphicsObject(); _invalid = false; } }
|
||||||
void updateGraphicsObject() const;
|
void updateGraphicsObject() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr< SunSkyStage > SunSkyStagePointer;
|
typedef std::shared_ptr< SunSkyStage > SunSkyStagePointer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -111,7 +111,7 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm
|
||||||
*(vertex++) = 0.0f;
|
*(vertex++) = 0.0f;
|
||||||
*(vertex++) = 1.0f * radius;
|
*(vertex++) = 1.0f * radius;
|
||||||
|
|
||||||
verticesBuffer->append(sizeof(GLfloat) * vertices * NUM_COORDS_PER_VERTEX, (gpu::Buffer::Byte*) vertexData);
|
verticesBuffer->append(sizeof(GLfloat) * vertices * NUM_COORDS_PER_VERTEX, (gpu::Byte*) vertexData);
|
||||||
delete[] vertexData;
|
delete[] vertexData;
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
|
@ -196,7 +196,7 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm
|
||||||
indexCount += 3;
|
indexCount += 3;
|
||||||
|
|
||||||
}
|
}
|
||||||
indicesBuffer->append(sizeof(GLushort) * indices, (gpu::Buffer::Byte*) indexData);
|
indicesBuffer->append(sizeof(GLushort) * indices, (gpu::Byte*) indexData);
|
||||||
delete[] indexData;
|
delete[] indexData;
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
|
@ -245,7 +245,7 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm
|
||||||
*(colorDataAt++) = compactColor;
|
*(colorDataAt++) = compactColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData);
|
colorBuffer->append(sizeof(int) * vertices, (gpu::Byte*) colorData);
|
||||||
delete[] colorData;
|
delete[] colorData;
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
|
@ -432,7 +432,7 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4&
|
||||||
*(vertex++) = y;
|
*(vertex++) = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
verticesBuffer->append(sizeof(GLfloat) * vertices * 2, (gpu::Buffer::Byte*) vertexData);
|
verticesBuffer->append(sizeof(GLfloat) * vertices * 2, (gpu::Byte*) vertexData);
|
||||||
delete[] vertexData;
|
delete[] vertexData;
|
||||||
|
|
||||||
_gridBuffers[key] = verticesBuffer;
|
_gridBuffers[key] = verticesBuffer;
|
||||||
|
@ -454,7 +454,7 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4&
|
||||||
*(colorDataAt++) = compactColor;
|
*(colorDataAt++) = compactColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData);
|
colorBuffer->append(sizeof(int) * vertices, (gpu::Byte*) colorData);
|
||||||
delete[] colorData;
|
delete[] colorData;
|
||||||
}
|
}
|
||||||
gpu::BufferPointer verticesBuffer = _gridBuffers[key];
|
gpu::BufferPointer verticesBuffer = _gridBuffers[key];
|
||||||
|
@ -537,7 +537,7 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in
|
||||||
tx += dx;
|
tx += dx;
|
||||||
}
|
}
|
||||||
|
|
||||||
verticesBuffer->append(sizeof(GLfloat) * vertices * 2, (gpu::Buffer::Byte*) vertexData);
|
verticesBuffer->append(sizeof(GLfloat) * vertices * 2, (gpu::Byte*) vertexData);
|
||||||
delete[] vertexData;
|
delete[] vertexData;
|
||||||
|
|
||||||
if (registered) {
|
if (registered) {
|
||||||
|
@ -564,7 +564,7 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in
|
||||||
*(colorDataAt++) = compactColor;
|
*(colorDataAt++) = compactColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData);
|
colorBuffer->append(sizeof(int) * vertices, (gpu::Byte*) colorData);
|
||||||
delete[] colorData;
|
delete[] colorData;
|
||||||
}
|
}
|
||||||
gpu::BufferPointer verticesBuffer = registered ? _registeredAlternateGridBuffers[id] : _alternateGridBuffers[key];
|
gpu::BufferPointer verticesBuffer = registered ? _registeredAlternateGridBuffers[id] : _alternateGridBuffers[key];
|
||||||
|
@ -648,8 +648,8 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con
|
||||||
*(colorDataAt++) = compactColor;
|
*(colorDataAt++) = compactColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData);
|
details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Byte*) vertexData);
|
||||||
details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData);
|
details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Byte*) colorData);
|
||||||
delete[] vertexData;
|
delete[] vertexData;
|
||||||
delete[] colorData;
|
delete[] colorData;
|
||||||
|
|
||||||
|
@ -711,8 +711,8 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con
|
||||||
*(colorDataAt++) = compactColor;
|
*(colorDataAt++) = compactColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData);
|
details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Byte*) vertexData);
|
||||||
details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData);
|
details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Byte*) colorData);
|
||||||
delete[] vertexData;
|
delete[] vertexData;
|
||||||
delete[] colorData;
|
delete[] colorData;
|
||||||
|
|
||||||
|
@ -793,7 +793,7 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) {
|
||||||
*(vertex++) = *cannonicalNormal++;
|
*(vertex++) = *cannonicalNormal++;
|
||||||
}
|
}
|
||||||
|
|
||||||
verticesBuffer->append(sizeof(GLfloat) * vertexPoints * 2, (gpu::Buffer::Byte*) vertexData);
|
verticesBuffer->append(sizeof(GLfloat) * vertexPoints * 2, (gpu::Byte*) vertexData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_solidCubeIndexBuffer) {
|
if (!_solidCubeIndexBuffer) {
|
||||||
|
@ -808,7 +808,7 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) {
|
||||||
gpu::BufferPointer indexBuffer(new gpu::Buffer());
|
gpu::BufferPointer indexBuffer(new gpu::Buffer());
|
||||||
_solidCubeIndexBuffer = indexBuffer;
|
_solidCubeIndexBuffer = indexBuffer;
|
||||||
|
|
||||||
_solidCubeIndexBuffer->append(sizeof(cannonicalIndices), (gpu::Buffer::Byte*) cannonicalIndices);
|
_solidCubeIndexBuffer->append(sizeof(cannonicalIndices), (gpu::Byte*) cannonicalIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_solidCubeColors.contains(colorKey)) {
|
if (!_solidCubeColors.contains(colorKey)) {
|
||||||
|
@ -827,7 +827,7 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) {
|
||||||
compactColor, compactColor, compactColor, compactColor,
|
compactColor, compactColor, compactColor, compactColor,
|
||||||
compactColor, compactColor, compactColor, compactColor };
|
compactColor, compactColor, compactColor, compactColor };
|
||||||
|
|
||||||
colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
}
|
}
|
||||||
gpu::BufferPointer verticesBuffer = _solidCubeVerticies[size];
|
gpu::BufferPointer verticesBuffer = _solidCubeVerticies[size];
|
||||||
gpu::BufferPointer colorBuffer = _solidCubeColors[colorKey];
|
gpu::BufferPointer colorBuffer = _solidCubeColors[colorKey];
|
||||||
|
@ -891,7 +891,7 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) {
|
||||||
vertex[i] = cannonicalVertices[i] * halfSize;
|
vertex[i] = cannonicalVertices[i] * halfSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
verticesBuffer->append(sizeof(GLfloat) * vertexPoints, (gpu::Buffer::Byte*) vertexData); // I'm skeptical that this is right
|
verticesBuffer->append(sizeof(GLfloat) * vertexPoints, (gpu::Byte*) vertexData); // I'm skeptical that this is right
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_wireCubeIndexBuffer) {
|
if (!_wireCubeIndexBuffer) {
|
||||||
|
@ -904,7 +904,7 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) {
|
||||||
gpu::BufferPointer indexBuffer(new gpu::Buffer());
|
gpu::BufferPointer indexBuffer(new gpu::Buffer());
|
||||||
_wireCubeIndexBuffer = indexBuffer;
|
_wireCubeIndexBuffer = indexBuffer;
|
||||||
|
|
||||||
_wireCubeIndexBuffer->append(sizeof(cannonicalIndices), (gpu::Buffer::Byte*) cannonicalIndices);
|
_wireCubeIndexBuffer->append(sizeof(cannonicalIndices), (gpu::Byte*) cannonicalIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_cubeColors.contains(colorKey)) {
|
if (!_cubeColors.contains(colorKey)) {
|
||||||
|
@ -919,7 +919,7 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) {
|
||||||
int colors[NUM_COLOR_SCALARS_PER_CUBE] = { compactColor, compactColor, compactColor, compactColor,
|
int colors[NUM_COLOR_SCALARS_PER_CUBE] = { compactColor, compactColor, compactColor, compactColor,
|
||||||
compactColor, compactColor, compactColor, compactColor };
|
compactColor, compactColor, compactColor, compactColor };
|
||||||
|
|
||||||
colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
}
|
}
|
||||||
gpu::BufferPointer verticesBuffer = _cubeVerticies[size];
|
gpu::BufferPointer verticesBuffer = _cubeVerticies[size];
|
||||||
gpu::BufferPointer colorBuffer = _cubeColors[colorKey];
|
gpu::BufferPointer colorBuffer = _cubeColors[colorKey];
|
||||||
|
@ -1037,8 +1037,8 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height,
|
||||||
compactColor, compactColor, compactColor, compactColor };
|
compactColor, compactColor, compactColor, compactColor };
|
||||||
|
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer);
|
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
||||||
details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
|
|
||||||
delete[] vertexBuffer;
|
delete[] vertexBuffer;
|
||||||
}
|
}
|
||||||
|
@ -1119,8 +1119,8 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC
|
||||||
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
|
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
|
||||||
|
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer);
|
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
||||||
details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::Batch batch;
|
gpu::Batch batch;
|
||||||
|
@ -1208,8 +1208,8 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC
|
||||||
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
|
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
|
||||||
|
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer);
|
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
||||||
details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::Batch batch;
|
gpu::Batch batch;
|
||||||
|
@ -1294,8 +1294,8 @@ void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxC
|
||||||
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
|
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
|
||||||
|
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer);
|
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
||||||
details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::Batch batch;
|
gpu::Batch batch;
|
||||||
|
@ -1396,8 +1396,8 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
||||||
((int(color.w * 255.0f) & 0xFF) << 24);
|
((int(color.w * 255.0f) & 0xFF) << 24);
|
||||||
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
|
int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer);
|
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
||||||
details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::Batch batch;
|
gpu::Batch batch;
|
||||||
|
@ -1510,8 +1510,8 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en
|
||||||
*(vertex++) = end.z;
|
*(vertex++) = end.z;
|
||||||
*(colorDataAt++) = compactColor;
|
*(colorDataAt++) = compactColor;
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData);
|
details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Byte*) vertexData);
|
||||||
details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData);
|
details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Byte*) colorData);
|
||||||
delete[] vertexData;
|
delete[] vertexData;
|
||||||
delete[] colorData;
|
delete[] colorData;
|
||||||
|
|
||||||
|
@ -1653,8 +1653,8 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2,
|
||||||
const int NUM_COLOR_SCALARS = 2;
|
const int NUM_COLOR_SCALARS = 2;
|
||||||
int colors[NUM_COLOR_SCALARS] = { compactColor1, compactColor2 };
|
int colors[NUM_COLOR_SCALARS] = { compactColor1, compactColor2 };
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer);
|
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
||||||
details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
if (id == UNKNOWN_ID) {
|
if (id == UNKNOWN_ID) {
|
||||||
|
@ -1745,8 +1745,8 @@ void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2,
|
||||||
const int NUM_COLOR_SCALARS = 2;
|
const int NUM_COLOR_SCALARS = 2;
|
||||||
int colors[NUM_COLOR_SCALARS] = { compactColor1, compactColor2 };
|
int colors[NUM_COLOR_SCALARS] = { compactColor1, compactColor2 };
|
||||||
|
|
||||||
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer);
|
details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer);
|
||||||
details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
|
details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
if (id == UNKNOWN_ID) {
|
if (id == UNKNOWN_ID) {
|
||||||
|
@ -2234,10 +2234,10 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
foreach(const FBXMeshPart& part, mesh.parts) {
|
foreach(const FBXMeshPart& part, mesh.parts) {
|
||||||
networkMesh._indexBuffer->setSubData(offset, part.quadIndices.size() * sizeof(int),
|
networkMesh._indexBuffer->setSubData(offset, part.quadIndices.size() * sizeof(int),
|
||||||
(gpu::Resource::Byte*) part.quadIndices.constData());
|
(gpu::Byte*) part.quadIndices.constData());
|
||||||
offset += part.quadIndices.size() * sizeof(int);
|
offset += part.quadIndices.size() * sizeof(int);
|
||||||
networkMesh._indexBuffer->setSubData(offset, part.triangleIndices.size() * sizeof(int),
|
networkMesh._indexBuffer->setSubData(offset, part.triangleIndices.size() * sizeof(int),
|
||||||
(gpu::Resource::Byte*) part.triangleIndices.constData());
|
(gpu::Byte*) part.triangleIndices.constData());
|
||||||
offset += part.triangleIndices.size() * sizeof(int);
|
offset += part.triangleIndices.size() * sizeof(int);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2256,19 +2256,19 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
|
||||||
|
|
||||||
networkMesh._vertexBuffer->resize(clusterWeightsOffset + mesh.clusterWeights.size() * sizeof(glm::vec4));
|
networkMesh._vertexBuffer->resize(clusterWeightsOffset + mesh.clusterWeights.size() * sizeof(glm::vec4));
|
||||||
|
|
||||||
networkMesh._vertexBuffer->setSubData(0, mesh.vertices.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) mesh.vertices.constData());
|
networkMesh._vertexBuffer->setSubData(0, mesh.vertices.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.vertices.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(normalsOffset, mesh.normals.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) mesh.normals.constData());
|
networkMesh._vertexBuffer->setSubData(normalsOffset, mesh.normals.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.normals.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(tangentsOffset,
|
networkMesh._vertexBuffer->setSubData(tangentsOffset,
|
||||||
mesh.tangents.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) mesh.tangents.constData());
|
mesh.tangents.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.tangents.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(colorsOffset, mesh.colors.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) mesh.colors.constData());
|
networkMesh._vertexBuffer->setSubData(colorsOffset, mesh.colors.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.colors.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(texCoordsOffset,
|
networkMesh._vertexBuffer->setSubData(texCoordsOffset,
|
||||||
mesh.texCoords.size() * sizeof(glm::vec2), (gpu::Resource::Byte*) mesh.texCoords.constData());
|
mesh.texCoords.size() * sizeof(glm::vec2), (gpu::Byte*) mesh.texCoords.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(texCoords1Offset,
|
networkMesh._vertexBuffer->setSubData(texCoords1Offset,
|
||||||
mesh.texCoords1.size() * sizeof(glm::vec2), (gpu::Resource::Byte*) mesh.texCoords1.constData());
|
mesh.texCoords1.size() * sizeof(glm::vec2), (gpu::Byte*) mesh.texCoords1.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(clusterIndicesOffset,
|
networkMesh._vertexBuffer->setSubData(clusterIndicesOffset,
|
||||||
mesh.clusterIndices.size() * sizeof(glm::vec4), (gpu::Resource::Byte*) mesh.clusterIndices.constData());
|
mesh.clusterIndices.size() * sizeof(glm::vec4), (gpu::Byte*) mesh.clusterIndices.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(clusterWeightsOffset,
|
networkMesh._vertexBuffer->setSubData(clusterWeightsOffset,
|
||||||
mesh.clusterWeights.size() * sizeof(glm::vec4), (gpu::Resource::Byte*) mesh.clusterWeights.constData());
|
mesh.clusterWeights.size() * sizeof(glm::vec4), (gpu::Byte*) mesh.clusterWeights.constData());
|
||||||
|
|
||||||
// otherwise, at least the cluster indices/weights can be static
|
// otherwise, at least the cluster indices/weights can be static
|
||||||
networkMesh._vertexStream = gpu::BufferStreamPointer(new gpu::BufferStream());
|
networkMesh._vertexStream = gpu::BufferStreamPointer(new gpu::BufferStream());
|
||||||
|
@ -2304,14 +2304,14 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
|
||||||
int clusterWeightsOffset = clusterIndicesOffset + mesh.clusterIndices.size() * sizeof(glm::vec4);
|
int clusterWeightsOffset = clusterIndicesOffset + mesh.clusterIndices.size() * sizeof(glm::vec4);
|
||||||
|
|
||||||
networkMesh._vertexBuffer->resize(clusterWeightsOffset + mesh.clusterWeights.size() * sizeof(glm::vec4));
|
networkMesh._vertexBuffer->resize(clusterWeightsOffset + mesh.clusterWeights.size() * sizeof(glm::vec4));
|
||||||
networkMesh._vertexBuffer->setSubData(0, mesh.tangents.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) mesh.tangents.constData());
|
networkMesh._vertexBuffer->setSubData(0, mesh.tangents.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.tangents.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(colorsOffset, mesh.colors.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) mesh.colors.constData());
|
networkMesh._vertexBuffer->setSubData(colorsOffset, mesh.colors.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.colors.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(texCoordsOffset,
|
networkMesh._vertexBuffer->setSubData(texCoordsOffset,
|
||||||
mesh.texCoords.size() * sizeof(glm::vec2), (gpu::Resource::Byte*) mesh.texCoords.constData());
|
mesh.texCoords.size() * sizeof(glm::vec2), (gpu::Byte*) mesh.texCoords.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(clusterIndicesOffset,
|
networkMesh._vertexBuffer->setSubData(clusterIndicesOffset,
|
||||||
mesh.clusterIndices.size() * sizeof(glm::vec4), (gpu::Resource::Byte*) mesh.clusterIndices.constData());
|
mesh.clusterIndices.size() * sizeof(glm::vec4), (gpu::Byte*) mesh.clusterIndices.constData());
|
||||||
networkMesh._vertexBuffer->setSubData(clusterWeightsOffset,
|
networkMesh._vertexBuffer->setSubData(clusterWeightsOffset,
|
||||||
mesh.clusterWeights.size() * sizeof(glm::vec4), (gpu::Resource::Byte*) mesh.clusterWeights.constData());
|
mesh.clusterWeights.size() * sizeof(glm::vec4), (gpu::Byte*) mesh.clusterWeights.constData());
|
||||||
|
|
||||||
networkMesh._vertexStream = gpu::BufferStreamPointer(new gpu::BufferStream());
|
networkMesh._vertexStream = gpu::BufferStreamPointer(new gpu::BufferStream());
|
||||||
if (mesh.tangents.size()) networkMesh._vertexStream->addBuffer(networkMesh._vertexBuffer, 0, sizeof(glm::vec3));
|
if (mesh.tangents.size()) networkMesh._vertexStream->addBuffer(networkMesh._vertexBuffer, 0, sizeof(glm::vec3));
|
||||||
|
|
|
@ -451,9 +451,9 @@ bool Model::updateGeometry() {
|
||||||
gpu::BufferPointer buffer(new gpu::Buffer());
|
gpu::BufferPointer buffer(new gpu::Buffer());
|
||||||
if (!mesh.blendshapes.isEmpty()) {
|
if (!mesh.blendshapes.isEmpty()) {
|
||||||
buffer->resize((mesh.vertices.size() + mesh.normals.size()) * sizeof(glm::vec3));
|
buffer->resize((mesh.vertices.size() + mesh.normals.size()) * sizeof(glm::vec3));
|
||||||
buffer->setSubData(0, mesh.vertices.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) mesh.vertices.constData());
|
buffer->setSubData(0, mesh.vertices.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.vertices.constData());
|
||||||
buffer->setSubData(mesh.vertices.size() * sizeof(glm::vec3),
|
buffer->setSubData(mesh.vertices.size() * sizeof(glm::vec3),
|
||||||
mesh.normals.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) mesh.normals.constData());
|
mesh.normals.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.normals.constData());
|
||||||
}
|
}
|
||||||
_blendedVertexBuffers.push_back(buffer);
|
_blendedVertexBuffers.push_back(buffer);
|
||||||
}
|
}
|
||||||
|
@ -1732,9 +1732,9 @@ void Model::setBlendedVertices(int blendNumber, const QWeakPointer<NetworkGeomet
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::BufferPointer& buffer = _blendedVertexBuffers[i];
|
gpu::BufferPointer& buffer = _blendedVertexBuffers[i];
|
||||||
buffer->setSubData(0, mesh.vertices.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) vertices.constData() + index*sizeof(glm::vec3));
|
buffer->setSubData(0, mesh.vertices.size() * sizeof(glm::vec3), (gpu::Byte*) vertices.constData() + index*sizeof(glm::vec3));
|
||||||
buffer->setSubData(mesh.vertices.size() * sizeof(glm::vec3),
|
buffer->setSubData(mesh.vertices.size() * sizeof(glm::vec3),
|
||||||
mesh.normals.size() * sizeof(glm::vec3), (gpu::Resource::Byte*) normals.constData() + index*sizeof(glm::vec3));
|
mesh.normals.size() * sizeof(glm::vec3), (gpu::Byte*) normals.constData() + index*sizeof(glm::vec3));
|
||||||
|
|
||||||
index += mesh.vertices.size();
|
index += mesh.vertices.size();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue