michael@0: // michael@0: // Copyright (c) 2002-2012 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: // Program.h: Defines the gl::Program class. Implements GL program objects michael@0: // and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28. michael@0: michael@0: #ifndef LIBGLESV2_PROGRAM_BINARY_H_ michael@0: #define LIBGLESV2_PROGRAM_BINARY_H_ michael@0: michael@0: #define GL_APICALL michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "common/RefCountObject.h" michael@0: #include "angletypes.h" michael@0: #include "libGLESv2/mathutil.h" michael@0: #include "libGLESv2/Uniform.h" michael@0: #include "libGLESv2/Shader.h" michael@0: #include "libGLESv2/Constants.h" michael@0: michael@0: namespace rx michael@0: { michael@0: class ShaderExecutable; michael@0: class Renderer; michael@0: struct TranslatedAttribute; michael@0: } michael@0: michael@0: namespace gl michael@0: { michael@0: class FragmentShader; michael@0: class VertexShader; michael@0: class InfoLog; michael@0: class AttributeBindings; michael@0: struct Varying; michael@0: michael@0: // Struct used for correlating uniforms/elements of uniform arrays to handles michael@0: struct UniformLocation michael@0: { michael@0: UniformLocation() michael@0: { michael@0: } michael@0: michael@0: UniformLocation(const std::string &name, unsigned int element, unsigned int index); michael@0: michael@0: std::string name; michael@0: unsigned int element; michael@0: unsigned int index; michael@0: }; michael@0: michael@0: // This is the result of linking a program. It is the state that would be passed to ProgramBinary. michael@0: class ProgramBinary : public RefCountObject michael@0: { michael@0: public: michael@0: explicit ProgramBinary(rx::Renderer *renderer); michael@0: ~ProgramBinary(); michael@0: michael@0: rx::ShaderExecutable *getPixelExecutable(); michael@0: rx::ShaderExecutable *getVertexExecutable(); michael@0: rx::ShaderExecutable *getGeometryExecutable(); michael@0: michael@0: GLuint getAttributeLocation(const char *name); michael@0: int getSemanticIndex(int attributeIndex); michael@0: michael@0: GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex); michael@0: TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex); michael@0: GLint getUsedSamplerRange(SamplerType type); michael@0: bool usesPointSize() const; michael@0: bool usesPointSpriteEmulation() const; michael@0: bool usesGeometryShader() const; michael@0: michael@0: GLint getUniformLocation(std::string name); michael@0: bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); michael@0: bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v); michael@0: bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v); michael@0: bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v); michael@0: bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); michael@0: bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); michael@0: bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); michael@0: bool setUniform1iv(GLint location, GLsizei count, const GLint *v); michael@0: bool setUniform2iv(GLint location, GLsizei count, const GLint *v); michael@0: bool setUniform3iv(GLint location, GLsizei count, const GLint *v); michael@0: bool setUniform4iv(GLint location, GLsizei count, const GLint *v); michael@0: michael@0: bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params); michael@0: bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params); michael@0: michael@0: void dirtyAllUniforms(); michael@0: void applyUniforms(); michael@0: michael@0: bool load(InfoLog &infoLog, const void *binary, GLsizei length); michael@0: bool save(void* binary, GLsizei bufSize, GLsizei *length); michael@0: GLint getLength(); michael@0: michael@0: bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); michael@0: void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); michael@0: michael@0: void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; michael@0: GLint getActiveAttributeCount() const; michael@0: GLint getActiveAttributeMaxLength() const; michael@0: michael@0: void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; michael@0: GLint getActiveUniformCount() const; michael@0: GLint getActiveUniformMaxLength() const; michael@0: michael@0: void validate(InfoLog &infoLog); michael@0: bool validateSamplers(InfoLog *infoLog); michael@0: bool isValidated() const; michael@0: michael@0: unsigned int getSerial() const; michael@0: michael@0: void sortAttributesByLayout(rx::TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndices[MAX_VERTEX_ATTRIBS]) const; michael@0: michael@0: static std::string decorateAttribute(const std::string &name); // Prepend an underscore michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(ProgramBinary); michael@0: michael@0: int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader); michael@0: bool linkVaryings(InfoLog &infoLog, int registers, const Varying *packing[][4], michael@0: std::string& pixelHLSL, std::string& vertexHLSL, michael@0: FragmentShader *fragmentShader, VertexShader *vertexShader); michael@0: michael@0: bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); michael@0: michael@0: bool linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &vertexUniforms, const sh::ActiveUniforms &fragmentUniforms); michael@0: bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog); michael@0: michael@0: std::string generateGeometryShaderHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; michael@0: std::string generatePointSpriteHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; michael@0: michael@0: rx::Renderer *const mRenderer; michael@0: michael@0: rx::ShaderExecutable *mPixelExecutable; michael@0: rx::ShaderExecutable *mVertexExecutable; michael@0: rx::ShaderExecutable *mGeometryExecutable; michael@0: michael@0: Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; michael@0: int mSemanticIndex[MAX_VERTEX_ATTRIBS]; michael@0: michael@0: struct Sampler michael@0: { michael@0: Sampler(); michael@0: michael@0: bool active; michael@0: GLint logicalTextureUnit; michael@0: TextureType textureType; michael@0: }; michael@0: michael@0: Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS]; michael@0: Sampler mSamplersVS[IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; michael@0: GLuint mUsedVertexSamplerRange; michael@0: GLuint mUsedPixelSamplerRange; michael@0: bool mUsesPointSize; michael@0: michael@0: UniformArray mUniforms; michael@0: typedef std::vector UniformIndex; michael@0: UniformIndex mUniformIndex; michael@0: michael@0: bool mValidated; michael@0: michael@0: const unsigned int mSerial; michael@0: michael@0: static unsigned int issueSerial(); michael@0: static unsigned int mCurrentSerial; michael@0: }; michael@0: } michael@0: michael@0: #endif // LIBGLESV2_PROGRAM_BINARY_H_