# Path: pyoptix/enums.py
# class ExceptionType:
#     program_id_invalid = RTexception.RT_EXCEPTION_PROGRAM_ID_INVALID
#     texture_id_invalid = RTexception.RT_EXCEPTION_TEXTURE_ID_INVALID
#     buffer_id_invalid = RTexception.RT_EXCEPTION_BUFFER_ID_INVALID
#     index_out_of_bounds = RTexception.RT_EXCEPTION_INDEX_OUT_OF_BOUNDS
#     stack_overflow = RTexception.RT_EXCEPTION_STACK_OVERFLOW
#     buffer_index_out_of_bounds = RTexception.RT_EXCEPTION_BUFFER_INDEX_OUT_OF_BOUNDS
#     invalid_ray = RTexception.RT_EXCEPTION_INVALID_RAY
#     internal_error = RTexception.RT_EXCEPTION_INTERNAL_ERROR
#     user = RTexception.RT_EXCEPTION_USER
#     all = RTexception.RT_EXCEPTION_ALL
# 
# Path: pyoptix/mixins/scoped.py
# class ScopedObject(DestroyableObject):
#     def __init__(self, native):
#         DestroyableObject.__init__(self, native)
#         self._variables = {}
# 
#     def __setitem__(self, key, value):
#         from pyoptix.variable import Variable
# 
#         variable_wrapper = self._safe_native.query_variable(key)
#         declared = False
# 
#         if variable_wrapper is None:
#             variable_wrapper = self._safe_native.declare_variable(key)
#             declared = True
# 
#         try:
#             optix_variable = Variable(variable_wrapper)
#             optix_variable.value = value
#             self._variables[key] = optix_variable
#         except Exception as e:
#             if declared:
#                 self._safe_native.remove_variable(variable_wrapper)
#             raise e
# 
#     def __getitem__(self, key):
#         return self._variables[key].value
# 
#     def __len__(self):
#         return len(self._variables)
# 
#     def __delitem__(self, key):
#         wrapped_variable = self._safe_native.query_variable(key)
#         if not wrapped_variable.is_valid():
#             raise ValueError("Variable not found")
# 
#         self._safe_native.remove_variable(wrapped_variable)
#         del self._variables[key]
# 
#     def __contains__(self, item):
#         return item in self._variables


import weakref
import atexit
from pyoptix._driver import NativeContextWrapper
from pyoptix.enums import ExceptionType
from pyoptix.mixins.scoped import ScopedObject


class Context(ScopedObject):
    def __init__(self):
        self._program_cache = {}
        self._ray_gen_programs = {}
        self._exception_programs = {}
        self._miss_programs = {}
        self._destroyables = []

        self._native = NativeContextWrapper()

# Path: pyoptix/enums.py
# class ExceptionType:
#     program_id_invalid = RTexception.RT_EXCEPTION_PROGRAM_ID_INVALID
#     texture_id_invalid = RTexception.RT_EXCEPTION_TEXTURE_ID_INVALID
#     buffer_id_invalid = RTexception.RT_EXCEPTION_BUFFER_ID_INVALID
#     index_out_of_bounds = RTexception.RT_EXCEPTION_INDEX_OUT_OF_BOUNDS
#     stack_overflow = RTexception.RT_EXCEPTION_STACK_OVERFLOW
#     buffer_index_out_of_bounds = RTexception.RT_EXCEPTION_BUFFER_INDEX_OUT_OF_BOUNDS
#     invalid_ray = RTexception.RT_EXCEPTION_INVALID_RAY
#     internal_error = RTexception.RT_EXCEPTION_INTERNAL_ERROR
#     user = RTexception.RT_EXCEPTION_USER
#     all = RTexception.RT_EXCEPTION_ALL
# 
# Path: pyoptix/mixins/scoped.py
# class ScopedObject(DestroyableObject):
#     def __init__(self, native):
#         DestroyableObject.__init__(self, native)
#         self._variables = {}
# 
#     def __setitem__(self, key, value):
#         from pyoptix.variable import Variable
# 
#         variable_wrapper = self._safe_native.query_variable(key)
#         declared = False
# 
#         if variable_wrapper is None:
#             variable_wrapper = self._safe_native.declare_variable(key)
#             declared = True
# 
#         try:
#             optix_variable = Variable(variable_wrapper)
#             optix_variable.value = value
#             self._variables[key] = optix_variable
#         except Exception as e:
#             if declared:
#                 self._safe_native.remove_variable(variable_wrapper)
#             raise e
# 
#     def __getitem__(self, key):
#         return self._variables[key].value
# 
#     def __len__(self):
#         return len(self._variables)
# 
#     def __delitem__(self, key):
#         wrapped_variable = self._safe_native.query_variable(key)
#         if not wrapped_variable.is_valid():
#             raise ValueError("Variable not found")
# 
#         self._safe_native.remove_variable(wrapped_variable)
#         del self._variables[key]
# 
#     def __contains__(self, item):
#         return item in self._variables


# Path: pyoptix/context.py
import weakref
import atexit
from pyoptix._driver import NativeContextWrapper
from pyoptix.enums import ExceptionType
from pyoptix.mixins.scoped import ScopedObject



class Context(ScopedObject):
    def __init__(self):
        self._program_cache = {}
        self._ray_gen_programs = {}
        self._exception_programs = {}
        self._miss_programs = {}
        self._destroyables = []

        self._native = NativeContextWrapper()

        ScopedObject.__init__(self, self._native)