Commit: 771f73b6bedbdd1c1e2993bd8d3680d53fa67b7c Author: Alexander Romanov Date: Wed Jan 27 12:06:57 2016 +0300 Branches: master https://developer.blender.org/rB771f73b6bedbdd1c1e2993bd8d3680d53fa67b7c
World textures displaying for viewport in BI. This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport. It supports: - "View", "AngMap" and "Equirectangular" types of mapping. - Different types of texture blending (according to BI world render). - Same color blending as when it lacked textures (but render via glsl). {F207734} {F207735} Example: {F275180} Original author: @valentin_b4w Regards, Alexander (Blend4Web Team). Reviewers: sergey, valentin_b4w, brecht, merwin Reviewed By: merwin Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin Projects: #rendering, #opengl_gfx, #bf_blender:_next Differential Revision: https://developer.blender.org/D1414 =================================================================== M source/blender/blenkernel/BKE_image.h M source/blender/blenkernel/intern/image.c M source/blender/blenloader/intern/readfile.c M source/blender/editors/space_view3d/drawmesh.c M source/blender/editors/space_view3d/view3d_draw.c M source/blender/gpu/GPU_draw.h M source/blender/gpu/GPU_extensions.h M source/blender/gpu/GPU_material.h M source/blender/gpu/GPU_texture.h M source/blender/gpu/intern/gpu_codegen.c M source/blender/gpu/intern/gpu_codegen.h M source/blender/gpu/intern/gpu_draw.c M source/blender/gpu/intern/gpu_extensions.c M source/blender/gpu/intern/gpu_material.c M source/blender/gpu/intern/gpu_texture.c M source/blender/gpu/shaders/gpu_shader_material.glsl M source/blender/makesdna/DNA_image_types.h M source/blender/makesrna/intern/rna_image_api.c M source/blender/python/intern/gpu.c M source/gameengine/Ketsji/BL_Texture.cpp M source/gameengine/VideoTexture/Texture.cpp =================================================================== diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 1d4a405..aec5b0a 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -259,6 +259,9 @@ bool BKE_image_scale(struct Image *image, int width, int height); /* check if texture has alpha (depth=32) */ bool BKE_image_has_alpha(struct Image *image); +/* check if texture has gpu texture code */ +bool BKE_image_has_bindcode(struct Image *ima); + void BKE_image_get_size(struct Image *image, struct ImageUser *iuser, int *width, int *height); void BKE_image_get_size_fl(struct Image *image, struct ImageUser *iuser, float size[2]); void BKE_image_get_aspect(struct Image *image, float *aspx, float *aspy); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 7c40674..d48b455 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -657,6 +657,18 @@ bool BKE_image_scale(Image *image, int width, int height) return (ibuf != NULL); } +bool BKE_image_has_bindcode(Image *ima) +{ + bool has_bindcode = false; + for (int i = 0; i < TEXTARGET_COUNT; i++) { + if (ima->bindcode[i]) { + has_bindcode = true; + break; + } + } + return has_bindcode; +} + static void image_init_color_management(Image *ima) { ImBuf *ibuf; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 8899af1..b8470b1 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1565,8 +1565,9 @@ void blo_make_image_pointer_map(FileData *fd, Main *oldmain) for (; ima; ima = ima->id.next) { if (ima->cache) oldnewmap_insert(fd->imamap, ima->cache, ima->cache, 0); - if (ima->gputexture) - oldnewmap_insert(fd->imamap, ima->gputexture, ima->gputexture, 0); + for (a = 0; a < TEXTARGET_COUNT; a++) + if (ima->gputexture[a]) + oldnewmap_insert(fd->imamap, ima->gputexture[a], ima->gputexture[a], 0); if (ima->rr) oldnewmap_insert(fd->imamap, ima->rr, ima->rr, 0); for (a=0; a < IMA_MAX_RENDER_SLOT; a++) @@ -1602,15 +1603,18 @@ void blo_end_image_pointer_map(FileData *fd, Main *oldmain) for (; ima; ima = ima->id.next) { ima->cache = newimaadr(fd, ima->cache); if (ima->cache == NULL) { - ima->bindcode = 0; ima->tpageflag &= ~IMA_GLBIND_IS_DATA; - ima->gputexture = NULL; + for (i = 0; i < TEXTARGET_COUNT; i++) { + ima->bindcode[i] = 0; + ima->gputexture[i] = NULL; + } ima->rr = NULL; } for (i = 0; i < IMA_MAX_RENDER_SLOT; i++) ima->renders[i] = newimaadr(fd, ima->renders[i]); - ima->gputexture = newimaadr(fd, ima->gputexture); + for (i = 0; i < TEXTARGET_COUNT; i++) + ima->gputexture[i] = newimaadr(fd, ima->gputexture[i]); ima->rr = newimaadr(fd, ima->rr); } for (; sce; sce = sce->id.next) { @@ -3644,9 +3648,11 @@ static void direct_link_image(FileData *fd, Image *ima) /* if not restored, we keep the binded opengl index */ if (!ima->cache) { - ima->bindcode = 0; ima->tpageflag &= ~IMA_GLBIND_IS_DATA; - ima->gputexture = NULL; + for (int i = 0; i < TEXTARGET_COUNT; i++) { + ima->bindcode[i] = 0; + ima->gputexture[i] = NULL; + } ima->rr = NULL; } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 8deabfb..11ba6fb 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -318,7 +318,7 @@ static bool set_draw_settings_cached(int clearcache, MTexPoly *texface, Material if (textured) { if (texpaint) { c_badtex = false; - if (GPU_verify_image(ima, NULL, 0, 1, 0, false)) { + if (GPU_verify_image(ima, NULL, GL_TEXTURE_2D, 0, 1, 0, false)) { glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); @@ -337,7 +337,7 @@ static bool set_draw_settings_cached(int clearcache, MTexPoly *texface, Material glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS); - glBindTexture(GL_TEXTURE_2D, ima->bindcode); + glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]); glActiveTexture(GL_TEXTURE0); } else { @@ -465,7 +465,7 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O /* load the stencil texture here */ if (Gtexdraw.stencil != NULL) { glActiveTexture(GL_TEXTURE2); - if (GPU_verify_image(Gtexdraw.stencil, NULL, false, false, false, false)) { + if (GPU_verify_image(Gtexdraw.stencil, NULL, GL_TEXTURE_2D, false, false, false, false)) { float col[4] = {imapaint->stencil_col[0], imapaint->stencil_col[1], imapaint->stencil_col[2], 1.0f}; glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); @@ -1046,7 +1046,7 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs) if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node, NULL)) { /* get openl texture */ int mipmap = 1; - int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap, false) : 0; + int bindcode = (ima) ? GPU_verify_image(ima, iuser, GL_TEXTURE_2D, 0, 0, mipmap, false) : 0; if (bindcode) { NodeTexBase *texbase = node->storage; @@ -1055,7 +1055,7 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs) GPU_object_material_unbind(); /* bind texture */ - glBindTexture(GL_TEXTURE_2D, ima->bindcode); + glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]); glMatrixMode(GL_TEXTURE); glLoadMatrixf(texbase->tex_mapping.mat); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index c37d90b..adffcb6 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -99,6 +99,7 @@ #include "GPU_framebuffer.h" #include "GPU_material.h" #include "GPU_compositing.h" +#include "GPU_extensions.h" #include "view3d_intern.h" /* own include */ @@ -2971,8 +2972,7 @@ void ED_view3d_draw_offscreen_init(Scene *scene, View3D *v3d) static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) { if (scene->world && (v3d->flag3 & V3D_SHOW_WORLD)) { - bool glsl = BKE_scene_use_new_shading_nodes(scene) && scene->world->nodetree && scene->world->use_nodes; - + bool glsl = GPU_glsl_support(); if (glsl) { RegionView3D *rv3d = ar->regiondata; GPUMaterial *gpumat = GPU_material_world(scene, scene->world); diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index afb1cbc..75d6362 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -132,13 +132,13 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap); void GPU_paint_update_image(struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h); void GPU_update_images_framechange(void); int GPU_update_image_time(struct Image *ima, double time); -int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, bool compare, bool mipmap, bool is_data); -void GPU_create_gl_tex( - unsigned int *bind, unsigned int *rect, float *frect, int rectw, int recth, - bool mipmap, bool use_hight_bit_depth, struct Image *ima); +int GPU_verify_image(struct Image *ima, + struct ImageUser *iuser, int textarget, int tftile, bool compare, bool mipmap, bool is_data); +void GPU_create_gl_tex(unsigned int *bind, unsigned int *rect, float *frect, int rectw, int recth, + int textarget, bool mipmap, bool use_hight_bit_depth, struct Image *ima); void GPU_create_gl_tex_compressed( - unsigned int *bind, unsigned int *pix, int x, int y, int mipmap, - struct Image *ima, struct ImBuf *ibuf); + unsigned int *bind, unsigned int *pix, int x, int y, int mipmap, + 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); diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index 64167e94..4a728c8 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -53,6 +53,7 @@ int GPU_max_texture_size(void); int GPU_max_textures(void); float GPU_max_texture_anisotropy(void); int GPU_max_color_texture_samples(void); +int GPU_max_cube_map_size(void); int GPU_color_depth(void); void GPU_get_dfdy_factors(float fac[2]); diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 65cdf83..3bcc7e2 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -78,6 +78,7 @@ typedef enum GPUType { GPU_TEX2D = 1002, GPU_SHADOW2D = 1003, + GPU_TEXCUBE = 1004, GPU_ATTRIB = 3001 } GPUType; @@ -179,6 +180,7 @@ typedef enum GPUDynamicType { GPU_DYNAMIC_HORIZON_COLOR = 1 | GPU_DYNAMIC_GROUP_WORLD, GPU_DYNAMIC_AMBIENT_COLOR = 2 | GPU_DYNAMIC_GROUP_WORLD, + GPU_DYNAMIC_ZENITH_COLOR = 3 | GPU_DYNAMIC_GROUP_WORLD, GPU_DYNAMIC_MAT_DIFFRGB = 1 | GPU_DYNAMIC_GROUP_MAT, GPU_DYNAMIC_MAT_REF = 2 | GPU_DYNAMIC_GROUP_MAT, @@ -194,6 +196,7 @@ GPUNodeLink *GPU_attribute(CustomDataType type, const char *name); GPUNodeLink *GPU_uniform(float *num); GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *data); GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, bool is_data); +GPUNodeLink *GPU_cube_map(struct Image *ima, struct ImageUser *iuser, bool is_data); GPUNodeLink *GPU_image_preview(struct PreviewImage *prv); GPUNodeLink *GPU_texture(int size, float *pixels); GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, GPUDynamicType dynamictype, void *data); diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h index 4166aaf..efa98f7 100644 --- a/source/blender/gpu/GPU_texture.h +++ b/source/blender/gpu/GPU_texture.h @@ -7 @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs