Skip to content

Commit

Permalink
fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
espes committed Aug 16, 2015
1 parent 9ec38af commit dc39687
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 77 deletions.
3 changes: 1 addition & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2657,14 +2657,13 @@ if test "$opengl" != "no" ; then
int main(void) { return GL_VERSION != 0; }
EOF
elif test "$mingw32" = "yes" ; then
opengl_libs="-lglut32win -lOpenGL32 -lglu32 -lglew32 -lgdi32"
opengl_libs="-lopengl32 -lglew32 -lgdi32"
cat > $TMPC << EOF
#include <windows.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/wglext.h>
#include <GL/glut.h>
int main(void) { return GL_VERSION != 0; }
EOF
else
Expand Down
7 changes: 7 additions & 0 deletions cpu-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#include "qemu/atomic.h"
#include "sysemu/qtest.h"

#if defined(_WIN64)
/* Temporary hack for win64 because the include order is broken.
* See os-win32.h.
*/
# define setjmp(env) _setjmp(env, NULL)
#endif

bool qemu_cpu_has_work(CPUState *cpu)
{
return cpu_has_work(cpu);
Expand Down
4 changes: 0 additions & 4 deletions gl/gloffscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
#ifdef __APPLE__
#include <OpenGL/gl3.h>
#include <OpenGL/glext.h>
#elif defined(_WIN32)
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glext.h>
#else
#include <GL/glew.h>
#include <GL/gl.h>
Expand Down
111 changes: 45 additions & 66 deletions gl/gloffscreen_wgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
#include <wingdi.h>

#include <GL/glew.h>
#include <GL/wglew.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/wglext.h>
#include <GL/glut.h>

#include "gloffscreen.h"

Expand Down Expand Up @@ -70,22 +69,15 @@ struct _GloContext {


#define GLO_WINDOW_CLASS "QEmuGLClass"
#define DEFAULT_DEPTH_BUFFER (16)

PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB;
PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB;
PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB;
PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB;

/* Initialise gloffscreen */
static void glo_init(void) {
WNDCLASSEX wcx;
PIXELFORMATDESCRIPTOR pfd;

if (glo_inited) {
printf("gloffscreen already inited\n");
exit(EXIT_FAILURE);
fprintf(stderr, "gloffscreen already inited\n");
abort();
}

/* Grab An Instance For Our Window */
Expand Down Expand Up @@ -113,11 +105,12 @@ static void glo_init(void) {
(LPVOID) NULL);

if (!glo.hWnd) {
printf("Unable to create window\n");
exit(EXIT_FAILURE);
fprintf(stderr, "Unable to create window\n");
abort();
}
glo.hDC = GetDC(glo.hWnd);

/* Create a pixel format */
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
Expand All @@ -131,39 +124,27 @@ static void glo_init(void) {
if (!SetPixelFormat(glo.hDC, pixelFormat, &pfd))
return;

/* Create a tempoary OpenGL 2 context */
glo.hContext = wglCreateContext(glo.hDC);
if (glo.hContext == NULL) {
printf("Unable to create GL context\n");
exit(EXIT_FAILURE);
fprintf(stderr, "Unable to create GL context\n");
abort();
}
wglMakeCurrent(glo.hDC, glo.hContext);

wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)
wglGetProcAddress("wglChoosePixelFormatARB");
wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)
wglGetProcAddress("wglGetPbufferDCARB");
wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)
wglGetProcAddress("wglReleasePbufferDCARB");
wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)
wglGetProcAddress("wglCreatePbufferARB");
wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)
wglGetProcAddress("wglDestroyPbufferARB");

if (!wglChoosePixelFormatARB ||
!wglGetPbufferDCARB ||
!wglReleasePbufferDCARB ||
!wglCreatePbufferARB ||
!wglDestroyPbufferARB) {
printf("Unable to load the required WGL extensions\n");
exit(EXIT_FAILURE);
/* Initialize glew */
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Glew init failed.\n");
abort();
}

/* Initialize glew */
if (GLEW_OK != glewInit()) {
/* GLEW failed! */
printf("Glew init failed.");
exit(1);
if (!WGLEW_ARB_create_context
|| !WGLEW_ARB_pixel_format
|| !WGLEW_ARB_pbuffer) {
fprintf(stderr, "Unable to load the required WGL extensions\n");
abort();
}

glo_inited = 1;
}

