mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-05 21:53:27 -06:00
ce9a65ee41
Housekeeping in VizFwk in preparation for introducing support for QOpenGLWidget and Qt6 * Adjusted unit tests to changes in source code * Use Qt5 as default and removed copying of Qt DLLs * Removed support for Qt4 * Removed the CVF_OPENGL_ES define. If we ever want to re-introduce support fro OpenGLES/Angle it should be handled differently. *Added include of <locale.h> * Added target for running Glsl2Include in order to build cvfShaderSourceStrings.h * Removed all usage of CVF_USING_CMAKE * Removed visual studio project files
178 lines
6.0 KiB
C++
178 lines
6.0 KiB
C++
//##################################################################################################
|
|
//
|
|
// Custom Visualization Core library
|
|
// Copyright (C) 2011-2013 Ceetron AS
|
|
//
|
|
// This library may be used under the terms of either the GNU General Public License or
|
|
// the GNU Lesser General Public License as follows:
|
|
//
|
|
// GNU General Public License Usage
|
|
// This library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
|
// for more details.
|
|
//
|
|
// GNU Lesser General Public License Usage
|
|
// This library is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation; either version 2.1 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
|
// for more details.
|
|
//
|
|
//##################################################################################################
|
|
|
|
|
|
#include "cvfBase.h"
|
|
#include "cvfRenderbufferObject.h"
|
|
#include "cvfOpenGL.h"
|
|
#include "cvfOglRc.h"
|
|
#include "cvfOpenGLResourceManager.h"
|
|
|
|
namespace cvf {
|
|
|
|
|
|
//==================================================================================================
|
|
///
|
|
/// \class cvf::RenderbufferObject
|
|
/// \ingroup Render
|
|
///
|
|
/// Encapsulates an OpenGL renderbuffer object
|
|
///
|
|
//==================================================================================================
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RenderbufferObject::RenderbufferObject(InternalFormat format, uint width, uint height)
|
|
: Object(),
|
|
m_interalFormat(format),
|
|
m_width(width),
|
|
m_height(height),
|
|
m_versionTick(1)
|
|
{
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RenderbufferObject::~RenderbufferObject()
|
|
{
|
|
// Just release our reference
|
|
CVF_ASSERT(OglRc::isSafeToRelease(m_oglRcBuffer.p()));
|
|
m_oglRcBuffer = NULL;
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
OglId RenderbufferObject::renderbufferOglId() const
|
|
{
|
|
return OglRc::safeOglId(m_oglRcBuffer.p());
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
uint RenderbufferObject::versionTick() const
|
|
{
|
|
return m_versionTick;
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RenderbufferObject::setSize(uint width, uint height)
|
|
{
|
|
// Forget existing buffer
|
|
CVF_ASSERT(OglRc::isSafeToRelease(m_oglRcBuffer.p()));
|
|
m_oglRcBuffer = NULL;
|
|
|
|
m_width = width;
|
|
m_height = height;
|
|
m_versionTick++;
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RenderbufferObject::create(OpenGLContext* oglContext)
|
|
{
|
|
CVF_CALLSITE_OPENGL(oglContext);
|
|
CVF_CLEAR_OGL_ERROR(oglContext);
|
|
|
|
m_oglRcBuffer = oglContext->resourceManager()->createOglRcRenderbuffer(oglContext);
|
|
OglId myOglId = OglRc::safeOglId(m_oglRcBuffer.p());
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, myOglId);
|
|
glRenderbufferStorage(GL_RENDERBUFFER, intenalFormatOpenGL(), static_cast<GLsizei>(m_width), static_cast<GLsizei>(m_height));
|
|
|
|
if (CVF_TEST_AND_REPORT_OPENGL_ERROR(oglContext, "Allocate render buffer storage"))
|
|
{
|
|
deleteRenderbuffer(oglContext);
|
|
return false;
|
|
}
|
|
|
|
m_versionTick++;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RenderbufferObject::deleteRenderbuffer(OpenGLContext* oglContext)
|
|
{
|
|
CVF_ASSERT(oglContext);
|
|
|
|
if (m_oglRcBuffer.notNull())
|
|
{
|
|
m_oglRcBuffer->deleteResource(oglContext);
|
|
CVF_CHECK_OGL(oglContext);
|
|
|
|
CVF_ASSERT(OglRc::isSafeToRelease(m_oglRcBuffer.p()));
|
|
m_oglRcBuffer = NULL;
|
|
}
|
|
|
|
m_versionTick++;
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
cvfGLenum RenderbufferObject::intenalFormatOpenGL() const
|
|
{
|
|
switch(m_interalFormat)
|
|
{
|
|
case RGBA: return GL_RGBA;
|
|
case DEPTH_COMPONENT16: return GL_DEPTH_COMPONENT16;
|
|
case DEPTH_COMPONENT24: return GL_DEPTH_COMPONENT24;
|
|
case DEPTH_COMPONENT32: return GL_DEPTH_COMPONENT32;
|
|
case DEPTH24_STENCIL8: return GL_DEPTH24_STENCIL8;
|
|
}
|
|
|
|
CVF_FAIL_MSG("Illegal renderbuffer format");
|
|
return GL_RGBA;
|
|
}
|
|
|
|
} // namespace cvf
|