2008-01-01 15:53:38 +00:00
|
|
|
/**
|
|
|
|
* $Id: mywindow.c 9584 2007-01-03 13:45:03Z ton $
|
|
|
|
*
|
|
|
|
* ***** 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,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): 2007 Blender Foundation (refactor)
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Subwindow opengl handling.
|
|
|
|
* BTW: subwindows open/close in X11 are way too slow, tried it, and choose for my own system... (ton)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_arithb.h"
|
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "BKE_context.h"
|
2008-01-01 15:53:38 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
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
|
|
|
#include "wm_subwindow.h"
|
2008-01-01 15:53:38 +00:00
|
|
|
#include "wm_window.h"
|
|
|
|
|
|
|
|
/* wmSubWindow stored in wmWindow... but not exposed outside this C file */
|
|
|
|
/* it seems a bit redundant (area regions can store it too, but we keep it
|
|
|
|
because we can store all kind of future opengl fanciness here */
|
|
|
|
|
|
|
|
/* we use indices and array because:
|
|
|
|
- index has safety, no pointers from this C file hanging around
|
|
|
|
- fast lookups of indices with array, list would give overhead
|
|
|
|
- old code used it this way...
|
|
|
|
- keep option open to have 2 screens using same window
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct wmSubWindow {
|
|
|
|
struct wmSubWindow *next, *prev;
|
|
|
|
|
|
|
|
rcti winrct;
|
|
|
|
int swinid;
|
|
|
|
|
|
|
|
float viewmat[4][4], winmat[4][4];
|
|
|
|
} wmSubWindow;
|
|
|
|
|
|
|
|
|
|
|
|
/* ******************* open, free, set, get data ******************** */
|
|
|
|
|
|
|
|
/* not subwindow itself */
|
|
|
|
static void wm_subwindow_free(wmSubWindow *swin)
|
|
|
|
{
|
|
|
|
/* future fancy stuff */
|
|
|
|
}
|
|
|
|
|
|
|
|
void wm_subwindows_free(wmWindow *win)
|
|
|
|
{
|
|
|
|
wmSubWindow *swin;
|
|
|
|
|
|
|
|
for(swin= win->subwindows.first; swin; swin= swin->next)
|
|
|
|
wm_subwindow_free(swin);
|
|
|
|
|
|
|
|
BLI_freelistN(&win->subwindows);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int wm_subwindow_get(wmWindow *win)
|
|
|
|
{
|
|
|
|
if(win->curswin)
|
|
|
|
return win->curswin->swinid;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static wmSubWindow *swin_from_swinid(wmWindow *win, int swinid)
|
|
|
|
{
|
|
|
|
wmSubWindow *swin;
|
|
|
|
|
|
|
|
for(swin= win->subwindows.first; swin; swin= swin->next)
|
|
|
|
if(swin->swinid==swinid)
|
|
|
|
break;
|
|
|
|
return swin;
|
|
|
|
}
|
|
|
|
|
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 wm_subwindow_getsize(wmWindow *win, int swinid, int *x, int *y)
|
|
|
|
{
|
|
|
|
wmSubWindow *swin= swin_from_swinid(win, swinid);
|
|
|
|
|
|
|
|
if(swin) {
|
|
|
|
*x= swin->winrct.xmax - swin->winrct.xmin + 1;
|
|
|
|
*y= swin->winrct.ymax - swin->winrct.ymin + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wm_subwindow_getorigin(wmWindow *win, int swinid, int *x, int *y)
|
|
|
|
{
|
|
|
|
wmSubWindow *swin= swin_from_swinid(win, swinid);
|
|
|
|
|
|
|
|
if(swin) {
|
|
|
|
*x= swin->winrct.xmin;
|
|
|
|
*y= swin->winrct.ymin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wm_subwindow_getmatrix(wmWindow *win, int swinid, float mat[][4])
|
|
|
|
{
|
|
|
|
wmSubWindow *swin= swin_from_swinid(win, swinid);
|
|
|
|
|
|
|
|
if(swin)
|
|
|
|
Mat4MulMat4(mat, swin->viewmat, swin->winmat);
|
|
|
|
}
|
|
|
|
|
2008-01-01 15:53:38 +00:00
|
|
|
/* always sets pixel-precise 2D window/view matrices */
|
|
|
|
/* coords is in whole pixels. xmin = 15, xmax= 16: means window is 2 pix big */
|
|
|
|
int wm_subwindow_open(wmWindow *win, rcti *winrct)
|
|
|
|
{
|
|
|
|
wmSubWindow *swin;
|
|
|
|
int width, height;
|
|
|
|
int freewinid= 1;
|
|
|
|
|
|
|
|
for(swin= win->subwindows.first; swin; swin= swin->next)
|
|
|
|
if(freewinid <= swin->swinid)
|
|
|
|
freewinid= swin->swinid+1;
|
|
|
|
|
|
|
|
win->curswin= swin= MEM_callocN(sizeof(wmSubWindow), "swinopen");
|
2008-01-07 18:03:41 +00:00
|
|
|
BLI_addtail(&win->subwindows, swin);
|
|
|
|
|
2.5 Branch
==========
* Changed wmOperatorType, removing init/exit callbacks and adding cancel
callback, removed default storage in favor of properties. Defined return
values for exec/invoke/modal/cancel.
* Don't allocate operator on the stack, and removed operator copy for
handlers. Now it frees based on return values from callbacks, and just
keeps a wmOperator on the heap. Also it now registers after the operator
is fully finished, to get the correct final properties.
* Changed OP_get_* functions to return 1 if the property is found and 0
otherwise, gives more readable code in my opinion. Added OP_verify_*
functions to quickly check if the property is available and set if it's
not, that's common for exec/invoke.
* Removed WM_operatortypelist_append in favor of WM_operatortype_append
which takes a function pointer instead of a list, avoids macro's and
duplicating code.
* Fix a crash where the handler would still be used while it was freed by
the operator.
* Spacetypes now have operatortypes() and keymap() callbacks to abstract
them a bit more.
* Renamed C->curarea to C->area for consistency. Removed View3D/View2D/
SpaceIpo from bContext, seems bad to keep these.
* Set context variables like window/screen/area/region to NULL again when
leaving that context, instead of leaving the pointers there.
* Added if(G.f & G_DEBUG) for many of the prints, makes output a bit
cleaner and easier to debug.
* Fixed priority of the editors/interface module in scons, would otherwise
give link errors.
* Added start of generic view2d api.
* Added space_time with some basic drawing and a single operator to change
the frame.
2008-06-11 10:10:31 +00:00
|
|
|
if(G.f & G_DEBUG) printf("swin %d added\n", freewinid);
|
2008-01-01 15:53:38 +00:00
|
|
|
swin->swinid= freewinid;
|
|
|
|
swin->winrct= *winrct;
|
|
|
|
|
|
|
|
Mat4One(swin->viewmat);
|
|
|
|
Mat4One(swin->winmat);
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
/* and we appy it all right away */
|
2008-12-19 14:14:43 +00:00
|
|
|
wmSubWindowSet(win, swin->swinid);
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2008-01-01 15:53:38 +00:00
|
|
|
/* extra service */
|
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
|
|
|
wm_subwindow_getsize(win, swin->swinid, &width, &height);
|
2008-12-19 14:14:43 +00:00
|
|
|
wmOrtho2(-0.375, (float)width-0.375, -0.375, (float)height-0.375);
|
|
|
|
wmLoadIdentity();
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
return swin->swinid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wm_subwindow_close(wmWindow *win, int swinid)
|
|
|
|
{
|
|
|
|
wmSubWindow *swin= swin_from_swinid(win, swinid);
|
|
|
|
|
|
|
|
if (swin) {
|
|
|
|
if (swin==win->curswin)
|
|
|
|
win->curswin= NULL;
|
|
|
|
wm_subwindow_free(swin);
|
|
|
|
BLI_remlink(&win->subwindows, swin);
|
|
|
|
MEM_freeN(swin);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("wm_subwindow_close: Internal error, bad winid: %d\n", swinid);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pixels go from 0-99 for a 100 pixel window */
|
|
|
|
void wm_subwindow_position(wmWindow *win, int swinid, rcti *winrct)
|
|
|
|
{
|
|
|
|
wmSubWindow *swin= swin_from_swinid(win, swinid);
|
|
|
|
|
|
|
|
if(swin) {
|
2008-01-07 18:03:41 +00:00
|
|
|
int width, height;
|
|
|
|
|
2008-01-01 15:53:38 +00:00
|
|
|
swin->winrct= *winrct;
|
|
|
|
|
|
|
|
/* CRITICAL, this clamping ensures that
|
|
|
|
* the viewport never goes outside the screen
|
|
|
|
* edges (assuming the x, y coords aren't
|
|
|
|
* outside). This caused a hardware lock
|
|
|
|
* on Matrox cards if it happens.
|
|
|
|
*
|
|
|
|
* Really Blender should never _ever_ try
|
|
|
|
* to do such a thing, but just to be safe
|
|
|
|
* clamp it anyway (or fix the bScreen
|
|
|
|
* scaling routine, and be damn sure you
|
|
|
|
* fixed it). - zr (2001!)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (swin->winrct.xmax >= win->sizex)
|
|
|
|
swin->winrct.xmax= win->sizex-1;
|
|
|
|
if (swin->winrct.ymax >= win->sizey)
|
|
|
|
swin->winrct.ymax= win->sizey-1;
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
/* extra service */
|
2008-12-19 14:14:43 +00:00
|
|
|
wmSubWindowSet(win, swinid);
|
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
|
|
|
wm_subwindow_getsize(win, swinid, &width, &height);
|
2008-12-19 14:14:43 +00:00
|
|
|
wmOrtho2(-0.375, (float)width-0.375, -0.375, (float)height-0.375);
|
2008-01-01 15:53:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("wm_subwindow_position: Internal error, bad winid: %d\n", swinid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------- WM versions of OpenGL calls, using glBlah() syntax ------------------------ */
|
|
|
|
/* ----------------- exported in WM_api.h ------------------------------------------------------ */
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
/* internal state, no threaded opengl! XXX */
|
|
|
|
static wmWindow *_curwindow= NULL;
|
|
|
|
static wmSubWindow *_curswin= NULL;
|
2008-01-01 15:53:38 +00:00
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
/* enable the WM versions of opengl calls */
|
|
|
|
void wmSubWindowSet(wmWindow *win, int swinid)
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
2008-12-19 14:14:43 +00:00
|
|
|
int width, height;
|
2008-12-19 17:59:54 +00:00
|
|
|
_curswin= swin_from_swinid(win, swinid);
|
2008-12-19 14:14:43 +00:00
|
|
|
|
|
|
|
if(_curswin==NULL) {
|
|
|
|
printf("wmSubWindowSet %d: doesn't exist\n", swinid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
win->curswin= _curswin;
|
|
|
|
_curwindow= win;
|
|
|
|
|
|
|
|
width= _curswin->winrct.xmax - _curswin->winrct.xmin + 1;
|
|
|
|
height= _curswin->winrct.ymax - _curswin->winrct.ymin + 1;
|
|
|
|
glViewport(_curswin->winrct.xmin, _curswin->winrct.ymin, width, height);
|
|
|
|
glScissor(_curswin->winrct.xmin, _curswin->winrct.ymin, width, height);
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadMatrixf(&_curswin->winmat[0][0]);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadMatrixf(&_curswin->viewmat[0][0]);
|
|
|
|
|
|
|
|
glFlush();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void wmLoadMatrix(float mat[][4])
|
|
|
|
{
|
|
|
|
if(_curswin==NULL) return;
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
glLoadMatrixf(mat);
|
|
|
|
|
|
|
|
if (glaGetOneInteger(GL_MATRIX_MODE)==GL_MODELVIEW)
|
2008-12-19 14:14:43 +00:00
|
|
|
Mat4CpyMat4(_curswin->viewmat, mat);
|
2008-01-01 15:53:38 +00:00
|
|
|
else
|
2008-12-19 14:14:43 +00:00
|
|
|
Mat4CpyMat4(_curswin->winmat, mat);
|
2008-01-01 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
void wmGetMatrix(float mat[][4])
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
2008-12-19 14:14:43 +00:00
|
|
|
if(_curswin==NULL) return;
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
if (glaGetOneInteger(GL_MATRIX_MODE)==GL_MODELVIEW) {
|
2008-12-19 14:14:43 +00:00
|
|
|
Mat4CpyMat4(mat, _curswin->viewmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
} else {
|
2008-12-19 14:14:43 +00:00
|
|
|
Mat4CpyMat4(mat, _curswin->winmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
void wmMultMatrix(float mat[][4])
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
2008-12-19 14:14:43 +00:00
|
|
|
if(_curswin==NULL) return;
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
glMultMatrixf((float*) mat);
|
|
|
|
|
|
|
|
if (glaGetOneInteger(GL_MATRIX_MODE)==GL_MODELVIEW)
|
2008-12-19 14:14:43 +00:00
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, (float *)_curswin->viewmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
else
|
2008-12-19 14:14:43 +00:00
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, (float *)_curswin->winmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
void wmGetSingleMatrix(float mat[][4])
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
2008-12-19 14:14:43 +00:00
|
|
|
if(_curswin)
|
|
|
|
Mat4MulMat4(mat, _curswin->viewmat, _curswin->winmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
void wmScale(float x, float y, float z)
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
2008-12-19 14:14:43 +00:00
|
|
|
if(_curswin==NULL) return;
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
glScalef(x, y, z);
|
|
|
|
|
|
|
|
if (glaGetOneInteger(GL_MATRIX_MODE)==GL_MODELVIEW)
|
2008-12-19 14:14:43 +00:00
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, (float *)_curswin->viewmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
else
|
2008-12-19 14:14:43 +00:00
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, (float *)_curswin->winmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
void wmLoadIdentity(void)
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
2008-12-19 14:14:43 +00:00
|
|
|
if(_curswin==NULL) return;
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
if (glaGetOneInteger(GL_MATRIX_MODE)==GL_MODELVIEW)
|
2008-12-19 14:14:43 +00:00
|
|
|
Mat4One(_curswin->viewmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
else
|
2008-12-19 14:14:43 +00:00
|
|
|
Mat4One(_curswin->winmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
glLoadIdentity();
|
|
|
|
}
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
void wmFrustum(float x1, float x2, float y1, float y2, float n, float f)
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
2008-12-19 14:14:43 +00:00
|
|
|
if(_curswin) {
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glFrustum(x1, x2, y1, y2, n, f);
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
glGetFloatv(GL_PROJECTION_MATRIX, (float *)_curswin->winmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
void wmOrtho(float x1, float x2, float y1, float y2, float n, float f)
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
2008-12-19 14:14:43 +00:00
|
|
|
if(_curswin) {
|
2008-01-01 15:53:38 +00:00
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glOrtho(x1, x2, y1, y2, n, f);
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
glGetFloatv(GL_PROJECTION_MATRIX, (float *)_curswin->winmat);
|
2008-01-01 15:53:38 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-19 14:14:43 +00:00
|
|
|
void wmOrtho2(float x1, float x2, float y1, float y2)
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
|
|
|
/* prevent opengl from generating errors */
|
|
|
|
if(x1==x2) x2+=1.0;
|
|
|
|
if(y1==y2) y2+=1.0;
|
2008-12-19 14:14:43 +00:00
|
|
|
wmOrtho(x1, x2, y1, y2, -100, 100);
|
2008-01-01 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* *************************** Framebuffer color depth, for selection codes ********************** */
|
|
|
|
|
|
|
|
static int wm_get_colordepth(void)
|
|
|
|
{
|
|
|
|
static int mainwin_color_depth= 0;
|
|
|
|
|
|
|
|
if(mainwin_color_depth==0) {
|
|
|
|
GLint r, g, b;
|
|
|
|
|
|
|
|
glGetIntegerv(GL_RED_BITS, &r);
|
|
|
|
glGetIntegerv(GL_GREEN_BITS, &g);
|
|
|
|
glGetIntegerv(GL_BLUE_BITS, &b);
|
|
|
|
|
|
|
|
mainwin_color_depth= r + g + b;
|
|
|
|
if(G.f & G_DEBUG) {
|
|
|
|
printf("Color depth r %d g %d b %d\n", (int)r, (int)g, (int)b);
|
|
|
|
glGetIntegerv(GL_AUX_BUFFERS, &r);
|
|
|
|
printf("Aux buffers: %d\n", (int)r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mainwin_color_depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
|
|
|
/* apple seems to round colors to below and up on some configs */
|
|
|
|
|
|
|
|
static unsigned int index_to_framebuffer(int index)
|
|
|
|
{
|
|
|
|
unsigned int i= index;
|
|
|
|
|
|
|
|
switch(wm_get_colordepth()) {
|
|
|
|
case 12:
|
|
|
|
i= ((i & 0xF00)<<12) + ((i & 0xF0)<<8) + ((i & 0xF)<<4);
|
|
|
|
/* sometimes dithering subtracts! */
|
|
|
|
i |= 0x070707;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
case 16:
|
|
|
|
i= ((i & 0x7C00)<<9) + ((i & 0x3E0)<<6) + ((i & 0x1F)<<3);
|
|
|
|
i |= 0x030303;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
break;
|
|
|
|
default: // 18 bits...
|
|
|
|
i= ((i & 0x3F000)<<6) + ((i & 0xFC0)<<4) + ((i & 0x3F)<<2);
|
|
|
|
i |= 0x010101;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* this is the old method as being in use for ages.... seems to work? colors are rounded to lower values */
|
|
|
|
|
|
|
|
static unsigned int index_to_framebuffer(int index)
|
|
|
|
{
|
|
|
|
unsigned int i= index;
|
|
|
|
|
|
|
|
switch(wm_get_colordepth()) {
|
|
|
|
case 8:
|
|
|
|
i= ((i & 48)<<18) + ((i & 12)<<12) + ((i & 3)<<6);
|
|
|
|
i |= 0x3F3F3F;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
i= ((i & 0xF00)<<12) + ((i & 0xF0)<<8) + ((i & 0xF)<<4);
|
|
|
|
/* sometimes dithering subtracts! */
|
|
|
|
i |= 0x0F0F0F;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
case 16:
|
|
|
|
i= ((i & 0x7C00)<<9) + ((i & 0x3E0)<<6) + ((i & 0x1F)<<3);
|
|
|
|
i |= 0x070707;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
break;
|
|
|
|
default: // 18 bits...
|
|
|
|
i= ((i & 0x3F000)<<6) + ((i & 0xFC0)<<4) + ((i & 0x3F)<<2);
|
|
|
|
i |= 0x030303;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-12-19 12:14:58 +00:00
|
|
|
void WM_set_framebuffer_index_color(int index)
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
|
|
|
cpack(index_to_framebuffer(index));
|
|
|
|
}
|
|
|
|
|
2008-12-30 13:16:14 +00:00
|
|
|
int WM_framebuffer_to_index(unsigned int col)
|
2008-01-01 15:53:38 +00:00
|
|
|
{
|
|
|
|
if (col==0) return 0;
|
|
|
|
|
|
|
|
switch(wm_get_colordepth()) {
|
|
|
|
case 8:
|
|
|
|
return ((col & 0xC00000)>>18) + ((col & 0xC000)>>12) + ((col & 0xC0)>>6);
|
|
|
|
case 12:
|
|
|
|
return ((col & 0xF00000)>>12) + ((col & 0xF000)>>8) + ((col & 0xF0)>>4);
|
|
|
|
case 15:
|
|
|
|
case 16:
|
|
|
|
return ((col & 0xF80000)>>9) + ((col & 0xF800)>>6) + ((col & 0xF8)>>3);
|
|
|
|
case 24:
|
|
|
|
return col & 0xFFFFFF;
|
|
|
|
default: // 18 bits...
|
|
|
|
return ((col & 0xFC0000)>>6) + ((col & 0xFC00)>>4) + ((col & 0xFC)>>2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ********** END MY WINDOW ************** */
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
static int is_a_really_crappy_nvidia_card(void) {
|
|
|
|
static int well_is_it= -1;
|
|
|
|
|
|
|
|
/* Do you understand the implication? Do you? */
|
|
|
|
if (well_is_it==-1)
|
|
|
|
well_is_it= (strcmp((char*) glGetString(GL_VENDOR), "NVIDIA Corporation") == 0);
|
|
|
|
|
|
|
|
return well_is_it;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|