0

Move per context GL state to a separate object.

This is in preparation for virutalizing GL contexts.

BUG=155557


Review URL: https://chromiumcodereview.appspot.com/11130005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161729 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
gman@chromium.org
2012-10-13 05:47:24 +00:00
parent c0299d6b37
commit e259eb41b3
5 changed files with 532 additions and 378 deletions

@ -0,0 +1,53 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/command_buffer/service/context_state.h"
namespace gpu {
namespace gles2 {
TextureUnit::TextureUnit()
: bind_target(GL_TEXTURE_2D) {
}
TextureUnit::~TextureUnit() {
}
ContextState::ContextState()
: pack_alignment(4),
unpack_alignment(4),
active_texture_unit(0),
color_clear_red(0),
color_clear_green(0),
color_clear_blue(0),
color_clear_alpha(0),
color_mask_red(true),
color_mask_green(true),
color_mask_blue(true),
color_mask_alpha(true),
stencil_clear(0),
stencil_mask_front(-1),
stencil_mask_back(-1),
depth_clear(1.0f),
depth_mask(true),
enable_blend(false),
enable_cull_face(false),
enable_scissor_test(false),
enable_depth_test(false),
enable_stencil_test(false),
viewport_x(0),
viewport_y(0),
viewport_width(0),
viewport_height(0),
viewport_max_width(0),
viewport_max_height(0) {
}
ContextState::~ContextState() {
}
} // namespace gles2
} // namespace gpu

