1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
Framebuffer
===========
.. py:class:: Framebuffer
Returned by :py:meth:`Context.framebuffer`
A :py:class:`Framebuffer` is a collection of buffers that can be used as the destination for rendering.
The buffers for Framebuffer objects reference images from either Textures or Renderbuffers.
Methods
-------
.. py:method:: Framebuffer.clear(red: float = 0.0, green: float = 0.0, blue: float = 0.0, alpha: float = 0.0, depth: float = 1.0, viewport=..., color=...) -> None
Clear the framebuffer.
If a `viewport` passed in, a scissor test will be used to clear the given viewport.
This viewport take presence over the framebuffers :py:attr:`~moderngl.Framebuffer.scissor`.
Clearing can still be done with scissor if no viewport is passed in.
This method also respects the
:py:attr:`~moderngl.Framebuffer.color_mask` and
:py:attr:`~moderngl.Framebuffer.depth_mask`. It can for example be used to only clear
the depth or color buffer or specific components in the color buffer.
If the `viewport` is a 2-tuple it will clear the
``(0, 0, width, height)`` where ``(width, height)`` is the 2-tuple.
If the `viewport` is a 4-tuple it will clear the given viewport.
:param float red: color component.
:param float green: color component.
:param float blue: color component.
:param float alpha: alpha component.
:param float depth: depth value.
:param tuple viewport: The viewport.
:param tuple color: Optional tuple replacing the red, green, blue and alpha arguments
.. py:method:: Framebuffer.read(viewport=..., components: int = 3, attachment: int = 0, alignment: int = 1, dtype: str = 'f1', clamp: bool = False) -> bytes
Read the content of the framebuffer.
:param tuple viewport: The viewport.
:param int components: The number of components to read.
:param int attachment: The color attachment number. -1 for the depth attachment
:param int alignment: The byte alignment of the pixels.
:param str dtype: Data type.
:param bool clamp: Clamps floating point values to ``[0.0, 1.0]``
.. code:: python
# Read the first color attachment's RGBA data
data = fbo.read(components=4)
# Read the second color attachment's RGB data
data = fbo.read(attachment=1)
# Read the depth attachment
data = fbo.read(attachment=-1)
# Read the lower left 10 x 10 pixels from the first color attachment
data = fbo.read(viewport=(0, 0, 10, 10))
.. py:method:: Framebuffer.read_into(buffer, viewport, components: int = 3, attachment: int = 0, alignment: int = 1, dtype: str = 'f1', write_offset: int = 0) -> None
Read the content of the framebuffer into a buffer.
:param bytearray buffer: The buffer that will receive the pixels.
:param tuple viewport: The viewport.
:param int components: The number of components to read.
:param int attachment: The color attachment.
:param int alignment: The byte alignment of the pixels.
:param str dtype: Data type.
:param int write_offset: The write offset.
.. py:method:: Framebuffer.use()
Bind the framebuffer.
.. py:method:: Framebuffer.release
Attributes
----------
.. py:attribute:: Framebuffer.viewport
:type: tuple
Get or set the viewport of the framebuffer.
.. py:attribute:: Framebuffer.scissor
:type: tuple
Get or set the scissor box of the framebuffer.
When scissor testing is enabled fragments outside
the defined scissor box will be discarded. This
applies to rendered geometry or :py:meth:`Framebuffer.clear`.
Setting is value enables scissor testing in the framebuffer.
Setting the scissor to ``None`` disables scissor testing
and reverts the scissor box to match the framebuffer size.
Example::
# Enable scissor testing
>>> ctx.scissor = 100, 100, 200, 100
# Disable scissor testing
>>> ctx.scissor = None
.. py:attribute:: Framebuffer.color_mask
:type: tuple
The color mask of the framebuffer.
Color masking controls what components in color attachments will be
affected by fragment write operations.
This includes rendering geometry and clearing the framebuffer.
Default value: ``(True, True, True, True)``.
Examples::
# Block writing to all color components (rgba) in color attachments
fbo.color_mask = False, False, False, False
# Re-enable writing to color attachments
fbo.color_mask = True, True, True, True
# Block fragment writes to alpha channel
fbo.color_mask = True, True, True, False
.. py:attribute:: Framebuffer.depth_mask
:type: bool
The depth mask of the framebuffer.
Depth mask enables or disables write operations to the depth buffer.
This also applies when clearing the framebuffer.
If depth testing is enabled fragments will still be culled, but
the depth buffer will not be updated with new values. This is
a very useful tool in many rendering techniques.
Default value: ``True``
.. py:attribute:: Framebuffer.width
:type: int
The width of the framebuffer.
Framebuffers created by a window will only report its initial size.
It's better get size information from the window itself.
.. py:attribute:: Framebuffer.height
:type: int
The height of the framebuffer.
Framebuffers created by a window will only report its initial size.
It's better get size information from the window itself.
.. py:attribute:: Framebuffer.size
:type: Tuple[int, int]
The size of the framebuffer.
Framebuffers created by a window will only report its initial size.
It's better get size information from the window itself.
.. py:attribute:: Framebuffer.samples
:type: int
The samples of the framebuffer.
.. py:attribute:: Framebuffer.bits
:type: int
The bits of the framebuffer.
.. py:attribute:: Framebuffer.color_attachments
:type: tuple
.. py:attribute:: Framebuffer.depth_attachment
:type: tuple
.. py:attribute:: Framebuffer.ctx
:type: Context
The context this object belongs to
.. py:attribute:: Framebuffer.glo
:type: int
The internal OpenGL object.
This values is provided for interoperability and debug purposes only.
.. py:attribute:: Framebuffer.extra
:type: Any
User defined data.
|