2007-02-12 19:18:36 +01:00
|
|
|
/*
|
|
|
|
* Context and render target management in wined3d
|
|
|
|
*
|
2013-05-14 17:38:18 +02:00
|
|
|
* Copyright 2007-2011, 2013 Stefan Dösinger for CodeWeavers
|
2011-04-05 19:01:30 +02:00
|
|
|
* Copyright 2009-2011 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"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
|
|
|
|
2007-02-12 19:18:36 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_FLOAT_H
|
|
|
|
# include <float.h>
|
|
|
|
#endif
|
2012-06-01 16:56:21 +02:00
|
|
|
|
2007-02-12 19:18:36 +01:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2013-04-19 08:34:12 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_synchronous);
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2013-08-30 08:42:45 +02:00
|
|
|
#define WINED3D_MAX_FBO_ENTRIES 64
|
|
|
|
|
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 */
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2013-05-27 09:22:49 +02:00
|
|
|
static 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;
|
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:
|
2013-05-27 09:22:49 +02:00
|
|
|
if (context->fbo_read_binding == fbo) return;
|
|
|
|
context->fbo_read_binding = fbo;
|
2009-07-17 10:34:05 +02:00
|
|
|
break;
|
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
case GL_DRAW_FRAMEBUFFER:
|
2013-05-27 09:22:49 +02:00
|
|
|
if (context->fbo_draw_binding == fbo) return;
|
|
|
|
context->fbo_draw_binding = fbo;
|
2009-07-17 10:34:05 +02:00
|
|
|
break;
|
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
case GL_FRAMEBUFFER:
|
2013-05-27 09:22:49 +02:00
|
|
|
if (context->fbo_read_binding == fbo
|
|
|
|
&& context->fbo_draw_binding == fbo) return;
|
|
|
|
context->fbo_read_binding = fbo;
|
|
|
|
context->fbo_draw_binding = fbo;
|
2009-07-17 10:34:05 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled target %#x.\n", target);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-27 09:22:49 +02:00
|
|
|
gl_info->fbo_ops.glBindFramebuffer(target, fbo);
|
2008-09-18 14:57:53 +02:00
|
|
|
checkGLcall("glBindFramebuffer()");
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation 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
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2013-05-27 09:22:49 +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);
|
2013-05-27 09:22:49 +02:00
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, 0);
|
2009-05-11 16:43:49 +02:00
|
|
|
|
2013-05-27 09:22:49 +02:00
|
|
|
gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
|
2008-09-18 14:57:53 +02:00
|
|
|
checkGLcall("glDeleteFramebuffers()");
|
|
|
|
}
|
|
|
|
|
2011-08-25 21:05:01 +02:00
|
|
|
static void context_attach_depth_stencil_rb(const struct wined3d_gl_info *gl_info,
|
2016-02-21 22:30:01 +01:00
|
|
|
GLenum fbo_target, DWORD flags, GLuint rb)
|
2011-08-25 21:05:01 +02:00
|
|
|
{
|
2016-02-21 22:30:01 +01:00
|
|
|
if (flags & WINED3D_FBO_ENTRY_FLAG_DEPTH)
|
2011-08-25 21:05:01 +02:00
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb);
|
|
|
|
checkGLcall("glFramebufferRenderbuffer()");
|
|
|
|
}
|
|
|
|
|
2016-02-21 22:30:01 +01:00
|
|
|
if (flags & WINED3D_FBO_ENTRY_FLAG_STENCIL)
|
2011-08-25 21:05:01 +02:00
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb);
|
|
|
|
checkGLcall("glFramebufferRenderbuffer()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-20 11:42:17 +02:00
|
|
|
static void context_attach_gl_texture_fbo(struct wined3d_context *context,
|
|
|
|
GLenum fbo_target, GLenum attachment, const struct wined3d_fbo_resource *resource)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (!resource)
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, attachment, GL_TEXTURE_2D, 0, 0);
|
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
|
|
|
}
|
|
|
|
else if (resource->target == GL_TEXTURE_2D_ARRAY)
|
|
|
|
{
|
|
|
|
if (!gl_info->fbo_ops.glFramebufferTextureLayer)
|
|
|
|
{
|
|
|
|
FIXME("OpenGL implementation doesn't support glFramebufferTextureLayer().\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->fbo_ops.glFramebufferTextureLayer(fbo_target, attachment,
|
|
|
|
resource->object, resource->level, resource->layer);
|
|
|
|
checkGLcall("glFramebufferTextureLayer()");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, attachment,
|
|
|
|
resource->target, resource->object, resource->level);
|
|
|
|
checkGLcall("glFramebufferTexture2D()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-27 23:21:25 +02:00
|
|
|
static void context_attach_depth_stencil_fbo(struct wined3d_context *context,
|
2016-02-21 22:29:57 +01:00
|
|
|
GLenum fbo_target, const struct wined3d_fbo_resource *resource, BOOL rb_namespace,
|
2016-02-21 22:30:01 +01:00
|
|
|
DWORD flags)
|
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
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
if (resource->object)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2016-02-21 22:29:57 +01:00
|
|
|
TRACE("Attach depth stencil %u.\n", resource->object);
|
2009-06-08 10:35:06 +02:00
|
|
|
|
2016-02-21 22:29:58 +01:00
|
|
|
if (rb_namespace)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2011-08-25 21:05:01 +02:00
|
|
|
context_attach_depth_stencil_rb(gl_info, fbo_target,
|
2016-02-21 22:30:01 +01:00
|
|
|
flags, resource->object);
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-21 22:30:01 +01:00
|
|
|
if (flags & WINED3D_FBO_ENTRY_FLAG_DEPTH)
|
2016-04-20 11:42:17 +02:00
|
|
|
context_attach_gl_texture_fbo(context, fbo_target, GL_DEPTH_ATTACHMENT, resource);
|
2011-08-25 21:05:03 +02:00
|
|
|
|
2016-02-21 22:30:01 +01:00
|
|
|
if (flags & WINED3D_FBO_ENTRY_FLAG_STENCIL)
|
2016-04-20 11:42:17 +02:00
|
|
|
context_attach_gl_texture_fbo(context, fbo_target, GL_STENCIL_ATTACHMENT, resource);
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
|
2016-02-21 22:30:01 +01:00
|
|
|
if (!(flags & WINED3D_FBO_ENTRY_FLAG_DEPTH))
|
2016-04-20 11:42:17 +02:00
|
|
|
context_attach_gl_texture_fbo(context, fbo_target, GL_DEPTH_ATTACHMENT, NULL);
|
2009-06-08 10:35:06 +02:00
|
|
|
|
2016-02-21 22:30:01 +01:00
|
|
|
if (!(flags & WINED3D_FBO_ENTRY_FLAG_STENCIL))
|
2016-04-20 11:42:17 +02:00
|
|
|
context_attach_gl_texture_fbo(context, fbo_target, GL_STENCIL_ATTACHMENT, NULL);
|
2009-06-08 10:35:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-21 22:29:57 +01:00
|
|
|
TRACE("Attach depth stencil 0.\n");
|
|
|
|
|
2016-04-20 11:42:17 +02:00
|
|
|
context_attach_gl_texture_fbo(context, fbo_target, GL_DEPTH_ATTACHMENT, NULL);
|
|
|
|
context_attach_gl_texture_fbo(context, fbo_target, GL_STENCIL_ATTACHMENT, NULL);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-27 23:21:25 +02:00
|
|
|
static void context_attach_surface_fbo(struct wined3d_context *context,
|
2016-02-21 22:29:57 +01:00
|
|
|
GLenum fbo_target, DWORD idx, const struct wined3d_fbo_resource *resource, BOOL rb_namespace)
|
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
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
TRACE("Attach GL object %u to %u.\n", resource->object, idx);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
if (resource->object)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2011-03-02 08:55:49 +01:00
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
if (rb_namespace)
|
2010-07-26 12:06:32 +02:00
|
|
|
{
|
2016-02-21 22:29:57 +01:00
|
|
|
gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_COLOR_ATTACHMENT0 + idx,
|
|
|
|
GL_RENDERBUFFER, resource->object);
|
|
|
|
checkGLcall("glFramebufferRenderbuffer()");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-20 11:42:17 +02:00
|
|
|
context_attach_gl_texture_fbo(context, fbo_target, GL_COLOR_ATTACHMENT0 + idx, resource);
|
2010-07-26 12:06:32 +02:00
|
|
|
}
|
2009-09-23 10:05:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-20 11:42:17 +02:00
|
|
|
context_attach_gl_texture_fbo(context, fbo_target, GL_COLOR_ATTACHMENT0 + idx, NULL);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2016-02-21 22:29:56 +01:00
|
|
|
static void context_dump_fbo_attachment(const struct wined3d_gl_info *gl_info, GLenum target,
|
|
|
|
GLenum attachment)
|
|
|
|
{
|
2016-04-22 11:18:47 +02:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
GLenum target;
|
|
|
|
GLenum binding;
|
|
|
|
const char *str;
|
|
|
|
enum wined3d_gl_extension extension;
|
|
|
|
}
|
|
|
|
texture_type[] =
|
|
|
|
{
|
|
|
|
{GL_TEXTURE_2D, GL_TEXTURE_BINDING_2D, "2d", WINED3D_GL_EXT_NONE},
|
|
|
|
{GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_BINDING_RECTANGLE_ARB, "rectangle", ARB_TEXTURE_RECTANGLE},
|
|
|
|
{GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BINDING_2D_ARRAY, "2d-array", EXT_TEXTURE_ARRAY},
|
|
|
|
};
|
|
|
|
|
2016-02-21 22:29:56 +01:00
|
|
|
GLint type, name, samples, width, height, old_texture, level, face, fmt, tex_target;
|
|
|
|
|
|
|
|
gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv(target, attachment,
|
|
|
|
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &name);
|
|
|
|
gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv(target, attachment,
|
|
|
|
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type);
|
|
|
|
|
|
|
|
if (type == GL_RENDERBUFFER)
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, name);
|
|
|
|
gl_info->fbo_ops.glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width);
|
|
|
|
gl_info->fbo_ops.glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height);
|
|
|
|
if (gl_info->limits.samples > 1)
|
|
|
|
gl_info->fbo_ops.glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples);
|
|
|
|
else
|
|
|
|
samples = 1;
|
|
|
|
gl_info->fbo_ops.glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_INTERNAL_FORMAT, &fmt);
|
|
|
|
FIXME(" %s: renderbuffer %d, %dx%d, %d samples, format %#x.\n",
|
|
|
|
debug_fboattachment(attachment), name, width, height, samples, fmt);
|
|
|
|
}
|
|
|
|
else if (type == GL_TEXTURE)
|
|
|
|
{
|
|
|
|
const char *tex_type_str;
|
|
|
|
|
|
|
|
gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv(target, attachment,
|
|
|
|
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, &level);
|
|
|
|
gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv(target, attachment,
|
|
|
|
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, &face);
|
|
|
|
|
|
|
|
if (face)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &old_texture);
|
|
|
|
|
2016-10-10 10:22:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, name);
|
|
|
|
gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(face, level, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
|
|
|
|
gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(face, level, GL_TEXTURE_WIDTH, &width);
|
|
|
|
gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(face, level, GL_TEXTURE_HEIGHT, &height);
|
2016-02-21 22:29:56 +01:00
|
|
|
|
|
|
|
tex_target = GL_TEXTURE_CUBE_MAP;
|
|
|
|
tex_type_str = "cube";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-22 11:18:47 +02:00
|
|
|
unsigned int i;
|
2016-02-21 22:29:56 +01:00
|
|
|
|
2016-04-22 11:18:47 +02:00
|
|
|
tex_type_str = NULL;
|
|
|
|
for (i = 0; i < sizeof(texture_type) / sizeof(*texture_type); ++i)
|
2016-02-21 22:29:56 +01:00
|
|
|
{
|
2016-04-22 11:18:47 +02:00
|
|
|
if (!gl_info->supported[texture_type[i].extension])
|
|
|
|
continue;
|
2016-02-21 22:29:56 +01:00
|
|
|
|
2016-04-22 11:18:47 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetIntegerv(texture_type[i].binding, &old_texture);
|
|
|
|
while (gl_info->gl_ops.gl.p_glGetError());
|
|
|
|
|
2016-10-10 10:22:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(texture_type[i].target, name);
|
2016-04-22 11:18:47 +02:00
|
|
|
if (!gl_info->gl_ops.gl.p_glGetError())
|
2016-02-21 22:29:56 +01:00
|
|
|
{
|
2016-04-22 11:18:47 +02:00
|
|
|
tex_target = texture_type[i].target;
|
|
|
|
tex_type_str = texture_type[i].str;
|
|
|
|
break;
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
2016-10-10 10:22:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(texture_type[i].target, old_texture);
|
2016-04-22 11:18:47 +02:00
|
|
|
}
|
|
|
|
if (!tex_type_str)
|
|
|
|
{
|
|
|
|
FIXME("Cannot find type of texture %d.\n", name);
|
|
|
|
return;
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
|
|
|
|
2016-10-10 10:22:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(tex_target, level, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
|
|
|
|
gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(tex_target, level, GL_TEXTURE_WIDTH, &width);
|
|
|
|
gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(tex_target, level, GL_TEXTURE_HEIGHT, &height);
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FIXME(" %s: %s texture %d, %dx%d, format %#x.\n", debug_fboattachment(attachment),
|
|
|
|
tex_type_str, name, width, height, fmt);
|
|
|
|
|
2016-10-10 10:22:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(tex_target, old_texture);
|
2016-04-22 11:18:47 +02:00
|
|
|
checkGLcall("Guess texture type");
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
|
|
|
else if (type == GL_NONE)
|
|
|
|
{
|
2016-04-22 11:18:47 +02:00
|
|
|
FIXME(" %s: NONE.\n", debug_fboattachment(attachment));
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
|
|
|
else
|
2016-04-22 11:18:47 +02:00
|
|
|
{
|
|
|
|
ERR(" %s: Unknown attachment %#x.\n", debug_fboattachment(attachment), type);
|
|
|
|
}
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-06-29 23:14:11 +02:00
|
|
|
void context_check_fbo_status(const 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;
|
|
|
|
|
2011-05-27 16:17:25 +02:00
|
|
|
if (!FIXME_ON(d3d)) return;
|
|
|
|
|
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");
|
2011-04-29 13:03:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
unsigned int i;
|
2011-04-29 13:03:42 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-21 22:29:56 +01:00
|
|
|
context_dump_fbo_attachment(gl_info, target, GL_DEPTH_ATTACHMENT);
|
|
|
|
context_dump_fbo_attachment(gl_info, target, GL_STENCIL_ATTACHMENT);
|
2010-07-26 12:06:32 +02:00
|
|
|
|
2009-10-29 10:37:10 +01:00
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2016-02-21 22:29:56 +01:00
|
|
|
context_dump_fbo_attachment(gl_info, target, GL_COLOR_ATTACHMENT0 + i);
|
|
|
|
checkGLcall("Dump FBO attachments");
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-21 21:34:54 +02:00
|
|
|
static inline DWORD context_generate_rt_mask(GLenum buffer)
|
|
|
|
{
|
|
|
|
/* Should take care of all the GL_FRONT/GL_BACK/GL_AUXi/GL_NONE... cases */
|
2015-08-26 12:46:47 +02:00
|
|
|
return buffer ? (1u << 31) | buffer : 0;
|
2011-08-21 21:34:54 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:52:25 +01:00
|
|
|
static inline DWORD context_generate_rt_mask_from_resource(struct wined3d_resource *resource)
|
2011-08-21 21:34:54 +02:00
|
|
|
{
|
2016-03-25 17:52:25 +01:00
|
|
|
if (resource->type != WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(resource->type));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-20 19:29:13 +02:00
|
|
|
return (1u << 31) | wined3d_texture_get_gl_buffer(texture_from_resource(resource));
|
2011-08-21 21:34:54 +02:00
|
|
|
}
|
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
static inline void context_set_fbo_key_for_surface(const struct wined3d_context *context,
|
|
|
|
struct wined3d_fbo_entry_key *key, UINT idx, struct wined3d_surface *surface,
|
|
|
|
DWORD location)
|
|
|
|
{
|
2016-06-06 12:19:32 +02:00
|
|
|
if (!surface || surface->container->resource.format->id == WINED3DFMT_NULL)
|
2016-02-21 22:29:57 +01:00
|
|
|
{
|
|
|
|
key->objects[idx].object = 0;
|
2016-04-20 11:42:17 +02:00
|
|
|
key->objects[idx].target = 0;
|
|
|
|
key->objects[idx].level = key->objects[idx].layer = 0;
|
2016-02-21 22:29:57 +01:00
|
|
|
}
|
2016-02-21 22:29:58 +01:00
|
|
|
else if (surface->current_renderbuffer)
|
|
|
|
{
|
|
|
|
key->objects[idx].object = surface->current_renderbuffer->id;
|
2016-04-20 11:42:17 +02:00
|
|
|
key->objects[idx].target = 0;
|
|
|
|
key->objects[idx].level = key->objects[idx].layer = 0;
|
2016-02-21 22:29:58 +01:00
|
|
|
key->rb_namespace |= 1 << idx;
|
|
|
|
}
|
2016-02-21 22:29:57 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
|
|
|
key->objects[idx].object = surface_get_texture_name(surface, context, FALSE);
|
|
|
|
key->objects[idx].target = surface->texture_target;
|
2016-04-20 11:42:17 +02:00
|
|
|
key->objects[idx].level = surface->texture_level;
|
|
|
|
key->objects[idx].layer = surface->texture_layer;
|
2016-02-21 22:29:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
|
|
|
key->objects[idx].object = surface_get_texture_name(surface, context, TRUE);
|
|
|
|
key->objects[idx].target = surface->texture_target;
|
2016-04-20 11:42:17 +02:00
|
|
|
key->objects[idx].level = surface->texture_level;
|
|
|
|
key->objects[idx].layer = surface->texture_layer;
|
2016-02-21 22:29:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_RB_MULTISAMPLE:
|
2016-04-18 19:06:26 +02:00
|
|
|
key->objects[idx].object = surface->container->rb_multisample;
|
2016-04-20 11:42:17 +02:00
|
|
|
key->objects[idx].target = 0;
|
|
|
|
key->objects[idx].level = key->objects[idx].layer = 0;
|
2016-02-21 22:29:57 +01:00
|
|
|
key->rb_namespace |= 1 << idx;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_RB_RESOLVED:
|
2016-04-18 19:06:26 +02:00
|
|
|
key->objects[idx].object = surface->container->rb_resolved;
|
2016-04-20 11:42:17 +02:00
|
|
|
key->objects[idx].target = 0;
|
|
|
|
key->objects[idx].level = key->objects[idx].layer = 0;
|
2016-02-21 22:29:57 +01:00
|
|
|
key->rb_namespace |= 1 << idx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void context_generate_fbo_key(const struct wined3d_context *context,
|
|
|
|
struct wined3d_fbo_entry_key *key, struct wined3d_surface **render_targets,
|
|
|
|
struct wined3d_surface *depth_stencil, DWORD color_location,
|
|
|
|
DWORD ds_location)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
key->rb_namespace = 0;
|
|
|
|
context_set_fbo_key_for_surface(context, key, 0, depth_stencil, ds_location);
|
|
|
|
|
|
|
|
for (i = 0; i < context->gl_info->limits.buffers; ++i)
|
|
|
|
context_set_fbo_key_for_surface(context, key, i + 1, render_targets[i], color_location);
|
|
|
|
}
|
|
|
|
|
2011-06-29 12:33:53 +02:00
|
|
|
static struct fbo_entry *context_create_fbo_entry(const struct wined3d_context *context,
|
2015-05-22 10:11:22 +02:00
|
|
|
struct wined3d_surface **render_targets, struct wined3d_surface *depth_stencil,
|
|
|
|
DWORD color_location, DWORD ds_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;
|
2016-02-21 22:29:57 +01:00
|
|
|
UINT object_count = gl_info->limits.buffers + 1;
|
|
|
|
|
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
FIELD_OFFSET(struct fbo_entry, key.objects[object_count]));
|
|
|
|
memset(&entry->key, 0, FIELD_OFFSET(struct wined3d_fbo_entry_key, objects[object_count]));
|
|
|
|
context_generate_fbo_key(context, &entry->key, render_targets, depth_stencil, color_location, ds_location);
|
2016-02-21 22:30:01 +01:00
|
|
|
entry->flags = 0;
|
|
|
|
if (depth_stencil)
|
|
|
|
{
|
|
|
|
if (depth_stencil->container->resource.format_flags & WINED3DFMT_FLAG_DEPTH)
|
|
|
|
entry->flags |= WINED3D_FBO_ENTRY_FLAG_DEPTH;
|
|
|
|
if (depth_stencil->container->resource.format_flags & WINED3DFMT_FLAG_STENCIL)
|
|
|
|
entry->flags |= WINED3D_FBO_ENTRY_FLAG_STENCIL;
|
|
|
|
}
|
2011-08-21 21:34:54 +02:00
|
|
|
entry->rt_mask = context_generate_rt_mask(GL_COLOR_ATTACHMENT0);
|
2013-05-27 09:22:49 +02:00
|
|
|
gl_info->fbo_ops.glGenFramebuffers(1, &entry->id);
|
|
|
|
checkGLcall("glGenFramebuffers()");
|
|
|
|
TRACE("Created FBO %u.\n", entry->id);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2008-09-18 14:57:53 +02:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation 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,
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface **render_targets, struct wined3d_surface *depth_stencil,
|
2015-05-22 10:11:22 +02:00
|
|
|
DWORD color_location, DWORD ds_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
|
|
|
|
2013-05-27 09:22:49 +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
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
context_generate_fbo_key(context, &entry->key, render_targets, depth_stencil, color_location, ds_location);
|
2016-02-21 22:30:01 +01:00
|
|
|
entry->flags = 0;
|
|
|
|
if (depth_stencil)
|
|
|
|
{
|
|
|
|
if (depth_stencil->container->resource.format_flags & WINED3DFMT_FLAG_DEPTH)
|
|
|
|
entry->flags |= WINED3D_FBO_ENTRY_FLAG_DEPTH;
|
|
|
|
if (depth_stencil->container->resource.format_flags & WINED3DFMT_FLAG_STENCIL)
|
|
|
|
entry->flags |= WINED3D_FBO_ENTRY_FLAG_STENCIL;
|
|
|
|
}
|
2009-05-11 16:43:49 +02:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation 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)
|
|
|
|
{
|
2013-05-27 09:22:49 +02:00
|
|
|
TRACE("Destroy FBO %u.\n", entry->id);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation 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,
|
2015-05-22 10:11:22 +02:00
|
|
|
struct wined3d_surface **render_targets, struct wined3d_surface *depth_stencil,
|
|
|
|
DWORD color_location, DWORD ds_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;
|
2016-04-17 19:07:49 +02:00
|
|
|
unsigned int object_count = gl_info->limits.buffers + 1;
|
|
|
|
struct wined3d_texture *rt_texture, *ds_texture;
|
2008-09-18 14:57:53 +02:00
|
|
|
struct fbo_entry *entry;
|
2016-02-21 22:29:57 +01:00
|
|
|
unsigned int i;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2016-03-11 16:01:38 +01:00
|
|
|
if (depth_stencil && render_targets[0])
|
2011-03-11 11:28:19 +01:00
|
|
|
{
|
2016-04-17 19:07:49 +02:00
|
|
|
rt_texture = render_targets[0]->container;
|
|
|
|
ds_texture = depth_stencil->container;
|
|
|
|
|
|
|
|
if (wined3d_texture_get_level_width(ds_texture, depth_stencil->texture_level)
|
|
|
|
< wined3d_texture_get_level_width(rt_texture, render_targets[0]->texture_level)
|
|
|
|
|| wined3d_texture_get_level_height(ds_texture, depth_stencil->texture_level)
|
|
|
|
< wined3d_texture_get_level_height(rt_texture, render_targets[0]->texture_level))
|
2011-03-11 11:28:19 +01:00
|
|
|
{
|
2016-04-17 19:07:49 +02:00
|
|
|
WARN("Depth stencil is smaller than the primary color buffer, disabling.\n");
|
2011-03-11 11:28:19 +01:00
|
|
|
depth_stencil = NULL;
|
|
|
|
}
|
2016-04-17 19:07:49 +02:00
|
|
|
else if (ds_texture->resource.multisample_type != rt_texture->resource.multisample_type
|
|
|
|
|| ds_texture->resource.multisample_quality != rt_texture->resource.multisample_quality)
|
2016-02-21 22:30:00 +01:00
|
|
|
{
|
|
|
|
WARN("Color multisample type %u and quality %u, depth stencil has %u and %u, disabling ds buffer.\n",
|
2016-04-17 19:07:49 +02:00
|
|
|
rt_texture->resource.multisample_type, rt_texture->resource.multisample_quality,
|
|
|
|
ds_texture->resource.multisample_type, ds_texture->resource.multisample_quality);
|
2016-02-21 22:30:00 +01:00
|
|
|
depth_stencil = NULL;
|
|
|
|
}
|
2016-02-21 22:29:58 +01:00
|
|
|
else
|
|
|
|
surface_set_compatible_renderbuffer(depth_stencil, render_targets[0]);
|
2011-03-11 11:28:19 +01:00
|
|
|
}
|
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
context_generate_fbo_key(context, context->fbo_key, render_targets, depth_stencil, color_location,
|
|
|
|
ds_location);
|
|
|
|
|
|
|
|
if (TRACE_ON(d3d))
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2016-02-21 22:29:57 +01:00
|
|
|
TRACE("Dumping FBO attachments:\n");
|
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2016-02-21 22:29:57 +01:00
|
|
|
if (render_targets[i])
|
|
|
|
{
|
2016-04-17 19:07:49 +02:00
|
|
|
rt_texture = render_targets[i]->container;
|
|
|
|
TRACE(" Color attachment %u: %p format %s, %s %u, %ux%u, %u samples.\n",
|
|
|
|
i, render_targets[i], debug_d3dformat(rt_texture->resource.format->id),
|
2016-09-22 20:39:37 +02:00
|
|
|
context->fbo_key->rb_namespace & (1 << (i + 1)) ? "renderbuffer" : "texture",
|
2016-02-21 22:29:57 +01:00
|
|
|
context->fbo_key->objects[i + 1].object,
|
2016-04-17 19:07:49 +02:00
|
|
|
wined3d_texture_get_level_pow2_width(rt_texture, render_targets[i]->texture_level),
|
|
|
|
wined3d_texture_get_level_pow2_height(rt_texture, render_targets[i]->texture_level),
|
|
|
|
rt_texture->resource.multisample_type);
|
2016-02-21 22:29:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (depth_stencil)
|
|
|
|
{
|
2016-04-17 19:07:49 +02:00
|
|
|
ds_texture = depth_stencil->container;
|
|
|
|
TRACE(" Depth attachment: %p format %s, %s %u, %ux%u, %u samples.\n",
|
|
|
|
depth_stencil, debug_d3dformat(ds_texture->resource.format->id),
|
2016-09-22 20:39:37 +02:00
|
|
|
context->fbo_key->rb_namespace & (1 << 0) ? "renderbuffer" : "texture",
|
2016-02-21 22:29:57 +01:00
|
|
|
context->fbo_key->objects[0].object,
|
2016-04-17 19:07:49 +02:00
|
|
|
wined3d_texture_get_level_pow2_width(ds_texture, depth_stencil->texture_level),
|
|
|
|
wined3d_texture_get_level_pow2_height(ds_texture, depth_stencil->texture_level),
|
|
|
|
ds_texture->resource.multisample_type);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(entry, &context->fbo_list, struct fbo_entry, entry)
|
|
|
|
{
|
|
|
|
if (memcmp(context->fbo_key, &entry->key, FIELD_OFFSET(struct wined3d_fbo_entry_key, objects[object_count])))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_remove(&entry->entry);
|
|
|
|
list_add_head(&context->fbo_list, &entry->entry);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2009-05-11 16:43:49 +02:00
|
|
|
if (context->fbo_entry_count < WINED3D_MAX_FBO_ENTRIES)
|
|
|
|
{
|
2015-05-22 10:11:22 +02:00
|
|
|
entry = context_create_fbo_entry(context, render_targets, depth_stencil, color_location, ds_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);
|
2015-05-22 10:11:22 +02:00
|
|
|
context_reuse_fbo_entry(context, target, render_targets, depth_stencil, color_location, ds_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
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation 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;
|
2013-04-26 14:58:27 +02:00
|
|
|
GLuint read_binding, draw_binding;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2016-02-21 22:30:01 +01:00
|
|
|
if (entry->flags & WINED3D_FBO_ENTRY_FLAG_ATTACHED)
|
2013-04-26 14:58:27 +02:00
|
|
|
{
|
2013-05-27 09:22:49 +02:00
|
|
|
context_bind_fbo(context, target, entry->id);
|
2013-04-26 14:58:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2013-04-26 14:58:27 +02:00
|
|
|
read_binding = context->fbo_read_binding;
|
|
|
|
draw_binding = context->fbo_draw_binding;
|
2013-05-27 09:22:49 +02:00
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, entry->id);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2011-05-27 13:57:34 +02:00
|
|
|
/* Apply render targets */
|
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2016-02-21 22:29:57 +01:00
|
|
|
context_attach_surface_fbo(context, target, i, &entry->key.objects[i + 1],
|
|
|
|
entry->key.rb_namespace & (1 << (i + 1)));
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2011-05-27 13:57:34 +02:00
|
|
|
|
2016-02-21 22:30:01 +01:00
|
|
|
context_attach_depth_stencil_fbo(context, target, &entry->key.objects[0],
|
|
|
|
entry->key.rb_namespace & 0x1, entry->flags);
|
2011-05-27 13:57:34 +02:00
|
|
|
|
2013-04-26 14:58:27 +02:00
|
|
|
/* Set valid read and draw buffer bindings to satisfy pedantic pre-ES2_compatibility
|
|
|
|
* GL contexts requirements. */
|
2015-02-09 21:19:49 +01:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(GL_NONE);
|
2013-04-26 14:58:27 +02:00
|
|
|
context_set_draw_buffer(context, GL_NONE);
|
|
|
|
if (target != GL_FRAMEBUFFER)
|
|
|
|
{
|
|
|
|
if (target == GL_READ_FRAMEBUFFER)
|
2013-05-27 09:22:49 +02:00
|
|
|
context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, draw_binding);
|
2013-04-26 14:58:27 +02:00
|
|
|
else
|
2013-05-27 09:22:49 +02:00
|
|
|
context_bind_fbo(context, GL_READ_FRAMEBUFFER, read_binding);
|
2013-04-26 14:58:27 +02:00
|
|
|
}
|
|
|
|
|
2016-02-21 22:30:01 +01:00
|
|
|
entry->flags |= WINED3D_FBO_ENTRY_FLAG_ATTACHED;
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation 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,
|
2015-05-22 10:11:22 +02:00
|
|
|
struct wined3d_surface **render_targets, struct wined3d_surface *depth_stencil,
|
|
|
|
DWORD color_location, DWORD ds_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)
|
|
|
|
{
|
2013-05-27 09:22:49 +02:00
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, 0);
|
2010-03-17 21:59:51 +01:00
|
|
|
context->rebind_fbo = FALSE;
|
|
|
|
}
|
|
|
|
|
2015-05-22 10:11:22 +02:00
|
|
|
if (color_location == WINED3D_LOCATION_DRAWABLE)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2011-08-24 22:08:47 +02:00
|
|
|
context->current_fbo = NULL;
|
2013-05-27 09:22:49 +02:00
|
|
|
context_bind_fbo(context, target, 0);
|
2010-05-04 20:39:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-22 10:11:22 +02:00
|
|
|
context->current_fbo = context_find_fbo_entry(context, target, render_targets, depth_stencil,
|
|
|
|
color_location, ds_location);
|
2011-08-24 22:08:47 +02:00
|
|
|
context_apply_fbo_entry(context, target, context->current_fbo);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation 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,
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location)
|
2010-05-04 20:39:52 +02:00
|
|
|
{
|
2011-08-25 21:04:55 +02:00
|
|
|
UINT clear_size = (context->gl_info->limits.buffers - 1) * sizeof(*context->blit_targets);
|
|
|
|
|
|
|
|
context->blit_targets[0] = render_target;
|
|
|
|
if (clear_size)
|
|
|
|
memset(&context->blit_targets[1], 0, clear_size);
|
2015-05-22 10:11:22 +02:00
|
|
|
context_apply_fbo_state(context, target, context->blit_targets, depth_stencil, location, 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
|
|
|
{
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glGenQueries(1, &query->id));
|
|
|
|
checkGLcall("glGenQueries");
|
2009-07-24 10:44:13 +02:00
|
|
|
|
|
|
|
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
|
|
|
{
|
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");
|
|
|
|
|
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
|
|
|
{
|
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");
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
void context_alloc_timestamp_query(struct wined3d_context *context, struct wined3d_timestamp_query *query)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (context->free_timestamp_query_count)
|
|
|
|
{
|
|
|
|
query->id = context->free_timestamp_queries[--context->free_timestamp_query_count];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glGenQueries(1, &query->id));
|
|
|
|
checkGLcall("glGenQueries");
|
2014-04-16 18:14:48 +02:00
|
|
|
|
|
|
|
TRACE("Allocated timestamp query %u in context %p.\n", query->id, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
query->context = context;
|
|
|
|
list_add_head(&context->timestamp_queries, &query->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void context_free_timestamp_query(struct wined3d_timestamp_query *query)
|
|
|
|
{
|
|
|
|
struct wined3d_context *context = query->context;
|
|
|
|
|
|
|
|
list_remove(&query->entry);
|
|
|
|
query->context = NULL;
|
|
|
|
|
|
|
|
if (context->free_timestamp_query_count >= context->free_timestamp_query_size - 1)
|
|
|
|
{
|
|
|
|
UINT new_size = context->free_timestamp_query_size << 1;
|
|
|
|
GLuint *new_data = HeapReAlloc(GetProcessHeap(), 0, context->free_timestamp_queries,
|
|
|
|
new_size * sizeof(*context->free_timestamp_queries));
|
|
|
|
|
|
|
|
if (!new_data)
|
|
|
|
{
|
|
|
|
ERR("Failed to grow free list, leaking query %u in context %p.\n", query->id, context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->free_timestamp_query_size = new_size;
|
|
|
|
context->free_timestamp_queries = new_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->free_timestamp_queries[context->free_timestamp_query_count++] = query->id;
|
|
|
|
}
|
|
|
|
|
2010-08-15 23:21:42 +02:00
|
|
|
typedef void (context_fbo_entry_func_t)(struct wined3d_context *context, struct fbo_entry *entry);
|
|
|
|
|
2016-02-21 22:29:59 +01:00
|
|
|
static void context_enum_fbo_entries(const struct wined3d_device *device,
|
|
|
|
GLuint name, BOOL rb_namespace, context_fbo_entry_func_t *callback)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
for (i = 0; i < device->context_count; ++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;
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-02-21 22:29:59 +01:00
|
|
|
for (j = 0; j < gl_info->limits.buffers + 1; ++j)
|
2010-08-15 23:21:42 +02:00
|
|
|
{
|
2016-02-21 22:29:59 +01:00
|
|
|
if (entry->key.objects[j].object == name
|
|
|
|
&& !(entry->key.rb_namespace & (1 << j)) == !rb_namespace)
|
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);
|
|
|
|
}
|
|
|
|
|
2011-06-29 23:14:13 +02:00
|
|
|
void context_resource_released(const struct wined3d_device *device,
|
2012-01-17 21:13:36 +01:00
|
|
|
struct wined3d_resource *resource, enum wined3d_resource_type type)
|
2010-08-15 23:21:42 +02:00
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
struct wined3d_texture *texture;
|
2016-02-21 22:29:59 +01:00
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if (!device->d3d_initialized)
|
|
|
|
return;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2010-08-15 23:21:42 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
case WINED3D_RTYPE_TEXTURE_2D:
|
|
|
|
case WINED3D_RTYPE_TEXTURE_3D:
|
2016-04-20 19:29:13 +02:00
|
|
|
texture = texture_from_resource(resource);
|
2016-02-21 22:29:59 +01:00
|
|
|
|
|
|
|
for (i = 0; i < device->context_count; ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_context *context = device->contexts[i];
|
2016-03-29 16:45:32 +02:00
|
|
|
if (context->current_rt.texture == texture)
|
|
|
|
{
|
|
|
|
context->current_rt.texture = NULL;
|
|
|
|
context->current_rt.sub_resource_idx = 0;
|
|
|
|
}
|
2016-02-21 22:29:59 +01:00
|
|
|
}
|
2010-08-15 23:21:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 22:29:59 +01:00
|
|
|
void context_gl_resource_released(struct wined3d_device *device,
|
|
|
|
GLuint name, BOOL rb_namespace)
|
2010-08-15 23:21:42 +02:00
|
|
|
{
|
2016-02-21 22:29:59 +01:00
|
|
|
context_enum_fbo_entries(device, name, rb_namespace, context_queue_fbo_entry_destruction);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2011-06-29 23:14:15 +02:00
|
|
|
void context_surface_update(struct wined3d_context *context, const struct wined3d_surface *surface)
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
for (i = 0; i < gl_info->limits.buffers + 1; ++i)
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
2016-02-21 22:29:57 +01:00
|
|
|
if (surface->container->texture_rgb.name == entry->key.objects[i].object
|
|
|
|
|| surface->container->texture_srgb.name == entry->key.objects[i].object)
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
2016-02-21 22:29:57 +01:00
|
|
|
TRACE("Updated surface %p is bound as attachment %u to the current FBO.\n", surface, i);
|
2010-03-17 21:59:51 +01:00
|
|
|
context->rebind_fbo = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-24 04:46:04 +01:00
|
|
|
static BOOL context_restore_pixel_format(struct wined3d_context *ctx)
|
2010-03-15 21:07:24 +01:00
|
|
|
{
|
2014-02-19 23:14:53 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = ctx->gl_info;
|
2014-03-24 04:46:04 +01:00
|
|
|
BOOL ret = FALSE;
|
2014-02-19 23:14:53 +01:00
|
|
|
|
|
|
|
if (ctx->restore_pf && IsWindow(ctx->restore_pf_win))
|
|
|
|
{
|
|
|
|
if (ctx->gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH])
|
|
|
|
{
|
2016-02-15 21:48:27 +01:00
|
|
|
HDC dc = GetDCEx(ctx->restore_pf_win, 0, DCX_USESTYLE | DCX_CACHE);
|
2014-02-19 23:14:53 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
2014-03-24 04:46:04 +01:00
|
|
|
if (!(ret = GL_EXTCALL(wglSetPixelFormatWINE(dc, ctx->restore_pf))))
|
2014-02-19 23:14:53 +01:00
|
|
|
{
|
|
|
|
ERR("wglSetPixelFormatWINE failed to restore pixel format %d on window %p.\n",
|
|
|
|
ctx->restore_pf, ctx->restore_pf_win);
|
|
|
|
}
|
|
|
|
ReleaseDC(ctx->restore_pf_win, dc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("can't restore pixel format %d on window %p\n", ctx->restore_pf, ctx->restore_pf_win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->restore_pf = 0;
|
|
|
|
ctx->restore_pf_win = NULL;
|
2014-03-24 04:46:04 +01:00
|
|
|
return ret;
|
2014-02-19 23:14:53 +01:00
|
|
|
}
|
|
|
|
|
2014-03-24 04:46:18 +01:00
|
|
|
static BOOL context_set_pixel_format(struct wined3d_context *context, HDC dc, BOOL private, int format)
|
2014-02-19 23:14:53 +01:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2014-03-24 04:46:25 +01:00
|
|
|
int current;
|
2010-03-15 21:07:24 +01:00
|
|
|
|
2014-03-24 04:46:25 +01:00
|
|
|
if (dc == context->hdc && context->hdc_is_private && context->hdc_has_format)
|
|
|
|
return TRUE;
|
|
|
|
|
2015-11-04 00:02:49 +01:00
|
|
|
current = gl_info->gl_ops.wgl.p_wglGetPixelFormat(dc);
|
2014-03-24 04:46:25 +01:00
|
|
|
if (current == format) goto success;
|
2010-03-15 21:07:24 +01:00
|
|
|
|
|
|
|
if (!current)
|
|
|
|
{
|
|
|
|
if (!SetPixelFormat(dc, format, NULL))
|
|
|
|
{
|
2011-10-16 21:55:31 +02:00
|
|
|
/* This may also happen if the dc belongs to a destroyed window. */
|
|
|
|
WARN("Failed to set pixel format %d on device context %p, last error %#x.\n",
|
2010-03-15 21:07:24 +01:00
|
|
|
format, dc, GetLastError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-19 23:14:53 +01:00
|
|
|
|
|
|
|
context->restore_pf = 0;
|
2014-03-24 04:46:18 +01:00
|
|
|
context->restore_pf_win = private ? NULL : WindowFromDC(dc);
|
2014-03-24 04:46:25 +01:00
|
|
|
goto success;
|
2010-03-15 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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])
|
|
|
|
{
|
2014-02-19 23:14:53 +01:00
|
|
|
HWND win;
|
|
|
|
|
2012-06-28 12:00:45 +02:00
|
|
|
if (!GL_EXTCALL(wglSetPixelFormatWINE(dc, format)))
|
2010-03-15 21:07:24 +01:00
|
|
|
{
|
|
|
|
ERR("wglSetPixelFormatWINE failed to set pixel format %d on device context %p.\n",
|
|
|
|
format, dc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-19 23:14:53 +01:00
|
|
|
|
2014-03-24 04:46:18 +01:00
|
|
|
win = private ? NULL : WindowFromDC(dc);
|
2014-02-19 23:14:53 +01:00
|
|
|
if (win != context->restore_pf_win)
|
|
|
|
{
|
|
|
|
context_restore_pixel_format(context);
|
|
|
|
|
2014-03-24 04:46:18 +01:00
|
|
|
context->restore_pf = private ? 0 : current;
|
2014-02-19 23:14:53 +01:00
|
|
|
context->restore_pf_win = win;
|
|
|
|
}
|
|
|
|
|
2014-03-24 04:46:25 +01:00
|
|
|
goto success;
|
2010-03-15 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
2014-03-24 04:46:25 +01:00
|
|
|
|
|
|
|
success:
|
|
|
|
if (dc == context->hdc && context->hdc_is_private)
|
|
|
|
context->hdc_has_format = TRUE;
|
|
|
|
return TRUE;
|
2010-03-15 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
2011-04-12 22:26:21 +02:00
|
|
|
static BOOL context_set_gl_context(struct wined3d_context *ctx)
|
|
|
|
{
|
2011-04-12 22:27:54 +02:00
|
|
|
struct wined3d_swapchain *swapchain = ctx->swapchain;
|
2011-10-16 21:55:31 +02:00
|
|
|
BOOL backup = FALSE;
|
2011-04-12 22:27:54 +02:00
|
|
|
|
2014-03-24 04:46:18 +01:00
|
|
|
if (!context_set_pixel_format(ctx, ctx->hdc, ctx->hdc_is_private, ctx->pixel_format))
|
2011-10-16 21:55:31 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to set pixel format %d on device context %p.\n",
|
|
|
|
ctx->pixel_format, ctx->hdc);
|
|
|
|
backup = TRUE;
|
|
|
|
}
|
|
|
|
|
2012-11-08 11:56:06 +01:00
|
|
|
if (backup || !wglMakeCurrent(ctx->hdc, ctx->glCtx))
|
2011-04-12 22:26:21 +02:00
|
|
|
{
|
2011-07-05 22:30:53 +02:00
|
|
|
HDC dc;
|
|
|
|
|
2011-04-12 22:26:21 +02:00
|
|
|
WARN("Failed to make GL context %p current on device context %p, last error %#x.\n",
|
|
|
|
ctx->glCtx, ctx->hdc, GetLastError());
|
|
|
|
ctx->valid = 0;
|
2011-04-12 22:27:54 +02:00
|
|
|
WARN("Trying fallback to the backup window.\n");
|
|
|
|
|
2011-10-16 21:55:30 +02:00
|
|
|
/* FIXME: If the context is destroyed it's no longer associated with
|
|
|
|
* a swapchain, so we can't use the swapchain to get a backup dc. To
|
|
|
|
* make this work windowless contexts would need to be handled by the
|
|
|
|
* device. */
|
2016-10-05 11:17:05 +02:00
|
|
|
if (ctx->destroyed || !swapchain)
|
2011-10-16 21:55:30 +02:00
|
|
|
{
|
|
|
|
FIXME("Unable to get backup dc for destroyed context %p.\n", ctx);
|
|
|
|
context_set_current(NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-07-05 22:30:53 +02:00
|
|
|
if (!(dc = swapchain_get_backup_dc(swapchain)))
|
2011-04-12 22:27:54 +02:00
|
|
|
{
|
2011-07-05 22:30:53 +02:00
|
|
|
context_set_current(NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-24 04:46:18 +01:00
|
|
|
if (!context_set_pixel_format(ctx, dc, TRUE, ctx->pixel_format))
|
2011-07-05 22:30:53 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to set pixel format %d on device context %p.\n",
|
|
|
|
ctx->pixel_format, dc);
|
|
|
|
context_set_current(NULL);
|
|
|
|
return FALSE;
|
2011-04-12 22:27:54 +02:00
|
|
|
}
|
|
|
|
|
2012-11-08 11:56:06 +01:00
|
|
|
if (!wglMakeCurrent(dc, ctx->glCtx))
|
2011-04-12 22:27:54 +02:00
|
|
|
{
|
|
|
|
ERR("Fallback to backup window (dc %p) failed too, last error %#x.\n",
|
2011-07-05 22:30:53 +02:00
|
|
|
dc, GetLastError());
|
2011-04-12 22:27:54 +02:00
|
|
|
context_set_current(NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-04 10:02:44 +01:00
|
|
|
|
|
|
|
ctx->valid = 1;
|
2011-04-12 22:26:21 +02:00
|
|
|
}
|
2014-02-19 23:14:04 +01:00
|
|
|
ctx->needs_set = 0;
|
2011-04-12 22:26:21 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-02-19 23:14:53 +01:00
|
|
|
static void context_restore_gl_context(const struct wined3d_gl_info *gl_info, HDC dc, HGLRC gl_ctx)
|
2011-04-12 22:26:21 +02:00
|
|
|
{
|
2012-11-08 11:56:06 +01:00
|
|
|
if (!wglMakeCurrent(dc, gl_ctx))
|
2011-04-12 22:26:21 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to restore GL context %p on device context %p, last error %#x.\n",
|
|
|
|
gl_ctx, dc, GetLastError());
|
|
|
|
context_set_current(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 11:17:04 +02:00
|
|
|
static void context_update_window(struct wined3d_context *context, HWND win_handle)
|
2010-03-15 21:07:31 +01:00
|
|
|
{
|
2016-10-05 11:17:04 +02:00
|
|
|
if (context->win_handle == win_handle)
|
2011-03-18 19:18:40 +01:00
|
|
|
return;
|
|
|
|
|
2010-03-15 21:07:31 +01:00
|
|
|
TRACE("Updating context %p window from %p to %p.\n",
|
2016-10-05 11:17:04 +02:00
|
|
|
context, context->win_handle, win_handle);
|
2010-03-15 21:07:31 +01:00
|
|
|
|
2014-03-24 04:45:44 +01:00
|
|
|
if (context->hdc)
|
2013-11-04 10:02:43 +01:00
|
|
|
wined3d_release_dc(context->win_handle, context->hdc);
|
2010-03-15 21:07:31 +01:00
|
|
|
|
2016-10-05 11:17:04 +02:00
|
|
|
context->win_handle = win_handle;
|
2014-03-24 04:46:18 +01:00
|
|
|
context->hdc_is_private = FALSE;
|
2014-03-24 04:46:25 +01:00
|
|
|
context->hdc_has_format = FALSE;
|
2014-02-19 23:14:24 +01:00
|
|
|
context->needs_set = 1;
|
2014-03-24 04:45:44 +01:00
|
|
|
context->valid = 1;
|
2010-03-15 21:07:31 +01:00
|
|
|
|
2016-02-15 21:48:27 +01:00
|
|
|
if (!(context->hdc = GetDCEx(context->win_handle, 0, DCX_USESTYLE | DCX_CACHE)))
|
2010-03-15 21:07:31 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to get a device context for window %p.\n", context->win_handle);
|
2014-03-24 04:45:50 +01:00
|
|
|
context->valid = 0;
|
2010-03-15 21:07:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2014-04-16 18:14:48 +02:00
|
|
|
struct wined3d_timestamp_query *timestamp_query;
|
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
|
|
|
|
2012-11-08 11:56:06 +01:00
|
|
|
restore_ctx = wglGetCurrentContext();
|
|
|
|
restore_dc = wglGetCurrentDC();
|
2009-07-22 10:41:06 +02:00
|
|
|
|
2014-02-05 22:24:19 +01:00
|
|
|
if (restore_ctx == context->glCtx)
|
2012-12-10 21:54:36 +01:00
|
|
|
restore_ctx = NULL;
|
2014-02-05 22:24:19 +01:00
|
|
|
else if (context->valid)
|
|
|
|
context_set_gl_context(context);
|
2009-07-22 10:41:06 +02:00
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(timestamp_query, &context->timestamp_queries, struct wined3d_timestamp_query, entry)
|
|
|
|
{
|
|
|
|
if (context->valid)
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glDeleteQueries(1, ×tamp_query->id));
|
2014-04-16 18:14:48 +02:00
|
|
|
timestamp_query->context = NULL;
|
|
|
|
}
|
|
|
|
|
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])
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glDeleteQueries(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->dummy_arbfp_prog)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteProgramsARB(1, &context->dummy_arbfp_prog));
|
|
|
|
}
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
if (gl_info->supported[ARB_TIMER_QUERY])
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glDeleteQueries(context->free_timestamp_query_count, context->free_timestamp_queries));
|
2014-04-16 18:14:48 +02:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_OCCLUSION_QUERY])
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glDeleteQueries(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])
|
|
|
|
{
|
2011-04-29 23:48:25 +02:00
|
|
|
for (i = 0; i < context->free_event_query_count; ++i)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteSync(context->free_event_queries[i].sync));
|
|
|
|
}
|
2010-01-25 19:51:30 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, context->free_timestamp_queries);
|
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
|
|
|
|
2014-02-19 23:14:53 +01:00
|
|
|
context_restore_pixel_format(context);
|
2009-10-28 11:00:10 +01:00
|
|
|
if (restore_ctx)
|
|
|
|
{
|
2014-02-19 23:14:53 +01:00
|
|
|
context_restore_gl_context(gl_info, restore_dc, restore_ctx);
|
2009-10-28 11:00:10 +01:00
|
|
|
}
|
2012-11-08 11:56:06 +01:00
|
|
|
else if (wglGetCurrentContext() && !wglMakeCurrent(NULL, NULL))
|
2009-07-22 10:41:06 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to disable GL context.\n");
|
|
|
|
}
|
|
|
|
|
2013-11-04 10:02:43 +01:00
|
|
|
wined3d_release_dc(context->win_handle, context->hdc);
|
2009-07-22 10:41:06 +02:00
|
|
|
|
2012-11-08 11:56:06 +01:00
|
|
|
if (!wglDeleteContext(context->glCtx))
|
2009-08-07 08:51:21 +02:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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);
|
2011-11-15 14:21:08 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, (void *)old->gl_info);
|
2009-07-22 10:41:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, old);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-27 20:39:31 +01:00
|
|
|
if (wglGetCurrentContext())
|
|
|
|
{
|
2016-10-10 10:22:36 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = old->gl_info;
|
2015-11-27 20:39:31 +01:00
|
|
|
TRACE("Flushing context %p before switching to %p.\n", old, ctx);
|
2016-10-10 10:22:36 +02:00
|
|
|
gl_info->gl_ops.gl.p_glFlush();
|
2015-11-27 20:39:31 +01:00
|
|
|
}
|
2009-07-22 10:41:06 +02:00
|
|
|
old->current = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 14:03:36 +02:00
|
|
|
if (ctx)
|
|
|
|
{
|
2011-03-18 19:17:52 +01:00
|
|
|
if (!ctx->valid)
|
|
|
|
{
|
|
|
|
ERR("Trying to make invalid context %p current\n", ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-07-22 14:03:36 +02:00
|
|
|
TRACE("Switching to D3D context %p, GL context %p, device context %p.\n", ctx, ctx->glCtx, ctx->hdc);
|
2011-04-12 22:26:21 +02:00
|
|
|
if (!context_set_gl_context(ctx))
|
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
|
|
|
}
|
2016-10-10 10:22:36 +02:00
|
|
|
else if (wglGetCurrentContext())
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
|
|
|
TRACE("Clearing current D3D context.\n");
|
2012-11-08 11:56:06 +01:00
|
|
|
if (!wglMakeCurrent(NULL, NULL))
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2014-02-19 23:14:53 +01:00
|
|
|
if (!--context->level)
|
2009-10-28 11:00:13 +01:00
|
|
|
{
|
2014-03-24 04:46:04 +01:00
|
|
|
if (context_restore_pixel_format(context))
|
|
|
|
context->needs_set = 1;
|
2014-02-19 23:14:53 +01:00
|
|
|
if (context->restore_ctx)
|
|
|
|
{
|
|
|
|
TRACE("Restoring GL context %p on device context %p.\n", context->restore_ctx, context->restore_dc);
|
|
|
|
context_restore_gl_context(context->gl_info, context->restore_dc, context->restore_ctx);
|
|
|
|
context->restore_ctx = NULL;
|
|
|
|
context->restore_dc = NULL;
|
|
|
|
}
|
2016-10-05 11:17:07 +02:00
|
|
|
|
|
|
|
if (context->destroy_delayed)
|
|
|
|
{
|
|
|
|
TRACE("Destroying context %p.\n", context);
|
|
|
|
context_destroy(context->device, context);
|
|
|
|
}
|
2009-10-28 11:00:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-12 22:34:39 +02:00
|
|
|
/* This is used when a context for render target A is active, but a separate context is
|
|
|
|
* needed to access the WGL framebuffer for render target B. Re-acquire a context for rt
|
|
|
|
* A to avoid breaking caller code. */
|
|
|
|
void context_restore(struct wined3d_context *context, struct wined3d_surface *restore)
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
if (context->current_rt.texture != restore->container
|
|
|
|
|| context->current_rt.sub_resource_idx != surface_get_sub_resource_idx(restore))
|
2015-10-12 22:34:39 +02:00
|
|
|
{
|
|
|
|
context_release(context);
|
2016-03-04 00:05:21 +01:00
|
|
|
context = context_acquire(restore->container->resource.device, restore);
|
2015-10-12 22:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2009-10-28 11:00:13 +01:00
|
|
|
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();
|
2012-11-08 11:56:06 +01:00
|
|
|
HGLRC current_gl = wglGetCurrentContext();
|
2009-10-28 11:00:13 +01:00
|
|
|
|
|
|
|
if (current_gl && (!current_context || current_context->glCtx != current_gl))
|
|
|
|
{
|
|
|
|
TRACE("Another GL context (%p on device context %p) is already current.\n",
|
2012-11-08 11:56:06 +01:00
|
|
|
current_gl, wglGetCurrentDC());
|
2009-10-28 11:00:13 +01:00
|
|
|
context->restore_ctx = current_gl;
|
2012-11-08 11:56:06 +01:00
|
|
|
context->restore_dc = wglGetCurrentDC();
|
2014-02-19 23:14:04 +01:00
|
|
|
context->needs_set = 1;
|
2009-10-28 11:00:13 +01:00
|
|
|
}
|
2014-03-24 04:46:25 +01:00
|
|
|
else if (!context->needs_set && !(context->hdc_is_private && context->hdc_has_format)
|
2015-11-04 00:02:49 +01:00
|
|
|
&& context->pixel_format != context->gl_info->gl_ops.wgl.p_wglGetPixelFormat(context->hdc))
|
2014-02-19 23:14:53 +01:00
|
|
|
context->needs_set = 1;
|
2009-10-28 11:00:13 +01:00
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
}
|
|
|
|
|
2011-07-26 19:52:45 +02:00
|
|
|
void context_invalidate_state(struct wined3d_context *context, DWORD state)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
2011-07-26 19:52:44 +02:00
|
|
|
DWORD rep = context->state_table[state].representative;
|
2007-02-12 19:21:10 +01:00
|
|
|
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);
|
2015-08-26 12:46:47 +02:00
|
|
|
context->isStateDirty[idx] |= (1u << shift);
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2011-08-22 21:02:44 +02:00
|
|
|
/* This function takes care of wined3d pixel format selection. */
|
2011-10-20 21:42:59 +02:00
|
|
|
static int context_choose_pixel_format(const struct wined3d_device *device, HDC hdc,
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *color_format, const struct wined3d_format *ds_format,
|
2011-08-25 21:05:02 +02:00
|
|
|
BOOL auxBuffers, BOOL findCompatible)
|
2008-04-27 19:35:27 +02:00
|
|
|
{
|
2008-11-20 23:13:48 +01:00
|
|
|
int iPixelFormat=0;
|
2011-11-08 20:48:57 +01:00
|
|
|
unsigned int current_value;
|
2011-10-27 17:06:25 +02:00
|
|
|
unsigned int cfg_count = device->adapter->cfg_count;
|
|
|
|
unsigned int i;
|
2008-04-27 19:35:27 +02:00
|
|
|
|
2011-08-25 21:05:02 +02:00
|
|
|
TRACE("device %p, dc %p, color_format %s, ds_format %s, aux_buffers %#x, find_compatible %#x.\n",
|
|
|
|
device, hdc, debug_d3dformat(color_format->id), debug_d3dformat(ds_format->id),
|
|
|
|
auxBuffers, findCompatible);
|
2008-06-02 22:39:51 +02:00
|
|
|
|
2011-11-08 20:48:57 +01:00
|
|
|
current_value = 0;
|
|
|
|
for (i = 0; i < cfg_count; ++i)
|
2011-05-05 20:56:10 +02:00
|
|
|
{
|
2011-11-08 20:48:57 +01:00
|
|
|
const struct wined3d_pixel_format *cfg = &device->adapter->cfgs[i];
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
/* For now only accept RGBA formats. Perhaps some day we will
|
|
|
|
* allow floating point formats for pbuffers. */
|
|
|
|
if (cfg->iPixelType != WGL_TYPE_RGBA_ARB)
|
|
|
|
continue;
|
|
|
|
/* In window mode we need a window drawable format and double buffering. */
|
|
|
|
if (!(cfg->windowDrawable && cfg->doubleBuffer))
|
|
|
|
continue;
|
2015-11-04 00:02:45 +01:00
|
|
|
if (cfg->redSize < color_format->red_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
continue;
|
2015-11-04 00:02:45 +01:00
|
|
|
if (cfg->greenSize < color_format->green_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
continue;
|
2015-11-04 00:02:45 +01:00
|
|
|
if (cfg->blueSize < color_format->blue_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
continue;
|
2015-11-04 00:02:45 +01:00
|
|
|
if (cfg->alphaSize < color_format->alpha_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
continue;
|
2015-11-04 00:02:46 +01:00
|
|
|
if (cfg->depthSize < ds_format->depth_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
continue;
|
2015-11-04 00:02:46 +01:00
|
|
|
if (ds_format->stencil_size && cfg->stencilSize != ds_format->stencil_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
continue;
|
|
|
|
/* Check multisampling support. */
|
|
|
|
if (cfg->numSamples)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
value = 1;
|
|
|
|
/* 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. */
|
2015-11-04 00:02:46 +01:00
|
|
|
if (cfg->depthSize == ds_format->depth_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
value += 1;
|
2015-11-04 00:02:46 +01:00
|
|
|
if (cfg->stencilSize == ds_format->stencil_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
value += 2;
|
2015-11-04 00:02:45 +01:00
|
|
|
if (cfg->alphaSize == color_format->alpha_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
value += 4;
|
|
|
|
/* We like to have aux buffers in backbuffer mode */
|
|
|
|
if (auxBuffers && cfg->auxBuffers)
|
|
|
|
value += 8;
|
2015-11-04 00:02:45 +01:00
|
|
|
if (cfg->redSize == color_format->red_size
|
|
|
|
&& cfg->greenSize == color_format->green_size
|
|
|
|
&& cfg->blueSize == color_format->blue_size)
|
2011-11-08 20:48:57 +01:00
|
|
|
value += 16;
|
|
|
|
|
|
|
|
if (value > current_value)
|
2011-05-05 20:56:10 +02:00
|
|
|
{
|
2011-11-08 20:48:57 +01:00
|
|
|
iPixelFormat = cfg->iPixelFormat;
|
|
|
|
current_value = value;
|
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;
|
2015-11-04 00:02:45 +01:00
|
|
|
pfd.cAlphaBits = color_format->alpha_size;
|
|
|
|
pfd.cColorBits = color_format->red_size + color_format->green_size
|
|
|
|
+ color_format->blue_size + color_format->alpha_size;
|
2015-11-04 00:02:46 +01:00
|
|
|
pfd.cDepthBits = ds_format->depth_size;
|
|
|
|
pfd.cStencilBits = ds_format->stencil_size;
|
2008-04-27 19:35:27 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2016-10-03 00:38:37 +02:00
|
|
|
void context_bind_dummy_textures(const struct wined3d_device *device, const struct wined3d_context *context)
|
2011-08-26 01:12:27 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2016-10-03 00:38:38 +02:00
|
|
|
unsigned int i;
|
2011-08-26 01:12:27 +02:00
|
|
|
|
2016-10-03 00:38:38 +02:00
|
|
|
for (i = 0; i < gl_info->limits.combined_samplers; ++i)
|
2011-08-26 01:12:27 +02:00
|
|
|
{
|
2015-01-08 17:20:21 +01:00
|
|
|
GL_EXTCALL(glActiveTexture(GL_TEXTURE0 + i));
|
|
|
|
checkGLcall("glActiveTexture");
|
2011-08-26 01:12:27 +02:00
|
|
|
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_textures.tex_2d);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_textures.tex_rect);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE3D])
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_textures.tex_3d);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_textures.tex_cube);
|
2016-04-19 00:01:26 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE_ARRAY])
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_textures.tex_2d_array);
|
|
|
|
|
|
|
|
checkGLcall("Bind dummy textures");
|
2011-08-26 01:12:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 10:32:43 +02:00
|
|
|
void wined3d_check_gl_call(const struct wined3d_gl_info *gl_info,
|
|
|
|
const char *file, unsigned int line, const char *name)
|
|
|
|
{
|
|
|
|
GLint err;
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_DEBUG_OUTPUT] || (err = gl_info->gl_ops.gl.p_glGetError()) == GL_NO_ERROR)
|
|
|
|
{
|
|
|
|
TRACE("%s call ok %s / %u.\n", name, file, line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ERR(">>>>>>> %s (%#x) from %s @ %s / %u.\n",
|
|
|
|
debug_glerror(err), err, name, file,line);
|
|
|
|
err = gl_info->gl_ops.gl.p_glGetError();
|
|
|
|
} while (err != GL_NO_ERROR);
|
|
|
|
}
|
|
|
|
|
2015-07-08 15:47:01 +02:00
|
|
|
static BOOL context_debug_output_enabled(const struct wined3d_gl_info *gl_info)
|
2013-04-19 08:34:12 +02:00
|
|
|
{
|
|
|
|
return gl_info->supported[ARB_DEBUG_OUTPUT]
|
|
|
|
&& (ERR_ON(d3d) || FIXME_ON(d3d) || WARN_ON(d3d_perf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINE_GLAPI wined3d_debug_callback(GLenum source, GLenum type, GLuint id,
|
|
|
|
GLenum severity, GLsizei length, const char *message, void *ctx)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GL_DEBUG_TYPE_ERROR_ARB:
|
|
|
|
ERR("%p: %s.\n", ctx, debugstr_an(message, length));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB:
|
|
|
|
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB:
|
|
|
|
case GL_DEBUG_TYPE_PORTABILITY_ARB:
|
|
|
|
FIXME("%p: %s.\n", ctx, debugstr_an(message, length));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_DEBUG_TYPE_PERFORMANCE_ARB:
|
|
|
|
WARN_(d3d_perf)("%p: %s.\n", ctx, debugstr_an(message, length));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("ctx %p, type %#x: %s.\n", ctx, type, debugstr_an(message, length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-08 15:47:01 +02:00
|
|
|
HGLRC context_create_wgl_attribs(const struct wined3d_gl_info *gl_info, HDC hdc, HGLRC share_ctx)
|
|
|
|
{
|
|
|
|
HGLRC ctx;
|
|
|
|
unsigned int ctx_attrib_idx = 0;
|
|
|
|
GLint ctx_attribs[7], ctx_flags = 0;
|
|
|
|
|
|
|
|
if (context_debug_output_enabled(gl_info))
|
|
|
|
ctx_flags = WGL_CONTEXT_DEBUG_BIT_ARB;
|
|
|
|
ctx_attribs[ctx_attrib_idx++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
|
|
|
|
ctx_attribs[ctx_attrib_idx++] = gl_info->selected_gl_version >> 16;
|
|
|
|
ctx_attribs[ctx_attrib_idx++] = WGL_CONTEXT_MINOR_VERSION_ARB;
|
|
|
|
ctx_attribs[ctx_attrib_idx++] = gl_info->selected_gl_version & 0xffff;
|
|
|
|
if (gl_info->selected_gl_version >= MAKEDWORD_VERSION(3, 2))
|
|
|
|
ctx_flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
if (ctx_flags)
|
|
|
|
{
|
|
|
|
ctx_attribs[ctx_attrib_idx++] = WGL_CONTEXT_FLAGS_ARB;
|
|
|
|
ctx_attribs[ctx_attrib_idx++] = ctx_flags;
|
|
|
|
}
|
|
|
|
ctx_attribs[ctx_attrib_idx] = 0;
|
|
|
|
|
|
|
|
if (!(ctx = gl_info->p_wglCreateContextAttribsARB(hdc, share_ctx, ctx_attribs)))
|
|
|
|
{
|
|
|
|
if (ctx_flags & WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB)
|
|
|
|
{
|
|
|
|
ctx_attribs[ctx_attrib_idx - 1] &= ~WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
if (!(ctx = gl_info->p_wglCreateContextAttribsARB(hdc, share_ctx, ctx_attribs)))
|
|
|
|
WARN("Failed to create a WGL context with wglCreateContextAttribsARB, last error %#x.\n",
|
|
|
|
GetLastError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
|
2016-03-23 17:58:22 +01:00
|
|
|
struct wined3d_texture *target, const struct wined3d_format *ds_format)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = swapchain->device;
|
2010-03-15 21:07:25 +01:00
|
|
|
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
|
|
|
BOOL auxBuffers = FALSE;
|
2013-04-19 08:34:11 +02:00
|
|
|
HGLRC ctx, share_ctx;
|
2010-03-14 21:53:23 +01:00
|
|
|
int pixel_format;
|
2009-03-25 10:12:27 +01:00
|
|
|
unsigned int s;
|
2010-03-14 21:53:24 +01:00
|
|
|
DWORD state;
|
2016-01-27 13:38:04 +01:00
|
|
|
HDC hdc = 0;
|
2014-03-24 04:46:18 +01:00
|
|
|
BOOL hdc_is_private = FALSE;
|
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)
|
|
|
|
return NULL;
|
|
|
|
|
2016-05-23 18:06:27 +02:00
|
|
|
if (!(ret->blit_targets = wined3d_calloc(gl_info->limits.buffers, sizeof(*ret->blit_targets))))
|
2011-10-13 21:43:07 +02:00
|
|
|
goto out;
|
|
|
|
|
2016-05-23 18:06:27 +02:00
|
|
|
if (!(ret->draw_buffers = wined3d_calloc(gl_info->limits.buffers, sizeof(*ret->draw_buffers))))
|
2011-10-13 21:43:07 +02:00
|
|
|
goto out;
|
|
|
|
|
2016-02-21 22:29:57 +01:00
|
|
|
ret->fbo_key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
FIELD_OFFSET(struct wined3d_fbo_entry_key, objects[gl_info->limits.buffers + 1]));
|
|
|
|
if (!ret->fbo_key)
|
|
|
|
goto out;
|
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
ret->free_timestamp_query_size = 4;
|
2016-05-23 18:06:27 +02:00
|
|
|
if (!(ret->free_timestamp_queries = wined3d_calloc(ret->free_timestamp_query_size,
|
|
|
|
sizeof(*ret->free_timestamp_queries))))
|
2014-04-16 18:14:48 +02:00
|
|
|
goto out;
|
|
|
|
list_init(&ret->timestamp_queries);
|
|
|
|
|
2011-10-13 21:43:07 +02:00
|
|
|
ret->free_occlusion_query_size = 4;
|
2016-05-23 18:06:27 +02:00
|
|
|
if (!(ret->free_occlusion_queries = wined3d_calloc(ret->free_occlusion_query_size,
|
|
|
|
sizeof(*ret->free_occlusion_queries))))
|
2011-10-13 21:43:07 +02:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
list_init(&ret->occlusion_queries);
|
|
|
|
|
|
|
|
ret->free_event_query_size = 4;
|
2016-05-23 18:06:27 +02:00
|
|
|
if (!(ret->free_event_queries = wined3d_calloc(ret->free_event_query_size,
|
|
|
|
sizeof(*ret->free_event_queries))))
|
2011-10-13 21:43:07 +02:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
list_init(&ret->event_queries);
|
|
|
|
list_init(&ret->fbo_list);
|
|
|
|
list_init(&ret->fbo_destroy_list);
|
|
|
|
|
2013-08-23 10:18:14 +02:00
|
|
|
if (!device->shader_backend->shader_allocate_context_data(ret))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate shader backend context data.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2015-03-23 18:59:09 +01:00
|
|
|
if (!device->adapter->fragment_pipe->allocate_context_data(ret))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate fragment pipeline context data.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2013-08-23 10:18:14 +02:00
|
|
|
|
2013-09-16 12:43:18 +02:00
|
|
|
/* Initialize the texture unit mapping to a 1:1 mapping */
|
|
|
|
for (s = 0; s < MAX_COMBINED_SAMPLERS; ++s)
|
|
|
|
{
|
2015-11-12 23:06:40 +01:00
|
|
|
if (s < gl_info->limits.combined_samplers)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
|
|
|
ret->tex_unit_map[s] = s;
|
|
|
|
ret->rev_tex_unit_map[s] = s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret->tex_unit_map[s] = WINED3D_UNMAPPED_STAGE;
|
|
|
|
ret->rev_tex_unit_map[s] = WINED3D_UNMAPPED_STAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-15 21:48:27 +01:00
|
|
|
if (!(hdc = GetDCEx(swapchain->win_handle, 0, DCX_USESTYLE | DCX_CACHE)))
|
2010-03-14 21:53:23 +01:00
|
|
|
{
|
2015-03-10 19:29:40 +01:00
|
|
|
WARN("Failed to retrieve device context, trying swapchain backup.\n");
|
2011-07-05 22:30:53 +02:00
|
|
|
|
2014-03-24 04:46:18 +01:00
|
|
|
if ((hdc = swapchain_get_backup_dc(swapchain)))
|
|
|
|
hdc_is_private = TRUE;
|
|
|
|
else
|
2011-07-05 22:30:53 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to retrieve a device context.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2010-03-14 21:53:23 +01:00
|
|
|
}
|
2008-04-27 20:40:33 +02:00
|
|
|
|
2016-03-23 17:58:22 +01: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
|
2011-05-09 09:03:40 +02:00
|
|
|
* old games like StarCraft and C&C. Most modern hardware doesn't support
|
2010-03-14 21:53:23 +01:00
|
|
|
* 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
|
|
|
|
2015-11-04 00:02:48 +01:00
|
|
|
/* When "always_offscreen" is enabled, we only use the drawable for
|
|
|
|
* presentation blits, and don't do any rendering to it. That means we
|
|
|
|
* don't need depth or stencil buffers, and can mostly ignore the render
|
|
|
|
* target format. This wouldn't necessarily be quite correct for 10bpc
|
|
|
|
* display modes, but we don't currently support those.
|
|
|
|
* Using the same format regardless of the color/depth/stencil targets
|
|
|
|
* makes it much less likely that different wined3d instances will set
|
|
|
|
* conflicting pixel formats. */
|
2015-11-18 22:23:25 +01:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_BACKBUFFER
|
|
|
|
&& wined3d_settings.always_offscreen)
|
2015-11-04 00:02:48 +01:00
|
|
|
{
|
|
|
|
color_format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM);
|
|
|
|
ds_format = wined3d_get_format(gl_info, WINED3DFMT_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
/* Try to find a pixel format which matches our requirements. */
|
2011-08-25 21:05:02 +02:00
|
|
|
pixel_format = context_choose_pixel_format(device, hdc, color_format, ds_format, auxBuffers, FALSE);
|
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");
|
2011-08-25 21:05:02 +02:00
|
|
|
pixel_format = context_choose_pixel_format(device, hdc, color_format, ds_format, auxBuffers, TRUE);
|
2010-03-14 21:53:23 +01:00
|
|
|
}
|
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
|
|
|
|
2014-02-19 23:14:53 +01:00
|
|
|
ret->gl_info = gl_info;
|
|
|
|
|
2015-11-04 00:02:49 +01:00
|
|
|
context_enter(ret);
|
|
|
|
|
2014-03-24 04:46:18 +01:00
|
|
|
if (!context_set_pixel_format(ret, hdc, hdc_is_private, 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);
|
2011-10-13 21:43:07 +02:00
|
|
|
context_release(ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-04-19 08:34:11 +02:00
|
|
|
share_ctx = device->context_count ? device->contexts[0]->glCtx : NULL;
|
|
|
|
if (gl_info->p_wglCreateContextAttribsARB)
|
2011-10-13 21:43:07 +02:00
|
|
|
{
|
2015-07-08 15:47:01 +02:00
|
|
|
if (!(ctx = context_create_wgl_attribs(gl_info, hdc, share_ctx)))
|
2013-04-19 08:34:11 +02:00
|
|
|
goto out;
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
2013-04-19 08:34:11 +02:00
|
|
|
else
|
2009-07-15 12:21:17 +02:00
|
|
|
{
|
2013-04-19 08:34:11 +02:00
|
|
|
if (!(ctx = wglCreateContext(hdc)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create a WGL context.\n");
|
|
|
|
context_release(ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (share_ctx && !wglShareLists(share_ctx, ctx))
|
2009-07-15 12:21:17 +02:00
|
|
|
{
|
2013-04-19 08:34:11 +02:00
|
|
|
ERR("wglShareLists(%p, %p) failed, last error %#x.\n", share_ctx, ctx, GetLastError());
|
2011-10-13 21:43:07 +02:00
|
|
|
context_release(ret);
|
2012-11-08 11:56:06 +01:00
|
|
|
if (!wglDeleteContext(ctx))
|
2011-10-13 21:43:07 +02:00
|
|
|
ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError());
|
|
|
|
goto out;
|
2009-07-15 12:21:17 +02:00
|
|
|
}
|
|
|
|
}
|
2007-08-08 03:09:38 +02: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");
|
2011-10-13 21:43:07 +02:00
|
|
|
context_release(ret);
|
2012-11-08 11:56:06 +01:00
|
|
|
if (!wglDeleteContext(ctx))
|
2011-10-13 21:43:07 +02:00
|
|
|
ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError());
|
2007-02-12 19:21:10 +01:00
|
|
|
goto out;
|
|
|
|
}
|
2010-03-14 21:53:24 +01:00
|
|
|
|
2013-04-25 15:20:24 +02:00
|
|
|
ret->d3d_info = &device->adapter->d3d_info;
|
2011-07-24 21:48:11 +02:00
|
|
|
ret->state_table = device->StateTable;
|
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)
|
|
|
|
{
|
2011-07-24 21:48:11 +02:00
|
|
|
if (ret->state_table[state].representative)
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(ret, state);
|
2010-03-14 21:53:24 +01:00
|
|
|
}
|
|
|
|
|
2016-10-05 11:17:03 +02:00
|
|
|
ret->device = device;
|
2010-03-15 21:07:25 +01:00
|
|
|
ret->swapchain = swapchain;
|
2016-03-29 16:45:32 +02:00
|
|
|
ret->current_rt.texture = target;
|
|
|
|
ret->current_rt.sub_resource_idx = 0;
|
2010-03-14 21:53:24 +01:00
|
|
|
ret->tid = GetCurrentThreadId();
|
|
|
|
|
2016-03-23 17:58:22 +01:00
|
|
|
ret->render_offscreen = wined3d_resource_is_offscreen(&target->resource);
|
2011-06-30 23:21:03 +02:00
|
|
|
ret->draw_buffers_mask = context_generate_rt_mask(GL_BACK);
|
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;
|
2014-03-24 04:46:18 +01:00
|
|
|
ret->hdc_is_private = hdc_is_private;
|
2014-03-24 04:46:25 +01:00
|
|
|
ret->hdc_has_format = TRUE;
|
2010-03-15 21:07:31 +01:00
|
|
|
ret->pixel_format = pixel_format;
|
2014-02-19 23:14:04 +01:00
|
|
|
ret->needs_set = 1;
|
2010-03-14 21:53:24 +01:00
|
|
|
|
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))
|
|
|
|
{
|
2011-10-13 21:43:07 +02:00
|
|
|
ERR("Cannot activate context to set up defaults.\n");
|
|
|
|
device_context_remove(device, ret);
|
2009-10-28 11:00:13 +01:00
|
|
|
context_release(ret);
|
2012-11-08 11:56:06 +01:00
|
|
|
if (!wglDeleteContext(ctx))
|
2011-10-13 21:43:07 +02:00
|
|
|
ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError());
|
2007-02-12 19:21:10 +01:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-04-19 08:34:12 +02:00
|
|
|
if (context_debug_output_enabled(gl_info))
|
|
|
|
{
|
2015-10-22 00:21:00 +02:00
|
|
|
GL_EXTCALL(glDebugMessageCallback(wined3d_debug_callback, ret));
|
2013-04-19 08:34:12 +02:00
|
|
|
if (TRACE_ON(d3d_synchronous))
|
2015-10-22 00:21:00 +02:00
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
|
|
|
GL_EXTCALL(glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_FALSE));
|
2013-04-19 08:34:12 +02:00
|
|
|
if (ERR_ON(d3d))
|
|
|
|
{
|
2015-10-22 00:21:00 +02:00
|
|
|
GL_EXTCALL(glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_ERROR,
|
2013-04-19 08:34:12 +02:00
|
|
|
GL_DONT_CARE, 0, NULL, GL_TRUE));
|
|
|
|
}
|
|
|
|
if (FIXME_ON(d3d))
|
|
|
|
{
|
2015-10-22 00:21:00 +02:00
|
|
|
GL_EXTCALL(glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR,
|
2013-04-19 08:34:12 +02:00
|
|
|
GL_DONT_CARE, 0, NULL, GL_TRUE));
|
2015-10-22 00:21:00 +02:00
|
|
|
GL_EXTCALL(glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR,
|
2013-04-19 08:34:12 +02:00
|
|
|
GL_DONT_CARE, 0, NULL, GL_TRUE));
|
2015-10-22 00:21:00 +02:00
|
|
|
GL_EXTCALL(glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_PORTABILITY,
|
2013-04-19 08:34:12 +02:00
|
|
|
GL_DONT_CARE, 0, NULL, GL_TRUE));
|
|
|
|
}
|
|
|
|
if (WARN_ON(d3d_perf))
|
|
|
|
{
|
2015-10-22 00:21:00 +02:00
|
|
|
GL_EXTCALL(glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_PERFORMANCE,
|
2013-04-19 08:34:12 +02:00
|
|
|
GL_DONT_CARE, 0, NULL, GL_TRUE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetIntegerv(GL_AUX_BUFFERS, &ret->aux_buffers);
|
2008-04-08 14:20:27 +02:00
|
|
|
|
2007-02-12 19:21:10 +01:00
|
|
|
TRACE("Setting up the screen\n");
|
|
|
|
|
2016-03-28 23:03:29 +02:00
|
|
|
if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
|
|
|
|
checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2016-03-28 23:03:29 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
|
|
|
|
checkGLcall("glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2016-03-28 23:03:29 +02:00
|
|
|
gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
|
|
|
checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
|
|
|
|
}
|
|
|
|
else
|
2015-07-10 00:06:19 +02:00
|
|
|
{
|
|
|
|
GLuint vao;
|
|
|
|
|
|
|
|
GL_EXTCALL(glGenVertexArrays(1, &vao));
|
|
|
|
GL_EXTCALL(glBindVertexArray(vao));
|
|
|
|
checkGLcall("creating VAO");
|
|
|
|
}
|
|
|
|
|
2016-03-28 23:03:29 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_PACK_ALIGNMENT, device->surface_alignment);
|
|
|
|
checkGLcall("glPixelStorei(GL_PACK_ALIGNMENT, device->surface_alignment);");
|
|
|
|
gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
2016-09-22 20:39:37 +02:00
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, 1);");
|
2016-03-28 23:03:29 +02:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_VERTEX_BLEND])
|
|
|
|
{
|
2012-07-24 11:32:27 +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 as well. */
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_WEIGHT_SUM_UNITY_ARB);
|
2007-04-27 00:43:15 +02:00
|
|
|
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
|
|
|
{
|
2011-08-03 01:34:15 +02:00
|
|
|
context_active_texture(ret, gl_info, s);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_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.
|
|
|
|
*/
|
2014-05-02 12:50:16 +02:00
|
|
|
static const char dummy_program[] =
|
2009-05-07 11:40:44 +02:00
|
|
|
"!!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
|
|
|
|
2011-08-04 19:53:31 +02:00
|
|
|
if (gl_info->supported[ARB_POINT_SPRITE])
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2011-08-04 19:53:31 +02:00
|
|
|
for (s = 0; s < gl_info->limits.textures; ++s)
|
|
|
|
{
|
2011-08-03 01:34:15 +02:00
|
|
|
context_active_texture(ret, gl_info, s);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
|
2011-08-04 19:53:31 +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
|
|
|
|
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));
|
|
|
|
}
|
2016-10-03 23:46:56 +02:00
|
|
|
if (gl_info->supported[ARB_CLIP_CONTROL])
|
|
|
|
GL_EXTCALL(glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT));
|
2015-06-02 16:39:46 +02:00
|
|
|
device->shader_backend->shader_init_context_state(ret);
|
2015-08-26 12:46:47 +02:00
|
|
|
ret->shader_update_mask = (1u << WINED3D_SHADER_TYPE_PIXEL)
|
|
|
|
| (1u << WINED3D_SHADER_TYPE_VERTEX)
|
2016-03-29 12:14:53 +02:00
|
|
|
| (1u << WINED3D_SHADER_TYPE_GEOMETRY)
|
2016-04-01 11:21:41 +02:00
|
|
|
| (1u << WINED3D_SHADER_TYPE_HULL)
|
2016-06-21 13:09:56 +02:00
|
|
|
| (1u << WINED3D_SHADER_TYPE_DOMAIN)
|
|
|
|
| (1u << WINED3D_SHADER_TYPE_COMPUTE);
|
2009-08-10 09:30:50 +02:00
|
|
|
|
2011-08-26 01:12:27 +02:00
|
|
|
/* If this happens to be the first context for the device, dummy textures
|
|
|
|
* are not created yet. In that case, they will be created (and bound) by
|
|
|
|
* create_dummy_textures right after this context is initialized. */
|
2016-10-03 00:38:37 +02:00
|
|
|
if (device->dummy_textures.tex_2d)
|
|
|
|
context_bind_dummy_textures(device, ret);
|
2011-08-26 01:12:27 +02: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:
|
2016-01-27 13:38:04 +01:00
|
|
|
if (hdc) wined3d_release_dc(swapchain->win_handle, hdc);
|
2013-08-23 10:18:14 +02:00
|
|
|
device->shader_backend->shader_free_context_data(ret);
|
2015-03-23 18:59:09 +01:00
|
|
|
device->adapter->fragment_pipe->free_context_data(ret);
|
2010-03-14 21:53:24 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret->free_event_queries);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ret->free_occlusion_queries);
|
2014-04-16 18:14:48 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret->free_timestamp_queries);
|
2016-02-21 22:29:57 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret->fbo_key);
|
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);
|
2008-08-21 18:34:55 +02:00
|
|
|
return NULL;
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
void context_destroy(struct wined3d_device *device, 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
|
|
|
|
2016-10-05 11:17:07 +02:00
|
|
|
/* We delay destroying a context when it is active. The context_release()
|
|
|
|
* function invokes context_destroy() again while leaving the last level. */
|
|
|
|
if (context->level)
|
|
|
|
{
|
|
|
|
TRACE("Delaying destruction of context %p.\n", context);
|
|
|
|
context->destroy_delayed = 1;
|
|
|
|
/* FIXME: Get rid of a pointer to swapchain from wined3d_context. */
|
|
|
|
context->swapchain = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-11-15 14:21:08 +01:00
|
|
|
/* Make a copy of gl_info for context_destroy_gl_resources use, the one
|
|
|
|
in wined3d_adapter may go away in the meantime */
|
|
|
|
struct wined3d_gl_info *gl_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*gl_info));
|
|
|
|
*gl_info = *context->gl_info;
|
|
|
|
context->gl_info = gl_info;
|
2009-07-22 10:41:06 +02:00
|
|
|
context->destroyed = 1;
|
|
|
|
destroy = FALSE;
|
2009-06-29 10:11:24 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 10:18:14 +02:00
|
|
|
device->shader_backend->shader_free_context_data(context);
|
2015-03-23 18:59:09 +01:00
|
|
|
device->adapter->fragment_pipe->free_context_data(context);
|
2016-02-21 22:29:57 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, context->fbo_key);
|
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);
|
2011-05-16 23:01:23 +02:00
|
|
|
device_context_remove(device, context);
|
2009-07-22 10:41:06 +02:00
|
|
|
if (destroy) HeapFree(GetProcessHeap(), 0, context);
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2012-07-24 11:32:27 +02:00
|
|
|
static void set_blit_dimension(const struct wined3d_gl_info *gl_info, UINT width, UINT height)
|
2011-11-01 20:15:18 +01:00
|
|
|
{
|
|
|
|
const GLdouble projection[] =
|
|
|
|
{
|
|
|
|
2.0 / width, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 2.0 / height, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 2.0, 0.0,
|
|
|
|
-1.0, -1.0, -1.0, 1.0,
|
|
|
|
};
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
|
2008-06-17 01:41:49 +02:00
|
|
|
checkGLcall("glMatrixMode(GL_PROJECTION)");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glLoadMatrixd(projection);
|
2011-11-01 20:15:18 +01:00
|
|
|
checkGLcall("glLoadMatrixd");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glViewport(0, 0, width, height);
|
2008-06-17 01:41:49 +02:00
|
|
|
checkGLcall("glViewport");
|
|
|
|
}
|
|
|
|
|
2012-04-04 20:37:20 +02:00
|
|
|
static void context_get_rt_size(const struct wined3d_context *context, SIZE *size)
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
const struct wined3d_texture *rt = context->current_rt.texture;
|
|
|
|
unsigned int level;
|
2012-04-04 20:37:20 +02:00
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
if (rt->swapchain && rt->swapchain->front_buffer == rt)
|
2012-04-04 20:37:20 +02:00
|
|
|
{
|
|
|
|
RECT window_size;
|
|
|
|
|
|
|
|
GetClientRect(context->win_handle, &window_size);
|
|
|
|
size->cx = window_size.right - window_size.left;
|
|
|
|
size->cy = window_size.bottom - window_size.top;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
level = context->current_rt.sub_resource_idx % rt->level_count;
|
|
|
|
size->cx = wined3d_texture_get_level_width(rt, level);
|
|
|
|
size->cy = wined3d_texture_get_level_height(rt, level);
|
2012-04-04 20:37:20 +02:00
|
|
|
}
|
|
|
|
|
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. */
|
2011-10-23 18:24:01 +02:00
|
|
|
static void SetupForBlit(const struct wined3d_device *device, struct wined3d_context *context)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
2009-08-17 09:39:07 +02:00
|
|
|
int i;
|
2009-07-17 10:34:02 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2009-08-17 09:39:07 +02:00
|
|
|
DWORD sampler;
|
2012-04-04 20:37:20 +02:00
|
|
|
SIZE rt_size;
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
TRACE("Setting up context %p for blitting\n", context);
|
2012-04-04 20:37:20 +02:00
|
|
|
|
|
|
|
context_get_rt_size(context, &rt_size);
|
|
|
|
|
|
|
|
if (context->last_was_blit)
|
|
|
|
{
|
|
|
|
if (context->blit_w != rt_size.cx || context->blit_h != rt_size.cy)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
set_blit_dimension(gl_info, rt_size.cx, rt_size.cy);
|
2012-04-04 20:37:20 +02:00
|
|
|
context->blit_w = rt_size.cx;
|
|
|
|
context->blit_h = rt_size.cy;
|
|
|
|
/* No need to dirtify here, the states are still dirtified because
|
|
|
|
* they weren't applied since the last SetupForBlit() call. */
|
2008-06-17 01:41:49 +02:00
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
2013-09-16 12:43:18 +02:00
|
|
|
sampler = context->rev_tex_unit_map[i];
|
2011-08-03 01:34:15 +02:00
|
|
|
context_active_texture(context, gl_info, i);
|
2007-02-12 19:18:41 +01:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
2008-12-16 13:18:49 +01:00
|
|
|
checkGLcall("glDisable GL_TEXTURE_CUBE_MAP_ARB");
|
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
|
2008-12-16 13:18:49 +01:00
|
|
|
checkGLcall("glDisable GL_TEXTURE_3D");
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
2008-12-16 13:18:49 +01:00
|
|
|
checkGLcall("glDisable GL_TEXTURE_RECTANGLE_ARB");
|
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
|
2008-12-16 13:18:49 +01:00
|
|
|
checkGLcall("glDisable GL_TEXTURE_2D");
|
2007-03-01 01:21:47 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2008-12-16 13:18:49 +01:00
|
|
|
checkGLcall("glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);");
|
|
|
|
|
2009-08-17 09:39:07 +02:00
|
|
|
if (sampler != WINED3D_UNMAPPED_STAGE)
|
|
|
|
{
|
2011-06-05 22:48:52 +02:00
|
|
|
if (sampler < MAX_TEXTURES)
|
2012-01-09 22:16:51 +01:00
|
|
|
context_invalidate_state(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP));
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_SAMPLER(sampler));
|
2007-02-12 19:18:41 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-15 17:19:06 +01:00
|
|
|
if (gl_info->supported[ARB_SAMPLER_OBJECTS])
|
|
|
|
GL_EXTCALL(glBindSampler(0, 0));
|
2011-08-03 01:34:15 +02:00
|
|
|
context_active_texture(context, gl_info, 0);
|
2008-07-15 23:54:44 +02:00
|
|
|
|
2013-09-16 12:43:18 +02:00
|
|
|
sampler = context->rev_tex_unit_map[0];
|
2008-07-15 23:54:44 +02:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
2007-03-28 19:17:51 +02:00
|
|
|
checkGLcall("glDisable GL_TEXTURE_CUBE_MAP_ARB");
|
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_TEXTURE_3D");
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
2008-08-20 20:50:51 +02:00
|
|
|
checkGLcall("glDisable GL_TEXTURE_RECTANGLE_ARB");
|
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
|
2007-11-26 21:43:08 +01:00
|
|
|
checkGLcall("glDisable GL_TEXTURE_2D");
|
2007-02-12 19:18:41 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2007-02-12 19:18:41 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glMatrixMode(GL_TEXTURE)");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glLoadIdentity();
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glLoadIdentity()");
|
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
|
|
|
|
GL_TEXTURE_LOD_BIAS_EXT, 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)
|
|
|
|
{
|
2011-06-05 22:48:52 +02:00
|
|
|
if (sampler < MAX_TEXTURES)
|
|
|
|
{
|
2012-01-11 21:27:32 +01:00
|
|
|
context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + sampler));
|
2012-01-09 22:16:51 +01:00
|
|
|
context_invalidate_state(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP));
|
2008-07-15 23:54:44 +02:00
|
|
|
}
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_SAMPLER(sampler));
|
2008-07-15 23:54:44 +02:00
|
|
|
}
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
/* Other misc states */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable(GL_ALPHA_TEST)");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHATESTENABLE));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_LIGHTING");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_LIGHTING));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_DEPTH_TEST");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZENABLE));
|
2008-12-15 19:38:48 +01:00
|
|
|
glDisableWINE(GL_FOG);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_FOG");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_FOGENABLE));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_BLEND");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_CULL_FACE");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_CULLMODE));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_STENCIL_TEST");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILENABLE));
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
|
2007-12-01 01:10:37 +01:00
|
|
|
checkGLcall("glDisable GL_SCISSOR_TEST");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE));
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_POINT_SPRITE])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_POINT_SPRITE_ARB);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glDisable GL_POINT_SPRITE_ARB");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE));
|
2007-02-12 19:18:41 +01:00
|
|
|
}
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE,GL_TRUE,GL_TRUE);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glColorMask");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3));
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[EXT_SECONDARY_COLOR])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_COLOR_SUM_EXT);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SPECULARENABLE));
|
2007-08-14 16:32:35 +02:00
|
|
|
checkGLcall("glDisable(GL_COLOR_SUM_EXT)");
|
|
|
|
}
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
/* Setup transforms */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glMatrixMode(GL_MODELVIEW)");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glLoadIdentity();
|
2007-02-12 19:18:41 +01:00
|
|
|
checkGLcall("glLoadIdentity()");
|
2012-01-11 21:27:32 +01:00
|
|
|
context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
|
2007-02-12 19:18:41 +01:00
|
|
|
|
|
|
|
context->last_was_rhw = TRUE;
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_VDECL); /* because of last_was_rhw = TRUE */
|
2007-02-12 19:18:41 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE0); checkGLcall("glDisable(clip plane 0)");
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE1); checkGLcall("glDisable(clip plane 1)");
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE2); checkGLcall("glDisable(clip plane 2)");
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)");
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)");
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)");
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_CLIPPING));
|
2007-02-12 19:18:41 +01:00
|
|
|
|
2016-10-03 23:46:56 +02:00
|
|
|
/* FIXME: Make draw_textured_quad() able to work with a upper left origin. */
|
|
|
|
if (gl_info->supported[ARB_CLIP_CONTROL])
|
|
|
|
GL_EXTCALL(glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE));
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
set_blit_dimension(gl_info, rt_size.cx, rt_size.cy);
|
2012-11-04 19:51:33 +01:00
|
|
|
|
|
|
|
/* Disable shaders */
|
2013-05-14 17:38:18 +02:00
|
|
|
device->shader_backend->shader_disable(device->shader_priv, context);
|
2009-05-13 18:22:54 +02:00
|
|
|
|
2012-04-04 20:37:20 +02:00
|
|
|
context->blit_w = rt_size.cx;
|
|
|
|
context->blit_h = rt_size.cy;
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_VIEWPORT);
|
2012-01-11 21:27:32 +01:00
|
|
|
context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
|
2007-02-12 19:18:41 +01:00
|
|
|
}
|
|
|
|
|
2011-06-06 23:46:12 +02:00
|
|
|
static inline BOOL is_rt_mask_onscreen(DWORD rt_mask)
|
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
return rt_mask & (1u << 31);
|
2011-06-06 23:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline GLenum draw_buffer_from_rt_mask(DWORD rt_mask)
|
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
return rt_mask & ~(1u << 31);
|
2011-06-06 23:46:12 +02:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-06-17 19:28:38 +02:00
|
|
|
static void context_apply_draw_buffers(struct wined3d_context *context, DWORD rt_mask)
|
2008-08-03 21:17:51 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
2011-05-24 22:24:12 +02:00
|
|
|
if (!rt_mask)
|
2011-04-08 20:22:49 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDrawBuffer(GL_NONE);
|
2011-04-08 20:22:49 +02:00
|
|
|
checkGLcall("glDrawBuffer()");
|
|
|
|
}
|
2011-06-06 23:46:12 +02:00
|
|
|
else if (is_rt_mask_onscreen(rt_mask))
|
2008-08-03 21:17:51 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDrawBuffer(draw_buffer_from_rt_mask(rt_mask));
|
2010-08-07 15:29:41 +02:00
|
|
|
checkGLcall("glDrawBuffer()");
|
2008-08-03 21:17:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-04 19:28:42 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
2008-08-04 19:28:37 +02:00
|
|
|
{
|
2011-05-24 22:24:12 +02:00
|
|
|
unsigned int i = 0;
|
2010-05-04 20:39:49 +02:00
|
|
|
|
2011-05-24 22:24:12 +02:00
|
|
|
while (rt_mask)
|
2010-08-29 21:57:40 +02:00
|
|
|
{
|
2011-06-17 19:28:38 +02:00
|
|
|
if (rt_mask & 1)
|
2010-08-29 21:57:40 +02:00
|
|
|
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;
|
2011-05-24 22:24:12 +02:00
|
|
|
|
|
|
|
rt_mask >>= 1;
|
|
|
|
++i;
|
2010-08-29 21:57:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_DRAW_BUFFERS])
|
|
|
|
{
|
2015-01-20 15:47:06 +01:00
|
|
|
GL_EXTCALL(glDrawBuffers(i, context->draw_buffers));
|
2010-08-29 21:57:40 +02:00
|
|
|
checkGLcall("glDrawBuffers()");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDrawBuffer(context->draw_buffers[0]);
|
2008-08-04 19:28:37 +02:00
|
|
|
checkGLcall("glDrawBuffer()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-21 18:28:36 +02:00
|
|
|
ERR("Unexpected draw buffers mask with backbuffer ORM.\n");
|
2008-08-04 19:28:37 +02:00
|
|
|
}
|
2008-08-03 21:17:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2009-12-10 21:41:52 +01:00
|
|
|
void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2013-04-10 01:35:42 +02:00
|
|
|
DWORD *current_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask;
|
|
|
|
DWORD new_mask = context_generate_rt_mask(buffer);
|
|
|
|
|
|
|
|
if (new_mask == *current_mask)
|
|
|
|
return;
|
2012-07-24 11:32:27 +02:00
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glDrawBuffer(buffer);
|
2009-12-10 21:41:52 +01:00
|
|
|
checkGLcall("glDrawBuffer()");
|
2013-04-10 01:35:42 +02:00
|
|
|
|
|
|
|
*current_mask = new_mask;
|
2009-12-10 21:41:52 +01:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-08-03 01:34:15 +02:00
|
|
|
void context_active_texture(struct wined3d_context *context, const struct wined3d_gl_info *gl_info, unsigned int unit)
|
|
|
|
{
|
2015-01-08 17:20:21 +01:00
|
|
|
GL_EXTCALL(glActiveTexture(GL_TEXTURE0 + unit));
|
|
|
|
checkGLcall("glActiveTexture");
|
2011-08-03 01:34:15 +02:00
|
|
|
context->active_texture = unit;
|
|
|
|
}
|
|
|
|
|
2011-08-26 01:12:26 +02:00
|
|
|
void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2011-08-26 01:12:27 +02:00
|
|
|
DWORD unit = context->active_texture;
|
|
|
|
DWORD old_texture_type = context->texture_type[unit];
|
|
|
|
|
2011-08-26 01:12:26 +02:00
|
|
|
if (name)
|
2011-08-26 01:12:27 +02:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(target, name);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
}
|
2011-08-26 01:12:26 +02:00
|
|
|
else
|
2011-08-26 01:12:27 +02:00
|
|
|
{
|
|
|
|
target = GL_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_texture_type != target)
|
|
|
|
{
|
2016-10-05 11:17:03 +02:00
|
|
|
const struct wined3d_device *device = context->device;
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
switch (old_texture_type)
|
|
|
|
{
|
|
|
|
case GL_NONE:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_2D:
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_textures.tex_2d);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
break;
|
2016-04-19 00:01:26 +02:00
|
|
|
case GL_TEXTURE_2D_ARRAY:
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_textures.tex_2d_array);
|
2016-04-19 00:01:26 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
break;
|
2011-08-26 01:12:27 +02:00
|
|
|
case GL_TEXTURE_RECTANGLE_ARB:
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, device->dummy_textures.tex_rect);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_CUBE_MAP:
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, device->dummy_textures.tex_cube);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_3D:
|
2016-10-03 00:38:37 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_textures.tex_3d);
|
2011-08-26 01:12:27 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
break;
|
|
|
|
default:
|
2016-04-19 00:01:26 +02:00
|
|
|
ERR("Unexpected texture target %#x.\n", old_texture_type);
|
2011-08-26 01:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
context->texture_type[unit] = target;
|
|
|
|
}
|
2011-08-26 01:12:26 +02:00
|
|
|
}
|
|
|
|
|
2011-07-26 19:52:44 +02:00
|
|
|
static void context_set_render_offscreen(struct wined3d_context *context, BOOL offscreen)
|
2010-03-28 16:42:32 +02:00
|
|
|
{
|
|
|
|
if (context->render_offscreen == offscreen) return;
|
|
|
|
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_VIEWPORT);
|
|
|
|
context_invalidate_state(context, STATE_SCISSORRECT);
|
2016-10-03 23:46:56 +02:00
|
|
|
if (!context->gl_info->supported[ARB_CLIP_CONTROL])
|
|
|
|
{
|
|
|
|
context_invalidate_state(context, STATE_FRONTFACE);
|
|
|
|
context_invalidate_state(context, STATE_POINTSPRITECOORDORIGIN);
|
|
|
|
context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
|
|
|
|
}
|
2016-10-03 23:46:52 +02:00
|
|
|
if (context->gl_info->supported[ARB_FRAGMENT_COORD_CONVENTIONS])
|
|
|
|
context_invalidate_state(context, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL));
|
2010-03-28 16:42:32 +02:00
|
|
|
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
|
|
|
{
|
2015-04-24 10:33:47 +02:00
|
|
|
if (existing == required)
|
|
|
|
return TRUE;
|
|
|
|
if ((existing->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
|
|
|
|
!= (required->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT))
|
|
|
|
return FALSE;
|
2015-11-04 00:02:46 +01:00
|
|
|
if (existing->depth_size < required->depth_size)
|
|
|
|
return FALSE;
|
|
|
|
/* If stencil bits are used the exact amount is required - otherwise
|
|
|
|
* wrapping won't work correctly. */
|
|
|
|
if (required->stencil_size && required->stencil_size != existing->stencil_size)
|
|
|
|
return FALSE;
|
2010-03-28 16:42:32 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2011-04-29 13:03:42 +02:00
|
|
|
|
2015-10-15 22:41:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-24 21:48:11 +02:00
|
|
|
static void context_validate_onscreen_formats(struct wined3d_context *context,
|
2014-08-22 12:32:01 +02:00
|
|
|
const struct wined3d_rendertarget_view *depth_stencil)
|
2010-03-28 16:42:32 +02:00
|
|
|
{
|
|
|
|
/* Onscreen surfaces are always in a swapchain */
|
2016-03-29 16:45:32 +02:00
|
|
|
struct wined3d_swapchain *swapchain = context->current_rt.texture->swapchain;
|
2010-03-28 16:42:32 +02:00
|
|
|
|
2010-05-18 09:53:08 +02:00
|
|
|
if (context->render_offscreen || !depth_stencil) return;
|
2014-08-22 12:32:01 +02:00
|
|
|
if (match_depth_stencil_format(swapchain->ds_format, depth_stencil->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 */
|
2016-08-02 12:26:29 +02:00
|
|
|
if (!(wined3d_texture_load_location(context->current_rt.texture, context->current_rt.sub_resource_idx,
|
|
|
|
context, WINED3D_LOCATION_TEXTURE_RGB)))
|
|
|
|
ERR("Failed to load location.\n");
|
2010-03-28 16:42:32 +02:00
|
|
|
swapchain->render_to_fbo = TRUE;
|
2011-08-23 20:08:08 +02:00
|
|
|
swapchain_update_draw_bindings(swapchain);
|
2011-07-26 19:52:44 +02:00
|
|
|
context_set_render_offscreen(context, TRUE);
|
2010-03-28 16:42:32 +02:00
|
|
|
}
|
|
|
|
|
2016-02-29 18:19:30 +01:00
|
|
|
GLenum context_get_offscreen_gl_buffer(const struct wined3d_context *context)
|
|
|
|
{
|
|
|
|
switch (wined3d_settings.offscreen_rendering_mode)
|
|
|
|
{
|
|
|
|
case ORM_FBO:
|
|
|
|
return GL_COLOR_ATTACHMENT0;
|
|
|
|
|
|
|
|
case ORM_BACKBUFFER:
|
|
|
|
return context->aux_buffers > 0 ? GL_AUX0 : GL_BACK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled offscreen rendering mode %#x.\n", wined3d_settings.offscreen_rendering_mode);
|
|
|
|
return GL_BACK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:52:26 +01:00
|
|
|
static DWORD context_generate_rt_mask_no_fbo(const struct wined3d_context *context, struct wined3d_texture *rt)
|
2011-06-21 18:28:36 +02:00
|
|
|
{
|
2016-03-25 17:52:26 +01:00
|
|
|
if (!rt || rt->resource.format->id == WINED3DFMT_NULL)
|
2011-06-21 18:28:36 +02:00
|
|
|
return 0;
|
2016-03-25 17:52:26 +01:00
|
|
|
else if (rt->swapchain)
|
|
|
|
return context_generate_rt_mask_from_resource(&rt->resource);
|
2011-06-21 18:28:36 +02:00
|
|
|
else
|
2016-02-29 18:19:30 +01:00
|
|
|
return context_generate_rt_mask(context_get_offscreen_gl_buffer(context));
|
2011-06-21 18:28:36 +02:00
|
|
|
}
|
|
|
|
|
2009-12-27 19:57:21 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-10-24 21:24:39 +02:00
|
|
|
void context_apply_blit_state(struct wined3d_context *context, const struct wined3d_device *device)
|
2009-07-23 10:54:36 +02:00
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
struct wined3d_texture *rt = context->current_rt.texture;
|
|
|
|
struct wined3d_surface *surface;
|
2012-03-28 13:52:11 +02:00
|
|
|
DWORD rt_mask, *cur_mask;
|
2011-06-06 17:44:43 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
2011-07-24 21:48:11 +02:00
|
|
|
context_validate_onscreen_formats(context, NULL);
|
2010-05-18 09:53:06 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (context->render_offscreen)
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
wined3d_texture_load(rt, context, FALSE);
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
surface = rt->sub_resources[context->current_rt.sub_resource_idx].u.surface;
|
|
|
|
context_apply_fbo_state_blit(context, GL_FRAMEBUFFER, surface, NULL, rt->resource.draw_binding);
|
|
|
|
if (rt->resource.format->id != WINED3DFMT_NULL)
|
2011-06-17 19:28:38 +02:00
|
|
|
rt_mask = 1;
|
|
|
|
else
|
|
|
|
rt_mask = 0;
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-27 09:22:48 +02:00
|
|
|
context->current_fbo = NULL;
|
2013-05-27 09:22:49 +02:00
|
|
|
context_bind_fbo(context, GL_FRAMEBUFFER, 0);
|
2016-03-29 16:45:32 +02:00
|
|
|
rt_mask = context_generate_rt_mask_from_resource(&rt->resource);
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
2011-06-06 17:44:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
rt_mask = context_generate_rt_mask_no_fbo(context, rt);
|
2007-11-06 01:11:35 +01:00
|
|
|
}
|
|
|
|
|
2012-03-28 13:52:11 +02:00
|
|
|
cur_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask;
|
2011-08-21 21:34:54 +02:00
|
|
|
|
2012-03-28 13:52:11 +02:00
|
|
|
if (rt_mask != *cur_mask)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2011-06-17 19:28:38 +02:00
|
|
|
context_apply_draw_buffers(context, rt_mask);
|
2012-03-28 13:52:11 +02:00
|
|
|
*cur_mask = rt_mask;
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2011-04-08 20:22:52 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
|
|
|
context_check_fbo_status(context, GL_FRAMEBUFFER);
|
|
|
|
}
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
SetupForBlit(device, context);
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
2007-07-09 16:57:58 +02:00
|
|
|
|
2014-08-22 12:32:01 +02:00
|
|
|
static BOOL context_validate_rt_config(UINT rt_count, struct wined3d_rendertarget_view * const *rts,
|
|
|
|
const struct wined3d_rendertarget_view *ds)
|
2011-01-26 19:45:02 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (ds) return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
if (rts[i] && rts[i]->format->id != WINED3DFMT_NULL)
|
2011-01-26 19:45:03 +01:00
|
|
|
return TRUE;
|
2011-01-26 19:45:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Invalid render target config, need at least one attachment.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2016-04-06 19:12:03 +02:00
|
|
|
BOOL context_apply_clear_state(struct wined3d_context *context, const struct wined3d_state *state,
|
2011-07-02 11:29:28 +02:00
|
|
|
UINT rt_count, const struct wined3d_fb_state *fb)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
struct wined3d_rendertarget_view **rts = fb->render_targets;
|
2015-05-22 10:11:22 +02:00
|
|
|
struct wined3d_rendertarget_view *dsv = fb->depth_stencil;
|
2012-07-24 11:32:26 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2012-03-28 13:52:11 +02:00
|
|
|
DWORD rt_mask = 0, *cur_mask;
|
2010-07-23 11:31:03 +02:00
|
|
|
UINT i;
|
2008-04-06 00:49:00 +02:00
|
|
|
|
2016-04-06 19:12:03 +02:00
|
|
|
if (isStateDirty(context, STATE_FRAMEBUFFER) || fb != state->fb
|
|
|
|
|| rt_count != gl_info->limits.buffers)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2015-05-22 10:11:22 +02:00
|
|
|
if (!context_validate_rt_config(rt_count, rts, dsv))
|
2011-06-08 00:49:58 +02:00
|
|
|
return FALSE;
|
2010-07-23 11:31:03 +02:00
|
|
|
|
2011-06-08 00:49:58 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2015-05-22 10:11:22 +02:00
|
|
|
context_validate_onscreen_formats(context, dsv);
|
2011-06-08 00:49:58 +02:00
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
if (!rt_count || wined3d_resource_is_offscreen(rts[0]->resource))
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2011-06-08 00:49:58 +02:00
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
context->blit_targets[i] = wined3d_rendertarget_view_get_surface(rts[i]);
|
|
|
|
if (rts[i] && rts[i]->format->id != WINED3DFMT_NULL)
|
2015-08-26 12:46:47 +02:00
|
|
|
rt_mask |= (1u << i);
|
2011-06-08 00:49:58 +02:00
|
|
|
}
|
2016-04-06 19:12:03 +02:00
|
|
|
while (i < gl_info->limits.buffers)
|
2011-06-08 00:49:58 +02:00
|
|
|
{
|
|
|
|
context->blit_targets[i] = NULL;
|
|
|
|
++i;
|
|
|
|
}
|
2014-08-22 12:32:01 +02:00
|
|
|
context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets,
|
2015-05-22 10:11:22 +02:00
|
|
|
wined3d_rendertarget_view_get_surface(dsv),
|
|
|
|
rt_count ? rts[0]->resource->draw_binding : 0,
|
|
|
|
dsv ? dsv->resource->draw_binding : 0);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
2011-06-08 00:49:58 +02:00
|
|
|
else
|
2010-07-23 11:31:03 +02:00
|
|
|
{
|
2015-05-22 10:11:22 +02:00
|
|
|
context_apply_fbo_state(context, GL_FRAMEBUFFER, NULL, NULL,
|
|
|
|
WINED3D_LOCATION_DRAWABLE, WINED3D_LOCATION_DRAWABLE);
|
2016-03-25 17:52:25 +01:00
|
|
|
rt_mask = context_generate_rt_mask_from_resource(rts[0]->resource);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
2011-06-08 00:49:58 +02:00
|
|
|
|
|
|
|
/* If the framebuffer is not the device's fb the device's fb has to be reapplied
|
|
|
|
* next draw. Otherwise we could mark the framebuffer state clean here, once the
|
|
|
|
* state management allows this */
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-29 18:19:30 +01:00
|
|
|
rt_mask = context_generate_rt_mask_no_fbo(context,
|
2016-03-25 17:52:26 +01:00
|
|
|
rt_count ? wined3d_rendertarget_view_get_surface(rts[0])->container : NULL);
|
2011-06-08 00:49:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
|
2014-08-21 09:55:55 +02:00
|
|
|
&& (!rt_count || wined3d_resource_is_offscreen(rts[0]->resource)))
|
2011-06-08 00:49:58 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
if (rts[i] && rts[i]->format->id != WINED3DFMT_NULL)
|
2015-08-26 12:46:47 +02:00
|
|
|
rt_mask |= (1u << i);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
2011-05-24 22:24:12 +02:00
|
|
|
else
|
|
|
|
{
|
2016-02-29 18:19:30 +01:00
|
|
|
rt_mask = context_generate_rt_mask_no_fbo(context,
|
2016-03-25 17:52:26 +01:00
|
|
|
rt_count ? wined3d_rendertarget_view_get_surface(rts[0])->container : NULL);
|
2011-05-24 22:24:12 +02:00
|
|
|
}
|
2007-07-09 16:57:58 +02:00
|
|
|
|
2012-03-28 13:52:11 +02:00
|
|
|
cur_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask;
|
2011-08-21 21:34:54 +02:00
|
|
|
|
2012-03-28 13:52:11 +02:00
|
|
|
if (rt_mask != *cur_mask)
|
2011-06-06 17:44:43 +02:00
|
|
|
{
|
2011-06-17 19:28:38 +02:00
|
|
|
context_apply_draw_buffers(context, rt_mask);
|
2012-03-28 13:52:11 +02:00
|
|
|
*cur_mask = rt_mask;
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
2011-06-06 17:44:43 +02:00
|
|
|
}
|
2007-07-01 23:40:57 +02:00
|
|
|
|
2011-04-08 20:22:52 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
|
|
|
context_check_fbo_status(context, GL_FRAMEBUFFER);
|
|
|
|
}
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (context->last_was_blit)
|
2011-06-02 19:54:37 +02:00
|
|
|
context->last_was_blit = FALSE;
|
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. */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_SCISSOR_TEST);
|
2016-03-17 16:30:01 +01:00
|
|
|
if (rt_count && gl_info->supported[ARB_FRAMEBUFFER_SRGB])
|
2015-11-27 20:39:35 +01:00
|
|
|
{
|
2016-04-06 19:12:03 +02:00
|
|
|
if (needs_srgb_write(context, state, fb))
|
2015-11-27 20:39:35 +01:00
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_FRAMEBUFFER_SRGB);
|
|
|
|
else
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_FRAMEBUFFER_SRGB);
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE));
|
|
|
|
}
|
|
|
|
checkGLcall("setting up state for clear");
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE));
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_SCISSORRECT);
|
2011-01-26 19:45:02 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2016-02-29 18:19:30 +01:00
|
|
|
static DWORD find_draw_buffers_mask(const struct wined3d_context *context, const struct wined3d_state *state)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
struct wined3d_rendertarget_view **rts = state->fb->render_targets;
|
2013-10-09 22:57:45 +02:00
|
|
|
struct wined3d_shader *ps = state->shader[WINED3D_SHADER_TYPE_PIXEL];
|
2011-07-02 11:24:37 +02:00
|
|
|
DWORD rt_mask, rt_mask_bits;
|
2010-05-03 22:03:27 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
|
2016-03-25 17:52:26 +01:00
|
|
|
return context_generate_rt_mask_no_fbo(context, wined3d_rendertarget_view_get_surface(rts[0])->container);
|
2014-08-21 09:55:55 +02:00
|
|
|
else if (!context->render_offscreen)
|
2016-03-25 17:52:25 +01:00
|
|
|
return context_generate_rt_mask_from_resource(rts[0]->resource);
|
2011-01-26 19:45:02 +01:00
|
|
|
|
2011-07-02 11:24:37 +02:00
|
|
|
rt_mask = ps ? ps->reg_maps.rt_mask : 1;
|
2013-04-25 15:20:29 +02:00
|
|
|
rt_mask &= context->d3d_info->valid_rt_mask;
|
2011-07-02 11:24:37 +02:00
|
|
|
rt_mask_bits = rt_mask;
|
|
|
|
i = 0;
|
|
|
|
while (rt_mask_bits)
|
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
rt_mask_bits &= ~(1u << i);
|
2014-08-21 09:55:55 +02:00
|
|
|
if (!rts[i] || rts[i]->format->id == WINED3DFMT_NULL)
|
2015-08-26 12:46:47 +02:00
|
|
|
rt_mask &= ~(1u << i);
|
2011-07-02 11:24:37 +02:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rt_mask;
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-14 01:02:48 +02:00
|
|
|
void context_state_fb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
|
2011-07-02 11:24:37 +02:00
|
|
|
{
|
2016-02-29 18:19:30 +01:00
|
|
|
DWORD rt_mask = find_draw_buffers_mask(context, state);
|
2011-07-14 01:02:44 +02:00
|
|
|
const struct wined3d_fb_state *fb = state->fb;
|
2012-03-28 13:52:11 +02:00
|
|
|
DWORD *cur_mask;
|
2010-07-21 18:48:23 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
2010-05-04 20:39:52 +02:00
|
|
|
if (!context->render_offscreen)
|
|
|
|
{
|
2015-05-22 10:11:22 +02:00
|
|
|
context_apply_fbo_state(context, GL_FRAMEBUFFER, NULL, NULL,
|
|
|
|
WINED3D_LOCATION_DRAWABLE, WINED3D_LOCATION_DRAWABLE);
|
2010-05-04 20:39:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 09:55:55 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < context->gl_info->limits.buffers; ++i)
|
|
|
|
{
|
|
|
|
context->blit_targets[i] = wined3d_rendertarget_view_get_surface(fb->render_targets[i]);
|
|
|
|
}
|
2014-08-22 12:32:01 +02:00
|
|
|
context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets,
|
|
|
|
wined3d_rendertarget_view_get_surface(fb->depth_stencil),
|
2016-03-22 13:41:48 +01:00
|
|
|
fb->render_targets[0] ? fb->render_targets[0]->resource->draw_binding : 0,
|
2015-05-22 10:11:22 +02:00
|
|
|
fb->depth_stencil ? fb->depth_stencil->resource->draw_binding : 0);
|
2010-05-04 20:39:52 +02:00
|
|
|
}
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
|
|
|
|
2012-03-28 13:52:11 +02:00
|
|
|
cur_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask;
|
|
|
|
if (rt_mask != *cur_mask)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2011-06-17 19:28:38 +02:00
|
|
|
context_apply_draw_buffers(context, rt_mask);
|
2012-03-28 13:52:11 +02:00
|
|
|
*cur_mask = rt_mask;
|
2007-02-12 19:18:36 +01:00
|
|
|
}
|
2016-10-07 00:57:51 +02:00
|
|
|
context->constant_update_mask |= WINED3D_SHADER_CONST_PS_Y_CORR;
|
2011-07-02 11:24:37 +02:00
|
|
|
}
|
2010-05-03 22:03:27 +02:00
|
|
|
|
2013-09-16 12:43:18 +02:00
|
|
|
static void context_map_stage(struct wined3d_context *context, DWORD stage, DWORD unit)
|
|
|
|
{
|
|
|
|
DWORD i = context->rev_tex_unit_map[unit];
|
|
|
|
DWORD j = context->tex_unit_map[stage];
|
|
|
|
|
2015-11-12 23:06:42 +01:00
|
|
|
TRACE("Mapping stage %u to unit %u.\n", stage, unit);
|
2013-09-16 12:43:18 +02:00
|
|
|
context->tex_unit_map[stage] = unit;
|
|
|
|
if (i != WINED3D_UNMAPPED_STAGE && i != stage)
|
|
|
|
context->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
|
|
|
|
|
|
|
|
context->rev_tex_unit_map[unit] = stage;
|
|
|
|
if (j != WINED3D_UNMAPPED_STAGE && j != unit)
|
|
|
|
context->rev_tex_unit_map[j] = WINED3D_UNMAPPED_STAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void context_invalidate_texture_stage(struct wined3d_context *context, DWORD stage)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for (i = 0; i <= WINED3D_HIGHEST_TEXTURE_STATE; ++i)
|
|
|
|
context_invalidate_state(context, STATE_TEXTURESTAGE(stage, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void context_update_fixed_function_usage_map(struct wined3d_context *context,
|
|
|
|
const struct wined3d_state *state)
|
|
|
|
{
|
2013-10-06 17:33:06 +02:00
|
|
|
UINT i, start, end;
|
2013-09-16 12:43:18 +02:00
|
|
|
|
|
|
|
context->fixed_function_usage_map = 0;
|
|
|
|
for (i = 0; i < MAX_TEXTURES; ++i)
|
|
|
|
{
|
|
|
|
enum wined3d_texture_op color_op = state->texture_states[i][WINED3D_TSS_COLOR_OP];
|
|
|
|
enum wined3d_texture_op alpha_op = state->texture_states[i][WINED3D_TSS_ALPHA_OP];
|
|
|
|
DWORD color_arg1 = state->texture_states[i][WINED3D_TSS_COLOR_ARG1] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD color_arg2 = state->texture_states[i][WINED3D_TSS_COLOR_ARG2] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD color_arg3 = state->texture_states[i][WINED3D_TSS_COLOR_ARG0] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg1 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg2 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] & WINED3DTA_SELECTMASK;
|
|
|
|
DWORD alpha_arg3 = state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] & WINED3DTA_SELECTMASK;
|
|
|
|
|
|
|
|
/* Not used, and disable higher stages. */
|
|
|
|
if (color_op == WINED3D_TOP_DISABLE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (((color_arg1 == WINED3DTA_TEXTURE) && color_op != WINED3D_TOP_SELECT_ARG2)
|
|
|
|
|| ((color_arg2 == WINED3DTA_TEXTURE) && color_op != WINED3D_TOP_SELECT_ARG1)
|
|
|
|
|| ((color_arg3 == WINED3DTA_TEXTURE)
|
|
|
|
&& (color_op == WINED3D_TOP_MULTIPLY_ADD || color_op == WINED3D_TOP_LERP))
|
|
|
|
|| ((alpha_arg1 == WINED3DTA_TEXTURE) && alpha_op != WINED3D_TOP_SELECT_ARG2)
|
|
|
|
|| ((alpha_arg2 == WINED3DTA_TEXTURE) && alpha_op != WINED3D_TOP_SELECT_ARG1)
|
|
|
|
|| ((alpha_arg3 == WINED3DTA_TEXTURE)
|
|
|
|
&& (alpha_op == WINED3D_TOP_MULTIPLY_ADD || alpha_op == WINED3D_TOP_LERP)))
|
2015-08-26 12:46:47 +02:00
|
|
|
context->fixed_function_usage_map |= (1u << i);
|
2013-09-16 12:43:18 +02:00
|
|
|
|
|
|
|
if ((color_op == WINED3D_TOP_BUMPENVMAP || color_op == WINED3D_TOP_BUMPENVMAP_LUMINANCE)
|
|
|
|
&& i < MAX_TEXTURES - 1)
|
2015-08-26 12:46:47 +02:00
|
|
|
context->fixed_function_usage_map |= (1u << (i + 1));
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
2013-10-06 17:33:06 +02:00
|
|
|
|
|
|
|
if (i < context->lowest_disabled_stage)
|
|
|
|
{
|
|
|
|
start = i;
|
|
|
|
end = context->lowest_disabled_stage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = context->lowest_disabled_stage;
|
|
|
|
end = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->lowest_disabled_stage = i;
|
|
|
|
for (i = start + 1; i < end; ++i)
|
|
|
|
{
|
|
|
|
context_invalidate_state(context, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
|
|
|
|
}
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void context_map_fixed_function_samplers(struct wined3d_context *context,
|
|
|
|
const struct wined3d_state *state)
|
|
|
|
{
|
2015-11-12 23:06:41 +01:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2013-09-16 12:43:18 +02:00
|
|
|
unsigned int i, tex;
|
|
|
|
WORD ffu_map;
|
|
|
|
|
|
|
|
context_update_fixed_function_usage_map(context, state);
|
2015-11-12 23:06:41 +01:00
|
|
|
|
|
|
|
if (gl_info->limits.combined_samplers >= MAX_COMBINED_SAMPLERS)
|
|
|
|
return;
|
|
|
|
|
2013-09-16 12:43:18 +02:00
|
|
|
ffu_map = context->fixed_function_usage_map;
|
|
|
|
|
|
|
|
if (d3d_info->limits.ffp_textures == d3d_info->limits.ffp_blend_stages
|
2013-10-06 17:33:06 +02:00
|
|
|
|| context->lowest_disabled_stage <= d3d_info->limits.ffp_textures)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
|
|
|
for (i = 0; ffu_map; ffu_map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(ffu_map & 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (context->tex_unit_map[i] != i)
|
|
|
|
{
|
|
|
|
context_map_stage(context, i, i);
|
|
|
|
context_invalidate_state(context, STATE_SAMPLER(i));
|
|
|
|
context_invalidate_texture_stage(context, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now work out the mapping */
|
|
|
|
tex = 0;
|
|
|
|
for (i = 0; ffu_map; ffu_map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(ffu_map & 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (context->tex_unit_map[i] != tex)
|
|
|
|
{
|
|
|
|
context_map_stage(context, i, tex);
|
|
|
|
context_invalidate_state(context, STATE_SAMPLER(i));
|
|
|
|
context_invalidate_texture_stage(context, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
++tex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void context_map_psamplers(struct wined3d_context *context, const struct wined3d_state *state)
|
|
|
|
{
|
2015-11-12 23:06:41 +01:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2014-12-03 10:28:11 +01:00
|
|
|
const struct wined3d_shader_resource_info *resource_info =
|
|
|
|
state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.resource_info;
|
2013-09-16 12:43:18 +02:00
|
|
|
unsigned int i;
|
2015-11-12 23:06:41 +01:00
|
|
|
|
|
|
|
if (gl_info->limits.combined_samplers >= MAX_COMBINED_SAMPLERS)
|
|
|
|
return;
|
2013-09-16 12:43:18 +02:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
|
|
|
|
{
|
2014-12-03 10:28:11 +01:00
|
|
|
if (resource_info[i].type && context->tex_unit_map[i] != i)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
|
|
|
context_map_stage(context, i, i);
|
|
|
|
context_invalidate_state(context, STATE_SAMPLER(i));
|
|
|
|
if (i < d3d_info->limits.ffp_blend_stages)
|
|
|
|
context_invalidate_texture_stage(context, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL context_unit_free_for_vs(const struct wined3d_context *context,
|
2015-11-12 23:06:42 +01:00
|
|
|
const struct wined3d_shader_resource_info *ps_resource_info, DWORD unit)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
|
|
|
DWORD current_mapping = context->rev_tex_unit_map[unit];
|
|
|
|
|
|
|
|
/* Not currently used */
|
|
|
|
if (current_mapping == WINED3D_UNMAPPED_STAGE)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (current_mapping < MAX_FRAGMENT_SAMPLERS)
|
|
|
|
{
|
|
|
|
/* Used by a fragment sampler */
|
|
|
|
|
2014-12-03 10:28:11 +01:00
|
|
|
if (!ps_resource_info)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
|
|
|
/* No pixel shader, check fixed function */
|
2015-08-26 12:46:47 +02:00
|
|
|
return current_mapping >= MAX_TEXTURES || !(context->fixed_function_usage_map & (1u << current_mapping));
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Pixel shader, check the shader's sampler map */
|
2014-12-03 10:28:11 +01:00
|
|
|
return !ps_resource_info[current_mapping].type;
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-12 23:06:42 +01:00
|
|
|
return TRUE;
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void context_map_vsamplers(struct wined3d_context *context, BOOL ps, const struct wined3d_state *state)
|
|
|
|
{
|
2014-12-03 10:28:11 +01:00
|
|
|
const struct wined3d_shader_resource_info *vs_resource_info =
|
|
|
|
state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.resource_info;
|
|
|
|
const struct wined3d_shader_resource_info *ps_resource_info = NULL;
|
2013-09-16 12:43:18 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
int start = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers) - 1;
|
|
|
|
int i;
|
|
|
|
|
2015-11-12 23:06:41 +01:00
|
|
|
if (gl_info->limits.combined_samplers >= MAX_COMBINED_SAMPLERS)
|
|
|
|
return;
|
|
|
|
|
2014-12-03 10:28:09 +01:00
|
|
|
/* Note that we only care if a resource is used or not, not the
|
|
|
|
* resource's specific type. Otherwise we'd need to call
|
|
|
|
* shader_update_samplers() here for 1.x pixelshaders. */
|
2013-09-16 12:43:18 +02:00
|
|
|
if (ps)
|
2014-12-03 10:28:11 +01:00
|
|
|
ps_resource_info = state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.resource_info;
|
2013-09-16 12:43:18 +02:00
|
|
|
|
2014-12-03 10:28:09 +01:00
|
|
|
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i)
|
|
|
|
{
|
2013-09-16 12:43:18 +02:00
|
|
|
DWORD vsampler_idx = i + MAX_FRAGMENT_SAMPLERS;
|
2014-12-03 10:28:11 +01:00
|
|
|
if (vs_resource_info[i].type)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
|
|
|
while (start >= 0)
|
|
|
|
{
|
2015-11-12 23:06:42 +01:00
|
|
|
if (context_unit_free_for_vs(context, ps_resource_info, start))
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2015-11-12 23:06:42 +01:00
|
|
|
if (context->tex_unit_map[vsampler_idx] != start)
|
|
|
|
{
|
|
|
|
context_map_stage(context, vsampler_idx, start);
|
|
|
|
context_invalidate_state(context, STATE_SAMPLER(vsampler_idx));
|
|
|
|
}
|
2013-09-16 12:43:18 +02:00
|
|
|
|
|
|
|
--start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
--start;
|
|
|
|
}
|
2015-11-12 23:06:42 +01:00
|
|
|
if (context->tex_unit_map[vsampler_idx] == WINED3D_UNMAPPED_STAGE)
|
|
|
|
WARN("Couldn't find a free texture unit for vertex sampler %u.\n", i);
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void context_update_tex_unit_map(struct wined3d_context *context, const struct wined3d_state *state)
|
|
|
|
{
|
|
|
|
BOOL vs = use_vs(state);
|
|
|
|
BOOL ps = use_ps(state);
|
2015-11-12 23:06:42 +01:00
|
|
|
|
|
|
|
/* Try to go for a 1:1 mapping of the samplers when possible. Pixel shaders
|
|
|
|
* need a 1:1 map at the moment.
|
|
|
|
* When the mapping of a stage is changed, sampler and ALL texture stage
|
|
|
|
* states have to be reset. */
|
|
|
|
|
2013-09-16 12:43:18 +02:00
|
|
|
if (ps)
|
|
|
|
context_map_psamplers(context, state);
|
|
|
|
else
|
|
|
|
context_map_fixed_function_samplers(context, state);
|
|
|
|
|
|
|
|
if (vs)
|
|
|
|
context_map_vsamplers(context, ps, state);
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-14 01:02:48 +02:00
|
|
|
void context_state_drawbuf(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
|
2011-07-02 11:24:37 +02:00
|
|
|
{
|
2012-03-28 13:52:11 +02:00
|
|
|
DWORD rt_mask, *cur_mask;
|
2011-07-02 11:24:37 +02:00
|
|
|
|
|
|
|
if (isStateDirty(context, STATE_FRAMEBUFFER)) return;
|
|
|
|
|
2012-03-28 13:52:11 +02:00
|
|
|
cur_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask;
|
2016-02-29 18:19:30 +01:00
|
|
|
rt_mask = find_draw_buffers_mask(context, state);
|
2012-03-28 13:52:11 +02:00
|
|
|
if (rt_mask != *cur_mask)
|
2011-04-08 20:22:52 +02:00
|
|
|
{
|
2011-07-02 11:24:37 +02:00
|
|
|
context_apply_draw_buffers(context, rt_mask);
|
2012-03-28 13:52:11 +02:00
|
|
|
*cur_mask = rt_mask;
|
2011-04-08 20:22:52 +02:00
|
|
|
}
|
2011-07-02 11:24:37 +02:00
|
|
|
}
|
2011-04-08 20:22:52 +02:00
|
|
|
|
2013-09-12 12:23:29 +02:00
|
|
|
static BOOL fixed_get_input(BYTE usage, BYTE usage_idx, unsigned int *regnum)
|
|
|
|
{
|
|
|
|
if ((usage == WINED3D_DECL_USAGE_POSITION || usage == WINED3D_DECL_USAGE_POSITIONT) && !usage_idx)
|
|
|
|
*regnum = WINED3D_FFP_POSITION;
|
|
|
|
else if (usage == WINED3D_DECL_USAGE_BLEND_WEIGHT && !usage_idx)
|
|
|
|
*regnum = WINED3D_FFP_BLENDWEIGHT;
|
|
|
|
else if (usage == WINED3D_DECL_USAGE_BLEND_INDICES && !usage_idx)
|
|
|
|
*regnum = WINED3D_FFP_BLENDINDICES;
|
|
|
|
else if (usage == WINED3D_DECL_USAGE_NORMAL && !usage_idx)
|
|
|
|
*regnum = WINED3D_FFP_NORMAL;
|
|
|
|
else if (usage == WINED3D_DECL_USAGE_PSIZE && !usage_idx)
|
|
|
|
*regnum = WINED3D_FFP_PSIZE;
|
|
|
|
else if (usage == WINED3D_DECL_USAGE_COLOR && !usage_idx)
|
|
|
|
*regnum = WINED3D_FFP_DIFFUSE;
|
|
|
|
else if (usage == WINED3D_DECL_USAGE_COLOR && usage_idx == 1)
|
|
|
|
*regnum = WINED3D_FFP_SPECULAR;
|
|
|
|
else if (usage == WINED3D_DECL_USAGE_TEXCOORD && usage_idx < WINED3DDP_MAXTEXCOORD)
|
|
|
|
*regnum = WINED3D_FFP_TEXCOORD0 + usage_idx;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Unsupported input stream [usage=%s, usage_idx=%u].\n", debug_d3ddeclusage(usage), usage_idx);
|
|
|
|
*regnum = ~0U;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
void context_stream_info_from_declaration(struct wined3d_context *context,
|
|
|
|
const struct wined3d_state *state, struct wined3d_stream_info *stream_info)
|
|
|
|
{
|
|
|
|
/* We need to deal with frequency data! */
|
|
|
|
struct wined3d_vertex_declaration *declaration = state->vertex_declaration;
|
2015-06-16 22:45:37 +02:00
|
|
|
BOOL generic_attributes = context->d3d_info->ffp_generic_attributes;
|
2016-05-24 10:17:49 +02:00
|
|
|
BOOL use_vshader = use_vs(state);
|
2013-09-12 12:23:29 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
stream_info->use_map = 0;
|
|
|
|
stream_info->swizzle_map = 0;
|
2016-05-24 10:17:49 +02:00
|
|
|
stream_info->position_transformed = 0;
|
|
|
|
|
|
|
|
if (!declaration)
|
|
|
|
return;
|
|
|
|
|
2013-09-12 12:23:29 +02:00
|
|
|
stream_info->position_transformed = declaration->position_transformed;
|
|
|
|
|
|
|
|
/* Translate the declaration into strided data. */
|
|
|
|
for (i = 0; i < declaration->element_count; ++i)
|
|
|
|
{
|
|
|
|
const struct wined3d_vertex_declaration_element *element = &declaration->elements[i];
|
|
|
|
const struct wined3d_stream_state *stream = &state->streams[element->input_slot];
|
|
|
|
BOOL stride_used;
|
|
|
|
unsigned int idx;
|
|
|
|
|
|
|
|
TRACE("%p Element %p (%u of %u).\n", declaration->elements,
|
|
|
|
element, i + 1, declaration->element_count);
|
|
|
|
|
2014-07-14 10:04:22 +02:00
|
|
|
if (!stream->buffer)
|
|
|
|
continue;
|
2013-09-12 12:23:29 +02:00
|
|
|
|
|
|
|
TRACE("offset %u input_slot %u usage_idx %d.\n", element->offset, element->input_slot, element->usage_idx);
|
|
|
|
|
|
|
|
if (use_vshader)
|
|
|
|
{
|
2015-03-23 09:17:16 +01:00
|
|
|
if (element->output_slot == WINED3D_OUTPUT_SLOT_UNUSED)
|
|
|
|
{
|
|
|
|
stride_used = FALSE;
|
|
|
|
}
|
|
|
|
else if (element->output_slot == WINED3D_OUTPUT_SLOT_SEMANTIC)
|
2013-09-12 12:23:29 +02:00
|
|
|
{
|
|
|
|
/* TODO: Assuming vertexdeclarations are usually used with the
|
|
|
|
* same or a similar shader, it might be worth it to store the
|
|
|
|
* last used output slot and try that one first. */
|
2013-10-09 22:57:45 +02:00
|
|
|
stride_used = vshader_get_input(state->shader[WINED3D_SHADER_TYPE_VERTEX],
|
2013-09-12 12:23:29 +02:00
|
|
|
element->usage, element->usage_idx, &idx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = element->output_slot;
|
|
|
|
stride_used = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-16 22:45:37 +02:00
|
|
|
if (!generic_attributes && !element->ffp_valid)
|
2013-09-12 12:23:29 +02:00
|
|
|
{
|
|
|
|
WARN("Skipping unsupported fixed function element of format %s and usage %s.\n",
|
|
|
|
debug_d3dformat(element->format->id), debug_d3ddeclusage(element->usage));
|
|
|
|
stride_used = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stride_used = fixed_get_input(element->usage, element->usage_idx, &idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stride_used)
|
|
|
|
{
|
|
|
|
TRACE("Load %s array %u [usage %s, usage_idx %u, "
|
2015-03-24 09:38:23 +01:00
|
|
|
"input_slot %u, offset %u, stride %u, format %s, class %s, step_rate %u].\n",
|
2013-09-12 12:23:29 +02:00
|
|
|
use_vshader ? "shader": "fixed function", idx,
|
|
|
|
debug_d3ddeclusage(element->usage), element->usage_idx, element->input_slot,
|
2015-03-24 09:38:23 +01:00
|
|
|
element->offset, stream->stride, debug_d3dformat(element->format->id),
|
|
|
|
debug_d3dinput_classification(element->input_slot_class), element->instance_data_step_rate);
|
2013-09-12 12:23:29 +02:00
|
|
|
|
|
|
|
stream_info->elements[idx].format = element->format;
|
2014-07-14 10:04:22 +02:00
|
|
|
stream_info->elements[idx].data.buffer_object = 0;
|
2014-07-22 08:44:24 +02:00
|
|
|
stream_info->elements[idx].data.addr = (BYTE *)NULL + stream->offset + element->offset;
|
2014-07-14 10:04:22 +02:00
|
|
|
stream_info->elements[idx].stride = stream->stride;
|
2013-09-12 12:23:29 +02:00
|
|
|
stream_info->elements[idx].stream_idx = element->input_slot;
|
2015-03-24 09:38:23 +01:00
|
|
|
if (stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
|
|
|
|
{
|
|
|
|
stream_info->elements[idx].divisor = 1;
|
|
|
|
}
|
|
|
|
else if (element->input_slot_class == WINED3D_INPUT_PER_INSTANCE_DATA)
|
|
|
|
{
|
|
|
|
stream_info->elements[idx].divisor = element->instance_data_step_rate;
|
|
|
|
if (!element->instance_data_step_rate)
|
|
|
|
FIXME("Instance step rate 0 not implemented.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stream_info->elements[idx].divisor = 0;
|
|
|
|
}
|
2013-09-12 12:23:29 +02:00
|
|
|
|
|
|
|
if (!context->gl_info->supported[ARB_VERTEX_ARRAY_BGRA]
|
|
|
|
&& element->format->id == WINED3DFMT_B8G8R8A8_UNORM)
|
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
stream_info->swizzle_map |= 1u << idx;
|
2013-09-12 12:23:29 +02:00
|
|
|
}
|
2015-08-26 12:46:47 +02:00
|
|
|
stream_info->use_map |= 1u << idx;
|
2013-09-12 12:23:29 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-14 10:04:22 +02:00
|
|
|
}
|
2013-09-12 12:23:29 +02:00
|
|
|
|
2014-07-14 10:04:22 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void context_update_stream_info(struct wined3d_context *context, const struct wined3d_state *state)
|
|
|
|
{
|
|
|
|
struct wined3d_stream_info *stream_info = &context->stream_info;
|
2016-05-24 10:17:49 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2014-07-14 10:04:22 +02:00
|
|
|
DWORD prev_all_vbo = stream_info->all_vbo;
|
|
|
|
unsigned int i;
|
|
|
|
WORD map;
|
|
|
|
|
|
|
|
context_stream_info_from_declaration(context, state, stream_info);
|
|
|
|
|
|
|
|
stream_info->all_vbo = 1;
|
2013-09-12 12:23:29 +02:00
|
|
|
context->num_buffer_queries = 0;
|
|
|
|
for (i = 0, map = stream_info->use_map; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_stream_info_element *element;
|
2014-07-14 10:04:22 +02:00
|
|
|
struct wined3d_bo_address data;
|
2013-09-12 12:23:29 +02:00
|
|
|
struct wined3d_buffer *buffer;
|
|
|
|
|
|
|
|
if (!(map & 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
element = &stream_info->elements[i];
|
|
|
|
buffer = state->streams[element->stream_idx].buffer;
|
|
|
|
|
2014-07-14 10:04:22 +02:00
|
|
|
/* We can't use VBOs if the base vertex index is negative. OpenGL
|
|
|
|
* doesn't accept negative offsets (or rather offsets bigger than the
|
|
|
|
* VBO, because the pointer is unsigned), so use system memory
|
|
|
|
* sources. In most sane cases the pointer - offset will still be > 0,
|
|
|
|
* otherwise it will wrap around to some big value. Hope that with the
|
|
|
|
* indices the driver wraps it back internally. If not,
|
2016-04-06 19:12:05 +02:00
|
|
|
* draw_primitive_immediate_mode() is needed, including a vertex buffer
|
|
|
|
* path. */
|
2014-07-14 10:04:22 +02:00
|
|
|
if (state->load_base_vertex_index < 0)
|
2013-09-12 12:23:29 +02:00
|
|
|
{
|
2014-07-14 10:04:22 +02:00
|
|
|
WARN_(d3d_perf)("load_base_vertex_index is < 0 (%d), not using VBOs.\n",
|
|
|
|
state->load_base_vertex_index);
|
2013-09-12 12:23:29 +02:00
|
|
|
element->data.buffer_object = 0;
|
2014-07-14 10:04:22 +02:00
|
|
|
element->data.addr += (ULONG_PTR)buffer_get_sysmem(buffer, context);
|
|
|
|
if ((UINT_PTR)element->data.addr < -state->load_base_vertex_index * element->stride)
|
|
|
|
FIXME("System memory vertex data load offset is negative!\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer_internal_preload(buffer, context, state);
|
|
|
|
buffer_get_memory(buffer, context, &data);
|
|
|
|
element->data.buffer_object = data.buffer_object;
|
|
|
|
element->data.addr += (ULONG_PTR)data.addr;
|
2013-09-12 12:23:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-14 10:04:22 +02:00
|
|
|
if (!element->data.buffer_object)
|
2013-09-12 12:23:29 +02:00
|
|
|
stream_info->all_vbo = 0;
|
|
|
|
|
|
|
|
if (buffer->query)
|
|
|
|
context->buffer_queries[context->num_buffer_queries++] = buffer->query;
|
|
|
|
|
2014-07-14 10:04:22 +02:00
|
|
|
TRACE("Load array %u {%#x:%p}.\n", i, element->data.buffer_object, element->data.addr);
|
|
|
|
}
|
2013-09-12 12:23:29 +02:00
|
|
|
|
2016-05-24 10:17:49 +02:00
|
|
|
if (prev_all_vbo != stream_info->all_vbo)
|
|
|
|
context_invalidate_state(context, STATE_INDEXBUFFER);
|
|
|
|
|
|
|
|
context->use_immediate_mode_draw = FALSE;
|
|
|
|
|
|
|
|
if (stream_info->all_vbo)
|
|
|
|
return;
|
|
|
|
|
2013-10-09 22:57:45 +02:00
|
|
|
if (use_vs(state))
|
2013-09-12 12:23:29 +02:00
|
|
|
{
|
2016-05-24 10:17:49 +02:00
|
|
|
if (state->vertex_declaration->half_float_conv_needed)
|
2013-09-12 12:23:29 +02:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
TRACE("Using immediate mode draw with vertex shaders for FLOAT16 conversion.\n");
|
2013-09-12 12:23:29 +02:00
|
|
|
context->use_immediate_mode_draw = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
WORD slow_mask = -!d3d_info->ffp_generic_attributes & (1u << WINED3D_FFP_PSIZE);
|
2016-07-30 19:56:55 +02:00
|
|
|
slow_mask |= -(!gl_info->supported[ARB_VERTEX_ARRAY_BGRA] && !d3d_info->ffp_generic_attributes)
|
2016-07-29 21:01:49 +02:00
|
|
|
& ((1u << WINED3D_FFP_DIFFUSE) | (1u << WINED3D_FFP_SPECULAR) | (1u << WINED3D_FFP_BLENDWEIGHT));
|
2013-09-12 12:23:29 +02:00
|
|
|
|
2016-05-24 10:17:49 +02:00
|
|
|
if ((stream_info->position_transformed && !d3d_info->xyzrhw)
|
|
|
|
|| (stream_info->use_map & slow_mask))
|
2013-09-12 12:23:29 +02:00
|
|
|
context->use_immediate_mode_draw = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-16 12:43:19 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void context_preload_texture(struct wined3d_context *context,
|
|
|
|
const struct wined3d_state *state, unsigned int idx)
|
|
|
|
{
|
|
|
|
struct wined3d_texture *texture;
|
|
|
|
|
|
|
|
if (!(texture = state->textures[idx]))
|
|
|
|
return;
|
|
|
|
|
2013-11-22 10:45:04 +01:00
|
|
|
wined3d_texture_load(texture, context, state->sampler_states[idx][WINED3D_SAMP_SRGB_TEXTURE]);
|
2013-09-16 12:43:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void context_preload_textures(struct wined3d_context *context, const struct wined3d_state *state)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (use_vs(state))
|
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i)
|
|
|
|
{
|
2014-12-03 10:28:11 +01:00
|
|
|
if (state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.resource_info[i].type)
|
2013-09-16 12:43:19 +02:00
|
|
|
context_preload_texture(context, state, MAX_FRAGMENT_SAMPLERS + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_ps(state))
|
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
|
|
|
|
{
|
2014-12-03 10:28:11 +01:00
|
|
|
if (state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.resource_info[i].type)
|
2013-09-16 12:43:19 +02:00
|
|
|
context_preload_texture(context, state, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WORD ffu_map = context->fixed_function_usage_map;
|
|
|
|
|
|
|
|
for (i = 0; ffu_map; ffu_map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (ffu_map & 1)
|
|
|
|
context_preload_texture(context, state, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 11:24:10 +02:00
|
|
|
static void context_load_shader_resources(struct wined3d_context *context, const struct wined3d_state *state)
|
|
|
|
{
|
|
|
|
struct wined3d_shader_sampler_map_entry *entry;
|
|
|
|
struct wined3d_shader_resource_view *view;
|
|
|
|
struct wined3d_shader *shader;
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
|
|
|
|
{
|
|
|
|
if (!(shader = state->shader[i]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < WINED3D_MAX_CBS; ++j)
|
|
|
|
{
|
|
|
|
if (state->cb[i][j])
|
|
|
|
buffer_internal_preload(state->cb[i][j], context, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < shader->reg_maps.sampler_map.count; ++j)
|
|
|
|
{
|
|
|
|
entry = &shader->reg_maps.sampler_map.entries[j];
|
|
|
|
|
|
|
|
if (!(view = state->shader_resource_view[i][entry->resource_idx]))
|
|
|
|
{
|
|
|
|
WARN("No resource view bound at index %u, %u.\n", i, entry->resource_idx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view->resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
buffer_internal_preload(buffer_from_resource(view->resource), context, state);
|
|
|
|
else
|
2016-04-20 19:29:13 +02:00
|
|
|
wined3d_texture_load(texture_from_resource(view->resource), context, FALSE);
|
2015-08-18 11:24:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-19 13:44:08 +01:00
|
|
|
static void context_bind_shader_resources(struct wined3d_context *context, const struct wined3d_state *state)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2016-10-05 11:17:03 +02:00
|
|
|
const struct wined3d_device *device = context->device;
|
2015-01-19 13:44:08 +01:00
|
|
|
struct wined3d_shader_sampler_map_entry *entry;
|
|
|
|
struct wined3d_shader_resource_view *view;
|
|
|
|
struct wined3d_sampler *sampler;
|
|
|
|
struct wined3d_shader *shader;
|
|
|
|
unsigned int i, j, count;
|
2016-01-05 21:52:31 +01:00
|
|
|
GLuint sampler_name;
|
2015-01-19 13:44:08 +01:00
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
enum wined3d_shader_type type;
|
|
|
|
unsigned int base_idx;
|
|
|
|
unsigned int count;
|
|
|
|
}
|
|
|
|
shader_types[] =
|
|
|
|
{
|
|
|
|
{WINED3D_SHADER_TYPE_PIXEL, 0, MAX_FRAGMENT_SAMPLERS},
|
|
|
|
{WINED3D_SHADER_TYPE_VERTEX, MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(shader_types); ++i)
|
|
|
|
{
|
|
|
|
if (!(shader = state->shader[shader_types[i].type]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
count = shader->reg_maps.sampler_map.count;
|
|
|
|
if (count > shader_types[i].count)
|
|
|
|
{
|
|
|
|
FIXME("Shader %p needs %u samplers, but only %u are supported.\n",
|
|
|
|
shader, count, shader_types[i].count);
|
|
|
|
count = shader_types[i].count;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < count; ++j)
|
|
|
|
{
|
|
|
|
entry = &shader->reg_maps.sampler_map.entries[j];
|
|
|
|
|
|
|
|
if (!(view = state->shader_resource_view[shader_types[i].type][entry->resource_idx]))
|
|
|
|
{
|
|
|
|
WARN("No resource view bound at index %u, %u.\n", shader_types[i].type, entry->resource_idx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-05 21:52:31 +01:00
|
|
|
if (entry->sampler_idx == WINED3D_SAMPLER_DEFAULT)
|
|
|
|
sampler_name = device->default_sampler;
|
|
|
|
else if ((sampler = state->sampler[shader_types[i].type][entry->sampler_idx]))
|
|
|
|
sampler_name = sampler->name;
|
|
|
|
else
|
2016-06-02 11:14:12 +02:00
|
|
|
sampler_name = device->null_sampler;
|
2015-01-19 13:44:08 +01:00
|
|
|
|
|
|
|
context_active_texture(context, gl_info, shader_types[i].base_idx + entry->bind_idx);
|
2016-01-05 21:52:31 +01:00
|
|
|
GL_EXTCALL(glBindSampler(shader_types[i].base_idx + entry->bind_idx, sampler_name));
|
2015-01-19 13:44:08 +01:00
|
|
|
checkGLcall("glBindSampler");
|
2016-06-07 13:24:39 +02:00
|
|
|
wined3d_shader_resource_view_bind(view, context);
|
2015-01-19 13:44:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 11:24:37 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2016-04-14 19:32:50 +02:00
|
|
|
BOOL context_apply_draw_state(struct wined3d_context *context,
|
|
|
|
const struct wined3d_device *device, const struct wined3d_state *state)
|
2011-07-02 11:24:37 +02:00
|
|
|
{
|
2011-07-24 21:48:11 +02:00
|
|
|
const struct StateEntry *state_table = context->state_table;
|
2011-07-14 01:02:48 +02:00
|
|
|
const struct wined3d_fb_state *fb = state->fb;
|
2015-08-18 11:24:10 +02:00
|
|
|
unsigned int i;
|
2014-07-14 10:04:21 +02:00
|
|
|
WORD map;
|
2011-07-02 11:24:37 +02:00
|
|
|
|
|
|
|
if (!context_validate_rt_config(context->gl_info->limits.buffers,
|
|
|
|
fb->render_targets, fb->depth_stencil))
|
|
|
|
return FALSE;
|
|
|
|
|
2011-07-27 23:22:49 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && isStateDirty(context, STATE_FRAMEBUFFER))
|
|
|
|
{
|
|
|
|
context_validate_onscreen_formats(context, fb->depth_stencil);
|
|
|
|
}
|
|
|
|
|
2011-07-02 11:24:37 +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. */
|
2013-09-16 12:43:18 +02:00
|
|
|
context_update_tex_unit_map(context, state);
|
2013-09-16 12:43:19 +02:00
|
|
|
context_preload_textures(context, state);
|
2015-08-18 11:24:10 +02:00
|
|
|
context_load_shader_resources(context, state);
|
2015-03-17 15:52:13 +01:00
|
|
|
/* TODO: Right now the dependency on the vertex shader is necessary
|
|
|
|
* since context_stream_info_from_declaration depends on the reg_maps of
|
|
|
|
* the current VS but maybe it's possible to relax the coupling in some
|
|
|
|
* situations at least. */
|
|
|
|
if (isStateDirty(context, STATE_VDECL) || isStateDirty(context, STATE_STREAMSRC)
|
|
|
|
|| isStateDirty(context, STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX)))
|
2014-07-14 10:04:21 +02:00
|
|
|
{
|
2013-09-12 12:23:29 +02:00
|
|
|
context_update_stream_info(context, state);
|
2014-07-14 10:04:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0, map = context->stream_info.use_map; map; map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (map & 1)
|
|
|
|
buffer_mark_used(state->streams[context->stream_info.elements[i].stream_idx].buffer);
|
|
|
|
}
|
|
|
|
}
|
2013-01-24 00:39:13 +01:00
|
|
|
if (state->index_buffer)
|
2012-05-28 18:17:25 +02:00
|
|
|
{
|
2013-09-12 12:23:29 +02:00
|
|
|
if (context->stream_info.all_vbo)
|
2013-09-12 12:23:30 +02:00
|
|
|
buffer_internal_preload(state->index_buffer, context, state);
|
2012-05-28 18:17:25 +02:00
|
|
|
else
|
2013-09-09 15:15:36 +02:00
|
|
|
buffer_get_sysmem(state->index_buffer, context);
|
2012-05-28 18:17:25 +02:00
|
|
|
}
|
2011-07-02 11:24:37 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
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);
|
2015-08-26 12:46:47 +02:00
|
|
|
context->isStateDirty[idx] &= ~(1u << shift);
|
2011-07-14 01:02:48 +02:00
|
|
|
state_table[rep].apply(context, state, rep);
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
2011-07-02 11:24:37 +02:00
|
|
|
|
2013-08-21 08:29:27 +02:00
|
|
|
if (context->shader_update_mask)
|
2012-11-04 19:51:32 +01:00
|
|
|
{
|
2013-05-14 17:38:19 +02:00
|
|
|
device->shader_backend->shader_select(device->shader_priv, context, state);
|
2013-08-21 08:29:27 +02:00
|
|
|
context->shader_update_mask = 0;
|
2012-11-04 19:51:32 +01:00
|
|
|
}
|
|
|
|
|
2013-08-16 09:12:30 +02:00
|
|
|
if (context->constant_update_mask)
|
2012-11-04 19:51:32 +01:00
|
|
|
{
|
2013-08-16 09:12:30 +02:00
|
|
|
device->shader_backend->shader_load_constants(device->shader_priv, context, state);
|
|
|
|
context->constant_update_mask = 0;
|
2012-11-04 19:51:32 +01:00
|
|
|
}
|
|
|
|
|
2015-01-19 13:44:08 +01:00
|
|
|
if (context->update_shader_resource_bindings)
|
|
|
|
{
|
|
|
|
context_bind_shader_resources(context, state);
|
|
|
|
context->update_shader_resource_bindings = 0;
|
|
|
|
}
|
|
|
|
|
2011-07-02 11:24:37 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
|
|
|
context_check_fbo_status(context, GL_FRAMEBUFFER);
|
|
|
|
}
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
context->numDirtyEntries = 0; /* This makes the whole list clean */
|
|
|
|
context->last_was_blit = FALSE;
|
2011-01-26 19:45:02 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2009-12-27 19:57:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
static void context_setup_target(struct wined3d_context *context,
|
|
|
|
struct wined3d_texture *texture, unsigned int sub_resource_idx)
|
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
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
render_offscreen = wined3d_resource_is_offscreen(&texture->resource);
|
|
|
|
if (context->current_rt.texture == texture
|
|
|
|
&& context->current_rt.sub_resource_idx == sub_resource_idx
|
|
|
|
&& 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. */
|
2016-03-29 16:45:32 +02:00
|
|
|
if (!context->current_rt.texture)
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE));
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
const struct wined3d_format *old = context->current_rt.texture->resource.format;
|
|
|
|
const struct wined3d_format *new = texture->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. */
|
2012-08-15 00:38:25 +02:00
|
|
|
if ((old->alpha_size && !new->alpha_size) || (!old->alpha_size && new->alpha_size)
|
2016-03-29 16:45:32 +02:00
|
|
|
|| !(texture->resource.format_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE));
|
2011-06-05 22:48:52 +02:00
|
|
|
|
2010-07-02 22:21:02 +02:00
|
|
|
/* Update sRGB writing when switching between formats that do/do not support sRGB writing */
|
2016-03-29 16:45:32 +02:00
|
|
|
if ((context->current_rt.texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE)
|
|
|
|
!= (texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE))
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE));
|
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
|
2014-01-17 13:27:16 +01:00
|
|
|
* done via PreLoad (and WINED3D_LOCATION_DRAWABLE set on the surface).
|
|
|
|
* There are some things that need care though. PreLoad needs a GL context,
|
2010-03-27 17:40:28 +01:00
|
|
|
* 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
|
2016-03-29 16:45:32 +02:00
|
|
|
&& old_render_offscreen && (context->current_rt.texture != texture
|
|
|
|
|| context->current_rt.sub_resource_idx != sub_resource_idx))
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
unsigned int prev_sub_resource_idx = context->current_rt.sub_resource_idx;
|
|
|
|
struct wined3d_texture *prev_texture = context->current_rt.texture;
|
2013-11-22 10:45:03 +01:00
|
|
|
|
2010-03-27 17:40:28 +01:00
|
|
|
/* Read the back buffer of the old drawable into the destination texture. */
|
2016-03-29 16:45:32 +02:00
|
|
|
if (prev_texture->texture_srgb.name)
|
|
|
|
wined3d_texture_load(prev_texture, context, TRUE);
|
|
|
|
wined3d_texture_load(prev_texture, context, FALSE);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(prev_texture, prev_sub_resource_idx, WINED3D_LOCATION_DRAWABLE);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
context->current_rt.texture = texture;
|
|
|
|
context->current_rt.sub_resource_idx = sub_resource_idx;
|
2011-07-26 19:52:44 +02:00
|
|
|
context_set_render_offscreen(context, render_offscreen);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
|
2011-10-25 21:20:29 +02:00
|
|
|
struct wined3d_context *context_acquire(const struct wined3d_device *device, struct wined3d_surface *target)
|
2009-12-27 19:57:21 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *current_context = context_get_current();
|
2016-10-05 11:17:04 +02:00
|
|
|
struct wined3d_swapchain *swapchain = NULL;
|
2016-03-29 16:45:32 +02:00
|
|
|
struct wined3d_texture *target_texture;
|
|
|
|
unsigned int target_sub_resource_idx;
|
2009-12-27 19:57:21 +01:00
|
|
|
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
|
|
|
|
2011-08-21 21:34:53 +02:00
|
|
|
if (current_context && current_context->destroyed)
|
|
|
|
current_context = NULL;
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
target_texture = target->container;
|
|
|
|
target_sub_resource_idx = surface_get_sub_resource_idx(target);
|
|
|
|
}
|
|
|
|
else
|
2011-08-21 21:34:53 +02:00
|
|
|
{
|
|
|
|
if (current_context
|
2016-03-29 16:45:32 +02:00
|
|
|
&& current_context->current_rt.texture
|
2016-10-05 11:17:03 +02:00
|
|
|
&& current_context->device == device)
|
2011-08-21 21:34:53 +02:00
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
target_texture = current_context->current_rt.texture;
|
|
|
|
target_sub_resource_idx = current_context->current_rt.sub_resource_idx;
|
2011-08-21 21:34:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct wined3d_swapchain *swapchain = device->swapchains[0];
|
2016-03-29 16:45:32 +02:00
|
|
|
|
2011-08-21 21:34:53 +02:00
|
|
|
if (swapchain->back_buffers)
|
2016-03-29 16:45:32 +02:00
|
|
|
target_texture = swapchain->back_buffers[0];
|
2011-08-21 21:34:53 +02:00
|
|
|
else
|
2016-03-29 16:45:32 +02:00
|
|
|
target_texture = swapchain->front_buffer;
|
|
|
|
target_sub_resource_idx = 0;
|
2011-08-21 21:34:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
if (current_context && current_context->current_rt.texture == target_texture)
|
2011-08-21 21:34:53 +02:00
|
|
|
{
|
|
|
|
context = current_context;
|
|
|
|
}
|
2016-10-05 11:17:04 +02:00
|
|
|
else if ((swapchain = target_texture->swapchain))
|
2011-08-21 21:34:53 +02:00
|
|
|
{
|
|
|
|
TRACE("Rendering onscreen.\n");
|
|
|
|
|
2016-10-05 11:17:04 +02:00
|
|
|
context = swapchain_get_context(swapchain);
|
2011-08-21 21:34:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Rendering offscreen.\n");
|
|
|
|
|
|
|
|
/* Stay with the current context if possible. Otherwise use the
|
|
|
|
* context for the primary swapchain. */
|
2016-10-05 11:17:03 +02:00
|
|
|
if (current_context && current_context->device == device)
|
2016-10-05 11:17:04 +02:00
|
|
|
{
|
2011-08-21 21:34:53 +02:00
|
|
|
context = current_context;
|
2016-10-05 11:17:04 +02:00
|
|
|
}
|
2011-08-21 21:34:53 +02:00
|
|
|
else
|
2016-10-05 11:17:04 +02:00
|
|
|
{
|
|
|
|
swapchain = device->swapchains[0];
|
|
|
|
context = swapchain_get_context(swapchain);
|
|
|
|
}
|
2011-08-21 21:34:53 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 23:13:29 +01:00
|
|
|
context_enter(context);
|
2016-10-05 11:17:04 +02:00
|
|
|
if (swapchain)
|
|
|
|
context_update_window(context, swapchain->win_handle);
|
2016-03-29 16:45:32 +02:00
|
|
|
context_setup_target(context, target_texture, target_sub_resource_idx);
|
2009-12-27 19:57:21 +01:00
|
|
|
if (!context->valid) return context;
|
|
|
|
|
|
|
|
if (context != current_context)
|
|
|
|
{
|
2011-05-24 23:36:16 +02:00
|
|
|
if (!context_set_current(context))
|
|
|
|
ERR("Failed to activate the new context.\n");
|
2009-12-27 19:57:21 +01:00
|
|
|
}
|
2014-02-19 23:14:04 +01:00
|
|
|
else if (context->needs_set)
|
2009-12-27 19:57:21 +01:00
|
|
|
{
|
2011-04-12 22:26:21 +02:00
|
|
|
context_set_gl_context(context);
|
2009-12-27 19:57:21 +01:00
|
|
|
}
|
|
|
|
|
2009-07-23 10:54:36 +02:00
|
|
|
return context;
|
2007-02-12 19:18:36 +01:00
|
|
|
}
|