mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
Python: Added support for GPU python module in background mode
This commit adds an init method to the gpu module. It allows for a more direct and intuitive way of enabling use of the gpu python module in background mode. Currently, a workaround exists to enable use of the gpu module which involves calling the bpy.ops.render.render() operator. This is rather uninituitive and hard to find. See `tests/python/modules/gpu_info.py` Co-authored-by: tobias <tobiaskrantz33@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/155400
This commit is contained in:
parent
f9766474ee
commit
a6f60f8657
5 changed files with 104 additions and 3 deletions
|
|
@ -265,6 +265,32 @@ add_blender_test(
|
|||
--python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_bpy_app.py
|
||||
)
|
||||
|
||||
if (WITH_GPU_BACKEND_TESTS)
|
||||
if(WITH_OPENGL_BACKEND)
|
||||
add_blender_test(
|
||||
script_pyapi_gpu_opengl
|
||||
--python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_gpu.py
|
||||
--gpu-backend opengl
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WITH_METAL_BACKEND)
|
||||
add_blender_test(
|
||||
script_pyapi_gpu_metal
|
||||
--python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_gpu.py
|
||||
--gpu-backend metal
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WITH_VULKAN_BACKEND)
|
||||
add_blender_test(
|
||||
script_pyapi_gpu_vulkan
|
||||
--python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_gpu.py
|
||||
--gpu-backend vulkan
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_blender_test(
|
||||
script_pyapi_bpy_app_tempdir
|
||||
--python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_bpy_app_tempdir.py
|
||||
|
|
|
|||
31
tests/python/bl_pyapi_gpu.py
Normal file
31
tests/python/bl_pyapi_gpu.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# SPDX-FileCopyrightText: 2026 Blender Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#
|
||||
# blender -b --factory-startup --python tests/python/bl_pyapi_gpu.py
|
||||
|
||||
import unittest
|
||||
|
||||
import gpu
|
||||
|
||||
|
||||
class TestGpuInit(unittest.TestCase):
|
||||
def test_gpu_module_is_usable_after_init(self):
|
||||
gpu.init()
|
||||
|
||||
# GPU module functions will raise SystemError if the GPU has not been initialized.
|
||||
gpu.platform.vendor_get()
|
||||
gpu.platform.renderer_get()
|
||||
gpu.platform.version_get()
|
||||
gpu.platform.device_type_get()
|
||||
gpu.types.GPUTexture(size=(1024, 1024), format="RGBA8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
sys.argv = [__file__] + (
|
||||
sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
||||
)
|
||||
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue