Move TObjectReflection into public interface to clean up reflection
* Forwarding functions are left to preserve source compatibility with code using the old queries.
This commit is contained in:
		
							parent
							
								
									9983f99e87
								
							
						
					
					
						commit
						1dc5dcf0a5
					
				@ -1983,27 +1983,15 @@ bool TProgram::buildReflection()
 | 
				
			|||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int TProgram::getNumLiveUniformVariables() const             { return reflection->getNumUniforms(); }
 | 
					 | 
				
			||||||
int TProgram::getNumLiveUniformBlocks() const                { return reflection->getNumUniformBlocks(); }
 | 
					 | 
				
			||||||
const char* TProgram::getUniformName(int index) const        { return reflection->getUniform(index).name.c_str(); }
 | 
					 | 
				
			||||||
const char* TProgram::getUniformBlockName(int index) const   { return reflection->getUniformBlock(index).name.c_str(); }
 | 
					 | 
				
			||||||
int TProgram::getUniformBlockSize(int index) const           { return reflection->getUniformBlock(index).size; }
 | 
					 | 
				
			||||||
int TProgram::getUniformIndex(const char* name) const        { return reflection->getIndex(name); }
 | 
					 | 
				
			||||||
int TProgram::getUniformBinding(int index) const             { return reflection->getUniform(index).getBinding(); }
 | 
					 | 
				
			||||||
EShLanguageMask TProgram::getUniformStages(int index) const  { return reflection->getUniform(index).stages; }
 | 
					 | 
				
			||||||
int TProgram::getUniformBlockBinding(int index) const        { return reflection->getUniformBlock(index).getBinding(); }
 | 
					 | 
				
			||||||
int TProgram::getUniformBlockIndex(int index) const          { return reflection->getUniform(index).index; }
 | 
					 | 
				
			||||||
int TProgram::getUniformBlockCounterIndex(int index) const   { return reflection->getUniformBlock(index).counterIndex; }
 | 
					 | 
				
			||||||
int TProgram::getUniformType(int index) const                { return reflection->getUniform(index).glDefineType; }
 | 
					 | 
				
			||||||
int TProgram::getUniformBufferOffset(int index) const        { return reflection->getUniform(index).offset; }
 | 
					 | 
				
			||||||
int TProgram::getUniformArraySize(int index) const           { return reflection->getUniform(index).size; }
 | 
					 | 
				
			||||||
int TProgram::getNumLiveAttributes() const                   { return reflection->getNumAttributes(); }
 | 
					 | 
				
			||||||
const char* TProgram::getAttributeName(int index) const      { return reflection->getAttribute(index).name.c_str(); }
 | 
					 | 
				
			||||||
int TProgram::getAttributeType(int index) const              { return reflection->getAttribute(index).glDefineType; }
 | 
					 | 
				
			||||||
const TType* TProgram::getAttributeTType(int index) const    { return reflection->getAttribute(index).getType(); }
 | 
					 | 
				
			||||||
const TType* TProgram::getUniformTType(int index) const      { return reflection->getUniform(index).getType(); }
 | 
					 | 
				
			||||||
const TType* TProgram::getUniformBlockTType(int index) const { return reflection->getUniformBlock(index).getType(); }
 | 
					 | 
				
			||||||
