Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
local shell = require("shell")
local tty = require("tty")

local args = shell.parse(...)
local args, ops = shell.parse(...)
local gpu = tty.gpu()

if ops["max"] or ops["m"] then
local w, h = gpu.maxResolution()
io.write(w," ",h,"\n")
local limited = nil
local gw, gh = gpu.hardwareResolution()
-- Only loads this when we need it
local component = require("component")
local sw, sh = component.invoke(tty.screen(), "hardwareResolution")
if gw < sw or gh < sh then
limited = "GPU"
elseif gw > sw or gh > sh then
limited = "screen"
end
if limited then
io.write("(Limited by ",limited,")\n")
end
return
end

if #args == 0 then
local w, h = gpu.getViewport()
io.write(w," ",h,"\n")
return
end

if #args ~= 2 then
print("Usage: resolution [<width> <height>]")
print("Usage: resolution [<width> <height>] or resolution --max")
return
end

Expand Down
10 changes: 10 additions & 0 deletions src/main/scala/li/cil/oc/common/component/TextBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ class TextBuffer(val host: EnvironmentHost) extends AbstractManagedEnvironment w
else result((), "unsupported operation")
}

@Callback(doc = """function():number -- Get the maximum resolution supported by the screen.""")
def hardwareResolution(context: Context, args: Arguments): Array[AnyRef] = {
val (smw, smh) = maxResolution
result(smw, smh)
}

@Callback(direct = true, doc = """function():number -- Get the maximum color depth supported by the screen.""")
def hardwareDepth(context: Context, args: Arguments): Array[AnyRef] =
result(PackedColor.Depth.bits(maxDepth))

// ----------------------------------------------------------------------- //

override def setEnergyCostPerTick(value: Double): Unit = {
Expand Down
14 changes: 12 additions & 2 deletions src/main/scala/li/cil/oc/server/component/GraphicsCard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,14 @@ class GraphicsCard(val tier: Int, val vramScreens: Option[Double] = None, val vi
})
}

@Callback(direct = true, doc = """function():number -- Get the maximum supported color depth.""")
@Callback(direct = true, doc = """function():number -- Get the maximum supported color depth by the current GPU+screen combo.""")
def maxDepth(context: Context, args: Arguments): Array[AnyRef] =
screen(s => result(PackedColor.Depth.bits(api.internal.TextBuffer.ColorDepth.values.apply(math.min(maxDepth.ordinal, s.getMaximumColorDepth.ordinal)))))

@Callback(direct = true, doc = """function():number -- Get the maximum color depth supported by the GPU.""")
def hardwareDepth(context: Context, args: Arguments): Array[AnyRef] =
result(PackedColor.Depth.bits(maxDepth))

@Callback(direct = true, doc = """function():number, number -- Get the current screen resolution.""")
def getResolution(context: Context, args: Arguments): Array[AnyRef] =
screen(s => result(s.getWidth, s.getHeight))
Expand All @@ -427,7 +431,7 @@ class GraphicsCard(val tier: Int, val vramScreens: Option[Double] = None, val vi
screen(s => result(s.setResolution(w, h)))
}

@Callback(direct = true, doc = """function():number, number -- Get the maximum screen resolution.""")
@Callback(direct = true, doc = """function():number, number -- Get the maximum screen resolution supported by the current GPU+screen combo.""")
def maxResolution(context: Context, args: Arguments): Array[AnyRef] =
screen(s => {
val (gmw, gmh) = maxResolution
Expand All @@ -436,6 +440,12 @@ class GraphicsCard(val tier: Int, val vramScreens: Option[Double] = None, val vi
result(math.min(gmw, smw), math.min(gmh, smh))
})

@Callback(direct = true, doc = """function():number, number -- Get the maximum screen resolution supported by the GPU.""")
def hardwareResolution(context: Context, args: Arguments): Array[AnyRef] = {
val (gmw, gmh) = maxResolution
result(gmw, gmh)
}

@Callback(direct = true, doc = """function():number, number -- Get the current viewport resolution.""")
def getViewport(context: Context, args: Arguments): Array[AnyRef] =
screen(s => result(s.getViewportWidth, s.getViewportHeight))
Expand Down
Loading