2007-02-12 19:18:36 +01:00
|
|
|
/*
|
|
|
|
* Context and render target management in wined3d
|
|
|
|
*
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2010-11-12 13:12:05 +01:00
|
|
|
* Copyright 2009-2010 Henri Verbeet for CodeWeavers
|
2007-02-12 19:18:36 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_FLOAT_H
|
|
|
|
# include <float.h>
|
|
|
|
#endif
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2009-07-22 14:03:36 +02:00
|
|
|
static DWORD wined3d_context_tls_idx;
|
2008-07-31 20:29:50 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
/* FBO helper functions */
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2009-08-03 08:06:51 +02:00
|
|
|
void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-07-17 10:34:03 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2009-07-17 10:34:04 +02:00
|
|
|
GLuint f;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2009-07-17 10:34:04 +02:00
|
|
|
if (!fbo)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-07-17 10:34:04 +02:00
|
|
|
f = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!*fbo)
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glGenFramebuffers(1, fbo);
|
|
|
|
checkGLcall("glGenFramebuffers()");
|
2009-07-17 10:34:04 +02:00
|
|
|
TRACE("Created FBO %u.\n", *fbo);
|
|
|
|
}
|
|
|
|
f = *fbo;
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2009-07-17 10:34:05 +02:00
|
|
|
switch (target)
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
case GL_READ_FRAMEBUFFER:
|
2009-07-17 10:34:05 +02:00
|
|
|
if (context->fbo_read_binding == f) return;
|
|
|
|
context->fbo_read_binding = f;
|
|
|
|
break;
|
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
case GL_DRAW_FRAMEBUFFER:
|
2009-07-17 10:34:05 +02:00
|
|
|
if (context->fbo_draw_binding == f) return;
|
|
|
|
context->fbo_draw_binding = f;
|
|
|
|
break;
|
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
case GL_FRAMEBUFFER:
|
2009-07-17 10:34:05 +02:00
|
|
|
if (context->fbo_read_binding == f
|
|
|
|
&& context->fbo_draw_binding == f) return;
|
|
|
|
context->fbo_read_binding = f;
|
|
|
|
context->fbo_draw_binding = f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled target %#x.\n", target);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glBindFramebuffer(target, f);
|
2008-09-18 14:57:53 +02:00
|
|
|
checkGLcall("glBindFramebuffer()");
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-05-19 11:13:35 +02:00
|
|
|
static void context_clean_fbo_attachments(const struct wined3d_gl_info *gl_info, GLenum target)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-03-25 10:12:27 +01:00
|
|
|
unsigned int i;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2009-10-29 10:37:10 +01:00
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-05-19 11:13:35 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(target, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, 0, 0);
|
2008-09-18 14:57:53 +02:00
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
|
|
|
}
|
2010-05-19 11:13:35 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
2008-09-18 14:57:53 +02:00
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2009-06-08 10:35:06 +02:00
|
|
|
|
2010-05-19 11:13:35 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(target, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
2009-06-08 10:35:06 +02:00
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2009-05-11 16:43:49 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2009-08-03 08:06:51 +02:00
|
|
|
static void context_destroy_fbo(struct wined3d_context *context, GLuint *fbo)
|
2009-05-11 16:43:49 +02:00
|
|
|
{
|
2009-07-17 10:34:03 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2009-07-17 10:34:02 +02:00
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, fbo);
|
2010-05-19 11:13:35 +02:00
|
|
|
context_clean_fbo_attachments(gl_info, GL_FRAMEBUFFER);
|
2009-09-23 10:05:55 +02:00
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
|
2009-05-11 16:43:49 +02:00
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glDeleteFramebuffers(1, fbo);
|
2008-09-18 14:57:53 +02:00
|
|
|
checkGLcall("glDeleteFramebuffers()");
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-07-26 12:06:32 +02:00
|
|
|
static void context_apply_attachment_filter_states(IWineD3DSurfaceImpl *surface, DWORD location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2008-09-18 14:57:53 +02:00
|
|
|
/* Update base texture states array */
|
2010-08-16 20:00:27 +02:00
|
|
|
if (surface->container.type == WINED3D_CONTAINER_TEXTURE)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-08-16 20:00:27 +02:00
|
|
|
IWineD3DBaseTextureImpl *texture_impl = surface->container.u.texture;
|
2010-04-15 19:21:24 +02:00
|
|
|
IWineD3DDeviceImpl *device = surface->resource.device;
|
2010-03-16 19:02:17 +01:00
|
|
|
BOOL update_minfilter = FALSE;
|
|
|
|
BOOL update_magfilter = FALSE;
|
2010-07-26 12:06:32 +02:00
|
|
|
struct gl_texture *gl_tex;
|
2010-03-16 19:02:17 +01:00
|
|
|
|
2010-07-26 12:06:32 +02:00
|
|
|
switch (location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
case SFLAG_INTEXTURE:
|
|
|
|
gl_tex = &texture_impl->baseTexture.texture_rgb;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFLAG_INSRGBTEX:
|
|
|
|
gl_tex = &texture_impl->baseTexture.texture_srgb;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Unsupported location %s (%#x).\n", debug_surflocation(location), location);
|
|
|
|
IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)texture_impl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_POINT
|
|
|
|
|| gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_NONE)
|
|
|
|
{
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
|
2008-09-18 14:57:53 +02:00
|
|
|
update_minfilter = TRUE;
|
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2010-07-26 12:06:32 +02:00
|
|
|
if (gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_POINT)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
|
2008-09-18 14:57:53 +02:00
|
|
|
update_magfilter = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture_impl->baseTexture.bindCount)
|
|
|
|
{
|
|
|
|
WARN("Render targets should not be bound to a sampler\n");
|
2009-07-17 10:34:03 +02:00
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(texture_impl->baseTexture.sampler));
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2010-03-16 19:02:17 +01:00
|
|
|
if (update_minfilter || update_magfilter)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-03-16 19:02:17 +01:00
|
|
|
GLenum target, bind_target;
|
|
|
|
GLint old_binding;
|
|
|
|
|
2010-04-15 19:21:24 +02:00
|
|
|
target = surface->texture_target;
|
2010-03-16 19:02:17 +01:00
|
|
|
if (target == GL_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
bind_target = GL_TEXTURE_2D;
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
|
|
|
|
}
|
|
|
|
else if (target == GL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
{
|
|
|
|
bind_target = GL_TEXTURE_RECTANGLE_ARB;
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bind_target = GL_TEXTURE_CUBE_MAP_ARB;
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARB, &old_binding);
|
|
|
|
}
|
|
|
|
|
2010-07-26 12:06:32 +02:00
|
|
|
glBindTexture(bind_target, gl_tex->name);
|
2010-03-16 19:02:17 +01:00
|
|
|
if (update_minfilter) glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
if (update_magfilter) glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glBindTexture(bind_target, old_binding);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2010-03-16 19:02:17 +01:00
|
|
|
checkGLcall("apply_attachment_filter_states()");
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2009-08-03 08:06:51 +02:00
|
|
|
void context_attach_depth_stencil_fbo(struct wined3d_context *context,
|
2010-04-15 19:21:26 +02:00
|
|
|
GLenum fbo_target, IWineD3DSurfaceImpl *depth_stencil, BOOL use_render_buffer)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-07-17 10:34:03 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
TRACE("Attach depth stencil %p\n", depth_stencil);
|
|
|
|
|
|
|
|
if (depth_stencil)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-11-12 13:12:05 +01:00
|
|
|
DWORD format_flags = depth_stencil->resource.format->flags;
|
2009-06-08 10:35:06 +02:00
|
|
|
|
2010-04-15 19:21:26 +02:00
|
|
|
if (use_render_buffer && depth_stencil->current_renderbuffer)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-06-08 10:35:06 +02:00
|
|
|
if (format_flags & WINED3DFMT_FLAG_DEPTH)
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_DEPTH_ATTACHMENT,
|
2010-04-15 19:21:26 +02:00
|
|
|
GL_RENDERBUFFER, depth_stencil->current_renderbuffer->id);
|
2009-09-23 10:05:55 +02:00
|
|
|
checkGLcall("glFramebufferRenderbuffer()");
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (format_flags & WINED3DFMT_FLAG_STENCIL)
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_STENCIL_ATTACHMENT,
|
2010-04-15 19:21:26 +02:00
|
|
|
GL_RENDERBUFFER, depth_stencil->current_renderbuffer->id);
|
2009-09-23 10:05:55 +02:00
|
|
|
checkGLcall("glFramebufferRenderbuffer()");
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-15 19:21:26 +02:00
|
|
|
surface_prepare_texture(depth_stencil, gl_info, FALSE);
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_attachment_filter_states(depth_stencil, SFLAG_INTEXTURE);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2009-06-08 10:35:06 +02:00
|
|
|
if (format_flags & WINED3DFMT_FLAG_DEPTH)
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_DEPTH_ATTACHMENT,
|
2010-04-15 19:21:26 +02:00
|
|
|
depth_stencil->texture_target, depth_stencil->texture_name,
|
|
|
|
depth_stencil->texture_level);
|
2009-09-23 10:05:55 +02:00
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (format_flags & WINED3DFMT_FLAG_STENCIL)
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_STENCIL_ATTACHMENT,
|
2010-04-15 19:21:26 +02:00
|
|
|
depth_stencil->texture_target, depth_stencil->texture_name,
|
|
|
|
depth_stencil->texture_level);
|
2009-09-23 10:05:55 +02:00
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(format_flags & WINED3DFMT_FLAG_DEPTH))
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(format_flags & WINED3DFMT_FLAG_STENCIL))
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2009-06-08 10:35:06 +02:00
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-05-19 11:13:34 +02:00
|
|
|
static void context_attach_surface_fbo(const struct wined3d_context *context,
|
2010-07-26 12:06:32 +02:00
|
|
|
GLenum fbo_target, DWORD idx, IWineD3DSurfaceImpl *surface, DWORD location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-07-17 10:34:03 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
TRACE("Attach surface %p to %u\n", surface, idx);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
if (surface)
|
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case SFLAG_INTEXTURE:
|
|
|
|
surface_prepare_texture(surface, gl_info, FALSE);
|
|
|
|
context_apply_attachment_filter_states(surface, location);
|
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_COLOR_ATTACHMENT0 + idx,
|
|
|
|
surface->texture_target, surface->texture_name, surface->texture_level);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFLAG_INSRGBTEX:
|
|
|
|
surface_prepare_texture(surface, gl_info, TRUE);
|
|
|
|
context_apply_attachment_filter_states(surface, location);
|
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_COLOR_ATTACHMENT0 + idx,
|
|
|
|
surface->texture_target, surface->texture_name_srgb, surface->texture_level);
|
|
|
|
break;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2010-07-26 12:06:32 +02:00
|
|
|
default:
|
|
|
|
ERR("Unsupported location %s (%#x).\n", debug_surflocation(location), location);
|
|
|
|
break;
|
|
|
|
}
|
2009-09-23 10:05:55 +02:00
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_COLOR_ATTACHMENT0 + idx, GL_TEXTURE_2D, 0, 0);
|
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-05-04 20:39:50 +02:00
|
|
|
static void context_check_fbo_status(struct wined3d_context *context, GLenum target)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-07-17 10:34:03 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2008-09-18 14:57:53 +02:00
|
|
|
GLenum status;
|
|
|
|
|
2010-05-04 20:39:50 +02:00
|
|
|
status = gl_info->fbo_ops.glCheckFramebufferStatus(target);
|
2009-09-23 10:05:55 +02:00
|
|
|
if (status == GL_FRAMEBUFFER_COMPLETE)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
|
|
|
TRACE("FBO complete\n");
|
|
|
|
} else {
|
|
|
|
IWineD3DSurfaceImpl *attachment;
|
2008-11-20 23:13:48 +01:00
|
|
|
unsigned int i;
|
2008-09-18 14:57:53 +02:00
|
|
|
FIXME("FBO status %s (%#x)\n", debug_fbostatus(status), status);
|
|
|
|
|
2009-10-26 10:12:19 +01:00
|
|
|
if (!context->current_fbo)
|
|
|
|
{
|
|
|
|
ERR("FBO 0 is incomplete, driver bug?\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-26 12:06:32 +02:00
|
|
|
FIXME("\tLocation %s (%#x).\n", debug_surflocation(context->current_fbo->location),
|
|
|
|
context->current_fbo->location);
|
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
/* Dump the FBO attachments */
|
2009-10-29 10:37:10 +01:00
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-04-15 19:21:27 +02:00
|
|
|
attachment = context->current_fbo->render_targets[i];
|
2008-09-18 14:57:53 +02:00
|
|
|
if (attachment)
|
|
|
|
{
|
2009-03-13 10:44:18 +01:00
|
|
|
FIXME("\tColor attachment %d: (%p) %s %ux%u\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
i, attachment, debug_d3dformat(attachment->resource.format->id),
|
2008-09-18 14:57:53 +02:00
|
|
|
attachment->pow2Width, attachment->pow2Height);
|
|
|
|
}
|
|
|
|
}
|
2010-04-15 19:21:28 +02:00
|
|
|
attachment = context->current_fbo->depth_stencil;
|
2008-09-18 14:57:53 +02:00
|
|
|
if (attachment)
|
|
|
|
{
|
2009-03-13 10:44:18 +01:00
|
|
|
FIXME("\tDepth attachment: (%p) %s %ux%u\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
attachment, debug_d3dformat(attachment->resource.format->id),
|
2008-09-18 14:57:53 +02:00
|
|
|
attachment->pow2Width, attachment->pow2Height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-04 20:39:51 +02:00
|
|
|
static struct fbo_entry *context_create_fbo_entry(struct wined3d_context *context,
|
2010-07-26 12:06:32 +02:00
|
|
|
IWineD3DSurfaceImpl **render_targets, IWineD3DSurfaceImpl *depth_stencil, DWORD location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-07-17 10:34:03 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2008-09-18 14:57:53 +02:00
|
|
|
struct fbo_entry *entry;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
|
2009-10-29 10:37:10 +01:00
|
|
|
entry->render_targets = HeapAlloc(GetProcessHeap(), 0, gl_info->limits.buffers * sizeof(*entry->render_targets));
|
2010-05-04 20:39:51 +02:00
|
|
|
memcpy(entry->render_targets, render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets));
|
|
|
|
entry->depth_stencil = depth_stencil;
|
2010-07-26 12:06:32 +02:00
|
|
|
entry->location = location;
|
2008-09-18 14:57:53 +02:00
|
|
|
entry->attached = FALSE;
|
|
|
|
entry->id = 0;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-05-04 20:39:51 +02:00
|
|
|
static void context_reuse_fbo_entry(struct wined3d_context *context, GLenum target,
|
|
|
|
IWineD3DSurfaceImpl **render_targets, IWineD3DSurfaceImpl *depth_stencil,
|
2010-07-26 12:06:32 +02:00
|
|
|
DWORD location, struct fbo_entry *entry)
|
2009-05-11 16:43:49 +02:00
|
|
|
{
|
2009-07-17 10:34:03 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2009-05-11 16:43:49 +02:00
|
|
|
|
2010-05-04 20:39:50 +02:00
|
|
|
context_bind_fbo(context, target, &entry->id);
|
2010-05-19 11:13:35 +02:00
|
|
|
context_clean_fbo_attachments(gl_info, target);
|
2009-05-11 16:43:49 +02:00
|
|
|
|
2010-05-04 20:39:51 +02:00
|
|
|
memcpy(entry->render_targets, render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets));
|
|
|
|
entry->depth_stencil = depth_stencil;
|
2010-07-26 12:06:32 +02:00
|
|
|
entry->location = location;
|
2009-05-11 16:43:49 +02:00
|
|
|
entry->attached = FALSE;
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2009-08-03 08:06:51 +02:00
|
|
|
static void context_destroy_fbo_entry(struct wined3d_context *context, struct fbo_entry *entry)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
|
|
|
if (entry->id)
|
|
|
|
{
|
|
|
|
TRACE("Destroy FBO %d\n", entry->id);
|
2009-07-17 10:34:03 +02:00
|
|
|
context_destroy_fbo(context, &entry->id);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2009-05-24 14:15:29 +02:00
|
|
|
--context->fbo_entry_count;
|
2008-09-18 14:57:53 +02:00
|
|
|
list_remove(&entry->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry->render_targets);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-05-04 20:39:51 +02:00
|
|
|
static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context, GLenum target,
|
2010-07-26 12:06:32 +02:00
|
|
|
IWineD3DSurfaceImpl **render_targets, IWineD3DSurfaceImpl *depth_stencil, DWORD location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-07-17 10:34:02 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2008-09-18 14:57:53 +02:00
|
|
|
struct fbo_entry *entry;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &context->fbo_list, struct fbo_entry, entry)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-10-22 10:09:54 +02:00
|
|
|
if (!memcmp(entry->render_targets,
|
2010-05-04 20:39:51 +02:00
|
|
|
render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets))
|
2010-07-26 12:06:32 +02:00
|
|
|
&& entry->depth_stencil == depth_stencil && entry->location == location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-05-11 16:43:49 +02:00
|
|
|
list_remove(&entry->entry);
|
|
|
|
list_add_head(&context->fbo_list, &entry->entry);
|
2008-09-18 14:57:53 +02:00
|
|
|
return entry;
|
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2009-05-11 16:43:49 +02:00
|
|
|
if (context->fbo_entry_count < WINED3D_MAX_FBO_ENTRIES)
|
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
entry = context_create_fbo_entry(context, render_targets, depth_stencil, location);
|
2009-05-11 16:43:49 +02:00
|
|
|
list_add_head(&context->fbo_list, &entry->entry);
|
|
|
|
++context->fbo_entry_count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
entry = LIST_ENTRY(list_tail(&context->fbo_list), struct fbo_entry, entry);
|
2010-07-26 12:06:32 +02:00
|
|
|
context_reuse_fbo_entry(context, target, render_targets, depth_stencil, location, entry);
|
2009-05-11 16:43:49 +02:00
|
|
|
list_remove(&entry->entry);
|
|
|
|
list_add_head(&context->fbo_list, &entry->entry);
|
|
|
|
}
|
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
return entry;
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-05-04 20:39:50 +02:00
|
|
|
static void context_apply_fbo_entry(struct wined3d_context *context, GLenum target, struct fbo_entry *entry)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-07-17 10:34:03 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2008-09-18 14:57:53 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2010-05-04 20:39:50 +02:00
|
|
|
context_bind_fbo(context, target, &entry->id);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
if (!entry->attached)
|
|
|
|
{
|
2008-09-18 14:57:53 +02:00
|
|
|
/* Apply render targets */
|
2009-10-29 10:37:10 +01:00
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
context_attach_surface_fbo(context, target, i, entry->render_targets[i], entry->location);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply depth targets */
|
2010-05-03 22:03:31 +02:00
|
|
|
if (entry->depth_stencil)
|
2009-07-17 10:34:03 +02:00
|
|
|
{
|
2010-05-03 22:03:31 +02:00
|
|
|
surface_set_compatible_renderbuffer(entry->depth_stencil,
|
|
|
|
entry->render_targets[0]->pow2Width, entry->render_targets[0]->pow2Height);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2010-05-04 20:39:50 +02:00
|
|
|
context_attach_depth_stencil_fbo(context, target, entry->depth_stencil, TRUE);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
entry->attached = TRUE;
|
2009-10-22 10:09:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-29 10:37:10 +01:00
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-05-03 22:03:31 +02:00
|
|
|
if (entry->render_targets[i])
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_attachment_filter_states(entry->render_targets[i], entry->location);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2010-05-03 22:03:31 +02:00
|
|
|
if (entry->depth_stencil)
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_attachment_filter_states(entry->depth_stencil, SFLAG_INTEXTURE);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-05-04 20:39:51 +02:00
|
|
|
static void context_apply_fbo_state(struct wined3d_context *context, GLenum target,
|
2010-07-26 12:06:32 +02:00
|
|
|
IWineD3DSurfaceImpl **render_targets, IWineD3DSurfaceImpl *depth_stencil, DWORD location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2009-10-20 11:05:06 +02:00
|
|
|
struct fbo_entry *entry, *entry2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_destroy_list, struct fbo_entry, entry)
|
|
|
|
{
|
|
|
|
context_destroy_fbo_entry(context, entry);
|
|
|
|
}
|
|
|
|
|
2010-03-17 21:59:51 +01:00
|
|
|
if (context->rebind_fbo)
|
|
|
|
{
|
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
|
|
|
|
context->rebind_fbo = FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-04 20:39:52 +02:00
|
|
|
if (render_targets)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
context->current_fbo = context_find_fbo_entry(context, target, render_targets, depth_stencil, location);
|
2010-05-04 20:39:50 +02:00
|
|
|
context_apply_fbo_entry(context, target, context->current_fbo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-18 14:57:53 +02:00
|
|
|
context->current_fbo = NULL;
|
2010-05-04 20:39:50 +02:00
|
|
|
context_bind_fbo(context, target, NULL);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2010-05-04 20:39:50 +02:00
|
|
|
context_check_fbo_status(context, target);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2010-05-04 20:39:52 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-05-05 18:22:35 +02:00
|
|
|
void context_apply_fbo_state_blit(struct wined3d_context *context, GLenum target,
|
2010-07-26 12:06:32 +02:00
|
|
|
IWineD3DSurfaceImpl *render_target, IWineD3DSurfaceImpl *depth_stencil, DWORD location)
|
2010-05-04 20:39:52 +02:00
|
|
|
{
|
2010-11-11 12:39:17 +01:00
|
|
|
if (location != SFLAG_INDRAWABLE || surface_is_offscreen(render_target))
|
2010-05-04 20:39:52 +02:00
|
|
|
{
|
2010-07-23 11:31:03 +02:00
|
|
|
UINT clear_size = (context->gl_info->limits.buffers - 1) * sizeof(*context->blit_targets);
|
2010-05-04 20:39:52 +02:00
|
|
|
context->blit_targets[0] = render_target;
|
2010-07-23 11:31:03 +02:00
|
|
|
if (clear_size) memset(&context->blit_targets[1], 0, clear_size);
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_fbo_state(context, target, context->blit_targets, depth_stencil, location);
|
2010-05-04 20:39:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_fbo_state(context, target, NULL, NULL, location);
|
2010-05-04 20:39:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2009-08-03 08:06:51 +02:00
|
|
|
void context_alloc_occlusion_query(struct wined3d_context *context, struct wined3d_occlusion_query *query)
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (context->free_occlusion_query_count)
|
|
|
|
{
|
|
|
|
query->id = context->free_occlusion_queries[--context->free_occlusion_query_count];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_OCCLUSION_QUERY])
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glGenQueriesARB(1, &query->id));
|
|
|
|
checkGLcall("glGenQueriesARB");
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
TRACE("Allocated occlusion query %u in context %p.\n", query->id, context);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Occlusion queries not supported, not allocating query id.\n");
|
|
|
|
query->id = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
query->context = context;
|
|
|
|
list_add_head(&context->occlusion_queries, &query->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_free_occlusion_query(struct wined3d_occlusion_query *query)
|
|
|
|
{
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context = query->context;
|
2009-07-24 10:44:13 +02:00
|
|
|
|
|
|
|
list_remove(&query->entry);
|
|
|
|
query->context = NULL;
|
|
|
|
|
|
|
|
if (context->free_occlusion_query_count >= context->free_occlusion_query_size - 1)
|
|
|
|
{
|
|
|
|
UINT new_size = context->free_occlusion_query_size << 1;
|
|
|
|
GLuint *new_data = HeapReAlloc(GetProcessHeap(), 0, context->free_occlusion_queries,
|
|
|
|
new_size * sizeof(*context->free_occlusion_queries));
|
|
|
|
|
|
|
|
if (!new_data)
|
|
|
|
{
|
|
|
|
ERR("Failed to grow free list, leaking query %u in context %p.\n", query->id, context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->free_occlusion_query_size = new_size;
|
|
|
|
context->free_occlusion_queries = new_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->free_occlusion_queries[context->free_occlusion_query_count++] = query->id;
|
|
|
|
}
|
|
|
|
|
2009-07-24 10:44:14 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2009-08-03 08:06:51 +02:00
|
|
|
void context_alloc_event_query(struct wined3d_context *context, struct wined3d_event_query *query)
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (context->free_event_query_count)
|
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
query->object = context->free_event_queries[--context->free_event_query_count];
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
/* Using ARB_sync, not much to do here. */
|
|
|
|
query->object.sync = NULL;
|
|
|
|
TRACE("Allocated event query %p in context %p.\n", query->object.sync, context);
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE])
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
|
|
|
ENTER_GL();
|
2010-01-25 19:51:30 +01:00
|
|
|
GL_EXTCALL(glGenFencesAPPLE(1, &query->object.id));
|
2009-07-24 10:44:14 +02:00
|
|
|
checkGLcall("glGenFencesAPPLE");
|
|
|
|
LEAVE_GL();
|
|
|
|
|
2010-01-25 19:51:30 +01:00
|
|
|
TRACE("Allocated event query %u in context %p.\n", query->object.id, context);
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
else if(gl_info->supported[NV_FENCE])
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
|
|
|
ENTER_GL();
|
2010-01-25 19:51:30 +01:00
|
|
|
GL_EXTCALL(glGenFencesNV(1, &query->object.id));
|
2009-07-24 10:44:14 +02:00
|
|
|
checkGLcall("glGenFencesNV");
|
|
|
|
LEAVE_GL();
|
|
|
|
|
2010-01-25 19:51:30 +01:00
|
|
|
TRACE("Allocated event query %u in context %p.\n", query->object.id, context);
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Event queries not supported, not allocating query id.\n");
|
2010-01-25 19:51:30 +01:00
|
|
|
query->object.id = 0;
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
query->context = context;
|
|
|
|
list_add_head(&context->event_queries, &query->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_free_event_query(struct wined3d_event_query *query)
|
|
|
|
{
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context = query->context;
|
2009-07-24 10:44:14 +02:00
|
|
|
|
|
|
|
list_remove(&query->entry);
|
|
|
|
query->context = NULL;
|
|
|
|
|
|
|
|
if (context->free_event_query_count >= context->free_event_query_size - 1)
|
|
|
|
{
|
|
|
|
UINT new_size = context->free_event_query_size << 1;
|
2010-01-25 19:51:30 +01:00
|
|
|
union wined3d_gl_query_object *new_data = HeapReAlloc(GetProcessHeap(), 0, context->free_event_queries,
|
2009-07-24 10:44:14 +02:00
|
|
|
new_size * sizeof(*context->free_event_queries));
|
|
|
|
|
|
|
|
if (!new_data)
|
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
ERR("Failed to grow free list, leaking query %u in context %p.\n", query->object.id, context);
|
2009-07-24 10:44:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->free_event_query_size = new_size;
|
|
|
|
context->free_event_queries = new_data;
|
|
|
|
}
|
|
|
|
|
2010-01-25 19:51:30 +01:00
|
|
|
context->free_event_queries[context->free_event_query_count++] = query->object;
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
|
2010-08-15 23:21:42 +02:00
|
|
|
typedef void (context_fbo_entry_func_t)(struct wined3d_context *context, struct fbo_entry *entry);
|
|
|
|
|
|
|
|
static void context_enum_surface_fbo_entries(IWineD3DDeviceImpl *device,
|
|
|
|
IWineD3DSurfaceImpl *surface, context_fbo_entry_func_t *callback)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
2010-08-15 23:21:42 +02:00
|
|
|
for (i = 0; i < device->numContexts; ++i)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-08-15 23:21:42 +02:00
|
|
|
struct wined3d_context *context = device->contexts[i];
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
struct fbo_entry *entry, *entry2;
|
|
|
|
|
|
|
|
if (context->current_rt == surface) context->current_rt = NULL;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_list, struct fbo_entry, entry)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-08-15 23:21:42 +02:00
|
|
|
UINT j;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2010-08-15 23:21:42 +02:00
|
|
|
if (entry->depth_stencil == surface)
|
|
|
|
{
|
|
|
|
callback(context, entry);
|
|
|
|
continue;
|
|
|
|
}
|
2009-08-03 08:06:48 +02:00
|
|
|
|
2010-08-15 23:21:42 +02:00
|
|
|
for (j = 0; j < gl_info->limits.buffers; ++j)
|
|
|
|
{
|
|
|
|
if (entry->render_targets[j] == surface)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2010-08-15 23:21:42 +02:00
|
|
|
callback(context, entry);
|
|
|
|
break;
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
2010-08-15 23:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void context_queue_fbo_entry_destruction(struct wined3d_context *context, struct fbo_entry *entry)
|
|
|
|
{
|
|
|
|
list_remove(&entry->entry);
|
|
|
|
list_add_head(&context->fbo_destroy_list, &entry->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_resource_released(IWineD3DDeviceImpl *device, IWineD3DResource *resource, WINED3DRESOURCETYPE type)
|
|
|
|
{
|
|
|
|
if (!device->d3d_initialized) return;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2010-08-15 23:21:42 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case WINED3DRTYPE_SURFACE:
|
|
|
|
context_enum_surface_fbo_entries(device, (IWineD3DSurfaceImpl *)resource,
|
|
|
|
context_queue_fbo_entry_destruction);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void context_detach_fbo_entry(struct wined3d_context *context, struct fbo_entry *entry)
|
|
|
|
{
|
|
|
|
entry->attached = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_resource_unloaded(IWineD3DDeviceImpl *device, IWineD3DResource *resource, WINED3DRESOURCETYPE type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case WINED3DRTYPE_SURFACE:
|
|
|
|
context_enum_surface_fbo_entries(device, (IWineD3DSurfaceImpl *)resource,
|
|
|
|
context_detach_fbo_entry);
|
2008-09-18 14:57:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-17 21:59:51 +01:00
|
|
|
void context_surface_update(struct wined3d_context *context, IWineD3DSurfaceImpl *surface)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
struct fbo_entry *entry = context->current_fbo;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!entry || context->rebind_fbo) return;
|
|
|
|
|
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
|
|
|
{
|
2010-04-15 19:21:27 +02:00
|
|
|
if (surface == entry->render_targets[i])
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
|
|
|
TRACE("Updated surface %p is bound as color attachment %u to the current FBO.\n", surface, i);
|
|
|
|
context->rebind_fbo = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-15 19:21:28 +02:00
|
|
|
if (surface == entry->depth_stencil)
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
|
|
|
TRACE("Updated surface %p is bound as depth attachment to the current FBO.\n", surface);
|
|
|
|
context->rebind_fbo = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-15 21:07:24 +01:00
|
|
|
static BOOL context_set_pixel_format(const struct wined3d_gl_info *gl_info, HDC dc, int format)
|
|
|
|
{
|
|
|
|
int current = GetPixelFormat(dc);
|
|
|
|
|
|
|
|
if (current == format) return TRUE;
|
|
|
|
|
|
|
|
if (!current)
|
|
|
|
{
|
|
|
|
if (!SetPixelFormat(dc, format, NULL))
|
|
|
|
{
|
|
|
|
ERR("Failed to set pixel format %d on device context %p, last error %#x.\n",
|
|
|
|
format, dc, GetLastError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* By default WGL doesn't allow pixel format adjustments but we need it
|
|
|
|
* here. For this reason there's a Wine specific wglSetPixelFormat()
|
|
|
|
* which allows us to set the pixel format multiple times. Only use it
|
|
|
|
* when really needed. */
|
|
|
|
if (gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH])
|
|
|
|
{
|
|
|
|
if (!GL_EXTCALL(wglSetPixelFormatWINE(dc, format, NULL)))
|
|
|
|
{
|
|
|
|
ERR("wglSetPixelFormatWINE failed to set pixel format %d on device context %p.\n",
|
|
|
|
format, dc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OpenGL doesn't allow pixel format adjustments. Print an error and
|
|
|
|
* continue using the old format. There's a big chance that the old
|
|
|
|
* format works although with a performance hit and perhaps rendering
|
|
|
|
* errors. */
|
|
|
|
ERR("Unable to set pixel format %d on device context %p. Already using format %d.\n",
|
|
|
|
format, dc, current);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-15 21:07:31 +01:00
|
|
|
static void context_update_window(struct wined3d_context *context)
|
|
|
|
{
|
|
|
|
TRACE("Updating context %p window from %p to %p.\n",
|
|
|
|
context, context->win_handle, context->swapchain->win_handle);
|
|
|
|
|
|
|
|
if (context->valid)
|
|
|
|
{
|
|
|
|
if (!ReleaseDC(context->win_handle, context->hdc))
|
|
|
|
{
|
|
|
|
ERR("Failed to release device context %p, last error %#x.\n",
|
|
|
|
context->hdc, GetLastError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else context->valid = 1;
|
|
|
|
|
|
|
|
context->win_handle = context->swapchain->win_handle;
|
|
|
|
|
|
|
|
if (!(context->hdc = GetDC(context->win_handle)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get a device context for window %p.\n", context->win_handle);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!context_set_pixel_format(context->gl_info, context->hdc, context->pixel_format))
|
|
|
|
{
|
|
|
|
ERR("Failed to set pixel format %d on device context %p.\n",
|
|
|
|
context->pixel_format, context->hdc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pwglMakeCurrent(context->hdc, context->glCtx))
|
|
|
|
{
|
|
|
|
ERR("Failed to make GL context %p current on device context %p, last error %#x.\n",
|
|
|
|
context->glCtx, context->hdc, GetLastError());
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
context->valid = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2009-10-27 10:10:42 +01:00
|
|
|
static void context_validate(struct wined3d_context *context)
|
|
|
|
{
|
|
|
|
HWND wnd = WindowFromDC(context->hdc);
|
|
|
|
|
|
|
|
if (wnd != context->win_handle)
|
|
|
|
{
|
|
|
|
WARN("DC %p belongs to window %p instead of %p.\n",
|
|
|
|
context->hdc, wnd, context->win_handle);
|
|
|
|
context->valid = 0;
|
|
|
|
}
|
2010-03-15 21:07:31 +01:00
|
|
|
|
|
|
|
if (context->win_handle != context->swapchain->win_handle)
|
|
|
|
context_update_window(context);
|
2009-10-27 10:10:42 +01:00
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2009-08-03 08:06:51 +02:00
|
|
|
static void context_destroy_gl_resources(struct wined3d_context *context)
|
2009-07-22 10:41:06 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2009-07-24 10:44:13 +02:00
|
|
|
struct wined3d_occlusion_query *occlusion_query;
|
2009-07-24 10:44:14 +02:00
|
|
|
struct wined3d_event_query *event_query;
|
2009-07-22 10:41:06 +02:00
|
|
|
struct fbo_entry *entry, *entry2;
|
2009-10-28 11:00:10 +01:00
|
|
|
HGLRC restore_ctx;
|
|
|
|
HDC restore_dc;
|
2010-01-25 19:51:30 +01:00
|
|
|
unsigned int i;
|
2009-10-28 11:00:10 +01:00
|
|
|
|
|
|
|
restore_ctx = pwglGetCurrentContext();
|
|
|
|
restore_dc = pwglGetCurrentDC();
|
2009-07-22 10:41:06 +02:00
|
|
|
|
2009-10-27 10:10:42 +01:00
|
|
|
context_validate(context);
|
2009-10-28 11:00:10 +01:00
|
|
|
if (context->valid && restore_ctx != context->glCtx) pwglMakeCurrent(context->hdc, context->glCtx);
|
|
|
|
else restore_ctx = NULL;
|
2009-10-27 10:10:42 +01:00
|
|
|
|
2009-07-22 10:41:06 +02:00
|
|
|
ENTER_GL();
|
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(occlusion_query, &context->occlusion_queries, struct wined3d_occlusion_query, entry)
|
|
|
|
{
|
2009-10-29 10:37:11 +01:00
|
|
|
if (context->valid && gl_info->supported[ARB_OCCLUSION_QUERY])
|
2009-10-20 11:05:05 +02:00
|
|
|
GL_EXTCALL(glDeleteQueriesARB(1, &occlusion_query->id));
|
2009-07-24 10:44:13 +02:00
|
|
|
occlusion_query->context = NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-24 10:44:14 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(event_query, &context->event_queries, struct wined3d_event_query, entry)
|
|
|
|
{
|
2009-10-20 11:05:05 +02:00
|
|
|
if (context->valid)
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
if (event_query->object.sync) GL_EXTCALL(glDeleteSync(event_query->object.sync));
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE]) GL_EXTCALL(glDeleteFencesAPPLE(1, &event_query->object.id));
|
|
|
|
else if (gl_info->supported[NV_FENCE]) GL_EXTCALL(glDeleteFencesNV(1, &event_query->object.id));
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
event_query->context = NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-20 11:05:06 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_destroy_list, struct fbo_entry, entry)
|
|
|
|
{
|
|
|
|
if (!context->valid) entry->id = 0;
|
|
|
|
context_destroy_fbo_entry(context, entry);
|
|
|
|
}
|
|
|
|
|
2009-10-20 11:05:05 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_list, struct fbo_entry, entry)
|
|
|
|
{
|
|
|
|
if (!context->valid) entry->id = 0;
|
2009-07-22 10:41:06 +02:00
|
|
|
context_destroy_fbo_entry(context, entry);
|
|
|
|
}
|
2009-10-20 11:05:05 +02:00
|
|
|
|
|
|
|
if (context->valid)
|
2009-07-22 10:41:06 +02:00
|
|
|
{
|
|
|
|
if (context->dst_fbo)
|
|
|
|
{
|
|
|
|
TRACE("Destroy dst FBO %d\n", context->dst_fbo);
|
|
|
|
context_destroy_fbo(context, &context->dst_fbo);
|
|
|
|
}
|
|
|
|
if (context->dummy_arbfp_prog)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteProgramsARB(1, &context->dummy_arbfp_prog));
|
|
|
|
}
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_OCCLUSION_QUERY])
|
2009-08-14 18:12:49 +02:00
|
|
|
GL_EXTCALL(glDeleteQueriesARB(context->free_occlusion_query_count, context->free_occlusion_queries));
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2010-01-25 19:51:30 +01:00
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
if (event_query->object.sync) GL_EXTCALL(glDeleteSync(event_query->object.sync));
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE])
|
|
|
|
{
|
|
|
|
for (i = 0; i < context->free_event_query_count; ++i)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteFencesAPPLE(1, &context->free_event_queries[i].id));
|
|
|
|
}
|
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
else if (gl_info->supported[NV_FENCE])
|
2010-01-25 19:51:30 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < context->free_event_query_count; ++i)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteFencesNV(1, &context->free_event_queries[i].id));
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 10:44:14 +02:00
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
checkGLcall("context cleanup");
|
2009-07-22 10:41:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, context->free_occlusion_queries);
|
2009-07-24 10:44:14 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, context->free_event_queries);
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2009-10-28 11:00:10 +01:00
|
|
|
if (restore_ctx)
|
|
|
|
{
|
|
|
|
if (!pwglMakeCurrent(restore_dc, restore_ctx))
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("Failed to restore GL context %p on device context %p, last error %#x.\n",
|
|
|
|
restore_ctx, restore_dc, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pwglGetCurrentContext() && !pwglMakeCurrent(NULL, NULL))
|
2009-07-22 10:41:06 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to disable GL context.\n");
|
|
|
|
}
|
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
ReleaseDC(context->win_handle, context->hdc);
|
2009-07-22 10:41:06 +02:00
|
|
|
|
2009-08-07 08:51:21 +02:00
|
|
|
if (!pwglDeleteContext(context->glCtx))
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("wglDeleteContext(%p) failed, last error %#x.\n", context->glCtx, err);
|
|
|
|
}
|
2009-07-22 10:41:06 +02:00
|
|
|
}
|
|
|
|
|
2009-07-22 14:03:36 +02:00
|
|
|
DWORD context_get_tls_idx(void)
|
|
|
|
{
|
|
|
|
return wined3d_context_tls_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_set_tls_idx(DWORD idx)
|
|
|
|
{
|
|
|
|
wined3d_context_tls_idx = idx;
|
|
|
|
}
|
|
|
|
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context_get_current(void)
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
|
|
|
return TlsGetValue(wined3d_context_tls_idx);
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2009-08-03 08:06:51 +02:00
|
|
|
BOOL context_set_current(struct wined3d_context *ctx)
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *old = context_get_current();
|
2009-07-22 14:03:36 +02:00
|
|
|
|
|
|
|
if (old == ctx)
|
|
|
|
{
|
|
|
|
TRACE("Already using D3D context %p.\n", ctx);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-07-22 10:41:06 +02:00
|
|
|
if (old)
|
|
|
|
{
|
|
|
|
if (old->destroyed)
|
|
|
|
{
|
|
|
|
TRACE("Switching away from destroyed context %p.\n", old);
|
|
|
|
context_destroy_gl_resources(old);
|
|
|
|
HeapFree(GetProcessHeap(), 0, old);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
old->current = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 14:03:36 +02:00
|
|
|
if (ctx)
|
|
|
|
{
|
|
|
|
TRACE("Switching to D3D context %p, GL context %p, device context %p.\n", ctx, ctx->glCtx, ctx->hdc);
|
|
|
|
if (!pwglMakeCurrent(ctx->hdc, ctx->glCtx))
|
|
|
|
{
|
2009-09-23 10:05:59 +02:00
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("Failed to make GL context %p current on device context %p, last error %#x.\n",
|
|
|
|
ctx->glCtx, ctx->hdc, err);
|
|
|
|
TlsSetValue(wined3d_context_tls_idx, NULL);
|
2009-07-22 14:03:36 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-07-22 10:41:06 +02:00
|
|
|
ctx->current = 1;
|
2009-07-22 14:03:36 +02:00
|
|
|
}
|
2009-09-19 15:52:18 +02:00
|
|
|
else if(pwglGetCurrentContext())
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
|
|
|
TRACE("Clearing current D3D context.\n");
|
|
|
|
if (!pwglMakeCurrent(NULL, NULL))
|
|
|
|
{
|
2009-09-23 10:05:59 +02:00
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("Failed to clear current GL context, last error %#x.\n", err);
|
|
|
|
TlsSetValue(wined3d_context_tls_idx, NULL);
|
2009-07-22 14:03:36 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TlsSetValue(wined3d_context_tls_idx, ctx);
|
|
|
|
}
|
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
void context_release(struct wined3d_context *context)
|
|
|
|
{
|
|
|
|
TRACE("Releasing context %p, level %u.\n", context, context->level);
|
|
|
|
|
|
|
|
if (WARN_ON(d3d))
|
|
|
|
{
|
|
|
|
if (!context->level)
|
|
|
|
WARN("Context %p is not active.\n", context);
|
|
|
|
else if (context != context_get_current())
|
|
|
|
WARN("Context %p is not the current context.\n", context);
|
|
|
|
}
|
|
|
|
|
2009-10-28 11:00:13 +01:00
|
|
|
if (!--context->level && context->restore_ctx)
|
|
|
|
{
|
|
|
|
TRACE("Restoring GL context %p on device context %p.\n", context->restore_ctx, context->restore_dc);
|
|
|
|
if (!pwglMakeCurrent(context->restore_dc, context->restore_ctx))
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("Failed to restore GL context %p on device context %p, last error %#x.\n",
|
|
|
|
context->restore_ctx, context->restore_dc, err);
|
|
|
|
}
|
|
|
|
context->restore_ctx = NULL;
|
|
|
|
context->restore_dc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void context_enter(struct wined3d_context *context)
|
|
|
|
{
|
|
|
|
TRACE("Entering context %p, level %u.\n", context, context->level + 1);
|
|
|
|
|
|
|
|
if (!context->level++)
|
|
|
|
{
|
|
|
|
const struct wined3d_context *current_context = context_get_current();
|
|
|
|
HGLRC current_gl = pwglGetCurrentContext();
|
|
|
|
|
|
|
|
if (current_gl && (!current_context || current_context->glCtx != current_gl))
|
|
|
|
{
|
|
|
|
TRACE("Another GL context (%p on device context %p) is already current.\n",
|
|
|
|
current_gl, pwglGetCurrentDC());
|
|
|
|
context->restore_ctx = current_gl;
|
|
|
|
context->restore_dc = pwglGetCurrentDC();
|
|
|
|
}
|
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
}
|
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Context_MarkStateDirty
|
|
|
|
*
|
|
|
|
* Marks a state in a context dirty. Only one context, opposed to
|
|
|
|
* IWineD3DDeviceImpl_MarkStateDirty, which marks the state dirty in all
|
|
|
|
* contexts
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* context: Context to mark the state dirty in
|
|
|
|
* state: State to mark dirty
|
2008-03-09 19:30:08 +01:00
|
|
|
* StateTable: Pointer to the state table in use(for state grouping)
|
2007-02-12 19:21:10 +01:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2009-08-03 08:06:51 +02:00
|
|
|
static void Context_MarkStateDirty(struct wined3d_context *context, DWORD state, const struct StateEntry *StateTable)
|
|
|
|
{
|
2007-02-12 19:21:10 +01:00
|
|
|
DWORD rep = StateTable[state].representative;
|
|
|
|
DWORD idx;
|
|
|
|
BYTE shift;
|
|
|
|
|
2009-08-21 09:12:28 +02:00
|
|
|
if (isStateDirty(context, rep)) return;
|
2007-02-12 19:21:10 +01:00
|
|
|
|
|
|
|
context->dirtyArray[context->numDirtyEntries++] = rep;
|
2009-12-29 17:10:22 +01:00
|
|
|
idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
|
|
|
|
shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
|
2007-02-12 19:21:10 +01:00
|
|
|
context->isStateDirty[idx] |= (1 << shift);
|
|
|
|
}
|
|
|
|
|
2008-04-27 19:35:27 +02:00
|
|
|
/* This function takes care of WineD3D pixel format selection. */
|
2009-03-24 10:09:24 +01:00
|
|
|
static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc,
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *color_format, const struct wined3d_format *ds_format,
|
2010-03-14 21:53:23 +01:00
|
|
|
BOOL auxBuffers, int numSamples, BOOL findCompatible)
|
2008-04-27 19:35:27 +02:00
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
int iPixelFormat=0;
|
|
|
|
unsigned int matchtry;
|
2008-04-27 19:35:27 +02:00
|
|
|
short redBits, greenBits, blueBits, alphaBits, colorBits;
|
|
|
|
short depthBits=0, stencilBits=0;
|
|
|
|
|
2010-08-22 23:35:38 +02:00
|
|
|
static const struct
|
|
|
|
{
|
2008-07-21 16:22:22 +02:00
|
|
|
BOOL require_aux;
|
|
|
|
BOOL exact_alpha;
|
|
|
|
BOOL exact_color;
|
2010-08-22 23:35:38 +02:00
|
|
|
}
|
|
|
|
matches[] =
|
|
|
|
{
|
2008-08-14 23:47:19 +02:00
|
|
|
/* First, try without alpha match buffers. MacOS supports aux buffers only
|
|
|
|
* on A8R8G8B8, and we prefer better offscreen rendering over an alpha match.
|
|
|
|
* Then try without aux buffers - this is the most common cause for not
|
|
|
|
* finding a pixel format. Also some drivers(the open source ones)
|
2008-07-21 16:22:22 +02:00
|
|
|
* only offer 32 bit ARB pixel formats. First try without an exact alpha
|
|
|
|
* match, then try without an exact alpha and color match.
|
|
|
|
*/
|
2008-08-14 23:47:19 +02:00
|
|
|
{ TRUE, TRUE, TRUE },
|
|
|
|
{ TRUE, FALSE, TRUE },
|
2008-09-03 20:56:17 +02:00
|
|
|
{ FALSE, TRUE, TRUE },
|
|
|
|
{ FALSE, FALSE, TRUE },
|
2008-08-14 23:47:19 +02:00
|
|
|
{ TRUE, FALSE, FALSE },
|
2008-09-03 20:56:17 +02:00
|
|
|
{ FALSE, FALSE, FALSE },
|
2008-07-21 16:22:22 +02:00
|
|
|
};
|
|
|
|
|
2008-04-27 19:42:48 +02:00
|
|
|
int i = 0;
|
|
|
|
int nCfgs = This->adapter->nCfgs;
|
2008-04-27 19:35:27 +02:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
TRACE("ColorFormat=%s, DepthStencilFormat=%s, auxBuffers=%d, numSamples=%d, findCompatible=%d\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
debug_d3dformat(color_format->id), debug_d3dformat(ds_format->id),
|
2010-03-14 21:53:23 +01:00
|
|
|
auxBuffers, numSamples, findCompatible);
|
2008-06-02 22:39:51 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (!getColorBits(color_format, &redBits, &greenBits, &blueBits, &alphaBits, &colorBits))
|
2009-03-13 10:44:18 +01:00
|
|
|
{
|
2009-03-24 10:09:24 +01:00
|
|
|
ERR("Unable to get color bits for format %s (%#x)!\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
debug_d3dformat(color_format->id), color_format->id);
|
2008-04-27 19:35:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
getDepthStencilBits(ds_format, &depthBits, &stencilBits);
|
2009-03-24 10:09:24 +01:00
|
|
|
|
2008-08-16 15:49:11 +02:00
|
|
|
for(matchtry = 0; matchtry < (sizeof(matches) / sizeof(matches[0])) && !iPixelFormat; matchtry++) {
|
2008-07-21 16:22:22 +02:00
|
|
|
for(i=0; i<nCfgs; i++) {
|
|
|
|
BOOL exactDepthMatch = TRUE;
|
2008-10-07 16:01:01 +02:00
|
|
|
WineD3D_PixelFormat *cfg = &This->adapter->cfgs[i];
|
2008-07-21 16:22:22 +02:00
|
|
|
|
|
|
|
/* For now only accept RGBA formats. Perhaps some day we will
|
|
|
|
* allow floating point formats for pbuffers. */
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->iPixelType != WGL_TYPE_RGBA_ARB)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* In window mode we need a window drawable format and double buffering. */
|
|
|
|
if(!(cfg->windowDrawable && cfg->doubleBuffer))
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* We like to have aux buffers in backbuffer mode */
|
2008-10-07 16:01:01 +02:00
|
|
|
if(auxBuffers && !cfg->auxBuffers && matches[matchtry].require_aux)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if(matches[matchtry].exact_color) {
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->redSize != redBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->greenSize != greenBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->blueSize != blueBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
} else {
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->redSize < redBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->greenSize < greenBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->blueSize < blueBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(matches[matchtry].exact_alpha) {
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->alphaSize != alphaBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
} else {
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->alphaSize < alphaBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We try to locate a format which matches our requirements exactly. In case of
|
|
|
|
* depth it is no problem to emulate 16-bit using e.g. 24-bit, so accept that. */
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->depthSize < depthBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
2008-10-07 16:01:01 +02:00
|
|
|
else if(cfg->depthSize > depthBits)
|
2008-07-21 16:22:22 +02:00
|
|
|
exactDepthMatch = FALSE;
|
|
|
|
|
|
|
|
/* In all cases make sure the number of stencil bits matches our requirements
|
|
|
|
* even when we don't need stencil because it could affect performance EXCEPT
|
|
|
|
* on cards which don't offer depth formats without stencil like the i915 drivers
|
|
|
|
* on Linux. */
|
2008-10-07 16:01:01 +02:00
|
|
|
if(stencilBits != cfg->stencilSize && !(This->adapter->brokenStencil && stencilBits <= cfg->stencilSize))
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Check multisampling support */
|
2008-10-07 16:01:01 +02:00
|
|
|
if(cfg->numSamples != numSamples)
|
2008-07-21 16:22:22 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* When we have passed all the checks then we have found a format which matches our
|
|
|
|
* requirements. Note that we only check for a limit number of capabilities right now,
|
|
|
|
* so there can easily be a dozen of pixel formats which appear to be the 'same' but
|
|
|
|
* can still differ in things like multisampling, stereo, SRGB and other flags.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Exit the loop as we have found a format :) */
|
|
|
|
if(exactDepthMatch) {
|
2008-10-07 16:01:01 +02:00
|
|
|
iPixelFormat = cfg->iPixelFormat;
|
2008-07-21 16:22:22 +02:00
|
|
|
break;
|
|
|
|
} else if(!iPixelFormat) {
|
|
|
|
/* In the end we might end up with a format which doesn't exactly match our depth
|
|
|
|
* requirements. Accept the first format we found because formats with higher iPixelFormat
|
|
|
|
* values tend to have more extended capabilities (e.g. multisampling) which we don't need. */
|
2008-10-07 16:01:01 +02:00
|
|
|
iPixelFormat = cfg->iPixelFormat;
|
2008-07-21 16:22:22 +02:00
|
|
|
}
|
2008-04-27 19:42:48 +02:00
|
|
|
}
|
2008-04-27 19:35:27 +02:00
|
|
|
}
|
|
|
|
|
2008-04-27 19:42:48 +02:00
|
|
|
/* When findCompatible is set and no suitable format was found, let ChoosePixelFormat choose a pixel format in order not to crash. */
|
|
|
|
if(!iPixelFormat && !findCompatible) {
|
2008-04-27 19:35:27 +02:00
|
|
|
ERR("Can't find a suitable iPixelFormat\n");
|
|
|
|
return FALSE;
|
2008-04-28 23:13:12 +02:00
|
|
|
} else if(!iPixelFormat) {
|
2008-04-27 19:35:27 +02:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
|
2008-04-27 19:42:48 +02:00
|
|
|
TRACE("Falling back to ChoosePixelFormat as we weren't able to find an exactly matching pixel format\n");
|
2008-04-27 19:35:27 +02:00
|
|
|
/* PixelFormat selection */
|
|
|
|
ZeroMemory(&pfd, sizeof(pfd));
|
|
|
|
pfd.nSize = sizeof(pfd);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
|
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cAlphaBits = alphaBits;
|
|
|
|
pfd.cColorBits = colorBits;
|
|
|
|
pfd.cDepthBits = depthBits;
|
|
|
|
pfd.cStencilBits = stencilBits;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
|
|
|
|
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
|
|
|
|
if(!iPixelFormat) {
|
|
|
|
/* If this happens something is very wrong as ChoosePixelFormat barely fails */
|
|
|
|
ERR("Can't find a suitable iPixelFormat\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-24 10:09:24 +01:00
|
|
|
TRACE("Found iPixelFormat=%d for ColorFormat=%s, DepthStencilFormat=%s\n",
|
2010-08-30 20:29:49 +02:00
|
|
|
iPixelFormat, debug_d3dformat(color_format->id), debug_d3dformat(ds_format->id));
|
2008-04-27 19:35:27 +02:00
|
|
|
return iPixelFormat;
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-08-30 20:29:49 +02:00
|
|
|
struct wined3d_context *context_create(IWineD3DSwapChainImpl *swapchain,
|
|
|
|
IWineD3DSurfaceImpl *target, const struct wined3d_format *ds_format)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
2010-03-15 21:07:25 +01:00
|
|
|
IWineD3DDeviceImpl *device = swapchain->device;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *color_format;
|
2010-03-14 21:53:24 +01:00
|
|
|
struct wined3d_context *ret;
|
2010-03-14 21:53:23 +01:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
BOOL auxBuffers = FALSE;
|
|
|
|
int numSamples = 0;
|
|
|
|
int pixel_format;
|
2009-03-25 10:12:27 +01:00
|
|
|
unsigned int s;
|
2010-03-14 21:53:24 +01:00
|
|
|
DWORD state;
|
2009-07-15 12:21:16 +02:00
|
|
|
HGLRC ctx;
|
|
|
|
HDC hdc;
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2010-03-15 21:07:25 +01:00
|
|
|
TRACE("swapchain %p, target %p, window %p.\n", swapchain, target, swapchain->win_handle);
|
2007-08-09 14:12:42 +02:00
|
|
|
|
2010-03-14 21:53:24 +01:00
|
|
|
ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate context memory.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-15 21:07:25 +01:00
|
|
|
if (!(hdc = GetDC(swapchain->win_handle)))
|
2010-03-14 21:53:23 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to retrieve a device context.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2008-04-27 20:40:33 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
color_format = target->resource.format;
|
2008-04-27 20:40:33 +02:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* In case of ORM_BACKBUFFER, make sure to request an alpha component for
|
|
|
|
* X4R4G4B4/X8R8G8B8 as we might need it for the backbuffer. */
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
|
|
|
|
{
|
|
|
|
auxBuffers = TRUE;
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (color_format->id == WINED3DFMT_B4G4R4X4_UNORM)
|
|
|
|
color_format = wined3d_get_format(gl_info, WINED3DFMT_B4G4R4A4_UNORM);
|
|
|
|
else if (color_format->id == WINED3DFMT_B8G8R8X8_UNORM)
|
|
|
|
color_format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM);
|
2010-03-14 21:53:23 +01:00
|
|
|
}
|
2007-08-06 20:53:20 +02:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* DirectDraw supports 8bit paletted render targets and these are used by
|
|
|
|
* old games like Starcraft and C&C. Most modern hardware doesn't support
|
|
|
|
* 8bit natively so we perform some form of 8bit -> 32bit conversion. The
|
|
|
|
* conversion (ab)uses the alpha component for storing the palette index.
|
|
|
|
* For this reason we require a format with 8bit alpha, so request
|
|
|
|
* A8R8G8B8. */
|
2010-08-30 20:29:49 +02:00
|
|
|
if (color_format->id == WINED3DFMT_P8_UINT)
|
|
|
|
color_format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM);
|
2007-08-08 03:09:38 +02:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* D3D only allows multisampling when SwapEffect is set to WINED3DSWAPEFFECT_DISCARD. */
|
2010-03-15 21:07:25 +01:00
|
|
|
if (swapchain->presentParms.MultiSampleType && (swapchain->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD))
|
2010-03-14 21:53:23 +01:00
|
|
|
{
|
|
|
|
if (!gl_info->supported[ARB_MULTISAMPLE])
|
|
|
|
WARN("The application is requesting multisampling without support.\n");
|
|
|
|
else
|
|
|
|
{
|
2010-03-15 21:07:25 +01:00
|
|
|
TRACE("Requesting multisample type %#x.\n", swapchain->presentParms.MultiSampleType);
|
|
|
|
numSamples = swapchain->presentParms.MultiSampleType;
|
2008-02-23 00:27:38 +01:00
|
|
|
}
|
2010-03-14 21:53:23 +01:00
|
|
|
}
|
2008-02-23 00:27:38 +01:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* Try to find a pixel format which matches our requirements. */
|
2010-08-30 20:29:49 +02:00
|
|
|
pixel_format = WineD3D_ChoosePixelFormat(device, hdc, color_format, ds_format,
|
2010-03-14 21:53:23 +01:00
|
|
|
auxBuffers, numSamples, FALSE /* findCompatible */);
|
2007-08-09 01:04:30 +02:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* Try to locate a compatible format if we weren't able to find anything. */
|
|
|
|
if (!pixel_format)
|
|
|
|
{
|
|
|
|
TRACE("Trying to locate a compatible pixel format because an exact match failed.\n");
|
2010-08-30 20:29:49 +02:00
|
|
|
pixel_format = WineD3D_ChoosePixelFormat(device, hdc, color_format, ds_format,
|
2010-03-14 21:53:23 +01:00
|
|
|
auxBuffers, 0 /* numSamples */, TRUE /* findCompatible */);
|
|
|
|
}
|
2007-08-09 01:04:30 +02:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* If we still don't have a pixel format, something is very wrong as ChoosePixelFormat barely fails */
|
|
|
|
if (!pixel_format)
|
|
|
|
{
|
|
|
|
ERR("Can't find a suitable pixel format.\n");
|
2010-03-14 21:53:24 +01:00
|
|
|
goto out;
|
2010-03-14 21:53:23 +01:00
|
|
|
}
|
2008-04-28 23:44:21 +02:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd);
|
2010-03-15 21:07:24 +01:00
|
|
|
if (!context_set_pixel_format(gl_info, hdc, pixel_format))
|
2010-03-14 21:53:23 +01:00
|
|
|
{
|
2010-03-15 21:07:24 +01:00
|
|
|
ERR("Failed to set pixel format %d on device context %p.\n", pixel_format, hdc);
|
|
|
|
goto out;
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2007-08-16 15:04:47 +02:00
|
|
|
ctx = pwglCreateContext(hdc);
|
2010-03-15 21:07:25 +01:00
|
|
|
if (device->numContexts)
|
2009-07-15 12:21:17 +02:00
|
|
|
{
|
2010-03-15 21:07:25 +01:00
|
|
|
if (!pwglShareLists(device->contexts[0]->glCtx, ctx))
|
2009-07-15 12:21:17 +02:00
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("wglShareLists(%p, %p) failed, last error %#x.\n",
|
2010-03-15 21:07:25 +01:00
|
|
|
device->contexts[0]->glCtx, ctx, err);
|
2009-07-15 12:21:17 +02:00
|
|
|
}
|
|
|
|
}
|
2007-08-08 03:09:38 +02:00
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
if(!ctx) {
|
2007-08-08 03:09:38 +02:00
|
|
|
ERR("Failed to create a WGL context\n");
|
2007-02-12 19:21:10 +01:00
|
|
|
goto out;
|
|
|
|
}
|
2010-03-14 21:53:24 +01:00
|
|
|
|
2010-03-15 21:07:25 +01:00
|
|
|
if (!device_context_add(device, ret))
|
2010-03-14 21:53:24 +01:00
|
|
|
{
|
2007-02-12 19:21:10 +01:00
|
|
|
ERR("Failed to add the newly created context to the context list\n");
|
2009-07-15 12:21:17 +02:00
|
|
|
if (!pwglDeleteContext(ctx))
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, err);
|
|
|
|
}
|
2007-02-12 19:21:10 +01:00
|
|
|
goto out;
|
|
|
|
}
|
2010-03-14 21:53:24 +01:00
|
|
|
|
2010-03-15 21:07:23 +01:00
|
|
|
ret->gl_info = gl_info;
|
2010-03-14 21:53:24 +01:00
|
|
|
|
|
|
|
/* Mark all states dirty to force a proper initialization of the states
|
|
|
|
* on the first use of the context. */
|
|
|
|
for (state = 0; state <= STATE_HIGHEST; ++state)
|
|
|
|
{
|
2010-03-15 21:07:25 +01:00
|
|
|
if (device->StateTable[state].representative)
|
|
|
|
Context_MarkStateDirty(ret, state, device->StateTable);
|
2010-03-14 21:53:24 +01:00
|
|
|
}
|
|
|
|
|
2010-03-15 21:07:25 +01:00
|
|
|
ret->swapchain = swapchain;
|
2010-04-21 22:02:31 +02:00
|
|
|
ret->current_rt = target;
|
2010-03-14 21:53:24 +01:00
|
|
|
ret->tid = GetCurrentThreadId();
|
|
|
|
|
2010-04-18 22:50:45 +02:00
|
|
|
ret->render_offscreen = surface_is_offscreen(target);
|
2009-12-15 17:51:37 +01:00
|
|
|
ret->draw_buffer_dirty = TRUE;
|
2010-03-14 21:53:24 +01:00
|
|
|
ret->valid = 1;
|
|
|
|
|
|
|
|
ret->glCtx = ctx;
|
2010-03-15 21:07:25 +01:00
|
|
|
ret->win_handle = swapchain->win_handle;
|
2010-03-14 21:53:24 +01:00
|
|
|
ret->hdc = hdc;
|
2010-03-15 21:07:31 +01:00
|
|
|
ret->pixel_format = pixel_format;
|
2010-03-14 21:53:24 +01:00
|
|
|
|
2010-03-15 21:07:25 +01:00
|
|
|
if (device->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *)device))
|
|
|
|
{
|
2008-03-04 02:30:23 +01:00
|
|
|
/* Create the dirty constants array and initialize them to dirty */
|
|
|
|
ret->vshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
|
2010-03-15 21:07:25 +01:00
|
|
|
sizeof(*ret->vshader_const_dirty) * device->d3d_vshader_constantF);
|
2008-03-04 02:30:23 +01:00
|
|
|
ret->pshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
|
2010-03-15 21:07:25 +01:00
|
|
|
sizeof(*ret->pshader_const_dirty) * device->d3d_pshader_constantF);
|
2008-03-04 02:30:23 +01:00
|
|
|
memset(ret->vshader_const_dirty, 1,
|
2010-03-15 21:07:25 +01:00
|
|
|
sizeof(*ret->vshader_const_dirty) * device->d3d_vshader_constantF);
|
2008-03-04 02:30:23 +01:00
|
|
|
memset(ret->pshader_const_dirty, 1,
|
2010-03-15 21:07:25 +01:00
|
|
|
sizeof(*ret->pshader_const_dirty) * device->d3d_pshader_constantF);
|
2008-03-04 02:30:23 +01:00
|
|
|
}
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2010-05-04 20:39:52 +02:00
|
|
|
ret->blit_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
gl_info->limits.buffers * sizeof(*ret->blit_targets));
|
|
|
|
if (!ret->blit_targets) goto out;
|
|
|
|
|
2010-07-30 10:15:26 +02:00
|
|
|
ret->draw_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
gl_info->limits.buffers * sizeof(*ret->draw_buffers));
|
|
|
|
if (!ret->draw_buffers) goto out;
|
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
ret->free_occlusion_query_size = 4;
|
|
|
|
ret->free_occlusion_queries = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
ret->free_occlusion_query_size * sizeof(*ret->free_occlusion_queries));
|
|
|
|
if (!ret->free_occlusion_queries) goto out;
|
|
|
|
|
|
|
|
list_init(&ret->occlusion_queries);
|
|
|
|
|
2009-07-24 10:44:14 +02:00
|
|
|
ret->free_event_query_size = 4;
|
|
|
|
ret->free_event_queries = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
ret->free_event_query_size * sizeof(*ret->free_event_queries));
|
|
|
|
if (!ret->free_event_queries) goto out;
|
|
|
|
|
|
|
|
list_init(&ret->event_queries);
|
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
TRACE("Successfully created new context %p\n", ret);
|
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
list_init(&ret->fbo_list);
|
2009-10-20 11:05:06 +02:00
|
|
|
list_init(&ret->fbo_destroy_list);
|
2008-08-21 18:34:55 +02:00
|
|
|
|
2009-10-28 11:00:13 +01:00
|
|
|
context_enter(ret);
|
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
/* Set up the context defaults */
|
2009-07-22 14:03:36 +02:00
|
|
|
if (!context_set_current(ret))
|
|
|
|
{
|
2007-02-12 19:21:10 +01:00
|
|
|
ERR("Cannot activate context to set up defaults\n");
|
2009-10-28 11:00:13 +01:00
|
|
|
context_release(ret);
|
2007-02-12 19:21:10 +01:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-09-29 16:58:44 +02:00
|
|
|
ENTER_GL();
|
2008-04-08 14:20:27 +02:00
|
|
|
|
|
|
|
glGetIntegerv(GL_AUX_BUFFERS, &ret->aux_buffers);
|
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
TRACE("Setting up the screen\n");
|
|
|
|
/* Clear the screen */
|
2009-07-07 11:08:01 +02:00
|
|
|
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
|
2007-02-12 19:21:10 +01:00
|
|
|
checkGLcall("glClearColor");
|
|
|
|
glClearIndex(0);
|
|
|
|
glClearDepth(1);
|
|
|
|
glClearStencil(0xffff);
|
|
|
|
|
|
|
|
checkGLcall("glClear");
|
|
|
|
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
|
|
|
|
checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
|
|
|
|
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
|
|
|
|
checkGLcall("glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
|
|
|
|
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
|
|
|
checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
|
|
|
|
|
2010-03-15 21:07:25 +01:00
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, device->surface_alignment);
|
|
|
|
checkGLcall("glPixelStorei(GL_PACK_ALIGNMENT, device->surface_alignment);");
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, device->surface_alignment);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, device->surface_alignment);");
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[APPLE_CLIENT_STORAGE])
|
|
|
|
{
|
2007-03-31 23:02:37 +02:00
|
|
|
/* Most textures will use client storage if supported. Exceptions are non-native power of 2 textures
|
|
|
|
* and textures in DIB sections(due to the memory protection).
|
|
|
|
*/
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
|
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_VERTEX_BLEND])
|
|
|
|
{
|
2007-04-27 00:43:15 +02:00
|
|
|
/* Direct3D always uses n-1 weights for n world matrices and uses 1 - sum for the last one
|
|
|
|
* this is equal to GL_WEIGHT_SUM_UNITY_ARB. Enabling it doesn't do anything unless
|
|
|
|
* GL_VERTEX_BLEND_ARB isn't enabled too
|
|
|
|
*/
|
|
|
|
glEnable(GL_WEIGHT_SUM_UNITY_ARB);
|
|
|
|
checkGLcall("glEnable(GL_WEIGHT_SUM_UNITY_ARB)");
|
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[NV_TEXTURE_SHADER2])
|
|
|
|
{
|
2007-05-07 21:08:14 +02:00
|
|
|
/* Set up the previous texture input for all shader units. This applies to bump mapping, and in d3d
|
|
|
|
* the previous texture where to source the offset from is always unit - 1.
|
|
|
|
*/
|
2009-10-29 10:37:10 +01:00
|
|
|
for (s = 1; s < gl_info->limits.textures; ++s)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2007-05-07 21:08:14 +02:00
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s));
|
|
|
|
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1);
|
2009-07-07 11:08:02 +02:00
|
|
|
checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ...");
|
2007-05-07 21:08:14 +02:00
|
|
|
}
|
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
|
|
|
|
{
|
2009-05-07 11:40:44 +02:00
|
|
|
/* MacOS(radeon X1600 at least, but most likely others too) refuses to draw if GLSL and ARBFP are
|
|
|
|
* enabled, but the currently bound arbfp program is 0. Enabling ARBFP with prog 0 is invalid, but
|
|
|
|
* GLSL should bypass this. This causes problems in programs that never use the fixed function pipeline,
|
|
|
|
* because the ARBFP extension is enabled by the ARBFP pipeline at context creation, but no program
|
|
|
|
* is ever assigned.
|
|
|
|
*
|
|
|
|
* So make sure a program is assigned to each context. The first real ARBFP use will set a different
|
|
|
|
* program and the dummy program is destroyed when the context is destroyed.
|
|
|
|
*/
|
|
|
|
const char *dummy_program =
|
|
|
|
"!!ARBfp1.0\n"
|
|
|
|
"MOV result.color, fragment.color.primary;\n"
|
|
|
|
"END\n";
|
|
|
|
GL_EXTCALL(glGenProgramsARB(1, &ret->dummy_arbfp_prog));
|
|
|
|
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ret->dummy_arbfp_prog));
|
|
|
|
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(dummy_program), dummy_program));
|
|
|
|
}
|
2008-03-22 14:31:52 +01:00
|
|
|
|
2009-10-29 10:37:10 +01:00
|
|
|
for (s = 0; s < gl_info->limits.point_sprite_units; ++s)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2009-05-06 19:36:08 +02:00
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s));
|
|
|
|
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
|
2009-07-07 11:08:02 +02:00
|
|
|
checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)");
|
2007-06-17 00:26:17 +02:00
|
|
|
}
|
2009-08-10 09:30:50 +02:00
|
|
|
|
2010-06-11 16:05:23 +02:00
|
|
|
if (gl_info->supported[WINED3D_GL_VERSION_2_0])
|
|
|
|
{
|
2010-07-16 18:39:06 +02:00
|
|
|
/* Windows doesn't support to query the glPointParameteri function pointer, so use the
|
|
|
|
* NV_POINT_SPRITE extension.
|
|
|
|
*/
|
|
|
|
if (glPointParameteri)
|
|
|
|
{
|
|
|
|
glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);
|
|
|
|
checkGLcall("glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT)");
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[NV_POINT_SPRITE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glPointParameteriNV(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT));
|
|
|
|
checkGLcall("glPointParameteriNV(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT)");
|
|
|
|
}
|
2010-06-11 16:05:23 +02:00
|
|
|
}
|
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_PROVOKING_VERTEX])
|
2009-09-23 10:05:58 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glProvokingVertex(GL_FIRST_VERTEX_CONVENTION));
|
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
else if (gl_info->supported[EXT_PROVOKING_VERTEX])
|
2009-08-10 09:30:50 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glProvokingVertexEXT(GL_FIRST_VERTEX_CONVENTION_EXT));
|
|
|
|
}
|
|
|
|
|
2007-09-29 16:58:44 +02:00
|
|
|
LEAVE_GL();
|
2007-03-31 23:02:37 +02:00
|
|
|
|
2010-03-15 21:07:25 +01:00
|
|
|
device->frag_pipe->enable_extension((IWineD3DDevice *)device, TRUE);
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2010-03-14 21:53:24 +01:00
|
|
|
TRACE("Created context %p.\n", ret);
|
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
return ret;
|
2008-08-21 18:34:55 +02:00
|
|
|
|
|
|
|
out:
|
2010-03-14 21:53:24 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret->free_event_queries);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ret->free_occlusion_queries);
|
2010-07-30 10:15:26 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret->draw_buffers);
|
2010-05-04 20:39:52 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret->blit_targets);
|
2010-03-14 21:53:24 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret->pshader_const_dirty);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ret->vshader_const_dirty);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ret);
|
2008-08-21 18:34:55 +02:00
|
|
|
return NULL;
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2009-10-28 11:00:14 +01:00
|
|
|
void context_destroy(IWineD3DDeviceImpl *This, struct wined3d_context *context)
|
2009-07-22 10:41:06 +02:00
|
|
|
{
|
|
|
|
BOOL destroy;
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2007-02-12 19:22:41 +01:00
|
|
|
TRACE("Destroying ctx %p\n", context);
|
2008-08-24 23:43:02 +02:00
|
|
|
|
2009-07-22 10:41:06 +02:00
|
|
|
if (context->tid == GetCurrentThreadId() || !context->current)
|
|
|
|
{
|
|
|
|
context_destroy_gl_resources(context);
|
2009-10-28 11:00:10 +01:00
|
|
|
TlsSetValue(wined3d_context_tls_idx, NULL);
|
2009-07-22 10:41:06 +02:00
|
|
|
destroy = TRUE;
|
2009-05-07 11:40:44 +02:00
|
|
|
}
|
2009-07-22 10:41:06 +02:00
|
|
|
else
|
2009-06-29 10:11:24 +02:00
|
|
|
{
|
2009-07-22 10:41:06 +02:00
|
|
|
context->destroyed = 1;
|
|
|
|
destroy = FALSE;
|
2009-06-29 10:11:24 +02:00
|
|
|
}
|
|
|
|
|
2010-07-30 10:15:26 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, context->draw_buffers);
|
2010-05-04 20:39:52 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, context->blit_targets);
|
2008-03-04 02:30:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, context->vshader_const_dirty);
|
|
|
|
HeapFree(GetProcessHeap(), 0, context->pshader_const_dirty);
|
2010-03-14 21:53:25 +01:00
|
|
|
device_context_remove(This, context);
|
2009-07-22 10:41:06 +02:00
|
|
|
if (destroy) HeapFree(GetProcessHeap(), 0, context);
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2008-06-17 01:41:49 +02:00
|
|
|
static inline void set_blit_dimension(UINT width, UINT height) {
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
checkGLcall("glMatrixMode(GL_PROJECTION)");
|
|
|
|
glLoadIdentity();
|
|
|
|
checkGLcall("glLoadIdentity()");
|
2010-10-29 12:25:18 +02:00
|
|
|
glOrtho(0, width, 0, height, 0.0, -1.0);
|
2008-06-17 01:41:49 +02:00
|
|
|
checkGLcall("glOrtho");
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
checkGLcall("glViewport");
|
|
|
|
}
|
|
|
|
|
2007-02-12 19:18:41 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* SetupForBlit
|
|
|
|
*
|
|
|
|
* Sets up a context for DirectDraw blitting.
|
2007-11-26 21:43:08 +01:00
|
|
|
* All texture units are disabled, texture unit 0 is set as current unit
|
2008-01-09 20:37:05 +01:00
|
|
|
* fog, lighting, blending, alpha test, z test, scissor test, culling disabled
|
2007-02-12 19:18:41 +01:00
|
|
|
* color writing enabled for all channels
|
|
|
|
* register combiners disabled, shaders disabled
|
2008-01-09 20:37:05 +01:00
|
|
|
* world matrix is set to identity, texture matrix 0 too
|
2007-02-12 19:18:41 +01:00
|
|
|
* projection matrix is setup for drawing screen coordinates
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* This: Device to activate the context for
|
|
|
|
* context: Context to setup
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2009-12-27 19:57:23 +01:00
|
|
|
static void SetupForBlit(IWineD3DDeviceImpl *This, struct wined3d_context *context)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
2009-08-17 09:39:07 +02:00
|
|
|
int i;
|
2008-07-02 01:23:44 +02:00
|
|
|
const struct StateEntry *StateTable = This->StateTable;
|
2009-07-17 10:34:02 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2010-04-21 22:02:31 +02:00
|
|
|
UINT width = context->current_rt->currentDesc.Width;
|
|
|
|
UINT height = context->current_rt->currentDesc.Height;
|
2009-08-17 09:39:07 +02:00
|
|
|
DWORD sampler;
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
TRACE("Setting up context %p for blitting\n", context);
|
|
|
|
if(context->last_was_blit) {
|
2008-06-17 01:41:49 +02:00
|
|
|
if(context->blit_w != width || context->blit_h != height) {
|
2009-05-13 18:22:54 +02:00
|
|
|
ENTER_GL();
|
2008-06-17 01:41:49 +02:00
|
|
|
set_blit_dimension(width, height);
|
2009-05-13 18:22:54 +02:00
|
|
|
LEAVE_GL();
|
2008-06-17 01:41:49 +02:00
|
|
|
context->blit_w = width; context->blit_h = height;
|
|
|
|
/* No need to dirtify here, the states are still dirtified because they weren't
|
|
|
|
* applied since the last SetupForBlit call. Otherwise last_was_blit would not
|
|
|
|
* be set
|
|
|
|
*/
|
|
|
|
}
|
2007-02-12 19:18:41 +01:00
|
|
|
TRACE("Context is already set up for blitting, nothing to do\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context->last_was_blit = TRUE;
|
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
/* TODO: Use a display list */
|
|
|
|
|
2007-02-12 19:18:41 +01:00
|
|
|
/* Disable shaders */
|
2009-05-12 16:19:56 +02:00
|
|
|
ENTER_GL();
|
2009-08-07 08:51:18 +02:00
|
|
|
This->shader_backend->shader_select(context, FALSE, FALSE);
|
2009-05-12 16:19:56 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_VSHADER, StateTable);
|
|
|
|
Context_MarkStateDirty(context, STATE_PIXELSHADER, StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
|
2008-10-19 01:57:36 +02:00
|
|
|
/* Call ENTER_GL() once for all gl calls below. In theory we should not call
|
|
|
|
* helper functions in between gl calls. This function is full of Context_MarkStateDirty
|
|
|
|
* which can safely be called from here, we only lock once instead locking/unlocking
|
|
|
|
* after each GL call.
|
|
|
|
*/
|
|
|
|
ENTER_GL();
|
|
|
|
|
2007-02-12 19:18:41 +01:00
|
|
|
/* Disable all textures. The caller can then bind a texture it wants to blit
|
|
|
|
* from
|
2008-12-16 13:18:49 +01:00
|
|
|
*
|
|
|
|
* The blitting code uses (for now) the fixed function pipeline, so make sure to reset all fixed
|
|
|
|
* function texture unit. No need to care for higher samplers
|
2007-02-12 19:18:41 +01:00
|
|
|
*/
|
2009-10-29 10:37:10 +01:00
|
|
|
for (i = gl_info->limits.textures - 1; i > 0 ; --i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2008-12-16 13:18:49 +01:00
|
|
|
sampler = This->rev_tex_unit_map[i];
|
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
|
|
|
|
checkGLcall("glActiveTextureARB");
|
2007-02-12 19:18:41 +01:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
2008-12-16 13:18:49 +01:00
|
|
|
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
checkGLcall("glDisable GL_TEXTURE_CUBE_MAP_ARB");
|
|
|
|
}
|
|
|
|
glDisable(GL_TEXTURE_3D);
|
|
|
|
checkGLcall("glDisable GL_TEXTURE_3D");
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
2008-12-16 13:18:49 +01:00
|
|
|
glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
checkGLcall("glDisable GL_TEXTURE_RECTANGLE_ARB");
|
|
|
|
}
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
checkGLcall("glDisable GL_TEXTURE_2D");
|
2007-03-01 01:21:47 +01:00
|
|
|
|
2008-12-16 13:18:49 +01:00
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
checkGLcall("glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);");
|
|
|
|
|
2009-08-17 09:39:07 +02:00
|
|
|
if (sampler != WINED3D_UNMAPPED_STAGE)
|
|
|
|
{
|
2008-12-16 13:18:49 +01:00
|
|
|
if (sampler < MAX_TEXTURES) {
|
|
|
|
Context_MarkStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP), StateTable);
|
2008-07-15 23:54:44 +02:00
|
|
|
}
|
2008-12-16 13:18:49 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_SAMPLER(sampler), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
}
|
|
|
|
}
|
2008-12-16 13:18:49 +01:00
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
|
|
|
|
checkGLcall("glActiveTextureARB");
|
2008-07-15 23:54:44 +02:00
|
|
|
|
|
|
|
sampler = This->rev_tex_unit_map[0];
|
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
2007-03-28 19:17:51 +02:00
|
|
|
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
checkGLcall("glDisable GL_TEXTURE_CUBE_MAP_ARB");
|
|
|
|
}
|
2007-02-12 19:18:41 +01:00
|
|
|
glDisable(GL_TEXTURE_3D);
|
|
|
|
checkGLcall("glDisable GL_TEXTURE_3D");
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
2008-08-20 20:50:51 +02:00
|
|
|
glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
checkGLcall("glDisable GL_TEXTURE_RECTANGLE_ARB");
|
|
|
|
}
|
2007-11-26 21:43:08 +01:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
checkGLcall("glDisable GL_TEXTURE_2D");
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
checkGLcall("glMatrixMode(GL_TEXTURE)");
|
|
|
|
glLoadIdentity();
|
|
|
|
checkGLcall("glLoadIdentity()");
|
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
|
|
|
|
{
|
2007-02-12 19:18:41 +01:00
|
|
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
|
|
|
|
GL_TEXTURE_LOD_BIAS_EXT,
|
2009-07-07 11:08:01 +02:00
|
|
|
0.0f);
|
2010-11-05 11:17:51 +01:00
|
|
|
checkGLcall("glTexEnvf GL_TEXTURE_LOD_BIAS_EXT ...");
|
2007-02-12 19:18:41 +01:00
|
|
|
}
|
2008-07-15 23:54:44 +02:00
|
|
|
|
2009-08-17 09:39:07 +02:00
|
|
|
if (sampler != WINED3D_UNMAPPED_STAGE)
|
|
|
|
{
|
2008-07-15 23:54:44 +02:00
|
|
|
if (sampler < MAX_TEXTURES) {
|
|
|
|
Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0 + sampler), StateTable);
|
|
|
|
Context_MarkStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP), StateTable);
|
|
|
|
}
|
|
|
|
Context_MarkStateDirty(context, STATE_SAMPLER(sampler), StateTable);
|
|
|
|
}
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
/* Other misc states */
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
checkGLcall("glDisable(GL_ALPHA_TEST)");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHATESTENABLE), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
checkGLcall("glDisable GL_LIGHTING");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_LIGHTING), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
checkGLcall("glDisable GL_DEPTH_TEST");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ZENABLE), StateTable);
|
2008-12-15 19:38:48 +01:00
|
|
|
glDisableWINE(GL_FOG);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_FOG");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_FOGENABLE), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
checkGLcall("glDisable GL_BLEND");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
checkGLcall("glDisable GL_CULL_FACE");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_CULLMODE), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
checkGLcall("glDisable GL_STENCIL_TEST");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_STENCILENABLE), StateTable);
|
2007-12-01 01:10:37 +01:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
checkGLcall("glDisable GL_SCISSOR_TEST");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), StateTable);
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_POINT_SPRITE])
|
|
|
|
{
|
2007-02-12 19:18:41 +01:00
|
|
|
glDisable(GL_POINT_SPRITE_ARB);
|
|
|
|
checkGLcall("glDisable GL_POINT_SPRITE_ARB");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_POINTSPRITEENABLE), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
}
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE,GL_TRUE,GL_TRUE);
|
|
|
|
checkGLcall("glColorMask");
|
2009-08-07 12:18:10 +02:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE), StateTable);
|
2010-03-25 22:51:22 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE1), StateTable);
|
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE2), StateTable);
|
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_COLORWRITEENABLE3), StateTable);
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[EXT_SECONDARY_COLOR])
|
|
|
|
{
|
2007-08-14 16:32:35 +02:00
|
|
|
glDisable(GL_COLOR_SUM_EXT);
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SPECULARENABLE), StateTable);
|
2007-08-14 16:32:35 +02:00
|
|
|
checkGLcall("glDisable(GL_COLOR_SUM_EXT)");
|
|
|
|
}
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
/* Setup transforms */
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
checkGLcall("glMatrixMode(GL_MODELVIEW)");
|
|
|
|
glLoadIdentity();
|
|
|
|
checkGLcall("glLoadIdentity()");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
context->last_was_rhw = TRUE;
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_VDECL, StateTable); /* because of last_was_rhw = TRUE */
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
glDisable(GL_CLIP_PLANE0); checkGLcall("glDisable(clip plane 0)");
|
|
|
|
glDisable(GL_CLIP_PLANE1); checkGLcall("glDisable(clip plane 1)");
|
|
|
|
glDisable(GL_CLIP_PLANE2); checkGLcall("glDisable(clip plane 2)");
|
|
|
|
glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)");
|
|
|
|
glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)");
|
|
|
|
glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)");
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPING), StateTable);
|
2007-02-12 19:18:41 +01:00
|
|
|
|
2008-06-17 01:41:49 +02:00
|
|
|
set_blit_dimension(width, height);
|
2009-05-13 18:22:54 +02:00
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
2008-06-17 01:41:49 +02:00
|
|
|
context->blit_w = width; context->blit_h = height;
|
2008-03-09 19:30:08 +01:00
|
|
|
Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
|
2008-06-17 01:41:49 +02:00
|
|
|
Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION), StateTable);
|
|
|
|
|
2007-05-07 21:08:14 +02:00
|
|
|
|
2008-07-04 22:09:49 +02:00
|
|
|
This->frag_pipe->enable_extension((IWineD3DDevice *) This, FALSE);
|
2007-02-12 19:18:41 +01:00
|
|
|
}
|
|
|
|
|
2007-07-04 16:47:22 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* findThreadContextForSwapChain
|
|
|
|
*
|
|
|
|
* Searches a swapchain for all contexts and picks one for the thread tid.
|
|
|
|
* If none can be found the swapchain is requested to create a new context
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2009-08-03 08:06:51 +02:00
|
|
|
static struct wined3d_context *findThreadContextForSwapChain(IWineD3DSwapChain *swapchain, DWORD tid)
|
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
unsigned int i;
|
2007-07-04 16:47:22 +02:00
|
|
|
|
|
|
|
for(i = 0; i < ((IWineD3DSwapChainImpl *) swapchain)->num_contexts; i++) {
|
|
|
|
if(((IWineD3DSwapChainImpl *) swapchain)->context[i]->tid == tid) {
|
|
|
|
return ((IWineD3DSwapChainImpl *) swapchain)->context[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new context for the thread */
|
2009-10-28 11:00:12 +01:00
|
|
|
return swapchain_create_context_for_thread(swapchain);
|
2007-07-04 16:47:22 +02:00
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-04-21 22:02:29 +02:00
|
|
|
static struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
|
|
|
struct wined3d_context *current_context = context_get_current();
|
2009-12-27 19:57:22 +01:00
|
|
|
DWORD tid = GetCurrentThreadId();
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2007-07-09 00:48:53 +02:00
|
|
|
|
2009-07-23 10:54:32 +02:00
|
|
|
if (current_context && current_context->destroyed) current_context = NULL;
|
|
|
|
|
2009-07-22 10:41:10 +02:00
|
|
|
if (!target)
|
|
|
|
{
|
|
|
|
if (current_context
|
2009-08-03 08:06:48 +02:00
|
|
|
&& current_context->current_rt
|
2010-03-15 21:07:25 +01:00
|
|
|
&& current_context->swapchain->device == This)
|
2009-07-22 10:41:10 +02:00
|
|
|
{
|
2010-04-21 22:02:31 +02:00
|
|
|
target = current_context->current_rt;
|
2009-07-22 10:41:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)This->swapchains[0];
|
2010-04-26 21:33:01 +02:00
|
|
|
if (swapchain->back_buffers) target = swapchain->back_buffers[0];
|
2010-04-26 21:33:00 +02:00
|
|
|
else target = swapchain->front_buffer;
|
2009-07-22 10:41:10 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-22 10:41:09 +02:00
|
|
|
|
2010-04-21 22:02:31 +02:00
|
|
|
if (current_context && current_context->current_rt == target)
|
2009-07-22 10:41:09 +02:00
|
|
|
{
|
2009-10-20 11:05:04 +02:00
|
|
|
context_validate(current_context);
|
2009-07-22 10:41:10 +02:00
|
|
|
return current_context;
|
2009-07-22 10:41:09 +02:00
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
if (target->container.type == WINED3D_CONTAINER_SWAPCHAIN)
|
2010-04-21 22:02:29 +02:00
|
|
|
{
|
2010-08-16 20:00:25 +02:00
|
|
|
IWineD3DSwapChain *swapchain;
|
|
|
|
|
2007-07-09 00:48:53 +02:00
|
|
|
TRACE("Rendering onscreen\n");
|
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
swapchain = (IWineD3DSwapChain *)target->container.u.swapchain;
|
2007-07-09 00:48:53 +02:00
|
|
|
context = findThreadContextForSwapChain(swapchain, tid);
|
2009-07-22 10:41:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-07-09 00:48:53 +02:00
|
|
|
TRACE("Rendering offscreen\n");
|
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* Stay with the currently active context. */
|
2010-03-15 21:07:25 +01:00
|
|
|
if (current_context && current_context->swapchain->device == This)
|
2009-07-22 10:41:08 +02:00
|
|
|
{
|
2010-03-14 21:53:23 +01:00
|
|
|
context = current_context;
|
2007-07-09 00:48:53 +02:00
|
|
|
}
|
2009-07-22 10:41:08 +02:00
|
|
|
else
|
|
|
|
{
|
2010-03-14 21:53:23 +01:00
|
|
|
/* This may happen if the app jumps straight into offscreen rendering
|
|
|
|
* Start using the context of the primary swapchain. tid == 0 is no problem
|
|
|
|
* for findThreadContextForSwapChain.
|
|
|
|
*
|
|
|
|
* Can also happen on thread switches - in that case findThreadContextForSwapChain
|
|
|
|
* is perfect to call. */
|
|
|
|
context = findThreadContextForSwapChain(This->swapchains[0], tid);
|
2007-07-09 00:48:53 +02:00
|
|
|
}
|
|
|
|
}
|
2008-06-12 21:18:46 +02:00
|
|
|
|
2009-10-20 11:05:04 +02:00
|
|
|
context_validate(context);
|
|
|
|
|
2007-07-09 00:48:53 +02:00
|
|
|
return context;
|
|
|
|
}
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2010-08-29 21:57:40 +02:00
|
|
|
static void context_apply_draw_buffers(struct wined3d_context *context, UINT rt_count, IWineD3DSurfaceImpl **rts)
|
2008-08-03 21:17:51 +02:00
|
|
|
{
|
2010-08-29 21:57:40 +02:00
|
|
|
if (!surface_is_offscreen(rts[0]))
|
2008-08-03 21:17:51 +02:00
|
|
|
{
|
2008-10-19 01:57:36 +02:00
|
|
|
ENTER_GL();
|
2010-08-29 21:57:40 +02:00
|
|
|
glDrawBuffer(surface_get_gl_buffer(rts[0]));
|
2010-08-07 15:29:41 +02:00
|
|
|
checkGLcall("glDrawBuffer()");
|
2008-10-19 01:57:36 +02:00
|
|
|
LEAVE_GL();
|
2008-08-03 21:17:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-19 01:57:36 +02:00
|
|
|
ENTER_GL();
|
2008-08-04 19:28:42 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
2008-08-04 19:28:37 +02:00
|
|
|
{
|
2010-08-29 21:57:40 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
unsigned int i;
|
2010-05-04 20:39:49 +02:00
|
|
|
|
2010-08-29 21:57:40 +02:00
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
|
|
|
{
|
|
|
|
if (i < rt_count && rts[i])
|
|
|
|
context->draw_buffers[i] = GL_COLOR_ATTACHMENT0 + i;
|
2008-08-04 19:28:42 +02:00
|
|
|
else
|
2010-08-29 21:57:40 +02:00
|
|
|
context->draw_buffers[i] = GL_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_DRAW_BUFFERS])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawBuffersARB(gl_info->limits.buffers, context->draw_buffers));
|
|
|
|
checkGLcall("glDrawBuffers()");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDrawBuffer(context->draw_buffers[0]);
|
2008-08-04 19:28:37 +02:00
|
|
|
checkGLcall("glDrawBuffer()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-29 21:57:40 +02:00
|
|
|
glDrawBuffer(rts[0]->resource.device->offscreenBuffer);
|
2008-08-04 19:28:37 +02:00
|
|
|
checkGLcall("glDrawBuffer()");
|
|
|
|
}
|
2008-10-19 01:57:36 +02:00
|
|
|
LEAVE_GL();
|
2008-08-03 21:17:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 21:41:52 +01:00
|
|
|
/* GL locking is done by the caller. */
|
|
|
|
void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer)
|
|
|
|
{
|
|
|
|
glDrawBuffer(buffer);
|
|
|
|
checkGLcall("glDrawBuffer()");
|
|
|
|
context->draw_buffer_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-28 16:42:32 +02:00
|
|
|
static inline void context_set_render_offscreen(struct wined3d_context *context, const struct StateEntry *StateTable,
|
|
|
|
BOOL offscreen)
|
|
|
|
{
|
2010-07-16 18:39:06 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
2010-03-28 16:42:32 +02:00
|
|
|
if (context->render_offscreen == offscreen) return;
|
|
|
|
|
2010-07-16 18:39:06 +02:00
|
|
|
if (gl_info->supported[WINED3D_GL_VERSION_2_0])
|
2010-06-11 16:05:23 +02:00
|
|
|
{
|
2010-07-16 18:39:06 +02:00
|
|
|
/* Windows doesn't support to query the glPointParameteri function pointer, so use the
|
|
|
|
* NV_POINT_SPRITE extension.
|
|
|
|
*/
|
|
|
|
if (glPointParameteri)
|
|
|
|
{
|
|
|
|
glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, offscreen ? GL_LOWER_LEFT : GL_UPPER_LEFT);
|
|
|
|
checkGLcall("glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, ...)");
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[NV_POINT_SPRITE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glPointParameteriNV(GL_POINT_SPRITE_COORD_ORIGIN, offscreen ? GL_LOWER_LEFT : GL_UPPER_LEFT));
|
|
|
|
checkGLcall("glPointParameteriNV(GL_POINT_SPRITE_COORD_ORIGIN, ...)");
|
|
|
|
}
|
2010-06-11 16:05:23 +02:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:42:32 +02:00
|
|
|
Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION), StateTable);
|
|
|
|
Context_MarkStateDirty(context, STATE_VDECL, StateTable);
|
|
|
|
Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
|
|
|
|
Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable);
|
|
|
|
Context_MarkStateDirty(context, STATE_FRONTFACE, StateTable);
|
|
|
|
context->render_offscreen = offscreen;
|
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
static BOOL match_depth_stencil_format(const struct wined3d_format *existing,
|
|
|
|
const struct wined3d_format *required)
|
2010-03-28 16:42:32 +02:00
|
|
|
{
|
|
|
|
short existing_depth, existing_stencil, required_depth, required_stencil;
|
|
|
|
|
2010-11-12 13:12:05 +01:00
|
|
|
if (existing == required) return TRUE;
|
|
|
|
if ((existing->flags & WINED3DFMT_FLAG_FLOAT) != (required->flags & WINED3DFMT_FLAG_FLOAT)) return FALSE;
|
2010-03-28 16:42:32 +02:00
|
|
|
|
|
|
|
getDepthStencilBits(existing, &existing_depth, &existing_stencil);
|
|
|
|
getDepthStencilBits(required, &required_depth, &required_stencil);
|
|
|
|
|
|
|
|
if(existing_depth < required_depth) return FALSE;
|
|
|
|
/* If stencil bits are used the exact amount is required - otherwise wrapping
|
|
|
|
* won't work correctly */
|
|
|
|
if(required_stencil && required_stencil != existing_stencil) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* The caller provides a context */
|
2010-05-18 09:53:07 +02:00
|
|
|
static void context_validate_onscreen_formats(IWineD3DDeviceImpl *device,
|
|
|
|
struct wined3d_context *context, IWineD3DSurfaceImpl *depth_stencil)
|
2010-03-28 16:42:32 +02:00
|
|
|
{
|
|
|
|
/* Onscreen surfaces are always in a swapchain */
|
2010-08-16 20:00:25 +02:00
|
|
|
IWineD3DSwapChainImpl *swapchain = context->current_rt->container.u.swapchain;
|
2010-03-28 16:42:32 +02:00
|
|
|
|
2010-05-18 09:53:08 +02:00
|
|
|
if (context->render_offscreen || !depth_stencil) return;
|
2010-08-30 20:29:49 +02:00
|
|
|
if (match_depth_stencil_format(swapchain->ds_format, depth_stencil->resource.format)) return;
|
2010-03-28 16:42:32 +02:00
|
|
|
|
|
|
|
/* TODO: If the requested format would satisfy the needs of the existing one(reverse match),
|
|
|
|
* or no onscreen depth buffer was created, the OpenGL drawable could be changed to the new
|
|
|
|
* format. */
|
|
|
|
WARN("Depth stencil format is not supported by WGL, rendering the backbuffer in an FBO\n");
|
|
|
|
|
|
|
|
/* The currently active context is the necessary context to access the swapchain's onscreen buffers */
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(context->current_rt, SFLAG_INTEXTURE, NULL);
|
2010-03-28 16:42:32 +02:00
|
|
|
swapchain->render_to_fbo = TRUE;
|
|
|
|
context_set_render_offscreen(context, device->StateTable, TRUE);
|
|
|
|
}
|
|
|
|
|
2009-12-27 19:57:21 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2010-05-03 22:03:28 +02:00
|
|
|
void context_apply_blit_state(struct wined3d_context *context, IWineD3DDeviceImpl *device)
|
2009-07-23 10:54:36 +02:00
|
|
|
{
|
2010-05-03 22:03:27 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
2010-05-18 09:53:08 +02:00
|
|
|
context_validate_onscreen_formats(device, context, NULL);
|
2010-05-18 09:53:06 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (context->render_offscreen)
|
|
|
|
{
|
|
|
|
surface_internal_preload(context->current_rt, SRGB_RGB);
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
ENTER_GL();
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_fbo_state_blit(context, GL_FRAMEBUFFER, context->current_rt, NULL, SFLAG_INTEXTURE);
|
2010-05-03 22:03:27 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ENTER_GL();
|
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
|
|
|
|
LEAVE_GL();
|
|
|
|
}
|
2008-08-04 19:28:37 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
context->draw_buffer_dirty = TRUE;
|
2007-11-06 01:11:35 +01:00
|
|
|
}
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (context->draw_buffer_dirty)
|
|
|
|
{
|
2010-08-29 21:57:40 +02:00
|
|
|
context_apply_draw_buffers(context, 1, &context->current_rt);
|
2010-05-03 22:03:27 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
|
|
|
|
context->draw_buffer_dirty = FALSE;
|
|
|
|
}
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
SetupForBlit(device, context);
|
|
|
|
}
|
2007-07-09 16:57:58 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2010-05-04 20:39:52 +02:00
|
|
|
void context_apply_clear_state(struct wined3d_context *context, IWineD3DDeviceImpl *device,
|
2010-07-23 11:31:03 +02:00
|
|
|
UINT rt_count, IWineD3DSurfaceImpl **rts, IWineD3DSurfaceImpl *depth_stencil)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
|
|
|
const struct StateEntry *state_table = device->StateTable;
|
2010-07-23 11:31:03 +02:00
|
|
|
UINT i;
|
2008-04-06 00:49:00 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
2010-05-18 09:53:08 +02:00
|
|
|
context_validate_onscreen_formats(device, context, depth_stencil);
|
2010-05-18 09:53:07 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
ENTER_GL();
|
2010-07-23 11:31:03 +02:00
|
|
|
|
|
|
|
if (surface_is_offscreen(rts[0]))
|
|
|
|
{
|
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
|
|
|
context->blit_targets[i] = rts[i];
|
|
|
|
}
|
|
|
|
while (i < context->gl_info->limits.buffers)
|
|
|
|
{
|
|
|
|
context->blit_targets[i] = NULL;
|
|
|
|
++i;
|
|
|
|
}
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets, depth_stencil, SFLAG_INTEXTURE);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_fbo_state(context, GL_FRAMEBUFFER, NULL, NULL, SFLAG_INDRAWABLE);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
}
|
2007-07-09 16:57:58 +02:00
|
|
|
|
2010-08-29 21:57:41 +02:00
|
|
|
context_apply_draw_buffers(context, rt_count, rts);
|
|
|
|
context->draw_buffer_dirty = TRUE;
|
2007-07-01 23:40:57 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (context->last_was_blit)
|
|
|
|
{
|
|
|
|
device->frag_pipe->enable_extension((IWineD3DDevice *)device, TRUE);
|
|
|
|
}
|
2007-07-01 23:40:57 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
/* Blending and clearing should be orthogonal, but tests on the nvidia
|
|
|
|
* driver show that disabling blending when clearing improves the clearing
|
|
|
|
* performance incredibly. */
|
|
|
|
ENTER_GL();
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
checkGLcall("glEnable GL_SCISSOR_TEST");
|
|
|
|
LEAVE_GL();
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
context->last_was_blit = FALSE;
|
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), state_table);
|
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), state_table);
|
|
|
|
Context_MarkStateDirty(context, STATE_SCISSORRECT, state_table);
|
|
|
|
}
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2010-05-03 22:03:28 +02:00
|
|
|
void context_apply_draw_state(struct wined3d_context *context, IWineD3DDeviceImpl *device)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
|
|
|
const struct StateEntry *state_table = device->StateTable;
|
|
|
|
unsigned int i;
|
|
|
|
|
2010-07-21 18:48:23 +02:00
|
|
|
/* Preload resources before FBO setup. Texture preload in particular may
|
|
|
|
* result in changes to the current FBO, due to using e.g. FBO blits for
|
|
|
|
* updating a resource location. */
|
|
|
|
IWineD3DDeviceImpl_FindTexUnitMap(device);
|
|
|
|
device_preload_textures(device);
|
|
|
|
if (isStateDirty(context, STATE_VDECL))
|
|
|
|
device_update_stream_info(device, context->gl_info);
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
2010-05-18 09:53:08 +02:00
|
|
|
context_validate_onscreen_formats(device, context, device->depth_stencil);
|
2010-05-18 09:53:06 +02:00
|
|
|
|
2010-05-04 20:39:52 +02:00
|
|
|
if (!context->render_offscreen)
|
|
|
|
{
|
|
|
|
ENTER_GL();
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_fbo_state(context, GL_FRAMEBUFFER, NULL, NULL, SFLAG_INDRAWABLE);
|
2010-05-04 20:39:52 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ENTER_GL();
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_fbo_state(context, GL_FRAMEBUFFER, device->render_targets,
|
|
|
|
device->depth_stencil, SFLAG_INTEXTURE);
|
2010-05-04 20:39:52 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
}
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (context->draw_buffer_dirty)
|
|
|
|
{
|
2010-08-29 21:57:40 +02:00
|
|
|
context_apply_draw_buffers(context, context->gl_info->limits.buffers, device->render_targets);
|
2010-05-03 22:03:27 +02:00
|
|
|
context->draw_buffer_dirty = FALSE;
|
2007-02-12 19:18:36 +01:00
|
|
|
}
|
2010-05-03 22:03:27 +02:00
|
|
|
|
|
|
|
if (context->last_was_blit)
|
|
|
|
{
|
|
|
|
device->frag_pipe->enable_extension((IWineD3DDevice *)device, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
for (i = 0; i < context->numDirtyEntries; ++i)
|
|
|
|
{
|
|
|
|
DWORD rep = context->dirtyArray[i];
|
|
|
|
DWORD idx = rep / (sizeof(*context->isStateDirty) * CHAR_BIT);
|
|
|
|
BYTE shift = rep & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
|
|
|
|
context->isStateDirty[idx] &= ~(1 << shift);
|
|
|
|
state_table[rep].apply(rep, device->stateBlock, context);
|
|
|
|
}
|
|
|
|
LEAVE_GL();
|
|
|
|
context->numDirtyEntries = 0; /* This makes the whole list clean */
|
|
|
|
context->last_was_blit = FALSE;
|
2009-12-27 19:57:21 +01:00
|
|
|
}
|
|
|
|
|
2010-04-21 22:02:30 +02:00
|
|
|
static void context_setup_target(IWineD3DDeviceImpl *device,
|
|
|
|
struct wined3d_context *context, IWineD3DSurfaceImpl *target)
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
2010-03-28 16:42:32 +02:00
|
|
|
BOOL old_render_offscreen = context->render_offscreen, render_offscreen;
|
2010-03-27 17:40:28 +01:00
|
|
|
const struct StateEntry *StateTable = device->StateTable;
|
|
|
|
|
|
|
|
if (!target) return;
|
2010-04-21 22:02:30 +02:00
|
|
|
render_offscreen = surface_is_offscreen(target);
|
2010-06-28 21:13:56 +02:00
|
|
|
if (context->current_rt == target && render_offscreen == old_render_offscreen) return;
|
2010-03-27 17:40:28 +01:00
|
|
|
|
|
|
|
/* To compensate the lack of format switching with some offscreen rendering methods and on onscreen buffers
|
|
|
|
* the alpha blend state changes with different render target formats. */
|
|
|
|
if (!context->current_rt)
|
|
|
|
{
|
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *old = context->current_rt->resource.format;
|
|
|
|
const struct wined3d_format *new = target->resource.format;
|
2010-03-27 17:40:28 +01:00
|
|
|
|
2010-08-25 20:46:51 +02:00
|
|
|
if (old->id != new->id)
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
|
|
|
/* Disable blending when the alpha mask has changed and when a format doesn't support blending. */
|
|
|
|
if ((old->alpha_mask && !new->alpha_mask) || (!old->alpha_mask && new->alpha_mask)
|
2010-11-12 13:12:05 +01:00
|
|
|
|| !(new->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable);
|
|
|
|
}
|
2010-07-02 22:21:02 +02:00
|
|
|
/* Update sRGB writing when switching between formats that do/do not support sRGB writing */
|
2010-11-12 13:12:05 +01:00
|
|
|
if ((old->flags & WINED3DFMT_FLAG_SRGB_WRITE) != (new->flags & WINED3DFMT_FLAG_SRGB_WRITE))
|
2010-07-02 22:21:02 +02:00
|
|
|
{
|
|
|
|
Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), StateTable);
|
|
|
|
}
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* When switching away from an offscreen render target, and we're not
|
|
|
|
* using FBOs, we have to read the drawable into the texture. This is
|
|
|
|
* done via PreLoad (and SFLAG_INDRAWABLE set on the surface). There
|
|
|
|
* are some things that need care though. PreLoad needs a GL context,
|
|
|
|
* and FindContext is called before the context is activated. It also
|
|
|
|
* has to be called with the old rendertarget active, otherwise a
|
|
|
|
* wrong drawable is read. */
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
|
2010-04-21 22:02:31 +02:00
|
|
|
&& old_render_offscreen && context->current_rt != target)
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
|
|
|
/* Read the back buffer of the old drawable into the destination texture. */
|
2010-04-21 22:02:31 +02:00
|
|
|
if (context->current_rt->texture_name_srgb)
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
2010-04-26 11:02:34 +02:00
|
|
|
surface_internal_preload(context->current_rt, SRGB_BOTH);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-26 11:02:34 +02:00
|
|
|
surface_internal_preload(context->current_rt, SRGB_RGB);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(context->current_rt, SFLAG_INDRAWABLE, FALSE);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context->draw_buffer_dirty = TRUE;
|
2010-04-21 22:02:31 +02:00
|
|
|
context->current_rt = target;
|
2010-08-07 22:35:31 +02:00
|
|
|
context_set_render_offscreen(context, StateTable, render_offscreen);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2010-05-03 22:03:28 +02:00
|
|
|
struct wined3d_context *context_acquire(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *target)
|
2009-12-27 19:57:21 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *current_context = context_get_current();
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
TRACE("device %p, target %p.\n", device, target);
|
2009-12-27 19:57:21 +01:00
|
|
|
|
2010-04-21 22:02:32 +02:00
|
|
|
context = FindContext(device, target);
|
|
|
|
context_setup_target(device, context, target);
|
2009-12-27 19:57:21 +01:00
|
|
|
context_enter(context);
|
|
|
|
if (!context->valid) return context;
|
|
|
|
|
|
|
|
if (context != current_context)
|
|
|
|
{
|
|
|
|
if (!context_set_current(context)) ERR("Failed to activate the new context.\n");
|
|
|
|
else device->frag_pipe->enable_extension((IWineD3DDevice *)device, !context->last_was_blit);
|
|
|
|
|
|
|
|
if (context->vshader_const_dirty)
|
|
|
|
{
|
|
|
|
memset(context->vshader_const_dirty, 1,
|
|
|
|
sizeof(*context->vshader_const_dirty) * device->d3d_vshader_constantF);
|
|
|
|
device->highest_dirty_vs_const = device->d3d_vshader_constantF;
|
|
|
|
}
|
|
|
|
if (context->pshader_const_dirty)
|
|
|
|
{
|
|
|
|
memset(context->pshader_const_dirty, 1,
|
|
|
|
sizeof(*context->pshader_const_dirty) * device->d3d_pshader_constantF);
|
|
|
|
device->highest_dirty_ps_const = device->d3d_pshader_constantF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (context->restore_ctx)
|
|
|
|
{
|
|
|
|
if (!pwglMakeCurrent(context->hdc, context->glCtx))
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("Failed to make GL context %p current on device context %p, last error %#x.\n",
|
|
|
|
context->hdc, context->glCtx, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-23 10:54:36 +02:00
|
|
|
return context;
|
2007-02-12 19:18:36 +01:00
|
|
|
}
|