int S9xOpenGLDisplayDriver::opengl_defaults (void) { using_pbos = 0; if (config->use_pbos) { if (!load_pixel_buffer_functions ()) { fprintf (stderr, _("pixel_buffer_object extension not supported.\n")); config->use_pbos = 0; } else { using_pbos = 1; } } using_shaders = 0; if (config->use_shaders) { if (!load_shaders (config->vertex_shader, config->fragment_shader)) { config->use_shaders = 0; } else { using_shaders = 1; } } tex_target = GL_TEXTURE_2D; texture_width = 1024; texture_height = 1024; dyn_resizing = FALSE; const char *extensions = (const char *) glGetString (GL_EXTENSIONS); if (extensions && config->npot_textures) { if (!using_shaders && strstr (extensions, "_texture_rectangle")) { tex_target = GL_TEXTURE_RECTANGLE; texture_width = scaled_max_width; texture_height = scaled_max_height; dyn_resizing = TRUE; } else if (strstr (extensions, "GL_ARB_texture_non_power_of_two")) { dyn_resizing = TRUE; } } glEnable (GL_VERTEX_ARRAY); glEnable (GL_TEXTURE_COORD_ARRAY); vertices[0] = 0.0f; vertices[1] = 0.0f; vertices[2] = 1.0f; vertices[3] = 0.0f; vertices[4] = 1.0f; vertices[5] = 1.0f; vertices[6] = 0.0f; vertices[7] = 1.0f; glVertexPointer (2, GL_FLOAT, 0, vertices); texcoords[0] = 0.0f; texcoords[5] = 0.0f; texcoords[6] = 0.0f; texcoords[7] = 0.0f; glTexCoordPointer (2, GL_FLOAT, 0, texcoords); if (config->use_pbos) { glGenBuffers (1, &pbo); glGenTextures (1, &texmap); glBindTexture (tex_target, texmap); glTexImage2D (tex_target, 0, config->pbo_format == PBO_FMT_16 ? GL_RGB5_A1 : 4, texture_width, texture_height, 0, PBO_GET_FORMAT (config->pbo_format), PBO_GET_PACKING (config->pbo_format), NULL); glBindBuffer (GL_PIXEL_UNPACK_BUFFER, pbo); glBufferData (GL_PIXEL_UNPACK_BUFFER, texture_width * texture_height * 3, NULL, GL_STREAM_DRAW); glBindBuffer (GL_PIXEL_UNPACK_BUFFER, 0); } else { glGenTextures (1, &texmap); glBindTexture (tex_target, texmap); glTexImage2D (tex_target, 0, GL_RGB5_A1, texture_width, texture_height, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); } glEnable (GL_DITHER); glDisable (GL_POLYGON_SMOOTH); glShadeModel (GL_FLAT); glPolygonMode (GL_FRONT, GL_FILL); glEnable (GL_CULL_FACE); glCullFace (GL_BACK); glClearColor (0.0, 0.0, 0.0, 0.0); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glDisable (GL_BLEND); glDisable (GL_DEPTH_TEST); glDisable (GL_TEXTURE_2D); glDisable (GL_TEXTURE_RECTANGLE); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (0.0, 1.0, 0.0, 1.0, -1, 1); return 1; }
void S9xOpenGLDisplayDriver::opengl_defaults (void) { XVisualInfo *vi; int glx_attribs[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; Display *display = GDK_DISPLAY (); vi = glXChooseVisual (display, DefaultScreen (display), glx_attribs); glx_context = glXCreateContext (display, vi, 0, 1); glXMakeCurrent (display, GDK_WINDOW_XWINDOW (drawing_area->window), glx_context); gl_lock (); const char *extensions = (const char *) glGetString (GL_EXTENSIONS); using_pbos = 0; if (config->use_pbos) { if (!load_pixel_buffer_functions ()) { fprintf (stderr, _("pixel_buffer_object extension not supported.\n")); config->use_pbos = 0; } else { using_pbos = 1; } } tex_target = GL_TEXTURE_2D; texture_width = 1024; texture_height = 1024; dyn_resizing = FALSE; if (config->npot_textures) { if (strstr (extensions, "_texture_rectangle")) { tex_target = GL_TEXTURE_RECTANGLE; texture_width = scaled_max_width; texture_height = scaled_max_height; dyn_resizing = TRUE; } else if (strstr (extensions, "GL_ARB_texture_non_power_of_two")) { dyn_resizing = TRUE; } } glEnable (GL_VERTEX_ARRAY); glEnable (GL_TEXTURE_COORD_ARRAY); vertices[0] = 0.0f; vertices[1] = 0.0f; vertices[2] = 1.0f; vertices[3] = 0.0f; vertices[4] = 1.0f; vertices[5] = 1.0f; vertices[6] = 0.0f; vertices[7] = 1.0f; glVertexPointer (2, GL_FLOAT, 0, vertices); texcoords[0] = 0.0f; texcoords[5] = 0.0f; texcoords[6] = 0.0f; texcoords[7] = 0.0f; glTexCoordPointer (2, GL_FLOAT, 0, texcoords); if (config->use_pbos) { glGenBuffers (1, &pbo); glGenTextures (1, &texmap); glBindTexture (tex_target, texmap); glTexImage2D (tex_target, 0, config->pbo_format == PBO_FMT_16 ? GL_RGB5_A1 : 4, texture_width, texture_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindBuffer (GL_PIXEL_UNPACK_BUFFER, pbo); glBufferData (GL_PIXEL_UNPACK_BUFFER, texture_width * texture_height * 3, NULL, GL_STREAM_DRAW); glBindBuffer (GL_PIXEL_UNPACK_BUFFER, 0); } else { glGenTextures (1, &texmap); glBindTexture (tex_target, texmap); glTexImage2D (tex_target, 0, GL_RGB5_A1, texture_width, texture_height, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); } glEnable (GL_DITHER); glDisable (GL_POLYGON_SMOOTH); glShadeModel (GL_FLAT); glPolygonMode (GL_FRONT, GL_FILL); glEnable (GL_CULL_FACE); glCullFace (GL_BACK); glClearColor (0.0, 0.0, 0.0, 0.0); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glDisable (GL_BLEND); glDisable (GL_DEPTH_TEST); glDisable (GL_TEXTURE_2D); glDisable (GL_TEXTURE_RECTANGLE); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (0.0, 1.0, 0.0, 1.0, -1, 1); gl_unlock (); return; }