1
0
Fork 0
forked from fte/fteqw

Does that fix mac gamma? (can't test this stuff)

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3263 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2009-07-12 15:26:47 +00:00
parent 942af209a7
commit 27fddffedb

View file

@ -1,239 +1,241 @@
/* /*
Copyright (C) 2001-2002 A Nourai Copyright (C) 2001-2002 A Nourai
Copyright (C) 2006 Jacek Piszczek (Mac OSX port) Copyright (C) 2006 Jacek Piszczek (Mac OSX port)
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the included (GNU.txt) GNU General Public License for more details. See the included (GNU.txt) GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "quakedef.h" #include "quakedef.h"
#include "glquake.h" #include "glquake.h"
#include <dlfcn.h> #include <dlfcn.h>
//#include "vid_macos.h" //#include "vid_macos.h"
#define WARP_WIDTH 320 #define WARP_WIDTH 320
#define WARP_HEIGHT 200 #define WARP_HEIGHT 200
// note: cocoa code is separated in vid_cocoa.m because of compilation pbs // note: cocoa code is separated in vid_cocoa.m because of compilation pbs
static qboolean vid_hwgamma_enabled = false; static qboolean vid_hwgamma_enabled = false;
cvar_t in_xflip = SCVAR("in_xflip", "0"); cvar_t in_xflip = SCVAR("in_xflip", "0");
static int real_width, real_height; static int real_width, real_height;
static void *agllibrary; static void *agllibrary;
static void *opengllibrary; static void *opengllibrary;
void *AGL_GetProcAddress(char *functionname) void *AGL_GetProcAddress(char *functionname)
{ {
void *func; void *func;
if (agllibrary) if (agllibrary)
{ {
func = dlsym(agllibrary, functionname); func = dlsym(agllibrary, functionname);
if (func) if (func)
return func; return func;
} }
if (opengllibrary) if (opengllibrary)
{ {
func = dlsym(opengllibrary, functionname); func = dlsym(opengllibrary, functionname);
if (func) if (func)
return func; return func;
} }
return NULL; return NULL;
} }
qboolean GLVID_Init(rendererstate_t *info, unsigned char *palette) qboolean GLVID_Init(rendererstate_t *info, unsigned char *palette)
{ {
int argnum; int argnum;
int i; int i;
agllibrary = dlopen("/System/Library/Frameworks/AGL.framework/AGL", RTLD_LAZY); agllibrary = dlopen("/System/Library/Frameworks/AGL.framework/AGL", RTLD_LAZY);
if (!agllibrary) if (!agllibrary)
{ {
Con_Printf("Couldn't load AGL framework\n"); Con_Printf("Couldn't load AGL framework\n");
return false; return false;
} }
opengllibrary = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY); opengllibrary = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY);
//don't care if opengl failed. //don't care if opengl failed.
vid.width = info->width; vid.width = info->width;
vid.height = info->height; vid.height = info->height;
vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT; vid.maxwarpheight = WARP_HEIGHT;
vid.numpages = 2; vid.numpages = 2;
vid.colormap = host_colormap; vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
// initialise the NSApplication and the screen // initialise the NSApplication and the screen
initCocoa(info); initCocoa(info);
// initCocoa stores current screen size in vid // initCocoa stores current screen size in vid
real_width = vid.width; real_width = vid.width;
real_height = vid.height; real_height = vid.height;
// calculate the conwidth AFTER the screen has been opened // calculate the conwidth AFTER the screen has been opened
if (vid.width <= 640) if (vid.width <= 640)
{ {
vid.conwidth = vid.width; vid.conwidth = vid.width;
vid.conheight = vid.height; vid.conheight = vid.height;
} }
else else
{ {
vid.conwidth = vid.width/2; vid.conwidth = vid.width/2;
vid.conheight = vid.height/2; vid.conheight = vid.height/2;
} }
if ((i = COM_CheckParm("-conwidth")) && i + 1 < com_argc) if ((i = COM_CheckParm("-conwidth")) && i + 1 < com_argc)
{ {
vid.conwidth = Q_atoi(com_argv[i + 1]); vid.conwidth = Q_atoi(com_argv[i + 1]);
// pick a conheight that matches with correct aspect // pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4; vid.conheight = vid.conwidth * 3 / 4;
} }
vid.conwidth &= 0xfff8; // make it a multiple of eight vid.conwidth &= 0xfff8; // make it a multiple of eight
if ((i = COM_CheckParm("-conheight")) && i + 1 < com_argc) if ((i = COM_CheckParm("-conheight")) && i + 1 < com_argc)
vid.conheight = Q_atoi(com_argv[i + 1]); vid.conheight = Q_atoi(com_argv[i + 1]);
if (vid.conwidth < 320) if (vid.conwidth < 320)
vid.conwidth = 320; vid.conwidth = 320;
if (vid.conheight < 200) if (vid.conheight < 200)
vid.conheight = 200; vid.conheight = 200;
vid.rowbytes = vid.width; vid.rowbytes = vid.width;
vid.direct = 0; /* Isn't used anywhere, but whatever. */ vid.direct = 0; /* Isn't used anywhere, but whatever. */
vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0); vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
if (vid.conheight > vid.height) if (vid.conheight > vid.height)
vid.conheight = vid.height; vid.conheight = vid.height;
if (vid.conwidth > vid.width) if (vid.conwidth > vid.width)
vid.conwidth = vid.width; vid.conwidth = vid.width;
vid.width = vid.conwidth; vid.width = vid.conwidth;
vid.height = vid.conheight; vid.height = vid.conheight;
GL_Init(AGL_GetProcAddress); GL_Init(AGL_GetProcAddress);
GLVID_SetPalette(palette); GLVID_SetPalette(palette);
vid.recalc_refdef = 1; vid.recalc_refdef = 1;
return true; return true;
} }
void GLVID_DeInit(void) void GLVID_DeInit(void)
{ {
killCocoa(); killCocoa();
} }
void GL_DoSwap(void) void GL_DoSwap(void)
{ {
} }
void GLVID_ForceLockState(int i) void GLVID_ForceLockState(int i)
{ {
} }
int GLVID_ForceUnlockedAndReturnState(void) int GLVID_ForceUnlockedAndReturnState(void)
{ {
return 0; return 0;
} }
void GLVID_SetPalette (unsigned char *palette) void GLVID_SetPalette (unsigned char *palette)
{ {
qbyte *pal; qbyte *pal;
unsigned int r,g,b; unsigned int r,g,b;
int i; int i;
unsigned *table1; unsigned *table1;
unsigned *table2; unsigned *table2;
extern qbyte gammatable[256]; extern qbyte gammatable[256];
Con_Printf("Converting 8to24\n"); Con_Printf("Converting 8to24\n");
pal = palette; pal = palette;
table1 = d_8to24rgbtable; table1 = d_8to24rgbtable;
table2 = d_8to24bgrtable; table2 = d_8to24bgrtable;
for (i=0 ; i<256 ; i++) for (i=0 ; i<256 ; i++)
{ {
r = gammatable[pal[0]]; r = gammatable[pal[0]];
g = gammatable[pal[1]]; g = gammatable[pal[1]];
b = gammatable[pal[2]]; b = gammatable[pal[2]];
pal += 3; pal += 3;
*table1++ = LittleLong((255<<24) + (r<<0) + (g<<8) + (b<<16)); *table1++ = LittleLong((255<<24) + (r<<0) + (g<<8) + (b<<16));
*table2++ = LittleLong((255<<24) + (r<<16) + (g<<8) + (b<<0)); *table2++ = LittleLong((255<<24) + (r<<16) + (g<<8) + (b<<0));
} }
d_8to24bgrtable[255] &= LittleLong(0xffffff); // 255 is transparent d_8to24bgrtable[255] &= LittleLong(0xffffff); // 255 is transparent
d_8to24rgbtable[255] &= LittleLong(0xffffff); // 255 is transparent d_8to24rgbtable[255] &= LittleLong(0xffffff); // 255 is transparent
Con_Printf("Converted\n"); Con_Printf("Converted\n");
} }
void GLVID_ShiftPalette(unsigned char *p) void Sys_SendKeyEvents(void)
{ {
// GLVID_SetPalette(p); }
}
void GLVID_LockBuffer(void)
void Sys_SendKeyEvents(void) {
{ }
}
void GLVID_UnlockBuffer(void)
void GLVID_LockBuffer(void) {
{ }
}
qboolean GLVID_IsLocked(void)
void GLVID_UnlockBuffer(void) {
{ return 0;
} }
qboolean GLVID_IsLocked(void) void GLD_BeginDirectRect(int x, int y, qbyte *pbitmap, int width, int height)
{ {
return 0; }
}
void GLD_EndDirectRect(int x, int y, int width, int height)
void GLD_BeginDirectRect(int x, int y, qbyte *pbitmap, int width, int height) {
{ }
}
void GLVID_SetCaption(char *text)
void GLD_EndDirectRect(int x, int y, int width, int height) {
{ }
}
void GL_BeginRendering (int *x, int *y, int *width, int *height)
void GLVID_SetCaption(char *text) {
{ *x = *y = 0;
} *width = real_width;
*height = real_height;
void GL_BeginRendering (int *x, int *y, int *width, int *height) }
{
*x = *y = 0; void GL_EndRendering(void)
*width = real_width; {
*height = real_height; flushCocoa();
} }
void GL_EndRendering(void) void GLVID_SetDeviceGammaRamp(unsigned short *ramps)
{ {
flushCocoa(); cocoaGamma(ramps,ramps+256,ramps+512);
} }
void GLVID_SetDeviceGammaRamp(unsigned short *ramps) void GLVID_ShiftPalette(unsigned char *p)
{ {
cocoaGamma(ramps,ramps+256,ramps+512); extern unsigned short ramps[3][256];
} GLVID_SetDeviceGammaRamp(ramps);
}