Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: gpu/command_buffer/service/context_state.cc

Issue 11275120: Virtual GL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/context_state.h" 5 #include "gpu/command_buffer/service/context_state.h"
6 6
7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
8 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/gl_implementation.h"
8 10
9 namespace gpu { 11 namespace gpu {
10 namespace gles2 { 12 namespace gles2 {
11 13
12 namespace { 14 namespace {
13 15
14 void EnableDisable(GLenum pname, bool enable) { 16 void EnableDisable(GLenum pname, bool enable) {
15 if (enable) { 17 if (enable) {
16 glEnable(pname); 18 glEnable(pname);
17 } else { 19 } else {
18 glDisable(pname); 20 glDisable(pname);
19 } 21 }
20 } 22 }
21 23
22 } // anonymous namespace. 24 } // anonymous namespace.
23 25
24 TextureUnit::TextureUnit() 26 TextureUnit::TextureUnit()
25 : bind_target(GL_TEXTURE_2D) { 27 : bind_target(GL_TEXTURE_2D) {
26 } 28 }
27 29
28 TextureUnit::~TextureUnit() { 30 TextureUnit::~TextureUnit() {
29 } 31 }
30 32
31 ContextState::ContextState() 33 ContextState::ContextState()
32 : pack_alignment(4), 34 : pack_alignment(4),
33 unpack_alignment(4), 35 unpack_alignment(4),
34 active_texture_unit(0), 36 active_texture_unit(0),
35 viewport_max_width(0),
36 viewport_max_height(0),
37 hint_generate_mipmap(GL_DONT_CARE), 37 hint_generate_mipmap(GL_DONT_CARE),
38 hint_fragment_shader_derivative(GL_DONT_CARE), 38 hint_fragment_shader_derivative(GL_DONT_CARE),
39 pack_reverse_row_order(false) { 39 pack_reverse_row_order(false) {
40 Initialize(); 40 Initialize();
41 } 41 }
42 42
43 ContextState::~ContextState() { 43 ContextState::~ContextState() {
44 } 44 }
45 45
46 void ContextState::RestoreState() const {
47 InitCapabilities();
48 InitState();
49
50 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment);
51 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment);
52
53 glHint(GL_GENERATE_MIPMAP_HINT, hint_generate_mipmap);
54 // TODO: If OES_standard_derivatives is available
55 // restore GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
56
57 // Restore Texture state.
58 for (size_t ii = 0; ii < texture_units.size(); ++ii) {
59 const TextureUnit& texture_unit = texture_units[ii];
60 glActiveTexture(GL_TEXTURE0 + ii);
61 GLuint service_id = texture_unit.bound_texture_2d ?
62 texture_unit.bound_texture_2d->service_id() : 0;
63 glBindTexture(GL_TEXTURE_2D, service_id);
64 service_id = texture_unit.bound_texture_cube_map ?
65 texture_unit.bound_texture_cube_map->service_id() : 0;
66 glBindTexture(GL_TEXTURE_CUBE_MAP, service_id);
67 // TODO: Restore bindings for GL_TEXTURE_RECTANGLE_ARB and
68 // GL_TEXTURE_EXTERNAL_OES.
69 }
70 glActiveTexture(GL_TEXTURE0 + active_texture_unit);
71
72 // Restore Attrib State
73 // TODO: This if should not be needed. RestoreState is getting called
74 // before GLES2Decoder::Initialize which is a bug.
75 if (vertex_attrib_manager) {
76 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs();
77 ++attrib) {
78 const VertexAttribManager::VertexAttribInfo* info =
79 vertex_attrib_manager->GetVertexAttribInfo(attrib);
80 const void* ptr = reinterpret_cast<const void*>(info->offset());
81 BufferManager::BufferInfo* buffer_info = info->buffer();
82 glBindBuffer(
83 GL_ARRAY_BUFFER, buffer_info ? buffer_info->service_id() : 0);
84 glVertexAttribPointer(
85 attrib, info->size(), info->type(), info->normalized(),
86 info->gl_stride(), ptr);
87 if (info->divisor())
88 glVertexAttribDivisorANGLE(attrib, info->divisor());
89 // Never touch vertex attribute 0's state (in particular, never
90 // disable it) when running on desktop GL because it will never be
91 // re-enabled.
92 if (attrib != 0 ||
93 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
94 if (info->enabled()) {
95 glEnableVertexAttribArray(attrib);
96 } else {
97 glDisableVertexAttribArray(attrib);
98 }
99 }
100 }
101 BufferManager::BufferInfo* element_array_buffer =
102 vertex_attrib_manager->element_array_buffer();
103 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
104 element_array_buffer ? element_array_buffer->service_id() : 0);
105 }
106
107 // Restore Bindings
108 glBindBuffer(
109 GL_ARRAY_BUFFER,
110 bound_array_buffer ? bound_array_buffer->service_id() : 0);
111 glBindRenderbufferEXT(
112 GL_RENDERBUFFER,
113 bound_renderbuffer ? bound_renderbuffer->service_id() : 0);
114
115 glUseProgram(current_program ? current_program->service_id() : 0);
116 }
117
46 // Include the auto-generated part of this file. We split this because it means 118 // Include the auto-generated part of this file. We split this because it means
47 // we can easily edit the non-auto generated parts right here in this file 119 // we can easily edit the non-auto generated parts right here in this file
48 // instead of having to edit some template or the code generator. 120 // instead of having to edit some template or the code generator.
49 #include "gpu/command_buffer/service/context_state_impl_autogen.h" 121 #include "gpu/command_buffer/service/context_state_impl_autogen.h"
50 122
51 } // namespace gles2 123 } // namespace gles2
52 } // namespace gpu 124 } // namespace gpu
53 125
54 126
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698