Files
rk_pve/pygl/texture.py
2025-10-21 13:18:23 +02:00

67 lines
2.1 KiB
Python

# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
from . import libgl
class Texture:
__slots__ = '_geometry', '_format', '_texture'
def __init__(self, geometry, format):
self._geometry = geometry
self._format = format
self._texture = libgl.create_texture(geometry.width, geometry.height, format.channels, format.depth)
def __del__(self):
libgl.delete_texture(self._texture)
@property
def geometry(self):
return self._geometry
@property
def width(self):
return self._geometry._width
@property
def height(self):
return self._geometry._height
@property
def ratio(self):
return self._geometry._ratio
@property
def format(self):
return self._format
@property
def channels(self):
return self._format._channels
@property
def depth(self):
return self._format._depth
def upload(self, pixmap):
assert (self._format == pixmap.format)
assert (self._geometry >= pixmap.geometry)
return libgl.upload_texture(self._texture, pixmap.view, pixmap.line_size)
def download(self, pixmap):
assert (self._format == pixmap.format)
assert (self._geometry >= pixmap.geometry)
return libgl.upload_texture(self._texture, pixmap.view, pixmap.line_size)