WebGLShader.h (1908B)
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 <memory> 10 #include <string> 11 #include <vector> 12 13 #include "GLDefs.h" 14 #include "WebGLObjectModel.h" 15 #include "mozilla/MemoryReporting.h" 16 17 namespace mozilla { 18 19 namespace webgl { 20 class ShaderValidatorResults; 21 } // namespace webgl 22 23 class WebGLShader final : public WebGLContextBoundObject { 24 friend class WebGLContext; 25 friend class WebGLProgram; 26 27 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLShader, override) 28 29 public: 30 WebGLShader(WebGLContext* webgl, GLenum type); 31 32 protected: 33 ~WebGLShader() override; 34 35 public: 36 // GL funcs 37 void CompileShader(); 38 void ShaderSource(const std::string& source); 39 40 // Util funcs 41 size_t CalcNumSamplerUniforms() const; 42 size_t NumAttributes() const; 43 44 const auto& CompileResults() const { return mCompileResults; } 45 const auto& CompileLog() const { return mCompilationLog; } 46 bool IsCompiled() const { return mCompilationSuccessful; } 47 48 private: 49 void BindAttribLocation(GLuint prog, const std::string& userName, 50 GLuint index) const; 51 void MapTransformFeedbackVaryings( 52 const std::vector<std::string>& varyings, 53 std::vector<std::string>* out_mappedVaryings) const; 54 55 public: 56 // Other funcs 57 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const; 58 59 public: 60 const GLuint mGLName; 61 const GLenum mType; 62 63 protected: 64 std::string mSource; 65 66 std::unique_ptr<const webgl::ShaderValidatorResults> 67 mCompileResults; // Never null. 68 bool mCompilationSuccessful = false; 69 std::string mCompilationLog; 70 }; 71 72 } // namespace mozilla 73 74 #endif // WEBGL_SHADER_H_