Exemplo n.º 1
0
void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType)
{
    size_t nameSize = 0;
    switch (varType) {
    case SH_ACTIVE_ATTRIBUTES:
        ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &nameSize);
        break;
    case SH_ACTIVE_UNIFORMS:
        ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &nameSize);
        break;
    default:
        assert(0);
    }
    if (nameSize <= 1) return;
    char* name = new char[nameSize];

    size_t activeVars = 0;
    int size = 0;
    sh::GLenum type = GL_NONE;
    ShPrecisionType precision = SH_PRECISION_UNDEFINED;
    int staticUse = 0;
    const char* typeName = NULL;
    ShGetInfo(compiler, varType, &activeVars);
    for (size_t i = 0; i < activeVars; ++i) {
        switch (varType) {
        case SH_ACTIVE_ATTRIBUTES:
            ShGetVariableInfo(compiler, SH_ACTIVE_ATTRIBUTES, static_cast<int>(i), NULL, &size, &type, &precision, &staticUse, name, NULL);
            break;
        case SH_ACTIVE_UNIFORMS:
            ShGetVariableInfo(compiler, SH_ACTIVE_UNIFORMS, static_cast<int>(i), NULL, &size, &type, &precision, &staticUse, name, NULL);
            break;
        default:
            assert(0);
        }
        switch (type) {
        case GL_FLOAT:
            typeName = "GL_FLOAT";
            break;
        case GL_FLOAT_VEC2:
            typeName = "GL_FLOAT_VEC2";
            break;
        case GL_FLOAT_VEC3:
            typeName = "GL_FLOAT_VEC3";
            break;
        case GL_FLOAT_VEC4:
            typeName = "GL_FLOAT_VEC4";
            break;
        case GL_INT:
            typeName = "GL_INT";
            break;
        case GL_INT_VEC2:
            typeName = "GL_INT_VEC2";
            break;
        case GL_INT_VEC3:
            typeName = "GL_INT_VEC3";
            break;
        case GL_INT_VEC4:
            typeName = "GL_INT_VEC4";
            break;
        case GL_UNSIGNED_INT:
            typeName = "GL_UNSIGNED_INT";
            break;
        case GL_UNSIGNED_INT_VEC2:
            typeName = "GL_UNSIGNED_INT_VEC2";
            break;
        case GL_UNSIGNED_INT_VEC3:
            typeName = "GL_UNSIGNED_INT_VEC3";
            break;
        case GL_UNSIGNED_INT_VEC4:
            typeName = "GL_UNSIGNED_INT_VEC4";
            break;
        case GL_BOOL:
            typeName = "GL_BOOL";
            break;
        case GL_BOOL_VEC2:
            typeName = "GL_BOOL_VEC2";
            break;
        case GL_BOOL_VEC3:
            typeName = "GL_BOOL_VEC3";
            break;
        case GL_BOOL_VEC4:
            typeName = "GL_BOOL_VEC4";
            break;
        case GL_FLOAT_MAT2:
            typeName = "GL_FLOAT_MAT2";
            break;
        case GL_FLOAT_MAT3:
            typeName = "GL_FLOAT_MAT3";
            break;
        case GL_FLOAT_MAT4:
            typeName = "GL_FLOAT_MAT4";
            break;
        case GL_FLOAT_MAT2x3:
            typeName = "GL_FLOAT_MAT2x3";
            break;
        case GL_FLOAT_MAT3x2:
            typeName = "GL_FLOAT_MAT3x2";
            break;
        case GL_FLOAT_MAT4x2:
            typeName = "GL_FLOAT_MAT4x2";
            break;
        case GL_FLOAT_MAT2x4:
            typeName = "GL_FLOAT_MAT2x4";
            break;
        case GL_FLOAT_MAT3x4:
            typeName = "GL_FLOAT_MAT3x4";
            break;
        case GL_FLOAT_MAT4x3:
            typeName = "GL_FLOAT_MAT4x3";
            break;
        case GL_SAMPLER_2D:
            typeName = "GL_SAMPLER_2D";
            break;
        case GL_SAMPLER_CUBE:
            typeName = "GL_SAMPLER_CUBE";
            break;
        case GL_SAMPLER_EXTERNAL_OES:
            typeName = "GL_SAMPLER_EXTERNAL_OES";
            break;
        default:
            assert(0);
        }
        printf("%lu: name:%s type:%s size:%d\n", i, name, typeName, size);
    }
    delete [] name;
}
Exemplo n.º 2
0
void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType, bool mapLongVariableNames)
{
    size_t nameSize = 0;
    switch (varType) {
        case SH_ACTIVE_ATTRIBUTES:
            ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &nameSize);
            break;
        case SH_ACTIVE_UNIFORMS:
            ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &nameSize);
            break;
        default: assert(0);
    }
    if (nameSize <= 1) return;
    char* name = new char[nameSize];

    char* mappedName = NULL;
    if (mapLongVariableNames) {
        size_t mappedNameSize = 0;
        ShGetInfo(compiler, SH_MAPPED_NAME_MAX_LENGTH, &mappedNameSize);
        mappedName = new char[mappedNameSize];
    }

    size_t activeVars = 0;
    int size = 0;
    ShDataType type = SH_NONE;
    ShPrecisionType precision = SH_PRECISION_UNDEFINED;
    int staticUse = 0;
    const char* typeName = NULL;
    ShGetInfo(compiler, varType, &activeVars);
    for (size_t i = 0; i < activeVars; ++i) {
        switch (varType) {
            case SH_ACTIVE_ATTRIBUTES:
                ShGetVariableInfo(compiler, SH_ACTIVE_ATTRIBUTES, static_cast<int>(i), NULL, &size, &type, &precision, &staticUse, name, mappedName);
                break;
            case SH_ACTIVE_UNIFORMS:
                ShGetVariableInfo(compiler, SH_ACTIVE_UNIFORMS, static_cast<int>(i), NULL, &size, &type, &precision, &staticUse, name, mappedName);
                break;
            default: assert(0);
        }
        switch (type) {
            case SH_FLOAT: typeName = "GL_FLOAT"; break;
            case SH_FLOAT_VEC2: typeName = "GL_FLOAT_VEC2"; break;
            case SH_FLOAT_VEC3: typeName = "GL_FLOAT_VEC3"; break;
            case SH_FLOAT_VEC4: typeName = "GL_FLOAT_VEC4"; break;
            case SH_INT: typeName = "GL_INT"; break;
            case SH_INT_VEC2: typeName = "GL_INT_VEC2"; break;
            case SH_INT_VEC3: typeName = "GL_INT_VEC3"; break;
            case SH_INT_VEC4: typeName = "GL_INT_VEC4"; break;
            case SH_BOOL: typeName = "GL_BOOL"; break;
            case SH_BOOL_VEC2: typeName = "GL_BOOL_VEC2"; break;
            case SH_BOOL_VEC3: typeName = "GL_BOOL_VEC3"; break;
            case SH_BOOL_VEC4: typeName = "GL_BOOL_VEC4"; break;
            case SH_FLOAT_MAT2: typeName = "GL_FLOAT_MAT2"; break;
            case SH_FLOAT_MAT3: typeName = "GL_FLOAT_MAT3"; break;
            case SH_FLOAT_MAT4: typeName = "GL_FLOAT_MAT4"; break;
            case SH_SAMPLER_2D: typeName = "GL_SAMPLER_2D"; break;
            case SH_SAMPLER_CUBE: typeName = "GL_SAMPLER_CUBE"; break;
            case SH_SAMPLER_EXTERNAL_OES: typeName = "GL_SAMPLER_EXTERNAL_OES"; break;
            default: assert(0);
        }
        printf("%u: name:%s type:%s size:%d", i, name, typeName, size);
        if (mapLongVariableNames)
            printf(" mapped name:%s", mappedName);
        printf("\n");
    }
    delete [] name;
    if (mappedName)
        delete [] mappedName;
}
Exemplo n.º 3
0
static bool getSymbolInfo(ShHandle compiler, ShShaderInfo symbolType, Vector<ANGLEShaderSymbol>& symbols)
{
    ShShaderInfo symbolMaxNameLengthType;

    switch (symbolType) {
    case SH_ACTIVE_ATTRIBUTES:
        symbolMaxNameLengthType = SH_ACTIVE_ATTRIBUTE_MAX_LENGTH;
        break;
    case SH_ACTIVE_UNIFORMS:
        symbolMaxNameLengthType = SH_ACTIVE_UNIFORM_MAX_LENGTH;
        break;
    default:
        ASSERT_NOT_REACHED();
        return false;
    }

    ANGLEGetInfoType numSymbols = getValidationResultValue(compiler, symbolType);

    ANGLEGetInfoType maxNameLength = getValidationResultValue(compiler, symbolMaxNameLengthType);
    if (maxNameLength <= 1)
        return false;

    ANGLEGetInfoType maxMappedNameLength = getValidationResultValue(compiler, SH_MAPPED_NAME_MAX_LENGTH);
    if (maxMappedNameLength <= 1)
        return false;

    // The maximum allowed symbol name length is 256 characters.
    Vector<char, 256> nameBuffer(maxNameLength);
    Vector<char, 256> mappedNameBuffer(maxMappedNameLength);

    for (ANGLEGetInfoType i = 0; i < numSymbols; ++i) {
        ANGLEShaderSymbol symbol;
        ANGLEGetInfoType nameLength = 0;
        switch (symbolType) {
        case SH_ACTIVE_ATTRIBUTES:
            symbol.symbolType = SHADER_SYMBOL_TYPE_ATTRIBUTE;
#if ANGLE_SH_VERSION >= 112
            ShGetVariableInfo(compiler, symbolType, i, &nameLength, &symbol.size, &symbol.dataType, &symbol.precision, &symbol.staticUse, nameBuffer.data(), mappedNameBuffer.data());
#else
            ShGetVariableInfo(compiler, symbolType, i, &nameLength, &symbol.size, &symbol.dataType, &symbol.precision, nameBuffer.data(), mappedNameBuffer.data());
#endif
            break;
        case SH_ACTIVE_UNIFORMS:
            symbol.symbolType = SHADER_SYMBOL_TYPE_UNIFORM;
#if ANGLE_SH_VERSION >= 112
            ShGetVariableInfo(compiler, symbolType, i, &nameLength, &symbol.size, &symbol.dataType, &symbol.precision, &symbol.staticUse, nameBuffer.data(), mappedNameBuffer.data());
#else
            ShGetVariableInfo(compiler, symbolType, i, &nameLength, &symbol.size, &symbol.dataType, &symbol.precision, nameBuffer.data(), mappedNameBuffer.data());
#endif
            break;
        default:
            ASSERT_NOT_REACHED();
            return false;
        }
        if (!nameLength)
            return false;

        // The ShGetActive* calls above are guaranteed to produce null-terminated strings for
        // nameBuffer and mappedNameBuffer. Also, the character set for symbol names
        // is a subset of Latin-1 as specified by the OpenGL ES Shading Language, Section 3.1 and
        // WebGL, Section "Characters Outside the GLSL Source Character Set".

        String name = String(nameBuffer.data());
        String mappedName = String(mappedNameBuffer.data());

        // ANGLE returns array names in the format "array[0]".
        // The only way to know if a symbol is an array is to check if it ends with "[0]".
        // We can't check the size because regular symbols and arrays of length 1 both have a size of 1.
        symbol.isArray = name.endsWith("[0]") && mappedName.endsWith("[0]");
        if (symbol.isArray) {
            // Add a symbol for the array name without the "[0]" suffix.
            name.truncate(name.length() - 3);
            mappedName.truncate(mappedName.length() - 3);
        }

        symbol.name = name;
        symbol.mappedName = mappedName;
        symbols.append(symbol);

        if (symbol.isArray) {
            // Add symbols for each array element.
            symbol.isArray = false;
            for (int i = 0; i < symbol.size; i++) {
                String arrayBrackets = "[" + String::number(i) + "]";
                symbol.name = name + arrayBrackets;
                symbol.mappedName = mappedName + arrayBrackets;
                symbols.append(symbol);
            }
        }
    }
    return true;
}