Browse Source

libobs: Implement BorderColor sampler state value

jp9000 9 years ago
parent
commit
f6728189f5
2 changed files with 22 additions and 10 deletions
  1. 19 8
      libobs/graphics/effect-parser.c
  2. 3 2
      libobs/graphics/shader-parser.c

+ 19 - 8
libobs/graphics/effect-parser.c

@@ -396,7 +396,8 @@ static int ep_parse_sampler_state_item(struct effect_parser *ep,
 		struct ep_sampler *eps)
 {
 	int ret;
-	char *state = NULL, *value = NULL;
+	char *state = NULL;
+	struct dstr value = {0};
 
 	ret = cf_next_name(&ep->cfp, &state, "state name", ";");
 	if (ret != PARSE_SUCCESS) goto fail;
@@ -404,19 +405,29 @@ static int ep_parse_sampler_state_item(struct effect_parser *ep,
 	ret = cf_next_token_should_be(&ep->cfp, "=", ";", NULL);
 	if (ret != PARSE_SUCCESS) goto fail;
 
-	ret = cf_next_name(&ep->cfp, &value, "value name", ";");
-	if (ret != PARSE_SUCCESS) goto fail;
+	for (;;) {
+		const char *cur_str;
 
-	ret = cf_next_token_should_be(&ep->cfp, ";", ";", NULL);
-	if (ret != PARSE_SUCCESS) goto fail;
+		if (!cf_next_valid_token(&ep->cfp))
+			return PARSE_EOF;
+
+		cur_str = ep->cfp.cur_token->str.array;
+		if (*cur_str == ';')
+			break;
+
+		dstr_ncat(&value, cur_str, ep->cfp.cur_token->str.len);
+	}
+
+	if (value.len) {
+		da_push_back(eps->states, &state);
+		da_push_back(eps->values, &value.array);
+	}
 
-	da_push_back(eps->states, &state);
-	da_push_back(eps->values, &value);
 	return ret;
 
 fail:
 	bfree(state);
-	bfree(value);
+	dstr_free(&value);
 	return ret;
 }
 

+ 3 - 2
libobs/graphics/shader-parser.c

@@ -112,8 +112,9 @@ void shader_sampler_convert(struct shader_sampler *ss,
 			info->address_w = get_address_mode(value);
 		else if (astrcmpi(state, "MaxAnisotropy") == 0)
 			info->max_anisotropy = (int)strtol(value, NULL, 10);
-		/*else if (astrcmpi(state, "BorderColor") == 0)
-			// TODO */
+		else if (astrcmpi(state, "BorderColor") == 0)
+			info->border_color = (*value == '#') ?
+				strtol(value + 1, NULL, 16) : 0;
 	}
 }