diff options
Diffstat (limited to 'gpu/command_buffer/service/shader_translator.h')
-rw-r--r-- | gpu/command_buffer/service/shader_translator.h | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/gpu/command_buffer/service/shader_translator.h b/gpu/command_buffer/service/shader_translator.h index 5054972..852ee5f 100644 --- a/gpu/command_buffer/service/shader_translator.h +++ b/gpu/command_buffer/service/shader_translator.h @@ -16,35 +16,69 @@ namespace gpu { namespace gles2 { // Translates GLSL ES 2.0 shader to desktop GLSL shader. -class ShaderTranslator { +class ShaderTranslatorInterface { public: - ShaderTranslator(); - ~ShaderTranslator(); + virtual ~ShaderTranslatorInterface() { } // Initializes the translator. // Must be called once before using the translator object. - bool Init(ShShaderType shader_type, - ShShaderSpec shader_spec, - const ShBuiltInResources* resources); + virtual bool Init( + ShShaderType shader_type, + ShShaderSpec shader_spec, + const ShBuiltInResources* resources) = 0; + // Translates the given shader source. // Returns true if translation is successful, false otherwise. - bool Translate(const char* shader); + virtual bool Translate(const char* shader) = 0; // The following functions return results from the last translation. // The results are NULL/empty if the translation was unsuccessful. // A valid info-log is always returned irrespective of whether translation // was successful or not. - const char* translated_shader() { return translated_shader_.get(); } - const char* info_log() { return info_log_.get(); } + virtual const char* translated_shader() const = 0; + virtual const char* info_log() const = 0; struct VariableInfo { + VariableInfo() + : type(0), + size(0) { + } + VariableInfo(int _type, int _size) + : type(_type), + size(_size) { + } int type; int size; }; // Mapping between variable name and info. typedef std::map<std::string, VariableInfo> VariableMap; - const VariableMap& attrib_map() { return attrib_map_; } - const VariableMap& uniform_map() { return uniform_map_; } + virtual const VariableMap& attrib_map() const = 0; + virtual const VariableMap& uniform_map() const = 0; +}; + +// Implementation of ShaderTranslatorInterface +class ShaderTranslator : public ShaderTranslatorInterface { + public: + ShaderTranslator(); + ~ShaderTranslator(); + + // Overridden from ShaderTranslatorInterface. + virtual bool Init( + ShShaderType shader_type, + ShShaderSpec shader_spec, + const ShBuiltInResources* resources); + + // Overridden from ShaderTranslatorInterface. + virtual bool Translate(const char* shader); + + // Overridden from ShaderTranslatorInterface. + virtual const char* translated_shader() const { + return translated_shader_.get(); } + virtual const char* info_log() const { return info_log_.get(); } + + // Overridden from ShaderTranslatorInterface. + virtual const VariableMap& attrib_map() const { return attrib_map_; } + virtual const VariableMap& uniform_map() const { return uniform_map_; } private: void ClearResults(); |