michael@0: // michael@0: // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // Shader.h: Defines the abstract gl::Shader class and its concrete derived michael@0: // classes VertexShader and FragmentShader. Implements GL shader objects and michael@0: // related functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section michael@0: // 3.8 page 84. michael@0: michael@0: #ifndef LIBGLESV2_SHADER_H_ michael@0: #define LIBGLESV2_SHADER_H_ michael@0: michael@0: #define GL_APICALL michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "compiler/CompilerUniform.h" michael@0: #include "common/angleutils.h" michael@0: michael@0: namespace rx michael@0: { michael@0: class Renderer; michael@0: } michael@0: michael@0: namespace gl michael@0: { michael@0: class ResourceManager; michael@0: michael@0: struct Varying michael@0: { michael@0: Varying(GLenum type, const std::string &name, int size, bool array) michael@0: : type(type), name(name), size(size), array(array), reg(-1), col(-1) michael@0: { michael@0: } michael@0: michael@0: GLenum type; michael@0: std::string name; michael@0: int size; // Number of 'type' elements michael@0: bool array; michael@0: michael@0: int reg; // First varying register, assigned during link michael@0: int col; // First register element, assigned during link michael@0: }; michael@0: michael@0: typedef std::list VaryingList; michael@0: michael@0: class Shader michael@0: { michael@0: friend class ProgramBinary; michael@0: michael@0: public: michael@0: Shader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle); michael@0: michael@0: virtual ~Shader(); michael@0: michael@0: virtual GLenum getType() = 0; michael@0: GLuint getHandle() const; michael@0: michael@0: void deleteSource(); michael@0: void setSource(GLsizei count, const char **string, const GLint *length); michael@0: int getInfoLogLength() const; michael@0: void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); michael@0: int getSourceLength() const; michael@0: void getSource(GLsizei bufSize, GLsizei *length, char *buffer); michael@0: int getTranslatedSourceLength() const; michael@0: void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer); michael@0: const sh::ActiveUniforms &getUniforms(); michael@0: michael@0: virtual void compile() = 0; michael@0: virtual void uncompile(); michael@0: bool isCompiled(); michael@0: const char *getHLSL(); michael@0: michael@0: void addRef(); michael@0: void release(); michael@0: unsigned int getRefCount() const; michael@0: bool isFlaggedForDeletion() const; michael@0: void flagForDeletion(); michael@0: michael@0: static void releaseCompiler(); michael@0: michael@0: protected: michael@0: void parseVaryings(); michael@0: void resetVaryingsRegisterAssignment(); michael@0: michael@0: void compileToHLSL(void *compiler); michael@0: michael@0: void getSourceImpl(char *source, GLsizei bufSize, GLsizei *length, char *buffer); michael@0: michael@0: static GLenum parseType(const std::string &type); michael@0: static bool compareVarying(const Varying &x, const Varying &y); michael@0: michael@0: const rx::Renderer *const mRenderer; michael@0: michael@0: VaryingList mVaryings; michael@0: michael@0: bool mUsesMultipleRenderTargets; michael@0: bool mUsesFragColor; michael@0: bool mUsesFragData; michael@0: bool mUsesFragCoord; michael@0: bool mUsesFrontFacing; michael@0: bool mUsesPointSize; michael@0: bool mUsesPointCoord; michael@0: bool mUsesDepthRange; michael@0: bool mUsesFragDepth; michael@0: michael@0: static void *mFragmentCompiler; michael@0: static void *mVertexCompiler; michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(Shader); michael@0: michael@0: void initializeCompiler(); michael@0: michael@0: const GLuint mHandle; michael@0: unsigned int mRefCount; // Number of program objects this shader is attached to michael@0: bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use michael@0: michael@0: char *mSource; michael@0: char *mHlsl; michael@0: char *mInfoLog; michael@0: sh::ActiveUniforms mActiveUniforms; michael@0: michael@0: ResourceManager *mResourceManager; michael@0: }; michael@0: michael@0: struct Attribute michael@0: { michael@0: Attribute() : type(GL_NONE), name("") michael@0: { michael@0: } michael@0: michael@0: Attribute(GLenum type, const std::string &name) : type(type), name(name) michael@0: { michael@0: } michael@0: michael@0: GLenum type; michael@0: std::string name; michael@0: }; michael@0: michael@0: typedef std::vector AttributeArray; michael@0: michael@0: class VertexShader : public Shader michael@0: { michael@0: friend class ProgramBinary; michael@0: michael@0: public: michael@0: VertexShader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle); michael@0: michael@0: ~VertexShader(); michael@0: michael@0: virtual GLenum getType(); michael@0: virtual void compile(); michael@0: virtual void uncompile(); michael@0: int getSemanticIndex(const std::string &attributeName); michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(VertexShader); michael@0: michael@0: void parseAttributes(); michael@0: michael@0: AttributeArray mAttributes; michael@0: }; michael@0: michael@0: class FragmentShader : public Shader michael@0: { michael@0: public: michael@0: FragmentShader(ResourceManager *manager,const rx::Renderer *renderer, GLuint handle); michael@0: michael@0: ~FragmentShader(); michael@0: michael@0: virtual GLenum getType(); michael@0: virtual void compile(); michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(FragmentShader); michael@0: }; michael@0: } michael@0: michael@0: #endif // LIBGLESV2_SHADER_H_