1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/libGLESv2/ProgramBinary.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,174 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +// Program.h: Defines the gl::Program class. Implements GL program objects 1.11 +// and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28. 1.12 + 1.13 +#ifndef LIBGLESV2_PROGRAM_BINARY_H_ 1.14 +#define LIBGLESV2_PROGRAM_BINARY_H_ 1.15 + 1.16 +#define GL_APICALL 1.17 +#include <GLES2/gl2.h> 1.18 +#include <GLES2/gl2ext.h> 1.19 + 1.20 +#include <string> 1.21 +#include <vector> 1.22 + 1.23 +#include "common/RefCountObject.h" 1.24 +#include "angletypes.h" 1.25 +#include "libGLESv2/mathutil.h" 1.26 +#include "libGLESv2/Uniform.h" 1.27 +#include "libGLESv2/Shader.h" 1.28 +#include "libGLESv2/Constants.h" 1.29 + 1.30 +namespace rx 1.31 +{ 1.32 +class ShaderExecutable; 1.33 +class Renderer; 1.34 +struct TranslatedAttribute; 1.35 +} 1.36 + 1.37 +namespace gl 1.38 +{ 1.39 +class FragmentShader; 1.40 +class VertexShader; 1.41 +class InfoLog; 1.42 +class AttributeBindings; 1.43 +struct Varying; 1.44 + 1.45 +// Struct used for correlating uniforms/elements of uniform arrays to handles 1.46 +struct UniformLocation 1.47 +{ 1.48 + UniformLocation() 1.49 + { 1.50 + } 1.51 + 1.52 + UniformLocation(const std::string &name, unsigned int element, unsigned int index); 1.53 + 1.54 + std::string name; 1.55 + unsigned int element; 1.56 + unsigned int index; 1.57 +}; 1.58 + 1.59 +// This is the result of linking a program. It is the state that would be passed to ProgramBinary. 1.60 +class ProgramBinary : public RefCountObject 1.61 +{ 1.62 + public: 1.63 + explicit ProgramBinary(rx::Renderer *renderer); 1.64 + ~ProgramBinary(); 1.65 + 1.66 + rx::ShaderExecutable *getPixelExecutable(); 1.67 + rx::ShaderExecutable *getVertexExecutable(); 1.68 + rx::ShaderExecutable *getGeometryExecutable(); 1.69 + 1.70 + GLuint getAttributeLocation(const char *name); 1.71 + int getSemanticIndex(int attributeIndex); 1.72 + 1.73 + GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex); 1.74 + TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex); 1.75 + GLint getUsedSamplerRange(SamplerType type); 1.76 + bool usesPointSize() const; 1.77 + bool usesPointSpriteEmulation() const; 1.78 + bool usesGeometryShader() const; 1.79 + 1.80 + GLint getUniformLocation(std::string name); 1.81 + bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); 1.82 + bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v); 1.83 + bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v); 1.84 + bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v); 1.85 + bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); 1.86 + bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); 1.87 + bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); 1.88 + bool setUniform1iv(GLint location, GLsizei count, const GLint *v); 1.89 + bool setUniform2iv(GLint location, GLsizei count, const GLint *v); 1.90 + bool setUniform3iv(GLint location, GLsizei count, const GLint *v); 1.91 + bool setUniform4iv(GLint location, GLsizei count, const GLint *v); 1.92 + 1.93 + bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params); 1.94 + bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params); 1.95 + 1.96 + void dirtyAllUniforms(); 1.97 + void applyUniforms(); 1.98 + 1.99 + bool load(InfoLog &infoLog, const void *binary, GLsizei length); 1.100 + bool save(void* binary, GLsizei bufSize, GLsizei *length); 1.101 + GLint getLength(); 1.102 + 1.103 + bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); 1.104 + void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); 1.105 + 1.106 + void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; 1.107 + GLint getActiveAttributeCount() const; 1.108 + GLint getActiveAttributeMaxLength() const; 1.109 + 1.110 + void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; 1.111 + GLint getActiveUniformCount() const; 1.112 + GLint getActiveUniformMaxLength() const; 1.113 + 1.114 + void validate(InfoLog &infoLog); 1.115 + bool validateSamplers(InfoLog *infoLog); 1.116 + bool isValidated() const; 1.117 + 1.118 + unsigned int getSerial() const; 1.119 + 1.120 + void sortAttributesByLayout(rx::TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndices[MAX_VERTEX_ATTRIBS]) const; 1.121 + 1.122 + static std::string decorateAttribute(const std::string &name); // Prepend an underscore 1.123 + 1.124 + private: 1.125 + DISALLOW_COPY_AND_ASSIGN(ProgramBinary); 1.126 + 1.127 + int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader); 1.128 + bool linkVaryings(InfoLog &infoLog, int registers, const Varying *packing[][4], 1.129 + std::string& pixelHLSL, std::string& vertexHLSL, 1.130 + FragmentShader *fragmentShader, VertexShader *vertexShader); 1.131 + 1.132 + bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); 1.133 + 1.134 + bool linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &vertexUniforms, const sh::ActiveUniforms &fragmentUniforms); 1.135 + bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog); 1.136 + 1.137 + std::string generateGeometryShaderHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; 1.138 + std::string generatePointSpriteHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; 1.139 + 1.140 + rx::Renderer *const mRenderer; 1.141 + 1.142 + rx::ShaderExecutable *mPixelExecutable; 1.143 + rx::ShaderExecutable *mVertexExecutable; 1.144 + rx::ShaderExecutable *mGeometryExecutable; 1.145 + 1.146 + Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; 1.147 + int mSemanticIndex[MAX_VERTEX_ATTRIBS]; 1.148 + 1.149 + struct Sampler 1.150 + { 1.151 + Sampler(); 1.152 + 1.153 + bool active; 1.154 + GLint logicalTextureUnit; 1.155 + TextureType textureType; 1.156 + }; 1.157 + 1.158 + Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS]; 1.159 + Sampler mSamplersVS[IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; 1.160 + GLuint mUsedVertexSamplerRange; 1.161 + GLuint mUsedPixelSamplerRange; 1.162 + bool mUsesPointSize; 1.163 + 1.164 + UniformArray mUniforms; 1.165 + typedef std::vector<UniformLocation> UniformIndex; 1.166 + UniformIndex mUniformIndex; 1.167 + 1.168 + bool mValidated; 1.169 + 1.170 + const unsigned int mSerial; 1.171 + 1.172 + static unsigned int issueSerial(); 1.173 + static unsigned int mCurrentSerial; 1.174 +}; 1.175 +} 1.176 + 1.177 +#endif // LIBGLESV2_PROGRAM_BINARY_H_