2007-02-12 19:18:36 +01:00
|
|
|
/*
|
|
|
|
* Context and render target management in wined3d
|
|
|
|
*
|
2018-02-25 23:23:31 +01:00
|
|
|
* Copyright 2002-2004 Jason Edmeades
|
|
|
|
* Copyright 2002-2004 Raphael Junqueira
|
|
|
|
* Copyright 2004 Christian Costa
|
|
|
|
* Copyright 2005 Oliver Stieber
|
|
|
|
* Copyright 2006, 2008 Henri Verbeet
|
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
|
2017-04-10 12:27:42 +02:00
|
|
|
#define WINED3D_ALL_LAYERS (~0u)
|
2013-08-30 08:42:45 +02:00
|
|
|
|
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. */
|
2019-05-15 15:32:58 +02:00
|
|
|
static void wined3d_context_gl_bind_fbo(struct wined3d_context_gl *context_gl, GLenum target, GLuint fbo)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->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:
|
2019-05-19 16:00:43 +02:00
|
|
|
if (context_gl->fbo_read_binding == fbo)
|
2019-05-15 15:32:58 +02:00
|
|
|
return;
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->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:
|
2019-05-19 16:00:43 +02:00
|
|
|
if (context_gl->fbo_draw_binding == fbo)
|
2019-05-15 15:32:58 +02:00
|
|
|
return;
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->fbo_draw_binding = fbo;
|
2009-07-17 10:34:05 +02:00
|
|
|
break;
|
|
|
|
|
2009-09-23 10:05:55 +02:00
|
|
|
case GL_FRAMEBUFFER:
|
2019-05-19 16:00:43 +02:00
|
|
|
if (context_gl->fbo_read_binding == fbo
|
|
|
|
&& context_gl->fbo_draw_binding == fbo)
|
2019-05-15 15:32:58 +02:00
|
|
|
return;
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->fbo_read_binding = fbo;
|
|
|
|
context_gl->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. */
|
2019-05-16 15:04:56 +02:00
|
|
|
static void wined3d_context_gl_destroy_fbo(struct wined3d_context_gl *context_gl, GLuint fbo)
|
2009-05-11 16:43:49 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2009-07-17 10:34:02 +02:00
|
|
|
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, GL_FRAMEBUFFER, fbo);
|
2010-05-19 11:13:35 +02:00
|
|
|
context_clean_fbo_attachments(gl_info, GL_FRAMEBUFFER);
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, 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()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 13:40:37 +02:00
|
|
|
static void wined3d_context_gl_attach_gl_texture_fbo(struct wined3d_context_gl *context_gl,
|
2016-04-20 11:42:17 +02:00
|
|
|
GLenum fbo_target, GLenum attachment, const struct wined3d_fbo_resource *resource)
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2016-04-20 11:42:17 +02:00
|
|
|
|
|
|
|
if (!resource)
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, attachment, GL_TEXTURE_2D, 0, 0);
|
|
|
|
}
|
2017-04-10 12:27:42 +02:00
|
|
|
else if (resource->layer == WINED3D_ALL_LAYERS)
|
2016-04-20 11:42:17 +02:00
|
|
|
{
|
2017-04-10 12:27:42 +02:00
|
|
|
if (!gl_info->fbo_ops.glFramebufferTexture)
|
2016-04-20 11:42:17 +02:00
|
|
|
{
|
2017-04-10 12:27:42 +02:00
|
|
|
FIXME("OpenGL implementation doesn't support glFramebufferTexture().\n");
|
2016-04-20 11:42:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-10 12:27:42 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTexture(fbo_target, attachment,
|
|
|
|
resource->object, resource->level);
|
2017-04-06 11:47:51 +02:00
|
|
|
}
|
2018-04-02 22:58:23 +02:00
|
|
|
else if (resource->target == GL_TEXTURE_1D_ARRAY || resource->target == GL_TEXTURE_2D_ARRAY
|
|
|
|
|| resource->target == GL_TEXTURE_3D)
|
2017-04-06 11:47:51 +02:00
|
|
|
{
|
2017-04-10 12:27:42 +02:00
|
|
|
if (!gl_info->fbo_ops.glFramebufferTextureLayer)
|
2017-04-06 11:47:51 +02:00
|
|
|
{
|
2017-04-10 12:27:42 +02:00
|
|
|
FIXME("OpenGL implementation doesn't support glFramebufferTextureLayer().\n");
|
2017-04-06 11:47:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-10 12:27:42 +02:00
|
|
|
gl_info->fbo_ops.glFramebufferTextureLayer(fbo_target, attachment,
|
|
|
|
resource->object, resource->level, resource->layer);
|
2016-04-20 11:42:17 +02:00
|
|
|
}
|
2018-04-02 22:58:23 +02:00
|
|
|
else if (resource->target == GL_TEXTURE_1D)
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glFramebufferTexture1D(fbo_target, attachment,
|
|
|
|
resource->target, resource->object, resource->level);
|
|
|
|
}
|
2016-04-20 11:42:17 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, attachment,
|
|
|
|
resource->target, resource->object, resource->level);
|
|
|
|
}
|
2017-04-06 11:47:51 +02:00
|
|
|
checkGLcall("attach texture to fbo");
|
2016-04-20 11:42:17 +02:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2019-06-14 13:17:19 +02:00
|
|
|
static void wined3d_context_gl_attach_depth_stencil_fbo(struct wined3d_context_gl *context_gl,
|
2016-02-21 22:29:57 +01:00
|
|
|
GLenum fbo_target, const struct wined3d_fbo_resource *resource, BOOL rb_namespace,
|
2019-06-14 13:17:19 +02:00
|
|
|
uint32_t flags)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->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)
|
2019-06-13 13:40:37 +02:00
|
|
|
wined3d_context_gl_attach_gl_texture_fbo(context_gl, 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)
|
2019-06-13 13:40:37 +02:00
|
|
|
wined3d_context_gl_attach_gl_texture_fbo(context_gl, 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))
|
2019-06-13 13:40:37 +02:00
|
|
|
wined3d_context_gl_attach_gl_texture_fbo(context_gl, 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))
|
2019-06-13 13:40:37 +02:00
|
|
|
wined3d_context_gl_attach_gl_texture_fbo(context_gl, 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");
|
|
|
|
|
2019-06-13 13:40:37 +02:00
|
|
|
wined3d_context_gl_attach_gl_texture_fbo(context_gl, fbo_target, GL_DEPTH_ATTACHMENT, NULL);
|
|
|
|
wined3d_context_gl_attach_gl_texture_fbo(context_gl, 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. */
|
2019-06-14 13:17:20 +02:00
|
|
|
static void wined3d_context_gl_attach_surface_fbo(struct wined3d_context_gl *context_gl,
|
|
|
|
GLenum fbo_target, unsigned int idx, const struct wined3d_fbo_resource *resource, BOOL rb_namespace)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->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
|
|
|
{
|
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
|
|
|
|
{
|
2019-06-13 13:40:37 +02:00
|
|
|
wined3d_context_gl_attach_gl_texture_fbo(context_gl, fbo_target, GL_COLOR_ATTACHMENT0 + idx, resource);
|
2010-07-26 12:06:32 +02:00
|
|
|
}
|
2009-09-23 10:05:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-13 13:40:37 +02:00
|
|
|
wined3d_context_gl_attach_gl_texture_fbo(context_gl, 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[] =
|
|
|
|
{
|
2018-04-02 22:58:23 +02:00
|
|
|
{GL_TEXTURE_1D, GL_TEXTURE_BINDING_1D, "1d", WINED3D_GL_EXT_NONE},
|
|
|
|
{GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BINDING_1D_ARRAY, "1d-array", EXT_TEXTURE_ARRAY},
|
2018-02-09 13:03:21 +01:00
|
|
|
{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},
|
2018-02-20 23:59:45 +01:00
|
|
|
{GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BINDING_CUBE_MAP, "cube", ARB_TEXTURE_CUBE_MAP},
|
2018-02-09 13:03:21 +01:00
|
|
|
{GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BINDING_2D_MULTISAMPLE, "2d-ms", ARB_TEXTURE_MULTISAMPLE},
|
|
|
|
{GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY, "2d-array-ms", ARB_TEXTURE_MULTISAMPLE},
|
2016-04-22 11:18:47 +02:00
|
|
|
};
|
|
|
|
|
2016-02-21 22:29:56 +01:00
|
|
|
GLint type, name, samples, width, height, old_texture, level, face, fmt, tex_target;
|
2018-02-20 23:59:45 +01:00
|
|
|
const char *tex_type_str;
|
|
|
|
unsigned int i;
|
2016-02-21 22:29:56 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2018-02-20 23:59:45 +01:00
|
|
|
if (gl_info->gl_ops.ext.p_glGetTextureParameteriv)
|
2016-02-21 22:29:56 +01:00
|
|
|
{
|
2018-02-20 23:59:45 +01:00
|
|
|
GL_EXTCALL(glGetTextureParameteriv(name, GL_TEXTURE_TARGET, &tex_target));
|
2016-02-21 22:29:56 +01:00
|
|
|
|
2018-02-20 23:59:45 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(texture_type); ++i)
|
|
|
|
{
|
|
|
|
if (texture_type[i].target == tex_target)
|
|
|
|
{
|
|
|
|
tex_type_str = texture_type[i].str;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == ARRAY_SIZE(texture_type))
|
|
|
|
tex_type_str = wine_dbg_sprintf("%#x", tex_target);
|
|
|
|
}
|
|
|
|
else 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);
|
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
|
|
|
tex_type_str = NULL;
|
2018-02-20 23:59:45 +01:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(texture_type); ++i)
|
2016-02-21 22:29:56 +01:00
|
|
|
{
|
2018-02-20 23:59:45 +01:00
|
|
|
if (!gl_info->supported[texture_type[i].extension])
|
|
|
|
continue;
|
2016-02-21 22:29:56 +01:00
|
|
|
|
2018-02-20 23:59:45 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGetIntegerv(texture_type[i].binding, &old_texture);
|
|
|
|
while (gl_info->gl_ops.gl.p_glGetError());
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(texture_type[i].target, name);
|
|
|
|
if (!gl_info->gl_ops.gl.p_glGetError())
|
2016-02-21 22:29:56 +01:00
|
|
|
{
|
2018-02-20 23:59:45 +01:00
|
|
|
tex_target = texture_type[i].target;
|
|
|
|
tex_type_str = texture_type[i].str;
|
|
|
|
break;
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
2018-02-20 23:59:45 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(texture_type[i].target, old_texture);
|
2016-04-22 11:18:47 +02:00
|
|
|
}
|
2018-02-20 23:59:45 +01:00
|
|
|
|
|
|
|
if (!tex_type_str)
|
2016-04-22 11:18:47 +02:00
|
|
|
{
|
2018-02-20 23:59:45 +01:00
|
|
|
FIXME("Cannot find type of texture %d.\n", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-02-21 22:29:56 +01:00
|
|
|
|
2018-02-20 23:59:45 +01:00
|
|
|
if (gl_info->gl_ops.ext.p_glGetTextureParameteriv)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glGetTextureLevelParameteriv(name, level, GL_TEXTURE_INTERNAL_FORMAT, &fmt));
|
|
|
|
GL_EXTCALL(glGetTextureLevelParameteriv(name, level, GL_TEXTURE_WIDTH, &width));
|
|
|
|
GL_EXTCALL(glGetTextureLevelParameteriv(name, level, GL_TEXTURE_HEIGHT, &height));
|
|
|
|
GL_EXTCALL(glGetTextureLevelParameteriv(name, level, GL_TEXTURE_SAMPLES, &samples));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_MULTISAMPLE])
|
|
|
|
gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(tex_target, level, GL_TEXTURE_SAMPLES, &samples);
|
|
|
|
else
|
|
|
|
samples = 1;
|
2018-02-09 13:03:20 +01:00
|
|
|
|
2018-02-20 23:59:45 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(tex_target, old_texture);
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
|
|
|
|
2018-02-09 13:03:21 +01:00
|
|
|
FIXME(" %s: %s texture %d, %dx%d, %d samples, format %#x.\n",
|
|
|
|
debug_fboattachment(attachment), tex_type_str, name, width, height, samples, fmt);
|
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);
|
|
|
|
}
|
2018-02-20 23:59:45 +01:00
|
|
|
|
|
|
|
checkGLcall("dump FBO attachment");
|
2016-02-21 22:29:56 +01:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2019-05-15 15:32:55 +02:00
|
|
|
void wined3d_context_gl_check_fbo_status(const struct wined3d_context_gl *context_gl, GLenum target)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2008-09-18 14:57:53 +02:00
|
|
|
GLenum status;
|
|
|
|
|
2018-02-27 10:17:36 +01:00
|
|
|
if (!FIXME_ON(d3d))
|
|
|
|
return;
|
2011-05-27 16:17:25 +02:00
|
|
|
|
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
|
|
|
{
|
2018-02-27 10:17:36 +01: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
|
|
|
|
2018-02-27 10:17:36 +01:00
|
|
|
FIXME("FBO status %s (%#x).\n", debug_fbostatus(status), status);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
if (!context_gl->current_fbo)
|
2009-10-26 10:12:19 +01:00
|
|
|
{
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
2019-06-14 13:17:21 +02:00
|
|
|
static inline void wined3d_context_gl_set_fbo_key_for_render_target(const struct wined3d_context_gl *context_gl,
|
2018-02-26 07:51:48 +01:00
|
|
|
struct wined3d_fbo_entry_key *key, unsigned int idx, const struct wined3d_rendertarget_info *render_target,
|
2016-02-21 22:29:57 +01:00
|
|
|
DWORD location)
|
|
|
|
{
|
2017-04-06 11:47:51 +02:00
|
|
|
unsigned int sub_resource_idx = render_target->sub_resource_idx;
|
|
|
|
struct wined3d_resource *resource = render_target->resource;
|
2018-10-29 08:17:10 +01:00
|
|
|
struct wined3d_texture_gl *texture_gl;
|
2017-04-06 11:47:51 +02:00
|
|
|
|
|
|
|
if (!resource || resource->format->id == WINED3DFMT_NULL || resource->type == WINED3D_RTYPE_BUFFER)
|
2016-02-21 22:29:57 +01:00
|
|
|
{
|
2017-04-06 11:47:51 +02:00
|
|
|
if (resource && resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(resource->type));
|
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;
|
2017-04-06 11:47:51 +02:00
|
|
|
return;
|
2016-02-21 22:29:57 +01:00
|
|
|
}
|
2017-04-06 11:47:51 +02:00
|
|
|
|
2017-04-10 12:27:42 +02:00
|
|
|
if (render_target->gl_view.name)
|
|
|
|
{
|
|
|
|
key->objects[idx].object = render_target->gl_view.name;
|
|
|
|
key->objects[idx].target = render_target->gl_view.target;
|
|
|
|
key->objects[idx].level = 0;
|
|
|
|
key->objects[idx].layer = WINED3D_ALL_LAYERS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-29 08:17:10 +01:00
|
|
|
texture_gl = wined3d_texture_gl(wined3d_texture_from_resource(resource));
|
|
|
|
if (texture_gl->current_renderbuffer)
|
2016-02-21 22:29:58 +01:00
|
|
|
{
|
2018-10-29 08:17:10 +01:00
|
|
|
key->objects[idx].object = texture_gl->current_renderbuffer->id;
|
2018-03-06 07:38:26 +01:00
|
|
|
key->objects[idx].target = 0;
|
|
|
|
key->objects[idx].level = key->objects[idx].layer = 0;
|
|
|
|
key->rb_namespace |= 1 << idx;
|
|
|
|
return;
|
2017-04-06 11:47:51 +02:00
|
|
|
}
|
2018-03-06 07:38:26 +01:00
|
|
|
|
2018-10-30 10:48:44 +01:00
|
|
|
key->objects[idx].target = wined3d_texture_gl_get_sub_resource_target(texture_gl, sub_resource_idx);
|
2018-10-29 08:17:10 +01:00
|
|
|
key->objects[idx].level = sub_resource_idx % texture_gl->t.level_count;
|
|
|
|
key->objects[idx].layer = sub_resource_idx / texture_gl->t.level_count;
|
2018-02-21 07:55:28 +01:00
|
|
|
|
2017-04-10 12:27:43 +02:00
|
|
|
if (render_target->layer_count != 1)
|
|
|
|
key->objects[idx].layer = WINED3D_ALL_LAYERS;
|
2017-04-06 11:47:51 +02:00
|
|
|
|
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
2019-06-14 13:17:21 +02:00
|
|
|
key->objects[idx].object = wined3d_texture_gl_get_texture_name(texture_gl, &context_gl->c, FALSE);
|
2017-04-06 11:47:51 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
2019-06-14 13:17:21 +02:00
|
|
|
key->objects[idx].object = wined3d_texture_gl_get_texture_name(texture_gl, &context_gl->c, TRUE);
|
2017-04-06 11:47:51 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_RB_MULTISAMPLE:
|
2018-10-29 08:17:11 +01:00
|
|
|
key->objects[idx].object = texture_gl->rb_multisample;
|
2017-04-06 11:47:51 +02:00
|
|
|
key->objects[idx].target = 0;
|
|
|
|
key->objects[idx].level = key->objects[idx].layer = 0;
|
|
|
|
key->rb_namespace |= 1 << idx;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_RB_RESOLVED:
|
2018-10-29 08:17:11 +01:00
|
|
|
key->objects[idx].object = texture_gl->rb_resolved;
|
2017-04-06 11:47:51 +02:00
|
|
|
key->objects[idx].target = 0;
|
|
|
|
key->objects[idx].level = key->objects[idx].layer = 0;
|
|
|
|
key->rb_namespace |= 1 << idx;
|
|
|
|
break;
|
2016-02-21 22:29:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 13:17:22 +02:00
|
|
|
static void wined3d_context_gl_generate_fbo_key(const struct wined3d_context_gl *context_gl,
|
2018-02-26 07:51:48 +01:00
|
|
|
struct wined3d_fbo_entry_key *key, const struct wined3d_rendertarget_info *render_targets,
|
2018-02-27 10:17:36 +01:00
|
|
|
const struct wined3d_rendertarget_info *depth_stencil, DWORD color_location, DWORD ds_location)
|
2016-02-21 22:29:57 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
unsigned int buffers = context_gl->gl_info->limits.buffers;
|
2017-04-06 11:47:50 +02:00
|
|
|
unsigned int i;
|
2016-02-21 22:29:57 +01:00
|
|
|
|
|
|
|
key->rb_namespace = 0;
|
2019-06-14 13:17:21 +02:00
|
|
|
wined3d_context_gl_set_fbo_key_for_render_target(context_gl, key, 0, depth_stencil, ds_location);
|
2017-04-06 11:47:51 +02:00
|
|
|
|
2018-02-27 10:17:36 +01:00
|
|
|
for (i = 0; i < buffers; ++i)
|
2019-06-14 13:17:21 +02:00
|
|
|
wined3d_context_gl_set_fbo_key_for_render_target(context_gl, key, i + 1, &render_targets[i], color_location);
|
2018-02-27 10:17:36 +01:00
|
|
|
|
|
|
|
memset(&key->objects[buffers + 1], 0, (ARRAY_SIZE(key->objects) - buffers - 1) * sizeof(*key->objects));
|
2016-02-21 22:29:57 +01:00
|
|
|
}
|
|
|
|
|
2019-06-17 12:32:10 +02:00
|
|
|
static struct fbo_entry *wined3d_context_gl_create_fbo_entry(const struct wined3d_context_gl *context_gl,
|
2018-02-26 07:51:48 +01:00
|
|
|
const struct wined3d_rendertarget_info *render_targets, const struct wined3d_rendertarget_info *depth_stencil,
|
2015-05-22 10:11:22 +02:00
|
|
|
DWORD color_location, DWORD ds_location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2008-09-18 14:57:53 +02:00
|
|
|
struct fbo_entry *entry;
|
2016-02-21 22:29:57 +01:00
|
|
|
|
2018-02-27 10:17:36 +01:00
|
|
|
entry = heap_alloc(sizeof(*entry));
|
2019-06-14 13:17:22 +02:00
|
|
|
wined3d_context_gl_generate_fbo_key(context_gl, &entry->key,
|
|
|
|
render_targets, depth_stencil, color_location, ds_location);
|
2016-02-21 22:30:01 +01:00
|
|
|
entry->flags = 0;
|
2018-02-26 07:51:48 +01:00
|
|
|
if (depth_stencil->resource)
|
2016-02-21 22:30:01 +01:00
|
|
|
{
|
2018-02-26 07:51:48 +01:00
|
|
|
if (depth_stencil->resource->format_flags & WINED3DFMT_FLAG_DEPTH)
|
2016-02-21 22:30:01 +01:00
|
|
|
entry->flags |= WINED3D_FBO_ENTRY_FLAG_DEPTH;
|
2018-02-26 07:51:48 +01:00
|
|
|
if (depth_stencil->resource->format_flags & WINED3DFMT_FLAG_STENCIL)
|
2016-02-21 22:30:01 +01:00
|
|
|
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. */
|
2019-05-16 15:04:57 +02:00
|
|
|
static void wined3d_context_gl_reuse_fbo_entry(struct wined3d_context_gl *context_gl, GLenum target,
|
2018-02-26 07:51:48 +01:00
|
|
|
const struct wined3d_rendertarget_info *render_targets, const struct wined3d_rendertarget_info *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
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2009-05-11 16:43:49 +02:00
|
|
|
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, 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
|
|
|
|
2019-06-14 13:17:22 +02:00
|
|
|
wined3d_context_gl_generate_fbo_key(context_gl, &entry->key,
|
|
|
|
render_targets, depth_stencil, color_location, ds_location);
|
2016-02-21 22:30:01 +01:00
|
|
|
entry->flags = 0;
|
2018-02-26 07:51:48 +01:00
|
|
|
if (depth_stencil->resource)
|
2016-02-21 22:30:01 +01:00
|
|
|
{
|
2018-02-26 07:51:48 +01:00
|
|
|
if (depth_stencil->resource->format_flags & WINED3DFMT_FLAG_DEPTH)
|
2016-02-21 22:30:01 +01:00
|
|
|
entry->flags |= WINED3D_FBO_ENTRY_FLAG_DEPTH;
|
2018-02-26 07:51:48 +01:00
|
|
|
if (depth_stencil->resource->format_flags & WINED3DFMT_FLAG_STENCIL)
|
2016-02-21 22:30:01 +01:00
|
|
|
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. */
|
2019-05-16 15:04:58 +02:00
|
|
|
static void wined3d_context_gl_destroy_fbo_entry(struct wined3d_context_gl *context_gl, 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);
|
2019-05-16 15:04:58 +02:00
|
|
|
wined3d_context_gl_destroy_fbo(context_gl, entry->id);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2019-05-19 16:00:43 +02:00
|
|
|
--context_gl->fbo_entry_count;
|
2008-09-18 14:57:53 +02:00
|
|
|
list_remove(&entry->entry);
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(entry);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2019-05-16 15:04:59 +02:00
|
|
|
static struct fbo_entry *wined3d_context_gl_find_fbo_entry(struct wined3d_context_gl *context_gl, GLenum target,
|
2018-02-26 07:51:48 +01:00
|
|
|
const struct wined3d_rendertarget_info *render_targets, const struct wined3d_rendertarget_info *depth_stencil,
|
2015-05-22 10:11:22 +02:00
|
|
|
DWORD color_location, DWORD ds_location)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2018-02-26 07:51:48 +01:00
|
|
|
static const struct wined3d_rendertarget_info ds_null = {{0}};
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2016-04-17 19:07:49 +02:00
|
|
|
struct wined3d_texture *rt_texture, *ds_texture;
|
2018-02-27 10:17:36 +01:00
|
|
|
struct wined3d_fbo_entry_key fbo_key;
|
2018-02-26 07:51:48 +01:00
|
|
|
unsigned int i, ds_level, rt_level;
|
2008-09-18 14:57:53 +02:00
|
|
|
struct fbo_entry *entry;
|
|
|
|
|
2018-02-26 07:51:48 +01:00
|
|
|
if (depth_stencil->resource && depth_stencil->resource->type != WINED3D_RTYPE_BUFFER
|
|
|
|
&& render_targets[0].resource && render_targets[0].resource->type != WINED3D_RTYPE_BUFFER)
|
2011-03-11 11:28:19 +01:00
|
|
|
{
|
2017-04-06 11:47:50 +02:00
|
|
|
rt_texture = wined3d_texture_from_resource(render_targets[0].resource);
|
2018-02-26 07:51:48 +01:00
|
|
|
rt_level = render_targets[0].sub_resource_idx % rt_texture->level_count;
|
|
|
|
ds_texture = wined3d_texture_from_resource(depth_stencil->resource);
|
|
|
|
ds_level = depth_stencil->sub_resource_idx % ds_texture->level_count;
|
|
|
|
|
|
|
|
if (wined3d_texture_get_level_width(ds_texture, ds_level)
|
|
|
|
< wined3d_texture_get_level_width(rt_texture, rt_level)
|
|
|
|
|| wined3d_texture_get_level_height(ds_texture, ds_level)
|
|
|
|
< wined3d_texture_get_level_height(rt_texture, rt_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");
|
2018-02-26 07:51:48 +01:00
|
|
|
depth_stencil = &ds_null;
|
2011-03-11 11:28:19 +01:00
|
|
|
}
|
2016-04-17 19:07:49 +02:00
|
|
|
else if (ds_texture->resource.multisample_type != rt_texture->resource.multisample_type
|
2019-02-06 22:09:38 +01:00
|
|
|
|| (ds_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);
|
2018-02-26 07:51:48 +01:00
|
|
|
depth_stencil = &ds_null;
|
|
|
|
}
|
|
|
|
else if (depth_stencil->resource->type == WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
{
|
2018-10-29 08:17:10 +01:00
|
|
|
wined3d_texture_gl_set_compatible_renderbuffer(wined3d_texture_gl(ds_texture),
|
2019-06-13 13:40:35 +02:00
|
|
|
context_gl, ds_level, &render_targets[0]);
|
2016-02-21 22:30:00 +01:00
|
|
|
}
|
2011-03-11 11:28:19 +01:00
|
|
|
}
|
|
|
|
|
2019-06-14 13:17:22 +02:00
|
|
|
wined3d_context_gl_generate_fbo_key(context_gl, &fbo_key,
|
|
|
|
render_targets, depth_stencil, color_location, ds_location);
|
2016-02-21 22:29:57 +01:00
|
|
|
|
|
|
|
if (TRACE_ON(d3d))
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2018-02-26 07:51:48 +01:00
|
|
|
struct wined3d_resource *resource;
|
|
|
|
unsigned int width, height;
|
|
|
|
const char *resource_type;
|
|
|
|
|
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
|
|
|
{
|
2017-04-06 11:47:50 +02:00
|
|
|
if ((resource = render_targets[i].resource))
|
2016-02-21 22:29:57 +01:00
|
|
|
{
|
2017-04-06 11:47:50 +02:00
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
width = resource->size;
|
|
|
|
height = 1;
|
|
|
|
resource_type = "buffer";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_texture = wined3d_texture_from_resource(resource);
|
2018-02-26 07:51:48 +01:00
|
|
|
rt_level = render_targets[i].sub_resource_idx % rt_texture->level_count;
|
|
|
|
width = wined3d_texture_get_level_pow2_width(rt_texture, rt_level);
|
|
|
|
height = wined3d_texture_get_level_pow2_height(rt_texture, rt_level);
|
2017-04-06 11:47:50 +02:00
|
|
|
resource_type = "texture";
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(" Color attachment %u: %p, %u format %s, %s %u, %ux%u, %u samples.\n",
|
|
|
|
i, resource, render_targets[i].sub_resource_idx, debug_d3dformat(resource->format->id),
|
2018-02-27 10:17:36 +01:00
|
|
|
fbo_key.rb_namespace & (1 << (i + 1)) ? "renderbuffer" : resource_type,
|
|
|
|
fbo_key.objects[i + 1].object, width, height, resource->multisample_type);
|
2016-02-21 22:29:57 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-26 07:51:48 +01:00
|
|
|
if ((resource = depth_stencil->resource))
|
2016-02-21 22:29:57 +01:00
|
|
|
{
|
2018-02-26 07:51:48 +01:00
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
width = resource->size;
|
|
|
|
height = 1;
|
|
|
|
resource_type = "buffer";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ds_texture = wined3d_texture_from_resource(resource);
|
|
|
|
ds_level = depth_stencil->sub_resource_idx % ds_texture->level_count;
|
|
|
|
width = wined3d_texture_get_level_pow2_width(ds_texture, ds_level);
|
|
|
|
height = wined3d_texture_get_level_pow2_height(ds_texture, ds_level);
|
|
|
|
resource_type = "texture";
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(" Depth attachment: %p, %u format %s, %s %u, %ux%u, %u samples.\n",
|
|
|
|
resource, depth_stencil->sub_resource_idx, debug_d3dformat(resource->format->id),
|
2018-02-27 10:17:36 +01:00
|
|
|
fbo_key.rb_namespace & (1 << 0) ? "renderbuffer" : resource_type,
|
|
|
|
fbo_key.objects[0].object, width, height, resource->multisample_type);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(entry, &context_gl->fbo_list, struct fbo_entry, entry)
|
2016-02-21 22:29:57 +01:00
|
|
|
{
|
2018-02-27 10:17:36 +01:00
|
|
|
if (memcmp(&fbo_key, &entry->key, sizeof(fbo_key)))
|
2016-02-21 22:29:57 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
list_remove(&entry->entry);
|
2019-05-19 16:00:43 +02:00
|
|
|
list_add_head(&context_gl->fbo_list, &entry->entry);
|
2016-02-21 22:29:57 +01:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
if (context_gl->fbo_entry_count < WINED3D_MAX_FBO_ENTRIES)
|
2009-05-11 16:43:49 +02:00
|
|
|
{
|
2019-06-17 12:32:10 +02:00
|
|
|
entry = wined3d_context_gl_create_fbo_entry(context_gl,
|
|
|
|
render_targets, depth_stencil, color_location, ds_location);
|
2019-05-19 16:00:43 +02:00
|
|
|
list_add_head(&context_gl->fbo_list, &entry->entry);
|
|
|
|
++context_gl->fbo_entry_count;
|
2009-05-11 16:43:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-19 16:00:43 +02:00
|
|
|
entry = LIST_ENTRY(list_tail(&context_gl->fbo_list), struct fbo_entry, entry);
|
2019-05-16 15:04:57 +02:00
|
|
|
wined3d_context_gl_reuse_fbo_entry(context_gl, target, render_targets,
|
|
|
|
depth_stencil, color_location, ds_location, entry);
|
2009-05-11 16:43:49 +02:00
|
|
|
list_remove(&entry->entry);
|
2019-05-19 16:00:43 +02:00
|
|
|
list_add_head(&context_gl->fbo_list, &entry->entry);
|
2009-05-11 16:43:49 +02:00
|
|
|
}
|
|
|
|
|
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. */
|
2019-05-17 13:45:13 +02:00
|
|
|
static void wined3d_context_gl_apply_fbo_entry(struct wined3d_context_gl *context_gl,
|
|
|
|
GLenum target, struct fbo_entry *entry)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2013-04-26 14:58:27 +02:00
|
|
|
GLuint read_binding, draw_binding;
|
2018-03-01 19:36:52 +01:00
|
|
|
unsigned int i;
|
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
|
|
|
{
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, target, entry->id);
|
2013-04-26 14:58:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
read_binding = context_gl->fbo_read_binding;
|
|
|
|
draw_binding = context_gl->fbo_draw_binding;
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, GL_FRAMEBUFFER, entry->id);
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2018-03-01 19:36:52 +01:00
|
|
|
if (gl_info->supported[ARB_FRAMEBUFFER_NO_ATTACHMENTS])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glFramebufferParameteri(GL_FRAMEBUFFER,
|
|
|
|
GL_FRAMEBUFFER_DEFAULT_WIDTH, gl_info->limits.framebuffer_width));
|
|
|
|
GL_EXTCALL(glFramebufferParameteri(GL_FRAMEBUFFER,
|
|
|
|
GL_FRAMEBUFFER_DEFAULT_HEIGHT, gl_info->limits.framebuffer_height));
|
|
|
|
GL_EXTCALL(glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_LAYERS, 1));
|
|
|
|
GL_EXTCALL(glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 1));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-06-14 13:17:20 +02:00
|
|
|
wined3d_context_gl_attach_surface_fbo(context_gl, 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
|
|
|
|
2019-06-14 13:17:19 +02:00
|
|
|
wined3d_context_gl_attach_depth_stencil_fbo(context_gl, 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);
|
2019-05-15 15:32:56 +02:00
|
|
|
wined3d_context_gl_set_draw_buffer(context_gl, GL_NONE);
|
2013-04-26 14:58:27 +02:00
|
|
|
if (target != GL_FRAMEBUFFER)
|
|
|
|
{
|
|
|
|
if (target == GL_READ_FRAMEBUFFER)
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, GL_DRAW_FRAMEBUFFER, draw_binding);
|
2013-04-26 14:58:27 +02:00
|
|
|
else
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, 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. */
|
2019-05-17 13:45:14 +02:00
|
|
|
static void wined3d_context_gl_apply_fbo_state(struct wined3d_context_gl *context_gl, GLenum target,
|
2018-03-12 10:06:48 +01:00
|
|
|
const struct wined3d_rendertarget_info *render_targets,
|
|
|
|
const struct wined3d_rendertarget_info *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;
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context_gl->fbo_destroy_list, struct fbo_entry, entry)
|
2009-10-20 11:05:06 +02:00
|
|
|
{
|
2019-05-16 15:04:58 +02:00
|
|
|
wined3d_context_gl_destroy_fbo_entry(context_gl, entry);
|
2009-10-20 11:05:06 +02:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
if (context_gl->rebind_fbo)
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, GL_FRAMEBUFFER, 0);
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->rebind_fbo = FALSE;
|
2010-03-17 21:59:51 +01:00
|
|
|
}
|
|
|
|
|
2015-05-22 10:11:22 +02:00
|
|
|
if (color_location == WINED3D_LOCATION_DRAWABLE)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->current_fbo = NULL;
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, target, 0);
|
2010-05-04 20:39:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->current_fbo = wined3d_context_gl_find_fbo_entry(context_gl,
|
|
|
|
target, render_targets, depth_stencil, color_location, ds_location);
|
|
|
|
wined3d_context_gl_apply_fbo_entry(context_gl, target, context_gl->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. */
|
2019-05-15 15:32:54 +02:00
|
|
|
void wined3d_context_gl_apply_fbo_state_blit(struct wined3d_context_gl *context_gl, GLenum target,
|
2018-03-12 10:06:49 +01:00
|
|
|
struct wined3d_resource *rt, unsigned int rt_sub_resource_idx,
|
|
|
|
struct wined3d_resource *ds, unsigned int ds_sub_resource_idx, DWORD location)
|
2010-05-04 20:39:52 +02:00
|
|
|
{
|
2018-03-12 10:06:48 +01:00
|
|
|
struct wined3d_rendertarget_info ds_info = {{0}};
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
memset(context_gl->blit_targets, 0, sizeof(context_gl->blit_targets));
|
2018-03-12 10:06:49 +01:00
|
|
|
if (rt)
|
2017-04-06 11:47:50 +02:00
|
|
|
{
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->blit_targets[0].resource = rt;
|
|
|
|
context_gl->blit_targets[0].sub_resource_idx = rt_sub_resource_idx;
|
|
|
|
context_gl->blit_targets[0].layer_count = 1;
|
2017-04-06 11:47:50 +02:00
|
|
|
}
|
2018-03-12 10:06:48 +01:00
|
|
|
|
2018-03-12 10:06:49 +01:00
|
|
|
if (ds)
|
2018-03-12 10:06:48 +01:00
|
|
|
{
|
2018-03-12 10:06:49 +01:00
|
|
|
ds_info.resource = ds;
|
|
|
|
ds_info.sub_resource_idx = ds_sub_resource_idx;
|
2018-03-12 10:06:48 +01:00
|
|
|
ds_info.layer_count = 1;
|
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
wined3d_context_gl_apply_fbo_state(context_gl, target, context_gl->blit_targets, &ds_info, 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. */
|
2019-05-10 18:31:07 +02:00
|
|
|
void wined3d_context_gl_alloc_occlusion_query(struct wined3d_context_gl *context_gl,
|
|
|
|
struct wined3d_occlusion_query *query)
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2019-05-10 18:31:07 +02:00
|
|
|
if (context_gl->free_occlusion_query_count)
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
2019-05-10 18:31:07 +02:00
|
|
|
query->id = context_gl->free_occlusion_queries[--context_gl->free_occlusion_query_count];
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2019-05-10 18:31:07 +02:00
|
|
|
TRACE("Allocated occlusion query %u in context %p.\n", query->id, context_gl);
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Occlusion queries not supported, not allocating query id.\n");
|
|
|
|
query->id = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 18:31:07 +02:00
|
|
|
query->context_gl = context_gl;
|
|
|
|
list_add_head(&context_gl->occlusion_queries, &query->entry);
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
|
|
|
|
2019-05-10 18:31:07 +02:00
|
|
|
void wined3d_context_gl_free_occlusion_query(struct wined3d_occlusion_query *query)
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
2019-05-10 18:31:07 +02:00
|
|
|
struct wined3d_context_gl *context_gl = query->context_gl;
|
2009-07-24 10:44:13 +02:00
|
|
|
|
|
|
|
list_remove(&query->entry);
|
2019-05-10 18:31:07 +02:00
|
|
|
query->context_gl = NULL;
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2019-05-10 18:31:07 +02:00
|
|
|
if (!wined3d_array_reserve((void **)&context_gl->free_occlusion_queries,
|
|
|
|
&context_gl->free_occlusion_query_size, context_gl->free_occlusion_query_count + 1,
|
|
|
|
sizeof(*context_gl->free_occlusion_queries)))
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
2019-05-10 18:31:07 +02:00
|
|
|
ERR("Failed to grow free list, leaking query %u in context %p.\n", query->id, context_gl);
|
2017-02-28 14:42:36 +01:00
|
|
|
return;
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
|
|
|
|
2019-05-10 18:31:07 +02:00
|
|
|
context_gl->free_occlusion_queries[context_gl->free_occlusion_query_count++] = query->id;
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
|
|
|
|
2009-07-24 10:44:14 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2019-05-14 12:56:19 +02:00
|
|
|
void wined3d_context_gl_alloc_fence(struct wined3d_context_gl *context_gl, struct wined3d_fence *fence)
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2009-07-24 10:44:14 +02:00
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
if (context_gl->free_fence_count)
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2019-05-14 12:56:19 +02:00
|
|
|
fence->object = context_gl->free_fences[--context_gl->free_fence_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. */
|
2017-07-09 13:25:49 +02:00
|
|
|
fence->object.sync = NULL;
|
2019-05-14 12:56:19 +02:00
|
|
|
TRACE("Allocated sync object in context %p.\n", context_gl);
|
2010-01-25 19:51:30 +01:00
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE])
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2017-07-09 13:25:49 +02:00
|
|
|
GL_EXTCALL(glGenFencesAPPLE(1, &fence->object.id));
|
2009-07-24 10:44:14 +02:00
|
|
|
checkGLcall("glGenFencesAPPLE");
|
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
TRACE("Allocated fence %u in context %p.\n", fence->object.id, context_gl);
|
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
|
|
|
{
|
2017-07-09 13:25:49 +02:00
|
|
|
GL_EXTCALL(glGenFencesNV(1, &fence->object.id));
|
2009-07-24 10:44:14 +02:00
|
|
|
checkGLcall("glGenFencesNV");
|
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
TRACE("Allocated fence %u in context %p.\n", fence->object.id, context_gl);
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-09 13:25:49 +02:00
|
|
|
WARN("Fences not supported, not allocating fence.\n");
|
|
|
|
fence->object.id = 0;
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
fence->context_gl = context_gl;
|
|
|
|
list_add_head(&context_gl->fences, &fence->entry);
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
void wined3d_context_gl_free_fence(struct wined3d_fence *fence)
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2019-05-14 12:56:19 +02:00
|
|
|
struct wined3d_context_gl *context_gl = fence->context_gl;
|
2009-07-24 10:44:14 +02:00
|
|
|
|
2017-07-09 13:25:49 +02:00
|
|
|
list_remove(&fence->entry);
|
2019-05-14 12:56:19 +02:00
|
|
|
fence->context_gl = NULL;
|
2009-07-24 10:44:14 +02:00
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
if (!wined3d_array_reserve((void **)&context_gl->free_fences,
|
|
|
|
&context_gl->free_fence_size, context_gl->free_fence_count + 1,
|
|
|
|
sizeof(*context_gl->free_fences)))
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2019-05-14 12:56:19 +02:00
|
|
|
ERR("Failed to grow free list, leaking fence %u in context %p.\n", fence->object.id, context_gl);
|
2017-02-28 14:42:36 +01:00
|
|
|
return;
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
context_gl->free_fences[context_gl->free_fence_count++] = fence->object;
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2019-05-14 12:56:20 +02:00
|
|
|
void wined3d_context_gl_alloc_timestamp_query(struct wined3d_context_gl *context_gl,
|
|
|
|
struct wined3d_timestamp_query *query)
|
2014-04-16 18:14:48 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2014-04-16 18:14:48 +02:00
|
|
|
|
2019-05-14 12:56:20 +02:00
|
|
|
if (context_gl->free_timestamp_query_count)
|
2014-04-16 18:14:48 +02:00
|
|
|
{
|
2019-05-14 12:56:20 +02:00
|
|
|
query->id = context_gl->free_timestamp_queries[--context_gl->free_timestamp_query_count];
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2019-05-14 12:56:20 +02:00
|
|
|
TRACE("Allocated timestamp query %u in context %p.\n", query->id, context_gl);
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:20 +02:00
|
|
|
query->context_gl = context_gl;
|
|
|
|
list_add_head(&context_gl->timestamp_queries, &query->entry);
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:20 +02:00
|
|
|
void wined3d_context_gl_free_timestamp_query(struct wined3d_timestamp_query *query)
|
2014-04-16 18:14:48 +02:00
|
|
|
{
|
2019-05-14 12:56:20 +02:00
|
|
|
struct wined3d_context_gl *context_gl = query->context_gl;
|
2014-04-16 18:14:48 +02:00
|
|
|
|
|
|
|
list_remove(&query->entry);
|
2019-05-14 12:56:20 +02:00
|
|
|
query->context_gl = NULL;
|
2014-04-16 18:14:48 +02:00
|
|
|
|
2019-05-14 12:56:20 +02:00
|
|
|
if (!wined3d_array_reserve((void **)&context_gl->free_timestamp_queries,
|
|
|
|
&context_gl->free_timestamp_query_size, context_gl->free_timestamp_query_count + 1,
|
|
|
|
sizeof(*context_gl->free_timestamp_queries)))
|
2014-04-16 18:14:48 +02:00
|
|
|
{
|
2019-05-14 12:56:20 +02:00
|
|
|
ERR("Failed to grow free list, leaking query %u in context %p.\n", query->id, context_gl);
|
2017-02-28 14:42:36 +01:00
|
|
|
return;
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:20 +02:00
|
|
|
context_gl->free_timestamp_queries[context_gl->free_timestamp_query_count++] = query->id;
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:21 +02:00
|
|
|
void wined3d_context_gl_alloc_so_statistics_query(struct wined3d_context_gl *context_gl,
|
2017-05-24 17:09:59 +02:00
|
|
|
struct wined3d_so_statistics_query *query)
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2017-05-24 17:09:59 +02:00
|
|
|
|
2019-05-14 12:56:21 +02:00
|
|
|
if (context_gl->free_so_statistics_query_count)
|
2017-05-24 17:09:59 +02:00
|
|
|
{
|
2019-05-14 12:56:21 +02:00
|
|
|
query->u = context_gl->free_so_statistics_queries[--context_gl->free_so_statistics_query_count];
|
2017-05-24 17:09:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glGenQueries(ARRAY_SIZE(query->u.id), query->u.id));
|
|
|
|
checkGLcall("glGenQueries");
|
|
|
|
|
|
|
|
TRACE("Allocated SO statistics queries %u, %u in context %p.\n",
|
2019-05-14 12:56:21 +02:00
|
|
|
query->u.id[0], query->u.id[1], context_gl);
|
2017-05-24 17:09:59 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:21 +02:00
|
|
|
query->context_gl = context_gl;
|
|
|
|
list_add_head(&context_gl->so_statistics_queries, &query->entry);
|
2017-05-24 17:09:59 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:21 +02:00
|
|
|
void wined3d_context_gl_free_so_statistics_query(struct wined3d_so_statistics_query *query)
|
2017-05-24 17:09:59 +02:00
|
|
|
{
|
2019-05-14 12:56:21 +02:00
|
|
|
struct wined3d_context_gl *context_gl = query->context_gl;
|
2017-05-24 17:09:59 +02:00
|
|
|
|
|
|
|
list_remove(&query->entry);
|
2019-05-14 12:56:21 +02:00
|
|
|
query->context_gl = NULL;
|
2017-05-24 17:09:59 +02:00
|
|
|
|
2019-05-14 12:56:21 +02:00
|
|
|
if (!wined3d_array_reserve((void **)&context_gl->free_so_statistics_queries,
|
|
|
|
&context_gl->free_so_statistics_query_size, context_gl->free_so_statistics_query_count + 1,
|
|
|
|
sizeof(*context_gl->free_so_statistics_queries)))
|
2017-05-24 17:09:59 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to grow free list, leaking GL queries %u, %u in context %p.\n",
|
2019-05-14 12:56:21 +02:00
|
|
|
query->u.id[0], query->u.id[1], context_gl);
|
2017-05-24 17:09:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:21 +02:00
|
|
|
context_gl->free_so_statistics_queries[context_gl->free_so_statistics_query_count++] = query->u;
|
2017-05-24 17:09:59 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:22 +02:00
|
|
|
void wined3d_context_gl_alloc_pipeline_statistics_query(struct wined3d_context_gl *context_gl,
|
2017-06-05 00:47:34 +02:00
|
|
|
struct wined3d_pipeline_statistics_query *query)
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2017-06-05 00:47:34 +02:00
|
|
|
|
2019-05-14 12:56:22 +02:00
|
|
|
if (context_gl->free_pipeline_statistics_query_count)
|
2017-06-05 00:47:34 +02:00
|
|
|
{
|
2019-05-14 12:56:22 +02:00
|
|
|
query->u = context_gl->free_pipeline_statistics_queries[--context_gl->free_pipeline_statistics_query_count];
|
2017-06-05 00:47:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glGenQueries(ARRAY_SIZE(query->u.id), query->u.id));
|
|
|
|
checkGLcall("glGenQueries");
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:22 +02:00
|
|
|
query->context_gl = context_gl;
|
|
|
|
list_add_head(&context_gl->pipeline_statistics_queries, &query->entry);
|
2017-06-05 00:47:34 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:22 +02:00
|
|
|
void wined3d_context_gl_free_pipeline_statistics_query(struct wined3d_pipeline_statistics_query *query)
|
2017-06-05 00:47:34 +02:00
|
|
|
{
|
2019-05-14 12:56:22 +02:00
|
|
|
struct wined3d_context_gl *context_gl = query->context_gl;
|
2017-06-05 00:47:34 +02:00
|
|
|
|
|
|
|
list_remove(&query->entry);
|
2019-05-14 12:56:22 +02:00
|
|
|
query->context_gl = NULL;
|
2017-06-05 00:47:34 +02:00
|
|
|
|
2019-05-14 12:56:22 +02:00
|
|
|
if (!wined3d_array_reserve((void **)&context_gl->free_pipeline_statistics_queries,
|
|
|
|
&context_gl->free_pipeline_statistics_query_size, context_gl->free_pipeline_statistics_query_count + 1,
|
|
|
|
sizeof(*context_gl->free_pipeline_statistics_queries)))
|
2017-06-05 00:47:34 +02:00
|
|
|
{
|
2019-05-14 12:56:22 +02:00
|
|
|
ERR("Failed to grow free list, leaking GL queries in context %p.\n", context_gl);
|
2017-06-05 00:47:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:22 +02:00
|
|
|
context_gl->free_pipeline_statistics_queries[context_gl->free_pipeline_statistics_query_count++] = query->u;
|
2017-06-05 00:47:34 +02:00
|
|
|
}
|
|
|
|
|
2019-05-17 13:45:15 +02:00
|
|
|
typedef void (context_fbo_entry_func_t)(struct wined3d_context_gl *context_gl, struct fbo_entry *entry);
|
2010-08-15 23:21:42 +02:00
|
|
|
|
2019-05-17 13:45:15 +02:00
|
|
|
static void wined3d_context_gl_enum_fbo_entries(const struct wined3d_device *device,
|
2016-02-21 22:29:59 +01:00
|
|
|
GLuint name, BOOL rb_namespace, context_fbo_entry_func_t *callback)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2018-02-27 10:17:36 +01:00
|
|
|
unsigned int i, j;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2011-03-30 20:49:27 +02:00
|
|
|
for (i = 0; i < device->context_count; ++i)
|
2008-09-18 14:57:53 +02:00
|
|
|
{
|
2019-05-17 13:45:15 +02:00
|
|
|
struct wined3d_context_gl *context_gl = wined3d_context_gl(device->contexts[i]);
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2010-08-15 23:21:42 +02:00
|
|
|
struct fbo_entry *entry, *entry2;
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context_gl->fbo_list, struct fbo_entry, entry)
|
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
|
|
|
{
|
2019-05-17 13:45:15 +02:00
|
|
|
callback(context_gl, entry);
|
2010-08-15 23:21:42 +02:00
|
|
|
break;
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
2010-08-15 23:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:45:15 +02:00
|
|
|
static void wined3d_context_gl_queue_fbo_entry_destruction(struct wined3d_context_gl *context_gl,
|
|
|
|
struct fbo_entry *entry)
|
2010-08-15 23:21:42 +02:00
|
|
|
{
|
|
|
|
list_remove(&entry->entry);
|
2019-05-19 16:00:43 +02:00
|
|
|
list_add_head(&context_gl->fbo_destroy_list, &entry->entry);
|
2010-08-15 23:21:42 +02:00
|
|
|
}
|
|
|
|
|
2018-03-22 10:52:44 +01:00
|
|
|
void context_resource_released(const struct wined3d_device *device, struct wined3d_resource *resource)
|
2010-08-15 23:21:42 +02:00
|
|
|
{
|
2018-03-22 10:52:44 +01:00
|
|
|
unsigned int i;
|
2016-02-21 22:29:59 +01:00
|
|
|
|
|
|
|
if (!device->d3d_initialized)
|
|
|
|
return;
|
2008-09-18 14:57:53 +02:00
|
|
|
|
2018-03-22 10:52:44 +01:00
|
|
|
for (i = 0; i < device->context_count; ++i)
|
2010-08-15 23:21:42 +02:00
|
|
|
{
|
2018-03-22 10:52:44 +01:00
|
|
|
struct wined3d_context *context = device->contexts[i];
|
2010-08-15 23:21:42 +02:00
|
|
|
|
2018-03-22 10:52:44 +01:00
|
|
|
if (&context->current_rt.texture->resource == resource)
|
|
|
|
{
|
|
|
|
context->current_rt.texture = NULL;
|
|
|
|
context->current_rt.sub_resource_idx = 0;
|
|
|
|
}
|
2010-08-15 23:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:45:15 +02:00
|
|
|
void context_gl_resource_released(struct wined3d_device *device, GLuint name, BOOL rb_namespace)
|
2010-08-15 23:21:42 +02:00
|
|
|
{
|
2019-05-17 13:45:15 +02:00
|
|
|
wined3d_context_gl_enum_fbo_entries(device, name, rb_namespace,
|
|
|
|
wined3d_context_gl_queue_fbo_entry_destruction);
|
2008-09-18 14:57:53 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 15:32:57 +02:00
|
|
|
void wined3d_context_gl_texture_update(struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_texture_gl *texture_gl)
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-05-19 16:00:43 +02:00
|
|
|
struct fbo_entry *entry = context_gl->current_fbo;
|
2010-03-17 21:59:51 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
if (!entry || context_gl->rebind_fbo)
|
2019-05-15 15:32:57 +02:00
|
|
|
return;
|
2010-03-17 21:59:51 +01:00
|
|
|
|
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
|
|
|
{
|
2018-10-30 10:48:43 +01:00
|
|
|
if (texture_gl->texture_rgb.name == entry->key.objects[i].object
|
|
|
|
|| texture_gl->texture_srgb.name == entry->key.objects[i].object)
|
2010-03-17 21:59:51 +01:00
|
|
|
{
|
2018-10-30 10:48:43 +01:00
|
|
|
TRACE("Updated texture %p is bound as attachment %u to the current FBO.\n", texture_gl, i);
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->rebind_fbo = TRUE;
|
2010-03-17 21:59:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:45 +02:00
|
|
|
static BOOL wined3d_context_gl_restore_pixel_format(struct wined3d_context_gl *context_gl)
|
2010-03-15 21:07:24 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2014-03-24 04:46:04 +01:00
|
|
|
BOOL ret = FALSE;
|
2014-02-19 23:14:53 +01:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (context_gl->restore_pf && IsWindow(context_gl->restore_pf_win))
|
2014-02-19 23:14:53 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
if (gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH])
|
2014-02-19 23:14:53 +01:00
|
|
|
{
|
2019-06-03 15:40:22 +02:00
|
|
|
HDC dc = GetDCEx(context_gl->restore_pf_win, 0, DCX_USESTYLE | DCX_CACHE);
|
2014-02-19 23:14:53 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
2019-06-03 15:40:22 +02:00
|
|
|
if (!(ret = GL_EXTCALL(wglSetPixelFormatWINE(dc, context_gl->restore_pf))))
|
2014-02-19 23:14:53 +01:00
|
|
|
{
|
2019-05-19 16:00:45 +02:00
|
|
|
ERR("Failed to restore pixel format %d on window %p.\n",
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->restore_pf, context_gl->restore_pf_win);
|
2014-02-19 23:14:53 +01:00
|
|
|
}
|
2019-06-03 15:40:22 +02:00
|
|
|
ReleaseDC(context_gl->restore_pf_win, dc);
|
2014-02-19 23:14:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-19 16:00:45 +02:00
|
|
|
ERR("Unable to restore pixel format %d on window %p.\n",
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->restore_pf, context_gl->restore_pf_win);
|
2014-02-19 23:14:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->restore_pf = 0;
|
|
|
|
context_gl->restore_pf_win = NULL;
|
2014-03-24 04:46:04 +01:00
|
|
|
return ret;
|
2014-02-19 23:14:53 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:46 +02:00
|
|
|
static BOOL wined3d_context_gl_set_pixel_format(struct wined3d_context_gl *context_gl)
|
2014-02-19 23:14:53 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-06-03 15:40:22 +02:00
|
|
|
BOOL private = context_gl->dc_is_private;
|
|
|
|
int format = context_gl->pixel_format;
|
|
|
|
HDC dc = context_gl->dc;
|
2014-03-24 04:46:25 +01:00
|
|
|
int current;
|
2010-03-15 21:07:24 +01:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (private && context_gl->dc_has_format)
|
2014-03-24 04:46:25 +01:00
|
|
|
return TRUE;
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (!private && WindowFromDC(dc) != context_gl->window)
|
2017-07-18 10:03:51 +02:00
|
|
|
return FALSE;
|
|
|
|
|
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
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->restore_pf = 0;
|
|
|
|
context_gl->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);
|
2019-06-03 15:40:22 +02:00
|
|
|
if (win != context_gl->restore_pf_win)
|
2014-02-19 23:14:53 +01:00
|
|
|
{
|
2019-05-19 16:00:45 +02:00
|
|
|
wined3d_context_gl_restore_pixel_format(context_gl);
|
2014-02-19 23:14:53 +01:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->restore_pf = private ? 0 : current;
|
|
|
|
context_gl->restore_pf_win = win;
|
2014-02-19 23:14:53 +01:00
|
|
|
}
|
|
|
|
|
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:
|
2017-08-02 18:40:35 +02:00
|
|
|
if (private)
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->dc_has_format = TRUE;
|
2014-03-24 04:46:25 +01:00
|
|
|
return TRUE;
|
2010-03-15 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
2019-05-20 23:41:03 +02:00
|
|
|
static BOOL wined3d_context_gl_set_gl_context(struct wined3d_context_gl *context_gl)
|
2011-04-12 22:26:21 +02:00
|
|
|
{
|
2019-08-13 10:31:38 +02:00
|
|
|
struct wined3d_swapchain_gl *swapchain_gl = wined3d_swapchain_gl(context_gl->c.swapchain);
|
2011-10-16 21:55:31 +02:00
|
|
|
BOOL backup = FALSE;
|
2011-04-12 22:27:54 +02:00
|
|
|
|
2019-05-19 16:00:46 +02:00
|
|
|
if (!wined3d_context_gl_set_pixel_format(context_gl))
|
2011-10-16 21:55:31 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to set pixel format %d on device context %p.\n",
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->pixel_format, context_gl->dc);
|
2011-10-16 21:55:31 +02:00
|
|
|
backup = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (backup || !wglMakeCurrent(context_gl->dc, context_gl->gl_ctx))
|
2011-04-12 22:26:21 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to make GL context %p current on device context %p, last error %#x.\n",
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->gl_ctx, context_gl->dc, GetLastError());
|
2019-06-06 14:51:06 +02:00
|
|
|
context_gl->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. */
|
2019-08-13 10:31:38 +02:00
|
|
|
if (context_gl->c.destroyed || !swapchain_gl)
|
2011-10-16 21:55:30 +02:00
|
|
|
{
|
2019-05-20 23:41:03 +02:00
|
|
|
FIXME("Unable to get backup dc for destroyed context %p.\n", context_gl);
|
2019-08-05 15:09:54 +02:00
|
|
|
wined3d_context_gl_set_current(NULL);
|
2011-10-16 21:55:30 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:38 +02:00
|
|
|
if (!(context_gl->dc = wined3d_swapchain_gl_get_backup_dc(swapchain_gl)))
|
2011-04-12 22:27:54 +02:00
|
|
|
{
|
2019-08-05 15:09:54 +02:00
|
|
|
wined3d_context_gl_set_current(NULL);
|
2011-07-05 22:30:53 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->dc_is_private = TRUE;
|
|
|
|
context_gl->dc_has_format = FALSE;
|
2017-08-02 18:40:34 +02:00
|
|
|
|
2019-05-19 16:00:46 +02:00
|
|
|
if (!wined3d_context_gl_set_pixel_format(context_gl))
|
2011-07-05 22:30:53 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to set pixel format %d on device context %p.\n",
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->pixel_format, context_gl->dc);
|
2019-08-05 15:09:54 +02:00
|
|
|
wined3d_context_gl_set_current(NULL);
|
2011-07-05 22:30:53 +02:00
|
|
|
return FALSE;
|
2011-04-12 22:27:54 +02:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (!wglMakeCurrent(context_gl->dc, context_gl->gl_ctx))
|
2011-04-12 22:27:54 +02:00
|
|
|
{
|
|
|
|
ERR("Fallback to backup window (dc %p) failed too, last error %#x.\n",
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->dc, GetLastError());
|
2019-08-05 15:09:54 +02:00
|
|
|
wined3d_context_gl_set_current(NULL);
|
2011-04-12 22:27:54 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-04 10:02:44 +01:00
|
|
|
|
2019-06-06 14:51:06 +02:00
|
|
|
context_gl->valid = 1;
|
2011-04-12 22:26:21 +02:00
|
|
|
}
|
2019-06-06 14:51:05 +02:00
|
|
|
context_gl->needs_set = 0;
|
2019-05-20 23:41:03 +02:00
|
|
|
|
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());
|
2019-08-05 15:09:54 +02:00
|
|
|
wined3d_context_gl_set_current(NULL);
|
2011-04-12 22:26:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 23:41:04 +02:00
|
|
|
static void wined3d_context_gl_update_window(struct wined3d_context_gl *context_gl)
|
2010-03-15 21:07:31 +01:00
|
|
|
{
|
2019-05-20 23:41:04 +02:00
|
|
|
if (!context_gl->c.swapchain)
|
2016-12-18 00:22:25 +01:00
|
|
|
return;
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (context_gl->window == context_gl->c.swapchain->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",
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl, context_gl->window, context_gl->c.swapchain->win_handle);
|
2010-03-15 21:07:31 +01:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (context_gl->dc)
|
|
|
|
wined3d_release_dc(context_gl->window, context_gl->dc);
|
2010-03-15 21:07:31 +01:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->window = context_gl->c.swapchain->win_handle;
|
|
|
|
context_gl->dc_is_private = FALSE;
|
|
|
|
context_gl->dc_has_format = FALSE;
|
2019-06-06 14:51:05 +02:00
|
|
|
context_gl->needs_set = 1;
|
2019-06-06 14:51:06 +02:00
|
|
|
context_gl->valid = 1;
|
2010-03-15 21:07:31 +01:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (!(context_gl->dc = GetDCEx(context_gl->window, 0, DCX_USESTYLE | DCX_CACHE)))
|
2010-03-15 21:07:31 +01:00
|
|
|
{
|
2019-06-03 15:40:22 +02:00
|
|
|
ERR("Failed to get a device context for window %p.\n", context_gl->window);
|
2019-06-06 14:51:06 +02:00
|
|
|
context_gl->valid = 0;
|
2010-03-15 21:07:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 12:30:10 +02:00
|
|
|
void wined3d_context_cleanup(struct wined3d_context *context)
|
2009-07-22 10:41:06 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
static void wined3d_context_gl_cleanup(struct wined3d_context_gl *context_gl)
|
2019-05-03 12:56:01 +02:00
|
|
|
{
|
2019-05-14 12:56:22 +02:00
|
|
|
struct wined3d_pipeline_statistics_query *pipeline_statistics_query;
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-05-14 12:56:21 +02:00
|
|
|
struct wined3d_so_statistics_query *so_statistics_query;
|
2019-05-14 12:56:20 +02:00
|
|
|
struct wined3d_timestamp_query *timestamp_query;
|
2019-05-10 18:31:07 +02:00
|
|
|
struct wined3d_occlusion_query *occlusion_query;
|
2019-05-19 16:00:43 +02:00
|
|
|
struct fbo_entry *entry, *entry2;
|
2019-05-14 12:56:19 +02:00
|
|
|
struct wined3d_fence *fence;
|
2019-05-08 15:21:35 +02:00
|
|
|
HGLRC restore_ctx;
|
|
|
|
HDC restore_dc;
|
2019-05-14 12:56:19 +02:00
|
|
|
unsigned int i;
|
2019-05-08 15:21:35 +02:00
|
|
|
|
|
|
|
restore_ctx = wglGetCurrentContext();
|
|
|
|
restore_dc = wglGetCurrentDC();
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (restore_ctx == context_gl->gl_ctx)
|
2019-05-08 15:21:35 +02:00
|
|
|
restore_ctx = NULL;
|
2019-06-06 14:51:06 +02:00
|
|
|
else if (context_gl->valid)
|
2019-05-20 23:41:03 +02:00
|
|
|
wined3d_context_gl_set_gl_context(context_gl);
|
2019-05-08 15:21:35 +02:00
|
|
|
|
2019-06-06 14:51:06 +02:00
|
|
|
if (context_gl->valid)
|
2019-05-08 15:21:35 +02:00
|
|
|
{
|
|
|
|
if (context_gl->dummy_arbfp_prog)
|
|
|
|
GL_EXTCALL(glDeleteProgramsARB(1, &context_gl->dummy_arbfp_prog));
|
|
|
|
|
2019-05-10 18:31:06 +02:00
|
|
|
if (context_gl->blit_vbo)
|
|
|
|
GL_EXTCALL(glDeleteBuffers(1, &context_gl->blit_vbo));
|
|
|
|
|
2019-05-14 12:56:22 +02:00
|
|
|
for (i = 0; i < context_gl->free_pipeline_statistics_query_count; ++i)
|
|
|
|
{
|
|
|
|
union wined3d_gl_pipeline_statistics_query *q = &context_gl->free_pipeline_statistics_queries[i];
|
|
|
|
GL_EXTCALL(glDeleteQueries(ARRAY_SIZE(q->id), q->id));
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:21 +02:00
|
|
|
for (i = 0; i < context_gl->free_so_statistics_query_count; ++i)
|
|
|
|
{
|
|
|
|
union wined3d_gl_so_statistics_query *q = &context_gl->free_so_statistics_queries[i];
|
|
|
|
GL_EXTCALL(glDeleteQueries(ARRAY_SIZE(q->id), q->id));
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:20 +02:00
|
|
|
if (context_gl->free_timestamp_query_count)
|
|
|
|
GL_EXTCALL(glDeleteQueries(context_gl->free_timestamp_query_count, context_gl->free_timestamp_queries));
|
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
for (i = 0; i < context_gl->free_fence_count; ++i)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteSync(context_gl->free_fences[i].sync));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE])
|
|
|
|
{
|
|
|
|
for (i = 0; i < context_gl->free_fence_count; ++i)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteFencesAPPLE(1, &context_gl->free_fences[i].id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[NV_FENCE])
|
|
|
|
{
|
|
|
|
for (i = 0; i < context_gl->free_fence_count; ++i)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteFencesNV(1, &context_gl->free_fences[i].id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 18:31:07 +02:00
|
|
|
if (context_gl->free_occlusion_query_count)
|
|
|
|
GL_EXTCALL(glDeleteQueries(context_gl->free_occlusion_query_count, context_gl->free_occlusion_queries));
|
|
|
|
|
2019-05-08 15:21:35 +02:00
|
|
|
checkGLcall("context cleanup");
|
|
|
|
}
|
2019-05-14 12:56:22 +02:00
|
|
|
heap_free(context_gl->free_pipeline_statistics_queries);
|
2019-05-14 12:56:21 +02:00
|
|
|
heap_free(context_gl->free_so_statistics_queries);
|
2019-05-14 12:56:20 +02:00
|
|
|
heap_free(context_gl->free_timestamp_queries);
|
2019-05-14 12:56:19 +02:00
|
|
|
heap_free(context_gl->free_fences);
|
2019-05-10 18:31:07 +02:00
|
|
|
heap_free(context_gl->free_occlusion_queries);
|
|
|
|
|
2019-05-14 12:56:22 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(pipeline_statistics_query, &context_gl->pipeline_statistics_queries,
|
|
|
|
struct wined3d_pipeline_statistics_query, entry)
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
if (context_gl->valid)
|
2019-05-14 12:56:22 +02:00
|
|
|
GL_EXTCALL(glDeleteQueries(ARRAY_SIZE(pipeline_statistics_query->u.id), pipeline_statistics_query->u.id));
|
|
|
|
pipeline_statistics_query->context_gl = NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:21 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(so_statistics_query, &context_gl->so_statistics_queries,
|
|
|
|
struct wined3d_so_statistics_query, entry)
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
if (context_gl->valid)
|
2019-05-14 12:56:21 +02:00
|
|
|
GL_EXTCALL(glDeleteQueries(ARRAY_SIZE(so_statistics_query->u.id), so_statistics_query->u.id));
|
|
|
|
so_statistics_query->context_gl = NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:20 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(timestamp_query, &context_gl->timestamp_queries, struct wined3d_timestamp_query, entry)
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
if (context_gl->valid)
|
2019-05-14 12:56:20 +02:00
|
|
|
GL_EXTCALL(glDeleteQueries(1, ×tamp_query->id));
|
|
|
|
timestamp_query->context_gl = NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:19 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(fence, &context_gl->fences, struct wined3d_fence, entry)
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
if (context_gl->valid)
|
2019-05-14 12:56:19 +02:00
|
|
|
{
|
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
if (fence->object.sync)
|
|
|
|
GL_EXTCALL(glDeleteSync(fence->object.sync));
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteFencesAPPLE(1, &fence->object.id));
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[NV_FENCE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDeleteFencesNV(1, &fence->object.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fence->context_gl = NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-10 18:31:07 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(occlusion_query, &context_gl->occlusion_queries, struct wined3d_occlusion_query, entry)
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
if (context_gl->valid)
|
2019-05-10 18:31:07 +02:00
|
|
|
GL_EXTCALL(glDeleteQueries(1, &occlusion_query->id));
|
|
|
|
occlusion_query->context_gl = NULL;
|
|
|
|
}
|
2019-05-08 15:21:35 +02:00
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context_gl->fbo_destroy_list, struct fbo_entry, entry)
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
if (!context_gl->valid)
|
2019-05-19 16:00:43 +02:00
|
|
|
entry->id = 0;
|
|
|
|
wined3d_context_gl_destroy_fbo_entry(context_gl, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context_gl->fbo_list, struct fbo_entry, entry)
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
if (!context_gl->valid)
|
2019-05-19 16:00:43 +02:00
|
|
|
entry->id = 0;
|
|
|
|
wined3d_context_gl_destroy_fbo_entry(context_gl, entry);
|
|
|
|
}
|
|
|
|
|
2019-05-08 15:21:34 +02:00
|
|
|
heap_free(context_gl->texture_type);
|
|
|
|
|
2019-05-19 16:00:45 +02:00
|
|
|
wined3d_context_gl_restore_pixel_format(context_gl);
|
2019-05-08 15:21:35 +02:00
|
|
|
if (restore_ctx)
|
|
|
|
context_restore_gl_context(gl_info, restore_dc, restore_ctx);
|
2019-06-03 15:40:22 +02:00
|
|
|
else if (wglGetCurrentContext() && !wglMakeCurrent(NULL, NULL))
|
|
|
|
ERR("Failed to disable GL context.\n");
|
|
|
|
|
|
|
|
wined3d_release_dc(context_gl->window, context_gl->dc);
|
|
|
|
|
|
|
|
if (!wglDeleteContext(context_gl->gl_ctx))
|
|
|
|
{
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
ERR("Failed to delete GL context %p, last error %#x.\n", context_gl->gl_ctx, err);
|
|
|
|
}
|
2019-05-08 15:21:35 +02:00
|
|
|
|
2019-05-03 12:56:01 +02:00
|
|
|
wined3d_context_cleanup(&context_gl->c);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
struct wined3d_context_gl *wined3d_context_gl_get_current(void)
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
|
|
|
return TlsGetValue(wined3d_context_tls_idx);
|
|
|
|
}
|
|
|
|
|
2019-08-05 15:09:54 +02:00
|
|
|
BOOL wined3d_context_gl_set_current(struct wined3d_context_gl *context_gl)
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
2019-08-05 15:09:55 +02:00
|
|
|
struct wined3d_context_gl *old = wined3d_context_gl_get_current();
|
2009-07-22 14:03:36 +02:00
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
if (old == context_gl)
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
2019-08-05 15:09:54 +02:00
|
|
|
TRACE("Already using D3D context %p.\n", context_gl);
|
2009-07-22 14:03:36 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-07-22 10:41:06 +02:00
|
|
|
if (old)
|
|
|
|
{
|
2019-08-05 15:09:55 +02:00
|
|
|
if (old->c.destroyed)
|
2009-07-22 10:41:06 +02:00
|
|
|
{
|
|
|
|
TRACE("Switching away from destroyed context %p.\n", old);
|
2019-08-05 15:09:55 +02:00
|
|
|
wined3d_context_gl_cleanup(old);
|
2019-08-07 13:41:58 +02:00
|
|
|
heap_free((void *)old->gl_info);
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(old);
|
2009-07-22 10:41:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-27 20:39:31 +01:00
|
|
|
if (wglGetCurrentContext())
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = old->gl_info;
|
2019-08-05 15:09:54 +02:00
|
|
|
TRACE("Flushing context %p before switching to %p.\n", old, context_gl);
|
2016-10-10 10:22:36 +02:00
|
|
|
gl_info->gl_ops.gl.p_glFlush();
|
2015-11-27 20:39:31 +01:00
|
|
|
}
|
2019-08-05 15:09:55 +02:00
|
|
|
old->c.current = 0;
|
2009-07-22 10:41:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 15:09:54 +02:00
|
|
|
if (context_gl)
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
if (!context_gl->valid)
|
2011-03-18 19:17:52 +01:00
|
|
|
{
|
2019-08-05 15:09:54 +02:00
|
|
|
ERR("Trying to make invalid context %p current.\n", context_gl);
|
2011-03-18 19:17:52 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
TRACE("Switching to D3D context %p, GL context %p, device context %p.\n",
|
|
|
|
context_gl, context_gl->gl_ctx, context_gl->dc);
|
2019-05-20 23:41:03 +02:00
|
|
|
if (!wined3d_context_gl_set_gl_context(context_gl))
|
2009-07-22 14:03:36 +02:00
|
|
|
return FALSE;
|
2019-08-05 15:09:54 +02:00
|
|
|
context_gl->c.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
return TlsSetValue(wined3d_context_tls_idx, context_gl);
|
2009-07-22 14:03:36 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
void wined3d_context_gl_release(struct wined3d_context_gl *context_gl)
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
2019-08-07 13:41:59 +02:00
|
|
|
TRACE("Releasing context %p, level %u.\n", context_gl, context_gl->level);
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
if (WARN_ON(d3d))
|
|
|
|
{
|
2019-08-07 13:41:59 +02:00
|
|
|
if (!context_gl->level)
|
|
|
|
WARN("Context %p is not active.\n", context_gl);
|
2019-08-05 15:09:55 +02:00
|
|
|
else if (context_gl != wined3d_context_gl_get_current())
|
2019-08-07 13:41:59 +02:00
|
|
|
WARN("Context %p is not the current context.\n", context_gl);
|
2009-10-28 11:00:11 +01:00
|
|
|
}
|
|
|
|
|
2019-08-07 13:41:59 +02:00
|
|
|
if (!--context_gl->level)
|
2009-10-28 11:00:13 +01:00
|
|
|
{
|
2019-05-19 16:00:45 +02:00
|
|
|
if (wined3d_context_gl_restore_pixel_format(context_gl))
|
2019-06-06 14:51:05 +02:00
|
|
|
context_gl->needs_set = 1;
|
2019-06-03 15:40:22 +02:00
|
|
|
if (context_gl->restore_ctx)
|
2014-02-19 23:14:53 +01:00
|
|
|
{
|
2019-06-03 15:40:22 +02:00
|
|
|
TRACE("Restoring GL context %p on device context %p.\n", context_gl->restore_ctx, context_gl->restore_dc);
|
2019-08-07 13:41:58 +02:00
|
|
|
context_restore_gl_context(context_gl->gl_info, context_gl->restore_dc, context_gl->restore_ctx);
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->restore_ctx = NULL;
|
|
|
|
context_gl->restore_dc = NULL;
|
2014-02-19 23:14:53 +01:00
|
|
|
}
|
2016-10-05 11:17:07 +02:00
|
|
|
|
2019-08-07 13:41:59 +02:00
|
|
|
if (context_gl->c.destroy_delayed)
|
2016-10-05 11:17:07 +02:00
|
|
|
{
|
2019-06-05 14:24:07 +02:00
|
|
|
TRACE("Destroying context %p.\n", context_gl);
|
|
|
|
wined3d_context_gl_destroy(context_gl);
|
2016-10-05 11:17:07 +02:00
|
|
|
}
|
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. */
|
2018-03-12 10:06:47 +01:00
|
|
|
void context_restore(struct wined3d_context *context, struct wined3d_texture *texture, unsigned int sub_resource_idx)
|
2015-10-12 22:34:39 +02:00
|
|
|
{
|
2018-03-12 10:06:47 +01:00
|
|
|
if (context->current_rt.texture != texture || context->current_rt.sub_resource_idx != sub_resource_idx)
|
2015-10-12 22:34:39 +02:00
|
|
|
{
|
|
|
|
context_release(context);
|
2018-03-12 10:06:47 +01:00
|
|
|
context = context_acquire(texture->resource.device, texture, sub_resource_idx);
|
2015-10-12 22:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2019-05-20 23:41:05 +02:00
|
|
|
static void wined3d_context_gl_enter(struct wined3d_context_gl *context_gl)
|
2009-10-28 11:00:13 +01:00
|
|
|
{
|
2019-08-07 13:41:59 +02:00
|
|
|
TRACE("Entering context %p, level %u.\n", context_gl, context_gl->level + 1);
|
2009-10-28 11:00:13 +01:00
|
|
|
|
2019-08-07 13:41:59 +02:00
|
|
|
if (!context_gl->level++)
|
2009-10-28 11:00:13 +01:00
|
|
|
{
|
2019-08-05 15:09:55 +02:00
|
|
|
const struct wined3d_context_gl *current_context = wined3d_context_gl_get_current();
|
2012-11-08 11:56:06 +01:00
|
|
|
HGLRC current_gl = wglGetCurrentContext();
|
2009-10-28 11:00:13 +01:00
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
if (current_gl && (!current_context || current_context->gl_ctx != current_gl))
|
2009-10-28 11:00:13 +01:00
|
|
|
{
|
|
|
|
TRACE("Another GL context (%p on device context %p) is already current.\n",
|
2012-11-08 11:56:06 +01:00
|
|
|
current_gl, wglGetCurrentDC());
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->restore_ctx = current_gl;
|
|
|
|
context_gl->restore_dc = wglGetCurrentDC();
|
2019-06-06 14:51:05 +02:00
|
|
|
context_gl->needs_set = 1;
|
2009-10-28 11:00:13 +01:00
|
|
|
}
|
2019-06-06 14:51:05 +02:00
|
|
|
else if (!context_gl->needs_set && !(context_gl->dc_is_private && context_gl->dc_has_format)
|
2019-08-07 13:41:58 +02:00
|
|
|
&& context_gl->pixel_format != context_gl->gl_info->gl_ops.wgl.p_wglGetPixelFormat(context_gl->dc))
|
2019-06-06 14:51:05 +02:00
|
|
|
context_gl->needs_set = 1;
|
2009-10-28 11:00:13 +01:00
|
|
|
}
|
2009-10-28 11:00:11 +01:00
|
|
|
}
|
|
|
|
|
2017-02-06 14:12:14 +01:00
|
|
|
void context_invalidate_compute_state(struct wined3d_context *context, DWORD state_id)
|
|
|
|
{
|
2017-02-06 14:12:15 +01:00
|
|
|
DWORD representative = context->state_table[state_id].representative - STATE_COMPUTE_OFFSET;
|
2017-02-06 14:12:14 +01:00
|
|
|
unsigned int index, shift;
|
|
|
|
|
|
|
|
index = representative / (sizeof(*context->dirty_compute_states) * CHAR_BIT);
|
|
|
|
shift = representative & (sizeof(*context->dirty_compute_states) * CHAR_BIT - 1);
|
|
|
|
context->dirty_compute_states[index] |= (1u << shift);
|
|
|
|
}
|
|
|
|
|
2019-08-07 13:42:01 +02:00
|
|
|
void context_invalidate_state(struct wined3d_context *context, unsigned int state_id)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
2019-08-07 13:42:01 +02:00
|
|
|
unsigned int representative = context->state_table[state_id].representative;
|
|
|
|
unsigned int index, shift;
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2019-08-07 13:42:01 +02:00
|
|
|
index = representative / (sizeof(*context->dirty_graphics_states) * CHAR_BIT);
|
|
|
|
shift = representative & ((sizeof(*context->dirty_graphics_states) * CHAR_BIT) - 1);
|
|
|
|
context->dirty_graphics_states[index] |= (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,
|
2017-02-10 12:26:58 +01:00
|
|
|
BOOL auxBuffers)
|
2008-04-27 19:35:27 +02:00
|
|
|
{
|
2019-03-28 09:53:57 +01:00
|
|
|
unsigned int cfg_count = wined3d_adapter_gl(device->adapter)->pixel_format_count;
|
2017-02-10 12:26:58 +01:00
|
|
|
unsigned int current_value;
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
int iPixelFormat = 0;
|
2011-10-27 17:06:25 +02:00
|
|
|
unsigned int i;
|
2008-04-27 19:35:27 +02:00
|
|
|
|
2017-02-10 12:26:58 +01:00
|
|
|
TRACE("device %p, dc %p, color_format %s, ds_format %s, aux_buffers %#x.\n",
|
2011-08-25 21:05:02 +02:00
|
|
|
device, hdc, debug_d3dformat(color_format->id), debug_d3dformat(ds_format->id),
|
2017-02-10 12:26:58 +01:00
|
|
|
auxBuffers);
|
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
|
|
|
{
|
2019-03-28 09:53:57 +01:00
|
|
|
const struct wined3d_pixel_format *cfg = &wined3d_adapter_gl(device->adapter)->pixel_formats[i];
|
2011-11-08 20:48:57 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-02-10 12:26:58 +01:00
|
|
|
if (!iPixelFormat)
|
|
|
|
{
|
|
|
|
ERR("Trying to locate a compatible pixel format because an exact match failed.\n");
|
2008-04-27 19:35:27 +02:00
|
|
|
|
2017-02-10 12:26:58 +01:00
|
|
|
memset(&pfd, 0, sizeof(pfd));
|
2008-04-27 19:35:27 +02:00
|
|
|
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;
|
|
|
|
|
2017-02-10 12:26:58 +01:00
|
|
|
if (!(iPixelFormat = ChoosePixelFormat(hdc, &pfd)))
|
|
|
|
{
|
|
|
|
/* Something is very wrong as ChoosePixelFormat() barely fails. */
|
|
|
|
ERR("Can't find a suitable pixel format.\n");
|
|
|
|
return 0;
|
2008-04-27 19:35:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 12:26:58 +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. */
|
2019-06-07 14:52:29 +02:00
|
|
|
void wined3d_context_gl_bind_dummy_textures(const struct wined3d_context_gl *context_gl)
|
2011-08-26 01:12:27 +02:00
|
|
|
{
|
2019-06-07 14:52:29 +02:00
|
|
|
const struct wined3d_dummy_textures *textures = &wined3d_device_gl(context_gl->c.device)->dummy_textures;
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->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));
|
2011-08-26 01:12:27 +02:00
|
|
|
|
2018-04-02 22:58:23 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, textures->tex_1d);
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, textures->tex_2d);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures->tex_rect);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE3D])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, textures->tex_3d);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, textures->tex_cube);
|
2016-04-19 00:01:26 +02:00
|
|
|
|
2017-03-08 12:07:20 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP_ARRAY])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textures->tex_cube_array);
|
2017-03-08 12:07:20 +01:00
|
|
|
|
2016-04-19 00:01:26 +02:00
|
|
|
if (gl_info->supported[EXT_TEXTURE_ARRAY])
|
2018-04-02 22:58:23 +02:00
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D_ARRAY, textures->tex_1d_array);
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, textures->tex_2d_array);
|
2018-04-02 22:58:23 +02:00
|
|
|
}
|
2016-10-03 00:38:37 +02:00
|
|
|
|
2017-01-26 13:07:30 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT])
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_BUFFER, textures->tex_buffer);
|
2017-01-26 13:07:30 +01:00
|
|
|
|
2018-02-15 13:49:35 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_MULTISAMPLE])
|
|
|
|
{
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textures->tex_2d_ms);
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, textures->tex_2d_ms_array);
|
2018-02-15 13:49:35 +01:00
|
|
|
}
|
2011-08-26 01:12:27 +02:00
|
|
|
}
|
2018-02-15 13:49:36 +01:00
|
|
|
|
|
|
|
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 (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)))
|
|
|
|
{
|
2018-05-03 00:04:04 +02:00
|
|
|
if (gl_info->selected_gl_version >= MAKEDWORD_VERSION(3, 2))
|
2015-07-08 15:47:01 +02:00
|
|
|
{
|
2018-05-03 00:04:04 +02:00
|
|
|
if (ctx_flags)
|
|
|
|
{
|
|
|
|
ctx_flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
ctx_attribs[ctx_attrib_idx - 1] = ctx_flags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ctx_flags = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
ctx_attribs[ctx_attrib_idx++] = WGL_CONTEXT_FLAGS_ARB;
|
|
|
|
ctx_attribs[ctx_attrib_idx++] = ctx_flags;
|
|
|
|
ctx_attribs[ctx_attrib_idx] = 0;
|
|
|
|
}
|
2015-07-08 15:47:01 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-04-16 18:29:07 +02:00
|
|
|
void wined3d_context_init(struct wined3d_context *context, struct wined3d_swapchain *swapchain)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = swapchain->device;
|
2010-03-14 21:53:24 +01:00
|
|
|
DWORD state;
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2018-08-22 19:43:00 +02:00
|
|
|
context->d3d_info = &device->adapter->d3d_info;
|
2019-03-03 19:55:26 +01:00
|
|
|
context->state_table = device->state_table;
|
2018-08-22 19:43:00 +02:00
|
|
|
|
|
|
|
/* Mark all states dirty to force a proper initialization of the states on
|
|
|
|
* the first use of the context. Compute states do not need initialization. */
|
|
|
|
for (state = 0; state <= STATE_HIGHEST; ++state)
|
|
|
|
{
|
|
|
|
if (context->state_table[state].representative && !STATE_IS_COMPUTE(state))
|
|
|
|
context_invalidate_state(context, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
context->device = device;
|
|
|
|
context->swapchain = swapchain;
|
2019-05-06 18:46:28 +02:00
|
|
|
context->current_rt.texture = swapchain->front_buffer;
|
2018-08-22 19:43:00 +02:00
|
|
|
context->current_rt.sub_resource_idx = 0;
|
|
|
|
|
|
|
|
context->shader_update_mask = (1u << WINED3D_SHADER_TYPE_PIXEL)
|
|
|
|
| (1u << WINED3D_SHADER_TYPE_VERTEX)
|
|
|
|
| (1u << WINED3D_SHADER_TYPE_GEOMETRY)
|
|
|
|
| (1u << WINED3D_SHADER_TYPE_HULL)
|
|
|
|
| (1u << WINED3D_SHADER_TYPE_DOMAIN)
|
|
|
|
| (1u << WINED3D_SHADER_TYPE_COMPUTE);
|
2019-05-02 14:40:52 +02:00
|
|
|
}
|
|
|
|
|
2019-05-07 12:30:10 +02:00
|
|
|
HRESULT wined3d_context_no3d_init(struct wined3d_context *context_no3d, struct wined3d_swapchain *swapchain)
|
2019-05-02 14:40:52 +02:00
|
|
|
{
|
2019-05-07 12:30:10 +02:00
|
|
|
TRACE("context_no3d %p, swapchain %p.\n", context_no3d, swapchain);
|
2019-05-02 14:40:52 +02:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
wined3d_context_init(context_no3d, swapchain);
|
2018-08-22 19:43:00 +02:00
|
|
|
|
2019-05-07 12:30:10 +02:00
|
|
|
return WINED3D_OK;
|
2018-08-22 19:43:00 +02:00
|
|
|
}
|
|
|
|
|
2019-11-18 15:18:11 +01:00
|
|
|
static BOOL wined3d_context_gl_create_wgl_ctx(struct wined3d_context_gl *context_gl,
|
|
|
|
struct wined3d_swapchain_gl *swapchain_gl)
|
2018-08-22 19:43:00 +02:00
|
|
|
{
|
2019-11-18 15:18:11 +01:00
|
|
|
const struct wined3d_format *colour_format, *ds_format;
|
2019-05-07 12:30:10 +02:00
|
|
|
struct wined3d_context *context = &context_gl->c;
|
2018-08-22 19:43:00 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-05-06 18:46:29 +02:00
|
|
|
struct wined3d_resource *target;
|
2019-11-18 15:18:11 +01:00
|
|
|
struct wined3d_adapter *adapter;
|
2018-10-31 10:31:50 +01:00
|
|
|
unsigned int target_bind_flags;
|
2019-05-07 12:30:10 +02:00
|
|
|
struct wined3d_device *device;
|
2018-08-22 19:43:00 +02:00
|
|
|
HGLRC ctx, share_ctx;
|
|
|
|
unsigned int i;
|
|
|
|
|
2019-05-07 12:30:10 +02:00
|
|
|
device = context->device;
|
2019-11-18 15:18:11 +01:00
|
|
|
adapter = device->adapter;
|
|
|
|
gl_info = &adapter->gl_info;
|
2008-04-27 20:40:33 +02:00
|
|
|
|
2019-05-06 18:46:29 +02:00
|
|
|
target = &context->current_rt.texture->resource;
|
|
|
|
target_bind_flags = target->bind_flags;
|
2008-04-27 20:40:33 +02:00
|
|
|
|
2010-03-14 21:53:23 +01:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
|
|
|
|
{
|
2019-05-07 12:30:09 +02:00
|
|
|
static const enum wined3d_format_id ds_formats[] =
|
|
|
|
{
|
|
|
|
WINED3DFMT_D24_UNORM_S8_UINT,
|
|
|
|
WINED3DFMT_D32_UNORM,
|
|
|
|
WINED3DFMT_R24_UNORM_X8_TYPELESS,
|
|
|
|
WINED3DFMT_D16_UNORM,
|
|
|
|
WINED3DFMT_S1_UINT_D15_UNORM,
|
|
|
|
};
|
|
|
|
|
2019-11-18 15:18:11 +01:00
|
|
|
colour_format = target->format;
|
2007-02-12 19:21:10 +01:00
|
|
|
|
2019-05-07 12:30:09 +02:00
|
|
|
/* In case of ORM_BACKBUFFER, make sure to request an alpha component for
|
|
|
|
* X4R4G4B4/X8R8G8B8 as we might need it for the backbuffer. */
|
2019-11-18 15:18:11 +01:00
|
|
|
if (colour_format->id == WINED3DFMT_B4G4R4X4_UNORM)
|
|
|
|
colour_format = wined3d_get_format(adapter, WINED3DFMT_B4G4R4A4_UNORM, target_bind_flags);
|
|
|
|
else if (colour_format->id == WINED3DFMT_B8G8R8X8_UNORM)
|
|
|
|
colour_format = wined3d_get_format(adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags);
|
2007-08-06 20:53:20 +02:00
|
|
|
|
2019-05-07 12:30:09 +02:00
|
|
|
/* DirectDraw supports 8bit paletted render targets and these are used by
|
|
|
|
* old games like StarCraft and C&C. Most modern hardware doesn't support
|
|
|
|
* 8bit natively so we perform some form of 8bit -> 32bit conversion. The
|
|
|
|
* conversion (ab)uses the alpha component for storing the palette index.
|
|
|
|
* For this reason we require a format with 8bit alpha, so request
|
|
|
|
* A8R8G8B8. */
|
2019-11-18 15:18:11 +01:00
|
|
|
if (colour_format->id == WINED3DFMT_P8_UINT)
|
|
|
|
colour_format = wined3d_get_format(adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags);
|
2019-05-07 12:30:09 +02:00
|
|
|
|
|
|
|
/* Try to find a pixel format which matches our requirements. */
|
2019-08-13 10:31:39 +02:00
|
|
|
if (!swapchain_gl->s.ds_format)
|
2019-05-07 12:30:09 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ds_formats); ++i)
|
|
|
|
{
|
2019-11-18 15:18:11 +01:00
|
|
|
ds_format = wined3d_get_format(adapter, ds_formats[i], WINED3D_BIND_DEPTH_STENCIL);
|
2019-06-03 15:40:22 +02:00
|
|
|
if ((context_gl->pixel_format = context_choose_pixel_format(device,
|
2019-11-18 15:18:11 +01:00
|
|
|
context_gl->dc, colour_format, ds_format, TRUE)))
|
2019-05-07 12:30:09 +02:00
|
|
|
{
|
2019-08-13 10:31:39 +02:00
|
|
|
swapchain_gl->s.ds_format = ds_format;
|
2019-05-07 12:30:09 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-08-08 03:09:38 +02:00
|
|
|
|
2019-05-07 12:30:09 +02:00
|
|
|
TRACE("Depth stencil format %s is not supported, trying next format.\n",
|
|
|
|
debug_d3dformat(ds_format->id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->pixel_format = context_choose_pixel_format(device,
|
2019-11-18 15:18:11 +01:00
|
|
|
context_gl->dc, colour_format, swapchain_gl->s.ds_format, TRUE);
|
2019-05-07 12:30:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-11-04 00:02:48 +01:00
|
|
|
{
|
2019-05-07 12:30:09 +02:00
|
|
|
/* When using FBOs for off-screen rendering, 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.
|
2019-11-18 15:18:11 +01:00
|
|
|
* Using the same format regardless of the colour/depth/stencil targets
|
2019-05-07 12:30:09 +02:00
|
|
|
* makes it much less likely that different wined3d instances will set
|
|
|
|
* conflicting pixel formats. */
|
2019-11-18 15:18:11 +01:00
|
|
|
colour_format = wined3d_get_format(adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags);
|
|
|
|
ds_format = wined3d_get_format(adapter, WINED3DFMT_UNKNOWN, WINED3D_BIND_DEPTH_STENCIL);
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->pixel_format = context_choose_pixel_format(device,
|
2019-11-18 15:18:11 +01:00
|
|
|
context_gl->dc, colour_format, ds_format, FALSE);
|
2015-11-04 00:02:48 +01:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
if (!context_gl->pixel_format)
|
2019-11-18 15:18:11 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to choose pixel format.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-19 23:14:53 +01:00
|
|
|
|
2019-05-20 23:41:05 +02:00
|
|
|
wined3d_context_gl_enter(context_gl);
|
2015-11-04 00:02:49 +01:00
|
|
|
|
2019-05-19 16:00:46 +02:00
|
|
|
if (!wined3d_context_gl_set_pixel_format(context_gl))
|
2010-03-14 21:53:23 +01:00
|
|
|
{
|
2018-08-22 19:43:00 +02:00
|
|
|
context_release(context);
|
2019-11-18 15:18:12 +01:00
|
|
|
|
|
|
|
if (context_gl->dc_is_private)
|
|
|
|
{
|
|
|
|
ERR("Failed to set pixel format %d on device context %p.\n", context_gl->pixel_format, context_gl->dc);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Failed to set pixel format %d on device context %p, trying backup DC.\n",
|
|
|
|
context_gl->pixel_format, context_gl->dc);
|
|
|
|
|
|
|
|
wined3d_release_dc(context_gl->window, context_gl->dc);
|
|
|
|
if (!(context_gl->dc = wined3d_swapchain_gl_get_backup_dc(swapchain_gl)))
|
|
|
|
{
|
|
|
|
ERR("Failed to retrieve the backup device context.\n");
|
2020-01-03 13:00:12 +01:00
|
|
|
return FALSE;
|
2019-11-18 15:18:12 +01:00
|
|
|
}
|
|
|
|
context_gl->dc_is_private = TRUE;
|
|
|
|
|
|
|
|
return wined3d_context_gl_create_wgl_ctx(context_gl, swapchain_gl);
|
2011-10-13 21:43:07 +02:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
share_ctx = device->context_count ? wined3d_context_gl(device->contexts[0])->gl_ctx : NULL;
|
2013-04-19 08:34:11 +02:00
|
|
|
if (gl_info->p_wglCreateContextAttribsARB)
|
2011-10-13 21:43:07 +02:00
|
|
|
{
|
2019-06-03 15:40:22 +02:00
|
|
|
if (!(ctx = context_create_wgl_attribs(gl_info, context_gl->dc, share_ctx)))
|
2018-08-22 19:43:00 +02:00
|
|
|
{
|
2019-11-18 15:18:11 +01:00
|
|
|
ERR("Failed to create a WGL context.\n");
|
2018-08-22 19:43:00 +02:00
|
|
|
context_release(context);
|
2019-11-18 15:18:11 +01:00
|
|
|
return FALSE;
|
2018-08-22 19:43:00 +02:00
|
|
|
}
|
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
|
|
|
{
|
2019-06-03 15:40:22 +02:00
|
|
|
if (!(ctx = wglCreateContext(context_gl->dc)))
|
2013-04-19 08:34:11 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to create a WGL context.\n");
|
2018-08-22 19:43:00 +02:00
|
|
|
context_release(context);
|
2019-11-18 15:18:11 +01:00
|
|
|
return FALSE;
|
2013-04-19 08:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2018-08-22 19:43:00 +02:00
|
|
|
context_release(context);
|
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());
|
2019-11-18 15:18:11 +01:00
|
|
|
return FALSE;
|
2009-07-15 12:21:17 +02:00
|
|
|
}
|
|
|
|
}
|
2007-08-08 03:09:38 +02:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
context_gl->dc_has_format = TRUE;
|
2019-06-06 14:51:05 +02:00
|
|
|
context_gl->needs_set = 1;
|
2019-11-18 15:18:11 +01:00
|
|
|
context_gl->valid = 1;
|
|
|
|
context_gl->gl_ctx = ctx;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wined3d_swapchain_gl *swapchain_gl)
|
|
|
|
{
|
|
|
|
struct wined3d_context *context = &context_gl->c;
|
|
|
|
const struct wined3d_d3d_info *d3d_info;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_device *device;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("context_gl %p, swapchain %p.\n", context_gl, swapchain_gl);
|
|
|
|
|
|
|
|
wined3d_context_init(&context_gl->c, &swapchain_gl->s);
|
|
|
|
|
|
|
|
device = context->device;
|
|
|
|
gl_info = &device->adapter->gl_info;
|
|
|
|
context_gl->gl_info = gl_info;
|
|
|
|
d3d_info = context->d3d_info;
|
|
|
|
|
|
|
|
context_gl->tid = GetCurrentThreadId();
|
|
|
|
context_gl->window = context->swapchain->win_handle;
|
|
|
|
if (context_gl->window == GetDesktopWindow())
|
|
|
|
{
|
|
|
|
TRACE("Swapchain is created on the desktop window, trying backup device context.\n");
|
|
|
|
context_gl->dc = NULL;
|
|
|
|
}
|
|
|
|
else if (!(context_gl->dc = GetDCEx(context_gl->window, 0, DCX_USESTYLE | DCX_CACHE)))
|
|
|
|
WARN("Failed to retrieve device context, trying swapchain backup.\n");
|
|
|
|
|
|
|
|
if (!context_gl->dc)
|
|
|
|
{
|
|
|
|
if (!(context_gl->dc = wined3d_swapchain_gl_get_backup_dc(swapchain_gl)))
|
|
|
|
{
|
|
|
|
ERR("Failed to retrieve a device context.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
context_gl->dc_is_private = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_init(&context_gl->fbo_list);
|
|
|
|
list_init(&context_gl->fbo_destroy_list);
|
|
|
|
|
|
|
|
list_init(&context_gl->occlusion_queries);
|
|
|
|
list_init(&context_gl->fences);
|
|
|
|
list_init(&context_gl->timestamp_queries);
|
|
|
|
list_init(&context_gl->so_statistics_queries);
|
|
|
|
list_init(&context_gl->pipeline_statistics_queries);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(context_gl->tex_unit_map); ++i)
|
|
|
|
context_gl->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(context_gl->rev_tex_unit_map); ++i)
|
|
|
|
context_gl->rev_tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
|
|
|
|
if (gl_info->limits.graphics_samplers >= WINED3D_MAX_COMBINED_SAMPLERS)
|
|
|
|
{
|
|
|
|
/* Initialize the texture unit mapping to a 1:1 mapping. */
|
|
|
|
unsigned int base, count;
|
|
|
|
|
|
|
|
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_PIXEL, &base, &count);
|
|
|
|
if (base + WINED3D_MAX_FRAGMENT_SAMPLERS > ARRAY_SIZE(context_gl->rev_tex_unit_map))
|
|
|
|
{
|
|
|
|
ERR("Unexpected texture unit base index %u.\n", base);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
for (i = 0; i < min(count, WINED3D_MAX_FRAGMENT_SAMPLERS); ++i)
|
|
|
|
{
|
|
|
|
context_gl->tex_unit_map[i] = base + i;
|
|
|
|
context_gl->rev_tex_unit_map[base + i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, WINED3D_SHADER_TYPE_VERTEX, &base, &count);
|
|
|
|
if (base + WINED3D_MAX_VERTEX_SAMPLERS > ARRAY_SIZE(context_gl->rev_tex_unit_map))
|
|
|
|
{
|
|
|
|
ERR("Unexpected texture unit base index %u.\n", base);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
for (i = 0; i < min(count, WINED3D_MAX_VERTEX_SAMPLERS); ++i)
|
|
|
|
{
|
|
|
|
context_gl->tex_unit_map[WINED3D_MAX_FRAGMENT_SAMPLERS + i] = base + i;
|
|
|
|
context_gl->rev_tex_unit_map[base + i] = WINED3D_MAX_FRAGMENT_SAMPLERS + i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(context_gl->texture_type = heap_calloc(gl_info->limits.combined_samplers,
|
|
|
|
sizeof(*context_gl->texture_type))))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!wined3d_context_gl_create_wgl_ctx(context_gl, swapchain_gl))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Set up the context defaults. */
|
|
|
|
|
|
|
|
context->render_offscreen = wined3d_resource_is_offscreen(&context->current_rt.texture->resource);
|
|
|
|
context_gl->draw_buffers_mask = context_generate_rt_mask(GL_BACK);
|
2010-03-14 21:53:24 +01:00
|
|
|
|
2019-08-05 15:09:54 +02:00
|
|
|
if (!wined3d_context_gl_set_current(context_gl))
|
2009-07-22 14:03:36 +02:00
|
|
|
{
|
2011-10-13 21:43:07 +02:00
|
|
|
ERR("Cannot activate context to set up defaults.\n");
|
2018-08-22 19:43:00 +02:00
|
|
|
context_release(context);
|
2019-11-18 15:18:11 +01:00
|
|
|
if (!wglDeleteContext(context_gl->gl_ctx))
|
|
|
|
ERR("wglDeleteContext(%p) failed, last error %#x.\n", context_gl->gl_ctx, GetLastError());
|
2019-06-03 15:40:22 +02:00
|
|
|
goto fail;
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2013-04-19 08:34:12 +02:00
|
|
|
if (context_debug_output_enabled(gl_info))
|
|
|
|
{
|
2018-08-22 19:43:00 +02:00
|
|
|
GL_EXTCALL(glDebugMessageCallback(wined3d_debug_callback, context));
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:08:40 +01:00
|
|
|
if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
|
2019-06-03 15:40:22 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGetIntegerv(GL_AUX_BUFFERS, &context_gl->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[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.
|
|
|
|
*/
|
2017-03-14 13:15:57 +01:00
|
|
|
for (i = 1; i < gl_info->limits.textures; ++i)
|
2009-10-22 10:09:54 +02:00
|
|
|
{
|
2019-06-05 14:24:04 +02:00
|
|
|
wined3d_context_gl_active_texture(context_gl, gl_info, i);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_SHADER_NV,
|
2017-03-14 13:15:57 +01:00
|
|
|
GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + i - 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";
|
2019-05-08 15:21:35 +02:00
|
|
|
GL_EXTCALL(glGenProgramsARB(1, &context_gl->dummy_arbfp_prog));
|
|
|
|
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, context_gl->dummy_arbfp_prog));
|
2018-08-22 19:43:00 +02:00
|
|
|
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
GL_PROGRAM_FORMAT_ASCII_ARB, strlen(dummy_program), dummy_program));
|
2009-05-07 11:40:44 +02:00
|
|
|
}
|
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
|
|
|
{
|
2017-03-14 13:15:57 +01:00
|
|
|
for (i = 0; i < gl_info->limits.textures; ++i)
|
2011-08-04 19:53:31 +02:00
|
|
|
{
|
2019-06-05 14:24:04 +02:00
|
|
|
wined3d_context_gl_active_texture(context_gl, gl_info, i);
|
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-12-07 12:43:01 +01:00
|
|
|
if (!(d3d_info->wined3d_creation_flags & WINED3D_NO_PRIMITIVE_RESTART))
|
|
|
|
{
|
|
|
|
if (gl_info->supported[ARB_ES3_COMPATIBILITY])
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
|
2017-03-08 12:07:23 +01:00
|
|
|
checkGLcall("enable GL_PRIMITIVE_RESTART_FIXED_INDEX");
|
2016-12-07 12:43:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("OpenGL implementation does not support GL_PRIMITIVE_RESTART_FIXED_INDEX.\n");
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 12:07:23 +01:00
|
|
|
if (!(d3d_info->wined3d_creation_flags & WINED3D_LEGACY_CUBEMAP_FILTERING)
|
|
|
|
&& gl_info->supported[ARB_SEAMLESS_CUBE_MAP])
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
|
|
|
checkGLcall("enable seamless cube map filtering");
|
|
|
|
}
|
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));
|
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. */
|
2018-10-26 15:13:06 +02:00
|
|
|
if (wined3d_device_gl(device)->dummy_textures.tex_2d)
|
2019-06-07 14:52:29 +02:00
|
|
|
wined3d_context_gl_bind_dummy_textures(context_gl);
|
2011-08-26 01:12:27 +02:00
|
|
|
|
2018-04-23 14:34:03 +02:00
|
|
|
/* Initialise all rectangles to avoid resetting unused ones later. */
|
|
|
|
gl_info->gl_ops.gl.p_glScissor(0, 0, 0, 0);
|
|
|
|
checkGLcall("glScissor");
|
|
|
|
|
2019-05-07 12:30:10 +02:00
|
|
|
return WINED3D_OK;
|
2019-06-03 15:40:22 +02:00
|
|
|
|
|
|
|
fail:
|
|
|
|
heap_free(context_gl->texture_type);
|
|
|
|
wined3d_release_dc(context_gl->window, context_gl->dc);
|
|
|
|
return E_FAIL;
|
2019-05-07 12:30:10 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
void wined3d_context_gl_destroy(struct wined3d_context_gl *context_gl)
|
2019-05-07 12:30:10 +02:00
|
|
|
{
|
2019-06-05 14:24:07 +02:00
|
|
|
struct wined3d_device *device = context_gl->c.device;
|
2019-05-07 12:30:10 +02:00
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
TRACE("Destroying context %p.\n", context_gl);
|
2019-05-07 12:30:10 +02:00
|
|
|
|
|
|
|
wined3d_from_cs(device->cs);
|
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
/* We delay destroying a context when it is active. The context_release()
|
|
|
|
* function invokes wined3d_context_gl_destroy() again while leaving the
|
|
|
|
* last level. */
|
2019-08-07 13:41:59 +02:00
|
|
|
if (context_gl->level)
|
2019-05-07 12:30:10 +02:00
|
|
|
{
|
2019-06-05 14:24:07 +02:00
|
|
|
TRACE("Delaying destruction of context %p.\n", context_gl);
|
|
|
|
context_gl->c.destroy_delayed = 1;
|
|
|
|
/* FIXME: Get rid of a pointer to swapchain from wined3d_context. */
|
|
|
|
context_gl->c.swapchain = NULL;
|
|
|
|
return;
|
2019-05-07 12:30:10 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
device_context_remove(device, &context_gl->c);
|
2019-05-07 12:30:10 +02:00
|
|
|
|
2019-06-07 14:52:27 +02:00
|
|
|
if (context_gl->c.current && context_gl->tid != GetCurrentThreadId())
|
2019-06-05 14:24:07 +02:00
|
|
|
{
|
|
|
|
struct wined3d_gl_info *gl_info;
|
2008-08-24 23:43:02 +02:00
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
/* Make a copy of gl_info for wined3d_context_gl_cleanup() use, the
|
|
|
|
* one in wined3d_adapter may go away in the meantime. */
|
|
|
|
gl_info = heap_alloc(sizeof(*gl_info));
|
2019-08-07 13:41:58 +02:00
|
|
|
*gl_info = *context_gl->gl_info;
|
|
|
|
context_gl->gl_info = gl_info;
|
2019-06-05 14:24:07 +02:00
|
|
|
context_gl->c.destroyed = 1;
|
2017-04-13 00:11:01 +02:00
|
|
|
|
2016-10-05 11:17:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
wined3d_context_gl_cleanup(context_gl);
|
|
|
|
TlsSetValue(context_get_tls_idx(), NULL);
|
|
|
|
heap_free(context_gl);
|
2007-02-12 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2019-05-09 16:41:09 +02:00
|
|
|
const unsigned int *wined3d_context_gl_get_tex_unit_mapping(const struct wined3d_context_gl *context_gl,
|
2017-03-14 13:15:58 +01:00
|
|
|
const struct wined3d_shader_version *shader_version, unsigned int *base, unsigned int *count)
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2017-03-14 13:15:58 +01:00
|
|
|
|
|
|
|
if (!shader_version)
|
|
|
|
{
|
|
|
|
*base = 0;
|
2019-02-20 21:53:57 +01:00
|
|
|
*count = WINED3D_MAX_TEXTURES;
|
2019-05-10 18:31:05 +02:00
|
|
|
return context_gl->tex_unit_map;
|
2017-03-14 13:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shader_version->major >= 4)
|
|
|
|
{
|
|
|
|
wined3d_gl_limits_get_texture_unit_range(&gl_info->limits, shader_version->type, base, count);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (shader_version->type)
|
|
|
|
{
|
|
|
|
case WINED3D_SHADER_TYPE_PIXEL:
|
|
|
|
*base = 0;
|
2019-02-20 21:53:58 +01:00
|
|
|
*count = WINED3D_MAX_FRAGMENT_SAMPLERS;
|
2017-03-14 13:15:58 +01:00
|
|
|
break;
|
|
|
|
case WINED3D_SHADER_TYPE_VERTEX:
|
2019-02-20 21:53:58 +01:00
|
|
|
*base = WINED3D_MAX_FRAGMENT_SAMPLERS;
|
2019-02-20 21:53:59 +01:00
|
|
|
*count = WINED3D_MAX_VERTEX_SAMPLERS;
|
2017-03-14 13:15:58 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unhandled shader type %#x.\n", shader_version->type);
|
|
|
|
*base = 0;
|
|
|
|
*count = 0;
|
|
|
|
}
|
|
|
|
|
2019-05-10 18:31:05 +02:00
|
|
|
return context_gl->tex_unit_map;
|
2017-03-14 13:15:58 +01:00
|
|
|
}
|
|
|
|
|
2019-05-20 23:41:06 +02:00
|
|
|
static void wined3d_context_gl_get_rt_size(const struct wined3d_context_gl *context_gl, SIZE *size)
|
2012-04-04 20:37:20 +02:00
|
|
|
{
|
2019-05-20 23:41:06 +02:00
|
|
|
const struct wined3d_texture *rt = context_gl->c.current_rt.texture;
|
2016-03-29 16:45:32 +02:00
|
|
|
unsigned int level;
|
2012-04-04 20:37:20 +02:00
|
|
|
|
2017-03-22 23:11:27 +01:00
|
|
|
if (rt->swapchain)
|
2012-04-04 20:37:20 +02:00
|
|
|
{
|
|
|
|
RECT window_size;
|
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
GetClientRect(context_gl->window, &window_size);
|
2012-04-04 20:37:20 +02:00
|
|
|
size->cx = window_size.right - window_size.left;
|
|
|
|
size->cy = window_size.bottom - window_size.top;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-20 23:41:06 +02:00
|
|
|
level = context_gl->c.current_rt.sub_resource_idx % rt->level_count;
|
2016-03-29 16:45:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-06-10 22:15:26 +02:00
|
|
|
void wined3d_context_gl_enable_clip_distances(struct wined3d_context_gl *context_gl, uint32_t enable_mask)
|
2017-12-02 10:24:43 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-06-10 22:15:26 +02:00
|
|
|
unsigned int clip_distance_count, i;
|
|
|
|
uint32_t disable_mask, current_mask;
|
2017-12-02 10:24:43 +01:00
|
|
|
|
2019-06-10 22:15:26 +02:00
|
|
|
clip_distance_count = gl_info->limits.user_clip_distances;
|
2017-12-02 10:24:43 +01:00
|
|
|
disable_mask = ~enable_mask;
|
|
|
|
enable_mask &= (1u << clip_distance_count) - 1;
|
|
|
|
disable_mask &= (1u << clip_distance_count) - 1;
|
2019-06-10 22:15:26 +02:00
|
|
|
current_mask = context_gl->c.clip_distance_mask;
|
|
|
|
context_gl->c.clip_distance_mask = enable_mask;
|
2017-12-02 10:24:43 +01:00
|
|
|
|
|
|
|
enable_mask &= ~current_mask;
|
2018-02-06 11:40:03 +01:00
|
|
|
while (enable_mask)
|
2017-12-02 10:24:43 +01:00
|
|
|
{
|
2018-02-06 11:40:03 +01:00
|
|
|
i = wined3d_bit_scan(&enable_mask);
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(GL_CLIP_DISTANCE0 + i);
|
2017-12-02 10:24:43 +01:00
|
|
|
}
|
|
|
|
disable_mask &= current_mask;
|
2018-02-06 11:40:03 +01:00
|
|
|
while (disable_mask)
|
2017-12-02 10:24:43 +01:00
|
|
|
{
|
2018-02-06 11:40:03 +01:00
|
|
|
i = wined3d_bit_scan(&disable_mask);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CLIP_DISTANCE0 + i);
|
2017-12-02 10:24:43 +01:00
|
|
|
}
|
|
|
|
checkGLcall("toggle clip distances");
|
|
|
|
}
|
|
|
|
|
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. */
|
2019-06-17 12:32:11 +02:00
|
|
|
static void wined3d_context_gl_apply_draw_buffers(struct wined3d_context_gl *context_gl, uint32_t rt_mask)
|
2008-08-03 21:17:51 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2020-03-24 17:35:23 +01:00
|
|
|
GLenum draw_buffers[WINED3D_MAX_RENDER_TARGETS];
|
2012-07-24 11:32:27 +02:00
|
|
|
|
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
|
|
|
}
|
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));
|
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)
|
2018-02-27 10:17:36 +01:00
|
|
|
draw_buffers[i] = GL_COLOR_ATTACHMENT0 + i;
|
2008-08-04 19:28:42 +02:00
|
|
|
else
|
2018-02-27 10:17:36 +01:00
|
|
|
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])
|
|
|
|
{
|
2018-02-27 10:17:36 +01:00
|
|
|
GL_EXTCALL(glDrawBuffers(i, draw_buffers));
|
2010-08-29 21:57:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-27 10:17:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDrawBuffer(draw_buffers[0]);
|
2008-08-04 19:28:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2018-02-27 10:17:36 +01:00
|
|
|
|
|
|
|
checkGLcall("apply draw buffers");
|
2008-08-03 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2019-05-15 15:32:56 +02:00
|
|
|
void wined3d_context_gl_set_draw_buffer(struct wined3d_context_gl *context_gl, GLenum buffer)
|
2009-12-10 21:41:52 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-05-19 16:00:43 +02:00
|
|
|
struct fbo_entry *current_fbo = context_gl->current_fbo;
|
2019-05-15 15:32:56 +02:00
|
|
|
uint32_t new_mask = context_generate_rt_mask(buffer);
|
|
|
|
uint32_t *current_mask;
|
2013-04-10 01:35:42 +02:00
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
current_mask = current_fbo ? ¤t_fbo->rt_mask : &context_gl->draw_buffers_mask;
|
2013-04-10 01:35:42 +02:00
|
|
|
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. */
|
2019-06-05 14:24:04 +02:00
|
|
|
void wined3d_context_gl_active_texture(struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_gl_info *gl_info, unsigned int unit)
|
2011-08-03 01:34:15 +02:00
|
|
|
{
|
2015-01-08 17:20:21 +01:00
|
|
|
GL_EXTCALL(glActiveTexture(GL_TEXTURE0 + unit));
|
|
|
|
checkGLcall("glActiveTexture");
|
2019-06-05 14:24:05 +02:00
|
|
|
context_gl->active_texture = unit;
|
2011-08-03 01:34:15 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 14:52:28 +02:00
|
|
|
void wined3d_context_gl_bind_bo(struct wined3d_context_gl *context_gl, GLenum binding, GLuint name)
|
2017-04-19 23:40:53 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2017-04-19 23:40:53 +02:00
|
|
|
|
|
|
|
if (binding == GL_ELEMENT_ARRAY_BUFFER)
|
2019-06-07 14:52:28 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_INDEXBUFFER);
|
2017-04-19 23:40:53 +02:00
|
|
|
|
|
|
|
GL_EXTCALL(glBindBuffer(binding, name));
|
|
|
|
}
|
|
|
|
|
2019-05-07 12:30:11 +02:00
|
|
|
void wined3d_context_gl_bind_texture(struct wined3d_context_gl *context_gl, GLenum target, GLuint name)
|
2011-08-26 01:12:26 +02:00
|
|
|
{
|
2019-05-07 12:30:11 +02:00
|
|
|
const struct wined3d_dummy_textures *textures = &wined3d_device_gl(context_gl->c.device)->dummy_textures;
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-05-07 12:30:11 +02:00
|
|
|
GLenum old_texture_type;
|
|
|
|
unsigned int unit;
|
2011-08-26 01:12:27 +02:00
|
|
|
|
2011-08-26 01:12:26 +02:00
|
|
|
if (name)
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(target, name);
|
2011-08-26 01:12:26 +02:00
|
|
|
else
|
2011-08-26 01:12:27 +02:00
|
|
|
target = GL_NONE;
|
|
|
|
|
2019-06-05 14:24:05 +02:00
|
|
|
unit = context_gl->active_texture;
|
2019-05-08 15:21:34 +02:00
|
|
|
old_texture_type = context_gl->texture_type[unit];
|
2011-08-26 01:12:27 +02:00
|
|
|
if (old_texture_type != target)
|
|
|
|
{
|
|
|
|
switch (old_texture_type)
|
|
|
|
{
|
|
|
|
case GL_NONE:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
2018-04-02 22:58:23 +02:00
|
|
|
case GL_TEXTURE_1D:
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, textures->tex_1d);
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_1D_ARRAY:
|
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D_ARRAY, textures->tex_1d_array);
|
|
|
|
break;
|
2011-08-26 01:12:27 +02:00
|
|
|
case GL_TEXTURE_2D:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, textures->tex_2d);
|
2011-08-26 01:12:27 +02:00
|
|
|
break;
|
2016-04-19 00:01:26 +02:00
|
|
|
case GL_TEXTURE_2D_ARRAY:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, textures->tex_2d_array);
|
2016-04-19 00:01:26 +02:00
|
|
|
break;
|
2011-08-26 01:12:27 +02:00
|
|
|
case GL_TEXTURE_RECTANGLE_ARB:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures->tex_rect);
|
2011-08-26 01:12:27 +02:00
|
|
|
break;
|
|
|
|
case GL_TEXTURE_CUBE_MAP:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP, textures->tex_cube);
|
2011-08-26 01:12:27 +02:00
|
|
|
break;
|
2017-02-10 12:26:54 +01:00
|
|
|
case GL_TEXTURE_CUBE_MAP_ARRAY:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textures->tex_cube_array);
|
2017-02-10 12:26:54 +01:00
|
|
|
break;
|
2011-08-26 01:12:27 +02:00
|
|
|
case GL_TEXTURE_3D:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, textures->tex_3d);
|
2011-08-26 01:12:27 +02:00
|
|
|
break;
|
2017-01-26 13:07:30 +01:00
|
|
|
case GL_TEXTURE_BUFFER:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_BUFFER, textures->tex_buffer);
|
2017-01-26 13:07:30 +01:00
|
|
|
break;
|
2018-02-15 13:49:35 +01:00
|
|
|
case GL_TEXTURE_2D_MULTISAMPLE:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textures->tex_2d_ms);
|
2018-02-15 13:49:35 +01:00
|
|
|
break;
|
|
|
|
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
|
2018-02-15 13:49:36 +01:00
|
|
|
gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, textures->tex_2d_ms_array);
|
2018-02-15 13:49:35 +01:00
|
|
|
break;
|
2011-08-26 01:12:27 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-05-08 15:21:34 +02:00
|
|
|
context_gl->texture_type[unit] = target;
|
2011-08-26 01:12:27 +02:00
|
|
|
}
|
2018-02-15 13:49:36 +01:00
|
|
|
|
|
|
|
checkGLcall("bind texture");
|
2011-08-26 01:12:26 +02:00
|
|
|
}
|
|
|
|
|
2019-06-10 22:15:28 +02:00
|
|
|
void *wined3d_context_gl_map_bo_address(struct wined3d_context_gl *context_gl,
|
2017-04-21 00:57:10 +02:00
|
|
|
const struct wined3d_bo_address *data, size_t size, GLenum binding, DWORD flags)
|
|
|
|
{
|
2017-06-16 16:01:04 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2017-04-21 00:57:10 +02:00
|
|
|
BYTE *memory;
|
|
|
|
|
|
|
|
if (!data->buffer_object)
|
|
|
|
return data->addr;
|
|
|
|
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2019-06-07 14:52:28 +02:00
|
|
|
wined3d_context_gl_bind_bo(context_gl, binding, data->buffer_object);
|
2017-04-21 00:57:10 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
|
|
|
|
{
|
2019-09-23 13:24:16 +02:00
|
|
|
memory = GL_EXTCALL(glMapBufferRange(binding, (INT_PTR)data->addr,
|
|
|
|
size, wined3d_resource_gl_map_flags(flags)));
|
2017-04-21 00:57:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memory = GL_EXTCALL(glMapBuffer(binding, wined3d_resource_gl_legacy_map_flags(flags)));
|
|
|
|
memory += (INT_PTR)data->addr;
|
|
|
|
}
|
|
|
|
|
2019-06-07 14:52:28 +02:00
|
|
|
wined3d_context_gl_bind_bo(context_gl, binding, 0);
|
2017-04-21 00:57:10 +02:00
|
|
|
checkGLcall("Map buffer object");
|
|
|
|
|
|
|
|
return memory;
|
|
|
|
}
|
|
|
|
|
2019-09-23 13:24:16 +02:00
|
|
|
void wined3d_context_gl_unmap_bo_address(struct wined3d_context_gl *context_gl, const struct wined3d_bo_address *data,
|
2020-02-27 13:31:10 +01:00
|
|
|
GLenum binding, unsigned int range_count, const struct wined3d_range *ranges)
|
2017-04-21 00:57:10 +02:00
|
|
|
{
|
2017-06-16 16:01:04 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-09-23 13:24:16 +02:00
|
|
|
unsigned int i;
|
2017-04-21 00:57:10 +02:00
|
|
|
|
|
|
|
if (!data->buffer_object)
|
|
|
|
return;
|
|
|
|
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2019-06-07 14:52:28 +02:00
|
|
|
wined3d_context_gl_bind_bo(context_gl, binding, data->buffer_object);
|
2019-09-23 13:24:16 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
|
|
|
|
{
|
|
|
|
for (i = 0; i < range_count; ++i)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glFlushMappedBufferRange(binding, (UINT_PTR)data->addr + ranges[i].offset, ranges[i].size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 00:57:10 +02:00
|
|
|
GL_EXTCALL(glUnmapBuffer(binding));
|
2019-06-07 14:52:28 +02:00
|
|
|
wined3d_context_gl_bind_bo(context_gl, binding, 0);
|
2017-04-21 00:57:10 +02:00
|
|
|
checkGLcall("Unmap buffer object");
|
|
|
|
}
|
|
|
|
|
2019-06-07 14:52:30 +02:00
|
|
|
void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
|
2017-08-04 19:53:47 +02:00
|
|
|
const struct wined3d_bo_address *dst, GLenum dst_binding,
|
|
|
|
const struct wined3d_bo_address *src, GLenum src_binding, size_t size)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
2020-02-27 13:31:10 +01:00
|
|
|
struct wined3d_range range;
|
2017-08-04 19:53:47 +02:00
|
|
|
BYTE *dst_ptr, *src_ptr;
|
|
|
|
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2017-08-04 19:53:47 +02:00
|
|
|
|
|
|
|
if (dst->buffer_object && src->buffer_object)
|
|
|
|
{
|
|
|
|
if (gl_info->supported[ARB_COPY_BUFFER])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_COPY_READ_BUFFER, src->buffer_object));
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_COPY_WRITE_BUFFER, dst->buffer_object));
|
|
|
|
GL_EXTCALL(glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
|
|
|
|
(GLintptr)src->addr, (GLintptr)dst->addr, size));
|
|
|
|
checkGLcall("direct buffer copy");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-10 22:15:28 +02:00
|
|
|
src_ptr = wined3d_context_gl_map_bo_address(context_gl, src, size, src_binding, WINED3D_MAP_READ);
|
|
|
|
dst_ptr = wined3d_context_gl_map_bo_address(context_gl, dst, size, dst_binding, WINED3D_MAP_WRITE);
|
2017-08-04 19:53:47 +02:00
|
|
|
|
|
|
|
memcpy(dst_ptr, src_ptr, size);
|
|
|
|
|
2019-09-23 13:24:16 +02:00
|
|
|
range.offset = 0;
|
|
|
|
range.size = size;
|
|
|
|
wined3d_context_gl_unmap_bo_address(context_gl, dst, dst_binding, 1, &range);
|
|
|
|
wined3d_context_gl_unmap_bo_address(context_gl, src, src_binding, 0, NULL);
|
2017-08-04 19:53:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!dst->buffer_object && src->buffer_object)
|
|
|
|
{
|
2019-06-07 14:52:28 +02:00
|
|
|
wined3d_context_gl_bind_bo(context_gl, src_binding, src->buffer_object);
|
2017-08-04 19:53:47 +02:00
|
|
|
GL_EXTCALL(glGetBufferSubData(src_binding, (GLintptr)src->addr, size, dst->addr));
|
|
|
|
checkGLcall("buffer download");
|
|
|
|
}
|
|
|
|
else if (dst->buffer_object && !src->buffer_object)
|
|
|
|
{
|
2019-06-07 14:52:28 +02:00
|
|
|
wined3d_context_gl_bind_bo(context_gl, dst_binding, dst->buffer_object);
|
2017-08-04 19:53:47 +02:00
|
|
|
GL_EXTCALL(glBufferSubData(dst_binding, (GLintptr)dst->addr, size, src->addr));
|
|
|
|
checkGLcall("buffer upload");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(dst->addr, src->addr, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 12:32:12 +02:00
|
|
|
static void wined3d_context_gl_set_render_offscreen(struct wined3d_context_gl *context_gl, BOOL offscreen)
|
2010-03-28 16:42:32 +02:00
|
|
|
{
|
2019-06-17 12:32:12 +02:00
|
|
|
if (context_gl->c.render_offscreen == offscreen)
|
2017-05-16 15:00:24 +02:00
|
|
|
return;
|
2010-03-28 16:42:32 +02:00
|
|
|
|
2019-06-17 12:32:12 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_VIEWPORT);
|
|
|
|
context_invalidate_state(&context_gl->c, STATE_SCISSORRECT);
|
2019-08-07 13:41:58 +02:00
|
|
|
if (!context_gl->gl_info->supported[ARB_CLIP_CONTROL])
|
2016-10-03 23:46:56 +02:00
|
|
|
{
|
2019-06-17 12:32:12 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_RASTERIZER);
|
|
|
|
context_invalidate_state(&context_gl->c, STATE_POINTSPRITECOORDORIGIN);
|
|
|
|
context_invalidate_state(&context_gl->c, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
|
2016-10-03 23:46:56 +02:00
|
|
|
}
|
2019-06-17 12:32:12 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN));
|
2019-08-07 13:41:58 +02:00
|
|
|
if (context_gl->gl_info->supported[ARB_FRAGMENT_COORD_CONVENTIONS])
|
2019-06-17 12:32:12 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL));
|
|
|
|
context_gl->c.render_offscreen = offscreen;
|
2010-03-28 16:42:32 +02:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:44 +02:00
|
|
|
GLenum wined3d_context_gl_get_offscreen_gl_buffer(const struct wined3d_context_gl *context_gl)
|
2016-02-29 18:19:30 +01:00
|
|
|
{
|
|
|
|
switch (wined3d_settings.offscreen_rendering_mode)
|
|
|
|
{
|
|
|
|
case ORM_FBO:
|
|
|
|
return GL_COLOR_ATTACHMENT0;
|
|
|
|
|
|
|
|
case ORM_BACKBUFFER:
|
2019-06-03 15:40:22 +02:00
|
|
|
return context_gl->aux_buffers > 0 ? GL_AUX0 : GL_BACK;
|
2016-02-29 18:19:30 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled offscreen rendering mode %#x.\n", wined3d_settings.offscreen_rendering_mode);
|
|
|
|
return GL_BACK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:19 +02:00
|
|
|
static uint32_t wined3d_context_gl_generate_rt_mask_no_fbo(const struct wined3d_context_gl *context_gl,
|
|
|
|
struct wined3d_resource *rt)
|
2011-06-21 18:28:36 +02:00
|
|
|
{
|
2018-03-14 09:09:13 +01:00
|
|
|
if (!rt || rt->format->id == WINED3DFMT_NULL)
|
2011-06-21 18:28:36 +02:00
|
|
|
return 0;
|
2018-03-14 09:09:13 +01:00
|
|
|
else if (rt->type != WINED3D_RTYPE_BUFFER && texture_from_resource(rt)->swapchain)
|
|
|
|
return context_generate_rt_mask_from_resource(rt);
|
2011-06-21 18:28:36 +02:00
|
|
|
else
|
2019-05-19 16:00:44 +02:00
|
|
|
return context_generate_rt_mask(wined3d_context_gl_get_offscreen_gl_buffer(context_gl));
|
2011-06-21 18:28:36 +02:00
|
|
|
}
|
|
|
|
|
2009-12-27 19:57:21 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2019-05-09 16:41:11 +02:00
|
|
|
void wined3d_context_gl_apply_blit_state(struct wined3d_context_gl *context_gl, const struct wined3d_device *device)
|
2009-07-23 10:54:36 +02:00
|
|
|
{
|
2019-05-09 16:41:11 +02:00
|
|
|
struct wined3d_context *context = &context_gl->c;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-06-03 15:40:19 +02:00
|
|
|
uint32_t rt_mask, *cur_mask;
|
2019-05-09 16:41:11 +02:00
|
|
|
struct wined3d_texture *rt;
|
2018-03-13 11:23:06 +01:00
|
|
|
unsigned int sampler;
|
|
|
|
SIZE rt_size;
|
|
|
|
|
|
|
|
TRACE("Setting up context %p for blitting.\n", context);
|
2011-06-06 17:44:43 +02:00
|
|
|
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2019-05-09 16:41:11 +02:00
|
|
|
rt = context->current_rt.texture;
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2019-05-15 15:32:54 +02:00
|
|
|
wined3d_context_gl_apply_fbo_state_blit(context_gl, GL_FRAMEBUFFER, &rt->resource,
|
2018-03-12 10:06:49 +01:00
|
|
|
context->current_rt.sub_resource_idx, NULL, 0, rt->resource.draw_binding);
|
2016-03-29 16:45:32 +02:00
|
|
|
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
|
|
|
|
{
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->current_fbo = NULL;
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, 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
|
|
|
|
{
|
2019-06-03 15:40:19 +02:00
|
|
|
rt_mask = wined3d_context_gl_generate_rt_mask_no_fbo(context_gl, &rt->resource);
|
2007-11-06 01:11:35 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
cur_mask = context_gl->current_fbo ? &context_gl->current_fbo->rt_mask : &context_gl->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
|
|
|
{
|
2019-06-17 12:32:11 +02:00
|
|
|
wined3d_context_gl_apply_draw_buffers(context_gl, 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)
|
2019-05-15 15:32:55 +02:00
|
|
|
wined3d_context_gl_check_fbo_status(context_gl, GL_FRAMEBUFFER);
|
2011-07-26 19:52:44 +02:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
2018-03-13 11:23:06 +01:00
|
|
|
|
2019-05-20 23:41:06 +02:00
|
|
|
wined3d_context_gl_get_rt_size(context_gl, &rt_size);
|
2018-03-13 11:23:06 +01:00
|
|
|
|
|
|
|
if (context->last_was_blit)
|
|
|
|
{
|
2019-06-05 14:24:06 +02:00
|
|
|
if (context_gl->blit_size.cx != rt_size.cx || context_gl->blit_size.cy != rt_size.cy)
|
2018-03-13 11:23:06 +01:00
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glViewport(0, 0, rt_size.cx, rt_size.cy);
|
2018-04-27 12:57:26 +02:00
|
|
|
context->viewport_count = WINED3D_MAX_VIEWPORTS;
|
2019-06-05 14:24:06 +02:00
|
|
|
context_gl->blit_size = rt_size;
|
2018-03-13 11:23:06 +01:00
|
|
|
/* No need to dirtify here, the states are still dirtified because
|
|
|
|
* they weren't applied since the last context_apply_blit_state()
|
|
|
|
* call. */
|
|
|
|
}
|
|
|
|
checkGLcall("blit state application");
|
|
|
|
TRACE("Context is already set up for blitting, nothing to do.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context->last_was_blit = TRUE;
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_SAMPLER_OBJECTS])
|
|
|
|
GL_EXTCALL(glBindSampler(0, 0));
|
2019-06-05 14:24:04 +02:00
|
|
|
wined3d_context_gl_active_texture(context_gl, gl_info, 0);
|
2018-03-13 11:23:06 +01:00
|
|
|
|
2019-05-10 18:31:05 +02:00
|
|
|
sampler = context_gl->rev_tex_unit_map[0];
|
2018-03-13 11:23:06 +01:00
|
|
|
if (sampler != WINED3D_UNMAPPED_STAGE)
|
|
|
|
{
|
2019-02-20 21:53:57 +01:00
|
|
|
if (sampler < WINED3D_MAX_TEXTURES)
|
2018-03-13 11:23:06 +01:00
|
|
|
{
|
|
|
|
context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + sampler));
|
|
|
|
context_invalidate_state(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP));
|
|
|
|
}
|
|
|
|
context_invalidate_state(context, STATE_SAMPLER(sampler));
|
|
|
|
}
|
2018-10-23 19:08:50 +02:00
|
|
|
context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING);
|
|
|
|
context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING);
|
2018-03-13 11:23:06 +01:00
|
|
|
|
|
|
|
if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHATESTENABLE));
|
|
|
|
}
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZENABLE));
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
|
2020-03-13 05:25:02 +01:00
|
|
|
gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2020-03-10 05:07:28 +01:00
|
|
|
context_invalidate_state(context, STATE_BLEND);
|
2018-03-13 11:23:06 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
|
2020-03-07 05:18:35 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
|
2020-03-06 02:28:10 +01:00
|
|
|
context_invalidate_state(context, STATE_RASTERIZER);
|
2018-03-13 11:23:06 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_STENCILENABLE));
|
|
|
|
if (gl_info->supported[ARB_POINT_SPRITE])
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_POINT_SPRITE_ARB);
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE));
|
|
|
|
}
|
2018-04-12 13:58:12 +02:00
|
|
|
if (gl_info->supported[ARB_FRAMEBUFFER_SRGB])
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_FRAMEBUFFER_SRGB);
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE));
|
|
|
|
}
|
2018-03-13 11:23:06 +01:00
|
|
|
|
|
|
|
context->last_was_rhw = TRUE;
|
|
|
|
context_invalidate_state(context, STATE_VDECL); /* because of last_was_rhw = TRUE */
|
|
|
|
|
2019-06-10 22:15:26 +02:00
|
|
|
wined3d_context_gl_enable_clip_distances(context_gl, 0);
|
2018-03-13 11:23:06 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_CLIPPING));
|
|
|
|
|
|
|
|
/* 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));
|
|
|
|
gl_info->gl_ops.gl.p_glViewport(0, 0, rt_size.cx, rt_size.cy);
|
2018-04-27 12:57:26 +02:00
|
|
|
context->viewport_count = WINED3D_MAX_VIEWPORTS;
|
2018-03-13 11:23:06 +01:00
|
|
|
context_invalidate_state(context, STATE_VIEWPORT);
|
|
|
|
|
|
|
|
device->shader_backend->shader_disable(device->shader_priv, context);
|
|
|
|
|
2019-06-05 14:24:06 +02:00
|
|
|
context_gl->blit_size = rt_size;
|
2018-03-13 11:23:06 +01:00
|
|
|
|
|
|
|
checkGLcall("blit state application");
|
|
|
|
}
|
|
|
|
|
2019-06-17 12:32:13 +02:00
|
|
|
static void wined3d_context_gl_apply_blit_projection(const struct wined3d_context_gl *context_gl,
|
|
|
|
unsigned int w, unsigned int h)
|
2018-03-13 11:23:06 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-03-13 11:23:06 +01:00
|
|
|
const GLdouble projection[] =
|
|
|
|
{
|
|
|
|
2.0 / w, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 2.0 / h, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 2.0, 0.0,
|
|
|
|
-1.0, -1.0, -1.0, 1.0,
|
|
|
|
};
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
|
|
|
|
gl_info->gl_ops.gl.p_glLoadMatrixd(projection);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup OpenGL states for fixed-function blitting. */
|
|
|
|
/* Context activation is done by the caller. */
|
2019-05-09 16:41:12 +02:00
|
|
|
void wined3d_context_gl_apply_ffp_blit_state(struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_device *device)
|
2018-03-13 11:23:06 +01:00
|
|
|
{
|
2019-05-09 16:41:12 +02:00
|
|
|
struct wined3d_context *context = &context_gl->c;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
2018-03-13 11:23:06 +01:00
|
|
|
unsigned int i, sampler;
|
|
|
|
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2018-03-13 11:23:06 +01:00
|
|
|
if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
|
|
|
|
ERR("Applying fixed-function state without legacy context support.\n");
|
|
|
|
|
|
|
|
if (context->last_was_ffp_blit)
|
|
|
|
{
|
|
|
|
SIZE rt_size;
|
|
|
|
|
2019-05-20 23:41:06 +02:00
|
|
|
wined3d_context_gl_get_rt_size(context_gl, &rt_size);
|
2019-06-05 14:24:06 +02:00
|
|
|
if (context_gl->blit_size.cx != rt_size.cx || context_gl->blit_size.cy != rt_size.cy)
|
2019-06-17 12:32:13 +02:00
|
|
|
wined3d_context_gl_apply_blit_projection(context_gl, rt_size.cx, rt_size.cy);
|
2019-05-09 16:41:11 +02:00
|
|
|
wined3d_context_gl_apply_blit_state(context_gl, device);
|
2018-03-13 11:23:06 +01:00
|
|
|
|
|
|
|
checkGLcall("ffp blit state application");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context->last_was_ffp_blit = TRUE;
|
|
|
|
|
2019-05-09 16:41:11 +02:00
|
|
|
wined3d_context_gl_apply_blit_state(context_gl, device);
|
2018-03-13 11:23:06 +01:00
|
|
|
|
|
|
|
/* Disable all textures. The caller can then bind a texture it wants to blit
|
|
|
|
* from. */
|
|
|
|
for (i = gl_info->limits.textures - 1; i > 0 ; --i)
|
|
|
|
{
|
2019-06-05 14:24:04 +02:00
|
|
|
wined3d_context_gl_active_texture(context_gl, gl_info, i);
|
2018-03-13 11:23:06 +01:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
|
2019-05-10 18:31:05 +02:00
|
|
|
sampler = context_gl->rev_tex_unit_map[i];
|
2018-03-13 11:23:06 +01:00
|
|
|
if (sampler != WINED3D_UNMAPPED_STAGE)
|
|
|
|
{
|
2019-02-20 21:53:57 +01:00
|
|
|
if (sampler < WINED3D_MAX_TEXTURES)
|
2018-03-13 11:23:06 +01:00
|
|
|
context_invalidate_state(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP));
|
|
|
|
context_invalidate_state(context, STATE_SAMPLER(sampler));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 14:24:04 +02:00
|
|
|
wined3d_context_gl_active_texture(context_gl, gl_info, 0);
|
2018-03-13 11:23:06 +01:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
|
|
|
|
gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.0f);
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
|
|
|
|
gl_info->gl_ops.gl.p_glLoadIdentity();
|
|
|
|
|
|
|
|
/* Setup transforms. */
|
|
|
|
gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
|
|
|
|
gl_info->gl_ops.gl.p_glLoadIdentity();
|
|
|
|
context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
|
2019-06-17 12:32:13 +02:00
|
|
|
wined3d_context_gl_apply_blit_projection(context_gl, context_gl->blit_size.cx, context_gl->blit_size.cy);
|
2018-03-13 11:23:06 +01:00
|
|
|
context_invalidate_state(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
|
|
|
|
|
|
|
|
/* Other misc states. */
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_LIGHTING));
|
2019-05-08 15:21:36 +02:00
|
|
|
gl_info->p_glDisableWINE(GL_FOG);
|
2018-03-13 11:23:06 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_FOGENABLE));
|
|
|
|
|
|
|
|
if (gl_info->supported[EXT_SECONDARY_COLOR])
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_COLOR_SUM_EXT);
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SPECULARENABLE));
|
|
|
|
}
|
|
|
|
checkGLcall("ffp blit state application");
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
2007-07-09 16:57:58 +02:00
|
|
|
|
2018-03-01 19:36:52 +01:00
|
|
|
static BOOL have_framebuffer_attachment(unsigned int rt_count, struct wined3d_rendertarget_view * const *rts,
|
2014-08-22 12:32:01 +02:00
|
|
|
const struct wined3d_rendertarget_view *ds)
|
2011-01-26 19:45:02 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2018-03-01 19:36:52 +01:00
|
|
|
if (ds)
|
|
|
|
return TRUE;
|
2011-01-26 19:45:02 +01: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)
|
2011-01-26 19:45:03 +01:00
|
|
|
return TRUE;
|
2011-01-26 19:45:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2019-05-14 12:56:23 +02:00
|
|
|
BOOL wined3d_context_gl_apply_clear_state(struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_state *state, unsigned int rt_count, const struct wined3d_fb_state *fb)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2018-02-25 23:23:33 +01:00
|
|
|
struct wined3d_rendertarget_view * const *rts = fb->render_targets;
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2015-05-22 10:11:22 +02:00
|
|
|
struct wined3d_rendertarget_view *dsv = fb->depth_stencil;
|
2019-06-03 15:40:19 +02:00
|
|
|
uint32_t rt_mask = 0, *cur_mask;
|
2017-04-06 11:47:50 +02:00
|
|
|
unsigned int i;
|
2008-04-06 00:49:00 +02:00
|
|
|
|
2020-03-26 13:25:57 +01:00
|
|
|
if (isStateDirty(&context_gl->c, STATE_FRAMEBUFFER) || fb != &state->fb
|
2016-04-06 19:12:03 +02:00
|
|
|
|| rt_count != gl_info->limits.buffers)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2018-03-01 19:36:52 +01:00
|
|
|
if (!have_framebuffer_attachment(rt_count, rts, dsv))
|
|
|
|
{
|
|
|
|
WARN("Invalid render target config, need at least one attachment.\n");
|
2011-06-08 00:49:58 +02:00
|
|
|
return FALSE;
|
2018-03-01 19:36:52 +01:00
|
|
|
}
|
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
|
|
|
{
|
2018-03-12 10:06:48 +01:00
|
|
|
struct wined3d_rendertarget_info ds_info = {{0}};
|
|
|
|
|
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
|
|
|
{
|
2019-05-19 16:00:43 +02:00
|
|
|
memset(context_gl->blit_targets, 0, sizeof(context_gl->blit_targets));
|
2011-06-08 00:49:58 +02:00
|
|
|
for (i = 0; i < rt_count; ++i)
|
|
|
|
{
|
2017-04-06 11:47:50 +02:00
|
|
|
if (rts[i])
|
|
|
|
{
|
2018-11-13 14:10:16 +01:00
|
|
|
struct wined3d_rendertarget_view_gl *rtv_gl = wined3d_rendertarget_view_gl(rts[i]);
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->blit_targets[i].gl_view = rtv_gl->gl_view;
|
|
|
|
context_gl->blit_targets[i].resource = rtv_gl->v.resource;
|
|
|
|
context_gl->blit_targets[i].sub_resource_idx = rtv_gl->v.sub_resource_idx;
|
|
|
|
context_gl->blit_targets[i].layer_count = rtv_gl->v.layer_count;
|
2017-04-06 11:47:50 +02:00
|
|
|
}
|
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-06-08 00:49:58 +02:00
|
|
|
}
|
2018-03-12 10:06:48 +01:00
|
|
|
|
|
|
|
if (dsv)
|
|
|
|
{
|
2018-11-13 14:10:16 +01:00
|
|
|
struct wined3d_rendertarget_view_gl *dsv_gl = wined3d_rendertarget_view_gl(dsv);
|
|
|
|
ds_info.gl_view = dsv_gl->gl_view;
|
|
|
|
ds_info.resource = dsv_gl->v.resource;
|
|
|
|
ds_info.sub_resource_idx = dsv_gl->v.sub_resource_idx;
|
|
|
|
ds_info.layer_count = dsv_gl->v.layer_count;
|
2018-03-12 10:06:48 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
wined3d_context_gl_apply_fbo_state(context_gl, GL_FRAMEBUFFER, context_gl->blit_targets, &ds_info,
|
|
|
|
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
|
|
|
{
|
2019-05-17 13:45:14 +02:00
|
|
|
wined3d_context_gl_apply_fbo_state(context_gl, GL_FRAMEBUFFER, NULL, &ds_info,
|
2015-05-22 10:11:22 +02:00
|
|
|
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 */
|
2019-05-14 12:56:23 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_FRAMEBUFFER);
|
2010-07-23 11:31:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-03 15:40:19 +02:00
|
|
|
rt_mask = wined3d_context_gl_generate_rt_mask_no_fbo(context_gl, rt_count ? rts[0]->resource : 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
|
|
|
|
{
|
2019-06-03 15:40:19 +02:00
|
|
|
rt_mask = wined3d_context_gl_generate_rt_mask_no_fbo(context_gl, rt_count ? rts[0]->resource : NULL);
|
2011-05-24 22:24:12 +02:00
|
|
|
}
|
2007-07-09 16:57:58 +02:00
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
cur_mask = context_gl->current_fbo ? &context_gl->current_fbo->rt_mask : &context_gl->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
|
|
|
{
|
2019-06-17 12:32:11 +02:00
|
|
|
wined3d_context_gl_apply_draw_buffers(context_gl, rt_mask);
|
2012-03-28 13:52:11 +02:00
|
|
|
*cur_mask = rt_mask;
|
2019-05-14 12:56:23 +02:00
|
|
|
context_invalidate_state(&context_gl->c, 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)
|
2019-05-15 15:32:55 +02:00
|
|
|
wined3d_context_gl_check_fbo_status(context_gl, GL_FRAMEBUFFER);
|
2011-04-08 20:22:52 +02:00
|
|
|
|
2019-05-14 12:56:23 +02:00
|
|
|
context_gl->c.last_was_blit = FALSE;
|
|
|
|
context_gl->c.last_was_ffp_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
|
|
|
{
|
2020-03-18 14:01:25 +01:00
|
|
|
if (needs_srgb_write(context_gl->c.d3d_info, 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);
|
2019-05-14 12:56:23 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE));
|
2015-11-27 20:39:35 +01:00
|
|
|
}
|
|
|
|
checkGLcall("setting up state for clear");
|
2007-02-12 19:18:36 +01:00
|
|
|
|
2020-03-10 05:07:28 +01:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_BLEND);
|
2020-03-07 05:18:35 +01:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_RASTERIZER);
|
2019-05-14 12:56:23 +02:00
|
|
|
context_invalidate_state(&context_gl->c, 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
|
|
|
|
2019-06-03 15:40:20 +02:00
|
|
|
static uint32_t find_draw_buffers_mask(const struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2020-03-26 13:25:57 +01:00
|
|
|
struct wined3d_rendertarget_view * const *rts = state->fb.render_targets;
|
2013-10-09 22:57:45 +02:00
|
|
|
struct wined3d_shader *ps = state->shader[WINED3D_SHADER_TYPE_PIXEL];
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-03-03 19:55:20 +01:00
|
|
|
unsigned int rt_mask, mask;
|
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)
|
2019-06-03 15:40:19 +02:00
|
|
|
return wined3d_context_gl_generate_rt_mask_no_fbo(context_gl, rts[0]->resource);
|
2019-06-03 15:40:20 +02:00
|
|
|
else if (!context_gl->c.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;
|
2019-03-03 19:55:20 +01:00
|
|
|
rt_mask &= (1u << gl_info->limits.buffers) - 1;
|
2020-03-18 01:30:38 +01:00
|
|
|
if (state->blend_state && state->blend_state->dual_source)
|
|
|
|
rt_mask = 1;
|
2018-02-28 12:12:37 +01:00
|
|
|
|
|
|
|
mask = rt_mask;
|
|
|
|
while (mask)
|
2011-07-02 11:24:37 +02:00
|
|
|
{
|
2018-02-28 12:12:37 +01:00
|
|
|
i = wined3d_bit_scan(&mask);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2019-05-17 13:45:14 +02:00
|
|
|
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
|
2019-06-03 15:40:20 +02:00
|
|
|
uint32_t rt_mask = find_draw_buffers_mask(context_gl, state);
|
2020-03-26 13:25:57 +01:00
|
|
|
const struct wined3d_fb_state *fb = &state->fb;
|
2018-03-01 19:36:54 +01:00
|
|
|
DWORD color_location = 0;
|
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)
|
|
|
|
{
|
2018-03-12 10:06:48 +01:00
|
|
|
struct wined3d_rendertarget_info ds_info = {{0}};
|
|
|
|
|
2010-05-04 20:39:52 +02:00
|
|
|
if (!context->render_offscreen)
|
|
|
|
{
|
2019-05-17 13:45:14 +02:00
|
|
|
wined3d_context_gl_apply_fbo_state(context_gl, GL_FRAMEBUFFER, NULL, &ds_info,
|
2015-05-22 10:11:22 +02:00
|
|
|
WINED3D_LOCATION_DRAWABLE, WINED3D_LOCATION_DRAWABLE);
|
2010-05-04 20:39:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-13 14:10:16 +01:00
|
|
|
const struct wined3d_rendertarget_view_gl *view_gl;
|
2014-08-21 09:55:55 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
memset(context_gl->blit_targets, 0, sizeof(context_gl->blit_targets));
|
2019-08-07 13:41:58 +02:00
|
|
|
for (i = 0; i < context_gl->gl_info->limits.buffers; ++i)
|
2014-08-21 09:55:55 +02:00
|
|
|
{
|
2018-03-01 19:36:54 +01:00
|
|
|
if (!fb->render_targets[i])
|
|
|
|
continue;
|
|
|
|
|
2018-11-13 14:10:16 +01:00
|
|
|
view_gl = wined3d_rendertarget_view_gl(fb->render_targets[i]);
|
2019-05-19 16:00:43 +02:00
|
|
|
context_gl->blit_targets[i].gl_view = view_gl->gl_view;
|
|
|
|
context_gl->blit_targets[i].resource = view_gl->v.resource;
|
|
|
|
context_gl->blit_targets[i].sub_resource_idx = view_gl->v.sub_resource_idx;
|
|
|
|
context_gl->blit_targets[i].layer_count = view_gl->v.layer_count;
|
2018-03-01 19:36:54 +01:00
|
|
|
|
|
|
|
if (!color_location)
|
2018-11-13 14:10:16 +01:00
|
|
|
color_location = view_gl->v.resource->draw_binding;
|
2014-08-21 09:55:55 +02:00
|
|
|
}
|
2018-03-12 10:06:48 +01:00
|
|
|
|
|
|
|
if (fb->depth_stencil)
|
|
|
|
{
|
2018-11-13 14:10:16 +01:00
|
|
|
view_gl = wined3d_rendertarget_view_gl(fb->depth_stencil);
|
|
|
|
ds_info.gl_view = view_gl->gl_view;
|
|
|
|
ds_info.resource = view_gl->v.resource;
|
|
|
|
ds_info.sub_resource_idx = view_gl->v.sub_resource_idx;
|
|
|
|
ds_info.layer_count = view_gl->v.layer_count;
|
2018-03-12 10:06:48 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
wined3d_context_gl_apply_fbo_state(context_gl, GL_FRAMEBUFFER, context_gl->blit_targets, &ds_info,
|
2018-03-01 19:36:54 +01:00
|
|
|
color_location, 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
|
|
|
}
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
cur_mask = context_gl->current_fbo ? &context_gl->current_fbo->rt_mask : &context_gl->draw_buffers_mask;
|
2012-03-28 13:52:11 +02:00
|
|
|
if (rt_mask != *cur_mask)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2019-06-17 12:32:11 +02:00
|
|
|
wined3d_context_gl_apply_draw_buffers(context_gl, 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
|
|
|
|
2019-05-09 21:08:19 +02:00
|
|
|
static void wined3d_context_gl_map_stage(struct wined3d_context_gl *context_gl, unsigned int stage, unsigned int unit)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-05-10 18:31:05 +02:00
|
|
|
unsigned int i = context_gl->rev_tex_unit_map[unit];
|
|
|
|
unsigned int j = context_gl->tex_unit_map[stage];
|
2013-09-16 12:43:18 +02:00
|
|
|
|
2015-11-12 23:06:42 +01:00
|
|
|
TRACE("Mapping stage %u to unit %u.\n", stage, unit);
|
2019-05-10 18:31:05 +02:00
|
|
|
context_gl->tex_unit_map[stage] = unit;
|
2013-09-16 12:43:18 +02:00
|
|
|
if (i != WINED3D_UNMAPPED_STAGE && i != stage)
|
2019-05-10 18:31:05 +02:00
|
|
|
context_gl->tex_unit_map[i] = WINED3D_UNMAPPED_STAGE;
|
2013-09-16 12:43:18 +02:00
|
|
|
|
2019-05-10 18:31:05 +02:00
|
|
|
context_gl->rev_tex_unit_map[unit] = stage;
|
2013-09-16 12:43:18 +02:00
|
|
|
if (j != WINED3D_UNMAPPED_STAGE && j != unit)
|
2019-05-10 18:31:05 +02:00
|
|
|
context_gl->rev_tex_unit_map[j] = WINED3D_UNMAPPED_STAGE;
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2019-02-20 21:53:57 +01:00
|
|
|
for (i = 0; i < WINED3D_MAX_TEXTURES; ++i)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
|
|
|
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)
|
2019-02-20 21:53:57 +01:00
|
|
|
&& i < WINED3D_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
|
|
|
}
|
|
|
|
|
2019-05-09 21:08:20 +02:00
|
|
|
static void wined3d_context_gl_map_fixed_function_samplers(struct wined3d_context_gl *context_gl,
|
2013-09-16 12:43:18 +02:00
|
|
|
const struct wined3d_state *state)
|
|
|
|
{
|
2019-05-09 21:08:20 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context_gl->c.d3d_info;
|
2013-09-16 12:43:18 +02:00
|
|
|
unsigned int i, tex;
|
|
|
|
WORD ffu_map;
|
|
|
|
|
2019-05-09 21:08:20 +02:00
|
|
|
ffu_map = context_gl->c.fixed_function_usage_map;
|
2013-09-16 12:43:18 +02:00
|
|
|
|
|
|
|
if (d3d_info->limits.ffp_textures == d3d_info->limits.ffp_blend_stages
|
2019-05-09 21:08:20 +02:00
|
|
|
|| context_gl->c.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;
|
|
|
|
|
2019-05-10 18:31:05 +02:00
|
|
|
if (context_gl->tex_unit_map[i] != i)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-05-09 21:08:19 +02:00
|
|
|
wined3d_context_gl_map_stage(context_gl, i, i);
|
2019-05-09 21:08:20 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_SAMPLER(i));
|
|
|
|
context_invalidate_texture_stage(&context_gl->c, i);
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now work out the mapping */
|
|
|
|
tex = 0;
|
|
|
|
for (i = 0; ffu_map; ffu_map >>= 1, ++i)
|
|
|
|
{
|
|
|
|
if (!(ffu_map & 1))
|
|
|
|
continue;
|
|
|
|
|
2019-05-10 18:31:05 +02:00
|
|
|
if (context_gl->tex_unit_map[i] != tex)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-05-09 21:08:19 +02:00
|
|
|
wined3d_context_gl_map_stage(context_gl, i, tex);
|
2019-05-09 21:08:20 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_SAMPLER(i));
|
|
|
|
context_invalidate_texture_stage(&context_gl->c, i);
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
++tex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 21:08:21 +02:00
|
|
|
static void wined3d_context_gl_map_psamplers(struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-05-09 21:08:21 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context_gl->c.d3d_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
|
|
|
|
2019-02-20 21:53:58 +01:00
|
|
|
for (i = 0; i < WINED3D_MAX_FRAGMENT_SAMPLERS; ++i)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-05-10 18:31:05 +02:00
|
|
|
if (resource_info[i].type && context_gl->tex_unit_map[i] != i)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-05-09 21:08:19 +02:00
|
|
|
wined3d_context_gl_map_stage(context_gl, i, i);
|
2019-05-09 21:08:21 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_SAMPLER(i));
|
2013-09-16 12:43:18 +02:00
|
|
|
if (i < d3d_info->limits.ffp_blend_stages)
|
2019-05-09 21:08:21 +02:00
|
|
|
context_invalidate_texture_stage(&context_gl->c, i);
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 21:08:23 +02:00
|
|
|
static BOOL wined3d_context_gl_unit_free_for_vs(const struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_shader_resource_info *ps_resource_info, unsigned int unit)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-05-10 18:31:05 +02:00
|
|
|
unsigned int current_mapping = context_gl->rev_tex_unit_map[unit];
|
2013-09-16 12:43:18 +02:00
|
|
|
|
|
|
|
/* Not currently used */
|
|
|
|
if (current_mapping == WINED3D_UNMAPPED_STAGE)
|
|
|
|
return TRUE;
|
|
|
|
|
2019-02-20 21:53:58 +01:00
|
|
|
if (current_mapping < WINED3D_MAX_FRAGMENT_SAMPLERS)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
|
|
|
/* 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 */
|
2019-05-09 21:08:23 +02:00
|
|
|
return current_mapping >= WINED3D_MAX_TEXTURES
|
|
|
|
|| !(context_gl->c.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
|
|
|
}
|
|
|
|
|
2019-05-09 21:08:22 +02:00
|
|
|
static void wined3d_context_gl_map_vsamplers(struct wined3d_context_gl *context_gl,
|
|
|
|
BOOL ps, const struct wined3d_state *state)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
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;
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-02-20 21:54:00 +01:00
|
|
|
int start = min(WINED3D_MAX_COMBINED_SAMPLERS, gl_info->limits.graphics_samplers) - 1;
|
2013-09-16 12:43:18 +02:00
|
|
|
int i;
|
|
|
|
|
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
|
|
|
|
2019-02-20 21:53:59 +01:00
|
|
|
for (i = 0; i < WINED3D_MAX_VERTEX_SAMPLERS; ++i)
|
2014-12-03 10:28:09 +01:00
|
|
|
{
|
2019-02-20 21:53:58 +01:00
|
|
|
DWORD vsampler_idx = i + WINED3D_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)
|
|
|
|
{
|
2019-05-09 21:08:23 +02:00
|
|
|
if (wined3d_context_gl_unit_free_for_vs(context_gl, ps_resource_info, start))
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-05-10 18:31:05 +02:00
|
|
|
if (context_gl->tex_unit_map[vsampler_idx] != start)
|
2015-11-12 23:06:42 +01:00
|
|
|
{
|
2019-05-09 21:08:19 +02:00
|
|
|
wined3d_context_gl_map_stage(context_gl, vsampler_idx, start);
|
2019-05-09 21:08:22 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_SAMPLER(vsampler_idx));
|
2015-11-12 23:06:42 +01:00
|
|
|
}
|
2013-09-16 12:43:18 +02:00
|
|
|
|
|
|
|
--start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
--start;
|
|
|
|
}
|
2019-05-10 18:31:05 +02:00
|
|
|
if (context_gl->tex_unit_map[vsampler_idx] == WINED3D_UNMAPPED_STAGE)
|
2015-11-12 23:06:42 +01:00
|
|
|
WARN("Couldn't find a free texture unit for vertex sampler %u.\n", i);
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 18:31:03 +02:00
|
|
|
static void wined3d_context_gl_update_tex_unit_map(struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_state *state)
|
2013-09-16 12:43:18 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2013-09-16 12:43:18 +02:00
|
|
|
BOOL vs = use_vs(state);
|
|
|
|
BOOL ps = use_ps(state);
|
2015-11-12 23:06:42 +01:00
|
|
|
|
2017-02-21 13:24:47 +01:00
|
|
|
if (!ps)
|
2019-05-10 18:31:03 +02:00
|
|
|
context_update_fixed_function_usage_map(&context_gl->c, state);
|
2017-02-21 13:24:47 +01:00
|
|
|
|
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. */
|
|
|
|
|
2019-02-20 21:54:00 +01:00
|
|
|
if (gl_info->limits.graphics_samplers >= WINED3D_MAX_COMBINED_SAMPLERS)
|
2017-02-21 13:24:47 +01:00
|
|
|
return;
|
|
|
|
|
2013-09-16 12:43:18 +02:00
|
|
|
if (ps)
|
2019-05-09 21:08:21 +02:00
|
|
|
wined3d_context_gl_map_psamplers(context_gl, state);
|
2013-09-16 12:43:18 +02:00
|
|
|
else
|
2019-05-09 21:08:20 +02:00
|
|
|
wined3d_context_gl_map_fixed_function_samplers(context_gl, state);
|
2013-09-16 12:43:18 +02:00
|
|
|
|
|
|
|
if (vs)
|
2019-05-09 21:08:22 +02:00
|
|
|
wined3d_context_gl_map_vsamplers(context_gl, ps, state);
|
2013-09-16 12:43:18 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-05-19 16:00:43 +02:00
|
|
|
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
|
2019-06-03 15:40:20 +02:00
|
|
|
uint32_t rt_mask, *cur_mask;
|
2011-07-02 11:24:37 +02:00
|
|
|
|
|
|
|
if (isStateDirty(context, STATE_FRAMEBUFFER)) return;
|
|
|
|
|
2019-05-19 16:00:43 +02:00
|
|
|
cur_mask = context_gl->current_fbo ? &context_gl->current_fbo->rt_mask : &context_gl->draw_buffers_mask;
|
2019-06-03 15:40:20 +02:00
|
|
|
rt_mask = find_draw_buffers_mask(context_gl, state);
|
2012-03-28 13:52:11 +02:00
|
|
|
if (rt_mask != *cur_mask)
|
2011-04-08 20:22:52 +02:00
|
|
|
{
|
2019-06-17 12:32:11 +02:00
|
|
|
wined3d_context_gl_apply_draw_buffers(context_gl, 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
|
|
|
|
{
|
2017-05-24 11:22:10 +02:00
|
|
|
WARN("Unsupported input stream [usage=%s, usage_idx=%u].\n", debug_d3ddeclusage(usage), usage_idx);
|
|
|
|
*regnum = ~0u;
|
2013-09-12 12:23:29 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2017-03-06 10:45:23 +01:00
|
|
|
void wined3d_stream_info_from_declaration(struct wined3d_stream_info *stream_info,
|
2019-03-13 14:48:15 +01:00
|
|
|
const struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info)
|
2013-09-12 12:23:29 +02:00
|
|
|
{
|
|
|
|
/* We need to deal with frequency data! */
|
|
|
|
struct wined3d_vertex_declaration *declaration = state->vertex_declaration;
|
2017-03-06 10:45:23 +01:00
|
|
|
BOOL generic_attributes = 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
|
|
|
|
2019-03-13 14:48:15 +01:00
|
|
|
if (!d3d_info->vertex_bgra && element->format->id == WINED3DFMT_B8G8R8A8_UNORM)
|
2013-09-12 12:23:29 +02:00
|
|
|
{
|
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;
|
2014-07-14 10:04:22 +02:00
|
|
|
DWORD prev_all_vbo = stream_info->all_vbo;
|
|
|
|
unsigned int i;
|
|
|
|
WORD map;
|
|
|
|
|
2019-03-13 14:48:15 +01:00
|
|
|
wined3d_stream_info_from_declaration(stream_info, state, d3d_info);
|
2014-07-14 10:04:22 +02:00
|
|
|
|
|
|
|
stream_info->all_vbo = 1;
|
2017-07-09 13:25:49 +02:00
|
|
|
context->buffer_fence_count = 0;
|
2013-09-12 12:23:29 +02:00
|
|
|
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;
|
2016-10-16 21:46:47 +02:00
|
|
|
element->data.addr += (ULONG_PTR)wined3d_buffer_load_sysmem(buffer, context);
|
2014-07-14 10:04:22 +02:00
|
|
|
if ((UINT_PTR)element->data.addr < -state->load_base_vertex_index * element->stride)
|
|
|
|
FIXME("System memory vertex data load offset is negative!\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-16 21:46:46 +02:00
|
|
|
wined3d_buffer_load(buffer, context, state);
|
2016-10-20 12:50:57 +02:00
|
|
|
wined3d_buffer_get_memory(buffer, &data, buffer->locations);
|
2014-07-14 10:04:22 +02:00
|
|
|
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;
|
|
|
|
|
2017-07-09 13:25:49 +02:00
|
|
|
if (buffer->fence)
|
|
|
|
context->buffer_fences[context->buffer_fence_count++] = buffer->fence;
|
2013-09-12 12:23:29 +02:00
|
|
|
|
2018-10-23 10:48:38 +02:00
|
|
|
TRACE("Load array %u %s.\n", i, debug_bo_address(&element->data));
|
2014-07-14 10:04:22 +02:00
|
|
|
}
|
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;
|
|
|
|
|
2019-08-05 15:09:57 +02:00
|
|
|
if (!use_vs(state))
|
2013-09-12 12:23:29 +02:00
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
WORD slow_mask = -!d3d_info->ffp_generic_attributes & (1u << WINED3D_FFP_PSIZE);
|
2019-08-05 15:09:56 +02:00
|
|
|
slow_mask |= -(!d3d_info->vertex_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;
|
|
|
|
|
2019-10-31 14:23:40 +01:00
|
|
|
if (wined3d_resource_check_fbo_attached(state, &texture->resource, NULL))
|
2019-10-23 18:44:58 +02:00
|
|
|
context->uses_fbo_attached_resources = 1;
|
|
|
|
|
2019-02-20 11:07:11 +01:00
|
|
|
wined3d_texture_load(texture, context, is_srgb_enabled(state->sampler_states[idx]));
|
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))
|
|
|
|
{
|
2019-02-20 21:53:59 +01:00
|
|
|
for (i = 0; i < WINED3D_MAX_VERTEX_SAMPLERS; ++i)
|
2013-09-16 12:43:19 +02:00
|
|
|
{
|
2014-12-03 10:28:11 +01:00
|
|
|
if (state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.resource_info[i].type)
|
2019-02-20 21:53:58 +01:00
|
|
|
context_preload_texture(context, state, WINED3D_MAX_FRAGMENT_SAMPLERS + i);
|
2013-09-16 12:43:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_ps(state))
|
|
|
|
{
|
2019-02-20 21:53:58 +01:00
|
|
|
for (i = 0; i < WINED3D_MAX_FRAGMENT_SAMPLERS; ++i)
|
2013-09-16 12:43:19 +02:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-06 14:12:14 +01:00
|
|
|
static void context_load_shader_resources(struct wined3d_context *context, const struct wined3d_state *state,
|
|
|
|
unsigned int shader_mask)
|
2015-08-18 11:24:10 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2017-02-06 14:12:14 +01:00
|
|
|
if (!(shader_mask & (1u << i)))
|
|
|
|
continue;
|
|
|
|
|
2015-08-18 11:24:10 +02:00
|
|
|
if (!(shader = state->shader[i]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < WINED3D_MAX_CBS; ++j)
|
|
|
|
{
|
|
|
|
if (state->cb[i][j])
|
2016-10-16 21:46:46 +02:00
|
|
|
wined3d_buffer_load(state->cb[i][j], context, state);
|
2015-08-18 11:24:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (view->resource->type == WINED3D_RTYPE_BUFFER)
|
2016-10-16 21:46:46 +02:00
|
|
|
wined3d_buffer_load(buffer_from_resource(view->resource), context, state);
|
2015-08-18 11:24:10 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 16:41:10 +02:00
|
|
|
static void wined3d_context_gl_bind_shader_resources(struct wined3d_context_gl *context_gl,
|
2017-03-15 12:00:04 +01:00
|
|
|
const struct wined3d_state *state, enum wined3d_shader_type shader_type)
|
2015-01-19 13:44:08 +01:00
|
|
|
{
|
2017-03-15 12:00:04 +01:00
|
|
|
unsigned int bind_idx, shader_sampler_count, base, count, i;
|
2019-05-09 16:41:10 +02:00
|
|
|
const struct wined3d_device *device = context_gl->c.device;
|
2015-01-19 13:44:08 +01:00
|
|
|
struct wined3d_shader_sampler_map_entry *entry;
|
|
|
|
struct wined3d_shader_resource_view *view;
|
2017-02-22 13:19:36 +01:00
|
|
|
const struct wined3d_shader *shader;
|
2019-05-09 16:41:09 +02:00
|
|
|
const unsigned int *tex_unit_map;
|
2015-01-19 13:44:08 +01:00
|
|
|
struct wined3d_sampler *sampler;
|
|
|
|
|
2017-02-22 13:19:36 +01:00
|
|
|
if (!(shader = state->shader[shader_type]))
|
|
|
|
return;
|
|
|
|
|
2019-05-09 16:41:09 +02:00
|
|
|
tex_unit_map = wined3d_context_gl_get_tex_unit_mapping(context_gl,
|
2017-03-15 12:00:04 +01:00
|
|
|
&shader->reg_maps.shader_version, &base, &count);
|
|
|
|
|
2017-02-22 13:19:36 +01:00
|
|
|
shader_sampler_count = shader->reg_maps.sampler_map.count;
|
|
|
|
if (shader_sampler_count > count)
|
|
|
|
FIXME("Shader %p needs %u samplers, but only %u are supported.\n",
|
|
|
|
shader, shader_sampler_count, count);
|
|
|
|
count = min(shader_sampler_count, count);
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
entry = &shader->reg_maps.sampler_map.entries[i];
|
2017-03-15 12:00:04 +01:00
|
|
|
bind_idx = base + entry->bind_idx;
|
|
|
|
if (tex_unit_map)
|
|
|
|
bind_idx = tex_unit_map[bind_idx];
|
2017-02-22 13:19:36 +01:00
|
|
|
|
|
|
|
if (!(view = state->shader_resource_view[shader_type][entry->resource_idx]))
|
|
|
|
{
|
|
|
|
WARN("No resource view bound at index %u, %u.\n", shader_type, entry->resource_idx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry->sampler_idx == WINED3D_SAMPLER_DEFAULT)
|
2017-03-20 12:13:06 +01:00
|
|
|
sampler = device->default_sampler;
|
|
|
|
else if (!(sampler = state->sampler[shader_type][entry->sampler_idx]))
|
|
|
|
sampler = device->null_sampler;
|
2019-08-15 11:49:59 +02:00
|
|
|
wined3d_shader_resource_view_gl_bind(wined3d_shader_resource_view_gl(view),
|
|
|
|
bind_idx, wined3d_sampler_gl(sampler), context_gl);
|
2017-02-22 13:19:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 13:19:26 +01:00
|
|
|
static void context_load_unordered_access_resources(struct wined3d_context *context,
|
2017-02-09 12:00:29 +01:00
|
|
|
const struct wined3d_shader *shader, struct wined3d_unordered_access_view * const *views)
|
2016-11-23 14:36:05 +01:00
|
|
|
{
|
|
|
|
struct wined3d_unordered_access_view *view;
|
2017-02-22 13:19:26 +01:00
|
|
|
struct wined3d_texture *texture;
|
2017-02-14 13:15:10 +01:00
|
|
|
struct wined3d_buffer *buffer;
|
2016-11-23 14:36:05 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
2016-11-23 14:36:10 +01:00
|
|
|
context->uses_uavs = 0;
|
|
|
|
|
2017-02-09 12:00:29 +01:00
|
|
|
if (!shader)
|
2016-11-23 14:36:05 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_UNORDERED_ACCESS_VIEWS; ++i)
|
|
|
|
{
|
2017-02-09 12:00:29 +01:00
|
|
|
if (!(view = views[i]))
|
2016-11-23 14:36:05 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (view->resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
2017-02-14 13:15:10 +01:00
|
|
|
buffer = buffer_from_resource(view->resource);
|
|
|
|
wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER);
|
|
|
|
wined3d_unordered_access_view_invalidate_location(view, ~WINED3D_LOCATION_BUFFER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
texture = texture_from_resource(view->resource);
|
|
|
|
wined3d_texture_load(texture, context, FALSE);
|
|
|
|
wined3d_unordered_access_view_invalidate_location(view, ~WINED3D_LOCATION_TEXTURE_RGB);
|
2016-11-23 14:36:05 +01:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:36:10 +01:00
|
|
|
context->uses_uavs = 1;
|
2017-02-22 13:19:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 00:03:32 +02:00
|
|
|
static void wined3d_context_gl_bind_unordered_access_views(struct wined3d_context_gl *context_gl,
|
2017-02-22 13:19:26 +01:00
|
|
|
const struct wined3d_shader *shader, struct wined3d_unordered_access_view * const *views)
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-11-13 14:10:18 +01:00
|
|
|
struct wined3d_unordered_access_view_gl *view_gl;
|
2018-09-22 01:26:09 +02:00
|
|
|
const struct wined3d_format_gl *format_gl;
|
2017-02-22 13:19:26 +01:00
|
|
|
GLuint texture_name;
|
|
|
|
unsigned int i;
|
|
|
|
GLint level;
|
|
|
|
|
|
|
|
if (!shader)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_UNORDERED_ACCESS_VIEWS; ++i)
|
|
|
|
{
|
2018-11-13 14:10:18 +01:00
|
|
|
if (!views[i])
|
2017-02-22 13:19:26 +01:00
|
|
|
{
|
2017-03-03 01:30:33 +01:00
|
|
|
if (shader->reg_maps.uav_resource_info[i].type)
|
|
|
|
WARN("No unordered access view bound at index %u.\n", i);
|
2017-02-22 13:19:26 +01:00
|
|
|
GL_EXTCALL(glBindImageTexture(i, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R8));
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-23 14:36:10 +01:00
|
|
|
|
2018-11-13 14:10:18 +01:00
|
|
|
view_gl = wined3d_unordered_access_view_gl(views[i]);
|
|
|
|
if (view_gl->gl_view.name)
|
2016-12-09 11:30:45 +01:00
|
|
|
{
|
2018-11-13 14:10:18 +01:00
|
|
|
texture_name = view_gl->gl_view.name;
|
2016-12-09 11:30:45 +01:00
|
|
|
level = 0;
|
|
|
|
}
|
2018-11-13 14:10:18 +01:00
|
|
|
else if (view_gl->v.resource->type != WINED3D_RTYPE_BUFFER)
|
2016-12-09 11:30:45 +01:00
|
|
|
{
|
2018-11-13 14:10:18 +01:00
|
|
|
struct wined3d_texture_gl *texture_gl = wined3d_texture_gl(texture_from_resource(view_gl->v.resource));
|
2019-06-18 00:03:32 +02:00
|
|
|
texture_name = wined3d_texture_gl_get_texture_name(texture_gl, &context_gl->c, FALSE);
|
2018-11-13 14:10:18 +01:00
|
|
|
level = view_gl->v.desc.u.texture.level_idx;
|
2016-12-09 11:30:45 +01:00
|
|
|
}
|
2017-02-14 13:15:10 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Unsupported buffer unordered access view.\n");
|
|
|
|
GL_EXTCALL(glBindImageTexture(i, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R8));
|
|
|
|
continue;
|
|
|
|
}
|
2016-12-09 11:30:45 +01:00
|
|
|
|
2018-11-13 14:10:18 +01:00
|
|
|
format_gl = wined3d_format_gl(view_gl->v.format);
|
2016-12-09 11:30:45 +01:00
|
|
|
GL_EXTCALL(glBindImageTexture(i, texture_name, level, GL_TRUE, 0, GL_READ_WRITE,
|
2018-09-22 01:26:09 +02:00
|
|
|
format_gl->internal));
|
2017-03-03 01:30:32 +01:00
|
|
|
|
2018-11-13 14:10:18 +01:00
|
|
|
if (view_gl->counter_bo)
|
|
|
|
GL_EXTCALL(glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i, view_gl->counter_bo));
|
2016-11-23 14:36:05 +01:00
|
|
|
}
|
|
|
|
checkGLcall("Bind unordered access views");
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:11:08 +02:00
|
|
|
static void context_load_stream_output_buffers(struct wined3d_context *context,
|
|
|
|
const struct wined3d_state *state)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(state->stream_output); ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer *buffer;
|
|
|
|
if (!(buffer = state->stream_output[i].buffer))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wined3d_buffer_load(buffer, context, state);
|
|
|
|
wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 11:24:37 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2018-02-25 23:23:31 +01:00
|
|
|
static BOOL context_apply_draw_state(struct wined3d_context *context,
|
2020-03-26 13:26:00 +01:00
|
|
|
const struct wined3d_device *device, const struct wined3d_state *state, BOOL indexed)
|
2011-07-02 11:24:37 +02:00
|
|
|
{
|
2019-03-03 19:55:27 +01:00
|
|
|
const struct wined3d_state_entry *state_table = context->state_table;
|
2019-05-09 16:41:10 +02:00
|
|
|
struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2020-03-26 13:25:57 +01:00
|
|
|
const struct wined3d_fb_state *fb = &state->fb;
|
2019-08-07 13:42:01 +02:00
|
|
|
unsigned int i, base;
|
2014-07-14 10:04:21 +02:00
|
|
|
WORD map;
|
2011-07-02 11:24:37 +02:00
|
|
|
|
2019-10-23 18:44:58 +02:00
|
|
|
context->uses_fbo_attached_resources = 0;
|
|
|
|
|
2018-03-01 19:36:52 +01:00
|
|
|
if (!have_framebuffer_attachment(gl_info->limits.buffers, fb->render_targets, fb->depth_stencil))
|
|
|
|
{
|
|
|
|
if (!gl_info->supported[ARB_FRAMEBUFFER_NO_ATTACHMENTS])
|
|
|
|
{
|
|
|
|
FIXME("OpenGL implementation does not support framebuffers with no attachments.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-17 12:32:12 +02:00
|
|
|
wined3d_context_gl_set_render_offscreen(context_gl, TRUE);
|
2018-03-01 19:36:52 +01:00
|
|
|
}
|
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. */
|
2019-05-10 18:31:03 +02:00
|
|
|
wined3d_context_gl_update_tex_unit_map(context_gl, state);
|
2013-09-16 12:43:19 +02:00
|
|
|
context_preload_textures(context, state);
|
2017-02-06 14:12:14 +01:00
|
|
|
context_load_shader_resources(context, state, ~(1u << WINED3D_SHADER_TYPE_COMPUTE));
|
2017-02-22 13:19:26 +01:00
|
|
|
context_load_unordered_access_resources(context, state->shader[WINED3D_SHADER_TYPE_PIXEL],
|
|
|
|
state->unordered_access_view[WINED3D_PIPELINE_GRAPHICS]);
|
2017-03-29 15:11:08 +02:00
|
|
|
context_load_stream_output_buffers(context, state);
|
2015-03-17 15:52:13 +01:00
|
|
|
/* TODO: Right now the dependency on the vertex shader is necessary
|
2017-03-06 10:45:23 +01:00
|
|
|
* since wined3d_stream_info_from_declaration() depends on the reg_maps of
|
2015-03-17 15:52:13 +01:00
|
|
|
* 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)
|
2017-01-31 15:47:14 +01:00
|
|
|
wined3d_buffer_load(state->streams[context->stream_info.elements[i].stream_idx].buffer,
|
|
|
|
context, state);
|
2014-07-14 10:04:21 +02:00
|
|
|
}
|
2017-01-31 15:47:14 +01:00
|
|
|
/* Loading the buffers above may have invalidated the stream info. */
|
|
|
|
if (isStateDirty(context, STATE_STREAMSRC))
|
|
|
|
context_update_stream_info(context, state);
|
2014-07-14 10:04:21 +02:00
|
|
|
}
|
2020-03-26 13:26:00 +01:00
|
|
|
if (indexed && 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)
|
2016-10-16 21:46:46 +02:00
|
|
|
wined3d_buffer_load(state->index_buffer, context, state);
|
2012-05-28 18:17:25 +02:00
|
|
|
else
|
2016-10-16 21:46:47 +02:00
|
|
|
wined3d_buffer_load_sysmem(state->index_buffer, context);
|
2012-05-28 18:17:25 +02:00
|
|
|
}
|
2011-07-02 11:24:37 +02:00
|
|
|
|
2019-08-07 13:42:01 +02:00
|
|
|
for (i = 0, base = 0; i < ARRAY_SIZE(context->dirty_graphics_states); ++i)
|
2010-05-03 22:03:27 +02:00
|
|
|
{
|
2019-08-07 13:42:01 +02:00
|
|
|
uint32_t dirty_mask = context->dirty_graphics_states[i];
|
|
|
|
|
|
|
|
while (dirty_mask)
|
|
|
|
{
|
|
|
|
unsigned int state_id = base + wined3d_bit_scan(&dirty_mask);
|
|
|
|
|
|
|
|
state_table[state_id].apply(context, state, state_id);
|
|
|
|
context->dirty_graphics_states[i] &= ~(1u << (state_id - base));
|
|
|
|
}
|
|
|
|
base += sizeof(dirty_mask) * CHAR_BIT;
|
2010-05-03 22:03:27 +02:00
|
|
|
}
|
2011-07-02 11:24:37 +02:00
|
|
|
|
2017-02-06 14:12:14 +01:00
|
|
|
if (context->shader_update_mask & ~(1u << WINED3D_SHADER_TYPE_COMPUTE))
|
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);
|
2017-02-06 14:12:14 +01:00
|
|
|
context->shader_update_mask &= 1u << WINED3D_SHADER_TYPE_COMPUTE;
|
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)
|
|
|
|
{
|
2017-03-15 12:00:04 +01:00
|
|
|
for (i = 0; i < WINED3D_SHADER_TYPE_GRAPHICS_COUNT; ++i)
|
2019-05-09 16:41:10 +02:00
|
|
|
wined3d_context_gl_bind_shader_resources(context_gl, state, i);
|
2015-01-19 13:44:08 +01:00
|
|
|
context->update_shader_resource_bindings = 0;
|
2017-02-22 13:19:36 +01:00
|
|
|
if (gl_info->limits.combined_samplers == gl_info->limits.graphics_samplers)
|
|
|
|
context->update_compute_shader_resource_bindings = 1;
|
2015-01-19 13:44:08 +01:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:36:05 +01:00
|
|
|
if (context->update_unordered_access_view_bindings)
|
|
|
|
{
|
2019-06-18 00:03:32 +02:00
|
|
|
wined3d_context_gl_bind_unordered_access_views(context_gl,
|
2017-02-09 12:00:36 +01:00
|
|
|
state->shader[WINED3D_SHADER_TYPE_PIXEL],
|
|
|
|
state->unordered_access_view[WINED3D_PIPELINE_GRAPHICS]);
|
2016-11-23 14:36:05 +01:00
|
|
|
context->update_unordered_access_view_bindings = 0;
|
2017-02-09 12:00:29 +01:00
|
|
|
context->update_compute_unordered_access_view_bindings = 1;
|
2016-11-23 14:36:05 +01:00
|
|
|
}
|
|
|
|
|
2011-07-02 11:24:37 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
2019-05-15 15:32:55 +02:00
|
|
|
wined3d_context_gl_check_fbo_status(context_gl, GL_FRAMEBUFFER);
|
2011-07-02 11:24:37 +02:00
|
|
|
|
2010-05-03 22:03:27 +02:00
|
|
|
context->last_was_blit = FALSE;
|
2018-03-13 11:23:06 +01:00
|
|
|
context->last_was_ffp_blit = FALSE;
|
2011-01-26 19:45:02 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2009-12-27 19:57:21 +01:00
|
|
|
}
|
|
|
|
|
2019-05-17 13:45:16 +02:00
|
|
|
static void wined3d_context_gl_apply_compute_state(struct wined3d_context_gl *context_gl,
|
2017-02-02 12:43:40 +01:00
|
|
|
const struct wined3d_device *device, const struct wined3d_state *state)
|
|
|
|
{
|
2019-05-17 13:45:16 +02:00
|
|
|
const struct wined3d_state_entry *state_table = context_gl->c.state_table;
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-02-06 11:40:04 +01:00
|
|
|
unsigned int state_id, i;
|
2017-02-06 14:12:14 +01:00
|
|
|
|
2019-05-17 13:45:16 +02:00
|
|
|
context_load_shader_resources(&context_gl->c, state, 1u << WINED3D_SHADER_TYPE_COMPUTE);
|
|
|
|
context_load_unordered_access_resources(&context_gl->c, state->shader[WINED3D_SHADER_TYPE_COMPUTE],
|
2017-02-22 13:19:26 +01:00
|
|
|
state->unordered_access_view[WINED3D_PIPELINE_COMPUTE]);
|
2017-02-06 14:12:14 +01:00
|
|
|
|
2019-05-17 13:45:16 +02:00
|
|
|
for (i = 0, state_id = STATE_COMPUTE_OFFSET; i < ARRAY_SIZE(context_gl->c.dirty_compute_states); ++i)
|
2017-02-06 14:12:14 +01:00
|
|
|
{
|
2019-05-17 13:45:16 +02:00
|
|
|
unsigned int dirty_mask = context_gl->c.dirty_compute_states[i];
|
|
|
|
|
2018-02-06 11:40:04 +01:00
|
|
|
while (dirty_mask)
|
2017-02-06 14:12:14 +01:00
|
|
|
{
|
2018-02-06 11:40:04 +01:00
|
|
|
unsigned int current_state_id = state_id + wined3d_bit_scan(&dirty_mask);
|
2019-05-17 13:45:16 +02:00
|
|
|
state_table[current_state_id].apply(&context_gl->c, state, current_state_id);
|
2017-02-06 14:12:14 +01:00
|
|
|
}
|
2019-05-17 13:45:16 +02:00
|
|
|
state_id += sizeof(*context_gl->c.dirty_compute_states) * CHAR_BIT;
|
2017-02-06 14:12:14 +01:00
|
|
|
}
|
2019-05-17 13:45:16 +02:00
|
|
|
memset(context_gl->c.dirty_compute_states, 0, sizeof(*context_gl->c.dirty_compute_states));
|
2017-02-06 14:12:14 +01:00
|
|
|
|
2019-05-17 13:45:16 +02:00
|
|
|
if (context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_COMPUTE))
|
2017-02-06 14:12:14 +01:00
|
|
|
{
|
2019-05-17 13:45:16 +02:00
|
|
|
device->shader_backend->shader_select_compute(device->shader_priv, &context_gl->c, state);
|
|
|
|
context_gl->c.shader_update_mask &= ~(1u << WINED3D_SHADER_TYPE_COMPUTE);
|
2017-02-06 14:12:14 +01:00
|
|
|
}
|
|
|
|
|
2019-05-17 13:45:16 +02:00
|
|
|
if (context_gl->c.update_compute_shader_resource_bindings)
|
2017-02-22 13:19:36 +01:00
|
|
|
{
|
2019-05-17 13:45:16 +02:00
|
|
|
wined3d_context_gl_bind_shader_resources(context_gl, state, WINED3D_SHADER_TYPE_COMPUTE);
|
|
|
|
context_gl->c.update_compute_shader_resource_bindings = 0;
|
2017-02-22 13:19:36 +01:00
|
|
|
if (gl_info->limits.combined_samplers == gl_info->limits.graphics_samplers)
|
2019-05-17 13:45:16 +02:00
|
|
|
context_gl->c.update_shader_resource_bindings = 1;
|
2017-02-22 13:19:36 +01:00
|
|
|
}
|
|
|
|
|
2019-05-17 13:45:16 +02:00
|
|
|
if (context_gl->c.update_compute_unordered_access_view_bindings)
|
2017-02-09 12:00:29 +01:00
|
|
|
{
|
2019-06-18 00:03:32 +02:00
|
|
|
wined3d_context_gl_bind_unordered_access_views(context_gl,
|
2017-02-09 12:00:36 +01:00
|
|
|
state->shader[WINED3D_SHADER_TYPE_COMPUTE],
|
|
|
|
state->unordered_access_view[WINED3D_PIPELINE_COMPUTE]);
|
2019-05-17 13:45:16 +02:00
|
|
|
context_gl->c.update_compute_unordered_access_view_bindings = 0;
|
|
|
|
context_gl->c.update_unordered_access_view_bindings = 1;
|
2017-02-09 12:00:29 +01:00
|
|
|
}
|
|
|
|
|
2017-12-04 14:42:24 +01:00
|
|
|
/* Updates to currently bound render targets aren't necessarily coherent
|
|
|
|
* between the graphics and compute pipelines. Unbind any currently bound
|
|
|
|
* FBO here to ensure preceding updates to its attachments by the graphics
|
|
|
|
* pipeline are visible to the compute pipeline.
|
|
|
|
*
|
|
|
|
* Without this, the bloom effect in Nier:Automata is too bright on the
|
|
|
|
* Mesa radeonsi driver, and presumably on other Mesa based drivers. */
|
2019-05-15 15:32:58 +02:00
|
|
|
wined3d_context_gl_bind_fbo(context_gl, GL_FRAMEBUFFER, 0);
|
2019-05-17 13:45:16 +02:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_FRAMEBUFFER);
|
2017-12-04 14:42:24 +01:00
|
|
|
|
2019-05-17 13:45:16 +02:00
|
|
|
context_gl->c.last_was_blit = FALSE;
|
|
|
|
context_gl->c.last_was_ffp_blit = FALSE;
|
2017-02-02 12:43:40 +01:00
|
|
|
}
|
|
|
|
|
2018-02-25 23:23:31 +01:00
|
|
|
static BOOL use_transform_feedback(const struct wined3d_state *state)
|
|
|
|
{
|
|
|
|
const struct wined3d_shader *shader;
|
|
|
|
if (!(shader = state->shader[WINED3D_SHADER_TYPE_GEOMETRY]))
|
|
|
|
return FALSE;
|
|
|
|
return shader->u.gs.so_desc.element_count;
|
|
|
|
}
|
|
|
|
|
2019-06-10 22:15:27 +02:00
|
|
|
void wined3d_context_gl_end_transform_feedback(struct wined3d_context_gl *context_gl)
|
2017-03-30 14:09:23 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-06-10 22:15:27 +02:00
|
|
|
|
|
|
|
if (context_gl->c.transform_feedback_active)
|
2017-03-30 14:09:23 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glEndTransformFeedback());
|
|
|
|
checkGLcall("glEndTransformFeedback");
|
2019-06-10 22:15:27 +02:00
|
|
|
context_gl->c.transform_feedback_active = 0;
|
|
|
|
context_gl->c.transform_feedback_paused = 0;
|
2017-03-30 14:09:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 00:03:33 +02:00
|
|
|
static void wined3d_context_gl_pause_transform_feedback(struct wined3d_context_gl *context_gl, BOOL force)
|
2018-02-25 23:23:31 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-02-25 23:23:31 +01:00
|
|
|
|
2019-06-18 00:03:33 +02:00
|
|
|
if (!context_gl->c.transform_feedback_active || context_gl->c.transform_feedback_paused)
|
2018-02-25 23:23:31 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TRANSFORM_FEEDBACK2])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glPauseTransformFeedback());
|
|
|
|
checkGLcall("glPauseTransformFeedback");
|
2019-06-18 00:03:33 +02:00
|
|
|
context_gl->c.transform_feedback_paused = 1;
|
2018-02-25 23:23:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Cannot pause transform feedback operations.\n");
|
|
|
|
|
|
|
|
if (force)
|
2019-06-10 22:15:27 +02:00
|
|
|
wined3d_context_gl_end_transform_feedback(context_gl);
|
2018-02-25 23:23:31 +01:00
|
|
|
}
|
|
|
|
|
2019-06-18 00:03:34 +02:00
|
|
|
static void wined3d_context_gl_setup_target(struct wined3d_context_gl *context_gl,
|
2016-03-29 16:45:32 +02:00
|
|
|
struct wined3d_texture *texture, unsigned int sub_resource_idx)
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
2019-06-18 00:03:34 +02:00
|
|
|
BOOL old_render_offscreen = context_gl->c.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);
|
2019-06-18 00:03:34 +02:00
|
|
|
if (context_gl->c.current_rt.texture == texture
|
|
|
|
&& context_gl->c.current_rt.sub_resource_idx == sub_resource_idx
|
2016-03-29 16:45:32 +02:00
|
|
|
&& 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. */
|
2019-06-18 00:03:34 +02:00
|
|
|
if (!context_gl->c.current_rt.texture)
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
2020-03-10 05:07:28 +01:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_BLEND);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-18 00:03:34 +02:00
|
|
|
const struct wined3d_format *old = context_gl->c.current_rt.texture->resource.format;
|
2016-03-29 16:45:32 +02:00
|
|
|
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))
|
2020-03-10 05:07:28 +01:00
|
|
|
context_invalidate_state(&context_gl->c, STATE_BLEND);
|
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 */
|
2019-06-18 00:03:34 +02:00
|
|
|
if ((context_gl->c.current_rt.texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE)
|
2016-03-29 16:45:32 +02:00
|
|
|
!= (texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE))
|
2020-03-16 05:42:06 +01:00
|
|
|
context_invalidate_state(&context_gl->c, 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
|
2019-06-18 00:03:34 +02:00
|
|
|
&& old_render_offscreen && (context_gl->c.current_rt.texture != texture
|
|
|
|
|| context_gl->c.current_rt.sub_resource_idx != sub_resource_idx))
|
2010-03-27 17:40:28 +01:00
|
|
|
{
|
2019-06-18 00:03:34 +02:00
|
|
|
struct wined3d_texture_gl *prev_texture = wined3d_texture_gl(context_gl->c.current_rt.texture);
|
|
|
|
unsigned int prev_sub_resource_idx = context_gl->c.current_rt.sub_resource_idx;
|
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)
|
2019-06-18 00:03:34 +02:00
|
|
|
wined3d_texture_load(&prev_texture->t, &context_gl->c, TRUE);
|
|
|
|
wined3d_texture_load(&prev_texture->t, &context_gl->c, FALSE);
|
2018-10-30 10:48:43 +01:00
|
|
|
wined3d_texture_invalidate_location(&prev_texture->t, prev_sub_resource_idx, WINED3D_LOCATION_DRAWABLE);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 00:03:34 +02:00
|
|
|
context_gl->c.current_rt.texture = texture;
|
|
|
|
context_gl->c.current_rt.sub_resource_idx = sub_resource_idx;
|
2019-06-17 12:32:12 +02:00
|
|
|
wined3d_context_gl_set_render_offscreen(context_gl, render_offscreen);
|
2010-03-27 17:40:28 +01:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:40:21 +02:00
|
|
|
static void wined3d_context_gl_activate(struct wined3d_context_gl *context_gl,
|
2018-02-27 10:17:37 +01:00
|
|
|
struct wined3d_texture *texture, unsigned int sub_resource_idx)
|
|
|
|
{
|
2019-05-20 23:41:05 +02:00
|
|
|
wined3d_context_gl_enter(context_gl);
|
2019-05-20 23:41:04 +02:00
|
|
|
wined3d_context_gl_update_window(context_gl);
|
2019-06-18 00:03:34 +02:00
|
|
|
wined3d_context_gl_setup_target(context_gl, texture, sub_resource_idx);
|
2019-06-06 14:51:06 +02:00
|
|
|
if (!context_gl->valid)
|
2018-02-27 10:17:37 +01:00
|
|
|
return;
|
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
if (context_gl != wined3d_context_gl_get_current())
|
2018-02-27 10:17:37 +01:00
|
|
|
{
|
2019-08-05 15:09:54 +02:00
|
|
|
if (!wined3d_context_gl_set_current(context_gl))
|
2018-02-27 10:17:37 +01:00
|
|
|
ERR("Failed to activate the new context.\n");
|
|
|
|
}
|
2019-06-06 14:51:05 +02:00
|
|
|
else if (context_gl->needs_set)
|
2018-02-27 10:17:37 +01:00
|
|
|
{
|
2019-05-20 23:41:03 +02:00
|
|
|
wined3d_context_gl_set_gl_context(context_gl);
|
2018-02-27 10:17:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device *device,
|
2017-02-15 14:17:15 +01:00
|
|
|
struct wined3d_texture *texture, unsigned int sub_resource_idx)
|
2009-12-27 19:57:21 +01:00
|
|
|
{
|
2019-08-05 15:09:55 +02:00
|
|
|
struct wined3d_context_gl *current_context = wined3d_context_gl_get_current();
|
|
|
|
struct wined3d_context_gl *context_gl;
|
2009-12-27 19:57:21 +01:00
|
|
|
|
2017-02-15 14:17:15 +01:00
|
|
|
TRACE("device %p, texture %p, sub_resource_idx %u.\n", device, texture, sub_resource_idx);
|
2009-12-27 19:57:21 +01:00
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
if (current_context && current_context->c.destroyed)
|
2011-08-21 21:34:53 +02:00
|
|
|
current_context = NULL;
|
|
|
|
|
2017-02-15 14:17:15 +01:00
|
|
|
if (!texture)
|
2011-08-21 21:34:53 +02:00
|
|
|
{
|
|
|
|
if (current_context
|
2019-08-05 15:09:55 +02:00
|
|
|
&& current_context->c.current_rt.texture
|
|
|
|
&& current_context->c.device == device)
|
2011-08-21 21:34:53 +02:00
|
|
|
{
|
2019-08-05 15:09:55 +02:00
|
|
|
texture = current_context->c.current_rt.texture;
|
|
|
|
sub_resource_idx = current_context->c.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)
|
2017-02-15 14:17:15 +01:00
|
|
|
texture = swapchain->back_buffers[0];
|
2011-08-21 21:34:53 +02:00
|
|
|
else
|
2017-02-15 14:17:15 +01:00
|
|
|
texture = swapchain->front_buffer;
|
|
|
|
sub_resource_idx = 0;
|
2011-08-21 21:34:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
if (current_context && current_context->c.current_rt.texture == texture)
|
2011-08-21 21:34:53 +02:00
|
|
|
{
|
2019-08-05 15:09:55 +02:00
|
|
|
context_gl = current_context;
|
2011-08-21 21:34:53 +02:00
|
|
|
}
|
2019-08-13 10:31:40 +02:00
|
|
|
else if (!wined3d_resource_is_offscreen(&texture->resource))
|
2011-08-21 21:34:53 +02:00
|
|
|
{
|
|
|
|
TRACE("Rendering onscreen.\n");
|
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
if (!(context_gl = wined3d_swapchain_gl_get_context(wined3d_swapchain_gl(texture->swapchain))))
|
2019-05-16 15:05:00 +02:00
|
|
|
return NULL;
|
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. */
|
2019-08-05 15:09:55 +02:00
|
|
|
if (current_context && current_context->c.device == device)
|
|
|
|
context_gl = current_context;
|
2019-08-13 10:31:39 +02:00
|
|
|
else if (!(context_gl = wined3d_swapchain_gl_get_context(wined3d_swapchain_gl(device->swapchains[0]))))
|
2019-05-16 15:05:00 +02:00
|
|
|
return NULL;
|
2011-08-21 21:34:53 +02:00
|
|
|
}
|
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
wined3d_context_gl_activate(context_gl, texture, sub_resource_idx);
|
2009-12-27 19:57:21 +01:00
|
|
|
|
2019-08-05 15:09:55 +02:00
|
|
|
return &context_gl->c;
|
2007-02-12 19:18:36 +01:00
|
|
|
}
|
2017-04-05 15:38:05 +02:00
|
|
|
|
2019-06-06 14:51:07 +02:00
|
|
|
struct wined3d_context_gl *wined3d_context_gl_reacquire(struct wined3d_context_gl *context_gl)
|
2017-04-05 15:38:05 +02:00
|
|
|
{
|
2018-02-27 10:17:37 +01:00
|
|
|
struct wined3d_context *acquired_context;
|
2019-06-06 14:51:07 +02:00
|
|
|
struct wined3d_device *device;
|
2018-02-27 10:17:37 +01:00
|
|
|
|
2019-06-07 14:52:27 +02:00
|
|
|
if (!context_gl || context_gl->tid != GetCurrentThreadId())
|
2017-04-05 15:38:05 +02:00
|
|
|
return NULL;
|
|
|
|
|
2019-06-06 14:51:07 +02:00
|
|
|
device = context_gl->c.device;
|
|
|
|
wined3d_from_cs(device->cs);
|
|
|
|
|
|
|
|
if (context_gl->c.current_rt.texture)
|
2018-02-27 10:17:37 +01:00
|
|
|
{
|
2019-06-06 14:51:07 +02:00
|
|
|
wined3d_context_gl_activate(context_gl, context_gl->c.current_rt.texture,
|
|
|
|
context_gl->c.current_rt.sub_resource_idx);
|
|
|
|
return context_gl;
|
2018-02-27 10:17:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
acquired_context = context_acquire(device, NULL, 0);
|
2019-06-06 14:51:07 +02:00
|
|
|
if (acquired_context != &context_gl->c)
|
|
|
|
ERR("Acquired context %p instead of %p.\n", acquired_context, &context_gl->c);
|
|
|
|
return wined3d_context_gl(acquired_context);
|
2017-04-05 15:38:05 +02:00
|
|
|
}
|
2018-02-25 23:23:28 +01:00
|
|
|
|
|
|
|
void dispatch_compute(struct wined3d_device *device, const struct wined3d_state *state,
|
|
|
|
const struct wined3d_dispatch_parameters *parameters)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-05-17 13:45:16 +02:00
|
|
|
struct wined3d_context_gl *context_gl;
|
2018-02-25 23:23:28 +01:00
|
|
|
|
2019-06-06 14:51:06 +02:00
|
|
|
context_gl = wined3d_context_gl(context_acquire(device, NULL, 0));
|
|
|
|
if (!context_gl->valid)
|
2018-02-25 23:23:28 +01:00
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
context_release(&context_gl->c);
|
2018-02-25 23:23:28 +01:00
|
|
|
WARN("Invalid context, skipping dispatch.\n");
|
|
|
|
return;
|
|
|
|
}
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2018-02-25 23:23:28 +01:00
|
|
|
|
|
|
|
if (!gl_info->supported[ARB_COMPUTE_SHADER])
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
context_release(&context_gl->c);
|
2018-02-25 23:23:28 +01:00
|
|
|
FIXME("OpenGL implementation does not support compute shaders.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters->indirect)
|
2019-06-06 14:51:06 +02:00
|
|
|
wined3d_buffer_load(parameters->u.indirect.buffer, &context_gl->c, state);
|
2018-02-25 23:23:28 +01:00
|
|
|
|
2019-05-17 13:45:16 +02:00
|
|
|
wined3d_context_gl_apply_compute_state(context_gl, device, state);
|
2018-02-25 23:23:28 +01:00
|
|
|
|
|
|
|
if (!state->shader[WINED3D_SHADER_TYPE_COMPUTE])
|
|
|
|
{
|
2019-06-06 14:51:06 +02:00
|
|
|
context_release(&context_gl->c);
|
2018-02-25 23:23:28 +01:00
|
|
|
WARN("No compute shader bound, skipping dispatch.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters->indirect)
|
|
|
|
{
|
|
|
|
const struct wined3d_indirect_dispatch_parameters *indirect = ¶meters->u.indirect;
|
|
|
|
struct wined3d_buffer *buffer = indirect->buffer;
|
|
|
|
|
2019-09-23 13:24:17 +02:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, buffer->buffer_object));
|
2018-02-25 23:23:28 +01:00
|
|
|
GL_EXTCALL(glDispatchComputeIndirect((GLintptr)indirect->offset));
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const struct wined3d_direct_dispatch_parameters *direct = ¶meters->u.direct;
|
|
|
|
GL_EXTCALL(glDispatchCompute(direct->group_count_x, direct->group_count_y, direct->group_count_z));
|
|
|
|
}
|
|
|
|
checkGLcall("dispatch compute");
|
|
|
|
|
|
|
|
GL_EXTCALL(glMemoryBarrier(GL_ALL_BARRIER_BITS));
|
|
|
|
checkGLcall("glMemoryBarrier");
|
|
|
|
|
2019-06-06 14:51:06 +02:00
|
|
|
context_release(&context_gl->c);
|
2018-02-25 23:23:28 +01:00
|
|
|
}
|
2018-02-25 23:23:31 +01:00
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2019-06-18 00:03:35 +02:00
|
|
|
static void wined3d_context_gl_draw_primitive_arrays(struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_state *state, const void *idx_data, unsigned int idx_size, int base_vertex_idx,
|
|
|
|
unsigned int start_idx, unsigned int count, unsigned int start_instance, unsigned int instance_count)
|
2018-02-25 23:23:31 +01:00
|
|
|
{
|
2019-06-18 00:03:35 +02:00
|
|
|
const struct wined3d_ffp_attrib_ops *ops = &context_gl->c.d3d_info->ffp_attrib_ops;
|
2018-02-25 23:23:31 +01:00
|
|
|
GLenum idx_type = idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
2019-06-18 00:03:35 +02:00
|
|
|
const struct wined3d_stream_info *si = &context_gl->c.stream_info;
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-02-25 23:23:31 +01:00
|
|
|
unsigned int instanced_elements[ARRAY_SIZE(si->elements)];
|
|
|
|
unsigned int instanced_element_count = 0;
|
|
|
|
GLenum mode = state->gl_primitive_type;
|
|
|
|
const void *indices;
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
indices = (const char *)idx_data + idx_size * start_idx;
|
|
|
|
|
|
|
|
if (!instance_count)
|
|
|
|
{
|
|
|
|
if (!idx_size)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDrawArrays(mode, start_idx, count);
|
|
|
|
checkGLcall("glDrawArrays");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawElementsBaseVertex(mode, count, idx_type, indices, base_vertex_idx));
|
|
|
|
checkGLcall("glDrawElementsBaseVertex");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glDrawElements(mode, count, idx_type, indices);
|
|
|
|
checkGLcall("glDrawElements");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_instance && !(gl_info->supported[ARB_BASE_INSTANCE] && gl_info->supported[ARB_INSTANCED_ARRAYS]))
|
|
|
|
FIXME("Start instance (%u) not supported.\n", start_instance);
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_INSTANCED_ARRAYS])
|
|
|
|
{
|
|
|
|
if (!idx_size)
|
|
|
|
{
|
|
|
|
if (gl_info->supported[ARB_BASE_INSTANCE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawArraysInstancedBaseInstance(mode, start_idx, count, instance_count, start_instance));
|
|
|
|
checkGLcall("glDrawArraysInstancedBaseInstance");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glDrawArraysInstanced(mode, start_idx, count, instance_count));
|
|
|
|
checkGLcall("glDrawArraysInstanced");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_BASE_INSTANCE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawElementsInstancedBaseVertexBaseInstance(mode, count, idx_type,
|
|
|
|
indices, instance_count, base_vertex_idx, start_instance));
|
|
|
|
checkGLcall("glDrawElementsInstancedBaseVertexBaseInstance");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawElementsInstancedBaseVertex(mode, count, idx_type,
|
|
|
|
indices, instance_count, base_vertex_idx));
|
|
|
|
checkGLcall("glDrawElementsInstancedBaseVertex");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glDrawElementsInstanced(mode, count, idx_type, indices, instance_count));
|
|
|
|
checkGLcall("glDrawElementsInstanced");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Instancing emulation by mixing immediate mode and arrays. */
|
|
|
|
|
|
|
|
/* This is a nasty thing. MSDN says no hardware supports this and
|
|
|
|
* applications have to use software vertex processing. We don't support
|
|
|
|
* this for now.
|
|
|
|
*
|
|
|
|
* Shouldn't be too hard to support with OpenGL, in theory just call
|
2019-12-12 11:20:53 +01:00
|
|
|
* glDrawArrays() instead of drawElements(). But the stream frequency value
|
2018-02-25 23:23:31 +01:00
|
|
|
* has a different meaning in that situation. */
|
|
|
|
if (!idx_size)
|
|
|
|
{
|
|
|
|
FIXME("Non-indexed instanced drawing is not supported.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(si->elements); ++i)
|
|
|
|
{
|
|
|
|
if (!(si->use_map & (1u << i)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (state->streams[si->elements[i].stream_idx].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
|
|
|
|
instanced_elements[instanced_element_count++] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < instance_count; ++i)
|
|
|
|
{
|
|
|
|
/* Specify the instanced attributes using immediate mode calls. */
|
|
|
|
for (j = 0; j < instanced_element_count; ++j)
|
|
|
|
{
|
|
|
|
const struct wined3d_stream_info_element *element;
|
|
|
|
unsigned int element_idx;
|
|
|
|
const BYTE *ptr;
|
|
|
|
|
|
|
|
element_idx = instanced_elements[j];
|
|
|
|
element = &si->elements[element_idx];
|
|
|
|
ptr = element->data.addr + element->stride * i;
|
|
|
|
if (element->data.buffer_object)
|
2019-06-18 00:03:35 +02:00
|
|
|
ptr += (ULONG_PTR)wined3d_buffer_load_sysmem(state->streams[element->stream_idx].buffer,
|
|
|
|
&context_gl->c);
|
2018-02-25 23:23:31 +01:00
|
|
|
ops->generic[element->format->emit_idx](element_idx, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawElementsBaseVertex(mode, count, idx_type, indices, base_vertex_idx));
|
|
|
|
checkGLcall("glDrawElementsBaseVertex");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDrawElements(mode, count, idx_type, indices);
|
|
|
|
checkGLcall("glDrawElements");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int get_stride_idx(const void *idx_data, unsigned int idx_size,
|
|
|
|
unsigned int base_vertex_idx, unsigned int start_idx, unsigned int vertex_idx)
|
|
|
|
{
|
|
|
|
if (!idx_data)
|
|
|
|
return start_idx + vertex_idx;
|
|
|
|
if (idx_size == 2)
|
|
|
|
return ((const WORD *)idx_data)[start_idx + vertex_idx] + base_vertex_idx;
|
|
|
|
return ((const DWORD *)idx_data)[start_idx + vertex_idx] + base_vertex_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2019-05-10 18:31:04 +02:00
|
|
|
static void draw_primitive_immediate_mode(struct wined3d_context_gl *context_gl, const struct wined3d_state *state,
|
2018-02-25 23:23:31 +01:00
|
|
|
const struct wined3d_stream_info *si, const void *idx_data, unsigned int idx_size,
|
|
|
|
int base_vertex_idx, unsigned int start_idx, unsigned int vertex_count, unsigned int instance_count)
|
|
|
|
{
|
|
|
|
const BYTE *position = NULL, *normal = NULL, *diffuse = NULL, *specular = NULL;
|
2019-05-10 18:31:04 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context_gl->c.d3d_info;
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-02-25 23:23:31 +01:00
|
|
|
unsigned int coord_idx, stride_idx, texture_idx, vertex_idx;
|
|
|
|
const struct wined3d_stream_info_element *element;
|
|
|
|
const BYTE *tex_coords[WINED3DDP_MAXTEXCOORD];
|
|
|
|
unsigned int texture_unit, texture_stages;
|
|
|
|
const struct wined3d_ffp_attrib_ops *ops;
|
|
|
|
unsigned int untracked_material_count;
|
|
|
|
unsigned int tex_mask = 0;
|
|
|
|
BOOL specular_fog = FALSE;
|
|
|
|
BOOL ps = use_ps(state);
|
|
|
|
const void *ptr;
|
|
|
|
|
|
|
|
static unsigned int once;
|
|
|
|
|
|
|
|
if (!once++)
|
|
|
|
FIXME_(d3d_perf)("Drawing using immediate mode.\n");
|
|
|
|
else
|
|
|
|
WARN_(d3d_perf)("Drawing using immediate mode.\n");
|
|
|
|
|
|
|
|
if (!idx_size && idx_data)
|
|
|
|
ERR("Non-NULL idx_data with 0 idx_size, this should never happen.\n");
|
|
|
|
|
|
|
|
if (instance_count)
|
|
|
|
FIXME("Instancing not implemented.\n");
|
|
|
|
|
|
|
|
/* Immediate mode drawing can't make use of indices in a VBO - get the
|
|
|
|
* data from the index buffer. */
|
|
|
|
if (idx_size)
|
2019-05-10 18:31:04 +02:00
|
|
|
idx_data = wined3d_buffer_load_sysmem(state->index_buffer, &context_gl->c) + state->index_offset;
|
2018-02-25 23:23:31 +01:00
|
|
|
|
|
|
|
ops = &d3d_info->ffp_attrib_ops;
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glBegin(state->gl_primitive_type);
|
|
|
|
|
|
|
|
if (use_vs(state) || d3d_info->ffp_generic_attributes)
|
|
|
|
{
|
|
|
|
for (vertex_idx = 0; vertex_idx < vertex_count; ++vertex_idx)
|
|
|
|
{
|
|
|
|
unsigned int use_map = si->use_map;
|
|
|
|
unsigned int element_idx;
|
|
|
|
|
|
|
|
stride_idx = get_stride_idx(idx_data, idx_size, base_vertex_idx, start_idx, vertex_idx);
|
|
|
|
for (element_idx = MAX_ATTRIBS - 1; use_map; use_map &= ~(1u << element_idx), --element_idx)
|
|
|
|
{
|
|
|
|
if (!(use_map & 1u << element_idx))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ptr = si->elements[element_idx].data.addr + si->elements[element_idx].stride * stride_idx;
|
|
|
|
ops->generic[si->elements[element_idx].format->emit_idx](element_idx, ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (si->use_map & (1u << WINED3D_FFP_POSITION))
|
|
|
|
position = si->elements[WINED3D_FFP_POSITION].data.addr;
|
|
|
|
|
|
|
|
if (si->use_map & (1u << WINED3D_FFP_NORMAL))
|
|
|
|
normal = si->elements[WINED3D_FFP_NORMAL].data.addr;
|
|
|
|
else
|
|
|
|
gl_info->gl_ops.gl.p_glNormal3f(0.0f, 0.0f, 0.0f);
|
|
|
|
|
2019-06-06 14:51:04 +02:00
|
|
|
untracked_material_count = context_gl->untracked_material_count;
|
2018-02-25 23:23:31 +01:00
|
|
|
if (si->use_map & (1u << WINED3D_FFP_DIFFUSE))
|
|
|
|
{
|
|
|
|
element = &si->elements[WINED3D_FFP_DIFFUSE];
|
|
|
|
diffuse = element->data.addr;
|
|
|
|
|
|
|
|
if (untracked_material_count && element->format->id != WINED3DFMT_B8G8R8A8_UNORM)
|
|
|
|
FIXME("Implement diffuse color tracking from %s.\n", debug_d3dformat(element->format->id));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (si->use_map & (1u << WINED3D_FFP_SPECULAR))
|
|
|
|
{
|
|
|
|
element = &si->elements[WINED3D_FFP_SPECULAR];
|
|
|
|
specular = element->data.addr;
|
|
|
|
|
|
|
|
/* Special case where the fog density is stored in the specular alpha channel. */
|
|
|
|
if (state->render_states[WINED3D_RS_FOGENABLE]
|
|
|
|
&& (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE
|
|
|
|
|| si->elements[WINED3D_FFP_POSITION].format->id == WINED3DFMT_R32G32B32A32_FLOAT)
|
|
|
|
&& state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
|
|
|
|
{
|
|
|
|
if (gl_info->supported[EXT_FOG_COORD])
|
|
|
|
{
|
|
|
|
if (element->format->id == WINED3DFMT_B8G8R8A8_UNORM)
|
|
|
|
specular_fog = TRUE;
|
|
|
|
else
|
|
|
|
FIXME("Implement fog coordinates from %s.\n", debug_d3dformat(element->format->id));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static unsigned int once;
|
|
|
|
|
|
|
|
if (!once++)
|
|
|
|
FIXME("Implement fog for transformed vertices in software.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[EXT_SECONDARY_COLOR])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glSecondaryColor3fEXT)(0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
texture_stages = d3d_info->limits.ffp_blend_stages;
|
|
|
|
for (texture_idx = 0; texture_idx < texture_stages; ++texture_idx)
|
|
|
|
{
|
|
|
|
if (!gl_info->supported[ARB_MULTITEXTURE] && texture_idx > 0)
|
|
|
|
{
|
|
|
|
FIXME("Program using multiple concurrent textures which this OpenGL implementation doesn't support.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ps && !state->textures[texture_idx])
|
|
|
|
continue;
|
|
|
|
|
2019-05-10 18:31:05 +02:00
|
|
|
texture_unit = context_gl->tex_unit_map[texture_idx];
|
2018-02-25 23:23:31 +01:00
|
|
|
if (texture_unit == WINED3D_UNMAPPED_STAGE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
|
|
|
|
if (coord_idx > 7)
|
|
|
|
{
|
|
|
|
TRACE("Skipping generated coordinates (%#x) for texture %u.\n", coord_idx, texture_idx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx)))
|
|
|
|
{
|
|
|
|
tex_coords[coord_idx] = si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].data.addr;
|
|
|
|
tex_mask |= (1u << texture_idx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Setting default coordinates for texture %u.\n", texture_idx);
|
|
|
|
if (gl_info->supported[ARB_MULTITEXTURE])
|
|
|
|
GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_unit, 0.0f, 0.0f, 0.0f, 1.0f));
|
|
|
|
else
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord4f(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Blending data and point sizes are not supported by this function. They
|
|
|
|
* are not supported by the fixed function pipeline at all. A FIXME for
|
|
|
|
* them is printed after decoding the vertex declaration. */
|
|
|
|
for (vertex_idx = 0; vertex_idx < vertex_count; ++vertex_idx)
|
|
|
|
{
|
|
|
|
unsigned int tmp_tex_mask;
|
|
|
|
|
|
|
|
stride_idx = get_stride_idx(idx_data, idx_size, base_vertex_idx, start_idx, vertex_idx);
|
|
|
|
|
|
|
|
if (normal)
|
|
|
|
{
|
|
|
|
ptr = normal + stride_idx * si->elements[WINED3D_FFP_NORMAL].stride;
|
|
|
|
ops->normal[si->elements[WINED3D_FFP_NORMAL].format->emit_idx](ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diffuse)
|
|
|
|
{
|
|
|
|
ptr = diffuse + stride_idx * si->elements[WINED3D_FFP_DIFFUSE].stride;
|
|
|
|
ops->diffuse[si->elements[WINED3D_FFP_DIFFUSE].format->emit_idx](ptr);
|
|
|
|
|
|
|
|
if (untracked_material_count)
|
|
|
|
{
|
|
|
|
struct wined3d_color color;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
wined3d_color_from_d3dcolor(&color, *(const DWORD *)ptr);
|
|
|
|
for (i = 0; i < untracked_material_count; ++i)
|
|
|
|
{
|
2019-05-10 18:31:04 +02:00
|
|
|
gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK,
|
2019-06-06 14:51:04 +02:00
|
|
|
context_gl->untracked_materials[i], &color.r);
|
2018-02-25 23:23:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specular)
|
|
|
|
{
|
|
|
|
ptr = specular + stride_idx * si->elements[WINED3D_FFP_SPECULAR].stride;
|
|
|
|
ops->specular[si->elements[WINED3D_FFP_SPECULAR].format->emit_idx](ptr);
|
|
|
|
|
|
|
|
if (specular_fog)
|
|
|
|
GL_EXTCALL(glFogCoordfEXT((float)(*(const DWORD *)ptr >> 24)));
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_tex_mask = tex_mask;
|
|
|
|
for (texture_idx = 0; tmp_tex_mask; tmp_tex_mask >>= 1, ++texture_idx)
|
|
|
|
{
|
|
|
|
if (!(tmp_tex_mask & 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
|
|
|
|
ptr = tex_coords[coord_idx] + (stride_idx * si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].stride);
|
|
|
|
ops->texcoord[si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->emit_idx](
|
2019-05-10 18:31:05 +02:00
|
|
|
GL_TEXTURE0_ARB + context_gl->tex_unit_map[texture_idx], ptr);
|
2018-02-25 23:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (position)
|
|
|
|
{
|
|
|
|
ptr = position + stride_idx * si->elements[WINED3D_FFP_POSITION].stride;
|
|
|
|
ops->position[si->elements[WINED3D_FFP_POSITION].format->emit_idx](ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
|
|
|
checkGLcall("draw immediate mode");
|
|
|
|
}
|
|
|
|
|
2019-06-19 01:50:05 +02:00
|
|
|
static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_gl, const struct wined3d_state *state,
|
2018-02-25 23:23:31 +01:00
|
|
|
const struct wined3d_indirect_draw_parameters *parameters, unsigned int idx_size)
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-02-25 23:23:31 +01:00
|
|
|
struct wined3d_buffer *buffer = parameters->buffer;
|
|
|
|
const void *offset;
|
|
|
|
|
|
|
|
if (!gl_info->supported[ARB_DRAW_INDIRECT])
|
|
|
|
{
|
|
|
|
FIXME("OpenGL implementation does not support indirect draws.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-23 13:24:17 +02:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffer->buffer_object));
|
2018-02-25 23:23:31 +01:00
|
|
|
|
|
|
|
offset = (void *)(GLintptr)parameters->offset;
|
|
|
|
if (idx_size)
|
|
|
|
{
|
|
|
|
GLenum idx_type = idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
|
|
|
if (state->index_offset)
|
|
|
|
FIXME("Ignoring index offset %u.\n", state->index_offset);
|
|
|
|
GL_EXTCALL(glDrawElementsIndirect(state->gl_primitive_type, idx_type, offset));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawArraysIndirect(state->gl_primitive_type, offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0));
|
|
|
|
|
|
|
|
checkGLcall("draw indirect");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_vbos(struct wined3d_context *context,
|
|
|
|
const struct wined3d_state *state, struct wined3d_stream_info *s)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(s->elements); ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_stream_info_element *e;
|
|
|
|
|
|
|
|
if (!(s->use_map & (1u << i)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
e = &s->elements[i];
|
|
|
|
if (e->data.buffer_object)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
|
|
|
|
e->data.buffer_object = 0;
|
|
|
|
e->data.addr += (ULONG_PTR)wined3d_buffer_load_sysmem(vb, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum gl_tfb_primitive_type_from_d3d(enum wined3d_primitive_type primitive_type)
|
|
|
|
{
|
|
|
|
GLenum gl_primitive_type = gl_primitive_type_from_d3d(primitive_type);
|
|
|
|
switch (gl_primitive_type)
|
|
|
|
{
|
|
|
|
case GL_POINTS:
|
|
|
|
return GL_POINTS;
|
|
|
|
|
|
|
|
case GL_LINE_STRIP:
|
|
|
|
case GL_LINE_STRIP_ADJACENCY:
|
|
|
|
case GL_LINES_ADJACENCY:
|
|
|
|
case GL_LINES:
|
|
|
|
return GL_LINES;
|
|
|
|
|
|
|
|
case GL_TRIANGLE_FAN:
|
|
|
|
case GL_TRIANGLE_STRIP:
|
|
|
|
case GL_TRIANGLE_STRIP_ADJACENCY:
|
|
|
|
case GL_TRIANGLES_ADJACENCY:
|
|
|
|
case GL_TRIANGLES:
|
|
|
|
return GL_TRIANGLES;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return gl_primitive_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 05:42:07 +01:00
|
|
|
static unsigned int get_render_target_writemask(const struct wined3d_blend_state *state, unsigned int index)
|
|
|
|
{
|
|
|
|
if (!state)
|
|
|
|
return 0xf;
|
|
|
|
if (!state->desc.independent)
|
|
|
|
index = 0;
|
|
|
|
return state->desc.rt[index].writemask;
|
|
|
|
}
|
|
|
|
|
2018-02-25 23:23:31 +01:00
|
|
|
/* Routine common to the draw primitive and draw indexed primitive routines */
|
|
|
|
void draw_primitive(struct wined3d_device *device, const struct wined3d_state *state,
|
|
|
|
const struct wined3d_draw_parameters *parameters)
|
|
|
|
{
|
|
|
|
BOOL emulation = FALSE, rasterizer_discard = FALSE;
|
2020-03-26 13:25:57 +01:00
|
|
|
const struct wined3d_fb_state *fb = &state->fb;
|
2018-02-25 23:23:31 +01:00
|
|
|
const struct wined3d_stream_info *stream_info;
|
|
|
|
struct wined3d_rendertarget_view *dsv, *rtv;
|
|
|
|
struct wined3d_stream_info si_emulated;
|
|
|
|
struct wined3d_fence *ib_fence = NULL;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-06-06 14:51:04 +02:00
|
|
|
struct wined3d_context_gl *context_gl;
|
2018-02-25 23:23:31 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
unsigned int i, idx_size = 0;
|
|
|
|
const void *idx_data = NULL;
|
|
|
|
|
2020-04-01 21:51:09 +02:00
|
|
|
TRACE("device %p, state %p, parameters %p.\n", device, state, parameters);
|
|
|
|
|
2018-02-25 23:23:31 +01:00
|
|
|
if (!parameters->indirect && !parameters->u.direct.index_count)
|
|
|
|
return;
|
|
|
|
|
2020-04-01 21:51:09 +02:00
|
|
|
if (!parameters->indirect)
|
|
|
|
TRACE("base_vertex_idx %d, start_idx %u, index_count %u, start_instance %u, instance_count %u.\n",
|
|
|
|
parameters->u.direct.base_vertex_idx, parameters->u.direct.start_idx,
|
|
|
|
parameters->u.direct.index_count, parameters->u.direct.start_instance,
|
|
|
|
parameters->u.direct.instance_count);
|
|
|
|
|
2018-02-25 23:23:31 +01:00
|
|
|
if (!(rtv = fb->render_targets[0]))
|
|
|
|
rtv = fb->depth_stencil;
|
2018-11-23 14:41:14 +01:00
|
|
|
|
|
|
|
if (rtv && rtv->resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
FIXME("Buffer render targets not implemented.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-25 23:23:31 +01:00
|
|
|
if (rtv)
|
|
|
|
context = context_acquire(device, wined3d_texture_from_resource(rtv->resource), rtv->sub_resource_idx);
|
|
|
|
else
|
|
|
|
context = context_acquire(device, NULL, 0);
|
2019-06-06 14:51:06 +02:00
|
|
|
context_gl = wined3d_context_gl(context);
|
|
|
|
if (!context_gl->valid)
|
2018-02-25 23:23:31 +01:00
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping draw.\n");
|
|
|
|
return;
|
|
|
|
}
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2018-02-25 23:23:31 +01:00
|
|
|
|
|
|
|
if (!use_transform_feedback(state))
|
2019-06-18 00:03:33 +02:00
|
|
|
wined3d_context_gl_pause_transform_feedback(context_gl, TRUE);
|
2018-02-25 23:23:31 +01:00
|
|
|
|
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
|
|
|
{
|
|
|
|
if (!(rtv = fb->render_targets[i]) || rtv->format->id == WINED3DFMT_NULL)
|
|
|
|
continue;
|
|
|
|
|
2020-03-16 05:42:07 +01:00
|
|
|
if (get_render_target_writemask(state->blend_state, i))
|
2018-02-25 23:23:31 +01:00
|
|
|
{
|
|
|
|
wined3d_rendertarget_view_load_location(rtv, context, rtv->resource->draw_binding);
|
|
|
|
wined3d_rendertarget_view_invalidate_location(rtv, ~rtv->resource->draw_binding);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_rendertarget_view_prepare_location(rtv, context, rtv->resource->draw_binding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dsv = fb->depth_stencil))
|
|
|
|
{
|
|
|
|
/* Note that this depends on the context_acquire() call above to set
|
|
|
|
* context->render_offscreen properly. We don't currently take the
|
|
|
|
* Z-compare function into account, but we could skip loading the
|
|
|
|
* depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
|
|
|
|
* that we never copy the stencil data.*/
|
|
|
|
DWORD location = context->render_offscreen ? dsv->resource->draw_binding : WINED3D_LOCATION_DRAWABLE;
|
|
|
|
|
|
|
|
if (state->render_states[WINED3D_RS_ZWRITEENABLE] || state->render_states[WINED3D_RS_ZENABLE])
|
|
|
|
wined3d_rendertarget_view_load_location(dsv, context, location);
|
|
|
|
else
|
|
|
|
wined3d_rendertarget_view_prepare_location(dsv, context, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters->indirect)
|
|
|
|
wined3d_buffer_load(parameters->u.indirect.buffer, context, state);
|
|
|
|
|
2020-03-26 13:26:00 +01:00
|
|
|
if (!context_apply_draw_state(context, device, state, parameters->indexed))
|
2018-02-25 23:23:31 +01:00
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Unable to apply draw state, skipping draw.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dsv && state->render_states[WINED3D_RS_ZWRITEENABLE])
|
|
|
|
{
|
|
|
|
DWORD location = context->render_offscreen ? dsv->resource->draw_binding : WINED3D_LOCATION_DRAWABLE;
|
|
|
|
|
|
|
|
wined3d_rendertarget_view_validate_location(dsv, location);
|
|
|
|
wined3d_rendertarget_view_invalidate_location(dsv, ~location);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_info = &context->stream_info;
|
|
|
|
|
|
|
|
if (parameters->indexed)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer *index_buffer = state->index_buffer;
|
2019-09-23 13:24:17 +02:00
|
|
|
if (!index_buffer->buffer_object || !stream_info->all_vbo)
|
2018-02-25 23:23:31 +01:00
|
|
|
{
|
|
|
|
idx_data = index_buffer->resource.heap_memory;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ib_fence = index_buffer->fence;
|
|
|
|
idx_data = NULL;
|
|
|
|
}
|
|
|
|
idx_data = (const BYTE *)idx_data + state->index_offset;
|
|
|
|
|
|
|
|
if (state->index_format == WINED3DFMT_R16_UINT)
|
|
|
|
idx_size = 2;
|
|
|
|
else
|
|
|
|
idx_size = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!use_vs(state))
|
|
|
|
{
|
2019-06-06 14:51:04 +02:00
|
|
|
if (!stream_info->position_transformed && context_gl->untracked_material_count
|
2018-02-25 23:23:31 +01:00
|
|
|
&& state->render_states[WINED3D_RS_LIGHTING])
|
|
|
|
{
|
|
|
|
static BOOL warned;
|
|
|
|
|
|
|
|
if (!warned++)
|
|
|
|
FIXME("Using software emulation because not all material properties could be tracked.\n");
|
|
|
|
else
|
|
|
|
WARN_(d3d_perf)("Using software emulation because not all material properties could be tracked.\n");
|
|
|
|
emulation = TRUE;
|
|
|
|
}
|
|
|
|
else if (context->fog_coord && state->render_states[WINED3D_RS_FOGENABLE])
|
|
|
|
{
|
|
|
|
static BOOL warned;
|
|
|
|
|
|
|
|
/* Either write a pipeline replacement shader or convert the
|
|
|
|
* specular alpha from unsigned byte to a float in the vertex
|
|
|
|
* buffer. */
|
|
|
|
if (!warned++)
|
|
|
|
FIXME("Using software emulation because manual fog coordinates are provided.\n");
|
|
|
|
else
|
|
|
|
WARN_(d3d_perf)("Using software emulation because manual fog coordinates are provided.\n");
|
|
|
|
emulation = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emulation)
|
|
|
|
{
|
|
|
|
si_emulated = context->stream_info;
|
|
|
|
remove_vbos(context, state, &si_emulated);
|
|
|
|
stream_info = &si_emulated;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_transform_feedback(state))
|
|
|
|
{
|
|
|
|
const struct wined3d_shader *shader = state->shader[WINED3D_SHADER_TYPE_GEOMETRY];
|
|
|
|
|
|
|
|
if (is_rasterization_disabled(shader))
|
|
|
|
{
|
|
|
|
glEnable(GL_RASTERIZER_DISCARD);
|
|
|
|
checkGLcall("enable rasterizer discard");
|
|
|
|
rasterizer_discard = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->transform_feedback_paused)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glResumeTransformFeedback());
|
|
|
|
checkGLcall("glResumeTransformFeedback");
|
|
|
|
context->transform_feedback_paused = 0;
|
|
|
|
}
|
|
|
|
else if (!context->transform_feedback_active)
|
|
|
|
{
|
2018-04-23 16:20:16 +02:00
|
|
|
enum wined3d_primitive_type primitive_type = shader->u.gs.output_type
|
|
|
|
? shader->u.gs.output_type : d3d_primitive_type_from_gl(state->gl_primitive_type);
|
|
|
|
GLenum mode = gl_tfb_primitive_type_from_d3d(primitive_type);
|
2018-02-25 23:23:31 +01:00
|
|
|
GL_EXTCALL(glBeginTransformFeedback(mode));
|
|
|
|
checkGLcall("glBeginTransformFeedback");
|
|
|
|
context->transform_feedback_active = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->gl_primitive_type == GL_PATCHES)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glPatchParameteri(GL_PATCH_VERTICES, state->gl_patch_vertices));
|
|
|
|
checkGLcall("glPatchParameteri");
|
|
|
|
}
|
|
|
|
|
2019-10-23 18:44:58 +02:00
|
|
|
if (context->uses_fbo_attached_resources)
|
|
|
|
{
|
|
|
|
static unsigned int fixme_once;
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_BARRIER])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glTextureBarrier());
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[NV_TEXTURE_BARRIER])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glTextureBarrierNV());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!fixme_once++)
|
|
|
|
FIXME("Sampling attached render targets is not supported.\n");
|
|
|
|
|
|
|
|
WARN("Sampling attached render targets is not supported, skipping draw.\n");
|
|
|
|
context_release(context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
checkGLcall("glTextureBarrier");
|
|
|
|
}
|
|
|
|
|
2018-02-25 23:23:31 +01:00
|
|
|
if (parameters->indirect)
|
|
|
|
{
|
|
|
|
if (!context->use_immediate_mode_draw && !emulation)
|
2019-06-19 01:50:05 +02:00
|
|
|
wined3d_context_gl_draw_indirect(context_gl, state, ¶meters->u.indirect, idx_size);
|
2018-02-25 23:23:31 +01:00
|
|
|
else
|
|
|
|
FIXME("Indirect draws with immediate mode/emulation are not supported.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned int instance_count = parameters->u.direct.instance_count;
|
|
|
|
if (context->instance_count)
|
|
|
|
instance_count = context->instance_count;
|
|
|
|
|
|
|
|
if (context->use_immediate_mode_draw || emulation)
|
2019-05-10 18:31:04 +02:00
|
|
|
draw_primitive_immediate_mode(wined3d_context_gl(context), state, stream_info, idx_data,
|
2018-02-25 23:23:31 +01:00
|
|
|
idx_size, parameters->u.direct.base_vertex_idx,
|
|
|
|
parameters->u.direct.start_idx, parameters->u.direct.index_count, instance_count);
|
|
|
|
else
|
2019-06-18 00:03:35 +02:00
|
|
|
wined3d_context_gl_draw_primitive_arrays(context_gl, state, idx_data, idx_size,
|
|
|
|
parameters->u.direct.base_vertex_idx, parameters->u.direct.start_idx,
|
|
|
|
parameters->u.direct.index_count, parameters->u.direct.start_instance, instance_count);
|
2018-02-25 23:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (context->uses_uavs)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glMemoryBarrier(GL_ALL_BARRIER_BITS));
|
|
|
|
checkGLcall("glMemoryBarrier");
|
|
|
|
}
|
|
|
|
|
2019-06-18 00:03:33 +02:00
|
|
|
wined3d_context_gl_pause_transform_feedback(context_gl, FALSE);
|
2018-02-25 23:23:31 +01:00
|
|
|
|
|
|
|
if (rasterizer_discard)
|
|
|
|
{
|
|
|
|
glDisable(GL_RASTERIZER_DISCARD);
|
|
|
|
checkGLcall("disable rasterizer discard");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ib_fence)
|
|
|
|
wined3d_fence_issue(ib_fence, device);
|
|
|
|
for (i = 0; i < context->buffer_fence_count; ++i)
|
|
|
|
wined3d_fence_issue(context->buffer_fences[i], device);
|
|
|
|
|
|
|
|
context_release(context);
|
2020-04-01 21:51:09 +02:00
|
|
|
|
|
|
|
TRACE("Draw completed.\n");
|
2018-02-25 23:23:31 +01:00
|
|
|
}
|
2018-04-12 13:58:13 +02:00
|
|
|
|
2019-06-10 22:15:29 +02:00
|
|
|
void wined3d_context_gl_unload_tex_coords(const struct wined3d_context_gl *context_gl)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-04-19 13:20:12 +02:00
|
|
|
unsigned int texture_idx;
|
|
|
|
|
|
|
|
for (texture_idx = 0; texture_idx < gl_info->limits.texture_coords; ++texture_idx)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.ext.p_glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx);
|
|
|
|
gl_info->gl_ops.gl.p_glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-08 15:21:38 +02:00
|
|
|
void wined3d_context_gl_load_tex_coords(const struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_stream_info *si, GLuint *current_bo, const struct wined3d_state *state)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-09-21 14:41:50 +02:00
|
|
|
const struct wined3d_format_gl *format_gl;
|
2018-04-19 13:20:12 +02:00
|
|
|
unsigned int mapped_stage = 0;
|
|
|
|
unsigned int texture_idx;
|
|
|
|
|
2019-05-08 15:21:38 +02:00
|
|
|
for (texture_idx = 0; texture_idx < context_gl->c.d3d_info->limits.ffp_blend_stages; ++texture_idx)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
|
|
|
unsigned int coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
|
|
|
|
|
2019-05-10 18:31:05 +02:00
|
|
|
if ((mapped_stage = context_gl->tex_unit_map[texture_idx]) == WINED3D_UNMAPPED_STAGE)
|
2018-04-19 13:20:12 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mapped_stage >= gl_info->limits.texture_coords)
|
|
|
|
{
|
|
|
|
FIXME("Attempted to load unsupported texture coordinate %u.\n", mapped_stage);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-02-20 21:53:57 +01:00
|
|
|
if (coord_idx < WINED3D_MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx))))
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_stream_info_element *e = &si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx];
|
|
|
|
|
2018-10-23 10:48:38 +02:00
|
|
|
TRACE("Setting up texture %u, idx %u, coord_idx %u, data %s.\n",
|
|
|
|
texture_idx, mapped_stage, coord_idx, debug_bo_address(&e->data));
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
if (*current_bo != e->data.buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
*current_bo = e->data.buffer_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
|
|
|
|
checkGLcall("glClientActiveTextureARB");
|
|
|
|
|
|
|
|
/* The coords to supply depend completely on the fvf/vertex shader. */
|
2018-09-21 14:41:50 +02:00
|
|
|
format_gl = wined3d_format_gl(e->format);
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoordPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
|
2018-04-19 13:20:12 +02:00
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
|
|
|
gl_info->gl_ops.gl.p_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + mapped_stage, 0, 0, 0, 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gl_info->supported[NV_REGISTER_COMBINERS])
|
|
|
|
{
|
|
|
|
/* The number of the mapped stages increases monotonically, so it's fine to use the last used one. */
|
|
|
|
for (texture_idx = mapped_stage + 1; texture_idx < gl_info->limits.textures; ++texture_idx)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, 0, 0, 0, 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkGLcall("loadTexCoords");
|
|
|
|
}
|
|
|
|
|
2019-06-19 01:50:07 +02:00
|
|
|
/* This should match any arrays loaded in wined3d_context_gl_load_vertex_data(). */
|
2019-06-19 01:50:06 +02:00
|
|
|
static void wined3d_context_gl_unload_vertex_data(struct wined3d_context_gl *context_gl)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-04-19 13:20:12 +02:00
|
|
|
|
2019-06-19 01:50:06 +02:00
|
|
|
if (!context_gl->c.namedArraysLoaded)
|
2018-04-19 13:20:13 +02:00
|
|
|
return;
|
2018-04-19 13:20:12 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
gl_info->gl_ops.gl.p_glDisableClientState(GL_NORMAL_ARRAY);
|
|
|
|
gl_info->gl_ops.gl.p_glDisableClientState(GL_COLOR_ARRAY);
|
|
|
|
if (gl_info->supported[EXT_SECONDARY_COLOR])
|
|
|
|
gl_info->gl_ops.gl.p_glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
|
2019-06-10 22:15:29 +02:00
|
|
|
wined3d_context_gl_unload_tex_coords(context_gl);
|
2019-06-19 01:50:06 +02:00
|
|
|
context_gl->c.namedArraysLoaded = FALSE;
|
2018-04-19 13:20:12 +02:00
|
|
|
}
|
|
|
|
|
2019-06-19 01:50:07 +02:00
|
|
|
static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *context_gl,
|
2018-04-19 13:20:12 +02:00
|
|
|
const struct wined3d_stream_info *si, const struct wined3d_state *state)
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-04-19 13:20:12 +02:00
|
|
|
const struct wined3d_stream_info_element *e;
|
2018-09-21 14:41:50 +02:00
|
|
|
const struct wined3d_format_gl *format_gl;
|
2018-04-19 13:20:12 +02:00
|
|
|
GLuint current_bo;
|
|
|
|
|
2019-06-19 01:50:07 +02:00
|
|
|
TRACE("context_gl %p, si %p, state %p.\n", context_gl, si, state);
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
/* This is used for the fixed-function pipeline only, and the
|
|
|
|
* fixed-function pipeline doesn't do instancing. */
|
2019-06-19 01:50:07 +02:00
|
|
|
context_gl->c.instance_count = 0;
|
2018-04-19 13:20:12 +02:00
|
|
|
current_bo = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0u : 0;
|
|
|
|
|
|
|
|
/* Blend data */
|
|
|
|
if ((si->use_map & (1u << WINED3D_FFP_BLENDWEIGHT))
|
|
|
|
|| si->use_map & (1u << WINED3D_FFP_BLENDINDICES))
|
|
|
|
{
|
|
|
|
/* TODO: Support vertex blending in immediate mode draws. No need to
|
|
|
|
* write a FIXME here, this is done after the general vertex
|
|
|
|
* declaration decoding. */
|
|
|
|
WARN("Vertex blending not supported.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Point Size */
|
|
|
|
if (si->use_map & (1u << WINED3D_FFP_PSIZE))
|
|
|
|
{
|
|
|
|
/* No such functionality in the fixed-function GL pipeline. */
|
|
|
|
WARN("Per-vertex point size not supported.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Position */
|
|
|
|
if (si->use_map & (1u << WINED3D_FFP_POSITION))
|
|
|
|
{
|
|
|
|
e = &si->elements[WINED3D_FFP_POSITION];
|
2018-09-21 14:41:50 +02:00
|
|
|
format_gl = wined3d_format_gl(e->format);
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
if (current_bo != e->data.buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
current_bo = e->data.buffer_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n",
|
2018-09-21 14:41:50 +02:00
|
|
|
format_gl->vtx_format, format_gl->vtx_type, e->stride,
|
2018-04-19 13:20:12 +02:00
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
2018-09-21 14:41:50 +02:00
|
|
|
gl_info->gl_ops.gl.p_glVertexPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
|
2018-04-19 13:20:12 +02:00
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
|
|
|
checkGLcall("glVertexPointer(...)");
|
|
|
|
gl_info->gl_ops.gl.p_glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
checkGLcall("glEnableClientState(GL_VERTEX_ARRAY)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normals */
|
|
|
|
if (si->use_map & (1u << WINED3D_FFP_NORMAL))
|
|
|
|
{
|
|
|
|
e = &si->elements[WINED3D_FFP_NORMAL];
|
2018-09-21 14:41:50 +02:00
|
|
|
format_gl = wined3d_format_gl(e->format);
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
if (current_bo != e->data.buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
current_bo = e->data.buffer_object;
|
|
|
|
}
|
|
|
|
|
2018-09-21 14:41:50 +02:00
|
|
|
TRACE("glNormalPointer(%#x, %#x, %p);\n", format_gl->vtx_type, e->stride,
|
2018-04-19 13:20:12 +02:00
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
2018-09-21 14:41:50 +02:00
|
|
|
gl_info->gl_ops.gl.p_glNormalPointer(format_gl->vtx_type, e->stride,
|
2018-04-19 13:20:12 +02:00
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
|
|
|
checkGLcall("glNormalPointer(...)");
|
|
|
|
gl_info->gl_ops.gl.p_glEnableClientState(GL_NORMAL_ARRAY);
|
|
|
|
checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glNormal3f(0, 0, 0);
|
|
|
|
checkGLcall("glNormal3f(0, 0, 0)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Diffuse colour */
|
|
|
|
if (si->use_map & (1u << WINED3D_FFP_DIFFUSE))
|
|
|
|
{
|
|
|
|
e = &si->elements[WINED3D_FFP_DIFFUSE];
|
2018-09-21 14:41:50 +02:00
|
|
|
format_gl = wined3d_format_gl(e->format);
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
if (current_bo != e->data.buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
current_bo = e->data.buffer_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("glColorPointer(%#x, %#x %#x, %p);\n",
|
2018-09-21 14:41:50 +02:00
|
|
|
format_gl->vtx_format, format_gl->vtx_type, e->stride,
|
2018-04-19 13:20:12 +02:00
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
2018-09-21 14:41:50 +02:00
|
|
|
gl_info->gl_ops.gl.p_glColorPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
|
2018-04-19 13:20:12 +02:00
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
|
|
|
checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
|
|
|
|
gl_info->gl_ops.gl.p_glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
checkGLcall("glEnableClientState(GL_COLOR_ARRAY)");
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
checkGLcall("glColor4f(1, 1, 1, 1)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Specular colour */
|
|
|
|
if (si->use_map & (1u << WINED3D_FFP_SPECULAR))
|
|
|
|
{
|
|
|
|
TRACE("Setting specular colour.\n");
|
|
|
|
|
|
|
|
e = &si->elements[WINED3D_FFP_SPECULAR];
|
|
|
|
|
|
|
|
if (gl_info->supported[EXT_SECONDARY_COLOR])
|
|
|
|
{
|
2018-09-21 14:41:50 +02:00
|
|
|
GLint format;
|
|
|
|
GLenum type;
|
|
|
|
|
|
|
|
format_gl = wined3d_format_gl(e->format);
|
|
|
|
type = format_gl->vtx_type;
|
|
|
|
format = format_gl->vtx_format;
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
if (current_bo != e->data.buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
current_bo = e->data.buffer_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format != 4 || (gl_info->quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
|
|
|
|
{
|
|
|
|
/* Usually specular colors only allow 3 components, since they have no alpha. In D3D, the specular alpha
|
|
|
|
* contains the fog coordinate, which is passed to GL with GL_EXT_fog_coord. However, the fixed function
|
|
|
|
* vertex pipeline can pass the specular alpha through, and pixel shaders can read it. So it GL accepts
|
|
|
|
* 4 component secondary colors use it
|
|
|
|
*/
|
|
|
|
TRACE("glSecondaryColorPointer(%#x, %#x, %#x, %p);\n", format, type, e->stride,
|
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
|
|
|
GL_EXTCALL(glSecondaryColorPointerEXT(format, type, e->stride,
|
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride));
|
|
|
|
checkGLcall("glSecondaryColorPointerEXT(format, type, ...)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GL_UNSIGNED_BYTE:
|
|
|
|
TRACE("glSecondaryColorPointer(3, GL_UNSIGNED_BYTE, %#x, %p);\n", e->stride,
|
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
|
|
|
GL_EXTCALL(glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, e->stride,
|
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride));
|
|
|
|
checkGLcall("glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, ...)");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Add 4 component specular colour pointers for type %#x.\n", type);
|
|
|
|
/* Make sure that the right colour component is dropped. */
|
|
|
|
TRACE("glSecondaryColorPointer(3, %#x, %#x, %p);\n", type, e->stride,
|
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride);
|
|
|
|
GL_EXTCALL(glSecondaryColorPointerEXT(3, type, e->stride,
|
|
|
|
e->data.addr + state->load_base_vertex_index * e->stride));
|
|
|
|
checkGLcall("glSecondaryColorPointerEXT(3, type, ...)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gl_info->gl_ops.gl.p_glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
|
|
|
|
checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Specular colour is not supported in this GL implementation.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gl_info->supported[EXT_SECONDARY_COLOR])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
|
|
|
|
checkGLcall("glSecondaryColor3fEXT(0, 0, 0)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Specular colour is not supported in this GL implementation.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Texture coordinates */
|
2019-05-08 15:21:38 +02:00
|
|
|
wined3d_context_gl_load_tex_coords(context_gl, si, ¤t_bo, state);
|
2018-04-19 13:20:12 +02:00
|
|
|
}
|
|
|
|
|
2019-06-19 01:50:08 +02:00
|
|
|
static void wined3d_context_gl_unload_numbered_array(struct wined3d_context_gl *context_gl, unsigned int i)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
GL_EXTCALL(glDisableVertexAttribArray(i));
|
|
|
|
checkGLcall("glDisableVertexAttribArray");
|
|
|
|
if (gl_info->supported[ARB_INSTANCED_ARRAYS])
|
|
|
|
GL_EXTCALL(glVertexAttribDivisor(i, 0));
|
|
|
|
|
2019-06-19 01:50:08 +02:00
|
|
|
context_gl->c.numbered_array_mask &= ~(1u << i);
|
2018-04-19 13:20:12 +02:00
|
|
|
}
|
|
|
|
|
2019-06-19 23:12:17 +02:00
|
|
|
static void wined3d_context_gl_unload_numbered_arrays(struct wined3d_context_gl *context_gl)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
2019-06-19 23:12:17 +02:00
|
|
|
uint32_t mask = context_gl->c.numbered_array_mask;
|
2018-04-19 13:20:12 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2019-06-19 23:12:17 +02:00
|
|
|
while (mask)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
2019-06-19 23:12:17 +02:00
|
|
|
i = wined3d_bit_scan(&mask);
|
2019-06-19 01:50:08 +02:00
|
|
|
wined3d_context_gl_unload_numbered_array(context_gl, i);
|
2018-04-19 13:20:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:24 +02:00
|
|
|
static void wined3d_context_gl_load_numbered_arrays(struct wined3d_context_gl *context_gl,
|
2018-04-19 13:20:12 +02:00
|
|
|
const struct wined3d_stream_info *stream_info, const struct wined3d_state *state)
|
|
|
|
{
|
2019-05-14 12:56:24 +02:00
|
|
|
struct wined3d_context *context = &context_gl->c;
|
2018-04-19 13:20:12 +02:00
|
|
|
const struct wined3d_shader *vs = state->shader[WINED3D_SHADER_TYPE_VERTEX];
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-04-19 13:20:12 +02:00
|
|
|
GLuint current_bo;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Default to no instancing. */
|
|
|
|
context->instance_count = 0;
|
|
|
|
current_bo = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0u : 0;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_ATTRIBS; ++i)
|
|
|
|
{
|
|
|
|
const struct wined3d_stream_info_element *element = &stream_info->elements[i];
|
|
|
|
const struct wined3d_stream_state *stream;
|
2018-09-21 14:41:50 +02:00
|
|
|
const struct wined3d_format_gl *format_gl;
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
if (!(stream_info->use_map & (1u << i)))
|
|
|
|
{
|
|
|
|
if (context->numbered_array_mask & (1u << i))
|
2019-06-19 01:50:08 +02:00
|
|
|
wined3d_context_gl_unload_numbered_array(context_gl, i);
|
2018-04-19 13:20:12 +02:00
|
|
|
if (!use_vs(state) && i == WINED3D_FFP_DIFFUSE)
|
2019-05-14 12:56:26 +02:00
|
|
|
{
|
|
|
|
if (!(context_gl->default_attrib_value_set & (1u << i)) || !context_gl->diffuse_attrib_to_1)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glVertexAttrib4f(i, 1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
context_gl->diffuse_attrib_to_1 = 1;
|
|
|
|
}
|
|
|
|
}
|
2018-04-19 13:20:12 +02:00
|
|
|
else
|
2019-05-14 12:56:26 +02:00
|
|
|
{
|
|
|
|
if (!(context_gl->default_attrib_value_set & (1u << i)))
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glVertexAttrib4f(i, 0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
if (i == WINED3D_FFP_DIFFUSE)
|
|
|
|
context_gl->diffuse_attrib_to_1 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
context_gl->default_attrib_value_set |= 1u << i;
|
2018-04-19 13:20:12 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-09-21 14:41:50 +02:00
|
|
|
format_gl = wined3d_format_gl(element->format);
|
2018-04-19 13:20:12 +02:00
|
|
|
stream = &state->streams[element->stream_idx];
|
|
|
|
|
|
|
|
if ((stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA) && !context->instance_count)
|
2019-02-08 17:34:13 +01:00
|
|
|
context->instance_count = state->streams[0].frequency;
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_INSTANCED_ARRAYS])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glVertexAttribDivisor(i, element->divisor));
|
|
|
|
}
|
|
|
|
else if (element->divisor)
|
|
|
|
{
|
|
|
|
/* Unload instanced arrays, they will be loaded using immediate
|
|
|
|
* mode instead. */
|
|
|
|
if (context->numbered_array_mask & (1u << i))
|
2019-06-19 01:50:08 +02:00
|
|
|
wined3d_context_gl_unload_numbered_array(context_gl, i);
|
2019-05-14 12:56:26 +02:00
|
|
|
context_gl->default_attrib_value_set &= ~(1u << i);
|
2018-04-19 13:20:12 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-10-23 10:48:38 +02:00
|
|
|
TRACE("Loading array %u %s.\n", i, debug_bo_address(&element->data));
|
2018-04-19 13:20:12 +02:00
|
|
|
|
|
|
|
if (element->stride)
|
|
|
|
{
|
2018-09-21 14:41:50 +02:00
|
|
|
DWORD format_flags = format_gl->f.flags[WINED3D_GL_RES_TYPE_BUFFER];
|
2018-09-09 22:32:47 +02:00
|
|
|
|
2018-04-19 13:20:12 +02:00
|
|
|
if (current_bo != element->data.buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, element->data.buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
current_bo = element->data.buffer_object;
|
|
|
|
}
|
|
|
|
/* Use the VBO to find out if a vertex buffer exists, not the vb
|
|
|
|
* pointer. vb can point to a user pointer data blob. In that case
|
|
|
|
* current_bo will be 0. If there is a vertex buffer but no vbo we
|
|
|
|
* won't be load converted attributes anyway. */
|
2018-09-09 22:32:47 +02:00
|
|
|
if (vs && vs->reg_maps.shader_version.major >= 4 && (format_flags & WINED3DFMT_FLAG_INTEGER))
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
2018-09-21 14:41:50 +02:00
|
|
|
GL_EXTCALL(glVertexAttribIPointer(i, format_gl->vtx_format, format_gl->vtx_type,
|
2018-04-19 13:20:12 +02:00
|
|
|
element->stride, element->data.addr + state->load_base_vertex_index * element->stride));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-21 14:41:50 +02:00
|
|
|
GL_EXTCALL(glVertexAttribPointer(i, format_gl->vtx_format, format_gl->vtx_type,
|
2018-09-09 22:32:47 +02:00
|
|
|
!!(format_flags & WINED3DFMT_FLAG_NORMALISED), element->stride,
|
2018-04-19 13:20:12 +02:00
|
|
|
element->data.addr + state->load_base_vertex_index * element->stride));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(context->numbered_array_mask & (1u << i)))
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glEnableVertexAttribArray(i));
|
|
|
|
context->numbered_array_mask |= (1u << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Stride = 0 means always the same values.
|
|
|
|
* glVertexAttribPointer() doesn't do that. Instead disable the
|
|
|
|
* pointer and set up the attribute statically. But we have to
|
|
|
|
* figure out the system memory address. */
|
|
|
|
const BYTE *ptr = element->data.addr;
|
|
|
|
if (element->data.buffer_object)
|
|
|
|
ptr += (ULONG_PTR)wined3d_buffer_load_sysmem(stream->buffer, context);
|
|
|
|
|
|
|
|
if (context->numbered_array_mask & (1u << i))
|
2019-06-19 01:50:08 +02:00
|
|
|
wined3d_context_gl_unload_numbered_array(context_gl, i);
|
2018-04-19 13:20:12 +02:00
|
|
|
|
2018-09-21 14:41:50 +02:00
|
|
|
switch (format_gl->f.id)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
|
|
|
case WINED3DFMT_R32_FLOAT:
|
|
|
|
GL_EXTCALL(glVertexAttrib1fv(i, (const GLfloat *)ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R32G32_FLOAT:
|
|
|
|
GL_EXTCALL(glVertexAttrib2fv(i, (const GLfloat *)ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
|
|
|
GL_EXTCALL(glVertexAttrib3fv(i, (const GLfloat *)ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
|
|
|
GL_EXTCALL(glVertexAttrib4fv(i, (const GLfloat *)ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R8G8B8A8_UINT:
|
|
|
|
GL_EXTCALL(glVertexAttrib4ubv(i, ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_B8G8R8A8_UNORM:
|
|
|
|
if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
|
|
|
|
{
|
|
|
|
const DWORD *src = (const DWORD *)ptr;
|
|
|
|
DWORD c = *src & 0xff00ff00u;
|
|
|
|
c |= (*src & 0xff0000u) >> 16;
|
|
|
|
c |= (*src & 0xffu) << 16;
|
|
|
|
GL_EXTCALL(glVertexAttrib4Nubv(i, (GLubyte *)&c));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* else fallthrough */
|
|
|
|
case WINED3DFMT_R8G8B8A8_UNORM:
|
|
|
|
GL_EXTCALL(glVertexAttrib4Nubv(i, ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R16G16_SINT:
|
|
|
|
GL_EXTCALL(glVertexAttrib2sv(i, (const GLshort *)ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
|
|
|
GL_EXTCALL(glVertexAttrib4sv(i, (const GLshort *)ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R16G16_SNORM:
|
|
|
|
{
|
|
|
|
const GLshort s[4] = {((const GLshort *)ptr)[0], ((const GLshort *)ptr)[1], 0, 1};
|
|
|
|
GL_EXTCALL(glVertexAttrib4Nsv(i, s));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WINED3DFMT_R16G16_UNORM:
|
|
|
|
{
|
|
|
|
const GLushort s[4] = {((const GLushort *)ptr)[0], ((const GLushort *)ptr)[1], 0, 1};
|
|
|
|
GL_EXTCALL(glVertexAttrib4Nusv(i, s));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WINED3DFMT_R16G16B16A16_SNORM:
|
|
|
|
GL_EXTCALL(glVertexAttrib4Nsv(i, (const GLshort *)ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R16G16B16A16_UNORM:
|
|
|
|
GL_EXTCALL(glVertexAttrib4Nusv(i, (const GLushort *)ptr));
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R10G10B10X2_UINT:
|
|
|
|
FIXME("Unsure about WINED3DDECLTYPE_UDEC3.\n");
|
|
|
|
/*glVertexAttrib3usvARB(i, (const GLushort *)ptr); Does not exist */
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R10G10B10X2_SNORM:
|
|
|
|
FIXME("Unsure about WINED3DDECLTYPE_DEC3N.\n");
|
|
|
|
/*glVertexAttrib3NusvARB(i, (const GLushort *)ptr); Does not exist */
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R16G16_FLOAT:
|
|
|
|
if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
|
|
|
|
{
|
|
|
|
/* Not supported by GL_ARB_half_float_vertex. */
|
|
|
|
GL_EXTCALL(glVertexAttrib2hvNV(i, (const GLhalfNV *)ptr));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float x = float_16_to_32(((const unsigned short *)ptr) + 0);
|
|
|
|
float y = float_16_to_32(((const unsigned short *)ptr) + 1);
|
|
|
|
GL_EXTCALL(glVertexAttrib2f(i, x, y));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
|
|
|
if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
|
|
|
|
{
|
|
|
|
/* Not supported by GL_ARB_half_float_vertex. */
|
|
|
|
GL_EXTCALL(glVertexAttrib4hvNV(i, (const GLhalfNV *)ptr));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float x = float_16_to_32(((const unsigned short *)ptr) + 0);
|
|
|
|
float y = float_16_to_32(((const unsigned short *)ptr) + 1);
|
|
|
|
float z = float_16_to_32(((const unsigned short *)ptr) + 2);
|
|
|
|
float w = float_16_to_32(((const unsigned short *)ptr) + 3);
|
|
|
|
GL_EXTCALL(glVertexAttrib4f(i, x, y, z, w));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unexpected declaration in stride 0 attributes.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2019-05-14 12:56:26 +02:00
|
|
|
context_gl->default_attrib_value_set &= ~(1u << i);
|
2018-04-19 13:20:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
checkGLcall("Loading numbered arrays");
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:56:25 +02:00
|
|
|
void wined3d_context_gl_update_stream_sources(struct wined3d_context_gl *context_gl,
|
|
|
|
const struct wined3d_state *state)
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
2019-05-14 12:56:25 +02:00
|
|
|
if (context_gl->c.use_immediate_mode_draw)
|
2018-04-19 13:20:15 +02:00
|
|
|
return;
|
2018-04-19 13:20:12 +02:00
|
|
|
|
2019-06-19 01:50:06 +02:00
|
|
|
wined3d_context_gl_unload_vertex_data(context_gl);
|
2019-05-14 12:56:25 +02:00
|
|
|
if (context_gl->c.d3d_info->ffp_generic_attributes || use_vs(state))
|
2018-04-19 13:20:12 +02:00
|
|
|
{
|
|
|
|
TRACE("Loading numbered arrays.\n");
|
2019-05-14 12:56:25 +02:00
|
|
|
wined3d_context_gl_load_numbered_arrays(context_gl, &context_gl->c.stream_info, state);
|
2018-04-19 13:20:15 +02:00
|
|
|
return;
|
2018-04-19 13:20:12 +02:00
|
|
|
}
|
2018-04-19 13:20:15 +02:00
|
|
|
|
|
|
|
TRACE("Loading named arrays.\n");
|
2019-06-19 23:12:17 +02:00
|
|
|
wined3d_context_gl_unload_numbered_arrays(context_gl);
|
2019-06-19 01:50:07 +02:00
|
|
|
wined3d_context_gl_load_vertex_data(context_gl, &context_gl->c.stream_info, state);
|
2019-05-14 12:56:25 +02:00
|
|
|
context_gl->c.namedArraysLoaded = TRUE;
|
2018-04-19 13:20:12 +02:00
|
|
|
}
|
|
|
|
|
2018-04-12 13:58:14 +02:00
|
|
|
static void apply_texture_blit_state(const struct wined3d_gl_info *gl_info, struct gl_texture *texture,
|
|
|
|
GLenum target, unsigned int level, enum wined3d_texture_filter_type filter)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(filter));
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
|
|
|
|
wined3d_gl_min_mip_filter(filter, WINED3D_TEXF_NONE));
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, level);
|
|
|
|
|
|
|
|
/* We changed the filtering settings on the texture. Make sure they get
|
|
|
|
* reset on subsequent draws. */
|
|
|
|
texture->sampler_desc.mag_filter = WINED3D_TEXF_POINT;
|
|
|
|
texture->sampler_desc.min_filter = WINED3D_TEXF_POINT;
|
|
|
|
texture->sampler_desc.mip_filter = WINED3D_TEXF_NONE;
|
|
|
|
texture->sampler_desc.address_u = WINED3D_TADDRESS_CLAMP;
|
|
|
|
texture->sampler_desc.address_v = WINED3D_TADDRESS_CLAMP;
|
|
|
|
texture->sampler_desc.srgb_decode = FALSE;
|
|
|
|
texture->base_level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2019-06-19 23:12:18 +02:00
|
|
|
void wined3d_context_gl_draw_shaded_quad(struct wined3d_context_gl *context_gl, struct wined3d_texture_gl *texture_gl,
|
2018-04-12 13:58:14 +02:00
|
|
|
unsigned int sub_resource_idx, const RECT *src_rect, const RECT *dst_rect,
|
|
|
|
enum wined3d_texture_filter_type filter)
|
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-04-12 13:58:14 +02:00
|
|
|
struct wined3d_blt_info info;
|
|
|
|
unsigned int level, w, h, i;
|
|
|
|
SIZE dst_size;
|
|
|
|
struct blit_vertex
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
struct wined3d_vec3 texcoord;
|
|
|
|
}
|
|
|
|
quad[4];
|
|
|
|
|
2018-10-30 10:48:44 +01:00
|
|
|
texture2d_get_blt_info(texture_gl, sub_resource_idx, src_rect, &info);
|
2018-04-12 13:58:14 +02:00
|
|
|
|
2018-10-30 10:48:43 +01:00
|
|
|
level = sub_resource_idx % texture_gl->t.level_count;
|
2019-05-07 12:30:11 +02:00
|
|
|
wined3d_context_gl_bind_texture(context_gl, info.bind_target, texture_gl->texture_rgb.name);
|
2018-10-30 10:48:43 +01:00
|
|
|
apply_texture_blit_state(gl_info, &texture_gl->texture_rgb, info.bind_target, level, filter);
|
2018-04-12 13:58:14 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAX_LEVEL, level);
|
|
|
|
|
2019-05-20 23:41:06 +02:00
|
|
|
wined3d_context_gl_get_rt_size(context_gl, &dst_size);
|
2018-04-12 13:58:14 +02:00
|
|
|
w = dst_size.cx;
|
|
|
|
h = dst_size.cy;
|
|
|
|
|
|
|
|
quad[0].x = dst_rect->left * 2.0f / w - 1.0f;
|
|
|
|
quad[0].y = dst_rect->top * 2.0f / h - 1.0f;
|
|
|
|
quad[0].texcoord = info.texcoords[0];
|
|
|
|
|
|
|
|
quad[1].x = dst_rect->right * 2.0f / w - 1.0f;
|
|
|
|
quad[1].y = dst_rect->top * 2.0f / h - 1.0f;
|
|
|
|
quad[1].texcoord = info.texcoords[1];
|
|
|
|
|
|
|
|
quad[2].x = dst_rect->left * 2.0f / w - 1.0f;
|
|
|
|
quad[2].y = dst_rect->bottom * 2.0f / h - 1.0f;
|
|
|
|
quad[2].texcoord = info.texcoords[2];
|
|
|
|
|
|
|
|
quad[3].x = dst_rect->right * 2.0f / w - 1.0f;
|
|
|
|
quad[3].y = dst_rect->bottom * 2.0f / h - 1.0f;
|
|
|
|
quad[3].texcoord = info.texcoords[3];
|
|
|
|
|
|
|
|
/* Draw a quad. */
|
2018-04-19 13:20:16 +02:00
|
|
|
if (gl_info->supported[ARB_VERTEX_BUFFER_OBJECT])
|
2018-04-12 13:58:14 +02:00
|
|
|
{
|
2019-05-10 18:31:06 +02:00
|
|
|
if (!context_gl->blit_vbo)
|
|
|
|
GL_EXTCALL(glGenBuffers(1, &context_gl->blit_vbo));
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, context_gl->blit_vbo));
|
2018-04-19 13:20:16 +02:00
|
|
|
|
2019-06-19 01:50:06 +02:00
|
|
|
wined3d_context_gl_unload_vertex_data(context_gl);
|
2019-06-19 23:12:17 +02:00
|
|
|
wined3d_context_gl_unload_numbered_arrays(context_gl);
|
2018-04-19 13:20:16 +02:00
|
|
|
|
|
|
|
GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STREAM_DRAW));
|
|
|
|
GL_EXTCALL(glVertexAttribPointer(0, 2, GL_FLOAT, FALSE, sizeof(*quad), NULL));
|
|
|
|
GL_EXTCALL(glVertexAttribPointer(1, 3, GL_FLOAT, FALSE, sizeof(*quad),
|
|
|
|
(void *)FIELD_OFFSET(struct blit_vertex, texcoord)));
|
|
|
|
|
|
|
|
GL_EXTCALL(glEnableVertexAttribArray(0));
|
|
|
|
GL_EXTCALL(glEnableVertexAttribArray(1));
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, 0));
|
|
|
|
GL_EXTCALL(glDisableVertexAttribArray(1));
|
|
|
|
GL_EXTCALL(glDisableVertexAttribArray(0));
|
2018-04-12 13:58:14 +02:00
|
|
|
}
|
2018-04-19 13:20:16 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
|
2018-04-12 13:58:14 +02:00
|
|
|
|
2018-04-19 13:20:16 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(quad); ++i)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glVertexAttrib3fv(1, &quad[i].texcoord.x));
|
|
|
|
GL_EXTCALL(glVertexAttrib2fv(0, &quad[i].x));
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
|
|
|
}
|
2018-04-12 13:58:14 +02:00
|
|
|
checkGLcall("draw");
|
|
|
|
|
2018-10-30 10:48:43 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAX_LEVEL, texture_gl->t.level_count - 1);
|
2019-05-07 12:30:11 +02:00
|
|
|
wined3d_context_gl_bind_texture(context_gl, info.bind_target, 0);
|
2018-04-12 13:58:14 +02:00
|
|
|
}
|
|
|
|
|
2018-04-12 13:58:13 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2019-06-19 23:12:19 +02:00
|
|
|
void wined3d_context_gl_draw_textured_quad(struct wined3d_context_gl *context_gl,
|
|
|
|
struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx,
|
|
|
|
const RECT *src_rect, const RECT *dst_rect, enum wined3d_texture_filter_type filter)
|
2018-04-12 13:58:13 +02:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2018-04-12 13:58:13 +02:00
|
|
|
struct wined3d_blt_info info;
|
|
|
|
unsigned int level;
|
|
|
|
|
2018-10-30 10:48:44 +01:00
|
|
|
texture2d_get_blt_info(texture_gl, sub_resource_idx, src_rect, &info);
|
2018-04-12 13:58:13 +02:00
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glEnable(info.bind_target);
|
|
|
|
checkGLcall("glEnable(bind_target)");
|
|
|
|
|
2018-10-30 10:48:43 +01:00
|
|
|
level = sub_resource_idx % texture_gl->t.level_count;
|
2019-05-07 12:30:11 +02:00
|
|
|
wined3d_context_gl_bind_texture(context_gl, info.bind_target, texture_gl->texture_rgb.name);
|
2018-10-30 10:48:43 +01:00
|
|
|
apply_texture_blit_state(gl_info, &texture_gl->texture_rgb, info.bind_target, level, filter);
|
2018-04-12 13:58:13 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAX_LEVEL, level);
|
|
|
|
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
checkGLcall("glTexEnvi");
|
|
|
|
|
|
|
|
/* Draw a quad. */
|
|
|
|
gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(&info.texcoords[0].x);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect->left, dst_rect->top);
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(&info.texcoords[1].x);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect->right, dst_rect->top);
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(&info.texcoords[2].x);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect->left, dst_rect->bottom);
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glTexCoord3fv(&info.texcoords[3].x);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(dst_rect->right, dst_rect->bottom);
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
|
|
|
|
2018-10-30 10:48:43 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAX_LEVEL, texture_gl->t.level_count - 1);
|
2019-05-07 12:30:11 +02:00
|
|
|
wined3d_context_gl_bind_texture(context_gl, info.bind_target, 0);
|
2018-04-12 13:58:13 +02:00
|
|
|
}
|