static CoglBool _cogl_pipeline_fragend_fixed_add_layer (CoglPipeline *pipeline, CoglPipelineLayer *layer, unsigned long layers_difference) { CoglTextureUnit *unit = _cogl_get_texture_unit (_cogl_pipeline_layer_get_unit_index (layer)); int unit_index = unit->index; int n_rgb_func_args; int n_alpha_func_args; _COGL_GET_CONTEXT (ctx, FALSE); /* XXX: Beware that since we are changing the active texture unit we * must make sure we don't call into other Cogl components that may * temporarily bind texture objects to query/modify parameters since * they will end up binding texture unit 1. See * _cogl_bind_gl_texture_transient for more details. */ _cogl_set_active_texture_unit (unit_index); if (G_UNLIKELY (unit_index >= get_max_texture_units ())) { _cogl_disable_texture_unit (unit_index); /* TODO: although this isn't considered an error that * warrants falling back to a different backend we * should print a warning here. */ return TRUE; } /* Handle enabling or disabling the right texture type */ if (layers_difference & COGL_PIPELINE_LAYER_STATE_TEXTURE_TYPE) { CoglTextureType texture_type = _cogl_pipeline_layer_get_texture_type (layer); GLenum gl_target; switch (texture_type) { case COGL_TEXTURE_TYPE_2D: gl_target = GL_TEXTURE_2D; break; case COGL_TEXTURE_TYPE_3D: gl_target = GL_TEXTURE_3D; break; case COGL_TEXTURE_TYPE_RECTANGLE: gl_target = GL_TEXTURE_RECTANGLE_ARB; break; } _cogl_set_active_texture_unit (unit_index); /* The common GL code handles binding the right texture so we just need to handle enabling and disabling it */ if (unit->enabled_gl_target != gl_target) { /* Disable the previous target if it's still enabled */ if (unit->enabled_gl_target) GE (ctx, glDisable (unit->enabled_gl_target)); /* Enable the new target */ if (!G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_TEXTURING))) { GE (ctx, glEnable (gl_target)); unit->enabled_gl_target = gl_target; } } } else { /* Even though there may be no difference between the last flushed * texture state and the current layers texture state it may be that the * texture unit has been disabled for some time so we need to assert that * it's enabled now. */ if (!G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_TEXTURING)) && unit->enabled_gl_target == 0) { _cogl_set_active_texture_unit (unit_index); GE (ctx, glEnable (unit->gl_target)); unit->enabled_gl_target = unit->gl_target; } } if (layers_difference & COGL_PIPELINE_LAYER_STATE_COMBINE) { CoglPipelineLayer *authority = _cogl_pipeline_layer_get_authority (layer, COGL_PIPELINE_LAYER_STATE_COMBINE); CoglPipelineLayerBigState *big_state = authority->big_state; GLenum sources[3]; GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE)); /* Set the combiner functions... */ GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, big_state->texture_combine_rgb_func)); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, big_state->texture_combine_alpha_func)); /* * Setup the function arguments... */ /* For the RGB components... */ n_rgb_func_args = _cogl_get_n_args_for_combine_func (big_state->texture_combine_rgb_func); translate_sources (pipeline, n_rgb_func_args, big_state->texture_combine_rgb_src, sources); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, sources[0])); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, big_state->texture_combine_rgb_op[0])); if (n_rgb_func_args > 1) { GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, sources[1])); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB, big_state->texture_combine_rgb_op[1])); } if (n_rgb_func_args > 2) { GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_RGB, sources[2])); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_RGB, big_state->texture_combine_rgb_op[2])); } /* For the Alpha component */ n_alpha_func_args = _cogl_get_n_args_for_combine_func (big_state->texture_combine_alpha_func); translate_sources (pipeline, n_alpha_func_args, big_state->texture_combine_alpha_src, sources); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, sources[0])); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, big_state->texture_combine_alpha_op[0])); if (n_alpha_func_args > 1) { GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, sources[1])); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, big_state->texture_combine_alpha_op[1])); } if (n_alpha_func_args > 2) { GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_ALPHA, sources[2])); GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, big_state->texture_combine_alpha_op[2])); } } if (layers_difference & COGL_PIPELINE_LAYER_STATE_COMBINE_CONSTANT) { CoglPipelineLayer *authority = _cogl_pipeline_layer_get_authority (layer, COGL_PIPELINE_LAYER_STATE_COMBINE_CONSTANT); CoglPipelineLayerBigState *big_state = authority->big_state; GE (ctx, glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, big_state->texture_combine_constant)); } return TRUE; }
void GlContext::initialize_bound_texture_arrays() { auto max_texture_units = get_max_texture_units(); m_bound_2d_textures.resize(max_texture_units); m_bound_2d_array_textures.resize(max_texture_units); }