1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef WEBGL_SHADER_H_ 7 #define WEBGL_SHADER_H_ 8 9 #include <map> 10 #include <memory> 11 #include <string> 12 #include <vector> 13 14 #include "GLDefs.h" 15 #include "mozilla/MemoryReporting.h" 16 17 #include "WebGLObjectModel.h" 18 19 namespace mozilla { 20 21 namespace webgl { 22 class ShaderValidatorResults; 23 } // namespace webgl 24 25 class WebGLShader final : public WebGLContextBoundObject { 26 friend class WebGLContext; 27 friend class WebGLProgram; 28 29 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLShader, override) 30 31 public: 32 WebGLShader(WebGLContext* webgl, GLenum type); 33 34 protected: 35 ~WebGLShader() override; 36 37 public: 38 // GL funcs 39 void CompileShader(); 40 void ShaderSource(const std::string& source); 41 42 // Util funcs 43 size_t CalcNumSamplerUniforms() const; 44 size_t NumAttributes() const; 45 CompileResults()46 const auto& CompileResults() const { return mCompileResults; } CompileLog()47 const auto& CompileLog() const { return mCompilationLog; } IsCompiled()48 bool IsCompiled() const { return mCompilationSuccessful; } 49 50 private: 51 void BindAttribLocation(GLuint prog, const std::string& userName, 52 GLuint index) const; 53 void MapTransformFeedbackVaryings( 54 const std::vector<std::string>& varyings, 55 std::vector<std::string>* out_mappedVaryings) const; 56 57 public: 58 // Other funcs 59 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const; 60 61 public: 62 const GLuint mGLName; 63 const GLenum mType; 64 65 protected: 66 std::string mSource; 67 68 std::unique_ptr<const webgl::ShaderValidatorResults> 69 mCompileResults; // Never null. 70 bool mCompilationSuccessful = false; 71 std::string mCompilationLog; 72 }; 73 74 } // namespace mozilla 75 76 #endif // WEBGL_SHADER_H_ 77