利用者:Jwilkins/VFX/Aspects

提供: wiki
< 利用者:Jwilkins‎ | VFX
2013年9月24日 (火) 08:32時点におけるwiki>Jwilkinsによる版 (Created page with "= Aspects = Header File: <tt>GPU_aspect.h</tt> An ''aspect'' is a collection of shaders and other features grouped together to do a particular kind of drawing in ''Blender''. A...")
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Aspects

Header File: GPU_aspect.h

An aspect is a collection of shaders and other features grouped together to do a particular kind of drawing in Blender. At a low level aspects can be thought of as a module that handles compiling and choosing between OpenGL shaders. For example, there is an aspect that manages shaders for drawing fonts, another for drawing solid 3D meshes, and another for drawing wire frame objects.

The term aspect is taken from aspect-oriented programming (AOP). The idea is that each way of drawing in Blender is a different facet of the more general task of drawing. In the language of AOP, which shader to use at a given time is a "cross cutting concern" of Blender and each kind of drawing (or aspect of drawing) should be controlled through a different module and choosing which module to use should be centralized.

Why do we need a special term here? Because words like renderer, shader, and context are already taken and choosing one of those would overload an already overburdened term.

The current interface may seem over-engineered, but this is because the interface is designed to allow for additional features, such as multi-pass drawing and the ability to select between polymorphic implementations of each aspect at runtime (including implementations created in Python). For this reason the interface should be considered experimental, as it could be either simplified or embellished as this feature evolves.

Objects

void GPU_gen_aspects   (size_t count,       uint32_t* aspects);
void GPU_delete_aspects(size_t count, const uint32_t* aspects);

Aspects are indexed by a uint32_t. Creating and destroying those indexes is done using GPU_gen_aspects and GPU_delete_aspects.

These functions operate similarly to OpenGL Gen and Delete functions.

Implementations

typedef struct GPUaspectimpl {
	bool  (*render_begin )(const void* object, void* param);
	bool  (*render_end   )(const void* object, void* param);
	bool  (*render_commit)(const void* object);
	bool  (*select_begin )(const void* object, void* param);
	bool  (*select_end   )(const void* object, void* param);
	bool  (*select_commit)(const void* object);
	void  (*enable       )(const void* object, uint32_t options);
	void  (*disable      )(const void* object, uint32_t options);
	void* object;
} GPUaspectimpl;

void GPU_aspect_impl(uint32_t aspect, GPUaspectimpl* aspectImpl);

Aspects are implemented by a table of functions held in a GPUaspectimpl structure. The implementation of an aspect is set by GPU_aspect_impl.

The aspect module does not own the pointer to this table, so it will not be freed when GPU_delete_aspect is called. It is up to the allocator of the GPUaspectimpl to free it if it was allocated dynamically, but not before GPU_delete_aspect is called or GPU_aspect_impl is called with a different pointer.

Setting the implementation pointer to NULL will return the implementation to its original state (which is a dummy implementation).

Creating a new implementation requires understanding what each of these functions is supposed to do, however the aspect module is still in development, so the functions and their purpose are subject to change.

The object field is meant so that different aspect implementations may use the same functions but have a separate workspace (like a this pointer in C++).

Switching

bool GPU_aspect_begin(uint32_t aspect, const void* object);
bool GPU_aspect_end(void);

Currently the param parameter is always NULL. The param parameter is intended to provide a local context for an aspect so that it can behave different depending on where it is called.

Header File: GPU_blender_aspect.h

GPU_ASPECT_BASIC
GPU_ASPECT_CODEGEN
GPU_ASPECT_FONT
GPU_ASPECT_PIXELS
GPU_ASPECT_RASTER
GPU_ASPECT_SPRITE

These are built-in aspects for Blender that can be in the aspect field of GPU_aspect_begin, GPU_aspect_enable, and GPU_aspect_disable.

Options

void GPU_aspect_enable (uint32_t aspect, uint32_t options);
void GPU_aspect_disable(uint32_t aspect, uint32_t options);

These functions set and reset flags in the context of each aspect. For example, in GPU_ASPECT_BASIC the GPU_BASIC_LIGHTING flag enables or disables whether lighting computations are done.

Commit

void GPU_commit_aspect(void);

Before drawing anything the GPU_commit_aspect function must be called so that all state needed by the current aspect can be "committed" to the OpenGL driver.