blob: a9fc5d0c434378626618effc59e983a97af7b9b7 [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
26// State associated with each texture unit.
[email protected]88a61bf2012-10-27 13:00:4227struct GPU_EXPORT TextureUnit {
[email protected]e259eb412012-10-13 05:47:2428 TextureUnit();
29 ~TextureUnit();
30
31 // The last target that was bound to this texture unit.
32 GLenum bind_target;
33
34 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
35 TextureManager::TextureInfo::Ref bound_texture_2d;
36
37 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
38 // glBindTexture
39 TextureManager::TextureInfo::Ref bound_texture_cube_map;
40
41 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
42 // glBindTexture
43 TextureManager::TextureInfo::Ref bound_texture_external_oes;
44
45 // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with
46 // glBindTexture
47 TextureManager::TextureInfo::Ref bound_texture_rectangle_arb;
48
49 TextureManager::TextureInfo::Ref GetInfoForSamplerType(GLenum type) {
50 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
51 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
52 switch (type) {
53 case GL_SAMPLER_2D:
54 return bound_texture_2d;
55 case GL_SAMPLER_CUBE:
56 return bound_texture_cube_map;
57 case GL_SAMPLER_EXTERNAL_OES:
58 return bound_texture_external_oes;
59 case GL_SAMPLER_2D_RECT_ARB:
60 return bound_texture_rectangle_arb;
61 }
62
63 NOTREACHED();
64 return NULL;
65 }
66
67 void Unbind(TextureManager::TextureInfo* texture) {
68 if (bound_texture_2d == texture) {
69 bound_texture_2d = NULL;
70 }
71 if (bound_texture_cube_map == texture) {
72 bound_texture_cube_map = NULL;
73 }
74 if (bound_texture_external_oes == texture) {
75 bound_texture_external_oes = NULL;
76 }
77 }
78};
79
80
[email protected]88a61bf2012-10-27 13:00:4281struct GPU_EXPORT ContextState {
[email protected]e259eb412012-10-13 05:47:2482 ContextState();
83 ~ContextState();
84
[email protected]f731b9462012-10-30 00:35:2285 void Initialize();
86
[email protected]1868a342012-11-07 15:56:0287 void RestoreState() const;
88 void InitCapabilities() const;
89 void InitState() const;
[email protected]f731b9462012-10-30 00:35:2290
[email protected]d058bca2012-11-26 10:27:2691 // Helper for getting cached state.
92 bool GetStateAsGLint(
93 GLenum pname, GLint* params, GLsizei* num_written) const;
94 bool GetStateAsGLfloat(
95 GLenum pname, GLfloat* params, GLsizei* num_written) const;
96 bool GetEnabled(GLenum cap) const;
97
[email protected]f731b9462012-10-30 00:35:2298 #include "gpu/command_buffer/service/context_state_autogen.h"
99
100 EnableFlags enable_flags;
101
[email protected]e259eb412012-10-13 05:47:24102 // pack alignment as last set by glPixelStorei
103 GLint pack_alignment;
104
105 // unpack alignment as last set by glPixelStorei
106 GLint unpack_alignment;
107
108 // Current active texture by 0 - n index.
109 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would
110 // be 2.
111 GLuint active_texture_unit;
112
[email protected]e259eb412012-10-13 05:47:24113 // The currently bound array buffer. If this is 0 it is illegal to call
114 // glVertexAttribPointer.
115 BufferManager::BufferInfo::Ref bound_array_buffer;
116
117 // Which textures are bound to texture units through glActiveTexture.
[email protected]1868a342012-11-07 15:56:02118 std::vector<TextureUnit> texture_units;
[email protected]e259eb412012-10-13 05:47:24119
120 // Class that manages vertex attribs.
121 VertexAttribManager::Ref vertex_attrib_manager;
122
123 // The program in use by glUseProgram
124 ProgramManager::ProgramInfo::Ref current_program;
125
126 // The currently bound framebuffers
127 FramebufferManager::FramebufferInfo::Ref bound_read_framebuffer;
128 FramebufferManager::FramebufferInfo::Ref bound_draw_framebuffer;
129
130 // The currently bound renderbuffer
131 RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer;
132
133 QueryManager::Query::Ref current_query;
134
[email protected]88a61bf2012-10-27 13:00:42135 GLenum hint_generate_mipmap;
136 GLenum hint_fragment_shader_derivative;
[email protected]e259eb412012-10-13 05:47:24137
138 bool pack_reverse_row_order;
139};
140
141} // namespace gles2
142} // namespace gpu
143
144#endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
145