File indexing completed on 2024-12-22 04:12:47
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 0008 #include "KisOpenGLBufferCreationGuard.h" 0009 0010 #include "kis_opengl.h" 0011 0012 0013 KisOpenGLBufferCreationGuard::KisOpenGLBufferCreationGuard(QOpenGLBuffer *buffer, int size, QOpenGLBuffer::UsagePattern usagePattern) 0014 { 0015 m_buffer = buffer; 0016 0017 m_buffer->create(); 0018 m_buffer->setUsagePattern(usagePattern); 0019 m_buffer->bind(); 0020 m_buffer->allocate(size); 0021 0022 if (KisOpenGL::supportsBufferMapping()) { 0023 m_bufferPtr = reinterpret_cast<quint8*>(m_buffer->map(QOpenGLBuffer::WriteOnly)); 0024 m_bufferIsMapped = true; 0025 } 0026 0027 if (!m_bufferPtr) { 0028 m_bufferPtr = new quint8[size]; 0029 } 0030 } 0031 0032 KisOpenGLBufferCreationGuard::~KisOpenGLBufferCreationGuard() 0033 { 0034 if (m_bufferIsMapped) { 0035 m_buffer->unmap(); 0036 } else { 0037 m_buffer->write(0, m_bufferPtr, m_buffer->size()); 0038 delete[] m_bufferPtr; 0039 } 0040 m_buffer->release(); 0041 }