|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
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 WEBGLSHADER_H_ |
|
7 #define WEBGLSHADER_H_ |
|
8 |
|
9 #include "WebGLObjectModel.h" |
|
10 #include "WebGLUniformInfo.h" |
|
11 |
|
12 #include "nsWrapperCache.h" |
|
13 |
|
14 #include "angle/ShaderLang.h" |
|
15 |
|
16 #include "mozilla/LinkedList.h" |
|
17 #include "mozilla/MemoryReporting.h" |
|
18 |
|
19 namespace mozilla { |
|
20 |
|
21 struct WebGLMappedIdentifier { |
|
22 nsCString original, mapped; // ASCII strings |
|
23 WebGLMappedIdentifier(const nsACString& o, const nsACString& m) : original(o), mapped(m) {} |
|
24 }; |
|
25 |
|
26 class WebGLShader MOZ_FINAL |
|
27 : public nsWrapperCache |
|
28 , public WebGLRefCountedObject<WebGLShader> |
|
29 , public LinkedListElement<WebGLShader> |
|
30 , public WebGLContextBoundObject |
|
31 { |
|
32 friend class WebGLContext; |
|
33 friend class WebGLProgram; |
|
34 |
|
35 public: |
|
36 WebGLShader(WebGLContext *context, GLenum stype); |
|
37 |
|
38 ~WebGLShader() { |
|
39 DeleteOnce(); |
|
40 } |
|
41 |
|
42 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; |
|
43 |
|
44 GLuint GLName() { return mGLName; } |
|
45 GLenum ShaderType() { return mType; } |
|
46 |
|
47 void SetSource(const nsAString& src) { |
|
48 // XXX do some quick gzip here maybe -- getting this will be very rare |
|
49 mSource.Assign(src); |
|
50 } |
|
51 |
|
52 const nsString& Source() const { return mSource; } |
|
53 |
|
54 void SetNeedsTranslation() { mNeedsTranslation = true; } |
|
55 bool NeedsTranslation() const { return mNeedsTranslation; } |
|
56 |
|
57 void SetCompileStatus (bool status) { |
|
58 mCompileStatus = status; |
|
59 } |
|
60 |
|
61 void Delete(); |
|
62 |
|
63 bool CompileStatus() const { |
|
64 return mCompileStatus; |
|
65 } |
|
66 |
|
67 void SetTranslationSuccess(); |
|
68 |
|
69 void SetTranslationFailure(const nsCString& msg) { |
|
70 mTranslationLog.Assign(msg); |
|
71 } |
|
72 |
|
73 const nsCString& TranslationLog() const { return mTranslationLog; } |
|
74 |
|
75 const nsString& TranslatedSource() const { return mTranslatedSource; } |
|
76 |
|
77 WebGLContext *GetParentObject() const { |
|
78 return Context(); |
|
79 } |
|
80 |
|
81 virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE; |
|
82 |
|
83 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLShader) |
|
84 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLShader) |
|
85 |
|
86 protected: |
|
87 |
|
88 GLuint mGLName; |
|
89 GLenum mType; |
|
90 nsString mSource; |
|
91 nsString mTranslatedSource; |
|
92 nsCString mTranslationLog; // The translation log should contain only ASCII characters |
|
93 bool mNeedsTranslation; |
|
94 nsTArray<WebGLMappedIdentifier> mAttributes; |
|
95 nsTArray<WebGLMappedIdentifier> mUniforms; |
|
96 nsTArray<WebGLUniformInfo> mUniformInfos; |
|
97 int mAttribMaxNameLength; |
|
98 bool mCompileStatus; |
|
99 }; |
|
100 } // namespace mozilla |
|
101 |
|
102 #endif |