Changeset View
Standalone View
release/scripts/modules/gpu_extras/batch.py
- This file was added.
| # ##### BEGIN GPL LICENSE BLOCK ##### | |||||
| # | |||||
| # This program 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 2 | |||||
| # of the License, or (at your option) any later version. | |||||
| # | |||||
| # This program 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 this program; if not, write to the Free Software Foundation, | |||||
| # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| # | |||||
| # ##### END GPL LICENSE BLOCK ##### | |||||
| import bpy | |||||
| import gpu | |||||
mano-wii: Is the module `bpy` really necessary here? | |||||
Not Done Inline Actionsagree, will remove it JacquesLucke: agree, will remove it | |||||
Not Done Inline ActionsIn this case it might be better to put the import gpu inside the function. mano-wii: In this case it might be better to put the `import gpu` inside the function. | |||||
Not Done Inline Actionsnot sure if I agree on that one. Importing it here does not really increase load times. And we probably won't only have one function that uses this module later on. Doesn't make sense to import it in every function imo. JacquesLucke: not sure if I agree on that one. Importing it here does not really increase load times. And we… | |||||
| __all__ = ( | |||||
| "batch_for_shader" | |||||
| ) | |||||
| def batch_for_shader(shader, type, content, indices=None): | |||||
| length = max(len(data) for data in content.values()) | |||||
Not Done Inline ActionsI found strange this name batch_for_shader. Is it really descriptive? How about batch_create_for_shader? mano-wii: I found strange this name `batch_for_shader`. Is it really descriptive? How about… | |||||
Not Done Inline Actionsnoticed that too. While using the function I also noticed that you'll import it like from gpu_extras.batch import ... because otherwise the line that uses this function becomes so long. For that reason it makes sense to keep "batch" in the name. Maybe we don't need the batch.py module though. I mean, it deals with all kinds of different types, so maybe it could just be importable from gpu_extras directly. For the name, personally I don't like changing the order of words like that. create_batch_for_shader (or some synonym for "create") sounds more natural and is easier to remember imo. Otherwise I always have to think how the word order was again... JacquesLucke: noticed that too. While using the function I also noticed that you'll import it like `from… | |||||
Not Done Inline Actionsformat_get would also not be a good name because, at least in C, several formats are compatible. It depends on the fetch. mano-wii: `format_get` would also not be a good name because, at least in C, several formats are… | |||||
| vbo_format = shader.format_calc() | |||||
| vbo = gpu.types.GPUVertBuf(vbo_format, length) | |||||
| for identifier, data in content.items(): | |||||
| vbo.fill_attribute(identifier, data) | |||||
| if indices is None: | |||||
| return gpu.types.GPUBatch(type=type, buf=vbo) | |||||
| else: | |||||
| ibo = gpu.types.GPUIndexBuf(type=type, seq=indices) | |||||
| return gpu.types.GPUBatch(type=type, buf=vbo, elem=ibo) | |||||
Not Done Inline ActionsConverted into an exception, since assert can be disabled. campbellbarton: Converted into an exception, since assert can be disabled. | |||||
Is the module bpy really necessary here?