Expand All @@ -189,23 +170,6 @@ static void glo_kill(void) {
* the GLO_ constants */
GloContext *glo_context_create(int formatFlags) {
GloContext *context;
/* pixel format attributes */
int pf_attri[] = {
WGL_SUPPORT_OPENGL_ARB, TRUE,
WGL_DRAW_TO_PBUFFER_ARB, TRUE,
WGL_RED_BITS_ARB, 8,
WGL_GREEN_BITS_ARB, 8,
WGL_BLUE_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 0,
WGL_STENCIL_BITS_ARB, 0,
WGL_DOUBLE_BUFFER_ARB, FALSE,
0
};
float pf_attrf[] = {0, 0};
unsigned int numReturned = 0;
int pb_attr[] = { 0 };
int rgbaBits[4];

if (!glo_inited)
glo_init();
Expand All @@ -214,41 +178,56 @@ GloContext *glo_context_create(int formatFlags) {
memset(context, 0, sizeof(GloContext));
context->formatFlags = formatFlags;

/* set up the surface format from the flags we were given */
glo_flags_get_rgba_bits(context->formatFlags, rgbaBits);
pf_attri[5] = rgbaBits[0];
pf_attri[7] = rgbaBits[1];
pf_attri[9] = rgbaBits[2];
pf_attri[11] = rgbaBits[3];
pf_attri[13] = glo_flags_get_depth_bits(context->formatFlags);
pf_attri[15] = glo_flags_get_stencil_bits(context->formatFlags);
/* pixel format attributes */
const int pf_attri[] = {
WGL_DRAW_TO_PBUFFER_ARB, TRUE,
WGL_SUPPORT_OPENGL_ARB, TRUE,
WGL_DOUBLE_BUFFER_ARB, FALSE,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
0
};
const float pf_attrf[] = {0, 0};

/* find out what pixel format to use */
unsigned int numReturned = 0;
wglChoosePixelFormatARB(glo.hDC, pf_attri, pf_attrf, 1,
&context->wglPixelFormat, &numReturned);
&context->wglPixelFormat, &numReturned);
if (numReturned == 0) {
printf( "No matching configs found.\n" );
exit(EXIT_FAILURE);
}

/* We create a tiny pbuffer - just so we can make a context of
* the right pixel format */
const int pb_attr[] = { 0 };
context->hPBuffer = wglCreatePbufferARB(glo.hDC, context->wglPixelFormat,
16, 16, pb_attr);
16, 16, pb_attr);
if (!context->hPBuffer) {
printf("Couldn't create the PBuffer\n");
exit(EXIT_FAILURE);
}

context->hDC = wglGetPbufferDCARB(context->hPBuffer);
if (!context->hDC) {
printf("Couldn't create the DC\n");
exit(EXIT_FAILURE);
}
context->hContext = wglCreateContext(context->hDC);

/* Create the context proper */
const int ctx_attri[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0
};
context->hContext = wglCreateContextAttribsARB(context->hDC, 0, ctx_attri);
if (context->hContext == NULL) {
printf("Unable to create GL context\n");
exit(EXIT_FAILURE);
}

glo_set_current(context);
return context;
}
Expand Down
4 changes: 2 additions & 2 deletions hw/xbox/nv2a.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,8 +1235,8 @@ static const SurfaceColorFormatInfo kelvin_surface_color_format_map[] = {
#define GET_MASK(v, mask) (((v) & (mask)) >> (ffs(mask)-1))

#define SET_MASK(v, mask, val) ({ \
const typeof(val) __val = (val); \
const typeof(mask) __mask = (mask); \
const unsigned int __val = (val); \
const unsigned int __mask = (mask); \
(v) &= ~(__mask); \
(v) |= ((__val) << (ffs(__mask)-1)) & (__mask); \
})
Expand Down
3 changes: 2 additions & 1 deletion hw/xbox/nv2a_vsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ QString* vsh_translate(uint16_t version,
QString *body = qstring_from_str("\n");

bool has_final = false;
for (int slot=0; slot<length; slot++) {
int slot;
for (slot=0; slot<length; slot++) {
const uint32_t* cur_token = &tokens[slot * VSH_TOKEN_SIZE];
QString *token_str = decode_token(cur_token);
qstring_append_fmt(body,
Expand Down
3 changes: 1 addition & 2 deletions include/sysemu/os-win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@

/* Declaration of ffs() is missing in MinGW's strings.h. */
int ffs(int i);
#define ffs(i) __builtin_ffs(i)

/* Missing POSIX functions. Don't use MinGW-w64 macros. */
#undef gmtime_r
struct tm *gmtime_r(const time_t *timep, struct tm *result);
#undef localtime_r
struct tm *localtime_r(const time_t *timep, struct tm *result);

char *strtok_r(char *str, const char *delim, char **saveptr);

static inline void os_setup_signal_handling(void) {}
static inline void os_daemonize(void) {}
static inline void os_setup_post(void) {}
Expand Down

0 comments on commit dc39687

Please sign in to comment.