| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							| 
									
										
										
										
											2018-06-01 18:19:39 +02:00
										 |  |  |  * of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup edscr | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
  Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
  This allows keeping UI and data without actual saves, until you actually save.
  When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v). 
  Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards. 
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
  Old option is called "Save Startup File" the new one "Save User Settings".
  To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
  This also fixes "Continuous Grab" for OSX. (error since 2009)
											
										 
											2012-12-12 18:58:11 +00:00
										 |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | #include "DNA_vec_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-24 21:57:13 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-02 17:28:37 +00:00
										 |  |  | #include "BKE_context.h"
 | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BIF_glutil.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-02 17:28:37 +00:00
										 |  |  | #include "IMB_colormanagement.h"
 | 
					
						
							|  |  |  | #include "IMB_imbuf_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-20 15:40:08 -04:00
										 |  |  | #include "GPU_immediate.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-21 16:08:14 -04:00
										 |  |  | #include "GPU_matrix.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-28 01:20:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-13 21:24:28 +02:00
										 |  |  | #ifdef __APPLE__
 | 
					
						
							|  |  |  | #  include "GPU_state.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-05 20:05:41 +06:00
										 |  |  | #include "UI_interface.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | /* ******************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 03:24:05 +11:00
										 |  |  | static int get_cached_work_texture(int *r_w, int *r_h) | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   static GLint texid = -1; | 
					
						
							|  |  |  |   static int tex_w = 256; | 
					
						
							|  |  |  |   static int tex_h = 256; | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (texid == -1) { | 
					
						
							|  |  |  |     glGenTextures(1, (GLuint *)&texid); | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     glBindTexture(GL_TEXTURE_2D, texid); | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 
					
						
							|  |  |  |     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     glBindTexture(GL_TEXTURE_2D, 0); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   *r_w = tex_w; | 
					
						
							|  |  |  |   *r_h = tex_h; | 
					
						
							|  |  |  |   return texid; | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | static void immDrawPixelsTexSetupAttributes(IMMDrawPixelsTexState *state) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPUVertFormat *vert_format = immVertexFormat(); | 
					
						
							|  |  |  |   state->pos = GPU_vertformat_attr_add(vert_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | 
					
						
							|  |  |  |   state->texco = GPU_vertformat_attr_add( | 
					
						
							|  |  |  |       vert_format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-24 11:11:43 +01:00
										 |  |  | /* To be used before calling immDrawPixelsTex
 | 
					
						
							|  |  |  |  * Default shader is GPU_SHADER_2D_IMAGE_COLOR | 
					
						
							|  |  |  |  * You can still set uniforms with : | 
					
						
							| 
									
										
										
										
											2020-06-02 12:29:20 +02:00
										 |  |  |  * GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "name"), 0); | 
					
						
							| 
									
										
										
										
											2017-02-24 11:11:43 +01:00
										 |  |  |  * */ | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin) | 
					
						
							| 
									
										
										
										
											2017-02-24 11:11:43 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   IMMDrawPixelsTexState state; | 
					
						
							|  |  |  |   immDrawPixelsTexSetupAttributes(&state); | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   state.shader = GPU_shader_get_builtin_shader(builtin); | 
					
						
							| 
									
										
										
										
											2017-04-12 19:11:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* Shader will be unbind by immUnbindProgram in immDrawPixelsTexScaled_clipping */ | 
					
						
							|  |  |  |   immBindBuiltinProgram(builtin); | 
					
						
							|  |  |  |   immUniform1i("image", 0); | 
					
						
							|  |  |  |   state.do_shader_unbind = true; | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return state; | 
					
						
							| 
									
										
										
										
											2017-02-24 11:11:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Use the currently bound shader.
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use immDrawPixelsTexSetup to bind the shader you | 
					
						
							|  |  |  |  * want before calling immDrawPixelsTex. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * If using a special shader double check it uses the same | 
					
						
							|  |  |  |  * attributes "pos" "texCoord" and uniform "image". | 
					
						
							| 
									
										
										
										
											2017-02-24 01:15:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-02-24 11:11:43 +01:00
										 |  |  |  * If color is NULL then use white by default | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Be also aware that this function unbinds the shader when | 
					
						
							|  |  |  |  * it's finished. | 
					
						
							|  |  |  |  * */ | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                                      float x, | 
					
						
							|  |  |  |                                      float y, | 
					
						
							|  |  |  |                                      int img_w, | 
					
						
							|  |  |  |                                      int img_h, | 
					
						
							|  |  |  |                                      int format, | 
					
						
							|  |  |  |                                      int type, | 
					
						
							|  |  |  |                                      int zoomfilter, | 
					
						
							|  |  |  |                                      void *rect, | 
					
						
							|  |  |  |                                      float scaleX, | 
					
						
							|  |  |  |                                      float scaleY, | 
					
						
							|  |  |  |                                      float clip_min_x, | 
					
						
							|  |  |  |                                      float clip_min_y, | 
					
						
							|  |  |  |                                      float clip_max_x, | 
					
						
							|  |  |  |                                      float clip_max_y, | 
					
						
							|  |  |  |                                      float xzoom, | 
					
						
							|  |  |  |                                      float yzoom, | 
					
						
							|  |  |  |                                      float color[4]) | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-03 16:21:24 +11:00
										 |  |  |   uchar *uc_rect = (uchar *)rect; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const float *f_rect = (float *)rect; | 
					
						
							|  |  |  |   int subpart_x, subpart_y, tex_w, tex_h; | 
					
						
							|  |  |  |   int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y; | 
					
						
							|  |  |  |   int texid = get_cached_work_texture(&tex_w, &tex_h); | 
					
						
							|  |  |  |   int components; | 
					
						
							|  |  |  |   const bool use_clipping = ((clip_min_x < clip_max_x) && (clip_min_y < clip_max_y)); | 
					
						
							|  |  |  |   float white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GLint unpack_row_length; | 
					
						
							|  |  |  |   glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpack_row_length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w); | 
					
						
							|  |  |  |   glActiveTexture(GL_TEXTURE0); | 
					
						
							|  |  |  |   glBindTexture(GL_TEXTURE_2D, texid); | 
					
						
							| 
									
										
										
										
											2020-06-10 13:36:34 +02:00
										 |  |  |   glBindSampler(0, 0); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* don't want nasty border artifacts */ | 
					
						
							|  |  |  |   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 
					
						
							|  |  |  |   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 
					
						
							|  |  |  |   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, zoomfilter); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* setup seamless 2=on, 0=off */ | 
					
						
							|  |  |  |   seamless = ((tex_w < img_w || tex_h < img_h) && tex_w > 2 && tex_h > 2) ? 2 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   offset_x = tex_w - seamless; | 
					
						
							|  |  |  |   offset_y = tex_h - seamless; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   nsubparts_x = (img_w + (offset_x - 1)) / (offset_x); | 
					
						
							|  |  |  |   nsubparts_y = (img_h + (offset_y - 1)) / (offset_y); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (format == GL_RGBA) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     components = 4; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (format == GL_RGB) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     components = 3; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (format == GL_RED) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     components = 1; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   else { | 
					
						
							|  |  |  |     BLI_assert(!"Incompatible format passed to glaDrawPixelsTexScaled"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (type == GL_FLOAT) { | 
					
						
							|  |  |  |     /* need to set internal format to higher range float */ | 
					
						
							|  |  |  |     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, tex_w, tex_h, 0, format, GL_FLOAT, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     /* switch to 8bit RGBA for byte buffer */ | 
					
						
							|  |  |  |     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, format, GL_UNSIGNED_BYTE, NULL); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 16:21:24 +11:00
										 |  |  |   uint pos = state->pos, texco = state->texco; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* optional */ | 
					
						
							|  |  |  |   /* NOTE: Shader could be null for GLSL OCIO drawing, it is fine, since
 | 
					
						
							|  |  |  |    * it does not need color. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2020-06-02 12:29:20 +02:00
										 |  |  |   if (state->shader != NULL && GPU_shader_get_uniform(state->shader, "color") != -1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     immUniformColor4fv((color) ? color : white); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) { | 
					
						
							|  |  |  |     for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) { | 
					
						
							|  |  |  |       int remainder_x = img_w - subpart_x * offset_x; | 
					
						
							|  |  |  |       int remainder_y = img_h - subpart_y * offset_y; | 
					
						
							|  |  |  |       int subpart_w = (remainder_x < tex_w) ? remainder_x : tex_w; | 
					
						
							|  |  |  |       int subpart_h = (remainder_y < tex_h) ? remainder_y : tex_h; | 
					
						
							|  |  |  |       int offset_left = (seamless && subpart_x != 0) ? 1 : 0; | 
					
						
							|  |  |  |       int offset_bot = (seamless && subpart_y != 0) ? 1 : 0; | 
					
						
							|  |  |  |       int offset_right = (seamless && remainder_x > tex_w) ? 1 : 0; | 
					
						
							|  |  |  |       int offset_top = (seamless && remainder_y > tex_h) ? 1 : 0; | 
					
						
							|  |  |  |       float rast_x = x + subpart_x * offset_x * xzoom; | 
					
						
							|  |  |  |       float rast_y = y + subpart_y * offset_y * yzoom; | 
					
						
							|  |  |  |       /* check if we already got these because we always get 2 more when doing seamless */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       if (subpart_w <= seamless || subpart_h <= seamless) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         continue; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (use_clipping) { | 
					
						
							|  |  |  |         if (rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX < clip_min_x || | 
					
						
							|  |  |  |             rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY < clip_min_y) { | 
					
						
							|  |  |  |           continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (rast_x + (float)offset_left * xzoom > clip_max_x || | 
					
						
							|  |  |  |             rast_y + (float)offset_bot * yzoom > clip_max_y) { | 
					
						
							|  |  |  |           continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (type == GL_FLOAT) { | 
					
						
							|  |  |  |         glTexSubImage2D(GL_TEXTURE_2D, | 
					
						
							|  |  |  |                         0, | 
					
						
							|  |  |  |                         0, | 
					
						
							|  |  |  |                         0, | 
					
						
							|  |  |  |                         subpart_w, | 
					
						
							|  |  |  |                         subpart_h, | 
					
						
							|  |  |  |                         format, | 
					
						
							|  |  |  |                         GL_FLOAT, | 
					
						
							|  |  |  |                         &f_rect[((size_t)subpart_y) * offset_y * img_w * components + | 
					
						
							|  |  |  |                                 subpart_x * offset_x * components]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* add an extra border of pixels so linear looks ok at edges of full image */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         if (subpart_w < tex_w) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           glTexSubImage2D(GL_TEXTURE_2D, | 
					
						
							|  |  |  |                           0, | 
					
						
							|  |  |  |                           subpart_w, | 
					
						
							|  |  |  |                           0, | 
					
						
							|  |  |  |                           1, | 
					
						
							|  |  |  |                           subpart_h, | 
					
						
							|  |  |  |                           format, | 
					
						
							|  |  |  |                           GL_FLOAT, | 
					
						
							|  |  |  |                           &f_rect[((size_t)subpart_y) * offset_y * img_w * components + | 
					
						
							|  |  |  |                                   (subpart_x * offset_x + subpart_w - 1) * components]); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (subpart_h < tex_h) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           glTexSubImage2D( | 
					
						
							|  |  |  |               GL_TEXTURE_2D, | 
					
						
							|  |  |  |               0, | 
					
						
							|  |  |  |               0, | 
					
						
							|  |  |  |               subpart_h, | 
					
						
							|  |  |  |               subpart_w, | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               format, | 
					
						
							|  |  |  |               GL_FLOAT, | 
					
						
							|  |  |  |               &f_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + | 
					
						
							|  |  |  |                       subpart_x * offset_x * components]); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (subpart_w < tex_w && subpart_h < tex_h) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           glTexSubImage2D( | 
					
						
							|  |  |  |               GL_TEXTURE_2D, | 
					
						
							|  |  |  |               0, | 
					
						
							|  |  |  |               subpart_w, | 
					
						
							|  |  |  |               subpart_h, | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               format, | 
					
						
							|  |  |  |               GL_FLOAT, | 
					
						
							|  |  |  |               &f_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + | 
					
						
							|  |  |  |                       (subpart_x * offset_x + subpart_w - 1) * components]); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         glTexSubImage2D(GL_TEXTURE_2D, | 
					
						
							|  |  |  |                         0, | 
					
						
							|  |  |  |                         0, | 
					
						
							|  |  |  |                         0, | 
					
						
							|  |  |  |                         subpart_w, | 
					
						
							|  |  |  |                         subpart_h, | 
					
						
							|  |  |  |                         format, | 
					
						
							|  |  |  |                         GL_UNSIGNED_BYTE, | 
					
						
							|  |  |  |                         &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + | 
					
						
							|  |  |  |                                  subpart_x * offset_x * components]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         if (subpart_w < tex_w) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           glTexSubImage2D(GL_TEXTURE_2D, | 
					
						
							|  |  |  |                           0, | 
					
						
							|  |  |  |                           subpart_w, | 
					
						
							|  |  |  |                           0, | 
					
						
							|  |  |  |                           1, | 
					
						
							|  |  |  |                           subpart_h, | 
					
						
							|  |  |  |                           format, | 
					
						
							|  |  |  |                           GL_UNSIGNED_BYTE, | 
					
						
							|  |  |  |                           &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + | 
					
						
							|  |  |  |                                    (subpart_x * offset_x + subpart_w - 1) * components]); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (subpart_h < tex_h) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           glTexSubImage2D( | 
					
						
							|  |  |  |               GL_TEXTURE_2D, | 
					
						
							|  |  |  |               0, | 
					
						
							|  |  |  |               0, | 
					
						
							|  |  |  |               subpart_h, | 
					
						
							|  |  |  |               subpart_w, | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               format, | 
					
						
							|  |  |  |               GL_UNSIGNED_BYTE, | 
					
						
							|  |  |  |               &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + | 
					
						
							|  |  |  |                        subpart_x * offset_x * components]); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (subpart_w < tex_w && subpart_h < tex_h) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           glTexSubImage2D( | 
					
						
							|  |  |  |               GL_TEXTURE_2D, | 
					
						
							|  |  |  |               0, | 
					
						
							|  |  |  |               subpart_w, | 
					
						
							|  |  |  |               subpart_h, | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               format, | 
					
						
							|  |  |  |               GL_UNSIGNED_BYTE, | 
					
						
							|  |  |  |               &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + | 
					
						
							|  |  |  |                        (subpart_x * offset_x + subpart_w - 1) * components]); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       immBegin(GPU_PRIM_TRI_FAN, 4); | 
					
						
							|  |  |  |       immAttr2f(texco, (float)(0 + offset_left) / tex_w, (float)(0 + offset_bot) / tex_h); | 
					
						
							|  |  |  |       immVertex2f(pos, rast_x + (float)offset_left * xzoom, rast_y + (float)offset_bot * yzoom); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       immAttr2f(texco, (float)(subpart_w - offset_right) / tex_w, (float)(0 + offset_bot) / tex_h); | 
					
						
							|  |  |  |       immVertex2f(pos, | 
					
						
							|  |  |  |                   rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, | 
					
						
							|  |  |  |                   rast_y + (float)offset_bot * yzoom); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       immAttr2f(texco, | 
					
						
							|  |  |  |                 (float)(subpart_w - offset_right) / tex_w, | 
					
						
							|  |  |  |                 (float)(subpart_h - offset_top) / tex_h); | 
					
						
							|  |  |  |       immVertex2f(pos, | 
					
						
							|  |  |  |                   rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, | 
					
						
							|  |  |  |                   rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       immAttr2f(texco, (float)(0 + offset_left) / tex_w, (float)(subpart_h - offset_top) / tex_h); | 
					
						
							|  |  |  |       immVertex2f(pos, | 
					
						
							|  |  |  |                   rast_x + (float)offset_left * xzoom, | 
					
						
							|  |  |  |                   rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY); | 
					
						
							|  |  |  |       immEnd(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /* NOTE: Weirdly enough this is only required on macOS. Without this there is some sort of
 | 
					
						
							|  |  |  |        * bleeding of data is happening from tiles which are drawn later on. | 
					
						
							| 
									
										
										
										
											2019-04-22 00:18:34 +10:00
										 |  |  |        * This doesn't seem to be too slow, | 
					
						
							|  |  |  |        * but still would be nice to have fast and nice solution. */ | 
					
						
							| 
									
										
										
										
											2019-04-09 12:44:04 +02:00
										 |  |  | #ifdef __APPLE__
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       GPU_flush(); | 
					
						
							| 
									
										
										
										
											2019-04-09 12:44:04 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (state->do_shader_unbind) { | 
					
						
							|  |  |  |     immUnbindProgram(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   glBindTexture(GL_TEXTURE_2D, 0); | 
					
						
							|  |  |  |   glPixelStorei(GL_UNPACK_ROW_LENGTH, unpack_row_length); | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | void immDrawPixelsTexScaled(IMMDrawPixelsTexState *state, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                             float x, | 
					
						
							|  |  |  |                             float y, | 
					
						
							|  |  |  |                             int img_w, | 
					
						
							|  |  |  |                             int img_h, | 
					
						
							|  |  |  |                             int format, | 
					
						
							|  |  |  |                             int type, | 
					
						
							|  |  |  |                             int zoomfilter, | 
					
						
							|  |  |  |                             void *rect, | 
					
						
							|  |  |  |                             float scaleX, | 
					
						
							|  |  |  |                             float scaleY, | 
					
						
							|  |  |  |                             float xzoom, | 
					
						
							|  |  |  |                             float yzoom, | 
					
						
							|  |  |  |                             float color[4]) | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   immDrawPixelsTexScaled_clipping(state, | 
					
						
							|  |  |  |                                   x, | 
					
						
							|  |  |  |                                   y, | 
					
						
							|  |  |  |                                   img_w, | 
					
						
							|  |  |  |                                   img_h, | 
					
						
							|  |  |  |                                   format, | 
					
						
							|  |  |  |                                   type, | 
					
						
							|  |  |  |                                   zoomfilter, | 
					
						
							|  |  |  |                                   rect, | 
					
						
							|  |  |  |                                   scaleX, | 
					
						
							|  |  |  |                                   scaleY, | 
					
						
							|  |  |  |                                   0.0f, | 
					
						
							|  |  |  |                                   0.0f, | 
					
						
							|  |  |  |                                   0.0f, | 
					
						
							|  |  |  |                                   0.0f, | 
					
						
							|  |  |  |                                   xzoom, | 
					
						
							|  |  |  |                                   yzoom, | 
					
						
							|  |  |  |                                   color); | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | void immDrawPixelsTex(IMMDrawPixelsTexState *state, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                       float x, | 
					
						
							|  |  |  |                       float y, | 
					
						
							|  |  |  |                       int img_w, | 
					
						
							|  |  |  |                       int img_h, | 
					
						
							|  |  |  |                       int format, | 
					
						
							|  |  |  |                       int type, | 
					
						
							|  |  |  |                       int zoomfilter, | 
					
						
							|  |  |  |                       void *rect, | 
					
						
							|  |  |  |                       float xzoom, | 
					
						
							|  |  |  |                       float yzoom, | 
					
						
							|  |  |  |                       float color[4]) | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   immDrawPixelsTexScaled_clipping(state, | 
					
						
							|  |  |  |                                   x, | 
					
						
							|  |  |  |                                   y, | 
					
						
							|  |  |  |                                   img_w, | 
					
						
							|  |  |  |                                   img_h, | 
					
						
							|  |  |  |                                   format, | 
					
						
							|  |  |  |                                   type, | 
					
						
							|  |  |  |                                   zoomfilter, | 
					
						
							|  |  |  |                                   rect, | 
					
						
							|  |  |  |                                   1.0f, | 
					
						
							|  |  |  |                                   1.0f, | 
					
						
							|  |  |  |                                   0.0f, | 
					
						
							|  |  |  |                                   0.0f, | 
					
						
							|  |  |  |                                   0.0f, | 
					
						
							|  |  |  |                                   0.0f, | 
					
						
							|  |  |  |                                   xzoom, | 
					
						
							|  |  |  |                                   yzoom, | 
					
						
							|  |  |  |                                   color); | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-11 16:30:00 +02:00
										 |  |  | void immDrawPixelsTex_clipping(IMMDrawPixelsTexState *state, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                                float x, | 
					
						
							|  |  |  |                                float y, | 
					
						
							|  |  |  |                                int img_w, | 
					
						
							|  |  |  |                                int img_h, | 
					
						
							|  |  |  |                                int format, | 
					
						
							|  |  |  |                                int type, | 
					
						
							|  |  |  |                                int zoomfilter, | 
					
						
							|  |  |  |                                void *rect, | 
					
						
							|  |  |  |                                float clip_min_x, | 
					
						
							|  |  |  |                                float clip_min_y, | 
					
						
							|  |  |  |                                float clip_max_x, | 
					
						
							|  |  |  |                                float clip_max_y, | 
					
						
							|  |  |  |                                float xzoom, | 
					
						
							|  |  |  |                                float yzoom, | 
					
						
							|  |  |  |                                float color[4]) | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   immDrawPixelsTexScaled_clipping(state, | 
					
						
							|  |  |  |                                   x, | 
					
						
							|  |  |  |                                   y, | 
					
						
							|  |  |  |                                   img_w, | 
					
						
							|  |  |  |                                   img_h, | 
					
						
							|  |  |  |                                   format, | 
					
						
							|  |  |  |                                   type, | 
					
						
							|  |  |  |                                   zoomfilter, | 
					
						
							|  |  |  |                                   rect, | 
					
						
							|  |  |  |                                   1.0f, | 
					
						
							|  |  |  |                                   1.0f, | 
					
						
							|  |  |  |                                   clip_min_x, | 
					
						
							|  |  |  |                                   clip_min_y, | 
					
						
							|  |  |  |                                   clip_max_x, | 
					
						
							|  |  |  |                                   clip_max_y, | 
					
						
							|  |  |  |                                   xzoom, | 
					
						
							|  |  |  |                                   yzoom, | 
					
						
							|  |  |  |                                   color); | 
					
						
							| 
									
										
										
										
											2017-02-10 16:13:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | /* *************** glPolygonOffset hack ************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-04 20:06:30 +01:00
										 |  |  | float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-08 14:18:12 +02:00
										 |  |  |   /* Seems like we have a factor of 2 more offset than 2.79 for some reason. Correct for this. */ | 
					
						
							|  |  |  |   dist *= 0.5f; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (winmat[15] > 0.5f) { | 
					
						
							| 
									
										
										
										
											2019-02-04 20:06:30 +01:00
										 |  |  | #if 1
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return 0.00001f * dist * viewdist;  // ortho tweaking
 | 
					
						
							| 
									
										
										
										
											2019-02-04 20:06:30 +01:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     static float depth_fac = 0.0f; | 
					
						
							|  |  |  |     if (depth_fac == 0.0f) { | 
					
						
							|  |  |  |       int depthbits; | 
					
						
							|  |  |  |       glGetIntegerv(GL_DEPTH_BITS, &depthbits); | 
					
						
							|  |  |  |       depth_fac = 1.0f / (float)((1 << depthbits) - 1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     offs = (-1.0 / winmat[10]) * dist * depth_fac; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     UNUSED_VARS(viewdist); | 
					
						
							| 
									
										
										
										
											2019-02-04 20:06:30 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     /* This adjustment effectively results in reducing the Z value by 0.25%.
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * winmat[14] actually evaluates to `-2 * far * near / (far - near)`, | 
					
						
							| 
									
										
										
										
											2019-04-22 00:18:34 +10:00
										 |  |  |      * is very close to -0.2 with default clip range, | 
					
						
							|  |  |  |      * and is used as the coefficient multiplied by `w / z`, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |      * thus controlling the z dependent part of the depth value. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     return winmat[14] * -0.0025f * dist; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-02-04 20:06:30 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-09 20:59:29 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * \note \a viewdist is only for ortho at the moment. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-04-29 06:08:45 +10:00
										 |  |  | void bglPolygonOffset(float viewdist, float dist) | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   static float winmat[16], offset = 0.0f; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (dist != 0.0f) { | 
					
						
							|  |  |  |     // glEnable(GL_POLYGON_OFFSET_FILL);
 | 
					
						
							|  |  |  |     // glPolygonOffset(-1.0, -1.0);
 | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* hack below is to mimic polygon offset */ | 
					
						
							|  |  |  |     GPU_matrix_projection_get(winmat); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* dist is from camera to center point */ | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     float offs = bglPolygonOffsetCalc(winmat, viewdist, dist); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     winmat[14] -= offs; | 
					
						
							|  |  |  |     offset += offs; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     winmat[14] += offset; | 
					
						
							|  |  |  |     offset = 0.0; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-22 14:48:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPU_matrix_projection_set(winmat); | 
					
						
							| 
									
										
										
										
											2008-01-07 18:03:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-02 17:28:37 +00:00
										 |  |  | /* **** Color management helper functions for GLSL display/transform ***** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Draw given image buffer on a screen using GLSL for display transform */ | 
					
						
							| 
									
										
										
										
											2019-04-20 12:56:29 +02:00
										 |  |  | void ED_draw_imbuf_clipping(ImBuf *ibuf, | 
					
						
							|  |  |  |                             float x, | 
					
						
							|  |  |  |                             float y, | 
					
						
							|  |  |  |                             int zoomfilter, | 
					
						
							|  |  |  |                             ColorManagedViewSettings *view_settings, | 
					
						
							|  |  |  |                             ColorManagedDisplaySettings *display_settings, | 
					
						
							|  |  |  |                             float clip_min_x, | 
					
						
							|  |  |  |                             float clip_min_y, | 
					
						
							|  |  |  |                             float clip_max_x, | 
					
						
							|  |  |  |                             float clip_max_y, | 
					
						
							|  |  |  |                             float zoom_x, | 
					
						
							|  |  |  |                             float zoom_y) | 
					
						
							| 
									
										
										
										
											2013-04-02 17:28:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bool force_fallback = false; | 
					
						
							|  |  |  |   bool need_fallback = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Early out */ | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ibuf->rect == NULL && ibuf->rect_float == NULL) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Single channel images could not be transformed using GLSL yet */ | 
					
						
							|  |  |  |   force_fallback |= ibuf->channels == 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */ | 
					
						
							| 
									
										
										
										
											2019-04-20 12:47:06 +02:00
										 |  |  |   force_fallback |= (ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Try to draw buffer using GLSL display transform */ | 
					
						
							|  |  |  |   if (force_fallback == false) { | 
					
						
							|  |  |  |     int ok; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IMMDrawPixelsTexState state = {0}; | 
					
						
							|  |  |  |     /* We want GLSL state to be fully handled by OCIO. */ | 
					
						
							|  |  |  |     state.do_shader_unbind = false; | 
					
						
							|  |  |  |     immDrawPixelsTexSetupAttributes(&state); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ibuf->rect_float) { | 
					
						
							|  |  |  |       if (ibuf->float_colorspace) { | 
					
						
							|  |  |  |         ok = IMB_colormanagement_setup_glsl_draw_from_space( | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |             view_settings, display_settings, ibuf->float_colorspace, ibuf->dither, true, false); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         ok = IMB_colormanagement_setup_glsl_draw( | 
					
						
							|  |  |  |             view_settings, display_settings, ibuf->dither, true); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       ok = IMB_colormanagement_setup_glsl_draw_from_space( | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  |           view_settings, display_settings, ibuf->rect_colorspace, ibuf->dither, false, false); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ok) { | 
					
						
							|  |  |  |       if (ibuf->rect_float) { | 
					
						
							|  |  |  |         int format = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         if (ibuf->channels == 3) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           format = GL_RGB; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         else if (ibuf->channels == 4) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           format = GL_RGBA; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           BLI_assert(!"Incompatible number of channels for GLSL display"); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (format != 0) { | 
					
						
							|  |  |  |           immDrawPixelsTex_clipping(&state, | 
					
						
							|  |  |  |                                     x, | 
					
						
							|  |  |  |                                     y, | 
					
						
							|  |  |  |                                     ibuf->x, | 
					
						
							|  |  |  |                                     ibuf->y, | 
					
						
							|  |  |  |                                     format, | 
					
						
							|  |  |  |                                     GL_FLOAT, | 
					
						
							|  |  |  |                                     zoomfilter, | 
					
						
							|  |  |  |                                     ibuf->rect_float, | 
					
						
							|  |  |  |                                     clip_min_x, | 
					
						
							|  |  |  |                                     clip_min_y, | 
					
						
							|  |  |  |                                     clip_max_x, | 
					
						
							|  |  |  |                                     clip_max_y, | 
					
						
							|  |  |  |                                     zoom_x, | 
					
						
							|  |  |  |                                     zoom_y, | 
					
						
							|  |  |  |                                     NULL); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else if (ibuf->rect) { | 
					
						
							|  |  |  |         /* ibuf->rect is always RGBA */ | 
					
						
							|  |  |  |         immDrawPixelsTex_clipping(&state, | 
					
						
							|  |  |  |                                   x, | 
					
						
							|  |  |  |                                   y, | 
					
						
							|  |  |  |                                   ibuf->x, | 
					
						
							|  |  |  |                                   ibuf->y, | 
					
						
							|  |  |  |                                   GL_RGBA, | 
					
						
							|  |  |  |                                   GL_UNSIGNED_BYTE, | 
					
						
							|  |  |  |                                   zoomfilter, | 
					
						
							|  |  |  |                                   ibuf->rect, | 
					
						
							|  |  |  |                                   clip_min_x, | 
					
						
							|  |  |  |                                   clip_min_y, | 
					
						
							|  |  |  |                                   clip_max_x, | 
					
						
							|  |  |  |                                   clip_max_y, | 
					
						
							|  |  |  |                                   zoom_x, | 
					
						
							|  |  |  |                                   zoom_y, | 
					
						
							|  |  |  |                                   NULL); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       IMB_colormanagement_finish_glsl_draw(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       need_fallback = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* In case GLSL failed or not usable, fallback to glaDrawPixelsAuto */ | 
					
						
							|  |  |  |   if (need_fallback) { | 
					
						
							| 
									
										
										
										
											2020-04-03 16:21:24 +11:00
										 |  |  |     uchar *display_buffer; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     void *cache_handle; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     display_buffer = IMB_display_buffer_acquire( | 
					
						
							|  |  |  |         ibuf, view_settings, display_settings, &cache_handle); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (display_buffer) { | 
					
						
							|  |  |  |       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); | 
					
						
							|  |  |  |       immDrawPixelsTex_clipping(&state, | 
					
						
							|  |  |  |                                 x, | 
					
						
							|  |  |  |                                 y, | 
					
						
							|  |  |  |                                 ibuf->x, | 
					
						
							|  |  |  |                                 ibuf->y, | 
					
						
							|  |  |  |                                 GL_RGBA, | 
					
						
							|  |  |  |                                 GL_UNSIGNED_BYTE, | 
					
						
							|  |  |  |                                 zoomfilter, | 
					
						
							|  |  |  |                                 display_buffer, | 
					
						
							|  |  |  |                                 clip_min_x, | 
					
						
							|  |  |  |                                 clip_min_y, | 
					
						
							|  |  |  |                                 clip_max_x, | 
					
						
							|  |  |  |                                 clip_max_y, | 
					
						
							|  |  |  |                                 zoom_x, | 
					
						
							|  |  |  |                                 zoom_y, | 
					
						
							|  |  |  |                                 NULL); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IMB_display_buffer_release(cache_handle); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-04-02 17:28:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 12:56:29 +02:00
										 |  |  | void ED_draw_imbuf(ImBuf *ibuf, | 
					
						
							|  |  |  |                    float x, | 
					
						
							|  |  |  |                    float y, | 
					
						
							|  |  |  |                    int zoomfilter, | 
					
						
							|  |  |  |                    ColorManagedViewSettings *view_settings, | 
					
						
							|  |  |  |                    ColorManagedDisplaySettings *display_settings, | 
					
						
							|  |  |  |                    float zoom_x, | 
					
						
							|  |  |  |                    float zoom_y) | 
					
						
							| 
									
										
										
										
											2016-05-06 16:54:07 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-20 12:56:29 +02:00
										 |  |  |   ED_draw_imbuf_clipping(ibuf, | 
					
						
							|  |  |  |                          x, | 
					
						
							|  |  |  |                          y, | 
					
						
							|  |  |  |                          zoomfilter, | 
					
						
							|  |  |  |                          view_settings, | 
					
						
							|  |  |  |                          display_settings, | 
					
						
							|  |  |  |                          0.0f, | 
					
						
							|  |  |  |                          0.0f, | 
					
						
							|  |  |  |                          0.0f, | 
					
						
							|  |  |  |                          0.0f, | 
					
						
							|  |  |  |                          zoom_x, | 
					
						
							|  |  |  |                          zoom_y); | 
					
						
							| 
									
										
										
										
											2016-05-06 16:54:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 12:56:29 +02:00
										 |  |  | void ED_draw_imbuf_ctx_clipping(const bContext *C, | 
					
						
							|  |  |  |                                 ImBuf *ibuf, | 
					
						
							|  |  |  |                                 float x, | 
					
						
							|  |  |  |                                 float y, | 
					
						
							|  |  |  |                                 int zoomfilter, | 
					
						
							|  |  |  |                                 float clip_min_x, | 
					
						
							|  |  |  |                                 float clip_min_y, | 
					
						
							|  |  |  |                                 float clip_max_x, | 
					
						
							|  |  |  |                                 float clip_max_y, | 
					
						
							|  |  |  |                                 float zoom_x, | 
					
						
							|  |  |  |                                 float zoom_y) | 
					
						
							| 
									
										
										
										
											2013-04-04 12:20:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ColorManagedViewSettings *view_settings; | 
					
						
							|  |  |  |   ColorManagedDisplaySettings *display_settings; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 12:56:29 +02:00
										 |  |  |   ED_draw_imbuf_clipping(ibuf, | 
					
						
							|  |  |  |                          x, | 
					
						
							|  |  |  |                          y, | 
					
						
							|  |  |  |                          zoomfilter, | 
					
						
							|  |  |  |                          view_settings, | 
					
						
							|  |  |  |                          display_settings, | 
					
						
							|  |  |  |                          clip_min_x, | 
					
						
							|  |  |  |                          clip_min_y, | 
					
						
							|  |  |  |                          clip_max_x, | 
					
						
							|  |  |  |                          clip_max_y, | 
					
						
							|  |  |  |                          zoom_x, | 
					
						
							|  |  |  |                          zoom_y); | 
					
						
							| 
									
										
										
										
											2016-05-06 16:54:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 12:56:29 +02:00
										 |  |  | void ED_draw_imbuf_ctx( | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     const bContext *C, ImBuf *ibuf, float x, float y, int zoomfilter, float zoom_x, float zoom_y) | 
					
						
							| 
									
										
										
										
											2016-05-06 16:54:07 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-20 12:56:29 +02:00
										 |  |  |   ED_draw_imbuf_ctx_clipping(C, ibuf, x, y, zoomfilter, 0.0f, 0.0f, 0.0f, 0.0f, zoom_x, zoom_y); | 
					
						
							| 
									
										
										
										
											2013-04-04 12:20:13 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-01 14:30:22 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 12:47:06 +02:00
										 |  |  | int ED_draw_imbuf_method(ImBuf *ibuf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (U.image_draw_method == IMAGE_DRAW_METHOD_AUTO) { | 
					
						
							|  |  |  |     /* Use faster GLSL when CPU to GPU transfer is unlikely to be a bottleneck,
 | 
					
						
							|  |  |  |      * otherwise do color management on CPU side. */ | 
					
						
							|  |  |  |     const size_t threshold = 2048 * 2048 * 4 * sizeof(float); | 
					
						
							|  |  |  |     const size_t data_size = (ibuf->rect_float) ? sizeof(float) : sizeof(uchar); | 
					
						
							|  |  |  |     const size_t size = ibuf->x * ibuf->y * ibuf->channels * data_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return (size > threshold) ? IMAGE_DRAW_METHOD_2DTEXTURE : IMAGE_DRAW_METHOD_GLSL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     return U.image_draw_method; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-05 18:30:14 +10:00
										 |  |  | /* don't move to GPU_immediate_util.h because this uses user-prefs
 | 
					
						
							|  |  |  |  * and isn't very low level */ | 
					
						
							| 
									
										
										
										
											2020-04-03 16:21:24 +11:00
										 |  |  | void immDrawBorderCorners(uint pos, const rcti *border, float zoomx, float zoomy) | 
					
						
							| 
									
										
										
										
											2017-02-24 00:16:46 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   float delta_x = 4.0f * UI_DPI_FAC / zoomx; | 
					
						
							|  |  |  |   float delta_y = 4.0f * UI_DPI_FAC / zoomy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   delta_x = min_ff(delta_x, border->xmax - border->xmin); | 
					
						
							|  |  |  |   delta_y = min_ff(delta_y, border->ymax - border->ymin); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* left bottom corner */ | 
					
						
							|  |  |  |   immBegin(GPU_PRIM_LINE_STRIP, 3); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmin, border->ymin + delta_y); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmin, border->ymin); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmin + delta_x, border->ymin); | 
					
						
							|  |  |  |   immEnd(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* left top corner */ | 
					
						
							|  |  |  |   immBegin(GPU_PRIM_LINE_STRIP, 3); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmin, border->ymax - delta_y); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmin, border->ymax); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmin + delta_x, border->ymax); | 
					
						
							|  |  |  |   immEnd(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* right bottom corner */ | 
					
						
							|  |  |  |   immBegin(GPU_PRIM_LINE_STRIP, 3); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmax - delta_x, border->ymin); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmax, border->ymin); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmax, border->ymin + delta_y); | 
					
						
							|  |  |  |   immEnd(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* right top corner */ | 
					
						
							|  |  |  |   immBegin(GPU_PRIM_LINE_STRIP, 3); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmax - delta_x, border->ymax); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmax, border->ymax); | 
					
						
							|  |  |  |   immVertex2f(pos, border->xmax, border->ymax - delta_y); | 
					
						
							|  |  |  |   immEnd(); | 
					
						
							| 
									
										
										
										
											2017-02-24 00:16:46 -03:00
										 |  |  | } |