mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 11:33:44 +02:00
experimenting with linear space vs srgb space
This commit is contained in:
parent
aecc8b85bd
commit
49dde269a6
11 changed files with 75 additions and 38 deletions
|
@ -272,8 +272,7 @@ FBXNode parseBinaryFBXNode(QDataStream& in, int& position) {
|
|||
position += nameLength;
|
||||
|
||||
for (quint32 i = 0; i < propertyCount; i++) {
|
||||
QVariant var = parseBinaryFBXProperty(in, position);
|
||||
node.properties.append(var);
|
||||
node.properties.append(parseBinaryFBXProperty(in, position));
|
||||
}
|
||||
|
||||
while (endOffset > position) {
|
||||
|
|
|
@ -93,15 +93,13 @@ static const int DIMENSION_COUNT[NUM_DIMENSIONS] = {
|
|||
// Provide information on how to use the element
|
||||
enum Semantic {
|
||||
RAW = 0, // used as RAW memory
|
||||
|
||||
RGB,
|
||||
RGBA,
|
||||
BGRA,
|
||||
XYZ,
|
||||
XYZW,
|
||||
POS_XYZ,
|
||||
POS_XYZW,
|
||||
QUAT,
|
||||
DIR_XYZ,
|
||||
UV,
|
||||
INDEX, //used by index buffer of a mesh
|
||||
PART, // used by part buffer of a mesh
|
||||
|
@ -109,6 +107,10 @@ enum Semantic {
|
|||
DEPTH, // Depth buffer
|
||||
DEPTH_STENCIL, // Depth Stencil buffer
|
||||
|
||||
SRGB,
|
||||
SRGBA,
|
||||
SBGRA,
|
||||
|
||||
NUM_SEMANTICS,
|
||||
};
|
||||
|
||||
|
|
|
@ -472,7 +472,7 @@ void GLBackend::do_setUniformTexture(Batch& batch, uint32 paramOffset) {
|
|||
GLuint slot = batch._params[paramOffset + 1]._uint;
|
||||
TexturePointer uniformTexture = batch._textures.get(batch._params[paramOffset + 0]._uint);
|
||||
|
||||
GLuint to = getTextureID(*uniformTexture);
|
||||
GLuint to = getTextureID(uniformTexture);
|
||||
glActiveTexture(GL_TEXTURE0 + slot);
|
||||
glBindTexture(GL_TEXTURE_2D, to);
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
~GLTexture();
|
||||
};
|
||||
static void syncGPUObject(const Texture& texture);
|
||||
static GLuint getTextureID(const Texture& texture);
|
||||
static GLuint getTextureID(const TexturePointer& texture);
|
||||
|
||||
static const int MAX_NUM_ATTRIBUTES = Stream::NUM_INPUT_SLOTS;
|
||||
static const int MAX_NUM_INPUT_BUFFERS = 16;
|
||||
|
|
|
@ -94,10 +94,13 @@ public:
|
|||
|
||||
switch(srcFormat.getSemantic()) {
|
||||
case gpu::BGRA:
|
||||
case gpu::SBGRA:
|
||||
texel.format = GL_BGRA;
|
||||
break;
|
||||
case gpu::RGB:
|
||||
case gpu::RGBA:
|
||||
case gpu::SRGB:
|
||||
case gpu::SRGBA:
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
@ -109,6 +112,12 @@ public:
|
|||
case gpu::RGBA:
|
||||
texel.internalFormat = GL_RGBA;
|
||||
break;
|
||||
case gpu::SRGB:
|
||||
texel.internalFormat = GL_SRGB;
|
||||
break;
|
||||
case gpu::SRGBA:
|
||||
texel.internalFormat = GL_SRGB_ALPHA;
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Unknown combination of texel format";
|
||||
}
|
||||
|
@ -170,6 +179,10 @@ public:
|
|||
case gpu::RGBA:
|
||||
texel.internalFormat = GL_RGB;
|
||||
break;
|
||||
case gpu::SRGB:
|
||||
case gpu::SRGBA:
|
||||
texel.internalFormat = GL_SRGB; // standard 2.2 gamma correction color
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Unknown combination of texel format";
|
||||
}
|
||||
|
@ -187,6 +200,12 @@ public:
|
|||
case gpu::RGBA:
|
||||
texel.internalFormat = GL_RGBA;
|
||||
break;
|
||||
case gpu::SRGB:
|
||||
texel.internalFormat = GL_SRGB;
|
||||
break;
|
||||
case gpu::SRGBA:
|
||||
texel.internalFormat = GL_SRGB_ALPHA; // standard 2.2 gamma correction color
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Unknown combination of texel format";
|
||||
}
|
||||
|
@ -295,13 +314,17 @@ void GLBackend::syncGPUObject(const Texture& texture) {
|
|||
|
||||
|
||||
|
||||
GLuint GLBackend::getTextureID(const Texture& texture) {
|
||||
GLBackend::syncGPUObject(texture);
|
||||
GLTexture* object = Backend::getGPUObject<GLBackend::GLTexture>(texture);
|
||||
if (object) {
|
||||
return object->_texture;
|
||||
} else {
|
||||
GLuint GLBackend::getTextureID(const TexturePointer& texture) {
|
||||
if (texture) {
|
||||
GLBackend::syncGPUObject(*texture);
|
||||
GLTexture* object = Backend::getGPUObject<GLBackend::GLTexture>(*texture);
|
||||
if (object) {
|
||||
return object->_texture;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@ Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) :
|
|||
Texture::Pixels::~Pixels() {
|
||||
}
|
||||
|
||||
void Texture::Storage::assignTexture(Texture* texture) {
|
||||
_texture = texture;
|
||||
}
|
||||
|
||||
Stamp Texture::Storage::getStamp(uint16 level) const {
|
||||
PixelsPointer mip = getMip(level);
|
||||
if (mip) {
|
||||
|
@ -111,7 +115,7 @@ Texture* Texture::create(Type type, const Element& texelFormat, uint16 width, ui
|
|||
Texture* Texture::createFromStorage(Storage* storage) {
|
||||
Texture* tex = new Texture();
|
||||
tex->_storage.reset(storage);
|
||||
storage->_texture = tex;
|
||||
storage->assignTexture(tex);
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,7 @@ public:
|
|||
typedef QSharedPointer< Pixels > PixelsPointer;
|
||||
|
||||
class Storage {
|
||||
Texture* _texture;
|
||||
std::vector<PixelsPointer> _mips;
|
||||
public:
|
||||
|
||||
Storage() {}
|
||||
virtual ~Storage() {}
|
||||
virtual void reset();
|
||||
|
@ -45,7 +42,13 @@ public:
|
|||
virtual bool allocateMip(uint16 level);
|
||||
virtual bool assignMipData(uint16 level, const Element& format, Size size, const Byte* bytes);
|
||||
virtual bool isMipAvailable(uint16 level) const;
|
||||
|
||||
|
||||
protected:
|
||||
Texture* _texture;
|
||||
std::vector<PixelsPointer> _mips;
|
||||
|
||||
virtual void assignTexture(Texture* tex);
|
||||
|
||||
friend class Texture;
|
||||
};
|
||||
|
||||
|
|
|
@ -2068,7 +2068,7 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
|
|||
|
||||
int channelNum = 0;
|
||||
networkMesh._vertexFormat = gpu::Stream::FormatPointer(new gpu::Stream::Format());
|
||||
networkMesh._vertexFormat->setAttribute(gpu::Stream::POSITION, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0);
|
||||
networkMesh._vertexFormat->setAttribute(gpu::Stream::POSITION, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0);
|
||||
if (mesh.normals.size()) networkMesh._vertexFormat->setAttribute(gpu::Stream::NORMAL, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ));
|
||||
if (mesh.tangents.size()) networkMesh._vertexFormat->setAttribute(gpu::Stream::TANGENT, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ));
|
||||
if (mesh.colors.size()) networkMesh._vertexFormat->setAttribute(gpu::Stream::COLOR, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RGB));
|
||||
|
@ -2102,7 +2102,7 @@ void NetworkGeometry::setGeometry(const FBXGeometry& geometry) {
|
|||
|
||||
int channelNum = 0;
|
||||
networkMesh._vertexFormat = gpu::Stream::FormatPointer(new gpu::Stream::Format());
|
||||
networkMesh._vertexFormat->setAttribute(gpu::Stream::POSITION, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ));
|
||||
networkMesh._vertexFormat->setAttribute(gpu::Stream::POSITION, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ));
|
||||
if (mesh.normals.size()) networkMesh._vertexFormat->setAttribute(gpu::Stream::NORMAL, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ));
|
||||
if (mesh.tangents.size()) networkMesh._vertexFormat->setAttribute(gpu::Stream::TANGENT, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ));
|
||||
if (mesh.colors.size()) networkMesh._vertexFormat->setAttribute(gpu::Stream::COLOR, channelNum++, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RGB));
|
||||
|
|
|
@ -167,7 +167,7 @@ TextRenderer::TextRenderer(const Properties& properties) :
|
|||
_glyphsStream(new gpu::BufferStream()),
|
||||
_numGlyphsBatched(0)
|
||||
{
|
||||
_glyphsStreamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::POS_XYZ), 0);
|
||||
_glyphsStreamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0);
|
||||
const int NUM_POS_COORDS = 2;
|
||||
const int VERTEX_TEXCOORD_OFFSET = NUM_POS_COORDS * sizeof(float);
|
||||
_glyphsStreamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET);
|
||||
|
|
|
@ -531,13 +531,17 @@ void NetworkTexture::setImage(const QImage& image, bool translucent, const QColo
|
|||
finishedLoading(true);
|
||||
imageLoaded(image);
|
||||
|
||||
if (image.hasAlphaChannel()) {
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), image.width(), image.height()));
|
||||
_gpuTexture->assignStoredMip(0, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::BGRA), image.byteCount(), image.constBits());
|
||||
_gpuTexture->autoGenerateMips(-1);
|
||||
} else {
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB), image.width(), image.height()));
|
||||
_gpuTexture->assignStoredMip(0, gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB), image.byteCount(), image.constBits());
|
||||
if ((_width > 0) && (_height > 0)) {
|
||||
bool isLinearRGB = (_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE);
|
||||
|
||||
gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB));
|
||||
gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB));
|
||||
if (image.hasAlphaChannel()) {
|
||||
formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA));
|
||||
formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA));
|
||||
}
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, image.width(), image.height()));
|
||||
_gpuTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||
_gpuTexture->autoGenerateMips(-1);
|
||||
}
|
||||
}
|
||||
|
@ -567,16 +571,17 @@ QSharedPointer<Texture> DilatableNetworkTexture::getDilatedTexture(float dilatio
|
|||
path.addEllipse(QPointF(_image.width() / 2.0, _image.height() / 2.0), radius, radius);
|
||||
painter.fillPath(path, Qt::black);
|
||||
painter.end();
|
||||
|
||||
|
||||
gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (_type == NORMAL_TEXTURE ? gpu::RGB : gpu::SRGB));
|
||||
gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (_type == NORMAL_TEXTURE ? gpu::RGB : gpu::SRGB));
|
||||
if (dilatedImage.hasAlphaChannel()) {
|
||||
texture->_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), dilatedImage.width(), dilatedImage.height()));
|
||||
texture->_gpuTexture->assignStoredMip(0, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::BGRA), dilatedImage.byteCount(), dilatedImage.constBits());
|
||||
texture->_gpuTexture->autoGenerateMips(-1);
|
||||
} else {
|
||||
texture->_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB), dilatedImage.width(), dilatedImage.height()));
|
||||
texture->_gpuTexture->assignStoredMip(0, gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB), dilatedImage.byteCount(), dilatedImage.constBits());
|
||||
texture->_gpuTexture->autoGenerateMips(-1);
|
||||
formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (_type == NORMAL_TEXTURE ? gpu::RGBA : gpu::SRGBA));
|
||||
formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (_type == NORMAL_TEXTURE ? gpu::BGRA : gpu::BGRA));
|
||||
}
|
||||
texture->_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, dilatedImage.width(), dilatedImage.height()));
|
||||
texture->_gpuTexture->assignStoredMip(0, formatMip, dilatedImage.byteCount(), dilatedImage.constBits());
|
||||
texture->_gpuTexture->autoGenerateMips(-1);
|
||||
|
||||
}
|
||||
|
||||
_dilatedTextures.insert(dilation, texture);
|
||||
|
|
|
@ -168,8 +168,9 @@ protected:
|
|||
|
||||
virtual void imageLoaded(const QImage& image);
|
||||
|
||||
private:
|
||||
TextureType _type;
|
||||
|
||||
private:
|
||||
bool _translucent;
|
||||
QColor _averageColor;
|
||||
int _width;
|
||||
|
|
Loading…
Reference in a new issue