ShaderUtilsGles.h#

Parent directory (OpenGLES)

Contains useful low level utils for shaders (loading, compiling) into low level Api object wrappers.

Includes#

  • BindingsGles.h (BindingsGles.h)

  • PVRCore/IAssetProvider.h

  • PVRCore/texture/TextureLoad.h

  • PVRUtils/OpenGLES/ConvertToGlesTypes.h

  • PVRUtils/PVRUtilsTypes.h

Included By#

Namespaces#

Functions#

Source Code#

#pragma once
#if !SC_ENABLED
#include "BindingsGles.h"
#include "PVRUtils/OpenGLES/ConvertToGlesTypes.h"
#include "PVRCore/IAssetProvider.h"
#include "PVRUtils/PVRUtilsTypes.h"
#include "PVRCore/texture/TextureLoad.h"

namespace pvr {
namespace utils {

GLuint loadShader(const Stream& shaderSource, ShaderType shaderType, const char* const* defines, uint32_t numDefines);

GLuint loadShader(const std::string& shaderSource, ShaderType shaderType, const char* const* defines, uint32_t numDefines);

GLuint createShaderProgram(
    const GLuint pShaders[], uint32_t shadersCount, const char** const attribNames, const uint16_t* attribIndices, uint32_t attribsCount, std::string* infolog = NULL);

inline GLuint createComputeShaderProgram(IAssetProvider& app, const char* compShaderFilename, const char* const* defines = 0, uint32_t numDefines = 0)
{
    GLuint shader = 0;
    GLuint program = 0;

    auto compShaderSrc = app.getAssetStream(compShaderFilename);

    if (!compShaderSrc)
    {
        Log("Failed to open compute shader %s", compShaderFilename);
        return false;
    }

    shader = pvr::utils::loadShader(*compShaderSrc, pvr::ShaderType::ComputeShader, defines, numDefines);

    program = pvr::utils::createShaderProgram(&shader, 1, 0, 0, 0);
    gl::DeleteShader(shader);

    return program;
}

inline GLuint createShaderProgram(const IAssetProvider& app, const char* vertShaderFilename, const char* tessCtrlShaderFilename, const char* tessEvalShaderFilename,
    const char* geometryShaderFilename, const char* fragShaderFilename, const char** attribNames, const uint16_t* attribIndices, uint32_t numAttribs,
    const char* const* defines = 0, uint32_t numDefines = 0)
{
    GLuint shaders[6] = { 0 };
    GLuint program = 0;
    uint32_t count = 0;
    if (vertShaderFilename)
    {
        auto vertShaderSrc = app.getAssetStream(vertShaderFilename);
        shaders[count++] = pvr::utils::loadShader(*vertShaderSrc, pvr::ShaderType::VertexShader, defines, numDefines);
    }

    if (tessCtrlShaderFilename)
    {
        auto texCtrShaderSrc = app.getAssetStream(tessCtrlShaderFilename);
        shaders[count++] = pvr::utils::loadShader(*texCtrShaderSrc, pvr::ShaderType::TessControlShader, defines, numDefines);
    }

    if (tessEvalShaderFilename)
    {
        auto texEvalShaderSrc = app.getAssetStream(tessEvalShaderFilename);
        shaders[count++] = pvr::utils::loadShader(*texEvalShaderSrc, pvr::ShaderType::TessEvaluationShader, defines, numDefines);
    }

    if (geometryShaderFilename)
    {
        auto geometryShaderSrc = app.getAssetStream(geometryShaderFilename);
        shaders[count++] = pvr::utils::loadShader(*geometryShaderSrc, pvr::ShaderType::GeometryShader, defines, numDefines);
    }

    if (fragShaderFilename)
    {
        auto fragShaderSrc = app.getAssetStream(fragShaderFilename);
        shaders[count++] = pvr::utils::loadShader(*fragShaderSrc, pvr::ShaderType::FragmentShader, defines, numDefines);
    }

    program = pvr::utils::createShaderProgram(shaders, count, attribNames, attribIndices, numAttribs);
    for (uint32_t i = 0; i < count; ++i) { gl::DeleteShader(shaders[i]); }

    return program;
}

inline GLuint createShaderProgram(const IAssetProvider& app, const char* vertShaderFilename, const char* fragShaderFilename, const char** attribNames, const uint16_t* attribIndices,
    uint32_t numAttribs, const char* const* defines = 0, uint32_t numDefines = 0)
{
    return createShaderProgram(app, vertShaderFilename, nullptr, nullptr, nullptr, fragShaderFilename, attribNames, attribIndices, numAttribs, defines, numDefines);
}
} // namespace utils
} // namespace pvr
#endif