Page MenuHome

Blender 2.8: OpenGL: replace old GL with the new immediate API in UI_draw_roundbox_gl_mode
ClosedPublic

Authored by Krantz Geoffroy (kgeogeo) on Oct 5 2016, 9:42 PM.

Details

Summary

I change UI_draw_roundbox_gl_mode to use immediate API.
The rest of the change is the call to the function.
I also make some change in UI_ThemeColor4(int colorid) for eg to make convenience to use.
I would really like to know if it's the good way to do, if yes I will make all the change in the node_daw.c after, else say me what's wrong and how to deal with color else.

Diff Detail

Event Timeline

Krantz Geoffroy (kgeogeo) retitled this revision from to Blender 2.8: OpenGL: replace old GL with the new immediate API in UI_draw_roundbox_gl_mode.
Krantz Geoffroy (kgeogeo) updated this object.

Thanks! Here are some notes:

source/blender/editors/interface/interface_draw.c
99

Yes!

104

Since color is set once for the whole roundbox, we can use GPU_SHADER_2D_UNIFORM_COLOR!

Color values still need to be passed into the function like you did. Just call immUniformColor4ubv right after binding the shader program.

1523

Suggestion:

const unsigned char color[4] = { ... };
UI_draw_roundbox_gl_mode( ... , color);
source/blender/editors/interface/resources.c
1265

Leave UI_ThemeColor functions alone for now. Lots of drawing code uses these!

Use existing UI_GetThemeColor functions to fetch color values (you might need to add one or two missing functions).

source/blender/gpu/gawain/immediate.c
567

Function owns the returned memory, so lifetime is ok... but the values are only good for a very short (undetermined) time. Calling again in the same thread or a different thread trashes the data.

I don't think we don't need this function.

@Krantz Geoffroy (kgeogeo) I added your name on the task list so other people will know that you're working here. You can mark it as "done" later, and claim new files / functions before starting more work.

Krantz Geoffroy (kgeogeo) marked 2 inline comments as done.Oct 5 2016, 11:19 PM

Thanks for your quick reply, it's motivating.

source/blender/editors/interface/resources.c
1265

No part of blender use the return of this function, it can still be a problem??

As you say it's used a lot of time, that why i make it, it's and will be a lot easier to make all the modification with this.
Do you have any plan to do something similar?

But you know it better than me for sure, I hope.... :-))))))

Julian Eisel (Severin) added inline comments.
source/blender/editors/interface/interface_draw.c
103

Not sure why 72? I only count 32 vertices.

source/blender/editors/interface/resources.c
1265

I'd prefer to get rid of the UI_ThemeColorXXX functions and only keep the UI_GetThemeColorXXX ones. I guess after 3.2 core profile transition they'll be useless anyway since it doesn't use color states (right?).

Julian Eisel (Severin) requested changes to this revision.Oct 5 2016, 11:33 PM
Julian Eisel (Severin) added inline comments.
source/blender/editors/interface/interface_draw.c
103

Eeeh, *36 :)

This revision now requires changes to proceed.Oct 5 2016, 11:33 PM
source/blender/editors/interface/resources.c
1265

Hmm, good points... All this makes me start thinking about a better API for using theme colors! But that's not really part of the immediate mode task.

UI_ThemeColor updates current OpenGL state to use a theme color. With your change it does that *and* returns a convenient pointer.

I still prefer the UI_GetThemeColor functions for this, since you are just getting a color. Yes it's less convenient to call. But it's not that bad.

source/blender/editors/interface/interface_draw.c
103

euh, not sure, we declare the vertex count or coordinate count??
36 vertex but 72 coordinate

source/blender/editors/interface/resources.c
1265

it's was me idee too, when 3.2 core will be activated we only delete glColor4ubv(cp); for eg. no?

source/blender/editors/interface/interface_draw.c
103

@Julian Eisel (Severin) is trying to crash us! I count 36 too.

source/blender/editors/interface/resources.c
1265

they'll be useless anyway since it doesn't use color states

