Frame:SetIsFrameBuffer

From Warcraft Wiki
Jump to navigation Jump to search

Controls whether or not a frame is rendered to its own framebuffer prior to being composited atop the UI.

Frame:SetIsFrameBuffer(isFrameBuffer)

Arguments

isFrameBuffer
boolean - true to enable rendering this frame to a framebuffer, or false to disable.

Details

  • Use of this flag allows frames to work around specific alpha-related issues when rendering.
  • The frame must be configured to flatten render layers for this flag to have any effect. Failure to configure this may result in an invisible frame, or potentially assertion errors on test clients.
  • The frame will be rendered to a framebuffer as if it were fully opaque. Any configured alpha for the frame is not inherited by direct children, causing their effective alpha to be 1 unless they themselves have a distinct alpha value. This can cause overlapping child frames to no longer blend together once rendered. The alpha value assigned to the frame is only applied once the framebuffer is composited atop the UI scene.

Example

API Frame SetFrameBuffer Example.png

The following snippet will create a frame in the middle of the screen with two rows of partially transparent textures in the middle, with a checkbox below the frame to toggle the framebuffer flag that is disabled by default.

Toggling the checkbox will demonstrate the effects of the flag; the top row of textures will become less opaque while enabled, and the bottom row will not blend their alpha together such that the green texture in the middle will obscure the overlapping edges of its adjacent textures.

local function CreateColoredTexture(parent, color)
    local texture = parent:CreateTexture()
    texture:SetColorTexture(color:GetRGB())
    return texture
end

local function CreateColoredFrame(parent, color)
    local frame = CreateFrame("Frame", nil, parent)
    frame.Color = CreateColoredTexture(frame, color)
    frame.Color:SetAllPoints(frame)
    return frame
end

FrameBufferTestMixin = {}

function FrameBufferTestMixin:OnLoad()
    local ItemWidth = 128
    local ItemHeight = 64
    local GridStride = 3
    local ColorsByColumn = { CreateColor(1, 0, 0), CreateColor(0, 1, 0), CreateColor(0, 0, 1) }
    local LevelsByColumn = { 1, 2, 1 }

    self:SetToplevel(true)
    self:SetIsFrameBuffer(false)
    self:SetAlpha(0.5)
    self:SetSize(ItemWidth * GridStride, ItemHeight * 3)

    self.Background = CreateColoredFrame(self, CreateColor(0, 0, 0))
    self.Background:SetFrameLevel(self:GetFrameLevel())
    self.Background:SetAllPoints(self)

    self.GridItems = {}

    for i = 1, 3 do
        local texture = CreateColoredTexture(self, ColorsByColumn[i])
        texture:SetSize(ItemWidth,  ItemHeight)
        texture:SetDrawLayer("ARTWORK", LevelsByColumn[i])
        table.insert(self.GridItems, texture)
    end

    for i = 1, 3 do
        local frame = CreateColoredFrame(self, ColorsByColumn[i])
        frame:SetSize(ItemWidth, ItemHeight)
        frame:SetFrameLevel(self:GetFrameLevel() + LevelsByColumn[i])
        table.insert(self.GridItems, frame)
    end

    do
        local paddingX = -32
        local paddingY = 16
        local direction = GridLayoutMixin.Direction.TopLeftToBottomRight

        local initialAnchor = AnchorUtil.CreateAnchor("TOPLEFT", self, "TOPLEFT", 32, -24)
        local layout = AnchorUtil.CreateGridLayout(direction, GridStride, paddingX, paddingY)

        AnchorUtil.GridLayout(self.GridItems, initialAnchor, layout)
    end
end

function FrameBufferTestMixin:ToggleFramebuffer()
    self.framebuffer = not self.framebuffer
    self:SetIsFrameBuffer(self.framebuffer)
end

FrameBufferTestFrame = Mixin(CreateFrame("Frame", nil, UIParent), FrameBufferTestMixin)
FrameBufferTestFrame:OnLoad()
FrameBufferTestFrame:SetPoint("CENTER")

FrameBufferToggleButton = CreateFrame("CheckButton", nil, UIParent, "UICheckButtonTemplate")
FrameBufferToggleButton:SetPoint("TOP", FrameBufferTestFrame, "BOTTOM")
FrameBufferToggleButton:SetScript("OnClick", function() FrameBufferTestFrame:ToggleFramebuffer() end)

Patch changes

Retail

Dragonflight Patch 10.0.0 (2022-10-25): Renamed to Frame:SetIsFrameBuffer().
Shadowlands Patch 9.1.0 (2021-06-29): Added.

Classic

Bc icon.gif Patch 2.5.2 (2021-08-31): Added.