blob: c2479cba2137996bf278057050697c2cab2ba4dd [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"
[email protected]d3eba342013-04-18 21:11:5012#include "base/memory/scoped_ptr.h"
[email protected]e259eb412012-10-13 05:47:2413#include "gpu/command_buffer/service/gl_utils.h"
[email protected]e259eb412012-10-13 05:47:2414#include "gpu/command_buffer/service/query_manager.h"
[email protected]e259eb412012-10-13 05:47:2415#include "gpu/command_buffer/service/texture_manager.h"
16#include "gpu/command_buffer/service/vertex_attrib_manager.h"
17#include "gpu/command_buffer/service/vertex_array_manager.h"
[email protected]88a61bf2012-10-27 13:00:4218#include "gpu/gpu_export.h"
[email protected]e259eb412012-10-13 05:47:2419
20namespace gpu {
21namespace gles2 {
22
[email protected]31494b82013-02-28 10:10:2623class Buffer;
[email protected]d3eba342013-04-18 21:11:5024class ErrorState;
[email protected]b3cbad12012-12-05 19:56:3625class FeatureInfo;
[email protected]31494b82013-02-28 10:10:2626class Framebuffer;
27class Program;
28class Renderbuffer;
[email protected]b3cbad12012-12-05 19:56:3629
[email protected]e259eb412012-10-13 05:47:2430// State associated with each texture unit.
[email protected]88a61bf2012-10-27 13:00:4231struct GPU_EXPORT TextureUnit {
[email protected]e259eb412012-10-13 05:47:2432 TextureUnit();
33 ~TextureUnit();
34
35 // The last target that was bound to this texture unit.
36 GLenum bind_target;
37
38 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
[email protected]370eaf12013-05-18 09:19:4939 scoped_refptr<TextureRef> bound_texture_2d;
[email protected]e259eb412012-10-13 05:47:2440
41 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
42 // glBindTexture
[email protected]370eaf12013-05-18 09:19:4943 scoped_refptr<TextureRef> bound_texture_cube_map;
[email protected]e259eb412012-10-13 05:47:2444
45 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
46 // glBindTexture
[email protected]370eaf12013-05-18 09:19:4947 scoped_refptr<TextureRef> bound_texture_external_oes;
[email protected]e259eb412012-10-13 05:47:2448
49 // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with
50 // glBindTexture
[email protected]370eaf12013-05-18 09:19:4951 scoped_refptr<TextureRef> bound_texture_rectangle_arb;
[email protected]e259eb412012-10-13 05:47:2452
[email protected]370eaf12013-05-18 09:19:4953 scoped_refptr<TextureRef> GetInfoForSamplerType(
[email protected]ed9f9cd2013-02-27 21:12:3554 GLenum type) {
[email protected]e259eb412012-10-13 05:47:2455 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
56 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
57 switch (type) {
58 case GL_SAMPLER_2D:
59 return bound_texture_2d;
60 case GL_SAMPLER_CUBE:
61 return bound_texture_cube_map;
62 case GL_SAMPLER_EXTERNAL_OES:
63 return bound_texture_external_oes;
64 case GL_SAMPLER_2D_RECT_ARB:
65 return bound_texture_rectangle_arb;
66 }
67
68 NOTREACHED();
69 return NULL;
70 }
71
[email protected]370eaf12013-05-18 09:19:4972 void Unbind(TextureRef* texture) {
[email protected]7cd76fd2013-06-02 21:11:1173 if (bound_texture_2d.get() == texture) {
[email protected]e259eb412012-10-13 05:47:2474 bound_texture_2d = NULL;
75 }
[email protected]7cd76fd2013-06-02 21:11:1176 if (bound_texture_cube_map.get() == texture) {
[email protected]e259eb412012-10-13 05:47:2477 bound_texture_cube_map = NULL;
78 }
[email protected]7cd76fd2013-06-02 21:11:1179 if (bound_texture_external_oes.get() == texture) {
[email protected]e259eb412012-10-13 05:47:2480 bound_texture_external_oes = NULL;
81 }
82 }
83};
84
[email protected]af6380962012-11-29 23:24:1385struct Vec4 {
86 Vec4() {
87 v[0] = 0.0f;
88 v[1] = 0.0f;
89 v[2] = 0.0f;
90 v[3] = 1.0f;
91 }
92 float v[4];
93};
[email protected]e259eb412012-10-13 05:47:2494
[email protected]88a61bf2012-10-27 13:00:4295struct GPU_EXPORT ContextState {
[email protected]d3eba342013-04-18 21:11:5096 ContextState(FeatureInfo* feature_info, Logger* logger);
[email protected]e259eb412012-10-13 05:47:2497 ~ContextState();
98
[email protected]f731b9462012-10-30 00:35:2299 void Initialize();
100
[email protected]5baa86bc2014-01-16 04:33:16101 void RestoreState(const ContextState* prev_state) const;
[email protected]1868a342012-11-07 15:56:02102 void InitCapabilities() const;
103 void InitState() const;
[email protected]f731b9462012-10-30 00:35:22104
[email protected]29a4d902013-02-26 20:18:06105 void RestoreActiveTexture() const;
[email protected]5baa86bc2014-01-16 04:33:16106 void RestoreAllTextureUnitBindings(const ContextState* prev_state) const;
[email protected]29a4d902013-02-26 20:18:06107 void RestoreAttribute(GLuint index) const;
108 void RestoreBufferBindings() const;
109 void RestoreGlobalState() const;
110 void RestoreProgramBindings() const;
111 void RestoreRenderbufferBindings() const;
[email protected]5baa86bc2014-01-16 04:33:16112 void RestoreTextureUnitBindings(
113 GLuint unit, const ContextState* prev_state) const;
[email protected]29a4d902013-02-26 20:18:06114
[email protected]d058bca2012-11-26 10:27:26115 // Helper for getting cached state.
116 bool GetStateAsGLint(
117 GLenum pname, GLint* params, GLsizei* num_written) const;
118 bool GetStateAsGLfloat(
119 GLenum pname, GLfloat* params, GLsizei* num_written) const;
120 bool GetEnabled(GLenum cap) const;
121
[email protected]d3eba342013-04-18 21:11:50122 ErrorState* GetErrorState();
123
[email protected]f731b9462012-10-30 00:35:22124 #include "gpu/command_buffer/service/context_state_autogen.h"
125
126 EnableFlags enable_flags;
127
[email protected]e259eb412012-10-13 05:47:24128 // 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]16ccec12013-02-28 03:40:21135 scoped_refptr<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
[email protected]e259eb412012-10-13 05:47:24149 // The currently bound renderbuffer
[email protected]ed9f9cd2013-02-27 21:12:35150 scoped_refptr<Renderbuffer> bound_renderbuffer;
[email protected]e259eb412012-10-13 05:47:24151
[email protected]8ebd46c2014-01-08 12:06:13152 // A map of of target -> Query for current queries
153 typedef std::map<GLuint, scoped_refptr<QueryManager::Query> > QueryMap;
154 QueryMap current_queries;
[email protected]e259eb412012-10-13 05:47:24155
[email protected]e259eb412012-10-13 05:47:24156 bool pack_reverse_row_order;
[email protected]b3cbad12012-12-05 19:56:36157
[email protected]28718a92013-04-04 12:12:51158 mutable bool fbo_binding_for_scissor_workaround_dirty_;
[email protected]b3cbad12012-12-05 19:56:36159 FeatureInfo* feature_info_;
[email protected]d3eba342013-04-18 21:11:50160
161 private:
162 scoped_ptr<ErrorState> error_state_;
[email protected]e259eb412012-10-13 05:47:24163};
164
165} // namespace gles2
166} // namespace gpu
167
168#endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
169