@ -0,0 +1,199 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file contains the ContextState class.
#ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
#define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
#include "base/logging.h"
#include "gpu/command_buffer/service/gl_utils.h"
#include "gpu/command_buffer/service/buffer_manager.h"
#include "gpu/command_buffer/service/framebuffer_manager.h"
#include "gpu/command_buffer/service/program_manager.h"
#include "gpu/command_buffer/service/query_manager.h"
#include "gpu/command_buffer/service/renderbuffer_manager.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/command_buffer/service/vertex_attrib_manager.h"
#include "gpu/command_buffer/service/vertex_array_manager.h"
namespace gpu {
namespace gles2 {
// State associated with each texture unit.
struct TextureUnit {
TextureUnit();
~TextureUnit();
// The last target that was bound to this texture unit.
GLenum bind_target;
// texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
TextureManager::TextureInfo::Ref bound_texture_2d;
// texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
// glBindTexture
TextureManager::TextureInfo::Ref bound_texture_cube_map;
// texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
// glBindTexture
TextureManager::TextureInfo::Ref bound_texture_external_oes;
// texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with
// glBindTexture
TextureManager::TextureInfo::Ref bound_texture_rectangle_arb;
TextureManager::TextureInfo::Ref GetInfoForSamplerType(GLenum type) {
DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
switch (type) {
case GL_SAMPLER_2D:
return bound_texture_2d;
case GL_SAMPLER_CUBE:
return bound_texture_cube_map;
case GL_SAMPLER_EXTERNAL_OES:
return bound_texture_external_oes;
case GL_SAMPLER_2D_RECT_ARB:
return bound_texture_rectangle_arb;
}
NOTREACHED();
return NULL;
}
void Unbind(TextureManager::TextureInfo* texture) {
if (bound_texture_2d == texture) {
bound_texture_2d = NULL;
}
if (bound_texture_cube_map == texture) {
bound_texture_cube_map = NULL;
}
if (bound_texture_external_oes == texture) {
bound_texture_external_oes = NULL;
}
}
};
struct ContextState {
ContextState();
~ContextState();
// pack alignment as last set by glPixelStorei
GLint pack_alignment;
// unpack alignment as last set by glPixelStorei
GLint unpack_alignment;
// Current active texture by 0 - n index.
// In other words, if we call glActiveTexture(GL_TEXTURE2) this value would
// be 2.
GLuint active_texture_unit;
GLfloat color_clear_red;
GLfloat color_clear_green;
GLfloat color_clear_blue;
GLfloat color_clear_alpha;
GLboolean color_mask_red;
GLboolean color_mask_green;
GLboolean color_mask_blue;
GLboolean color_mask_alpha;
GLint stencil_clear;
GLuint stencil_mask_front;
GLuint stencil_mask_back;
GLclampf depth_clear;
GLboolean depth_mask;
bool enable_blend;
bool enable_cull_face;
bool enable_scissor_test;
bool enable_depth_test;
bool enable_stencil_test;
// Cached values of the currently assigned viewport dimensions.
GLint viewport_x;
GLint viewport_y;
GLsizei viewport_width;
GLsizei viewport_height;
GLsizei viewport_max_width;
GLsizei viewport_max_height;
// The currently bound array buffer. If this is 0 it is illegal to call
// glVertexAttribPointer.
BufferManager::BufferInfo::Ref bound_array_buffer;
// Which textures are bound to texture units through glActiveTexture.
scoped_array<TextureUnit> texture_units;
// Class that manages vertex attribs.
VertexAttribManager::Ref vertex_attrib_manager;
// The program in use by glUseProgram
ProgramManager::ProgramInfo::Ref current_program;
// The currently bound framebuffers
FramebufferManager::FramebufferInfo::Ref bound_read_framebuffer;
FramebufferManager::FramebufferInfo::Ref bound_draw_framebuffer;
// The currently bound renderbuffer
RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer;
QueryManager::Query::Ref current_query;
GLenum cull_mode;
GLenum front_face;
GLenum depth_func;
GLenum source_blend_rgb;
GLenum dest_blend_rgb;
GLenum source_blend_alpha;
GLenum dest_blend_alpha;
GLenum blend_equation_rgb;
GLenum blend_equation_alpha;
GLfloat blend_color_red;
GLfloat blend_color_green;
GLfloat blend_color_blue;
GLfloat blend_color_alpha;
GLenum stencil_func;
GLint stencil_ref;
GLenum stencil_fail;
GLenum stencil_pass_depth_fail;
GLenum stencil_pass_depth_pass;
GLuint stencil_writemask;
GLenum stencil_back_func;
GLint stencil_back_ref;
GLenum stencil_back_fail;
GLenum stencil_back_pass_depth_fail;
GLenum stencil_back_pass_depth_pass;
GLuint stencil_back_writemask;
bool polygon_offset_fill;
GLfloat polygon_offset_factor;
GLfloat polygon_offset_units;
bool sample_alpha_to_coverage;
bool sample_coverage;
GLclampf sample_coverage_value;
bool sample_coverage_invert;
bool dither;
GLfloat line_width;
GLenum generate_mipmap_hint;
GLenum fragment_shader_derivative_hint;
float z_near;
float z_far;
GLint scissor_x;
GLint scissor_y;
GLsizei scissor_width;
GLsizei scissor_height;
bool pack_reverse_row_order;
};
} // namespace gles2
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_

File diff suppressed because it is too large Load Diff

@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_COMMAND_BUFFER_SERVICE_VERTEX_ATTRIB_MANAGER_H_
#define GPU_COMMAND_BUFFER_SERVICE_VERTEX_ATTRIB_MANAGER_H_
#include <list>
#include "base/logging.h"
#include "base/memory/ref_counted.h"
@ -298,3 +301,6 @@ class GPU_EXPORT VertexAttribManager :
} // namespace gles2
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_VERTEX_ATTRIB_MANAGER_H_

@ -34,6 +34,8 @@
'command_buffer/service/common_decoder.h',
'command_buffer/service/context_group.h',
'command_buffer/service/context_group.cc',
'command_buffer/service/context_state.h',
'command_buffer/service/context_state.cc',
'command_buffer/service/feature_info.h',
'command_buffer/service/feature_info.cc',
'command_buffer/service/framebuffer_manager.h',