blob: 769a56b2b4979cbccc7cf5a81eaee3059870189c [file] [log] [blame]
[email protected]e259eb412012-10-13 05:47:241// 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
3// found in the LICENSE file.
4
5// This file contains the ContextState class.
6
7#ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
8#define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
9
[email protected]1868a342012-11-07 15:56:0210#include <vector>
[email protected]e259eb412012-10-13 05:47:2411#include "base/logging.h"
12#include "gpu/command_buffer/service/gl_utils.h"
13#include "gpu/command_buffer/service/buffer_manager.h"
14#include "gpu/command_buffer/service/framebuffer_manager.h"
15#include "gpu/command_buffer/service/program_manager.h"
16#include "gpu/command_buffer/service/query_manager.h"
17#include "gpu/command_buffer/service/renderbuffer_manager.h"
18#include "gpu/command_buffer/service/texture_manager.h"
19#include "gpu/command_buffer/service/vertex_attrib_manager.h"
20#include "gpu/command_buffer/service/vertex_array_manager.h"
[email protected]88a61bf2012-10-27 13:00:4221#include "gpu/gpu_export.h"
[email protected]e259eb412012-10-13 05:47:2422
23namespace gpu {
24namespace gles2 {
25
[email protected]b3cbad12012-12-05 19:56:3626class FeatureInfo;
27
[email protected]e259eb412012-10-13 05:47:2428// State associated with each texture unit.
[email protected]88a61bf2012-10-27 13:00:4229struct GPU_EXPORT TextureUnit {
[email protected]e259eb412012-10-13 05:47:2430 TextureUnit();
31 ~TextureUnit();
32
33 // The last target that was bound to this texture unit.
34 GLenum bind_target;
35
36 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
[email protected]ed9f9cd2013-02-27 21:12:3537 scoped_refptr<Texture> bound_texture_2d;
[email protected]e259eb412012-10-13 05:47:2438
39 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
40 // glBindTexture
[email protected]ed9f9cd2013-02-27 21:12:3541 scoped_refptr<Texture> bound_texture_cube_map;
[email protected]e259eb412012-10-13 05:47:2442
43 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
44 // glBindTexture
[email protected]ed9f9cd2013-02-27 21:12:3545 scoped_refptr<Texture> bound_texture_external_oes;
[email protected]e259eb412012-10-13 05:47:2446
47 // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with
48 // glBindTexture
[email protected]ed9f9cd2013-02-27 21:12:3549 scoped_refptr<Texture> bound_texture_rectangle_arb;
[email protected]e259eb412012-10-13 05:47:2450
[email protected]ed9f9cd2013-02-27 21:12:3551 scoped_refptr<Texture> GetInfoForSamplerType(
52 GLenum type) {
[email protected]e259eb412012-10-13 05:47:2453 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
54 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
55 switch (type) {
56 case GL_SAMPLER_2D:
57 return bound_texture_2d;
58 case GL_SAMPLER_CUBE:
59 return bound_texture_cube_map;
60 case GL_SAMPLER_EXTERNAL_OES:
61 return bound_texture_external_oes;
62 case GL_SAMPLER_2D_RECT_ARB:
63 return bound_texture_rectangle_arb;
64 }
65
66 NOTREACHED();
67 return NULL;
68 }
69
[email protected]ed9f9cd2013-02-27 21:12:3570 void Unbind(Texture* texture) {
[email protected]e259eb412012-10-13 05:47:2471 if (bound_texture_2d == texture) {
72 bound_texture_2d = NULL;
73 }
74 if (bound_texture_cube_map == texture) {
75 bound_texture_cube_map = NULL;
76 }
77 if (bound_texture_external_oes == texture) {
78 bound_texture_external_oes = NULL;
79 }
80 }
81};
82
[email protected]af6380962012-11-29 23:24:1383struct Vec4 {
84 Vec4() {
85 v[0] = 0.0f;
86 v[1] = 0.0f;
87 v[2] = 0.0f;
88 v[3] = 1.0f;
89 }
90 float v[4];
91};
[email protected]e259eb412012-10-13 05:47:2492
[email protected]88a61bf2012-10-27 13:00:4293struct GPU_EXPORT ContextState {
[email protected]b3cbad12012-12-05 19:56:3694 explicit ContextState(FeatureInfo* feature_info);
[email protected]e259eb412012-10-13 05:47:2495 ~ContextState();
96
[email protected]f731b9462012-10-30 00:35:2297 void Initialize();
98
[email protected]1868a342012-11-07 15:56:0299 void RestoreState() const;
100 void InitCapabilities() const;
101 void InitState() const;
[email protected]f731b9462012-10-30 00:35:22102
[email protected]29a4d902013-02-26 20:18:06103 void RestoreActiveTexture() const;
104 void RestoreAttribute(GLuint index) const;
105 void RestoreBufferBindings() const;
106 void RestoreGlobalState() const;
107 void RestoreProgramBindings() const;
108 void RestoreRenderbufferBindings() const;
109 void RestoreTextureUnitBindings(GLuint unit) const;
110
[email protected]d058bca2012-11-26 10:27:26111 // Helper for getting cached state.
112 bool GetStateAsGLint(
113 GLenum pname, GLint* params, GLsizei* num_written) const;
114 bool GetStateAsGLfloat(
115 GLenum pname, GLfloat* params, GLsizei* num_written) const;
116 bool GetEnabled(GLenum cap) const;
117
[email protected]f731b9462012-10-30 00:35:22118 #include "gpu/command_buffer/service/context_state_autogen.h"
119
120 EnableFlags enable_flags;
121
[email protected]e259eb412012-10-13 05:47:24122 // pack alignment as last set by glPixelStorei
123 GLint pack_alignment;
124
125 // unpack alignment as last set by glPixelStorei
126 GLint unpack_alignment;
127
128 // Current active texture by 0 - n index.
129 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would
130 // be 2.
131 GLuint active_texture_unit;
132
[email protected]e259eb412012-10-13 05:47:24133 // The currently bound array buffer. If this is 0 it is illegal to call
134 // glVertexAttribPointer.
[email protected]ed9f9cd2013-02-27 21:12:35135 scoped_refptr<BufferManager::Buffer> bound_array_buffer;
[email protected]e259eb412012-10-13 05:47:24136
137 // Which textures are bound to texture units through glActiveTexture.
[email protected]1868a342012-11-07 15:56:02138 std::vector<TextureUnit> texture_units;
[email protected]e259eb412012-10-13 05:47:24139
[email protected]af6380962012-11-29 23:24:13140 // The values for each attrib.
141 std::vector<Vec4> attrib_values;
142
[email protected]e259eb412012-10-13 05:47:24143 // Class that manages vertex attribs.
[email protected]ed9f9cd2013-02-27 21:12:35144 scoped_refptr<VertexAttribManager> vertex_attrib_manager;
[email protected]e259eb412012-10-13 05:47:24145
146 // The program in use by glUseProgram
[email protected]ed9f9cd2013-02-27 21:12:35147 scoped_refptr<Program> current_program;
[email protected]e259eb412012-10-13 05:47:24148
149 // The currently bound framebuffers
[email protected]ed9f9cd2013-02-27 21:12:35150 scoped_refptr<Framebuffer> bound_read_framebuffer;
151 scoped_refptr<Framebuffer> bound_draw_framebuffer;
[email protected]e259eb412012-10-13 05:47:24152
153 // The currently bound renderbuffer
[email protected]ed9f9cd2013-02-27 21:12:35154 scoped_refptr<Renderbuffer> bound_renderbuffer;
[email protected]e259eb412012-10-13 05:47:24155
[email protected]ed9f9cd2013-02-27 21:12:35156 scoped_refptr<QueryManager::Query> current_query;
[email protected]e259eb412012-10-13 05:47:24157
[email protected]88a61bf2012-10-27 13:00:42158 GLenum hint_generate_mipmap;
159 GLenum hint_fragment_shader_derivative;
[email protected]e259eb412012-10-13 05:47:24160
161 bool pack_reverse_row_order;
[email protected]b3cbad12012-12-05 19:56:36162
163 FeatureInfo* feature_info_;
[email protected]e259eb412012-10-13 05:47:24164};
165
166} // namespace gles2
167} // namespace gpu
168
169#endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
170