05.03., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 9a834357 authored by Jakob Weiss's avatar Jakob Weiss

Merge branch 'campvis-nx' of gitlab.lrz.de:weiss/campvis-nx into campvis-nx

# Conflicts:
#	ext/cgt/texture.cpp
parents 1e8bb380 609563e6
......@@ -98,7 +98,7 @@ namespace campvis {
// converting from GL representation
GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* toReturn = nullptr;
GLJobProc.enqueueJobBlocking([&]() {
if (cgt::Texture::calcMatchingDataType(tester->getTexture()->getInternalFormat()) != TypeTraits<BASETYPE, NUMCHANNELS>::glDataType)
if (cgt::Texture::calcMatchingPixelDataType(tester->getTexture()->getInternalFormat()) != TypeTraits<BASETYPE, NUMCHANNELS>::glDataType)
LDEBUGC("CAMPVis.core.datastructures.GenericLocalConversion", "Performing conversion between data types, you may lose information or the resulting data may show other unexpected features.");
WeaklyTypedPointer wtp = tester->getWeaklyTypedPointerConvert(TypeTraits<BASETYPE, NUMCHANNELS>::glDataType);
......
......@@ -201,15 +201,15 @@ namespace campvis {
}
const WeaklyTypedPointer ImageRepresentationGL::getWeaklyTypedPointerCopy() const {
GLint format = cgt::Texture::calcMatchingFormat(_texture->getInternalFormat());
GLenum dataType = cgt::Texture::calcMatchingDataType(_texture->getInternalFormat());
GLint format = cgt::Texture::calcMatchingPixelFormat(_texture->getInternalFormat());
GLenum dataType = cgt::Texture::calcMatchingPixelDataType(_texture->getInternalFormat());
GLubyte* data = _texture->downloadTextureToBuffer(format, dataType);
return WeaklyTypedPointer(WeaklyTypedPointer::baseType(dataType), _texture->getNumChannels(), data);
}
const WeaklyTypedPointer ImageRepresentationGL::getWeaklyTypedPointerConvert(GLenum dataType) const {
GLint format = cgt::Texture::calcMatchingFormat(_texture->getInternalFormat());
GLint format = cgt::Texture::calcMatchingPixelFormat(_texture->getInternalFormat());
GLubyte* data = _texture->downloadTextureToBuffer(format, dataType);
return WeaklyTypedPointer(WeaklyTypedPointer::baseType(dataType), _texture->getNumChannels(), data);
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
// (c) 2016 Jakob Weiss <jakob.weiss@tum.de>
#include "cshelper.h"
#include <sstream>
#include <cgt/texture.h>
#include <cgt/imageunit.h>
#include <cgt/gltextureformattraits.h>
namespace campvis {
namespace CSHelper {
//const std::string loggerCat_ = "CAMPVis.core.tools.CSHelper";
CAMPVIS_CORE_API std::string generateGLSLImageDefinition(const cgt::Texture & tex, const std::string& uniformName, const cgt::ImageUnit& imgUnit)
{
std::stringstream ss;
auto fmtTraits = cgt::GLTextureFormatTraits::get(tex.getInternalFormat());
ss << "layout(" << fmtTraits.glslFormatQualifier() << ", binding = " << imgUnit.getUnitNumber() << ") uniform "; // "layout( (r8|r16|rgba16|...) uniform"
ss << (fmtTraits.isIntegerFormat() ? (fmtTraits.isSignedFormat() ? "iimage" : "uimage") : "image"); // "(i|u|_)image"
ss << ( (tex.getType() == GL_TEXTURE_1D) ? 1 : ( (tex.getType() == GL_TEXTURE_2D) ? 2 : 3) ) << "D "; // "(1|2|3)D"
ss << uniformName << ";" << std::endl;
return ss.str();
}
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
// (c) 2016 Jakob Weiss <jakob.weiss@tum.de>
#ifndef CSHELPER_H__
#define CSHELPER_H__
#include <string>
#include "core/coreapi.h"
namespace cgt {
class Texture;
class ImageUnit;
}
namespace campvis {
/**
* CSHelper namespace
* Collection of various helper classes and functions to simplify using Compute Shaders for various applications
*/
namespace CSHelper {
/// Loggin category for the LDEBUG macros
//const std::string loggerCat_;
/**
* Generates a glsl image definition that matches the texture type and layout
*/
CAMPVIS_CORE_API std::string generateGLSLImageDefinition(const cgt::Texture& tex, const std::string& uniformName, const cgt::ImageUnit& imgUnit);
}
}
#endif // CSHELPER_H__
......@@ -176,7 +176,7 @@ namespace campvis {
}
// read back stuff
GLenum readBackFormat = cgt::Texture::calcMatchingFormat(outputTex->getInternalFormat());
GLenum readBackFormat = cgt::Texture::calcMatchingPixelFormat(outputTex->getInternalFormat());
size_t channels = outputTex->getNumChannels();
toReturn.resize(channels);
glReadBuffer(GL_COLOR_ATTACHMENT0);
......
......@@ -31,6 +31,7 @@ SET(CGT_SOURCES
glcontextmanager.cpp
gpucapabilities.cpp
gpucapabilitieswindows.cpp
imageunit.cpp
init.cpp
logmanager.cpp
job.cpp
......
/**********************************************************************
* *
* cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2015 *
* Chair for Computer Aided Medical Procedures *
* Technische Universitaet Muenchen, Germany. *
* <http://campar.in.tum.de/> *
* *
* forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011 *
* Visualization and Computer Graphics Group, Department of *
* Computer Science, University of Muenster, Germany. *
* <http://viscg.uni-muenster.de> *
* *
* This file is part of the cgt library. This library is free *
* software; you can redistribute it and/or modify it under the terms *
* of the GNU Lesser General Public License version 2.1 as published *
* by the Free Software Foundation. *
* *
* 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 for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License in the file "LICENSE.txt" along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
**********************************************************************/
#pragma once
#include <GL/glew.h>
#include <string>
namespace cgt {
/**
* Class for storing and querying texture format traits at runtime. Can be used to
* gain more insight into the texture format of a texture if only the internal format
* is known. Use the static \a get() method to query the traits for a format at
* runtime.
*/
class GLTextureFormatTraits {
public:
/// Constructor for unknown format
constexpr GLTextureFormatTraits(GLint internalFormat__)
: known_{ false }
, internalFormatName_{ "Unknown" }
, bpp_{ 0 }
, channels_{ 0 }
, internalFormat_{ internalFormat__ }
, pixelFormat_{ -1 }
, pixelDataType_{ -1 }
, glslFormatQualifier_{ "Unknown" }
{};
/// Constructor for known formats
constexpr GLTextureFormatTraits(GLint internalFormat__, const char* internalFormatName__, int bpp__, int channels__, GLint pixelFormat__, GLint pixelDataType__, const char* glslFormatQualifier__)
: internalFormatName_{ internalFormatName__ }
, known_{ true }
, bpp_{ bpp__ }
, channels_{ channels__ }
, internalFormat_{ internalFormat__ }
, pixelFormat_{ pixelFormat__ }
, pixelDataType_{ pixelDataType__ }
, glslFormatQualifier_{ glslFormatQualifier__ }
{};
static constexpr GLTextureFormatTraits get(GLint internalFormat);
/**
* Whether the specified GLint is a valid internal format. If this is
* false, all other fields will contain default (invalid) values.
*/
constexpr bool known() const { return known_; };
/**
* The name of the macro as a string, empty if unknown.
*/
constexpr const char* internalFormatName() const { return internalFormatName_; } ;
/**
* Number of bytes per pixel
* @return the number of bytes per pixel (1-16 on current hardware) or zero for unknown format
*/
constexpr int bpp() const { return bpp_; };
/**
* Number of channels
* @return the number of channels (1-4) or 0 for unknown format
*/
constexpr int channels() const { return channels_; };
/**
* GLint of the internal format
*/
constexpr GLint internalFormat() const { return internalFormat_; };
/**
* Matching pixel format
* @return one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_RED_INTEGER, GL_RG_INTEGER, GL_RGB_INTEGER, GL_RGBA_INTEGER, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL
*/
constexpr GLint pixelFormat() const { return pixelFormat_; };
/**
* Matching pixel data type
* @return GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT
*/
constexpr GLint pixelDataType() const { return pixelDataType_; };
/**
* Matching write format qualifier for use in glsl with image read/write operations.
* @return rgba32f, r16, r8u, ...
*/
constexpr const char* glslFormatQualifier() const { return glslFormatQualifier_; };
/**
* Is the format is a (signed or unsigned) integer format?
*/
constexpr bool isIntegerFormat() const {
return pixelDataType_ == GL_RED_INTEGER
|| pixelDataType_ == GL_RG_INTEGER
|| pixelDataType_ == GL_RGB_INTEGER
|| pixelDataType_ == GL_RGBA_INTEGER;
}
/**
* Is the format unsigned or not? (float formats have a sign)
*/
constexpr bool isSignedFormat() const {
return (pixelDataType_ != GL_UNSIGNED_BYTE
&& pixelDataType_ != GL_UNSIGNED_SHORT
&& pixelDataType_ != GL_UNSIGNED_INT);
}
private:
const bool known_;
const char* internalFormatName_;
const int bpp_;
const int channels_;
const GLint internalFormat_;
const GLint pixelFormat_;
const GLint pixelDataType_;
const char* glslFormatQualifier_;
};
#define defFormat(INTERNAL_FORMAT, BPP, CHANNELS, PIXEL_FORMAT, PIXEL_DATA_TYPE, GLSL_FORMAT_QUALIFIER) \
(internalFormat == INTERNAL_FORMAT) ? GLTextureFormatTraits(INTERNAL_FORMAT, #INTERNAL_FORMAT, BPP, CHANNELS, PIXEL_FORMAT, PIXEL_DATA_TYPE, GLSL_FORMAT_QUALIFIER) :
constexpr GLTextureFormatTraits GLTextureFormatTraits::get(GLint internalFormat)
{
return
defFormat(GL_DEPTH_COMPONENT , 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT , "**UNKNOWN**")
defFormat(GL_R8 , 1, 1, GL_RED , GL_UNSIGNED_BYTE , "r8")
defFormat(GL_R8_SNORM , 1, 1, GL_RED , GL_BYTE , "r8_snorm")
defFormat(GL_R8I , 1, 1, GL_RED_INTEGER , GL_BYTE , "r8i")
defFormat(GL_R8UI , 1, 1, GL_RED_INTEGER , GL_UNSIGNED_BYTE , "r8ui")
defFormat(GL_R3_G3_B2 , 1, 3, GL_RGB , GL_FLOAT , "**UNKNOWN**")
defFormat(GL_RGBA2 , 1, 4, GL_RGB , GL_UNSIGNED_BYTE , "**UNKNOWN**")
// , bpp, chn, pixel_format , pixel_data_type, "**UNKNOWN**");
defFormat(GL_DEPTH_COMPONENT16 , 2, 1, GL_DEPTH_COMPONENT, GL_FLOAT , "**UNKNOWN**")
defFormat(GL_R16 , 2, 1, GL_RED , GL_UNSIGNED_SHORT, "r16")
defFormat(GL_R16_SNORM , 2, 1, GL_RED , GL_SHORT , "r16_snorm")
defFormat(GL_R16F , 2, 1, GL_RED , GL_FLOAT , "r16f")
defFormat(GL_R16I , 2, 1, GL_RED_INTEGER , GL_SHORT , "r16i")
defFormat(GL_R16UI , 2, 1, GL_RED_INTEGER , GL_UNSIGNED_SHORT, "r16ui")
defFormat(GL_DEPTH_STENCIL , 2, 1, GL_RG , GL_FLOAT , "**UNKNOWN**")
defFormat(GL_RG8 , 2, 2, GL_RG , GL_UNSIGNED_BYTE , "rg8")
defFormat(GL_RG8_SNORM , 2, 2, GL_RG , GL_BYTE , "rg8_snorm")
defFormat(GL_RG8I , 2, 2, GL_RG_INTEGER , GL_BYTE , "rg8i")
defFormat(GL_RG8UI , 2, 2, GL_RG_INTEGER , GL_UNSIGNED_BYTE , "rg8ui")
defFormat(GL_RGB4 , 2, 3, GL_RGB , GL_UNSIGNED_BYTE , "**UNKNOWN**")
defFormat(GL_RGB5 , 2, 3, GL_RGB , GL_FLOAT , "**UNKNOWN**")
defFormat(GL_RGBA4 , 2, 4, GL_RGBA , GL_UNSIGNED_BYTE , "**UNKNOWN**")
defFormat(GL_RGB5_A1 , 2, 4, GL_RGBA , GL_FLOAT , "**UNKNOWN**")
// , bpp, chn, pixel_format , pixel_data_type, "**UNKNOWN**");
defFormat(GL_DEPTH_COMPONENT24 , 3, 1, GL_DEPTH_COMPONENT, GL_FLOAT , "**UNKNOWN**")
defFormat(GL_RGB8 , 3, 3, GL_RGB , GL_UNSIGNED_BYTE , "**UNKNOWN**")
defFormat(GL_RGB8_SNORM , 3, 3, GL_RGB , GL_BYTE , "**UNKNOWN**")
defFormat(GL_SRGB8 , 3, 3, GL_RGB , GL_UNSIGNED_BYTE , "**UNKNOWN**")
defFormat(GL_RGB8I , 3, 3, GL_RGB_INTEGER , GL_BYTE , "**UNKNOWN**")
defFormat(GL_RGB8UI , 3, 3, GL_RGB_INTEGER , GL_UNSIGNED_BYTE , "**UNKNOWN**")
// , bpp, chn, pixel_format , pixel_data_type, "**UNKNOWN**");
defFormat(GL_DEPTH_COMPONENT32 , 4, 1, GL_DEPTH_COMPONENT, GL_FLOAT , "**UNKNOWN**")
defFormat(GL_DEPTH_COMPONENT32F , 4, 1, GL_DEPTH_COMPONENT, GL_FLOAT , "**UNKNOWN**")
defFormat(GL_R32F , 4, 1, GL_RED , GL_FLOAT , "r32f")
defFormat(GL_R32I , 4, 1, GL_RED_INTEGER , GL_INT , "r32i")
defFormat(GL_R32UI , 4, 1, GL_RED_INTEGER , GL_UNSIGNED_INT , "r32ui")
defFormat(GL_RG16 , 4, 2, GL_RG , GL_UNSIGNED_SHORT, "rg16")
defFormat(GL_RG16_SNORM , 4, 2, GL_RG , GL_SHORT , "rg16_snorm")
defFormat(GL_RG16F , 4, 2, GL_RG , GL_FLOAT , "rg16f")
defFormat(GL_RG16I , 4, 2, GL_RG_INTEGER , GL_SHORT , "rg16i")
defFormat(GL_RG16UI , 4, 2, GL_RG_INTEGER , GL_UNSIGNED_SHORT, "rg16ui")
defFormat(GL_RGB10 , 4, 3, GL_RGB , GL_FLOAT , "**UNKNOWN**")
defFormat(GL_R11F_G11F_B10F , 4, 3, GL_RGB , GL_FLOAT , "r11f_g11f_b10f")
defFormat(GL_RGB9_E5 , 4, 3, GL_RGB , GL_FLOAT , "**UNKNOWN**")
defFormat(GL_RGBA8 , 4, 4, GL_RGBA , GL_UNSIGNED_BYTE , "rgba8")
defFormat(GL_RGBA8_SNORM , 4, 4, GL_RGBA , GL_BYTE , "rgba8_snorm")
defFormat(GL_RGB10_A2 , 4, 4, GL_RGBA , GL_FLOAT , "rgb10_a2")
defFormat(GL_RGB10_A2UI , 4, 4, GL_RGBA_INTEGER , GL_FLOAT , "rgb10_a2ui")
defFormat(GL_SRGB8_ALPHA8 , 4, 4, GL_RGBA , GL_UNSIGNED_BYTE , "**UNKNOWN**")
defFormat(GL_RGBA8I , 4, 4, GL_RGBA_INTEGER , GL_BYTE , "rgba8i")
defFormat(GL_RGBA8UI , 4, 4, GL_RGBA_INTEGER , GL_UNSIGNED_BYTE , "rgba8ui")
// , bpp, chn, pixel_format , pixel_data_type, "**UNKNOWN**");
defFormat(GL_RGB12 , 5, 3, GL_RGB , GL_FLOAT , "**UNKNOWN**")
// , bpp, chn, pixel_format , pixel_data_type, "**UNKNOWN**");
defFormat(GL_RGB16 , 6, 3, GL_RGB , GL_UNSIGNED_SHORT, "**UNKNOWN**")
defFormat(GL_RGB16_SNORM , 6, 3, GL_RGB , GL_SHORT , "**UNKNOWN**")
defFormat(GL_RGB16F , 6, 3, GL_RGB , GL_FLOAT , "**UNKNOWN**")
defFormat(GL_RGB16I , 6, 3, GL_RGB_INTEGER , GL_SHORT , "**UNKNOWN**")
defFormat(GL_RGB16UI , 6, 3, GL_RGB_INTEGER , GL_UNSIGNED_SHORT, "**UNKNOWN**")
defFormat(GL_RGBA12 , 6, 4, GL_RGBA , GL_FLOAT , "**UNKNOWN**")
// , bpp, chn, pixel_format , pixel_data_type, "**UNKNOWN**");
defFormat(GL_RG32F , 8, 2, GL_RG , GL_FLOAT , "rg32f")
defFormat(GL_RG32I , 8, 2, GL_RG_INTEGER , GL_INT , "rg32i")
defFormat(GL_RG32UI , 8, 2, GL_RG_INTEGER , GL_UNSIGNED_INT , "rg32ui")
defFormat(GL_RGBA16 , 8, 4, GL_RGBA , GL_FLOAT , "rgba16")
defFormat(GL_RGBA16_SNORM , 8, 4, GL_RGBA , GL_SHORT , "rgba16_snorm")
defFormat(GL_RGBA16F , 8, 4, GL_RGBA , GL_FLOAT , "rgba16f")
defFormat(GL_RGBA16I , 8, 4, GL_RGBA_INTEGER , GL_SHORT , "rgba16i")
defFormat(GL_RGBA16UI , 8, 4, GL_RGBA_INTEGER , GL_UNSIGNED_SHORT, "rgba16ui")
// , bpp, chn, pixel_format , pixel_data_type, "**UNKNOWN**");
defFormat(GL_RGB32F , 12, 3, GL_RGB , GL_FLOAT , "**UNKNOWN**")
defFormat(GL_RGB32I , 12, 3, GL_RGB_INTEGER , GL_INT , "**UNKNOWN**")
defFormat(GL_RGB32UI , 12, 3, GL_RGB_INTEGER , GL_UNSIGNED_INT , "**UNKNOWN**")
// , bpp, chn, pixel_format , pixel_data_type, "**UNKNOWN**");
defFormat(GL_RGBA32F , 16, 4, GL_RGBA , GL_FLOAT , "rgba32f")
defFormat(GL_RGBA32I , 16, 4, GL_RGBA_INTEGER , GL_INT , "rgba32i")
defFormat(GL_RGBA32UI , 16, 4, GL_RGBA_INTEGER , GL_UNSIGNED_INT , "rgba32ui")
// default case:
GLTextureFormatTraits(internalFormat);
}
#undef defFormat
}; // namspace cgt
\ No newline at end of file
......@@ -107,6 +107,11 @@ bool GpuCapabilities::areShadersSupported() {
return shaderSupport_;
}
bool GpuCapabilities::areComputeShadersSupported()
{
return computeShaderSupport_;
}
bool GpuCapabilities::areShadersSupportedARB() {
return shaderSupportARB_;
}
......@@ -139,6 +144,11 @@ int GpuCapabilities::getNumTextureUnits() {
return numTextureUnits_;
}
int GpuCapabilities::getNumImageUnits()
{
return numImageUnits_;
}
bool GpuCapabilities::isNpotSupported() {
return npotTextures_;
}
......@@ -291,6 +301,7 @@ void GpuCapabilities::detectCapabilities() {
shaderSupport_ = (glVersion_ >= GlVersion::CGT_GL_VERSION_2_0);
shaderSupportARB_ = (isExtensionSupported("GL_ARB_vertex_program") &&
isExtensionSupported("GL_ARB_fragment_program"));
computeShaderSupport_ = (glVersion_ >= GlVersion::CGT_GL_VERSION_4_3);
if (!shaderVersion_.parseVersionString(glslVersionString_)) {
LERROR("Malformed GLSL version string: " << glslVersionString_);
......@@ -336,6 +347,8 @@ void GpuCapabilities::detectCapabilities() {
if (numTextureUnits_ < 0)
glGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint *) &numTextureUnits_);
glGetIntegerv(GL_MAX_IMAGE_UNITS, (GLint*)&numImageUnits_);
npotTextures_ = (isExtensionSupported("GL_ARB_texture_non_power_of_two"));
#if defined(__APPLE__) || defined(__linux__)
// No NPOT support on older ATI Macs and Linux.
......
......@@ -258,13 +258,19 @@ public:
std::string getShadingLanguageVersionString();
/**
* Returns wether shaders are supported, which
* Returns whether shaders are supported, which
* is true for OpenGL version 2.0 or later.
*/
bool areShadersSupported();
/**
* Returns wether the ARB shader extensions
* Returns whether shaders are supported, which
* is true for OpenGL version 4.3 or later.
*/
bool areComputeShadersSupported();
/**
* Returns whether the ARB shader extensions
* are supported (GL_ARB_vertex_program and
* GL_ARB_fragment_program).
*
......@@ -326,6 +332,12 @@ public:
*/
int getNumTextureUnits();
/**
* Returns the number of image units
* provided by the GPU.
*/
int getNumImageUnits();
/**
* Returns wether non-power-of-two textures
* are supported (extension GL_ARB_texture_non_power_of_two).
......@@ -429,6 +441,7 @@ private:
bool shaderSupport_;
bool shaderSupportARB_;
bool computeShaderSupport_;
GlVersion shaderVersion_;
ShaderModel shaderModel_;
......@@ -436,6 +449,7 @@ private:
bool texturing3D_;
int max3DTexSize_;
int numTextureUnits_;
int numImageUnits_;
bool npotTextures_;
bool textureRectangles_;
bool anisotropicFiltering_;
......
#include "imageunit.h"
#include "imageunit.h"
/**********************************************************************
* *
* cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2015 *
* Chair for Computer Aided Medical Procedures *
* Technische Universitaet Muenchen, Germany. *
* <http://campar.in.tum.de/> *
* *
* forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011 *
* Visualization and Computer Graphics Group, Department of *
* Computer Science, University of Muenster, Germany. *
* <http://viscg.uni-muenster.de> *
* *
* This file is part of the cgt library. This library is free *
* software; you can redistribute it and/or modify it under the terms *
* of the GNU Lesser General Public License version 2.1 as published *
* by the Free Software Foundation. *
* *
* 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 for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License in the file "LICENSE.txt" along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
**********************************************************************/
#include "cgt/imageunit.h"
#include "cgt/gpucapabilities.h"
#include "cgt/assert.h"
namespace cgt {
bool ImageUnit::initialized_ = false;
unsigned short ImageUnit::totalActive_ = 0;
unsigned short ImageUnit::maxTexUnits_ = 0;
unsigned short ImageUnit::numKeptUnits_ = 0;
std::vector<bool> ImageUnit::busyUnits_ = std::vector<bool>();
tbb::spin_mutex ImageUnit::mutex_ = tbb::spin_mutex();
ImageUnit::ImageUnit(bool keep)
: number_(0)
, assigned_(false)
{
if (!initialized_)
init();
}
void ImageUnit::init() {
tbb::spin_mutex::scoped_lock lock(mutex_);
if (initialized_)
return;
maxTexUnits_ = GpuCaps.getNumImageUnits();
busyUnits_ = std::vector<bool>(maxTexUnits_, false);
numKeptUnits_ = 0;
initialized_ = true;
}
ImageUnit::~ImageUnit() {
if(assigned_)
releaseUnit();
}
ImageUnit::ImageUnit(ImageUnit && other)
{
*this = std::move(other);
}
ImageUnit & ImageUnit::operator=(ImageUnit && rhs)
{
if (this == &rhs)
return *this;
if (assigned_)
releaseUnit();
assigned_ = rhs.assigned_;
number_ = rhs.number_;
rhs.assigned_ = false;
rhs.number_ = 0;
return *this;
}
GLint ImageUnit::getUnitNumber() const {
if (!assigned_)
assignUnit();
return number_;
}
void ImageUnit::cleanup() {
tbb::spin_mutex::scoped_lock lock(mutex_);
for (size_t i = 0; i < maxTexUnits_; i++) {
if (busyUnits_.at(i))
busyUnits_.at(i) = false;
}
totalActive_ = 0;
numKeptUnits_ = 0;
}
bool ImageUnit::unused() {
return (totalActive_ == 0);
}
unsigned short ImageUnit::numLocalActive() {
return (totalActive_ - numKeptUnits_);
}
void ImageUnit::assignUnit() const {
tbb::spin_mutex::scoped_lock lock(mutex_);
cgtAssert(totalActive_ <= maxTexUnits_, "No more texture units available");
assigned_ = true;
for (size_t i = 0; i < maxTexUnits_; i++) {
if (!busyUnits_.at(i)) {
number_ = (GLint)i;
busyUnits_.at(i) = true;
totalActive_++;
break;
}
}
}
void ImageUnit::releaseUnit()
{
tbb::spin_mutex::scoped_lock lock(mutex_);
busyUnits_.at(number_) = false;
totalActive_--;
}
} // namespace
/**********************************************************************
* *
* cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2015 *
* Chair for Computer Aided Medical Procedures *
* Technische Universitaet Muenchen, Germany. *
* <http://campar.in.tum.de/> *
* *
* forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011 *
* Visualization and Computer Graphics Group, Department of *
* Computer Science, University of Muenster, Germany. *
* <http://viscg.uni-muenster.de> *
* *
* This file is part of the cgt library. This library is free *
* software; you can redistribute it and/or modify it under the terms *
* of the GNU Lesser General Public License version 2.1 as published *
* by the Free Software Foundation. *
* *
* 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 for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License in the file "LICENSE.txt" along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
**********************************************************************/
#ifndef CGT_IMAGEUNIT_H
#define CGT_IMAGEUNIT_H
#include <string>
#include <tbb/spin_mutex.h>
#include "cgt/cgt_gl.h"
#include "cgt/shadermanager.h"
namespace cgt {
/**
* OpenGL Image Unit
*/
class CGT_API ImageUnit {
public:
ImageUnit(bool keep = false);
~ImageUnit();
void releaseUnit();
// copy construction and assignment is not allowed
ImageUnit(const ImageUnit& other) = delete;
ImageUnit& operator=(const ImageUnit& other) = delete;
// move construction and assignment is possible
ImageUnit(ImageUnit&& other);
ImageUnit& operator=(ImageUnit&& rhs);
GLint getUnitNumber() const;
static void cleanup();
static unsigned short numLocalActive();
/**
* Returns true if no texture units are currently assigned.
*/
static bool unused();
protected:
void assignUnit() const;
static void init();
mutable GLint number_;
mutable bool assigned_;
static bool initialized_;
static unsigned short totalActive_;
static unsigned short maxTexUnits_;
static unsigned short numKeptUnits_;
static std::vector<bool> busyUnits_;
static tbb::spin_mutex mutex_;
};
} // namespace cgt
#endif // CGT_IMAGEUNIT_H
......@@ -32,6 +32,7 @@
#include <iostream>
#include <fstream>
#include <memory>
using std::string;
......@@ -602,9 +603,9 @@ void Shader::loadSeparate(const string& vert_filename, const string& geom_filena
const string&