-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a mechanism to declare capability dependencies at widget/gadget G…
…etInfo (#4034) Add a mechanism to declare capability dependencies at widgets and gadgets * Through the new 'depends' field. * For now added: gl, gl4, shaders, fbo. * This makes the widgets and gadgets automatically inactive if capabilities not present. Extends the Platform module for this. * Adds Platform.check(capabilities), also Platform.gl, Platform.gl4, Platform.glHaveFBO. * These also allow testing for the features partially inside modules in a cleaner way than the current way of gl.CreateShader or similar, and it can be a central place where the tests can be improved.
- Loading branch information
Showing
8 changed files
with
75 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
if not Platform then return end | ||
local hasGL4 = false | ||
local hasGL = false | ||
local hasShaders = false | ||
local hasFBO = false | ||
local isSyncedCode = (SendToUnsynced ~= nil) | ||
|
||
local function determineCapabilities() | ||
if not gl then | ||
return | ||
end | ||
if Platform.glVendor ~= "" then | ||
hasGL = true | ||
end | ||
if gl.CreateShader and Platform.glHaveGLSL then | ||
hasShaders = true | ||
end | ||
if gl.CreateFBO then | ||
hasFBO = true | ||
end | ||
|
||
if hasFBO and hasShaders and Platform.glHaveGL4 then | ||
hasGL4 = true | ||
end | ||
end | ||
|
||
local function checkRequires(allRequires) | ||
if not allRequires or isSyncedCode then | ||
return true | ||
end | ||
for _, req in pairs(allRequires) do | ||
if req == 'gl' and not hasGL then | ||
return false | ||
elseif req == 'gl4' and not hasGL4 then | ||
return false | ||
elseif req == 'shaders' and not hasShaders then | ||
return false | ||
elseif req == 'fbo' and not hasVBO then | ||
return false | ||
end | ||
end | ||
return true | ||
end | ||
|
||
local function extendPlatform() | ||
Platform.gl = Platform.gl or hasGL | ||
Platform.gl4 = Platform.gl4 or hasGL4 | ||
Platform.glHaveFBO = Platform.glHaveFBO or hasFBO | ||
Platform.check = checkRequires | ||
end | ||
|
||
determineCapabilities() | ||
extendPlatform() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ function widget:GetInfo() | |
license = "Lua code: GNU GPL, v2 or later, Shader GLSL code: (c) Beherith ([email protected])", | ||
layer = 999, | ||
enabled = true, | ||
depends = {'gl4'}, | ||
} | ||
end | ||
|
||
|
@@ -1925,10 +1926,6 @@ local function UnitScriptDecal(unitID, unitDefID, whichDecal, posx, posz, headin | |
end | ||
|
||
function widget:Initialize() | ||
if not gl.CreateShader then -- no shader support, so just remove the widget itself, especially for headless | ||
widgetHandler:RemoveWidget() | ||
return | ||
end | ||
local t0 = Spring.GetTimer() | ||
--if makeAtlases() == false then | ||
-- goodbye("Failed to init texture atlas for DecalsGL4") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ function widget:GetInfo() | |
license = "Lua: GPLv2, GLSL: (c) Beherith ([email protected])", | ||
layer = -99, | ||
enabled = true, | ||
depends = {'gl4'}, | ||
} | ||
end | ||
|
||
|
@@ -708,10 +709,6 @@ function widget:PlayerChanged(playerID) | |
end | ||
|
||
function widget:Initialize() | ||
if not gl.CreateShader then -- no shader support, so just remove the widget itself, especially for headless | ||
widgetHandler:RemoveWidget(self) | ||
return | ||
end | ||
initUnitList() | ||
|
||
if initGL4() == false then | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters