2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-01-07 18:03:41 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/screen/glutil.c
|
|
|
|
* \ingroup edscr
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.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"
|
|
|
|
|
2012-08-21 20:34:05 +00:00
|
|
|
#include "BLI_rect.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2013-01-24 21:57:13 +00:00
|
|
|
#include "BLI_math.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_gl.h"
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
2013-04-02 17:28:37 +00:00
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
2015-12-05 22:11:31 +01:00
|
|
|
#include "GPU_basic_shader.h"
|
2016-08-20 15:40:08 -04:00
|
|
|
#include "GPU_immediate.h"
|
2015-11-28 01:20:28 +01:00
|
|
|
|
2014-06-05 20:05:41 +06:00
|
|
|
#include "UI_interface.h"
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
#ifndef GL_CLAMP_TO_EDGE
|
|
|
|
#define GL_CLAMP_TO_EDGE 0x812F
|
|
|
|
#endif
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
void fdrawline(float x1, float y1, float x2, float y2)
|
|
|
|
{
|
2015-12-07 21:24:41 -05:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex2f(x1, y1);
|
|
|
|
glVertex2f(x2, y2);
|
2008-01-07 18:03:41 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
void fdrawbox(float x1, float y1, float x2, float y2)
|
|
|
|
{
|
2015-12-07 21:24:41 -05:00
|
|
|
glBegin(GL_LINE_LOOP);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2015-12-07 21:24:41 -05:00
|
|
|
glVertex2f(x1, y1);
|
|
|
|
glVertex2f(x1, y2);
|
|
|
|
glVertex2f(x2, y2);
|
|
|
|
glVertex2f(x2, y1);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2012-03-28 09:07:10 +00:00
|
|
|
void fdrawcheckerboard(float x1, float y1, float x2, float y2)
|
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
unsigned char col1[4] = {40, 40, 40}, col2[4] = {50, 50, 50};
|
2012-03-28 09:07:10 +00:00
|
|
|
|
|
|
|
glColor3ubv(col1);
|
|
|
|
glRectf(x1, y1, x2, y2);
|
|
|
|
glColor3ubv(col2);
|
|
|
|
|
2015-12-25 22:57:50 +01:00
|
|
|
GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
|
|
|
|
GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
|
2012-03-28 09:07:10 +00:00
|
|
|
glRectf(x1, y1, x2, y2);
|
2015-12-25 22:57:50 +01:00
|
|
|
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
|
2012-03-28 09:07:10 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 14:00:30 +02:00
|
|
|
void sdrawline(int x1, int y1, int x2, int y2)
|
2008-01-07 18:03:41 +00:00
|
|
|
{
|
2015-12-07 21:24:41 -05:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex2i(x1, y1);
|
|
|
|
glVertex2i(x2, y2);
|
2008-01-07 18:03:41 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2014-10-08 14:00:30 +02:00
|
|
|
void sdrawbox(int x1, int y1, int x2, int y2)
|
2008-01-07 18:03:41 +00:00
|
|
|
{
|
2015-12-07 21:24:41 -05:00
|
|
|
glBegin(GL_LINE_LOOP);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2015-12-07 21:24:41 -05:00
|
|
|
glVertex2i(x1, y1);
|
|
|
|
glVertex2i(x1, y2);
|
|
|
|
glVertex2i(x2, y2);
|
|
|
|
glVertex2i(x2, y1);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ******************************************** */
|
|
|
|
|
Various changes made in the process of working on the UI code:
* Added functions to generate Timer events. There was some unfinished code to
create one timer per window, this replaces that with a way to let operators
or other handlers add/remove their own timers as needed. This is currently
delivered as an event with the timer handle, perhaps this should be a notifier
instead? Also includes some fixes in ghost for timer events that were not
delivered in time, due to passing negative timeout.
* Added a Message event, which is a generic event that can be added by any
operator. This is used in the UI code to communicate the results of opened
blocks. Again, this may be better as a notifier.
* These two events should not be blocked as they are intended for a specific
operator or handler, so there were exceptions added for this, which is one
of the reasons they might work better as notifiers, but currently these
things can't listen to notifier yet.
* Added an option to events to indicate if the customdata should be freed or
not.
* Added a free() callback for area regions, and added a free function for
area regions in blenkernel since it was already there for screens and areas.
* Added ED_screen/area/region_exit functions to clean up things like operators
and handlers when they are closed.
* Added screen level regions, these will draw over areas boundaries, with the
last created region on top. These are useful for tooltips, menus, etc, and
are not saved to file. It's using the same ARegion struct as areas to avoid
code duplication, but perhaps that should be renamed then. Note that redraws
currently go correct, because only full window redraws are used, for partial
redraws without any frontbuffer drawing, the window manager needs to get
support for compositing subwindows.
* Minor changes in the subwindow code to retrieve the matrix, and moved
setlinestyle to glutil.c.
* Reversed argument order in WM_event_add/remove_keymap_handler to be consistent
with modal_handler.
* Operators can now block events but not necessarily cancel/finish.
* Modal operators are now stored in a list in the window/area/region they were
created in. This means for example that when a transform operator is invoked
from a region but registers a handler at the window level (since mouse motion
across areas should work), it will still get removed when the region is closed
while the operator is running.
2008-11-11 15:18:21 +00:00
|
|
|
void setlinestyle(int nr)
|
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
if (nr == 0) {
|
Various changes made in the process of working on the UI code:
* Added functions to generate Timer events. There was some unfinished code to
create one timer per window, this replaces that with a way to let operators
or other handlers add/remove their own timers as needed. This is currently
delivered as an event with the timer handle, perhaps this should be a notifier
instead? Also includes some fixes in ghost for timer events that were not
delivered in time, due to passing negative timeout.
* Added a Message event, which is a generic event that can be added by any
operator. This is used in the UI code to communicate the results of opened
blocks. Again, this may be better as a notifier.
* These two events should not be blocked as they are intended for a specific
operator or handler, so there were exceptions added for this, which is one
of the reasons they might work better as notifiers, but currently these
things can't listen to notifier yet.
* Added an option to events to indicate if the customdata should be freed or
not.
* Added a free() callback for area regions, and added a free function for
area regions in blenkernel since it was already there for screens and areas.
* Added ED_screen/area/region_exit functions to clean up things like operators
and handlers when they are closed.
* Added screen level regions, these will draw over areas boundaries, with the
last created region on top. These are useful for tooltips, menus, etc, and
are not saved to file. It's using the same ARegion struct as areas to avoid
code duplication, but perhaps that should be renamed then. Note that redraws
currently go correct, because only full window redraws are used, for partial
redraws without any frontbuffer drawing, the window manager needs to get
support for compositing subwindows.
* Minor changes in the subwindow code to retrieve the matrix, and moved
setlinestyle to glutil.c.
* Reversed argument order in WM_event_add/remove_keymap_handler to be consistent
with modal_handler.
* Operators can now block events but not necessarily cancel/finish.
* Modal operators are now stored in a list in the window/area/region they were
created in. This means for example that when a transform operator is invoked
from a region but registers a handler at the window level (since mouse motion
across areas should work), it will still get removed when the region is closed
while the operator is running.
2008-11-11 15:18:21 +00:00
|
|
|
glDisable(GL_LINE_STIPPLE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
glEnable(GL_LINE_STIPPLE);
|
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
|
|
|
if (U.pixelsize > 1.0f)
|
|
|
|
glLineStipple(nr, 0xCCCC);
|
|
|
|
else
|
|
|
|
glLineStipple(nr, 0xAAAA);
|
Various changes made in the process of working on the UI code:
* Added functions to generate Timer events. There was some unfinished code to
create one timer per window, this replaces that with a way to let operators
or other handlers add/remove their own timers as needed. This is currently
delivered as an event with the timer handle, perhaps this should be a notifier
instead? Also includes some fixes in ghost for timer events that were not
delivered in time, due to passing negative timeout.
* Added a Message event, which is a generic event that can be added by any
operator. This is used in the UI code to communicate the results of opened
blocks. Again, this may be better as a notifier.
* These two events should not be blocked as they are intended for a specific
operator or handler, so there were exceptions added for this, which is one
of the reasons they might work better as notifiers, but currently these
things can't listen to notifier yet.
* Added an option to events to indicate if the customdata should be freed or
not.
* Added a free() callback for area regions, and added a free function for
area regions in blenkernel since it was already there for screens and areas.
* Added ED_screen/area/region_exit functions to clean up things like operators
and handlers when they are closed.
* Added screen level regions, these will draw over areas boundaries, with the
last created region on top. These are useful for tooltips, menus, etc, and
are not saved to file. It's using the same ARegion struct as areas to avoid
code duplication, but perhaps that should be renamed then. Note that redraws
currently go correct, because only full window redraws are used, for partial
redraws without any frontbuffer drawing, the window manager needs to get
support for compositing subwindows.
* Minor changes in the subwindow code to retrieve the matrix, and moved
setlinestyle to glutil.c.
* Reversed argument order in WM_event_add/remove_keymap_handler to be consistent
with modal_handler.
* Operators can now block events but not necessarily cancel/finish.
* Modal operators are now stored in a list in the window/area/region they were
created in. This means for example that when a transform operator is invoked
from a region but registers a handler at the window level (since mouse motion
across areas should work), it will still get removed when the region is closed
while the operator is running.
2008-11-11 15:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
/* Invert line handling */
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-09-06 01:31:15 +00:00
|
|
|
#define GL_TOGGLE(mode, onoff) (((onoff) ? glEnable : glDisable)(mode))
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
void set_inverted_drawing(int enable)
|
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
glLogicOp(enable ? GL_INVERT : GL_COPY);
|
2012-09-06 01:31:15 +00:00
|
|
|
GL_TOGGLE(GL_COLOR_LOGIC_OP, enable);
|
|
|
|
GL_TOGGLE(GL_DITHER, !enable);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fdrawXORcirc(float xofs, float yofs, float rad)
|
|
|
|
{
|
|
|
|
set_inverted_drawing(1);
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(xofs, yofs, 0.0);
|
2012-05-08 15:43:59 +00:00
|
|
|
glutil_draw_lined_arc(0.0, M_PI * 2.0, rad, 20);
|
2008-01-07 18:03:41 +00:00
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
set_inverted_drawing(0);
|
|
|
|
}
|
|
|
|
|
2011-09-28 05:53:40 +00:00
|
|
|
void glutil_draw_filled_arc(float start, float angle, float radius, int nsegments)
|
|
|
|
{
|
2008-01-07 18:03:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
glVertex2f(0.0, 0.0);
|
2012-05-08 15:43:59 +00:00
|
|
|
for (i = 0; i < nsegments; i++) {
|
|
|
|
float t = (float) i / (nsegments - 1);
|
|
|
|
float cur = start + t * angle;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
glVertex2f(cosf(cur) * radius, sinf(cur) * radius);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2011-09-28 05:53:40 +00:00
|
|
|
void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments)
|
|
|
|
{
|
2008-01-07 18:03:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
glBegin(GL_LINE_STRIP);
|
2012-05-08 15:43:59 +00:00
|
|
|
for (i = 0; i < nsegments; i++) {
|
|
|
|
float t = (float) i / (nsegments - 1);
|
|
|
|
float cur = start + t * angle;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
glVertex2f(cosf(cur) * radius, sinf(cur) * radius);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2016-08-22 23:39:42 -04:00
|
|
|
static void imm_draw_circle(GLenum prim_type, unsigned pos, float x, float y, float rad, int nsegments)
|
2016-08-20 15:40:08 -04:00
|
|
|
{
|
2016-08-22 23:39:42 -04:00
|
|
|
immBegin(prim_type, nsegments);
|
2016-08-20 15:40:08 -04:00
|
|
|
for (int i = 0; i < nsegments; ++i) {
|
|
|
|
float angle = 2 * M_PI * ((float)i / (float)nsegments);
|
|
|
|
immVertex2f(pos, x + rad * cosf(angle),
|
|
|
|
y + rad * sinf(angle));
|
|
|
|
}
|
|
|
|
immEnd();
|
|
|
|
}
|
|
|
|
|
2016-08-22 23:39:42 -04:00
|
|
|
void imm_draw_lined_circle(unsigned pos, float x, float y, float rad, int nsegments)
|
|
|
|
{
|
|
|
|
imm_draw_circle(GL_LINE_LOOP, pos, x, y, rad, nsegments);
|
|
|
|
}
|
|
|
|
|
|
|
|
void imm_draw_filled_circle(unsigned pos, float x, float y, float rad, int nsegments)
|
|
|
|
{
|
|
|
|
imm_draw_circle(GL_TRIANGLE_FAN, pos, x, y, rad, nsegments);
|
|
|
|
}
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
float glaGetOneFloat(int param)
|
|
|
|
{
|
|
|
|
GLfloat v;
|
|
|
|
glGetFloatv(param, &v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2016-06-09 05:12:42 +10:00
|
|
|
int glaGetOneInt(int param)
|
|
|
|
{
|
|
|
|
GLint v;
|
|
|
|
glGetIntegerv(param, &v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y)
|
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
GLubyte dummy = 0;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
/* As long as known good coordinates are correct
|
|
|
|
* this is guaranteed to generate an ok raster
|
|
|
|
* position (ignoring potential (real) overflow
|
|
|
|
* issues).
|
|
|
|
*/
|
2008-01-07 18:03:41 +00:00
|
|
|
glRasterPos2f(known_good_x, known_good_y);
|
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
/* Now shift the raster position to where we wanted
|
|
|
|
* it in the first place using the glBitmap trick.
|
|
|
|
*/
|
2008-01-07 18:03:41 +00:00
|
|
|
glBitmap(0, 0, 0, 0, x - known_good_x, y - known_good_y, &dummy);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
static GLint texid = -1;
|
|
|
|
static int tex_w = 256;
|
|
|
|
static int tex_h = 256;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
if (texid == -1) {
|
2008-01-07 18:03:41 +00:00
|
|
|
glGenTextures(1, (GLuint *)&texid);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texid);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
2015-12-26 22:23:12 -05: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
|
|
|
|
2015-11-28 01:45:23 +01:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-03-16 03:24:05 +11:00
|
|
|
*r_w = tex_w;
|
|
|
|
*r_h = tex_h;
|
2008-01-07 18:03:41 +00:00
|
|
|
return texid;
|
|
|
|
}
|
|
|
|
|
2016-05-06 16:54:07 +02:00
|
|
|
void glaDrawPixelsTexScaled_clipping(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)
|
2008-01-07 18:03:41 +00:00
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
unsigned char *uc_rect = (unsigned char *) rect;
|
2014-04-27 00:22:49 +10:00
|
|
|
const float *f_rect = (float *)rect;
|
2012-05-08 15:43:59 +00:00
|
|
|
float xzoom = glaGetOneFloat(GL_ZOOM_X), yzoom = glaGetOneFloat(GL_ZOOM_Y);
|
2008-01-07 18:03:41 +00:00
|
|
|
int subpart_x, subpart_y, tex_w, tex_h;
|
2010-03-12 16:02:05 +00:00
|
|
|
int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y;
|
2012-05-08 15:43:59 +00:00
|
|
|
int texid = get_cached_work_texture(&tex_w, &tex_h);
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
int components;
|
2016-05-06 16:54:07 +02:00
|
|
|
const bool use_clipping = ((clip_min_x < clip_max_x) && (clip_min_y < clip_max_y));
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
/* Specify the color outside this function, and tex will modulate it.
|
|
|
|
* This is useful for changing alpha without using glPixelTransferf()
|
|
|
|
*/
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texid);
|
|
|
|
|
2009-11-26 02:11:07 +00: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);
|
2013-03-17 17:32:45 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, zoomfilter);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2010-03-12 16:02:05 +00:00
|
|
|
/* setup seamless 2=on, 0=off */
|
2012-05-08 15:43:59 +00:00
|
|
|
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);
|
|
|
|
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
if (format == GL_RGBA)
|
|
|
|
components = 4;
|
|
|
|
else if (format == GL_RGB)
|
|
|
|
components = 3;
|
2016-01-04 01:37:55 -05:00
|
|
|
else if (ELEM(format, GL_LUMINANCE, GL_ALPHA))
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
components = 1;
|
2013-04-03 16:21:14 +00:00
|
|
|
else {
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
BLI_assert(!"Incompatible format passed to glaDrawPixelsTexScaled");
|
2013-04-03 16:21:14 +00:00
|
|
|
return;
|
|
|
|
}
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
|
|
|
|
if (type == GL_FLOAT) {
|
2013-03-29 16:02:27 +00:00
|
|
|
/* need to set internal format to higher range float */
|
2013-04-05 11:01:35 +00:00
|
|
|
|
|
|
|
/* NOTE: this could fail on some drivers, like mesa,
|
|
|
|
* but currently this code is only used by color
|
|
|
|
* management stuff which already checks on whether
|
|
|
|
* it's possible to use GL_RGBA16F_ARB
|
|
|
|
*/
|
|
|
|
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, tex_w, tex_h, 0, format, GL_FLOAT, NULL);
|
2013-03-29 16:02:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-01-04 01:37:55 -05:00
|
|
|
/* switch to 8bit RGBA for byte buffer */
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, format, GL_UNSIGNED_BYTE, NULL);
|
2013-03-29 16:02:27 +00:00
|
|
|
}
|
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
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;
|
2016-01-04 01:37:55 -05:00
|
|
|
/* check if we already got these because we always get 2 more when doing seamless */
|
2012-05-08 15:43:59 +00:00
|
|
|
if (subpart_w <= seamless || subpart_h <= seamless)
|
2010-03-12 16:02:05 +00:00
|
|
|
continue;
|
2016-05-06 16:54:07 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
if (type == GL_FLOAT) {
|
2015-04-30 12:10:58 +02:00
|
|
|
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]);
|
2010-03-12 16:02:05 +00:00
|
|
|
|
2016-01-04 01:37:55 -05:00
|
|
|
/* add an extra border of pixels so linear looks ok at edges of full image */
|
2012-05-08 15:43:59 +00:00
|
|
|
if (subpart_w < tex_w)
|
2015-04-30 12:10:58 +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]);
|
2012-05-08 15:43:59 +00:00
|
|
|
if (subpart_h < tex_h)
|
2015-04-30 12:10:58 +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]);
|
2012-05-08 15:43:59 +00:00
|
|
|
if (subpart_w < tex_w && subpart_h < tex_h)
|
2015-04-30 12:10:58 +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]);
|
2010-03-12 16:02:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-04-30 12:10:58 +02:00
|
|
|
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]);
|
2010-03-12 16:02:05 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
if (subpart_w < tex_w)
|
2015-04-30 12:10:58 +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]);
|
2012-05-08 15:43:59 +00:00
|
|
|
if (subpart_h < tex_h)
|
2015-04-30 12:10:58 +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]);
|
2012-05-08 15:43:59 +00:00
|
|
|
if (subpart_w < tex_w && subpart_h < tex_h)
|
2015-04-30 12:10:58 +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]);
|
2010-03-12 16:02:05 +00:00
|
|
|
}
|
|
|
|
|
2015-12-05 22:11:31 +01:00
|
|
|
GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
|
2008-01-07 18:03:41 +00:00
|
|
|
glBegin(GL_QUADS);
|
2012-05-08 15:43:59 +00:00
|
|
|
glTexCoord2f((float)(0 + offset_left) / tex_w, (float)(0 + offset_bot) / tex_h);
|
2013-03-10 07:01:52 +00:00
|
|
|
glVertex2f(rast_x + (float)offset_left * xzoom, rast_y + (float)offset_bot * yzoom);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
glTexCoord2f((float)(subpart_w - offset_right) / tex_w, (float)(0 + offset_bot) / tex_h);
|
2013-03-10 07:01:52 +00:00
|
|
|
glVertex2f(rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)offset_bot * yzoom);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
glTexCoord2f((float)(subpart_w - offset_right) / tex_w, (float)(subpart_h - offset_top) / tex_h);
|
|
|
|
glVertex2f(rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
glTexCoord2f((float)(0 + offset_left) / tex_w, (float)(subpart_h - offset_top) / tex_h);
|
|
|
|
glVertex2f(rast_x + (float)offset_left * xzoom, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY);
|
2008-01-07 18:03:41 +00:00
|
|
|
glEnd();
|
2015-12-05 22:11:31 +01:00
|
|
|
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 01:45:23 +01:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-06 16:54:07 +02:00
|
|
|
void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h,
|
|
|
|
int format, int type, int zoomfilter, void *rect,
|
|
|
|
float scaleX, float scaleY)
|
|
|
|
{
|
|
|
|
glaDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect,
|
|
|
|
scaleX, scaleY, 0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect)
|
2009-05-14 18:08:14 +00:00
|
|
|
{
|
2016-05-06 16:54:07 +02:00
|
|
|
glaDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void glaDrawPixelsTex_clipping(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)
|
|
|
|
{
|
|
|
|
glaDrawPixelsTexScaled_clipping(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);
|
2009-05-14 18:08:14 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect)
|
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
float xzoom = glaGetOneFloat(GL_ZOOM_X);
|
|
|
|
float yzoom = glaGetOneFloat(GL_ZOOM_Y);
|
|
|
|
|
|
|
|
/* The pixel space coordinate of the intersection of
|
|
|
|
* the [zoomed] image with the origin.
|
|
|
|
*/
|
|
|
|
float ix = -x / xzoom;
|
|
|
|
float iy = -y / yzoom;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
/* The maximum pixel amounts the image can be cropped
|
|
|
|
* at the lower left without exceeding the origin.
|
|
|
|
*/
|
2012-10-25 22:47:54 +00:00
|
|
|
int off_x = floor(max_ff(ix, 0.0f));
|
|
|
|
int off_y = floor(max_ff(iy, 0.0f));
|
2012-05-08 15:43:59 +00:00
|
|
|
|
|
|
|
/* The zoomed space coordinate of the raster position
|
|
|
|
* (starting at the lower left most unclipped pixel).
|
|
|
|
*/
|
|
|
|
float rast_x = x + off_x * xzoom;
|
|
|
|
float rast_y = y + off_y * yzoom;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
GLfloat scissor[4];
|
|
|
|
int draw_w, draw_h;
|
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
/* Determine the smallest number of pixels we need to draw
|
|
|
|
* before the image would go off the upper right corner.
|
|
|
|
*
|
|
|
|
* It may seem this is just an optimization but some graphics
|
|
|
|
* cards (ATI) freak out if there is a large zoom factor and
|
|
|
|
* a large number of pixels off the screen (probably at some
|
|
|
|
* level the number of image pixels to draw is getting multiplied
|
|
|
|
* by the zoom and then clamped). Making sure we draw the
|
|
|
|
* fewest pixels possible keeps everyone mostly happy (still
|
|
|
|
* fails if we zoom in on one really huge pixel so that it
|
|
|
|
* covers the entire screen).
|
|
|
|
*/
|
2008-01-07 18:03:41 +00:00
|
|
|
glGetFloatv(GL_SCISSOR_BOX, scissor);
|
2012-10-23 13:28:22 +00:00
|
|
|
draw_w = min_ii(img_w - off_x, ceil((scissor[2] - rast_x) / xzoom));
|
|
|
|
draw_h = min_ii(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom));
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
if (draw_w > 0 && draw_h > 0) {
|
2016-06-08 04:03:25 +10:00
|
|
|
|
|
|
|
int bound_options;
|
|
|
|
GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
|
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
/* Don't use safe RasterPos (slower) if we can avoid it. */
|
|
|
|
if (rast_x >= 0 && rast_y >= 0) {
|
2008-01-07 18:03:41 +00:00
|
|
|
glRasterPos2f(rast_x, rast_y);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-01-07 18:03:41 +00:00
|
|
|
glaRasterPosSafe2f(rast_x, rast_y, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, row_w);
|
2012-05-08 15:43:59 +00:00
|
|
|
if (format == GL_LUMINANCE || format == GL_RED) {
|
|
|
|
if (type == GL_FLOAT) {
|
2014-04-27 00:22:49 +10:00
|
|
|
const float *f_rect = (float *)rect;
|
2012-05-08 15:43:59 +00:00
|
|
|
glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y * row_w + off_x));
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
2012-05-08 15:43:59 +00:00
|
|
|
else if (type == GL_INT || type == GL_UNSIGNED_INT) {
|
2014-04-27 00:22:49 +10:00
|
|
|
const int *i_rect = (int *)rect;
|
2012-05-08 15:43:59 +00:00
|
|
|
glDrawPixels(draw_w, draw_h, format, type, i_rect + (off_y * row_w + off_x));
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* RGBA */
|
2012-05-08 15:43:59 +00:00
|
|
|
if (type == GL_FLOAT) {
|
2014-04-27 00:22:49 +10:00
|
|
|
const float *f_rect = (float *)rect;
|
2012-05-08 15:43:59 +00:00
|
|
|
glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y * row_w + off_x) * 4);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
2012-05-08 15:43:59 +00:00
|
|
|
else if (type == GL_UNSIGNED_BYTE) {
|
|
|
|
unsigned char *uc_rect = (unsigned char *) rect;
|
|
|
|
glDrawPixels(draw_w, draw_h, format, type, uc_rect + (off_y * row_w + off_x) * 4);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 01:45:23 +01:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
2016-06-08 04:03:25 +10:00
|
|
|
|
|
|
|
GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-17 14:38:58 +00:00
|
|
|
/* uses either DrawPixelsSafe or DrawPixelsTex, based on user defined maximum */
|
2016-05-06 16:54:07 +02:00
|
|
|
void glaDrawPixelsAuto_clipping(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)
|
2013-03-17 14:38:58 +00:00
|
|
|
{
|
2013-04-12 10:52:47 +00:00
|
|
|
if (U.image_draw_method != IMAGE_DRAW_METHOD_DRAWPIXELS) {
|
|
|
|
glColor4f(1.0, 1.0, 1.0, 1.0);
|
2016-05-06 16:54:07 +02:00
|
|
|
glaDrawPixelsTex_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect,
|
|
|
|
clip_min_x, clip_min_y, clip_max_x, clip_max_y);
|
2013-04-12 10:52:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
glaDrawPixelsSafe(x, y, img_w, img_h, img_w, format, type, rect);
|
2013-03-17 14:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 16:54:07 +02:00
|
|
|
void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect)
|
|
|
|
{
|
|
|
|
glaDrawPixelsAuto_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
/* 2D Drawing Assistance */
|
|
|
|
|
|
|
|
void glaDefine2DArea(rcti *screen_rect)
|
|
|
|
{
|
2012-09-15 11:48:20 +00:00
|
|
|
const int sc_w = BLI_rcti_size_x(screen_rect) + 1;
|
|
|
|
const int sc_h = BLI_rcti_size_y(screen_rect) + 1;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
glViewport(screen_rect->xmin, screen_rect->ymin, sc_w, sc_h);
|
|
|
|
glScissor(screen_rect->xmin, screen_rect->ymin, sc_w, sc_h);
|
|
|
|
|
2012-08-05 17:27:52 +00:00
|
|
|
/* The GLA_PIXEL_OFS magic number is to shift the matrix so that
|
2012-05-08 15:43:59 +00:00
|
|
|
* both raster and vertex integer coordinates fall at pixel
|
|
|
|
* centers properly. For a longer discussion see the OpenGL
|
|
|
|
* Programming Guide, Appendix H, Correctness Tips.
|
|
|
|
*/
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho(0.0, sc_w, 0.0, sc_h, -1, 1);
|
2012-08-05 17:27:52 +00:00
|
|
|
glTranslatef(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
}
|
|
|
|
|
2016-08-20 13:57:17 -04:00
|
|
|
/* TODO(merwin): put the following 2D code to use, or build new 2D code inspired & informd by it */
|
|
|
|
|
2012-04-23 07:32:13 +00:00
|
|
|
#if 0 /* UNUSED */
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
struct gla2DDrawInfo {
|
|
|
|
int orig_vp[4], orig_sc[4];
|
|
|
|
float orig_projmat[16], orig_viewmat[16];
|
|
|
|
|
|
|
|
rcti screen_rect;
|
|
|
|
rctf world_rect;
|
|
|
|
|
|
|
|
float wo_to_sc[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
void gla2DGetMap(gla2DDrawInfo *di, rctf *rect)
|
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
*rect = di->world_rect;
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gla2DSetMap(gla2DDrawInfo *di, rctf *rect)
|
|
|
|
{
|
|
|
|
int sc_w, sc_h;
|
|
|
|
float wo_w, wo_h;
|
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
di->world_rect = *rect;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-09-15 11:48:20 +00:00
|
|
|
sc_w = BLI_rcti_size_x(&di->screen_rect);
|
|
|
|
sc_h = BLI_rcti_size_y(&di->screen_rect);
|
|
|
|
wo_w = BLI_rcti_size_x(&di->world_rect);
|
|
|
|
wo_h = BLI_rcti_size_y(&di->world_rect);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
di->wo_to_sc[0] = sc_w / wo_w;
|
|
|
|
di->wo_to_sc[1] = sc_h / wo_h;
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 15:04:24 +00:00
|
|
|
/** Save the current OpenGL state and initialize OpenGL for 2D
|
|
|
|
* rendering. glaEnd2DDraw should be called on the returned structure
|
|
|
|
* to free it and to return OpenGL to its previous state. The
|
|
|
|
* scissor rectangle is set to match the viewport.
|
|
|
|
*
|
|
|
|
* See glaDefine2DArea for an explanation of why this function uses integers.
|
|
|
|
*
|
|
|
|
* \param screen_rect The screen rectangle to be used for 2D drawing.
|
|
|
|
* \param world_rect The world rectangle that the 2D area represented
|
|
|
|
* by \a screen_rect is supposed to represent. If NULL it is assumed the
|
|
|
|
* world has a 1 to 1 mapping to the screen.
|
|
|
|
*/
|
2008-01-07 18:03:41 +00:00
|
|
|
gla2DDrawInfo *glaBegin2DDraw(rcti *screen_rect, rctf *world_rect)
|
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
gla2DDrawInfo *di = MEM_mallocN(sizeof(*di), "gla2DDrawInfo");
|
2008-01-07 18:03:41 +00:00
|
|
|
int sc_w, sc_h;
|
|
|
|
float wo_w, wo_h;
|
|
|
|
|
|
|
|
glGetIntegerv(GL_VIEWPORT, (GLint *)di->orig_vp);
|
|
|
|
glGetIntegerv(GL_SCISSOR_BOX, (GLint *)di->orig_sc);
|
|
|
|
glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat *)di->orig_projmat);
|
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *)di->orig_viewmat);
|
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
di->screen_rect = *screen_rect;
|
2008-01-07 18:03:41 +00:00
|
|
|
if (world_rect) {
|
2012-05-08 15:43:59 +00:00
|
|
|
di->world_rect = *world_rect;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-24 02:51:46 +00:00
|
|
|
di->world_rect.xmin = di->screen_rect.xmin;
|
|
|
|
di->world_rect.ymin = di->screen_rect.ymin;
|
|
|
|
di->world_rect.xmax = di->screen_rect.xmax;
|
|
|
|
di->world_rect.ymax = di->screen_rect.ymax;
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
2012-09-15 11:48:20 +00:00
|
|
|
sc_w = BLI_rcti_size_x(&di->screen_rect);
|
|
|
|
sc_h = BLI_rcti_size_y(&di->screen_rect);
|
|
|
|
wo_w = BLI_rcti_size_x(&di->world_rect);
|
|
|
|
wo_h = BLI_rcti_size_y(&di->world_rect);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
di->wo_to_sc[0] = sc_w / wo_w;
|
|
|
|
di->wo_to_sc[1] = sc_h / wo_h;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
glaDefine2DArea(&di->screen_rect);
|
|
|
|
|
|
|
|
return di;
|
|
|
|
}
|
|
|
|
|
2013-04-03 15:04:24 +00:00
|
|
|
/**
|
|
|
|
* Translate the (\a wo_x, \a wo_y) point from world coordinates into screen space.
|
|
|
|
*/
|
2014-03-16 03:24:05 +11:00
|
|
|
void gla2DDrawTranslatePt(gla2DDrawInfo *di, float wo_x, float wo_y, int *r_sc_x, int *r_sc_y)
|
2008-01-07 18:03:41 +00:00
|
|
|
{
|
2014-03-16 03:24:05 +11:00
|
|
|
*r_sc_x = (wo_x - di->world_rect.xmin) * di->wo_to_sc[0];
|
|
|
|
*r_sc_y = (wo_y - di->world_rect.ymin) * di->wo_to_sc[1];
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
2013-04-03 15:04:24 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-26 14:11:39 -05:00
|
|
|
* Translate the \a world point from world coordinates into screen space.
|
2013-04-03 15:04:24 +00:00
|
|
|
*/
|
2015-05-08 07:25:39 +10:00
|
|
|
void gla2DDrawTranslatePtv(gla2DDrawInfo *di, float world[2], int r_screen[2])
|
2008-01-07 18:03:41 +00:00
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
screen_r[0] = (world[0] - di->world_rect.xmin) * di->wo_to_sc[0];
|
|
|
|
screen_r[1] = (world[1] - di->world_rect.ymin) * di->wo_to_sc[1];
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 15:04:24 +00:00
|
|
|
/**
|
2015-02-26 14:11:39 -05:00
|
|
|
* Restores the previous OpenGL state and frees the auxiliary gla data.
|
2013-04-03 15:04:24 +00:00
|
|
|
*/
|
2008-01-07 18:03:41 +00:00
|
|
|
void glaEnd2DDraw(gla2DDrawInfo *di)
|
|
|
|
{
|
|
|
|
glViewport(di->orig_vp[0], di->orig_vp[1], di->orig_vp[2], di->orig_vp[3]);
|
|
|
|
glScissor(di->orig_vp[0], di->orig_vp[1], di->orig_vp[2], di->orig_vp[3]);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadMatrixf(di->orig_projmat);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadMatrixf(di->orig_viewmat);
|
|
|
|
|
|
|
|
MEM_freeN(di);
|
|
|
|
}
|
2016-08-20 13:57:17 -04:00
|
|
|
|
|
|
|
#endif /* UNUSED */
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Uses current OpenGL state to get view matrices for gluProject/gluUnProject */
|
|
|
|
void bgl_get_mats(bglMats *mats)
|
|
|
|
{
|
2012-05-08 15:43:59 +00:00
|
|
|
const double badvalue = 1.0e-6;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
glGetDoublev(GL_MODELVIEW_MATRIX, mats->modelview);
|
|
|
|
glGetDoublev(GL_PROJECTION_MATRIX, mats->projection);
|
|
|
|
glGetIntegerv(GL_VIEWPORT, (GLint *)mats->viewport);
|
|
|
|
|
|
|
|
/* Very strange code here - it seems that certain bad values in the
|
2012-03-03 16:31:46 +00:00
|
|
|
* modelview matrix can cause gluUnProject to give bad results. */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mats->modelview[0] < badvalue &&
|
2012-04-28 06:31:57 +00:00
|
|
|
mats->modelview[0] > -badvalue)
|
|
|
|
{
|
|
|
|
mats->modelview[0] = 0;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mats->modelview[5] < badvalue &&
|
2012-04-28 06:31:57 +00:00
|
|
|
mats->modelview[5] > -badvalue)
|
|
|
|
{
|
|
|
|
mats->modelview[5] = 0;
|
|
|
|
}
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
/* Set up viewport so that gluUnProject will give correct values */
|
|
|
|
mats->viewport[0] = 0;
|
|
|
|
mats->viewport[1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *************** glPolygonOffset hack ************* */
|
|
|
|
|
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
|
|
|
{
|
2016-01-04 01:37:55 -05:00
|
|
|
static float winmat[16], offset = 0.0f;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (dist != 0.0f) {
|
2008-01-07 18:03:41 +00:00
|
|
|
float offs;
|
|
|
|
|
|
|
|
// glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
// glPolygonOffset(-1.0, -1.0);
|
|
|
|
|
|
|
|
/* hack below is to mimic polygon offset */
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glGetFloatv(GL_PROJECTION_MATRIX, (float *)winmat);
|
|
|
|
|
|
|
|
/* dist is from camera to center point */
|
|
|
|
|
2015-04-28 20:41:37 +02:00
|
|
|
if (winmat[15] > 0.5f) {
|
2015-04-29 06:08:45 +10:00
|
|
|
#if 1
|
2015-04-29 05:30:30 +10:00
|
|
|
offs = 0.00001f * dist * viewdist; // ortho tweaking
|
|
|
|
#else
|
|
|
|
static float depth_fac = 0.0f;
|
|
|
|
if (depth_fac == 0.0f) {
|
|
|
|
int depthbits;
|
|
|
|
glGetIntegerv(GL_DEPTH_BITS, &depthbits);
|
2015-04-29 05:36:39 +10:00
|
|
|
depth_fac = 1.0f / (float)((1 << depthbits) - 1);
|
2015-04-28 20:41:37 +02:00
|
|
|
}
|
2015-04-29 05:30:30 +10:00
|
|
|
offs = (-1.0 / winmat[10]) * dist * depth_fac;
|
2015-04-29 06:08:45 +10:00
|
|
|
|
|
|
|
UNUSED_VARS(viewdist);
|
2015-04-29 05:30:30 +10:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
2016-04-27 19:14:13 +10:00
|
|
|
/* This adjustment effectively results in reducing the Z value by 0.25%.
|
|
|
|
*
|
|
|
|
* winmat[14] actually evaluates to `-2 * far * near / (far - near)`,
|
|
|
|
* is very close to -0.2 with default clip range, and is used as the coefficient multiplied by `w / z`,
|
|
|
|
* thus controlling the z dependent part of the depth value.
|
|
|
|
*/
|
|
|
|
offs = winmat[14] * -0.0025f * dist;
|
2015-04-28 20:41:37 +02:00
|
|
|
}
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2012-05-08 15:43:59 +00:00
|
|
|
winmat[14] -= offs;
|
|
|
|
offset += offs;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
glLoadMatrixf(winmat);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
2012-05-08 15:43:59 +00:00
|
|
|
winmat[14] += offset;
|
|
|
|
offset = 0.0;
|
2008-01-07 18:03:41 +00:00
|
|
|
glLoadMatrixf(winmat);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 */
|
2016-05-06 16:54:07 +02:00
|
|
|
void glaDrawImBuf_glsl_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)
|
2013-04-02 17:28:37 +00:00
|
|
|
{
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
bool force_fallback = false;
|
2013-04-02 17:28:37 +00:00
|
|
|
bool need_fallback = true;
|
|
|
|
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
/* Early out */
|
|
|
|
if (ibuf->rect == NULL && ibuf->rect_float == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Single channel images could not be transformed using GLSL yet */
|
2013-04-25 12:02:56 +00:00
|
|
|
force_fallback |= ibuf->channels == 1;
|
2013-04-03 09:08:02 +00:00
|
|
|
|
2013-04-12 10:52:47 +00:00
|
|
|
/* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */
|
2013-04-29 15:50:12 +00:00
|
|
|
force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL);
|
2013-04-12 10:52:47 +00:00
|
|
|
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
/* Try to draw buffer using GLSL display transform */
|
|
|
|
if (force_fallback == false) {
|
|
|
|
int ok;
|
|
|
|
|
2013-04-04 12:20:13 +00:00
|
|
|
if (ibuf->rect_float) {
|
|
|
|
if (ibuf->float_colorspace) {
|
|
|
|
ok = IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings,
|
2013-12-13 12:36:45 +06:00
|
|
|
ibuf->float_colorspace,
|
|
|
|
ibuf->dither, true);
|
2013-04-04 12:20:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-12-13 12:36:45 +06:00
|
|
|
ok = IMB_colormanagement_setup_glsl_draw(view_settings, display_settings,
|
|
|
|
ibuf->dither, true);
|
2013-04-04 12:20:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok = IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings,
|
2013-12-13 12:36:45 +06:00
|
|
|
ibuf->rect_colorspace,
|
|
|
|
ibuf->dither, false);
|
2013-04-04 12:20:13 +00:00
|
|
|
}
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
|
|
|
|
if (ok) {
|
2013-04-02 17:28:37 +00:00
|
|
|
glColor4f(1.0, 1.0, 1.0, 1.0);
|
|
|
|
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
if (ibuf->rect_float) {
|
2013-04-03 16:21:14 +00:00
|
|
|
int format = 0;
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
|
|
|
|
if (ibuf->channels == 3)
|
|
|
|
format = GL_RGB;
|
|
|
|
else if (ibuf->channels == 4)
|
|
|
|
format = GL_RGBA;
|
|
|
|
else
|
|
|
|
BLI_assert(!"Incompatible number of channels for GLSL display");
|
|
|
|
|
2013-04-03 16:21:14 +00:00
|
|
|
if (format != 0) {
|
2016-05-06 16:54:07 +02:00
|
|
|
glaDrawPixelsTex_clipping(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);
|
2013-04-03 16:21:14 +00:00
|
|
|
}
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
}
|
|
|
|
else if (ibuf->rect) {
|
|
|
|
/* ibuf->rect is always RGBA */
|
2016-05-06 16:54:07 +02:00
|
|
|
glaDrawPixelsTex_clipping(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);
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
}
|
2013-04-02 17:28:37 +00:00
|
|
|
|
|
|
|
IMB_colormanagement_finish_glsl_draw();
|
|
|
|
|
|
|
|
need_fallback = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
|
|
|
/* In case GLSL failed or not usable, fallback to glaDrawPixelsAuto */
|
2013-04-02 17:28:37 +00:00
|
|
|
if (need_fallback) {
|
|
|
|
unsigned char *display_buffer;
|
|
|
|
void *cache_handle;
|
|
|
|
|
2013-04-04 12:20:13 +00:00
|
|
|
display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle);
|
2013-04-02 17:28:37 +00:00
|
|
|
|
2016-05-06 16:54:07 +02:00
|
|
|
if (display_buffer) {
|
|
|
|
glaDrawPixelsAuto_clipping(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);
|
|
|
|
}
|
2013-04-02 17:28:37 +00:00
|
|
|
|
|
|
|
IMB_display_buffer_release(cache_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 16:54:07 +02:00
|
|
|
void glaDrawImBuf_glsl(ImBuf *ibuf, float x, float y, int zoomfilter,
|
|
|
|
ColorManagedViewSettings *view_settings,
|
|
|
|
ColorManagedDisplaySettings *display_settings)
|
|
|
|
{
|
|
|
|
glaDrawImBuf_glsl_clipping(ibuf, x, y, zoomfilter, view_settings, display_settings,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void glaDrawImBuf_glsl_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)
|
2013-04-04 12:20:13 +00:00
|
|
|
{
|
|
|
|
ColorManagedViewSettings *view_settings;
|
|
|
|
ColorManagedDisplaySettings *display_settings;
|
|
|
|
|
|
|
|
IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings);
|
|
|
|
|
2016-05-06 16:54:07 +02:00
|
|
|
glaDrawImBuf_glsl_clipping(ibuf, x, y, zoomfilter, view_settings, display_settings,
|
|
|
|
clip_min_x, clip_min_y, clip_max_x, clip_max_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void glaDrawImBuf_glsl_ctx(const bContext *C, ImBuf *ibuf, float x, float y, int zoomfilter)
|
|
|
|
{
|
|
|
|
glaDrawImBuf_glsl_ctx_clipping(C, ibuf, x, y, zoomfilter, 0.0f, 0.0f, 0.0f, 0.0f);
|
2013-04-04 12:20:13 +00:00
|
|
|
}
|
2013-12-01 14:30:22 +11:00
|
|
|
|
|
|
|
void cpack(unsigned int x)
|
|
|
|
{
|
2015-02-07 04:33:48 +11:00
|
|
|
glColor3ub(( (x) & 0xFF),
|
|
|
|
(((x) >> 8) & 0xFF),
|
|
|
|
(((x) >> 16) & 0xFF));
|
2013-12-01 14:30:22 +11:00
|
|
|
}
|
2014-06-05 20:05:41 +06:00
|
|
|
|
|
|
|
void glaDrawBorderCorners(const rcti *border, float zoomx, float zoomy)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex2f(border->xmin, border->ymin + delta_y);
|
|
|
|
glVertex2f(border->xmin, border->ymin);
|
|
|
|
glVertex2f(border->xmin + delta_x, border->ymin);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
/* left top corner */
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex2f(border->xmin, border->ymax - delta_y);
|
|
|
|
glVertex2f(border->xmin, border->ymax);
|
|
|
|
glVertex2f(border->xmin + delta_x, border->ymax);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
/* right bottom corner */
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex2f(border->xmax - delta_x, border->ymin);
|
|
|
|
glVertex2f(border->xmax, border->ymin);
|
|
|
|
glVertex2f(border->xmax, border->ymin + delta_y);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
/* right top corner */
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex2f(border->xmax - delta_x, border->ymax);
|
|
|
|
glVertex2f(border->xmax, border->ymax);
|
|
|
|
glVertex2f(border->xmax, border->ymax - delta_y);
|
|
|
|
glEnd();
|
|
|
|
}
|