Commit b3708213 authored by Dylan Baker's avatar Dylan Baker
Browse files

gen_uniform_initializer_tests templates: minor cleanups and refactors



This patch changes some of the implementation details of the templates.
These can be changes can be broken down into two types,
using mako features:
- converting from ${'{}.{}'.format(a, b)} to ${a}.${b}

making the code more pythonic and less C-like
Signed-off-by: default avatarDylan Baker <dylanx.c.baker@intel.com>
parent f18dc953
[require]
GLSL >= ${"{0}.{1}".format(major, minor)}
GLSL >= ${major}.${minor}
[vertex shader]
......@@ -10,17 +10,17 @@ void main()
[fragment shader]
% for (type, name, value) in type_list:
const ${type} c${name} = ${value};
% for type_, name, value in type_list:
const ${type_} c${name} = ${value};
% endfor
% for (type, name, value) in type_list:
uniform ${type} ${name} = c${name};
% for type_, name, value in type_list:
uniform ${type_} ${name} = c${name};
% endfor
void main()
{
if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
if (${" && ".join('{0} == {1}'.format(n, v) for _, n, v in type_list)}) {
gl_FragColor = vec4(0, 1, 0, 1);
} else {
gl_FragColor = vec4(1, 0, 0, 1);
......
<%!
def constructor(type, values):
return "{0}({1})".format(type, ", ".join(values))
%>[require]
GLSL >= ${"{0}.{1}".format(major, minor)}
[require]
GLSL >= ${major}.${minor}
[vertex shader]
......@@ -14,13 +10,15 @@ void main()
[fragment shader]
% for (type, name, value) in type_list:
uniform ${type} ${name} = ${value};
% for type_, name, value in type_list:
uniform ${type_} ${name} = ${value};
% endfor
void main()
{
if (${"\n && ".join('{0} == {1}'.format(type_list[i][1], constructor(type_list[i][0], api_types[i][2])) for i in range(1, len(type_list) - 1))}) {
## This is a little bit complex too look at, but it's actually pretty simple.
## What it does is use the name and type values from type_list, but the values from api_types
if (${' && '.join('{0} == {1}({2})'.format(n, t, ', '.join(api_types[i][2])) for i, (t, n, _) in enumerate(type_list[1:-1], start=1))}) {
gl_FragColor = vec4(0, 1, 0, 1);
} else {
gl_FragColor = vec4(1, 0, 0, 1);
......@@ -28,7 +26,7 @@ void main()
}
[test]
% for (api_type, name, values) in api_types:
% for api_type, name, values in api_types:
uniform ${api_type} ${name} ${" ".join(values)}
% endfor
draw rect -1 -1 2 2
......
[require]
GLSL >= ${"{0}.{1}".format(major, minor)}
GLSL >= ${major}.${minor}
[vertex shader]
% for (type, name, value) in type_list:
uniform ${type} ${name} = ${value};
% for type_, name, value in type_list:
uniform ${type_} ${name} = ${value};
% endfor
void main()
......@@ -14,13 +14,13 @@ void main()
[fragment shader]
% for (type, name, value) in type_list:
uniform ${type} ${name};
% for type_, name, value in type_list:
uniform ${type_} ${name};
% endfor
void main()
{
if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
gl_FragColor = vec4(0, 1, 0, 1);
} else {
gl_FragColor = vec4(1, 0, 0, 1);
......
[require]
GLSL >= ${"{0}.{1}".format(major, minor)}
GLSL >= ${major}.${minor}
[vertex shader]
......@@ -10,13 +10,13 @@ void main()
[fragment shader]
% for (type, name, value) in type_list:
uniform ${type} ${name} = ${value};
% for type_, name, value in type_list:
uniform ${type_} ${name} = ${value};
% endfor
void main()
{
if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
gl_FragColor = vec4(0, 1, 0, 1);
} else {
gl_FragColor = vec4(1, 0, 0, 1);
......
[require]
GLSL >= ${"{0}.{1}".format(major, minor)}
GLSL >= ${major}.${minor}
[vertex shader]
varying vec4 color;
% for (type, name, value) in type_list:
const ${type} c${name} = ${value};
% for type_, name, value in type_list:
const ${type_} c${name} = ${value};
% endfor
% for (type, name, value) in type_list:
uniform ${type} ${name} = c${name};
% for type_, name, value in type_list:
uniform ${type_} ${name} = c${name};
% endfor
void main()
{
if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
color = vec4(0, 1, 0, 1);
} else {
color = vec4(1, 0, 0, 1);
......
<%!
def constructor(type, values):
return "{0}({1})".format(type, ", ".join(values))
%>[require]
GLSL >= ${"{0}.{1}".format(major, minor)}
[require]
GLSL >= ${major}.${minor}
[vertex shader]
varying vec4 color;
% for (type, name, value) in type_list:
uniform ${type} ${name} = ${value};
% for type_, name, value in type_list:
uniform ${type_} ${name} = ${value};
% endfor
void main()
{
if (${"\n && ".join('{0} == {1}'.format(type_list[i][1], constructor(type_list[i][0], api_types[i][2])) for i in range(1, len(type_list) - 1))}) {
## This is a little bit complex too look at, but it's actually pretty simple.
## What it does is use the name and type values from type_list, but the values from api_types
if (${' && '.join('{0} == {1}({2})'.format(n, t, ', '.join(api_types[i][2])) for i, (t, n, _) in enumerate(type_list[1:-1], start=1))}) {
color = vec4(0, 1, 0, 1);
} else {
color = vec4(1, 0, 0, 1);
......@@ -32,7 +30,7 @@ void main()
}
[test]
% for (api_type, name, values) in api_types:
% for api_type, name, values in api_types:
uniform ${api_type} ${name} ${" ".join(values)}
% endfor
draw rect -1 -1 2 2
......
[require]
GLSL >= ${"{0}.{1}".format(major, minor)}
GLSL >= ${major}.${minor}
[vertex shader]
varying vec4 color;
% for (type, name, value) in type_list:
uniform ${type} ${name};
% for type_, name, _ in type_list:
uniform ${type_} ${name};
% endfor
void main()
{
if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
color = vec4(0, 1, 0, 1);
} else {
color = vec4(1, 0, 0, 1);
......@@ -22,8 +22,8 @@ void main()
[fragment shader]
varying vec4 color;
% for (type, name, value) in type_list:
uniform ${type} ${name} = ${value};
% for type_, name, value in type_list:
uniform ${type_} ${name} = ${value};
% endfor
void main()
......
[require]
GLSL >= ${"{0}.{1}".format(major, minor)}
GLSL >= ${major}.${minor}
[vertex shader]
varying vec4 color;
% for (type, name, value) in type_list:
uniform ${type} ${name} = ${value};
% for type_, name, value in type_list:
uniform ${type_} ${name} = ${value};
% endfor
void main()
{
if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
color = vec4(0, 1, 0, 1);
} else {
color = vec4(1, 0, 0, 1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment