Home | History | Annotate | Download | only in scripts
      1 import sys
      2 import string
      3 from genutil import *
      4 
      5 # Templates
      6 
      7 INVALID_TEXTURE_FUNC_TEMPLATE = """
      8 case ${{NAME}}
      9 	expect compile_fail
     10 	values {}
     11 	version 300 es
     12 
     13 	both ""
     14 		#version 300 es
     15 		precision mediump float;
     16 		${DECLARATIONS}
     17 		uniform mediump ${{SAMPLERTYPE}} s;
     18 
     19 		void main()
     20 		{
     21 			${SETUP}
     22 			${POSITION_FRAG_COLOR} = vec4(${{LOOKUP}});
     23 			${OUTPUT}
     24 		}
     25 	""
     26 end
     27 """[1:-1]
     28 
     29 # Classes
     30 
     31 def getValueExpr (argType):
     32 	return "%s(0)" % argType
     33 
     34 class InvalidTexFuncCase(ShaderCase):
     35 	def __init__(self, funcname, args):
     36 		self.name		= string.join([s.lower() for s in [funcname] + args], "_")
     37 		self.funcname	= funcname
     38 		self.args		= args
     39 
     40 	def __str__(self):
     41 		samplerType	= self.args[0]
     42 
     43 		lookup = self.funcname + "(s"
     44 		for arg in self.args[1:]:
     45 			lookup += ", %s" % getValueExpr(arg)
     46 		lookup += ")"
     47 
     48 		params = { "NAME": self.name, "SAMPLERTYPE": samplerType, "LOOKUP": lookup }
     49 		return fillTemplate(INVALID_TEXTURE_FUNC_TEMPLATE, params)
     50 
     51 # Invalid lookup cases
     52 # \note Does not include cases that don't make sense
     53 
     54 INVALID_TEX_FUNC_CASES = [
     55 	# texture
     56 	InvalidTexFuncCase("texture",				["sampler3DShadow",	"vec4"]),
     57 	InvalidTexFuncCase("texture",				["sampler2DArrayShadow", "vec4", "float"]),
     58 
     59 	# textureProj
     60 	InvalidTexFuncCase("textureProj",			["samplerCube", "vec4"]),
     61 	InvalidTexFuncCase("textureProj",			["isamplerCube", "vec4"]),
     62 	InvalidTexFuncCase("textureProj",			["usamplerCube", "vec4"]),
     63 	InvalidTexFuncCase("textureProj",			["samplerCube", "vec4", "float"]),
     64 	InvalidTexFuncCase("textureProj",			["isamplerCube", "vec4", "float"]),
     65 	InvalidTexFuncCase("textureProj",			["usamplerCube", "vec4", "float"]),
     66 	InvalidTexFuncCase("textureProj",			["sampler2DArrayShadow", "vec4"]),
     67 	InvalidTexFuncCase("textureProj",			["sampler2DArrayShadow", "vec4", "float"]),
     68 
     69 	# textureLod
     70 	InvalidTexFuncCase("textureLod",			["samplerCubeShadow", "vec4", "float"]),
     71 	InvalidTexFuncCase("textureLod",			["sampler2DArrayShadow", "vec4", "float"]),
     72 
     73 	# textureOffset
     74 	InvalidTexFuncCase("textureOffset",			["samplerCube", "vec3", "ivec2"]),
     75 	InvalidTexFuncCase("textureOffset",			["isamplerCube", "vec3", "ivec2"]),
     76 	InvalidTexFuncCase("textureOffset",			["usamplerCube", "vec3", "ivec2"]),
     77 	InvalidTexFuncCase("textureOffset",			["samplerCube", "vec3", "ivec3"]),
     78 	InvalidTexFuncCase("textureOffset",			["isamplerCube", "vec3", "ivec3"]),
     79 	InvalidTexFuncCase("textureOffset",			["usamplerCube", "vec3", "ivec3"]),
     80 	InvalidTexFuncCase("textureOffset",			["samplerCube", "vec3", "ivec2", "float"]),
     81 	InvalidTexFuncCase("textureOffset",			["samplerCube", "vec3", "ivec3", "float"]),
     82 	InvalidTexFuncCase("textureOffset",			["sampler2DArray", "vec3", "ivec3"]),
     83 	InvalidTexFuncCase("textureOffset",			["sampler2DArray", "vec3", "ivec3", "float"]),
     84 	InvalidTexFuncCase("textureOffset",			["samplerCubeShadow", "vec4", "ivec2"]),
     85 	InvalidTexFuncCase("textureOffset",			["samplerCubeShadow", "vec4", "ivec3"]),
     86 	InvalidTexFuncCase("textureOffset",			["sampler2DArrayShadow", "vec4", "ivec2"]),
     87 	InvalidTexFuncCase("textureOffset",			["sampler2DArrayShadow", "vec4", "ivec2", "float"]),
     88 
     89 	# texelFetch
     90 	InvalidTexFuncCase("texelFetch",			["samplerCube", "ivec3", "int"]),
     91 	InvalidTexFuncCase("texelFetch",			["isamplerCube", "ivec3", "int"]),
     92 	InvalidTexFuncCase("texelFetch",			["usamplerCube", "ivec3", "int"]),
     93 	InvalidTexFuncCase("texelFetch",			["sampler2DShadow", "ivec2", "int"]),
     94 	InvalidTexFuncCase("texelFetch",			["samplerCubeShadow", "ivec3", "int"]),
     95 	InvalidTexFuncCase("texelFetch",			["sampler2DArrayShadow", "ivec3", "int"]),
     96 
     97 	# texelFetchOffset
     98 	InvalidTexFuncCase("texelFetch",			["samplerCube", "ivec3", "int", "ivec3"]),
     99 	InvalidTexFuncCase("texelFetch",			["sampler2DShadow", "ivec2", "int", "ivec2"]),
    100 	InvalidTexFuncCase("texelFetch",			["samplerCubeShadow", "ivec3", "int", "ivec3"]),
    101 	InvalidTexFuncCase("texelFetch",			["sampler2DArrayShadow", "ivec3", "int", "ivec3"]),
    102 
    103 	# textureProjOffset
    104 	InvalidTexFuncCase("textureProjOffset",		["samplerCube", "vec4", "ivec2"]),
    105 	InvalidTexFuncCase("textureProjOffset",		["samplerCube", "vec4", "ivec3"]),
    106 	InvalidTexFuncCase("textureProjOffset",		["samplerCubeShadow", "vec4", "ivec3"]),
    107 	InvalidTexFuncCase("textureProjOffset",		["sampler2DArrayShadow", "vec4", "ivec2"]),
    108 	InvalidTexFuncCase("textureProjOffset",		["sampler2DArrayShadow", "vec4", "ivec3"]),
    109 
    110 	# textureLodOffset
    111 	InvalidTexFuncCase("textureLodOffset",		["samplerCube", "vec3", "float", "ivec2"]),
    112 	InvalidTexFuncCase("textureLodOffset",		["samplerCube", "vec3", "float", "ivec3"]),
    113 	InvalidTexFuncCase("textureLodOffset",		["samplerCubeShadow", "vec3", "float", "ivec3"]),
    114 	InvalidTexFuncCase("textureLodOffset",		["sampler2DArrayShadow", "vec3", "float", "ivec2"]),
    115 	InvalidTexFuncCase("textureLodOffset",		["sampler2DArrayShadow", "vec3", "float", "ivec3"]),
    116 
    117 	# textureProjLod
    118 	InvalidTexFuncCase("textureProjLod",		["samplerCube", "vec4", "float"]),
    119 	InvalidTexFuncCase("textureProjLod",		["sampler2DArray", "vec4", "float"]),
    120 	InvalidTexFuncCase("textureProjLod",		["sampler2DArrayShadow", "vec4", "float"]),
    121 
    122 	# textureGrad
    123 	InvalidTexFuncCase("textureGrad",			["sampler2DArray", "vec3", "vec3", "vec3"]),
    124 
    125 	# textureGradOffset
    126 	InvalidTexFuncCase("textureGradOffset",		["samplerCube", "vec3", "vec3", "vec3", "ivec2"]),
    127 	InvalidTexFuncCase("textureGradOffset",		["samplerCube", "vec3", "vec3", "vec3", "ivec3"]),
    128 	InvalidTexFuncCase("textureGradOffset",		["samplerCubeShadow", "vec4", "vec3", "vec3", "ivec2"]),
    129 	InvalidTexFuncCase("textureGradOffset",		["samplerCubeShadow", "vec4", "vec3", "vec3", "ivec3"]),
    130 
    131 	# textureProjGrad
    132 	InvalidTexFuncCase("textureProjGrad",		["samplerCube", "vec4", "vec3", "vec3"]),
    133 	InvalidTexFuncCase("textureProjGrad",		["sampler2DArray", "vec4", "vec2", "vec2"]),
    134 
    135 	# textureProjGradOffset
    136 	InvalidTexFuncCase("textureProjGradOffset",	["samplerCube", "vec4", "vec3", "vec3", "ivec2"]),
    137 	InvalidTexFuncCase("textureProjGradOffset",	["samplerCube", "vec4", "vec3", "vec3", "ivec3"]),
    138 	InvalidTexFuncCase("textureProjGradOffset",	["sampler2DArray", "vec4", "vec2", "vec2", "ivec2"]),
    139 	InvalidTexFuncCase("textureProjGradOffset",	["sampler2DArray", "vec4", "vec2", "vec2", "ivec3"])
    140 ]
    141 
    142 if __name__ == "__main__":
    143 	print "Generating shader case files."
    144 	writeAllCases("invalid_texture_functions.test", INVALID_TEX_FUNC_CASES)
    145