Merge branch 'master' into blender2.8

Conflicts:
	source/blender/editors/sculpt_paint/paint_image.c
	source/blender/editors/space_view3d/view3d_draw.c
	source/blender/editors/space_view3d/view3d_view.c
	source/blender/gpu/GPU_draw.h
	source/blender/gpu/GPU_material.h
	source/blender/gpu/intern/gpu_draw.c
	source/blender/gpu/intern/gpu_material.c
	source/blender/makesrna/intern/rna_userdef.c
	source/blender/windowmanager/intern/wm_files_link.c
	source/blender/windowmanager/intern/wm_init_exit.c
	source/creator/creator_args.c
	source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
	source/gameengine/Ketsji/KX_PythonInit.cpp
	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
This commit is contained in:
Bastien Montagne 2018-06-25 12:50:32 +02:00
commit e97237892c
15 changed files with 70 additions and 57 deletions

View File

@ -1433,7 +1433,7 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph)
Render *render = engine->re;
if (G.background && DST.gl_context == NULL) {
WM_init_opengl();
WM_init_opengl(G_MAIN);
}
void *re_gl_context = RE_gl_context_get(render);

View File

@ -1054,6 +1054,7 @@ static int texture_paint_toggle_poll(bContext *C)
static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
{
struct wmMsgBus *mbus = CTX_wm_message_bus(C);
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
const int mode_flag = OB_MODE_TEXTURE_PAINT;
@ -1069,14 +1070,13 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
ob->mode &= ~mode_flag;
if (U.glreslimit != 0)
GPU_free_images();
GPU_paint_set_mipmap(1);
GPU_free_images(bmain);
GPU_paint_set_mipmap(bmain, 1);
toggle_paint_cursor(C, 0);
}
else {
bScreen *sc;
Main *bmain = CTX_data_main(C);
Image *ima = NULL;
ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
@ -1121,8 +1121,8 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
BKE_paint_init(bmain, scene, ePaintTextureProjective, PAINT_CURSOR_TEXTURE_PAINT);
if (U.glreslimit != 0)
GPU_free_images();
GPU_paint_set_mipmap(0);
GPU_free_images(bmain);
GPU_paint_set_mipmap(bmain, 0);
toggle_paint_cursor(C, 1);
}

View File

@ -542,7 +542,7 @@ static int outliner_id_remap_exec(bContext *C, wmOperator *op)
DEG_relations_tag_update(bmain);
/* free gpu materials, some materials depend on existing objects, such as lamps so freeing correctly refreshes */
GPU_materials_free();
GPU_materials_free(bmain);
WM_event_add_notifier(C, NC_WINDOW, NULL);

View File

@ -44,6 +44,7 @@
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_key.h"
#include "BKE_main.h"
#include "BKE_scene.h"
#include "BKE_object.h"
#include "BKE_paint.h"
@ -1196,8 +1197,6 @@ void view3d_draw_region_info(const bContext *C, ARegion *ar, const int offset)
rcti rect;
ED_region_visible_rect(ar, &rect);
/* Leave room for previously drawn info. */
rect.ymax -= offset;
view3d_draw_border(C, ar);
view3d_draw_grease_pencil(C);
@ -1271,11 +1270,12 @@ RenderEngineType *ED_view3d_engine_type(Scene *scene, int drawtype)
void view3d_main_region_draw(const bContext *C, ARegion *ar)
{
Main *bmain = CTX_data_main(C);
View3D *v3d = CTX_wm_view3d(C);
view3d_draw_view(C, ar);
GPU_free_images_old();
GPU_free_images_old(bmain);
GPU_pass_cache_garbage_collect();
/* XXX This is in order to draw UI batches with the DRW
@ -1348,7 +1348,7 @@ void ED_view3d_draw_offscreen(
if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
/* free images which can have changed on frame-change
* warning! can be slow so only free animated images - campbell */
GPU_free_images_anim();
GPU_free_images_anim(G.main); /* XXX :((( */
}
gpuPushProjectionMatrix();

View File

