Commits

Jason McKesson committed a714bc4

Enum validation against actual GL enumerators.
Also, more enums added to some core extensions.

Comments (0)

Files changed (9)

 local lfs = require "lfs"
 local save = require "_StableSaveTable"
+require "_EnumProc"
 
 --[[
 Copies the stuff from basic_dump to function_enums, but does so in a way that preserves the function_enum data entered thus far.

RegularizeFunctionEnums.lua

 local lfs = require "lfs"
 local save = require "_StableSaveTable"
-
+require "_EnumProc"
 
 
 local filename = ...

ValidateEnums.lua

+local lfs = require "lfs"
+local save = require "_StableSaveTable"
+require "_EnumProc"
+
+local specpathname = "glLoadGen/glspecs/glspec.lua"
+assert(lfs.attributes(specpathname, "mode") == "file",
+	"You either have not place glLoadGen in the glLoadGen directory, or you are running this tool from the wrong directory.")
+	
+local validEnums = {}
+	
+do
+	local spec = dofile(specpathname)
+
+	for _, enum in ipairs(spec.enumerations) do
+		validEnums[enum.name] = enum
+	end
+end
+
+local function printf(str, ...)
+	print(str:format(...))
+end
+
+local VerifyEnum = {}
+
+function VerifyEnum.range(enumTbl)
+	if(not validEnums[enumTbl.start]) then
+		return false, enumTbl.start
+	end
+	
+	if(enumTbl.maxQuery) then
+		if(not validEnums[enumTbl.maxQuery]) then
+			return false, enumTbl.maxQuery
+		end
+	end
+	
+	return true, nil
+end
+
+function VerifyEnum.include(enumTbl)
+	return true, nil --Don't bother validating across files.
+end
+
+local function VerifyFile(fullpathname)
+	local status, tbl = pcall(dofile, fullpathname)
+	
+	if(not status) then
+		print("Error processing " .. fullpathname)
+		print(tbl)
+	else
+		for funcName, funcData in pairs(tbl) do
+			for paramName, enumList in pairs(funcData) do
+				for _, enumName in ipairs(enumList) do
+					if(type(enumName) == "string") then
+						if(not validEnums[enumName]) then
+							printf("File %s: invalid enum %s in function.param %s.%s.", fullpathname, enumName, funcName, paramName)
+						end
+					else
+						if(not VerifyEnum[enumName._type]) then
+							printf("File %s: invalid enum-like specification in function.param %s.%s.", fullpathname, funcName, paramName)
+						else
+							local valid, badEnum = VerifyEnum[enumName._type](enumName)
+							if(not valid) then
+								printf("File %s: invalid enum %s in function.param %s.%s.", fullpathname, badEnum, funcName, paramName)
+							end
+						end
+					end
+				end
+			end
+		end
+	end
+end
+
+local filename = ...
+
+local funcDir = "function_enums/"
+
+if(filename) then
+	VerifyFile(filename)
+else
+	for path in lfs.dir(funcDir) do
+		local fullpathname = funcDir .. path;
+		if(path:match("%.lua$") and lfs.attributes(fullpathname, "mode") == "file") then
+			VerifyFile(fullpathname)
+		end
+	end
+end
+
+
+local inclMetatable =
+{
+	__eq = function(lhs, rhs)
+		return (lhs.fileName == rhs.fileName) and
+			(lhs.funcName == rhs.funcName) and
+			(lhs.paramName == rhs.paramName)
+	end
+}
+
+local rngMetatable =
+{
+	__eq = function(lhs, rhs)
+		return (lhs.start == rhs.start) and
+			(lhs.maxQuery == rhs.maxQuery)
+	end
+}
+
+function include(targetLoc)
+	local fileName, funcName, paramName = targetLoc:match("(.+)%.(.+)%.(.+)")
+	
+	assert(fileName and paramName, "The inclusion target name " .. targetLoc
+		.. " is not properly formatted.")
+
+	local inclTbl = {
+			fileName = fileName,
+			funcName = funcName,
+			paramName = paramName,
+			_type = "include",
+		}
+	
+	setmetatable(inclTbl, inclMetatable)
+	
+	return inclTbl
+end
+
+function range(startRange, maxQuery)
+	local rngTbl = {
+		start = startRange,
+		maxQuery = maxQuery,
+		_type = "range",
+	}
+	
+	setmetatable(rngTbl, rngMetatable)
+	
+	return rngTbl
+end

_StableSaveTable.lua

 
 
+local EnumWriter = {}
+
+function EnumWriter.range(hFile, enumTbl)
+	if(enumTbl.maxQuery) then
+		hFile:write("range('", enumTbl.start, "', '", enumTbl.maxQuery, "')")
+	else
+		hFile:write("range '", enumTbl.start, "'")
+	end
+end
+
+function EnumWriter.include(hFile, enumTbl)
+	hFile:write("include '",
+		enumTbl.fileName, ".",
+		enumTbl.funcName, ".",
+		enumTbl.paramName, "'")
+end
+
 local function WriteTableToFile(outputFilename, tbl)
 	local hFile = io.open(outputFilename, "w")
 	
 			if(#funcData[paramName] ~= 0) then
 				hFile:write("\n")
 				for _, enumName in ipairs(funcData[paramName]) do
-					hFile:write("\t\t'", enumName, "',\n")
+					hFile:write("\t\t")
+					if(type(enumName) == "string") then
+						hFile:write("'", enumName, "'")
+					else
+						assert(enumName._type and EnumWriter[enumName._type])
+						EnumWriter[enumName._type](hFile, enumName)
+					end
+					hFile:write(",\n")
 				end
 				hFile:write("\t")
 			end

function_enums/ARB_base_instance.lua

 return {
 ['DrawArraysInstancedBaseInstance'] = {
-	['mode'] = {},
+	['mode'] = {
+		'POINTS',
+		'LINE_STRIP',
+		'LINE_LOOP',
+		'LINES',
+		'POLYGON',
+		'TRIANGLE_STRIP',
+		'TRIANGLE_FAN',
+		'TRIANGLES',
+		'QUAD_STRIP',
+		'QUADS',
+		'LINES_ADJACENCY',
+		'LINE_STRIP_ADJACENCY',
+		'TRIANGLES_ADJACENCY',
+		'TRIANGLE_STRIP_ADJACENCY',
+		'PATCHES',
+	},
 },
 
 ['DrawElementsInstancedBaseInstance'] = {
-	['mode'] = {},
-	['type'] = {},
+	['mode'] = {
+		'POINTS',
+		'LINE_STRIP',
+		'LINE_LOOP',
+		'LINES',
+		'POLYGON',
+		'TRIANGLE_STRIP',
+		'TRIANGLE_FAN',
+		'TRIANGLES',
+		'QUAD_STRIP',
+		'QUADS',
+		'LINES_ADJACENCY',
+		'LINE_STRIP_ADJACENCY',
+		'TRIANGLES_ADJACENCY',
+		'TRIANGLE_STRIP_ADJACENCY',
+		'PATCHES',
+	},
+	['type'] = {
+		'UNSIGNED_BYTE',
+		'UNSIGNED_SHORT',
+		'UNSIGNED_INT',
+	},
 },
 
 ['DrawElementsInstancedBaseVertexBaseInstance'] = {
-	['mode'] = {},
-	['type'] = {},
+	['mode'] = {
+		'POINTS',
+		'LINE_STRIP',
+		'LINE_LOOP',
+		'LINES',
+		'POLYGON',
+		'TRIANGLE_STRIP',
+		'TRIANGLE_FAN',
+		'TRIANGLES',
+		'QUAD_STRIP',
+		'QUADS',
+		'LINES_ADJACENCY',
+		'LINE_STRIP_ADJACENCY',
+		'TRIANGLES_ADJACENCY',
+		'TRIANGLE_STRIP_ADJACENCY',
+		'PATCHES',
+	},
+	['type'] = {
+		'UNSIGNED_BYTE',
+		'UNSIGNED_SHORT',
+		'UNSIGNED_INT',
+	},
 },
 
 }

function_enums/ARB_clear_buffer_object.lua

 return {
 ['ClearBufferData'] = {
 	['format'] = {},
-	['internalformat'] = {},
-	['target'] = {},
+	['internalformat'] = {
+		'R8',
+		'R16',
+		'R16F',
+		'R32F',
+		'R8I',
+		'R16I',
+		'R32I',
+		'R8UI',
+		'R16UI',
+		'R32UI',
+		'RG8',
+		'RG16',
+		'RG16F',
+		'RG32F',
+		'RG8I',
+		'RG16I',
+		'RG32I',
+		'RG8UI',
+		'RG16UI',
+		'RG32UI',
+		'RGB32F',
+		'RGB32I',
+		'RGB32UI',
+		'RGBA8',
+		'RGBA16',
+		'RGBA16F',
+		'RGBA32F',
+		'RGBA8I',
+		'RGBA16I',
+		'RGBA32I',
+		'RGBA8UI',
+		'RGBA16UI',
+		'RGBA32UI',
+	},
+	['target'] = {
+		'ARRAY_BUFFER',
+		'ATOMIC_COUNTER_BUFFER',
+		'COPY_READ_BUFFER',
+		'COPY_WRITE_BUFFER',
+		'DISPATCH_INDIRECT_BUFFER',
+		'DRAW_INDIRECT_BUFFER',
+		'ELEMENT_ARRAY_BUFFER',
+		'PIXEL_PACK_BUFFER',
+		'PIXEL_UNPACK_BUFFER',
+		'SHADER_STORAGE_BUFFER',
+		'TEXTURE_BUFFER',
+		'TRANSFORM_FEEDBACK_BUFFER',
+		'UNIFORM_BUFFER',
+	},
 	['type'] = {},
 },
 
 ['ClearBufferSubData'] = {
 	['format'] = {},
-	['internalformat'] = {},
-	['target'] = {},
+	['internalformat'] = {
+		'R8',
+		'R16',
+		'R16F',
+		'R32F',
+		'R8I',
+		'R16I',
+		'R32I',
+		'R8UI',
+		'R16UI',
+		'R32UI',
+		'RG8',
+		'RG16',
+		'RG16F',
+		'RG32F',
+		'RG8I',
+		'RG16I',
+		'RG32I',
+		'RG8UI',
+		'RG16UI',
+		'RG32UI',
+		'RGB32F',
+		'RGB32I',
+		'RGB32UI',
+		'RGBA8',
+		'RGBA16',
+		'RGBA16F',
+		'RGBA32F',
+		'RGBA8I',
+		'RGBA16I',
+		'RGBA32I',
+		'RGBA8UI',
+		'RGBA16UI',
+		'RGBA32UI',
+	},
+	['target'] = {
+		'ARRAY_BUFFER',
+		'ATOMIC_COUNTER_BUFFER',
+		'COPY_READ_BUFFER',
+		'COPY_WRITE_BUFFER',
+		'DISPATCH_INDIRECT_BUFFER',
+		'DRAW_INDIRECT_BUFFER',
+		'ELEMENT_ARRAY_BUFFER',
+		'PIXEL_PACK_BUFFER',
+		'PIXEL_UNPACK_BUFFER',
+		'SHADER_STORAGE_BUFFER',
+		'TEXTURE_BUFFER',
+		'TRANSFORM_FEEDBACK_BUFFER',
+		'UNIFORM_BUFFER',
+	},
 	['type'] = {},
 },
 
 ['ClearNamedBufferDataEXT'] = {
 	['format'] = {},
-	['internalformat'] = {},
+	['internalformat'] = {
+		'R8',
+		'R16',
+		'R16F',
+		'R32F',
+		'R8I',
+		'R16I',
+		'R32I',
+		'R8UI',
+		'R16UI',
+		'R32UI',
+		'RG8',
+		'RG16',
+		'RG16F',
+		'RG32F',
+		'RG8I',
+		'RG16I',
+		'RG32I',
+		'RG8UI',
+		'RG16UI',
+		'RG32UI',
+		'RGB32F',
+		'RGB32I',
+		'RGB32UI',
+		'RGBA8',
+		'RGBA16',
+		'RGBA16F',
+		'RGBA32F',
+		'RGBA8I',
+		'RGBA16I',
+		'RGBA32I',
+		'RGBA8UI',
+		'RGBA16UI',
+		'RGBA32UI',
+	},
 	['type'] = {},
 },
 
 ['ClearNamedBufferSubDataEXT'] = {
 	['format'] = {},
-	['internalformat'] = {},
+	['internalformat'] = {
+		'R8',
+		'R16',
+		'R16F',
+		'R32F',
+		'R8I',
+		'R16I',
+		'R32I',
+		'R8UI',
+		'R16UI',
+		'R32UI',
+		'RG8',
+		'RG16',
+		'RG16F',
+		'RG32F',
+		'RG8I',
+		'RG16I',
+		'RG32I',
+		'RG8UI',
+		'RG16UI',
+		'RG32UI',
+		'RGB32F',
+		'RGB32I',
+		'RGB32UI',
+		'RGBA8',
+		'RGBA16',
+		'RGBA16F',
+		'RGBA32F',
+		'RGBA8I',
+		'RGBA16I',
+		'RGBA32I',
+		'RGBA8UI',
+		'RGBA16UI',
+		'RGBA32UI',
+	},
 	['type'] = {},
 },
 

function_enums/ARB_copy_buffer.lua

 return {
 ['CopyBufferSubData'] = {
-	['readTarget'] = {},
-	['writeTarget'] = {},
+	['readTarget'] = {
+		'ARRAY_BUFFER',
+		'ATOMIC_COUNTER_BUFFER',
+		'COPY_READ_BUFFER',
+		'COPY_WRITE_BUFFER',
+		'DISPATCH_INDIRECT_BUFFER',
+		'DRAW_INDIRECT_BUFFER',
+		'ELEMENT_ARRAY_BUFFER',
+		'PIXEL_PACK_BUFFER',
+		'PIXEL_UNPACK_BUFFER',
+		'SHADER_STORAGE_BUFFER',
+		'TEXTURE_BUFFER',
+		'TRANSFORM_FEEDBACK_BUFFER',
+		'UNIFORM_BUFFER',
+	},
+	['writeTarget'] = {
+		'ARRAY_BUFFER',
+		'ATOMIC_COUNTER_BUFFER',
+		'COPY_READ_BUFFER',
+		'COPY_WRITE_BUFFER',
+		'DISPATCH_INDIRECT_BUFFER',
+		'DRAW_INDIRECT_BUFFER',
+		'ELEMENT_ARRAY_BUFFER',
+		'PIXEL_PACK_BUFFER',
+		'PIXEL_UNPACK_BUFFER',
+		'SHADER_STORAGE_BUFFER',
+		'TEXTURE_BUFFER',
+		'TRANSFORM_FEEDBACK_BUFFER',
+		'UNIFORM_BUFFER',
+	},
 },
 
 }

function_enums/Version_1_1.lua

 		'INT',
 		'UNSIGNED_INT',
 		'FLOAT',
-		'HALF',
+		'HALF_FLOAT',
 		'DOUBLE',
 		'INT_2_10_10_10_REV',
 		'UNSIGNED_INT_2_10_10_10_REV',
 		'LEFT',
 		'RIGHT',
 		'FRONT_AND_BACK',
-		'AUX0',
-		'COLOR_ATTACHMENT0',
+		range 'AUX0',
+		range 'COLOR_ATTACHMENT0',
 	},
 },
 
 
 ['GetClipPlane'] = {
 	['plane'] = {
-		'CLIP_DISTANCE0',
+		range 'CLIP_DISTANCE0',
 	},
 },
 
 		'LEFT',
 		'RIGHT',
 		'FRONT_AND_BACK',
-		'AUX0',
-		'COLOR_ATTACHMENT0',
+		range 'AUX0',
+		range 'COLOR_ATTACHMENT0',
 	},
 },