Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • c267948
  • /
  • glvu
  • /
  • GLProgram.h
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:a621630ca57c73dfe7bec7c318a6eef936fe2cbd
directory badge
swh:1:dir:cf90c7a577b701392d16a2c3885de4cbc59b28a5

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
GLProgram.h
#ifndef GLPROGRAM_H
#define GLPROGRAM_H

#include <string>
#include <map>

#define OPENGL_VERSION 3

class GLProgram
{
public:
    enum ShaderType { VERTEX_SHADER = 0, GEOMETRY_SHADER, FRAGMENT_SHADER, TESS_CONTROL_SHADER, TESS_EVALUATION_SHADER, COMPUTE_SHADER, NUM_SHADER_TYPE };
    static const char *const ShaderTypeStrs[NUM_SHADER_TYPE];

private:
    unsigned int  pProgram;
    unsigned int  pShader[NUM_SHADER_TYPE];
    std::string logString;
    bool          rowmajor; // for setting matrix uniforms

    struct Uniform { unsigned int type; int location, size, stride; };

    struct BlockUniform { unsigned int type; int offset, size, arrayStride; };

	/// stores information for a block and its uniforms
    struct UniformBlock {
        /// size of the uniform block
        int size;
        /// buffer bound to the index point
        unsigned int buffer;
        /// binding index
        unsigned int bindingIndex;
        /// uniforms information
        std::map<std::string, BlockUniform > uniformOffsets;
    };

    std::map < std::string, Uniform > pUniforms;
    std::map < std::string, UniformBlock > pBlocks;

public:
    GLProgram();
    ~GLProgram();

    void reset();

    bool   compileShaderFromFile( const char * fileName, ShaderType type );
    bool   compileShaderFromString( const std::string & source, ShaderType type );
	int    compileAndLinkAllShadersFromString(const std::string &vtxShaderStr, const std::string &fragShaderStr, const std::string &geomShaderStr="");
	int    compileAndLinkAllShadersFromFile(const char * vertexShaderFile, const char * fragShaderFile, const char *geomShaderFile=NULL);

    std::string getShaderInfoLog(ShaderType type);
    std::string getProgramInfoLog();
    std::string getAllInfoLog();

    bool   link();
    bool   validate();
    void   bind();
    void   unbind();

	bool   isbinded();

    std::string log() const { return logString; }

    int    getHandle() { return pProgram; }

    bool   shaderCompiled(ShaderType);
    bool   linked();

    void   cacheUniforms();
    void   cacheBlocks();

    void   setUniformPVOID(const char *, void *);

    // only work on OpenGL4 hardware
#if OPENGL_VERSION >= 4
    void   setUniformPVOID_GL4(const char *, void *);
#endif

    void   setBlock(const char *, void *);
    void   setBlockUniform(const char*, const char*, void *);
    void   setBlockUniformArrayElement(const char *, const char *, int, void *);

    template<typename R, typename... Rs>
    typename std::enable_if<!std::is_pointer<R>::value&&std::is_scalar<R>::value,void>::type setUniform(const char *name, R v1, Rs... v) {
        static_assert(sizeof(R) == 4 || sizeof(R) == 8, "OpenGL only takes data of unsigned, int, float, double");
        R vals[] = { v1, v... };
        setUniformPVOID(name, (void*)vals);
    }

    template<typename R>
    typename std::enable_if<std::is_scalar<R>::value,void>::type setUniform(const char *name, R* vals) {
        static_assert(sizeof(R) == 4 || sizeof(R) == 8, "OpenGL only takes data of unsigned, int, float, double");
        setUniformPVOID(name, (void*)vals);
    }

    void   bindAttribLocation(unsigned int location, const char * name);
    void   bindFragDataLocation( unsigned int location, const char * name );

    int    getAttribLocation(const char * name);

    void   printActiveUniforms();
    void   printActiveAttribs();
};

#endif // GLPROGRAM_H

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API