Cleanup: replace attrib w/ attr
Also rename GPUVertexAttribs to GPUVertAttrLayers, avoids confusion with GPUVertAttr which isn't closely related.
This commit is contained in:
@@ -408,8 +408,8 @@ void EEVEE_lightprobes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedat
|
||||
|
||||
/* Planar Display */
|
||||
DRW_shgroup_instance_format(e_data.format_probe_display_planar, {
|
||||
{"probe_id", DRW_ATTRIB_INT, 1},
|
||||
{"probe_mat", DRW_ATTRIB_FLOAT, 16},
|
||||
{"probe_id", DRW_ATTR_INT, 1},
|
||||
{"probe_mat", DRW_ATTR_FLOAT, 16},
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
|
||||
@@ -478,7 +478,7 @@ void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderLayer *rl
|
||||
/* Sort transparents before the loop. */
|
||||
DRW_pass_sort_shgroup_z(psl->transparent_pass);
|
||||
|
||||
/* Push instances attribs to the GPU. */
|
||||
/* Push instances attributes to the GPU. */
|
||||
DRW_render_instance_buffer_finish();
|
||||
|
||||
/* Need to be called after DRW_render_instance_buffer_finish() */
|
||||
|
||||
@@ -21,7 +21,7 @@ void main()
|
||||
worldNormal = viewNormal = normalize(-viewPosition);
|
||||
#endif
|
||||
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(viewPosition);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(viewPosition);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ void main() {
|
||||
for (int v = 0; v < 3; ++v) {
|
||||
gl_Position = vPos[v];
|
||||
worldPosition = x_axis[fFace] * vPos[v].x + y_axis[fFace] * vPos[v].y + maj_axes[fFace];
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(v);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(v);
|
||||
#endif
|
||||
EmitVertex();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat3 WorldNormalMatrix;
|
||||
#ifndef ATTRIB
|
||||
#ifndef USE_ATTR
|
||||
uniform mat4 ModelMatrix;
|
||||
uniform mat3 NormalMatrix;
|
||||
uniform mat4 ModelMatrixInverse;
|
||||
@@ -73,7 +73,7 @@ void main()
|
||||
/* Used for planar reflections */
|
||||
gl_ClipDistance[0] = dot(vec4(worldPosition, 1.0), ClipPlanes[0]);
|
||||
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(pos);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ uniform mat4 ModelViewProjectionMatrix;
|
||||
#ifdef MESH_SHADER
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat3 WorldNormalMatrix;
|
||||
# ifndef ATTRIB
|
||||
# ifndef USE_ATTR
|
||||
uniform mat4 ModelMatrix;
|
||||
uniform mat3 NormalMatrix;
|
||||
# endif
|
||||
@@ -26,8 +26,8 @@ void main() {
|
||||
worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
|
||||
viewNormal = normalize(NormalMatrix * nor);
|
||||
worldNormal = normalize(WorldNormalMatrix * nor);
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(pos);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(pos);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -17,20 +17,20 @@ flat out int slice;
|
||||
void main() {
|
||||
gl_Layer = slice = int(vPos[0].z);
|
||||
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(0);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(0);
|
||||
#endif
|
||||
gl_Position = vPos[0].xyww;
|
||||
EmitVertex();
|
||||
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(1);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(1);
|
||||
#endif
|
||||
gl_Position = vPos[1].xyww;
|
||||
EmitVertex();
|
||||
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(2);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(2);
|
||||
#endif
|
||||
gl_Position = vPos[2].xyww;
|
||||
EmitVertex();
|
||||
@@ -46,20 +46,20 @@ void main() {
|
||||
void main() {
|
||||
gl_Layer = slice = int(vPos[0].z);
|
||||
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(0);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(0);
|
||||
#endif
|
||||
gl_Position = vPos[0].xyww;
|
||||
EmitVertex();
|
||||
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(1);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(1);
|
||||
#endif
|
||||
gl_Position = vPos[1].xyww;
|
||||
EmitVertex();
|
||||
|
||||
#ifdef ATTRIB
|
||||
pass_attrib(2);
|
||||
#ifdef USE_ATTR
|
||||
pass_attr(2);
|
||||
#endif
|
||||
gl_Position = vPos[2].xyww;
|
||||
EmitVertex();
|
||||
|
||||
@@ -319,21 +319,21 @@ typedef enum {
|
||||
#define DRW_STATE_DEFAULT (DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL)
|
||||
|
||||
typedef enum {
|
||||
DRW_ATTRIB_INT,
|
||||
DRW_ATTRIB_FLOAT,
|
||||
} DRWAttribType;
|
||||
DRW_ATTR_INT,
|
||||
DRW_ATTR_FLOAT,
|
||||
} eDRWAttrType;
|
||||
|
||||
typedef struct DRWInstanceAttribFormat {
|
||||
typedef struct DRWInstanceAttrFormat {
|
||||
char name[32];
|
||||
DRWAttribType type;
|
||||
eDRWAttrType type;
|
||||
int components;
|
||||
} DRWInstanceAttribFormat;
|
||||
} DRWInstanceAttrFormat;
|
||||
|
||||
struct GPUVertFormat *DRW_shgroup_instance_format_array(const DRWInstanceAttribFormat attribs[], int arraysize);
|
||||
struct GPUVertFormat *DRW_shgroup_instance_format_array(const DRWInstanceAttrFormat attrs[], int arraysize);
|
||||
#define DRW_shgroup_instance_format(format, ...) do { \
|
||||
if (format == NULL) { \
|
||||
DRWInstanceAttribFormat drw_format[] = __VA_ARGS__;\
|
||||
format = DRW_shgroup_instance_format_array(drw_format, (sizeof(drw_format) / sizeof(DRWInstanceAttribFormat))); \
|
||||
DRWInstanceAttrFormat drw_format[] = __VA_ARGS__;\
|
||||
format = DRW_shgroup_instance_format_array(drw_format, (sizeof(drw_format) / sizeof(DRWInstanceAttrFormat))); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -383,7 +383,7 @@ void DRW_shgroup_call_object_add_ex(
|
||||
void DRW_shgroup_call_object_add_with_callback(
|
||||
DRWShadingGroup *shgroup, struct GPUBatch *geom, struct Object *ob, struct Material *ma,
|
||||
DRWCallVisibilityFn *callback, void *user_data);
|
||||
/* Used for drawing a batch with instancing without instance attribs. */
|
||||
/* Used for drawing a batch with instancing without instance attributes. */
|
||||
void DRW_shgroup_call_instances_add(
|
||||
DRWShadingGroup *shgroup, struct GPUBatch *geom, float (*obmat)[4], uint *count);
|
||||
void DRW_shgroup_call_object_instances_add(
|
||||
|
||||
@@ -304,16 +304,16 @@ static int curve_render_data_normal_len_get(const CurveRenderData *rdata)
|
||||
|
||||
static void curve_cd_calc_used_gpu_layers(int *cd_layers, struct GPUMaterial **gpumat_array, int gpumat_array_len)
|
||||
{
|
||||
GPUVertexAttribs gattribs = {{{0}}};
|
||||
GPUVertAttrLayers gpu_attrs = {{{0}}};
|
||||
for (int i = 0; i < gpumat_array_len; i++) {
|
||||
struct GPUMaterial *gpumat = gpumat_array[i];
|
||||
if (gpumat == NULL) {
|
||||
continue;
|
||||
}
|
||||
GPU_material_vertex_attributes(gpumat, &gattribs);
|
||||
for (int j = 0; j < gattribs.totlayer; j++) {
|
||||
const char *name = gattribs.layer[j].name;
|
||||
int type = gattribs.layer[j].type;
|
||||
GPU_material_vertex_attrs(gpumat, &gpu_attrs);
|
||||
for (int j = 0; j < gpu_attrs.totlayer; j++) {
|
||||
const char *name = gpu_attrs.layer[j].name;
|
||||
int type = gpu_attrs.layer[j].type;
|
||||
|
||||
/* Curves cannot have named layers.
|
||||
* Note: We could relax this assumption later. */
|
||||
@@ -662,7 +662,7 @@ static void curve_create_edit_curves_nor(CurveRenderData *rdata, GPUVertBuf *vbo
|
||||
GPUPackedNormal pnor = GPU_normal_convert_i10_v3(nor);
|
||||
GPUPackedNormal ptan = GPU_normal_convert_i10_v3(bevp->dir);
|
||||
|
||||
/* Only set attribs for one vertex. */
|
||||
/* Only set attributes for one vertex. */
|
||||
GPU_vertbuf_attr_set(vbo_curves_nor, attr_id.pos, vbo_len_used, bevp->vec);
|
||||
GPU_vertbuf_attr_set(vbo_curves_nor, attr_id.rad, vbo_len_used, &bevp->radius);
|
||||
GPU_vertbuf_attr_set(vbo_curves_nor, attr_id.nor, vbo_len_used, &pnor);
|
||||
@@ -897,7 +897,7 @@ void DRW_curve_batch_cache_create_requested(Object *ob)
|
||||
Curve *cu = ob->data;
|
||||
CurveBatchCache *cache = curve_batch_cache_get(cu);
|
||||
|
||||
/* Verify that all surface batches have needed attrib layers. */
|
||||
/* Verify that all surface batches have needed attribute layers. */
|
||||
/* TODO(fclem): We could be a bit smarter here and only do it per material. */
|
||||
for (int i = 0; i < cache->mat_len; ++i) {
|
||||
if ((cache->cd_used & cache->cd_needed) != cache->cd_needed) {
|
||||
|
||||
@@ -376,15 +376,15 @@ static void mesh_cd_calc_used_gpu_layers(
|
||||
const CustomData *cd_ldata = (me->edit_btmesh) ? &me->edit_btmesh->bm->ldata : &me->ldata;
|
||||
|
||||
/* See: DM_vertex_attributes_from_gpu for similar logic */
|
||||
GPUVertexAttribs gattribs = {{{0}}};
|
||||
GPUVertAttrLayers gpu_attrs = {{{0}}};
|
||||
|
||||
for (int i = 0; i < gpumat_array_len; i++) {
|
||||
GPUMaterial *gpumat = gpumat_array[i];
|
||||
if (gpumat) {
|
||||
GPU_material_vertex_attributes(gpumat, &gattribs);
|
||||
for (int j = 0; j < gattribs.totlayer; j++) {
|
||||
const char *name = gattribs.layer[j].name;
|
||||
int type = gattribs.layer[j].type;
|
||||
GPU_material_vertex_attrs(gpumat, &gpu_attrs);
|
||||
for (int j = 0; j < gpu_attrs.totlayer; j++) {
|
||||
const char *name = gpu_attrs.layer[j].name;
|
||||
int type = gpu_attrs.layer[j].type;
|
||||
int layer = -1;
|
||||
|
||||
if (type == CD_AUTO_FROM_NAME) {
|
||||
@@ -2101,7 +2101,7 @@ typedef struct MeshBatchCache {
|
||||
GPUBatch **surf_per_mat;
|
||||
|
||||
/* arrays of bool uniform names (and value) that will be use to
|
||||
* set srgb conversion for auto attribs.*/
|
||||
* set srgb conversion for auto attributes.*/
|
||||
char *auto_layer_names;
|
||||
int *auto_layer_is_srgb;
|
||||
int auto_layer_len;
|
||||
@@ -3103,15 +3103,15 @@ static void mesh_create_loop_uv_and_tan(MeshRenderData *rdata, GPUVertBuf *vbo)
|
||||
GPUVertFormat format = { 0 };
|
||||
|
||||
for (uint i = 0; i < uv_len; i++) {
|
||||
const char *attrib_name = mesh_render_data_uv_layer_uuid_get(rdata, i);
|
||||
const char *attr_name = mesh_render_data_uv_layer_uuid_get(rdata, i);
|
||||
#if 0 /* these are clamped. Maybe use them as an option in the future */
|
||||
uv_id[i] = GPU_vertformat_attr_add(&format, attrib_name, GPU_COMP_I16, 2, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
uv_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_I16, 2, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
#else
|
||||
uv_id[i] = GPU_vertformat_attr_add(&format, attrib_name, GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
uv_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
#endif
|
||||
/* Auto Name */
|
||||
attrib_name = mesh_render_data_uv_auto_layer_uuid_get(rdata, i);
|
||||
GPU_vertformat_alias_add(&format, attrib_name);
|
||||
attr_name = mesh_render_data_uv_auto_layer_uuid_get(rdata, i);
|
||||
GPU_vertformat_alias_add(&format, attr_name);
|
||||
|
||||
if (i == rdata->cd.layers.uv_active) {
|
||||
GPU_vertformat_alias_add(&format, "u");
|
||||
@@ -3119,18 +3119,18 @@ static void mesh_create_loop_uv_and_tan(MeshRenderData *rdata, GPUVertBuf *vbo)
|
||||
}
|
||||
|
||||
for (uint i = 0; i < tangent_len; i++) {
|
||||
const char *attrib_name = mesh_render_data_tangent_layer_uuid_get(rdata, i);
|
||||
const char *attr_name = mesh_render_data_tangent_layer_uuid_get(rdata, i);
|
||||
#ifdef USE_COMP_MESH_DATA
|
||||
tangent_id[i] = GPU_vertformat_attr_add(&format, attrib_name, GPU_COMP_I16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
tangent_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_I16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
#else
|
||||
tangent_id[i] = GPU_vertformat_attr_add(&format, attrib_name, GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
|
||||
tangent_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
|
||||
#endif
|
||||
if (i == rdata->cd.layers.tangent_active) {
|
||||
GPU_vertformat_alias_add(&format, "t");
|
||||
}
|
||||
}
|
||||
|
||||
/* HACK: Create a dummy attrib in case there is no valid UV/tangent layer. */
|
||||
/* HACK: Create a dummy attribute in case there is no valid UV/tangent layer. */
|
||||
if (layers_combined_len == 0) {
|
||||
GPU_vertformat_attr_add(&format, "dummy", GPU_COMP_U8, 1, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
}
|
||||
@@ -3218,12 +3218,12 @@ static void mesh_create_loop_vcol(MeshRenderData *rdata, GPUVertBuf *vbo)
|
||||
GPUVertFormat format = { 0 };
|
||||
|
||||
for (uint i = 0; i < vcol_len; i++) {
|
||||
const char *attrib_name = mesh_render_data_vcol_layer_uuid_get(rdata, i);
|
||||
vcol_id[i] = GPU_vertformat_attr_add(&format, attrib_name, GPU_COMP_U8, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
const char *attr_name = mesh_render_data_vcol_layer_uuid_get(rdata, i);
|
||||
vcol_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_U8, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
/* Auto layer */
|
||||
if (rdata->cd.layers.auto_vcol[i]) {
|
||||
attrib_name = mesh_render_data_vcol_auto_layer_uuid_get(rdata, i);
|
||||
GPU_vertformat_alias_add(&format, attrib_name);
|
||||
attr_name = mesh_render_data_vcol_auto_layer_uuid_get(rdata, i);
|
||||
GPU_vertformat_alias_add(&format, attr_name);
|
||||
}
|
||||
if (i == rdata->cd.layers.vcol_active) {
|
||||
GPU_vertformat_alias_add(&format, "c");
|
||||
@@ -4980,7 +4980,7 @@ void DRW_mesh_batch_cache_create_requested(
|
||||
drw_mesh_weight_state_clear(&wstate);
|
||||
}
|
||||
|
||||
/* Verify that all surface batches have needed attrib layers. */
|
||||
/* Verify that all surface batches have needed attribute layers. */
|
||||
/* TODO(fclem): We could be a bit smarter here and only do it per material. */
|
||||
bool cd_overlap = mesh_cd_layers_type_overlap(cache->cd_vused, cache->cd_lused,
|
||||
cache->cd_vneeded, cache->cd_lneeded);
|
||||
|
||||
@@ -1174,8 +1174,8 @@ static void particle_batch_cache_ensure_pos_and_seg(
|
||||
attr_id.ind = GPU_vertformat_attr_add(&format, "ind", GPU_COMP_I32, 1, GPU_FETCH_INT);
|
||||
|
||||
if (psmd) {
|
||||
uv_id = MEM_mallocN(sizeof(*uv_id) * num_uv_layers, "UV attrib format");
|
||||
col_id = MEM_mallocN(sizeof(*col_id) * num_col_layers, "Col attrib format");
|
||||
uv_id = MEM_mallocN(sizeof(*uv_id) * num_uv_layers, "UV attr format");
|
||||
col_id = MEM_mallocN(sizeof(*col_id) * num_col_layers, "Col attr format");
|
||||
|
||||
for (int i = 0; i < num_uv_layers; i++) {
|
||||
const char *name = CustomData_get_layer_name(&psmd->mesh_final->ldata, CD_MLOOPUV, i);
|
||||
|
||||
@@ -318,8 +318,8 @@ DRWShadingGroup *shgroup_dynlines_flat_color(DRWPass *pass)
|
||||
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.dynlines_color, {
|
||||
{"pos", DRW_ATTRIB_FLOAT, 3},
|
||||
{"color", DRW_ATTRIB_FLOAT, 4}
|
||||
{"pos", DRW_ATTR_FLOAT, 3},
|
||||
{"color", DRW_ATTR_FLOAT, 4}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_line_batch_create_with_format(sh, pass, g_formats.dynlines_color);
|
||||
@@ -385,8 +385,8 @@ DRWShadingGroup *shgroup_instance_screenspace(
|
||||
GPUShader *sh = DRW_shader_get_builtin_shader(GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR, shader_slot);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_screenspace, {
|
||||
{"world_pos", DRW_ATTRIB_FLOAT, 3},
|
||||
{"color", DRW_ATTRIB_FLOAT, 3}
|
||||
{"world_pos", DRW_ATTR_FLOAT, 3},
|
||||
{"color", DRW_ATTR_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_screenspace);
|
||||
@@ -405,8 +405,8 @@ DRWShadingGroup *shgroup_instance_solid(DRWPass *pass, struct GPUBatch *geom)
|
||||
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_color, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"color", DRW_ATTRIB_FLOAT, 4}
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
||||
{"color", DRW_ATTR_FLOAT, 4}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_color);
|
||||
@@ -420,8 +420,8 @@ DRWShadingGroup *shgroup_instance_wire(DRWPass *pass, struct GPUBatch *geom)
|
||||
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_color, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"color", DRW_ATTRIB_FLOAT, 4}
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
||||
{"color", DRW_ATTR_FLOAT, 4}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_color);
|
||||
@@ -435,9 +435,9 @@ DRWShadingGroup *shgroup_instance_screen_aligned(
|
||||
GPUShader *sh = DRW_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED, shader_slot);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_screen_aligned, {
|
||||
{"color", DRW_ATTRIB_FLOAT, 3},
|
||||
{"size", DRW_ATTRIB_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"color", DRW_ATTR_FLOAT, 3},
|
||||
{"size", DRW_ATTR_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_screen_aligned);
|
||||
@@ -453,9 +453,9 @@ DRWShadingGroup *shgroup_instance_scaled(DRWPass *pass, struct GPUBatch *geom, e
|
||||
GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE, shader_slot);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_scaled, {
|
||||
{"color", DRW_ATTRIB_FLOAT, 3},
|
||||
{"size", DRW_ATTRIB_FLOAT, 3},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"color", DRW_ATTR_FLOAT, 3},
|
||||
{"size", DRW_ATTR_FLOAT, 3},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_scaled);
|
||||
@@ -470,9 +470,9 @@ DRWShadingGroup *shgroup_instance(DRWPass *pass, struct GPUBatch *geom, eDRW_Sha
|
||||
GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, shader_slot);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_sized, {
|
||||
{"color", DRW_ATTRIB_FLOAT, 4},
|
||||
{"size", DRW_ATTRIB_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"color", DRW_ATTR_FLOAT, 4},
|
||||
{"size", DRW_ATTR_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
|
||||
@@ -488,9 +488,9 @@ DRWShadingGroup *shgroup_instance_alpha(DRWPass *pass, struct GPUBatch *geom, eD
|
||||
GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, shader_slot);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_sized, {
|
||||
{"color", DRW_ATTRIB_FLOAT, 4},
|
||||
{"size", DRW_ATTRIB_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"color", DRW_ATTR_FLOAT, 4},
|
||||
{"size", DRW_ATTR_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
|
||||
@@ -513,9 +513,9 @@ DRWShadingGroup *shgroup_instance_empty_axes(DRWPass *pass, struct GPUBatch *geo
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_sized, {
|
||||
{"color", DRW_ATTRIB_FLOAT, 3},
|
||||
{"size", DRW_ATTRIB_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"color", DRW_ATTR_FLOAT, 3},
|
||||
{"size", DRW_ATTR_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_data->empty_axes_sh, pass, geom, g_formats.instance_sized);
|
||||
@@ -531,9 +531,9 @@ DRWShadingGroup *shgroup_instance_outline(DRWPass *pass, struct GPUBatch *geom,
|
||||
GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_outline, {
|
||||
{"callId", DRW_ATTRIB_INT, 1},
|
||||
{"size", DRW_ATTRIB_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"callId", DRW_ATTR_INT, 1},
|
||||
{"size", DRW_ATTR_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_outline);
|
||||
@@ -547,11 +547,11 @@ DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom, e
|
||||
GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_CAMERA, shader_slot);
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_camera, {
|
||||
{"color", DRW_ATTRIB_FLOAT, 3},
|
||||
{"corners", DRW_ATTRIB_FLOAT, 8},
|
||||
{"depth", DRW_ATTRIB_FLOAT, 1},
|
||||
{"tria", DRW_ATTRIB_FLOAT, 4},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"color", DRW_ATTR_FLOAT, 3},
|
||||
{"corners", DRW_ATTR_FLOAT, 8},
|
||||
{"depth", DRW_ATTR_FLOAT, 1},
|
||||
{"tria", DRW_ATTR_FLOAT, 4},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_camera);
|
||||
@@ -567,10 +567,10 @@ DRWShadingGroup *shgroup_distance_lines_instance(DRWPass *pass, struct GPUBatch
|
||||
static float point_size = 4.0f;
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_distance_lines, {
|
||||
{"color", DRW_ATTRIB_FLOAT, 3},
|
||||
{"start", DRW_ATTRIB_FLOAT, 1},
|
||||
{"end", DRW_ATTRIB_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"color", DRW_ATTR_FLOAT, 3},
|
||||
{"start", DRW_ATTR_FLOAT, 1},
|
||||
{"end", DRW_ATTR_FLOAT, 1},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_distance_lines);
|
||||
@@ -586,8 +586,8 @@ DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct GPUBatch *geom)
|
||||
static const int False = false;
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_spot, {
|
||||
{"color", DRW_ATTRIB_FLOAT, 3},
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
|
||||
{"color", DRW_ATTR_FLOAT, 3},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_spot);
|
||||
@@ -608,8 +608,8 @@ DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_color, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"color", DRW_ATTRIB_FLOAT, 4}
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
||||
{"color", DRW_ATTR_FLOAT, 4}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -631,10 +631,10 @@ DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass)
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope_outline, {
|
||||
{"headSphere", DRW_ATTRIB_FLOAT, 4},
|
||||
{"tailSphere", DRW_ATTRIB_FLOAT, 4},
|
||||
{"outlineColorSize", DRW_ATTRIB_FLOAT, 4},
|
||||
{"xAxis", DRW_ATTRIB_FLOAT, 3}
|
||||
{"headSphere", DRW_ATTR_FLOAT, 4},
|
||||
{"tailSphere", DRW_ATTR_FLOAT, 4},
|
||||
{"outlineColorSize", DRW_ATTR_FLOAT, 4},
|
||||
{"xAxis", DRW_ATTR_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -656,9 +656,9 @@ DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope_distance, {
|
||||
{"headSphere", DRW_ATTRIB_FLOAT, 4},
|
||||
{"tailSphere", DRW_ATTRIB_FLOAT, 4},
|
||||
{"xAxis", DRW_ATTRIB_FLOAT, 3}
|
||||
{"headSphere", DRW_ATTR_FLOAT, 4},
|
||||
{"tailSphere", DRW_ATTR_FLOAT, 4},
|
||||
{"xAxis", DRW_ATTR_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -679,11 +679,11 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope, {
|
||||
{"headSphere", DRW_ATTRIB_FLOAT, 4},
|
||||
{"tailSphere", DRW_ATTRIB_FLOAT, 4},
|
||||
{"boneColor", DRW_ATTRIB_FLOAT, 3},
|
||||
{"stateColor", DRW_ATTRIB_FLOAT, 3},
|
||||
{"xAxis", DRW_ATTRIB_FLOAT, 3}
|
||||
{"headSphere", DRW_ATTR_FLOAT, 4},
|
||||
{"tailSphere", DRW_ATTR_FLOAT, 4},
|
||||
{"boneColor", DRW_ATTR_FLOAT, 3},
|
||||
{"stateColor", DRW_ATTR_FLOAT, 3},
|
||||
{"xAxis", DRW_ATTR_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -705,9 +705,9 @@ DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_mball_handles, {
|
||||
{"ScaleTranslationMatrix", DRW_ATTRIB_FLOAT, 12},
|
||||
{"radius", DRW_ATTRIB_FLOAT, 1},
|
||||
{"color", DRW_ATTRIB_FLOAT, 3}
|
||||
{"ScaleTranslationMatrix", DRW_ATTR_FLOAT, 12},
|
||||
{"radius", DRW_ATTR_FLOAT, 1},
|
||||
{"color", DRW_ATTR_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -732,8 +732,8 @@ DRWShadingGroup *shgroup_instance_bone_shape_outline(DRWPass *pass, struct GPUBa
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_outline, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"outlineColorSize", DRW_ATTRIB_FLOAT, 4}
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
||||
{"outlineColorSize", DRW_ATTR_FLOAT, 4}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -754,9 +754,9 @@ DRWShadingGroup *shgroup_instance_bone_shape_solid(DRWPass *pass, struct GPUBatc
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"boneColor", DRW_ATTRIB_FLOAT, 3},
|
||||
{"stateColor", DRW_ATTRIB_FLOAT, 3}
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
||||
{"boneColor", DRW_ATTR_FLOAT, 3},
|
||||
{"stateColor", DRW_ATTR_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -777,9 +777,9 @@ DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp)
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"boneColor", DRW_ATTRIB_FLOAT, 3},
|
||||
{"stateColor", DRW_ATTRIB_FLOAT, 3}
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
||||
{"boneColor", DRW_ATTR_FLOAT, 3},
|
||||
{"stateColor", DRW_ATTR_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -801,8 +801,8 @@ DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass)
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_outline, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"outlineColorSize", DRW_ATTRIB_FLOAT, 4}
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
||||
{"outlineColorSize", DRW_ATTR_FLOAT, 4}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -824,12 +824,12 @@ DRWShadingGroup *shgroup_instance_bone_stick(DRWPass *pass)
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_stick, {
|
||||
{"boneStart", DRW_ATTRIB_FLOAT, 3},
|
||||
{"boneEnd", DRW_ATTRIB_FLOAT, 3},
|
||||
{"wireColor", DRW_ATTRIB_FLOAT, 4}, /* TODO port theses to uchar color */
|
||||
{"boneColor", DRW_ATTRIB_FLOAT, 4},
|
||||
{"headColor", DRW_ATTRIB_FLOAT, 4},
|
||||
{"tailColor", DRW_ATTRIB_FLOAT, 4}
|
||||
{"boneStart", DRW_ATTR_FLOAT, 3},
|
||||
{"boneEnd", DRW_ATTR_FLOAT, 3},
|
||||
{"wireColor", DRW_ATTR_FLOAT, 4}, /* TODO port theses to uchar color */
|
||||
{"boneColor", DRW_ATTR_FLOAT, 4},
|
||||
{"headColor", DRW_ATTR_FLOAT, 4},
|
||||
{"tailColor", DRW_ATTR_FLOAT, 4}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
@@ -852,10 +852,10 @@ struct DRWShadingGroup *shgroup_instance_bone_dof(struct DRWPass *pass, struct G
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_dof, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"color", DRW_ATTRIB_FLOAT, 4},
|
||||
{"amin", DRW_ATTRIB_FLOAT, 2},
|
||||
{"amax", DRW_ATTRIB_FLOAT, 2},
|
||||
{"InstanceModelMatrix", DRW_ATTR_FLOAT, 16},
|
||||
{"color", DRW_ATTR_FLOAT, 4},
|
||||
{"amin", DRW_ATTR_FLOAT, 2},
|
||||
{"amax", DRW_ATTR_FLOAT, 2},
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(
|
||||
|
||||
@@ -290,24 +290,24 @@ void DRW_instance_buffer_finish(DRWInstanceDataList *idatalist)
|
||||
/** \name Instance Data (DRWInstanceData)
|
||||
* \{ */
|
||||
|
||||
static DRWInstanceData *drw_instance_data_create(DRWInstanceDataList *idatalist, uint attrib_size)
|
||||
static DRWInstanceData *drw_instance_data_create(DRWInstanceDataList *idatalist, uint attr_size)
|
||||
{
|
||||
DRWInstanceData *idata = MEM_callocN(sizeof(DRWInstanceData), "DRWInstanceData");
|
||||
idata->next = NULL;
|
||||
idata->used = true;
|
||||
idata->data_size = attrib_size;
|
||||
idata->data_size = attr_size;
|
||||
idata->mempool = BLI_mempool_create(sizeof(float) * idata->data_size, 0, 16, 0);
|
||||
|
||||
BLI_assert(attrib_size > 0);
|
||||
BLI_assert(attr_size > 0);
|
||||
|
||||
/* Push to linked list. */
|
||||
if (idatalist->idata_head[attrib_size - 1] == NULL) {
|
||||
idatalist->idata_head[attrib_size - 1] = idata;
|
||||
if (idatalist->idata_head[attr_size - 1] == NULL) {
|
||||
idatalist->idata_head[attr_size - 1] = idata;
|
||||
}
|
||||
else {
|
||||
idatalist->idata_tail[attrib_size - 1]->next = idata;
|
||||
idatalist->idata_tail[attr_size - 1]->next = idata;
|
||||
}
|
||||
idatalist->idata_tail[attrib_size - 1] = idata;
|
||||
idatalist->idata_tail[attr_size - 1] = idata;
|
||||
|
||||
return idata;
|
||||
}
|
||||
@@ -325,11 +325,11 @@ void *DRW_instance_data_next(DRWInstanceData *idata)
|
||||
return BLI_mempool_alloc(idata->mempool);
|
||||
}
|
||||
|
||||
DRWInstanceData *DRW_instance_data_request(DRWInstanceDataList *idatalist, uint attrib_size)
|
||||
DRWInstanceData *DRW_instance_data_request(DRWInstanceDataList *idatalist, uint attr_size)
|
||||
{
|
||||
BLI_assert(attrib_size > 0 && attrib_size <= MAX_INSTANCE_DATA_SIZE);
|
||||
BLI_assert(attr_size > 0 && attr_size <= MAX_INSTANCE_DATA_SIZE);
|
||||
|
||||
DRWInstanceData *idata = idatalist->idata_head[attrib_size - 1];
|
||||
DRWInstanceData *idata = idatalist->idata_head[attr_size - 1];
|
||||
|
||||
/* Search for an unused data chunk. */
|
||||
for (; idata; idata = idata->next) {
|
||||
@@ -339,7 +339,7 @@ DRWInstanceData *DRW_instance_data_request(DRWInstanceDataList *idatalist, uint
|
||||
}
|
||||
}
|
||||
|
||||
return drw_instance_data_create(idatalist, attrib_size);
|
||||
return drw_instance_data_create(idatalist, attr_size);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -43,7 +43,7 @@ struct DRWShadingGroup;
|
||||
|
||||
void *DRW_instance_data_next(DRWInstanceData *idata);
|
||||
DRWInstanceData *DRW_instance_data_request(
|
||||
DRWInstanceDataList *idatalist, uint attrib_size);
|
||||
DRWInstanceDataList *idatalist, uint attr_size);
|
||||
|
||||
void DRW_batching_buffer_request(
|
||||
DRWInstanceDataList *idatalist, GPUVertFormat *format, GPUPrimType type, struct DRWShadingGroup *shgroup,
|
||||
|
||||
@@ -1765,7 +1765,7 @@ void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph *depsgraph
|
||||
drw_viewport_var_init();
|
||||
|
||||
/* set default viewport */
|
||||
gpuPushAttrib(GPU_ENABLE_BIT | GPU_VIEWPORT_BIT);
|
||||
gpuPushAttr(GPU_ENABLE_BIT | GPU_VIEWPORT_BIT);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glViewport(0, 0, size[0], size[1]);
|
||||
|
||||
@@ -1790,7 +1790,7 @@ void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph *depsgraph
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
/* Restore Drawing area. */
|
||||
gpuPopAttrib();
|
||||
gpuPopAttr();
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
GPU_framebuffer_restore();
|
||||
|
||||
|
||||
@@ -135,11 +135,16 @@ typedef struct DRWCallState {
|
||||
} DRWCallState;
|
||||
|
||||
typedef enum {
|
||||
DRW_CALL_SINGLE, /* A single batch */
|
||||
DRW_CALL_RANGE, /* Like single but only draw a range of vertices/indices. */
|
||||
DRW_CALL_INSTANCES, /* Draw instances without any instancing attribs. */
|
||||
DRW_CALL_GENERATE, /* Uses a callback to draw with any number of batches. */
|
||||
DRW_CALL_PROCEDURAL, /* Generate a drawcall without any GPUBatch. */
|
||||
/** A single batch. */
|
||||
DRW_CALL_SINGLE,
|
||||
/** Like single but only draw a range of vertices/indices. */
|
||||
DRW_CALL_RANGE,
|
||||
/** Draw instances without any instancing attributes. */
|
||||
DRW_CALL_INSTANCES,
|
||||
/** Uses a callback to draw with any number of batches. */
|
||||
DRW_CALL_GENERATE,
|
||||
/** Generate a drawcall without any #GPUBatch. */
|
||||
DRW_CALL_PROCEDURAL,
|
||||
} DRWCallType;
|
||||
|
||||
typedef struct DRWCall {
|
||||
@@ -268,7 +273,7 @@ struct DRWShadingGroup {
|
||||
|
||||
DRWPass *pass_parent; /* backlink to pass we're in */
|
||||
#ifndef NDEBUG
|
||||
char attribs_count;
|
||||
char attrs_count;
|
||||
#endif
|
||||
#ifdef USE_GPU_SELECT
|
||||
GPUVertBuf *inst_selectid;
|
||||
|
||||
@@ -608,7 +608,7 @@ void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *at
|
||||
}
|
||||
#endif
|
||||
|
||||
BLI_assert(attr_len == shgroup->attribs_count);
|
||||
BLI_assert(attr_len == shgroup->attrs_count);
|
||||
UNUSED_VARS_NDEBUG(attr_len);
|
||||
|
||||
for (int i = 0; i < attr_len; ++i) {
|
||||
@@ -638,7 +638,7 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
|
||||
shgroup->override_selectid = -1;
|
||||
#endif
|
||||
#ifndef NDEBUG
|
||||
shgroup->attribs_count = 0;
|
||||
shgroup->attrs_count = 0;
|
||||
#endif
|
||||
|
||||
int view_ubo_location = GPU_shader_get_uniform_block(shader, "viewBlock");
|
||||
@@ -710,7 +710,7 @@ static void drw_shgroup_instance_init(
|
||||
|
||||
shgroup->instance_geom = batch;
|
||||
#ifndef NDEBUG
|
||||
shgroup->attribs_count = format->attr_len;
|
||||
shgroup->attrs_count = format->attr_len;
|
||||
#endif
|
||||
|
||||
DRW_instancing_buffer_request(DST.idatalist, format, batch, shgroup,
|
||||
@@ -738,7 +738,7 @@ static void drw_shgroup_batching_init(
|
||||
drw_shgroup_init(shgroup, shader);
|
||||
|
||||
#ifndef NDEBUG
|
||||
shgroup->attribs_count = (format != NULL) ? format->attr_len : 0;
|
||||
shgroup->attrs_count = (format != NULL) ? format->attr_len : 0;
|
||||
#endif
|
||||
BLI_assert(format != NULL);
|
||||
|
||||
@@ -844,15 +844,16 @@ static DRWShadingGroup *drw_shgroup_material_inputs(DRWShadingGroup *grp, struct
|
||||
return grp;
|
||||
}
|
||||
|
||||
GPUVertFormat *DRW_shgroup_instance_format_array(const DRWInstanceAttribFormat attribs[], int arraysize)
|
||||
GPUVertFormat *DRW_shgroup_instance_format_array(const DRWInstanceAttrFormat attrs[], int arraysize)
|
||||
{
|
||||
GPUVertFormat *format = MEM_callocN(sizeof(GPUVertFormat), "GPUVertFormat");
|
||||
|
||||
for (int i = 0; i < arraysize; ++i) {
|
||||
GPU_vertformat_attr_add(format, attribs[i].name,
|
||||
(attribs[i].type == DRW_ATTRIB_INT) ? GPU_COMP_I32 : GPU_COMP_F32,
|
||||
attribs[i].components,
|
||||
(attribs[i].type == DRW_ATTRIB_INT) ? GPU_FETCH_INT : GPU_FETCH_FLOAT);
|
||||
GPU_vertformat_attr_add(
|
||||
format, attrs[i].name,
|
||||
(attrs[i].type == DRW_ATTR_INT) ? GPU_COMP_I32 : GPU_COMP_F32,
|
||||
attrs[i].components,
|
||||
(attrs[i].type == DRW_ATTR_INT) ? GPU_FETCH_INT : GPU_FETCH_FLOAT);
|
||||
}
|
||||
return format;
|
||||
}
|
||||
@@ -929,7 +930,7 @@ DRWShadingGroup *DRW_shgroup_instance_create(
|
||||
|
||||
DRWShadingGroup *DRW_shgroup_point_batch_create(struct GPUShader *shader, DRWPass *pass)
|
||||
{
|
||||
DRW_shgroup_instance_format(g_pos_format, {{"pos", DRW_ATTRIB_FLOAT, 3}});
|
||||
DRW_shgroup_instance_format(g_pos_format, {{"pos", DRW_ATTR_FLOAT, 3}});
|
||||
|
||||
DRWShadingGroup *shgroup = drw_shgroup_create_ex(shader, pass);
|
||||
shgroup->type = DRW_SHG_POINT_BATCH;
|
||||
@@ -952,14 +953,16 @@ DRWShadingGroup *DRW_shgroup_line_batch_create_with_format(
|
||||
|
||||
DRWShadingGroup *DRW_shgroup_line_batch_create(struct GPUShader *shader, DRWPass *pass)
|
||||
{
|
||||
DRW_shgroup_instance_format(g_pos_format, {{"pos", DRW_ATTRIB_FLOAT, 3}});
|
||||
DRW_shgroup_instance_format(g_pos_format, {{"pos", DRW_ATTR_FLOAT, 3}});
|
||||
|
||||
return DRW_shgroup_line_batch_create_with_format(shader, pass, g_pos_format);
|
||||
}
|
||||
|
||||
/* Very special batch. Use this if you position
|
||||
/**
|
||||
* Very special batch. Use this if you position
|
||||
* your vertices with the vertex shader
|
||||
* and dont need any VBO attrib */
|
||||
* and dont need any VBO attribute.
|
||||
*/
|
||||
DRWShadingGroup *DRW_shgroup_empty_tri_batch_create(struct GPUShader *shader, DRWPass *pass, int tri_count)
|
||||
{
|
||||
#ifdef USE_GPU_SELECT
|
||||
@@ -989,13 +992,15 @@ DRWShadingGroup *DRW_shgroup_transform_feedback_create(struct GPUShader *shader,
|
||||
return shgroup;
|
||||
}
|
||||
|
||||
/* Specify an external batch instead of adding each attrib one by one. */
|
||||
/**
|
||||
* Specify an external batch instead of adding each attribute one by one.
|
||||
*/
|
||||
void DRW_shgroup_instance_batch(DRWShadingGroup *shgroup, struct GPUBatch *batch)
|
||||
{
|
||||
BLI_assert(shgroup->type == DRW_SHG_INSTANCE);
|
||||
BLI_assert(shgroup->instance_count == 0);
|
||||
/* You cannot use external instancing batch without a dummy format. */
|
||||
BLI_assert(shgroup->attribs_count != 0);
|
||||
BLI_assert(shgroup->attrs_count != 0);
|
||||
|
||||
shgroup->type = DRW_SHG_INSTANCE_EXTERNAL;
|
||||
drw_call_calc_orco(NULL, shgroup->instance_orcofac);
|
||||
|
||||
@@ -2832,7 +2832,7 @@ static void OBJECT_cache_populate_particles(
|
||||
static float def_sec_col[3] = {1.0f, 1.0f, 1.0f};
|
||||
|
||||
/* Dummy particle format for instancing to work. */
|
||||
DRW_shgroup_instance_format(e_data.particle_format, {{"dummy", DRW_ATTRIB_FLOAT, 1}});
|
||||
DRW_shgroup_instance_format(e_data.particle_format, {{"dummy", DRW_ATTR_FLOAT, 1}});
|
||||
|
||||
Material *ma = give_current_material(ob, part->omat);
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
uniform vec3 screenVecs[3];
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in float axis; /* position on the axis. [0.0-1.0] is X axis, [1.0-2.0] is Y, etc... */
|
||||
in vec2 screenPos;
|
||||
in vec3 colorAxis;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec4 color;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec2 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
/* Assumed to be in world coordinate already. */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec4 color;
|
||||
|
||||
@@ -7,12 +7,12 @@ uniform mat4 ProjectionMatrix;
|
||||
uniform vec2 viewportSize;
|
||||
uniform float lineThickness = 2.0;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec2 pos0;
|
||||
in vec2 pos1;
|
||||
in vec2 pos2;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
/* Assumed to be in world coordinate already. */
|
||||
in vec4 headSphere;
|
||||
in vec4 tailSphere;
|
||||
|
||||
@@ -3,10 +3,10 @@ uniform mat4 ViewMatrix;
|
||||
uniform mat4 ViewMatrixInverse;
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
/* Assumed to be in world coordinate already. */
|
||||
in vec4 headSphere;
|
||||
in vec4 tailSphere;
|
||||
|
||||
@@ -5,11 +5,11 @@ uniform mat4 ViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform vec2 viewportSize;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
in vec3 snor;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec4 outlineColorSize;
|
||||
|
||||
@@ -28,7 +28,7 @@ vec2 proj(vec4 pos)
|
||||
void main()
|
||||
{
|
||||
/* This is slow and run per vertex, but it's still faster than
|
||||
* doing it per instance on CPU and sending it on via instance attrib */
|
||||
* doing it per instance on CPU and sending it on via instance attribute. */
|
||||
mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
|
||||
|
||||
vec4 viewpos = ViewMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
|
||||
|
||||
@@ -6,11 +6,11 @@ uniform mat4 ViewProjectionMatrix;
|
||||
uniform mat4 ViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
in vec3 nor;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec3 boneColor;
|
||||
in vec3 stateColor;
|
||||
|
||||
@@ -4,11 +4,11 @@ uniform mat4 ProjectionMatrix;
|
||||
uniform vec2 viewportSize;
|
||||
uniform float lineThickness = 2.0;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec2 pos0;
|
||||
in vec2 pos1;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec4 outlineColorSize;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
uniform mat4 ViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec2 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec3 stateColor;
|
||||
in vec3 boneColor;
|
||||
|
||||
@@ -4,7 +4,7 @@ uniform mat4 ViewProjectionMatrix;
|
||||
uniform mat4 ViewMatrix;
|
||||
uniform vec2 viewportSize;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec2 pos; /* bone aligned screen space */
|
||||
in uint flag;
|
||||
|
||||
@@ -17,7 +17,7 @@ in uint flag;
|
||||
#define POS_TAIL 32u /* (1 << 5) */ /* UNUSED */
|
||||
#define POS_BONE 64u /* (1 << 6) */
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in vec3 boneStart;
|
||||
in vec3 boneEnd;
|
||||
in vec4 wireColor; /* alpha encode if we do wire. If 0.0 we dont. */
|
||||
|
||||
@@ -71,7 +71,7 @@ int hair_get_base_id(float local_time, int strand_segments, out float interp_tim
|
||||
return int(ratio);
|
||||
}
|
||||
|
||||
void hair_get_interp_attribs(out vec4 data0, out vec4 data1, out vec4 data2, out vec4 data3, out float interp_time)
|
||||
void hair_get_interp_attrs(out vec4 data0, out vec4 data1, out vec4 data2, out vec4 data3, out float interp_time)
|
||||
{
|
||||
float local_time = float(gl_VertexID % hairStrandsRes) / float(hairStrandsRes - 1);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ void main(void)
|
||||
{
|
||||
float interp_time;
|
||||
vec4 data0, data1, data2, data3;
|
||||
hair_get_interp_attribs(data0, data1, data2, data3, interp_time);
|
||||
hair_get_interp_attrs(data0, data1, data2, data3, interp_time);
|
||||
|
||||
vec4 weights = get_weights_cardinal(interp_time);
|
||||
outData = interp_data(data0, data1, data2, data3, weights);
|
||||
|
||||
@@ -182,7 +182,7 @@ void main()
|
||||
#endif
|
||||
|
||||
/* Remember that we are assuming the last vertex
|
||||
* of a triangle is the provoking vertex (decide what flat attribs are). */
|
||||
* of a triangle is the provoking vertex (decide what flat attributes are). */
|
||||
|
||||
if ((eflag[2] & EDGE_EXISTS) != 0) {
|
||||
/* Do 0 -> 1 edge strip */
|
||||
|
||||
@@ -4,11 +4,11 @@ uniform mat4 ModelMatrix;
|
||||
|
||||
uniform vec3 screenVecs[3];
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in float axis; /* position on the axis. [0.0-1.0] is X axis, [1.0-2.0] is Y, etc... */
|
||||
in vec2 screenPos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in vec3 color;
|
||||
in float size;
|
||||
in mat4 InstanceModelMatrix;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
uniform vec3 screen_vecs[2];
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec2 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat3x4 ScaleTranslationMatrix;
|
||||
in float radius;
|
||||
in vec3 color;
|
||||
|
||||
@@ -4,7 +4,7 @@ in vec3 finalColor;
|
||||
out vec4 fragColor;
|
||||
uniform float white_factor = 1.0;
|
||||
|
||||
vec3 linear_to_srgb_attrib(vec3 c) {
|
||||
vec3 linear_to_srgb_attr(vec3 c) {
|
||||
c = max(c, vec3(0.0));
|
||||
vec3 c1 = c * 12.92;
|
||||
vec3 c2 = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055;
|
||||
@@ -13,6 +13,6 @@ vec3 linear_to_srgb_attrib(vec3 c) {
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor.rgb = mix(linear_to_srgb_attrib(finalColor), vec3(1.0), white_factor);
|
||||
fragColor.rgb = mix(linear_to_srgb_attr(finalColor), vec3(1.0), white_factor);
|
||||
fragColor.a = 1.0;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ in vec3 c; /* active color */
|
||||
|
||||
out vec3 finalColor;
|
||||
|
||||
vec3 srgb_to_linear_attrib(vec3 c) {
|
||||
vec3 srgb_to_linear_attr(vec3 c) {
|
||||
c = max(c, vec3(0.0));
|
||||
vec3 c1 = c * (1.0 / 12.92);
|
||||
vec3 c2 = pow((c + 0.055) * (1.0 / 1.055), vec3(2.4));
|
||||
@@ -18,7 +18,7 @@ void main()
|
||||
{
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
|
||||
finalColor = srgb_to_linear_attrib(c);
|
||||
finalColor = srgb_to_linear_attr(c);
|
||||
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
|
||||
|
||||
@@ -251,7 +251,7 @@ void UI_draw_roundbox_4fv(bool filled, float minx, float miny, float maxx, float
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void round_box_shade_col(unsigned attrib, const float col1[3], float const col2[3], const float fac)
|
||||
static void round_box_shade_col(uint attr, const float col1[3], float const col2[3], const float fac)
|
||||
{
|
||||
float col[4] = {
|
||||
fac * col1[0] + (1.0f - fac) * col2[0],
|
||||
@@ -259,7 +259,7 @@ static void round_box_shade_col(unsigned attrib, const float col1[3], float cons
|
||||
fac * col1[2] + (1.0f - fac) * col2[2],
|
||||
1.0f
|
||||
};
|
||||
immAttr4fv(attrib, col);
|
||||
immAttr4fv(attr, col);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -686,8 +686,8 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, const uiWidgetColors *UN
|
||||
*
|
||||
* \Note This functionn is to be used with the 2D dashed shader enabled.
|
||||
*
|
||||
* \param pos: is a PRIM_FLOAT, 2, GPU_FETCH_FLOAT vertex attrib
|
||||
* \param line_origin: is a PRIM_FLOAT, 2, GPU_FETCH_FLOAT vertex attrib
|
||||
* \param pos: is a PRIM_FLOAT, 2, GPU_FETCH_FLOAT vertex attribute.
|
||||
* \param line_origin: is a PRIM_FLOAT, 2, GPU_FETCH_FLOAT vertex attribute.
|
||||
*
|
||||
* The next 4 parameters are the offsets for the view, not the zones.
|
||||
*/
|
||||
@@ -733,7 +733,7 @@ static void draw_scope_end(const rctf *rect, GLint *scissor)
|
||||
static void histogram_draw_one(
|
||||
float r, float g, float b, float alpha,
|
||||
float x, float y, float w, float h, const float *data, int res, const bool is_line,
|
||||
uint pos_attrib)
|
||||
uint pos_attr)
|
||||
{
|
||||
float color[4] = {r, g, b, alpha};
|
||||
|
||||
@@ -753,19 +753,19 @@ static void histogram_draw_one(
|
||||
immBegin(GPU_PRIM_LINE_STRIP, res);
|
||||
for (int i = 0; i < res; i++) {
|
||||
float x2 = x + i * (w / (float)res);
|
||||
immVertex2f(pos_attrib, x2, y + (data[i] * h));
|
||||
immVertex2f(pos_attr, x2, y + (data[i] * h));
|
||||
}
|
||||
immEnd();
|
||||
}
|
||||
else {
|
||||
/* under the curve */
|
||||
immBegin(GPU_PRIM_TRI_STRIP, res * 2);
|
||||
immVertex2f(pos_attrib, x, y);
|
||||
immVertex2f(pos_attrib, x, y + (data[0] * h));
|
||||
immVertex2f(pos_attr, x, y);
|
||||
immVertex2f(pos_attr, x, y + (data[0] * h));
|
||||
for (int i = 1; i < res; i++) {
|
||||
float x2 = x + i * (w / (float)res);
|
||||
immVertex2f(pos_attrib, x2, y + (data[i] * h));
|
||||
immVertex2f(pos_attrib, x2, y);
|
||||
immVertex2f(pos_attr, x2, y + (data[i] * h));
|
||||
immVertex2f(pos_attr, x2, y);
|
||||
}
|
||||
immEnd();
|
||||
|
||||
@@ -776,7 +776,7 @@ static void histogram_draw_one(
|
||||
immBegin(GPU_PRIM_LINE_STRIP, res);
|
||||
for (int i = 0; i < res; i++) {
|
||||
float x2 = x + i * (w / (float)res);
|
||||
immVertex2f(pos_attrib, x2, y + (data[i] * h));
|
||||
immVertex2f(pos_attr, x2, y + (data[i] * h));
|
||||
}
|
||||
immEnd();
|
||||
}
|
||||
@@ -2078,7 +2078,7 @@ void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, const uiWidgetColors *UNUSE
|
||||
* would replace / modify the following 3 functions - merwin
|
||||
*/
|
||||
|
||||
static void ui_shadowbox(unsigned pos, unsigned color, float minx, float miny, float maxx, float maxy, float shadsize, uchar alpha)
|
||||
static void ui_shadowbox(uint pos, uint color, float minx, float miny, float maxx, float maxy, float shadsize, uchar alpha)
|
||||
{
|
||||
/**
|
||||
* <pre>
|
||||
|
||||
@@ -1134,7 +1134,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
|
||||
float inverse_diff_mat[4][4];
|
||||
|
||||
/* recalculate all strokes
|
||||
* (all layers are considered without evaluating lock attributtes) */
|
||||
* (all layers are considered without evaluating lock attributes) */
|
||||
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
|
||||
/* calculate difference matrix */
|
||||
ED_gpencil_parent_location(depsgraph, obact, gpd, gpl, diff_mat);
|
||||
|
||||
@@ -807,7 +807,7 @@ static void paint_draw_alpha_overlay(
|
||||
* secondary is used for alpha/mask control */
|
||||
bool col = ELEM(mode, PAINT_MODE_TEXTURE_3D, PAINT_MODE_TEXTURE_2D, PAINT_MODE_VERTEX) ? true : false;
|
||||
eOverlayControlFlags flags = BKE_paint_get_overlay_flags();
|
||||
gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_BLEND_BIT);
|
||||
gpuPushAttr(GPU_DEPTH_BUFFER_BIT | GPU_BLEND_BIT);
|
||||
|
||||
/* Translate to region. */
|
||||
GPU_matrix_push();
|
||||
@@ -832,7 +832,7 @@ static void paint_draw_alpha_overlay(
|
||||
}
|
||||
|
||||
GPU_matrix_pop();
|
||||
gpuPopAttrib();
|
||||
gpuPopAttr();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,8 +35,10 @@
|
||||
#include "GPU_common.h"
|
||||
|
||||
typedef struct GPUAttrBinding {
|
||||
uint64_t loc_bits; /* store 4 bits for each of the 16 attribs */
|
||||
uint16_t enabled_bits; /* 1 bit for each attrib */
|
||||
/** Store 4 bits for each of the 16 attributes. */
|
||||
uint64_t loc_bits;
|
||||
/** 1 bit for each attribute. */
|
||||
uint16_t enabled_bits;
|
||||
} GPUAttrBinding;
|
||||
|
||||
#endif /* __GPU_ATTR_BINDING_H__ */
|
||||
|
||||
@@ -51,9 +51,13 @@ typedef enum {
|
||||
|
||||
typedef struct GPUBatch {
|
||||
/* geometry */
|
||||
GPUVertBuf *verts[GPU_BATCH_VBO_MAX_LEN]; /* verts[0] is required, others can be NULL */
|
||||
GPUVertBuf *inst; /* instance attribs */
|
||||
GPUIndexBuf *elem; /* NULL if element list not needed */
|
||||
|
||||
/** verts[0] is required, others can be NULL */
|
||||
GPUVertBuf *verts[GPU_BATCH_VBO_MAX_LEN];
|
||||
/** Instance attributes. */
|
||||
GPUVertBuf *inst;
|
||||
/** NULL if element list not needed */
|
||||
GPUIndexBuf *elem;
|
||||
uint32_t gl_prim_type;
|
||||
|
||||
/* cached values (avoid dereferencing later) */
|
||||
@@ -63,21 +67,22 @@ typedef struct GPUBatch {
|
||||
|
||||
/* book-keeping */
|
||||
uint owns_flag;
|
||||
struct GPUContext *context; /* used to free all vaos. this implies all vaos were created under the same context. */
|
||||
/** used to free all vaos. this implies all vaos were created under the same context. */
|
||||
struct GPUContext *context;
|
||||
GPUBatchPhase phase;
|
||||
bool program_in_use;
|
||||
|
||||
/* Vao management: remembers all geometry state (vertex attrib bindings & element buffer)
|
||||
/* Vao management: remembers all geometry state (vertex attribute bindings & element buffer)
|
||||
* for each shader interface. Start with a static number of vaos and fallback to dynamic count
|
||||
* if necessary. Once a batch goes dynamic it does not go back. */
|
||||
bool is_dynamic_vao_count;
|
||||
union {
|
||||
/* Static handle count */
|
||||
/** Static handle count */
|
||||
struct {
|
||||
const struct GPUShaderInterface *interfaces[GPU_BATCH_VAO_STATIC_LEN];
|
||||
uint32_t vao_ids[GPU_BATCH_VAO_STATIC_LEN];
|
||||
} static_vaos;
|
||||
/* Dynamic handle count */
|
||||
/** Dynamic handle count */
|
||||
struct {
|
||||
uint count;
|
||||
const struct GPUShaderInterface **interfaces;
|
||||
|
||||
@@ -112,16 +112,16 @@ void GPU_select_index_get(int index, int *r_col);
|
||||
int GPU_select_to_index(unsigned int col);
|
||||
void GPU_select_to_index_array(unsigned int *col, const unsigned int size);
|
||||
|
||||
typedef enum eGPUAttribMask {
|
||||
typedef enum eGPUAttrMask {
|
||||
GPU_DEPTH_BUFFER_BIT = (1 << 0),
|
||||
GPU_ENABLE_BIT = (1 << 1),
|
||||
GPU_SCISSOR_BIT = (1 << 2),
|
||||
GPU_VIEWPORT_BIT = (1 << 3),
|
||||
GPU_BLEND_BIT = (1 << 4),
|
||||
} eGPUAttribMask;
|
||||
} eGPUAttrMask;
|
||||
|
||||
void gpuPushAttrib(eGPUAttribMask mask);
|
||||
void gpuPopAttrib(void);
|
||||
void gpuPushAttr(eGPUAttrMask mask);
|
||||
void gpuPopAttr(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -40,13 +40,18 @@
|
||||
#include "GPU_immediate_util.h"
|
||||
#include "GPU_shader.h"
|
||||
|
||||
GPUVertFormat *immVertexFormat(void); /* returns a cleared vertex format, ready for add_attrib. */
|
||||
/** Returns a cleared vertex format, ready for #add_attr. */
|
||||
GPUVertFormat *immVertexFormat(void);
|
||||
|
||||
void immBindProgram(uint32_t program, const GPUShaderInterface *); /* every immBegin must have a program bound first. */
|
||||
void immUnbindProgram(void); /* call after your last immEnd, or before binding another program. */
|
||||
/** Every immBegin must have a program bound first. */
|
||||
void immBindProgram(uint32_t program, const GPUShaderInterface *);
|
||||
/** Call after your last immEnd, or before binding another program. */
|
||||
void immUnbindProgram(void);
|
||||
|
||||
void immBegin(GPUPrimType, uint vertex_len); /* must supply exactly vertex_len vertices. */
|
||||
void immBeginAtMost(GPUPrimType, uint max_vertex_len); /* can supply fewer vertices. */
|
||||
/** Must supply exactly vertex_len vertices. */
|
||||
void immBegin(GPUPrimType, uint vertex_len);
|
||||
/** Can supply fewer vertices. */
|
||||
void immBeginAtMost(GPUPrimType, uint max_vertex_len);
|
||||
void immEnd(void); /* finishes and draws. */
|
||||
|
||||
/* ImmBegin a batch, then use standard immFunctions as usual. */
|
||||
|
||||
@@ -47,7 +47,7 @@ struct GPUNodeLink;
|
||||
struct GPUNodeStack;
|
||||
struct GPUTexture;
|
||||
struct GPUUniformBuffer;
|
||||
struct GPUVertexAttribs;
|
||||
struct GPUVertAttrLayers;
|
||||
struct Image;
|
||||
struct ImageUser;
|
||||
struct ListBase;
|
||||
@@ -90,7 +90,7 @@ typedef enum eGPUType {
|
||||
GPU_CLOSURE = 1006,
|
||||
|
||||
/* Opengl Attributes */
|
||||
GPU_ATTRIB = 3001,
|
||||
GPU_ATTR = 3001,
|
||||
} eGPUType;
|
||||
|
||||
typedef enum eGPUBuiltin {
|
||||
@@ -189,9 +189,9 @@ struct GPUUniformBuffer *GPU_material_uniform_buffer_get(GPUMaterial *material);
|
||||
void GPU_material_uniform_buffer_create(GPUMaterial *material, ListBase *inputs);
|
||||
struct GPUUniformBuffer *GPU_material_create_sss_profile_ubo(void);
|
||||
|
||||
void GPU_material_vertex_attributes(
|
||||
void GPU_material_vertex_attrs(
|
||||
GPUMaterial *material,
|
||||
struct GPUVertexAttribs *attrib);
|
||||
struct GPUVertAttrLayers *attrs);
|
||||
|
||||
bool GPU_material_do_color_management(GPUMaterial *mat);
|
||||
bool GPU_material_use_domain_surface(GPUMaterial *mat);
|
||||
|
||||
@@ -383,20 +383,20 @@ void GPU_shader_free_builtin_shaders(void);
|
||||
|
||||
/* Vertex attributes for shaders */
|
||||
|
||||
#define GPU_MAX_ATTRIB 32
|
||||
#define GPU_MAX_ATTR 32
|
||||
|
||||
typedef struct GPUVertexAttribs {
|
||||
typedef struct GPUVertAttrLayers {
|
||||
struct {
|
||||
int type;
|
||||
int glindex;
|
||||
int glinfoindoex;
|
||||
int gltexco;
|
||||
int attribid;
|
||||
int attr_id;
|
||||
char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
|
||||
} layer[GPU_MAX_ATTRIB];
|
||||
} layer[GPU_MAX_ATTR];
|
||||
|
||||
int totlayer;
|
||||
} GPUVertexAttribs;
|
||||
} GPUVertAttrLayers;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -69,9 +69,12 @@ typedef struct GPUShaderInput {
|
||||
struct GPUShaderInput *next;
|
||||
uint32_t name_offset;
|
||||
uint name_hash;
|
||||
GPUUniformBuiltin builtin_type; /* only for uniform inputs */
|
||||
uint32_t gl_type; /* only for attrib inputs */
|
||||
int32_t size; /* only for attrib inputs */
|
||||
/** Only for uniform inputs. */
|
||||
GPUUniformBuiltin builtin_type;
|
||||
/** Only for attribute inputs. */
|
||||
uint32_t gl_type;
|
||||
/** Only for attribute inputs. */
|
||||
int32_t size;
|
||||
int32_t location;
|
||||
} GPUShaderInput;
|
||||
|
||||
@@ -81,7 +84,7 @@ typedef struct GPUShaderInput {
|
||||
typedef struct GPUShaderInterface {
|
||||
int32_t program;
|
||||
uint32_t name_buffer_offset;
|
||||
GPUShaderInput *attrib_buckets[GPU_NUM_SHADERINTERFACE_BUCKETS];
|
||||
GPUShaderInput *attr_buckets[GPU_NUM_SHADERINTERFACE_BUCKETS];
|
||||
GPUShaderInput *uniform_buckets[GPU_NUM_SHADERINTERFACE_BUCKETS];
|
||||
GPUShaderInput *ubo_buckets[GPU_NUM_SHADERINTERFACE_BUCKETS];
|
||||
GPUShaderInput *builtin_uniforms[GPU_NUM_UNIFORMS];
|
||||
|
||||
@@ -79,10 +79,10 @@ void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len);
|
||||
void GPU_vertbuf_data_resize(GPUVertBuf *, uint v_len);
|
||||
void GPU_vertbuf_data_len_set(GPUVertBuf *, uint v_len);
|
||||
|
||||
/* The most important set_attrib variant is the untyped one. Get it right first. */
|
||||
/* It takes a void* so the app developer is responsible for matching their app data types */
|
||||
/* to the vertex attribute's type and component count. They're in control of both, so this */
|
||||
/* should not be a problem. */
|
||||
/* The most important #set_attr variant is the untyped one. Get it right first.
|
||||
* It takes a void* so the app developer is responsible for matching their app data types
|
||||
* to the vertex attribute's type and component count. They're in control of both, so this
|
||||
* should not be a problem. */
|
||||
|
||||
void GPU_vertbuf_attr_set(GPUVertBuf *, uint a_idx, uint v_idx, const void *data);
|
||||
void GPU_vertbuf_attr_fill(GPUVertBuf *, uint a_idx, const void *data); /* tightly packed, non interleaved input data */
|
||||
|
||||
@@ -71,13 +71,17 @@ typedef struct GPUVertAttr {
|
||||
} GPUVertAttr;
|
||||
|
||||
typedef struct GPUVertFormat {
|
||||
uint attr_len; /* 0 to 16 (GPU_VERT_ATTR_MAX_LEN) */
|
||||
uint name_len; /* total count of active vertex attrib */
|
||||
uint stride; /* stride in bytes, 1 to 256 */
|
||||
/** 0 to 16 (GPU_VERT_ATTR_MAX_LEN). */
|
||||
uint attr_len;
|
||||
/** Total count of active vertex attribute. */
|
||||
uint name_len;
|
||||
/** Stride in bytes, 1 to 256. */
|
||||
uint stride;
|
||||
uint name_offset;
|
||||
bool packed;
|
||||
char names[GPU_VERT_ATTR_NAMES_BUF_LEN];
|
||||
GPUVertAttr attribs[GPU_VERT_ATTR_MAX_LEN]; /* TODO: variable-size attribs array */
|
||||
/** TODO: variable-size array */
|
||||
GPUVertAttr attrs[GPU_VERT_ATTR_MAX_LEN];
|
||||
} GPUVertFormat;
|
||||
|
||||
struct GPUShaderInterface;
|
||||
@@ -93,7 +97,7 @@ void GPU_vertformat_alias_add(GPUVertFormat *, const char *alias);
|
||||
int GPU_vertformat_attr_id_get(const GPUVertFormat *, const char *name);
|
||||
|
||||
/**
|
||||
* This makes the "virtual" attribs with suffixes "0", "1", "2" to access triangle data in the vertex
|
||||
* This makes the "virtual" attributes with suffixes "0", "1", "2" to access triangle data in the vertex
|
||||
* shader.
|
||||
*
|
||||
* IMPORTANT:
|
||||
|
||||
@@ -35,16 +35,16 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#if GPU_VERT_ATTR_MAX_LEN != 16
|
||||
# error "attrib binding code assumes GPU_VERT_ATTR_MAX_LEN = 16"
|
||||
# error "attribute binding code assumes GPU_VERT_ATTR_MAX_LEN = 16"
|
||||
#endif
|
||||
|
||||
void AttribBinding_clear(GPUAttrBinding *binding)
|
||||
void AttrBinding_clear(GPUAttrBinding *binding)
|
||||
{
|
||||
binding->loc_bits = 0;
|
||||
binding->enabled_bits = 0;
|
||||
}
|
||||
|
||||
uint read_attrib_location(const GPUAttrBinding *binding, uint a_idx)
|
||||
uint read_attr_location(const GPUAttrBinding *binding, uint a_idx)
|
||||
{
|
||||
#if TRUST_NO_ONE
|
||||
assert(a_idx < GPU_VERT_ATTR_MAX_LEN);
|
||||
@@ -53,7 +53,7 @@ uint read_attrib_location(const GPUAttrBinding *binding, uint a_idx)
|
||||
return (binding->loc_bits >> (4 * a_idx)) & 0xF;
|
||||
}
|
||||
|
||||
static void write_attrib_location(GPUAttrBinding *binding, uint a_idx, uint location)
|
||||
static void write_attr_location(GPUAttrBinding *binding, uint a_idx, uint location)
|
||||
{
|
||||
#if TRUST_NO_ONE
|
||||
assert(a_idx < GPU_VERT_ATTR_MAX_LEN);
|
||||
@@ -61,25 +61,25 @@ static void write_attrib_location(GPUAttrBinding *binding, uint a_idx, uint loca
|
||||
#endif
|
||||
const uint shift = 4 * a_idx;
|
||||
const uint64_t mask = ((uint64_t)0xF) << shift;
|
||||
/* overwrite this attrib's previous location */
|
||||
/* overwrite this attr's previous location */
|
||||
binding->loc_bits = (binding->loc_bits & ~mask) | (location << shift);
|
||||
/* mark this attrib as enabled */
|
||||
/* mark this attr as enabled */
|
||||
binding->enabled_bits |= 1 << a_idx;
|
||||
}
|
||||
|
||||
void get_attrib_locations(const GPUVertFormat *format, GPUAttrBinding *binding, const GPUShaderInterface *shaderface)
|
||||
void get_attr_locations(const GPUVertFormat *format, GPUAttrBinding *binding, const GPUShaderInterface *shaderface)
|
||||
{
|
||||
AttribBinding_clear(binding);
|
||||
AttrBinding_clear(binding);
|
||||
|
||||
for (uint a_idx = 0; a_idx < format->attr_len; ++a_idx) {
|
||||
const GPUVertAttr *a = format->attribs + a_idx;
|
||||
const GPUVertAttr *a = &format->attrs[a_idx];
|
||||
for (uint n_idx = 0; n_idx < a->name_len; ++n_idx) {
|
||||
const GPUShaderInput *input = GPU_shaderinterface_attr(shaderface, a->name[n_idx]);
|
||||
#if TRUST_NO_ONE
|
||||
assert(input != NULL);
|
||||
/* TODO: make this a recoverable runtime error? indicates mismatch between vertex format and program */
|
||||
#endif
|
||||
write_attrib_location(binding, a_idx, input->location);
|
||||
write_attr_location(binding, a_idx, input->location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
#include "GPU_vertex_format.h"
|
||||
#include "GPU_shader_interface.h"
|
||||
|
||||
void AttribBinding_clear(GPUAttrBinding *binding);
|
||||
void AttrBinding_clear(GPUAttrBinding *binding);
|
||||
|
||||
void get_attrib_locations(
|
||||
void get_attr_locations(
|
||||
const GPUVertFormat *format, GPUAttrBinding *binding, const GPUShaderInterface *shaderface);
|
||||
uint read_attrib_location(
|
||||
uint read_attr_location(
|
||||
const GPUAttrBinding *binding, uint a_idx);
|
||||
|
||||
#endif /* __GPU_ATTR_BINDING_PRIVATE_H__ */
|
||||
|
||||
@@ -197,7 +197,7 @@ int GPU_batch_vertbuf_add_ex(
|
||||
assert(verts->vertex_len == batch->verts[0]->vertex_len);
|
||||
#endif
|
||||
batch->verts[v] = verts;
|
||||
/* TODO: mark dirty so we can keep attrib bindings up-to-date */
|
||||
/* TODO: mark dirty so we can keep attribute bindings up-to-date */
|
||||
if (own_vbo)
|
||||
batch->owns_flag |= (1 << v);
|
||||
return v;
|
||||
@@ -351,7 +351,7 @@ static void create_bindings(
|
||||
GPU_vertbuf_use(verts);
|
||||
|
||||
for (uint a_idx = 0; a_idx < attr_len; ++a_idx) {
|
||||
const GPUVertAttr *a = format->attribs + a_idx;
|
||||
const GPUVertAttr *a = &format->attrs[a_idx];
|
||||
const GLvoid *pointer = (const GLubyte *)0 + a->offset + v_first * stride;
|
||||
|
||||
for (uint n_idx = 0; n_idx < a->name_len; ++n_idx) {
|
||||
|
||||
@@ -78,14 +78,14 @@ static char *glsl_material_library = NULL;
|
||||
static GPUPass *pass_cache = NULL;
|
||||
static SpinLock pass_cache_spin;
|
||||
|
||||
static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, GPUVertexAttribs *attribs)
|
||||
static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, GPUVertAttrLayers *attrs)
|
||||
{
|
||||
BLI_HashMurmur2A hm2a;
|
||||
BLI_hash_mm2a_init(&hm2a, 0);
|
||||
BLI_hash_mm2a_add(&hm2a, (uchar *)frag_gen, strlen(frag_gen));
|
||||
if (attribs) {
|
||||
for (int att_idx = 0; att_idx < attribs->totlayer; att_idx++) {
|
||||
char *name = attribs->layer[att_idx].name;
|
||||
if (attrs) {
|
||||
for (int att_idx = 0; att_idx < attrs->totlayer; att_idx++) {
|
||||
char *name = attrs->layer[att_idx].name;
|
||||
BLI_hash_mm2a_add(&hm2a, (uchar *)name, strlen(name));
|
||||
}
|
||||
}
|
||||
@@ -636,10 +636,10 @@ static int codegen_process_uniforms_functions(GPUMaterial *material, DynStr *ds,
|
||||
codegen_print_datatype(ds, input->type, input->vec);
|
||||
BLI_dynstr_append(ds, ";\n");
|
||||
}
|
||||
else if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
|
||||
else if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
||||
BLI_dynstr_appendf(
|
||||
ds, "in %s var%d;\n",
|
||||
GPU_DATATYPE_STR[input->type], input->attribid);
|
||||
GPU_DATATYPE_STR[input->type], input->attr_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -743,8 +743,8 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
|
||||
else if (input->source == GPU_SOURCE_CONSTANT) {
|
||||
BLI_dynstr_appendf(ds, "cons%d", input->id);
|
||||
}
|
||||
else if (input->source == GPU_SOURCE_ATTRIB) {
|
||||
BLI_dynstr_appendf(ds, "var%d", input->attribid);
|
||||
else if (input->source == GPU_SOURCE_ATTR) {
|
||||
BLI_dynstr_appendf(ds, "var%d", input->attr_id);
|
||||
}
|
||||
|
||||
BLI_dynstr_append(ds, ", ");
|
||||
@@ -841,7 +841,7 @@ static char *code_generate_fragment(GPUMaterial *material, ListBase *nodes, GPUO
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char *attrib_prefix_get(CustomDataType type)
|
||||
static const char *attr_prefix_get(CustomDataType type)
|
||||
{
|
||||
switch (type) {
|
||||
case CD_ORCO: return "orco";
|
||||
@@ -861,13 +861,13 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u
|
||||
char *code;
|
||||
int builtins = 0;
|
||||
|
||||
/* Hairs uv and col attribs are passed by bufferTextures. */
|
||||
/* Hairs uv and col attributes are passed by bufferTextures. */
|
||||
BLI_dynstr_append(
|
||||
ds,
|
||||
"#ifdef HAIR_SHADER\n"
|
||||
"#define DEFINE_ATTRIB(type, attr) uniform samplerBuffer attr\n"
|
||||
"#define DEFINE_ATTR(type, attr) uniform samplerBuffer attr\n"
|
||||
"#else\n"
|
||||
"#define DEFINE_ATTRIB(type, attr) in type attr\n"
|
||||
"#define DEFINE_ATTR(type, attr) in type attr\n"
|
||||
"#endif\n"
|
||||
);
|
||||
|
||||
@@ -876,35 +876,35 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u
|
||||
if (input->source == GPU_SOURCE_BUILTIN) {
|
||||
builtins |= input->builtin;
|
||||
}
|
||||
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
|
||||
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
||||
/* XXX FIXME : see notes in mesh_render_data_create() */
|
||||
/* NOTE : Replicate changes to mesh_render_data_create() in draw_cache_impl_mesh.c */
|
||||
if (input->attribtype == CD_ORCO) {
|
||||
if (input->attr_type == CD_ORCO) {
|
||||
/* orco is computed from local positions, see below */
|
||||
BLI_dynstr_appendf(ds, "uniform vec3 OrcoTexCoFactors[2];\n");
|
||||
}
|
||||
else if (input->attribname[0] == '\0') {
|
||||
BLI_dynstr_appendf(ds, "DEFINE_ATTRIB(%s, %s);\n", GPU_DATATYPE_STR[input->type], attrib_prefix_get(input->attribtype));
|
||||
BLI_dynstr_appendf(ds, "#define att%d %s\n", input->attribid, attrib_prefix_get(input->attribtype));
|
||||
else if (input->attr_name[0] == '\0') {
|
||||
BLI_dynstr_appendf(ds, "DEFINE_ATTR(%s, %s);\n", GPU_DATATYPE_STR[input->type], attr_prefix_get(input->attr_type));
|
||||
BLI_dynstr_appendf(ds, "#define att%d %s\n", input->attr_id, attr_prefix_get(input->attr_type));
|
||||
}
|
||||
else {
|
||||
uint hash = BLI_ghashutil_strhash_p(input->attribname);
|
||||
uint hash = BLI_ghashutil_strhash_p(input->attr_name);
|
||||
BLI_dynstr_appendf(
|
||||
ds, "DEFINE_ATTRIB(%s, %s%u);\n",
|
||||
GPU_DATATYPE_STR[input->type], attrib_prefix_get(input->attribtype), hash);
|
||||
ds, "DEFINE_ATTR(%s, %s%u);\n",
|
||||
GPU_DATATYPE_STR[input->type], attr_prefix_get(input->attr_type), hash);
|
||||
BLI_dynstr_appendf(
|
||||
ds, "#define att%d %s%u\n",
|
||||
input->attribid, attrib_prefix_get(input->attribtype), hash);
|
||||
/* Auto attrib can be vertex color byte buffer.
|
||||
input->attr_id, attr_prefix_get(input->attr_type), hash);
|
||||
/* Auto attribute can be vertex color byte buffer.
|
||||
* We need to know and convert them to linear space in VS. */
|
||||
if (!use_geom && input->attribtype == CD_AUTO_FROM_NAME) {
|
||||
if (!use_geom && input->attr_type == CD_AUTO_FROM_NAME) {
|
||||
BLI_dynstr_appendf(ds, "uniform bool ba%u;\n", hash);
|
||||
BLI_dynstr_appendf(ds, "#define att%d_is_srgb ba%u\n", input->attribid, hash);
|
||||
BLI_dynstr_appendf(ds, "#define att%d_is_srgb ba%u\n", input->attr_id, hash);
|
||||
}
|
||||
}
|
||||
BLI_dynstr_appendf(
|
||||
ds, "out %s var%d%s;\n",
|
||||
GPU_DATATYPE_STR[input->type], input->attribid, use_geom ? "g" : "");
|
||||
GPU_DATATYPE_STR[input->type], input->attr_id, use_geom ? "g" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -924,11 +924,11 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u
|
||||
|
||||
BLI_dynstr_append(
|
||||
ds,
|
||||
"#define ATTRIB\n"
|
||||
"#define USE_ATTR\n"
|
||||
"uniform mat3 NormalMatrix;\n"
|
||||
"uniform mat4 ModelMatrixInverse;\n"
|
||||
"uniform mat4 ModelMatrix;\n"
|
||||
"vec3 srgb_to_linear_attrib(vec3 c) {\n"
|
||||
"vec3 srgb_to_linear_attr(vec3 c) {\n"
|
||||
"\tc = max(c, vec3(0.0));\n"
|
||||
"\tvec3 c1 = c * (1.0 / 12.92);\n"
|
||||
"\tvec3 c2 = pow((c + 0.055) * (1.0 / 1.055), vec3(2.4));\n"
|
||||
@@ -947,7 +947,7 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u
|
||||
"\n"
|
||||
);
|
||||
|
||||
BLI_dynstr_append(ds, "void pass_attrib(in vec3 position) {\n");
|
||||
BLI_dynstr_append(ds, "void pass_attr(in vec3 position) {\n");
|
||||
|
||||
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
||||
|
||||
@@ -971,22 +971,22 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u
|
||||
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
|
||||
if (input->attribtype == CD_TANGENT) {
|
||||
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
||||
if (input->attr_type == CD_TANGENT) {
|
||||
/* Not supported by hairs */
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s = vec4(0.0);\n",
|
||||
input->attribid, use_geom ? "g" : "");
|
||||
input->attr_id, use_geom ? "g" : "");
|
||||
}
|
||||
else if (input->attribtype == CD_ORCO) {
|
||||
else if (input->attr_type == CD_ORCO) {
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s = OrcoTexCoFactors[0] + (ModelMatrixInverse * vec4(hair_get_strand_pos(), 1.0)).xyz * OrcoTexCoFactors[1];\n",
|
||||
input->attribid, use_geom ? "g" : "");
|
||||
input->attr_id, use_geom ? "g" : "");
|
||||
}
|
||||
else {
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s = hair_get_customdata_%s(att%d);\n",
|
||||
input->attribid, use_geom ? "g" : "", GPU_DATATYPE_STR[input->type], input->attribid);
|
||||
input->attr_id, use_geom ? "g" : "", GPU_DATATYPE_STR[input->type], input->attr_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1009,35 +1009,35 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u
|
||||
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
|
||||
if (input->attribtype == CD_TANGENT) { /* silly exception */
|
||||
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
||||
if (input->attr_type == CD_TANGENT) { /* silly exception */
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s.xyz = normalize(NormalMatrix * att%d.xyz);\n",
|
||||
input->attribid, use_geom ? "g" : "", input->attribid);
|
||||
input->attr_id, use_geom ? "g" : "", input->attr_id);
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s.w = att%d.w;\n",
|
||||
input->attribid, use_geom ? "g" : "", input->attribid);
|
||||
input->attr_id, use_geom ? "g" : "", input->attr_id);
|
||||
}
|
||||
else if (input->attribtype == CD_ORCO) {
|
||||
else if (input->attr_type == CD_ORCO) {
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s = OrcoTexCoFactors[0] + position * OrcoTexCoFactors[1];\n",
|
||||
input->attribid, use_geom ? "g" : "");
|
||||
input->attr_id, use_geom ? "g" : "");
|
||||
}
|
||||
else if (input->attribtype == CD_MCOL) {
|
||||
else if (input->attr_type == CD_MCOL) {
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s = srgb_to_linear_attrib(att%d);\n",
|
||||
input->attribid, use_geom ? "g" : "", input->attribid);
|
||||
ds, "\tvar%d%s = srgb_to_linear_attr(att%d);\n",
|
||||
input->attr_id, use_geom ? "g" : "", input->attr_id);
|
||||
}
|
||||
else if (input->attribtype == CD_AUTO_FROM_NAME) {
|
||||
else if (input->attr_type == CD_AUTO_FROM_NAME) {
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s = (att%d_is_srgb) ? srgb_to_linear_attrib(att%d) : att%d;\n",
|
||||
input->attribid, use_geom ? "g" : "",
|
||||
input->attribid, input->attribid, input->attribid);
|
||||
ds, "\tvar%d%s = (att%d_is_srgb) ? srgb_to_linear_attr(att%d) : att%d;\n",
|
||||
input->attr_id, use_geom ? "g" : "",
|
||||
input->attr_id, input->attr_id, input->attr_id);
|
||||
}
|
||||
else {
|
||||
BLI_dynstr_appendf(
|
||||
ds, "\tvar%d%s = att%d;\n",
|
||||
input->attribid, use_geom ? "g" : "", input->attribid);
|
||||
input->attr_id, use_geom ? "g" : "", input->attr_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1088,9 +1088,9 @@ static char *code_generate_geometry(ListBase *nodes, const char *geom_code)
|
||||
int builtins = 0;
|
||||
|
||||
/* Create prototype because attributes cannot be declared before layout. */
|
||||
BLI_dynstr_appendf(ds, "void pass_attrib(in int vert);\n");
|
||||
BLI_dynstr_appendf(ds, "void pass_attr(in int vert);\n");
|
||||
BLI_dynstr_appendf(ds, "void calc_barycentric_distances(vec3 pos0, vec3 pos1, vec3 pos2);\n");
|
||||
BLI_dynstr_append(ds, "#define ATTRIB\n");
|
||||
BLI_dynstr_append(ds, "#define USE_ATTR\n");
|
||||
|
||||
/* Generate varying declarations. */
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
@@ -1098,15 +1098,15 @@ static char *code_generate_geometry(ListBase *nodes, const char *geom_code)
|
||||
if (input->source == GPU_SOURCE_BUILTIN) {
|
||||
builtins |= input->builtin;
|
||||
}
|
||||
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
|
||||
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
||||
BLI_dynstr_appendf(
|
||||
ds, "in %s var%dg[];\n",
|
||||
GPU_DATATYPE_STR[input->type],
|
||||
input->attribid);
|
||||
input->attr_id);
|
||||
BLI_dynstr_appendf(
|
||||
ds, "out %s var%d;\n",
|
||||
GPU_DATATYPE_STR[input->type],
|
||||
input->attribid);
|
||||
input->attr_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1150,15 +1150,15 @@ static char *code_generate_geometry(ListBase *nodes, const char *geom_code)
|
||||
}
|
||||
|
||||
BLI_dynstr_appendf(ds, "\tgl_Position = gl_in[0].gl_Position;\n");
|
||||
BLI_dynstr_appendf(ds, "\tpass_attrib(0);\n");
|
||||
BLI_dynstr_appendf(ds, "\tpass_attr(0);\n");
|
||||
BLI_dynstr_appendf(ds, "\tEmitVertex();\n");
|
||||
|
||||
BLI_dynstr_appendf(ds, "\tgl_Position = gl_in[1].gl_Position;\n");
|
||||
BLI_dynstr_appendf(ds, "\tpass_attrib(1);\n");
|
||||
BLI_dynstr_appendf(ds, "\tpass_attr(1);\n");
|
||||
BLI_dynstr_appendf(ds, "\tEmitVertex();\n");
|
||||
|
||||
BLI_dynstr_appendf(ds, "\tgl_Position = gl_in[2].gl_Position;\n");
|
||||
BLI_dynstr_appendf(ds, "\tpass_attrib(2);\n");
|
||||
BLI_dynstr_appendf(ds, "\tpass_attr(2);\n");
|
||||
BLI_dynstr_appendf(ds, "\tEmitVertex();\n");
|
||||
BLI_dynstr_appendf(ds, "};\n");
|
||||
}
|
||||
@@ -1186,7 +1186,7 @@ static char *code_generate_geometry(ListBase *nodes, const char *geom_code)
|
||||
}
|
||||
|
||||
/* Generate varying assignments. */
|
||||
BLI_dynstr_appendf(ds, "void pass_attrib(in int vert) {\n");
|
||||
BLI_dynstr_appendf(ds, "void pass_attr(in int vert) {\n");
|
||||
|
||||
/* XXX HACK: Eevee specific. */
|
||||
if (geom_code == NULL) {
|
||||
@@ -1202,9 +1202,9 @@ static char *code_generate_geometry(ListBase *nodes, const char *geom_code)
|
||||
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
|
||||
/* TODO let shader choose what to do depending on what the attrib is. */
|
||||
BLI_dynstr_appendf(ds, "\tvar%d = var%dg[vert];\n", input->attribid, input->attribid);
|
||||
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
||||
/* TODO let shader choose what to do depending on what the attribute is. */
|
||||
BLI_dynstr_appendf(ds, "\tvar%d = var%dg[vert];\n", input->attr_id, input->attr_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1262,7 +1262,7 @@ void GPU_nodes_extract_dynamic_inputs(GPUShader *shader, ListBase *inputs, ListB
|
||||
/* attributes don't need to be bound, they already have
|
||||
* an id that the drawing functions will use. Builtins have
|
||||
* constant names. */
|
||||
if (ELEM(input->source, GPU_SOURCE_ATTRIB, GPU_SOURCE_BUILTIN)) {
|
||||
if (ELEM(input->source, GPU_SOURCE_ATTR, GPU_SOURCE_BUILTIN)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1367,10 +1367,10 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const eGPUType
|
||||
input->iuser = link->iuser;
|
||||
input->image_isdata = link->image_isdata;
|
||||
break;
|
||||
case GPU_NODE_LINK_ATTRIB:
|
||||
input->source = GPU_SOURCE_ATTRIB;
|
||||
input->attribtype = link->attribtype;
|
||||
BLI_strncpy(input->attribname, link->attribname, sizeof(input->attribname));
|
||||
case GPU_NODE_LINK_ATTR:
|
||||
input->source = GPU_SOURCE_ATTR;
|
||||
input->attr_type = link->attr_type;
|
||||
BLI_strncpy(input->attr_name, link->attr_name, sizeof(input->attr_name));
|
||||
break;
|
||||
case GPU_NODE_LINK_CONSTANT:
|
||||
input->source = (type == GPU_CLOSURE) ? GPU_SOURCE_STRUCT : GPU_SOURCE_CONSTANT;
|
||||
@@ -1533,7 +1533,7 @@ static void gpu_nodes_free(ListBase *nodes)
|
||||
|
||||
/* vertex attributes */
|
||||
|
||||
void GPU_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *attribs)
|
||||
void GPU_nodes_get_vertex_attrs(ListBase *nodes, GPUVertAttrLayers *attrs)
|
||||
{
|
||||
GPUNode *node;
|
||||
GPUInput *input;
|
||||
@@ -1542,32 +1542,32 @@ void GPU_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *attribs)
|
||||
/* convert attributes requested by node inputs to an array of layers,
|
||||
* checking for duplicates and assigning id's starting from zero. */
|
||||
|
||||
memset(attribs, 0, sizeof(*attribs));
|
||||
memset(attrs, 0, sizeof(*attrs));
|
||||
|
||||
for (node = nodes->first; node; node = node->next) {
|
||||
for (input = node->inputs.first; input; input = input->next) {
|
||||
if (input->source == GPU_SOURCE_ATTRIB) {
|
||||
for (a = 0; a < attribs->totlayer; a++) {
|
||||
if (attribs->layer[a].type == input->attribtype &&
|
||||
STREQ(attribs->layer[a].name, input->attribname))
|
||||
if (input->source == GPU_SOURCE_ATTR) {
|
||||
for (a = 0; a < attrs->totlayer; a++) {
|
||||
if (attrs->layer[a].type == input->attr_type &&
|
||||
STREQ(attrs->layer[a].name, input->attr_name))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (a < GPU_MAX_ATTRIB) {
|
||||
if (a == attribs->totlayer) {
|
||||
input->attribid = attribs->totlayer++;
|
||||
input->attribfirst = true;
|
||||
if (a < GPU_MAX_ATTR) {
|
||||
if (a == attrs->totlayer) {
|
||||
input->attr_id = attrs->totlayer++;
|
||||
input->attr_first = true;
|
||||
|
||||
attribs->layer[a].type = input->attribtype;
|
||||
attribs->layer[a].attribid = input->attribid;
|
||||
attrs->layer[a].type = input->attr_type;
|
||||
attrs->layer[a].attr_id = input->attr_id;
|
||||
BLI_strncpy(
|
||||
attribs->layer[a].name, input->attribname,
|
||||
sizeof(attribs->layer[a].name));
|
||||
attrs->layer[a].name, input->attr_name,
|
||||
sizeof(attrs->layer[a].name));
|
||||
}
|
||||
else {
|
||||
input->attribid = attribs->layer[a].attribid;
|
||||
input->attr_id = attrs->layer[a].attr_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1580,14 +1580,14 @@ void GPU_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *attribs)
|
||||
GPUNodeLink *GPU_attribute(const CustomDataType type, const char *name)
|
||||
{
|
||||
GPUNodeLink *link = GPU_node_link_create();
|
||||
link->link_type = GPU_NODE_LINK_ATTRIB;
|
||||
link->attribname = name;
|
||||
link->link_type = GPU_NODE_LINK_ATTR;
|
||||
link->attr_name = name;
|
||||
/* Fall back to the UV layer, which matches old behavior. */
|
||||
if (type == CD_AUTO_FROM_NAME && name[0] == '\0') {
|
||||
link->attribtype = CD_MTFACE;
|
||||
link->attr_type = CD_MTFACE;
|
||||
}
|
||||
else {
|
||||
link->attribtype = type;
|
||||
link->attr_type = type;
|
||||
}
|
||||
return link;
|
||||
}
|
||||
@@ -1787,7 +1787,7 @@ static bool gpu_pass_is_valid(GPUPass *pass)
|
||||
GPUPass *GPU_generate_pass(
|
||||
GPUMaterial *material,
|
||||
GPUNodeLink *frag_outlink,
|
||||
struct GPUVertexAttribs *attribs,
|
||||
struct GPUVertAttrLayers *attrs,
|
||||
ListBase *nodes,
|
||||
int *builtins,
|
||||
const char *vert_code,
|
||||
@@ -1801,13 +1801,13 @@ GPUPass *GPU_generate_pass(
|
||||
/* prune unused nodes */
|
||||
GPU_nodes_prune(nodes, frag_outlink);
|
||||
|
||||
GPU_nodes_get_vertex_attributes(nodes, attribs);
|
||||
GPU_nodes_get_vertex_attrs(nodes, attrs);
|
||||
|
||||
/* generate code */
|
||||
char *fragmentgen = code_generate_fragment(material, nodes, frag_outlink->output, builtins);
|
||||
|
||||
/* Cache lookup: Reuse shaders already compiled */
|
||||
uint32_t hash = gpu_pass_hash(fragmentgen, defines, attribs);
|
||||
uint32_t hash = gpu_pass_hash(fragmentgen, defines, attrs);
|
||||
pass_hash = gpu_pass_cache_lookup(hash);
|
||||
|
||||
if (pass_hash && (pass_hash->next == NULL || pass_hash->next->hash != hash)) {
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
struct GPUNode;
|
||||
struct GPUOutput;
|
||||
struct GPUShader;
|
||||
struct GPUVertexAttribs;
|
||||
struct GPUVertAttrLayers;
|
||||
struct ListBase;
|
||||
struct PreviewImage;
|
||||
|
||||
@@ -55,7 +55,7 @@ typedef enum eGPUDataSource {
|
||||
GPU_SOURCE_OUTPUT,
|
||||
GPU_SOURCE_CONSTANT,
|
||||
GPU_SOURCE_UNIFORM,
|
||||
GPU_SOURCE_ATTRIB,
|
||||
GPU_SOURCE_ATTR,
|
||||
GPU_SOURCE_BUILTIN,
|
||||
GPU_SOURCE_STRUCT,
|
||||
GPU_SOURCE_TEX,
|
||||
@@ -63,7 +63,7 @@ typedef enum eGPUDataSource {
|
||||
|
||||
typedef enum {
|
||||
GPU_NODE_LINK_NONE = 0,
|
||||
GPU_NODE_LINK_ATTRIB,
|
||||
GPU_NODE_LINK_ATTR,
|
||||
GPU_NODE_LINK_BUILTIN,
|
||||
GPU_NODE_LINK_COLORBAND,
|
||||
GPU_NODE_LINK_CONSTANT,
|
||||
@@ -99,10 +99,10 @@ struct GPUNodeLink {
|
||||
struct GPUTexture **coba;
|
||||
/* GPU_NODE_LINK_OUTPUT */
|
||||
struct GPUOutput *output;
|
||||
/* GPU_NODE_LINK_ATTRIB */
|
||||
/* GPU_NODE_LINK_ATTR */
|
||||
struct {
|
||||
const char *attribname;
|
||||
CustomDataType attribtype;
|
||||
const char *attr_name;
|
||||
CustomDataType attr_type;
|
||||
};
|
||||
/* GPU_NODE_LINK_IMAGE_BLENDER */
|
||||
struct {
|
||||
@@ -151,12 +151,16 @@ typedef struct GPUInput {
|
||||
int texid; /* number for multitexture, starting from zero */
|
||||
eGPUType textype; /* texture type (2D, 1D Array ...) */
|
||||
};
|
||||
/* GPU_SOURCE_ATTRIB */
|
||||
/* GPU_SOURCE_ATTR */
|
||||
struct {
|
||||
char attribname[MAX_CUSTOMDATA_LAYER_NAME]; /* attribute name */
|
||||
int attribid; /* id for vertex attributes */
|
||||
bool attribfirst; /* this is the first one that is bound */
|
||||
CustomDataType attribtype; /* attribute type */
|
||||
/** Attribute name. */
|
||||
char attr_name[MAX_CUSTOMDATA_LAYER_NAME];
|
||||
/** ID for vertex attributes. */
|
||||
int attr_id;
|
||||
/** This is the first one that is bound. */
|
||||
bool attr_first;
|
||||
/** Attribute type. */
|
||||
CustomDataType attr_type;
|
||||
};
|
||||
};
|
||||
} GPUInput;
|
||||
@@ -178,7 +182,7 @@ typedef struct GPUPass GPUPass;
|
||||
|
||||
GPUPass *GPU_generate_pass(
|
||||
GPUMaterial *material,
|
||||
GPUNodeLink *frag_outlink, struct GPUVertexAttribs *attribs,
|
||||
GPUNodeLink *frag_outlink, struct GPUVertAttrLayers *attrs,
|
||||
ListBase *nodes, int *builtins,
|
||||
const char *vert_code, const char *geom_code,
|
||||
const char *frag_lib, const char *defines);
|
||||
@@ -186,7 +190,7 @@ GPUPass *GPU_generate_pass(
|
||||
struct GPUShader *GPU_pass_shader_get(GPUPass *pass);
|
||||
|
||||
void GPU_nodes_extract_dynamic_inputs(struct GPUShader *shader, ListBase *inputs, ListBase *nodes);
|
||||
void GPU_nodes_get_vertex_attributes(ListBase *nodes, struct GPUVertexAttribs *attribs);
|
||||
void GPU_nodes_get_vertex_attrs(ListBase *nodes, struct GPUVertAttrLayers *attrs);
|
||||
void GPU_nodes_prune(ListBase *nodes, struct GPUNodeLink *outlink);
|
||||
|
||||
void GPU_pass_compile(GPUPass *pass, const char *shname);
|
||||
|
||||
@@ -1423,7 +1423,7 @@ void GPU_select_to_index_array(uint *col, const uint size)
|
||||
#define STATE_STACK_DEPTH 16
|
||||
|
||||
typedef struct {
|
||||
eGPUAttribMask mask;
|
||||
eGPUAttrMask mask;
|
||||
|
||||
/* GL_ENABLE_BIT */
|
||||
uint is_blend : 1;
|
||||
@@ -1456,19 +1456,19 @@ typedef struct {
|
||||
/* GL_VIEWPORT_BIT */
|
||||
int viewport[4];
|
||||
double near_far[2];
|
||||
} GPUAttribValues;
|
||||
} GPUAttrValues;
|
||||
|
||||
typedef struct {
|
||||
GPUAttribValues attrib_stack[STATE_STACK_DEPTH];
|
||||
GPUAttrValues attr_stack[STATE_STACK_DEPTH];
|
||||
uint top;
|
||||
} GPUAttribStack;
|
||||
} GPUAttrStack;
|
||||
|
||||
static GPUAttribStack state = {
|
||||
static GPUAttrStack state = {
|
||||
.top = 0,
|
||||
};
|
||||
|
||||
#define AttribStack state
|
||||
#define Attrib state.attrib_stack[state.top]
|
||||
#define AttrStack state
|
||||
#define Attr state.attr_stack[state.top]
|
||||
|
||||
/**
|
||||
* Replacement for glPush/PopAttributes
|
||||
@@ -1476,54 +1476,54 @@ static GPUAttribStack state = {
|
||||
* We don't need to cover all the options of legacy OpenGL
|
||||
* but simply the ones used by Blender.
|
||||
*/
|
||||
void gpuPushAttrib(eGPUAttribMask mask)
|
||||
void gpuPushAttr(eGPUAttrMask mask)
|
||||
{
|
||||
Attrib.mask = mask;
|
||||
Attr.mask = mask;
|
||||
|
||||
if ((mask & GPU_DEPTH_BUFFER_BIT) != 0) {
|
||||
Attrib.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||
glGetIntegerv(GL_DEPTH_FUNC, &Attrib.depth_func);
|
||||
glGetDoublev(GL_DEPTH_CLEAR_VALUE, &Attrib.depth_clear_value);
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, (GLboolean *)&Attrib.depth_write_mask);
|
||||
Attr.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||
glGetIntegerv(GL_DEPTH_FUNC, &Attr.depth_func);
|
||||
glGetDoublev(GL_DEPTH_CLEAR_VALUE, &Attr.depth_clear_value);
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, (GLboolean *)&Attr.depth_write_mask);
|
||||
}
|
||||
|
||||
if ((mask & GPU_ENABLE_BIT) != 0) {
|
||||
Attrib.is_blend = glIsEnabled(GL_BLEND);
|
||||
Attr.is_blend = glIsEnabled(GL_BLEND);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Attrib.is_clip_plane[i] = glIsEnabled(GL_CLIP_PLANE0 + i);
|
||||
Attr.is_clip_plane[i] = glIsEnabled(GL_CLIP_PLANE0 + i);
|
||||
}
|
||||
|
||||
Attrib.is_cull_face = glIsEnabled(GL_CULL_FACE);
|
||||
Attrib.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||
Attrib.is_dither = glIsEnabled(GL_DITHER);
|
||||
Attrib.is_line_smooth = glIsEnabled(GL_LINE_SMOOTH);
|
||||
Attrib.is_color_logic_op = glIsEnabled(GL_COLOR_LOGIC_OP);
|
||||
Attrib.is_multisample = glIsEnabled(GL_MULTISAMPLE);
|
||||
Attrib.is_polygon_offset_line = glIsEnabled(GL_POLYGON_OFFSET_LINE);
|
||||
Attrib.is_polygon_offset_fill = glIsEnabled(GL_POLYGON_OFFSET_FILL);
|
||||
Attrib.is_polygon_smooth = glIsEnabled(GL_POLYGON_SMOOTH);
|
||||
Attrib.is_sample_alpha_to_coverage = glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE);
|
||||
Attrib.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||
Attrib.is_stencil_test = glIsEnabled(GL_STENCIL_TEST);
|
||||
Attr.is_cull_face = glIsEnabled(GL_CULL_FACE);
|
||||
Attr.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||
Attr.is_dither = glIsEnabled(GL_DITHER);
|
||||
Attr.is_line_smooth = glIsEnabled(GL_LINE_SMOOTH);
|
||||
Attr.is_color_logic_op = glIsEnabled(GL_COLOR_LOGIC_OP);
|
||||
Attr.is_multisample = glIsEnabled(GL_MULTISAMPLE);
|
||||
Attr.is_polygon_offset_line = glIsEnabled(GL_POLYGON_OFFSET_LINE);
|
||||
Attr.is_polygon_offset_fill = glIsEnabled(GL_POLYGON_OFFSET_FILL);
|
||||
Attr.is_polygon_smooth = glIsEnabled(GL_POLYGON_SMOOTH);
|
||||
Attr.is_sample_alpha_to_coverage = glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE);
|
||||
Attr.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||
Attr.is_stencil_test = glIsEnabled(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
if ((mask & GPU_SCISSOR_BIT) != 0) {
|
||||
Attrib.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||
glGetIntegerv(GL_SCISSOR_BOX, (GLint *)&Attrib.scissor_box);
|
||||
Attr.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||
glGetIntegerv(GL_SCISSOR_BOX, (GLint *)&Attr.scissor_box);
|
||||
}
|
||||
|
||||
if ((mask & GPU_VIEWPORT_BIT) != 0) {
|
||||
glGetDoublev(GL_DEPTH_RANGE, (GLdouble *)&Attrib.near_far);
|
||||
glGetIntegerv(GL_VIEWPORT, (GLint *)&Attrib.viewport);
|
||||
glGetDoublev(GL_DEPTH_RANGE, (GLdouble *)&Attr.near_far);
|
||||
glGetIntegerv(GL_VIEWPORT, (GLint *)&Attr.viewport);
|
||||
}
|
||||
|
||||
if ((mask & GPU_BLEND_BIT) != 0) {
|
||||
Attrib.is_blend = glIsEnabled(GL_BLEND);
|
||||
Attr.is_blend = glIsEnabled(GL_BLEND);
|
||||
}
|
||||
|
||||
BLI_assert(AttribStack.top < STATE_STACK_DEPTH);
|
||||
AttribStack.top++;
|
||||
BLI_assert(AttrStack.top < STATE_STACK_DEPTH);
|
||||
AttrStack.top++;
|
||||
}
|
||||
|
||||
static void restore_mask(GLenum cap, const bool value)
|
||||
@@ -1536,57 +1536,57 @@ static void restore_mask(GLenum cap, const bool value)
|
||||
}
|
||||
}
|
||||
|
||||
void gpuPopAttrib(void)
|
||||
void gpuPopAttr(void)
|
||||
{
|
||||
BLI_assert(AttribStack.top > 0);
|
||||
AttribStack.top--;
|
||||
BLI_assert(AttrStack.top > 0);
|
||||
AttrStack.top--;
|
||||
|
||||
GLint mask = Attrib.mask;
|
||||
GLint mask = Attr.mask;
|
||||
|
||||
if ((mask & GPU_DEPTH_BUFFER_BIT) != 0) {
|
||||
restore_mask(GL_DEPTH_TEST, Attrib.is_depth_test);
|
||||
glDepthFunc(Attrib.depth_func);
|
||||
glClearDepth(Attrib.depth_clear_value);
|
||||
glDepthMask(Attrib.depth_write_mask);
|
||||
restore_mask(GL_DEPTH_TEST, Attr.is_depth_test);
|
||||
glDepthFunc(Attr.depth_func);
|
||||
glClearDepth(Attr.depth_clear_value);
|
||||
glDepthMask(Attr.depth_write_mask);
|
||||
}
|
||||
|
||||
if ((mask & GPU_ENABLE_BIT) != 0) {
|
||||
restore_mask(GL_BLEND, Attrib.is_blend);
|
||||
restore_mask(GL_BLEND, Attr.is_blend);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
restore_mask(GL_CLIP_PLANE0 + i, Attrib.is_clip_plane[i]);
|
||||
restore_mask(GL_CLIP_PLANE0 + i, Attr.is_clip_plane[i]);
|
||||
}
|
||||
|
||||
restore_mask(GL_CULL_FACE, Attrib.is_cull_face);
|
||||
restore_mask(GL_DEPTH_TEST, Attrib.is_depth_test);
|
||||
restore_mask(GL_DITHER, Attrib.is_dither);
|
||||
restore_mask(GL_LINE_SMOOTH, Attrib.is_line_smooth);
|
||||
restore_mask(GL_COLOR_LOGIC_OP, Attrib.is_color_logic_op);
|
||||
restore_mask(GL_MULTISAMPLE, Attrib.is_multisample);
|
||||
restore_mask(GL_POLYGON_OFFSET_LINE, Attrib.is_polygon_offset_line);
|
||||
restore_mask(GL_POLYGON_OFFSET_FILL, Attrib.is_polygon_offset_fill);
|
||||
restore_mask(GL_POLYGON_SMOOTH, Attrib.is_polygon_smooth);
|
||||
restore_mask(GL_SAMPLE_ALPHA_TO_COVERAGE, Attrib.is_sample_alpha_to_coverage);
|
||||
restore_mask(GL_SCISSOR_TEST, Attrib.is_scissor_test);
|
||||
restore_mask(GL_STENCIL_TEST, Attrib.is_stencil_test);
|
||||
restore_mask(GL_CULL_FACE, Attr.is_cull_face);
|
||||
restore_mask(GL_DEPTH_TEST, Attr.is_depth_test);
|
||||
restore_mask(GL_DITHER, Attr.is_dither);
|
||||
restore_mask(GL_LINE_SMOOTH, Attr.is_line_smooth);
|
||||
restore_mask(GL_COLOR_LOGIC_OP, Attr.is_color_logic_op);
|
||||
restore_mask(GL_MULTISAMPLE, Attr.is_multisample);
|
||||
restore_mask(GL_POLYGON_OFFSET_LINE, Attr.is_polygon_offset_line);
|
||||
restore_mask(GL_POLYGON_OFFSET_FILL, Attr.is_polygon_offset_fill);
|
||||
restore_mask(GL_POLYGON_SMOOTH, Attr.is_polygon_smooth);
|
||||
restore_mask(GL_SAMPLE_ALPHA_TO_COVERAGE, Attr.is_sample_alpha_to_coverage);
|
||||
restore_mask(GL_SCISSOR_TEST, Attr.is_scissor_test);
|
||||
restore_mask(GL_STENCIL_TEST, Attr.is_stencil_test);
|
||||
}
|
||||
|
||||
if ((mask & GPU_VIEWPORT_BIT) != 0) {
|
||||
glViewport(Attrib.viewport[0], Attrib.viewport[1], Attrib.viewport[2], Attrib.viewport[3]);
|
||||
glDepthRange(Attrib.near_far[0], Attrib.near_far[1]);
|
||||
glViewport(Attr.viewport[0], Attr.viewport[1], Attr.viewport[2], Attr.viewport[3]);
|
||||
glDepthRange(Attr.near_far[0], Attr.near_far[1]);
|
||||
}
|
||||
|
||||
if ((mask & GPU_SCISSOR_BIT) != 0) {
|
||||
restore_mask(GL_SCISSOR_TEST, Attrib.is_scissor_test);
|
||||
glScissor(Attrib.scissor_box[0], Attrib.scissor_box[1], Attrib.scissor_box[2], Attrib.scissor_box[3]);
|
||||
restore_mask(GL_SCISSOR_TEST, Attr.is_scissor_test);
|
||||
glScissor(Attr.scissor_box[0], Attr.scissor_box[1], Attr.scissor_box[2], Attr.scissor_box[3]);
|
||||
}
|
||||
|
||||
if ((mask & GPU_BLEND_BIT) != 0) {
|
||||
restore_mask(GL_BLEND, Attrib.is_blend);
|
||||
restore_mask(GL_BLEND, Attr.is_blend);
|
||||
}
|
||||
}
|
||||
|
||||
#undef Attrib
|
||||
#undef AttribStack
|
||||
#undef Attr
|
||||
#undef AttrStack
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -808,7 +808,7 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, bool dept
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpuPushAttrib(GPU_VIEWPORT_BIT);
|
||||
gpuPushAttr(GPU_VIEWPORT_BIT);
|
||||
|
||||
GPU_framebuffer_ensure_config(&ofs->fb, {
|
||||
GPU_ATTACHMENT_TEXTURE(ofs->depth),
|
||||
@@ -818,13 +818,13 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, bool dept
|
||||
/* check validity at the very end! */
|
||||
if (!GPU_framebuffer_check_valid(ofs->fb, err_out)) {
|
||||
GPU_offscreen_free(ofs);
|
||||
gpuPopAttrib();
|
||||
gpuPopAttr();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GPU_framebuffer_restore();
|
||||
|
||||
gpuPopAttrib();
|
||||
gpuPopAttr();
|
||||
|
||||
return ofs;
|
||||
}
|
||||
@@ -844,7 +844,7 @@ void GPU_offscreen_free(GPUOffScreen *ofs)
|
||||
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save)
|
||||
{
|
||||
if (save) {
|
||||
gpuPushAttrib(GPU_SCISSOR_BIT | GPU_VIEWPORT_BIT);
|
||||
gpuPushAttr(GPU_SCISSOR_BIT | GPU_VIEWPORT_BIT);
|
||||
GPUFrameBuffer *fb = GPU_framebuffer_active_get();
|
||||
gpuPushFrameBuffer(fb);
|
||||
}
|
||||
@@ -857,7 +857,7 @@ void GPU_offscreen_unbind(GPUOffScreen *UNUSED(ofs), bool restore)
|
||||
GPUFrameBuffer *fb = NULL;
|
||||
|
||||
if (restore) {
|
||||
gpuPopAttrib();
|
||||
gpuPopAttr();
|
||||
fb = gpuPopFrameBuffer();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,15 +66,15 @@ typedef struct {
|
||||
/* current vertex */
|
||||
uint vertex_idx;
|
||||
GLubyte *vertex_data;
|
||||
uint16_t unassigned_attrib_bits; /* which attributes of current vertex have not been given values? */
|
||||
uint16_t unassigned_attr_bits; /* which attributes of current vertex have not been given values? */
|
||||
|
||||
GLuint vbo_id;
|
||||
GLuint vao_id;
|
||||
|
||||
GLuint bound_program;
|
||||
const GPUShaderInterface *shader_interface;
|
||||
GPUAttrBinding attrib_binding;
|
||||
uint16_t prev_enabled_attrib_bits; /* <-- only affects this VAO, so we're ok */
|
||||
GPUAttrBinding attr_binding;
|
||||
uint16_t prev_enabled_attr_bits; /* <-- only affects this VAO, so we're ok */
|
||||
} Immediate;
|
||||
|
||||
/* size of internal buffer -- make this adjustable? */
|
||||
@@ -121,7 +121,7 @@ void immDeactivate(void)
|
||||
#endif
|
||||
GPU_vao_free(imm.vao_id, imm.context);
|
||||
imm.vao_id = 0;
|
||||
imm.prev_enabled_attrib_bits = 0;
|
||||
imm.prev_enabled_attr_bits = 0;
|
||||
}
|
||||
|
||||
void immDestroy(void)
|
||||
@@ -150,7 +150,7 @@ void immBindProgram(GLuint program, const GPUShaderInterface *shaderface)
|
||||
VertexFormat_pack(&imm.vertex_format);
|
||||
|
||||
glUseProgram(program);
|
||||
get_attrib_locations(&imm.vertex_format, &imm.attrib_binding, shaderface);
|
||||
get_attr_locations(&imm.vertex_format, &imm.attr_binding, shaderface);
|
||||
GPU_matrix_bind(shaderface);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ void immBegin(GPUPrimType prim_type, uint vertex_len)
|
||||
imm.prim_type = prim_type;
|
||||
imm.vertex_len = vertex_len;
|
||||
imm.vertex_idx = 0;
|
||||
imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
|
||||
imm.unassigned_attr_bits = imm.attr_binding.enabled_bits;
|
||||
|
||||
/* how many bytes do we need for this draw call? */
|
||||
const uint bytes_needed = vertex_buffer_size(&imm.vertex_format, vertex_len);
|
||||
@@ -270,7 +270,7 @@ GPUBatch *immBeginBatch(GPUPrimType prim_type, uint vertex_len)
|
||||
imm.prim_type = prim_type;
|
||||
imm.vertex_len = vertex_len;
|
||||
imm.vertex_idx = 0;
|
||||
imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
|
||||
imm.unassigned_attr_bits = imm.attr_binding.enabled_bits;
|
||||
|
||||
GPUVertBuf *verts = GPU_vertbuf_create_with_format(&imm.vertex_format);
|
||||
GPU_vertbuf_data_alloc(verts, vertex_len);
|
||||
@@ -295,11 +295,11 @@ static void immDrawSetup(void)
|
||||
/* set up VAO -- can be done during Begin or End really */
|
||||
glBindVertexArray(imm.vao_id);
|
||||
|
||||
/* enable/disable vertex attribs as needed */
|
||||
if (imm.attrib_binding.enabled_bits != imm.prev_enabled_attrib_bits) {
|
||||
/* Enable/Disable vertex attributes as needed. */
|
||||
if (imm.attr_binding.enabled_bits != imm.prev_enabled_attr_bits) {
|
||||
for (uint loc = 0; loc < GPU_VERT_ATTR_MAX_LEN; ++loc) {
|
||||
bool is_enabled = imm.attrib_binding.enabled_bits & (1 << loc);
|
||||
bool was_enabled = imm.prev_enabled_attrib_bits & (1 << loc);
|
||||
bool is_enabled = imm.attr_binding.enabled_bits & (1 << loc);
|
||||
bool was_enabled = imm.prev_enabled_attr_bits & (1 << loc);
|
||||
|
||||
if (is_enabled && !was_enabled) {
|
||||
glEnableVertexAttribArray(loc);
|
||||
@@ -309,18 +309,18 @@ static void immDrawSetup(void)
|
||||
}
|
||||
}
|
||||
|
||||
imm.prev_enabled_attrib_bits = imm.attrib_binding.enabled_bits;
|
||||
imm.prev_enabled_attr_bits = imm.attr_binding.enabled_bits;
|
||||
}
|
||||
|
||||
const uint stride = imm.vertex_format.stride;
|
||||
|
||||
for (uint a_idx = 0; a_idx < imm.vertex_format.attr_len; ++a_idx) {
|
||||
const GPUVertAttr *a = imm.vertex_format.attribs + a_idx;
|
||||
const GPUVertAttr *a = &imm.vertex_format.attrs[a_idx];
|
||||
|
||||
const uint offset = imm.buffer_offset + a->offset;
|
||||
const GLvoid *pointer = (const GLubyte *)0 + offset;
|
||||
|
||||
const uint loc = read_attrib_location(&imm.attrib_binding, a_idx);
|
||||
const uint loc = read_attr_location(&imm.attr_binding, a_idx);
|
||||
|
||||
switch (a->fetch_mode) {
|
||||
case GPU_FETCH_FLOAT:
|
||||
@@ -400,29 +400,29 @@ void immEnd(void)
|
||||
imm.strict_vertex_len = true;
|
||||
}
|
||||
|
||||
static void setAttribValueBit(uint attrib_id)
|
||||
static void setAttrValueBit(uint attr_id)
|
||||
{
|
||||
uint16_t mask = 1 << attrib_id;
|
||||
uint16_t mask = 1 << attr_id;
|
||||
#if TRUST_NO_ONE
|
||||
assert(imm.unassigned_attrib_bits & mask); /* not already set */
|
||||
assert(imm.unassigned_attr_bits & mask); /* not already set */
|
||||
#endif
|
||||
imm.unassigned_attrib_bits &= ~mask;
|
||||
imm.unassigned_attr_bits &= ~mask;
|
||||
}
|
||||
|
||||
|
||||
/* --- generic attribute functions --- */
|
||||
|
||||
void immAttr1f(uint attrib_id, float x)
|
||||
void immAttr1f(uint attr_id, float x)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_F32);
|
||||
assert(attr->comp_len == 1);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
float *data = (float *)(imm.vertex_data + attr->offset);
|
||||
/* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
|
||||
@@ -430,17 +430,17 @@ void immAttr1f(uint attrib_id, float x)
|
||||
data[0] = x;
|
||||
}
|
||||
|
||||
void immAttr2f(uint attrib_id, float x, float y)
|
||||
void immAttr2f(uint attr_id, float x, float y)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_F32);
|
||||
assert(attr->comp_len == 2);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
float *data = (float *)(imm.vertex_data + attr->offset);
|
||||
/* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
|
||||
@@ -449,17 +449,17 @@ void immAttr2f(uint attrib_id, float x, float y)
|
||||
data[1] = y;
|
||||
}
|
||||
|
||||
void immAttr3f(uint attrib_id, float x, float y, float z)
|
||||
void immAttr3f(uint attr_id, float x, float y, float z)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_F32);
|
||||
assert(attr->comp_len == 3);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
float *data = (float *)(imm.vertex_data + attr->offset);
|
||||
/* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
|
||||
@@ -469,17 +469,17 @@ void immAttr3f(uint attrib_id, float x, float y, float z)
|
||||
data[2] = z;
|
||||
}
|
||||
|
||||
void immAttr4f(uint attrib_id, float x, float y, float z, float w)
|
||||
void immAttr4f(uint attr_id, float x, float y, float z, float w)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_F32);
|
||||
assert(attr->comp_len == 4);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
float *data = (float *)(imm.vertex_data + attr->offset);
|
||||
/* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
|
||||
@@ -490,34 +490,34 @@ void immAttr4f(uint attrib_id, float x, float y, float z, float w)
|
||||
data[3] = w;
|
||||
}
|
||||
|
||||
void immAttr1u(uint attrib_id, uint x)
|
||||
void immAttr1u(uint attr_id, uint x)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_U32);
|
||||
assert(attr->comp_len == 1);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
uint *data = (uint *)(imm.vertex_data + attr->offset);
|
||||
|
||||
data[0] = x;
|
||||
}
|
||||
|
||||
void immAttr2i(uint attrib_id, int x, int y)
|
||||
void immAttr2i(uint attr_id, int x, int y)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_I32);
|
||||
assert(attr->comp_len == 2);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
int *data = (int *)(imm.vertex_data + attr->offset);
|
||||
|
||||
@@ -525,17 +525,17 @@ void immAttr2i(uint attrib_id, int x, int y)
|
||||
data[1] = y;
|
||||
}
|
||||
|
||||
void immAttr2s(uint attrib_id, short x, short y)
|
||||
void immAttr2s(uint attr_id, short x, short y)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_I16);
|
||||
assert(attr->comp_len == 2);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
short *data = (short *)(imm.vertex_data + attr->offset);
|
||||
|
||||
@@ -543,32 +543,32 @@ void immAttr2s(uint attrib_id, short x, short y)
|
||||
data[1] = y;
|
||||
}
|
||||
|
||||
void immAttr2fv(uint attrib_id, const float data[2])
|
||||
void immAttr2fv(uint attr_id, const float data[2])
|
||||
{
|
||||
immAttr2f(attrib_id, data[0], data[1]);
|
||||
immAttr2f(attr_id, data[0], data[1]);
|
||||
}
|
||||
|
||||
void immAttr3fv(uint attrib_id, const float data[3])
|
||||
void immAttr3fv(uint attr_id, const float data[3])
|
||||
{
|
||||
immAttr3f(attrib_id, data[0], data[1], data[2]);
|
||||
immAttr3f(attr_id, data[0], data[1], data[2]);
|
||||
}
|
||||
|
||||
void immAttr4fv(uint attrib_id, const float data[4])
|
||||
void immAttr4fv(uint attr_id, const float data[4])
|
||||
{
|
||||
immAttr4f(attrib_id, data[0], data[1], data[2], data[3]);
|
||||
immAttr4f(attr_id, data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
void immAttr3ub(uint attrib_id, uchar r, uchar g, uchar b)
|
||||
void immAttr3ub(uint attr_id, uchar r, uchar g, uchar b)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_U8);
|
||||
assert(attr->comp_len == 3);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
GLubyte *data = imm.vertex_data + attr->offset;
|
||||
/* printf("%s %td %p\n", __FUNCTION__, data - imm.buffer_data, data); */
|
||||
@@ -578,17 +578,17 @@ void immAttr3ub(uint attrib_id, uchar r, uchar g, uchar b)
|
||||
data[2] = b;
|
||||
}
|
||||
|
||||
void immAttr4ub(uint attrib_id, uchar r, uchar g, uchar b, uchar a)
|
||||
void immAttr4ub(uint attr_id, uchar r, uchar g, uchar b, uchar a)
|
||||
{
|
||||
GPUVertAttr *attr = imm.vertex_format.attribs + attrib_id;
|
||||
GPUVertAttr *attr = &imm.vertex_format.attrs[attr_id];
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(attr->comp_type == GPU_COMP_U8);
|
||||
assert(attr->comp_len == 4);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
|
||||
GLubyte *data = imm.vertex_data + attr->offset;
|
||||
/* printf("%s %td %p\n", __FUNCTION__, data - imm.buffer_data, data); */
|
||||
@@ -599,24 +599,24 @@ void immAttr4ub(uint attrib_id, uchar r, uchar g, uchar b, uchar a)
|
||||
data[3] = a;
|
||||
}
|
||||
|
||||
void immAttr3ubv(uint attrib_id, const uchar data[3])
|
||||
void immAttr3ubv(uint attr_id, const uchar data[3])
|
||||
{
|
||||
immAttr3ub(attrib_id, data[0], data[1], data[2]);
|
||||
immAttr3ub(attr_id, data[0], data[1], data[2]);
|
||||
}
|
||||
|
||||
void immAttr4ubv(uint attrib_id, const uchar data[4])
|
||||
void immAttr4ubv(uint attr_id, const uchar data[4])
|
||||
{
|
||||
immAttr4ub(attrib_id, data[0], data[1], data[2], data[3]);
|
||||
immAttr4ub(attr_id, data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
void immAttrSkip(uint attrib_id)
|
||||
void immAttrSkip(uint attr_id)
|
||||
{
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib_id < imm.vertex_format.attr_len);
|
||||
assert(attr_id < imm.vertex_format.attr_len);
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
assert(imm.prim_type != GPU_PRIM_NONE); /* make sure we're between a Begin/End pair */
|
||||
#endif
|
||||
setAttribValueBit(attrib_id);
|
||||
setAttrValueBit(attr_id);
|
||||
}
|
||||
|
||||
static void immEndVertex(void) /* and move on to the next vertex */
|
||||
@@ -626,15 +626,15 @@ static void immEndVertex(void) /* and move on to the next vertex */
|
||||
assert(imm.vertex_idx < imm.vertex_len);
|
||||
#endif
|
||||
|
||||
/* have all attribs been assigned values?
|
||||
* if not, copy value from previous vertex */
|
||||
if (imm.unassigned_attrib_bits) {
|
||||
/* Have all attributes been assigned values?
|
||||
* If not, copy value from previous vertex. */
|
||||
if (imm.unassigned_attr_bits) {
|
||||
#if TRUST_NO_ONE
|
||||
assert(imm.vertex_idx > 0); /* first vertex must have all attribs specified */
|
||||
assert(imm.vertex_idx > 0); /* first vertex must have all attributes specified */
|
||||
#endif
|
||||
for (uint a_idx = 0; a_idx < imm.vertex_format.attr_len; ++a_idx) {
|
||||
if ((imm.unassigned_attrib_bits >> a_idx) & 1) {
|
||||
const GPUVertAttr *a = imm.vertex_format.attribs + a_idx;
|
||||
if ((imm.unassigned_attr_bits >> a_idx) & 1) {
|
||||
const GPUVertAttr *a = &imm.vertex_format.attrs[a_idx];
|
||||
|
||||
/* printf("copying %s from vertex %u to %u\n", a->name, imm.vertex_idx - 1, imm.vertex_idx); */
|
||||
|
||||
@@ -647,54 +647,54 @@ static void immEndVertex(void) /* and move on to the next vertex */
|
||||
|
||||
imm.vertex_idx++;
|
||||
imm.vertex_data += imm.vertex_format.stride;
|
||||
imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
|
||||
imm.unassigned_attr_bits = imm.attr_binding.enabled_bits;
|
||||
}
|
||||
|
||||
void immVertex2f(uint attrib_id, float x, float y)
|
||||
void immVertex2f(uint attr_id, float x, float y)
|
||||
{
|
||||
immAttr2f(attrib_id, x, y);
|
||||
immAttr2f(attr_id, x, y);
|
||||
immEndVertex();
|
||||
}
|
||||
|
||||
void immVertex3f(uint attrib_id, float x, float y, float z)
|
||||
void immVertex3f(uint attr_id, float x, float y, float z)
|
||||
{
|
||||
immAttr3f(attrib_id, x, y, z);
|
||||
immAttr3f(attr_id, x, y, z);
|
||||
immEndVertex();
|
||||
}
|
||||
|
||||
void immVertex4f(uint attrib_id, float x, float y, float z, float w)
|
||||
void immVertex4f(uint attr_id, float x, float y, float z, float w)
|
||||
{
|
||||
immAttr4f(attrib_id, x, y, z, w);
|
||||
immAttr4f(attr_id, x, y, z, w);
|
||||
immEndVertex();
|
||||
}
|
||||
|
||||
void immVertex2i(uint attrib_id, int x, int y)
|
||||
void immVertex2i(uint attr_id, int x, int y)
|
||||
{
|
||||
immAttr2i(attrib_id, x, y);
|
||||
immAttr2i(attr_id, x, y);
|
||||
immEndVertex();
|
||||
}
|
||||
|
||||
void immVertex2s(uint attrib_id, short x, short y)
|
||||
void immVertex2s(uint attr_id, short x, short y)
|
||||
{
|
||||
immAttr2s(attrib_id, x, y);
|
||||
immAttr2s(attr_id, x, y);
|
||||
immEndVertex();
|
||||
}
|
||||
|
||||
void immVertex2fv(uint attrib_id, const float data[2])
|
||||
void immVertex2fv(uint attr_id, const float data[2])
|
||||
{
|
||||
immAttr2f(attrib_id, data[0], data[1]);
|
||||
immAttr2f(attr_id, data[0], data[1]);
|
||||
immEndVertex();
|
||||
}
|
||||
|
||||
void immVertex3fv(uint attrib_id, const float data[3])
|
||||
void immVertex3fv(uint attr_id, const float data[3])
|
||||
{
|
||||
immAttr3f(attrib_id, data[0], data[1], data[2]);
|
||||
immAttr3f(attr_id, data[0], data[1], data[2]);
|
||||
immEndVertex();
|
||||
}
|
||||
|
||||
void immVertex2iv(uint attrib_id, const int data[2])
|
||||
void immVertex2iv(uint attr_id, const int data[2])
|
||||
{
|
||||
immAttr2i(attrib_id, data[0], data[1]);
|
||||
immAttr2i(attr_id, data[0], data[1]);
|
||||
immEndVertex();
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ void immRecti_fast_with_color(uint pos, uint col, int x1, int y1, int x2, int y2
|
||||
void immRecti_complete(int x1, int y1, int x2, int y2, const float color[4])
|
||||
{
|
||||
GPUVertFormat *format = immVertexFormat();
|
||||
uint pos = add_attrib(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
|
||||
uint pos = add_attr(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
|
||||
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
||||
immUniformColor4fv(color);
|
||||
immRecti(pos, x1, y1, x2, y2);
|
||||
|
||||
@@ -82,7 +82,7 @@ struct GPUMaterial {
|
||||
/* for binding the material */
|
||||
GPUPass *pass;
|
||||
ListBase inputs; /* GPUInput */
|
||||
GPUVertexAttribs attribs;
|
||||
GPUVertAttrLayers attrs;
|
||||
int builtins;
|
||||
int alpha, obcolalpha;
|
||||
int dynproperty;
|
||||
@@ -569,9 +569,9 @@ struct GPUUniformBuffer *GPU_material_create_sss_profile_ubo(void)
|
||||
#undef SSS_EXPONENT
|
||||
#undef SSS_SAMPLES
|
||||
|
||||
void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs)
|
||||
void GPU_material_vertex_attrs(GPUMaterial *material, GPUVertAttrLayers *r_attrs)
|
||||
{
|
||||
*attribs = material->attribs;
|
||||
*r_attrs = material->attrs;
|
||||
}
|
||||
|
||||
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
|
||||
@@ -676,15 +676,15 @@ GPUMaterial *GPU_material_from_nodetree(
|
||||
}
|
||||
|
||||
if (mat->outlink) {
|
||||
/* Prune the unused nodes and extract attribs before compiling so the
|
||||
/* Prune the unused nodes and extract attributes before compiling so the
|
||||
* generated VBOs are ready to accept the future shader. */
|
||||
GPU_nodes_prune(&mat->nodes, mat->outlink);
|
||||
GPU_nodes_get_vertex_attributes(&mat->nodes, &mat->attribs);
|
||||
GPU_nodes_get_vertex_attrs(&mat->nodes, &mat->attrs);
|
||||
/* Create source code and search pass cache for an already compiled version. */
|
||||
mat->pass = GPU_generate_pass(
|
||||
mat,
|
||||
mat->outlink,
|
||||
&mat->attribs,
|
||||
&mat->attrs,
|
||||
&mat->nodes,
|
||||
&mat->builtins,
|
||||
vert_code,
|
||||
|
||||
@@ -317,7 +317,7 @@ void gpu_select_pick_begin(
|
||||
|
||||
/* Restrict OpenGL operations for when we don't have cache */
|
||||
if (ps->is_cached == false) {
|
||||
gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_VIEWPORT_BIT);
|
||||
gpuPushAttr(GPU_DEPTH_BUFFER_BIT | GPU_VIEWPORT_BIT);
|
||||
|
||||
/* disable writing to the framebuffer */
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
@@ -539,7 +539,7 @@ uint gpu_select_pick_end(void)
|
||||
/* force finishing last pass */
|
||||
gpu_select_pick_load_id(ps->gl.prev_id);
|
||||
}
|
||||
gpuPopAttrib();
|
||||
gpuPopAttr();
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ void gpu_select_query_begin(
|
||||
g_query_state.id = MEM_mallocN(g_query_state.num_of_queries * sizeof(*g_query_state.id), "gpu selection ids");
|
||||
glGenQueries(g_query_state.num_of_queries, g_query_state.queries);
|
||||
|
||||
gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_VIEWPORT_BIT | GPU_SCISSOR_BIT);
|
||||
gpuPushAttr(GPU_DEPTH_BUFFER_BIT | GPU_VIEWPORT_BIT | GPU_SCISSOR_BIT);
|
||||
/* disable writing to the framebuffer */
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
|
||||
@@ -219,7 +219,7 @@ uint gpu_select_query_end(void)
|
||||
glDeleteQueries(g_query_state.num_of_queries, g_query_state.queries);
|
||||
MEM_freeN(g_query_state.queries);
|
||||
MEM_freeN(g_query_state.id);
|
||||
gpuPopAttrib();
|
||||
gpuPopAttr();
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
|
||||
return hits;
|
||||
|
||||
@@ -674,8 +674,8 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText
|
||||
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
|
||||
{
|
||||
BLI_assert(shader && shader->program);
|
||||
const GPUShaderInput *attrib = GPU_shaderinterface_attr(shader->interface, name);
|
||||
return attrib ? attrib->location : -1;
|
||||
const GPUShaderInput *attr = GPU_shaderinterface_attr(shader->interface, name);
|
||||
return attr ? attr->location : -1;
|
||||
}
|
||||
|
||||
static const GPUShaderStages builtin_shader_stages[GPU_NUM_BUILTIN_SHADERS] = {
|
||||
|
||||
@@ -221,15 +221,15 @@ GPUShaderInterface *GPU_shaderinterface_create(int32_t program)
|
||||
printf("GPUShaderInterface %p, program %d\n", shaderface, program);
|
||||
#endif
|
||||
|
||||
GLint max_attrib_name_len, attr_len;
|
||||
glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_attrib_name_len);
|
||||
GLint max_attr_name_len, attr_len;
|
||||
glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_attr_name_len);
|
||||
glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &attr_len);
|
||||
|
||||
GLint max_ubo_name_len, ubo_len;
|
||||
glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &max_ubo_name_len);
|
||||
glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &ubo_len);
|
||||
|
||||
const uint32_t name_buffer_len = attr_len * max_attrib_name_len + ubo_len * max_ubo_name_len;
|
||||
const uint32_t name_buffer_len = attr_len * max_attr_name_len + ubo_len * max_ubo_name_len;
|
||||
shaderface->name_buffer = MEM_mallocN(name_buffer_len, "name_buffer");
|
||||
|
||||
/* Attributes */
|
||||
@@ -253,10 +253,10 @@ GPUShaderInterface *GPU_shaderinterface_create(int32_t program)
|
||||
|
||||
set_input_name(shaderface, input, name, name_len);
|
||||
|
||||
shader_input_to_bucket(input, shaderface->attrib_buckets);
|
||||
shader_input_to_bucket(input, shaderface->attr_buckets);
|
||||
|
||||
#if DEBUG_SHADER_INTERFACE
|
||||
printf("attrib[%u] '%s' at location %d\n", i, name, input->location);
|
||||
printf("attr[%u] '%s' at location %d\n", i, name, input->location);
|
||||
#endif
|
||||
}
|
||||
/* Uniform Blocks */
|
||||
@@ -296,7 +296,7 @@ void GPU_shaderinterface_discard(GPUShaderInterface *shaderface)
|
||||
{
|
||||
/* Free memory used by buckets and has entries. */
|
||||
buckets_free(shaderface->uniform_buckets);
|
||||
buckets_free(shaderface->attrib_buckets);
|
||||
buckets_free(shaderface->attr_buckets);
|
||||
buckets_free(shaderface->ubo_buckets);
|
||||
/* Free memory used by name_buffer. */
|
||||
MEM_freeN(shaderface->name_buffer);
|
||||
@@ -358,7 +358,7 @@ const GPUShaderInput *GPU_shaderinterface_ubo(const GPUShaderInterface *shaderfa
|
||||
|
||||
const GPUShaderInput *GPU_shaderinterface_attr(const GPUShaderInterface *shaderface, const char *name)
|
||||
{
|
||||
return buckets_lookup(shaderface->attrib_buckets, shaderface->name_buffer, name);
|
||||
return buckets_lookup(shaderface->attr_buckets, shaderface->name_buffer, name);
|
||||
}
|
||||
|
||||
void GPU_shaderinterface_add_batch_ref(GPUShaderInterface *shaderface, GPUBatch *batch)
|
||||
|
||||
@@ -29,13 +29,18 @@
|
||||
#include "GPU_shader_interface.h"
|
||||
|
||||
struct GPUShader {
|
||||
GLuint program; /* handle for full program (links shader stages below) */
|
||||
/** Handle for full program (links shader stages below). */
|
||||
GLuint program;
|
||||
|
||||
GLuint vertex; /* handle for vertex shader */
|
||||
GLuint geometry; /* handle for geometry shader */
|
||||
GLuint fragment; /* handle for fragment shader */
|
||||
/** Handle for vertex shader. */
|
||||
GLuint vertex;
|
||||
/** Handle for geometry shader. */
|
||||
GLuint geometry;
|
||||
/** Handle for fragment shader. */
|
||||
GLuint fragment;
|
||||
|
||||
GPUShaderInterface *interface; /* cached uniform & attrib interface for shader */
|
||||
/** Cached uniform & attribute interface for shader. */
|
||||
GPUShaderInterface *interface;
|
||||
|
||||
int feedback_transform_type;
|
||||
#ifndef NDEBUG
|
||||
|
||||
@@ -1064,7 +1064,7 @@ GPUTexture *GPU_texture_create_cube(
|
||||
GPUTexture *GPU_texture_create_from_vertbuf(GPUVertBuf *vert)
|
||||
{
|
||||
GPUVertFormat *format = &vert->format;
|
||||
GPUVertAttr *attr = &format->attribs[0];
|
||||
GPUVertAttr *attr = &format->attrs[0];
|
||||
|
||||
/* Detect incompatible cases (not supported by texture buffers) */
|
||||
BLI_assert(format->attr_len == 1 && vert->vbo_id != 0);
|
||||
|
||||
@@ -169,7 +169,7 @@ void GPU_vertbuf_data_len_set(GPUVertBuf *verts, uint v_len)
|
||||
void GPU_vertbuf_attr_set(GPUVertBuf *verts, uint a_idx, uint v_idx, const void *data)
|
||||
{
|
||||
const GPUVertFormat *format = &verts->format;
|
||||
const GPUVertAttr *a = format->attribs + a_idx;
|
||||
const GPUVertAttr *a = &format->attrs[a_idx];
|
||||
|
||||
#if TRUST_NO_ONE
|
||||
assert(a_idx < format->attr_len);
|
||||
@@ -183,7 +183,7 @@ void GPU_vertbuf_attr_set(GPUVertBuf *verts, uint a_idx, uint v_idx, const void
|
||||
void GPU_vertbuf_attr_fill(GPUVertBuf *verts, uint a_idx, const void *data)
|
||||
{
|
||||
const GPUVertFormat *format = &verts->format;
|
||||
const GPUVertAttr *a = format->attribs + a_idx;
|
||||
const GPUVertAttr *a = &format->attrs[a_idx];
|
||||
|
||||
#if TRUST_NO_ONE
|
||||
assert(a_idx < format->attr_len);
|
||||
@@ -196,7 +196,7 @@ void GPU_vertbuf_attr_fill(GPUVertBuf *verts, uint a_idx, const void *data)
|
||||
void GPU_vertbuf_attr_fill_stride(GPUVertBuf *verts, uint a_idx, uint stride, const void *data)
|
||||
{
|
||||
const GPUVertFormat *format = &verts->format;
|
||||
const GPUVertAttr *a = format->attribs + a_idx;
|
||||
const GPUVertAttr *a = &format->attrs[a_idx];
|
||||
|
||||
#if TRUST_NO_ONE
|
||||
assert(a_idx < format->attr_len);
|
||||
@@ -220,7 +220,7 @@ void GPU_vertbuf_attr_fill_stride(GPUVertBuf *verts, uint a_idx, uint stride, co
|
||||
void GPU_vertbuf_attr_get_raw_data(GPUVertBuf *verts, uint a_idx, GPUVertBufRaw *access)
|
||||
{
|
||||
const GPUVertFormat *format = &verts->format;
|
||||
const GPUVertAttr *a = format->attribs + a_idx;
|
||||
const GPUVertAttr *a = &format->attrs[a_idx];
|
||||
|
||||
#if TRUST_NO_ONE
|
||||
assert(a_idx < format->attr_len);
|
||||
|
||||
@@ -55,7 +55,7 @@ void GPU_vertformat_clear(GPUVertFormat *format)
|
||||
format->name_len = 0;
|
||||
|
||||
for (uint i = 0; i < GPU_VERT_ATTR_MAX_LEN; i++) {
|
||||
format->attribs[i].name_len = 0;
|
||||
format->attrs[i].name_len = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -66,8 +66,8 @@ void GPU_vertformat_copy(GPUVertFormat *dest, const GPUVertFormat *src)
|
||||
memcpy(dest, src, sizeof(GPUVertFormat));
|
||||
|
||||
for (uint i = 0; i < dest->attr_len; i++) {
|
||||
for (uint j = 0; j < dest->attribs[i].name_len; j++) {
|
||||
dest->attribs[i].name[j] = (char *)dest + (src->attribs[i].name[j] - ((char *)src));
|
||||
for (uint j = 0; j < dest->attrs[i].name_len; j++) {
|
||||
dest->attrs[i].name[j] = (char *)dest + (src->attrs[i].name[j] - ((char *)src));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ static uint comp_sz(GPUVertCompType type)
|
||||
return sizes[type];
|
||||
}
|
||||
|
||||
static uint attrib_sz(const GPUVertAttr *a)
|
||||
static uint attr_sz(const GPUVertAttr *a)
|
||||
{
|
||||
if (a->comp_type == GPU_COMP_I10) {
|
||||
return 4; /* always packed as 10_10_10_2 */
|
||||
@@ -106,7 +106,7 @@ static uint attrib_sz(const GPUVertAttr *a)
|
||||
return a->comp_len * comp_sz(a->comp_type);
|
||||
}
|
||||
|
||||
static uint attrib_align(const GPUVertAttr *a)
|
||||
static uint attr_align(const GPUVertAttr *a)
|
||||
{
|
||||
if (a->comp_type == GPU_COMP_I10) {
|
||||
return 4; /* always packed as 10_10_10_2 */
|
||||
@@ -128,7 +128,7 @@ uint vertex_buffer_size(const GPUVertFormat *format, uint vertex_len)
|
||||
return format->stride * vertex_len;
|
||||
}
|
||||
|
||||
static const char *copy_attrib_name(GPUVertFormat *format, const char *name, const char *suffix)
|
||||
static const char *copy_attr_name(GPUVertFormat *format, const char *name, const char *suffix)
|
||||
{
|
||||
/* strncpy does 110% of what we need; let's do exactly 100% */
|
||||
char *name_copy = format->names + format->name_offset;
|
||||
@@ -196,37 +196,37 @@ uint GPU_vertformat_attr_add(
|
||||
#endif
|
||||
format->name_len++; /* multiname support */
|
||||
|
||||
const uint attrib_id = format->attr_len++;
|
||||
GPUVertAttr *attrib = format->attribs + attrib_id;
|
||||
const uint attr_id = format->attr_len++;
|
||||
GPUVertAttr *attr = &format->attrs[attr_id];
|
||||
|
||||
attrib->name[attrib->name_len++] = copy_attrib_name(format, name, NULL);
|
||||
attrib->comp_type = comp_type;
|
||||
attrib->gl_comp_type = convert_comp_type_to_gl(comp_type);
|
||||
attrib->comp_len = (comp_type == GPU_COMP_I10) ? 4 : comp_len; /* system needs 10_10_10_2 to be 4 or BGRA */
|
||||
attrib->sz = attrib_sz(attrib);
|
||||
attrib->offset = 0; /* offsets & stride are calculated later (during pack) */
|
||||
attrib->fetch_mode = fetch_mode;
|
||||
attr->name[attr->name_len++] = copy_attr_name(format, name, NULL);
|
||||
attr->comp_type = comp_type;
|
||||
attr->gl_comp_type = convert_comp_type_to_gl(comp_type);
|
||||
attr->comp_len = (comp_type == GPU_COMP_I10) ? 4 : comp_len; /* system needs 10_10_10_2 to be 4 or BGRA */
|
||||
attr->sz = attr_sz(attr);
|
||||
attr->offset = 0; /* offsets & stride are calculated later (during pack) */
|
||||
attr->fetch_mode = fetch_mode;
|
||||
|
||||
return attrib_id;
|
||||
return attr_id;
|
||||
}
|
||||
|
||||
void GPU_vertformat_alias_add(GPUVertFormat *format, const char *alias)
|
||||
{
|
||||
GPUVertAttr *attrib = format->attribs + (format->attr_len - 1);
|
||||
GPUVertAttr *attr = &format->attrs[format->attr_len - 1];
|
||||
#if TRUST_NO_ONE
|
||||
assert(format->name_len < GPU_VERT_ATTR_MAX_LEN); /* there's room for more */
|
||||
assert(attrib->name_len < GPU_VERT_ATTR_MAX_NAMES);
|
||||
assert(attr->name_len < GPU_VERT_ATTR_MAX_NAMES);
|
||||
#endif
|
||||
format->name_len++; /* multiname support */
|
||||
attrib->name[attrib->name_len++] = copy_attrib_name(format, alias, NULL);
|
||||
attr->name[attr->name_len++] = copy_attr_name(format, alias, NULL);
|
||||
}
|
||||
|
||||
int GPU_vertformat_attr_id_get(const GPUVertFormat *format, const char *name)
|
||||
{
|
||||
for (int i = 0; i < format->attr_len; i++) {
|
||||
const GPUVertAttr *attrib = format->attribs + i;
|
||||
for (int j = 0; j < attrib->name_len; j++) {
|
||||
if (STREQ(name, attrib->name[j])) {
|
||||
const GPUVertAttr *attr = &format->attrs[i];
|
||||
for (int j = 0; j < attr->name_len; j++) {
|
||||
if (STREQ(name, attr->name[j])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -246,25 +246,25 @@ void GPU_vertformat_triple_load(GPUVertFormat *format)
|
||||
|
||||
uint old_attr_len = format->attr_len;
|
||||
for (uint a_idx = 0; a_idx < old_attr_len; ++a_idx) {
|
||||
GPUVertAttr *attrib = format->attribs + a_idx;
|
||||
/* Duplicate attrib twice */
|
||||
GPUVertAttr *attr = &format->attrs[a_idx];
|
||||
/* Duplicate attr twice */
|
||||
for (int i = 1; i < 3; ++i) {
|
||||
GPUVertAttr *dst_attrib = format->attribs + format->attr_len;
|
||||
memcpy(dst_attrib, attrib, sizeof(GPUVertAttr));
|
||||
GPUVertAttr *dst_attr = &format->attrs[format->attr_len];
|
||||
memcpy(dst_attr, attr, sizeof(GPUVertAttr));
|
||||
/* Increase offset to the next vertex. */
|
||||
dst_attrib->offset += format->stride * i;
|
||||
dst_attr->offset += format->stride * i;
|
||||
/* Only copy first name for now. */
|
||||
dst_attrib->name_len = 0;
|
||||
dst_attrib->name[dst_attrib->name_len++] = copy_attrib_name(format, attrib->name[0], (i == 1) ? "1" : "2");
|
||||
dst_attr->name_len = 0;
|
||||
dst_attr->name[dst_attr->name_len++] = copy_attr_name(format, attr->name[0], (i == 1) ? "1" : "2");
|
||||
format->attr_len++;
|
||||
}
|
||||
|
||||
#if TRUST_NO_ONE
|
||||
assert(attrib->name_len < GPU_VERT_ATTR_MAX_NAMES);
|
||||
assert(attr->name_len < GPU_VERT_ATTR_MAX_NAMES);
|
||||
#endif
|
||||
/* Add alias to first attrib. */
|
||||
/* Add alias to first attr. */
|
||||
format->name_len++;
|
||||
attrib->name[attrib->name_len++] = copy_attrib_name(format, attrib->name[0], "0");
|
||||
attr->name[attr->name_len++] = copy_attr_name(format, attr->name[0], "0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,14 +290,14 @@ static void show_pack(uint a_idx, uint sz, uint pad)
|
||||
void VertexFormat_pack(GPUVertFormat *format)
|
||||
{
|
||||
/* For now, attributes are packed in the order they were added,
|
||||
* making sure each attrib is naturally aligned (add padding where necessary)
|
||||
* making sure each attribute is naturally aligned (add padding where necessary)
|
||||
* Later we can implement more efficient packing w/ reordering
|
||||
* (keep attrib ID order, adjust their offsets to reorder in buffer). */
|
||||
* (keep attribute ID order, adjust their offsets to reorder in buffer). */
|
||||
|
||||
/* TODO: realloc just enough to hold the final combo string. And just enough to
|
||||
* hold used attribs, not all 16. */
|
||||
* hold used attributes, not all 16. */
|
||||
|
||||
GPUVertAttr *a0 = format->attribs + 0;
|
||||
GPUVertAttr *a0 = &format->attrs[0];
|
||||
a0->offset = 0;
|
||||
uint offset = a0->sz;
|
||||
|
||||
@@ -306,8 +306,8 @@ void VertexFormat_pack(GPUVertFormat *format)
|
||||
#endif
|
||||
|
||||
for (uint a_idx = 1; a_idx < format->attr_len; ++a_idx) {
|
||||
GPUVertAttr *a = format->attribs + a_idx;
|
||||
uint mid_padding = padding(offset, attrib_align(a));
|
||||
GPUVertAttr *a = &format->attrs[a_idx];
|
||||
uint mid_padding = padding(offset, attr_align(a));
|
||||
offset += mid_padding;
|
||||
a->offset = offset;
|
||||
offset += a->sz;
|
||||
@@ -317,7 +317,7 @@ void VertexFormat_pack(GPUVertFormat *format)
|
||||
#endif
|
||||
}
|
||||
|
||||
uint end_padding = padding(offset, attrib_align(a0));
|
||||
uint end_padding = padding(offset, attr_align(a0));
|
||||
|
||||
#if PACK_DEBUG
|
||||
show_pack(0, 0, end_padding);
|
||||
@@ -412,7 +412,7 @@ void GPU_vertformat_from_interface(GPUVertFormat *format, const GPUShaderInterfa
|
||||
const char *name_buffer = shaderface->name_buffer;
|
||||
|
||||
for (int i = 0; i < GPU_NUM_SHADERINTERFACE_BUCKETS; i++) {
|
||||
const GPUShaderInput *input = shaderface->attrib_buckets[i];
|
||||
const GPUShaderInput *input = shaderface->attr_buckets[i];
|
||||
if (input == NULL) {
|
||||
continue;
|
||||
}
|
||||
@@ -425,13 +425,13 @@ void GPU_vertformat_from_interface(GPUVertFormat *format, const GPUShaderInterfa
|
||||
format->name_len++; /* multiname support */
|
||||
format->attr_len++;
|
||||
|
||||
GPUVertAttr *attrib = format->attribs + input->location;
|
||||
GPUVertAttr *attr = &format->attrs[input->location];
|
||||
|
||||
attrib->name[attrib->name_len++] = copy_attrib_name(format, name_buffer + input->name_offset, NULL);
|
||||
attrib->offset = 0; /* offsets & stride are calculated later (during pack) */
|
||||
attrib->comp_len = calc_input_component_size(input);
|
||||
attrib->sz = attrib->comp_len * 4;
|
||||
get_fetch_mode_and_comp_type(input->gl_type, &attrib->comp_type, &attrib->gl_comp_type, &attrib->fetch_mode);
|
||||
attr->name[attr->name_len++] = copy_attr_name(format, name_buffer + input->name_offset, NULL);
|
||||
attr->offset = 0; /* offsets & stride are calculated later (during pack) */
|
||||
attr->comp_len = calc_input_component_size(input);
|
||||
attr->sz = attr->comp_len * 4;
|
||||
get_fetch_mode_and_comp_type(input->gl_type, &attr->comp_type, &attr->gl_comp_type, &attr->fetch_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ in vec2 pos; /* verts position in the curve tangent space */
|
||||
in vec2 expand;
|
||||
|
||||
#ifdef USE_INSTANCE
|
||||
/* Instance attrib */
|
||||
/* Instance attrs. */
|
||||
in vec2 P0;
|
||||
in vec2 P1;
|
||||
in vec2 P2;
|
||||
|
||||
@@ -4,10 +4,10 @@ uniform mat4 ViewProjectionMatrix;
|
||||
uniform mat4 ModelMatrix;
|
||||
#endif
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in float pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in vec3 color;
|
||||
in vec4 corners[2]; /* trouble fetching vec2 */
|
||||
in float depth;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in vec3 color;
|
||||
in float start;
|
||||
in float end;
|
||||
|
||||
@@ -16,7 +16,7 @@ uniform mat4 ProjectionMatrix;
|
||||
in vec3 pos;
|
||||
in vec3 N1, N2; // normals of faces this edge joins (object coords)
|
||||
|
||||
/* instance attrib */
|
||||
/* Instance attrs */
|
||||
in vec3 color;
|
||||
in mat4 InstanceModelMatrix;
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
uniform mat4 ViewMatrix;
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
in vec3 nor;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec4 color;
|
||||
|
||||
@@ -17,7 +17,7 @@ void main()
|
||||
{
|
||||
mat4 ModelViewProjectionMatrix = ViewProjectionMatrix * InstanceModelMatrix;
|
||||
/* This is slow and run per vertex, but it's still faster than
|
||||
* doing it per instance on CPU and sending it on via instance attrib */
|
||||
* doing it per instance on CPU and sending it on via instance attr. */
|
||||
mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
|
||||
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
|
||||
@@ -5,10 +5,10 @@ uniform mat4 ModelMatrix;
|
||||
#endif
|
||||
uniform vec3 screen_vecs[2];
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos; /* using Z as axis id */
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec3 color;
|
||||
in float size;
|
||||
|
||||
@@ -4,10 +4,10 @@ uniform vec3 screen_vecs[2];
|
||||
uniform float size;
|
||||
uniform float pixel_size;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec2 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in vec3 world_pos;
|
||||
in vec3 color;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
uniform mat4 ModelMatrix;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec4 color;
|
||||
#ifdef UNIFORM_SCALE
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
uniform int baseId;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
#ifdef UNIFORM_SCALE
|
||||
in float size;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
|
||||
/* ---- Instantiated Attribs ---- */
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
/* ---- Per instance Attrs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
|
||||
void main()
|
||||
|
||||
@@ -3,7 +3,7 @@ uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 ModelViewMatrixInverse;
|
||||
uniform mat3 NormalMatrix;
|
||||
|
||||
#ifndef ATTRIB
|
||||
#ifndef USE_ATTR
|
||||
uniform mat4 ModelMatrix;
|
||||
uniform mat4 ModelMatrixInverse;
|
||||
#endif
|
||||
|
||||
@@ -101,7 +101,7 @@ static bool bpygpu_vertbuf_fill_impl(
|
||||
const char *exc_str_size_mismatch = "Expected a %s of size %d, got %u";
|
||||
|
||||
bool ok = true;
|
||||
const GPUVertAttr *attr = &vbo->format.attribs[data_id];
|
||||
const GPUVertAttr *attr = &vbo->format.attrs[data_id];
|
||||
|
||||
if (PyObject_CheckBuffer(seq)) {
|
||||
Py_buffer pybuffer;
|
||||
|
||||
Reference in New Issue
Block a user