帧缓冲#

FrameBuffer#

class arcade.gl.Framebuffer(ctx: Context, *, color_attachments=None, depth_attachment=None)[源代码]#

基类:object

屏幕外渲染目标在OpenGL中也称为帧缓冲区对象。此实现使用的是纹理附件。创建帧缓冲区时,我们为其提供要将场景渲染到其中的纹理。使用纹理附件的优势是我们能够继续处理帧缓冲区的内容。

创建帧缓冲区的最佳方式是通过 arcade.gl.Context.framebuffer() ::

# Create a 100 x 100 framebuffer with one attachment
ctx.framebuffer(color_attachments=[ctx.texture((100, 100), components=4)])

# Create a 100 x 100 framebuffer with two attachments
# Shaders can be configured writing to the different layers
ctx.framebuffer(
    color_attachments=[
        ctx.texture((100, 100), components=4),
        ctx.texture((100, 100), components=4),
    ]
)
参数
is_default = False#

这是默认的帧缓冲区吗?(窗口缓冲区)

property glo: ctypes.c_uint#

帧缓冲区的OpenGL ID/名称

类型

GLuint

property viewport: Tuple[int, int, int, int]#

获取或设置帧缓冲区的视区。视区参数为 (x, y, width, height) 。它确定应渲染到帧缓冲区的哪个部分。默认情况下,该视口为 (0, 0, width, height)

每次绑定帧缓冲区时,都会自动应用视口值为永久的所有内容。

示例::

# 100, x 100 lower left with size 200 x 200px
fb.viewport = 100, 100, 200, 200
property scissor: Optional[Tuple[int, int, int, int]]#

获取或设置此帧缓冲区的剪贴框。

默认情况下,剪裁框处于禁用状态,不起作用,初始值为 None 。设置值时启用剪贴框,设置为时禁用剪贴框 None

#在100 x 100像素的左下角区域#设置并启用剪贴框仅绘制#ctx.scissor=0,0,100,100#禁用剪裁ctx.scissor=无

类型

元组(x,y,宽度,高度)

property ctx: Context#

此对象所属的上下文。

类型

arcade.gl.Context

property width: int#

帧缓冲区的宽度(以像素为单位

类型

集成

property height: int#

帧缓冲区的高度(以像素为单位

类型

集成

property size: Tuple[int, int]#

大小为 (w, h) 元组

类型

元组(int,int)

property samples: int#

样本数(MSAA)

类型

集成

property color_attachments: List[arcade.gl.texture.Texture]#

颜色附件列表

类型

列表: arcade.gl.Texture

property depth_attachment: arcade.gl.texture.Texture#

深度依恋

类型

arcade.gl.Texture

property depth_mask: bool#

获取或设置深度蒙版(默认: True )。它确定启用深度测试时是否应将深度值写入深度纹理。

每次绑定帧缓冲区时,将自动应用所有深度遮罩值。

类型

布尔尔

activate()[源代码]#

用于绑定帧缓冲区的上下文管理器。

与此类中的默认上下文管理器不同,它支持嵌套的帧缓冲区绑定。

use(*, force: bool = False)[源代码]#

绑定帧缓冲区,使其成为所有渲染命令的目标

参数

force (bool) -- 强制帧缓冲区绑定,即使系统已经认为它已经绑定。

clear(color=(0.0, 0.0, 0.0, 0.0), *, depth: float = 1.0, normalized: bool = False, viewport: Optional[Tuple[int, int, int, int]] = None)[源代码]#

清除帧缓冲区::

# Clear framebuffer using the color red in normalized form
fbo.clear(color=(1.0, 0.0, 0.0, 1.0), normalized=True)
# Clear the framebuffer using arcade's colors (not normalized)
fb.clear(color=arcade.color.WHITE)

如果背景颜色为 RGB 值而不是 RGBA ‘我们假设alpha值为255。

参数
  • color (tuple) -- 包含颜色的3或4分量元组

  • depth (float) -- 值以清除深度缓冲区(未使用)

  • normalized (bool) -- 颜色值是否归一化

  • viewport (Tuple[int, int, int, int]) -- 要清除的视区范围

read(*, viewport=None, components=3, attachment=0, dtype='f1') bytearray[源代码]#

读取帧缓冲区像素

参数
  • viewport (Tuple[int,int,int,int]) -- 要读取的x,y,with,高度

  • components (int) --

  • attachment (int) -- 要从中读取的附件ID

  • dtype (str) -- 要读取的数据类型

返回

字节数组形式的像素数据

resize()[源代码]#

检测附件中的大小更改。这会将视口重置为 0, 0, width, height

delete()[源代码]#

销毁底层OpenGL资源。除非你清楚地知道自己在做什么,否则不要使用这个。

static delete_glo(ctx, framebuffer_id)[源代码]#

销毁帧缓冲区对象

参数
  • ctx -- OpenGL上下文

  • framebuffer_id -- 要销毁的帧缓冲区(GLO)

DefaultFrameBuffer#

class arcade.gl.framebuffer.DefaultFrameBuffer(ctx: Context)[源代码]#

基类:arcade.gl.framebuffer.Framebuffer

表示默认的帧缓冲区。这是窗口本身的帧缓冲区,需要进行一些特殊处理。

我们不允许销毁此帧缓冲区,因为它属于侏儒所有。该帧缓冲区还可以在任何点更改大小和像素比例。

我们正在进行一些初步的内省,以猜测一些合理的初始值。因为这是一个动态帧缓冲区,所以我们不能信任内部值。我们只能信任侏儒窗口本身报告的与窗口大小和帧缓冲区大小相关的内容。这应该在 on_resize 回拨。

is_default = True#

这是默认的帧缓冲区吗?(窗口缓冲区)

property viewport: Tuple[int, int, int, int]#

获取或设置帧缓冲区的视区。视区参数为 (x, y, width, height) 。它确定应渲染到帧缓冲区的哪个部分。默认情况下,该视口为 (0, 0, width, height)

每次绑定帧缓冲区时,都会自动应用视口值为永久的所有内容。

示例::

# 100, x 100 lower left with size 200 x 200px
fb.viewport = 100, 100, 200, 200
property scissor: Optional[Tuple[int, int, int, int]]#

获取或设置此帧缓冲区的剪贴框。

默认情况下,剪裁框处于禁用状态,不起作用,初始值为 None 。设置值时启用剪贴框,设置为时禁用剪贴框 None

#在100 x 100像素的左下角区域#设置并启用剪贴框仅绘制#ctx.scissor=0,0,100,100#禁用剪裁ctx.scissor=无

类型

元组(x,y,宽度,高度)