OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SAMPLER_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_SAMPLER_MANAGER_H_ |
| 7 |
| 8 #include <vector> |
| 9 #include "base/basictypes.h" |
| 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "gpu/command_buffer/service/feature_info.h" |
| 15 #include "gpu/command_buffer/service/gl_utils.h" |
| 16 #include "gpu/gpu_export.h" |
| 17 |
| 18 namespace gpu { |
| 19 |
| 20 namespace gles2 { |
| 21 |
| 22 class SamplerManager; |
| 23 |
| 24 class GPU_EXPORT Sampler : public base::RefCounted<Sampler> { |
| 25 public: |
| 26 Sampler(SamplerManager* manager, GLuint service_id); |
| 27 |
| 28 // The service side OpenGL id of the texture. |
| 29 GLuint service_id() const { |
| 30 return service_id_; |
| 31 } |
| 32 |
| 33 // Sampler parameters |
| 34 GLenum min_filter() const { |
| 35 return min_filter_; |
| 36 } |
| 37 |
| 38 GLenum mag_filter() const { |
| 39 return mag_filter_; |
| 40 } |
| 41 |
| 42 GLenum wrap_r() const { |
| 43 return wrap_r_; |
| 44 } |
| 45 |
| 46 GLenum wrap_s() const { |
| 47 return wrap_s_; |
| 48 } |
| 49 |
| 50 GLenum wrap_t() const { |
| 51 return wrap_t_; |
| 52 } |
| 53 |
| 54 GLenum compare_func() const { |
| 55 return compare_func_; |
| 56 } |
| 57 |
| 58 GLenum compare_mode() const { |
| 59 return compare_mode_; |
| 60 } |
| 61 |
| 62 GLfloat max_lod() const { |
| 63 return max_lod_; |
| 64 } |
| 65 |
| 66 GLfloat min_lod() const { |
| 67 return min_lod_; |
| 68 } |
| 69 |
| 70 bool IsDeleted() const { |
| 71 return deleted_; |
| 72 } |
| 73 |
| 74 protected: |
| 75 virtual ~Sampler(); |
| 76 |
| 77 SamplerManager* manager() const { |
| 78 return manager_; |
| 79 } |
| 80 |
| 81 void MarkAsDeleted() { |
| 82 deleted_ = true; |
| 83 } |
| 84 |
| 85 private: |
| 86 friend class SamplerManager; |
| 87 friend class base::RefCounted<Sampler>; |
| 88 |
| 89 // Sets a sampler parameter. |
| 90 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
| 91 GLenum SetParameteri( |
| 92 const FeatureInfo* feature_info, GLenum pname, GLint param); |
| 93 GLenum SetParameterf( |
| 94 const FeatureInfo* feature_info, GLenum pname, GLfloat param); |
| 95 |
| 96 // The manager that owns this Sampler. |
| 97 SamplerManager* manager_; |
| 98 |
| 99 // The id of the texure |
| 100 GLuint service_id_; |
| 101 |
| 102 // Texture parameters. |
| 103 GLenum min_filter_; |
| 104 GLenum mag_filter_; |
| 105 GLenum wrap_r_; |
| 106 GLenum wrap_s_; |
| 107 GLenum wrap_t_; |
| 108 GLenum compare_func_; |
| 109 GLenum compare_mode_; |
| 110 GLfloat max_lod_; |
| 111 GLfloat min_lod_; |
| 112 |
| 113 // True if deleted. |
| 114 bool deleted_; |
| 115 }; |
| 116 |
| 117 // This class keeps track of the samplers and their state. |
| 118 class GPU_EXPORT SamplerManager { |
| 119 public: |
| 120 SamplerManager(FeatureInfo* feature_info); |
| 121 ~SamplerManager(); |
| 122 |
| 123 // Must call before destruction. |
| 124 void Destroy(bool have_context); |
| 125 |
| 126 // Creates a Sampler for the given sampler. |
| 127 Sampler* CreateSampler(GLuint client_id, GLuint service_id); |
| 128 |
| 129 // Gets the Sampler info for the given sampler. |
| 130 Sampler* GetSampler(GLuint client_id); |
| 131 |
| 132 // Removes a Sampler info for the given sampler. |
| 133 void RemoveSampler(GLuint client_id); |
| 134 |
| 135 // Sets a sampler parameter of a Sampler. |
| 136 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
| 137 void SetParameteri( |
| 138 const char* function_name, ErrorState* error_state, |
| 139 Sampler* sampler, GLenum pname, GLint param); |
| 140 void SetParameterf( |
| 141 const char* function_name, ErrorState* error_state, |
| 142 Sampler* sampler, GLenum pname, GLfloat param); |
| 143 |
| 144 private: |
| 145 friend class Sampler; |
| 146 |
| 147 scoped_refptr<FeatureInfo> feature_info_; |
| 148 |
| 149 // Info for each sampler in the system. |
| 150 typedef base::hash_map<GLuint, scoped_refptr<Sampler> > SamplerMap; |
| 151 SamplerMap samplers_; |
| 152 |
| 153 bool have_context_; |
| 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(SamplerManager); |
| 156 }; |
| 157 |
| 158 } // namespace gles2 |
| 159 } // namespace gpu |
| 160 |
| 161 #endif // GPU_COMMAND_BUFFER_SERVICE_SAMPLER_MANAGER_H_ |
OLD | NEW |