@ -81,7 +81,7 @@ public:
bool ok = BPY_execute_filepath(_context, fn, reports);
#else
bool ok;
Text *text = BKE_text_load(&_freestyle_bmain, fn, G.main->name);
Text *text = BKE_text_load(&_freestyle_bmain, fn, G_MAIN->name);
if (text) {
ok = BPY_execute_text(_context, text, reports, false);
BKE_libblock_delete(&_freestyle_bmain, text);

View File

@ -39,6 +39,7 @@ extern "C" {
struct ImBuf;
struct Image;
struct ImageUser;
struct Main;
struct Object;
struct Scene;
struct ViewLayer;
@ -68,19 +69,19 @@ void GPU_disable_program_point_size(void);
/* Mipmap settings
* - these will free textures on changes */
void GPU_set_mipmap(bool mipmap);
void GPU_set_mipmap(struct Main *bmain, bool mipmap);
bool GPU_get_mipmap(void);
void GPU_set_linear_mipmap(bool linear);
bool GPU_get_linear_mipmap(void);
void GPU_paint_set_mipmap(bool mipmap);
void GPU_paint_set_mipmap(struct Main *bmain, bool mipmap);
/* Anisotropic filtering settings
* - these will free textures on changes */
void GPU_set_anisotropic(float value);
void GPU_set_anisotropic(struct Main *bmain, float value);
float GPU_get_anisotropic(void);
/* enable gpu mipmapping */
void GPU_set_gpu_mipmapping(int gpu_mipmap);
void GPU_set_gpu_mipmapping(struct Main *bmain, int gpu_mipmap);
/* Image updates and free
* - these deal with images bound as opengl textures */
@ -94,16 +95,16 @@ void GPU_create_gl_tex_compressed(
int textarget, struct Image *ima, struct ImBuf *ibuf);
bool GPU_upload_dxt_texture(struct ImBuf *ibuf);
void GPU_free_image(struct Image *ima);
void GPU_free_images(void);
void GPU_free_images_anim(void);
void GPU_free_images_old(void);
void GPU_free_images(struct Main *bmain);
void GPU_free_images_anim(struct Main *bmain);
void GPU_free_images_old(struct Main *bmain);
/* smoke drawing functions */
void GPU_free_smoke(struct SmokeModifierData *smd);
void GPU_create_smoke(struct SmokeModifierData *smd, int highres);
/* Delayed free of OpenGL buffers by main thread */
void GPU_free_unused_buffers(void);
void GPU_free_unused_buffers(struct Main *bmain);
/* utilities */
void GPU_select_index_set(int index);

View File

@ -44,6 +44,7 @@ extern "C" {
struct Image;
struct ImageUser;
struct ListBase;
struct Main;
struct Material;
struct Object;
struct Scene;
@ -251,7 +252,7 @@ GPUMaterial *GPU_material_from_nodetree(
void GPU_material_compile(GPUMaterial *mat);
void GPU_material_free(struct ListBase *gpumaterial);
void GPU_materials_free(void);
void GPU_materials_free(struct Main *bmain);
void GPU_material_orphans_init(void);
void GPU_material_orphans_exit(void);

View File

@ -140,7 +140,7 @@ static struct GPUTextureState {
/* Mipmap settings */
void GPU_set_gpu_mipmapping(int gpu_mipmap)
void GPU_set_gpu_mipmapping(Main *bmain, int gpu_mipmap)
{
int old_value = GTS.gpu_mipmap;
@ -148,14 +148,14 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap)
GTS.gpu_mipmap = gpu_mipmap;
if (old_value != GTS.gpu_mipmap) {
GPU_free_images();
GPU_free_images(bmain);
}
}
void GPU_set_mipmap(bool mipmap)
void GPU_set_mipmap(Main *bmain, bool mipmap)
{
if (GTS.domipmap != mipmap) {
GPU_free_images();
GPU_free_images(bmain);
GTS.domipmap = mipmap;
}
}
@ -203,10 +203,10 @@ static GLenum gpu_get_mipmap_filter(bool mag)
}
/* Anisotropic filtering settings */
void GPU_set_anisotropic(float value)
void GPU_set_anisotropic(Main *bmain, float value)
{
if (GTS.anisotropic != value) {
GPU_free_images();
GPU_free_images(bmain);
/* Clamp value to the maximum value the graphics card supports */
const float max = GPU_max_texture_anisotropy();
@ -682,7 +682,7 @@ void GPU_create_gl_tex_compressed(
* temporary disabling/enabling mipmapping on all images for quick texture
* updates with glTexSubImage2D. images that didn't change don't have to be
* re-uploaded to OpenGL */
void GPU_paint_set_mipmap(bool mipmap)
void GPU_paint_set_mipmap(Main *bmain, bool mipmap)
{
if (!GTS.domipmap)
return;
@ -690,7 +690,7 @@ void GPU_paint_set_mipmap(bool mipmap)
GTS.texpaint = !mipmap;
if (mipmap) {
for (Image *ima = G.main->image.first; ima; ima = ima->id.next) {
for (Image *ima = bmain->image.first; ima; ima = ima->id.next) {
if (BKE_image_has_opengl_texture(ima)) {
if (ima->tpageflag & IMA_MIPMAP_COMPLETE) {
if (ima->gputexture[TEXTARGET_TEXTURE_2D]) {
@ -709,7 +709,7 @@ void GPU_paint_set_mipmap(bool mipmap)
}
else {
for (Image *ima = G.main->image.first; ima; ima = ima->id.next) {
for (Image *ima = bmain->image.first; ima; ima = ima->id.next) {
if (BKE_image_has_opengl_texture(ima)) {
if (ima->gputexture[TEXTARGET_TEXTURE_2D]) {
GPU_texture_bind(ima->gputexture[TEXTARGET_TEXTURE_2D], 0);
@ -980,7 +980,7 @@ static void gpu_queue_image_for_free(Image *ima)
BLI_thread_unlock(LOCK_OPENGL);
}
void GPU_free_unused_buffers(void)
void GPU_free_unused_buffers(Main *bmain)
{
if (!BLI_thread_is_main())
return;
@ -992,7 +992,7 @@ void GPU_free_unused_buffers(void)
Image *ima = node->link;
/* check in case it was freed in the meantime */
if (G.main && BLI_findindex(&G.main->image, ima) != -1)
if (bmain && BLI_findindex(&bmain->image, ima) != -1)
GPU_free_image(ima);
}
@ -1020,24 +1020,29 @@ void GPU_free_image(Image *ima)
ima->tpageflag &= ~(IMA_MIPMAP_COMPLETE | IMA_GLBIND_IS_DATA);
}
void GPU_free_images(void)
void GPU_free_images(Main *bmain)
{
if (G.main)
for (Image *ima = G.main->image.first; ima; ima = ima->id.next)
if (bmain) {
for (Image *ima = bmain->image.first; ima; ima = ima->id.next) {
GPU_free_image(ima);
}
}
}
/* same as above but only free animated images */
void GPU_free_images_anim(void)
void GPU_free_images_anim(Main *bmain)
{
if (G.main)
for (Image *ima = G.main->image.first; ima; ima = ima->id.next)
if (BKE_image_is_animated(ima))
if (bmain) {
for (Image *ima = bmain->image.first; ima; ima = ima->id.next) {
if (BKE_image_is_animated(ima)) {
GPU_free_image(ima);
}
}
}
}
void GPU_free_images_old(void)
void GPU_free_images_old(Main *bmain)
{
static int lasttime = 0;
int ctime = (int)PIL_check_seconds_timer();
@ -1055,7 +1060,7 @@ void GPU_free_images_old(void)
lasttime = ctime;
Image *ima = G.main->image.first;
Image *ima = bmain->image.first;
while (ima) {
if ((ima->flag & IMA_NOCOLLECT) == 0 && ctime - ima->lastused > U.textimeout) {
/* If it's in GL memory, deallocate and set time tag to current time

View File

@ -723,16 +723,16 @@ void GPU_material_compile(GPUMaterial *mat)
}
}
void GPU_materials_free(void)
void GPU_materials_free(Main *bmain)
{
Material *ma;
World *wo;
extern Material defmaterial;
for (ma = G.main->mat.first; ma; ma = ma->id.next)
for (ma = bmain->mat.first; ma; ma = ma->id.next)
GPU_material_free(&ma->gpumaterial);
for (wo = G.main->world.first; wo; wo = wo->id.next)
for (wo = bmain->world.first; wo; wo = wo->id.next)
GPU_material_free(&wo->gpumaterial);
GPU_material_free(&defmaterial.gpumaterial);

View File

@ -216,25 +216,25 @@ static void rna_userdef_load_ui_update(Main *UNUSED(bmain), Scene *UNUSED(scene)
static void rna_userdef_anisotropic_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
GPU_set_anisotropic(U.anisotropic_filter);
GPU_set_anisotropic(bmain, U.anisotropic_filter);
rna_userdef_update(bmain, scene, ptr);
}
static void rna_userdef_gl_gpu_mipmaps(Main *bmain, Scene *scene, PointerRNA *ptr)
{
GPU_set_gpu_mipmapping(U.use_gpu_mipmap);
GPU_set_gpu_mipmapping(bmain, U.use_gpu_mipmap);
rna_userdef_update(bmain, scene, ptr);
}
static void rna_userdef_gl_texture_limit_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
GPU_free_images();
GPU_free_images(bmain);
rna_userdef_update(bmain, scene, ptr);
}
static void rna_userdef_gl_use_16bit_textures(Main *bmain, Scene *scene, PointerRNA *ptr)
{
GPU_free_images();
GPU_free_images(bmain);
rna_userdef_update(bmain, scene, ptr);
}

View File

@ -280,7 +280,10 @@ void ntreeCompositTagRender(Scene *curscene)
{
Scene *sce;
for (sce = G.main->scene.first; sce; sce = sce->id.next) {
/* XXX Think using G_MAIN here is valid, since you want to update current file's scene nodes,
* not the ones in temp main generated for rendering?
* This is still rather weak though, ideally render struct would store own main AND original G_MAIN... */
for (sce = G_MAIN->scene.first; sce; sce = sce->id.next) {
if (sce->nodetree) {
bNode *node;

View File

@ -163,6 +163,8 @@ bNodeTreeExec *ntree_exec_begin(bNodeExecContext *context, bNodeTree *ntree, bNo
/* XXX texnodes have threading issues with muting, have to disable it there ... */
/* ensure all sock->link pointers and node levels are correct */
/* Using global main here is likely totally wrong, not sure what to do about that one though...
* We cannot even check ntree is in global main, since most of the time it won't be (thanks to ntree design)!!! */
ntreeUpdateTree(G.main, ntree);
/* get a dependency-sorted list of nodes */

View File

@ -96,7 +96,7 @@ void WM_main (struct bContext *C) ATTR_NORETURN;
void WM_init_splash (struct bContext *C);
void WM_init_opengl (void);
void WM_init_opengl (struct Main *bmain);
void WM_check (struct bContext *C);

View File

@ -782,6 +782,7 @@ void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *UNUSED(ar))
void wm_draw_update(bContext *C)
{
Main *bmain = CTX_data_main(C);
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win;
@ -789,7 +790,7 @@ void wm_draw_update(bContext *C)
BKE_subsurf_free_unused_buffers();
#endif
GPU_free_unused_buffers();
GPU_free_unused_buffers(bmain);
for (win = wm->windows.first; win; win = win->next) {
#ifdef WIN32

View File

@ -167,7 +167,7 @@ bool wm_start_with_console = false; /* used in creator.c */
**/
static bool opengl_is_init = false;
void WM_init_opengl(void)
void WM_init_opengl(Main *bmain)
{
/* must be called only once */
BLI_assert(opengl_is_init == false);
@ -181,10 +181,10 @@ void WM_init_opengl(void)
DRW_opengl_context_create();
GPU_init();
GPU_set_mipmap(true);
GPU_set_mipmap(bmain, true);
GPU_set_linear_mipmap(true);
GPU_set_anisotropic(U.anisotropic_filter);
GPU_set_gpu_mipmapping(U.use_gpu_mipmap);
GPU_set_anisotropic(bmain, U.anisotropic_filter);
GPU_set_gpu_mipmapping(bmain, U.use_gpu_mipmap);
GPU_pass_cache_init();
@ -250,7 +250,7 @@ void WM_init(bContext *C, int argc, const char **argv)
/* sets 3D mouse deadzone */
WM_ndof_deadzone_set(U.ndof_deadzone);
#endif
WM_init_opengl();
WM_init_opengl(G_MAIN);
UI_init();
BKE_studiolight_init();
@ -491,7 +491,7 @@ void WM_exit_ext(bContext *C, const bool do_python)
BKE_subsurf_osd_cleanup();
#endif
GPU_free_unused_buffers();
GPU_free_unused_buffers(G_MAIN);
GPU_exit();
}