summaryrefslogtreecommitdiff
path: root/GLESv2/yagl_glsl_state.c
diff options
context:
space:
mode:
Diffstat (limited to 'GLESv2/yagl_glsl_state.c')
-rw-r--r--GLESv2/yagl_glsl_state.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/GLESv2/yagl_glsl_state.c b/GLESv2/yagl_glsl_state.c
index c6e9f48..86190ec 100644
--- a/GLESv2/yagl_glsl_state.c
+++ b/GLESv2/yagl_glsl_state.c
@@ -408,8 +408,11 @@ void yagl_glsl_state_add_sampler_ExternalOES(struct yagl_glsl_state *state,
sampler.name = strdup(str);
sampler.location = YAGL_GLSL_SAMPLER_LOCATION_UNKNOWN;
sampler.value = 0; // GL spec predefines uniform value as 0
+ sampler.count = YAGL_GLSL_SAMPLER_DEFAULT_COUNT; // real count provided by yagl_glsl_state_set_last_sampler_array_count
sampler.replaced_tex2d = YAGL_GLSL_SAMPLER_VALUE_UNKNOWN;
yagl_vector_push_back(&state->samplers_ExternalOES, &sampler);
+
+ state->last_declared_sampler_externaloes = 1;
}
void yagl_glsl_state_add_sampler_2D(struct yagl_glsl_state *state,
@@ -419,8 +422,31 @@ void yagl_glsl_state_add_sampler_2D(struct yagl_glsl_state *state,
sampler.name = strdup(str);
sampler.location = YAGL_GLSL_SAMPLER_LOCATION_UNKNOWN;
sampler.value = 0; // GL spec predefines uniform value as 0
+ sampler.count = YAGL_GLSL_SAMPLER_DEFAULT_COUNT; // real count provided by yagl_glsl_state_set_last_sampler_array_count
sampler.replaced_tex2d = YAGL_GLSL_SAMPLER_VALUE_UNKNOWN;
yagl_vector_push_back(&state->samplers_2D, &sampler);
+
+ state->last_declared_sampler_externaloes = 0;
+}
+
+void yagl_glsl_state_set_last_sampler_array_count(struct yagl_glsl_state *state, int count)
+{
+ assert(state->last_declared_sampler_externaloes != -1);
+
+ struct yagl_vector *samplers = NULL;
+ if (state->last_declared_sampler_externaloes) {
+ samplers = &state->samplers_ExternalOES;
+ } else {
+ samplers = &state->samplers_2D;
+ }
+
+ int samplers_size = yagl_vector_size(samplers);
+ assert(samplers_size > 0);
+ struct yagl_glsl_sampler *samplers_data = (struct yagl_glsl_sampler *)yagl_vector_data(samplers);
+ samplers_data += samplers_size - 1;
+ samplers_data->count = count;
+
+ state->last_declared_sampler_externaloes = -1;
}
void yagl_glsl_state_pp_add_define_string(struct yagl_glsl_state *state,
@@ -583,6 +609,8 @@ int yagl_glsl_state_pp_is_condition_completed(struct yagl_glsl_state *state)
void yagl_glsl_state_pp_condition_parse_start(struct yagl_glsl_state *state)
{
+ assert(!state->pp_condition_parse_started);
+
// initialize expression stack and operation stack for RPN
memset(state->pp_exprs, 0, sizeof(struct yagl_glsl_pp_expr) * YAGL_GLSL_PP_EXPRESSION_STACK_SIZE);
state->pp_current_expr = 0;
@@ -785,7 +813,8 @@ static inline int yagl_glsl_pp_expr_op_is_unary(yagl_glsl_pp_expr_op op)
}
}
-yagl_glsl_pp_condition_status yagl_glsl_state_pp_condition_resolve(struct yagl_glsl_state *state)
+yagl_glsl_pp_condition_status yagl_glsl_state_pp_condition_resolve(struct yagl_glsl_state *state,
+ int *resolution_value)
{
struct yagl_glsl_pp_token res_stack[YAGL_GLSL_PP_EXPRESSION_STACK_SIZE];
int res_cur = 0;
@@ -794,6 +823,8 @@ yagl_glsl_pp_condition_status yagl_glsl_state_pp_condition_resolve(struct yagl_g
yagl_glsl_pp_condition_status result = yagl_glsl_pp_condition_not_met;
YAGL_LOG_FUNC_SET(yagl_glsl_state_pp_condition_resolve);
+ assert(state->pp_condition_parse_started);
+
// empty op stack into expression stack
while (state->pp_current_op > 0) {
assert(state->pp_current_expr < YAGL_GLSL_PP_EXPRESSION_STACK_SIZE);
@@ -837,7 +868,29 @@ yagl_glsl_pp_condition_status yagl_glsl_state_pp_condition_resolve(struct yagl_g
// there should be only one resolution on stack remaining - the result
assert(res_cur == 1);
- result = (res_stack[res_cur - 1].value > 0 ? yagl_glsl_pp_condition_met : yagl_glsl_pp_condition_not_met);
+
+ // in some cases resolution can be just a preprocessor macro - try resolving it
+ int result_value = 0;
+ if (res_stack[res_cur - 1].macro != NULL) {
+ char* define_resolution = NULL; // should stay null, but if it doesn't it's syntax error
+ yagl_glsl_state_pp_resolve_define(state, res_stack[res_cur - 1].macro, &define_resolution, &result_value);
+ if (define_resolution != NULL) {
+ // error - macro did not become a constant, cannot evaluate result
+ YAGL_LOG_ERROR("Expression resolution error - macro %s did not evaluate to integer constant", res_stack[res_cur - 1].macro);
+ result = yagl_glsl_pp_condition_error;
+ yagl_free(define_resolution);
+ goto clean;
+ }
+ } else {
+ result_value = res_stack[res_cur - 1].value;
+ }
+
+ // determine final result (and pass the value if it's needed)
+ result = (result_value > 0 ? yagl_glsl_pp_condition_met : yagl_glsl_pp_condition_not_met);
+ if (resolution_value != NULL) {
+ *resolution_value = result_value;
+ YAGL_LOG_TRACE("Expression resolution value: %d", *resolution_value);
+ }
clean:
// cleanup