#pragma once #include "../Macros.h" #include "../Types.h" #include "../RenderPipelineDescriptor.h" #include "base/CCRef.h" #include "platform/CCGL.h" #include "../Program.h" #include #include #include CC_BACKEND_BEGIN class ShaderModuleGL; struct AttributeInfo { unsigned int location = 0; unsigned int size = 0; GLenum type = GL_BYTE; GLsizei stride = 0; unsigned int offset = 0; GLboolean needToBeNormallized = GL_FALSE; }; class ProgramGL : public Program { public: typedef std::vector VertexAttributeArray; ProgramGL(const std::string& vertexShader, const std::string& fragmentShader); ~ProgramGL(); inline const std::vector& getAttributeInfos() const { return _attributeInfos; } inline GLuint getHandler() const { return _program; } void computeAttributeInfos(const RenderPipelineDescriptor& descriptor); virtual const std::unordered_map& getVertexUniformInfos() const override; virtual const std::unordered_map& getFragmentUniformInfos() const override; virtual UniformLocation getUniformLocation(const std::string& uniform) const override; virtual int getMaxVertexLocation() const override; virtual int getMaxFragmentLocation() const override; virtual std::vector getActiveAttributes() const override; private: void compileProgram(); bool getAttributeLocation(const std::string& attributeName, unsigned int& location) const; void computeUniformInfos(); GLuint _program = 0; ShaderModuleGL* _vertexShaderModule = nullptr; ShaderModuleGL* _fragmentShaderModule = nullptr; std::vector _attributeInfos; std::unordered_map _uniformInfos; int _maxLocation = -1; }; CC_BACKEND_END