# Path: pyoptix/enums.py
# class Format:
#     unknown = RTformat.RT_FORMAT_UNKNOWN
#     float = RTformat.RT_FORMAT_FLOAT
#     float2 = RTformat.RT_FORMAT_FLOAT2
#     float3 = RTformat.RT_FORMAT_FLOAT3
#     float4 = RTformat.RT_FORMAT_FLOAT4
#     byte = RTformat.RT_FORMAT_BYTE
#     byte2 = RTformat.RT_FORMAT_BYTE2
#     byte3 = RTformat.RT_FORMAT_BYTE3
#     byte4 = RTformat.RT_FORMAT_BYTE4
#     unsigned_byte = RTformat.RT_FORMAT_UNSIGNED_BYTE
#     unsigned_byte2 = RTformat.RT_FORMAT_UNSIGNED_BYTE2
#     unsigned_byte3 = RTformat.RT_FORMAT_UNSIGNED_BYTE3
#     unsigned_byte4 = RTformat.RT_FORMAT_UNSIGNED_BYTE4
#     short = RTformat.RT_FORMAT_SHORT
#     short2 = RTformat.RT_FORMAT_SHORT2
#     short3 = RTformat.RT_FORMAT_SHORT3
#     short4 = RTformat.RT_FORMAT_SHORT4
#     unsigned_short = RTformat.RT_FORMAT_UNSIGNED_SHORT
#     unsigned_short2 = RTformat.RT_FORMAT_UNSIGNED_SHORT2
#     unsigned_short3 = RTformat.RT_FORMAT_UNSIGNED_SHORT3
#     unsigned_short4 = RTformat.RT_FORMAT_UNSIGNED_SHORT4
#     int = RTformat.RT_FORMAT_INT
#     int2 = RTformat.RT_FORMAT_INT2
#     int3 = RTformat.RT_FORMAT_INT3
#     int4 = RTformat.RT_FORMAT_INT4
#     unsigned_int = RTformat.RT_FORMAT_UNSIGNED_INT
#     unsigned_int2 = RTformat.RT_FORMAT_UNSIGNED_INT2
#     unsigned_int3 = RTformat.RT_FORMAT_UNSIGNED_INT3
#     unsigned_int4 = RTformat.RT_FORMAT_UNSIGNED_INT4
#     user = RTformat.RT_FORMAT_USER
#     buffer_id = RTformat.RT_FORMAT_BUFFER_ID
#     program_id = RTformat.RT_FORMAT_PROGRAM_ID
# 
# def convert_buffer_type(string):
#     if isinstance(string, str) and string.lower() in BUFFER_STRING_TO_OPTIX_ENUM:
#         return BUFFER_STRING_TO_OPTIX_ENUM[string]
#     else:
#         raise string
# 
# def get_format_from_dtype(dtype, type_size):
#     if dtype in DTYPE_TO_FORMAT and type_size in DTYPE_TO_FORMAT[dtype]:
#         return DTYPE_TO_FORMAT[dtype][type_size]
#     else:
#         return DTYPE_TO_FORMAT['default']
# 
# Path: pyoptix/context.py
# def current_context():
#     return _context_stack[-1]
# 
# Path: pyoptix/mixins/bindless.py
# class BindlessMixin(object):
#     def __init__(self):
#         self._bindless = False
# 
#     @property
#     def bindless(self):
#         return self._bindless
# 
#     @bindless.setter
#     def bindless(self, value):
#         value = bool(value)
#         self._safe_native.auto_destroy = not value
#         self._bindless = value
# 
# Path: pyoptix/mixins/destroyable.py
# class DestroyableObject(object):
#     def __init__(self, native):
#         self._native = native
# 
#     @property
#     def _safe_native(self):
#         if not self._native.is_destroyed:
#             return self._native
#         else:
#             raise RuntimeError('Underlying OptiX object was destroyed before.')
# 
# Path: pyoptix/mixins/hascontext.py
# class HasContextMixin(object):
#     def __init__(self, context):
#         self._context_ref = weakref.ref(context)
# 
#     @property
#     def _safe_context(self):
#         ctx = self._context_ref()
#         if ctx is not None:
#             return ctx
#         else:
#             raise RuntimeError('Context of this object is no longer valid')


import numpy
from pyoptix.enums import Format, convert_buffer_type, get_format_from_dtype
from pyoptix.context import current_context
from pyoptix.mixins.bindless import BindlessMixin
from pyoptix.mixins.destroyable import DestroyableObject
from pyoptix.mixins.hascontext import HasContextMixin


class Buffer(HasContextMixin, DestroyableObject, BindlessMixin):
    def __init__(self, buffer_type='io'):
        HasContextMixin.__init__(self, current_context())
        DestroyableObject.__init__(self, self._safe_context._create_buffer(convert_buffer_type(buffer_type)))

