Source code for picogl.buffers.vertex.registry

"""
A module for managing OpenGL object information.

This module defines a data structure for representing OpenGL object info,
and provides a registry to store and manage these objects. It includes
details such as object handle, type, label, creation time, and associated
attributes.
"""

import time
from dataclasses import dataclass, field
from typing import Dict, Optional

from decologr import Decologr as log
from PySide6 import QtGui


[docs] class GLObjectAttrs: """GL Object Attributes"""
[docs] handle = "handle"
[docs] label = "label"
[docs] created_context = "created_context"
[docs] current_context = "current_context"
@dataclass
[docs] class GLObjectInfo:
[docs] handle: int
[docs] type: str
[docs] label: str
[docs] created_at: float = field(default_factory=time.time)
[docs] context_id: Optional[int] = None
[docs] attributes: dict = field(default_factory=dict)
[docs] GL_REGISTRY: Dict[int, GLObjectInfo] = {}
[docs] def debug_vao(vao): info = GL_REGISTRY.get(vao) if not info: log.error(f"VAO {vao} not found in registry") return log.error("VAO DEBUG INFO") log.parameter(GLObjectAttrs.handle, info.handle) log.parameter(GLObjectAttrs.label, info.label) log.parameter(GLObjectAttrs.created_context, info.context_id) log.parameter( GLObjectAttrs.current_context, id(QtGui.QOpenGLContext.currentContext()) )
[docs] def dump_gl_registry(): print(GL_REGISTRY) for obj in GL_REGISTRY.values(): log.info( f"{obj.type} {obj.handle} label={obj.label} " f"context={obj.context_id}", scope="dump_gl_registry" )
[docs] def store_in_gl_registry(handle: int, label: str, ctx_id: int, buffer_type: str = "VAO"): """store in gl registry""" GL_REGISTRY[handle] = GLObjectInfo(handle=handle, type=buffer_type, label=label, context_id=ctx_id)