Draw Manager: Changed buffer uniform api.

Use a reference to where will the texture be instead of an index.
This commit is contained in:
Clément Foucault 2017-03-02 22:55:54 +01:00
parent 0c1c646118
commit bb8a172dfb
3 changed files with 16 additions and 21 deletions

View File

@ -117,13 +117,6 @@ typedef struct CLAY_TextureList {
struct GPUTexture *depth_dup;
} CLAY_TextureList;
/* for clarity follow the same layout as CLAY_TextureList */
enum {
SCENE_COLOR,
SCENE_DEPTH,
SCENE_DEPTH_DUP,
};
/* keep it under MAX_PASSES */
typedef struct CLAY_PassList {
struct DRWPass *depth_pass;
@ -438,9 +431,10 @@ static DRWShadingGroup *CLAY_shgroup_create(DRWPass *pass, int *material_id)
const int depthloc = 0, matcaploc = 1, jitterloc = 2, sampleloc = 3;
DRWShadingGroup *grp = DRW_shgroup_create(data.clay_sh, pass);
CLAY_TextureList *txl = DRW_engine_texture_list_get();
DRW_shgroup_uniform_vec2(grp, "screenres", DRW_viewport_size_get(), 1);
DRW_shgroup_uniform_buffer(grp, "depthtex", SCENE_DEPTH_DUP, depthloc);
DRW_shgroup_uniform_buffer(grp, "depthtex", &txl->depth_dup, depthloc);
DRW_shgroup_uniform_texture(grp, "matcaps", data.matcap_array, matcaploc);
DRW_shgroup_uniform_mat4(grp, "WinMatrix", (float *)data.winmat);
DRW_shgroup_uniform_vec4(grp, "viewvecs", (float *)data.viewvecs, 3);

View File

@ -173,7 +173,7 @@ void DRW_shgroup_attrib_float(DRWShadingGroup *shgroup, const char *name, int si
void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const struct GPUTexture *tex, int loc);
void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const struct GPUUniformBuffer *ubo, int loc);
void DRW_shgroup_uniform_buffer(DRWShadingGroup *shgroup, const char *name, const int value, int loc);
void DRW_shgroup_uniform_buffer(DRWShadingGroup *shgroup, const char *name, struct GPUTexture **tex, int loc);
void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const bool *value, int arraysize);
void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
void DRW_shgroup_uniform_vec2(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);

View File

@ -526,10 +526,9 @@ void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const
DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BLOCK, ubo, 0, 0, loc);
}
void DRW_shgroup_uniform_buffer(DRWShadingGroup *shgroup, const char *name, const int value, int loc)
void DRW_shgroup_uniform_buffer(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex, int loc)
{
/* we abuse the lenght attrib to store the buffer index */
DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BUFFER, NULL, value, 0, loc);
DRW_interface_uniform(shgroup, name, DRW_UNIFORM_BUFFER, tex, 0, 0, loc);
}
void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const bool *value, int arraysize)
@ -829,6 +828,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup)
BLI_assert(shgroup->interface);
DRWInterface *interface = shgroup->interface;
GPUTexture *tex;
if (DST.shader != shgroup->shader) {
if (DST.shader) GPU_shader_unbind();
@ -858,25 +858,26 @@ static void draw_shgroup(DRWShadingGroup *shgroup)
GPU_shader_uniform_vector(shgroup->shader, uni->location, uni->length, uni->arraysize, (float *)uni->value);
break;
case DRW_UNIFORM_TEXTURE:
GPU_texture_bind((GPUTexture *)uni->value, uni->bindloc);
tex = (GPUTexture *)uni->value;
GPU_texture_bind(tex, uni->bindloc);
bound_tex = MEM_callocN(sizeof(DRWBoundTexture), "DRWBoundTexture");
bound_tex->tex = (GPUTexture *)uni->value;
bound_tex->tex = tex;
BLI_addtail(&DST.bound_texs, bound_tex);
GPU_shader_uniform_texture(shgroup->shader, uni->location, (GPUTexture *)uni->value);
GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
break;
case DRW_UNIFORM_BUFFER:
/* restore index from lenght we abused */
GPU_texture_bind(DST.txl->textures[uni->length], uni->bindloc);
GPU_texture_compare_mode(DST.txl->textures[uni->length], false);
GPU_texture_filter_mode(DST.txl->textures[uni->length], false);
tex = *((GPUTexture **)uni->value);
GPU_texture_bind(tex, uni->bindloc);
GPU_texture_compare_mode(tex, false);
GPU_texture_filter_mode(tex, false);
bound_tex = MEM_callocN(sizeof(DRWBoundTexture), "DRWBoundTexture");
bound_tex->tex = DST.txl->textures[uni->length];
bound_tex->tex = tex;
BLI_addtail(&DST.bound_texs, bound_tex);
GPU_shader_uniform_texture(shgroup->shader, uni->location, DST.txl->textures[uni->length]);
GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
break;
case DRW_UNIFORM_BLOCK:
GPU_uniformbuffer_bind((GPUUniformBuffer *)uni->value, uni->bindloc);