# Path: pyoptix/enums.py
# class Format:
#     unknown = RTformat.RT_FORMAT_UNKNOWN
#     float = RTformat.RT_FORMAT_FLOAT
#     float2 = RTformat.RT_FORMAT_FLOAT2
#     float3 = RTformat.RT_FORMAT_FLOAT3
#     float4 = RTformat.RT_FORMAT_FLOAT4
#     byte = RTformat.RT_FORMAT_BYTE
#     byte2 = RTformat.RT_FORMAT_BYTE2
#     byte3 = RTformat.RT_FORMAT_BYTE3
#     byte4 = RTformat.RT_FORMAT_BYTE4
#     unsigned_byte = RTformat.RT_FORMAT_UNSIGNED_BYTE
#     unsigned_byte2 = RTformat.RT_FORMAT_UNSIGNED_BYTE2
#     unsigned_byte3 = RTformat.RT_FORMAT_UNSIGNED_BYTE3
#     unsigned_byte4 = RTformat.RT_FORMAT_UNSIGNED_BYTE4
#     short = RTformat.RT_FORMAT_SHORT
#     short2 = RTformat.RT_FORMAT_SHORT2
#     short3 = RTformat.RT_FORMAT_SHORT3
#     short4 = RTformat.RT_FORMAT_SHORT4
#     unsigned_short = RTformat.RT_FORMAT_UNSIGNED_SHORT
#     unsigned_short2 = RTformat.RT_FORMAT_UNSIGNED_SHORT2
#     unsigned_short3 = RTformat.RT_FORMAT_UNSIGNED_SHORT3
#     unsigned_short4 = RTformat.RT_FORMAT_UNSIGNED_SHORT4
#     int = RTformat.RT_FORMAT_INT
#     int2 = RTformat.RT_FORMAT_INT2
#     int3 = RTformat.RT_FORMAT_INT3
#     int4 = RTformat.RT_FORMAT_INT4
#     unsigned_int = RTformat.RT_FORMAT_UNSIGNED_INT
#     unsigned_int2 = RTformat.RT_FORMAT_UNSIGNED_INT2
#     unsigned_int3 = RTformat.RT_FORMAT_UNSIGNED_INT3
#     unsigned_int4 = RTformat.RT_FORMAT_UNSIGNED_INT4
#     user = RTformat.RT_FORMAT_USER
#     buffer_id = RTformat.RT_FORMAT_BUFFER_ID
#     program_id = RTformat.RT_FORMAT_PROGRAM_ID
# 
# def convert_buffer_type(string):
#     if isinstance(string, str) and string.lower() in BUFFER_STRING_TO_OPTIX_ENUM:
#         return BUFFER_STRING_TO_OPTIX_ENUM[string]
#     else:
#         raise string
# 
# def get_format_from_dtype(dtype, type_size):
#     if dtype in DTYPE_TO_FORMAT and type_size in DTYPE_TO_FORMAT[dtype]:
#         return DTYPE_TO_FORMAT[dtype][type_size]
#     else:
#         return DTYPE_TO_FORMAT['default']
# 
# Path: pyoptix/context.py
# def current_context():
#     return _context_stack[-1]
# 
# Path: pyoptix/mixins/bindless.py
# class BindlessMixin(object):
#     def __init__(self):
#         self._bindless = False
# 
#     @property
#     def bindless(self):
#         return self._bindless
# 
#     @bindless.setter
#     def bindless(self, value):
#         value = bool(value)
#         self._safe_native.auto_destroy = not value
#         self._bindless = value
# 
# Path: pyoptix/mixins/destroyable.py
# class DestroyableObject(object):
#     def __init__(self, native):
#         self._native = native
# 
#     @property
#     def _safe_native(self):
#         if not self._native.is_destroyed:
#             return self._native
#         else:
#             raise RuntimeError('Underlying OptiX object was destroyed before.')
# 
# Path: pyoptix/mixins/hascontext.py
# class HasContextMixin(object):
#     def __init__(self, context):
#         self._context_ref = weakref.ref(context)
# 
#     @property
#     def _safe_context(self):
#         ctx = self._context_ref()
#         if ctx is not None:
#             return ctx
#         else:
#             raise RuntimeError('Context of this object is no longer valid')


# Path: pyoptix/buffer.py
import numpy
from pyoptix.enums import Format, convert_buffer_type, get_format_from_dtype
from pyoptix.context import current_context
from pyoptix.mixins.bindless import BindlessMixin
from pyoptix.mixins.destroyable import DestroyableObject
from pyoptix.mixins.hascontext import HasContextMixin



class Buffer(HasContextMixin, DestroyableObject, BindlessMixin):
    def __init__(self, buffer_type='io'):
        HasContextMixin.__init__(self, current_context())
        DestroyableObject.__init__(self, self._safe_context._create_buffer(convert_buffer_type(buffer_type)))

        BindlessMixin.__init__(self)