Merge pull request #33 from espes/glo-cleanup

remove gloffscreen format flags
This commit is contained in:
espes 2015-08-17 11:59:41 +10:00
commit 5bfdab5b5b
6 changed files with 17 additions and 134 deletions

View File

@ -43,27 +43,6 @@
struct _GloContext;
typedef struct _GloContext GloContext;
/* Format flags for glo_surface_create */
#define GLO_FF_ALPHA_MASK (0x0001)
#define GLO_FF_NOALPHA (0x0000)
#define GLO_FF_ALPHA (0x0001)
#define GLO_FF_BITS_MASK (0x00F0)
#define GLO_FF_BITS_16 (0x0020)
#define GLO_FF_BITS_24 (0x0030)
#define GLO_FF_BITS_32 (0x0040)
#define GLO_FF_DEPTH_MASK (0x0F00)
#define GLO_FF_DEPTH_16 (0x0100)
#define GLO_FF_DEPTH_24 (0x0200)
#define GLO_FF_DEPTH_32 (0x0300)
#define GLO_FF_STENCIL_MASK (0xF000)
#define GLO_FF_STENCIL_8 (0x1000)
/* The only currently supported format */
#define GLO_FF_DEFAULT (GLO_FF_BITS_24|GLO_FF_DEPTH_24)
/* Change current context */
void glo_set_current(GloContext *context);
@ -71,22 +50,12 @@ void glo_set_current(GloContext *context);
bool glo_check_extension(const char* ext_name);
void* glo_get_extension_proc(const char* extProc);
/* Create an OpenGL context for a certain
* pixel format. formatflags are from the
* GLO_ constants */
GloContext *glo_context_create(int formatFlags);
/* Create an OpenGL context */
GloContext *glo_context_create(void);
/* Destroy a previouslu created OpenGL context */
void glo_context_destroy(GloContext *context);
/* Functions to decode the format flags */
int glo_flags_get_depth_bits(int formatFlags);
int glo_flags_get_stencil_bits(int formatFlags);
void glo_flags_get_rgba_bits(int formatFlags, int *rgba);
int glo_flags_get_bytes_per_pixel(int formatFlags);
/* Score how close the given format flags match. 0=great, >0 not so great */
int glo_flags_score(int formatFlagsExpected, int formatFlagsReal);
/* Note that this is top-down, not bottom-up as glReadPixels would do. */
void glo_readpixels(GLenum gl_format, GLenum gl_type,
unsigned int bytes_per_pixel, unsigned int stride,

View File

@ -40,7 +40,7 @@ struct _GloContext {
/* Create an OpenGL context for a certain pixel format. formatflags are from
* the GLO_ constants */
GloContext *glo_context_create(int formatFlags)
GloContext *glo_context_create(void)
{
CGLError err;

View File

@ -29,84 +29,6 @@
#include "qemu-common.h"
#include "gloffscreen.h"
int glo_flags_get_depth_bits(int formatFlags) {
switch ( formatFlags & GLO_FF_DEPTH_MASK ) {
case GLO_FF_DEPTH_16: return 16;
case GLO_FF_DEPTH_24: return 24;
case GLO_FF_DEPTH_32: return 32;
default: return 0;
}
}
int glo_flags_get_stencil_bits(int formatFlags) {
switch ( formatFlags & GLO_FF_STENCIL_MASK ) {
case GLO_FF_STENCIL_8: return 8;
default: return 0;
}
}
void glo_flags_get_rgba_bits(int formatFlags, int *rgba) {
int alpha = (formatFlags & GLO_FF_ALPHA) != 0;
switch ( formatFlags & GLO_FF_BITS_MASK ) {
case GLO_FF_BITS_16:
rgba[0] = alpha ? 4 : 5;
rgba[1] = alpha ? 4 : 6;
rgba[2] = alpha ? 4 : 5;
rgba[3] = alpha ? 4 : 0;
break;
case GLO_FF_BITS_24:
// ignore alpha
rgba[0] = 8;
rgba[1] = 8;
rgba[2] = 8;
rgba[3] = 0;
break;
case GLO_FF_BITS_32:
rgba[0] = 8;
rgba[1] = 8;
rgba[2] = 8;
rgba[3] = 8;
break;
default:
rgba[0] = 8;
rgba[1] = 8;
rgba[2] = 8;
rgba[3] = 0;
break;
}
}
int glo_flags_get_bytes_per_pixel(int formatFlags) {
switch ( formatFlags & GLO_FF_BITS_MASK ) {
case GLO_FF_BITS_16: return 2;
case GLO_FF_BITS_24: return 3;
case GLO_FF_BITS_32: return 4;
default: return 3;
}
}
int glo_flags_score(int formatFlagsExpected, int formatFlagsReal) {
if (formatFlagsExpected == formatFlagsReal) return 0;
int score = 1;
// we wanted alpha, but we didn't get it
if ((formatFlagsExpected&GLO_FF_ALPHA_MASK) <
(formatFlagsReal&GLO_FF_ALPHA_MASK))
score++;
// less bits than we expected
if ((formatFlagsExpected&GLO_FF_BITS_MASK) <
!(formatFlagsReal&GLO_FF_BITS_MASK))
score++;
// less depth bits than we expected
if ((formatFlagsExpected&GLO_FF_DEPTH_MASK) <
!(formatFlagsReal&GLO_FF_DEPTH_MASK))
score++;
// less stencil bits than we expected
if ((formatFlagsExpected&GLO_FF_STENCIL_MASK) <
!(formatFlagsReal&GLO_FF_STENCIL_MASK))
score++;
return score;
}
void glo_readpixels(GLenum gl_format, GLenum gl_type,
unsigned int bytes_per_pixel, unsigned int stride,

View File

@ -43,9 +43,8 @@ struct _GloContext {
static Display* x_display;
/* Create an OpenGL context for a certain pixel format. formatflags are from
* the GLO_ constants */
GloContext *glo_context_create(int formatFlags)
/* Create an OpenGL context */
GloContext *glo_context_create(void)
{
static bool initialized = false;
@ -60,23 +59,22 @@ GloContext *glo_context_create(int formatFlags)
}
GloContext *context = (GloContext *)g_malloc0(sizeof(GloContext));
int rgbaBits[4];
glo_flags_get_rgba_bits(formatFlags, rgbaBits);
int fb_attribute_list[] = {
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_RED_SIZE, rgbaBits[0],
GLX_GREEN_SIZE, rgbaBits[1],
GLX_BLUE_SIZE, rgbaBits[2],
GLX_ALPHA_SIZE, rgbaBits[3],
GLX_DEPTH_SIZE, glo_flags_get_depth_bits(formatFlags),
GLX_STENCIL_SIZE, glo_flags_get_stencil_bits(formatFlags),
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_ALPHA_SIZE, 8,
GLX_DEPTH_SIZE, 24,
GLX_STENCIL_SIZE, 8,
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
None
};
int nelements;
GLXFBConfig* configs = glXChooseFBConfig(x_display, DefaultScreen(x_display), fb_attribute_list, &nelements);
GLXFBConfig* configs = glXChooseFBConfig(x_display,
DefaultScreen(x_display),
fb_attribute_list, &nelements);
if (configs == NULL) { return NULL; }
if (nelements == 0) { return NULL; }

View File

@ -58,7 +58,6 @@ struct GloMain glo;
int glo_inited = 0;
struct _GloContext {
int formatFlags;
/* Pixel format returned by wglChoosePixelFormat */
int wglPixelFormat;
/* We need a pbuffer to make a context of the right pixelformat :( */
@ -166,17 +165,12 @@ static void glo_kill(void) {
UnregisterClass(GLO_WINDOW_CLASS, glo.hInstance);
}
/* Create an OpenGL context for a certain pixel format. formatflags are from
* the GLO_ constants */
GloContext *glo_context_create(int formatFlags) {
GloContext *context;
GloContext *glo_context_create(void) {
if (!glo_inited)
glo_init();
context = (GloContext *)malloc(sizeof(GloContext));
GloContext *context = (GloContext *)malloc(sizeof(GloContext));
memset(context, 0, sizeof(GloContext));
context->formatFlags = formatFlags;
/* pixel format attributes */
const int pf_attri[] = {

View File

@ -3363,7 +3363,7 @@ static void pgraph_init(NV2AState *d)
/* fire up opengl */
pg->gl_context = glo_context_create(GLO_FF_DEFAULT);
pg->gl_context = glo_context_create();
assert(pg->gl_context);
#ifdef DEBUG_NV2A_GL