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
2929 REGISTER_META_OBJECT(SphereRenderer)
3030 REGISTER_META_OBJECT(StaticModelRenderer)
3131
32−static int texturePointerMetaTypeId = qRegisterMetaType<TexturePointer>();
3332 static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
3433
3534 void MetavoxelSystem::init() {
@@ -113,9 +112,9 @@ void MetavoxelSystem::render() { · 77 unmodified lines
113112 guideToAugmented(renderVisitor);
114113 }
115114
116−void MetavoxelSystem::deleteTextures(const TexturePointer& height, const TexturePointer& color) {
117− delete height;
118− delete color;
115+void MetavoxelSystem::deleteTextures(int heightID, int colorID) {
116+ glDeleteTextures(1, (GLuint*)&heightID);
117+ glDeleteTextures(1, (GLuint*)&colorID);
119118 }
120119
121120 MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {
@@ -267,18 +266,19 @@ HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, · 145 unmodified lines
267266 _height(height),
268267 _color(color),
269268 _clearAfterLoading(clearAfterLoading),
270− _heightTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)),
271− _colorTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)) {
269+ _heightTextureID(0),
270+ _colorTextureID(0),
271+ _heightSize(glm::sqrt(height.size())) {
272272 }
273273
274274 HeightfieldBuffer::~HeightfieldBuffer() {
275275 // the textures have to be deleted on the main thread (for its opengl context)
276276 if (QThread::currentThread() != Application::getInstance()->thread()) {
277277 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));
279279 } else {
280− delete _heightTexture;
281− delete _colorTexture;
280+ glDeleteTextures(1, &_heightTextureID);
281+ glDeleteTextures(1, &_colorTextureID);
282282 }
283283 }
284284
@@ -290,49 +290,46 @@ public: · 5 unmodified lines
290290
291291 void HeightfieldBuffer::render() {
292292 // initialize textures, etc. on first render
293− if (!_heightTexture->isCreated()) {
294− int heightSize = glm::sqrt(_height.size());
295− _heightTexture->setSize(heightSize, heightSize);
296− _heightTexture->setAutoMipMapGenerationEnabled(false);
297− _heightTexture->setMinificationFilter(QOpenGLTexture::Linear);
298− _heightTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
299− _heightTexture->setFormat(QOpenGLTexture::LuminanceFormat);
300− _heightTexture->allocateStorage();
301− _heightTexture->setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data());
293+ if (_heightTextureID == 0) {
294+ glGenTextures(1, &_heightTextureID);
295+ glBindTexture(GL_TEXTURE_2D, _heightTextureID);
296+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
297+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
298+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
299+ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, _heightSize, _heightSize, 0,
300+ GL_LUMINANCE, GL_UNSIGNED_BYTE, _height.constData());
302301 if (_clearAfterLoading) {
303302 _height.clear();
304303 }
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 {
306315 int colorSize = glm::sqrt(_color.size() / 3);
307− _colorTexture->setSize(colorSize, colorSize);
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+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData());
316317 if (_clearAfterLoading) {
317318 _color.clear();
318319 }
319− } else {
320− const quint8 WHITE_COLOR[] = { 255, 255, 255 };
321− _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR));
322320 }
323321 }
324322 // create the buffer objects lazily
325− int size = _heightTexture->width();
326− int sizeWithSkirt = size + 2;
323+ int sizeWithSkirt = _heightSize + 2;
327324 int vertexCount = sizeWithSkirt * sizeWithSkirt;
328325 int rows = sizeWithSkirt - 1;
329326 int indexCount = rows * rows * 4;
330− BufferPair& bufferPair = _bufferPairs[size];
327+ BufferPair& bufferPair = _bufferPairs[_heightSize];
331328 if (!bufferPair.first.isCreated()) {
332329 QVector<HeightfieldPoint> vertices(vertexCount);
333330 HeightfieldPoint* point = vertices.data();
334331
335− float step = 1.0f / (size - 1);
332+ float step = 1.0f / (_heightSize - 1);
336333 float z = -step;
337334 for (int i = 0; i < sizeWithSkirt; i++, z += step) {
338335 float x = -step;
@@ -380,13 +377,17 @@ void HeightfieldBuffer::render() { · 41 unmodified lines
380377 glTranslatef(_translation.x, _translation.y, _translation.z);
381378 glScalef(_scale, _scale, _scale);
382379
383− _heightTexture->bind(0);
384− _colorTexture->bind(1);
380+ glBindTexture(GL_TEXTURE_2D, _heightTextureID);
381+
382+ glActiveTexture(GL_TEXTURE1);
383+ glBindTexture(GL_TEXTURE_2D, _colorTextureID);
385384
386385 glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
387386
388− _colorTexture->release(1);
389− _heightTexture->release(0);
387+ glBindTexture(GL_TEXTURE_2D, 0);
388+
389+ glActiveTexture(GL_TEXTURE0);
390+ glBindTexture(GL_TEXTURE_2D, 0);
390391
391392 glPopMatrix();
392393

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