Right, those functions will be obsolete. After that maybe we can redo the theme color API.

source/blender/editors/interface/interface_draw.c
103

I try it and you're right... I've made the change.
thanks

source/blender/editors/interface/interface_draw.c
103

vertex count or coordinate count?

Yep it's vertex count. Doesn't matter if coordinates are 2D or 3D. Also doesn't matter how many attributes each vertex has. I'll remember to explain this better in the docs.

source/blender/editors/interface/interface_draw.c
587

OK, I think I see what you mean (I hope ;-)))) )

unsigned char color[4];
UI_GetThemeColor4ubv(TH_PREVIEW_BACK, color)

UI_draw_roundbox_corner_set(UI_CNR_ALL);
UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f, color);

it would be good, that's what you mean/want??

if yes I have to make UI_GetThemeColorShade4ubv too for eg??

source/blender/editors/interface/interface_draw.c
587

Yes to all of that :)

Krantz Geoffroy (kgeogeo) marked 7 inline comments as done.Oct 6 2016, 9:09 AM
Krantz Geoffroy (kgeogeo) edited edge metadata.

I this it's done...

Julian Eisel (Severin) requested changes to this revision.Oct 6 2016, 10:28 AM
Julian Eisel (Severin) edited edge metadata.

Almost willing to accept this, just one thing that annoys me a bit ;) Added inline comment

source/blender/editors/animation/anim_channels_defines.c
125

It's a bit ugly to have float->uchar conversions everywhere, I'd suggest you solve this a bit differently:

  • Replace UI_draw_roundbox_gl_mode with the two variations, UI_draw_roundbox_gl_mode_uchar and UI_draw_roundbox_gl_mode_fl.
  • UI_draw_roundbox_gl_mode_uchar would do nothing but calling rgba_uchar_to_float and then UI_draw_roundbox_gl_mode_fl (The immediate mode shader works with floats, so to avoid float->uchar->float conversions, it's better to pass floats directly - this requires you to add immUniformColor4fl though).
  • Take the alpha value as extra argument, so you can pass a float/char [3] and the alpha value separately.

Here, the call would simplify to this then:

float color[3];
... /* fill color array */
UI_draw_roundbox_gl_mode_fl(..., color, 1.0f);
This revision now requires changes to proceed.Oct 6 2016, 10:28 AM

Almost done

source/blender/editors/animation/anim_channels_defines.c
125

I disagree here. Why should a roundbox drawing function have two or more interfaces? I think it should just take byte[4] colors (like now) or just float[4] colors and callers have to deal with it.

Looks like float colors are used more often so can we use that?

UI_GetThemeColorShade4fv already exists. Keep the new UI_GetThemeColorShade4ubv because it is useful.

I'll add immUniformColor4fv in a minute, so "git stash" then "git pull --rebase" then "git stash pop".

Sorry for the extra work @Krantz Geoffroy (kgeogeo) -- we're almost there!

@Krantz Geoffroy (kgeogeo) may I suggest you tackling ui_panel_category_draw_tab in interface_panel.c next? it's based on this code.

Mike Erwin (merwin) edited edge metadata.

One more tiny fix then this is ready

source/blender/editors/interface/interface_draw.c
1791–1792

100/255 = 0.392... change 0.3 to 0.4 alpha

sorry git not up to date

Voilà!!! for sur now :-)))

Oops, today I pushed a change to view3d_draw.c so "arc patch" failed. Please rebase and update this patch, then I will land it.

There might be a simple way to do all this but I don't know arcanist well.

should work for you now!!

Mike Erwin (merwin) edited edge metadata.

Landed in blender2.8! I thought that would auto-close this diff...

Thanks @Krantz Geoffroy (kgeogeo) for your contribution so far.

@Julian Eisel (Severin) please accept & close this revision.

thanks for your help!!
I will try to make the panel stuff now

Julian Eisel (Severin) edited edge metadata.
This revision is now accepted and ready to land.Oct 7 2016, 9:47 PM