unsigned TProgram::getLocalSize(int dim) const                      { return reflection->getLocalSize(dim); }
 | 
					unsigned TProgram::getLocalSize(int dim) const                      { return reflection->getLocalSize(dim); }
 | 
				
			||||||
 | 
					int TProgram::getReflectionIndex(const char* name) const            { return reflection->getIndex(name); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int TProgram::getNumUniformVariables() const                        { return reflection->getNumUniforms(); }
 | 
				
			||||||
 | 
					const TObjectReflection& TProgram::getUniform(int index) const      { return reflection->getUniform(index); }
 | 
				
			||||||
 | 
					int TProgram::getNumUniformBlocks() const                           { return reflection->getNumUniformBlocks(); }
 | 
				
			||||||
 | 
					const TObjectReflection& TProgram::getUniformBlock(int index) const { return reflection->getUniformBlock(index); }
 | 
				
			||||||
 | 
					int TProgram::getNumAttributes() const                              { return reflection->getNumAttributes(); }
 | 
				
			||||||
 | 
					const TObjectReflection& TProgram::getAttribute(int index) const    { return reflection->getAttribute(index); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TProgram::dumpReflection()                      { reflection->dump(); }
 | 
					void TProgram::dumpReflection()                      { reflection->dump(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -832,6 +832,35 @@ void TReflectionTraverser::visitSymbol(TIntermSymbol* base)
 | 
				
			|||||||
        addAttribute(*base);
 | 
					        addAttribute(*base);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Implement TObjectReflection methods.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TObjectReflection::TObjectReflection(const std::string &pName, const TType &pType, int pOffset, int pGLDefineType,
 | 
				
			||||||
 | 
					                                     int pSize, int pIndex)
 | 
				
			||||||
 | 
					    : name(pName), offset(pOffset), glDefineType(pGLDefineType), size(pSize), index(pIndex), counterIndex(-1),
 | 
				
			||||||
 | 
					      stages(EShLanguageMask(0)), type(pType.clone())
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int TObjectReflection::getBinding() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (type == nullptr || !type->getQualifier().hasBinding())
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    return type->getQualifier().layoutBinding;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void TObjectReflection::dump() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    printf("%s: offset %d, type %x, size %d, index %d, binding %d, stages %d", name.c_str(), offset, glDefineType, size,
 | 
				
			||||||
 | 
					           index, getBinding(), stages);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (counterIndex != -1)
 | 
				
			||||||
 | 
					        printf(", counter %d", counterIndex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    printf("\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Implement TReflection methods.
 | 
					// Implement TReflection methods.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
				
			|||||||
@ -52,47 +52,6 @@ class TIntermediate;
 | 
				
			|||||||
class TIntermAggregate;
 | 
					class TIntermAggregate;
 | 
				
			||||||
class TReflectionTraverser;
 | 
					class TReflectionTraverser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Data needed for just a single object at the granularity exchanged by the reflection API
 | 
					 | 
				
			||||||
class TObjectReflection {
 | 
					 | 
				
			||||||
public:
 | 
					 | 
				
			||||||
    TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex) :
 | 
					 | 
				
			||||||
        name(pName), offset(pOffset),
 | 
					 | 
				
			||||||
        glDefineType(pGLDefineType), size(pSize), index(pIndex), counterIndex(-1), stages(EShLanguageMask(0)), type(pType.clone()) { }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const TType* getType() const { return type; }
 | 
					 | 
				
			||||||
    int getBinding() const
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        if (type == nullptr || !type->getQualifier().hasBinding())
 | 
					 | 
				
			||||||
            return -1;
 | 
					 | 
				
			||||||
        return type->getQualifier().layoutBinding;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    void dump() const
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        printf("%s: offset %d, type %x, size %d, index %d, binding %d, stages %d",
 | 
					 | 
				
			||||||
               name.c_str(), offset, glDefineType, size, index, getBinding(), stages );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (counterIndex != -1)
 | 
					 | 
				
			||||||
            printf(", counter %d", counterIndex);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        printf("\n");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    static TObjectReflection badReflection() { return TObjectReflection(); }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    std::string name;
 | 
					 | 
				
			||||||
    int offset;
 | 
					 | 
				
			||||||
    int glDefineType;
 | 
					 | 
				
			||||||
    int size;         // data size in bytes for a block, array size for a (non-block) object that's an array
 | 
					 | 
				
			||||||
    int index;
 | 
					 | 
				
			||||||
    int counterIndex;
 | 
					 | 
				
			||||||
    EShLanguageMask stages;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
protected:
 | 
					 | 
				
			||||||
    TObjectReflection() :
 | 
					 | 
				
			||||||
        offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), stages(EShLanguageMask(0)), type(nullptr) { }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const TType* type;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// The full reflection database
 | 
					// The full reflection database
 | 
				
			||||||
class TReflection {
 | 
					class TReflection {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
				
			|||||||
@ -599,6 +599,35 @@ private:
 | 
				
			|||||||
    TShader& operator=(TShader&);
 | 
					    TShader& operator=(TShader&);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// A reflection database and its interface, consistent with the OpenGL API reflection queries.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Data needed for just a single object at the granularity exchanged by the reflection API
 | 
				
			||||||
 | 
					class TObjectReflection {
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const TType* getType() const { return type; }
 | 
				
			||||||
 | 
					    int getBinding() const;
 | 
				
			||||||
 | 
					    void dump() const;
 | 
				
			||||||
 | 
					    static TObjectReflection badReflection() { return TObjectReflection(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::string name;
 | 
				
			||||||
 | 
					    int offset;
 | 
				
			||||||
 | 
					    int glDefineType;
 | 
				
			||||||
 | 
					    int size;         // data size in bytes for a block, array size for a (non-block) object that's an array
 | 
				
			||||||
 | 
					    int index;
 | 
				
			||||||
 | 
					    int counterIndex;
 | 
				
			||||||
 | 
					    EShLanguageMask stages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
 | 
					    TObjectReflection() :
 | 
				
			||||||
 | 
					        offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), stages(EShLanguageMask(0)), type(nullptr) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const TType* type;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TReflection;
 | 
					class TReflection;
 | 
				
			||||||
class TIoMapper;
 | 
					class TIoMapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -689,27 +718,117 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Reflection Interface
 | 
					    // Reflection Interface
 | 
				
			||||||
    bool buildReflection();                          // call first, to do liveness analysis, index mapping, etc.; returns false on failure
 | 
					    bool buildReflection();                          // call first, to do liveness analysis, index mapping, etc.; returns false on failure
 | 
				
			||||||
    int getNumLiveUniformVariables() const;                // can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
 | 
					
 | 
				
			||||||
    int getNumLiveUniformBlocks() const;                   // can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
 | 
					 | 
				
			||||||
    const char* getUniformName(int index) const;           // can be used for "name" part of glGetActiveUniform()
 | 
					 | 
				
			||||||
    const char* getUniformBlockName(int blockIndex) const; // can be used for glGetActiveUniformBlockName()
 | 
					 | 
				
			||||||
    int getUniformBlockSize(int blockIndex) const;         // can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
 | 
					 | 
				
			||||||
    int getUniformIndex(const char* name) const;           // can be used for glGetUniformIndices()
 | 
					 | 
				
			||||||
    int getUniformBinding(int index) const;                // returns the binding number
 | 
					 | 
				
			||||||
    EShLanguageMask getUniformStages(int index) const;     // returns Shaders Stages where a Uniform is present
 | 
					 | 
				
			||||||
    int getUniformBlockBinding(int index) const;           // returns the block binding number
 | 
					 | 
				
			||||||
    int getUniformBlockIndex(int index) const;             // can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
 | 
					 | 
				
			||||||
    int getUniformBlockCounterIndex(int index) const;      // returns block index of associated counter.
 | 
					 | 
				
			||||||
    int getUniformType(int index) const;                   // can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
 | 
					 | 
				
			||||||
    int getUniformBufferOffset(int index) const;           // can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
 | 
					 | 
				
			||||||
    int getUniformArraySize(int index) const;              // can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
 | 
					 | 
				
			||||||
    int getNumLiveAttributes() const;                      // can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
 | 
					 | 
				
			||||||
    unsigned getLocalSize(int dim) const;                  // return dim'th local size
 | 
					    unsigned getLocalSize(int dim) const;                  // return dim'th local size
 | 
				
			||||||
    const char *getAttributeName(int index) const;         // can be used for glGetActiveAttrib()
 | 
					    int getReflectionIndex(const char *name) const;
 | 
				
			||||||
    int getAttributeType(int index) const;                 // can be used for glGetActiveAttrib()
 | 
					
 | 
				
			||||||
    const TType* getUniformTType(int index) const;         // returns a TType*
 | 
					    int getNumUniformVariables() const;
 | 
				
			||||||
    const TType* getUniformBlockTType(int index) const;    // returns a TType*
 | 
					    const TObjectReflection& getUniform(int index) const;
 | 
				
			||||||
    const TType* getAttributeTType(int index) const;       // returns a TType*
 | 
					    int getNumUniformBlocks() const;
 | 
				
			||||||
 | 
					    const TObjectReflection& getUniformBlock(int index) const;
 | 
				
			||||||
 | 
					    int getNumAttributes() const;
 | 
				
			||||||
 | 
					    const TObjectReflection& getAttribute(int index) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Legacy Reflection Interface - expressed in terms of above interface
 | 
				
			||||||
 | 
					    int getNumLiveUniformVariables() const                 // can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getNumUniformVariables();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getNumLiveUniformBlocks() const                    // can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getNumUniformBlocks();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getNumLiveAttributes() const                       // can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getNumAttributes();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformIndex(const char* name) const            // can be used for glGetUniformIndices()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getReflectionIndex(name);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const char* getUniformName(int index) const            // can be used for "name" part of glGetActiveUniform()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniform(index).name.c_str();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformBinding(int index) const                 // returns the binding number
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniform(index).getBinding();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    EShLanguageMask getUniformStages(int index) const      // returns Shaders Stages where a Uniform is present
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniform(index).stages;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformBlockIndex(int index) const              // can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniform(index).index;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformType(int index) const                    // can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniform(index).glDefineType;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformBufferOffset(int index) const            // can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniform(index).offset;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformArraySize(int index) const               // can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniform(index).size;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const TType* getUniformTType(int index) const          // returns a TType*
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniform(index).getType();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const char* getUniformBlockName(int index) const  // can be used for glGetActiveUniformBlockName()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniformBlock(index).name.c_str();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformBlockSize(int index) const          // can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniformBlock(index).size;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformBlockBinding(int index) const            // returns the block binding number
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniformBlock(index).getBinding();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getUniformBlockCounterIndex(int index) const       // returns block index of associated counter.
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniformBlock(index).counterIndex;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const TType* getUniformBlockTType(int index) const     // returns a TType*
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getUniformBlock(index).getType();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const char* getAttributeName(int index) const          // can be used for glGetActiveAttrib()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getAttribute(index).name.c_str();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getAttributeType(int index) const                  // can be used for glGetActiveAttrib()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getAttribute(index).glDefineType;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const TType* getAttributeTType(int index) const        // returns a TType*
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return getAttribute(index).getType();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void dumpReflection();
 | 
					    void dumpReflection();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user