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

gltextureformattraits.h 4.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
/**********************************************************************
*                                                                    *
* 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 GLTextureFormatTraits {

public:
    /// Constructor for unknown format
    GLTextureFormatTraits(GLint internalFormat__)
        : known_{ false }
        , internalFormatName_{ "Unknown" }
        , bpp_{ 0 }
        , channels_{ 0 }
        , internalFormat_{ internalFormat__ }
        , pixelFormat_{ -1 }
        , pixelDataType_{ -1 }
        , glslFormatQualifier_{ "Unknown" }
    {};

    /// Constructor for known formats
    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 GLTextureFormatTraits get(GLint internalFormat);

    /**
     * Whether the specified GLint is a valid internal format
     */
    bool known() const { return known_; };

    /**
     * The name of the macro as a string
     */
    std::string internalFormatName() const { return internalFormatName_; } ;

    /**
     *	Number of bytes per pixel
     */
     int bpp() const { return bpp_; };

    /**
     *	Number of channels (1-4)
     */
     int channels() const { return channels_; };

    /**
     *	GLint of the internal format
     */
    GLint internalFormat() const { return internalFormat_; };

    /**
     *	Matching pixel format (GL_RED, GL_RG, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_RED_INTEGER, GL_RG_INTEGER, GL_RGB_INTEGER, GL_BGR_INTEGER, GL_RGBA_INTEGER, GL_BGRA_INTEGER, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL)
     */
    GLint pixelFormat() const { return pixelFormat_; };

    /**
     *	Matching pixel data type (GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, and GL_UNSIGNED_INT_2_10_10_10_REV)
     */
    GLint pixelDataType() const { return pixelDataType_; };

    /**
     *	Matching write format qualifier for use in glsl with image read/write operations. (rgba32f, r16, r8u, ...)
     */
    std::string glslFormatQualifier() const { return glslFormatQualifier_; };

private:
    bool known_;
    const std::string internalFormatName_;
    const int bpp_;
    const int channels_;
    const GLint internalFormat_;
    const GLint pixelFormat_;
    const GLint pixelDataType_;
    const std::string glslFormatQualifier_;

};


}; // namspace cgt