From 7116f4eb131d18cab8141ecd33a844d00391841e Mon Sep 17 00:00:00 2001 From: espes Date: Thu, 12 Sep 2013 04:04:11 +1000 Subject: [PATCH] cleanups to context creation; handle 0 viewport z scale --- gl/gloffscreen_cgl.c | 17 +++++++++++------ hw/xbox/nv2a.c | 8 ++------ hw/xbox/nv2a_vsh.c | 10 ++++++++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/gl/gloffscreen_cgl.c b/gl/gloffscreen_cgl.c index 02c3a5e10b..6374a71c57 100644 --- a/gl/gloffscreen_cgl.c +++ b/gl/gloffscreen_cgl.c @@ -25,6 +25,8 @@ #include #include +#include "qemu-common.h" + #include #include #include @@ -41,21 +43,24 @@ struct _GloContext { * the GLO_ constants */ GloContext *glo_context_create(int formatFlags) { - GloContext *context; + CGLError err; - context = (GloContext *)malloc(sizeof(GloContext)); - memset(context, 0, sizeof(GloContext)); + GloContext *context = (GloContext *)g_malloc0(sizeof(GloContext)); /* pixel format attributes */ - CGLPixelFormatAttribute attributes[] = { + CGLPixelFormatAttribute attributes[] = { kCGLPFAAccelerated, (CGLPixelFormatAttribute)0 }; CGLPixelFormatObj pix; GLint num; - CGLChoosePixelFormat(attributes, &pix, &num); - CGLCreateContext(pix, NULL, &context->cglContext); + err = CGLChoosePixelFormat(attributes, &pix, &num); + if (err) return NULL; + + err = CGLCreateContext(pix, NULL, &context->cglContext); + if (err) return NULL; + CGLDestroyPixelFormat(pix); glo_set_current(context); diff --git a/hw/xbox/nv2a.c b/hw/xbox/nv2a.c index e8b1cbed9e..71a4491d31 100644 --- a/hw/xbox/nv2a.c +++ b/hw/xbox/nv2a.c @@ -1572,12 +1572,10 @@ static void pgraph_context_init(GraphicsContext *context) { context->gl_context = glo_context_create(GLO_FF_DEFAULT); - - /* TODO: create glo functions for Mac */ + assert(context->gl_context); /* Check context capabilities */ - const GLubyte *extensions; - extensions = glGetString (GL_EXTENSIONS); + const GLubyte *extensions = glGetString(GL_EXTENSIONS); assert(glo_check_extension((const GLubyte *) "GL_EXT_texture_compression_s3tc", @@ -2156,13 +2154,11 @@ static void pgraph_method(NV2AState *d, unsigned int start = GET_MASK(parameter, NV097_DRAW_ARRAYS_START_INDEX); unsigned int count = GET_MASK(parameter, NV097_DRAW_ARRAYS_COUNT)+1; - kelvin_update_surface(d, kelvin, true); kelvin_bind_converted_vertex_attributes(d, kelvin, false, start + count); glDrawArrays(kelvin->gl_primitive_mode, start, count); - kelvin->surface_color.draw_dirty = true; break; } case NV097_INLINE_ARRAY: diff --git a/hw/xbox/nv2a_vsh.c b/hw/xbox/nv2a_vsh.c index 4a4f69e609..42aaac90da 100644 --- a/hw/xbox/nv2a_vsh.c +++ b/hw/xbox/nv2a_vsh.c @@ -664,7 +664,7 @@ QString* vsh_translate(uint16_t version, /* the shaders leave the result in screen space, while - * opengl expects it in normalised device coords. + * opengl expects it in clip coordinates. * Use the magic viewport constants for now, * but they're not necessarily present. * Same idea as above I think, but dono what the mvp stuff is about... @@ -673,7 +673,13 @@ QString* vsh_translate(uint16_t version, "ADD R12, R12, -c[59];\n" "RCP R1.x, c[58].x;\n" "RCP R1.y, c[58].y;\n" - "RCP R1.z, c[58].z;\n" + + /* scale_z = view_z == 0 ? 1 : 1 / view_z */ + "ABS R1.z, c[58].z;\n" + "SGE R1.z, -R1.z, 0;\n" + "ADD R1.z, R1.z, c[58].z;\n" + "RCP R1.z, R1.z;\n" + "MUL R12.xyz, R12, R1;\n" /* Z coord [0;1]->[-1;1] mapping, see comment in transform_projection