OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "third_party/angle/include/GLSLANG/ShaderLang.h" | 13 #include "third_party/angle/include/GLSLANG/ShaderLang.h" |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
16 namespace gles2 { | 16 namespace gles2 { |
17 | 17 |
18 // Translates GLSL ES 2.0 shader to desktop GLSL shader. | 18 // Translates a GLSL ES 2.0 shader to desktop GLSL shader, or just |
| 19 // validates GLSL ES 2.0 shaders on a true GLSL ES implementation. |
19 class ShaderTranslatorInterface { | 20 class ShaderTranslatorInterface { |
20 public: | 21 public: |
21 virtual ~ShaderTranslatorInterface() { } | 22 virtual ~ShaderTranslatorInterface() { } |
22 | 23 |
23 // Initializes the translator. | 24 // Initializes the translator. |
24 // Must be called once before using the translator object. | 25 // Must be called once before using the translator object. |
25 virtual bool Init( | 26 virtual bool Init( |
26 ShShaderType shader_type, | 27 ShShaderType shader_type, |
27 ShShaderSpec shader_spec, | 28 ShShaderSpec shader_spec, |
28 const ShBuiltInResources* resources) = 0; | 29 const ShBuiltInResources* resources, |
| 30 bool implementation_is_glsl_es) = 0; |
29 | 31 |
30 // Translates the given shader source. | 32 // Translates the given shader source. |
31 // Returns true if translation is successful, false otherwise. | 33 // Returns true if translation is successful, false otherwise. |
32 virtual bool Translate(const char* shader) = 0; | 34 virtual bool Translate(const char* shader) = 0; |
33 | 35 |
34 // The following functions return results from the last translation. | 36 // The following functions return results from the last translation. |
35 // The results are NULL/empty if the translation was unsuccessful. | 37 // The results are NULL/empty if the translation was unsuccessful. |
36 // A valid info-log is always returned irrespective of whether translation | 38 // A valid info-log is always returned irrespective of whether translation |
37 // was successful or not. | 39 // was successful or not. |
38 virtual const char* translated_shader() const = 0; | 40 virtual const char* translated_shader() const = 0; |
(...skipping 20 matching lines...) Expand all Loading... |
59 // Implementation of ShaderTranslatorInterface | 61 // Implementation of ShaderTranslatorInterface |
60 class ShaderTranslator : public ShaderTranslatorInterface { | 62 class ShaderTranslator : public ShaderTranslatorInterface { |
61 public: | 63 public: |
62 ShaderTranslator(); | 64 ShaderTranslator(); |
63 ~ShaderTranslator(); | 65 ~ShaderTranslator(); |
64 | 66 |
65 // Overridden from ShaderTranslatorInterface. | 67 // Overridden from ShaderTranslatorInterface. |
66 virtual bool Init( | 68 virtual bool Init( |
67 ShShaderType shader_type, | 69 ShShaderType shader_type, |
68 ShShaderSpec shader_spec, | 70 ShShaderSpec shader_spec, |
69 const ShBuiltInResources* resources); | 71 const ShBuiltInResources* resources, |
| 72 bool implementation_is_glsl_es); |
70 | 73 |
71 // Overridden from ShaderTranslatorInterface. | 74 // Overridden from ShaderTranslatorInterface. |
72 virtual bool Translate(const char* shader); | 75 virtual bool Translate(const char* shader); |
73 | 76 |
74 // Overridden from ShaderTranslatorInterface. | 77 // Overridden from ShaderTranslatorInterface. |
75 virtual const char* translated_shader() const { | 78 virtual const char* translated_shader() const { |
76 return translated_shader_.get(); } | 79 return translated_shader_.get(); } |
77 virtual const char* info_log() const { return info_log_.get(); } | 80 virtual const char* info_log() const { return info_log_.get(); } |
78 | 81 |
79 // Overridden from ShaderTranslatorInterface. | 82 // Overridden from ShaderTranslatorInterface. |
80 virtual const VariableMap& attrib_map() const { return attrib_map_; } | 83 virtual const VariableMap& attrib_map() const { return attrib_map_; } |
81 virtual const VariableMap& uniform_map() const { return uniform_map_; } | 84 virtual const VariableMap& uniform_map() const { return uniform_map_; } |
82 | 85 |
83 private: | 86 private: |
84 void ClearResults(); | 87 void ClearResults(); |
85 | 88 |
86 ShHandle compiler_; | 89 ShHandle compiler_; |
87 scoped_array<char> translated_shader_; | 90 scoped_array<char> translated_shader_; |
88 scoped_array<char> info_log_; | 91 scoped_array<char> info_log_; |
89 VariableMap attrib_map_; | 92 VariableMap attrib_map_; |
90 VariableMap uniform_map_; | 93 VariableMap uniform_map_; |
| 94 bool implementation_is_glsl_es_; |
91 | 95 |
92 DISALLOW_COPY_AND_ASSIGN(ShaderTranslator); | 96 DISALLOW_COPY_AND_ASSIGN(ShaderTranslator); |
93 }; | 97 }; |
94 | 98 |
95 } // namespace gles2 | 99 } // namespace gles2 |
96 } // namespace gpu | 100 } // namespace gpu |
97 | 101 |
98 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ | 102 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_H_ |
99 | 103 |
OLD | NEW |