History

Use raw OpenGL textures rather than QOpenGLTexture, since that we're having issues with constants in that class.

Andrzej Kapolka committed 12 years ago

Commit a0886d41 parent 90ce7382 files · +44 −50Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 2 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+40−39
@@ -29,7 +29,6 @@ REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) · 28 unmodified lines
29REGISTER_META_OBJECT(SphereRenderer)29REGISTER_META_OBJECT(SphereRenderer)
30REGISTER_META_OBJECT(StaticModelRenderer)30REGISTER_META_OBJECT(StaticModelRenderer)
31 31
32static int texturePointerMetaTypeId = qRegisterMetaType<TexturePointer>();
33static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();32static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
34 33
35void MetavoxelSystem::init() {34void MetavoxelSystem::init() {
@@ -113,9 +112,9 @@ void MetavoxelSystem::render() { · 77 unmodified lines
113 guideToAugmented(renderVisitor);112 guideToAugmented(renderVisitor);
114}113}
115 114
116void MetavoxelSystem::deleteTextures(const TexturePointer& height, const TexturePointer& color) {115void MetavoxelSystem::deleteTextures(int heightID, int colorID) {
117 delete height;116 glDeleteTextures(1, (GLuint*)&heightID);
118 delete color;117 glDeleteTextures(1, (GLuint*)&colorID);
119}118}
120 119
121MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {120MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {
@@ -267,18 +266,19 @@ HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, · 145 unmodified lines
267 _height(height),266 _height(height),
268 _color(color),267 _color(color),
269 _clearAfterLoading(clearAfterLoading),268 _clearAfterLoading(clearAfterLoading),
270 _heightTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)),269 _heightTextureID(0),
271 _colorTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)) {270 _colorTextureID(0),
271 _heightSize(glm::sqrt(height.size())) {
272}272}
273 273
274HeightfieldBuffer::~HeightfieldBuffer() {274HeightfieldBuffer::~HeightfieldBuffer() {
275 // the textures have to be deleted on the main thread (for its opengl context)275 // the textures have to be deleted on the main thread (for its opengl context)
276 if (QThread::currentThread() != Application::getInstance()->thread()) {276 if (QThread::currentThread() != Application::getInstance()->thread()) {
277 QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures",277 QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures",
278 Q_ARG(const TexturePointer&, _heightTexture), Q_ARG(const TexturePointer&, _colorTexture));278 Q_ARG(int, _heightTextureID), Q_ARG(int, _colorTextureID));
279 } else {279 } else {
280 delete _heightTexture;280 glDeleteTextures(1, &_heightTextureID);
281 delete _colorTexture;281 glDeleteTextures(1, &_colorTextureID);
282 }282 }
283}283}
284 284
@@ -290,49 +290,46 @@ public: · 5 unmodified lines
290 290
291void HeightfieldBuffer::render() {291void HeightfieldBuffer::render() {
292 // initialize textures, etc. on first render292 // initialize textures, etc. on first render
293 if (!_heightTexture->isCreated()) {293 if (_heightTextureID == 0) {
294 int heightSize = glm::sqrt(_height.size());294 glGenTextures(1, &_heightTextureID);
295 _heightTexture->setSize(heightSize, heightSize);295 glBindTexture(GL_TEXTURE_2D, _heightTextureID);
296 _heightTexture->setAutoMipMapGenerationEnabled(false);296 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
297 _heightTexture->setMinificationFilter(QOpenGLTexture::Linear);297 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
298 _heightTexture->setWrapMode(QOpenGLTexture::ClampToEdge);298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
299 _heightTexture->setFormat(QOpenGLTexture::LuminanceFormat);299 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0,
300 _heightTexture->allocateStorage();300 GL_LUMINANCE, GL_UNSIGNED_BYTE, _height.constData());
301 _heightTexture->setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data());
302 if (_clearAfterLoading) {301 if (_clearAfterLoading) {
303 _height.clear();302 _height.clear();
304 }303 }
305 if (!_color.isEmpty()) {304
305 glGenTextures(1, &_colorTextureID);
306 glBindTexture(GL_TEXTURE_2D, _colorTextureID);
307 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
308 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
310 if (_color.isEmpty()) {
311 const quint8 WHITE_COLOR[] = { 255, 255, 255 };
312 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR);
313
314 } else {
306 int colorSize = glm::sqrt(_color.size() / 3);315 int colorSize = glm::sqrt(_color.size() / 3);
307 _colorTexture->setSize(colorSize, colorSize);316 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData());
308 }
309 _colorTexture->setAutoMipMapGenerationEnabled(false);
310 _colorTexture->setMinificationFilter(QOpenGLTexture::Linear);
311 _colorTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
312 _colorTexture->setFormat(QOpenGLTexture::RGBFormat);
313 _colorTexture->allocateStorage();
314 if (!_color.isEmpty()) {
315 _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data());
316 if (_clearAfterLoading) {317 if (_clearAfterLoading) {
317 _color.clear();318 _color.clear();
318 }319 }
319 } else {
320 const quint8 WHITE_COLOR[] = { 255, 255, 255 };
321 _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR));
322 }320 }
323 }321 }
324 // create the buffer objects lazily322 // create the buffer objects lazily
325 int size = _heightTexture->width();323 int sizeWithSkirt = _heightSize + 2;
326 int sizeWithSkirt = size + 2;
327 int vertexCount = sizeWithSkirt * sizeWithSkirt;324 int vertexCount = sizeWithSkirt * sizeWithSkirt;
328 int rows = sizeWithSkirt - 1;325 int rows = sizeWithSkirt - 1;
329 int indexCount = rows * rows * 4;326 int indexCount = rows * rows * 4;
330 BufferPair& bufferPair = _bufferPairs[size];327 BufferPair& bufferPair = _bufferPairs[_heightSize];
331 if (!bufferPair.first.isCreated()) {328 if (!bufferPair.first.isCreated()) {
332 QVector<HeightfieldPoint> vertices(vertexCount);329 QVector<HeightfieldPoint> vertices(vertexCount);
333 HeightfieldPoint* point = vertices.data();330 HeightfieldPoint* point = vertices.data();
334 331
335 float step = 1.0f / (size - 1);332 float step = 1.0f / (_heightSize - 1);
336 float z = -step;333 float z = -step;
337 for (int i = 0; i < sizeWithSkirt; i++, z += step) {334 for (int i = 0; i < sizeWithSkirt; i++, z += step) {
338 float x = -step;335 float x = -step;
@@ -380,13 +377,17 @@ void HeightfieldBuffer::render() { · 41 unmodified lines
380 glTranslatef(_translation.x, _translation.y, _translation.z);377 glTranslatef(_translation.x, _translation.y, _translation.z);
381 glScalef(_scale, _scale, _scale);378 glScalef(_scale, _scale, _scale);
382 379
383 _heightTexture->bind(0);380 glBindTexture(GL_TEXTURE_2D, _heightTextureID);
384 _colorTexture->bind(1);381
382 glActiveTexture(GL_TEXTURE1);
383 glBindTexture(GL_TEXTURE_2D, _colorTextureID);
385 384
386 glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);385 glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
387 386
388 _colorTexture->release(1);387 glBindTexture(GL_TEXTURE_2D, 0);
389 _heightTexture->release(0);388
389 glActiveTexture(GL_TEXTURE0);
390 glBindTexture(GL_TEXTURE_2D, 0);
390 391
391 glPopMatrix();392 glPopMatrix();
392 393

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t