[email protected] | 529c667 | 2012-01-04 02:18:26 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 8a837bb | 2010-01-05 00:21:24 | [diff] [blame] | 5 | #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
[email protected] | 7447070 | 2010-01-06 18:51:16 | [diff] [blame] | 6 | |
| 7 | #include <stdio.h> |
| 8 | |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 10 | #include <list> |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 11 | #include <map> |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <vector> |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 14 | |
[email protected] | 1e6f58d | 2011-03-24 00:00:40 | [diff] [blame] | 15 | #include "base/atomicops.h" |
[email protected] | 00eb49a | 2010-08-12 20:46:57 | [diff] [blame] | 16 | #include "base/at_exit.h" |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 17 | #include "base/bind.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 18 | #include "base/command_line.h" |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 19 | #include "base/debug/trace_event.h" |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 20 | #if defined(OS_MACOSX) |
| 21 | #include "base/mac/scoped_cftyperef.h" |
| 22 | #endif |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 23 | #include "base/memory/scoped_ptr.h" |
| 24 | #include "base/memory/weak_ptr.h" |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 25 | #include "build/build_config.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 26 | #define GLES2_GPU_SERVICE 1 |
| 27 | #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 28 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 29 | #include "gpu/command_buffer/common/id_allocator.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 30 | #include "gpu/command_buffer/service/buffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 31 | #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 32 | #include "gpu/command_buffer/service/context_group.h" |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 33 | #include "gpu/command_buffer/service/feature_info.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 34 | #include "gpu/command_buffer/service/framebuffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 35 | #include "gpu/command_buffer/service/gl_utils.h" |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 36 | #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 37 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 38 | #include "gpu/command_buffer/service/program_manager.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 39 | #include "gpu/command_buffer/service/renderbuffer_manager.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 40 | #include "gpu/command_buffer/service/shader_manager.h" |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 41 | #include "gpu/command_buffer/service/shader_translator.h" |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 42 | #include "gpu/command_buffer/service/stream_texture.h" |
| 43 | #include "gpu/command_buffer/service/stream_texture_manager.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 44 | #include "gpu/command_buffer/service/texture_manager.h" |
[email protected] | d8ea977 | 2011-07-11 18:11:43 | [diff] [blame] | 45 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
[email protected] | 5ae0b28 | 2011-03-28 19:24:49 | [diff] [blame] | 46 | #include "ui/gfx/gl/gl_context.h" |
| 47 | #include "ui/gfx/gl/gl_implementation.h" |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 48 | #include "ui/gfx/gl/gl_surface.h" |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 49 | #if defined(OS_MACOSX) |
| 50 | #include "ui/gfx/surface/io_surface_support_mac.h" |
| 51 | #endif |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 52 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 53 | #if !defined(GL_DEPTH24_STENCIL8) |
| 54 | #define GL_DEPTH24_STENCIL8 0x88F0 |
| 55 | #endif |
| 56 | |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 57 | namespace gpu { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 58 | namespace gles2 { |
| 59 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 60 | namespace { |
| 61 | static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
| 62 | } |
| 63 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 64 | class GLES2DecoderImpl; |
| 65 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 66 | // Check that certain assumptions the code makes are true. There are places in |
| 67 | // the code where shared memory is passed direclty to GL. Example, glUniformiv, |
| 68 | // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe |
| 69 | // a few others) are 32bits. If they are not 32bits the code will have to change |
| 70 | // to call those GL functions with service side memory and then copy the results |
| 71 | // to shared memory, converting the sizes. |
| 72 | COMPILE_ASSERT(sizeof(GLint) == sizeof(uint32), // NOLINT |
| 73 | GLint_not_same_size_as_uint32); |
| 74 | COMPILE_ASSERT(sizeof(GLsizei) == sizeof(uint32), // NOLINT |
| 75 | GLint_not_same_size_as_uint32); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 76 | COMPILE_ASSERT(sizeof(GLfloat) == sizeof(float), // NOLINT |
| 77 | GLfloat_not_same_size_as_float); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 78 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 79 | // TODO(kbr): the use of this anonymous namespace core dumps the |
| 80 | // linker on Mac OS X 10.6 when the symbol ordering file is used |
| 81 | // namespace { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 82 | |
| 83 | // Returns the address of the first byte after a struct. |
| 84 | template <typename T> |
| 85 | const void* AddressAfterStruct(const T& pod) { |
| 86 | return reinterpret_cast<const uint8*>(&pod) + sizeof(pod); |
| 87 | } |
| 88 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 89 | // Returns the address of the frst byte after the struct or NULL if size > |
| 90 | // immediate_data_size. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 91 | template <typename RETURN_TYPE, typename COMMAND_TYPE> |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 92 | RETURN_TYPE GetImmediateDataAs(const COMMAND_TYPE& pod, |
| 93 | uint32 size, |
| 94 | uint32 immediate_data_size) { |
| 95 | return (size <= immediate_data_size) ? |
| 96 | static_cast<RETURN_TYPE>(const_cast<void*>(AddressAfterStruct(pod))) : |
| 97 | NULL; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 98 | } |
| 99 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 100 | // Computes the data size for certain gl commands like glUniform. |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 101 | bool ComputeDataSize( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 102 | GLuint count, |
| 103 | size_t size, |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 104 | unsigned int elements_per_unit, |
| 105 | uint32* dst) { |
| 106 | uint32 value; |
| 107 | if (!SafeMultiplyUint32(count, size, &value)) { |
| 108 | return false; |
| 109 | } |
| 110 | if (!SafeMultiplyUint32(value, elements_per_unit, &value)) { |
| 111 | return false; |
| 112 | } |
| 113 | *dst = value; |
| 114 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // A struct to hold info about each command. |
| 118 | struct CommandInfo { |
| 119 | int arg_flags; // How to handle the arguments for this command |
| 120 | int arg_count; // How many arguments are expected for this command. |
| 121 | }; |
| 122 | |
| 123 | // A table of CommandInfo for all the commands. |
| 124 | const CommandInfo g_command_info[] = { |
| 125 | #define GLES2_CMD_OP(name) { \ |
| 126 | name::kArgFlags, \ |
| 127 | sizeof(name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \ |
| 128 | |
| 129 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 130 | |
| 131 | #undef GLES2_CMD_OP |
| 132 | }; |
| 133 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 134 | // Return true if a character belongs to the ASCII subset as defined in |
| 135 | // GLSL ES 1.0 spec section 3.1. |
| 136 | static bool CharacterIsValidForGLES(unsigned char c) { |
| 137 | // Printing characters are valid except " $ ` @ \ ' DEL. |
| 138 | if (c >= 32 && c <= 126 && |
| 139 | c != '"' && |
| 140 | c != '$' && |
| 141 | c != '`' && |
| 142 | c != '@' && |
| 143 | c != '\\' && |
| 144 | c != '\'') { |
| 145 | return true; |
| 146 | } |
| 147 | // Horizontal tab, line feed, vertical tab, form feed, carriage return |
| 148 | // are also valid. |
| 149 | if (c >= 9 && c <= 13) { |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | static bool StringIsValidForGLES(const char* str) { |
| 157 | for (; *str; ++str) { |
| 158 | if (!CharacterIsValidForGLES(*str)) { |
| 159 | return false; |
| 160 | } |
| 161 | } |
| 162 | return true; |
| 163 | } |
| 164 | |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 165 | static inline GLenum GetTexInternalFormat(GLenum internal_format) { |
| 166 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 167 | if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) |
| 168 | return GL_RGBA8; |
| 169 | } |
| 170 | return internal_format; |
| 171 | } |
| 172 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 173 | static void WrappedTexImage2D( |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 174 | GLenum target, |
| 175 | GLint level, |
| 176 | GLenum internal_format, |
| 177 | GLsizei width, |
| 178 | GLsizei height, |
| 179 | GLint border, |
| 180 | GLenum format, |
| 181 | GLenum type, |
| 182 | const void* pixels) { |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 183 | GLenum gl_internal_format = GetTexInternalFormat(internal_format); |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 184 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 185 | if (type == GL_FLOAT) { |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 186 | if (format == GL_RGBA) { |
| 187 | gl_internal_format = GL_RGBA32F_ARB; |
| 188 | } else if (format == GL_RGB) { |
| 189 | gl_internal_format = GL_RGB32F_ARB; |
| 190 | } |
| 191 | } else if (type == GL_HALF_FLOAT_OES) { |
| 192 | if (format == GL_RGBA) { |
| 193 | gl_internal_format = GL_RGBA16F_ARB; |
| 194 | } else if (format == GL_RGB) { |
| 195 | gl_internal_format = GL_RGB16F_ARB; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | glTexImage2D( |
| 200 | target, level, gl_internal_format, width, height, border, format, type, |
| 201 | pixels); |
| 202 | } |
| 203 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 204 | // Wrapper for glEnable/glDisable that doesn't suck. |
| 205 | static void EnableDisable(GLenum pname, bool enable) { |
| 206 | if (enable) { |
| 207 | glEnable(pname); |
| 208 | } else { |
| 209 | glDisable(pname); |
| 210 | } |
| 211 | } |
| 212 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 213 | // This class prevents any GL errors that occur when it is in scope from |
| 214 | // being reported to the client. |
| 215 | class ScopedGLErrorSuppressor { |
| 216 | public: |
| 217 | explicit ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder); |
| 218 | ~ScopedGLErrorSuppressor(); |
| 219 | private: |
| 220 | GLES2DecoderImpl* decoder_; |
| 221 | DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 222 | }; |
| 223 | |
| 224 | // Temporarily changes a decoder's bound 2D texture and restore it when this |
| 225 | // object goes out of scope. Also temporarily switches to using active texture |
| 226 | // unit zero in case the client has changed that to something invalid. |
| 227 | class ScopedTexture2DBinder { |
| 228 | public: |
| 229 | ScopedTexture2DBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 230 | ~ScopedTexture2DBinder(); |
| 231 | |
| 232 | private: |
| 233 | GLES2DecoderImpl* decoder_; |
| 234 | DISALLOW_COPY_AND_ASSIGN(ScopedTexture2DBinder); |
| 235 | }; |
| 236 | |
| 237 | // Temporarily changes a decoder's bound render buffer and restore it when this |
| 238 | // object goes out of scope. |
| 239 | class ScopedRenderBufferBinder { |
| 240 | public: |
| 241 | ScopedRenderBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 242 | ~ScopedRenderBufferBinder(); |
| 243 | |
| 244 | private: |
| 245 | GLES2DecoderImpl* decoder_; |
| 246 | DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder); |
| 247 | }; |
| 248 | |
| 249 | // Temporarily changes a decoder's bound frame buffer and restore it when this |
| 250 | // object goes out of scope. |
| 251 | class ScopedFrameBufferBinder { |
| 252 | public: |
| 253 | ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 254 | ~ScopedFrameBufferBinder(); |
| 255 | |
| 256 | private: |
| 257 | GLES2DecoderImpl* decoder_; |
| 258 | DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); |
| 259 | }; |
| 260 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 261 | // Temporarily changes a decoder's bound frame buffer to a resolved version of |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 262 | // the multisampled offscreen render buffer if that buffer is multisampled, and, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 263 | // if it is bound or enforce_internal_framebuffer is true. If internal is |
| 264 | // true, the resolved framebuffer is not visible to the parent. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 265 | class ScopedResolvedFrameBufferBinder { |
| 266 | public: |
[email protected] | e7e3803 | 2011-07-26 17:25:25 | [diff] [blame] | 267 | ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 268 | bool enforce_internal_framebuffer, |
| 269 | bool internal); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 270 | ~ScopedResolvedFrameBufferBinder(); |
| 271 | |
| 272 | private: |
| 273 | GLES2DecoderImpl* decoder_; |
| 274 | bool resolve_and_bind_; |
| 275 | DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
| 276 | }; |
| 277 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 278 | // Encapsulates an OpenGL texture. |
| 279 | class Texture { |
| 280 | public: |
| 281 | explicit Texture(GLES2DecoderImpl* decoder); |
| 282 | ~Texture(); |
| 283 | |
| 284 | // Create a new render texture. |
| 285 | void Create(); |
| 286 | |
| 287 | // Set the initial size and format of a render texture or resize it. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 288 | bool AllocateStorage(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 289 | |
| 290 | // Copy the contents of the currently bound frame buffer. |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 291 | void Copy(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 292 | |
| 293 | // Destroy the render texture. This must be explicitly called before |
| 294 | // destroying this object. |
| 295 | void Destroy(); |
| 296 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 297 | // Invalidate the texture. This can be used when a context is lost and it is |
| 298 | // not possible to make it current in order to free the resource. |
| 299 | void Invalidate(); |
| 300 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 301 | GLuint id() const { |
| 302 | return id_; |
| 303 | } |
| 304 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 305 | gfx::Size size() const { |
| 306 | return size_; |
| 307 | } |
| 308 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 309 | size_t estimated_size() const { |
| 310 | return estimated_size_; |
| 311 | } |
| 312 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 313 | private: |
| 314 | GLES2DecoderImpl* decoder_; |
| 315 | GLuint id_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 316 | gfx::Size size_; |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 317 | size_t estimated_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 318 | DISALLOW_COPY_AND_ASSIGN(Texture); |
| 319 | }; |
| 320 | |
| 321 | // Encapsulates an OpenGL render buffer of any format. |
| 322 | class RenderBuffer { |
| 323 | public: |
| 324 | explicit RenderBuffer(GLES2DecoderImpl* decoder); |
| 325 | ~RenderBuffer(); |
| 326 | |
| 327 | // Create a new render buffer. |
| 328 | void Create(); |
| 329 | |
| 330 | // Set the initial size and format of a render buffer or resize it. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 331 | bool AllocateStorage(const gfx::Size& size, GLenum format, GLsizei samples); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 332 | |
| 333 | // Destroy the render buffer. This must be explicitly called before destroying |
| 334 | // this object. |
| 335 | void Destroy(); |
| 336 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 337 | // Invalidate the render buffer. This can be used when a context is lost and |
| 338 | // it is not possible to make it current in order to free the resource. |
| 339 | void Invalidate(); |
| 340 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 341 | GLuint id() const { |
| 342 | return id_; |
| 343 | } |
| 344 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 345 | size_t estimated_size() const { |
| 346 | return estimated_size_; |
| 347 | } |
| 348 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 349 | private: |
| 350 | GLES2DecoderImpl* decoder_; |
| 351 | GLuint id_; |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 352 | size_t estimated_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 353 | DISALLOW_COPY_AND_ASSIGN(RenderBuffer); |
| 354 | }; |
| 355 | |
| 356 | // Encapsulates an OpenGL frame buffer. |
| 357 | class FrameBuffer { |
| 358 | public: |
| 359 | explicit FrameBuffer(GLES2DecoderImpl* decoder); |
| 360 | ~FrameBuffer(); |
| 361 | |
| 362 | // Create a new frame buffer. |
| 363 | void Create(); |
| 364 | |
| 365 | // Attach a color render buffer to a frame buffer. |
| 366 | void AttachRenderTexture(Texture* texture); |
| 367 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 368 | // Attach a render buffer to a frame buffer. Note that this unbinds any |
| 369 | // currently bound frame buffer. |
| 370 | void AttachRenderBuffer(GLenum target, RenderBuffer* render_buffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 371 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 372 | // Destroy the frame buffer. This must be explicitly called before destroying |
| 373 | // this object. |
| 374 | void Destroy(); |
| 375 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 376 | // Invalidate the frame buffer. This can be used when a context is lost and it |
| 377 | // is not possible to make it current in order to free the resource. |
| 378 | void Invalidate(); |
| 379 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 380 | // See glCheckFramebufferStatusEXT. |
| 381 | GLenum CheckStatus(); |
| 382 | |
| 383 | GLuint id() const { |
| 384 | return id_; |
| 385 | } |
| 386 | |
| 387 | private: |
| 388 | GLES2DecoderImpl* decoder_; |
| 389 | GLuint id_; |
| 390 | DISALLOW_COPY_AND_ASSIGN(FrameBuffer); |
| 391 | }; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 392 | |
| 393 | class ContextCreationAttribParser { |
| 394 | public: |
| 395 | ContextCreationAttribParser(); |
| 396 | bool Parse(const std::vector<int32>& attribs); |
| 397 | |
| 398 | // -1 if invalid or unspecified. |
| 399 | int32 alpha_size_; |
| 400 | int32 blue_size_; |
| 401 | int32 green_size_; |
| 402 | int32 red_size_; |
| 403 | int32 depth_size_; |
| 404 | int32 stencil_size_; |
| 405 | int32 samples_; |
| 406 | int32 sample_buffers_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 407 | bool buffer_preserved_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 408 | }; |
| 409 | |
| 410 | ContextCreationAttribParser::ContextCreationAttribParser() |
| 411 | : alpha_size_(-1), |
| 412 | blue_size_(-1), |
| 413 | green_size_(-1), |
| 414 | red_size_(-1), |
| 415 | depth_size_(-1), |
| 416 | stencil_size_(-1), |
| 417 | samples_(-1), |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 418 | sample_buffers_(-1), |
| 419 | buffer_preserved_(true) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | bool ContextCreationAttribParser::Parse(const std::vector<int32>& attribs) { |
| 423 | // From <EGL/egl.h>. |
| 424 | const int32 EGL_ALPHA_SIZE = 0x3021; |
| 425 | const int32 EGL_BLUE_SIZE = 0x3022; |
| 426 | const int32 EGL_GREEN_SIZE = 0x3023; |
| 427 | const int32 EGL_RED_SIZE = 0x3024; |
| 428 | const int32 EGL_DEPTH_SIZE = 0x3025; |
| 429 | const int32 EGL_STENCIL_SIZE = 0x3026; |
| 430 | const int32 EGL_SAMPLES = 0x3031; |
| 431 | const int32 EGL_SAMPLE_BUFFERS = 0x3032; |
| 432 | const int32 EGL_NONE = 0x3038; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 433 | const int32 EGL_SWAP_BEHAVIOR = 0x3093; |
| 434 | const int32 EGL_BUFFER_PRESERVED = 0x3094; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 435 | |
| 436 | for (size_t i = 0; i < attribs.size(); i += 2) { |
| 437 | const int32 attrib = attribs[i]; |
| 438 | if (i + 1 >= attribs.size()) { |
| 439 | if (attrib == EGL_NONE) |
| 440 | return true; |
| 441 | |
| 442 | DLOG(ERROR) << "Missing value after context creation attribute: " |
| 443 | << attrib; |
| 444 | return false; |
| 445 | } |
| 446 | |
| 447 | const int32 value = attribs[i+1]; |
| 448 | switch (attrib) { |
| 449 | case EGL_ALPHA_SIZE: |
| 450 | alpha_size_ = value; |
| 451 | break; |
| 452 | case EGL_BLUE_SIZE: |
| 453 | blue_size_ = value; |
| 454 | break; |
| 455 | case EGL_GREEN_SIZE: |
| 456 | green_size_ = value; |
| 457 | break; |
| 458 | case EGL_RED_SIZE: |
| 459 | red_size_ = value; |
| 460 | break; |
| 461 | case EGL_DEPTH_SIZE: |
| 462 | depth_size_ = value; |
| 463 | break; |
| 464 | case EGL_STENCIL_SIZE: |
| 465 | stencil_size_ = value; |
| 466 | break; |
| 467 | case EGL_SAMPLES: |
| 468 | samples_ = value; |
| 469 | break; |
| 470 | case EGL_SAMPLE_BUFFERS: |
| 471 | sample_buffers_ = value; |
| 472 | break; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 473 | case EGL_SWAP_BEHAVIOR: |
| 474 | buffer_preserved_ = value == EGL_BUFFER_PRESERVED; |
| 475 | break; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 476 | case EGL_NONE: |
| 477 | // Terminate list, even if more attributes. |
| 478 | return true; |
| 479 | default: |
| 480 | DLOG(ERROR) << "Invalid context creation attribute: " << attrib; |
| 481 | return false; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | return true; |
| 486 | } |
| 487 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 488 | // } // anonymous namespace. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 489 | |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 490 | bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
| 491 | uint32* service_texture_id) { |
| 492 | return false; |
| 493 | } |
| 494 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 495 | GLES2Decoder::GLES2Decoder() |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 496 | : debug_(false), |
[email protected] | b5d647c | 2012-02-10 01:41:32 | [diff] [blame^] | 497 | log_commands_(false), |
| 498 | log_synthesized_gl_errors_(true) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 501 | GLES2Decoder::~GLES2Decoder() { |
| 502 | } |
| 503 | |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 504 | bool GLES2Decoder::testing_force_is_angle_; |
| 505 | |
| 506 | void GLES2Decoder::set_testing_force_is_angle(bool force) { |
| 507 | testing_force_is_angle_ = force; |
| 508 | } |
| 509 | |
| 510 | bool GLES2Decoder::IsAngle() { |
| 511 | #if defined(OS_WIN) |
| 512 | return testing_force_is_angle_ || |
| 513 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; |
| 514 | #else |
| 515 | return testing_force_is_angle_; |
| 516 | #endif |
| 517 | } |
| 518 | |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 519 | // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
| 520 | // cmd stuff to outside this class. |
| 521 | class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, |
| 522 | public GLES2Decoder { |
| 523 | public: |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 524 | explicit GLES2DecoderImpl(ContextGroup* group); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 525 | ~GLES2DecoderImpl(); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 526 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 527 | // Overridden from AsyncAPIInterface. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 528 | virtual Error DoCommand(unsigned int command, |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 529 | unsigned int arg_count, |
| 530 | const void* args); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 531 | |
| 532 | // Overridden from AsyncAPIInterface. |
| 533 | virtual const char* GetCommandName(unsigned int command_id) const; |
| 534 | |
| 535 | // Overridden from GLES2Decoder. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 536 | virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 537 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 538 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 539 | const DisallowedFeatures& disallowed_features, |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 540 | const char* allowed_extensions, |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 541 | const std::vector<int32>& attribs); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 542 | virtual void Destroy(); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 543 | virtual bool SetParent(GLES2Decoder* parent_decoder, |
| 544 | uint32 parent_texture_id); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 545 | virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size); |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 546 | void UpdateParentTextureInfo(); |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 547 | virtual bool MakeCurrent(); |
[email protected] | a96a602 | 2011-11-04 00:58:12 | [diff] [blame] | 548 | virtual void ReleaseCurrent(); |
[email protected] | 56ac89b | 2010-03-17 21:16:55 | [diff] [blame] | 549 | virtual GLES2Util* GetGLES2Util() { return &util_; } |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 550 | virtual gfx::GLContext* GetGLContext() { return context_.get(); } |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 551 | virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 552 | virtual ContextGroup* GetContextGroup() { return group_.get(); } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 553 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 554 | virtual void SetGLError(GLenum error, const char* msg); |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 555 | virtual void SetResizeCallback( |
| 556 | const base::Callback<void(gfx::Size)>& callback); |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 557 | |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 558 | virtual void SetMsgCallback(const MsgCallback& callback); |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 559 | |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 560 | virtual void SetStreamTextureManager(StreamTextureManager* manager); |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 561 | virtual bool GetServiceTextureId(uint32 client_texture_id, |
| 562 | uint32* service_texture_id); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 563 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 564 | // Restores the current state to the user's settings. |
| 565 | void RestoreCurrentFramebufferBindings(); |
| 566 | void RestoreCurrentRenderbufferBindings(); |
| 567 | void RestoreCurrentTexture2DBindings(); |
| 568 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 569 | // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 570 | void ApplyDirtyState(); |
| 571 | |
| 572 | // These check the state of the currently bound framebuffer or the |
| 573 | // backbuffer if no framebuffer is bound. |
| 574 | bool BoundFramebufferHasColorAttachmentWithAlpha(); |
| 575 | bool BoundFramebufferHasDepthAttachment(); |
| 576 | bool BoundFramebufferHasStencilAttachment(); |
| 577 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 578 | virtual error::ContextLostReason GetContextLostReason(); |
| 579 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 580 | private: |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 581 | friend class ScopedGLErrorSuppressor; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 582 | friend class ScopedResolvedFrameBufferBinder; |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 583 | friend class Texture; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 584 | friend class RenderBuffer; |
| 585 | friend class FrameBuffer; |
| 586 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 587 | // State associated with each texture unit. |
| 588 | struct TextureUnit { |
| 589 | TextureUnit() : bind_target(GL_TEXTURE_2D) { } |
| 590 | |
| 591 | // The last target that was bound to this texture unit. |
| 592 | GLenum bind_target; |
| 593 | |
| 594 | // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture |
| 595 | TextureManager::TextureInfo::Ref bound_texture_2d; |
| 596 | |
| 597 | // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with |
| 598 | // glBindTexture |
| 599 | TextureManager::TextureInfo::Ref bound_texture_cube_map; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 600 | |
| 601 | // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with |
| 602 | // glBindTexture |
| 603 | TextureManager::TextureInfo::Ref bound_texture_external_oes; |
| 604 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 605 | // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with |
| 606 | // glBindTexture |
| 607 | TextureManager::TextureInfo::Ref bound_texture_rectangle_arb; |
| 608 | |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 609 | TextureManager::TextureInfo::Ref GetInfoForSamplerType(GLenum type) { |
| 610 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 611 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 612 | switch (type) { |
| 613 | case GL_SAMPLER_2D: |
| 614 | return bound_texture_2d; |
| 615 | case GL_SAMPLER_CUBE: |
| 616 | return bound_texture_cube_map; |
| 617 | case GL_SAMPLER_EXTERNAL_OES: |
| 618 | return bound_texture_external_oes; |
| 619 | case GL_SAMPLER_2D_RECT_ARB: |
| 620 | return bound_texture_rectangle_arb; |
| 621 | } |
| 622 | |
| 623 | NOTREACHED(); |
| 624 | return NULL; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 625 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 626 | |
| 627 | void Unbind(TextureManager::TextureInfo* texture) { |
| 628 | if (bound_texture_2d == texture) { |
| 629 | bound_texture_2d = NULL; |
| 630 | } |
| 631 | if (bound_texture_cube_map == texture) { |
| 632 | bound_texture_cube_map = NULL; |
| 633 | } |
| 634 | if (bound_texture_external_oes == texture) { |
| 635 | bound_texture_external_oes = NULL; |
| 636 | } |
| 637 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 638 | }; |
| 639 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 640 | // Initialize or re-initialize the shader translator. |
| 641 | bool InitializeShaderTranslator(); |
| 642 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 643 | void UpdateCapabilities(); |
| 644 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 645 | // Helpers for the glGen and glDelete functions. |
| 646 | bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 647 | void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 648 | bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 649 | void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 650 | bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 651 | void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 652 | bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
| 653 | void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 654 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 655 | // TODO(gman): Cache these pointers? |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 656 | BufferManager* buffer_manager() { |
| 657 | return group_->buffer_manager(); |
| 658 | } |
| 659 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 660 | RenderbufferManager* renderbuffer_manager() { |
| 661 | return group_->renderbuffer_manager(); |
| 662 | } |
| 663 | |
| 664 | FramebufferManager* framebuffer_manager() { |
| 665 | return group_->framebuffer_manager(); |
| 666 | } |
| 667 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 668 | ProgramManager* program_manager() { |
| 669 | return group_->program_manager(); |
| 670 | } |
| 671 | |
| 672 | ShaderManager* shader_manager() { |
| 673 | return group_->shader_manager(); |
| 674 | } |
| 675 | |
| 676 | TextureManager* texture_manager() { |
| 677 | return group_->texture_manager(); |
| 678 | } |
| 679 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 680 | bool IsOffscreenBufferMultisampled() const { |
| 681 | return offscreen_target_samples_ > 1; |
| 682 | } |
| 683 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 684 | // Creates a TextureInfo for the given texture. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 685 | TextureManager::TextureInfo* CreateTextureInfo( |
| 686 | GLuint client_id, GLuint service_id) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 687 | return texture_manager()->CreateTextureInfo(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | // Gets the texture info for the given texture. Returns NULL if none exists. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 691 | TextureManager::TextureInfo* GetTextureInfo(GLuint client_id) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 692 | TextureManager::TextureInfo* info = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 693 | texture_manager()->GetTextureInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 694 | return info; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | // Deletes the texture info for the given texture. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 698 | void RemoveTextureInfo(GLuint client_id) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 699 | texture_manager()->RemoveTextureInfo(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 700 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 701 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 702 | // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 703 | // or regular back buffer). |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 704 | gfx::Size GetBoundReadFrameBufferSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 705 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 706 | // Get the format of the currently bound frame buffer (either FBO or regular |
| 707 | // back buffer) |
| 708 | GLenum GetBoundReadFrameBufferInternalFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 709 | GLenum GetBoundDrawFrameBufferInternalFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 710 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 711 | // Wrapper for CompressedTexImage2D commands. |
| 712 | error::Error DoCompressedTexImage2D( |
| 713 | GLenum target, |
| 714 | GLint level, |
| 715 | GLenum internal_format, |
| 716 | GLsizei width, |
| 717 | GLsizei height, |
| 718 | GLint border, |
| 719 | GLsizei image_size, |
| 720 | const void* data); |
| 721 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 722 | // Wrapper for CompressedTexSubImage2D. |
| 723 | void DoCompressedTexSubImage2D( |
| 724 | GLenum target, |
| 725 | GLint level, |
| 726 | GLint xoffset, |
| 727 | GLint yoffset, |
| 728 | GLsizei width, |
| 729 | GLsizei height, |
| 730 | GLenum format, |
| 731 | GLsizei imageSize, |
| 732 | const void * data); |
| 733 | |
| 734 | // Wrapper for CopyTexImage2D. |
| 735 | void DoCopyTexImage2D( |
| 736 | GLenum target, |
| 737 | GLint level, |
| 738 | GLenum internal_format, |
| 739 | GLint x, |
| 740 | GLint y, |
| 741 | GLsizei width, |
| 742 | GLsizei height, |
| 743 | GLint border); |
| 744 | |
| 745 | // Wrapper for CopyTexSubImage2D. |
| 746 | void DoCopyTexSubImage2D( |
| 747 | GLenum target, |
| 748 | GLint level, |
| 749 | GLint xoffset, |
| 750 | GLint yoffset, |
| 751 | GLint x, |
| 752 | GLint y, |
| 753 | GLsizei width, |
| 754 | GLsizei height); |
| 755 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 756 | // Wrapper for TexImage2D commands. |
| 757 | error::Error DoTexImage2D( |
| 758 | GLenum target, |
| 759 | GLint level, |
| 760 | GLenum internal_format, |
| 761 | GLsizei width, |
| 762 | GLsizei height, |
| 763 | GLint border, |
| 764 | GLenum format, |
| 765 | GLenum type, |
| 766 | const void* pixels, |
| 767 | uint32 pixels_size); |
| 768 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 769 | // Wrapper for TexSubImage2D. |
| 770 | void DoTexSubImage2D( |
| 771 | GLenum target, |
| 772 | GLint level, |
| 773 | GLint xoffset, |
| 774 | GLint yoffset, |
| 775 | GLsizei width, |
| 776 | GLsizei height, |
| 777 | GLenum format, |
| 778 | GLenum type, |
| 779 | const void * data); |
| 780 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 781 | // Wrapper for TexImageIOSurface2DCHROMIUM. |
| 782 | void DoTexImageIOSurface2DCHROMIUM( |
| 783 | GLenum target, |
| 784 | GLsizei width, |
| 785 | GLsizei height, |
| 786 | GLuint io_surface_id, |
| 787 | GLuint plane); |
| 788 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 789 | // Wrapper for TexStorage2DEXT. |
| 790 | void DoTexStorage2DEXT( |
| 791 | GLenum target, |
| 792 | GLint levels, |
| 793 | GLenum internal_format, |
| 794 | GLsizei width, |
| 795 | GLsizei height); |
| 796 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 797 | // Creates a ProgramInfo for the given program. |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 798 | ProgramManager::ProgramInfo* CreateProgramInfo( |
| 799 | GLuint client_id, GLuint service_id) { |
| 800 | return program_manager()->CreateProgramInfo(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 801 | } |
| 802 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 803 | // Gets the program info for the given program. Returns NULL if none exists. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 804 | ProgramManager::ProgramInfo* GetProgramInfo(GLuint client_id) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 805 | return program_manager()->GetProgramInfo(client_id); |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 806 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 807 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 808 | // Gets the program info for the given program. If it's not a program |
| 809 | // generates a GL error. Returns NULL if not program. |
| 810 | ProgramManager::ProgramInfo* GetProgramInfoNotShader( |
| 811 | GLuint client_id, const char* function_name) { |
| 812 | ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); |
| 813 | if (!info) { |
| 814 | if (GetShaderInfo(client_id)) { |
| 815 | SetGLError(GL_INVALID_OPERATION, |
| 816 | (std::string(function_name) + |
| 817 | ": shader passed for program").c_str()); |
| 818 | } else { |
| 819 | SetGLError(GL_INVALID_VALUE, |
| 820 | (std::string(function_name) + ": unknown program").c_str()); |
| 821 | } |
| 822 | } |
| 823 | return info; |
| 824 | } |
| 825 | |
| 826 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 827 | // Creates a ShaderInfo for the given shader. |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 828 | ShaderManager::ShaderInfo* CreateShaderInfo( |
| 829 | GLuint client_id, |
| 830 | GLuint service_id, |
| 831 | GLenum shader_type) { |
| 832 | return shader_manager()->CreateShaderInfo( |
| 833 | client_id, service_id, shader_type); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | // Gets the shader info for the given shader. Returns NULL if none exists. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 837 | ShaderManager::ShaderInfo* GetShaderInfo(GLuint client_id) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 838 | return shader_manager()->GetShaderInfo(client_id); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 839 | } |
| 840 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 841 | // Gets the shader info for the given shader. If it's not a shader generates a |
| 842 | // GL error. Returns NULL if not shader. |
| 843 | ShaderManager::ShaderInfo* GetShaderInfoNotProgram( |
| 844 | GLuint client_id, const char* function_name) { |
| 845 | ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); |
| 846 | if (!info) { |
| 847 | if (GetProgramInfo(client_id)) { |
| 848 | SetGLError( |
| 849 | GL_INVALID_OPERATION, |
| 850 | (std::string(function_name) + |
| 851 | ": program passed for shader").c_str()); |
| 852 | } else { |
| 853 | SetGLError(GL_INVALID_VALUE, |
| 854 | (std::string(function_name) + ": unknown shader").c_str()); |
| 855 | } |
| 856 | } |
| 857 | return info; |
| 858 | } |
| 859 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 860 | // Creates a buffer info for the given buffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 861 | void CreateBufferInfo(GLuint client_id, GLuint service_id) { |
| 862 | return buffer_manager()->CreateBufferInfo(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 863 | } |
| 864 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 865 | // Gets the buffer info for the given buffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 866 | BufferManager::BufferInfo* GetBufferInfo(GLuint client_id) { |
| 867 | BufferManager::BufferInfo* info = |
| 868 | buffer_manager()->GetBufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 869 | return info; |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 870 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 871 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 872 | // Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used |
| 873 | // on glDeleteBuffers so we can make sure the user does not try to render |
| 874 | // with deleted buffers. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 875 | void RemoveBufferInfo(GLuint client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 876 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 877 | // Creates a framebuffer info for the given framebuffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 878 | void CreateFramebufferInfo(GLuint client_id, GLuint service_id) { |
| 879 | return framebuffer_manager()->CreateFramebufferInfo(client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // Gets the framebuffer info for the given framebuffer. |
| 883 | FramebufferManager::FramebufferInfo* GetFramebufferInfo( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 884 | GLuint client_id) { |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 885 | FramebufferManager::FramebufferInfo* info = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 886 | framebuffer_manager()->GetFramebufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 887 | return info; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | // Removes the framebuffer info for the given framebuffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 891 | void RemoveFramebufferInfo(GLuint client_id) { |
| 892 | framebuffer_manager()->RemoveFramebufferInfo(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | // Creates a renderbuffer info for the given renderbuffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 896 | void CreateRenderbufferInfo(GLuint client_id, GLuint service_id) { |
| 897 | return renderbuffer_manager()->CreateRenderbufferInfo( |
| 898 | client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | // Gets the renderbuffer info for the given renderbuffer. |
| 902 | RenderbufferManager::RenderbufferInfo* GetRenderbufferInfo( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 903 | GLuint client_id) { |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 904 | RenderbufferManager::RenderbufferInfo* info = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 905 | renderbuffer_manager()->GetRenderbufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 906 | return info; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | // Removes the renderbuffer info for the given renderbuffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 910 | void RemoveRenderbufferInfo(GLuint client_id) { |
| 911 | renderbuffer_manager()->RemoveRenderbufferInfo(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 912 | } |
| 913 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 914 | void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name); |
| 915 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 916 | error::Error GetAttribLocationHelper( |
| 917 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 918 | const std::string& name_str); |
| 919 | |
| 920 | error::Error GetUniformLocationHelper( |
| 921 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 922 | const std::string& name_str); |
| 923 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 924 | // Helper for glShaderSource. |
| 925 | error::Error ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 926 | GLuint client_id, const char* data, uint32 data_size); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 927 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 928 | // Clear any textures used by the current program. |
| 929 | bool ClearUnclearedTextures(); |
| 930 | |
| 931 | // Clear any uncleared level in texture. |
| 932 | // Returns false if there was a generated GL error. |
| 933 | bool ClearTexture(TextureManager::TextureInfo* info); |
| 934 | |
| 935 | // Clears any uncleared attachments attached to the given frame buffer. |
| 936 | // Returns false if there was a generated GL error. |
| 937 | void ClearUnclearedAttachments( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 938 | GLenum target, FramebufferManager::FramebufferInfo* info); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 939 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 940 | // overridden from GLES2Decoder |
| 941 | virtual bool ClearLevel( |
| 942 | unsigned service_id, |
| 943 | unsigned bind_target, |
| 944 | unsigned target, |
| 945 | int level, |
| 946 | unsigned format, |
| 947 | unsigned type, |
| 948 | int width, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 949 | int height, |
| 950 | bool is_texture_immutable); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 951 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 952 | // Restore all GL state that affects clearing. |
| 953 | void RestoreClearState(); |
| 954 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 955 | // Remembers the state of some capabilities. |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 956 | // Returns: true if glEnable/glDisable should actually be called. |
| 957 | bool SetCapabilityState(GLenum cap, bool enabled); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 958 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 959 | // Check that the currently bound framebuffers are valid. |
| 960 | // Generates GL error if not. |
| 961 | bool CheckBoundFramebuffersValid(const char* func_name); |
| 962 | |
| 963 | // Check if a framebuffer meets our requirements. |
| 964 | bool CheckFramebufferValid( |
| 965 | FramebufferManager::FramebufferInfo* framebuffer, |
| 966 | GLenum target, |
| 967 | const char* func_name); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 968 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 969 | // Checks if the current program exists and is valid. If not generates the |
| 970 | // appropriate GL error. Returns true if the current program is in a usable |
| 971 | // state. |
| 972 | bool CheckCurrentProgram(const char* function_name); |
| 973 | |
| 974 | // Checks if the current program exists and is valid and that location is not |
| 975 | // -1. If the current program is not valid generates the appropriate GL |
| 976 | // error. Returns true if the current program is in a usable state and |
| 977 | // location is not -1. |
| 978 | bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
| 979 | |
| 980 | // Gets the type of a uniform for a location in the current program. Sets GL |
| 981 | // errors if the current program is not valid. Returns true if the current |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 982 | // program is valid and the location exists. Adjusts count so it |
| 983 | // does not overflow the uniform. |
| 984 | bool PrepForSetUniformByLocation( |
| 985 | GLint location, const char* function_name, GLenum* type, GLsizei* count); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 986 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 987 | // Gets the service id for any simulated backbuffer fbo. |
| 988 | GLuint GetBackbufferServiceId(); |
| 989 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 990 | // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv |
| 991 | bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); |
| 992 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 993 | // Wrapper for glCreateProgram |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 994 | bool CreateProgramHelper(GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 995 | |
| 996 | // Wrapper for glCreateShader |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 997 | bool CreateShaderHelper(GLenum type, GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 998 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 999 | // Wrapper for glActiveTexture |
| 1000 | void DoActiveTexture(GLenum texture_unit); |
| 1001 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1002 | // Wrapper for glAttachShader |
| 1003 | void DoAttachShader(GLuint client_program_id, GLint client_shader_id); |
| 1004 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1005 | // Wrapper for glBindBuffer since we need to track the current targets. |
| 1006 | void DoBindBuffer(GLenum target, GLuint buffer); |
| 1007 | |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1008 | // Wrapper for glBindFramebuffer since we need to track the current targets. |
| 1009 | void DoBindFramebuffer(GLenum target, GLuint framebuffer); |
| 1010 | |
| 1011 | // Wrapper for glBindRenderbuffer since we need to track the current targets. |
| 1012 | void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); |
| 1013 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1014 | // Wrapper for glBindTexture since we need to track the current targets. |
| 1015 | void DoBindTexture(GLenum target, GLuint texture); |
| 1016 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1017 | // Wrapper for glBlitFramebufferEXT. |
| 1018 | void DoBlitFramebufferEXT( |
| 1019 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 1020 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1021 | GLbitfield mask, GLenum filter); |
| 1022 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1023 | // Wrapper for glBufferData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1024 | void DoBufferData( |
| 1025 | GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); |
| 1026 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1027 | // Wrapper for glBufferSubData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1028 | void DoBufferSubData( |
| 1029 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 1030 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1031 | // Wrapper for glCheckFramebufferStatus |
| 1032 | GLenum DoCheckFramebufferStatus(GLenum target); |
| 1033 | |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1034 | // Wrapper for glClear |
| 1035 | void DoClear(GLbitfield mask); |
| 1036 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1037 | // Wrappers for clear and mask settings functions. |
| 1038 | void DoClearColor( |
| 1039 | GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); |
| 1040 | void DoClearDepthf(GLclampf depth); |
| 1041 | void DoClearStencil(GLint s); |
| 1042 | void DoColorMask( |
| 1043 | GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); |
| 1044 | void DoDepthMask(GLboolean depth); |
| 1045 | void DoStencilMask(GLuint mask); |
| 1046 | void DoStencilMaskSeparate(GLenum face, GLuint mask); |
| 1047 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1048 | // Wrapper for glCompileShader. |
| 1049 | void DoCompileShader(GLuint shader); |
| 1050 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1051 | // Helper for DeleteSharedIdsCHROMIUM commands. |
| 1052 | void DoDeleteSharedIdsCHROMIUM( |
| 1053 | GLuint namespace_id, GLsizei n, const GLuint* ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1054 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1055 | // Wrapper for glDetachShader |
| 1056 | void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
| 1057 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1058 | // Wrapper for glDisable |
| 1059 | void DoDisable(GLenum cap); |
| 1060 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1061 | // Wrapper for glDisableVertexAttribArray. |
| 1062 | void DoDisableVertexAttribArray(GLuint index); |
| 1063 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1064 | // Wrapper for glEnable |
| 1065 | void DoEnable(GLenum cap); |
| 1066 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1067 | // Wrapper for glEnableVertexAttribArray. |
| 1068 | void DoEnableVertexAttribArray(GLuint index); |
| 1069 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1070 | // Wrapper for glFramebufferRenderbufffer. |
| 1071 | void DoFramebufferRenderbuffer( |
| 1072 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
| 1073 | GLuint renderbuffer); |
| 1074 | |
| 1075 | // Wrapper for glFramebufferTexture2D. |
| 1076 | void DoFramebufferTexture2D( |
| 1077 | GLenum target, GLenum attachment, GLenum textarget, GLuint texture, |
| 1078 | GLint level); |
| 1079 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1080 | // Wrapper for glGenerateMipmap |
| 1081 | void DoGenerateMipmap(GLenum target); |
| 1082 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1083 | // Helper for GenSharedIdsCHROMIUM commands. |
| 1084 | void DoGenSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1085 | GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids); |
| 1086 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1087 | // Wrapper for DoGetBooleanv. |
| 1088 | void DoGetBooleanv(GLenum pname, GLboolean* params); |
| 1089 | |
| 1090 | // Wrapper for DoGetFloatv. |
| 1091 | void DoGetFloatv(GLenum pname, GLfloat* params); |
| 1092 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1093 | // Wrapper for glGetFramebufferAttachmentParameteriv. |
| 1094 | void DoGetFramebufferAttachmentParameteriv( |
| 1095 | GLenum target, GLenum attachment, GLenum pname, GLint* params); |
| 1096 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1097 | // Wrapper for glGetIntegerv. |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1098 | void DoGetIntegerv(GLenum pname, GLint* params); |
| 1099 | |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1100 | // Gets the max value in a range in a buffer. |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1101 | GLuint DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1102 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); |
| 1103 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1104 | // Wrapper for glGetProgramiv. |
| 1105 | void DoGetProgramiv( |
| 1106 | GLuint program_id, GLenum pname, GLint* params); |
| 1107 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1108 | // Wrapper for glRenderbufferParameteriv. |
| 1109 | void DoGetRenderbufferParameteriv( |
| 1110 | GLenum target, GLenum pname, GLint* params); |
| 1111 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 1112 | // Wrapper for glGetShaderiv |
| 1113 | void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
| 1114 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1115 | // Wrappers for glGetVertexAttrib. |
| 1116 | void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); |
| 1117 | void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); |
| 1118 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1119 | // Wrappers for glIsXXX functions. |
| 1120 | bool DoIsBuffer(GLuint client_id); |
| 1121 | bool DoIsFramebuffer(GLuint client_id); |
| 1122 | bool DoIsProgram(GLuint client_id); |
| 1123 | bool DoIsRenderbuffer(GLuint client_id); |
| 1124 | bool DoIsShader(GLuint client_id); |
| 1125 | bool DoIsTexture(GLuint client_id); |
| 1126 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1127 | // Wrapper for glLinkProgram |
| 1128 | void DoLinkProgram(GLuint program); |
| 1129 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1130 | // Helper for RegisterSharedIdsCHROMIUM. |
| 1131 | void DoRegisterSharedIdsCHROMIUM( |
| 1132 | GLuint namespace_id, GLsizei n, const GLuint* ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1133 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1134 | // Wrapper for glRenderbufferStorage. |
| 1135 | void DoRenderbufferStorage( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1136 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1137 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1138 | // Wrapper for glRenderbufferStorageMultisampleEXT. |
| 1139 | void DoRenderbufferStorageMultisample( |
| 1140 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1141 | GLsizei width, GLsizei height); |
| 1142 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1143 | // Wrapper for glReleaseShaderCompiler. |
| 1144 | void DoReleaseShaderCompiler() { } |
| 1145 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1146 | // Wrappers for glTexParameter functions. |
| 1147 | void DoTexParameterf(GLenum target, GLenum pname, GLfloat param); |
| 1148 | void DoTexParameteri(GLenum target, GLenum pname, GLint param); |
| 1149 | void DoTexParameterfv(GLenum target, GLenum pname, const GLfloat* params); |
| 1150 | void DoTexParameteriv(GLenum target, GLenum pname, const GLint* params); |
| 1151 | |
| 1152 | // Wrappers for glUniform1i and glUniform1iv as according to the GLES2 |
| 1153 | // spec only these 2 functions can be used to set sampler uniforms. |
| 1154 | void DoUniform1i(GLint location, GLint v0); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1155 | void DoUniform1iv(GLint location, GLsizei count, const GLint* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1156 | void DoUniform2iv(GLint location, GLsizei count, const GLint* value); |
| 1157 | void DoUniform3iv(GLint location, GLsizei count, const GLint* value); |
| 1158 | void DoUniform4iv(GLint location, GLsizei count, const GLint* value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1159 | |
| 1160 | // Wrappers for glUniformfv because some drivers don't correctly accept |
| 1161 | // bool uniforms. |
| 1162 | void DoUniform1fv(GLint location, GLsizei count, const GLfloat* value); |
| 1163 | void DoUniform2fv(GLint location, GLsizei count, const GLfloat* value); |
| 1164 | void DoUniform3fv(GLint location, GLsizei count, const GLfloat* value); |
| 1165 | void DoUniform4fv(GLint location, GLsizei count, const GLfloat* value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1166 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1167 | void DoUniformMatrix2fv( |
| 1168 | GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); |
| 1169 | void DoUniformMatrix3fv( |
| 1170 | GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); |
| 1171 | void DoUniformMatrix4fv( |
| 1172 | GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); |
| 1173 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1174 | // Wrappers for glVertexAttrib?? |
| 1175 | void DoVertexAttrib1f(GLuint index, GLfloat v0); |
| 1176 | void DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1); |
| 1177 | void DoVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); |
| 1178 | void DoVertexAttrib4f( |
| 1179 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); |
| 1180 | void DoVertexAttrib1fv(GLuint index, const GLfloat *v); |
| 1181 | void DoVertexAttrib2fv(GLuint index, const GLfloat *v); |
| 1182 | void DoVertexAttrib3fv(GLuint index, const GLfloat *v); |
| 1183 | void DoVertexAttrib4fv(GLuint index, const GLfloat *v); |
| 1184 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1185 | // Wrapper for glUseProgram |
| 1186 | void DoUseProgram(GLuint program); |
| 1187 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1188 | // Wrapper for glValidateProgram. |
| 1189 | void DoValidateProgram(GLuint program_client_id); |
| 1190 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 1191 | // Gets the number of values that will be returned by glGetXXX. Returns |
| 1192 | // false if pname is unknown. |
| 1193 | bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); |
| 1194 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1195 | // Gets the GLError through our wrapper. |
| 1196 | GLenum GetGLError(); |
| 1197 | |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 1198 | // Gets the GLError and stores it in our wrapper. Effectively |
| 1199 | // this lets us peek at the error without losing it. |
| 1200 | GLenum PeekGLError(); |
| 1201 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1202 | // Copies the real GL errors to the wrapper. This is so we can |
| 1203 | // make sure there are no native GL errors before calling some GL function |
| 1204 | // so that on return we know any error generated was for that specific |
| 1205 | // command. |
| 1206 | void CopyRealGLErrorsToWrapper(); |
| 1207 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1208 | // Clear all real GL errors. This is to prevent the client from seeing any |
| 1209 | // errors caused by GL calls that it was not responsible for issuing. |
| 1210 | void ClearRealGLErrors(); |
| 1211 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1212 | // Checks if the current program and vertex attributes are valid for drawing. |
| 1213 | bool IsDrawValid(GLuint max_vertex_accessed); |
| 1214 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 1215 | // Returns true if successful, simulated will be true if attrib0 was |
| 1216 | // simulated. |
| 1217 | bool SimulateAttrib0(GLuint max_vertex_accessed, bool* simulated); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1218 | void RestoreStateForSimulatedAttrib0(); |
| 1219 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 1220 | // Returns true if textures were set. |
| 1221 | bool SetBlackTextureForNonRenderableTextures(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1222 | void RestoreStateForNonRenderableTextures(); |
| 1223 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1224 | // Returns true if GL_FIXED attribs were simulated. |
| 1225 | bool SimulateFixedAttribs(GLuint max_vertex_accessed, bool* simulated); |
| 1226 | void RestoreStateForSimulatedFixedAttribs(); |
| 1227 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1228 | // Gets the buffer id for a given target. |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1229 | BufferManager::BufferInfo* GetBufferInfoForTarget(GLenum target) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1230 | DCHECK(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1231 | BufferManager::BufferInfo* info = target == GL_ARRAY_BUFFER ? |
| 1232 | bound_array_buffer_ : bound_element_array_buffer_; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 1233 | return info; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1234 | } |
| 1235 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1236 | // Gets the texture id for a given target. |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1237 | TextureManager::TextureInfo* GetTextureInfoForTarget(GLenum target) { |
| 1238 | TextureUnit& unit = texture_units_[active_texture_unit_]; |
| 1239 | TextureManager::TextureInfo* info = NULL; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1240 | switch (target) { |
| 1241 | case GL_TEXTURE_2D: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1242 | info = unit.bound_texture_2d; |
| 1243 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1244 | case GL_TEXTURE_CUBE_MAP: |
| 1245 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1246 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1247 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1248 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1249 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1250 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1251 | info = unit.bound_texture_cube_map; |
| 1252 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1253 | case GL_TEXTURE_EXTERNAL_OES: |
| 1254 | info = unit.bound_texture_external_oes; |
| 1255 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1256 | case GL_TEXTURE_RECTANGLE_ARB: |
| 1257 | info = unit.bound_texture_rectangle_arb; |
| 1258 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1259 | default: |
| 1260 | NOTREACHED(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1261 | return NULL; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1262 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 1263 | return info; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1264 | } |
| 1265 | |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1266 | GLenum GetBindTargetForSamplerType(GLenum type) { |
| 1267 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1268 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 1269 | switch (type) { |
| 1270 | case GL_SAMPLER_2D: |
| 1271 | return GL_TEXTURE_2D; |
| 1272 | case GL_SAMPLER_CUBE: |
| 1273 | return GL_TEXTURE_CUBE_MAP; |
| 1274 | case GL_SAMPLER_EXTERNAL_OES: |
| 1275 | return GL_TEXTURE_EXTERNAL_OES; |
| 1276 | case GL_SAMPLER_2D_RECT_ARB: |
| 1277 | return GL_TEXTURE_RECTANGLE_ARB; |
| 1278 | } |
| 1279 | |
| 1280 | NOTREACHED(); |
| 1281 | return 0; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1282 | } |
| 1283 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1284 | // Gets the framebuffer info for a particular target. |
| 1285 | FramebufferManager::FramebufferInfo* GetFramebufferInfoForTarget( |
| 1286 | GLenum target) { |
| 1287 | FramebufferManager::FramebufferInfo* info = NULL; |
| 1288 | switch (target) { |
| 1289 | case GL_FRAMEBUFFER: |
| 1290 | case GL_DRAW_FRAMEBUFFER: |
| 1291 | info = bound_draw_framebuffer_; |
| 1292 | break; |
| 1293 | case GL_READ_FRAMEBUFFER: |
| 1294 | info = bound_read_framebuffer_; |
| 1295 | break; |
| 1296 | default: |
| 1297 | NOTREACHED(); |
| 1298 | break; |
| 1299 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 1300 | return info; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1301 | } |
| 1302 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1303 | RenderbufferManager::RenderbufferInfo* GetRenderbufferInfoForTarget( |
| 1304 | GLenum target) { |
| 1305 | RenderbufferManager::RenderbufferInfo* info = NULL; |
| 1306 | switch (target) { |
| 1307 | case GL_RENDERBUFFER: |
| 1308 | info = bound_renderbuffer_; |
| 1309 | break; |
| 1310 | default: |
| 1311 | NOTREACHED(); |
| 1312 | break; |
| 1313 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 1314 | return info; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1315 | } |
| 1316 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1317 | // Validates the program and location for a glGetUniform call and returns |
| 1318 | // a SizeResult setup to receive the result. Returns true if glGetUniform |
| 1319 | // should be called. |
| 1320 | bool GetUniformSetup( |
| 1321 | GLuint program, GLint location, |
| 1322 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1323 | error::Error* error, GLuint* service_id, void** result, |
| 1324 | GLenum* result_type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1325 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1326 | // Computes the estimated memory used for the backbuffer and passes it to |
| 1327 | // the tracing system. |
| 1328 | void UpdateBackbufferMemoryAccounting(); |
| 1329 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1330 | // Returns true if the context was just lost due to e.g. GL_ARB_robustness. |
| 1331 | bool WasContextLost(); |
| 1332 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1333 | #if defined(OS_MACOSX) |
| 1334 | void ReleaseIOSurfaceForTexture(GLuint texture_id); |
| 1335 | #endif |
| 1336 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1337 | // Generate a member function prototype for each command in an automated and |
| 1338 | // typesafe way. |
| 1339 | #define GLES2_CMD_OP(name) \ |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 1340 | Error Handle ## name( \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 1341 | uint32 immediate_data_size, \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1342 | const gles2::name& args); \ |
| 1343 | |
| 1344 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1345 | |
| 1346 | #undef GLES2_CMD_OP |
| 1347 | |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 1348 | // The GL context this decoder renders to on behalf of the client. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1349 | scoped_refptr<gfx::GLSurface> surface_; |
| 1350 | scoped_refptr<gfx::GLContext> context_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1351 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1352 | // The ContextGroup for this decoder uses to track resources. |
| 1353 | ContextGroup::Ref group_; |
| 1354 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1355 | // A parent decoder can access this decoders saved offscreen frame buffer. |
| 1356 | // The parent pointer is reset if the parent is destroyed. |
| 1357 | base::WeakPtr<GLES2DecoderImpl> parent_; |
| 1358 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1359 | // Current width and height of the offscreen frame buffer. |
| 1360 | gfx::Size offscreen_size_; |
| 1361 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1362 | // Current GL error bits. |
| 1363 | uint32 error_bits_; |
| 1364 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1365 | // Util to help with GL. |
| 1366 | GLES2Util util_; |
| 1367 | |
| 1368 | // pack alignment as last set by glPixelStorei |
| 1369 | GLint pack_alignment_; |
| 1370 | |
| 1371 | // unpack alignment as last set by glPixelStorei |
| 1372 | GLint unpack_alignment_; |
| 1373 | |
| 1374 | // The currently bound array buffer. If this is 0 it is illegal to call |
| 1375 | // glVertexAttribPointer. |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1376 | BufferManager::BufferInfo::Ref bound_array_buffer_; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1377 | |
| 1378 | // The currently bound element array buffer. If this is 0 it is illegal |
| 1379 | // to call glDrawElements. |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1380 | BufferManager::BufferInfo::Ref bound_element_array_buffer_; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1381 | |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 1382 | // Class that manages vertex attribs. |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 1383 | scoped_ptr<VertexAttribManager> vertex_attrib_manager_; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1384 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1385 | // The buffer we bind to attrib 0 since OpenGL requires it (ES does not). |
| 1386 | GLuint attrib_0_buffer_id_; |
| 1387 | |
| 1388 | // The value currently in attrib_0. |
| 1389 | VertexAttribManager::VertexAttribInfo::Vec4 attrib_0_value_; |
| 1390 | |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1391 | // Whether or not the attrib_0 buffer holds the attrib_0_value. |
| 1392 | bool attrib_0_buffer_matches_value_; |
| 1393 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1394 | // The size of attrib 0. |
| 1395 | GLsizei attrib_0_size_; |
| 1396 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1397 | // The buffer used to simulate GL_FIXED attribs. |
| 1398 | GLuint fixed_attrib_buffer_id_; |
| 1399 | |
| 1400 | // The size of fiixed attrib buffer. |
| 1401 | GLsizei fixed_attrib_buffer_size_; |
| 1402 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1403 | // Current active texture by 0 - n index. |
| 1404 | // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would |
| 1405 | // be 2. |
| 1406 | GLuint active_texture_unit_; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1407 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1408 | // Which textures are bound to texture units through glActiveTexture. |
| 1409 | scoped_array<TextureUnit> texture_units_; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1410 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1411 | // state saved for clearing so we can clear render buffers and then |
| 1412 | // restore to these values. |
| 1413 | GLclampf clear_red_; |
| 1414 | GLclampf clear_green_; |
| 1415 | GLclampf clear_blue_; |
| 1416 | GLclampf clear_alpha_; |
| 1417 | GLboolean mask_red_; |
| 1418 | GLboolean mask_green_; |
| 1419 | GLboolean mask_blue_; |
| 1420 | GLboolean mask_alpha_; |
| 1421 | GLint clear_stencil_; |
| 1422 | GLuint mask_stencil_front_; |
| 1423 | GLuint mask_stencil_back_; |
| 1424 | GLclampf clear_depth_; |
| 1425 | GLboolean mask_depth_; |
| 1426 | bool enable_scissor_test_; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1427 | bool enable_depth_test_; |
| 1428 | bool enable_stencil_test_; |
| 1429 | bool state_dirty_; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1430 | |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 1431 | // The program in use by glUseProgram |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1432 | ProgramManager::ProgramInfo::Ref current_program_; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1433 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1434 | // The currently bound framebuffers |
| 1435 | FramebufferManager::FramebufferInfo::Ref bound_read_framebuffer_; |
| 1436 | FramebufferManager::FramebufferInfo::Ref bound_draw_framebuffer_; |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1437 | |
| 1438 | // The currently bound renderbuffer |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 1439 | RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer_; |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1440 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1441 | // The offscreen frame buffer that the client renders to. With EGL, the |
| 1442 | // depth and stencil buffers are separate. With regular GL there is a single |
| 1443 | // packed depth stencil buffer in offscreen_target_depth_render_buffer_. |
| 1444 | // offscreen_target_stencil_render_buffer_ is unused. |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1445 | scoped_ptr<FrameBuffer> offscreen_target_frame_buffer_; |
| 1446 | scoped_ptr<Texture> offscreen_target_color_texture_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1447 | scoped_ptr<RenderBuffer> offscreen_target_color_render_buffer_; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1448 | scoped_ptr<RenderBuffer> offscreen_target_depth_render_buffer_; |
| 1449 | scoped_ptr<RenderBuffer> offscreen_target_stencil_render_buffer_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1450 | GLenum offscreen_target_color_format_; |
| 1451 | GLenum offscreen_target_depth_format_; |
| 1452 | GLenum offscreen_target_stencil_format_; |
| 1453 | GLsizei offscreen_target_samples_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1454 | GLboolean offscreen_target_buffer_preserved_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1455 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1456 | // The copy that is saved when SwapBuffers is called. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1457 | scoped_ptr<FrameBuffer> offscreen_saved_frame_buffer_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1458 | scoped_ptr<Texture> offscreen_saved_color_texture_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1459 | TextureManager::TextureInfo::Ref offscreen_saved_color_texture_info_; |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1460 | |
| 1461 | // The copy that is used as the destination for multi-sample resolves. |
| 1462 | scoped_ptr<FrameBuffer> offscreen_resolved_frame_buffer_; |
| 1463 | scoped_ptr<Texture> offscreen_resolved_color_texture_; |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1464 | GLenum offscreen_saved_color_format_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1465 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 1466 | base::Callback<void(gfx::Size)> resize_callback_; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 1467 | |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 1468 | MsgCallback msg_callback_; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 1469 | |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1470 | StreamTextureManager* stream_texture_manager_; |
| 1471 | |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1472 | // The format of the back buffer_ |
| 1473 | GLenum back_buffer_color_format_; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1474 | bool back_buffer_has_depth_; |
| 1475 | bool back_buffer_has_stencil_; |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1476 | |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1477 | bool teximage2d_faster_than_texsubimage2d_; |
| 1478 | bool bufferdata_faster_than_buffersubdata_; |
| 1479 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 1480 | // The last error message set. |
| 1481 | std::string last_error_; |
| 1482 | |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1483 | // The current decoder error. |
| 1484 | error::Error current_decoder_error_; |
| 1485 | |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1486 | bool use_shader_translator_; |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 1487 | scoped_ptr<ShaderTranslator> vertex_translator_; |
| 1488 | scoped_ptr<ShaderTranslator> fragment_translator_; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1489 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1490 | DisallowedFeatures disallowed_features_; |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1491 | |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1492 | // Cached from ContextGroup |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1493 | const Validators* validators_; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 1494 | FeatureInfo::Ref feature_info_; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1495 | |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 1496 | // This indicates all the following texSubImage2D calls that are part of the |
| 1497 | // failed texImage2D call should be ignored. |
| 1498 | bool tex_image_2d_failed_; |
| 1499 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1500 | int frame_number_; |
| 1501 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1502 | bool has_arb_robustness_; |
| 1503 | GLenum reset_status_; |
| 1504 | |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 1505 | bool needs_mac_nvidia_driver_workaround_; |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 1506 | bool needs_glsl_built_in_function_emulation_; |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 1507 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1508 | // These flags are used to override the state of the shared feature_info_ |
| 1509 | // member. Because the same FeatureInfo instance may be shared among many |
| 1510 | // contexts, the assumptions on the availablity of extensions in WebGL |
| 1511 | // contexts may be broken. These flags override the shared state to preserve |
| 1512 | // WebGL semantics. |
| 1513 | bool force_webgl_glsl_validation_; |
| 1514 | bool derivatives_explicitly_enabled_; |
| 1515 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1516 | bool compile_shader_always_succeeds_; |
| 1517 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1518 | #if defined(OS_MACOSX) |
| 1519 | typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; |
| 1520 | TextureToIOSurfaceMap texture_to_io_surface_map_; |
| 1521 | #endif |
| 1522 | |
[email protected] | c826d73 | 2012-02-09 04:40:26 | [diff] [blame] | 1523 | typedef std::vector<GLES2DecoderImpl*> ChildList; |
| 1524 | ChildList children_; |
| 1525 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1526 | DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
| 1527 | }; |
| 1528 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1529 | ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder) |
| 1530 | : decoder_(decoder) { |
| 1531 | decoder_->CopyRealGLErrorsToWrapper(); |
| 1532 | } |
| 1533 | |
| 1534 | ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
| 1535 | decoder_->ClearRealGLErrors(); |
| 1536 | } |
| 1537 | |
| 1538 | ScopedTexture2DBinder::ScopedTexture2DBinder(GLES2DecoderImpl* decoder, |
| 1539 | GLuint id) |
| 1540 | : decoder_(decoder) { |
| 1541 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1542 | |
| 1543 | // TODO(apatrick): Check if there are any other states that need to be reset |
| 1544 | // before binding a new texture. |
| 1545 | glActiveTexture(GL_TEXTURE0); |
| 1546 | glBindTexture(GL_TEXTURE_2D, id); |
| 1547 | } |
| 1548 | |
| 1549 | ScopedTexture2DBinder::~ScopedTexture2DBinder() { |
| 1550 | ScopedGLErrorSuppressor suppressor(decoder_); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1551 | decoder_->RestoreCurrentTexture2DBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | ScopedRenderBufferBinder::ScopedRenderBufferBinder(GLES2DecoderImpl* decoder, |
| 1555 | GLuint id) |
| 1556 | : decoder_(decoder) { |
| 1557 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1558 | glBindRenderbufferEXT(GL_RENDERBUFFER, id); |
| 1559 | } |
| 1560 | |
| 1561 | ScopedRenderBufferBinder::~ScopedRenderBufferBinder() { |
| 1562 | ScopedGLErrorSuppressor suppressor(decoder_); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1563 | decoder_->RestoreCurrentRenderbufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | ScopedFrameBufferBinder::ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 1567 | GLuint id) |
| 1568 | : decoder_(decoder) { |
| 1569 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1570 | glBindFramebufferEXT(GL_FRAMEBUFFER, id); |
| 1571 | } |
| 1572 | |
| 1573 | ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { |
| 1574 | ScopedGLErrorSuppressor suppressor(decoder_); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1575 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1576 | } |
| 1577 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1578 | ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder( |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1579 | GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 1580 | : decoder_(decoder) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1581 | resolve_and_bind_ = (decoder_->offscreen_target_frame_buffer_.get() && |
| 1582 | decoder_->IsOffscreenBufferMultisampled() && |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 1583 | (!decoder_->bound_read_framebuffer_.get() || |
| 1584 | enforce_internal_framebuffer)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1585 | if (!resolve_and_bind_) |
| 1586 | return; |
| 1587 | |
| 1588 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1589 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, |
| 1590 | decoder_->offscreen_target_frame_buffer_->id()); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1591 | GLuint targetid; |
| 1592 | if (internal) { |
| 1593 | if (!decoder_->offscreen_resolved_frame_buffer_.get()) { |
| 1594 | decoder_->offscreen_resolved_frame_buffer_.reset( |
| 1595 | new FrameBuffer(decoder_)); |
| 1596 | decoder_->offscreen_resolved_frame_buffer_->Create(); |
| 1597 | decoder_->offscreen_resolved_color_texture_.reset(new Texture(decoder_)); |
| 1598 | decoder_->offscreen_resolved_color_texture_->Create(); |
| 1599 | |
| 1600 | DCHECK(decoder_->offscreen_saved_color_format_); |
| 1601 | decoder_->offscreen_resolved_color_texture_->AllocateStorage( |
| 1602 | decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1603 | decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( |
| 1604 | decoder_->offscreen_resolved_color_texture_.get()); |
| 1605 | if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != |
| 1606 | GL_FRAMEBUFFER_COMPLETE) { |
| 1607 | LOG(ERROR) << "ScopedResolvedFrameBufferBinder failed " |
| 1608 | << "because offscreen resolved FBO was incomplete."; |
| 1609 | return; |
| 1610 | } |
| 1611 | } |
| 1612 | targetid = decoder_->offscreen_resolved_frame_buffer_->id(); |
| 1613 | } else { |
| 1614 | targetid = decoder_->offscreen_saved_frame_buffer_->id(); |
| 1615 | } |
| 1616 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1617 | const int width = decoder_->offscreen_size_.width(); |
| 1618 | const int height = decoder_->offscreen_size_.height(); |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 1619 | glDisable(GL_SCISSOR_TEST); |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 1620 | if (GLES2Decoder::IsAngle()) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1621 | glBlitFramebufferANGLE(0, 0, width, height, 0, 0, width, height, |
| 1622 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1623 | } else { |
| 1624 | glBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, |
| 1625 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1626 | } |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1627 | glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { |
| 1631 | if (!resolve_and_bind_) |
| 1632 | return; |
| 1633 | |
| 1634 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1635 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 1636 | if (decoder_->enable_scissor_test_) { |
| 1637 | glEnable(GL_SCISSOR_TEST); |
| 1638 | } |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1639 | } |
| 1640 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1641 | Texture::Texture(GLES2DecoderImpl* decoder) |
| 1642 | : decoder_(decoder), |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1643 | id_(0), |
| 1644 | estimated_size_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | Texture::~Texture() { |
| 1648 | // This does not destroy the render texture because that would require that |
| 1649 | // the associated GL context was current. Just check that it was explicitly |
| 1650 | // destroyed. |
| 1651 | DCHECK_EQ(id_, 0u); |
| 1652 | } |
| 1653 | |
| 1654 | void Texture::Create() { |
| 1655 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1656 | Destroy(); |
| 1657 | glGenTextures(1, &id_); |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1658 | ScopedTexture2DBinder binder(decoder_, id_); |
| 1659 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1660 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1661 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1662 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
[email protected] | 6278880 | 2011-10-03 17:57:16 | [diff] [blame] | 1663 | |
| 1664 | // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 1665 | // never called on an offscreen context, no data will ever be uploaded to the |
| 1666 | // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 1667 | // is called). My idea is that some nvidia drivers might have a bug where |
| 1668 | // deleting a texture that has never been populated might cause a |
| 1669 | // crash. |
| 1670 | glTexImage2D( |
| 1671 | GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1672 | estimated_size_ = 16u * 16u * 4u; |
| 1673 | decoder_->UpdateBackbufferMemoryAccounting(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1674 | } |
| 1675 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1676 | bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1677 | DCHECK_NE(id_, 0u); |
| 1678 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1679 | ScopedTexture2DBinder binder(decoder_, id_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1680 | |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 1681 | WrappedTexImage2D(GL_TEXTURE_2D, |
| 1682 | 0, // mip level |
| 1683 | format, |
| 1684 | size.width(), |
| 1685 | size.height(), |
| 1686 | 0, // border |
| 1687 | format, |
| 1688 | GL_UNSIGNED_BYTE, |
| 1689 | NULL); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1690 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1691 | size_ = size; |
| 1692 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1693 | bool success = glGetError() == GL_NO_ERROR; |
| 1694 | if (success) { |
| 1695 | uint32 image_size = 0; |
| 1696 | GLES2Util::ComputeImageDataSize( |
| 1697 | size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size); |
| 1698 | estimated_size_ = image_size; |
| 1699 | decoder_->UpdateBackbufferMemoryAccounting(); |
| 1700 | } |
| 1701 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1702 | } |
| 1703 | |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1704 | void Texture::Copy(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1705 | DCHECK_NE(id_, 0u); |
| 1706 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1707 | ScopedTexture2DBinder binder(decoder_, id_); |
| 1708 | glCopyTexImage2D(GL_TEXTURE_2D, |
| 1709 | 0, // level |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1710 | format, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1711 | 0, 0, |
| 1712 | size.width(), |
| 1713 | size.height(), |
| 1714 | 0); // border |
| 1715 | } |
| 1716 | |
| 1717 | void Texture::Destroy() { |
| 1718 | if (id_ != 0) { |
| 1719 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1720 | glDeleteTextures(1, &id_); |
| 1721 | id_ = 0; |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1722 | estimated_size_ = 0; |
| 1723 | decoder_->UpdateBackbufferMemoryAccounting(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1724 | } |
| 1725 | } |
| 1726 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1727 | void Texture::Invalidate() { |
| 1728 | id_ = 0; |
| 1729 | } |
| 1730 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1731 | RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) |
| 1732 | : decoder_(decoder), |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1733 | id_(0), |
| 1734 | estimated_size_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | RenderBuffer::~RenderBuffer() { |
| 1738 | // This does not destroy the render buffer because that would require that |
| 1739 | // the associated GL context was current. Just check that it was explicitly |
| 1740 | // destroyed. |
| 1741 | DCHECK_EQ(id_, 0u); |
| 1742 | } |
| 1743 | |
| 1744 | void RenderBuffer::Create() { |
| 1745 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1746 | Destroy(); |
| 1747 | glGenRenderbuffersEXT(1, &id_); |
| 1748 | } |
| 1749 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1750 | bool RenderBuffer::AllocateStorage(const gfx::Size& size, GLenum format, |
| 1751 | GLsizei samples) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1752 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1753 | ScopedRenderBufferBinder binder(decoder_, id_); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1754 | if (samples <= 1) { |
| 1755 | glRenderbufferStorageEXT(GL_RENDERBUFFER, |
| 1756 | format, |
| 1757 | size.width(), |
| 1758 | size.height()); |
| 1759 | } else { |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 1760 | if (GLES2Decoder::IsAngle()) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1761 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, |
| 1762 | samples, |
| 1763 | format, |
| 1764 | size.width(), |
| 1765 | size.height()); |
| 1766 | } else { |
| 1767 | glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, |
| 1768 | samples, |
| 1769 | format, |
| 1770 | size.width(), |
| 1771 | size.height()); |
| 1772 | } |
| 1773 | } |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1774 | bool success = glGetError() == GL_NO_ERROR; |
| 1775 | if (success) { |
| 1776 | estimated_size_ = size.width() * size.height() * samples * |
| 1777 | GLES2Util::RenderbufferBytesPerPixel(format); |
| 1778 | decoder_->UpdateBackbufferMemoryAccounting(); |
| 1779 | } |
| 1780 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void RenderBuffer::Destroy() { |
| 1784 | if (id_ != 0) { |
| 1785 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1786 | glDeleteRenderbuffersEXT(1, &id_); |
| 1787 | id_ = 0; |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1788 | estimated_size_ = 0; |
| 1789 | decoder_->UpdateBackbufferMemoryAccounting(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1790 | } |
| 1791 | } |
| 1792 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1793 | void RenderBuffer::Invalidate() { |
| 1794 | id_ = 0; |
| 1795 | } |
| 1796 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1797 | FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) |
| 1798 | : decoder_(decoder), |
| 1799 | id_(0) { |
| 1800 | } |
| 1801 | |
| 1802 | FrameBuffer::~FrameBuffer() { |
| 1803 | // This does not destroy the frame buffer because that would require that |
| 1804 | // the associated GL context was current. Just check that it was explicitly |
| 1805 | // destroyed. |
| 1806 | DCHECK_EQ(id_, 0u); |
| 1807 | } |
| 1808 | |
| 1809 | void FrameBuffer::Create() { |
| 1810 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1811 | Destroy(); |
| 1812 | glGenFramebuffersEXT(1, &id_); |
| 1813 | } |
| 1814 | |
| 1815 | void FrameBuffer::AttachRenderTexture(Texture* texture) { |
| 1816 | DCHECK_NE(id_, 0u); |
| 1817 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1818 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 1819 | GLuint attach_id = texture ? texture->id() : 0; |
| 1820 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 1821 | GL_COLOR_ATTACHMENT0, |
| 1822 | GL_TEXTURE_2D, |
| 1823 | attach_id, |
| 1824 | 0); |
| 1825 | } |
| 1826 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1827 | void FrameBuffer::AttachRenderBuffer(GLenum target, |
| 1828 | RenderBuffer* render_buffer) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1829 | DCHECK_NE(id_, 0u); |
| 1830 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1831 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 1832 | GLuint attach_id = render_buffer ? render_buffer->id() : 0; |
| 1833 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1834 | target, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1835 | GL_RENDERBUFFER, |
| 1836 | attach_id); |
| 1837 | } |
| 1838 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1839 | void FrameBuffer::Destroy() { |
| 1840 | if (id_ != 0) { |
| 1841 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1842 | glDeleteFramebuffersEXT(1, &id_); |
| 1843 | id_ = 0; |
| 1844 | } |
| 1845 | } |
| 1846 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1847 | void FrameBuffer::Invalidate() { |
| 1848 | id_ = 0; |
| 1849 | } |
| 1850 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1851 | GLenum FrameBuffer::CheckStatus() { |
| 1852 | DCHECK_NE(id_, 0u); |
| 1853 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1854 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 1855 | return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 1856 | } |
| 1857 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 1858 | GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { |
| 1859 | return new GLES2DecoderImpl(group); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1860 | } |
| 1861 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 1862 | GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1863 | : GLES2Decoder(), |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 1864 | group_(group), |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1865 | error_bits_(0), |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1866 | pack_alignment_(4), |
| 1867 | unpack_alignment_(4), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1868 | attrib_0_buffer_id_(0), |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1869 | attrib_0_buffer_matches_value_(true), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1870 | attrib_0_size_(0), |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1871 | fixed_attrib_buffer_id_(0), |
| 1872 | fixed_attrib_buffer_size_(0), |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1873 | active_texture_unit_(0), |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1874 | clear_red_(0), |
| 1875 | clear_green_(0), |
| 1876 | clear_blue_(0), |
| 1877 | clear_alpha_(0), |
| 1878 | mask_red_(true), |
| 1879 | mask_green_(true), |
| 1880 | mask_blue_(true), |
| 1881 | mask_alpha_(true), |
| 1882 | clear_stencil_(0), |
| 1883 | mask_stencil_front_(-1), |
| 1884 | mask_stencil_back_(-1), |
| 1885 | clear_depth_(1.0f), |
| 1886 | mask_depth_(true), |
| 1887 | enable_scissor_test_(false), |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1888 | enable_depth_test_(false), |
| 1889 | enable_stencil_test_(false), |
| 1890 | state_dirty_(true), |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1891 | offscreen_target_color_format_(0), |
| 1892 | offscreen_target_depth_format_(0), |
| 1893 | offscreen_target_stencil_format_(0), |
| 1894 | offscreen_target_samples_(0), |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1895 | offscreen_target_buffer_preserved_(true), |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1896 | offscreen_saved_color_format_(0), |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1897 | stream_texture_manager_(NULL), |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1898 | back_buffer_color_format_(0), |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1899 | back_buffer_has_depth_(false), |
| 1900 | back_buffer_has_stencil_(false), |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1901 | teximage2d_faster_than_texsubimage2d_(true), |
| 1902 | bufferdata_faster_than_buffersubdata_(true), |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1903 | current_decoder_error_(error::kNoError), |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1904 | use_shader_translator_(true), |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1905 | validators_(group_->feature_info()->validators()), |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 1906 | feature_info_(group_->feature_info()), |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1907 | tex_image_2d_failed_(false), |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1908 | frame_number_(0), |
| 1909 | has_arb_robustness_(false), |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 1910 | reset_status_(GL_NO_ERROR), |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 1911 | needs_mac_nvidia_driver_workaround_(false), |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1912 | needs_glsl_built_in_function_emulation_(false), |
| 1913 | force_webgl_glsl_validation_(false), |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1914 | derivatives_explicitly_enabled_(false), |
| 1915 | compile_shader_always_succeeds_(false) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 1916 | DCHECK(group); |
| 1917 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1918 | attrib_0_value_.v[0] = 0.0f; |
| 1919 | attrib_0_value_.v[1] = 0.0f; |
| 1920 | attrib_0_value_.v[2] = 0.0f; |
| 1921 | attrib_0_value_.v[3] = 1.0f; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1922 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 1923 | // The shader translator is used for WebGL even when running on EGL |
| 1924 | // because additional restrictions are needed (like only enabling |
| 1925 | // GL_OES_standard_derivatives on demand). It is used for the unit |
| 1926 | // tests because |
| 1927 | // GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes the |
| 1928 | // empty string to CompileShader and this is not a valid shader. |
| 1929 | // TODO(apatrick): fix this test. |
| 1930 | if ((gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1931 | !feature_info_->feature_flags().chromium_webglsl && |
| 1932 | !force_webgl_glsl_validation_) || |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1933 | gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) { |
| 1934 | use_shader_translator_ = false; |
| 1935 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1936 | |
| 1937 | // TODO(gman): Consider setting these based on GPU and/or driver. |
| 1938 | if (IsAngle()) { |
| 1939 | teximage2d_faster_than_texsubimage2d_ = false; |
| 1940 | bufferdata_faster_than_buffersubdata_ = false; |
| 1941 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1942 | } |
| 1943 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 1944 | GLES2DecoderImpl::~GLES2DecoderImpl() { |
| 1945 | } |
| 1946 | |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1947 | bool GLES2DecoderImpl::Initialize( |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1948 | const scoped_refptr<gfx::GLSurface>& surface, |
| 1949 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1950 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1951 | const DisallowedFeatures& disallowed_features, |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1952 | const char* allowed_extensions, |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 1953 | const std::vector<int32>& attribs) { |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 1954 | DCHECK(context); |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 1955 | DCHECK(!context_.get()); |
| 1956 | |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 1957 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1958 | switches::kEnableGPUDebugging)) { |
| 1959 | set_debug(true); |
| 1960 | } |
| 1961 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1962 | compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 1963 | switches::kCompileShaderAlwaysSucceeds); |
| 1964 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1965 | // Take ownership of the GLSurface. TODO(apatrick): once the parent / child |
| 1966 | // context is retired, the decoder should not take an initial surface as |
| 1967 | // an argument to this function. |
| 1968 | // Maybe create a short lived offscreen GLSurface for the purpose of |
| 1969 | // initializing the decoder's GLContext. |
| 1970 | surface_ = surface; |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 1971 | |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 1972 | // Take ownership of the GLContext. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1973 | context_ = context; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1974 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 1975 | if (!MakeCurrent()) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 1976 | LOG(ERROR) << "GLES2DecoderImpl::Initialize failed because " |
| 1977 | << "MakeCurrent failed."; |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 1978 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 1979 | Destroy(); |
| 1980 | return false; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 1981 | } |
| 1982 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1983 | if (!group_->Initialize(disallowed_features, allowed_extensions)) { |
[email protected] | 09ddb91f | 2011-04-14 23:16:22 | [diff] [blame] | 1984 | LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1985 | << "failed to initialize."; |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 1986 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1987 | Destroy(); |
[email protected] | ae174109 | 2010-11-17 19:16:03 | [diff] [blame] | 1988 | return false; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1989 | } |
| 1990 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 1991 | CHECK_GL_ERROR(); |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1992 | disallowed_features_ = disallowed_features; |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 1993 | |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 1994 | vertex_attrib_manager_.reset(new VertexAttribManager()); |
| 1995 | vertex_attrib_manager_->Initialize(group_->max_vertex_attribs()); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 1996 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 1997 | util_.set_num_compressed_texture_formats( |
| 1998 | validators_->compressed_texture_format.GetValues().size()); |
| 1999 | |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 2000 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2001 | // We have to enable vertex array 0 on OpenGL or it won't render. Note that |
| 2002 | // OpenGL ES 2.0 does not have this issue. |
| 2003 | glEnableVertexAttribArray(0); |
| 2004 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2005 | glGenBuffersARB(1, &attrib_0_buffer_id_); |
| 2006 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 2007 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
| 2008 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2009 | glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 2010 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2011 | texture_units_.reset( |
| 2012 | new TextureUnit[group_->max_texture_units()]); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 2013 | for (uint32 tt = 0; tt < group_->max_texture_units(); ++tt) { |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2014 | glActiveTexture(GL_TEXTURE0 + tt); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2015 | // We want the last bind to be 2D. |
| 2016 | TextureManager::TextureInfo* info; |
| 2017 | if (feature_info_->feature_flags().oes_egl_image_external) { |
| 2018 | info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_EXTERNAL_OES); |
| 2019 | texture_units_[tt].bound_texture_external_oes = info; |
| 2020 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, info->service_id()); |
| 2021 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2022 | if (feature_info_->feature_flags().arb_texture_rectangle) { |
| 2023 | info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_RECTANGLE_ARB); |
| 2024 | texture_units_[tt].bound_texture_rectangle_arb = info; |
| 2025 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, info->service_id()); |
| 2026 | } |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2027 | info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2028 | texture_units_[tt].bound_texture_cube_map = info; |
| 2029 | glBindTexture(GL_TEXTURE_CUBE_MAP, info->service_id()); |
| 2030 | info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
| 2031 | texture_units_[tt].bound_texture_2d = info; |
| 2032 | glBindTexture(GL_TEXTURE_2D, info->service_id()); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 2033 | } |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2034 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2035 | CHECK_GL_ERROR(); |
| 2036 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2037 | ContextCreationAttribParser attrib_parser; |
| 2038 | if (!attrib_parser.Parse(attribs)) |
| 2039 | return false; |
[email protected] | 41c5636 | 2011-06-14 16:47:43 | [diff] [blame] | 2040 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2041 | // These are NOT if the back buffer has these proprorties. They are |
| 2042 | // if we want the command buffer to enforce them regardless of what |
| 2043 | // the real backbuffer is assuming the real back buffer gives us more than |
| 2044 | // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
| 2045 | // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
| 2046 | // can't do anything about that. |
| 2047 | |
| 2048 | GLint v = 0; |
| 2049 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 2050 | // This checks if the user requested RGBA and we have RGBA then RGBA. If the |
| 2051 | // user requested RGB then RGB. If the user did not specify a preference than |
| 2052 | // use whatever we were given. Same for DEPTH and STENCIL. |
| 2053 | back_buffer_color_format_ = |
| 2054 | (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB; |
| 2055 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 2056 | back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0; |
| 2057 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 2058 | back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0; |
| 2059 | |
| 2060 | if (surface_->IsOffscreen()) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2061 | if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && |
[email protected] | 53862ed | 2010-10-25 19:22:54 | [diff] [blame] | 2062 | (context_->HasExtension("GL_EXT_framebuffer_multisample") || |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2063 | context_->HasExtension("GL_ANGLE_framebuffer_multisample"))) { |
| 2064 | // Per ext_framebuffer_multisample spec, need max bound on sample count. |
[email protected] | 0b1e9d7 | 2010-11-11 16:29:43 | [diff] [blame] | 2065 | // max_sample_count must be initialized to a sane value. If |
| 2066 | // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
| 2067 | GLint max_sample_count = 1; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2068 | glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
| 2069 | offscreen_target_samples_ = std::min(attrib_parser.samples_, |
| 2070 | max_sample_count); |
| 2071 | } else { |
| 2072 | offscreen_target_samples_ = 1; |
| 2073 | } |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2074 | offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2075 | |
| 2076 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 2077 | const bool rgb8_supported = |
| 2078 | context_->HasExtension("GL_OES_rgb8_rgba8"); |
| 2079 | // The only available default render buffer formats in GLES2 have very |
| 2080 | // little precision. Don't enable multisampling unless 8-bit render |
| 2081 | // buffer formats are available--instead fall back to 8-bit textures. |
| 2082 | if (rgb8_supported && offscreen_target_samples_ > 1) { |
| 2083 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2084 | GL_RGBA8 : GL_RGB8; |
| 2085 | } else { |
| 2086 | offscreen_target_samples_ = 1; |
| 2087 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2088 | GL_RGBA : GL_RGB; |
| 2089 | } |
| 2090 | |
| 2091 | // ANGLE only supports packed depth/stencil formats, so use it if it is |
| 2092 | // available. |
| 2093 | const bool depth24_stencil8_supported = |
| 2094 | context_->HasExtension("GL_OES_packed_depth_stencil"); |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2095 | VLOG(1) << "GL_OES_packed_depth_stencil " |
| 2096 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2097 | if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && |
| 2098 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2099 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2100 | offscreen_target_stencil_format_ = 0; |
| 2101 | } else { |
| 2102 | // It may be the case that this depth/stencil combination is not |
| 2103 | // supported, but this will be checked later by CheckFramebufferStatus. |
| 2104 | offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? |
| 2105 | GL_DEPTH_COMPONENT16 : 0; |
| 2106 | offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? |
| 2107 | GL_STENCIL_INDEX8 : 0; |
| 2108 | } |
| 2109 | } else { |
| 2110 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2111 | GL_RGBA : GL_RGB; |
| 2112 | |
| 2113 | // If depth is requested at all, use the packed depth stencil format if |
| 2114 | // it's available, as some desktop GL drivers don't support any non-packed |
| 2115 | // formats for depth attachments. |
| 2116 | const bool depth24_stencil8_supported = |
| 2117 | context_->HasExtension("GL_EXT_packed_depth_stencil"); |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2118 | VLOG(1) << "GL_EXT_packed_depth_stencil " |
| 2119 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2120 | |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2121 | if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && |
| 2122 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2123 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2124 | offscreen_target_stencil_format_ = 0; |
| 2125 | } else { |
| 2126 | offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? |
| 2127 | GL_DEPTH_COMPONENT : 0; |
| 2128 | offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? |
| 2129 | GL_STENCIL_INDEX : 0; |
| 2130 | } |
| 2131 | } |
| 2132 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2133 | offscreen_saved_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2134 | GL_RGBA : GL_RGB; |
| 2135 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2136 | // Create the target frame buffer. This is the one that the client renders |
| 2137 | // directly to. |
| 2138 | offscreen_target_frame_buffer_.reset(new FrameBuffer(this)); |
| 2139 | offscreen_target_frame_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2140 | // Due to GLES2 format limitations, either the color texture (for |
| 2141 | // non-multisampling) or the color render buffer (for multisampling) will be |
| 2142 | // attached to the offscreen frame buffer. The render buffer has more |
| 2143 | // limited formats available to it, but the texture can't do multisampling. |
| 2144 | if (IsOffscreenBufferMultisampled()) { |
| 2145 | offscreen_target_color_render_buffer_.reset(new RenderBuffer(this)); |
| 2146 | offscreen_target_color_render_buffer_->Create(); |
| 2147 | } else { |
| 2148 | offscreen_target_color_texture_.reset(new Texture(this)); |
| 2149 | offscreen_target_color_texture_->Create(); |
| 2150 | } |
| 2151 | offscreen_target_depth_render_buffer_.reset(new RenderBuffer(this)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2152 | offscreen_target_depth_render_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2153 | offscreen_target_stencil_render_buffer_.reset(new RenderBuffer(this)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2154 | offscreen_target_stencil_render_buffer_->Create(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2155 | |
| 2156 | // Create the saved offscreen texture. The target frame buffer is copied |
| 2157 | // here when SwapBuffers is called. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2158 | offscreen_saved_frame_buffer_.reset(new FrameBuffer(this)); |
| 2159 | offscreen_saved_frame_buffer_->Create(); |
| 2160 | // |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2161 | offscreen_saved_color_texture_.reset(new Texture(this)); |
| 2162 | offscreen_saved_color_texture_->Create(); |
| 2163 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2164 | // Allocate the render buffers at their initial size and check the status |
| 2165 | // of the frame buffers is okay. |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2166 | if (!ResizeOffscreenFrameBuffer(size)) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 2167 | LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2168 | Destroy(); |
| 2169 | return false; |
| 2170 | } |
| 2171 | |
| 2172 | // Bind to the new default frame buffer (the offscreen target frame buffer). |
| 2173 | // This should now be associated with ID zero. |
| 2174 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2175 | } |
| 2176 | |
[email protected] | 295faf4b | 2012-01-25 23:31:41 | [diff] [blame] | 2177 | // Clear the backbuffer. |
| 2178 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 2179 | |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2180 | // OpenGL ES 2.0 implicitly enables the desktop GL capability |
| 2181 | // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
| 2182 | // isn't well documented; it was discovered in the Khronos OpenGL ES |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2183 | // mailing list archives. It also implicitly enables the desktop GL |
| 2184 | // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
| 2185 | // variable in fragment shaders. |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2186 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2187 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2188 | glEnable(GL_POINT_SPRITE); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2189 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2190 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2191 | has_arb_robustness_ = context->HasExtension("GL_ARB_robustness"); |
| 2192 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2193 | if (!disallowed_features_.driver_bug_workarounds) { |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 2194 | #if defined(OS_MACOSX) |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2195 | const char* vendor_str = reinterpret_cast<const char*>( |
| 2196 | glGetString(GL_VENDOR)); |
| 2197 | needs_mac_nvidia_driver_workaround_ = |
| 2198 | vendor_str && strstr(vendor_str, "NVIDIA"); |
| 2199 | needs_glsl_built_in_function_emulation_ = |
| 2200 | vendor_str && (strstr(vendor_str, "ATI") || strstr(vendor_str, "AMD")); |
| 2201 | #elif defined(OS_WIN) |
| 2202 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 2203 | needs_glsl_built_in_function_emulation_ = true; |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 2204 | #endif |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2205 | } |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 2206 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2207 | if (!InitializeShaderTranslator()) { |
| 2208 | return false; |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2209 | } |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2210 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2211 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2212 | } |
| 2213 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2214 | void GLES2DecoderImpl::UpdateCapabilities() { |
| 2215 | util_.set_num_compressed_texture_formats( |
| 2216 | validators_->compressed_texture_format.GetValues().size()); |
| 2217 | util_.set_num_shader_binary_formats( |
| 2218 | validators_->shader_binary_format.GetValues().size()); |
| 2219 | } |
| 2220 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2221 | bool GLES2DecoderImpl::InitializeShaderTranslator() { |
| 2222 | // Re-check the state of use_shader_translator_ each time this is called. |
| 2223 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2224 | (feature_info_->feature_flags().chromium_webglsl || |
| 2225 | force_webgl_glsl_validation_) && |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2226 | !use_shader_translator_) { |
| 2227 | use_shader_translator_ = true; |
| 2228 | } |
| 2229 | if (!use_shader_translator_) { |
| 2230 | return true; |
| 2231 | } |
| 2232 | ShBuiltInResources resources; |
| 2233 | ShInitBuiltInResources(&resources); |
| 2234 | resources.MaxVertexAttribs = group_->max_vertex_attribs(); |
| 2235 | resources.MaxVertexUniformVectors = |
| 2236 | group_->max_vertex_uniform_vectors(); |
| 2237 | resources.MaxVaryingVectors = group_->max_varying_vectors(); |
| 2238 | resources.MaxVertexTextureImageUnits = |
| 2239 | group_->max_vertex_texture_image_units(); |
| 2240 | resources.MaxCombinedTextureImageUnits = group_->max_texture_units(); |
| 2241 | resources.MaxTextureImageUnits = group_->max_texture_image_units(); |
| 2242 | resources.MaxFragmentUniformVectors = |
| 2243 | group_->max_fragment_uniform_vectors(); |
| 2244 | resources.MaxDrawBuffers = 1; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2245 | |
| 2246 | if (force_webgl_glsl_validation_) { |
| 2247 | resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
| 2248 | } else { |
| 2249 | resources.OES_standard_derivatives = |
| 2250 | feature_info_->feature_flags().oes_standard_derivatives ? 1 : 0; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2251 | resources.ARB_texture_rectangle = |
| 2252 | feature_info_->feature_flags().arb_texture_rectangle ? 1 : 0; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2253 | } |
| 2254 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2255 | vertex_translator_.reset(new ShaderTranslator); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2256 | ShShaderSpec shader_spec = force_webgl_glsl_validation_ || |
| 2257 | feature_info_->feature_flags().chromium_webglsl ? |
| 2258 | SH_WEBGL_SPEC : SH_GLES2_SPEC; |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2259 | ShaderTranslatorInterface::GlslImplementationType implementation_type = |
| 2260 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? |
| 2261 | ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; |
| 2262 | ShaderTranslatorInterface::GlslBuiltInFunctionBehavior function_behavior = |
| 2263 | needs_glsl_built_in_function_emulation_ ? |
| 2264 | ShaderTranslatorInterface::kGlslBuiltInFunctionEmulated : |
| 2265 | ShaderTranslatorInterface::kGlslBuiltInFunctionOriginal; |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2266 | if (!vertex_translator_->Init( |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2267 | SH_VERTEX_SHADER, shader_spec, &resources, |
| 2268 | implementation_type, function_behavior)) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2269 | LOG(ERROR) << "Could not initialize vertex shader translator."; |
| 2270 | Destroy(); |
| 2271 | return false; |
| 2272 | } |
| 2273 | fragment_translator_.reset(new ShaderTranslator); |
| 2274 | if (!fragment_translator_->Init( |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2275 | SH_FRAGMENT_SHADER, shader_spec, &resources, |
| 2276 | implementation_type, function_behavior)) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2277 | LOG(ERROR) << "Could not initialize fragment shader translator."; |
| 2278 | Destroy(); |
| 2279 | return false; |
| 2280 | } |
| 2281 | return true; |
| 2282 | } |
| 2283 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2284 | bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2285 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2286 | if (GetBufferInfo(client_ids[ii])) { |
| 2287 | return false; |
| 2288 | } |
| 2289 | } |
| 2290 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 2291 | glGenBuffersARB(n, service_ids.get()); |
| 2292 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2293 | CreateBufferInfo(client_ids[ii], service_ids[ii]); |
| 2294 | } |
| 2295 | return true; |
| 2296 | } |
| 2297 | |
| 2298 | bool GLES2DecoderImpl::GenFramebuffersHelper( |
| 2299 | GLsizei n, const GLuint* client_ids) { |
| 2300 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2301 | if (GetFramebufferInfo(client_ids[ii])) { |
| 2302 | return false; |
| 2303 | } |
| 2304 | } |
| 2305 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 2306 | glGenFramebuffersEXT(n, service_ids.get()); |
| 2307 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2308 | CreateFramebufferInfo(client_ids[ii], service_ids[ii]); |
| 2309 | } |
| 2310 | return true; |
| 2311 | } |
| 2312 | |
| 2313 | bool GLES2DecoderImpl::GenRenderbuffersHelper( |
| 2314 | GLsizei n, const GLuint* client_ids) { |
| 2315 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2316 | if (GetRenderbufferInfo(client_ids[ii])) { |
| 2317 | return false; |
| 2318 | } |
| 2319 | } |
| 2320 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 2321 | glGenRenderbuffersEXT(n, service_ids.get()); |
| 2322 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2323 | CreateRenderbufferInfo(client_ids[ii], service_ids[ii]); |
| 2324 | } |
| 2325 | return true; |
| 2326 | } |
| 2327 | |
| 2328 | bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { |
| 2329 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2330 | if (GetTextureInfo(client_ids[ii])) { |
| 2331 | return false; |
| 2332 | } |
| 2333 | } |
| 2334 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 2335 | glGenTextures(n, service_ids.get()); |
| 2336 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2337 | CreateTextureInfo(client_ids[ii], service_ids[ii]); |
| 2338 | } |
| 2339 | return true; |
| 2340 | } |
| 2341 | |
| 2342 | void GLES2DecoderImpl::DeleteBuffersHelper( |
| 2343 | GLsizei n, const GLuint* client_ids) { |
| 2344 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2345 | BufferManager::BufferInfo* buffer = GetBufferInfo(client_ids[ii]); |
| 2346 | if (buffer && !buffer->IsDeleted()) { |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 2347 | vertex_attrib_manager_->Unbind(buffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2348 | if (bound_array_buffer_ == buffer) { |
| 2349 | bound_array_buffer_ = NULL; |
| 2350 | } |
| 2351 | if (bound_element_array_buffer_ == buffer) { |
| 2352 | bound_element_array_buffer_ = NULL; |
| 2353 | } |
| 2354 | GLuint service_id = buffer->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2355 | glDeleteBuffersARB(1, &service_id); |
| 2356 | RemoveBufferInfo(client_ids[ii]); |
| 2357 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2358 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2359 | } |
| 2360 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2361 | void GLES2DecoderImpl::DeleteFramebuffersHelper( |
| 2362 | GLsizei n, const GLuint* client_ids) { |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2363 | bool supports_seperate_framebuffer_binds = |
| 2364 | feature_info_->feature_flags().chromium_framebuffer_multisample; |
| 2365 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2366 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2367 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2368 | GetFramebufferInfo(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2369 | if (framebuffer && !framebuffer->IsDeleted()) { |
| 2370 | if (framebuffer == bound_draw_framebuffer_) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2371 | bound_draw_framebuffer_ = NULL; |
| 2372 | state_dirty_ = true; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2373 | GLenum target = supports_seperate_framebuffer_binds ? |
| 2374 | GL_DRAW_FRAMEBUFFER : GL_FRAMEBUFFER; |
| 2375 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
| 2376 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2377 | if (framebuffer == bound_read_framebuffer_) { |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2378 | bound_read_framebuffer_ = NULL; |
| 2379 | GLenum target = supports_seperate_framebuffer_binds ? |
| 2380 | GL_READ_FRAMEBUFFER : GL_FRAMEBUFFER; |
| 2381 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2382 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2383 | GLuint service_id = framebuffer->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2384 | glDeleteFramebuffersEXT(1, &service_id); |
| 2385 | RemoveFramebufferInfo(client_ids[ii]); |
| 2386 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2387 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2388 | } |
| 2389 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2390 | void GLES2DecoderImpl::DeleteRenderbuffersHelper( |
| 2391 | GLsizei n, const GLuint* client_ids) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2392 | bool supports_seperate_framebuffer_binds = |
| 2393 | feature_info_->feature_flags().chromium_framebuffer_multisample; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2394 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2395 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2396 | GetRenderbufferInfo(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2397 | if (renderbuffer && !renderbuffer->IsDeleted()) { |
| 2398 | if (bound_renderbuffer_ == renderbuffer) { |
| 2399 | bound_renderbuffer_ = NULL; |
| 2400 | } |
| 2401 | // Unbind from current framebuffers. |
| 2402 | if (supports_seperate_framebuffer_binds) { |
| 2403 | if (bound_read_framebuffer_) { |
| 2404 | bound_read_framebuffer_->UnbindRenderbuffer( |
| 2405 | GL_READ_FRAMEBUFFER, renderbuffer); |
| 2406 | } |
| 2407 | if (bound_draw_framebuffer_) { |
| 2408 | bound_draw_framebuffer_->UnbindRenderbuffer( |
| 2409 | GL_DRAW_FRAMEBUFFER, renderbuffer); |
| 2410 | } |
| 2411 | } else { |
| 2412 | if (bound_draw_framebuffer_) { |
| 2413 | bound_draw_framebuffer_->UnbindRenderbuffer( |
| 2414 | GL_FRAMEBUFFER, renderbuffer); |
| 2415 | } |
| 2416 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2417 | state_dirty_ = true; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2418 | GLuint service_id = renderbuffer->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2419 | glDeleteRenderbuffersEXT(1, &service_id); |
| 2420 | RemoveRenderbufferInfo(client_ids[ii]); |
| 2421 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2422 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2423 | } |
| 2424 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2425 | void GLES2DecoderImpl::DeleteTexturesHelper( |
| 2426 | GLsizei n, const GLuint* client_ids) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2427 | bool supports_seperate_framebuffer_binds = |
| 2428 | feature_info_->feature_flags().chromium_framebuffer_multisample; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2429 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2430 | TextureManager::TextureInfo* texture = GetTextureInfo(client_ids[ii]); |
| 2431 | if (texture && !texture->IsDeleted()) { |
| 2432 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2433 | state_dirty_ = true; |
| 2434 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2435 | // Unbind texture from texture units. |
| 2436 | for (size_t jj = 0; jj < group_->max_texture_units(); ++jj) { |
| 2437 | texture_units_[ii].Unbind(texture); |
| 2438 | } |
| 2439 | // Unbind from current framebuffers. |
| 2440 | if (supports_seperate_framebuffer_binds) { |
| 2441 | if (bound_read_framebuffer_) { |
| 2442 | bound_read_framebuffer_->UnbindTexture(GL_READ_FRAMEBUFFER, texture); |
| 2443 | } |
| 2444 | if (bound_draw_framebuffer_) { |
| 2445 | bound_draw_framebuffer_->UnbindTexture(GL_DRAW_FRAMEBUFFER, texture); |
| 2446 | } |
| 2447 | } else { |
| 2448 | if (bound_draw_framebuffer_) { |
| 2449 | bound_draw_framebuffer_->UnbindTexture(GL_FRAMEBUFFER, texture); |
| 2450 | } |
| 2451 | } |
| 2452 | GLuint service_id = texture->service_id(); |
| 2453 | if (texture->IsStreamTexture() && stream_texture_manager_) { |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 2454 | stream_texture_manager_->DestroyStreamTexture(service_id); |
| 2455 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2456 | #if defined(OS_MACOSX) |
| 2457 | if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { |
| 2458 | ReleaseIOSurfaceForTexture(service_id); |
| 2459 | } |
| 2460 | #endif |
[email protected] | 5f4f2a73 | 2011-07-30 00:47:55 | [diff] [blame] | 2461 | glDeleteTextures(1, &service_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2462 | RemoveTextureInfo(client_ids[ii]); |
| 2463 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2464 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2465 | } |
| 2466 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 2467 | // } // anonymous namespace |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2468 | |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2469 | bool GLES2DecoderImpl::MakeCurrent() { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2470 | bool result = context_.get() ? context_->MakeCurrent(surface_.get()) : false; |
| 2471 | if (result && WasContextLost()) { |
| 2472 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; |
| 2473 | result = false; |
| 2474 | } |
| 2475 | |
| 2476 | return result; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2477 | } |
| 2478 | |
[email protected] | a96a602 | 2011-11-04 00:58:12 | [diff] [blame] | 2479 | void GLES2DecoderImpl::ReleaseCurrent() { |
| 2480 | if (context_.get()) |
| 2481 | context_->ReleaseCurrent(surface_.get()); |
| 2482 | } |
| 2483 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2484 | void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2485 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 2486 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2487 | glBindRenderbufferEXT( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2488 | GL_RENDERBUFFER, renderbuffer ? renderbuffer->service_id() : 0); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | static void RebindCurrentFramebuffer( |
| 2492 | GLenum target, |
| 2493 | FramebufferManager::FramebufferInfo* info, |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2494 | GLuint back_buffer_service_id) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2495 | GLuint framebuffer_id = info ? info->service_id() : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2496 | |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2497 | if (framebuffer_id == 0) { |
| 2498 | framebuffer_id = back_buffer_service_id; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2499 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2500 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2501 | glBindFramebufferEXT(target, framebuffer_id); |
| 2502 | } |
| 2503 | |
| 2504 | void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2505 | state_dirty_ = true; |
| 2506 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2507 | if (!feature_info_->feature_flags().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2508 | RebindCurrentFramebuffer( |
| 2509 | GL_FRAMEBUFFER, |
| 2510 | bound_draw_framebuffer_.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2511 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2512 | } else { |
| 2513 | RebindCurrentFramebuffer( |
| 2514 | GL_READ_FRAMEBUFFER_EXT, |
| 2515 | bound_read_framebuffer_.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2516 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2517 | RebindCurrentFramebuffer( |
| 2518 | GL_DRAW_FRAMEBUFFER_EXT, |
| 2519 | bound_draw_framebuffer_.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2520 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | void GLES2DecoderImpl::RestoreCurrentTexture2DBindings() { |
| 2525 | GLES2DecoderImpl::TextureUnit& info = texture_units_[0]; |
| 2526 | GLuint last_id; |
| 2527 | if (info.bound_texture_2d) { |
| 2528 | last_id = info.bound_texture_2d->service_id(); |
| 2529 | } else { |
| 2530 | last_id = 0; |
| 2531 | } |
| 2532 | |
| 2533 | glBindTexture(GL_TEXTURE_2D, last_id); |
| 2534 | glActiveTexture(GL_TEXTURE0 + active_texture_unit_); |
| 2535 | } |
| 2536 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2537 | bool GLES2DecoderImpl::CheckFramebufferValid( |
| 2538 | FramebufferManager::FramebufferInfo* framebuffer, |
| 2539 | GLenum target, const char* func_name) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2540 | if (!framebuffer) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2541 | return true; |
| 2542 | } |
| 2543 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2544 | if (framebuffer_manager()->IsComplete(framebuffer)) { |
| 2545 | return true; |
| 2546 | } |
| 2547 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2548 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 2549 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 2550 | SetGLError( |
| 2551 | GL_INVALID_FRAMEBUFFER_OPERATION, |
| 2552 | (std::string(func_name) + " framebuffer incomplete").c_str()); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 2553 | return false; |
| 2554 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2555 | |
| 2556 | // Are all the attachments cleared? |
| 2557 | if (renderbuffer_manager()->HaveUnclearedRenderbuffers() || |
| 2558 | texture_manager()->HaveUnclearedMips()) { |
| 2559 | if (!framebuffer->IsCleared()) { |
| 2560 | // Can we clear them? |
| 2561 | if (glCheckFramebufferStatusEXT(target) != GL_FRAMEBUFFER_COMPLETE) { |
| 2562 | SetGLError( |
| 2563 | GL_INVALID_FRAMEBUFFER_OPERATION, |
| 2564 | (std::string(func_name) + |
| 2565 | " framebuffer incomplete (clear)").c_str()); |
| 2566 | return false; |
| 2567 | } |
| 2568 | ClearUnclearedAttachments(target, framebuffer); |
| 2569 | } |
| 2570 | } |
| 2571 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2572 | if (!framebuffer_manager()->IsComplete(framebuffer)) { |
| 2573 | if (glCheckFramebufferStatusEXT(target) != GL_FRAMEBUFFER_COMPLETE) { |
| 2574 | SetGLError( |
| 2575 | GL_INVALID_FRAMEBUFFER_OPERATION, |
| 2576 | (std::string(func_name) + |
| 2577 | " framebuffer incomplete (check)").c_str()); |
| 2578 | return false; |
| 2579 | } |
| 2580 | framebuffer_manager()->MarkAsComplete(framebuffer); |
| 2581 | } |
| 2582 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2583 | // NOTE: At this point we don't know if the framebuffer is complete but |
| 2584 | // we DO know that everything that needs to be cleared has been cleared. |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 2585 | return true; |
| 2586 | } |
| 2587 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2588 | bool GLES2DecoderImpl::CheckBoundFramebuffersValid(const char* func_name) { |
| 2589 | if (!feature_info_->feature_flags().chromium_framebuffer_multisample) { |
| 2590 | return CheckFramebufferValid( |
| 2591 | bound_draw_framebuffer_, GL_FRAMEBUFFER_EXT, func_name); |
| 2592 | } |
| 2593 | return CheckFramebufferValid( |
| 2594 | bound_draw_framebuffer_, GL_DRAW_FRAMEBUFFER_EXT, func_name) && |
| 2595 | CheckFramebufferValid( |
| 2596 | bound_read_framebuffer_, GL_READ_FRAMEBUFFER_EXT, func_name); |
| 2597 | } |
| 2598 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2599 | gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2600 | FramebufferManager::FramebufferInfo* framebuffer = |
| 2601 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER); |
| 2602 | if (framebuffer != NULL) { |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2603 | const FramebufferManager::FramebufferInfo::Attachment* attachment = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2604 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2605 | if (attachment) { |
| 2606 | return gfx::Size(attachment->width(), attachment->height()); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2607 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2608 | return gfx::Size(0, 0); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2609 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2610 | return offscreen_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2611 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 2612 | return surface_->GetSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2613 | } |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2614 | } |
| 2615 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2616 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2617 | FramebufferManager::FramebufferInfo* framebuffer = |
| 2618 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER); |
| 2619 | if (framebuffer != NULL) { |
| 2620 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2621 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2622 | return offscreen_target_color_format_; |
| 2623 | } else { |
| 2624 | return back_buffer_color_format_; |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | GLenum GLES2DecoderImpl::GetBoundDrawFrameBufferInternalFormat() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2629 | FramebufferManager::FramebufferInfo* framebuffer = |
| 2630 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER); |
| 2631 | if (framebuffer != NULL) { |
| 2632 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2633 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2634 | return offscreen_target_color_format_; |
| 2635 | } else { |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 2636 | return back_buffer_color_format_; |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2637 | } |
| 2638 | } |
| 2639 | |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 2640 | void GLES2DecoderImpl::UpdateParentTextureInfo() { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2641 | if (parent_) { |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 2642 | // Update the info about the offscreen saved color texture in the parent. |
| 2643 | // The reference to the parent is a weak pointer and will become null if the |
| 2644 | // parent is later destroyed. |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2645 | TextureManager* parent_texture_manager = parent_->texture_manager(); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2646 | parent_texture_manager->SetLevelInfo( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2647 | offscreen_saved_color_texture_info_, |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 2648 | GL_TEXTURE_2D, |
| 2649 | 0, // level |
| 2650 | GL_RGBA, |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2651 | offscreen_size_.width(), |
| 2652 | offscreen_size_.height(), |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 2653 | 1, // depth |
| 2654 | 0, // border |
| 2655 | GL_RGBA, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2656 | GL_UNSIGNED_BYTE, |
| 2657 | true); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2658 | parent_texture_manager->SetParameter( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2659 | offscreen_saved_color_texture_info_, |
[email protected] | 8c515f8 | 2010-11-09 03:40:04 | [diff] [blame] | 2660 | GL_TEXTURE_MAG_FILTER, |
| 2661 | GL_NEAREST); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2662 | parent_texture_manager->SetParameter( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2663 | offscreen_saved_color_texture_info_, |
[email protected] | 8c515f8 | 2010-11-09 03:40:04 | [diff] [blame] | 2664 | GL_TEXTURE_MIN_FILTER, |
| 2665 | GL_NEAREST); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2666 | parent_texture_manager->SetParameter( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2667 | offscreen_saved_color_texture_info_, |
[email protected] | 8c515f8 | 2010-11-09 03:40:04 | [diff] [blame] | 2668 | GL_TEXTURE_WRAP_S, |
| 2669 | GL_CLAMP_TO_EDGE); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2670 | parent_texture_manager->SetParameter( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2671 | offscreen_saved_color_texture_info_, |
[email protected] | 8c515f8 | 2010-11-09 03:40:04 | [diff] [blame] | 2672 | GL_TEXTURE_WRAP_T, |
| 2673 | GL_CLAMP_TO_EDGE); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2674 | } else { |
| 2675 | offscreen_saved_color_texture_info_ = NULL; |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 2676 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2677 | } |
| 2678 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2679 | void GLES2DecoderImpl::SetResizeCallback( |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 2680 | const base::Callback<void(gfx::Size)>& callback) { |
| 2681 | resize_callback_ = callback; |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 2682 | } |
| 2683 | |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 2684 | void GLES2DecoderImpl::SetMsgCallback(const MsgCallback& callback) { |
| 2685 | msg_callback_ = callback; |
| 2686 | } |
| 2687 | |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 2688 | void GLES2DecoderImpl::SetStreamTextureManager(StreamTextureManager* manager) { |
| 2689 | stream_texture_manager_ = manager; |
| 2690 | } |
| 2691 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 2692 | bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, |
| 2693 | uint32* service_texture_id) { |
| 2694 | TextureManager::TextureInfo* texture = |
| 2695 | texture_manager()->GetTextureInfo(client_texture_id); |
| 2696 | if (texture) { |
| 2697 | *service_texture_id = texture->service_id(); |
| 2698 | return true; |
| 2699 | } |
| 2700 | return false; |
| 2701 | } |
| 2702 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2703 | void GLES2DecoderImpl::Destroy() { |
[email protected] | eadc9679 | 2010-10-27 19:39:39 | [diff] [blame] | 2704 | bool have_context = context_.get() && MakeCurrent(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2705 | |
[email protected] | c826d73 | 2012-02-09 04:40:26 | [diff] [blame] | 2706 | ChildList children = children_; |
| 2707 | for (ChildList::iterator it = children.begin(); it != children.end(); ++it) |
| 2708 | (*it)->SetParent(NULL, 0); |
| 2709 | DCHECK(children_.empty()); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2710 | SetParent(NULL, 0); |
| 2711 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2712 | // Unbind everything. |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 2713 | vertex_attrib_manager_.reset(); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2714 | texture_units_.reset(); |
| 2715 | bound_array_buffer_ = NULL; |
| 2716 | bound_element_array_buffer_ = NULL; |
| 2717 | current_program_ = NULL; |
| 2718 | bound_read_framebuffer_ = NULL; |
| 2719 | bound_draw_framebuffer_ = NULL; |
| 2720 | bound_renderbuffer_ = NULL; |
| 2721 | |
[email protected] | eadc9679 | 2010-10-27 19:39:39 | [diff] [blame] | 2722 | if (have_context) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 2723 | if (current_program_) { |
| 2724 | program_manager()->UnuseProgram(shader_manager(), current_program_); |
| 2725 | current_program_ = NULL; |
| 2726 | } |
| 2727 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2728 | if (attrib_0_buffer_id_) { |
| 2729 | glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
| 2730 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2731 | if (fixed_attrib_buffer_id_) { |
| 2732 | glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
| 2733 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2734 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2735 | if (offscreen_target_frame_buffer_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 2736 | offscreen_target_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2737 | if (offscreen_target_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 2738 | offscreen_target_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2739 | if (offscreen_target_color_render_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2740 | offscreen_target_color_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2741 | if (offscreen_target_depth_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2742 | offscreen_target_depth_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2743 | if (offscreen_target_stencil_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2744 | offscreen_target_stencil_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2745 | if (offscreen_saved_frame_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2746 | offscreen_saved_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2747 | if (offscreen_saved_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 2748 | offscreen_saved_color_texture_->Destroy(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2749 | if (offscreen_resolved_frame_buffer_.get()) |
| 2750 | offscreen_resolved_frame_buffer_->Destroy(); |
| 2751 | if (offscreen_resolved_color_texture_.get()) |
| 2752 | offscreen_resolved_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2753 | } else { |
| 2754 | if (offscreen_target_frame_buffer_.get()) |
| 2755 | offscreen_target_frame_buffer_->Invalidate(); |
| 2756 | if (offscreen_target_color_texture_.get()) |
| 2757 | offscreen_target_color_texture_->Invalidate(); |
| 2758 | if (offscreen_target_color_render_buffer_.get()) |
| 2759 | offscreen_target_color_render_buffer_->Invalidate(); |
| 2760 | if (offscreen_target_depth_render_buffer_.get()) |
| 2761 | offscreen_target_depth_render_buffer_->Invalidate(); |
| 2762 | if (offscreen_target_stencil_render_buffer_.get()) |
| 2763 | offscreen_target_stencil_render_buffer_->Invalidate(); |
| 2764 | if (offscreen_saved_frame_buffer_.get()) |
| 2765 | offscreen_saved_frame_buffer_->Invalidate(); |
| 2766 | if (offscreen_saved_color_texture_.get()) |
| 2767 | offscreen_saved_color_texture_->Invalidate(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2768 | if (offscreen_resolved_frame_buffer_.get()) |
| 2769 | offscreen_resolved_frame_buffer_->Invalidate(); |
| 2770 | if (offscreen_resolved_color_texture_.get()) |
| 2771 | offscreen_resolved_color_texture_->Invalidate(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2772 | } |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2773 | |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 2774 | if (group_) { |
| 2775 | group_->Destroy(have_context); |
| 2776 | group_ = NULL; |
| 2777 | } |
[email protected] | 3ae01938 | 2011-10-05 19:42:41 | [diff] [blame] | 2778 | |
[email protected] | fe87166 | 2011-06-16 20:43:05 | [diff] [blame] | 2779 | if (context_.get()) { |
| 2780 | context_->ReleaseCurrent(NULL); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 2781 | context_ = NULL; |
[email protected] | fe87166 | 2011-06-16 20:43:05 | [diff] [blame] | 2782 | } |
[email protected] | 0fc3574 | 2011-04-13 17:57:54 | [diff] [blame] | 2783 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2784 | offscreen_target_frame_buffer_.reset(); |
| 2785 | offscreen_target_color_texture_.reset(); |
| 2786 | offscreen_target_color_render_buffer_.reset(); |
| 2787 | offscreen_target_depth_render_buffer_.reset(); |
| 2788 | offscreen_target_stencil_render_buffer_.reset(); |
| 2789 | offscreen_saved_frame_buffer_.reset(); |
| 2790 | offscreen_saved_color_texture_.reset(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2791 | offscreen_resolved_frame_buffer_.reset(); |
| 2792 | offscreen_resolved_color_texture_.reset(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2793 | |
| 2794 | #if defined(OS_MACOSX) |
| 2795 | for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
| 2796 | it != texture_to_io_surface_map_.end(); ++it) { |
| 2797 | CFRelease(it->second); |
| 2798 | } |
| 2799 | texture_to_io_surface_map_.clear(); |
| 2800 | #endif |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2801 | } |
| 2802 | |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2803 | bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, |
| 2804 | uint32 new_parent_texture_id) { |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 2805 | if (!offscreen_saved_color_texture_.get()) |
| 2806 | return false; |
| 2807 | |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2808 | // Remove the saved frame buffer mapping from the parent decoder. The |
| 2809 | // parent pointer is a weak pointer so it will be null if the parent has |
| 2810 | // already been destroyed. |
| 2811 | if (parent_) { |
[email protected] | c826d73 | 2012-02-09 04:40:26 | [diff] [blame] | 2812 | ChildList::iterator it = std::find( |
| 2813 | parent_->children_.begin(), |
| 2814 | parent_->children_.end(), |
| 2815 | this); |
| 2816 | DCHECK(it != parent_->children_.end()); |
| 2817 | parent_->children_.erase(it); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2818 | // First check the texture has been mapped into the parent. This might not |
| 2819 | // be the case if initialization failed midway through. |
| 2820 | GLuint service_id = offscreen_saved_color_texture_->id(); |
| 2821 | GLuint client_id = 0; |
| 2822 | if (parent_->texture_manager()->GetClientId(service_id, &client_id)) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2823 | parent_->texture_manager()->RemoveTextureInfo(client_id); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | GLES2DecoderImpl* new_parent_impl = static_cast<GLES2DecoderImpl*>( |
| 2828 | new_parent); |
| 2829 | if (new_parent_impl) { |
[email protected] | c826d73 | 2012-02-09 04:40:26 | [diff] [blame] | 2830 | #ifndef NDEBUG |
| 2831 | ChildList::iterator it = std::find( |
| 2832 | new_parent_impl->children_.begin(), |
| 2833 | new_parent_impl->children_.end(), |
| 2834 | this); |
| 2835 | DCHECK(it == new_parent_impl->children_.end()); |
| 2836 | #endif |
| 2837 | new_parent_impl->children_.push_back(this); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2838 | // Map the ID of the saved offscreen texture into the parent so that |
| 2839 | // it can reference it. |
| 2840 | GLuint service_id = offscreen_saved_color_texture_->id(); |
[email protected] | 9868786 | 2011-07-11 23:31:30 | [diff] [blame] | 2841 | |
| 2842 | // Replace texture info when ID is already in use by parent. |
| 2843 | if (new_parent_impl->texture_manager()->GetTextureInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2844 | new_parent_texture_id)) |
[email protected] | 9868786 | 2011-07-11 23:31:30 | [diff] [blame] | 2845 | new_parent_impl->texture_manager()->RemoveTextureInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2846 | new_parent_texture_id); |
[email protected] | 9868786 | 2011-07-11 23:31:30 | [diff] [blame] | 2847 | |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2848 | offscreen_saved_color_texture_info_ = |
[email protected] | 5f4f2a73 | 2011-07-30 00:47:55 | [diff] [blame] | 2849 | new_parent_impl->CreateTextureInfo(new_parent_texture_id, service_id); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2850 | offscreen_saved_color_texture_info_->SetNotOwned(); |
| 2851 | new_parent_impl->texture_manager()-> |
| 2852 | SetInfoTarget(offscreen_saved_color_texture_info_, GL_TEXTURE_2D); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2853 | |
| 2854 | parent_ = new_parent_impl->AsWeakPtr(); |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 2855 | |
| 2856 | UpdateParentTextureInfo(); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2857 | } else { |
| 2858 | parent_.reset(); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2859 | offscreen_saved_color_texture_info_ = NULL; |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | return true; |
| 2863 | } |
| 2864 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2865 | void GLES2DecoderImpl::UpdateBackbufferMemoryAccounting() { |
| 2866 | size_t total = 0; |
| 2867 | if (offscreen_target_frame_buffer_.get()) { |
| 2868 | if (offscreen_target_color_texture_.get()) { |
| 2869 | total += offscreen_target_color_texture_->estimated_size(); |
| 2870 | } |
| 2871 | if (offscreen_target_color_render_buffer_.get()) { |
| 2872 | total += offscreen_target_color_render_buffer_->estimated_size(); |
| 2873 | } |
| 2874 | if (offscreen_target_depth_render_buffer_.get()) { |
| 2875 | total += offscreen_target_depth_render_buffer_->estimated_size(); |
| 2876 | } |
| 2877 | if (offscreen_target_stencil_render_buffer_.get()) { |
| 2878 | total += offscreen_target_stencil_render_buffer_->estimated_size(); |
| 2879 | } |
| 2880 | if (offscreen_saved_color_texture_.get()) { |
| 2881 | total += offscreen_saved_color_texture_->estimated_size(); |
| 2882 | } |
| 2883 | if (offscreen_resolved_color_texture_.get()) { |
| 2884 | total += offscreen_resolved_color_texture_->estimated_size(); |
| 2885 | } |
| 2886 | } else { |
| 2887 | gfx::Size size = surface_->GetSize(); |
| 2888 | total += size.width() * size.height() * |
| 2889 | GLES2Util::RenderbufferBytesPerPixel(back_buffer_color_format_); |
| 2890 | } |
| 2891 | TRACE_COUNTER_ID1( |
| 2892 | "GLES2DecoderImpl", "BackbufferMemory", this, total); |
| 2893 | } |
| 2894 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2895 | bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 2896 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 2897 | if (!is_offscreen) { |
| 2898 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " |
| 2899 | << " with an onscreen framebuffer."; |
| 2900 | return false; |
| 2901 | } |
| 2902 | |
| 2903 | if (offscreen_size_ == size) |
| 2904 | return true; |
| 2905 | |
| 2906 | offscreen_size_ = size; |
| 2907 | int w = offscreen_size_.width(); |
| 2908 | int h = offscreen_size_.height(); |
| 2909 | if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) { |
| 2910 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 2911 | << "to allocate storage due to excessive dimensions."; |
| 2912 | return false; |
| 2913 | } |
| 2914 | |
| 2915 | // Reallocate the offscreen target buffers. |
| 2916 | DCHECK(offscreen_target_color_format_); |
| 2917 | if (IsOffscreenBufferMultisampled()) { |
| 2918 | if (!offscreen_target_color_render_buffer_->AllocateStorage( |
| 2919 | offscreen_size_, offscreen_target_color_format_, |
| 2920 | offscreen_target_samples_)) { |
| 2921 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 2922 | << "to allocate storage for offscreen target color buffer."; |
| 2923 | return false; |
| 2924 | } |
| 2925 | } else { |
| 2926 | if (!offscreen_target_color_texture_->AllocateStorage( |
| 2927 | offscreen_size_, offscreen_target_color_format_)) { |
| 2928 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 2929 | << "to allocate storage for offscreen target color texture."; |
| 2930 | return false; |
| 2931 | } |
| 2932 | } |
| 2933 | if (offscreen_target_depth_format_ && |
| 2934 | !offscreen_target_depth_render_buffer_->AllocateStorage( |
| 2935 | offscreen_size_, offscreen_target_depth_format_, |
| 2936 | offscreen_target_samples_)) { |
| 2937 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 2938 | << "to allocate storage for offscreen target depth buffer."; |
| 2939 | return false; |
| 2940 | } |
| 2941 | if (offscreen_target_stencil_format_ && |
| 2942 | !offscreen_target_stencil_render_buffer_->AllocateStorage( |
| 2943 | offscreen_size_, offscreen_target_stencil_format_, |
| 2944 | offscreen_target_samples_)) { |
| 2945 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 2946 | << "to allocate storage for offscreen target stencil buffer."; |
| 2947 | return false; |
| 2948 | } |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2949 | UpdateBackbufferMemoryAccounting(); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2950 | |
| 2951 | // Attach the offscreen target buffers to the target frame buffer. |
| 2952 | if (IsOffscreenBufferMultisampled()) { |
| 2953 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 2954 | GL_COLOR_ATTACHMENT0, |
| 2955 | offscreen_target_color_render_buffer_.get()); |
| 2956 | } else { |
| 2957 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 2958 | offscreen_target_color_texture_.get()); |
| 2959 | } |
| 2960 | if (offscreen_target_depth_format_) { |
| 2961 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 2962 | GL_DEPTH_ATTACHMENT, |
| 2963 | offscreen_target_depth_render_buffer_.get()); |
| 2964 | } |
| 2965 | const bool packed_depth_stencil = |
| 2966 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 2967 | if (packed_depth_stencil) { |
| 2968 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 2969 | GL_STENCIL_ATTACHMENT, |
| 2970 | offscreen_target_depth_render_buffer_.get()); |
| 2971 | } else if (offscreen_target_stencil_format_) { |
| 2972 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 2973 | GL_STENCIL_ATTACHMENT, |
| 2974 | offscreen_target_stencil_render_buffer_.get()); |
| 2975 | } |
| 2976 | |
| 2977 | if (offscreen_target_frame_buffer_->CheckStatus() != |
| 2978 | GL_FRAMEBUFFER_COMPLETE) { |
| 2979 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 2980 | << "because offscreen FBO was incomplete."; |
| 2981 | return false; |
| 2982 | } |
| 2983 | |
| 2984 | // Clear the target frame buffer. |
| 2985 | { |
| 2986 | ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
| 2987 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 2988 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
| 2989 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 2990 | glClearStencil(0); |
| 2991 | glStencilMaskSeparate(GL_FRONT, -1); |
| 2992 | glStencilMaskSeparate(GL_BACK, -1); |
| 2993 | glClearDepth(0); |
| 2994 | glDepthMask(GL_TRUE); |
| 2995 | glDisable(GL_SCISSOR_TEST); |
| 2996 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 2997 | RestoreClearState(); |
| 2998 | } |
[email protected] | d85ef76d | 2011-09-08 22:21:43 | [diff] [blame] | 2999 | |
| 3000 | // Destroy the offscreen resolved framebuffers. |
| 3001 | if (offscreen_resolved_frame_buffer_.get()) |
| 3002 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3003 | if (offscreen_resolved_color_texture_.get()) |
| 3004 | offscreen_resolved_color_texture_->Destroy(); |
| 3005 | offscreen_resolved_color_texture_.reset(); |
| 3006 | offscreen_resolved_frame_buffer_.reset(); |
| 3007 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3008 | return true; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3009 | } |
| 3010 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3011 | error::Error GLES2DecoderImpl::HandleResizeCHROMIUM( |
| 3012 | uint32 immediate_data_size, const gles2::ResizeCHROMIUM& c) { |
| 3013 | GLuint width = static_cast<GLuint>(c.width); |
| 3014 | GLuint height = static_cast<GLuint>(c.height); |
| 3015 | TRACE_EVENT2("gpu", "glResizeChromium", "width", width, "height", height); |
[email protected] | a0d98916 | 2011-11-22 13:15:07 | [diff] [blame] | 3016 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && \ |
| 3017 | !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3018 | // Make sure that we are done drawing to the back buffer before resizing. |
| 3019 | glFinish(); |
| 3020 | #endif |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3021 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3022 | if (is_offscreen) { |
| 3023 | if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) |
| 3024 | return error::kLostContext; |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3025 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3026 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3027 | if (!resize_callback_.is_null()) { |
| 3028 | resize_callback_.Run(gfx::Size(width, height)); |
[email protected] | c777de5 | 2011-09-09 23:08:56 | [diff] [blame] | 3029 | DCHECK(context_->IsCurrent(surface_.get())); |
| 3030 | if (!context_->IsCurrent(surface_.get())) |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3031 | return error::kLostContext; |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3032 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3033 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 3034 | UpdateBackbufferMemoryAccounting(); |
| 3035 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3036 | return error::kNoError; |
[email protected] | 43ecf37 | 2010-11-16 19:19:39 | [diff] [blame] | 3037 | } |
| 3038 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3039 | const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
| 3040 | if (command_id > kStartPoint && command_id < kNumCommands) { |
| 3041 | return gles2::GetCommandName(static_cast<CommandId>(command_id)); |
| 3042 | } |
| 3043 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 3044 | } |
| 3045 | |
| 3046 | // Decode command with its arguments, and call the corresponding GL function. |
| 3047 | // Note: args is a pointer to the command buffer. As such, it could be changed |
| 3048 | // by a (malicious) client at any time, so if validation has to happen, it |
| 3049 | // should operate on a copy of them. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3050 | error::Error GLES2DecoderImpl::DoCommand( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3051 | unsigned int command, |
| 3052 | unsigned int arg_count, |
| 3053 | const void* cmd_data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3054 | error::Error result = error::kNoError; |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 3055 | if (log_commands()) { |
[email protected] | 4297cbe | 2011-11-03 18:04:00 | [diff] [blame] | 3056 | LOG(INFO) << "[" << this << "]" << "cmd: " << GetCommandName(command); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3057 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3058 | unsigned int command_index = command - kStartPoint - 1; |
| 3059 | if (command_index < arraysize(g_command_info)) { |
| 3060 | const CommandInfo& info = g_command_info[command_index]; |
| 3061 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 3062 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 3063 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3064 | uint32 immediate_data_size = |
| 3065 | (arg_count - info_arg_count) * sizeof(CommandBufferEntry); // NOLINT |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3066 | switch (command) { |
| 3067 | #define GLES2_CMD_OP(name) \ |
| 3068 | case name::kCmdId: \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3069 | result = Handle ## name( \ |
| 3070 | immediate_data_size, \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3071 | *static_cast<const name*>(cmd_data)); \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3072 | break; \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3073 | |
| 3074 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3075 | #undef GLES2_CMD_OP |
[email protected] | bf0985e | 2009-12-17 03:04:38 | [diff] [blame] | 3076 | } |
| 3077 | if (debug()) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3078 | GLenum error; |
| 3079 | while ((error = glGetError()) != GL_NO_ERROR) { |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 3080 | SetGLError(error, "GL error from driver"); |
| 3081 | LOG(INFO) << "[" << this << "]" |
| 3082 | << "GL ERROR: " << GLES2Util::GetStringEnum(error) << " : " |
| 3083 | << GetCommandName(command); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3084 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3085 | } |
| 3086 | } else { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3087 | result = error::kInvalidArguments; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3088 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3089 | } else { |
| 3090 | result = DoCommonCommand(command, arg_count, cmd_data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3091 | } |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 3092 | if (result == error::kNoError && current_decoder_error_ != error::kNoError) { |
| 3093 | result = current_decoder_error_; |
| 3094 | current_decoder_error_ = error::kNoError; |
| 3095 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3096 | return result; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3097 | } |
| 3098 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3099 | void GLES2DecoderImpl::RemoveBufferInfo(GLuint client_id) { |
| 3100 | buffer_manager()->RemoveBufferInfo(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3101 | } |
| 3102 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3103 | bool GLES2DecoderImpl::CreateProgramHelper(GLuint client_id) { |
| 3104 | if (GetProgramInfo(client_id)) { |
| 3105 | return false; |
| 3106 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3107 | GLuint service_id = glCreateProgram(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3108 | if (service_id != 0) { |
| 3109 | CreateProgramInfo(client_id, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3110 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3111 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3112 | } |
| 3113 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3114 | bool GLES2DecoderImpl::CreateShaderHelper(GLenum type, GLuint client_id) { |
| 3115 | if (GetShaderInfo(client_id)) { |
| 3116 | return false; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3117 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3118 | GLuint service_id = glCreateShader(type); |
| 3119 | if (service_id != 0) { |
[email protected] | 7cea56d9 | 2010-04-28 17:21:38 | [diff] [blame] | 3120 | CreateShaderInfo(client_id, service_id, type); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3121 | } |
| 3122 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3123 | } |
| 3124 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3125 | void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3126 | GLuint texture_index = texture_unit - GL_TEXTURE0; |
[email protected] | 660858b | 2011-07-13 23:16:14 | [diff] [blame] | 3127 | if (texture_index >= group_->max_texture_units()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3128 | SetGLError(GL_INVALID_ENUM, "glActiveTexture: texture_unit out of range."); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3129 | return; |
| 3130 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3131 | active_texture_unit_ = texture_index; |
| 3132 | glActiveTexture(texture_unit); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3133 | } |
| 3134 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3135 | void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3136 | BufferManager::BufferInfo* info = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3137 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3138 | if (client_id != 0) { |
| 3139 | info = GetBufferInfo(client_id); |
| 3140 | if (!info) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3141 | if (!group_->bind_generates_resource()) { |
| 3142 | SetGLError(GL_INVALID_VALUE, |
| 3143 | "glBindBuffer: id not generated by glGenBuffers"); |
| 3144 | return; |
| 3145 | } |
| 3146 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3147 | // It's a new id so make a buffer info for it. |
| 3148 | glGenBuffersARB(1, &service_id); |
| 3149 | CreateBufferInfo(client_id, service_id); |
| 3150 | info = GetBufferInfo(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3151 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3152 | group_->GetIdAllocator(id_namespaces::kBuffers); |
| 3153 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3154 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3155 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3156 | if (info) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3157 | if (!buffer_manager()->SetTarget(info, target)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3158 | SetGLError(GL_INVALID_OPERATION, |
| 3159 | "glBindBuffer: buffer bound to more than 1 target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3160 | return; |
| 3161 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3162 | service_id = info->service_id(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3163 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3164 | switch (target) { |
| 3165 | case GL_ARRAY_BUFFER: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3166 | bound_array_buffer_ = info; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3167 | break; |
| 3168 | case GL_ELEMENT_ARRAY_BUFFER: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3169 | bound_element_array_buffer_ = info; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3170 | break; |
| 3171 | default: |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3172 | NOTREACHED(); // Validation should prevent us getting here. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3173 | break; |
| 3174 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3175 | glBindBuffer(target, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3176 | } |
| 3177 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3178 | bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha() { |
| 3179 | return (GLES2Util::GetChannelsForFormat( |
| 3180 | GetBoundDrawFrameBufferInternalFormat()) & 0x0008) != 0; |
| 3181 | } |
| 3182 | |
| 3183 | bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3184 | FramebufferManager::FramebufferInfo* framebuffer = |
| 3185 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER); |
| 3186 | if (framebuffer) { |
| 3187 | return framebuffer->HasDepthAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3188 | } |
| 3189 | if (offscreen_target_frame_buffer_.get()) { |
| 3190 | return offscreen_target_depth_format_ != 0; |
| 3191 | } |
| 3192 | return back_buffer_has_depth_; |
| 3193 | } |
| 3194 | |
| 3195 | bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3196 | FramebufferManager::FramebufferInfo* framebuffer = |
| 3197 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER); |
| 3198 | if (framebuffer) { |
| 3199 | return framebuffer->HasStencilAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3200 | } |
| 3201 | if (offscreen_target_frame_buffer_.get()) { |
| 3202 | return offscreen_target_stencil_format_ != 0 || |
| 3203 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3204 | } |
| 3205 | return back_buffer_has_stencil_; |
| 3206 | } |
| 3207 | |
| 3208 | void GLES2DecoderImpl::ApplyDirtyState() { |
| 3209 | if (state_dirty_) { |
| 3210 | glColorMask( |
| 3211 | mask_red_, mask_green_, mask_blue_, |
| 3212 | mask_alpha_ && BoundFramebufferHasColorAttachmentWithAlpha()); |
| 3213 | bool have_depth = BoundFramebufferHasDepthAttachment(); |
| 3214 | glDepthMask(mask_depth_ && have_depth); |
| 3215 | EnableDisable(GL_DEPTH_TEST, enable_depth_test_ && have_depth); |
| 3216 | bool have_stencil = BoundFramebufferHasStencilAttachment(); |
| 3217 | glStencilMaskSeparate(GL_FRONT, have_stencil ? mask_stencil_front_ : 0); |
| 3218 | glStencilMaskSeparate(GL_BACK, have_stencil ? mask_stencil_back_ : 0); |
| 3219 | EnableDisable(GL_STENCIL_TEST, enable_stencil_test_ && have_stencil); |
| 3220 | state_dirty_ = false; |
| 3221 | } |
| 3222 | } |
| 3223 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3224 | GLuint GLES2DecoderImpl::GetBackbufferServiceId() { |
| 3225 | return (offscreen_target_frame_buffer_.get()) ? |
| 3226 | offscreen_target_frame_buffer_->id() : |
| 3227 | surface_->GetBackingFrameBufferObject(); |
| 3228 | } |
| 3229 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3230 | void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { |
| 3231 | FramebufferManager::FramebufferInfo* info = NULL; |
| 3232 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3233 | if (client_id != 0) { |
| 3234 | info = GetFramebufferInfo(client_id); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3235 | if (!info) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3236 | if (!group_->bind_generates_resource()) { |
| 3237 | SetGLError(GL_INVALID_VALUE, |
| 3238 | "glBindFramebuffer: id not generated by glGenFramebuffers"); |
| 3239 | return; |
| 3240 | } |
| 3241 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3242 | // It's a new id so make a framebuffer info for it. |
| 3243 | glGenFramebuffersEXT(1, &service_id); |
| 3244 | CreateFramebufferInfo(client_id, service_id); |
| 3245 | info = GetFramebufferInfo(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3246 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3247 | group_->GetIdAllocator(id_namespaces::kFramebuffers); |
| 3248 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3249 | } else { |
| 3250 | service_id = info->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3251 | } |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 3252 | info->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3253 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3254 | |
| 3255 | if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { |
| 3256 | bound_draw_framebuffer_ = info; |
| 3257 | } |
| 3258 | if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { |
| 3259 | bound_read_framebuffer_ = info; |
| 3260 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3261 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3262 | state_dirty_ = true; |
| 3263 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3264 | // If we are rendering to the backbuffer get the FBO id for any simulated |
| 3265 | // backbuffer. |
| 3266 | if (info == NULL) { |
| 3267 | service_id = GetBackbufferServiceId(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3268 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3269 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3270 | glBindFramebufferEXT(target, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 3271 | } |
| 3272 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3273 | void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { |
| 3274 | RenderbufferManager::RenderbufferInfo* info = NULL; |
| 3275 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3276 | if (client_id != 0) { |
| 3277 | info = GetRenderbufferInfo(client_id); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3278 | if (!info) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3279 | if (!group_->bind_generates_resource()) { |
| 3280 | SetGLError( |
| 3281 | GL_INVALID_VALUE, |
| 3282 | "glBindRenderbuffer: id not generated by glGenRenderbuffers"); |
| 3283 | return; |
| 3284 | } |
| 3285 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3286 | // It's a new id so make a renderbuffer info for it. |
| 3287 | glGenRenderbuffersEXT(1, &service_id); |
| 3288 | CreateRenderbufferInfo(client_id, service_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3289 | info = GetRenderbufferInfo(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3290 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3291 | group_->GetIdAllocator(id_namespaces::kRenderbuffers); |
| 3292 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3293 | } else { |
| 3294 | service_id = info->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3295 | } |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 3296 | info->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3297 | } |
| 3298 | bound_renderbuffer_ = info; |
| 3299 | glBindRenderbufferEXT(target, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 3300 | } |
| 3301 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3302 | void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3303 | TextureManager::TextureInfo* info = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3304 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3305 | if (client_id != 0) { |
| 3306 | info = GetTextureInfo(client_id); |
| 3307 | if (!info) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3308 | if (!group_->bind_generates_resource()) { |
| 3309 | SetGLError(GL_INVALID_VALUE, |
| 3310 | "glBindTexture: id not generated by glGenTextures"); |
| 3311 | return; |
| 3312 | } |
| 3313 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3314 | // It's a new id so make a texture info for it. |
| 3315 | glGenTextures(1, &service_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3316 | DCHECK_NE(0u, service_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3317 | CreateTextureInfo(client_id, service_id); |
| 3318 | info = GetTextureInfo(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3319 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3320 | group_->GetIdAllocator(id_namespaces::kTextures); |
| 3321 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3322 | } |
| 3323 | } else { |
| 3324 | info = texture_manager()->GetDefaultTextureInfo(target); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3325 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3326 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3327 | // Check the texture exists |
| 3328 | // Check that we are not trying to bind it to a different target. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3329 | if (info->target() != 0 && info->target() != target) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3330 | SetGLError(GL_INVALID_OPERATION, |
| 3331 | "glBindTexture: texture bound to more than 1 target."); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3332 | return; |
| 3333 | } |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 3334 | if (info->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { |
| 3335 | SetGLError(GL_INVALID_OPERATION, |
| 3336 | "glBindTexture: illegal target for stream texture."); |
| 3337 | return; |
| 3338 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3339 | if (info->target() == 0) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3340 | texture_manager()->SetInfoTarget(info, target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3341 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3342 | glBindTexture(target, info->service_id()); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3343 | TextureUnit& unit = texture_units_[active_texture_unit_]; |
| 3344 | unit.bind_target = target; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3345 | switch (target) { |
| 3346 | case GL_TEXTURE_2D: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3347 | unit.bound_texture_2d = info; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3348 | break; |
| 3349 | case GL_TEXTURE_CUBE_MAP: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3350 | unit.bound_texture_cube_map = info; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3351 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3352 | case GL_TEXTURE_EXTERNAL_OES: |
| 3353 | unit.bound_texture_external_oes = info; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 3354 | if (info->IsStreamTexture()) { |
| 3355 | DCHECK(stream_texture_manager_); |
| 3356 | StreamTexture* stream_tex = |
| 3357 | stream_texture_manager_->LookupStreamTexture(info->service_id()); |
| 3358 | if (stream_tex) |
| 3359 | stream_tex->Update(); |
| 3360 | } |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3361 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3362 | case GL_TEXTURE_RECTANGLE_ARB: |
| 3363 | unit.bound_texture_rectangle_arb = info; |
| 3364 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3365 | default: |
| 3366 | NOTREACHED(); // Validation should prevent us getting here. |
| 3367 | break; |
| 3368 | } |
| 3369 | } |
| 3370 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3371 | void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 3372 | if (vertex_attrib_manager_->Enable(index, false)) { |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 3373 | if (index != 0 || |
| 3374 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3375 | glDisableVertexAttribArray(index); |
| 3376 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3377 | } else { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3378 | SetGLError(GL_INVALID_VALUE, |
| 3379 | "glDisableVertexAttribArray: index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 3384 | if (vertex_attrib_manager_->Enable(index, true)) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3385 | glEnableVertexAttribArray(index); |
| 3386 | } else { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3387 | SetGLError(GL_INVALID_VALUE, |
| 3388 | "glEnableVertexAttribArray: index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3389 | } |
| 3390 | } |
| 3391 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3392 | void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3393 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 3394 | if (!info || |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3395 | !texture_manager()->MarkMipmapsGenerated(info)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3396 | SetGLError(GL_INVALID_OPERATION, |
| 3397 | "glGenerateMipmaps: Can not generate mips for npot textures"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3398 | return; |
| 3399 | } |
[email protected] | 59f3ca0 | 2011-03-26 22:24:19 | [diff] [blame] | 3400 | // Workaround for Mac driver bug. In the large scheme of things setting |
| 3401 | // glTexParamter twice for glGenerateMipmap is probably not a lage performance |
[email protected] | a8bad26 | 2011-10-21 18:28:56 | [diff] [blame] | 3402 | // hit so there's probably no need to make this conditional. The bug appears |
| 3403 | // to be that if the filtering mode is set to something that doesn't require |
| 3404 | // mipmaps for rendering, or is never set to something other than the default, |
| 3405 | // then glGenerateMipmap misbehaves. |
| 3406 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3407 | glGenerateMipmapEXT(target); |
[email protected] | 59f3ca0 | 2011-03-26 22:24:19 | [diff] [blame] | 3408 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, info->min_filter()); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3409 | } |
| 3410 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3411 | bool GLES2DecoderImpl::GetHelper( |
| 3412 | GLenum pname, GLint* params, GLsizei* num_written) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3413 | DCHECK(num_written); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3414 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 3415 | switch (pname) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3416 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 3417 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3418 | if (params) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 3419 | *params = GL_RGBA; // We don't support other formats. |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3420 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3421 | return true; |
| 3422 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 3423 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3424 | if (params) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 3425 | *params = GL_UNSIGNED_BYTE; // We don't support other types. |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3426 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3427 | return true; |
| 3428 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 3429 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3430 | if (params) { |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 3431 | *params = group_->max_fragment_uniform_vectors(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3432 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3433 | return true; |
| 3434 | case GL_MAX_VARYING_VECTORS: |
| 3435 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3436 | if (params) { |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 3437 | *params = group_->max_varying_vectors(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3438 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3439 | return true; |
| 3440 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 3441 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3442 | if (params) { |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 3443 | *params = group_->max_vertex_uniform_vectors(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3444 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3445 | return true; |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 3446 | } |
| 3447 | } |
| 3448 | switch (pname) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 3449 | case GL_MAX_VIEWPORT_DIMS: |
| 3450 | if (offscreen_target_frame_buffer_.get()) { |
| 3451 | *num_written = 2; |
| 3452 | if (params) { |
| 3453 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 3454 | params[1] = renderbuffer_manager()->max_renderbuffer_size(); |
| 3455 | } |
| 3456 | return true; |
| 3457 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 3458 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 3459 | case GL_MAX_SAMPLES: |
| 3460 | *num_written = 1; |
| 3461 | if (params) { |
| 3462 | params[0] = renderbuffer_manager()->max_samples(); |
| 3463 | } |
| 3464 | return true; |
| 3465 | case GL_MAX_RENDERBUFFER_SIZE: |
| 3466 | *num_written = 1; |
| 3467 | if (params) { |
| 3468 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 3469 | } |
| 3470 | return true; |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 3471 | case GL_MAX_TEXTURE_SIZE: |
| 3472 | *num_written = 1; |
| 3473 | if (params) { |
| 3474 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D); |
| 3475 | } |
| 3476 | return true; |
| 3477 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 3478 | *num_written = 1; |
| 3479 | if (params) { |
| 3480 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP); |
| 3481 | } |
| 3482 | return true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3483 | case GL_COLOR_WRITEMASK: |
| 3484 | *num_written = 4; |
| 3485 | if (params) { |
| 3486 | params[0] = mask_red_; |
| 3487 | params[1] = mask_green_; |
| 3488 | params[2] = mask_blue_; |
| 3489 | params[3] = mask_alpha_; |
| 3490 | } |
| 3491 | return true; |
| 3492 | case GL_DEPTH_WRITEMASK: |
| 3493 | *num_written = 1; |
| 3494 | if (params) { |
| 3495 | params[0] = mask_depth_; |
| 3496 | } |
| 3497 | return true; |
| 3498 | case GL_STENCIL_BACK_WRITEMASK: |
| 3499 | *num_written = 1; |
| 3500 | if (params) { |
| 3501 | params[0] = mask_stencil_back_; |
| 3502 | } |
| 3503 | return true; |
| 3504 | case GL_STENCIL_WRITEMASK: |
| 3505 | *num_written = 1; |
| 3506 | if (params) { |
| 3507 | params[0] = mask_stencil_front_; |
| 3508 | } |
| 3509 | return true; |
| 3510 | case GL_DEPTH_TEST: |
| 3511 | *num_written = 1; |
| 3512 | if (params) { |
| 3513 | params[0] = enable_depth_test_; |
| 3514 | } |
| 3515 | return true; |
| 3516 | case GL_STENCIL_TEST: |
| 3517 | *num_written = 1; |
| 3518 | if (params) { |
| 3519 | params[0] = enable_stencil_test_; |
| 3520 | } |
| 3521 | return true; |
| 3522 | case GL_ALPHA_BITS: |
| 3523 | *num_written = 1; |
| 3524 | if (params) { |
| 3525 | GLint v = 0; |
| 3526 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 3527 | params[0] = BoundFramebufferHasColorAttachmentWithAlpha() ? v : 0; |
| 3528 | } |
| 3529 | return true; |
| 3530 | case GL_DEPTH_BITS: |
| 3531 | *num_written = 1; |
| 3532 | if (params) { |
| 3533 | GLint v = 0; |
| 3534 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 3535 | params[0] = BoundFramebufferHasDepthAttachment() ? v : 0; |
| 3536 | } |
| 3537 | return true; |
| 3538 | case GL_STENCIL_BITS: |
| 3539 | *num_written = 1; |
| 3540 | if (params) { |
| 3541 | GLint v = 0; |
| 3542 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 3543 | params[0] = BoundFramebufferHasStencilAttachment() ? v : 0; |
| 3544 | } |
| 3545 | return true; |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 3546 | case GL_COMPRESSED_TEXTURE_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3547 | *num_written = validators_->compressed_texture_format.GetValues().size(); |
| 3548 | if (params) { |
| 3549 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 3550 | params[ii] = validators_->compressed_texture_format.GetValues()[ii]; |
| 3551 | } |
| 3552 | } |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 3553 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3554 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 3555 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3556 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3557 | *params = validators_->compressed_texture_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3558 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3559 | return true; |
| 3560 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 3561 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3562 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3563 | *params = validators_->shader_binary_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3564 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3565 | return true; |
| 3566 | case GL_SHADER_BINARY_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3567 | *num_written = validators_->shader_binary_format.GetValues().size(); |
| 3568 | if (params) { |
| 3569 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 3570 | params[ii] = validators_->shader_binary_format.GetValues()[ii]; |
| 3571 | } |
| 3572 | } |
| 3573 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3574 | case GL_SHADER_COMPILER: |
| 3575 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3576 | if (params) { |
| 3577 | *params = GL_TRUE; |
| 3578 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3579 | return true; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3580 | case GL_ARRAY_BUFFER_BINDING: |
| 3581 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3582 | if (params) { |
| 3583 | if (bound_array_buffer_) { |
| 3584 | GLuint client_id = 0; |
| 3585 | buffer_manager()->GetClientId(bound_array_buffer_->service_id(), |
| 3586 | &client_id); |
| 3587 | *params = client_id; |
| 3588 | } else { |
| 3589 | *params = 0; |
| 3590 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3591 | } |
| 3592 | return true; |
| 3593 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 3594 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3595 | if (params) { |
| 3596 | if (bound_element_array_buffer_) { |
| 3597 | GLuint client_id = 0; |
| 3598 | buffer_manager()->GetClientId( |
| 3599 | bound_element_array_buffer_->service_id(), |
| 3600 | &client_id); |
| 3601 | *params = client_id; |
| 3602 | } else { |
| 3603 | *params = 0; |
| 3604 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3605 | } |
| 3606 | return true; |
| 3607 | case GL_FRAMEBUFFER_BINDING: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3608 | // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3609 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3610 | if (params) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3611 | FramebufferManager::FramebufferInfo* framebuffer = |
| 3612 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER); |
| 3613 | if (framebuffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3614 | GLuint client_id = 0; |
| 3615 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3616 | framebuffer->service_id(), &client_id); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3617 | *params = client_id; |
| 3618 | } else { |
| 3619 | *params = 0; |
| 3620 | } |
| 3621 | } |
| 3622 | return true; |
| 3623 | case GL_READ_FRAMEBUFFER_BINDING: |
| 3624 | *num_written = 1; |
| 3625 | if (params) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3626 | FramebufferManager::FramebufferInfo* framebuffer = |
| 3627 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER); |
| 3628 | if (framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3629 | GLuint client_id = 0; |
| 3630 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3631 | framebuffer->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3632 | *params = client_id; |
| 3633 | } else { |
| 3634 | *params = 0; |
| 3635 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3636 | } |
| 3637 | return true; |
| 3638 | case GL_RENDERBUFFER_BINDING: |
| 3639 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3640 | if (params) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3641 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 3642 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 3643 | if (renderbuffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3644 | GLuint client_id = 0; |
| 3645 | renderbuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3646 | renderbuffer->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3647 | *params = client_id; |
| 3648 | } else { |
| 3649 | *params = 0; |
| 3650 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3651 | } |
| 3652 | return true; |
| 3653 | case GL_CURRENT_PROGRAM: |
| 3654 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3655 | if (params) { |
| 3656 | if (current_program_) { |
| 3657 | GLuint client_id = 0; |
| 3658 | program_manager()->GetClientId( |
| 3659 | current_program_->service_id(), &client_id); |
| 3660 | *params = client_id; |
| 3661 | } else { |
| 3662 | *params = 0; |
| 3663 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3664 | } |
| 3665 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3666 | case GL_TEXTURE_BINDING_2D: |
| 3667 | *num_written = 1; |
| 3668 | if (params) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3669 | TextureUnit& unit = texture_units_[active_texture_unit_]; |
| 3670 | if (unit.bound_texture_2d) { |
| 3671 | GLuint client_id = 0; |
| 3672 | texture_manager()->GetClientId( |
| 3673 | unit.bound_texture_2d->service_id(), &client_id); |
| 3674 | *params = client_id; |
| 3675 | } else { |
| 3676 | *params = 0; |
| 3677 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3678 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3679 | return true; |
| 3680 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 3681 | *num_written = 1; |
| 3682 | if (params) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3683 | TextureUnit& unit = texture_units_[active_texture_unit_]; |
| 3684 | if (unit.bound_texture_cube_map) { |
| 3685 | GLuint client_id = 0; |
| 3686 | texture_manager()->GetClientId( |
| 3687 | unit.bound_texture_cube_map->service_id(), &client_id); |
| 3688 | *params = client_id; |
| 3689 | } else { |
| 3690 | *params = 0; |
| 3691 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3692 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3693 | return true; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3694 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 3695 | *num_written = 1; |
| 3696 | if (params) { |
| 3697 | TextureUnit& unit = texture_units_[active_texture_unit_]; |
| 3698 | if (unit.bound_texture_external_oes) { |
| 3699 | GLuint client_id = 0; |
| 3700 | texture_manager()->GetClientId( |
| 3701 | unit.bound_texture_external_oes->service_id(), &client_id); |
| 3702 | *params = client_id; |
| 3703 | } else { |
| 3704 | *params = 0; |
| 3705 | } |
| 3706 | } |
| 3707 | return true; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3708 | case GL_TEXTURE_BINDING_RECTANGLE_ARB: |
| 3709 | *num_written = 1; |
| 3710 | if (params) { |
| 3711 | TextureUnit& unit = texture_units_[active_texture_unit_]; |
| 3712 | if (unit.bound_texture_rectangle_arb) { |
| 3713 | GLuint client_id = 0; |
| 3714 | texture_manager()->GetClientId( |
| 3715 | unit.bound_texture_rectangle_arb->service_id(), &client_id); |
| 3716 | *params = client_id; |
| 3717 | } else { |
| 3718 | *params = 0; |
| 3719 | } |
| 3720 | } |
| 3721 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3722 | default: |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3723 | *num_written = util_.GLGetNumValuesReturned(pname); |
[email protected] | c5d79834 | 2010-09-24 20:42:53 | [diff] [blame] | 3724 | return false; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3725 | } |
| 3726 | } |
| 3727 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3728 | bool GLES2DecoderImpl::GetNumValuesReturnedForGLGet( |
| 3729 | GLenum pname, GLsizei* num_values) { |
| 3730 | return GetHelper(pname, NULL, num_values); |
| 3731 | } |
| 3732 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3733 | void GLES2DecoderImpl::DoGetBooleanv(GLenum pname, GLboolean* params) { |
| 3734 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3735 | GLsizei num_written = 0; |
| 3736 | if (GetHelper(pname, NULL, &num_written)) { |
| 3737 | scoped_array<GLint> values(new GLint[num_written]); |
| 3738 | GetHelper(pname, values.get(), &num_written); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3739 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 3740 | params[ii] = static_cast<GLboolean>(values[ii]); |
| 3741 | } |
| 3742 | } else { |
| 3743 | glGetBooleanv(pname, params); |
| 3744 | } |
| 3745 | } |
| 3746 | |
| 3747 | void GLES2DecoderImpl::DoGetFloatv(GLenum pname, GLfloat* params) { |
| 3748 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3749 | GLsizei num_written = 0; |
| 3750 | if (GetHelper(pname, NULL, &num_written)) { |
| 3751 | scoped_array<GLint> values(new GLint[num_written]); |
| 3752 | GetHelper(pname, values.get(), &num_written); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3753 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 3754 | params[ii] = static_cast<GLfloat>(values[ii]); |
| 3755 | } |
| 3756 | } else { |
| 3757 | glGetFloatv(pname, params); |
| 3758 | } |
| 3759 | } |
| 3760 | |
| 3761 | void GLES2DecoderImpl::DoGetIntegerv(GLenum pname, GLint* params) { |
| 3762 | DCHECK(params); |
| 3763 | GLsizei num_written; |
| 3764 | if (!GetHelper(pname, params, &num_written)) { |
| 3765 | glGetIntegerv(pname, params); |
| 3766 | } |
| 3767 | } |
| 3768 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 3769 | void GLES2DecoderImpl::DoGetProgramiv( |
| 3770 | GLuint program_id, GLenum pname, GLint* params) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3771 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 3772 | program_id, "glGetProgramiv"); |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 3773 | if (!info) { |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 3774 | return; |
| 3775 | } |
| 3776 | info->GetProgramiv(pname, params); |
| 3777 | } |
| 3778 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3779 | void GLES2DecoderImpl::DoBindAttribLocation( |
| 3780 | GLuint program, GLuint index, const char* name) { |
| 3781 | if (!StringIsValidForGLES(name)) { |
| 3782 | SetGLError(GL_INVALID_VALUE, "glBindAttribLocation: Invalid character"); |
| 3783 | return; |
| 3784 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3785 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 3786 | program, "glBindAttribLocation"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3787 | if (!info) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3788 | return; |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3789 | } |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3790 | glBindAttribLocation(info->service_id(), index, name); |
| 3791 | } |
| 3792 | |
| 3793 | error::Error GLES2DecoderImpl::HandleBindAttribLocation( |
| 3794 | uint32 immediate_data_size, const gles2::BindAttribLocation& c) { |
| 3795 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3796 | GLuint index = static_cast<GLuint>(c.index); |
| 3797 | uint32 name_size = c.data_size; |
| 3798 | const char* name = GetSharedMemoryAs<const char*>( |
| 3799 | c.name_shm_id, c.name_shm_offset, name_size); |
| 3800 | if (name == NULL) { |
| 3801 | return error::kOutOfBounds; |
| 3802 | } |
| 3803 | String name_str(name, name_size); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3804 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3805 | return error::kNoError; |
| 3806 | } |
| 3807 | |
| 3808 | error::Error GLES2DecoderImpl::HandleBindAttribLocationImmediate( |
| 3809 | uint32 immediate_data_size, const gles2::BindAttribLocationImmediate& c) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3810 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3811 | GLuint index = static_cast<GLuint>(c.index); |
| 3812 | uint32 name_size = c.data_size; |
| 3813 | const char* name = GetImmediateDataAs<const char*>( |
| 3814 | c, name_size, immediate_data_size); |
| 3815 | if (name == NULL) { |
| 3816 | return error::kOutOfBounds; |
| 3817 | } |
| 3818 | String name_str(name, name_size); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3819 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3820 | return error::kNoError; |
| 3821 | } |
| 3822 | |
| 3823 | error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( |
| 3824 | uint32 immediate_data_size, const gles2::BindAttribLocationBucket& c) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3825 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3826 | GLuint index = static_cast<GLuint>(c.index); |
| 3827 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 3828 | if (!bucket || bucket->size() == 0) { |
| 3829 | return error::kInvalidArguments; |
| 3830 | } |
| 3831 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 3832 | if (!bucket->GetAsString(&name_str)) { |
| 3833 | return error::kInvalidArguments; |
| 3834 | } |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3835 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3836 | return error::kNoError; |
| 3837 | } |
| 3838 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3839 | error::Error GLES2DecoderImpl::HandleDeleteShader( |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 3840 | uint32 immediate_data_size, const gles2::DeleteShader& c) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3841 | GLuint client_id = c.shader; |
| 3842 | if (client_id) { |
| 3843 | ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); |
| 3844 | if (info) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 3845 | if (!info->IsDeleted()) { |
| 3846 | glDeleteShader(info->service_id()); |
| 3847 | shader_manager()->MarkAsDeleted(info); |
| 3848 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3849 | } else { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3850 | SetGLError(GL_INVALID_VALUE, "glDeleteShader: unknown shader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3851 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3852 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3853 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3854 | } |
| 3855 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3856 | error::Error GLES2DecoderImpl::HandleDeleteProgram( |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 3857 | uint32 immediate_data_size, const gles2::DeleteProgram& c) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3858 | GLuint client_id = c.program; |
| 3859 | if (client_id) { |
| 3860 | ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); |
| 3861 | if (info) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 3862 | if (!info->IsDeleted()) { |
| 3863 | glDeleteProgram(info->service_id()); |
| 3864 | program_manager()->MarkAsDeleted(shader_manager(), info); |
| 3865 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3866 | } else { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3867 | SetGLError(GL_INVALID_VALUE, "glDeleteProgram: unknown program"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3868 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3869 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3870 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3871 | } |
| 3872 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3873 | void GLES2DecoderImpl::DoDeleteSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3874 | GLuint namespace_id, GLsizei n, const GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3875 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3876 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3877 | id_allocator->FreeID(ids[ii]); |
| 3878 | } |
| 3879 | } |
| 3880 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3881 | error::Error GLES2DecoderImpl::HandleDeleteSharedIdsCHROMIUM( |
| 3882 | uint32 immediate_data_size, const gles2::DeleteSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3883 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 3884 | GLsizei n = static_cast<GLsizei>(c.n); |
| 3885 | uint32 data_size; |
| 3886 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 3887 | return error::kOutOfBounds; |
| 3888 | } |
| 3889 | const GLuint* ids = GetSharedMemoryAs<const GLuint*>( |
| 3890 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 3891 | if (n < 0) { |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3892 | SetGLError(GL_INVALID_VALUE, "DeleteSharedIdsCHROMIUM: n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3893 | return error::kNoError; |
| 3894 | } |
| 3895 | if (ids == NULL) { |
| 3896 | return error::kOutOfBounds; |
| 3897 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3898 | DoDeleteSharedIdsCHROMIUM(namespace_id, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3899 | return error::kNoError; |
| 3900 | } |
| 3901 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3902 | void GLES2DecoderImpl::DoGenSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3903 | GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3904 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3905 | if (id_offset == 0) { |
| 3906 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3907 | ids[ii] = id_allocator->AllocateID(); |
| 3908 | } |
| 3909 | } else { |
| 3910 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3911 | ids[ii] = id_allocator->AllocateIDAtOrAbove(id_offset); |
| 3912 | id_offset = ids[ii] + 1; |
| 3913 | } |
| 3914 | } |
| 3915 | } |
| 3916 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3917 | error::Error GLES2DecoderImpl::HandleGenSharedIdsCHROMIUM( |
| 3918 | uint32 immediate_data_size, const gles2::GenSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3919 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 3920 | GLuint id_offset = static_cast<GLuint>(c.id_offset); |
| 3921 | GLsizei n = static_cast<GLsizei>(c.n); |
| 3922 | uint32 data_size; |
| 3923 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 3924 | return error::kOutOfBounds; |
| 3925 | } |
| 3926 | GLuint* ids = GetSharedMemoryAs<GLuint*>( |
| 3927 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 3928 | if (n < 0) { |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3929 | SetGLError(GL_INVALID_VALUE, "GenSharedIdsCHROMIUM: n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3930 | return error::kNoError; |
| 3931 | } |
| 3932 | if (ids == NULL) { |
| 3933 | return error::kOutOfBounds; |
| 3934 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3935 | DoGenSharedIdsCHROMIUM(namespace_id, id_offset, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3936 | return error::kNoError; |
| 3937 | } |
| 3938 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3939 | void GLES2DecoderImpl::DoRegisterSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3940 | GLuint namespace_id, GLsizei n, const GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3941 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3942 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3943 | if (!id_allocator->MarkAsUsed(ids[ii])) { |
| 3944 | for (GLsizei jj = 0; jj < ii; ++jj) { |
| 3945 | id_allocator->FreeID(ids[jj]); |
| 3946 | } |
| 3947 | SetGLError( |
| 3948 | GL_INVALID_VALUE, |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3949 | "RegisterSharedIdsCHROMIUM: attempt to register " |
| 3950 | "id that already exists"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3951 | return; |
| 3952 | } |
| 3953 | } |
| 3954 | } |
| 3955 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3956 | error::Error GLES2DecoderImpl::HandleRegisterSharedIdsCHROMIUM( |
| 3957 | uint32 immediate_data_size, const gles2::RegisterSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3958 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 3959 | GLsizei n = static_cast<GLsizei>(c.n); |
| 3960 | uint32 data_size; |
| 3961 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 3962 | return error::kOutOfBounds; |
| 3963 | } |
| 3964 | GLuint* ids = GetSharedMemoryAs<GLuint*>( |
| 3965 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 3966 | if (n < 0) { |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3967 | SetGLError(GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM: n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3968 | return error::kNoError; |
| 3969 | } |
| 3970 | if (ids == NULL) { |
| 3971 | return error::kOutOfBounds; |
| 3972 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 3973 | DoRegisterSharedIdsCHROMIUM(namespace_id, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3974 | return error::kNoError; |
| 3975 | } |
| 3976 | |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3977 | void GLES2DecoderImpl::DoClear(GLbitfield mask) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3978 | if (CheckBoundFramebuffersValid("glClear")) { |
[email protected] | 529c667 | 2012-01-04 02:18:26 | [diff] [blame] | 3979 | UNSHIPPED_TRACE_EVENT_INSTANT2("test_gpu", "DoClear", "red", clear_red_, |
| 3980 | "green", clear_green_); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3981 | ApplyDirtyState(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3982 | glClear(mask); |
| 3983 | } |
| 3984 | } |
| 3985 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3986 | void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
| 3987 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3988 | GLuint client_renderbuffer_id) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3989 | FramebufferManager::FramebufferInfo* framebuffer_info = |
| 3990 | GetFramebufferInfoForTarget(target); |
| 3991 | if (!framebuffer_info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3992 | SetGLError(GL_INVALID_OPERATION, |
| 3993 | "glFramebufferRenderbuffer: no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3994 | return; |
| 3995 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3996 | GLuint service_id = 0; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 3997 | RenderbufferManager::RenderbufferInfo* info = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3998 | if (client_renderbuffer_id) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 3999 | info = GetRenderbufferInfo(client_renderbuffer_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4000 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4001 | SetGLError(GL_INVALID_OPERATION, |
| 4002 | "glFramebufferRenderbuffer: unknown renderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4003 | return; |
| 4004 | } |
| 4005 | service_id = info->service_id(); |
| 4006 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4007 | CopyRealGLErrorsToWrapper(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4008 | glFramebufferRenderbufferEXT( |
| 4009 | target, attachment, renderbuffertarget, service_id); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4010 | GLenum error = PeekGLError(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4011 | if (error == GL_NO_ERROR) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4012 | framebuffer_info->AttachRenderbuffer(attachment, info); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4013 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4014 | if (framebuffer_info == bound_draw_framebuffer_) { |
| 4015 | state_dirty_ = true; |
| 4016 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4017 | } |
| 4018 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4019 | bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4020 | switch (cap) { |
| 4021 | case GL_SCISSOR_TEST: |
| 4022 | enable_scissor_test_ = enabled; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4023 | return true; |
| 4024 | case GL_DEPTH_TEST: { |
| 4025 | if (enable_depth_test_ != enabled) { |
| 4026 | enable_depth_test_ = enabled; |
| 4027 | state_dirty_ = true; |
| 4028 | } |
| 4029 | return false; |
| 4030 | } |
| 4031 | case GL_STENCIL_TEST: |
| 4032 | if (enable_stencil_test_ != enabled) { |
| 4033 | enable_stencil_test_ = enabled; |
| 4034 | state_dirty_ = true; |
| 4035 | } |
| 4036 | return false; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4037 | default: |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4038 | return true; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | void GLES2DecoderImpl::DoDisable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4043 | if (SetCapabilityState(cap, false)) { |
| 4044 | glDisable(cap); |
| 4045 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | void GLES2DecoderImpl::DoEnable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4049 | if (SetCapabilityState(cap, true)) { |
| 4050 | glEnable(cap); |
| 4051 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | void GLES2DecoderImpl::DoClearColor( |
| 4055 | GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { |
| 4056 | clear_red_ = red; |
| 4057 | clear_green_ = green; |
| 4058 | clear_blue_ = blue; |
| 4059 | clear_alpha_ = alpha; |
| 4060 | glClearColor(red, green, blue, alpha); |
| 4061 | } |
| 4062 | |
| 4063 | void GLES2DecoderImpl::DoClearDepthf(GLclampf depth) { |
| 4064 | clear_depth_ = depth; |
| 4065 | glClearDepth(depth); |
| 4066 | } |
| 4067 | |
| 4068 | void GLES2DecoderImpl::DoClearStencil(GLint s) { |
| 4069 | clear_stencil_ = s; |
| 4070 | glClearStencil(s); |
| 4071 | } |
| 4072 | |
| 4073 | void GLES2DecoderImpl::DoColorMask( |
| 4074 | GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { |
| 4075 | mask_red_ = red; |
| 4076 | mask_green_ = green; |
| 4077 | mask_blue_ = blue; |
| 4078 | mask_alpha_ = alpha; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4079 | state_dirty_ = true; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | void GLES2DecoderImpl::DoDepthMask(GLboolean depth) { |
| 4083 | mask_depth_ = depth; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4084 | state_dirty_ = true; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | void GLES2DecoderImpl::DoStencilMask(GLuint mask) { |
| 4088 | mask_stencil_front_ = mask; |
| 4089 | mask_stencil_back_ = mask; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4090 | state_dirty_ = true; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | void GLES2DecoderImpl::DoStencilMaskSeparate(GLenum face, GLuint mask) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4094 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4095 | mask_stencil_front_ = mask; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4096 | } |
| 4097 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4098 | mask_stencil_back_ = mask; |
| 4099 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4100 | state_dirty_ = true; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4101 | } |
| 4102 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4103 | // Assumes framebuffer is complete. |
| 4104 | void GLES2DecoderImpl::ClearUnclearedAttachments( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4105 | GLenum target, FramebufferManager::FramebufferInfo* info) { |
| 4106 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4107 | // bind this to the DRAW point, clear then bind back to READ |
| 4108 | // TODO(gman): I don't think there is any guarantee that an FBO that |
| 4109 | // is complete on the READ attachment will be complete as a DRAW |
| 4110 | // attachment. |
| 4111 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
| 4112 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, info->service_id()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4113 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4114 | GLbitfield clear_bits = 0; |
| 4115 | if (info->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4116 | glClearColor( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4117 | 0.0f, 0.0f, 0.0f, |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4118 | (GLES2Util::GetChannelsForFormat( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4119 | info->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : 1.0f); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4120 | glColorMask(true, true, true, true); |
| 4121 | clear_bits |= GL_COLOR_BUFFER_BIT; |
| 4122 | } |
| 4123 | |
| 4124 | if (info->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 4125 | info->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
| 4126 | glClearStencil(0); |
| 4127 | glStencilMask(-1); |
| 4128 | clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 4129 | } |
| 4130 | |
| 4131 | if (info->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 4132 | info->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
| 4133 | glClearDepth(1.0f); |
| 4134 | glDepthMask(true); |
| 4135 | clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 4136 | } |
| 4137 | |
| 4138 | glDisable(GL_SCISSOR_TEST); |
| 4139 | glClear(clear_bits); |
| 4140 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 4141 | framebuffer_manager()->MarkAttachmentsAsCleared( |
| 4142 | info, renderbuffer_manager(), texture_manager()); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4143 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 4144 | RestoreClearState(); |
| 4145 | |
| 4146 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4147 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, info->service_id()); |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 4148 | FramebufferManager::FramebufferInfo* framebuffer = |
| 4149 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 4150 | GLuint service_id = |
| 4151 | framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
| 4152 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 4153 | } |
| 4154 | } |
| 4155 | |
| 4156 | void GLES2DecoderImpl::RestoreClearState() { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4157 | state_dirty_ = true; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4158 | glClearColor(clear_red_, clear_green_, clear_blue_, clear_alpha_); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4159 | glClearStencil(clear_stencil_); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4160 | glClearDepth(clear_depth_); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4161 | if (enable_scissor_test_) { |
| 4162 | glEnable(GL_SCISSOR_TEST); |
| 4163 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4167 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4168 | GetFramebufferInfoForTarget(target); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4169 | if (!framebuffer) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4170 | return GL_FRAMEBUFFER_COMPLETE; |
| 4171 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4172 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 4173 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 4174 | return completeness; |
| 4175 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4176 | return glCheckFramebufferStatusEXT(target); |
| 4177 | } |
| 4178 | |
| 4179 | void GLES2DecoderImpl::DoFramebufferTexture2D( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4180 | GLenum target, GLenum attachment, GLenum textarget, |
| 4181 | GLuint client_texture_id, GLint level) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4182 | FramebufferManager::FramebufferInfo* framebuffer_info = |
| 4183 | GetFramebufferInfoForTarget(target); |
| 4184 | if (!framebuffer_info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4185 | SetGLError(GL_INVALID_OPERATION, |
| 4186 | "glFramebufferTexture2D: no framebuffer bound."); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4187 | return; |
| 4188 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4189 | GLuint service_id = 0; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4190 | TextureManager::TextureInfo* info = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4191 | if (client_texture_id) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4192 | info = GetTextureInfo(client_texture_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4193 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4194 | SetGLError(GL_INVALID_OPERATION, |
| 4195 | "glFramebufferTexture2D: unknown texture"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4196 | return; |
| 4197 | } |
| 4198 | service_id = info->service_id(); |
| 4199 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4200 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4201 | if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4202 | SetGLError(GL_INVALID_VALUE, |
| 4203 | "glFramebufferTexture2D: level out of range"); |
| 4204 | return; |
| 4205 | } |
| 4206 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4207 | CopyRealGLErrorsToWrapper(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4208 | glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4209 | GLenum error = PeekGLError(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4210 | if (error == GL_NO_ERROR) { |
| 4211 | framebuffer_info->AttachTexture(attachment, info, textarget, level); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4212 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4213 | if (framebuffer_info == bound_draw_framebuffer_) { |
| 4214 | state_dirty_ = true; |
| 4215 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
| 4219 | GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4220 | FramebufferManager::FramebufferInfo* framebuffer_info = |
| 4221 | GetFramebufferInfoForTarget(target); |
| 4222 | if (!framebuffer_info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4223 | SetGLError(GL_INVALID_OPERATION, |
| 4224 | "glFramebufferAttachmentParameteriv: no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4225 | return; |
| 4226 | } |
| 4227 | glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 4228 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { |
| 4229 | GLint type = 0; |
| 4230 | GLuint client_id = 0; |
| 4231 | glGetFramebufferAttachmentParameterivEXT( |
| 4232 | target, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); |
| 4233 | switch (type) { |
| 4234 | case GL_RENDERBUFFER: { |
| 4235 | renderbuffer_manager()->GetClientId(*params, &client_id); |
| 4236 | break; |
| 4237 | } |
| 4238 | case GL_TEXTURE: { |
| 4239 | texture_manager()->GetClientId(*params, &client_id); |
| 4240 | break; |
| 4241 | } |
| 4242 | default: |
| 4243 | break; |
| 4244 | } |
| 4245 | *params = client_id; |
| 4246 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | void GLES2DecoderImpl::DoGetRenderbufferParameteriv( |
| 4250 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4251 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 4252 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4253 | if (!renderbuffer) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4254 | SetGLError(GL_INVALID_OPERATION, |
| 4255 | "glGetRenderbufferParameteriv: no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4256 | return; |
| 4257 | } |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4258 | switch (pname) { |
| 4259 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4260 | *params = renderbuffer->internal_format(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4261 | break; |
| 4262 | case GL_RENDERBUFFER_WIDTH: |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4263 | *params = renderbuffer->width(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4264 | break; |
| 4265 | case GL_RENDERBUFFER_HEIGHT: |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4266 | *params = renderbuffer->height(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4267 | break; |
| 4268 | default: |
| 4269 | glGetRenderbufferParameterivEXT(target, pname, params); |
| 4270 | break; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 4271 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4272 | } |
| 4273 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4274 | void GLES2DecoderImpl::DoBlitFramebufferEXT( |
| 4275 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 4276 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 4277 | GLbitfield mask, GLenum filter) { |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 4278 | if (!feature_info_->feature_flags().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4279 | SetGLError(GL_INVALID_OPERATION, |
| 4280 | "glBlitFramebufferEXT: function not available"); |
| 4281 | } |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 4282 | if (IsAngle()) { |
| 4283 | glBlitFramebufferANGLE( |
| 4284 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 4285 | } else { |
| 4286 | glBlitFramebufferEXT( |
| 4287 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 4288 | } |
[email protected] | 529c667 | 2012-01-04 02:18:26 | [diff] [blame] | 4289 | UNSHIPPED_TRACE_EVENT_INSTANT1("test_gpu", "DoBlit", "width", srcX1 - srcX0); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | void GLES2DecoderImpl::DoRenderbufferStorageMultisample( |
| 4293 | GLenum target, GLsizei samples, GLenum internalformat, |
| 4294 | GLsizei width, GLsizei height) { |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 4295 | if (!feature_info_->feature_flags().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4296 | SetGLError(GL_INVALID_OPERATION, |
| 4297 | "glRenderbufferStorageMultisampleEXT: function not available"); |
| 4298 | return; |
| 4299 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4300 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4301 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 4302 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4303 | if (!renderbuffer) { |
| 4304 | SetGLError(GL_INVALID_OPERATION, |
| 4305 | "glGetRenderbufferStorageMultisample: no renderbuffer bound"); |
| 4306 | return; |
| 4307 | } |
| 4308 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4309 | if (samples > renderbuffer_manager()->max_samples()) { |
| 4310 | SetGLError(GL_INVALID_VALUE, |
| 4311 | "glGetRenderbufferStorageMultisample: samples too large"); |
| 4312 | return; |
| 4313 | } |
| 4314 | |
| 4315 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 4316 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
| 4317 | SetGLError(GL_INVALID_VALUE, |
| 4318 | "glGetRenderbufferStorageMultisample: size too large"); |
| 4319 | return; |
| 4320 | } |
| 4321 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4322 | GLenum impl_format = internalformat; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4323 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4324 | switch (impl_format) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4325 | case GL_DEPTH_COMPONENT16: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4326 | impl_format = GL_DEPTH_COMPONENT; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4327 | break; |
| 4328 | case GL_RGBA4: |
| 4329 | case GL_RGB5_A1: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4330 | impl_format = GL_RGBA; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4331 | break; |
| 4332 | case GL_RGB565: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4333 | impl_format = GL_RGB; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4334 | break; |
| 4335 | } |
| 4336 | } |
| 4337 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4338 | CopyRealGLErrorsToWrapper(); |
[email protected] | 866b91c5 | 2011-03-23 14:38:08 | [diff] [blame] | 4339 | if (IsAngle()) { |
| 4340 | glRenderbufferStorageMultisampleANGLE( |
| 4341 | target, samples, impl_format, width, height); |
| 4342 | } else { |
| 4343 | glRenderbufferStorageMultisampleEXT( |
| 4344 | target, samples, impl_format, width, height); |
| 4345 | } |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4346 | GLenum error = PeekGLError(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4347 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 4348 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 4349 | // attached to we could just mark those framebuffers as not complete. |
| 4350 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4351 | renderbuffer_manager()->SetInfo( |
| 4352 | renderbuffer, samples, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4353 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4354 | } |
| 4355 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4356 | void GLES2DecoderImpl::DoRenderbufferStorage( |
| 4357 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4358 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 4359 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4360 | if (!renderbuffer) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4361 | SetGLError(GL_INVALID_OPERATION, |
| 4362 | "glGetRenderbufferStorage: no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4363 | return; |
| 4364 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4365 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4366 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 4367 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
| 4368 | SetGLError(GL_INVALID_VALUE, |
| 4369 | "glGetRenderbufferStorage: size too large"); |
| 4370 | return; |
| 4371 | } |
| 4372 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4373 | GLenum impl_format = internalformat; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4374 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4375 | switch (impl_format) { |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4376 | case GL_DEPTH_COMPONENT16: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4377 | impl_format = GL_DEPTH_COMPONENT; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4378 | break; |
| 4379 | case GL_RGBA4: |
| 4380 | case GL_RGB5_A1: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4381 | impl_format = GL_RGBA; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4382 | break; |
| 4383 | case GL_RGB565: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4384 | impl_format = GL_RGB; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4385 | break; |
| 4386 | } |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 4387 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4388 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4389 | CopyRealGLErrorsToWrapper(); |
| 4390 | glRenderbufferStorageEXT(target, impl_format, width, height); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4391 | GLenum error = PeekGLError(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4392 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 4393 | // TODO(gman): If tetxures tracked which framebuffers they were attached to |
| 4394 | // we could just mark those framebuffers as not complete. |
| 4395 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4396 | renderbuffer_manager()->SetInfo( |
| 4397 | renderbuffer, 0, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4398 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4399 | } |
| 4400 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4401 | void GLES2DecoderImpl::DoLinkProgram(GLuint program) { |
[email protected] | 0c8fabf | 2011-06-14 19:35:22 | [diff] [blame] | 4402 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4403 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 4404 | program, "glLinkProgram"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4405 | if (!info) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4406 | return; |
| 4407 | } |
[email protected] | 05afda1 | 2011-01-20 00:17:34 | [diff] [blame] | 4408 | |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 4409 | info->Link(); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4410 | }; |
| 4411 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4412 | void GLES2DecoderImpl::DoTexParameterf( |
| 4413 | GLenum target, GLenum pname, GLfloat param) { |
| 4414 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4415 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4416 | SetGLError(GL_INVALID_VALUE, "glTexParameterf: unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4417 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4418 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4419 | |
| 4420 | if (!texture_manager()->SetParameter( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4421 | info, pname, static_cast<GLint>(param))) { |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4422 | SetGLError(GL_INVALID_ENUM, "glTexParameterf: param GL_INVALID_ENUM"); |
| 4423 | return; |
| 4424 | } |
| 4425 | glTexParameterf(target, pname, param); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4426 | } |
| 4427 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4428 | void GLES2DecoderImpl::DoTexParameteri( |
| 4429 | GLenum target, GLenum pname, GLint param) { |
| 4430 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 4431 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4432 | SetGLError(GL_INVALID_VALUE, "glTexParameteri: unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4433 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4434 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4435 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4436 | if (!texture_manager()->SetParameter(info, pname, param)) { |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4437 | SetGLError(GL_INVALID_ENUM, "glTexParameteri: param GL_INVALID_ENUM"); |
| 4438 | return; |
| 4439 | } |
| 4440 | glTexParameteri(target, pname, param); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | void GLES2DecoderImpl::DoTexParameterfv( |
| 4444 | GLenum target, GLenum pname, const GLfloat* params) { |
| 4445 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 4446 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4447 | SetGLError(GL_INVALID_VALUE, "glTexParameterfv: unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4448 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4449 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4450 | |
| 4451 | if (!texture_manager()->SetParameter( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4452 | info, pname, static_cast<GLint>(params[0]))) { |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4453 | SetGLError(GL_INVALID_ENUM, "glTexParameterfv: param GL_INVALID_ENUM"); |
| 4454 | return; |
| 4455 | } |
| 4456 | glTexParameterfv(target, pname, params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4457 | } |
| 4458 | |
| 4459 | void GLES2DecoderImpl::DoTexParameteriv( |
| 4460 | GLenum target, GLenum pname, const GLint* params) { |
| 4461 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 4462 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4463 | SetGLError(GL_INVALID_VALUE, "glTexParameteriv: unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4464 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4465 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4466 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4467 | if (!texture_manager()->SetParameter(info, pname, *params)) { |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4468 | SetGLError(GL_INVALID_ENUM, "glTexParameteriv: param GL_INVALID_ENUM"); |
| 4469 | return; |
| 4470 | } |
| 4471 | glTexParameteriv(target, pname, params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4472 | } |
| 4473 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4474 | bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4475 | if (!current_program_) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4476 | // The program does not exist. |
| 4477 | SetGLError(GL_INVALID_OPERATION, |
| 4478 | (std::string(function_name) + ": no program in use").c_str()); |
| 4479 | return false; |
| 4480 | } |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4481 | if (!current_program_->InUse()) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4482 | SetGLError(GL_INVALID_OPERATION, |
| 4483 | (std::string(function_name) + ": program not linked").c_str()); |
| 4484 | return false; |
| 4485 | } |
| 4486 | return true; |
| 4487 | } |
| 4488 | |
| 4489 | bool GLES2DecoderImpl::CheckCurrentProgramForUniform( |
| 4490 | GLint location, const char* function_name) { |
| 4491 | if (!CheckCurrentProgram(function_name)) { |
| 4492 | return false; |
| 4493 | } |
| 4494 | return location != -1; |
| 4495 | } |
| 4496 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4497 | bool GLES2DecoderImpl::PrepForSetUniformByLocation( |
| 4498 | GLint location, const char* function_name, GLenum* type, GLsizei* count) { |
| 4499 | DCHECK(type); |
| 4500 | DCHECK(count); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4501 | if (!CheckCurrentProgramForUniform(location, function_name)) { |
| 4502 | return false; |
| 4503 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4504 | GLint array_index = -1; |
| 4505 | const ProgramManager::ProgramInfo::UniformInfo* info = |
| 4506 | current_program_->GetUniformInfoByLocation(location, &array_index); |
| 4507 | if (!info) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4508 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4509 | (std::string(function_name) + ": unknown location").c_str()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4510 | return false; |
| 4511 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4512 | if (*count > 1 && !info->is_array) { |
| 4513 | SetGLError( |
| 4514 | GL_INVALID_OPERATION, |
| 4515 | (std::string(function_name) + ": count > 1 for non-array").c_str()); |
| 4516 | return false; |
| 4517 | } |
| 4518 | *count = std::min(info->size - array_index, *count); |
| 4519 | if (*count <= 0) { |
| 4520 | return false; |
| 4521 | } |
| 4522 | *type = info->type; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4523 | return true; |
| 4524 | } |
| 4525 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4526 | void GLES2DecoderImpl::DoUniform1i(GLint location, GLint v0) { |
| 4527 | if (!CheckCurrentProgramForUniform(location, "glUniform1i")) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4528 | return; |
| 4529 | } |
| 4530 | current_program_->SetSamplers(location, 1, &v0); |
| 4531 | glUniform1i(location, v0); |
| 4532 | } |
| 4533 | |
| 4534 | void GLES2DecoderImpl::DoUniform1iv( |
| 4535 | GLint location, GLsizei count, const GLint *value) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4536 | if (!CheckCurrentProgramForUniform(location, "glUniform1iv")) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4537 | return; |
| 4538 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4539 | GLenum type = 0; |
| 4540 | if (!PrepForSetUniformByLocation(location, "glUniform1iv", &type, &count)) { |
| 4541 | return; |
| 4542 | } |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4543 | if (type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
| 4544 | type == GL_SAMPLER_EXTERNAL_OES) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4545 | current_program_->SetSamplers(location, count, value); |
| 4546 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4547 | glUniform1iv(location, count, value); |
| 4548 | } |
| 4549 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4550 | void GLES2DecoderImpl::DoUniform1fv( |
| 4551 | GLint location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4552 | GLenum type = 0; |
| 4553 | if (!PrepForSetUniformByLocation(location, "glUniform1fv", &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4554 | return; |
| 4555 | } |
| 4556 | if (type == GL_BOOL) { |
| 4557 | scoped_array<GLint> temp(new GLint[count]); |
| 4558 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 4559 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4560 | } |
| 4561 | DoUniform1iv(location, count, temp.get()); |
| 4562 | } else { |
| 4563 | glUniform1fv(location, count, value); |
| 4564 | } |
| 4565 | } |
| 4566 | |
| 4567 | void GLES2DecoderImpl::DoUniform2fv( |
| 4568 | GLint location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4569 | GLenum type = 0; |
| 4570 | if (!PrepForSetUniformByLocation(location, "glUniform2fv", &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4571 | return; |
| 4572 | } |
| 4573 | if (type == GL_BOOL_VEC2) { |
| 4574 | GLsizei num_values = count * 2; |
| 4575 | scoped_array<GLint> temp(new GLint[num_values]); |
| 4576 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 4577 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4578 | } |
| 4579 | glUniform2iv(location, count, temp.get()); |
| 4580 | } else { |
| 4581 | glUniform2fv(location, count, value); |
| 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | void GLES2DecoderImpl::DoUniform3fv( |
| 4586 | GLint location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4587 | GLenum type = 0; |
| 4588 | if (!PrepForSetUniformByLocation(location, "glUniform3fv", &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4589 | return; |
| 4590 | } |
| 4591 | if (type == GL_BOOL_VEC3) { |
| 4592 | GLsizei num_values = count * 3; |
| 4593 | scoped_array<GLint> temp(new GLint[num_values]); |
| 4594 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 4595 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4596 | } |
| 4597 | glUniform3iv(location, count, temp.get()); |
| 4598 | } else { |
| 4599 | glUniform3fv(location, count, value); |
| 4600 | } |
| 4601 | } |
| 4602 | |
| 4603 | void GLES2DecoderImpl::DoUniform4fv( |
| 4604 | GLint location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4605 | GLenum type = 0; |
| 4606 | if (!PrepForSetUniformByLocation(location, "glUniform4fv", &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4607 | return; |
| 4608 | } |
| 4609 | if (type == GL_BOOL_VEC4) { |
| 4610 | GLsizei num_values = count * 4; |
| 4611 | scoped_array<GLint> temp(new GLint[num_values]); |
| 4612 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 4613 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4614 | } |
| 4615 | glUniform4iv(location, count, temp.get()); |
| 4616 | } else { |
| 4617 | glUniform4fv(location, count, value); |
| 4618 | } |
| 4619 | } |
| 4620 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4621 | void GLES2DecoderImpl::DoUniform2iv( |
| 4622 | GLint location, GLsizei count, const GLint* value) { |
| 4623 | GLenum type = 0; |
| 4624 | if (!PrepForSetUniformByLocation(location, "glUniform2iv", &type, &count)) { |
| 4625 | return; |
| 4626 | } |
| 4627 | glUniform2iv(location, count, value); |
| 4628 | } |
| 4629 | |
| 4630 | void GLES2DecoderImpl::DoUniform3iv( |
| 4631 | GLint location, GLsizei count, const GLint* value) { |
| 4632 | GLenum type = 0; |
| 4633 | if (!PrepForSetUniformByLocation(location, "glUniform3iv", &type, &count)) { |
| 4634 | return; |
| 4635 | } |
| 4636 | glUniform3iv(location, count, value); |
| 4637 | } |
| 4638 | |
| 4639 | void GLES2DecoderImpl::DoUniform4iv( |
| 4640 | GLint location, GLsizei count, const GLint* value) { |
| 4641 | GLenum type = 0; |
| 4642 | if (!PrepForSetUniformByLocation(location, "glUniform4iv", &type, &count)) { |
| 4643 | return; |
| 4644 | } |
| 4645 | glUniform4iv(location, count, value); |
| 4646 | } |
| 4647 | |
| 4648 | void GLES2DecoderImpl::DoUniformMatrix2fv( |
| 4649 | GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { |
| 4650 | GLenum type = 0; |
| 4651 | if (!PrepForSetUniformByLocation( |
| 4652 | location, "glUniformMatrix2fv", &type, &count)) { |
| 4653 | return; |
| 4654 | } |
[email protected] | e508126 | 2012-01-05 23:09:03 | [diff] [blame] | 4655 | glUniformMatrix2fv(location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | void GLES2DecoderImpl::DoUniformMatrix3fv( |
| 4659 | GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { |
| 4660 | GLenum type = 0; |
| 4661 | if (!PrepForSetUniformByLocation( |
| 4662 | location, "glUniformMatrix3fv", &type, &count)) { |
| 4663 | return; |
| 4664 | } |
[email protected] | e508126 | 2012-01-05 23:09:03 | [diff] [blame] | 4665 | glUniformMatrix3fv(location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | void GLES2DecoderImpl::DoUniformMatrix4fv( |
| 4669 | GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { |
| 4670 | GLenum type = 0; |
| 4671 | if (!PrepForSetUniformByLocation( |
| 4672 | location, "glUniformMatrix4fv", &type, &count)) { |
| 4673 | return; |
| 4674 | } |
[email protected] | e508126 | 2012-01-05 23:09:03 | [diff] [blame] | 4675 | glUniformMatrix4fv(location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4676 | } |
| 4677 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4678 | void GLES2DecoderImpl::DoUseProgram(GLuint program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4679 | GLuint service_id = 0; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4680 | ProgramManager::ProgramInfo* info = NULL; |
| 4681 | if (program) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4682 | info = GetProgramInfoNotShader(program, "glUseProgram"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4683 | if (!info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4684 | return; |
| 4685 | } |
| 4686 | if (!info->IsValid()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4687 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4688 | SetGLError(GL_INVALID_OPERATION, "glUseProgram: program not linked"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4689 | return; |
| 4690 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4691 | service_id = info->service_id(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4692 | } |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4693 | if (current_program_) { |
| 4694 | program_manager()->UnuseProgram(shader_manager(), current_program_); |
| 4695 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4696 | current_program_ = info; |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4697 | if (current_program_) { |
| 4698 | program_manager()->UseProgram(current_program_); |
| 4699 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4700 | glUseProgram(service_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4701 | } |
| 4702 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4703 | GLenum GLES2DecoderImpl::GetGLError() { |
| 4704 | // Check the GL error first, then our wrapped error. |
| 4705 | GLenum error = glGetError(); |
| 4706 | if (error == GL_NO_ERROR && error_bits_ != 0) { |
[email protected] | 03f882a | 2010-01-08 20:46:37 | [diff] [blame] | 4707 | for (uint32 mask = 1; mask != 0; mask = mask << 1) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4708 | if ((error_bits_ & mask) != 0) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 4709 | error = GLES2Util::GLErrorBitToGLError(mask); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4710 | break; |
| 4711 | } |
| 4712 | } |
| 4713 | } |
| 4714 | |
| 4715 | if (error != GL_NO_ERROR) { |
| 4716 | // There was an error, clear the corresponding wrapped error. |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 4717 | error_bits_ &= ~GLES2Util::GLErrorToErrorBit(error); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4718 | } |
| 4719 | return error; |
| 4720 | } |
| 4721 | |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4722 | GLenum GLES2DecoderImpl::PeekGLError() { |
| 4723 | GLenum error = glGetError(); |
| 4724 | if (error != GL_NO_ERROR) { |
| 4725 | SetGLError(error, ""); |
| 4726 | } |
| 4727 | return error; |
| 4728 | } |
| 4729 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4730 | void GLES2DecoderImpl::SetGLError(GLenum error, const char* msg) { |
| 4731 | if (msg) { |
| 4732 | last_error_ = msg; |
[email protected] | b5d647c | 2012-02-10 01:41:32 | [diff] [blame^] | 4733 | // LOG this unless logging is turned off as any chromium code that generates |
| 4734 | // these errors probably has a bug. |
| 4735 | if (log_synthesized_gl_errors()) { |
| 4736 | LOG(ERROR) << last_error_; |
| 4737 | } |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 4738 | if (!msg_callback_.is_null()) { |
| 4739 | msg_callback_.Run(0, GLES2Util::GetStringEnum(error) + " : " + msg); |
| 4740 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4741 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 4742 | error_bits_ |= GLES2Util::GLErrorToErrorBit(error); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4743 | } |
| 4744 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4745 | void GLES2DecoderImpl::CopyRealGLErrorsToWrapper() { |
| 4746 | GLenum error; |
| 4747 | while ((error = glGetError()) != GL_NO_ERROR) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4748 | SetGLError(error, NULL); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4749 | } |
| 4750 | } |
| 4751 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4752 | void GLES2DecoderImpl::ClearRealGLErrors() { |
| 4753 | GLenum error; |
| 4754 | while ((error = glGetError()) != GL_NO_ERROR) { |
[email protected] | 3ed14d11 | 2011-12-13 22:05:51 | [diff] [blame] | 4755 | if (error != GL_OUT_OF_MEMORY) { |
| 4756 | // GL_OUT_OF_MEMORY can legally happen on lost device. |
| 4757 | NOTREACHED() << "GL error " << error << " was unhandled."; |
| 4758 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4759 | } |
| 4760 | } |
| 4761 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 4762 | bool GLES2DecoderImpl::SetBlackTextureForNonRenderableTextures() { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4763 | DCHECK(current_program_); |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 4764 | // Only check if there are some unrenderable textures. |
| 4765 | if (!texture_manager()->HaveUnrenderableTextures()) { |
| 4766 | return false; |
| 4767 | } |
| 4768 | bool textures_set = false; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4769 | const ProgramManager::ProgramInfo::SamplerIndices& sampler_indices = |
| 4770 | current_program_->sampler_indices(); |
| 4771 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 4772 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
| 4773 | current_program_->GetUniformInfo(sampler_indices[ii]); |
| 4774 | DCHECK(uniform_info); |
| 4775 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 4776 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
| 4777 | if (texture_unit_index < group_->max_texture_units()) { |
| 4778 | TextureUnit& texture_unit = texture_units_[texture_unit_index]; |
| 4779 | TextureManager::TextureInfo* texture_info = |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4780 | texture_unit.GetInfoForSamplerType(uniform_info->type); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4781 | if (!texture_info || !texture_manager()->CanRender(texture_info)) { |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 4782 | textures_set = true; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4783 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 4784 | glBindTexture( |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4785 | GetBindTargetForSamplerType(uniform_info->type), |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 4786 | texture_manager()->black_texture_id(uniform_info->type)); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4787 | } |
| 4788 | } |
| 4789 | // else: should this be an error? |
| 4790 | } |
| 4791 | } |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 4792 | return textures_set; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | void GLES2DecoderImpl::RestoreStateForNonRenderableTextures() { |
| 4796 | DCHECK(current_program_); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4797 | const ProgramManager::ProgramInfo::SamplerIndices& sampler_indices = |
| 4798 | current_program_->sampler_indices(); |
| 4799 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 4800 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
| 4801 | current_program_->GetUniformInfo(sampler_indices[ii]); |
| 4802 | DCHECK(uniform_info); |
| 4803 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 4804 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
| 4805 | if (texture_unit_index < group_->max_texture_units()) { |
| 4806 | TextureUnit& texture_unit = texture_units_[texture_unit_index]; |
| 4807 | TextureManager::TextureInfo* texture_info = |
| 4808 | uniform_info->type == GL_SAMPLER_2D ? |
| 4809 | texture_unit.bound_texture_2d : |
| 4810 | texture_unit.bound_texture_cube_map; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4811 | if (!texture_info || !texture_manager()->CanRender(texture_info)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4812 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 4813 | // Get the texture info that was previously bound here. |
| 4814 | texture_info = texture_unit.bind_target == GL_TEXTURE_2D ? |
| 4815 | texture_unit.bound_texture_2d : |
| 4816 | texture_unit.bound_texture_cube_map; |
| 4817 | glBindTexture(texture_unit.bind_target, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4818 | texture_info ? texture_info->service_id() : 0); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4819 | } |
| 4820 | } |
| 4821 | } |
| 4822 | } |
| 4823 | // Set the active texture back to whatever the user had it as. |
| 4824 | glActiveTexture(GL_TEXTURE0 + active_texture_unit_); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4825 | } |
| 4826 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4827 | bool GLES2DecoderImpl::ClearUnclearedTextures() { |
| 4828 | // Only check if there are some uncleared textures. |
| 4829 | if (!texture_manager()->HaveUnsafeTextures()) { |
| 4830 | return true; |
| 4831 | } |
| 4832 | |
| 4833 | // 1: Check all textures we are about to render with. |
| 4834 | if (current_program_) { |
| 4835 | const ProgramManager::ProgramInfo::SamplerIndices& sampler_indices = |
| 4836 | current_program_->sampler_indices(); |
| 4837 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 4838 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
| 4839 | current_program_->GetUniformInfo(sampler_indices[ii]); |
| 4840 | DCHECK(uniform_info); |
| 4841 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 4842 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
| 4843 | if (texture_unit_index < group_->max_texture_units()) { |
| 4844 | TextureUnit& texture_unit = texture_units_[texture_unit_index]; |
| 4845 | TextureManager::TextureInfo* texture_info = |
| 4846 | texture_unit.GetInfoForSamplerType(uniform_info->type); |
| 4847 | if (texture_info && !texture_info->SafeToRenderFrom()) { |
| 4848 | if (!texture_manager()->ClearRenderableLevels(this, texture_info)) { |
| 4849 | return false; |
| 4850 | } |
| 4851 | } |
| 4852 | } |
| 4853 | } |
| 4854 | } |
| 4855 | } |
| 4856 | return true; |
| 4857 | } |
| 4858 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4859 | bool GLES2DecoderImpl::IsDrawValid(GLuint max_vertex_accessed) { |
[email protected] | 689fa1c5 | 2010-06-09 18:35:03 | [diff] [blame] | 4860 | // NOTE: We specifically do not check current_program->IsValid() because |
| 4861 | // it could never be invalid since glUseProgram would have failed. While |
| 4862 | // glLinkProgram could later mark the program as invalid the previous |
| 4863 | // valid program will still function if it is still the current program. |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4864 | if (!current_program_) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4865 | // The program does not exist. |
| 4866 | // But GL says no ERROR. |
| 4867 | return false; |
| 4868 | } |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 4869 | // Validate all attribs currently enabled. If they are used by the current |
| 4870 | // program then check that they have enough elements to handle the draw call. |
| 4871 | // If they are not used by the current program check that they have a buffer |
| 4872 | // assigned. |
| 4873 | const VertexAttribManager::VertexAttribInfoList& infos = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 4874 | vertex_attrib_manager_->GetEnabledVertexAttribInfos(); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 4875 | for (VertexAttribManager::VertexAttribInfoList::const_iterator it = |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 4876 | infos.begin(); it != infos.end(); ++it) { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 4877 | const VertexAttribManager::VertexAttribInfo* info = *it; |
| 4878 | const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
| 4879 | current_program_->GetAttribInfoByLocation(info->index()); |
| 4880 | if (attrib_info) { |
| 4881 | // This attrib is used in the current program. |
| 4882 | if (!info->CanAccess(max_vertex_accessed)) { |
| 4883 | SetGLError(GL_INVALID_OPERATION, |
| 4884 | "glDrawXXX: attempt to access out of range vertices"); |
| 4885 | return false; |
| 4886 | } |
| 4887 | } else { |
| 4888 | // This attrib is not used in the current program. |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 4889 | if (!info->buffer()) { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 4890 | SetGLError( |
| 4891 | GL_INVALID_OPERATION, |
| 4892 | "glDrawXXX: attempt to render with no buffer attached to enabled " |
| 4893 | "attrib"); |
| 4894 | return false; |
| 4895 | } |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 4896 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4897 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4898 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4899 | } |
| 4900 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 4901 | bool GLES2DecoderImpl::SimulateAttrib0( |
| 4902 | GLuint max_vertex_accessed, bool* simulated) { |
| 4903 | DCHECK(simulated); |
| 4904 | *simulated = false; |
| 4905 | |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4906 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 4907 | return true; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4908 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4909 | const VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 4910 | vertex_attrib_manager_->GetVertexAttribInfo(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4911 | // If it's enabled or it's not used then we don't need to do anything. |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 4912 | bool attrib_0_used = current_program_->GetAttribInfoByLocation(0) != NULL; |
| 4913 | if (info->enabled() && attrib_0_used) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 4914 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4915 | } |
| 4916 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4917 | // Make a buffer with a single repeated vec4 value enough to |
| 4918 | // simulate the constant value that is supposed to be here. |
| 4919 | // This is required to emulate GLES2 on GL. |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 4920 | typedef VertexAttribManager::VertexAttribInfo::Vec4 Vec4; |
| 4921 | |
| 4922 | GLuint num_vertices = max_vertex_accessed + 1; |
| 4923 | GLuint size_needed = 0; |
| 4924 | |
| 4925 | if (num_vertices == 0 || |
| 4926 | !SafeMultiply(num_vertices, static_cast<GLuint>(sizeof(Vec4)), |
| 4927 | &size_needed) || |
| 4928 | size_needed > 0x7FFFFFFFU) { |
| 4929 | SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: Simulating attrib 0"); |
| 4930 | return false; |
| 4931 | } |
| 4932 | |
| 4933 | CopyRealGLErrorsToWrapper(); |
| 4934 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 4935 | |
| 4936 | if (static_cast<GLsizei>(size_needed) > attrib_0_size_) { |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 4937 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 4938 | GLenum error = glGetError(); |
| 4939 | if (error != GL_NO_ERROR) { |
| 4940 | SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: Simulating attrib 0"); |
| 4941 | return false; |
| 4942 | } |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 4943 | attrib_0_buffer_matches_value_ = false; |
| 4944 | } |
| 4945 | if (attrib_0_used && |
| 4946 | (!attrib_0_buffer_matches_value_ || |
| 4947 | (info->value().v[0] != attrib_0_value_.v[0] || |
| 4948 | info->value().v[1] != attrib_0_value_.v[1] || |
| 4949 | info->value().v[2] != attrib_0_value_.v[2] || |
| 4950 | info->value().v[3] != attrib_0_value_.v[3]))) { |
| 4951 | std::vector<Vec4> temp(num_vertices, info->value()); |
| 4952 | glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
| 4953 | attrib_0_buffer_matches_value_ = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4954 | attrib_0_value_ = info->value(); |
| 4955 | attrib_0_size_ = size_needed; |
| 4956 | } |
| 4957 | |
| 4958 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 4959 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 4960 | *simulated = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4961 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4962 | } |
| 4963 | |
| 4964 | void GLES2DecoderImpl::RestoreStateForSimulatedAttrib0() { |
| 4965 | const VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 4966 | vertex_attrib_manager_->GetVertexAttribInfo(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4967 | const void* ptr = reinterpret_cast<const void*>(info->offset()); |
| 4968 | BufferManager::BufferInfo* buffer_info = info->buffer(); |
| 4969 | glBindBuffer(GL_ARRAY_BUFFER, buffer_info ? buffer_info->service_id() : 0); |
| 4970 | glVertexAttribPointer( |
| 4971 | 0, info->size(), info->type(), info->normalized(), info->gl_stride(), |
| 4972 | ptr); |
| 4973 | glBindBuffer(GL_ARRAY_BUFFER, |
| 4974 | bound_array_buffer_ ? bound_array_buffer_->service_id() : 0); |
| 4975 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4976 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 4977 | bool GLES2DecoderImpl::SimulateFixedAttribs( |
| 4978 | GLuint max_vertex_accessed, bool* simulated) { |
| 4979 | DCHECK(simulated); |
| 4980 | *simulated = false; |
| 4981 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 4982 | return true; |
| 4983 | |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 4984 | if (!vertex_attrib_manager_->HaveFixedAttribs()) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 4985 | return true; |
| 4986 | } |
| 4987 | |
| 4988 | // NOTE: we could be smart and try to check if a buffer is used |
| 4989 | // twice in 2 different attribs, find the overlapping parts and therefore |
| 4990 | // duplicate the minimum amount of data but this whole code path is not meant |
| 4991 | // to be used normally. It's just here to pass that OpenGL ES 2.0 conformance |
| 4992 | // tests so we just add to the buffer attrib used. |
| 4993 | |
| 4994 | // Compute the number of elements needed. |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 4995 | GLuint num_vertices = max_vertex_accessed + 1; |
| 4996 | if (num_vertices == 0) { |
| 4997 | SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: Simulating attrib 0"); |
| 4998 | return false; |
| 4999 | } |
| 5000 | |
| 5001 | GLuint elements_needed = 0; |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5002 | const VertexAttribManager::VertexAttribInfoList& infos = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5003 | vertex_attrib_manager_->GetEnabledVertexAttribInfos(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5004 | for (VertexAttribManager::VertexAttribInfoList::const_iterator it = |
| 5005 | infos.begin(); it != infos.end(); ++it) { |
| 5006 | const VertexAttribManager::VertexAttribInfo* info = *it; |
| 5007 | const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
| 5008 | current_program_->GetAttribInfoByLocation(info->index()); |
| 5009 | if (attrib_info && |
| 5010 | info->CanAccess(max_vertex_accessed) && |
| 5011 | info->type() == GL_FIXED) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5012 | GLuint elements_used = 0; |
| 5013 | if (!SafeMultiply(num_vertices, |
| 5014 | static_cast<GLuint>(info->size()), &elements_used) || |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5015 | !SafeAdd(elements_needed, elements_used, &elements_needed)) { |
| 5016 | SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: simulating GL_FIXED attribs"); |
| 5017 | return false; |
| 5018 | } |
| 5019 | } |
| 5020 | } |
| 5021 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5022 | const GLuint kSizeOfFloat = sizeof(float); // NOLINT |
| 5023 | GLuint size_needed = 0; |
| 5024 | if (!SafeMultiply(elements_needed, kSizeOfFloat, &size_needed) || |
| 5025 | size_needed > 0x7FFFFFFFU) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5026 | SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: simulating GL_FIXED attribs"); |
| 5027 | return false; |
| 5028 | } |
| 5029 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5030 | CopyRealGLErrorsToWrapper(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5031 | |
| 5032 | glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5033 | if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5034 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5035 | GLenum error = glGetError(); |
| 5036 | if (error != GL_NO_ERROR) { |
| 5037 | SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: simulating GL_FIXED attribs"); |
| 5038 | return false; |
| 5039 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | // Copy the elements and convert to float |
| 5043 | GLintptr offset = 0; |
| 5044 | for (VertexAttribManager::VertexAttribInfoList::const_iterator it = |
| 5045 | infos.begin(); it != infos.end(); ++it) { |
| 5046 | const VertexAttribManager::VertexAttribInfo* info = *it; |
| 5047 | const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
| 5048 | current_program_->GetAttribInfoByLocation(info->index()); |
| 5049 | if (attrib_info && |
| 5050 | info->CanAccess(max_vertex_accessed) && |
| 5051 | info->type() == GL_FIXED) { |
| 5052 | int num_elements = info->size() * kSizeOfFloat; |
| 5053 | int size = num_elements * num_vertices; |
| 5054 | scoped_array<float> data(new float[size]); |
| 5055 | const int32* src = reinterpret_cast<const int32 *>( |
| 5056 | info->buffer()->GetRange(info->offset(), size)); |
| 5057 | const int32* end = src + num_elements; |
| 5058 | float* dst = data.get(); |
| 5059 | while (src != end) { |
| 5060 | *dst++ = static_cast<float>(*src++) / 65536.0f; |
| 5061 | } |
| 5062 | glBufferSubData(GL_ARRAY_BUFFER, offset, size, data.get()); |
| 5063 | glVertexAttribPointer( |
| 5064 | info->index(), info->size(), GL_FLOAT, false, 0, |
| 5065 | reinterpret_cast<GLvoid*>(offset)); |
| 5066 | offset += size; |
| 5067 | } |
| 5068 | } |
| 5069 | *simulated = true; |
| 5070 | return true; |
| 5071 | } |
| 5072 | |
| 5073 | void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() { |
| 5074 | // There's no need to call glVertexAttribPointer because we shadow all the |
| 5075 | // settings and passing GL_FIXED to it will not work. |
| 5076 | glBindBuffer(GL_ARRAY_BUFFER, |
| 5077 | bound_array_buffer_ ? bound_array_buffer_->service_id() : 0); |
| 5078 | } |
| 5079 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5080 | error::Error GLES2DecoderImpl::HandleDrawArrays( |
| 5081 | uint32 immediate_data_size, const gles2::DrawArrays& c) { |
| 5082 | GLenum mode = static_cast<GLenum>(c.mode); |
| 5083 | GLint first = static_cast<GLint>(c.first); |
| 5084 | GLsizei count = static_cast<GLsizei>(c.count); |
| 5085 | if (!validators_->draw_mode.IsValid(mode)) { |
| 5086 | SetGLError(GL_INVALID_ENUM, "glDrawArrays: mode GL_INVALID_ENUM"); |
| 5087 | return error::kNoError; |
| 5088 | } |
| 5089 | if (count < 0) { |
| 5090 | SetGLError(GL_INVALID_VALUE, "glDrawArrays: count < 0"); |
| 5091 | return error::kNoError; |
| 5092 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5093 | if (!CheckBoundFramebuffersValid("glDrawArrays")) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5094 | return error::kNoError; |
| 5095 | } |
| 5096 | // We have to check this here because the prototype for glDrawArrays |
| 5097 | // is GLint not GLsizei. |
| 5098 | if (first < 0) { |
| 5099 | SetGLError(GL_INVALID_VALUE, "glDrawArrays: first < 0"); |
| 5100 | return error::kNoError; |
| 5101 | } |
| 5102 | |
| 5103 | if (count == 0) { |
| 5104 | return error::kNoError; |
| 5105 | } |
| 5106 | |
| 5107 | GLuint max_vertex_accessed = first + count - 1; |
| 5108 | if (IsDrawValid(max_vertex_accessed)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5109 | if (!ClearUnclearedTextures()) { |
| 5110 | SetGLError(GL_INVALID_VALUE, "glDrawArrays: out of memory"); |
| 5111 | return error::kNoError; |
| 5112 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5113 | bool simulated_attrib_0 = false; |
| 5114 | if (!SimulateAttrib0(max_vertex_accessed, &simulated_attrib_0)) { |
| 5115 | return error::kNoError; |
| 5116 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5117 | bool simulated_fixed_attribs = false; |
| 5118 | if (SimulateFixedAttribs(max_vertex_accessed, &simulated_fixed_attribs)) { |
| 5119 | bool textures_set = SetBlackTextureForNonRenderableTextures(); |
| 5120 | ApplyDirtyState(); |
| 5121 | glDrawArrays(mode, first, count); |
| 5122 | if (textures_set) { |
| 5123 | RestoreStateForNonRenderableTextures(); |
| 5124 | } |
| 5125 | if (simulated_fixed_attribs) { |
| 5126 | RestoreStateForSimulatedFixedAttribs(); |
| 5127 | } |
| 5128 | } |
| 5129 | if (simulated_attrib_0) { |
| 5130 | RestoreStateForSimulatedAttrib0(); |
| 5131 | } |
| 5132 | if (WasContextLost()) { |
| 5133 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during DrawArrays."; |
| 5134 | return error::kLostContext; |
| 5135 | } |
| 5136 | } |
| 5137 | return error::kNoError; |
| 5138 | } |
| 5139 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5140 | error::Error GLES2DecoderImpl::HandleDrawElements( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5141 | uint32 immediate_data_size, const gles2::DrawElements& c) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5142 | if (!bound_element_array_buffer_) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5143 | SetGLError(GL_INVALID_OPERATION, |
| 5144 | "glDrawElements: No element array buffer bound"); |
| 5145 | return error::kNoError; |
| 5146 | } |
| 5147 | |
| 5148 | GLenum mode = c.mode; |
| 5149 | GLsizei count = c.count; |
| 5150 | GLenum type = c.type; |
| 5151 | int32 offset = c.index_offset; |
| 5152 | if (count < 0) { |
| 5153 | SetGLError(GL_INVALID_VALUE, "glDrawElements: count < 0"); |
| 5154 | return error::kNoError; |
| 5155 | } |
| 5156 | if (offset < 0) { |
| 5157 | SetGLError(GL_INVALID_VALUE, "glDrawElements: offset < 0"); |
| 5158 | return error::kNoError; |
| 5159 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5160 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5161 | SetGLError(GL_INVALID_ENUM, "glDrawElements: mode GL_INVALID_ENUM"); |
| 5162 | return error::kNoError; |
| 5163 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5164 | if (!validators_->index_type.IsValid(type)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5165 | SetGLError(GL_INVALID_ENUM, "glDrawElements: type GL_INVALID_ENUM"); |
| 5166 | return error::kNoError; |
| 5167 | } |
| 5168 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5169 | if (!CheckBoundFramebuffersValid("glDrawElements")) { |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5170 | return error::kNoError; |
| 5171 | } |
| 5172 | |
[email protected] | 6c788fb7 | 2010-08-26 02:16:31 | [diff] [blame] | 5173 | if (count == 0) { |
| 5174 | return error::kNoError; |
| 5175 | } |
| 5176 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5177 | GLuint max_vertex_accessed; |
| 5178 | if (!bound_element_array_buffer_->GetMaxValueForRange( |
| 5179 | offset, count, type, &max_vertex_accessed)) { |
| 5180 | SetGLError(GL_INVALID_OPERATION, |
| 5181 | "glDrawElements: range out of bounds for buffer"); |
| 5182 | return error::kNoError; |
| 5183 | } |
| 5184 | |
| 5185 | if (IsDrawValid(max_vertex_accessed)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5186 | if (!ClearUnclearedTextures()) { |
| 5187 | SetGLError(GL_INVALID_VALUE, "glDrawElements: out of memory"); |
| 5188 | return error::kNoError; |
| 5189 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5190 | bool simulated_attrib_0 = false; |
| 5191 | if (!SimulateAttrib0(max_vertex_accessed, &simulated_attrib_0)) { |
| 5192 | return error::kNoError; |
| 5193 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5194 | bool simulated_fixed_attribs = false; |
| 5195 | if (SimulateFixedAttribs(max_vertex_accessed, &simulated_fixed_attribs)) { |
| 5196 | bool textures_set = SetBlackTextureForNonRenderableTextures(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5197 | ApplyDirtyState(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5198 | const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
| 5199 | glDrawElements(mode, count, type, indices); |
| 5200 | if (textures_set) { |
| 5201 | RestoreStateForNonRenderableTextures(); |
| 5202 | } |
| 5203 | if (simulated_fixed_attribs) { |
| 5204 | RestoreStateForSimulatedFixedAttribs(); |
| 5205 | } |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 5206 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5207 | if (simulated_attrib_0) { |
| 5208 | RestoreStateForSimulatedAttrib0(); |
| 5209 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5210 | if (WasContextLost()) { |
| 5211 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during DrawElements."; |
| 5212 | return error::kLostContext; |
| 5213 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5214 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5215 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5216 | } |
| 5217 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 5218 | GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 5219 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { |
| 5220 | GLuint max_vertex_accessed = 0; |
| 5221 | BufferManager::BufferInfo* info = GetBufferInfo(buffer_id); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5222 | if (!info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5223 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5224 | SetGLError(GL_INVALID_VALUE, |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 5225 | "GetMaxValueInBufferCHROMIUM: unknown buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 5226 | } else { |
| 5227 | if (!info->GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5228 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 5229 | SetGLError( |
| 5230 | GL_INVALID_OPERATION, |
| 5231 | "GetMaxValueInBufferCHROMIUM: range out of bounds for buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 5232 | } |
| 5233 | } |
| 5234 | return max_vertex_accessed; |
| 5235 | } |
| 5236 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5237 | // Calls glShaderSource for the various versions of the ShaderSource command. |
| 5238 | // Assumes that data / data_size points to a piece of memory that is in range |
| 5239 | // of whatever context it came from (shared memory, immediate memory, bucket |
| 5240 | // memory.) |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5241 | error::Error GLES2DecoderImpl::ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5242 | GLuint client_id, const char* data, uint32 data_size) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5243 | std::string str(data, data + data_size); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5244 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5245 | client_id, "glShaderSource"); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5246 | if (!info) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5247 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5248 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5249 | // Note: We don't actually call glShaderSource here. We wait until |
| 5250 | // the call to glCompileShader. |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5251 | info->UpdateSource(str.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5252 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5253 | } |
| 5254 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5255 | error::Error GLES2DecoderImpl::HandleShaderSource( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5256 | uint32 immediate_data_size, const gles2::ShaderSource& c) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5257 | uint32 data_size = c.data_size; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5258 | const char* data = GetSharedMemoryAs<const char*>( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5259 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 5260 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5261 | return error::kOutOfBounds; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5262 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5263 | return ShaderSourceHelper(c.shader, data, data_size); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5264 | } |
| 5265 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5266 | error::Error GLES2DecoderImpl::HandleShaderSourceImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5267 | uint32 immediate_data_size, const gles2::ShaderSourceImmediate& c) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5268 | uint32 data_size = c.data_size; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5269 | const char* data = GetImmediateDataAs<const char*>( |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5270 | c, data_size, immediate_data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 5271 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5272 | return error::kOutOfBounds; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5273 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5274 | return ShaderSourceHelper(c.shader, data, data_size); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5275 | } |
| 5276 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5277 | error::Error GLES2DecoderImpl::HandleShaderSourceBucket( |
| 5278 | uint32 immediate_data_size, const gles2::ShaderSourceBucket& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5279 | Bucket* bucket = GetBucket(c.data_bucket_id); |
| 5280 | if (!bucket || bucket->size() == 0) { |
| 5281 | return error::kInvalidArguments; |
| 5282 | } |
| 5283 | return ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5284 | c.shader, bucket->GetDataAs<const char*>(0, bucket->size() - 1), |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5285 | bucket->size() - 1); |
| 5286 | } |
| 5287 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5288 | void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { |
[email protected] | 0c8fabf | 2011-06-14 19:35:22 | [diff] [blame] | 5289 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompileShader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5290 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5291 | client_id, "glCompileShader"); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5292 | if (!info) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5293 | return; |
| 5294 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 5295 | // Translate GL ES 2.0 shader to Desktop GL shader and pass that to |
| 5296 | // glShaderSource and then glCompileShader. |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5297 | const char* shader_src = info->source() ? info->source()->c_str() : ""; |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 5298 | ShaderTranslator* translator = NULL; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 5299 | if (use_shader_translator_) { |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 5300 | translator = info->shader_type() == GL_VERTEX_SHADER ? |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 5301 | vertex_translator_.get() : fragment_translator_.get(); |
[email protected] | 5236b75 | 2010-07-27 18:02:23 | [diff] [blame] | 5302 | |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 5303 | if (!translator->Translate(shader_src)) { |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 5304 | info->SetStatus(false, translator->info_log(), NULL); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 5305 | return; |
| 5306 | } |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 5307 | shader_src = translator->translated_shader(); |
[email protected] | 9329770 | 2011-11-05 05:09:46 | [diff] [blame] | 5308 | if (!feature_info_->feature_flags().angle_translated_shader_source) |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5309 | info->UpdateTranslatedSource(shader_src); |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 5310 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 5311 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5312 | glShaderSource(info->service_id(), 1, &shader_src, NULL); |
| 5313 | glCompileShader(info->service_id()); |
[email protected] | 9329770 | 2011-11-05 05:09:46 | [diff] [blame] | 5314 | if (feature_info_->feature_flags().angle_translated_shader_source) { |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5315 | GLint max_len = 0; |
| 5316 | glGetShaderiv(info->service_id(), |
| 5317 | GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, |
| 5318 | &max_len); |
| 5319 | scoped_array<char> temp(new char[max_len]); |
| 5320 | GLint len = 0; |
| 5321 | glGetTranslatedShaderSourceANGLE( |
| 5322 | info->service_id(), max_len, &len, temp.get()); |
| 5323 | DCHECK(max_len == 0 || len < max_len); |
| 5324 | DCHECK(len == 0 || temp[len] == '\0'); |
| 5325 | info->UpdateTranslatedSource(temp.get()); |
| 5326 | } |
| 5327 | |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 5328 | GLint status = GL_FALSE; |
| 5329 | glGetShaderiv(info->service_id(), GL_COMPILE_STATUS, &status); |
| 5330 | if (status) { |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 5331 | info->SetStatus(true, "", translator); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 5332 | } else { |
[email protected] | d9977d4 | 2010-09-01 20:27:02 | [diff] [blame] | 5333 | // We cannot reach here if we are using the shader translator. |
| 5334 | // All invalid shaders must be rejected by the translator. |
| 5335 | // All translated shaders must compile. |
| 5336 | LOG_IF(ERROR, use_shader_translator_) |
| 5337 | << "Shader translator allowed/produced an invalid shader."; |
[email protected] | 1fd26d8 | 2010-11-04 16:06:33 | [diff] [blame] | 5338 | GLint max_len = 0; |
| 5339 | glGetShaderiv(info->service_id(), GL_INFO_LOG_LENGTH, &max_len); |
| 5340 | scoped_array<char> temp(new char[max_len]); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 5341 | GLint len = 0; |
[email protected] | 1fd26d8 | 2010-11-04 16:06:33 | [diff] [blame] | 5342 | glGetShaderInfoLog(info->service_id(), max_len, &len, temp.get()); |
| 5343 | DCHECK(max_len == 0 || len < max_len); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5344 | DCHECK(len == 0 || temp[len] == '\0'); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5345 | info->SetStatus(false, std::string(temp.get(), len).c_str(), NULL); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 5346 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5347 | }; |
| 5348 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5349 | void GLES2DecoderImpl::DoGetShaderiv( |
| 5350 | GLuint shader, GLenum pname, GLint* params) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5351 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5352 | shader, "glGetShaderiv"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5353 | if (!info) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5354 | return; |
| 5355 | } |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5356 | switch (pname) { |
| 5357 | case GL_SHADER_SOURCE_LENGTH: |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5358 | *params = info->source() ? info->source()->size() + 1 : 0; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5359 | return; |
| 5360 | case GL_COMPILE_STATUS: |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 5361 | *params = compile_shader_always_succeeds_ ? true : info->IsValid(); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 5362 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5363 | case GL_INFO_LOG_LENGTH: |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5364 | *params = info->log_info() ? info->log_info()->size() + 1 : 0; |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 5365 | return; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5366 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5367 | *params = info->translated_source() ? |
| 5368 | info->translated_source()->size() + 1 : 0; |
| 5369 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5370 | default: |
| 5371 | break; |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5372 | } |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5373 | glGetShaderiv(info->service_id(), pname, params); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5374 | } |
| 5375 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5376 | error::Error GLES2DecoderImpl::HandleGetShaderSource( |
| 5377 | uint32 immediate_data_size, const gles2::GetShaderSource& c) { |
| 5378 | GLuint shader = c.shader; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5379 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 5380 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5381 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5382 | shader, "glGetShaderSource"); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5383 | if (!info || !info->source()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5384 | bucket->SetSize(0); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5385 | return error::kNoError; |
| 5386 | } |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5387 | bucket->SetFromString(info->source()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5388 | return error::kNoError; |
| 5389 | } |
| 5390 | |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5391 | error::Error GLES2DecoderImpl::HandleGetTranslatedShaderSourceANGLE( |
| 5392 | uint32 immediate_data_size, |
| 5393 | const gles2::GetTranslatedShaderSourceANGLE& c) { |
| 5394 | GLuint shader = c.shader; |
| 5395 | |
| 5396 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 5397 | Bucket* bucket = CreateBucket(bucket_id); |
| 5398 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5399 | shader, "glTranslatedGetShaderSourceANGLE"); |
| 5400 | if (!info) { |
| 5401 | bucket->SetSize(0); |
| 5402 | return error::kNoError; |
| 5403 | } |
| 5404 | |
| 5405 | bucket->SetFromString(info->translated_source() ? |
| 5406 | info->translated_source()->c_str() : NULL); |
| 5407 | return error::kNoError; |
| 5408 | } |
| 5409 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5410 | error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( |
| 5411 | uint32 immediate_data_size, const gles2::GetProgramInfoLog& c) { |
| 5412 | GLuint program = c.program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5413 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 5414 | Bucket* bucket = CreateBucket(bucket_id); |
| 5415 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 5416 | program, "glGetProgramInfoLog"); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5417 | if (!info || !info->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 5418 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5419 | return error::kNoError; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5420 | } |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5421 | bucket->SetFromString(info->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5422 | return error::kNoError; |
| 5423 | } |
| 5424 | |
| 5425 | error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( |
| 5426 | uint32 immediate_data_size, const gles2::GetShaderInfoLog& c) { |
| 5427 | GLuint shader = c.shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5428 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 5429 | Bucket* bucket = CreateBucket(bucket_id); |
| 5430 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5431 | shader, "glGetShaderInfoLog"); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5432 | if (!info || !info->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 5433 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5434 | return error::kNoError; |
| 5435 | } |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5436 | bucket->SetFromString(info->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5437 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5438 | } |
| 5439 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5440 | bool GLES2DecoderImpl::DoIsBuffer(GLuint client_id) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5441 | const BufferManager::BufferInfo* buffer = GetBufferInfo(client_id); |
| 5442 | return buffer && buffer->IsValid() && !buffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5443 | } |
| 5444 | |
| 5445 | bool GLES2DecoderImpl::DoIsFramebuffer(GLuint client_id) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5446 | const FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 5447 | GetFramebufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5448 | return framebuffer && framebuffer->IsValid() && !framebuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | bool GLES2DecoderImpl::DoIsProgram(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 5452 | // IsProgram is true for programs as soon as they are created, until they are |
| 5453 | // deleted and no longer in use. |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5454 | const ProgramManager::ProgramInfo* program = GetProgramInfo(client_id); |
| 5455 | return program != NULL && !program->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | bool GLES2DecoderImpl::DoIsRenderbuffer(GLuint client_id) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5459 | const RenderbufferManager::RenderbufferInfo* renderbuffer = |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 5460 | GetRenderbufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5461 | return renderbuffer && renderbuffer->IsValid() && !renderbuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 5465 | // IsShader is true for shaders as soon as they are created, until they |
| 5466 | // are deleted and not attached to any programs. |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5467 | const ShaderManager::ShaderInfo* shader = GetShaderInfo(client_id); |
| 5468 | return shader != NULL && !shader->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5472 | const TextureManager::TextureInfo* texture = GetTextureInfo(client_id); |
| 5473 | return texture && texture->IsValid() && !texture->IsDeleted(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | void GLES2DecoderImpl::DoAttachShader( |
| 5477 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5478 | ProgramManager::ProgramInfo* program_info = GetProgramInfoNotShader( |
| 5479 | program_client_id, "glAttachShader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5480 | if (!program_info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5481 | return; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5482 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5483 | ShaderManager::ShaderInfo* shader_info = GetShaderInfoNotProgram( |
| 5484 | shader_client_id, "glAttachShader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5485 | if (!shader_info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5486 | return; |
| 5487 | } |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5488 | if (!program_info->AttachShader(shader_manager(), shader_info)) { |
[email protected] | fb96c8e | 2010-08-12 04:10:31 | [diff] [blame] | 5489 | SetGLError(GL_INVALID_OPERATION, |
| 5490 | "glAttachShader: can not attach more than" |
| 5491 | " one shader of the same type."); |
| 5492 | return; |
| 5493 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5494 | glAttachShader(program_info->service_id(), shader_info->service_id()); |
| 5495 | } |
| 5496 | |
| 5497 | void GLES2DecoderImpl::DoDetachShader( |
| 5498 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5499 | ProgramManager::ProgramInfo* program_info = GetProgramInfoNotShader( |
| 5500 | program_client_id, "glDetachShader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5501 | if (!program_info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5502 | return; |
| 5503 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5504 | ShaderManager::ShaderInfo* shader_info = GetShaderInfoNotProgram( |
| 5505 | shader_client_id, "glDetachShader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5506 | if (!shader_info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5507 | return; |
| 5508 | } |
[email protected] | 9a0ccd4 | 2011-03-16 23:58:22 | [diff] [blame] | 5509 | if (!program_info->DetachShader(shader_manager(), shader_info)) { |
| 5510 | SetGLError(GL_INVALID_OPERATION, |
| 5511 | "glDetachShader: shader not attached to program"); |
| 5512 | return; |
| 5513 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5514 | glDetachShader(program_info->service_id(), shader_info->service_id()); |
| 5515 | } |
| 5516 | |
| 5517 | void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5518 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 5519 | program_client_id, "glValidateProgram"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5520 | if (!info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5521 | return; |
| 5522 | } |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 5523 | info->Validate(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5524 | } |
| 5525 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5526 | void GLES2DecoderImpl::DoGetVertexAttribfv( |
| 5527 | GLuint index, GLenum pname, GLfloat* params) { |
| 5528 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5529 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5530 | if (!info) { |
| 5531 | SetGLError(GL_INVALID_VALUE, "glGetVertexAttribfv: index out of range"); |
| 5532 | return; |
| 5533 | } |
| 5534 | switch (pname) { |
| 5535 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
| 5536 | BufferManager::BufferInfo* buffer = info->buffer(); |
| 5537 | if (buffer && !buffer->IsDeleted()) { |
| 5538 | GLuint client_id; |
| 5539 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 5540 | *params = static_cast<GLfloat>(client_id); |
| 5541 | } |
| 5542 | break; |
| 5543 | } |
| 5544 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5545 | *params = static_cast<GLfloat>(info->enabled()); |
| 5546 | break; |
| 5547 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5548 | *params = static_cast<GLfloat>(info->size()); |
| 5549 | break; |
| 5550 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5551 | *params = static_cast<GLfloat>(info->gl_stride()); |
| 5552 | break; |
| 5553 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5554 | *params = static_cast<GLfloat>(info->type()); |
| 5555 | break; |
| 5556 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5557 | *params = static_cast<GLfloat>(info->normalized()); |
| 5558 | break; |
| 5559 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5560 | params[0] = info->value().v[0]; |
| 5561 | params[1] = info->value().v[1]; |
| 5562 | params[2] = info->value().v[2]; |
| 5563 | params[3] = info->value().v[3]; |
| 5564 | break; |
| 5565 | default: |
| 5566 | NOTREACHED(); |
| 5567 | break; |
| 5568 | } |
| 5569 | } |
| 5570 | |
| 5571 | void GLES2DecoderImpl::DoGetVertexAttribiv( |
| 5572 | GLuint index, GLenum pname, GLint* params) { |
| 5573 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5574 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5575 | if (!info) { |
| 5576 | SetGLError(GL_INVALID_VALUE, "glGetVertexAttribiv: index out of range"); |
| 5577 | return; |
| 5578 | } |
| 5579 | switch (pname) { |
| 5580 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
| 5581 | BufferManager::BufferInfo* buffer = info->buffer(); |
| 5582 | if (buffer && !buffer->IsDeleted()) { |
| 5583 | GLuint client_id; |
| 5584 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 5585 | *params = client_id; |
| 5586 | } |
| 5587 | break; |
| 5588 | } |
| 5589 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5590 | *params = info->enabled(); |
| 5591 | break; |
| 5592 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5593 | *params = info->size(); |
| 5594 | break; |
| 5595 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5596 | *params = info->gl_stride(); |
| 5597 | break; |
| 5598 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5599 | *params = info->type(); |
| 5600 | break; |
| 5601 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5602 | *params = static_cast<GLint>(info->normalized()); |
| 5603 | break; |
| 5604 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5605 | params[0] = static_cast<GLint>(info->value().v[0]); |
| 5606 | params[1] = static_cast<GLint>(info->value().v[1]); |
| 5607 | params[2] = static_cast<GLint>(info->value().v[2]); |
| 5608 | params[3] = static_cast<GLint>(info->value().v[3]); |
| 5609 | break; |
| 5610 | default: |
| 5611 | NOTREACHED(); |
| 5612 | break; |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) { |
| 5617 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5618 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5619 | if (!info) { |
| 5620 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib1f: index out of range"); |
| 5621 | return; |
| 5622 | } |
| 5623 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 5624 | value.v[0] = v0; |
| 5625 | value.v[1] = 0.0f; |
| 5626 | value.v[2] = 0.0f; |
| 5627 | value.v[3] = 1.0f; |
| 5628 | info->set_value(value); |
| 5629 | glVertexAttrib1f(index, v0); |
| 5630 | } |
| 5631 | |
| 5632 | void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) { |
| 5633 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5634 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5635 | if (!info) { |
| 5636 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib2f: index out of range"); |
| 5637 | return; |
| 5638 | } |
| 5639 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 5640 | value.v[0] = v0; |
| 5641 | value.v[1] = v1; |
| 5642 | value.v[2] = 0.0f; |
| 5643 | value.v[3] = 1.0f; |
| 5644 | info->set_value(value); |
| 5645 | glVertexAttrib2f(index, v0, v1); |
| 5646 | } |
| 5647 | |
| 5648 | void GLES2DecoderImpl::DoVertexAttrib3f( |
| 5649 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { |
| 5650 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5651 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5652 | if (!info) { |
| 5653 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib3f: index out of range"); |
| 5654 | return; |
| 5655 | } |
| 5656 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 5657 | value.v[0] = v0; |
| 5658 | value.v[1] = v1; |
| 5659 | value.v[2] = v2; |
| 5660 | value.v[3] = 1.0f; |
| 5661 | info->set_value(value); |
| 5662 | glVertexAttrib3f(index, v0, v1, v2); |
| 5663 | } |
| 5664 | |
| 5665 | void GLES2DecoderImpl::DoVertexAttrib4f( |
| 5666 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { |
| 5667 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5668 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5669 | if (!info) { |
| 5670 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib4f: index out of range"); |
| 5671 | return; |
| 5672 | } |
| 5673 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 5674 | value.v[0] = v0; |
| 5675 | value.v[1] = v1; |
| 5676 | value.v[2] = v2; |
| 5677 | value.v[3] = v3; |
| 5678 | info->set_value(value); |
| 5679 | glVertexAttrib4f(index, v0, v1, v2, v3); |
| 5680 | } |
| 5681 | |
| 5682 | void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) { |
| 5683 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5684 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5685 | if (!info) { |
| 5686 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib1fv: index out of range"); |
| 5687 | return; |
| 5688 | } |
| 5689 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 5690 | value.v[0] = v[0]; |
| 5691 | value.v[1] = 0.0f; |
| 5692 | value.v[2] = 0.0f; |
| 5693 | value.v[3] = 1.0f; |
| 5694 | info->set_value(value); |
| 5695 | glVertexAttrib1fv(index, v); |
| 5696 | } |
| 5697 | |
| 5698 | void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) { |
| 5699 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5700 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5701 | if (!info) { |
| 5702 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib2fv: index out of range"); |
| 5703 | return; |
| 5704 | } |
| 5705 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 5706 | value.v[0] = v[0]; |
| 5707 | value.v[1] = v[1]; |
| 5708 | value.v[2] = 0.0f; |
| 5709 | value.v[3] = 1.0f; |
| 5710 | info->set_value(value); |
| 5711 | glVertexAttrib2fv(index, v); |
| 5712 | } |
| 5713 | |
| 5714 | void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) { |
| 5715 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5716 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5717 | if (!info) { |
| 5718 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib3fv: index out of range"); |
| 5719 | return; |
| 5720 | } |
| 5721 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 5722 | value.v[0] = v[0]; |
| 5723 | value.v[1] = v[1]; |
| 5724 | value.v[2] = v[2]; |
| 5725 | value.v[3] = 1.0f; |
| 5726 | info->set_value(value); |
| 5727 | glVertexAttrib3fv(index, v); |
| 5728 | } |
| 5729 | |
| 5730 | void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) { |
| 5731 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5732 | vertex_attrib_manager_->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5733 | if (!info) { |
| 5734 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib4fv: index out of range"); |
| 5735 | return; |
| 5736 | } |
| 5737 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 5738 | value.v[0] = v[0]; |
| 5739 | value.v[1] = v[1]; |
| 5740 | value.v[2] = v[2]; |
| 5741 | value.v[3] = v[3]; |
| 5742 | info->set_value(value); |
| 5743 | glVertexAttrib4fv(index, v); |
| 5744 | } |
| 5745 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5746 | error::Error GLES2DecoderImpl::HandleVertexAttribPointer( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5747 | uint32 immediate_data_size, const gles2::VertexAttribPointer& c) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5748 | if (!bound_array_buffer_ || bound_array_buffer_->IsDeleted()) { |
| 5749 | SetGLError(GL_INVALID_VALUE, |
| 5750 | "glVertexAttribPointer: no array buffer bound"); |
| 5751 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5752 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5753 | |
| 5754 | GLuint indx = c.indx; |
| 5755 | GLint size = c.size; |
| 5756 | GLenum type = c.type; |
| 5757 | GLboolean normalized = c.normalized; |
| 5758 | GLsizei stride = c.stride; |
| 5759 | GLsizei offset = c.offset; |
| 5760 | const void* ptr = reinterpret_cast<const void*>(offset); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5761 | if (!validators_->vertex_attrib_type.IsValid(type)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5762 | SetGLError(GL_INVALID_ENUM, |
| 5763 | "glVertexAttribPointer: type GL_INVALID_ENUM"); |
| 5764 | return error::kNoError; |
| 5765 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5766 | if (!validators_->vertex_attrib_size.IsValid(size)) { |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 5767 | SetGLError(GL_INVALID_VALUE, |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5768 | "glVertexAttribPointer: size GL_INVALID_VALUE"); |
| 5769 | return error::kNoError; |
| 5770 | } |
| 5771 | if (indx >= group_->max_vertex_attribs()) { |
| 5772 | SetGLError(GL_INVALID_VALUE, "glVertexAttribPointer: index out of range"); |
| 5773 | return error::kNoError; |
| 5774 | } |
| 5775 | if (stride < 0) { |
| 5776 | SetGLError(GL_INVALID_VALUE, |
| 5777 | "glVertexAttribPointer: stride < 0"); |
| 5778 | return error::kNoError; |
| 5779 | } |
| 5780 | if (stride > 255) { |
| 5781 | SetGLError(GL_INVALID_VALUE, |
| 5782 | "glVertexAttribPointer: stride > 255"); |
| 5783 | return error::kNoError; |
| 5784 | } |
| 5785 | if (offset < 0) { |
| 5786 | SetGLError(GL_INVALID_VALUE, |
| 5787 | "glVertexAttribPointer: offset < 0"); |
| 5788 | return error::kNoError; |
| 5789 | } |
| 5790 | GLsizei component_size = |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 5791 | GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5792 | if (offset % component_size > 0) { |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 5793 | SetGLError(GL_INVALID_OPERATION, |
| 5794 | "glVertexAttribPointer: offset not valid for type"); |
| 5795 | return error::kNoError; |
| 5796 | } |
| 5797 | if (stride % component_size > 0) { |
| 5798 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5799 | "glVertexAttribPointer: stride not valid for type"); |
| 5800 | return error::kNoError; |
| 5801 | } |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 5802 | vertex_attrib_manager_->SetAttribInfo( |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5803 | indx, |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5804 | bound_array_buffer_, |
| 5805 | size, |
| 5806 | type, |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5807 | normalized, |
| 5808 | stride, |
| 5809 | stride != 0 ? stride : component_size * size, |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5810 | offset); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5811 | if (type != GL_FIXED) { |
| 5812 | glVertexAttribPointer(indx, size, type, normalized, stride, ptr); |
| 5813 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5814 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5815 | } |
| 5816 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5817 | error::Error GLES2DecoderImpl::HandleReadPixels( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5818 | uint32 immediate_data_size, const gles2::ReadPixels& c) { |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 5819 | GLint x = c.x; |
| 5820 | GLint y = c.y; |
| 5821 | GLsizei width = c.width; |
| 5822 | GLsizei height = c.height; |
| 5823 | GLenum format = c.format; |
| 5824 | GLenum type = c.type; |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5825 | if (width < 0 || height < 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5826 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions < 0"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5827 | return error::kNoError; |
| 5828 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 5829 | typedef gles2::ReadPixels::Result Result; |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 5830 | uint32 pixels_size; |
| 5831 | if (!GLES2Util::ComputeImageDataSize( |
| 5832 | width, height, format, type, pack_alignment_, &pixels_size)) { |
| 5833 | return error::kOutOfBounds; |
| 5834 | } |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 5835 | void* pixels = GetSharedMemoryAs<void*>( |
| 5836 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 5837 | Result* result = GetSharedMemoryAs<Result*>( |
| 5838 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 5839 | if (!pixels || !result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5840 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 5841 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 5842 | |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5843 | if (!validators_->read_pixel_format.IsValid(format)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5844 | SetGLError(GL_INVALID_ENUM, "glReadPixels: format GL_INVALID_ENUM"); |
| 5845 | return error::kNoError; |
| 5846 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5847 | if (!validators_->pixel_type.IsValid(type)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5848 | SetGLError(GL_INVALID_ENUM, "glReadPixels: type GL_INVALID_ENUM"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 5849 | return error::kNoError; |
| 5850 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5851 | if (width == 0 || height == 0) { |
| 5852 | return error::kNoError; |
| 5853 | } |
| 5854 | |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5855 | // Get the size of the current fbo or backbuffer. |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5856 | gfx::Size max_size = GetBoundReadFrameBufferSize(); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5857 | |
| 5858 | GLint max_x; |
| 5859 | GLint max_y; |
| 5860 | if (!SafeAdd(x, width, &max_x) || !SafeAdd(y, height, &max_y)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5861 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5862 | return error::kNoError; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 5863 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5864 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5865 | if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 5866 | return error::kNoError; |
| 5867 | } |
| 5868 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5869 | CopyRealGLErrorsToWrapper(); |
| 5870 | |
| 5871 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 5872 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 5873 | if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5874 | // The user requested an out of range area. Get the results 1 line |
| 5875 | // at a time. |
| 5876 | uint32 temp_size; |
| 5877 | if (!GLES2Util::ComputeImageDataSize( |
| 5878 | width, 1, format, type, pack_alignment_, &temp_size)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5879 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5880 | return error::kNoError; |
| 5881 | } |
| 5882 | GLsizei unpadded_row_size = temp_size; |
| 5883 | if (!GLES2Util::ComputeImageDataSize( |
| 5884 | width, 2, format, type, pack_alignment_, &temp_size)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5885 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5886 | return error::kNoError; |
| 5887 | } |
| 5888 | GLsizei padded_row_size = temp_size - unpadded_row_size; |
| 5889 | if (padded_row_size < 0 || unpadded_row_size < 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5890 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5891 | return error::kNoError; |
| 5892 | } |
| 5893 | |
| 5894 | GLint dest_x_offset = std::max(-x, 0); |
| 5895 | uint32 dest_row_offset; |
| 5896 | if (!GLES2Util::ComputeImageDataSize( |
| 5897 | dest_x_offset, 1, format, type, pack_alignment_, &dest_row_offset)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5898 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5899 | return error::kNoError; |
| 5900 | } |
| 5901 | |
| 5902 | // Copy each row into the larger dest rect. |
| 5903 | int8* dst = static_cast<int8*>(pixels); |
| 5904 | GLint read_x = std::max(0, x); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 5905 | GLint read_end_x = std::max(0, std::min(max_size.width(), max_x)); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5906 | GLint read_width = read_end_x - read_x; |
| 5907 | for (GLint yy = 0; yy < height; ++yy) { |
| 5908 | GLint ry = y + yy; |
| 5909 | |
| 5910 | // Clear the row. |
| 5911 | memset(dst, 0, unpadded_row_size); |
| 5912 | |
| 5913 | // If the row is in range, copy it. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 5914 | if (ry >= 0 && ry < max_size.height() && read_width > 0) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 5915 | glReadPixels( |
| 5916 | read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
| 5917 | } |
| 5918 | dst += padded_row_size; |
| 5919 | } |
| 5920 | } else { |
| 5921 | glReadPixels(x, y, width, height, format, type, pixels); |
| 5922 | } |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 5923 | GLenum error = PeekGLError(); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 5924 | if (error == GL_NO_ERROR) { |
| 5925 | *result = true; |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 5926 | |
| 5927 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 5928 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 5929 | if ((channels_exist & 0x0008) == 0) { |
| 5930 | // Set the alpha to 255 because some drivers are buggy in this regard. |
| 5931 | uint32 temp_size; |
| 5932 | if (!GLES2Util::ComputeImageDataSize( |
| 5933 | width, 1, format, type, pack_alignment_, &temp_size)) { |
| 5934 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); |
| 5935 | return error::kNoError; |
| 5936 | } |
| 5937 | GLsizei unpadded_row_size = temp_size; |
| 5938 | if (!GLES2Util::ComputeImageDataSize( |
| 5939 | width, 2, format, type, pack_alignment_, &temp_size)) { |
| 5940 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); |
| 5941 | return error::kNoError; |
| 5942 | } |
| 5943 | GLsizei padded_row_size = temp_size - unpadded_row_size; |
| 5944 | if (padded_row_size < 0 || unpadded_row_size < 0) { |
| 5945 | SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); |
| 5946 | return error::kNoError; |
| 5947 | } |
| 5948 | // NOTE: Assumes the type is GL_UNSIGNED_BYTE which was true at the time |
| 5949 | // of this implementation. |
| 5950 | if (type != GL_UNSIGNED_BYTE) { |
| 5951 | SetGLError(GL_INVALID_OPERATION, "unsupported readPixel format"); |
| 5952 | return error::kNoError; |
| 5953 | } |
| 5954 | switch (format) { |
| 5955 | case GL_RGBA: |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5956 | case GL_BGRA_EXT: |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 5957 | case GL_ALPHA: { |
| 5958 | int offset = (format == GL_ALPHA) ? 0 : 3; |
| 5959 | int step = (format == GL_ALPHA) ? 1 : 4; |
| 5960 | uint8* dst = static_cast<uint8*>(pixels) + offset; |
| 5961 | for (GLint yy = 0; yy < height; ++yy) { |
| 5962 | uint8* end = dst + unpadded_row_size; |
| 5963 | for (uint8* d = dst; d < end; d += step) { |
| 5964 | *d = 255; |
| 5965 | } |
| 5966 | dst += padded_row_size; |
| 5967 | } |
| 5968 | break; |
| 5969 | } |
| 5970 | default: |
| 5971 | break; |
| 5972 | } |
| 5973 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 5974 | } |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 5975 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5976 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5977 | } |
| 5978 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5979 | error::Error GLES2DecoderImpl::HandlePixelStorei( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5980 | uint32 immediate_data_size, const gles2::PixelStorei& c) { |
| 5981 | GLenum pname = c.pname; |
| 5982 | GLenum param = c.param; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5983 | if (!validators_->pixel_store.IsValid(pname)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5984 | SetGLError(GL_INVALID_ENUM, "glPixelStorei: pname GL_INVALID_ENUM"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 5985 | return error::kNoError; |
| 5986 | } |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 5987 | switch (pname) { |
| 5988 | case GL_PACK_ALIGNMENT: |
| 5989 | case GL_UNPACK_ALIGNMENT: |
| 5990 | if (!validators_->pixel_store_alignment.IsValid(param)) { |
| 5991 | SetGLError(GL_INVALID_VALUE, |
| 5992 | "glPixelSTore: param GL_INVALID_VALUE"); |
| 5993 | return error::kNoError; |
| 5994 | } |
| 5995 | default: |
| 5996 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5997 | } |
| 5998 | glPixelStorei(pname, param); |
| 5999 | switch (pname) { |
| 6000 | case GL_PACK_ALIGNMENT: |
| 6001 | pack_alignment_ = param; |
| 6002 | break; |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 6003 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
| 6004 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6005 | case GL_UNPACK_ALIGNMENT: |
| 6006 | unpack_alignment_ = param; |
| 6007 | break; |
| 6008 | default: |
| 6009 | // Validation should have prevented us from getting here. |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 6010 | NOTREACHED(); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6011 | break; |
| 6012 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6013 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6014 | } |
| 6015 | |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 6016 | error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( |
| 6017 | uint32 immediate_data_size, const gles2::PostSubBufferCHROMIUM& c) { |
| 6018 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM"); |
[email protected] | aa25882 | 2011-11-22 13:52:25 | [diff] [blame] | 6019 | if (!context_->HasExtension("GL_CHROMIUM_post_sub_buffer")) { |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 6020 | SetGLError(GL_INVALID_OPERATION, |
| 6021 | "glPostSubBufferCHROMIUM: command not supported by surface"); |
| 6022 | return error::kNoError; |
| 6023 | } |
| 6024 | if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height)) |
| 6025 | return error::kNoError; |
| 6026 | else |
| 6027 | return error::kLostContext; |
| 6028 | } |
| 6029 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6030 | error::Error GLES2DecoderImpl::GetAttribLocationHelper( |
| 6031 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 6032 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6033 | if (!StringIsValidForGLES(name_str.c_str())) { |
| 6034 | SetGLError(GL_INVALID_VALUE, "glGetAttribLocation: Invalid character"); |
| 6035 | return error::kNoError; |
| 6036 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6037 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 6038 | client_id, "glGetAttribLocation"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6039 | if (!info) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6040 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6041 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6042 | if (!info->IsValid()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6043 | SetGLError(GL_INVALID_OPERATION, "glGetAttribLocation: program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 6044 | return error::kNoError; |
| 6045 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6046 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6047 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 6048 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6049 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6050 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6051 | // Require the client to init this incase the context is lost and we are no |
| 6052 | // longer executing commands. |
| 6053 | if (*location != -1) { |
| 6054 | return error::kGenericError; |
| 6055 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 6056 | *location = info->GetAttribLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6057 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6058 | } |
| 6059 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6060 | error::Error GLES2DecoderImpl::HandleGetAttribLocation( |
| 6061 | uint32 immediate_data_size, const gles2::GetAttribLocation& c) { |
| 6062 | uint32 name_size = c.data_size; |
| 6063 | const char* name = GetSharedMemoryAs<const char*>( |
| 6064 | c.name_shm_id, c.name_shm_offset, name_size); |
| 6065 | if (!name) { |
| 6066 | return error::kOutOfBounds; |
| 6067 | } |
| 6068 | String name_str(name, name_size); |
| 6069 | return GetAttribLocationHelper( |
| 6070 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 6071 | } |
| 6072 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6073 | error::Error GLES2DecoderImpl::HandleGetAttribLocationImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6074 | uint32 immediate_data_size, const gles2::GetAttribLocationImmediate& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6075 | uint32 name_size = c.data_size; |
| 6076 | const char* name = GetImmediateDataAs<const char*>( |
| 6077 | c, name_size, immediate_data_size); |
| 6078 | if (!name) { |
| 6079 | return error::kOutOfBounds; |
| 6080 | } |
| 6081 | String name_str(name, name_size); |
| 6082 | return GetAttribLocationHelper( |
| 6083 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 6084 | } |
| 6085 | |
| 6086 | error::Error GLES2DecoderImpl::HandleGetAttribLocationBucket( |
| 6087 | uint32 immediate_data_size, const gles2::GetAttribLocationBucket& c) { |
| 6088 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 6089 | if (!bucket) { |
| 6090 | return error::kInvalidArguments; |
| 6091 | } |
| 6092 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 6093 | if (!bucket->GetAsString(&name_str)) { |
| 6094 | return error::kInvalidArguments; |
| 6095 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6096 | return GetAttribLocationHelper( |
| 6097 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 6098 | } |
| 6099 | |
| 6100 | error::Error GLES2DecoderImpl::GetUniformLocationHelper( |
| 6101 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 6102 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6103 | if (!StringIsValidForGLES(name_str.c_str())) { |
| 6104 | SetGLError(GL_INVALID_VALUE, "glGetUniformLocation: Invalid character"); |
| 6105 | return error::kNoError; |
| 6106 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6107 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 6108 | client_id, "glUniformLocation"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6109 | if (!info) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6110 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6111 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6112 | if (!info->IsValid()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6113 | SetGLError(GL_INVALID_OPERATION, |
| 6114 | "glGetUniformLocation: program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 6115 | return error::kNoError; |
| 6116 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6117 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6118 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 6119 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6120 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6121 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6122 | // Require the client to init this incase the context is lost an we are no |
| 6123 | // longer executing commands. |
| 6124 | if (*location != -1) { |
| 6125 | return error::kGenericError; |
| 6126 | } |
[email protected] | 5d4c6b2 | 2012-02-07 08:22:28 | [diff] [blame] | 6127 | *location = program_manager()->SwizzleLocation( |
| 6128 | info->GetUniformLocation(name_str)); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6129 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6130 | } |
| 6131 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6132 | error::Error GLES2DecoderImpl::HandleGetUniformLocation( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6133 | uint32 immediate_data_size, const gles2::GetUniformLocation& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6134 | uint32 name_size = c.data_size; |
| 6135 | const char* name = GetSharedMemoryAs<const char*>( |
| 6136 | c.name_shm_id, c.name_shm_offset, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6137 | if (!name) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6138 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6139 | } |
| 6140 | String name_str(name, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6141 | return GetUniformLocationHelper( |
| 6142 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6143 | } |
| 6144 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6145 | error::Error GLES2DecoderImpl::HandleGetUniformLocationImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6146 | uint32 immediate_data_size, const gles2::GetUniformLocationImmediate& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6147 | uint32 name_size = c.data_size; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6148 | const char* name = GetImmediateDataAs<const char*>( |
| 6149 | c, name_size, immediate_data_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6150 | if (!name) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6151 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6152 | } |
| 6153 | String name_str(name, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6154 | return GetUniformLocationHelper( |
| 6155 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 6156 | } |
| 6157 | |
| 6158 | error::Error GLES2DecoderImpl::HandleGetUniformLocationBucket( |
| 6159 | uint32 immediate_data_size, const gles2::GetUniformLocationBucket& c) { |
| 6160 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 6161 | if (!bucket) { |
| 6162 | return error::kInvalidArguments; |
| 6163 | } |
| 6164 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 6165 | if (!bucket->GetAsString(&name_str)) { |
| 6166 | return error::kInvalidArguments; |
| 6167 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6168 | return GetUniformLocationHelper( |
| 6169 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6170 | } |
| 6171 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6172 | error::Error GLES2DecoderImpl::HandleGetString( |
| 6173 | uint32 immediate_data_size, const gles2::GetString& c) { |
| 6174 | GLenum name = static_cast<GLenum>(c.name); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6175 | if (!validators_->string_type.IsValid(name)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6176 | SetGLError(GL_INVALID_ENUM, "glGetString: name GL_INVALID_ENUM"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6177 | return error::kNoError; |
| 6178 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6179 | const char* gl_str = reinterpret_cast<const char*>(glGetString(name)); |
| 6180 | const char* str = NULL; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 6181 | std::string extensions; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6182 | switch (name) { |
| 6183 | case GL_VERSION: |
| 6184 | str = "OpenGL ES 2.0 Chromium"; |
| 6185 | break; |
| 6186 | case GL_SHADING_LANGUAGE_VERSION: |
| 6187 | str = "OpenGL ES GLSL ES 1.0 Chromium"; |
| 6188 | break; |
| 6189 | case GL_EXTENSIONS: |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 6190 | { |
| 6191 | // For WebGL contexts, strip out the OES derivatives extension if it has |
| 6192 | // not been enabled. |
| 6193 | if (force_webgl_glsl_validation_ && |
| 6194 | !derivatives_explicitly_enabled_) { |
| 6195 | extensions = feature_info_->extensions(); |
| 6196 | size_t offset = extensions.find(kOESDerivativeExtension); |
| 6197 | if (std::string::npos != offset) { |
| 6198 | extensions.replace(offset, |
| 6199 | offset + arraysize(kOESDerivativeExtension), |
| 6200 | std::string()); |
| 6201 | } |
| 6202 | str = extensions.c_str(); |
| 6203 | } else { |
| 6204 | str = feature_info_->extensions().c_str(); |
| 6205 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 6206 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6207 | break; |
| 6208 | default: |
| 6209 | str = gl_str; |
| 6210 | break; |
| 6211 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6212 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6213 | bucket->SetFromString(str); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6214 | return error::kNoError; |
| 6215 | } |
| 6216 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6217 | void GLES2DecoderImpl::DoBufferData( |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 6218 | GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) { |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6219 | if (!validators_->buffer_target.IsValid(target)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6220 | SetGLError(GL_INVALID_ENUM, "glBufferData: target GL_INVALID_ENUM"); |
| 6221 | return; |
| 6222 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6223 | if (!validators_->buffer_usage.IsValid(usage)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6224 | SetGLError(GL_INVALID_ENUM, "glBufferData: usage GL_INVALID_ENUM"); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6225 | return; |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6226 | } |
| 6227 | if (size < 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6228 | SetGLError(GL_INVALID_VALUE, "glBufferData: size < 0"); |
[email protected] | 037896bd | 2010-04-21 19:07:28 | [diff] [blame] | 6229 | return; |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6230 | } |
| 6231 | BufferManager::BufferInfo* info = GetBufferInfoForTarget(target); |
| 6232 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6233 | SetGLError(GL_INVALID_VALUE, "glBufferData: unknown buffer"); |
[email protected] | 037896bd | 2010-04-21 19:07:28 | [diff] [blame] | 6234 | return; |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6235 | } |
| 6236 | // Clear the buffer to 0 if no initial data was passed in. |
| 6237 | scoped_array<int8> zero; |
| 6238 | if (!data) { |
| 6239 | zero.reset(new int8[size]); |
| 6240 | memset(zero.get(), 0, size); |
| 6241 | data = zero.get(); |
| 6242 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6243 | |
| 6244 | if (!bufferdata_faster_than_buffersubdata_ && |
| 6245 | size == info->size() && usage == info->usage()) { |
| 6246 | glBufferSubData(target, 0, size, data); |
| 6247 | info->SetRange(0, size, data); |
| 6248 | return; |
| 6249 | } |
| 6250 | |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6251 | CopyRealGLErrorsToWrapper(); |
| 6252 | glBufferData(target, size, data, usage); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 6253 | GLenum error = PeekGLError(); |
| 6254 | if (error == GL_NO_ERROR) { |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6255 | buffer_manager()->SetInfo(info, size, usage); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6256 | info->SetRange(0, size, data); |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6257 | } |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | error::Error GLES2DecoderImpl::HandleBufferData( |
| 6261 | uint32 immediate_data_size, const gles2::BufferData& c) { |
| 6262 | GLenum target = static_cast<GLenum>(c.target); |
| 6263 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 6264 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 6265 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 6266 | GLenum usage = static_cast<GLenum>(c.usage); |
| 6267 | const void* data = NULL; |
| 6268 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 6269 | data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); |
| 6270 | if (!data) { |
| 6271 | return error::kOutOfBounds; |
| 6272 | } |
| 6273 | } |
| 6274 | DoBufferData(target, size, data, usage); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6275 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6276 | } |
| 6277 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6278 | error::Error GLES2DecoderImpl::HandleBufferDataImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6279 | uint32 immediate_data_size, const gles2::BufferDataImmediate& c) { |
| 6280 | GLenum target = static_cast<GLenum>(c.target); |
| 6281 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6282 | const void* data = GetImmediateDataAs<const void*>( |
| 6283 | c, size, immediate_data_size); |
| 6284 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6285 | return error::kOutOfBounds; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6286 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6287 | GLenum usage = static_cast<GLenum>(c.usage); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6288 | DoBufferData(target, size, data, usage); |
| 6289 | return error::kNoError; |
| 6290 | } |
| 6291 | |
| 6292 | void GLES2DecoderImpl::DoBufferSubData( |
| 6293 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6294 | BufferManager::BufferInfo* info = GetBufferInfoForTarget(target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6295 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6296 | SetGLError(GL_INVALID_VALUE, "glBufferSubData: unknown buffer"); |
[email protected] | 037896bd | 2010-04-21 19:07:28 | [diff] [blame] | 6297 | return; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6298 | } |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6299 | if (!info->SetRange(offset, size, data)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6300 | SetGLError(GL_INVALID_VALUE, "glBufferSubData: out of range"); |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6301 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6302 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6303 | if (bufferdata_faster_than_buffersubdata_ && |
| 6304 | offset == 0 && size == info->size()) { |
| 6305 | glBufferData(target, size, data, info->usage()); |
| 6306 | return; |
| 6307 | } |
| 6308 | glBufferSubData(target, offset, size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6309 | } |
| 6310 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6311 | bool GLES2DecoderImpl::ClearLevel( |
| 6312 | unsigned service_id, |
| 6313 | unsigned bind_target, |
| 6314 | unsigned target, |
| 6315 | int level, |
| 6316 | unsigned format, |
| 6317 | unsigned type, |
| 6318 | int width, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6319 | int height, |
| 6320 | bool is_texture_immutable) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6321 | // Assumes the size has already been checked. |
| 6322 | uint32 pixels_size = 0; |
| 6323 | if (!GLES2Util::ComputeImageDataSize( |
| 6324 | width, height, format, type, unpack_alignment_, &pixels_size)) { |
| 6325 | return false; |
| 6326 | } |
| 6327 | scoped_array<char> zero(new char[pixels_size]); |
| 6328 | memset(zero.get(), 0, pixels_size); |
| 6329 | glBindTexture(bind_target, service_id); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6330 | if (is_texture_immutable) { |
| 6331 | glTexSubImage2D( |
| 6332 | target, level, 0, 0, width, height, format, type, zero.get()); |
| 6333 | } else { |
| 6334 | WrappedTexImage2D( |
| 6335 | target, level, format, width, height, 0, format, type, zero.get()); |
| 6336 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6337 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(bind_target); |
| 6338 | glBindTexture(bind_target, info ? info->service_id() : 0); |
| 6339 | return true; |
| 6340 | } |
| 6341 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6342 | error::Error GLES2DecoderImpl::DoCompressedTexImage2D( |
| 6343 | GLenum target, |
| 6344 | GLint level, |
| 6345 | GLenum internal_format, |
| 6346 | GLsizei width, |
| 6347 | GLsizei height, |
| 6348 | GLint border, |
| 6349 | GLsizei image_size, |
| 6350 | const void* data) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6351 | // TODO(gman): Validate image_size is correct for width, height and format. |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6352 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6353 | SetGLError(GL_INVALID_ENUM, |
| 6354 | "glCompressedTexImage2D: target GL_INVALID_ENUM"); |
| 6355 | return error::kNoError; |
| 6356 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6357 | if (!validators_->compressed_texture_format.IsValid( |
| 6358 | internal_format)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6359 | SetGLError(GL_INVALID_ENUM, |
| 6360 | "glCompressedTexImage2D: internal_format GL_INVALID_ENUM"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6361 | return error::kNoError; |
| 6362 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 6363 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6364 | border != 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6365 | SetGLError(GL_INVALID_VALUE, |
| 6366 | "glCompressedTexImage2D: dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6367 | return error::kNoError; |
| 6368 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6369 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6370 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6371 | SetGLError(GL_INVALID_VALUE, |
| 6372 | "glCompressedTexImage2D: unknown texture target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6373 | return error::kNoError; |
| 6374 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 6375 | if (info->IsImmutable()) { |
| 6376 | SetGLError(GL_INVALID_OPERATION, |
| 6377 | "glCompressedTexImage2D: texture is immutable"); |
| 6378 | return error::kNoError; |
| 6379 | } |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 6380 | |
| 6381 | if (info->IsAttachedToFramebuffer()) { |
| 6382 | state_dirty_ = true; |
| 6383 | // TODO(gman): If textures tracked which framebuffers they were attached to |
| 6384 | // we could just mark those framebuffers as not complete. |
| 6385 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 6386 | } |
| 6387 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6388 | scoped_array<int8> zero; |
| 6389 | if (!data) { |
| 6390 | zero.reset(new int8[image_size]); |
| 6391 | memset(zero.get(), 0, image_size); |
| 6392 | data = zero.get(); |
| 6393 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6394 | CopyRealGLErrorsToWrapper(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6395 | glCompressedTexImage2D( |
| 6396 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 6397 | GLenum error = PeekGLError(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6398 | if (error == GL_NO_ERROR) { |
| 6399 | texture_manager()->SetLevelInfo( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6400 | info, target, level, internal_format, width, height, 1, border, 0, 0, |
| 6401 | true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6402 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6403 | return error::kNoError; |
| 6404 | } |
| 6405 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6406 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6407 | uint32 immediate_data_size, const gles2::CompressedTexImage2D& c) { |
| 6408 | GLenum target = static_cast<GLenum>(c.target); |
| 6409 | GLint level = static_cast<GLint>(c.level); |
| 6410 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 6411 | GLsizei width = static_cast<GLsizei>(c.width); |
| 6412 | GLsizei height = static_cast<GLsizei>(c.height); |
| 6413 | GLint border = static_cast<GLint>(c.border); |
| 6414 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 6415 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 6416 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 6417 | const void* data = NULL; |
| 6418 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 6419 | data = GetSharedMemoryAs<const void*>( |
| 6420 | data_shm_id, data_shm_offset, image_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6421 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6422 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6423 | } |
| 6424 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6425 | return DoCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6426 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6427 | } |
| 6428 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6429 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6430 | uint32 immediate_data_size, const gles2::CompressedTexImage2DImmediate& c) { |
| 6431 | GLenum target = static_cast<GLenum>(c.target); |
| 6432 | GLint level = static_cast<GLint>(c.level); |
| 6433 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 6434 | GLsizei width = static_cast<GLsizei>(c.width); |
| 6435 | GLsizei height = static_cast<GLsizei>(c.height); |
| 6436 | GLint border = static_cast<GLint>(c.border); |
| 6437 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6438 | const void* data = GetImmediateDataAs<const void*>( |
| 6439 | c, image_size, immediate_data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6440 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6441 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6442 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6443 | return DoCompressedTexImage2D( |
| 6444 | target, level, internal_format, width, height, border, image_size, data); |
| 6445 | } |
| 6446 | |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 6447 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DBucket( |
| 6448 | uint32 immediate_data_size, const gles2::CompressedTexImage2DBucket& c) { |
| 6449 | GLenum target = static_cast<GLenum>(c.target); |
| 6450 | GLint level = static_cast<GLint>(c.level); |
| 6451 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 6452 | GLsizei width = static_cast<GLsizei>(c.width); |
| 6453 | GLsizei height = static_cast<GLsizei>(c.height); |
| 6454 | GLint border = static_cast<GLint>(c.border); |
| 6455 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 6456 | if (!bucket) { |
| 6457 | return error::kInvalidArguments; |
| 6458 | } |
| 6459 | uint32 data_size = bucket->size(); |
| 6460 | GLsizei imageSize = data_size; |
| 6461 | const void* data = bucket->GetData(0, data_size); |
| 6462 | if (!data) { |
| 6463 | return error::kInvalidArguments; |
| 6464 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 6465 | return DoCompressedTexImage2D( |
| 6466 | target, level, internal_format, width, height, border, |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 6467 | imageSize, data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 6468 | } |
| 6469 | |
| 6470 | error::Error GLES2DecoderImpl::HandleCompressedTexSubImage2DBucket( |
| 6471 | uint32 immediate_data_size, |
| 6472 | const gles2::CompressedTexSubImage2DBucket& c) { |
| 6473 | GLenum target = static_cast<GLenum>(c.target); |
| 6474 | GLint level = static_cast<GLint>(c.level); |
| 6475 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 6476 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 6477 | GLsizei width = static_cast<GLsizei>(c.width); |
| 6478 | GLsizei height = static_cast<GLsizei>(c.height); |
| 6479 | GLenum format = static_cast<GLenum>(c.format); |
| 6480 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 6481 | if (!bucket) { |
| 6482 | return error::kInvalidArguments; |
| 6483 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 6484 | uint32 data_size = bucket->size(); |
| 6485 | GLsizei imageSize = data_size; |
| 6486 | const void* data = bucket->GetData(0, data_size); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 6487 | if (!data) { |
| 6488 | return error::kInvalidArguments; |
| 6489 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6490 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 6491 | SetGLError( |
| 6492 | GL_INVALID_ENUM, "glCompressedTexSubImage2D: target GL_INVALID_ENUM"); |
| 6493 | return error::kNoError; |
| 6494 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6495 | if (!validators_->compressed_texture_format.IsValid(format)) { |
| 6496 | SetGLError(GL_INVALID_ENUM, |
| 6497 | "glCompressedTexSubImage2D: format GL_INVALID_ENUM"); |
| 6498 | return error::kNoError; |
| 6499 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 6500 | if (width < 0) { |
| 6501 | SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D: width < 0"); |
| 6502 | return error::kNoError; |
| 6503 | } |
| 6504 | if (height < 0) { |
| 6505 | SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D: height < 0"); |
| 6506 | return error::kNoError; |
| 6507 | } |
| 6508 | if (imageSize < 0) { |
| 6509 | SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D: imageSize < 0"); |
| 6510 | return error::kNoError; |
| 6511 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6512 | DoCompressedTexSubImage2D( |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 6513 | target, level, xoffset, yoffset, width, height, format, imageSize, data); |
| 6514 | return error::kNoError; |
| 6515 | } |
| 6516 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6517 | error::Error GLES2DecoderImpl::DoTexImage2D( |
| 6518 | GLenum target, |
| 6519 | GLint level, |
| 6520 | GLenum internal_format, |
| 6521 | GLsizei width, |
| 6522 | GLsizei height, |
| 6523 | GLint border, |
| 6524 | GLenum format, |
| 6525 | GLenum type, |
| 6526 | const void* pixels, |
| 6527 | uint32 pixels_size) { |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6528 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6529 | SetGLError(GL_INVALID_ENUM, "glTexImage2D: target GL_INVALID_ENUM"); |
| 6530 | return error::kNoError; |
| 6531 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6532 | if (!validators_->texture_format.IsValid(internal_format)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6533 | SetGLError(GL_INVALID_ENUM, |
| 6534 | "glTexImage2D: internal_format GL_INVALID_ENUM"); |
| 6535 | return error::kNoError; |
| 6536 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6537 | if (!validators_->texture_format.IsValid(format)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6538 | SetGLError(GL_INVALID_ENUM, "glTexImage2D: format GL_INVALID_ENUM"); |
| 6539 | return error::kNoError; |
| 6540 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6541 | if (!validators_->pixel_type.IsValid(type)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6542 | SetGLError(GL_INVALID_ENUM, "glTexImage2D: type GL_INVALID_ENUM"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6543 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6544 | } |
[email protected] | 7b92c41 | 2010-07-20 17:48:25 | [diff] [blame] | 6545 | if (format != internal_format) { |
| 6546 | SetGLError(GL_INVALID_OPERATION, "glTexImage2D: format != internalFormat"); |
| 6547 | return error::kNoError; |
| 6548 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 6549 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6550 | border != 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6551 | SetGLError(GL_INVALID_VALUE, "glTexImage2D: dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6552 | return error::kNoError; |
| 6553 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6554 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6555 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6556 | SetGLError(GL_INVALID_OPERATION, |
| 6557 | "glTexImage2D: unknown texture for target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6558 | return error::kNoError; |
| 6559 | } |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 6560 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 6561 | if (info->IsImmutable()) { |
| 6562 | SetGLError(GL_INVALID_OPERATION, |
| 6563 | "glTexImage2D: texture is immutable"); |
| 6564 | return error::kNoError; |
| 6565 | } |
| 6566 | |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 6567 | GLsizei tex_width = 0; |
| 6568 | GLsizei tex_height = 0; |
| 6569 | GLenum tex_type = 0; |
| 6570 | GLenum tex_format = 0; |
| 6571 | bool level_is_same = |
| 6572 | info->GetLevelSize(target, level, &tex_width, &tex_height) && |
| 6573 | info->GetLevelType(target, level, &tex_type, &tex_format) && |
| 6574 | width == tex_width && height == tex_height && |
| 6575 | type == tex_type && format == tex_format; |
| 6576 | |
| 6577 | if (level_is_same && !pixels) { |
[email protected] | 1bed622 | 2011-12-21 11:21:39 | [diff] [blame] | 6578 | // Just set the level info but mark the texture as uncleared. |
| 6579 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 6580 | info, |
[email protected] | 1bed622 | 2011-12-21 11:21:39 | [diff] [blame] | 6581 | target, level, internal_format, width, height, 1, border, format, type, |
| 6582 | false); |
[email protected] | ea72ed22 | 2011-08-17 18:58:43 | [diff] [blame] | 6583 | tex_image_2d_failed_ = false; |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 6584 | return error::kNoError; |
| 6585 | } |
| 6586 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6587 | if (info->IsAttachedToFramebuffer()) { |
| 6588 | state_dirty_ = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 6589 | // TODO(gman): If textures tracked which framebuffers they were attached to |
| 6590 | // we could just mark those framebuffers as not complete. |
| 6591 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6592 | } |
| 6593 | |
[email protected] | 1bed622 | 2011-12-21 11:21:39 | [diff] [blame] | 6594 | if (!teximage2d_faster_than_texsubimage2d_ && level_is_same && pixels) { |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 6595 | glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels); |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 6596 | texture_manager()->SetLevelCleared(info, target, level); |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 6597 | tex_image_2d_failed_ = false; |
| 6598 | return error::kNoError; |
[email protected] | 7488d96 | 2010-07-16 02:41:58 | [diff] [blame] | 6599 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6600 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6601 | CopyRealGLErrorsToWrapper(); |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6602 | WrappedTexImage2D( |
| 6603 | target, level, internal_format, width, height, border, format, type, |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6604 | pixels); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 6605 | GLenum error = PeekGLError(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6606 | if (error == GL_NO_ERROR) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6607 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 6608 | info, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6609 | target, level, internal_format, width, height, 1, border, format, type, |
| 6610 | pixels != NULL); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 6611 | tex_image_2d_failed_ = false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6612 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6613 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6614 | } |
| 6615 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6616 | error::Error GLES2DecoderImpl::HandleTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6617 | uint32 immediate_data_size, const gles2::TexImage2D& c) { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 6618 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 6619 | tex_image_2d_failed_ = true; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6620 | GLenum target = static_cast<GLenum>(c.target); |
| 6621 | GLint level = static_cast<GLint>(c.level); |
| 6622 | GLint internal_format = static_cast<GLint>(c.internalformat); |
| 6623 | GLsizei width = static_cast<GLsizei>(c.width); |
| 6624 | GLsizei height = static_cast<GLsizei>(c.height); |
| 6625 | GLint border = static_cast<GLint>(c.border); |
| 6626 | GLenum format = static_cast<GLenum>(c.format); |
| 6627 | GLenum type = static_cast<GLenum>(c.type); |
| 6628 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 6629 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 6630 | uint32 pixels_size; |
| 6631 | if (!GLES2Util::ComputeImageDataSize( |
| 6632 | width, height, format, type, unpack_alignment_, &pixels_size)) { |
| 6633 | return error::kOutOfBounds; |
| 6634 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6635 | const void* pixels = NULL; |
| 6636 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 6637 | pixels = GetSharedMemoryAs<const void*>( |
| 6638 | pixels_shm_id, pixels_shm_offset, pixels_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6639 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6640 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6641 | } |
| 6642 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6643 | return DoTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6644 | target, level, internal_format, width, height, border, format, type, |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6645 | pixels, pixels_size); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6646 | } |
| 6647 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6648 | error::Error GLES2DecoderImpl::HandleTexImage2DImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6649 | uint32 immediate_data_size, const gles2::TexImage2DImmediate& c) { |
| 6650 | GLenum target = static_cast<GLenum>(c.target); |
| 6651 | GLint level = static_cast<GLint>(c.level); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6652 | GLint internal_format = static_cast<GLint>(c.internalformat); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6653 | GLsizei width = static_cast<GLsizei>(c.width); |
| 6654 | GLsizei height = static_cast<GLsizei>(c.height); |
| 6655 | GLint border = static_cast<GLint>(c.border); |
| 6656 | GLenum format = static_cast<GLenum>(c.format); |
| 6657 | GLenum type = static_cast<GLenum>(c.type); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 6658 | uint32 size; |
| 6659 | if (!GLES2Util::ComputeImageDataSize( |
| 6660 | width, height, format, type, unpack_alignment_, &size)) { |
| 6661 | return error::kOutOfBounds; |
| 6662 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6663 | const void* pixels = GetImmediateDataAs<const void*>( |
| 6664 | c, size, immediate_data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6665 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6666 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6667 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6668 | DoTexImage2D( |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6669 | target, level, internal_format, width, height, border, format, type, |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6670 | pixels, size); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6671 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6672 | } |
| 6673 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6674 | void GLES2DecoderImpl::DoCompressedTexSubImage2D( |
| 6675 | GLenum target, |
| 6676 | GLint level, |
| 6677 | GLint xoffset, |
| 6678 | GLint yoffset, |
| 6679 | GLsizei width, |
| 6680 | GLsizei height, |
| 6681 | GLenum format, |
| 6682 | GLsizei image_size, |
| 6683 | const void * data) { |
| 6684 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 6685 | if (!info) { |
| 6686 | SetGLError(GL_INVALID_OPERATION, |
| 6687 | "glCompressedTexSubImage2D: unknown texture for target"); |
| 6688 | return; |
| 6689 | } |
| 6690 | GLenum type = 0; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 6691 | GLenum internal_format = 0; |
| 6692 | if (!info->GetLevelType(target, level, &type, &internal_format)) { |
| 6693 | SetGLError( |
| 6694 | GL_INVALID_OPERATION, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6695 | "glCompressedTexSubImage2D: level does not exist."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 6696 | return; |
| 6697 | } |
| 6698 | if (internal_format != format) { |
| 6699 | SetGLError( |
| 6700 | GL_INVALID_OPERATION, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6701 | "glCompressedTexSubImage2D: format does not match internal format."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 6702 | return; |
| 6703 | } |
| 6704 | if (!info->ValidForTexture( |
| 6705 | target, level, xoffset, yoffset, width, height, format, type)) { |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6706 | SetGLError(GL_INVALID_VALUE, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6707 | "glCompressedTexSubImage2D: bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6708 | return; |
| 6709 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6710 | // Note: There is no need to deal with texture cleared tracking here |
| 6711 | // because the validation above means you can only get here if the level |
| 6712 | // is already a matching compressed format and in that case |
| 6713 | // CompressedTexImage2D already cleared the texture. |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6714 | glCompressedTexSubImage2D( |
| 6715 | target, level, xoffset, yoffset, width, height, format, image_size, data); |
| 6716 | } |
| 6717 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6718 | static void Clip( |
| 6719 | GLint start, GLint range, GLint sourceRange, |
| 6720 | GLint* out_start, GLint* out_range) { |
| 6721 | DCHECK(out_start); |
| 6722 | DCHECK(out_range); |
| 6723 | if (start < 0) { |
| 6724 | range += start; |
| 6725 | start = 0; |
| 6726 | } |
| 6727 | GLint end = start + range; |
| 6728 | if (end > sourceRange) { |
| 6729 | range -= end - sourceRange; |
| 6730 | } |
| 6731 | *out_start = start; |
| 6732 | *out_range = range; |
| 6733 | } |
| 6734 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6735 | void GLES2DecoderImpl::DoCopyTexImage2D( |
| 6736 | GLenum target, |
| 6737 | GLint level, |
| 6738 | GLenum internal_format, |
| 6739 | GLint x, |
| 6740 | GLint y, |
| 6741 | GLsizei width, |
| 6742 | GLsizei height, |
| 6743 | GLint border) { |
| 6744 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 6745 | if (!info) { |
| 6746 | SetGLError(GL_INVALID_OPERATION, |
| 6747 | "glCopyTexImage2D: unknown texture for target"); |
| 6748 | return; |
| 6749 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 6750 | if (info->IsImmutable()) { |
| 6751 | SetGLError(GL_INVALID_OPERATION, |
| 6752 | "glCopyTexImage2D: texture is immutable"); |
| 6753 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 6754 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 6755 | border != 0) { |
| 6756 | SetGLError(GL_INVALID_VALUE, "glCopyTexImage2D: dimensions out of range"); |
| 6757 | return; |
| 6758 | } |
| 6759 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 6760 | // Check we have compatible formats. |
| 6761 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 6762 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 6763 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
| 6764 | |
| 6765 | if ((channels_needed & channels_exist) != channels_needed) { |
| 6766 | SetGLError(GL_INVALID_OPERATION, "glCopyTexImage2D: incompatible format"); |
| 6767 | return; |
| 6768 | } |
| 6769 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6770 | if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { |
| 6771 | return; |
| 6772 | } |
| 6773 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6774 | CopyRealGLErrorsToWrapper(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 6775 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6776 | gfx::Size size = GetBoundReadFrameBufferSize(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 6777 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6778 | if (info->IsAttachedToFramebuffer()) { |
| 6779 | state_dirty_ = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 6780 | // TODO(gman): If textures tracked which framebuffers they were attached to |
| 6781 | // we could just mark those framebuffers as not complete. |
| 6782 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6783 | } |
| 6784 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 6785 | // Clip to size to source dimensions |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6786 | GLint copyX = 0; |
| 6787 | GLint copyY = 0; |
| 6788 | GLint copyWidth = 0; |
| 6789 | GLint copyHeight = 0; |
| 6790 | Clip(x, width, size.width(), ©X, ©Width); |
| 6791 | Clip(y, height, size.height(), ©Y, ©Height); |
| 6792 | |
| 6793 | if (copyX != x || |
| 6794 | copyY != y || |
| 6795 | copyWidth != width || |
| 6796 | copyHeight != height) { |
| 6797 | // some part was clipped so clear the texture. |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6798 | if (!ClearLevel( |
| 6799 | info->service_id(), info->target(), |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6800 | target, level, internal_format, GL_UNSIGNED_BYTE, width, height, |
| 6801 | info->IsImmutable())) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6802 | SetGLError(GL_OUT_OF_MEMORY, "glCopyTexImage2D: dimensions too big"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6803 | return; |
| 6804 | } |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6805 | if (copyHeight > 0 && copyWidth > 0) { |
| 6806 | GLint dx = copyX - x; |
| 6807 | GLint dy = copyY - y; |
| 6808 | GLint destX = dx; |
| 6809 | GLint destY = dy; |
| 6810 | glCopyTexSubImage2D(target, level, |
| 6811 | destX, destY, copyX, copyY, |
| 6812 | copyWidth, copyHeight); |
| 6813 | } |
| 6814 | } else { |
| 6815 | glCopyTexImage2D(target, level, internal_format, |
| 6816 | copyX, copyY, copyWidth, copyHeight, border); |
| 6817 | } |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 6818 | GLenum error = PeekGLError(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6819 | if (error == GL_NO_ERROR) { |
| 6820 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 6821 | info, target, level, internal_format, width, height, 1, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6822 | border, internal_format, GL_UNSIGNED_BYTE, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6823 | } |
| 6824 | } |
| 6825 | |
| 6826 | void GLES2DecoderImpl::DoCopyTexSubImage2D( |
| 6827 | GLenum target, |
| 6828 | GLint level, |
| 6829 | GLint xoffset, |
| 6830 | GLint yoffset, |
| 6831 | GLint x, |
| 6832 | GLint y, |
| 6833 | GLsizei width, |
| 6834 | GLsizei height) { |
| 6835 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 6836 | if (!info) { |
| 6837 | SetGLError(GL_INVALID_OPERATION, |
| 6838 | "glCopyTexSubImage2D: unknown texture for target"); |
| 6839 | return; |
| 6840 | } |
| 6841 | GLenum type = 0; |
| 6842 | GLenum format = 0; |
| 6843 | if (!info->GetLevelType(target, level, &type, &format) || |
| 6844 | !info->ValidForTexture( |
| 6845 | target, level, xoffset, yoffset, width, height, format, type)) { |
| 6846 | SetGLError(GL_INVALID_VALUE, |
| 6847 | "glCopyTexSubImage2D: bad dimensions."); |
| 6848 | return; |
| 6849 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 6850 | |
| 6851 | // Check we have compatible formats. |
| 6852 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 6853 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 6854 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); |
| 6855 | |
| 6856 | if ((channels_needed & channels_exist) != channels_needed) { |
| 6857 | SetGLError( |
| 6858 | GL_INVALID_OPERATION, "glCopyTexSubImage2D: incompatible format"); |
| 6859 | return; |
| 6860 | } |
| 6861 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6862 | if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { |
| 6863 | return; |
| 6864 | } |
| 6865 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 6866 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6867 | gfx::Size size = GetBoundReadFrameBufferSize(); |
| 6868 | GLint copyX = 0; |
| 6869 | GLint copyY = 0; |
| 6870 | GLint copyWidth = 0; |
| 6871 | GLint copyHeight = 0; |
| 6872 | Clip(x, width, size.width(), ©X, ©Width); |
| 6873 | Clip(y, height, size.height(), ©Y, ©Height); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6874 | |
| 6875 | if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { |
| 6876 | SetGLError(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D: dimensions too big"); |
| 6877 | return; |
| 6878 | } |
| 6879 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6880 | if (copyX != x || |
| 6881 | copyY != y || |
| 6882 | copyWidth != width || |
| 6883 | copyHeight != height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6884 | // some part was clipped so clear the sub rect. |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6885 | uint32 pixels_size = 0; |
| 6886 | if (!GLES2Util::ComputeImageDataSize( |
| 6887 | width, height, format, type, unpack_alignment_, &pixels_size)) { |
| 6888 | SetGLError(GL_INVALID_VALUE, "glCopyTexSubImage2D: dimensions too large"); |
| 6889 | return; |
| 6890 | } |
| 6891 | scoped_array<char> zero(new char[pixels_size]); |
| 6892 | memset(zero.get(), 0, pixels_size); |
| 6893 | glTexSubImage2D( |
| 6894 | target, level, xoffset, yoffset, width, height, |
| 6895 | format, type, zero.get()); |
| 6896 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6897 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 6898 | if (copyHeight > 0 && copyWidth > 0) { |
| 6899 | GLint dx = copyX - x; |
| 6900 | GLint dy = copyY - y; |
| 6901 | GLint destX = xoffset + dx; |
| 6902 | GLint destY = yoffset + dy; |
| 6903 | glCopyTexSubImage2D(target, level, |
| 6904 | destX, destY, copyX, copyY, |
| 6905 | copyWidth, copyHeight); |
| 6906 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6907 | } |
| 6908 | |
| 6909 | void GLES2DecoderImpl::DoTexSubImage2D( |
| 6910 | GLenum target, |
| 6911 | GLint level, |
| 6912 | GLint xoffset, |
| 6913 | GLint yoffset, |
| 6914 | GLsizei width, |
| 6915 | GLsizei height, |
| 6916 | GLenum format, |
| 6917 | GLenum type, |
| 6918 | const void * data) { |
| 6919 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 6920 | if (!info) { |
| 6921 | SetGLError(GL_INVALID_OPERATION, |
| 6922 | "glTexSubImage2D: unknown texture for target"); |
| 6923 | return; |
| 6924 | } |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 6925 | GLenum current_type = 0; |
| 6926 | GLenum internal_format = 0; |
| 6927 | if (!info->GetLevelType(target, level, ¤t_type, &internal_format)) { |
| 6928 | SetGLError( |
| 6929 | GL_INVALID_OPERATION, |
| 6930 | "glTexSubImage2D: level does not exist."); |
| 6931 | return; |
| 6932 | } |
| 6933 | if (format != internal_format) { |
| 6934 | SetGLError(GL_INVALID_OPERATION, |
| 6935 | "glTexSubImage2D: format does not match internal format."); |
| 6936 | return; |
| 6937 | } |
| 6938 | if (type != current_type) { |
| 6939 | SetGLError(GL_INVALID_OPERATION, |
| 6940 | "glTexSubImage2D: type does not match type of texture."); |
| 6941 | return; |
| 6942 | } |
| 6943 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6944 | if (!info->ValidForTexture( |
| 6945 | target, level, xoffset, yoffset, width, height, format, type)) { |
| 6946 | SetGLError(GL_INVALID_VALUE, |
| 6947 | "glTexSubImage2D: bad dimensions."); |
| 6948 | return; |
| 6949 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6950 | |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6951 | GLsizei tex_width = 0; |
| 6952 | GLsizei tex_height = 0; |
| 6953 | bool ok = info->GetLevelSize(target, level, &tex_width, &tex_height); |
| 6954 | DCHECK(ok); |
| 6955 | if (xoffset != 0 || yoffset != 0 || |
| 6956 | width != tex_width || height != tex_height) { |
| 6957 | if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { |
| 6958 | SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D: dimensions too big"); |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6959 | return; |
| 6960 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6961 | glTexSubImage2D( |
| 6962 | target, level, xoffset, yoffset, width, height, format, type, data); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6963 | return; |
| 6964 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6965 | |
| 6966 | if (teximage2d_faster_than_texsubimage2d_ && !info->IsImmutable()) { |
| 6967 | // NOTE: In OpenGL ES 2.0 border is always zero and format is always the |
| 6968 | // same as internal_foramt. If that changes we'll need to look them up. |
| 6969 | WrappedTexImage2D( |
| 6970 | target, level, format, width, height, 0, format, type, data); |
| 6971 | } else { |
| 6972 | glTexSubImage2D( |
| 6973 | target, level, xoffset, yoffset, width, height, format, type, data); |
| 6974 | } |
| 6975 | texture_manager()->SetLevelCleared(info, target, level); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 6976 | } |
| 6977 | |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 6978 | error::Error GLES2DecoderImpl::HandleTexSubImage2D( |
| 6979 | uint32 immediate_data_size, const gles2::TexSubImage2D& c) { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 6980 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 6981 | GLboolean internal = static_cast<GLboolean>(c.internal); |
| 6982 | if (internal == GL_TRUE && tex_image_2d_failed_) |
| 6983 | return error::kNoError; |
| 6984 | |
| 6985 | GLenum target = static_cast<GLenum>(c.target); |
| 6986 | GLint level = static_cast<GLint>(c.level); |
| 6987 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 6988 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 6989 | GLsizei width = static_cast<GLsizei>(c.width); |
| 6990 | GLsizei height = static_cast<GLsizei>(c.height); |
| 6991 | GLenum format = static_cast<GLenum>(c.format); |
| 6992 | GLenum type = static_cast<GLenum>(c.type); |
| 6993 | uint32 data_size; |
| 6994 | if (!GLES2Util::ComputeImageDataSize( |
| 6995 | width, height, format, type, unpack_alignment_, &data_size)) { |
| 6996 | return error::kOutOfBounds; |
| 6997 | } |
| 6998 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 6999 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
| 7000 | if (!validators_->texture_target.IsValid(target)) { |
| 7001 | SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: target GL_INVALID_ENUM"); |
| 7002 | return error::kNoError; |
| 7003 | } |
| 7004 | if (width < 0) { |
| 7005 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: width < 0"); |
| 7006 | return error::kNoError; |
| 7007 | } |
| 7008 | if (height < 0) { |
| 7009 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: height < 0"); |
| 7010 | return error::kNoError; |
| 7011 | } |
| 7012 | if (!validators_->texture_format.IsValid(format)) { |
| 7013 | SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: format GL_INVALID_ENUM"); |
| 7014 | return error::kNoError; |
| 7015 | } |
| 7016 | if (!validators_->pixel_type.IsValid(type)) { |
| 7017 | SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: type GL_INVALID_ENUM"); |
| 7018 | return error::kNoError; |
| 7019 | } |
| 7020 | if (pixels == NULL) { |
| 7021 | return error::kOutOfBounds; |
| 7022 | } |
| 7023 | DoTexSubImage2D( |
| 7024 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
| 7025 | return error::kNoError; |
| 7026 | } |
| 7027 | |
| 7028 | error::Error GLES2DecoderImpl::HandleTexSubImage2DImmediate( |
| 7029 | uint32 immediate_data_size, const gles2::TexSubImage2DImmediate& c) { |
| 7030 | GLboolean internal = static_cast<GLboolean>(c.internal); |
| 7031 | if (internal == GL_TRUE && tex_image_2d_failed_) |
| 7032 | return error::kNoError; |
| 7033 | |
| 7034 | GLenum target = static_cast<GLenum>(c.target); |
| 7035 | GLint level = static_cast<GLint>(c.level); |
| 7036 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 7037 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 7038 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7039 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7040 | GLenum format = static_cast<GLenum>(c.format); |
| 7041 | GLenum type = static_cast<GLenum>(c.type); |
| 7042 | uint32 data_size; |
| 7043 | if (!GLES2Util::ComputeImageDataSize( |
| 7044 | width, height, format, type, unpack_alignment_, &data_size)) { |
| 7045 | return error::kOutOfBounds; |
| 7046 | } |
| 7047 | const void* pixels = GetImmediateDataAs<const void*>( |
| 7048 | c, data_size, immediate_data_size); |
| 7049 | if (!validators_->texture_target.IsValid(target)) { |
| 7050 | SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: target GL_INVALID_ENUM"); |
| 7051 | return error::kNoError; |
| 7052 | } |
| 7053 | if (width < 0) { |
| 7054 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: width < 0"); |
| 7055 | return error::kNoError; |
| 7056 | } |
| 7057 | if (height < 0) { |
| 7058 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: height < 0"); |
| 7059 | return error::kNoError; |
| 7060 | } |
| 7061 | if (!validators_->texture_format.IsValid(format)) { |
| 7062 | SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: format GL_INVALID_ENUM"); |
| 7063 | return error::kNoError; |
| 7064 | } |
| 7065 | if (!validators_->pixel_type.IsValid(type)) { |
| 7066 | SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: type GL_INVALID_ENUM"); |
| 7067 | return error::kNoError; |
| 7068 | } |
| 7069 | if (pixels == NULL) { |
| 7070 | return error::kOutOfBounds; |
| 7071 | } |
| 7072 | DoTexSubImage2D( |
| 7073 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
| 7074 | return error::kNoError; |
| 7075 | } |
| 7076 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7077 | error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7078 | uint32 immediate_data_size, const gles2::GetVertexAttribPointerv& c) { |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7079 | GLuint index = static_cast<GLuint>(c.index); |
| 7080 | GLenum pname = static_cast<GLenum>(c.pname); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7081 | typedef gles2::GetVertexAttribPointerv::Result Result; |
| 7082 | Result* result = GetSharedMemoryAs<Result*>( |
| 7083 | c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1)); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7084 | if (!result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7085 | return error::kOutOfBounds; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7086 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 7087 | // Check that the client initialized the result. |
| 7088 | if (result->size != 0) { |
| 7089 | return error::kInvalidArguments; |
| 7090 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7091 | if (!validators_->vertex_pointer.IsValid(pname)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7092 | SetGLError(GL_INVALID_ENUM, |
| 7093 | "glGetVertexAttribPointerv: pname GL_INVALID_ENUM"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7094 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7095 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 7096 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7097 | SetGLError(GL_INVALID_VALUE, |
| 7098 | "glGetVertexAttribPointerv: index out of range."); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7099 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7100 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7101 | result->SetNumResults(1); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 7102 | *result->GetData() = |
[email protected] | 3757a37 | 2012-01-19 05:20:44 | [diff] [blame] | 7103 | vertex_attrib_manager_->GetVertexAttribInfo(index)->offset(); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7104 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7105 | } |
| 7106 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7107 | bool GLES2DecoderImpl::GetUniformSetup( |
| 7108 | GLuint program, GLint location, |
| 7109 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7110 | error::Error* error, GLuint* service_id, void** result_pointer, |
| 7111 | GLenum* result_type) { |
| 7112 | DCHECK(error); |
| 7113 | DCHECK(service_id); |
| 7114 | DCHECK(result_pointer); |
| 7115 | DCHECK(result_type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7116 | *error = error::kNoError; |
| 7117 | // Make sure we have enough room for the result on failure. |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7118 | SizedResult<GLint>* result; |
| 7119 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 7120 | shm_id, shm_offset, SizedResult<GLint>::ComputeSize(0)); |
| 7121 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7122 | *error = error::kOutOfBounds; |
| 7123 | return false; |
| 7124 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7125 | *result_pointer = result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7126 | // Set the result size to 0 so the client does not have to check for success. |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7127 | result->SetNumResults(0); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7128 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 7129 | program, "glGetUniform"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7130 | if (!info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7131 | return false; |
| 7132 | } |
| 7133 | if (!info->IsValid()) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7134 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7135 | SetGLError(GL_INVALID_OPERATION, "glGetUniform: program not linked"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7136 | return false; |
| 7137 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7138 | *service_id = info->service_id(); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 7139 | GLint array_index = -1; |
| 7140 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
| 7141 | info->GetUniformInfoByLocation(location, &array_index); |
| 7142 | if (!uniform_info) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7143 | // No such location. |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7144 | SetGLError(GL_INVALID_OPERATION, "glGetUniform: unknown location"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7145 | return false; |
| 7146 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 7147 | GLenum type = uniform_info->type; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 7148 | GLsizei size = GLES2Util::GetGLDataTypeSizeForUniforms(type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7149 | if (size == 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7150 | SetGLError(GL_INVALID_OPERATION, "glGetUniform: unknown type"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7151 | return false; |
| 7152 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7153 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 7154 | shm_id, shm_offset, SizedResult<GLint>::ComputeSizeFromBytes(size)); |
| 7155 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7156 | *error = error::kOutOfBounds; |
| 7157 | return false; |
| 7158 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7159 | result->size = size; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7160 | *result_type = type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7161 | return true; |
| 7162 | } |
| 7163 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7164 | error::Error GLES2DecoderImpl::HandleGetUniformiv( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7165 | uint32 immediate_data_size, const gles2::GetUniformiv& c) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7166 | GLuint program = c.program; |
[email protected] | 5d4c6b2 | 2012-02-07 08:22:28 | [diff] [blame] | 7167 | GLint location = program_manager()->UnswizzleLocation(c.location); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7168 | GLuint service_id; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7169 | GLenum result_type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7170 | Error error; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7171 | void* result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7172 | if (GetUniformSetup( |
| 7173 | program, location, c.params_shm_id, c.params_shm_offset, |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7174 | &error, &service_id, &result, &result_type)) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7175 | glGetUniformiv( |
| 7176 | service_id, location, |
| 7177 | static_cast<gles2::GetUniformiv::Result*>(result)->GetData()); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7178 | } |
| 7179 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7180 | } |
| 7181 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7182 | error::Error GLES2DecoderImpl::HandleGetUniformfv( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7183 | uint32 immediate_data_size, const gles2::GetUniformfv& c) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7184 | GLuint program = c.program; |
[email protected] | 5d4c6b2 | 2012-02-07 08:22:28 | [diff] [blame] | 7185 | GLint location = program_manager()->UnswizzleLocation(c.location); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7186 | GLuint service_id; |
| 7187 | Error error; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7188 | typedef gles2::GetUniformfv::Result Result; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7189 | Result* result; |
| 7190 | GLenum result_type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7191 | if (GetUniformSetup( |
| 7192 | program, location, c.params_shm_id, c.params_shm_offset, |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7193 | &error, &service_id, reinterpret_cast<void**>(&result), &result_type)) { |
| 7194 | if (result_type == GL_BOOL || result_type == GL_BOOL_VEC2 || |
| 7195 | result_type == GL_BOOL_VEC3 || result_type == GL_BOOL_VEC4) { |
| 7196 | GLsizei num_values = result->GetNumResults(); |
| 7197 | scoped_array<GLint> temp(new GLint[num_values]); |
| 7198 | glGetUniformiv(service_id, location, temp.get()); |
| 7199 | GLfloat* dst = result->GetData(); |
| 7200 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
| 7201 | dst[ii] = (temp[ii] != 0); |
| 7202 | } |
| 7203 | } else { |
| 7204 | glGetUniformfv(service_id, location, result->GetData()); |
| 7205 | } |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7206 | } |
| 7207 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7208 | } |
| 7209 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7210 | error::Error GLES2DecoderImpl::HandleGetShaderPrecisionFormat( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7211 | uint32 immediate_data_size, const gles2::GetShaderPrecisionFormat& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7212 | GLenum shader_type = static_cast<GLenum>(c.shadertype); |
| 7213 | GLenum precision_type = static_cast<GLenum>(c.precisiontype); |
| 7214 | typedef gles2::GetShaderPrecisionFormat::Result Result; |
| 7215 | Result* result = GetSharedMemoryAs<Result*>( |
| 7216 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7217 | if (!result) { |
| 7218 | return error::kOutOfBounds; |
| 7219 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 7220 | // Check that the client initialized the result. |
| 7221 | if (result->success != 0) { |
| 7222 | return error::kInvalidArguments; |
| 7223 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7224 | if (!validators_->shader_type.IsValid(shader_type)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7225 | SetGLError(GL_INVALID_ENUM, |
| 7226 | "glGetShaderPrecisionFormat: shader_type GL_INVALID_ENUM"); |
| 7227 | return error::kNoError; |
| 7228 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7229 | if (!validators_->shader_precision.IsValid(precision_type)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7230 | SetGLError(GL_INVALID_ENUM, |
| 7231 | "glGetShaderPrecisionFormat: precision_type GL_INVALID_ENUM"); |
| 7232 | return error::kNoError; |
| 7233 | } |
| 7234 | |
| 7235 | result->success = 1; // true |
| 7236 | switch (precision_type) { |
| 7237 | case GL_LOW_INT: |
| 7238 | case GL_MEDIUM_INT: |
| 7239 | case GL_HIGH_INT: |
| 7240 | result->min_range = -31; |
| 7241 | result->max_range = 31; |
| 7242 | result->precision = 0; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 7243 | break; |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7244 | case GL_LOW_FLOAT: |
| 7245 | case GL_MEDIUM_FLOAT: |
| 7246 | case GL_HIGH_FLOAT: |
| 7247 | result->min_range = -62; |
| 7248 | result->max_range = 62; |
| 7249 | result->precision = -16; |
| 7250 | break; |
| 7251 | default: |
| 7252 | NOTREACHED(); |
| 7253 | break; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7254 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7255 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7256 | } |
| 7257 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7258 | error::Error GLES2DecoderImpl::HandleGetAttachedShaders( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7259 | uint32 immediate_data_size, const gles2::GetAttachedShaders& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7260 | uint32 result_size = c.result_size; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7261 | GLuint program = static_cast<GLuint>(c.program); |
| 7262 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 7263 | program, "glGetAttachedShaders"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7264 | if (!info) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7265 | return error::kNoError; |
| 7266 | } |
| 7267 | typedef gles2::GetAttachedShaders::Result Result; |
| 7268 | uint32 max_count = Result::ComputeMaxResults(result_size); |
| 7269 | Result* result = GetSharedMemoryAs<Result*>( |
| 7270 | c.result_shm_id, c.result_shm_offset, Result::ComputeSize(max_count)); |
| 7271 | if (!result) { |
| 7272 | return error::kOutOfBounds; |
| 7273 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 7274 | // Check that the client initialized the result. |
| 7275 | if (result->size != 0) { |
| 7276 | return error::kInvalidArguments; |
| 7277 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7278 | GLsizei count = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7279 | glGetAttachedShaders( |
| 7280 | info->service_id(), max_count, &count, result->GetData()); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7281 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7282 | if (!shader_manager()->GetClientId(result->GetData()[ii], |
| 7283 | &result->GetData()[ii])) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7284 | NOTREACHED(); |
| 7285 | return error::kGenericError; |
| 7286 | } |
| 7287 | } |
| 7288 | result->SetNumResults(count); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7289 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7290 | } |
| 7291 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7292 | error::Error GLES2DecoderImpl::HandleGetActiveUniform( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7293 | uint32 immediate_data_size, const gles2::GetActiveUniform& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7294 | GLuint program = c.program; |
| 7295 | GLuint index = c.index; |
| 7296 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7297 | typedef gles2::GetActiveUniform::Result Result; |
| 7298 | Result* result = GetSharedMemoryAs<Result*>( |
| 7299 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7300 | if (!result) { |
| 7301 | return error::kOutOfBounds; |
| 7302 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 7303 | // Check that the client initialized the result. |
| 7304 | if (result->success != 0) { |
| 7305 | return error::kInvalidArguments; |
| 7306 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7307 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 7308 | program, "glGetActiveUniform"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7309 | if (!info) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7310 | return error::kNoError; |
| 7311 | } |
| 7312 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
| 7313 | info->GetUniformInfo(index); |
| 7314 | if (!uniform_info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7315 | SetGLError(GL_INVALID_VALUE, "glGetActiveUniform: index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7316 | return error::kNoError; |
| 7317 | } |
| 7318 | result->success = 1; // true. |
| 7319 | result->size = uniform_info->size; |
| 7320 | result->type = uniform_info->type; |
| 7321 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 7322 | bucket->SetFromString(uniform_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7323 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7324 | } |
| 7325 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7326 | error::Error GLES2DecoderImpl::HandleGetActiveAttrib( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7327 | uint32 immediate_data_size, const gles2::GetActiveAttrib& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7328 | GLuint program = c.program; |
| 7329 | GLuint index = c.index; |
| 7330 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7331 | typedef gles2::GetActiveAttrib::Result Result; |
| 7332 | Result* result = GetSharedMemoryAs<Result*>( |
| 7333 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7334 | if (!result) { |
| 7335 | return error::kOutOfBounds; |
| 7336 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 7337 | // Check that the client initialized the result. |
| 7338 | if (result->success != 0) { |
| 7339 | return error::kInvalidArguments; |
| 7340 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7341 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 7342 | program, "glGetActiveAttrib"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7343 | if (!info) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7344 | return error::kNoError; |
| 7345 | } |
| 7346 | const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
| 7347 | info->GetAttribInfo(index); |
| 7348 | if (!attrib_info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7349 | SetGLError(GL_INVALID_VALUE, "glGetActiveAttrib: index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7350 | return error::kNoError; |
| 7351 | } |
| 7352 | result->success = 1; // true. |
| 7353 | result->size = attrib_info->size; |
| 7354 | result->type = attrib_info->type; |
| 7355 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 7356 | bucket->SetFromString(attrib_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7357 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7358 | } |
| 7359 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 7360 | error::Error GLES2DecoderImpl::HandleShaderBinary( |
| 7361 | uint32 immediate_data_size, const gles2::ShaderBinary& c) { |
| 7362 | #if 1 // No binary shader support. |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7363 | SetGLError(GL_INVALID_OPERATION, "glShaderBinary: not supported"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 7364 | return error::kNoError; |
| 7365 | #else |
| 7366 | GLsizei n = static_cast<GLsizei>(c.n); |
| 7367 | if (n < 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7368 | SetGLError(GL_INVALID_VALUE, "glShaderBinary: n < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 7369 | return error::kNoError; |
| 7370 | } |
| 7371 | GLsizei length = static_cast<GLsizei>(c.length); |
| 7372 | if (length < 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7373 | SetGLError(GL_INVALID_VALUE, "glShaderBinary: length < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 7374 | return error::kNoError; |
| 7375 | } |
| 7376 | uint32 data_size; |
| 7377 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 7378 | return error::kOutOfBounds; |
| 7379 | } |
| 7380 | const GLuint* shaders = GetSharedMemoryAs<const GLuint*>( |
| 7381 | c.shaders_shm_id, c.shaders_shm_offset, data_size); |
| 7382 | GLenum binaryformat = static_cast<GLenum>(c.binaryformat); |
| 7383 | const void* binary = GetSharedMemoryAs<const void*>( |
| 7384 | c.binary_shm_id, c.binary_shm_offset, length); |
| 7385 | if (shaders == NULL || binary == NULL) { |
| 7386 | return error::kOutOfBounds; |
| 7387 | } |
| 7388 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 7389 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7390 | ShaderManager::ShaderInfo* info = GetShaderInfo(shaders[ii]); |
| 7391 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7392 | SetGLError(GL_INVALID_VALUE, "glShaderBinary: unknown shader"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 7393 | return error::kNoError; |
| 7394 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7395 | service_ids[ii] = info->service_id(); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 7396 | } |
| 7397 | // TODO(gman): call glShaderBinary |
| 7398 | return error::kNoError; |
| 7399 | #endif |
| 7400 | } |
| 7401 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 7402 | error::Error GLES2DecoderImpl::HandleSwapBuffers( |
| 7403 | uint32 immediate_data_size, const gles2::SwapBuffers& c) { |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 7404 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 7405 | int this_frame_number = frame_number_++; |
[email protected] | da15151 | 2011-11-11 23:27:38 | [diff] [blame] | 7406 | // TRACE_EVENT for gpu tests: |
[email protected] | 529c667 | 2012-01-04 02:18:26 | [diff] [blame] | 7407 | TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", |
| 7408 | "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 7409 | "width", (is_offscreen ? offscreen_size_.width() : |
| 7410 | surface_->GetSize().width())); |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 7411 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleSwapBuffers", |
| 7412 | "offscreen", is_offscreen, |
| 7413 | "frame", this_frame_number); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 7414 | // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 7415 | // the rendered frame to another frame buffer. |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 7416 | if (is_offscreen) { |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 7417 | if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
| 7418 | // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
| 7419 | // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
| 7420 | // fix this. |
| 7421 | if (needs_mac_nvidia_driver_workaround_) { |
| 7422 | offscreen_saved_frame_buffer_->Create(); |
| 7423 | glFinish(); |
| 7424 | } |
| 7425 | |
| 7426 | // Allocate the offscreen saved color texture. |
| 7427 | DCHECK(offscreen_saved_color_format_); |
| 7428 | offscreen_saved_color_texture_->AllocateStorage( |
| 7429 | offscreen_size_, offscreen_saved_color_format_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 7430 | UpdateBackbufferMemoryAccounting(); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 7431 | |
| 7432 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 7433 | offscreen_saved_color_texture_.get()); |
| 7434 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 7435 | GL_FRAMEBUFFER_COMPLETE) { |
| 7436 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 7437 | << "because offscreen saved FBO was incomplete."; |
| 7438 | return error::kLostContext; |
| 7439 | } |
| 7440 | |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 7441 | // Clear the offscreen color texture. |
| 7442 | // TODO(piman): Is this still necessary? |
| 7443 | { |
| 7444 | ScopedFrameBufferBinder binder(this, |
| 7445 | offscreen_saved_frame_buffer_->id()); |
| 7446 | glClearColor(0, 0, 0, 0); |
| 7447 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 7448 | glDisable(GL_SCISSOR_TEST); |
| 7449 | glClear(GL_COLOR_BUFFER_BIT); |
| 7450 | RestoreClearState(); |
| 7451 | } |
| 7452 | |
| 7453 | UpdateParentTextureInfo(); |
| 7454 | } |
| 7455 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 7456 | ScopedGLErrorSuppressor suppressor(this); |
| 7457 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 7458 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 7459 | // For multisampled buffers, resolve the frame buffer. |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 7460 | ScopedResolvedFrameBufferBinder binder(this, true, false); |
[email protected] | 89d6ed0 | 2011-04-20 00:23:23 | [diff] [blame] | 7461 | return error::kNoError; |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 7462 | } else { |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 7463 | if (surface_->IsOffscreen()) { |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 7464 | ScopedFrameBufferBinder binder(this, |
| 7465 | offscreen_target_frame_buffer_->id()); |
| 7466 | |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 7467 | if (offscreen_target_buffer_preserved_) { |
| 7468 | // Copy the target frame buffer to the saved offscreen texture. |
| 7469 | offscreen_saved_color_texture_->Copy( |
| 7470 | offscreen_saved_color_texture_->size(), |
| 7471 | offscreen_saved_color_format_); |
| 7472 | } else { |
| 7473 | // Flip the textures in the parent context via the texture manager. |
| 7474 | if (!!offscreen_saved_color_texture_info_.get()) |
| 7475 | offscreen_saved_color_texture_info_-> |
| 7476 | SetServiceId(offscreen_target_color_texture_->id()); |
| 7477 | |
| 7478 | offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); |
| 7479 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 7480 | offscreen_target_color_texture_.get()); |
| 7481 | } |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 7482 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 7483 | // Ensure the side effects of the copy are visible to the parent |
| 7484 | // context. There is no need to do this for ANGLE because it uses a |
| 7485 | // single D3D device for all contexts. |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 7486 | if (!IsAngle()) |
| 7487 | glFlush(); |
| 7488 | } |
[email protected] | 89d6ed0 | 2011-04-20 00:23:23 | [diff] [blame] | 7489 | return error::kNoError; |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 7490 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 7491 | } else { |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 7492 | TRACE_EVENT1("gpu", "GLContext::SwapBuffers", "frame", this_frame_number); |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 7493 | if (!surface_->SwapBuffers()) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 7494 | LOG(ERROR) << "Context lost because SwapBuffers failed."; |
[email protected] | 5259ead8 | 2010-09-10 18:02:02 | [diff] [blame] | 7495 | return error::kLostContext; |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 7496 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 7497 | } |
| 7498 | |
[email protected] | 89d6ed0 | 2011-04-20 00:23:23 | [diff] [blame] | 7499 | return error::kNoError; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 7500 | } |
| 7501 | |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 7502 | error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
| 7503 | uint32 immediate_data_size, const gles2::EnableFeatureCHROMIUM& c) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7504 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7505 | if (!bucket || bucket->size() == 0) { |
| 7506 | return error::kInvalidArguments; |
| 7507 | } |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 7508 | typedef gles2::EnableFeatureCHROMIUM::Result Result; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7509 | Result* result = GetSharedMemoryAs<Result*>( |
| 7510 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7511 | if (!result) { |
| 7512 | return error::kOutOfBounds; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 7513 | } |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7514 | // Check that the client initialized the result. |
| 7515 | if (*result != 0) { |
| 7516 | return error::kInvalidArguments; |
| 7517 | } |
| 7518 | std::string feature_str; |
| 7519 | if (!bucket->GetAsString(&feature_str)) { |
| 7520 | return error::kInvalidArguments; |
| 7521 | } |
| 7522 | |
| 7523 | // TODO(gman): make this some kind of table to function pointer thingy. |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 7524 | if (feature_str.compare("pepper3d_allow_buffers_on_multiple_targets") == 0) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7525 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 7526 | } else if (feature_str.compare("pepper3d_support_fixed_attribs") == 0) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7527 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
| 7528 | // TODO(gman): decide how to remove the need for this const_cast. |
| 7529 | // I could make validators_ non const but that seems bad as this is the only |
| 7530 | // place it is needed. I could make some special friend class of validators |
| 7531 | // just to allow this to set them. That seems silly. I could refactor this |
| 7532 | // code to use the extension mechanism or the initialization attributes to |
| 7533 | // turn this feature on. Given that the only real point of this is to make |
| 7534 | // the conformance tests pass and given that there is lots of real work that |
| 7535 | // needs to be done it seems like refactoring for one to one of those |
| 7536 | // methods is a very low priority. |
| 7537 | const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7538 | } else if (feature_str.compare("webgl_enable_glsl_webgl_validation") == 0) { |
| 7539 | force_webgl_glsl_validation_ = true; |
| 7540 | InitializeShaderTranslator(); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7541 | } else { |
| 7542 | return error::kNoError; |
| 7543 | } |
| 7544 | |
| 7545 | *result = 1; // true. |
| 7546 | return error::kNoError; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 7547 | } |
| 7548 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 7549 | error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( |
| 7550 | uint32 immediate_data_size, |
| 7551 | const gles2::GetRequestableExtensionsCHROMIUM& c) { |
| 7552 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7553 | FeatureInfo::Ref info(new FeatureInfo()); |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 7554 | info->Initialize(disallowed_features_, NULL); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 7555 | bucket->SetFromString(info->extensions().c_str()); |
| 7556 | return error::kNoError; |
| 7557 | } |
| 7558 | |
| 7559 | error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( |
| 7560 | uint32 immediate_data_size, const gles2::RequestExtensionCHROMIUM& c) { |
| 7561 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7562 | if (!bucket || bucket->size() == 0) { |
| 7563 | return error::kInvalidArguments; |
| 7564 | } |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 7565 | std::string feature_str; |
| 7566 | if (!bucket->GetAsString(&feature_str)) { |
| 7567 | return error::kInvalidArguments; |
| 7568 | } |
| 7569 | |
| 7570 | bool std_derivatives_enabled = |
| 7571 | feature_info_->feature_flags().oes_standard_derivatives; |
| 7572 | bool webglsl_enabled = |
| 7573 | feature_info_->feature_flags().chromium_webglsl; |
| 7574 | |
| 7575 | feature_info_->AddFeatures(feature_str.c_str()); |
| 7576 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7577 | bool initialization_required = false; |
| 7578 | if (force_webgl_glsl_validation_ && !derivatives_explicitly_enabled_) { |
| 7579 | size_t derivatives_offset = feature_str.find(kOESDerivativeExtension); |
| 7580 | if (std::string::npos != derivatives_offset) { |
| 7581 | derivatives_explicitly_enabled_ = true; |
| 7582 | initialization_required = true; |
| 7583 | } |
| 7584 | } |
| 7585 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 7586 | // If we just enabled a feature which affects the shader translator, |
| 7587 | // we may need to re-initialize it. |
| 7588 | if (std_derivatives_enabled != |
| 7589 | feature_info_->feature_flags().oes_standard_derivatives || |
| 7590 | webglsl_enabled != |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7591 | feature_info_->feature_flags().chromium_webglsl || |
| 7592 | initialization_required) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 7593 | InitializeShaderTranslator(); |
| 7594 | } |
| 7595 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 7596 | UpdateCapabilities(); |
| 7597 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 7598 | return error::kNoError; |
| 7599 | } |
| 7600 | |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 7601 | error::Error GLES2DecoderImpl::HandleGetMultipleIntegervCHROMIUM( |
| 7602 | uint32 immediate_data_size, const gles2::GetMultipleIntegervCHROMIUM& c) { |
| 7603 | GLuint count = c.count; |
| 7604 | uint32 pnames_size; |
| 7605 | if (!SafeMultiplyUint32(count, sizeof(GLenum), &pnames_size)) { |
| 7606 | return error::kOutOfBounds; |
| 7607 | } |
| 7608 | const GLenum* pnames = GetSharedMemoryAs<const GLenum*>( |
| 7609 | c.pnames_shm_id, c.pnames_shm_offset, pnames_size); |
| 7610 | if (pnames == NULL) { |
| 7611 | return error::kOutOfBounds; |
| 7612 | } |
| 7613 | |
| 7614 | // We have to copy them since we use them twice so the client |
| 7615 | // can't change them between the time we validate them and the time we use |
| 7616 | // them. |
| 7617 | scoped_array<GLenum> enums(new GLenum[count]); |
| 7618 | memcpy(enums.get(), pnames, pnames_size); |
| 7619 | |
| 7620 | // Count up the space needed for the result. |
| 7621 | uint32 num_results = 0; |
| 7622 | for (GLuint ii = 0; ii < count; ++ii) { |
| 7623 | uint32 num = util_.GLGetNumValuesReturned(enums[ii]); |
| 7624 | if (num == 0) { |
| 7625 | SetGLError(GL_INVALID_ENUM, |
| 7626 | "glGetMulitpleCHROMIUM: pname GL_INVALID_ENUM"); |
| 7627 | return error::kNoError; |
| 7628 | } |
| 7629 | // Num will never be more than 4. |
| 7630 | DCHECK_LE(num, 4u); |
| 7631 | if (!SafeAdd(num_results, num, &num_results)) { |
| 7632 | return error::kOutOfBounds; |
| 7633 | } |
| 7634 | } |
| 7635 | |
| 7636 | uint32 result_size = 0; |
| 7637 | if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) { |
| 7638 | return error::kOutOfBounds; |
| 7639 | } |
| 7640 | |
| 7641 | if (result_size != static_cast<uint32>(c.size)) { |
| 7642 | SetGLError(GL_INVALID_VALUE, |
| 7643 | "glGetMulitpleCHROMIUM: bad size GL_INVALID_VALUE"); |
| 7644 | return error::kNoError; |
| 7645 | } |
| 7646 | |
| 7647 | GLint* results = GetSharedMemoryAs<GLint*>( |
| 7648 | c.results_shm_id, c.results_shm_offset, result_size); |
| 7649 | if (results == NULL) { |
| 7650 | return error::kOutOfBounds; |
| 7651 | } |
| 7652 | |
| 7653 | // Check the results have been cleared in case the context was lost. |
| 7654 | for (uint32 ii = 0; ii < num_results; ++ii) { |
| 7655 | if (results[ii]) { |
| 7656 | return error::kInvalidArguments; |
| 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | // Get each result. |
| 7661 | GLint* start = results; |
| 7662 | for (GLuint ii = 0; ii < count; ++ii) { |
| 7663 | GLsizei num_written = 0; |
| 7664 | if (!GetHelper(enums[ii], results, &num_written)) { |
| 7665 | glGetIntegerv(enums[ii], results); |
| 7666 | } |
| 7667 | results += num_written; |
| 7668 | } |
| 7669 | |
| 7670 | // Just to verify. Should this be a DCHECK? |
| 7671 | if (static_cast<uint32>(results - start) != num_results) { |
| 7672 | return error::kOutOfBounds; |
| 7673 | } |
| 7674 | |
| 7675 | return error::kNoError; |
| 7676 | } |
| 7677 | |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 7678 | error::Error GLES2DecoderImpl::HandleGetProgramInfoCHROMIUM( |
| 7679 | uint32 immediate_data_size, const gles2::GetProgramInfoCHROMIUM& c) { |
| 7680 | GLuint program = static_cast<GLuint>(c.program); |
| 7681 | uint32 bucket_id = c.bucket_id; |
| 7682 | Bucket* bucket = CreateBucket(bucket_id); |
| 7683 | bucket->SetSize(sizeof(ProgramInfoHeader)); // in case we fail. |
| 7684 | ProgramManager::ProgramInfo* info = NULL; |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 7685 | info = GetProgramInfo(program); |
| 7686 | if (!info || !info->IsValid()) { |
| 7687 | return error::kNoError; |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 7688 | } |
[email protected] | 5d4c6b2 | 2012-02-07 08:22:28 | [diff] [blame] | 7689 | info->GetProgramInfo(program_manager(), bucket); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 7690 | return error::kNoError; |
| 7691 | } |
| 7692 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7693 | error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() { |
| 7694 | switch (reset_status_) { |
| 7695 | case GL_NO_ERROR: |
| 7696 | // TODO(kbr): improve the precision of the error code in this case. |
| 7697 | // Consider delegating to context for error code if MakeCurrent fails. |
| 7698 | return error::kUnknown; |
| 7699 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 7700 | return error::kGuilty; |
| 7701 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 7702 | return error::kInnocent; |
| 7703 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 7704 | return error::kUnknown; |
| 7705 | } |
| 7706 | |
| 7707 | NOTREACHED(); |
| 7708 | return error::kUnknown; |
| 7709 | } |
| 7710 | |
| 7711 | bool GLES2DecoderImpl::WasContextLost() { |
| 7712 | if (context_->WasAllocatedUsingARBRobustness() && has_arb_robustness_) { |
| 7713 | GLenum status = glGetGraphicsResetStatusARB(); |
| 7714 | if (status != GL_NO_ERROR) { |
| 7715 | // The graphics card was reset. Signal a lost context to the application. |
| 7716 | reset_status_ = status; |
| 7717 | LOG(ERROR) << (surface_->IsOffscreen() ? "Offscreen" : "Onscreen") |
| 7718 | << " context lost via ARB_robustness. Reset status = 0x" |
| 7719 | << std::hex << status << std::dec; |
| 7720 | return true; |
| 7721 | } |
| 7722 | } |
| 7723 | return false; |
| 7724 | } |
| 7725 | |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 7726 | error::Error GLES2DecoderImpl::HandleCreateStreamTextureCHROMIUM( |
| 7727 | uint32 immediate_data_size, |
| 7728 | const gles2::CreateStreamTextureCHROMIUM& c) { |
| 7729 | if (!feature_info_->feature_flags().chromium_stream_texture) { |
| 7730 | SetGLError(GL_INVALID_OPERATION, |
| 7731 | "glOpenStreamTextureCHROMIUM: " |
| 7732 | "not supported."); |
| 7733 | return error::kNoError; |
| 7734 | } |
| 7735 | |
| 7736 | uint32 client_id = c.client_id; |
| 7737 | typedef gles2::CreateStreamTextureCHROMIUM::Result Result; |
| 7738 | Result* result = GetSharedMemoryAs<Result*>( |
| 7739 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7740 | |
[email protected] | e508126 | 2012-01-05 23:09:03 | [diff] [blame] | 7741 | if (!result) |
| 7742 | return error::kOutOfBounds; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 7743 | *result = GL_ZERO; |
| 7744 | TextureManager::TextureInfo* info = |
| 7745 | texture_manager()->GetTextureInfo(client_id); |
| 7746 | if (!info) { |
| 7747 | SetGLError(GL_INVALID_VALUE, |
| 7748 | "glCreateStreamTextureCHROMIUM: " |
| 7749 | "bad texture id."); |
| 7750 | return error::kNoError; |
| 7751 | } |
| 7752 | |
| 7753 | if (info->IsStreamTexture()) { |
| 7754 | SetGLError(GL_INVALID_OPERATION, |
| 7755 | "glCreateStreamTextureCHROMIUM: " |
| 7756 | "is already a stream texture."); |
| 7757 | return error::kNoError; |
| 7758 | } |
| 7759 | |
| 7760 | if (info->target() && info->target() != GL_TEXTURE_EXTERNAL_OES) { |
| 7761 | SetGLError(GL_INVALID_OPERATION, |
| 7762 | "glCreateStreamTextureCHROMIUM: " |
| 7763 | "is already bound to incompatible target."); |
| 7764 | return error::kNoError; |
| 7765 | } |
| 7766 | |
| 7767 | if (!stream_texture_manager_) |
| 7768 | return error::kInvalidArguments; |
| 7769 | |
| 7770 | GLuint object_id = stream_texture_manager_->CreateStreamTexture( |
| 7771 | info->service_id(), client_id); |
| 7772 | |
| 7773 | if (object_id) { |
| 7774 | info->SetStreamTexture(true); |
| 7775 | } else { |
| 7776 | SetGLError(GL_OUT_OF_MEMORY, |
| 7777 | "glCreateStreamTextureCHROMIUM: " |
| 7778 | "failed to create platform texture."); |
| 7779 | } |
| 7780 | |
| 7781 | *result = object_id; |
| 7782 | return error::kNoError; |
| 7783 | } |
| 7784 | |
| 7785 | error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( |
| 7786 | uint32 immediate_data_size, |
| 7787 | const gles2::DestroyStreamTextureCHROMIUM& c) { |
| 7788 | GLuint client_id = c.texture; |
| 7789 | TextureManager::TextureInfo* info = |
| 7790 | texture_manager()->GetTextureInfo(client_id); |
| 7791 | if (info && info->IsStreamTexture()) { |
| 7792 | if (!stream_texture_manager_) |
| 7793 | return error::kInvalidArguments; |
| 7794 | |
| 7795 | stream_texture_manager_->DestroyStreamTexture(info->service_id()); |
| 7796 | info->SetStreamTexture(false); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7797 | texture_manager()->SetInfoTarget(info, 0); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 7798 | } else { |
| 7799 | SetGLError(GL_INVALID_VALUE, |
| 7800 | "glDestroyStreamTextureCHROMIUM: bad texture id."); |
| 7801 | } |
| 7802 | |
| 7803 | return error::kNoError; |
| 7804 | } |
| 7805 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 7806 | #if defined(OS_MACOSX) |
| 7807 | void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { |
| 7808 | TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( |
| 7809 | texture_id); |
| 7810 | if (it != texture_to_io_surface_map_.end()) { |
| 7811 | // Found a previous IOSurface bound to this texture; release it. |
| 7812 | CFTypeRef surface = it->second; |
| 7813 | CFRelease(surface); |
| 7814 | texture_to_io_surface_map_.erase(it); |
| 7815 | } |
| 7816 | } |
| 7817 | #endif |
| 7818 | |
| 7819 | void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( |
| 7820 | GLenum target, GLsizei width, GLsizei height, |
| 7821 | GLuint io_surface_id, GLuint plane) { |
| 7822 | #if defined(OS_MACOSX) |
| 7823 | if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
| 7824 | SetGLError(GL_INVALID_OPERATION, |
| 7825 | "glTexImageIOSurface2DCHROMIUM: only supported on desktop GL."); |
| 7826 | return; |
| 7827 | } |
| 7828 | |
| 7829 | IOSurfaceSupport* surface_support = IOSurfaceSupport::Initialize(); |
| 7830 | if (!surface_support) { |
| 7831 | SetGLError(GL_INVALID_OPERATION, |
| 7832 | "glTexImageIOSurface2DCHROMIUM: only supported on 10.6."); |
| 7833 | return; |
| 7834 | } |
| 7835 | |
| 7836 | if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 7837 | // This might be supported in the future, and if we could require |
| 7838 | // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
| 7839 | // could delete a lot of code. For now, perform strict validation so we |
| 7840 | // know what's going on. |
| 7841 | SetGLError( |
| 7842 | GL_INVALID_OPERATION, |
| 7843 | "glTexImageIOSurface2DCHROMIUM: requires TEXTURE_RECTANGLE_ARB target"); |
| 7844 | return; |
| 7845 | } |
| 7846 | |
| 7847 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 7848 | if (!info) { |
| 7849 | SetGLError(GL_INVALID_OPERATION, |
| 7850 | "glTexImageIOSurface2DCHROMIUM: no rectangle texture bound"); |
| 7851 | return; |
| 7852 | } |
| 7853 | if (info == texture_manager()->GetDefaultTextureInfo(target)) { |
| 7854 | // Maybe this is conceptually valid, but disallow it to avoid accidents. |
| 7855 | SetGLError(GL_INVALID_OPERATION, |
| 7856 | "glTexImageIOSurface2DCHROMIUM: can't bind default texture"); |
| 7857 | return; |
| 7858 | } |
| 7859 | |
| 7860 | // Look up the new IOSurface. Note that because of asynchrony |
| 7861 | // between processes this might fail; during live resizing the |
| 7862 | // plugin process might allocate and release an IOSurface before |
| 7863 | // this process gets a chance to look it up. Hold on to any old |
| 7864 | // IOSurface in this case. |
| 7865 | CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); |
| 7866 | if (!surface) { |
| 7867 | SetGLError(GL_INVALID_OPERATION, |
| 7868 | "glTexImageIOSurface2DCHROMIUM: no IOSurface with the given ID"); |
| 7869 | return; |
| 7870 | } |
| 7871 | |
| 7872 | // Release any IOSurface previously bound to this texture. |
| 7873 | ReleaseIOSurfaceForTexture(info->service_id()); |
| 7874 | |
| 7875 | // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. |
| 7876 | texture_to_io_surface_map_.insert( |
| 7877 | std::make_pair(info->service_id(), surface)); |
| 7878 | |
| 7879 | CGLContextObj context = |
| 7880 | static_cast<CGLContextObj>(context_->GetHandle()); |
| 7881 | |
| 7882 | CGLError err = surface_support->CGLTexImageIOSurface2D( |
| 7883 | context, |
| 7884 | target, |
| 7885 | GL_RGBA, |
| 7886 | width, |
| 7887 | height, |
| 7888 | GL_BGRA, |
| 7889 | GL_UNSIGNED_INT_8_8_8_8_REV, |
| 7890 | surface, |
| 7891 | plane); |
| 7892 | |
| 7893 | if (err != kCGLNoError) { |
| 7894 | SetGLError( |
| 7895 | GL_INVALID_OPERATION, |
| 7896 | "glTexImageIOSurface2DCHROMIUM: error in CGLTexImageIOSurface2D"); |
| 7897 | return; |
| 7898 | } |
| 7899 | |
| 7900 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7901 | info, target, 0, GL_RGBA, width, height, 1, 0, |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 7902 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); |
| 7903 | |
| 7904 | #else |
| 7905 | SetGLError(GL_INVALID_OPERATION, |
| 7906 | "glTexImageIOSurface2DCHROMIUM: not supported."); |
| 7907 | #endif |
| 7908 | } |
| 7909 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7910 | static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { |
| 7911 | switch (internalformat) { |
| 7912 | case GL_RGB565: |
| 7913 | return GL_RGB; |
| 7914 | case GL_RGBA4: |
| 7915 | return GL_RGBA; |
| 7916 | case GL_RGB5_A1: |
| 7917 | return GL_RGBA; |
| 7918 | case GL_RGB8_OES: |
| 7919 | return GL_RGB; |
| 7920 | case GL_RGBA8_OES: |
| 7921 | return GL_RGBA; |
| 7922 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 7923 | return GL_LUMINANCE_ALPHA; |
| 7924 | case GL_LUMINANCE8_EXT: |
| 7925 | return GL_LUMINANCE; |
| 7926 | case GL_ALPHA8_EXT: |
| 7927 | return GL_ALPHA; |
| 7928 | case GL_RGBA32F_EXT: |
| 7929 | return GL_RGBA; |
| 7930 | case GL_RGB32F_EXT: |
| 7931 | return GL_RGB; |
| 7932 | case GL_ALPHA32F_EXT: |
| 7933 | return GL_ALPHA; |
| 7934 | case GL_LUMINANCE32F_EXT: |
| 7935 | return GL_LUMINANCE; |
| 7936 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 7937 | return GL_LUMINANCE_ALPHA; |
| 7938 | case GL_RGBA16F_EXT: |
| 7939 | return GL_RGBA; |
| 7940 | case GL_RGB16F_EXT: |
| 7941 | return GL_RGB; |
| 7942 | case GL_ALPHA16F_EXT: |
| 7943 | return GL_ALPHA; |
| 7944 | case GL_LUMINANCE16F_EXT: |
| 7945 | return GL_LUMINANCE; |
| 7946 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 7947 | return GL_LUMINANCE_ALPHA; |
| 7948 | case GL_BGRA8_EXT: |
| 7949 | return GL_BGRA_EXT; |
| 7950 | default: |
| 7951 | return GL_NONE; |
| 7952 | } |
| 7953 | } |
| 7954 | |
| 7955 | static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 7956 | switch (internalformat) { |
| 7957 | case GL_RGB565: |
| 7958 | return GL_UNSIGNED_SHORT_5_6_5; |
| 7959 | case GL_RGBA4: |
| 7960 | return GL_UNSIGNED_SHORT_4_4_4_4; |
| 7961 | case GL_RGB5_A1: |
| 7962 | return GL_UNSIGNED_SHORT_5_5_5_1; |
| 7963 | case GL_RGB8_OES: |
| 7964 | return GL_UNSIGNED_BYTE; |
| 7965 | case GL_RGBA8_OES: |
| 7966 | return GL_UNSIGNED_BYTE; |
| 7967 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 7968 | return GL_UNSIGNED_BYTE; |
| 7969 | case GL_LUMINANCE8_EXT: |
| 7970 | return GL_UNSIGNED_BYTE; |
| 7971 | case GL_ALPHA8_EXT: |
| 7972 | return GL_UNSIGNED_BYTE; |
| 7973 | case GL_RGBA32F_EXT: |
| 7974 | return GL_FLOAT; |
| 7975 | case GL_RGB32F_EXT: |
| 7976 | return GL_FLOAT; |
| 7977 | case GL_ALPHA32F_EXT: |
| 7978 | return GL_FLOAT; |
| 7979 | case GL_LUMINANCE32F_EXT: |
| 7980 | return GL_FLOAT; |
| 7981 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 7982 | return GL_FLOAT; |
| 7983 | case GL_RGBA16F_EXT: |
| 7984 | return GL_HALF_FLOAT_OES; |
| 7985 | case GL_RGB16F_EXT: |
| 7986 | return GL_HALF_FLOAT_OES; |
| 7987 | case GL_ALPHA16F_EXT: |
| 7988 | return GL_HALF_FLOAT_OES; |
| 7989 | case GL_LUMINANCE16F_EXT: |
| 7990 | return GL_HALF_FLOAT_OES; |
| 7991 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 7992 | return GL_HALF_FLOAT_OES; |
| 7993 | case GL_BGRA8_EXT: |
| 7994 | return GL_UNSIGNED_BYTE; |
| 7995 | default: |
| 7996 | return GL_NONE; |
| 7997 | } |
| 7998 | } |
| 7999 | |
| 8000 | void GLES2DecoderImpl::DoTexStorage2DEXT( |
| 8001 | GLenum target, |
| 8002 | GLint levels, |
| 8003 | GLenum internal_format, |
| 8004 | GLsizei width, |
| 8005 | GLsizei height) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8006 | if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8007 | TextureManager::ComputeMipMapCount(width, height, 1) < levels) { |
| 8008 | SetGLError(GL_INVALID_VALUE, "glTexStorage2DEXT: dimensions out of range"); |
| 8009 | return; |
| 8010 | } |
| 8011 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 8012 | if (!info) { |
| 8013 | SetGLError(GL_INVALID_OPERATION, |
| 8014 | "glTexStorage2DEXT: unknown texture for target"); |
| 8015 | return; |
| 8016 | } |
| 8017 | if (info->IsAttachedToFramebuffer()) { |
| 8018 | state_dirty_ = true; |
| 8019 | } |
| 8020 | if (info->IsImmutable()) { |
| 8021 | SetGLError(GL_INVALID_OPERATION, |
| 8022 | "glTexStorage2DEXT: texture is immutable"); |
| 8023 | return; |
| 8024 | } |
| 8025 | CopyRealGLErrorsToWrapper(); |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 8026 | glTexStorage2DEXT(target, levels, GetTexInternalFormat(internal_format), |
| 8027 | width, height); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8028 | GLenum error = PeekGLError(); |
| 8029 | if (error == GL_NO_ERROR) { |
| 8030 | GLenum format = ExtractFormatFromStorageFormat(internal_format); |
| 8031 | GLenum type = ExtractTypeFromStorageFormat(internal_format); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8032 | GLsizei level_width = width; |
| 8033 | GLsizei level_height = height; |
| 8034 | for (int ii = 0; ii < levels; ++ii) { |
| 8035 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8036 | info, target, 0, format, level_width, level_height, 1, 0, format, |
| 8037 | type, false); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8038 | level_width = std::max(1, level_width >> 1); |
| 8039 | level_height = std::max(1, level_height >> 1); |
| 8040 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8041 | info->SetImmutable(true); |
| 8042 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8043 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8044 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8045 | // Include the auto-generated part of this file. We split this because it means |
| 8046 | // we can easily edit the non-auto generated parts right here in this file |
| 8047 | // instead of having to edit some template or the code generator. |
| 8048 | #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 8049 | |
| 8050 | } // namespace gles2 |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 8051 | } // namespace gpu |