mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
Use raw OpenGL textures rather than QOpenGLTexture, since that we're having
issues with constants in that class.
This commit is contained in:
parent
90ce73823a
commit
a0886d4301
2 changed files with 44 additions and 50 deletions
|
@ -29,7 +29,6 @@ REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation)
|
||||||
REGISTER_META_OBJECT(SphereRenderer)
|
REGISTER_META_OBJECT(SphereRenderer)
|
||||||
REGISTER_META_OBJECT(StaticModelRenderer)
|
REGISTER_META_OBJECT(StaticModelRenderer)
|
||||||
|
|
||||||
static int texturePointerMetaTypeId = qRegisterMetaType<TexturePointer>();
|
|
||||||
static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
|
static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
|
||||||
|
|
||||||
void MetavoxelSystem::init() {
|
void MetavoxelSystem::init() {
|
||||||
|
@ -113,9 +112,9 @@ void MetavoxelSystem::render() {
|
||||||
guideToAugmented(renderVisitor);
|
guideToAugmented(renderVisitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetavoxelSystem::deleteTextures(const TexturePointer& height, const TexturePointer& color) {
|
void MetavoxelSystem::deleteTextures(int heightID, int colorID) {
|
||||||
delete height;
|
glDeleteTextures(1, (GLuint*)&heightID);
|
||||||
delete color;
|
glDeleteTextures(1, (GLuint*)&colorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {
|
MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {
|
||||||
|
@ -267,18 +266,19 @@ HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale,
|
||||||
_height(height),
|
_height(height),
|
||||||
_color(color),
|
_color(color),
|
||||||
_clearAfterLoading(clearAfterLoading),
|
_clearAfterLoading(clearAfterLoading),
|
||||||
_heightTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)),
|
_heightTextureID(0),
|
||||||
_colorTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)) {
|
_colorTextureID(0),
|
||||||
|
_heightSize(glm::sqrt(height.size())) {
|
||||||
}
|
}
|
||||||
|
|
||||||
HeightfieldBuffer::~HeightfieldBuffer() {
|
HeightfieldBuffer::~HeightfieldBuffer() {
|
||||||
// the textures have to be deleted on the main thread (for its opengl context)
|
// the textures have to be deleted on the main thread (for its opengl context)
|
||||||
if (QThread::currentThread() != Application::getInstance()->thread()) {
|
if (QThread::currentThread() != Application::getInstance()->thread()) {
|
||||||
QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures",
|
QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures",
|
||||||
Q_ARG(const TexturePointer&, _heightTexture), Q_ARG(const TexturePointer&, _colorTexture));
|
Q_ARG(int, _heightTextureID), Q_ARG(int, _colorTextureID));
|
||||||
} else {
|
} else {
|
||||||
delete _heightTexture;
|
glDeleteTextures(1, &_heightTextureID);
|
||||||
delete _colorTexture;
|
glDeleteTextures(1, &_colorTextureID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,49 +290,46 @@ public:
|
||||||
|
|
||||||
void HeightfieldBuffer::render() {
|
void HeightfieldBuffer::render() {
|
||||||
// initialize textures, etc. on first render
|
// initialize textures, etc. on first render
|
||||||
if (!_heightTexture->isCreated()) {
|
if (_heightTextureID == 0) {
|
||||||
int heightSize = glm::sqrt(_height.size());
|
glGenTextures(1, &_heightTextureID);
|
||||||
_heightTexture->setSize(heightSize, heightSize);
|
glBindTexture(GL_TEXTURE_2D, _heightTextureID);
|
||||||
_heightTexture->setAutoMipMapGenerationEnabled(false);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
_heightTexture->setMinificationFilter(QOpenGLTexture::Linear);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
_heightTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
_heightTexture->setFormat(QOpenGLTexture::LuminanceFormat);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0,
|
||||||
_heightTexture->allocateStorage();
|
GL_LUMINANCE, GL_UNSIGNED_BYTE, _height.constData());
|
||||||
_heightTexture->setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data());
|
|
||||||
if (_clearAfterLoading) {
|
if (_clearAfterLoading) {
|
||||||
_height.clear();
|
_height.clear();
|
||||||
}
|
}
|
||||||
if (!_color.isEmpty()) {
|
|
||||||
|
glGenTextures(1, &_colorTextureID);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
if (_color.isEmpty()) {
|
||||||
|
const quint8 WHITE_COLOR[] = { 255, 255, 255 };
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR);
|
||||||
|
|
||||||
|
} else {
|
||||||
int colorSize = glm::sqrt(_color.size() / 3);
|
int colorSize = glm::sqrt(_color.size() / 3);
|
||||||
_colorTexture->setSize(colorSize, colorSize);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData());
|
||||||
}
|
|
||||||
_colorTexture->setAutoMipMapGenerationEnabled(false);
|
|
||||||
_colorTexture->setMinificationFilter(QOpenGLTexture::Linear);
|
|
||||||
_colorTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
|
|
||||||
_colorTexture->setFormat(QOpenGLTexture::RGBFormat);
|
|
||||||
_colorTexture->allocateStorage();
|
|
||||||
if (!_color.isEmpty()) {
|
|
||||||
_colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data());
|
|
||||||
if (_clearAfterLoading) {
|
if (_clearAfterLoading) {
|
||||||
_color.clear();
|
_color.clear();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const quint8 WHITE_COLOR[] = { 255, 255, 255 };
|
|
||||||
_colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create the buffer objects lazily
|
// create the buffer objects lazily
|
||||||
int size = _heightTexture->width();
|
int sizeWithSkirt = _heightSize + 2;
|
||||||
int sizeWithSkirt = size + 2;
|
|
||||||
int vertexCount = sizeWithSkirt * sizeWithSkirt;
|
int vertexCount = sizeWithSkirt * sizeWithSkirt;
|
||||||
int rows = sizeWithSkirt - 1;
|
int rows = sizeWithSkirt - 1;
|
||||||
int indexCount = rows * rows * 4;
|
int indexCount = rows * rows * 4;
|
||||||
BufferPair& bufferPair = _bufferPairs[size];
|
BufferPair& bufferPair = _bufferPairs[_heightSize];
|
||||||
if (!bufferPair.first.isCreated()) {
|
if (!bufferPair.first.isCreated()) {
|
||||||
QVector<HeightfieldPoint> vertices(vertexCount);
|
QVector<HeightfieldPoint> vertices(vertexCount);
|
||||||
HeightfieldPoint* point = vertices.data();
|
HeightfieldPoint* point = vertices.data();
|
||||||
|
|
||||||
float step = 1.0f / (size - 1);
|
float step = 1.0f / (_heightSize - 1);
|
||||||
float z = -step;
|
float z = -step;
|
||||||
for (int i = 0; i < sizeWithSkirt; i++, z += step) {
|
for (int i = 0; i < sizeWithSkirt; i++, z += step) {
|
||||||
float x = -step;
|
float x = -step;
|
||||||
|
@ -380,13 +377,17 @@ void HeightfieldBuffer::render() {
|
||||||
glTranslatef(_translation.x, _translation.y, _translation.z);
|
glTranslatef(_translation.x, _translation.y, _translation.z);
|
||||||
glScalef(_scale, _scale, _scale);
|
glScalef(_scale, _scale, _scale);
|
||||||
|
|
||||||
_heightTexture->bind(0);
|
glBindTexture(GL_TEXTURE_2D, _heightTextureID);
|
||||||
_colorTexture->bind(1);
|
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||||
|
|
||||||
glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
|
glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
_colorTexture->release(1);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
_heightTexture->release(0);
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,8 @@
|
||||||
#ifndef hifi_MetavoxelSystem_h
|
#ifndef hifi_MetavoxelSystem_h
|
||||||
#define hifi_MetavoxelSystem_h
|
#define hifi_MetavoxelSystem_h
|
||||||
|
|
||||||
// include this before QOpenGLTexture, which includes an earlier version of OpenGL
|
|
||||||
#include "InterfaceConfig.h"
|
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLTexture>
|
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
@ -29,8 +25,6 @@
|
||||||
|
|
||||||
class Model;
|
class Model;
|
||||||
|
|
||||||
typedef QOpenGLTexture* TexturePointer;
|
|
||||||
|
|
||||||
/// Renders a metavoxel tree.
|
/// Renders a metavoxel tree.
|
||||||
class MetavoxelSystem : public MetavoxelClientManager {
|
class MetavoxelSystem : public MetavoxelClientManager {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -47,7 +41,7 @@ public:
|
||||||
void simulate(float deltaTime);
|
void simulate(float deltaTime);
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
Q_INVOKABLE void deleteTextures(const TexturePointer& height, const TexturePointer& color);
|
Q_INVOKABLE void deleteTextures(int heightID, int colorID);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -64,8 +58,6 @@ private:
|
||||||
QReadWriteLock _lodLock;
|
QReadWriteLock _lodLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(TexturePointer)
|
|
||||||
|
|
||||||
/// Describes contents of a point in a point buffer.
|
/// Describes contents of a point in a point buffer.
|
||||||
class BufferPoint {
|
class BufferPoint {
|
||||||
public:
|
public:
|
||||||
|
@ -154,8 +146,9 @@ private:
|
||||||
QByteArray _height;
|
QByteArray _height;
|
||||||
QByteArray _color;
|
QByteArray _color;
|
||||||
bool _clearAfterLoading;
|
bool _clearAfterLoading;
|
||||||
TexturePointer _heightTexture;
|
GLuint _heightTextureID;
|
||||||
TexturePointer _colorTexture;
|
GLuint _colorTextureID;
|
||||||
|
int _heightSize;
|
||||||
|
|
||||||
typedef QPair<QOpenGLBuffer, QOpenGLBuffer> BufferPair;
|
typedef QPair<QOpenGLBuffer, QOpenGLBuffer> BufferPair;
|
||||||
static QHash<int, BufferPair> _bufferPairs;
|
static QHash<int, BufferPair> _bufferPairs;
|
||||||
|
|
Loading…
Reference in a new issue