summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/builtin_function.cpp8
-rw-r--r--src/glsl/builtins/110/fract8
-rw-r--r--src/glsl/ir.cpp2
-rw-r--r--src/glsl/ir.h1
-rw-r--r--src/glsl/ir_constant_expression.cpp18
5 files changed, 29 insertions, 8 deletions
diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp
index b7dbc6b34f5..30ba6a52677 100644
--- a/src/glsl/builtin_function.cpp
+++ b/src/glsl/builtin_function.cpp
@@ -781,22 +781,22 @@ static const char *builtins_110_fract = {
" (signature float\n"
" (parameters\n"
" (declare (in) float x))\n"
- " ((return (expression float - (var_ref x) (expression float floor (var_ref x))))))\n"
+ " ((return (expression float fract (var_ref x)))))\n"
"\n"
" (signature vec2\n"
" (parameters\n"
" (declare (in) vec2 x))\n"
- " ((return (expression vec2 - (var_ref x) (expression vec2 floor (var_ref x))))))\n"
+ " ((return (expression vec2 fract (var_ref x)))))\n"
"\n"
" (signature vec3\n"
" (parameters\n"
" (declare (in) vec3 x))\n"
- " ((return (expression vec3 - (var_ref x) (expression vec3 floor (var_ref x))))))\n"
+ " ((return (expression vec3 fract (var_ref x)))))\n"
"\n"
" (signature vec4\n"
" (parameters\n"
" (declare (in) vec4 x))\n"
- " ((return (expression vec4 - (var_ref x) (expression vec4 floor (var_ref x))))))\n"
+ " ((return (expression vec4 fract (var_ref x)))))\n"
"))\n"
"\n"
};
diff --git a/src/glsl/builtins/110/fract b/src/glsl/builtins/110/fract
index 46741bb3cb4..3f0763d1b3e 100644
--- a/src/glsl/builtins/110/fract
+++ b/src/glsl/builtins/110/fract
@@ -2,21 +2,21 @@
(signature float
(parameters
(declare (in) float x))
- ((return (expression float - (var_ref x) (expression float floor (var_ref x))))))
+ ((return (expression float fract (var_ref x)))))
(signature vec2
(parameters
(declare (in) vec2 x))
- ((return (expression vec2 - (var_ref x) (expression vec2 floor (var_ref x))))))
+ ((return (expression vec2 fract (var_ref x)))))
(signature vec3
(parameters
(declare (in) vec3 x))
- ((return (expression vec3 - (var_ref x) (expression vec3 floor (var_ref x))))))
+ ((return (expression vec3 fract (var_ref x)))))
(signature vec4
(parameters
(declare (in) vec4 x))
- ((return (expression vec4 - (var_ref x) (expression vec4 floor (var_ref x))))))
+ ((return (expression vec4 fract (var_ref x)))))
))
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 60ee36d17cb..42578425839 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -72,6 +72,7 @@ ir_expression::get_num_operands(ir_expression_operation op)
1, /* ir_unop_trunc */
1, /* ir_unop_ceil */
1, /* ir_unop_floor */
+ 1, /* ir_unop_fract */
1, /* ir_unop_sin */
1, /* ir_unop_cos */
@@ -137,6 +138,7 @@ static const char *const operator_strs[] = {
"trunc",
"ceil",
"floor",
+ "fract",
"sin",
"cos",
"dFdx",
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 00b0076c172..f47813786b5 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -528,6 +528,7 @@ enum ir_expression_operation {
ir_unop_trunc,
ir_unop_ceil,
ir_unop_floor,
+ ir_unop_fract,
/*@}*/
/**
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index c6348ac4347..548217cddd9 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -187,6 +187,24 @@ ir_constant_visitor::visit(ir_expression *ir)
}
break;
+ case ir_unop_fract:
+ for (c = 0; c < ir->operands[0]->type->components(); c++) {
+ switch (ir->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = 0;
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = 0;
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]);
+ break;
+ default:
+ assert(0);
+ }
+ }
+ break;
+
case ir_unop_neg:
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->type->base_type) {