"""
Provides utilities and context managers for managing OpenGL textures.
This module defines enumerations and helper classes for texture handling, along
with context managers for safely enabling and binding textures in an OpenGL
environment. It aims to simplify texture management tasks and ensure proper
state restoration after operations.
"""
from contextlib import contextmanager
from dataclasses import dataclass
from picogl.backend.gl.driver.capability import GLCapabilityDriver
from picogl.texture.gltexture import GLTexture
@dataclass(frozen=True)
[docs]
class TexCoord2f:
"""Tex Coord 2F"""
@dataclass(frozen=True)
[docs]
class Vertex3f:
"""Vertex 3F"""
@contextmanager
[docs]
def texture2d_enabled():
"""Texture 2D Enabled"""
was_enabled = GLCapabilityDriver.is_enabled(GLTexture.TEXTURE_2D)
try:
if not was_enabled:
GLCapabilityDriver.enable(GLTexture.TEXTURE_2D)
yield
finally:
if not was_enabled:
GLCapabilityDriver.disable(GLTexture.TEXTURE_2D)