WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
WINE_DECLARE_DEBUG_CHANNEL(d3d);
-#define GLINFO_LOCATION (*gl_info)
-
static void surface_cleanup(IWineD3DSurfaceImpl *This)
{
IWineD3DDeviceImpl *device = This->resource.device;
* target, Uninit3D() will activate a context before doing anything. */
if (device->render_targets && device->render_targets[0])
{
- context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+ context = context_acquire(device, NULL);
}
ENTER_GL();
if (context) context_release(context);
}
-UINT surface_calculate_size(const struct GlPixelFormatDesc *format_desc, UINT alignment, UINT width, UINT height)
+UINT surface_calculate_size(const struct wined3d_format_desc *format_desc, UINT alignment, UINT width, UINT height)
{
UINT size;
return size;
}
+struct blt_info
+{
+ GLenum binding;
+ GLenum bind_target;
+ enum tex_types tex_type;
+ GLfloat coords[4][3];
+};
+
+struct float_rect
+{
+ float l;
+ float t;
+ float r;
+ float b;
+};
+
+static inline void cube_coords_float(const RECT *r, UINT w, UINT h, struct float_rect *f)
+{
+ f->l = ((r->left * 2.0f) / w) - 1.0f;
+ f->t = ((r->top * 2.0f) / h) - 1.0f;
+ f->r = ((r->right * 2.0f) / w) - 1.0f;
+ f->b = ((r->bottom * 2.0f) / h) - 1.0f;
+}
+
+static void surface_get_blt_info(GLenum target, const RECT *rect_in, GLsizei w, GLsizei h, struct blt_info *info)
+{
+ GLfloat (*coords)[3] = info->coords;
+ RECT rect;
+ struct float_rect f;
+
+ if (rect_in)
+ rect = *rect_in;
+ else
+ {
+ rect.left = 0;
+ rect.top = h;
+ rect.right = w;
+ rect.bottom = 0;
+ }
+
+ switch (target)
+ {
+ default:
+ FIXME("Unsupported texture target %#x\n", target);
+ /* Fall back to GL_TEXTURE_2D */
+ case GL_TEXTURE_2D:
+ info->binding = GL_TEXTURE_BINDING_2D;
+ info->bind_target = GL_TEXTURE_2D;
+ info->tex_type = tex_2d;
+ coords[0][0] = (float)rect.left / w;
+ coords[0][1] = (float)rect.top / h;
+ coords[0][2] = 0.0f;
+
+ coords[1][0] = (float)rect.right / w;
+ coords[1][1] = (float)rect.top / h;
+ coords[1][2] = 0.0f;
+
+ coords[2][0] = (float)rect.left / w;
+ coords[2][1] = (float)rect.bottom / h;
+ coords[2][2] = 0.0f;
+
+ coords[3][0] = (float)rect.right / w;
+ coords[3][1] = (float)rect.bottom / h;
+ coords[3][2] = 0.0f;
+ break;
+
+ case GL_TEXTURE_RECTANGLE_ARB:
+ info->binding = GL_TEXTURE_BINDING_RECTANGLE_ARB;
+ info->bind_target = GL_TEXTURE_RECTANGLE_ARB;
+ info->tex_type = tex_rect;
+ coords[0][0] = rect.left; coords[0][1] = rect.top; coords[0][2] = 0.0f;
+ coords[1][0] = rect.right; coords[1][1] = rect.top; coords[1][2] = 0.0f;
+ coords[2][0] = rect.left; coords[2][1] = rect.bottom; coords[2][2] = 0.0f;
+ coords[3][0] = rect.right; coords[3][1] = rect.bottom; coords[3][2] = 0.0f;
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+ info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+ info->tex_type = tex_cube;
+ cube_coords_float(&rect, w, h, &f);
+
+ coords[0][0] = 1.0f; coords[0][1] = -f.t; coords[0][2] = -f.l;
+ coords[1][0] = 1.0f; coords[1][1] = -f.t; coords[1][2] = -f.r;
+ coords[2][0] = 1.0f; coords[2][1] = -f.b; coords[2][2] = -f.l;
+ coords[3][0] = 1.0f; coords[3][1] = -f.b; coords[3][2] = -f.r;
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+ info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+ info->tex_type = tex_cube;
+ cube_coords_float(&rect, w, h, &f);
+
+ coords[0][0] = -1.0f; coords[0][1] = -f.t; coords[0][2] = f.l;
+ coords[1][0] = -1.0f; coords[1][1] = -f.t; coords[1][2] = f.r;
+ coords[2][0] = -1.0f; coords[2][1] = -f.b; coords[2][2] = f.l;
+ coords[3][0] = -1.0f; coords[3][1] = -f.b; coords[3][2] = f.r;
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+ info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+ info->tex_type = tex_cube;
+ cube_coords_float(&rect, w, h, &f);
+
+ coords[0][0] = f.l; coords[0][1] = 1.0f; coords[0][2] = f.t;
+ coords[1][0] = f.r; coords[1][1] = 1.0f; coords[1][2] = f.t;
+ coords[2][0] = f.l; coords[2][1] = 1.0f; coords[2][2] = f.b;
+ coords[3][0] = f.r; coords[3][1] = 1.0f; coords[3][2] = f.b;
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+ info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+ info->tex_type = tex_cube;
+ cube_coords_float(&rect, w, h, &f);
+
+ coords[0][0] = f.l; coords[0][1] = -1.0f; coords[0][2] = -f.t;
+ coords[1][0] = f.r; coords[1][1] = -1.0f; coords[1][2] = -f.t;
+ coords[2][0] = f.l; coords[2][1] = -1.0f; coords[2][2] = -f.b;
+ coords[3][0] = f.r; coords[3][1] = -1.0f; coords[3][2] = -f.b;
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+ info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+ info->tex_type = tex_cube;
+ cube_coords_float(&rect, w, h, &f);
+
+ coords[0][0] = f.l; coords[0][1] = -f.t; coords[0][2] = 1.0f;
+ coords[1][0] = f.r; coords[1][1] = -f.t; coords[1][2] = 1.0f;
+ coords[2][0] = f.l; coords[2][1] = -f.b; coords[2][2] = 1.0f;
+ coords[3][0] = f.r; coords[3][1] = -f.b; coords[3][2] = 1.0f;
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+ info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+ info->tex_type = tex_cube;
+ cube_coords_float(&rect, w, h, &f);
+
+ coords[0][0] = -f.l; coords[0][1] = -f.t; coords[0][2] = -1.0f;
+ coords[1][0] = -f.r; coords[1][1] = -f.t; coords[1][2] = -1.0f;
+ coords[2][0] = -f.l; coords[2][1] = -f.b; coords[2][2] = -1.0f;
+ coords[3][0] = -f.r; coords[3][1] = -f.b; coords[3][2] = -1.0f;
+ break;
+ }
+}
+
+static inline void surface_get_rect(IWineD3DSurfaceImpl *This, const RECT *rect_in, RECT *rect_out)
+{
+ if (rect_in)
+ *rect_out = *rect_in;
+ else
+ {
+ rect_out->left = 0;
+ rect_out->top = 0;
+ rect_out->right = This->currentDesc.Width;
+ rect_out->bottom = This->currentDesc.Height;
+ }
+}
+
+/* GL locking and context activation is done by the caller */
+void draw_textured_quad(IWineD3DSurfaceImpl *src_surface, const RECT *src_rect, const RECT *dst_rect, WINED3DTEXTUREFILTERTYPE Filter)
+{
+ IWineD3DBaseTextureImpl *texture;
+ struct blt_info info;
+
+ surface_get_blt_info(src_surface->texture_target, src_rect, src_surface->pow2Width, src_surface->pow2Height, &info);
+
+ glEnable(info.bind_target);
+ checkGLcall("glEnable(bind_target)");
+
+ /* Bind the texture */
+ glBindTexture(info.bind_target, src_surface->texture_name);
+ checkGLcall("glBindTexture");
+
+ /* Filtering for StretchRect */
+ glTexParameteri(info.bind_target, GL_TEXTURE_MAG_FILTER,
+ wined3d_gl_mag_filter(magLookup, Filter));
+ checkGLcall("glTexParameteri");
+ glTexParameteri(info.bind_target, GL_TEXTURE_MIN_FILTER,
+ wined3d_gl_min_mip_filter(minMipLookup, Filter, WINED3DTEXF_NONE));
+ checkGLcall("glTexParameteri");
+ glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(info.bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ checkGLcall("glTexEnvi");
+
+ /* Draw a quad */
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord3fv(info.coords[0]);
+ glVertex2i(dst_rect->left, dst_rect->top);
+
+ glTexCoord3fv(info.coords[1]);
+ glVertex2i(dst_rect->right, dst_rect->top);
+
+ glTexCoord3fv(info.coords[2]);
+ glVertex2i(dst_rect->left, dst_rect->bottom);
+
+ glTexCoord3fv(info.coords[3]);
+ glVertex2i(dst_rect->right, dst_rect->bottom);
+ glEnd();
+
+ /* Unbind the texture */
+ glBindTexture(info.bind_target, 0);
+ checkGLcall("glBindTexture(info->bind_target, 0)");
+
+ /* We changed the filtering settings on the texture. Inform the
+ * container about this to get the filters reset properly next draw. */
+ if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)src_surface, &IID_IWineD3DBaseTexture, (void **)&texture)))
+ {
+ texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
+ texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
+ texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
+ IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)texture);
+ }
+}
+
HRESULT surface_init(IWineD3DSurfaceImpl *surface, WINED3DSURFTYPE surface_type, UINT alignment,
UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
{
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
- const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
+ const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
void (*cleanup)(IWineD3DSurfaceImpl *This);
unsigned int resource_size;
HRESULT hr;
}
/* Mark the texture as dirty so that it gets loaded first time around. */
- surface_add_dirty_rect((IWineD3DSurface *)surface, NULL);
+ surface_add_dirty_rect(surface, NULL);
list_init(&surface->renderbuffers);
TRACE("surface %p, memory %p, size %u\n", surface, surface->resource.allocatedMemory, surface->resource.size);
return hr;
}
-static void surface_force_reload(IWineD3DSurface *iface)
+static void surface_force_reload(IWineD3DSurfaceImpl *surface)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-
- This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
+ surface->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
}
-void surface_set_texture_name(IWineD3DSurface *iface, GLuint new_name, BOOL srgb)
+void surface_set_texture_name(IWineD3DSurfaceImpl *surface, GLuint new_name, BOOL srgb)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
GLuint *name;
DWORD flag;
+ TRACE("surface %p, new_name %u, srgb %#x.\n", surface, new_name, srgb);
+
if(srgb)
{
- name = &This->texture_name_srgb;
+ name = &surface->texture_name_srgb;
flag = SFLAG_INSRGBTEX;
}
else
{
- name = &This->texture_name;
+ name = &surface->texture_name;
flag = SFLAG_INTEXTURE;
}
- TRACE("(%p) : setting texture name %u\n", This, new_name);
-
if (!*name && new_name)
{
/* FIXME: We shouldn't need to remove SFLAG_INTEXTURE if the
* surface has no texture name yet. See if we can get rid of this. */
- if (This->Flags & flag)
+ if (surface->Flags & flag)
ERR("Surface has SFLAG_INTEXTURE set, but no texture name\n");
- IWineD3DSurface_ModifyLocation(iface, flag, FALSE);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, flag, FALSE);
}
*name = new_name;
- surface_force_reload(iface);
+ surface_force_reload(surface);
}
-void surface_set_texture_target(IWineD3DSurface *iface, GLenum target)
+void surface_set_texture_target(IWineD3DSurfaceImpl *surface, GLenum target)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+ TRACE("surface %p, target %#x.\n", surface, target);
- TRACE("(%p) : setting target %#x\n", This, target);
-
- if (This->texture_target != target)
+ if (surface->texture_target != target)
{
if (target == GL_TEXTURE_RECTANGLE_ARB)
{
- This->Flags &= ~SFLAG_NORMCOORD;
+ surface->Flags &= ~SFLAG_NORMCOORD;
}
- else if (This->texture_target == GL_TEXTURE_RECTANGLE_ARB)
+ else if (surface->texture_target == GL_TEXTURE_RECTANGLE_ARB)
{
- This->Flags |= SFLAG_NORMCOORD;
+ surface->Flags |= SFLAG_NORMCOORD;
}
}
- This->texture_target = target;
- surface_force_reload(iface);
+ surface->texture_target = target;
+ surface_force_reload(surface);
}
/* Context activation is done by the caller. */
/* This function checks if the primary render target uses the 8bit paletted format. */
static BOOL primary_render_target_is_p8(IWineD3DDeviceImpl *device)
{
- if (device->render_targets && device->render_targets[0]) {
- IWineD3DSurfaceImpl* render_target = (IWineD3DSurfaceImpl*)device->render_targets[0];
+ if (device->render_targets && device->render_targets[0])
+ {
+ IWineD3DSurfaceImpl *render_target = device->render_targets[0];
if ((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET)
&& (render_target->resource.format_desc->format == WINED3DFMT_P8_UINT))
return TRUE;
return FALSE;
}
-#undef GLINFO_LOCATION
-
-#define GLINFO_LOCATION This->resource.device->adapter->gl_info
-
/* This call just downloads data, the caller is responsible for binding the
* correct texture. */
/* Context activation is done by the caller. */
-static void surface_download_data(IWineD3DSurfaceImpl *This) {
- const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
+static void surface_download_data(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info)
+{
+ const struct wined3d_format_desc *format_desc = This->resource.format_desc;
/* Only support read back of converted P8 surfaces */
if (This->Flags & SFLAG_CONVERTED && format_desc->format != WINED3DFMT_P8_UINT)
/* This call just uploads data, the caller is responsible for binding the
* correct texture. */
/* Context activation is done by the caller. */
-static void surface_upload_data(IWineD3DSurfaceImpl *This, GLenum internal, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data) {
- const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
+static void surface_upload_data(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
+ const struct wined3d_format_desc *format_desc, BOOL srgb, const GLvoid *data)
+{
+ GLsizei width = This->currentDesc.Width;
+ GLsizei height = This->currentDesc.Height;
+ GLenum internal;
+
+ if (srgb)
+ {
+ internal = format_desc->glGammaInternal;
+ }
+ else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET && surface_is_offscreen(This))
+ {
+ internal = format_desc->rtInternal;
+ }
+ else
+ {
+ internal = format_desc->glInternal;
+ }
TRACE("This %p, internal %#x, width %d, height %d, format %#x, type %#x, data %p.\n",
- This, internal, width, height, format, type, data);
+ This, internal, width, height, format_desc->glFormat, format_desc->glType, data);
TRACE("target %#x, level %u, resource size %u.\n",
This->texture_target, This->texture_level, This->resource.size);
TRACE("Calling glTexSubImage2D.\n");
glTexSubImage2D(This->texture_target, This->texture_level,
- 0, 0, width, height, format, type, data);
+ 0, 0, width, height, format_desc->glFormat, format_desc->glType, data);
checkGLcall("glTexSubImage2D");
}
}
LEAVE_GL();
+
+ if (gl_info->quirks & WINED3D_QUIRK_FBO_TEX_UPDATE)
+ {
+ IWineD3DDeviceImpl *device = This->resource.device;
+ unsigned int i;
+
+ for (i = 0; i < device->numContexts; ++i)
+ {
+ context_surface_update(device->contexts[i], This);
+ }
+ }
}
/* This call just allocates the texture, the caller is responsible for binding
* the correct texture. */
/* Context activation is done by the caller. */
-static void surface_allocate_surface(IWineD3DSurfaceImpl *This, GLenum internal, GLsizei width, GLsizei height, GLenum format, GLenum type) {
- const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
- const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
+static void surface_allocate_surface(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
+ const struct wined3d_format_desc *format_desc, BOOL srgb)
+{
BOOL enable_client_storage = FALSE;
+ GLsizei width = This->pow2Width;
+ GLsizei height = This->pow2Height;
const BYTE *mem = NULL;
+ GLenum internal;
+
+ if (srgb)
+ {
+ internal = format_desc->glGammaInternal;
+ }
+ else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET && surface_is_offscreen(This))
+ {
+ internal = format_desc->rtInternal;
+ }
+ else
+ {
+ internal = format_desc->glInternal;
+ }
if (format_desc->heightscale != 1.0f && format_desc->heightscale != 0.0f) height *= format_desc->heightscale;
TRACE("(%p) : Creating surface (target %#x) level %d, d3d format %s, internal format %#x, width %d, height %d, gl format %#x, gl type=%#x\n",
This, This->texture_target, This->texture_level, debug_d3dformat(format_desc->format),
- internal, width, height, format, type);
+ internal, width, height, format_desc->glFormat, format_desc->glType);
ENTER_GL();
if (gl_info->supported[APPLE_CLIENT_STORAGE])
{
- if(This->Flags & (SFLAG_NONPOW2 | SFLAG_DIBSECTION | SFLAG_OVERSIZE | SFLAG_CONVERTED) || This->resource.allocatedMemory == NULL) {
+ if(This->Flags & (SFLAG_NONPOW2 | SFLAG_DIBSECTION | SFLAG_CONVERTED) || This->resource.allocatedMemory == NULL) {
/* In some cases we want to disable client storage.
* SFLAG_NONPOW2 has a bigger opengl texture than the client memory, and different pitches
* SFLAG_DIBSECTION: Dibsections may have read / write protections on the memory. Avoid issues...
- * SFLAG_OVERSIZE: The gl texture is smaller than the allocated memory
* SFLAG_CONVERTED: The conversion destination memory is freed after loading the surface
* allocatedMemory == NULL: Not defined in the extension. Seems to disable client storage effectively
*/
else
{
glTexImage2D(This->texture_target, This->texture_level,
- internal, width, height, 0, format, type, mem);
+ internal, width, height, 0, format_desc->glFormat, format_desc->glType, mem);
checkGLcall("glTexImage2D");
}
* render target dimensions. With FBOs, the dimensions have to be an exact match. */
/* TODO: We should synchronize the renderbuffer's content with the texture's content. */
/* GL locking is done by the caller */
-void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height) {
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
- const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
+void surface_set_compatible_renderbuffer(IWineD3DSurfaceImpl *surface, unsigned int width, unsigned int height)
+{
+ const struct wined3d_gl_info *gl_info = &surface->resource.device->adapter->gl_info;
renderbuffer_entry_t *entry;
GLuint renderbuffer = 0;
unsigned int src_width, src_height;
- src_width = This->pow2Width;
- src_height = This->pow2Height;
+ src_width = surface->pow2Width;
+ src_height = surface->pow2Height;
/* A depth stencil smaller than the render target is not valid */
if (width > src_width || height > src_height) return;
if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
|| (width == src_width && height == src_height))
{
- This->current_renderbuffer = NULL;
+ surface->current_renderbuffer = NULL;
return;
}
/* Look if we've already got a renderbuffer of the correct dimensions */
- LIST_FOR_EACH_ENTRY(entry, &This->renderbuffers, renderbuffer_entry_t, entry) {
- if (entry->width == width && entry->height == height) {
+ LIST_FOR_EACH_ENTRY(entry, &surface->renderbuffers, renderbuffer_entry_t, entry)
+ {
+ if (entry->width == width && entry->height == height)
+ {
renderbuffer = entry->id;
- This->current_renderbuffer = entry;
+ surface->current_renderbuffer = entry;
break;
}
}
- if (!renderbuffer) {
+ if (!renderbuffer)
+ {
gl_info->fbo_ops.glGenRenderbuffers(1, &renderbuffer);
gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER,
- This->resource.format_desc->glInternal, width, height);
+ surface->resource.format_desc->glInternal, width, height);
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(renderbuffer_entry_t));
entry->width = width;
entry->height = height;
entry->id = renderbuffer;
- list_add_head(&This->renderbuffers, &entry->entry);
+ list_add_head(&surface->renderbuffers, &entry->entry);
- This->current_renderbuffer = entry;
+ surface->current_renderbuffer = entry;
}
checkGLcall("set_compatible_renderbuffer");
}
-GLenum surface_get_gl_buffer(IWineD3DSurface *iface)
+GLenum surface_get_gl_buffer(IWineD3DSurfaceImpl *surface)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
- IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)This->container;
+ IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)surface->container;
- TRACE("iface %p.\n", iface);
+ TRACE("surface %p.\n", surface);
- if (!(This->Flags & SFLAG_SWAPCHAIN))
+ if (!(surface->Flags & SFLAG_SWAPCHAIN))
{
- ERR("Surface %p is not on a swapchain.\n", iface);
+ ERR("Surface %p is not on a swapchain.\n", surface);
return GL_NONE;
}
- if (swapchain->backBuffer && swapchain->backBuffer[0] == iface)
+ if (swapchain->back_buffers && swapchain->back_buffers[0] == surface)
{
if (swapchain->render_to_fbo)
{
TRACE("Returning GL_BACK\n");
return GL_BACK;
}
- else if (swapchain->frontBuffer == iface)
+ else if (surface == swapchain->front_buffer)
{
TRACE("Returning GL_FRONT\n");
return GL_FRONT;
}
/* Slightly inefficient way to handle multiple dirty rects but it works :) */
-void surface_add_dirty_rect(IWineD3DSurface *iface, const RECT *dirty_rect)
+void surface_add_dirty_rect(IWineD3DSurfaceImpl *surface, const RECT *dirty_rect)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
IWineD3DBaseTexture *baseTexture = NULL;
- if (!(This->Flags & SFLAG_INSYSMEM) && (This->Flags & SFLAG_INTEXTURE))
- IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
+ TRACE("surface %p, dirty_rect %s.\n", surface, wine_dbgstr_rect(dirty_rect));
+
+ if (!(surface->Flags & SFLAG_INSYSMEM) && (surface->Flags & SFLAG_INTEXTURE))
+ /* No partial locking for textures yet. */
+ IWineD3DSurface_LoadLocation((IWineD3DSurface *)surface, SFLAG_INSYSMEM, NULL);
- IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, SFLAG_INSYSMEM, TRUE);
if (dirty_rect)
{
- This->dirtyRect.left = min(This->dirtyRect.left, dirty_rect->left);
- This->dirtyRect.top = min(This->dirtyRect.top, dirty_rect->top);
- This->dirtyRect.right = max(This->dirtyRect.right, dirty_rect->right);
- This->dirtyRect.bottom = max(This->dirtyRect.bottom, dirty_rect->bottom);
+ surface->dirtyRect.left = min(surface->dirtyRect.left, dirty_rect->left);
+ surface->dirtyRect.top = min(surface->dirtyRect.top, dirty_rect->top);
+ surface->dirtyRect.right = max(surface->dirtyRect.right, dirty_rect->right);
+ surface->dirtyRect.bottom = max(surface->dirtyRect.bottom, dirty_rect->bottom);
}
else
{
- This->dirtyRect.left = 0;
- This->dirtyRect.top = 0;
- This->dirtyRect.right = This->currentDesc.Width;
- This->dirtyRect.bottom = This->currentDesc.Height;
+ surface->dirtyRect.left = 0;
+ surface->dirtyRect.top = 0;
+ surface->dirtyRect.right = surface->currentDesc.Width;
+ surface->dirtyRect.bottom = surface->currentDesc.Height;
}
- TRACE("(%p) : Dirty: yes, Rect:(%d, %d, %d, %d)\n", This, This->dirtyRect.left,
- This->dirtyRect.top, This->dirtyRect.right, This->dirtyRect.bottom);
-
/* if the container is a basetexture then mark it dirty. */
- if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&baseTexture)))
+ if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)surface,
+ &IID_IWineD3DBaseTexture, (void **)&baseTexture)))
{
TRACE("Passing to container\n");
IWineD3DBaseTexture_SetDirty(baseTexture, TRUE);
}
}
-static inline BOOL surface_can_stretch_rect(IWineD3DSurfaceImpl *src, IWineD3DSurfaceImpl *dst)
+static BOOL surface_convert_color_to_argb(IWineD3DSurfaceImpl *This, DWORD color, DWORD *argb_color)
{
- return ((src->resource.format_desc->Flags & WINED3DFMT_FLAG_FBO_ATTACHABLE)
- || (src->resource.usage & WINED3DUSAGE_RENDERTARGET))
- && ((dst->resource.format_desc->Flags & WINED3DFMT_FLAG_FBO_ATTACHABLE)
- || (dst->resource.usage & WINED3DUSAGE_RENDERTARGET))
- && (src->resource.format_desc->format == dst->resource.format_desc->format
- || (is_identity_fixup(src->resource.format_desc->color_fixup)
- && is_identity_fixup(dst->resource.format_desc->color_fixup)));
+ IWineD3DDeviceImpl *device = This->resource.device;
+
+ switch(This->resource.format_desc->format)
+ {
+ case WINED3DFMT_P8_UINT:
+ {
+ DWORD alpha;
+
+ if (primary_render_target_is_p8(device))
+ alpha = color << 24;
+ else
+ alpha = 0xFF000000;
+
+ if (This->palette) {
+ *argb_color = (alpha |
+ (This->palette->palents[color].peRed << 16) |
+ (This->palette->palents[color].peGreen << 8) |
+ (This->palette->palents[color].peBlue));
+ } else {
+ *argb_color = alpha;
+ }
+ }
+ break;
+
+ case WINED3DFMT_B5G6R5_UNORM:
+ {
+ if (color == 0xFFFF) {
+ *argb_color = 0xFFFFFFFF;
+ } else {
+ *argb_color = ((0xFF000000) |
+ ((color & 0xF800) << 8) |
+ ((color & 0x07E0) << 5) |
+ ((color & 0x001F) << 3));
+ }
+ }
+ break;
+
+ case WINED3DFMT_B8G8R8_UNORM:
+ case WINED3DFMT_B8G8R8X8_UNORM:
+ *argb_color = 0xFF000000 | color;
+ break;
+
+ case WINED3DFMT_B8G8R8A8_UNORM:
+ *argb_color = color;
+ break;
+
+ default:
+ ERR("Unhandled conversion from %s to ARGB!\n", debug_d3dformat(This->resource.format_desc->format));
+ return FALSE;
+ }
+ return TRUE;
}
static ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface)
IWineD3DSurface IWineD3DResource parts follow
**************************************************** */
-void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb)
+void surface_internal_preload(IWineD3DSurfaceImpl *surface, enum WINED3DSRGB srgb)
{
/* TODO: check for locks */
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
- IWineD3DDeviceImpl *device = This->resource.device;
+ IWineD3DDeviceImpl *device = surface->resource.device;
IWineD3DBaseTexture *baseTexture = NULL;
- TRACE("(%p)Checking to see if the container is a base texture\n", This);
- if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&baseTexture) == WINED3D_OK) {
- IWineD3DBaseTextureImpl *tex_impl = (IWineD3DBaseTextureImpl *) baseTexture;
+ TRACE("(%p)Checking to see if the container is a base texture\n", surface);
+ if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)surface,
+ &IID_IWineD3DBaseTexture, (void **)&baseTexture)))
+ {
+ IWineD3DBaseTextureImpl *tex_impl = (IWineD3DBaseTextureImpl *)baseTexture;
TRACE("Passing to container\n");
tex_impl->baseTexture.internal_preload(baseTexture, srgb);
IWineD3DBaseTexture_Release(baseTexture);
} else {
struct wined3d_context *context = NULL;
- TRACE("(%p) : About to load surface\n", This);
+ TRACE("(%p) : About to load surface\n", surface);
- if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+ if (!device->isInDraw) context = context_acquire(device, NULL);
- if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
- || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
+ if (surface->resource.format_desc->format == WINED3DFMT_P8_UINT
+ || surface->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
{
- if(palette9_changed(This)) {
+ if (palette9_changed(surface))
+ {
TRACE("Reloading surface because the d3d8/9 palette was changed\n");
/* TODO: This is not necessarily needed with hw palettized texture support */
- IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL);
+ IWineD3DSurface_LoadLocation((IWineD3DSurface *)surface, SFLAG_INSYSMEM, NULL);
/* Make sure the texture is reloaded because of the palette change, this kills performance though :( */
- IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, SFLAG_INTEXTURE, FALSE);
}
}
- IWineD3DSurface_LoadTexture(iface, srgb == SRGB_SRGB ? TRUE : FALSE);
+ IWineD3DSurface_LoadTexture((IWineD3DSurface *)surface, srgb == SRGB_SRGB ? TRUE : FALSE);
- if (This->resource.pool == WINED3DPOOL_DEFAULT) {
+ if (surface->resource.pool == WINED3DPOOL_DEFAULT)
+ {
/* Tell opengl to try and keep this texture in video ram (well mostly) */
GLclampf tmp;
tmp = 0.9f;
ENTER_GL();
- glPrioritizeTextures(1, &This->texture_name, &tmp);
+ glPrioritizeTextures(1, &surface->texture_name, &tmp);
LEAVE_GL();
}
}
}
-static void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface) {
- surface_internal_preload(iface, SRGB_ANY);
+static void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface)
+{
+ surface_internal_preload((IWineD3DSurfaceImpl *)iface, SRGB_ANY);
}
/* Context activation is done by the caller. */
-static void surface_remove_pbo(IWineD3DSurfaceImpl *This) {
+static void surface_remove_pbo(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info)
+{
This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
This->resource.allocatedMemory =
(BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
This->Flags &= ~SFLAG_PBO;
}
-BOOL surface_init_sysmem(IWineD3DSurface *iface)
+BOOL surface_init_sysmem(IWineD3DSurfaceImpl *surface)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
-
- if(!This->resource.allocatedMemory)
+ if (!surface->resource.allocatedMemory)
{
- This->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->resource.size + RESOURCE_ALIGNMENT);
- if(!This->resource.heapMemory)
+ surface->resource.heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+ surface->resource.size + RESOURCE_ALIGNMENT);
+ if (!surface->resource.heapMemory)
{
ERR("Out of memory\n");
return FALSE;
}
- This->resource.allocatedMemory =
- (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
+ surface->resource.allocatedMemory =
+ (BYTE *)(((ULONG_PTR)surface->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
}
else
{
- memset(This->resource.allocatedMemory, 0, This->resource.size);
+ memset(surface->resource.allocatedMemory, 0, surface->resource.size);
}
- IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, SFLAG_INSYSMEM, TRUE);
return TRUE;
}
* or the depth stencil into an FBO the texture or render buffer will be removed
* and all flags get lost
*/
- surface_init_sysmem(iface);
- } else {
+ surface_init_sysmem(This);
+ }
+ else
+ {
/* Load the surface into system memory */
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL);
IWineD3DSurface_ModifyLocation(iface, SFLAG_INDRAWABLE, FALSE);
IWineD3DSurface_ModifyLocation(iface, SFLAG_INSRGBTEX, FALSE);
This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
- context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+ context = context_acquire(device, NULL);
gl_info = context->gl_info;
/* Destroy PBOs, but load them into real sysmem before */
- if(This->Flags & SFLAG_PBO) {
- surface_remove_pbo(This);
- }
+ if (This->Flags & SFLAG_PBO)
+ surface_remove_pbo(This, gl_info);
/* Destroy fbo render buffers. This is needed for implicit render targets, for
* all application-created targets the application has to release the surface
/* Read the framebuffer back into the surface */
static void read_from_framebuffer(IWineD3DSurfaceImpl *This, const RECT *rect, void *dest, UINT pitch)
{
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = This->resource.device;
+ const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
BYTE *mem;
GLint fmt;
* should help here. Furthermore unlockrect will need the context set up for blitting. The context manager will find
* context->last_was_blit set on the unlock.
*/
- context = context_acquire(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
+ context = context_acquire(device, This);
+ context_apply_blit_state(context, device);
+ gl_info = context->gl_info;
+
ENTER_GL();
/* Select the correct read buffer, and give some debug output.
* There is no need to keep track of the current read buffer or reset it, every part of the code
* that reads sets the read buffer as desired.
*/
- if (surface_is_offscreen((IWineD3DSurface *) This))
+ if (surface_is_offscreen(This))
{
/* Locking the primary render target which is not on a swapchain(=offscreen render target).
* Read from the back buffer
*/
TRACE("Locking offscreen render target\n");
- glReadBuffer(myDevice->offscreenBuffer);
+ glReadBuffer(device->offscreenBuffer);
srcIsUpsideDown = TRUE;
}
else
{
/* Onscreen surfaces are always part of a swapchain */
- GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
+ GLenum buffer = surface_get_gl_buffer(This);
TRACE("Locking %#x buffer\n", buffer);
glReadBuffer(buffer);
checkGLcall("glReadBuffer");
{
case WINED3DFMT_P8_UINT:
{
- if(primary_render_target_is_p8(myDevice)) {
+ if (primary_render_target_is_p8(device))
+ {
/* In case of P8 render targets the index is stored in the alpha component */
fmt = GL_ALPHA;
type = GL_UNSIGNED_BYTE;
* the same color but we have no choice.
* In case of P8 render targets, the index is stored in the alpha component so no conversion is needed.
*/
- if (This->resource.format_desc->format == WINED3DFMT_P8_UINT && !primary_render_target_is_p8(myDevice))
+ if (This->resource.format_desc->format == WINED3DFMT_P8_UINT && !primary_render_target_is_p8(device))
{
const PALETTEENTRY *pal = NULL;
DWORD width = pitch / 3;
static void read_from_framebuffer_texture(IWineD3DSurfaceImpl *This, BOOL srgb)
{
IWineD3DDeviceImpl *device = This->resource.device;
+ const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
- int bpp;
- GLenum format, internal, type;
- CONVERT_TYPES convert;
GLint prevRead;
- BOOL alloc_flag = srgb ? SFLAG_SRGBALLOCATED : SFLAG_ALLOCATED;
-
- d3dfmt_get_conv(This, TRUE /* We need color keying */, TRUE /* We will use textures */, &format, &internal, &type, &convert, &bpp, srgb);
/* Activate the surface to read from. In some situations it isn't the currently active target(e.g. backbuffer
* locking during offscreen rendering). RESOURCELOAD is ok because glCopyTexSubImage2D isn't affected by any
* states in the stateblock, and no driver was found yet that had bugs in that regard.
*/
- context = context_acquire(device, (IWineD3DSurface *) This, CTXUSAGE_RESOURCELOAD);
+ context = context_acquire(device, This);
+ gl_info = context->gl_info;
+
+ surface_prepare_texture(This, gl_info, srgb);
surface_bind_and_dirtify(This, srgb);
ENTER_GL();
* There is no need to keep track of the current read buffer or reset it, every part of the code
* that reads sets the read buffer as desired.
*/
- if (!surface_is_offscreen((IWineD3DSurface *)This))
+ if (!surface_is_offscreen(This))
{
- GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
+ GLenum buffer = surface_get_gl_buffer(This);
TRACE("Locking %#x buffer\n", buffer);
ENTER_GL();
LEAVE_GL();
}
- if(!(This->Flags & alloc_flag)) {
- surface_allocate_surface(This, internal, This->pow2Width,
- This->pow2Height, format, type);
- This->Flags |= alloc_flag;
- }
-
ENTER_GL();
/* If !SrcIsUpsideDown we should flip the surface.
* This can be done using glCopyTexSubImage2D but this
}
/* Context activation is done by the caller. */
-void surface_prepare_texture(IWineD3DSurfaceImpl *surface, BOOL srgb)
+static void surface_prepare_texture_internal(IWineD3DSurfaceImpl *surface,
+ const struct wined3d_gl_info *gl_info, BOOL srgb)
{
DWORD alloc_flag = srgb ? SFLAG_SRGBALLOCATED : SFLAG_ALLOCATED;
- GLenum format, internal, type;
- GLsizei width, height;
CONVERT_TYPES convert;
- int bpp;
+ struct wined3d_format_desc desc;
if (surface->Flags & alloc_flag) return;
- d3dfmt_get_conv(surface, TRUE, TRUE, &format, &internal, &type, &convert, &bpp, srgb);
- if(convert != NO_CONVERSION) surface->Flags |= SFLAG_CONVERTED;
+ d3dfmt_get_conv(surface, TRUE, TRUE, &desc, &convert);
+ if(convert != NO_CONVERSION || desc.convert) surface->Flags |= SFLAG_CONVERTED;
else surface->Flags &= ~SFLAG_CONVERTED;
- if ((surface->Flags & SFLAG_NONPOW2) && !(surface->Flags & SFLAG_OVERSIZE))
- {
- width = surface->pow2Width;
- height = surface->pow2Height;
- }
- else
+ surface_bind_and_dirtify(surface, srgb);
+ surface_allocate_surface(surface, gl_info, &desc, srgb);
+ surface->Flags |= alloc_flag;
+}
+
+/* Context activation is done by the caller. */
+void surface_prepare_texture(IWineD3DSurfaceImpl *surface, const struct wined3d_gl_info *gl_info, BOOL srgb)
+{
+ IWineD3DBaseTextureImpl *texture;
+
+ if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)surface,
+ &IID_IWineD3DBaseTexture, (void **)&texture)))
{
- width = surface->glRect.right - surface->glRect.left;
- height = surface->glRect.bottom - surface->glRect.top;
+ UINT sub_count = texture->baseTexture.level_count * texture->baseTexture.layer_count;
+ UINT i;
+
+ TRACE("surface %p is a subresource of texture %p.\n", surface, texture);
+
+ for (i = 0; i < sub_count; ++i)
+ {
+ IWineD3DSurfaceImpl *s = (IWineD3DSurfaceImpl *)texture->baseTexture.sub_resources[i];
+ surface_prepare_texture_internal(s, gl_info, srgb);
+ }
+
+ IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)texture);
}
- surface_bind_and_dirtify(surface, srgb);
- surface_allocate_surface(surface, internal, width, height, format, type);
- surface->Flags |= alloc_flag;
+ surface_prepare_texture_internal(surface, gl_info, srgb);
}
static void surface_prepare_system_memory(IWineD3DSurfaceImpl *This)
GLenum error;
struct wined3d_context *context;
- context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+ context = context_acquire(device, NULL);
ENTER_GL();
GL_EXTCALL(glGenBuffersARB(1, &This->pbo));
static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = This->resource.device;
const RECT *pass_rect = pRect;
- TRACE("(%p) : rect@%p flags(%08x), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->resource.allocatedMemory);
+ TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n",
+ iface, pLockedRect, wine_dbgstr_rect(pRect), Flags);
/* This is also done in the base class, but we have to verify this before loading any data from
* gl into the sysmem copy. The PBO may be mapped, a different rectangle locked, the discard flag
}
if (!(wined3d_settings.rendertargetlock_mode == RTL_DISABLE
- && ((This->Flags & SFLAG_SWAPCHAIN) || iface == myDevice->render_targets[0])))
+ && ((This->Flags & SFLAG_SWAPCHAIN) || This == device->render_targets[0])))
{
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, pass_rect);
}
lock_end:
if (This->Flags & SFLAG_PBO)
{
+ const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
- context = context_acquire(myDevice, NULL, CTXUSAGE_RESOURCELOAD);
+ context = context_acquire(device, NULL);
+ gl_info = context->gl_info;
+
ENTER_GL();
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
checkGLcall("glBindBufferARB");
* Dirtify on lock
* as seen in msdn docs
*/
- surface_add_dirty_rect(iface, pRect);
+ surface_add_dirty_rect(This, pRect);
/** Dirtify Container if needed */
if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&pBaseTexture))) {
GLint prev_rasterpos[4];
GLint skipBytes = 0;
UINT pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This); /* target is argb, 4 byte */
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = This->resource.device;
+ const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
/* Activate the correct context for the render target */
- context = context_acquire(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
+ context = context_acquire(device, This);
+ context_apply_blit_state(context, device);
+ gl_info = context->gl_info;
+
ENTER_GL();
- if (!surface_is_offscreen((IWineD3DSurface *)This))
+ if (!surface_is_offscreen(This))
{
- GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This);
+ GLenum buffer = surface_get_gl_buffer(This);
TRACE("Unlocking %#x buffer.\n", buffer);
context_set_draw_buffer(context, buffer);
}
{
/* Primary offscreen render target */
TRACE("Offscreen render target.\n");
- context_set_draw_buffer(context, myDevice->offscreenBuffer);
+ context_set_draw_buffer(context, device->offscreenBuffer);
}
glGetIntegerv(GL_PACK_SWAP_BYTES, &prev_store);
static HRESULT WINAPI IWineD3DSurfaceImpl_UnlockRect(IWineD3DSurface *iface) {
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = This->resource.device;
BOOL fullsurface;
if (!(This->Flags & SFLAG_LOCKED)) {
if (This->Flags & SFLAG_PBO)
{
+ const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
TRACE("Freeing PBO memory\n");
- context = context_acquire(myDevice, NULL, CTXUSAGE_RESOURCELOAD);
+ context = context_acquire(device, NULL);
+ gl_info = context->gl_info;
+
ENTER_GL();
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
goto unlock_end;
}
- if ((This->Flags & SFLAG_SWAPCHAIN) || (myDevice->render_targets && iface == myDevice->render_targets[0]))
+ if ((This->Flags & SFLAG_SWAPCHAIN) || (device->render_targets && This == device->render_targets[0]))
{
if(wined3d_settings.rendertargetlock_mode == RTL_DISABLE) {
static BOOL warned = FALSE;
This->dirtyRect.top = This->currentDesc.Height;
This->dirtyRect.right = 0;
This->dirtyRect.bottom = 0;
- } else if(iface == myDevice->stencilBufferTarget) {
+ }
+ else if (This == device->depth_stencil)
+ {
FIXME("Depth Stencil buffer locking is not implemented\n");
} else {
/* The rest should be a normal texture */
* states need resetting
*/
if(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&impl) == WINED3D_OK) {
- if(impl->baseTexture.bindCount) {
- IWineD3DDeviceImpl_MarkStateDirty(myDevice, STATE_SAMPLER(impl->baseTexture.sampler));
- }
+ if (impl->baseTexture.bindCount)
+ IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(impl->baseTexture.sampler));
IWineD3DBaseTexture_Release((IWineD3DBaseTexture *) impl);
}
}
return WINED3D_OK;
}
-static void surface_release_client_storage(IWineD3DSurface *iface)
+static void surface_release_client_storage(IWineD3DSurfaceImpl *surface)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
struct wined3d_context *context;
- context = context_acquire(This->resource.device, NULL, CTXUSAGE_RESOURCELOAD);
+ context = context_acquire(surface->resource.device, NULL);
ENTER_GL();
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
- if(This->texture_name)
+ if (surface->texture_name)
{
- surface_bind_and_dirtify(This, FALSE);
- glTexImage2D(This->texture_target, This->texture_level,
- GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+ surface_bind_and_dirtify(surface, FALSE);
+ glTexImage2D(surface->texture_target, surface->texture_level,
+ GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
}
- if(This->texture_name_srgb)
+ if (surface->texture_name_srgb)
{
- surface_bind_and_dirtify(This, TRUE);
- glTexImage2D(This->texture_target, This->texture_level,
- GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+ surface_bind_and_dirtify(surface, TRUE);
+ glTexImage2D(surface->texture_target, surface->texture_level,
+ GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
}
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
LEAVE_GL();
context_release(context);
- IWineD3DSurface_ModifyLocation(iface, SFLAG_INSRGBTEX, FALSE);
- IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
- surface_force_reload(iface);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, SFLAG_INSRGBTEX, FALSE);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)surface, SFLAG_INTEXTURE, FALSE);
+ surface_force_reload(surface);
}
static HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC)
if(!This->hDC) {
if(This->Flags & SFLAG_CLIENT) {
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL);
- surface_release_client_storage(iface);
+ surface_release_client_storage(This);
}
hr = IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
if(FAILED(hr)) return WINED3DERR_INVALIDCALL;
IWineD3DSurfaceImpl *dds_primary;
IWineD3DSwapChainImpl *swapchain;
swapchain = (IWineD3DSwapChainImpl *)This->resource.device->swapchains[0];
- dds_primary = (IWineD3DSurfaceImpl *)swapchain->frontBuffer;
+ dds_primary = swapchain->front_buffer;
if (dds_primary && dds_primary->palette)
pal = dds_primary->palette->palents;
}
IWineD3DSurface Internal (No mapping to directx api) parts follow
****************************************************** */
-HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format, GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode) {
+HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, struct wined3d_format_desc *desc, CONVERT_TYPES *convert)
+{
BOOL colorkey_active = need_alpha_ck && (This->CKeyFlags & WINEDDSD_CKSRCBLT);
- const struct GlPixelFormatDesc *glDesc = This->resource.format_desc;
IWineD3DDeviceImpl *device = This->resource.device;
- const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+ BOOL blit_supported = FALSE;
+ RECT rect = {0, 0, This->pow2Width, This->pow2Height};
- /* Default values: From the surface */
- *format = glDesc->glFormat;
- *type = glDesc->glType;
+ /* Copy the default values from the surface. Below we might perform fixups */
+ /* TODO: get rid of color keying desc fixups by using e.g. a table. */
+ *desc = *This->resource.format_desc;
*convert = NO_CONVERSION;
- *target_bpp = glDesc->byte_count;
-
- if(srgb_mode) {
- *internal = glDesc->glGammaInternal;
- }
- else if (This->resource.usage & WINED3DUSAGE_RENDERTARGET
- && surface_is_offscreen((IWineD3DSurface *) This))
- {
- *internal = glDesc->rtInternal;
- } else {
- *internal = glDesc->glInternal;
- }
/* Ok, now look if we have to do any conversion */
switch(This->resource.format_desc->format)
Paletted Texture
**************** */
- /* Use conversion when the paletted texture extension OR fragment shaders are available. When either
- * of the two is available make sure texturing is requested as neither of the two works in
- * conjunction with calls like glDraw-/glReadPixels. Further also use conversion in case of color keying.
+ blit_supported = device->blitter->blit_supported(&device->adapter->gl_info, BLIT_OP_BLIT,
+ &rect, This->resource.usage, This->resource.pool,
+ This->resource.format_desc, &rect, This->resource.usage,
+ This->resource.pool, This->resource.format_desc);
+
+ /* Use conversion when the blit_shader backend supports it. It only supports this in case of
+ * texturing. Further also use conversion in case of color keying.
* Paletted textures can be emulated using shaders but only do that for 2D purposes e.g. situations
* in which the main render target uses p8. Some games like GTA Vice City use P8 for texturing which
* conflicts with this.
*/
- if (!(gl_info->supported[EXT_PALETTED_TEXTURE] || (device->blitter->color_fixup_supported(This->resource.format_desc->color_fixup)
- && device->render_targets && This == (IWineD3DSurfaceImpl*)device->render_targets[0]))
+ if (!((blit_supported && device->render_targets && This == device->render_targets[0]))
|| colorkey_active || !use_texturing)
{
- *format = GL_RGBA;
- *internal = GL_RGBA;
- *type = GL_UNSIGNED_BYTE;
- *target_bpp = 4;
+ desc->glFormat = GL_RGBA;
+ desc->glInternal = GL_RGBA;
+ desc->glType = GL_UNSIGNED_BYTE;
+ desc->conv_byte_count = 4;
if(colorkey_active) {
*convert = CONVERT_PALETTED_CK;
} else {
*convert = CONVERT_PALETTED;
}
}
- else if (!gl_info->supported[EXT_PALETTED_TEXTURE] && device->blitter->color_fixup_supported(This->resource.format_desc->color_fixup))
- {
- *format = GL_ALPHA;
- *type = GL_UNSIGNED_BYTE;
- *target_bpp = 1;
- }
-
break;
case WINED3DFMT_B2G3R3_UNORM:
case WINED3DFMT_B5G6R5_UNORM:
if (colorkey_active) {
*convert = CONVERT_CK_565;
- *format = GL_RGBA;
- *internal = GL_RGB5_A1;
- *type = GL_UNSIGNED_SHORT_5_5_5_1;
+ desc->glFormat = GL_RGBA;
+ desc->glInternal = GL_RGB5_A1;
+ desc->glType = GL_UNSIGNED_SHORT_5_5_5_1;
+ desc->conv_byte_count = 2;
}
break;
case WINED3DFMT_B5G5R5X1_UNORM:
if (colorkey_active) {
*convert = CONVERT_CK_5551;
- *format = GL_BGRA;
- *internal = GL_RGB5_A1;
- *type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+ desc->glFormat = GL_BGRA;
+ desc->glInternal = GL_RGB5_A1;
+ desc->glType = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+ desc->conv_byte_count = 2;
}
break;
case WINED3DFMT_B8G8R8_UNORM:
if (colorkey_active) {
*convert = CONVERT_CK_RGB24;
- *format = GL_RGBA;
- *internal = GL_RGBA8;
- *type = GL_UNSIGNED_INT_8_8_8_8;
- *target_bpp = 4;
+ desc->glFormat = GL_RGBA;
+ desc->glInternal = GL_RGBA8;
+ desc->glType = GL_UNSIGNED_INT_8_8_8_8;
+ desc->conv_byte_count = 4;
}
break;
case WINED3DFMT_B8G8R8X8_UNORM:
if (colorkey_active) {
*convert = CONVERT_RGB32_888;
- *format = GL_RGBA;
- *internal = GL_RGBA8;
- *type = GL_UNSIGNED_INT_8_8_8_8;
- }
- break;
-
- case WINED3DFMT_R8G8_SNORM:
- if (gl_info->supported[NV_TEXTURE_SHADER]) break;
- *convert = CONVERT_V8U8;
- *format = GL_BGR;
- *type = GL_UNSIGNED_BYTE;
- *target_bpp = 3;
- break;
-
- case WINED3DFMT_R5G5_SNORM_L6_UNORM:
- *convert = CONVERT_L6V5U5;
- if (gl_info->supported[NV_TEXTURE_SHADER])
- {
- *target_bpp = 3;
- /* Use format and types from table */
- } else {
- /* Load it into unsigned R5G6B5, swap L and V channels, and revert that in the shader */
- *target_bpp = 2;
- *format = GL_RGB;
- *type = GL_UNSIGNED_SHORT_5_6_5;
- }
- break;
-
- case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
- *convert = CONVERT_X8L8V8U8;
- *target_bpp = 4;
- if (gl_info->supported[NV_TEXTURE_SHADER])
- {
- /* Use formats from gl table. It is a bit unfortunate, but the conversion
- * is needed to set the X format to 255 to get 1.0 for alpha when sampling
- * the texture. OpenGL can't use GL_DSDT8_MAG8_NV as internal format with
- * the needed type and format parameter, so the internal format contains a
- * 4th component, which is returned as alpha
- */
- } else {
- *format = GL_BGRA;
- *type = GL_UNSIGNED_INT_8_8_8_8_REV;
- }
- break;
-
- case WINED3DFMT_R8G8B8A8_SNORM:
- if (gl_info->supported[NV_TEXTURE_SHADER]) break;
- *convert = CONVERT_Q8W8V8U8;
- *format = GL_BGRA;
- *type = GL_UNSIGNED_BYTE;
- *target_bpp = 4;
- break;
-
- case WINED3DFMT_R16G16_SNORM:
- if (gl_info->supported[NV_TEXTURE_SHADER]) break;
- *convert = CONVERT_V16U16;
- *format = GL_BGR;
- *type = GL_UNSIGNED_SHORT;
- *target_bpp = 6;
- break;
-
- case WINED3DFMT_L4A4_UNORM:
- /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
- * format+type combination to load it. Thus convert it to A8L8, then load it
- * with A4L4 internal, but A8L8 format+type
- */
- *convert = CONVERT_A4L4;
- *format = GL_LUMINANCE_ALPHA;
- *type = GL_UNSIGNED_BYTE;
- *target_bpp = 2;
- break;
-
- case WINED3DFMT_R16G16_UNORM:
- *convert = CONVERT_G16R16;
- *format = GL_RGB;
- *type = GL_UNSIGNED_SHORT;
- *target_bpp = 6;
- break;
-
- case WINED3DFMT_R16G16_FLOAT:
- *convert = CONVERT_R16G16F;
- *format = GL_RGB;
- *type = GL_HALF_FLOAT_ARB;
- *target_bpp = 6;
- break;
-
- case WINED3DFMT_R32G32_FLOAT:
- *convert = CONVERT_R32G32F;
- *format = GL_RGB;
- *type = GL_FLOAT;
- *target_bpp = 12;
- break;
-
- case WINED3DFMT_S1_UINT_D15_UNORM:
- if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
- || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
- {
- *convert = CONVERT_D15S1;
- *target_bpp = 4;
- }
- break;
-
- case WINED3DFMT_S4X4_UINT_D24_UNORM:
- if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
- || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
- {
- *convert = CONVERT_D24X4S4;
- }
- break;
-
- case WINED3DFMT_S8_UINT_D24_FLOAT:
- if (gl_info->supported[ARB_DEPTH_BUFFER_FLOAT])
- {
- *convert = CONVERT_D24FS8;
- *target_bpp = 8;
+ desc->glFormat = GL_RGBA;
+ desc->glInternal = GL_RGBA8;
+ desc->glType = GL_UNSIGNED_INT_8_8_8_8;
+ desc->conv_byte_count = 4;
}
break;
return WINED3D_OK;
}
-static void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey)
+void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey)
{
IWineD3DDeviceImpl *device = This->resource.device;
IWineD3DPaletteImpl *pal = This->palette;
static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UINT width,
UINT height, UINT outpitch, CONVERT_TYPES convert, IWineD3DSurfaceImpl *This)
{
- IWineD3DDeviceImpl *device = This->resource.device;
- const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
const BYTE *source;
BYTE *dest;
TRACE("(%p)->(%p),(%d,%d,%d,%d,%p)\n", src, dst, pitch, height, outpitch, convert,This);
}
break;
- case CONVERT_V8U8:
- {
- unsigned int x, y;
- const short *Source;
- unsigned char *Dest;
- for(y = 0; y < height; y++) {
- Source = (const short *)(src + y * pitch);
- Dest = dst + y * outpitch;
- for (x = 0; x < width; x++ ) {
- long color = (*Source++);
- /* B */ Dest[0] = 0xff;
- /* G */ Dest[1] = (color >> 8) + 128; /* V */
- /* R */ Dest[2] = (color) + 128; /* U */
- Dest += 3;
- }
- }
- break;
- }
-
- case CONVERT_V16U16:
- {
- unsigned int x, y;
- const DWORD *Source;
- unsigned short *Dest;
- for(y = 0; y < height; y++) {
- Source = (const DWORD *)(src + y * pitch);
- Dest = (unsigned short *) (dst + y * outpitch);
- for (x = 0; x < width; x++ ) {
- DWORD color = (*Source++);
- /* B */ Dest[0] = 0xffff;
- /* G */ Dest[1] = (color >> 16) + 32768; /* V */
- /* R */ Dest[2] = (color ) + 32768; /* U */
- Dest += 3;
- }
- }
- break;
- }
-
- case CONVERT_Q8W8V8U8:
- {
- unsigned int x, y;
- const DWORD *Source;
- unsigned char *Dest;
- for(y = 0; y < height; y++) {
- Source = (const DWORD *)(src + y * pitch);
- Dest = dst + y * outpitch;
- for (x = 0; x < width; x++ ) {
- long color = (*Source++);
- /* B */ Dest[0] = ((color >> 16) & 0xff) + 128; /* W */
- /* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
- /* R */ Dest[2] = (color & 0xff) + 128; /* U */
- /* A */ Dest[3] = ((color >> 24) & 0xff) + 128; /* Q */
- Dest += 4;
- }
- }
- break;
- }
-
- case CONVERT_L6V5U5:
- {
- unsigned int x, y;
- const WORD *Source;
- unsigned char *Dest;
-
- if (gl_info->supported[NV_TEXTURE_SHADER])
- {
- /* This makes the gl surface bigger(24 bit instead of 16), but it works with
- * fixed function and shaders without further conversion once the surface is
- * loaded
- */
- for(y = 0; y < height; y++) {
- Source = (const WORD *)(src + y * pitch);
- Dest = dst + y * outpitch;
- for (x = 0; x < width; x++ ) {
- short color = (*Source++);
- unsigned char l = ((color >> 10) & 0xfc);
- char v = ((color >> 5) & 0x3e);
- char u = ((color ) & 0x1f);
-
- /* 8 bits destination, 6 bits source, 8th bit is the sign. gl ignores the sign
- * and doubles the positive range. Thus shift left only once, gl does the 2nd
- * shift. GL reads a signed value and converts it into an unsigned value.
- */
- /* M */ Dest[2] = l << 1;
-
- /* Those are read as signed, but kept signed. Just left-shift 3 times to scale
- * from 5 bit values to 8 bit values.
- */
- /* V */ Dest[1] = v << 3;
- /* U */ Dest[0] = u << 3;
- Dest += 3;
- }
- }
- } else {
- for(y = 0; y < height; y++) {
- unsigned short *Dest_s = (unsigned short *) (dst + y * outpitch);
- Source = (const WORD *)(src + y * pitch);
- for (x = 0; x < width; x++ ) {
- short color = (*Source++);
- unsigned char l = ((color >> 10) & 0xfc);
- short v = ((color >> 5) & 0x3e);
- short u = ((color ) & 0x1f);
- short v_conv = v + 16;
- short u_conv = u + 16;
-
- *Dest_s = ((v_conv << 11) & 0xf800) | ((l << 5) & 0x7e0) | (u_conv & 0x1f);
- Dest_s += 1;
- }
- }
- }
- break;
- }
-
- case CONVERT_X8L8V8U8:
- {
- unsigned int x, y;
- const DWORD *Source;
- unsigned char *Dest;
-
- if (gl_info->supported[NV_TEXTURE_SHADER])
- {
- /* This implementation works with the fixed function pipeline and shaders
- * without further modification after converting the surface.
- */
- for(y = 0; y < height; y++) {
- Source = (const DWORD *)(src + y * pitch);
- Dest = dst + y * outpitch;
- for (x = 0; x < width; x++ ) {
- long color = (*Source++);
- /* L */ Dest[2] = ((color >> 16) & 0xff); /* L */
- /* V */ Dest[1] = ((color >> 8 ) & 0xff); /* V */
- /* U */ Dest[0] = (color & 0xff); /* U */
- /* I */ Dest[3] = 255; /* X */
- Dest += 4;
- }
- }
- } else {
- /* Doesn't work correctly with the fixed function pipeline, but can work in
- * shaders if the shader is adjusted. (There's no use for this format in gl's
- * standard fixed function pipeline anyway).
- */
- for(y = 0; y < height; y++) {
- Source = (const DWORD *)(src + y * pitch);
- Dest = dst + y * outpitch;
- for (x = 0; x < width; x++ ) {
- long color = (*Source++);
- /* B */ Dest[0] = ((color >> 16) & 0xff); /* L */
- /* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
- /* R */ Dest[2] = (color & 0xff) + 128; /* U */
- Dest += 4;
- }
- }
- }
- break;
- }
-
- case CONVERT_A4L4:
- {
- unsigned int x, y;
- const unsigned char *Source;
- unsigned char *Dest;
- for(y = 0; y < height; y++) {
- Source = src + y * pitch;
- Dest = dst + y * outpitch;
- for (x = 0; x < width; x++ ) {
- unsigned char color = (*Source++);
- /* A */ Dest[1] = (color & 0xf0) << 0;
- /* L */ Dest[0] = (color & 0x0f) << 4;
- Dest += 2;
- }
- }
- break;
- }
-
- case CONVERT_G16R16:
- case CONVERT_R16G16F:
- {
- unsigned int x, y;
- const WORD *Source;
- WORD *Dest;
-
- for(y = 0; y < height; y++) {
- Source = (const WORD *)(src + y * pitch);
- Dest = (WORD *) (dst + y * outpitch);
- for (x = 0; x < width; x++ ) {
- WORD green = (*Source++);
- WORD red = (*Source++);
- Dest[0] = green;
- Dest[1] = red;
- /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
- * shader overwrites it anyway
- */
- Dest[2] = 0xffff;
- Dest += 3;
- }
- }
- break;
- }
-
- case CONVERT_R32G32F:
- {
- unsigned int x, y;
- const float *Source;
- float *Dest;
- for(y = 0; y < height; y++) {
- Source = (const float *)(src + y * pitch);
- Dest = (float *) (dst + y * outpitch);
- for (x = 0; x < width; x++ ) {
- float green = (*Source++);
- float red = (*Source++);
- Dest[0] = green;
- Dest[1] = red;
- Dest[2] = 1.0f;
- Dest += 3;
- }
- }
- break;
- }
-
- case CONVERT_D15S1:
- {
- unsigned int x, y;
-
- for (y = 0; y < height; ++y)
- {
- const WORD *source = (const WORD *)(src + y * pitch);
- DWORD *dest = (DWORD *)(dst + y * outpitch);
-
- for (x = 0; x < width; ++x)
- {
- /* The depth data is normalized, so needs to be scaled,
- * the stencil data isn't. Scale depth data by
- * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
- WORD d15 = source[x] >> 1;
- DWORD d24 = (d15 << 9) + (d15 >> 6);
- dest[x] = (d24 << 8) | (source[x] & 0x1);
- }
- }
- break;
- }
-
- case CONVERT_D24X4S4:
- {
- unsigned int x, y;
-
- for (y = 0; y < height; ++y)
- {
- const DWORD *source = (const DWORD *)(src + y * pitch);
- DWORD *dest = (DWORD *)(dst + y * outpitch);
-
- for (x = 0; x < width; ++x)
- {
- /* Just need to clear out the X4 part. */
- dest[x] = source[x] & ~0xf0;
- }
- }
- break;
- }
-
- case CONVERT_D24FS8:
- {
- unsigned int x, y;
-
- for (y = 0; y < height; ++y)
- {
- const DWORD *source = (const DWORD *)(src + y * pitch);
- float *dest_f = (float *)(dst + y * outpitch);
- DWORD *dest_s = (DWORD *)(dst + y * outpitch);
-
- for (x = 0; x < width; ++x)
- {
- dest_f[x * 2] = float_24_to_32((source[x] & 0xffffff00) >> 8);
- dest_s[x * 2 + 1] = source[x] & 0xff;
- }
- }
- break;
- }
-
default:
ERR("Unsupported conversion type %#x.\n", convert);
}
return WINED3D_OK;
}
-/* This function is used in case of 8bit paletted textures to upload the palette.
- It supports GL_EXT_paletted_texture and GL_ARB_fragment_program, support for other
- extensions like ATI_fragment_shaders is possible.
-*/
-/* Context activation is done by the caller. */
-static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface, CONVERT_TYPES convert) {
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
- BYTE table[256][4];
- IWineD3DDeviceImpl *device = This->resource.device;
- const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-
- d3dfmt_p8_init_palette(This, table, (convert == CONVERT_PALETTED_CK));
-
- /* Try to use the paletted texture extension */
- if (gl_info->supported[EXT_PALETTED_TEXTURE])
- {
- TRACE("Using GL_EXT_PALETTED_TEXTURE for 8-bit paletted texture support\n");
- ENTER_GL();
- GL_EXTCALL(glColorTableEXT(This->texture_target, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, table));
- LEAVE_GL();
- }
- else
- {
- /* Let a fragment shader do the color conversion by uploading the palette to a 1D texture.
- * The 8bit pixel data will be used as an index in this palette texture to retrieve the final color. */
- TRACE("Using fragment shaders for emulating 8-bit paletted texture support\n");
-
- device->blitter->set_shader((IWineD3DDevice *) device, This->resource.format_desc,
- This->texture_target, This->pow2Width, This->pow2Height);
-
- ENTER_GL();
- GL_EXTCALL(glActiveTextureARB(GL_TEXTURE1));
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-
- glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /* Make sure we have discrete color levels. */
- glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table); /* Upload the palette */
-
- /* Switch back to unit 0 in which the 2D texture will be stored. */
- GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0));
-
- /* Rebind the texture because it isn't bound anymore */
- glBindTexture(This->texture_target, This->texture_name);
- LEAVE_GL();
- }
-}
-
BOOL palette9_changed(IWineD3DSurfaceImpl *This)
{
IWineD3DDeviceImpl *device = This->resource.device;
LEAVE_GL();
} else { /* bind the real texture, and make sure it up to date */
- surface_internal_preload(iface, SRGB_RGB);
+ surface_internal_preload(This, SRGB_RGB);
surface_bind_and_dirtify(This, FALSE);
}
allocatedMemory = HeapAlloc(GetProcessHeap(), 0, width * height * 4);
IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
/* For client textures opengl has to be notified */
- if(This->Flags & SFLAG_CLIENT) {
- surface_release_client_storage(iface);
- }
+ if (This->Flags & SFLAG_CLIENT)
+ surface_release_client_storage(This);
/* Now free the old memory if any */
HeapFree(GetProcessHeap(), 0, release);
if(This->resource.heapMemory != NULL) ERR("User pointer surface has heap memory allocated\n");
This->Flags &= ~SFLAG_USERPTR;
- if(This->Flags & SFLAG_CLIENT) {
- surface_release_client_storage(iface);
- }
+ if (This->Flags & SFLAG_CLIENT)
+ surface_release_client_storage(This);
}
return WINED3D_OK;
}
}
/* Flipping a OpenGL surface -> Use WineD3DDevice::Present */
- hr = IWineD3DSwapChain_Present((IWineD3DSwapChain *) swapchain, NULL, NULL, 0, NULL, 0);
+ hr = IWineD3DSwapChain_Present((IWineD3DSwapChain *)swapchain,
+ NULL, NULL, swapchain->win_handle, NULL, 0);
IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
return hr;
}
/* Does a direct frame buffer -> texture copy. Stretching is done
* with single pixel copy calls
*/
-static inline void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface,
- const WINED3DRECT *srect, const WINED3DRECT *drect, BOOL upsidedown, WINED3DTEXTUREFILTERTYPE Filter)
+static void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *dst_surface, IWineD3DSurfaceImpl *src_surface,
+ const RECT *src_rect, const RECT *dst_rect_in, WINED3DTEXTUREFILTERTYPE Filter)
{
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = dst_surface->resource.device;
float xrel, yrel;
UINT row;
- IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
struct wined3d_context *context;
+ BOOL upsidedown = FALSE;
+ RECT dst_rect = *dst_rect_in;
+ /* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
+ * glCopyTexSubImage is a bit picky about the parameters we pass to it
+ */
+ if(dst_rect.top > dst_rect.bottom) {
+ UINT tmp = dst_rect.bottom;
+ dst_rect.bottom = dst_rect.top;
+ dst_rect.top = tmp;
+ upsidedown = TRUE;
+ }
- context = context_acquire(myDevice, SrcSurface, CTXUSAGE_BLIT);
- surface_internal_preload((IWineD3DSurface *) This, SRGB_RGB);
+ context = context_acquire(device, src_surface);
+ context_apply_blit_state(context, device);
+ surface_internal_preload(dst_surface, SRGB_RGB);
ENTER_GL();
/* Bind the target texture */
- glBindTexture(This->texture_target, This->texture_name);
+ glBindTexture(dst_surface->texture_target, dst_surface->texture_name);
checkGLcall("glBindTexture");
- if(surface_is_offscreen(SrcSurface)) {
+ if (surface_is_offscreen(src_surface))
+ {
TRACE("Reading from an offscreen target\n");
upsidedown = !upsidedown;
- glReadBuffer(myDevice->offscreenBuffer);
+ glReadBuffer(device->offscreenBuffer);
}
else
{
- glReadBuffer(surface_get_gl_buffer(SrcSurface));
+ glReadBuffer(surface_get_gl_buffer(src_surface));
}
checkGLcall("glReadBuffer");
- xrel = (float) (srect->x2 - srect->x1) / (float) (drect->x2 - drect->x1);
- yrel = (float) (srect->y2 - srect->y1) / (float) (drect->y2 - drect->y1);
+ xrel = (float) (src_rect->right - src_rect->left) / (float) (dst_rect.right - dst_rect.left);
+ yrel = (float) (src_rect->bottom - src_rect->top) / (float) (dst_rect.bottom - dst_rect.top);
if ((xrel - 1.0f < -eps) || (xrel - 1.0f > eps))
{
{
/* Upside down copy without stretching is nice, one glCopyTexSubImage call will do */
- glCopyTexSubImage2D(This->texture_target, This->texture_level,
- drect->x1 /*xoffset */, drect->y1 /* y offset */,
- srect->x1, Src->currentDesc.Height - srect->y2,
- drect->x2 - drect->x1, drect->y2 - drect->y1);
+ glCopyTexSubImage2D(dst_surface->texture_target, dst_surface->texture_level,
+ dst_rect.left /*xoffset */, dst_rect.top /* y offset */,
+ src_rect->left, src_surface->currentDesc.Height - src_rect->bottom,
+ dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top);
} else {
- UINT yoffset = Src->currentDesc.Height - srect->y1 + drect->y1 - 1;
+ UINT yoffset = src_surface->currentDesc.Height - src_rect->top + dst_rect.top - 1;
/* I have to process this row by row to swap the image,
* otherwise it would be upside down, so stretching in y direction
* doesn't cost extra time
*
* However, stretching in x direction can be avoided if not necessary
*/
- for(row = drect->y1; row < drect->y2; row++) {
+ for(row = dst_rect.top; row < dst_rect.bottom; row++) {
if ((xrel - 1.0f < -eps) || (xrel - 1.0f > eps))
{
/* Well, that stuff works, but it's very slow.
*/
UINT col;
- for(col = drect->x1; col < drect->x2; col++) {
- glCopyTexSubImage2D(This->texture_target, This->texture_level,
- drect->x1 + col /* x offset */, row /* y offset */,
- srect->x1 + col * xrel, yoffset - (int) (row * yrel), 1, 1);
+ for (col = dst_rect.left; col < dst_rect.right; ++col)
+ {
+ glCopyTexSubImage2D(dst_surface->texture_target, dst_surface->texture_level,
+ dst_rect.left + col /* x offset */, row /* y offset */,
+ src_rect->left + col * xrel, yoffset - (int) (row * yrel), 1, 1);
}
- } else {
- glCopyTexSubImage2D(This->texture_target, This->texture_level,
- drect->x1 /* x offset */, row /* y offset */,
- srect->x1, yoffset - (int) (row * yrel), drect->x2-drect->x1, 1);
+ }
+ else
+ {
+ glCopyTexSubImage2D(dst_surface->texture_target, dst_surface->texture_level,
+ dst_rect.left /* x offset */, row /* y offset */,
+ src_rect->left, yoffset - (int) (row * yrel), dst_rect.right - dst_rect.left, 1);
}
}
}
/* The texture is now most up to date - If the surface is a render target and has a drawable, this
* path is never entered
*/
- IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INTEXTURE, TRUE);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)dst_surface, SFLAG_INTEXTURE, TRUE);
}
/* Uses the hardware to stretch and flip the image */
-static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface,
- IWineD3DSwapChainImpl *swapchain, const WINED3DRECT *srect, const WINED3DRECT *drect,
- BOOL upsidedown, WINED3DTEXTUREFILTERTYPE Filter)
+static void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *dst_surface, IWineD3DSurfaceImpl *src_surface,
+ const RECT *src_rect, const RECT *dst_rect_in, WINED3DTEXTUREFILTERTYPE Filter)
{
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = dst_surface->resource.device;
GLuint src, backup = 0;
- IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
+ IWineD3DSwapChainImpl *src_swapchain = NULL;
float left, right, top, bottom; /* Texture coordinates */
- UINT fbwidth = Src->currentDesc.Width;
- UINT fbheight = Src->currentDesc.Height;
+ UINT fbwidth = src_surface->currentDesc.Width;
+ UINT fbheight = src_surface->currentDesc.Height;
struct wined3d_context *context;
GLenum drawBuffer = GL_BACK;
GLenum texture_target;
BOOL noBackBufferBackup;
BOOL src_offscreen;
+ BOOL upsidedown = FALSE;
+ RECT dst_rect = *dst_rect_in;
TRACE("Using hwstretch blit\n");
/* Activate the Proper context for reading from the source surface, set it up for blitting */
- context = context_acquire(myDevice, SrcSurface, CTXUSAGE_BLIT);
- surface_internal_preload((IWineD3DSurface *) This, SRGB_RGB);
+ context = context_acquire(device, src_surface);
+ context_apply_blit_state(context, device);
+ surface_internal_preload(dst_surface, SRGB_RGB);
- src_offscreen = surface_is_offscreen(SrcSurface);
+ src_offscreen = surface_is_offscreen(src_surface);
noBackBufferBackup = src_offscreen && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
- if (!noBackBufferBackup && !Src->texture_name)
+ if (!noBackBufferBackup && !src_surface->texture_name)
{
/* Get it a description */
- surface_internal_preload(SrcSurface, SRGB_RGB);
+ surface_internal_preload(src_surface, SRGB_RGB);
}
ENTER_GL();
/* Got more than one aux buffer? Use the 2nd aux buffer */
drawBuffer = GL_AUX1;
}
- else if ((!src_offscreen || myDevice->offscreenBuffer == GL_BACK) && context->aux_buffers >= 1)
+ else if ((!src_offscreen || device->offscreenBuffer == GL_BACK) && context->aux_buffers >= 1)
{
/* Only one aux buffer, but it isn't used (Onscreen rendering, or non-aux orm)? Use it! */
drawBuffer = GL_AUX0;
/* Backup the back buffer and copy the source buffer into a texture to draw an upside down stretched quad. If
* we are reading from the back buffer, the backup can be used as source texture
*/
- texture_target = Src->texture_target;
- glBindTexture(texture_target, Src->texture_name);
- checkGLcall("glBindTexture(texture_target, Src->texture_name)");
+ texture_target = src_surface->texture_target;
+ glBindTexture(texture_target, src_surface->texture_name);
+ checkGLcall("glBindTexture(texture_target, src_surface->texture_name)");
glEnable(texture_target);
checkGLcall("glEnable(texture_target)");
/* For now invalidate the texture copy of the back buffer. Drawable and sysmem copy are untouched */
- Src->Flags &= ~SFLAG_INTEXTURE;
+ src_surface->Flags &= ~SFLAG_INTEXTURE;
+ }
+
+ /* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
+ * glCopyTexSubImage is a bit picky about the parameters we pass to it
+ */
+ if(dst_rect.top > dst_rect.bottom) {
+ UINT tmp = dst_rect.bottom;
+ dst_rect.bottom = dst_rect.top;
+ dst_rect.top = tmp;
+ upsidedown = TRUE;
}
if (src_offscreen)
{
TRACE("Reading from an offscreen target\n");
upsidedown = !upsidedown;
- glReadBuffer(myDevice->offscreenBuffer);
+ glReadBuffer(device->offscreenBuffer);
}
else
{
- glReadBuffer(surface_get_gl_buffer(SrcSurface));
+ glReadBuffer(surface_get_gl_buffer(src_surface));
}
/* TODO: Only back up the part that will be overwritten */
wined3d_gl_min_mip_filter(minMipLookup, Filter, WINED3DTEXF_NONE));
checkGLcall("glTexParameteri");
- if(!swapchain || (IWineD3DSurface *) Src == swapchain->backBuffer[0]) {
- src = backup ? backup : Src->texture_name;
- } else {
+ IWineD3DSurface_GetContainer((IWineD3DSurface *)src_surface, &IID_IWineD3DSwapChain, (void **)&src_swapchain);
+ if (src_swapchain) IWineD3DSwapChain_Release((IWineD3DSwapChain *)src_swapchain);
+ if (!src_swapchain || src_surface == src_swapchain->back_buffers[0])
+ {
+ src = backup ? backup : src_surface->texture_name;
+ }
+ else
+ {
glReadBuffer(GL_FRONT);
checkGLcall("glReadBuffer(GL_FRONT)");
glBindTexture(GL_TEXTURE_2D, src);
checkGLcall("glBindTexture(GL_TEXTURE_2D, src)");
- /* TODO: Only copy the part that will be read. Use srect->x1, srect->y2 as origin, but with the width watch
+ /* TODO: Only copy the part that will be read. Use src_rect->left, src_rect->bottom as origin, but with the width watch
* out for power of 2 sizes
*/
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Src->pow2Width, Src->pow2Height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, src_surface->pow2Width,
+ src_surface->pow2Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
checkGLcall("glTexImage2D");
glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
0, 0 /* read offsets */,
}
checkGLcall("glEnd and previous");
- left = srect->x1;
- right = srect->x2;
+ left = src_rect->left;
+ right = src_rect->right;
- if(upsidedown) {
- top = Src->currentDesc.Height - srect->y1;
- bottom = Src->currentDesc.Height - srect->y2;
- } else {
- top = Src->currentDesc.Height - srect->y2;
- bottom = Src->currentDesc.Height - srect->y1;
+ if (upsidedown)
+ {
+ top = src_surface->currentDesc.Height - src_rect->top;
+ bottom = src_surface->currentDesc.Height - src_rect->bottom;
+ }
+ else
+ {
+ top = src_surface->currentDesc.Height - src_rect->bottom;
+ bottom = src_surface->currentDesc.Height - src_rect->top;
}
- if(Src->Flags & SFLAG_NORMCOORD) {
- left /= Src->pow2Width;
- right /= Src->pow2Width;
- top /= Src->pow2Height;
- bottom /= Src->pow2Height;
+ if (src_surface->Flags & SFLAG_NORMCOORD)
+ {
+ left /= src_surface->pow2Width;
+ right /= src_surface->pow2Width;
+ top /= src_surface->pow2Height;
+ bottom /= src_surface->pow2Height;
}
/* draw the source texture stretched and upside down. The correct surface is bound already */
/* top left */
glTexCoord2f(left, top);
- glVertex2i(0, fbheight - drect->y2 - drect->y1);
+ glVertex2i(0, fbheight - dst_rect.bottom - dst_rect.top);
/* top right */
glTexCoord2f(right, top);
- glVertex2i(drect->x2 - drect->x1, fbheight - drect->y2 - drect->y1);
+ glVertex2i(dst_rect.right - dst_rect.left, fbheight - dst_rect.bottom - dst_rect.top);
/* bottom right */
glTexCoord2f(right, bottom);
- glVertex2i(drect->x2 - drect->x1, fbheight);
+ glVertex2i(dst_rect.right - dst_rect.left, fbheight);
glEnd();
checkGLcall("glEnd and previous");
- if (texture_target != This->texture_target)
+ if (texture_target != dst_surface->texture_target)
{
glDisable(texture_target);
- glEnable(This->texture_target);
- texture_target = This->texture_target;
+ glEnable(dst_surface->texture_target);
+ texture_target = dst_surface->texture_target;
}
/* Now read the stretched and upside down image into the destination texture */
- glBindTexture(texture_target, This->texture_name);
+ glBindTexture(texture_target, dst_surface->texture_name);
checkGLcall("glBindTexture");
glCopyTexSubImage2D(texture_target,
0,
- drect->x1, drect->y1, /* xoffset, yoffset */
+ dst_rect.left, dst_rect.top, /* xoffset, yoffset */
0, 0, /* We blitted the image to the origin */
- drect->x2 - drect->x1, drect->y2 - drect->y1);
+ dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top);
checkGLcall("glCopyTexSubImage2D");
if(drawBuffer == GL_BACK) {
}
glBindTexture(GL_TEXTURE_2D, backup);
checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
- } else {
- if (texture_target != Src->texture_target)
- {
- glDisable(texture_target);
- glEnable(Src->texture_target);
- texture_target = Src->texture_target;
+ }
+ else
+ {
+ if (texture_target != src_surface->texture_target)
+ {
+ glDisable(texture_target);
+ glEnable(src_surface->texture_target);
+ texture_target = src_surface->texture_target;
}
- glBindTexture(Src->texture_target, Src->texture_name);
- checkGLcall("glBindTexture(Src->texture_target, Src->texture_name)");
+ glBindTexture(src_surface->texture_target, src_surface->texture_name);
+ checkGLcall("glBindTexture(src_surface->texture_target, src_surface->texture_name)");
}
glBegin(GL_QUADS);
/* top left */
- glTexCoord2f(0.0f, (float)fbheight / (float)Src->pow2Height);
+ glTexCoord2f(0.0f, (float)fbheight / (float)src_surface->pow2Height);
glVertex2i(0, 0);
/* bottom left */
glVertex2i(0, fbheight);
/* bottom right */
- glTexCoord2f((float)fbwidth / (float)Src->pow2Width, 0.0f);
- glVertex2i(fbwidth, Src->currentDesc.Height);
+ glTexCoord2f((float)fbwidth / (float)src_surface->pow2Width, 0.0f);
+ glVertex2i(fbwidth, src_surface->currentDesc.Height);
/* top right */
- glTexCoord2f((float) fbwidth / (float) Src->pow2Width, (float) fbheight / (float) Src->pow2Height);
+ glTexCoord2f((float)fbwidth / (float)src_surface->pow2Width,
+ (float)fbheight / (float)src_surface->pow2Height);
glVertex2i(fbwidth, 0);
glEnd();
}
checkGLcall("glDisable(texture_target)");
/* Cleanup */
- if (src != Src->texture_name && src != backup)
+ if (src != src_surface->texture_name && src != backup)
{
glDeleteTextures(1, &src);
checkGLcall("glDeleteTextures(1, &src)");
LEAVE_GL();
- wglFlush(); /* Flush to ensure ordering across contexts. */
+ if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
context_release(context);
/* The texture is now most up to date - If the surface is a render target and has a drawable, this
* path is never entered
*/
- IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INTEXTURE, TRUE);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)dst_surface, SFLAG_INTEXTURE, TRUE);
+}
+
+/* Until the blit_shader is ready, define some prototypes here. */
+static BOOL fbo_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
+ const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool,
+ const struct wined3d_format_desc *src_format_desc,
+ const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool,
+ const struct wined3d_format_desc *dst_format_desc);
+
+/* Front buffer coordinates are always full screen coordinates, but our GL
+ * drawable is limited to the window's client area. The sysmem and texture
+ * copies do have the full screen size. Note that GL has a bottom-left
+ * origin, while D3D has a top-left origin. */
+void surface_translate_frontbuffer_coords(IWineD3DSurfaceImpl *surface, HWND window, RECT *rect)
+{
+ POINT offset = {0, surface->currentDesc.Height};
+ RECT windowsize;
+
+ GetClientRect(window, &windowsize);
+ offset.y -= windowsize.bottom - windowsize.top;
+ ScreenToClient(window, &offset);
+ OffsetRect(rect, offset.x, offset.y);
}
/* Not called from the VTable */
-static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, const RECT *DestRect,
- IWineD3DSurface *SrcSurface, const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx,
+static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *dst_surface, const RECT *DestRect,
+ IWineD3DSurfaceImpl *src_surface, const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx,
WINED3DTEXTUREFILTERTYPE Filter)
{
- IWineD3DDeviceImpl *myDevice = This->resource.device;
- WINED3DRECT rect;
+ IWineD3DDeviceImpl *device = dst_surface->resource.device;
IWineD3DSwapChainImpl *srcSwapchain = NULL, *dstSwapchain = NULL;
- IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
+ RECT dst_rect, src_rect;
- TRACE("(%p)->(%p,%p,%p,%08x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
+ TRACE("dst_surface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, blt_fx %p, filter %s.\n",
+ dst_surface, wine_dbgstr_rect(DestRect), src_surface, wine_dbgstr_rect(SrcRect),
+ Flags, DDBltFx, debug_d3dtexturefiltertype(Filter));
/* Get the swapchain. One of the surfaces has to be a primary surface */
- if(This->resource.pool == WINED3DPOOL_SYSTEMMEM) {
+ if (dst_surface->resource.pool == WINED3DPOOL_SYSTEMMEM)
+ {
WARN("Destination is in sysmem, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
- IWineD3DSurface_GetContainer( (IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&dstSwapchain);
- if(dstSwapchain) IWineD3DSwapChain_Release((IWineD3DSwapChain *) dstSwapchain);
- if(Src) {
- if(Src->resource.pool == WINED3DPOOL_SYSTEMMEM) {
+ IWineD3DSurface_GetContainer((IWineD3DSurface *)dst_surface, &IID_IWineD3DSwapChain, (void **)&dstSwapchain);
+ if (dstSwapchain) IWineD3DSwapChain_Release((IWineD3DSwapChain *)dstSwapchain);
+ if (src_surface)
+ {
+ if (src_surface->resource.pool == WINED3DPOOL_SYSTEMMEM)
+ {
WARN("Src is in sysmem, rejecting gl blt\n");
return WINED3DERR_INVALIDCALL;
}
- IWineD3DSurface_GetContainer( (IWineD3DSurface *) Src, &IID_IWineD3DSwapChain, (void **)&srcSwapchain);
- if(srcSwapchain) IWineD3DSwapChain_Release((IWineD3DSwapChain *) srcSwapchain);
+ IWineD3DSurface_GetContainer((IWineD3DSurface *)src_surface, &IID_IWineD3DSwapChain, (void **)&srcSwapchain);
+ if (srcSwapchain) IWineD3DSwapChain_Release((IWineD3DSwapChain *)srcSwapchain);
}
/* Early sort out of cases where no render target is used */
- if(!dstSwapchain && !srcSwapchain &&
- SrcSurface != myDevice->render_targets[0] && This != (IWineD3DSurfaceImpl *) myDevice->render_targets[0]) {
- TRACE("No surface is render target, not using hardware blit. Src = %p, dst = %p\n", Src, This);
+ if (!dstSwapchain && !srcSwapchain
+ && src_surface != device->render_targets[0]
+ && dst_surface != device->render_targets[0])
+ {
+ TRACE("No surface is render target, not using hardware blit.\n");
return WINED3DERR_INVALIDCALL;
}
return WINED3DERR_INVALIDCALL;
}
- if (DestRect) {
- rect.x1 = DestRect->left;
- rect.y1 = DestRect->top;
- rect.x2 = DestRect->right;
- rect.y2 = DestRect->bottom;
- } else {
- rect.x1 = 0;
- rect.y1 = 0;
- rect.x2 = This->currentDesc.Width;
- rect.y2 = This->currentDesc.Height;
- }
+ surface_get_rect(dst_surface, DestRect, &dst_rect);
+ if (src_surface) surface_get_rect(src_surface, SrcRect, &src_rect);
/* The only case where both surfaces on a swapchain are supported is a back buffer -> front buffer blit on the same swapchain */
- if(dstSwapchain && dstSwapchain == srcSwapchain && dstSwapchain->backBuffer &&
- ((IWineD3DSurface *) This == dstSwapchain->frontBuffer) && SrcSurface == dstSwapchain->backBuffer[0]) {
+ if (dstSwapchain && dstSwapchain == srcSwapchain && dstSwapchain->back_buffers
+ && dst_surface == dstSwapchain->front_buffer
+ && src_surface == dstSwapchain->back_buffers[0])
+ {
/* Half-life does a Blt from the back buffer to the front buffer,
* Full surface size, no flags... Use present instead
*
/* Check rects - IWineD3DDevice_Present doesn't handle them */
while(1)
{
- RECT mySrcRect;
TRACE("Looking if a Present can be done...\n");
/* Source Rectangle must be full surface */
- if( SrcRect ) {
- if(SrcRect->left != 0 || SrcRect->top != 0 ||
- SrcRect->right != Src->currentDesc.Width || SrcRect->bottom != Src->currentDesc.Height) {
- TRACE("No, Source rectangle doesn't match\n");
- break;
- }
+ if (src_rect.left || src_rect.top
+ || src_rect.right != src_surface->currentDesc.Width
+ || src_rect.bottom != src_surface->currentDesc.Height)
+ {
+ TRACE("No, Source rectangle doesn't match\n");
+ break;
}
- mySrcRect.left = 0;
- mySrcRect.top = 0;
- mySrcRect.right = Src->currentDesc.Width;
- mySrcRect.bottom = Src->currentDesc.Height;
/* No stretching may occur */
- if(mySrcRect.right != rect.x2 - rect.x1 ||
- mySrcRect.bottom != rect.y2 - rect.y1) {
+ if(src_rect.right != dst_rect.right - dst_rect.left ||
+ src_rect.bottom != dst_rect.bottom - dst_rect.top) {
TRACE("No, stretching is done\n");
break;
}
/* Destination must be full surface or match the clipping rectangle */
- if(This->clipper && ((IWineD3DClipperImpl *) This->clipper)->hWnd)
+ if (dst_surface->clipper && ((IWineD3DClipperImpl *)dst_surface->clipper)->hWnd)
{
RECT cliprect;
POINT pos[2];
- GetClientRect(((IWineD3DClipperImpl *) This->clipper)->hWnd, &cliprect);
- pos[0].x = rect.x1;
- pos[0].y = rect.y1;
- pos[1].x = rect.x2;
- pos[1].y = rect.y2;
- MapWindowPoints(GetDesktopWindow(), ((IWineD3DClipperImpl *) This->clipper)->hWnd,
- pos, 2);
+ GetClientRect(((IWineD3DClipperImpl *)dst_surface->clipper)->hWnd, &cliprect);
+ pos[0].x = dst_rect.left;
+ pos[0].y = dst_rect.top;
+ pos[1].x = dst_rect.right;
+ pos[1].y = dst_rect.bottom;
+ MapWindowPoints(GetDesktopWindow(), ((IWineD3DClipperImpl *)dst_surface->clipper)->hWnd, pos, 2);
if(pos[0].x != cliprect.left || pos[0].y != cliprect.top ||
pos[1].x != cliprect.right || pos[1].y != cliprect.bottom)
{
TRACE("No, dest rectangle doesn't match(clipper)\n");
- TRACE("Clip rect at (%d,%d)-(%d,%d)\n", cliprect.left, cliprect.top, cliprect.right, cliprect.bottom);
- TRACE("Blt dest: (%d,%d)-(%d,%d)\n", rect.x1, rect.y1, rect.x2, rect.y2);
+ TRACE("Clip rect at %s\n", wine_dbgstr_rect(&cliprect));
+ TRACE("Blt dest: %s\n", wine_dbgstr_rect(&dst_rect));
break;
}
}
- else
+ else if (dst_rect.left || dst_rect.top
+ || dst_rect.right != dst_surface->currentDesc.Width
+ || dst_rect.bottom != dst_surface->currentDesc.Height)
{
- if(rect.x1 != 0 || rect.y1 != 0 ||
- rect.x2 != This->currentDesc.Width || rect.y2 != This->currentDesc.Height) {
- TRACE("No, dest rectangle doesn't match(surface size)\n");
- break;
- }
+ TRACE("No, dest rectangle doesn't match(surface size)\n");
+ break;
}
TRACE("Yes\n");
dstSwapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_IMMEDIATE;
TRACE("Full screen back buffer -> front buffer blt, performing a flip instead\n");
- IWineD3DSwapChain_Present((IWineD3DSwapChain *) dstSwapchain, NULL, NULL, 0, NULL, 0);
+ IWineD3DSwapChain_Present((IWineD3DSwapChain *)dstSwapchain,
+ NULL, NULL, dstSwapchain->win_handle, NULL, 0);
dstSwapchain->presentParms.SwapEffect = orig_swap;
} else if(dstSwapchain && srcSwapchain) {
FIXME("Implement hardware blit between two different swapchains\n");
return WINED3DERR_INVALIDCALL;
- } else if(dstSwapchain) {
- if(SrcSurface == myDevice->render_targets[0]) {
+ }
+ else if (dstSwapchain)
+ {
+ /* Handled with regular texture -> swapchain blit */
+ if (src_surface == device->render_targets[0])
TRACE("Blit from active render target to a swapchain\n");
- /* Handled with regular texture -> swapchain blit */
- }
- } else if(srcSwapchain && This == (IWineD3DSurfaceImpl *) myDevice->render_targets[0]) {
+ }
+ else if (srcSwapchain && dst_surface == device->render_targets[0])
+ {
FIXME("Implement blit from a swapchain to the active render target\n");
return WINED3DERR_INVALIDCALL;
}
- if((srcSwapchain || SrcSurface == myDevice->render_targets[0]) && !dstSwapchain) {
+ if ((srcSwapchain || src_surface == device->render_targets[0]) && !dstSwapchain)
+ {
/* Blit from render target to texture */
- WINED3DRECT srect;
- BOOL upsideDown, stretchx;
- BOOL paletteOverride = FALSE;
+ BOOL stretchx;
+
+ /* P8 read back is not implemented */
+ if (src_surface->resource.format_desc->format == WINED3DFMT_P8_UINT
+ || dst_surface->resource.format_desc->format == WINED3DFMT_P8_UINT)
+ {
+ TRACE("P8 read back not supported by frame buffer to texture blit\n");
+ return WINED3DERR_INVALIDCALL;
+ }
if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
TRACE("Color keying not supported by frame buffer to texture blit\n");
/* Destination color key is checked above */
}
- /* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
- * glCopyTexSubImage is a bit picky about the parameters we pass to it
- */
- if(SrcRect) {
- if(SrcRect->top < SrcRect->bottom) {
- srect.y1 = SrcRect->top;
- srect.y2 = SrcRect->bottom;
- upsideDown = FALSE;
- } else {
- srect.y1 = SrcRect->bottom;
- srect.y2 = SrcRect->top;
- upsideDown = TRUE;
- }
- srect.x1 = SrcRect->left;
- srect.x2 = SrcRect->right;
- } else {
- srect.x1 = 0;
- srect.y1 = 0;
- srect.x2 = Src->currentDesc.Width;
- srect.y2 = Src->currentDesc.Height;
- upsideDown = FALSE;
- }
- if(rect.x1 > rect.x2) {
- UINT tmp = rect.x2;
- rect.x2 = rect.x1;
- rect.x1 = tmp;
- upsideDown = !upsideDown;
- }
-
- if(rect.x2 - rect.x1 != srect.x2 - srect.x1) {
+ if(dst_rect.right - dst_rect.left != src_rect.right - src_rect.left) {
stretchx = TRUE;
} else {
stretchx = FALSE;
}
- /* When blitting from a render target a texture, the texture isn't required to have a palette.
- * In this case grab the palette from the render target. */
- if (This->resource.format_desc->format == WINED3DFMT_P8_UINT && !This->palette)
- {
- paletteOverride = TRUE;
- TRACE("Source surface (%p) lacks palette, overriding palette with palette %p of destination surface (%p)\n", Src, This->palette, This);
- This->palette = Src->palette;
- }
-
/* Blt is a pretty powerful call, while glCopyTexSubImage2D is not. glCopyTexSubImage cannot
* flip the image nor scale it.
*
* FBO support, so it doesn't really make sense to try and make it work with different offscreen rendering
* backends.
*/
- if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
- && myDevice->adapter->gl_info.fbo_ops.glBlitFramebuffer
- && surface_can_stretch_rect(Src, This))
+ if (fbo_blit_supported(&device->adapter->gl_info, BLIT_OP_BLIT,
+ &src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format_desc,
+ &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format_desc))
+ {
+ stretch_rect_fbo(device, src_surface, &src_rect, dst_surface, &dst_rect, Filter);
+ }
+ else if (!stretchx || dst_rect.right - dst_rect.left > src_surface->currentDesc.Width
+ || dst_rect.bottom - dst_rect.top > src_surface->currentDesc.Height)
{
- stretch_rect_fbo((IWineD3DDevice *)myDevice, SrcSurface, &srect,
- (IWineD3DSurface *)This, &rect, Filter, upsideDown);
- } else if((!stretchx) || rect.x2 - rect.x1 > Src->currentDesc.Width ||
- rect.y2 - rect.y1 > Src->currentDesc.Height) {
TRACE("No stretching in x direction, using direct framebuffer -> texture copy\n");
- fb_copy_to_texture_direct(This, SrcSurface, &srect, &rect, upsideDown, Filter);
+ fb_copy_to_texture_direct(dst_surface, src_surface, &src_rect, &dst_rect, Filter);
} else {
TRACE("Using hardware stretching to flip / stretch the texture\n");
- fb_copy_to_texture_hwstretch(This, SrcSurface, srcSwapchain, &srect, &rect, upsideDown, Filter);
+ fb_copy_to_texture_hwstretch(dst_surface, src_surface, &src_rect, &dst_rect, Filter);
}
- /* Clear the palette as the surface didn't have a palette attached, it would confuse GetPalette and other calls */
- if(paletteOverride)
- This->palette = NULL;
-
- if(!(This->Flags & SFLAG_DONOTFREE)) {
- HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
- This->resource.allocatedMemory = NULL;
- This->resource.heapMemory = NULL;
- } else {
- This->Flags &= ~SFLAG_INSYSMEM;
+ if (!(dst_surface->Flags & SFLAG_DONOTFREE))
+ {
+ HeapFree(GetProcessHeap(), 0, dst_surface->resource.heapMemory);
+ dst_surface->resource.allocatedMemory = NULL;
+ dst_surface->resource.heapMemory = NULL;
+ }
+ else
+ {
+ dst_surface->Flags &= ~SFLAG_INSYSMEM;
}
return WINED3D_OK;
- } else if(Src) {
+ }
+ else if (src_surface)
+ {
/* Blit from offscreen surface to render target */
- float glTexCoord[4];
- DWORD oldCKeyFlags = Src->CKeyFlags;
- WINEDDCOLORKEY oldBltCKey = Src->SrcBltCKey;
+ DWORD oldCKeyFlags = src_surface->CKeyFlags;
+ WINEDDCOLORKEY oldBltCKey = src_surface->SrcBltCKey;
struct wined3d_context *context;
- RECT SourceRectangle;
- BOOL paletteOverride = FALSE;
- TRACE("Blt from surface %p to rendertarget %p\n", Src, This);
+ TRACE("Blt from surface %p to rendertarget %p\n", src_surface, dst_surface);
- if(SrcRect) {
- SourceRectangle.left = SrcRect->left;
- SourceRectangle.right = SrcRect->right;
- SourceRectangle.top = SrcRect->top;
- SourceRectangle.bottom = SrcRect->bottom;
- } else {
- SourceRectangle.left = 0;
- SourceRectangle.right = Src->currentDesc.Width;
- SourceRectangle.top = 0;
- SourceRectangle.bottom = Src->currentDesc.Height;
- }
-
- /* When blitting from an offscreen surface to a rendertarget, the source
- * surface is not required to have a palette. Our rendering / conversion
- * code further down the road retrieves the palette from the surface, so
- * it must have a palette set. */
- if (Src->resource.format_desc->format == WINED3DFMT_P8_UINT && !Src->palette)
- {
- paletteOverride = TRUE;
- TRACE("Source surface (%p) lacks palette, overriding palette with palette %p of destination surface (%p)\n", Src, This->palette, This);
- Src->palette = This->palette;
- }
-
- if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
- && myDevice->adapter->gl_info.fbo_ops.glBlitFramebuffer
- && !(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE))
- && surface_can_stretch_rect(Src, This))
+ if (!(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE))
+ && fbo_blit_supported(&device->adapter->gl_info, BLIT_OP_BLIT,
+ &src_rect, src_surface->resource.usage, src_surface->resource.pool,
+ src_surface->resource.format_desc,
+ &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool,
+ dst_surface->resource.format_desc))
{
TRACE("Using stretch_rect_fbo\n");
/* The source is always a texture, but never the currently active render target, and the texture
- * contents are never upside down
- */
- stretch_rect_fbo((IWineD3DDevice *)myDevice, SrcSurface, (WINED3DRECT *) &SourceRectangle,
- (IWineD3DSurface *)This, &rect, Filter, FALSE);
-
- /* Clear the palette as the surface didn't have a palette attached, it would confuse GetPalette and other calls */
- if(paletteOverride)
- Src->palette = NULL;
+ * contents are never upside down. */
+ stretch_rect_fbo(device, src_surface, &src_rect, dst_surface, &dst_rect, Filter);
return WINED3D_OK;
}
- if(!CalculateTexRect(Src, &SourceRectangle, glTexCoord)) {
- /* Fall back to software */
- WARN("(%p) Source texture area (%d,%d)-(%d,%d) is too big\n", Src,
- SourceRectangle.left, SourceRectangle.top,
- SourceRectangle.right, SourceRectangle.bottom);
- return WINED3DERR_INVALIDCALL;
+ if (!(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE))
+ && arbfp_blit.blit_supported(&device->adapter->gl_info, BLIT_OP_BLIT,
+ &src_rect, src_surface->resource.usage, src_surface->resource.pool,
+ src_surface->resource.format_desc,
+ &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool,
+ dst_surface->resource.format_desc))
+ {
+ return arbfp_blit_surface(device, src_surface, &src_rect, dst_surface, &dst_rect, BLIT_OP_BLIT, Filter);
}
/* Color keying: Check if we have to do a color keyed blt,
/* Use color key from surface */
} else if(Flags & WINEDDBLT_KEYSRCOVERRIDE) {
/* Use color key from DDBltFx */
- Src->CKeyFlags |= WINEDDSD_CKSRCBLT;
- Src->SrcBltCKey = DDBltFx->ddckSrcColorkey;
+ src_surface->CKeyFlags |= WINEDDSD_CKSRCBLT;
+ src_surface->SrcBltCKey = DDBltFx->ddckSrcColorkey;
} else {
/* Do not use color key */
- Src->CKeyFlags &= ~WINEDDSD_CKSRCBLT;
+ src_surface->CKeyFlags &= ~WINEDDSD_CKSRCBLT;
}
/* Now load the surface */
- surface_internal_preload((IWineD3DSurface *) Src, SRGB_RGB);
+ surface_internal_preload(src_surface, SRGB_RGB);
/* Activate the destination context, set it up for blitting */
- context = context_acquire(myDevice, (IWineD3DSurface *)This, CTXUSAGE_BLIT);
+ context = context_acquire(device, dst_surface);
+ context_apply_blit_state(context, device);
- /* The coordinates of the ddraw front buffer are always fullscreen ('screen coordinates',
- * while OpenGL coordinates are window relative.
- * Also beware of the origin difference(top left vs bottom left).
- * Also beware that the front buffer's surface size is screen width x screen height,
- * whereas the real gl drawable size is the size of the window.
- */
- if (dstSwapchain && (IWineD3DSurface *)This == dstSwapchain->frontBuffer) {
- RECT windowsize;
- POINT offset = {0,0};
- UINT h;
- ClientToScreen(dstSwapchain->win_handle, &offset);
- GetClientRect(dstSwapchain->win_handle, &windowsize);
- h = windowsize.bottom - windowsize.top;
- rect.x1 -= offset.x; rect.x2 -=offset.x;
- rect.y1 -= offset.y; rect.y2 -=offset.y;
- rect.y1 += This->currentDesc.Height - h; rect.y2 += This->currentDesc.Height - h;
- }
-
- if (!is_identity_fixup(This->resource.format_desc->color_fixup))
- {
- FIXME("Destination format %s has a fixup, this is not supported.\n",
- debug_d3dformat(This->resource.format_desc->format));
- dump_color_fixup_desc(This->resource.format_desc->color_fixup);
- }
+ if (dstSwapchain && dst_surface == dstSwapchain->front_buffer)
+ surface_translate_frontbuffer_coords(dst_surface, context->win_handle, &dst_rect);
- if (!myDevice->blitter->color_fixup_supported(Src->resource.format_desc->color_fixup))
+ if (!device->blitter->blit_supported(&device->adapter->gl_info, BLIT_OP_BLIT,
+ &src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format_desc,
+ &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool, dst_surface->resource.format_desc))
{
- FIXME("Source format %s has an unsupported fixup:\n",
- debug_d3dformat(Src->resource.format_desc->format));
- dump_color_fixup_desc(Src->resource.format_desc->color_fixup);
+ FIXME("Unsupported blit operation falling back to software\n");
+ return WINED3DERR_INVALIDCALL;
}
- myDevice->blitter->set_shader((IWineD3DDevice *) myDevice, Src->resource.format_desc,
- Src->texture_target, Src->pow2Width, Src->pow2Height);
+ device->blitter->set_shader((IWineD3DDevice *)device, src_surface);
ENTER_GL();
- /* Bind the texture */
- glBindTexture(Src->texture_target, Src->texture_name);
- checkGLcall("glBindTexture");
-
- /* Filtering for StretchRect */
- glTexParameteri(Src->texture_target, GL_TEXTURE_MAG_FILTER,
- wined3d_gl_mag_filter(magLookup, Filter));
- checkGLcall("glTexParameteri");
- glTexParameteri(Src->texture_target, GL_TEXTURE_MIN_FILTER,
- wined3d_gl_min_mip_filter(minMipLookup, Filter, WINED3DTEXF_NONE));
- checkGLcall("glTexParameteri");
- glTexParameteri(Src->texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(Src->texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- checkGLcall("glTexEnvi");
-
/* This is for color keying */
if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
glEnable(GL_ALPHA_TEST);
/* When the primary render target uses P8, the alpha component contains the palette index.
* Which means that the colorkey is one of the palette entries. In other cases pixels that
* should be masked away have alpha set to 0. */
- if(primary_render_target_is_p8(myDevice))
- glAlphaFunc(GL_NOTEQUAL, (float)Src->SrcBltCKey.dwColorSpaceLowValue / 256.0f);
+ if (primary_render_target_is_p8(device))
+ glAlphaFunc(GL_NOTEQUAL, (float)src_surface->SrcBltCKey.dwColorSpaceLowValue / 256.0f);
else
glAlphaFunc(GL_NOTEQUAL, 0.0f);
checkGLcall("glAlphaFunc");
/* Draw a textured quad
*/
- glBegin(GL_QUADS);
-
- glColor3f(1.0f, 1.0f, 1.0f);
- glTexCoord2f(glTexCoord[0], glTexCoord[2]);
- glVertex3f(rect.x1, rect.y1, 0.0f);
-
- glTexCoord2f(glTexCoord[0], glTexCoord[3]);
- glVertex3f(rect.x1, rect.y2, 0.0f);
-
- glTexCoord2f(glTexCoord[1], glTexCoord[3]);
- glVertex3f(rect.x2, rect.y2, 0.0f);
-
- glTexCoord2f(glTexCoord[1], glTexCoord[2]);
- glVertex3f(rect.x2, rect.y1, 0.0f);
-
- glEnd();
- checkGLcall("glEnd");
+ draw_textured_quad(src_surface, &src_rect, &dst_rect, Filter);
if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
glDisable(GL_ALPHA_TEST);
checkGLcall("glDisable(GL_ALPHA_TEST)");
}
- glBindTexture(Src->texture_target, 0);
- checkGLcall("glBindTexture(Src->texture_target, 0)");
-
/* Restore the color key parameters */
- Src->CKeyFlags = oldCKeyFlags;
- Src->SrcBltCKey = oldBltCKey;
-
- /* Clear the palette as the surface didn't have a palette attached, it would confuse GetPalette and other calls */
- if(paletteOverride)
- Src->palette = NULL;
+ src_surface->CKeyFlags = oldCKeyFlags;
+ src_surface->SrcBltCKey = oldBltCKey;
LEAVE_GL();
/* Leave the opengl state valid for blitting */
- myDevice->blitter->unset_shader((IWineD3DDevice *) myDevice);
+ device->blitter->unset_shader((IWineD3DDevice *)device);
- wglFlush(); /* Flush to ensure ordering across contexts. */
+ if (wined3d_settings.strict_draw_ordering || (dstSwapchain
+ && (dst_surface == dstSwapchain->front_buffer
+ || dstSwapchain->num_contexts > 1)))
+ wglFlush(); /* Flush to ensure ordering across contexts. */
context_release(context);
/* The surface is now in the drawable. On onscreen surfaces or without fbos the texture
* is outdated now
*/
- IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INDRAWABLE, TRUE);
+ IWineD3DSurface_ModifyLocation((IWineD3DSurface *)dst_surface, SFLAG_INDRAWABLE, TRUE);
return WINED3D_OK;
} else {
/* Source-Less Blit to render target */
if (Flags & WINEDDBLT_COLORFILL) {
- /* This is easy to handle for the D3D Device... */
DWORD color;
TRACE("Colorfill\n");
- /* This == (IWineD3DSurfaceImpl *) myDevice->render_targets[0] || dstSwapchain
- must be true if we are here */
- if (This != (IWineD3DSurfaceImpl *) myDevice->render_targets[0] &&
- !(This == (IWineD3DSurfaceImpl*) dstSwapchain->frontBuffer ||
- (dstSwapchain->backBuffer && This == (IWineD3DSurfaceImpl*) dstSwapchain->backBuffer[0]))) {
- TRACE("Surface is higher back buffer, falling back to software\n");
- return WINED3DERR_INVALIDCALL;
- }
-
/* The color as given in the Blt function is in the format of the frame-buffer...
* 'clear' expect it in ARGB format => we need to do some conversion :-)
*/
- if (This->resource.format_desc->format == WINED3DFMT_P8_UINT)
- {
- DWORD alpha;
-
- if (primary_render_target_is_p8(myDevice)) alpha = DDBltFx->u5.dwFillColor << 24;
- else alpha = 0xFF000000;
-
- if (This->palette) {
- color = (alpha |
- (This->palette->palents[DDBltFx->u5.dwFillColor].peRed << 16) |
- (This->palette->palents[DDBltFx->u5.dwFillColor].peGreen << 8) |
- (This->palette->palents[DDBltFx->u5.dwFillColor].peBlue));
- } else {
- color = alpha;
- }
- }
- else if (This->resource.format_desc->format == WINED3DFMT_B5G6R5_UNORM)
+ if (!surface_convert_color_to_argb(dst_surface, DDBltFx->u5.dwFillColor, &color))
{
- if (DDBltFx->u5.dwFillColor == 0xFFFF) {
- color = 0xFFFFFFFF;
- } else {
- color = ((0xFF000000) |
- ((DDBltFx->u5.dwFillColor & 0xF800) << 8) |
- ((DDBltFx->u5.dwFillColor & 0x07E0) << 5) |
- ((DDBltFx->u5.dwFillColor & 0x001F) << 3));
- }
+ /* The color conversion function already prints an error, so need to do it here */
+ return WINED3DERR_INVALIDCALL;
}
- else if (This->resource.format_desc->format == WINED3DFMT_B8G8R8_UNORM
- || This->resource.format_desc->format == WINED3DFMT_B8G8R8X8_UNORM)
+
+ if (ffp_blit.blit_supported(&device->adapter->gl_info, BLIT_OP_COLOR_FILL,
+ NULL, 0, 0, NULL,
+ &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool,
+ dst_surface->resource.format_desc))
{
- color = 0xFF000000 | DDBltFx->u5.dwFillColor;
+ return ffp_blit.color_fill(device, dst_surface, &dst_rect, color);
}
- else if (This->resource.format_desc->format == WINED3DFMT_B8G8R8A8_UNORM)
+ else if (cpu_blit.blit_supported(&device->adapter->gl_info, BLIT_OP_COLOR_FILL,
+ NULL, 0, 0, NULL,
+ &dst_rect, dst_surface->resource.usage, dst_surface->resource.pool,
+ dst_surface->resource.format_desc))
{
- color = DDBltFx->u5.dwFillColor;
+ return cpu_blit.color_fill(device, dst_surface, &dst_rect, color);
}
- else {
- ERR("Wrong surface type for BLT override(Format doesn't match) !\n");
- return WINED3DERR_INVALIDCALL;
- }
-
- TRACE("(%p) executing Render Target override, color = %x\n", This, color);
- IWineD3DDeviceImpl_ClearSurface(myDevice, This, 1 /* Number of rectangles */,
- &rect, WINED3DCLEAR_TARGET, color, 0.0f /* Z */, 0 /* Stencil */);
- return WINED3D_OK;
+ return WINED3DERR_INVALIDCALL;
}
}
static HRESULT IWineD3DSurfaceImpl_BltZ(IWineD3DSurfaceImpl *This, const RECT *DestRect,
IWineD3DSurface *SrcSurface, const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx)
{
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = This->resource.device;
float depth;
if (Flags & WINEDDBLT_DEPTHFILL) {
ERR("Unexpected format for depth fill: %s\n", debug_d3dformat(This->resource.format_desc->format));
}
- return IWineD3DDevice_Clear((IWineD3DDevice *) myDevice,
- DestRect == NULL ? 0 : 1,
- (const WINED3DRECT *)DestRect,
- WINED3DCLEAR_ZBUFFER,
- 0x00000000,
- depth,
- 0x00000000);
+ return IWineD3DDevice_Clear((IWineD3DDevice *)device, DestRect ? 1 : 0, (const WINED3DRECT *)DestRect,
+ WINED3DCLEAR_ZBUFFER, 0x00000000, depth, 0x00000000);
}
FIXME("(%p): Unsupp depthstencil blit\n", This);
const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter) {
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = This->resource.device;
TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
TRACE("(%p): Usage is %s\n", This, debug_d3dusage(This->resource.usage));
/* Accessing the depth stencil is supposed to fail between a BeginScene and EndScene pair,
* except depth blits, which seem to work
*/
- if(iface == myDevice->stencilBufferTarget || (SrcSurface && SrcSurface == myDevice->stencilBufferTarget)) {
- if(myDevice->inScene && !(Flags & WINEDDBLT_DEPTHFILL)) {
+ if (This == device->depth_stencil || (Src && Src == device->depth_stencil))
+ {
+ if (device->inScene && !(Flags & WINEDDBLT_DEPTHFILL))
+ {
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
return WINED3DERR_INVALIDCALL;
} else if(IWineD3DSurfaceImpl_BltZ(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx) == WINED3D_OK) {
}
/* Special cases for RenderTargets */
- if( (This->resource.usage & WINED3DUSAGE_RENDERTARGET) ||
- ( Src && (Src->resource.usage & WINED3DUSAGE_RENDERTARGET) )) {
- if(IWineD3DSurfaceImpl_BltOverride(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter) == WINED3D_OK) return WINED3D_OK;
+ if ((This->resource.usage & WINED3DUSAGE_RENDERTARGET)
+ || (Src && (Src->resource.usage & WINED3DUSAGE_RENDERTARGET)))
+ {
+ if (SUCCEEDED(IWineD3DSurfaceImpl_BltOverride(This, DestRect, Src, SrcRect, Flags, DDBltFx, Filter)))
+ return WINED3D_OK;
}
/* For the rest call the X11 surface implementation.
{
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
IWineD3DSurfaceImpl *srcImpl = (IWineD3DSurfaceImpl *) Source;
- IWineD3DDeviceImpl *myDevice = This->resource.device;
+ IWineD3DDeviceImpl *device = This->resource.device;
TRACE("(%p)->(%d, %d, %p, %p, %08x\n", iface, dstx, dsty, Source, rsrc, trans);
return WINEDDERR_SURFACEBUSY;
}
- if(myDevice->inScene &&
- (iface == myDevice->stencilBufferTarget ||
- (Source == myDevice->stencilBufferTarget))) {
+ if (device->inScene && (This == device->depth_stencil || srcImpl == device->depth_stencil))
+ {
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
return WINED3DERR_INVALIDCALL;
}
RECT SrcRect, DstRect;
DWORD Flags=0;
- if(rsrc) {
- SrcRect.left = rsrc->left;
- SrcRect.top= rsrc->top;
- SrcRect.bottom = rsrc->bottom;
- SrcRect.right = rsrc->right;
- } else {
- SrcRect.left = 0;
- SrcRect.top = 0;
- SrcRect.right = srcImpl->currentDesc.Width;
- SrcRect.bottom = srcImpl->currentDesc.Height;
- }
+ surface_get_rect(srcImpl, rsrc, &SrcRect);
DstRect.left = dstx;
DstRect.top=dsty;
if(trans & WINEDDBLTFAST_DONOTWAIT)
Flags |= WINEDDBLT_DONOTWAIT;
- if(IWineD3DSurfaceImpl_BltOverride(This, &DstRect, Source, &SrcRect, Flags, NULL, WINED3DTEXF_POINT) == WINED3D_OK) return WINED3D_OK;
+ if (SUCCEEDED(IWineD3DSurfaceImpl_BltOverride(This,
+ &DstRect, srcImpl, &SrcRect, Flags, NULL, WINED3DTEXF_POINT)))
+ return WINED3D_OK;
}
if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
|| This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
{
- int bpp;
- GLenum format, internal, type;
- CONVERT_TYPES convert;
-
- /* Check if we are using a RTL mode which uses texturing for uploads */
- BOOL use_texture = (wined3d_settings.rendertargetlock_mode == RTL_READTEX);
-
- /* Check if we have hardware palette conversion if we have convert is set to NO_CONVERSION */
- d3dfmt_get_conv(This, TRUE, use_texture, &format, &internal, &type, &convert, &bpp, FALSE);
-
- if((This->resource.usage & WINED3DUSAGE_RENDERTARGET) && (convert == NO_CONVERSION))
+ if(This->resource.usage & WINED3DUSAGE_RENDERTARGET)
{
- IWineD3DDeviceImpl *device = This->resource.device;
- struct wined3d_context *context;
-
/* Make sure the texture is up to date. This call doesn't do anything if the texture is already up to date. */
IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL);
/* We want to force a palette refresh, so mark the drawable as not being up to date */
IWineD3DSurface_ModifyLocation(iface, SFLAG_INDRAWABLE, FALSE);
-
- /* Re-upload the palette */
- context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
- d3dfmt_p8_upload_palette(iface, convert);
- context_release(context);
} else {
if(!(This->Flags & SFLAG_INSYSMEM)) {
TRACE("Palette changed with surface that does not have an up to date system memory copy\n");
3: WARN and return WINED3DERR_NOTAVAILABLE;
4: Create the surface, but allow it to be used only for DirectDraw Blts. Some apps(e.g. Swat 3) create textures with a Height of 16 and a Width > 3000 and blt 16x16 letter areas from them to the render target.
*/
- WARN("(%p) Creating an oversized surface: %ux%u (texture is %ux%u)\n",
- This, This->pow2Width, This->pow2Height, This->currentDesc.Width, This->currentDesc.Height);
- This->Flags |= SFLAG_OVERSIZE;
-
- /* This will be initialized on the first blt */
- This->glRect.left = 0;
- This->glRect.top = 0;
- This->glRect.right = 0;
- This->glRect.bottom = 0;
- } else {
- /* Check this after the oversize check - do not make an oversized surface a texture_rectangle one.
- Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
+ if(This->resource.pool == WINED3DPOOL_DEFAULT || This->resource.pool == WINED3DPOOL_MANAGED)
+ {
+ WARN("(%p) Unable to allocate a surface which exceeds the maximum OpenGL texture size\n", This);
+ return WINED3DERR_NOTAVAILABLE;
+ }
+
+ /* We should never use this surface in combination with OpenGL! */
+ TRACE("(%p) Creating an oversized surface: %ux%u\n", This, This->pow2Width, This->pow2Height);
+ }
+ else
+ {
+ /* Don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
is used in combination with texture uploads (RTL_READTEX/RTL_TEXTEX). The reason is that EXT_PALETTED_TEXTURE
doesn't work in combination with ARB_TEXTURE_RECTANGLE.
*/
This->pow2Height = This->currentDesc.Height;
This->Flags &= ~(SFLAG_NONPOW2 | SFLAG_NORMCOORD);
}
-
- /* No oversize, gl rect is the full texture size */
- This->Flags &= ~SFLAG_OVERSIZE;
- This->glRect.left = 0;
- This->glRect.top = 0;
- This->glRect.right = This->pow2Width;
- This->glRect.bottom = This->pow2Height;
}
if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
switch(wined3d_settings.offscreen_rendering_mode) {
case ORM_FBO: This->get_drawable_size = get_drawable_size_fbo; break;
- case ORM_PBUFFER: This->get_drawable_size = get_drawable_size_pbuffer; break;
case ORM_BACKBUFFER: This->get_drawable_size = get_drawable_size_backbuffer; break;
}
}
return WINED3D_OK;
}
-struct depth_blt_info
-{
- GLenum binding;
- GLenum bind_target;
- enum tex_types tex_type;
- GLfloat coords[4][3];
-};
-
-static void surface_get_depth_blt_info(GLenum target, GLsizei w, GLsizei h, struct depth_blt_info *info)
-{
- GLfloat (*coords)[3] = info->coords;
-
- switch (target)
- {
- default:
- FIXME("Unsupported texture target %#x\n", target);
- /* Fall back to GL_TEXTURE_2D */
- case GL_TEXTURE_2D:
- info->binding = GL_TEXTURE_BINDING_2D;
- info->bind_target = GL_TEXTURE_2D;
- info->tex_type = tex_2d;
- coords[0][0] = 0.0f; coords[0][1] = 1.0f; coords[0][2] = 0.0f;
- coords[1][0] = 1.0f; coords[1][1] = 1.0f; coords[1][2] = 0.0f;
- coords[2][0] = 0.0f; coords[2][1] = 0.0f; coords[2][2] = 0.0f;
- coords[3][0] = 1.0f; coords[3][1] = 0.0f; coords[3][2] = 0.0f;
- break;
-
- case GL_TEXTURE_RECTANGLE_ARB:
- info->binding = GL_TEXTURE_BINDING_RECTANGLE_ARB;
- info->bind_target = GL_TEXTURE_RECTANGLE_ARB;
- info->tex_type = tex_rect;
- coords[0][0] = 0.0f; coords[0][1] = h; coords[0][2] = 0.0f;
- coords[1][0] = w; coords[1][1] = h; coords[1][2] = 0.0f;
- coords[2][0] = 0.0f; coords[2][1] = 0.0f; coords[2][2] = 0.0f;
- coords[3][0] = w; coords[3][1] = 0.0f; coords[3][2] = 0.0f;
- break;
-
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
- info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- info->tex_type = tex_cube;
- coords[0][0] = 1.0f; coords[0][1] = -1.0f; coords[0][2] = 1.0f;
- coords[1][0] = 1.0f; coords[1][1] = -1.0f; coords[1][2] = -1.0f;
- coords[2][0] = 1.0f; coords[2][1] = 1.0f; coords[2][2] = 1.0f;
- coords[3][0] = 1.0f; coords[3][1] = 1.0f; coords[3][2] = -1.0f;
-
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
- info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- info->tex_type = tex_cube;
- coords[0][0] = -1.0f; coords[0][1] = -1.0f; coords[0][2] = -1.0f;
- coords[1][0] = -1.0f; coords[1][1] = -1.0f; coords[1][2] = 1.0f;
- coords[2][0] = -1.0f; coords[2][1] = 1.0f; coords[2][2] = -1.0f;
- coords[3][0] = -1.0f; coords[3][1] = 1.0f; coords[3][2] = 1.0f;
-
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
- info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- info->tex_type = tex_cube;
- coords[0][0] = -1.0f; coords[0][1] = 1.0f; coords[0][2] = 1.0f;
- coords[1][0] = 1.0f; coords[1][1] = 1.0f; coords[1][2] = 1.0f;
- coords[2][0] = -1.0f; coords[2][1] = 1.0f; coords[2][2] = -1.0f;
- coords[3][0] = 1.0f; coords[3][1] = 1.0f; coords[3][2] = -1.0f;
-
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
- info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- info->tex_type = tex_cube;
- coords[0][0] = -1.0f; coords[0][1] = -1.0f; coords[0][2] = -1.0f;
- coords[1][0] = 1.0f; coords[1][1] = -1.0f; coords[1][2] = -1.0f;
- coords[2][0] = -1.0f; coords[2][1] = -1.0f; coords[2][2] = 1.0f;
- coords[3][0] = 1.0f; coords[3][1] = -1.0f; coords[3][2] = 1.0f;
-
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
- info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- info->tex_type = tex_cube;
- coords[0][0] = -1.0f; coords[0][1] = -1.0f; coords[0][2] = 1.0f;
- coords[1][0] = 1.0f; coords[1][1] = -1.0f; coords[1][2] = 1.0f;
- coords[2][0] = -1.0f; coords[2][1] = 1.0f; coords[2][2] = 1.0f;
- coords[3][0] = 1.0f; coords[3][1] = 1.0f; coords[3][2] = 1.0f;
-
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
- info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- info->tex_type = tex_cube;
- coords[0][0] = 1.0f; coords[0][1] = -1.0f; coords[0][2] = -1.0f;
- coords[1][0] = -1.0f; coords[1][1] = -1.0f; coords[1][2] = -1.0f;
- coords[2][0] = 1.0f; coords[2][1] = 1.0f; coords[2][2] = -1.0f;
- coords[3][0] = -1.0f; coords[3][1] = 1.0f; coords[3][2] = -1.0f;
- }
-}
-
/* GL locking is done by the caller */
-static void surface_depth_blt(IWineD3DSurfaceImpl *This, GLuint texture, GLsizei w, GLsizei h, GLenum target)
+static void surface_depth_blt(IWineD3DSurfaceImpl *This, const struct wined3d_gl_info *gl_info,
+ GLuint texture, GLsizei w, GLsizei h, GLenum target)
{
IWineD3DDeviceImpl *device = This->resource.device;
- struct depth_blt_info info;
+ GLint compare_mode = GL_NONE;
+ struct blt_info info;
GLint old_binding = 0;
glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glViewport(0, 0, w, h);
- surface_get_depth_blt_info(target, w, h, &info);
+ surface_get_blt_info(target, NULL, w, h, &info);
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
glGetIntegerv(info.binding, &old_binding);
glBindTexture(info.bind_target, texture);
+ if (gl_info->supported[ARB_SHADOW])
+ {
+ glGetTexParameteriv(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, &compare_mode);
+ if (compare_mode != GL_NONE) glTexParameteri(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
+ }
- device->shader_backend->shader_select_depth_blt((IWineD3DDevice *)device, info.tex_type);
+ device->shader_backend->shader_select_depth_blt((IWineD3DDevice *)device,
+ info.tex_type, &This->ds_current_size);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord3fv(info.coords[0]);
glVertex2f(1.0f, 1.0f);
glEnd();
+ if (compare_mode != GL_NONE) glTexParameteri(info.bind_target, GL_TEXTURE_COMPARE_MODE_ARB, compare_mode);
glBindTexture(info.bind_target, old_binding);
glPopAttrib();
device->shader_backend->shader_deselect_depth_blt((IWineD3DDevice *)device);
}
-void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location) {
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-
- TRACE("(%p) New location %#x\n", This, location);
+void surface_modify_ds_location(IWineD3DSurfaceImpl *surface,
+ DWORD location, UINT w, UINT h)
+{
+ TRACE("surface %p, new location %#x, w %u, h %u.\n", surface, location, w, h);
- if (location & ~SFLAG_DS_LOCATIONS) {
- FIXME("(%p) Invalid location (%#x) specified\n", This, location);
- }
+ if (location & ~SFLAG_DS_LOCATIONS)
+ FIXME("Invalid location (%#x) specified.\n", location);
- This->Flags &= ~SFLAG_DS_LOCATIONS;
- This->Flags |= location;
+ surface->ds_current_size.cx = w;
+ surface->ds_current_size.cy = h;
+ surface->Flags &= ~SFLAG_DS_LOCATIONS;
+ surface->Flags |= location;
}
/* Context activation is done by the caller. */
-void surface_load_ds_location(IWineD3DSurface *iface, struct wined3d_context *context, DWORD location)
+void surface_load_ds_location(IWineD3DSurfaceImpl *surface, struct wined3d_context *context, DWORD location)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
- IWineD3DDeviceImpl *device = This->resource.device;
+ IWineD3DDeviceImpl *device = surface->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
- TRACE("(%p) New location %#x\n", This, location);
+ TRACE("surface %p, new location %#x.\n", surface, location);
/* TODO: Make this work for modes other than FBO */
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return;
- if (This->Flags & location) {
- TRACE("(%p) Location (%#x) is already up to date\n", This, location);
- return;
+ if (!(surface->Flags & location))
+ {
+ surface->ds_current_size.cx = 0;
+ surface->ds_current_size.cy = 0;
}
- if (This->current_renderbuffer) {
- FIXME("(%p) Not supported with fixed up depth stencil\n", This);
+ if (surface->ds_current_size.cx == surface->currentDesc.Width
+ && surface->ds_current_size.cy == surface->currentDesc.Height)
+ {
+ TRACE("Location (%#x) is already up to date.\n", location);
return;
}
- if (location == SFLAG_DS_OFFSCREEN) {
- if (This->Flags & SFLAG_DS_ONSCREEN) {
- GLint old_binding = 0;
- GLenum bind_target;
-
- TRACE("(%p) Copying onscreen depth buffer to depth texture\n", This);
-
- ENTER_GL();
-
- if (!device->depth_blt_texture) {
- glGenTextures(1, &device->depth_blt_texture);
- }
+ if (surface->current_renderbuffer)
+ {
+ FIXME("Not supported with fixed up depth stencil.\n");
+ return;
+ }
- /* Note that we use depth_blt here as well, rather than glCopyTexImage2D
- * directly on the FBO texture. That's because we need to flip. */
- context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
- if (This->texture_target == GL_TEXTURE_RECTANGLE_ARB)
- {
- glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
- bind_target = GL_TEXTURE_RECTANGLE_ARB;
- } else {
- glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
- bind_target = GL_TEXTURE_2D;
- }
- glBindTexture(bind_target, device->depth_blt_texture);
- glCopyTexImage2D(bind_target, This->texture_level, This->resource.format_desc->glInternal,
- 0, 0, This->currentDesc.Width, This->currentDesc.Height, 0);
- glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(bind_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
- glTexParameteri(bind_target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
- glBindTexture(bind_target, old_binding);
-
- /* Setup the destination */
- if (!device->depth_blt_rb) {
- gl_info->fbo_ops.glGenRenderbuffers(1, &device->depth_blt_rb);
- checkGLcall("glGenRenderbuffersEXT");
- }
- if (device->depth_blt_rb_w != This->currentDesc.Width
- || device->depth_blt_rb_h != This->currentDesc.Height) {
- gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, device->depth_blt_rb);
- checkGLcall("glBindRenderbufferEXT");
- gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8,
- This->currentDesc.Width, This->currentDesc.Height);
- checkGLcall("glRenderbufferStorageEXT");
- device->depth_blt_rb_w = This->currentDesc.Width;
- device->depth_blt_rb_h = This->currentDesc.Height;
- }
+ if (!(surface->Flags & SFLAG_LOCATIONS))
+ {
+ FIXME("No up to date depth stencil location.\n");
+ surface->Flags |= location;
+ return;
+ }
- context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo);
- gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER,
- GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, device->depth_blt_rb);
- checkGLcall("glFramebufferRenderbufferEXT");
- context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, iface, FALSE);
+ if (location == SFLAG_DS_OFFSCREEN)
+ {
+ GLint old_binding = 0;
+ GLenum bind_target;
- /* Do the actual blit */
- surface_depth_blt(This, device->depth_blt_texture, This->currentDesc.Width, This->currentDesc.Height, bind_target);
- checkGLcall("depth_blt");
+ TRACE("Copying onscreen depth buffer to depth texture.\n");
- if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id);
- else context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
+ ENTER_GL();
- LEAVE_GL();
+ if (!device->depth_blt_texture)
+ {
+ glGenTextures(1, &device->depth_blt_texture);
+ }
- wglFlush(); /* Flush to ensure ordering across contexts. */
+ /* Note that we use depth_blt here as well, rather than glCopyTexImage2D
+ * directly on the FBO texture. That's because we need to flip. */
+ context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
+ if (surface->texture_target == GL_TEXTURE_RECTANGLE_ARB)
+ {
+ glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
+ bind_target = GL_TEXTURE_RECTANGLE_ARB;
}
else
{
- FIXME("No up to date depth stencil location\n");
+ glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
+ bind_target = GL_TEXTURE_2D;
+ }
+ glBindTexture(bind_target, device->depth_blt_texture);
+ glCopyTexImage2D(bind_target, surface->texture_level, surface->resource.format_desc->glInternal,
+ 0, 0, surface->currentDesc.Width, surface->currentDesc.Height, 0);
+ glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(bind_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+ glTexParameteri(bind_target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
+ glBindTexture(bind_target, old_binding);
+
+ /* Setup the destination */
+ if (!device->depth_blt_rb)
+ {
+ gl_info->fbo_ops.glGenRenderbuffers(1, &device->depth_blt_rb);
+ checkGLcall("glGenRenderbuffersEXT");
+ }
+ if (device->depth_blt_rb_w != surface->currentDesc.Width
+ || device->depth_blt_rb_h != surface->currentDesc.Height)
+ {
+ gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, device->depth_blt_rb);
+ checkGLcall("glBindRenderbufferEXT");
+ gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8,
+ surface->currentDesc.Width, surface->currentDesc.Height);
+ checkGLcall("glRenderbufferStorageEXT");
+ device->depth_blt_rb_w = surface->currentDesc.Width;
+ device->depth_blt_rb_h = surface->currentDesc.Height;
}
- } else if (location == SFLAG_DS_ONSCREEN) {
- if (This->Flags & SFLAG_DS_OFFSCREEN) {
- TRACE("(%p) Copying depth texture to onscreen depth buffer\n", This);
- ENTER_GL();
+ context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo);
+ gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, device->depth_blt_rb);
+ checkGLcall("glFramebufferRenderbufferEXT");
+ context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, surface, FALSE);
- context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
- surface_depth_blt(This, This->texture_name, This->currentDesc.Width,
- This->currentDesc.Height, This->texture_target);
- checkGLcall("depth_blt");
+ /* Do the actual blit */
+ surface_depth_blt(surface, gl_info, device->depth_blt_texture,
+ surface->currentDesc.Width, surface->currentDesc.Height, bind_target);
+ checkGLcall("depth_blt");
- if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id);
+ if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id);
+ else context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
- LEAVE_GL();
+ LEAVE_GL();
- wglFlush(); /* Flush to ensure ordering across contexts. */
- }
- else
- {
- FIXME("No up to date depth stencil location\n");
- }
- } else {
- ERR("(%p) Invalid location (%#x) specified\n", This, location);
+ if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
}
+ else if (location == SFLAG_DS_ONSCREEN)
+ {
+ TRACE("Copying depth texture to onscreen depth buffer.\n");
+
+ ENTER_GL();
+
+ context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
+ surface_depth_blt(surface, gl_info, surface->texture_name,
+ surface->currentDesc.Width, surface->currentDesc.Height, surface->texture_target);
+ checkGLcall("depth_blt");
+
+ if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id);
+
+ LEAVE_GL();
- This->Flags |= location;
+ if (wined3d_settings.strict_draw_ordering) wglFlush(); /* Flush to ensure ordering across contexts. */
+ }
+ else
+ {
+ ERR("Invalid location (%#x) specified.\n", location);
+ }
+
+ surface->Flags |= location;
+ surface->ds_current_size.cx = surface->currentDesc.Width;
+ surface->ds_current_size.cy = surface->currentDesc.Height;
}
static void WINAPI IWineD3DSurfaceImpl_ModifyLocation(IWineD3DSurface *iface, DWORD flag, BOOL persistent) {
TRACE("(%p)->(%s, %s)\n", iface, debug_surflocation(flag),
persistent ? "TRUE" : "FALSE");
- if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
- if (surface_is_offscreen(iface))
+ if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+ {
+ if (surface_is_offscreen(This))
{
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
if (flag & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE)) flag |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
}
}
-struct coords {
- GLfloat x, y, z;
-};
-
-struct float_rect
-{
- float l;
- float t;
- float r;
- float b;
-};
-
-static inline void cube_coords_float(const RECT *r, UINT w, UINT h, struct float_rect *f)
-{
- f->l = ((r->left * 2.0f) / w) - 1.0f;
- f->t = ((r->top * 2.0f) / h) - 1.0f;
- f->r = ((r->right * 2.0f) / w) - 1.0f;
- f->b = ((r->bottom * 2.0f) / h) - 1.0f;
-}
-
static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT *rect_in)
{
IWineD3DDeviceImpl *device = This->resource.device;
- IWineD3DBaseTextureImpl *texture;
+ IWineD3DSwapChainImpl *swapchain;
struct wined3d_context *context;
- struct coords coords[4];
- RECT rect;
- GLenum bind_target;
- struct float_rect f;
+ RECT src_rect, dst_rect;
- if(rect_in) {
- rect = *rect_in;
- } else {
- rect.left = 0;
- rect.top = 0;
- rect.right = This->currentDesc.Width;
- rect.bottom = This->currentDesc.Height;
- }
+ surface_get_rect(This, rect_in, &src_rect);
- switch (This->texture_target)
+ context = context_acquire(device, This);
+ context_apply_blit_state(context, device);
+ if (context->render_offscreen)
{
- case GL_TEXTURE_2D:
- bind_target = GL_TEXTURE_2D;
-
- coords[0].x = (float)rect.left / This->pow2Width;
- coords[0].y = (float)rect.top / This->pow2Height;
- coords[0].z = 0;
-
- coords[1].x = (float)rect.left / This->pow2Width;
- coords[1].y = (float)rect.bottom / This->pow2Height;
- coords[1].z = 0;
-
- coords[2].x = (float)rect.right / This->pow2Width;
- coords[2].y = (float)rect.bottom / This->pow2Height;
- coords[2].z = 0;
-
- coords[3].x = (float)rect.right / This->pow2Width;
- coords[3].y = (float)rect.top / This->pow2Height;
- coords[3].z = 0;
- break;
-
- case GL_TEXTURE_RECTANGLE_ARB:
- bind_target = GL_TEXTURE_RECTANGLE_ARB;
- coords[0].x = rect.left; coords[0].y = rect.top; coords[0].z = 0;
- coords[1].x = rect.left; coords[1].y = rect.bottom; coords[1].z = 0;
- coords[2].x = rect.right; coords[2].y = rect.bottom; coords[2].z = 0;
- coords[3].x = rect.right; coords[3].y = rect.top; coords[3].z = 0;
- break;
-
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
- coords[0].x = 1; coords[0].y = -f.t; coords[0].z = -f.l;
- coords[1].x = 1; coords[1].y = -f.b; coords[1].z = -f.l;
- coords[2].x = 1; coords[2].y = -f.b; coords[2].z = -f.r;
- coords[3].x = 1; coords[3].y = -f.t; coords[3].z = -f.r;
- break;
-
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
- coords[0].x = -1; coords[0].y = -f.t; coords[0].z = f.l;
- coords[1].x = -1; coords[1].y = -f.b; coords[1].z = f.l;
- coords[2].x = -1; coords[2].y = -f.b; coords[2].z = f.r;
- coords[3].x = -1; coords[3].y = -f.t; coords[3].z = f.r;
- break;
-
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
- coords[0].x = f.l; coords[0].y = 1; coords[0].z = f.t;
- coords[1].x = f.l; coords[1].y = 1; coords[1].z = f.b;
- coords[2].x = f.r; coords[2].y = 1; coords[2].z = f.b;
- coords[3].x = f.r; coords[3].y = 1; coords[3].z = f.t;
- break;
-
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
- coords[0].x = f.l; coords[0].y = -1; coords[0].z = -f.t;
- coords[1].x = f.l; coords[1].y = -1; coords[1].z = -f.b;
- coords[2].x = f.r; coords[2].y = -1; coords[2].z = -f.b;
- coords[3].x = f.r; coords[3].y = -1; coords[3].z = -f.t;
- break;
-
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
- coords[0].x = f.l; coords[0].y = -f.t; coords[0].z = 1;
- coords[1].x = f.l; coords[1].y = -f.b; coords[1].z = 1;
- coords[2].x = f.r; coords[2].y = -f.b; coords[2].z = 1;
- coords[3].x = f.r; coords[3].y = -f.t; coords[3].z = 1;
- break;
-
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- bind_target = GL_TEXTURE_CUBE_MAP_ARB;
- cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
- coords[0].x = -f.l; coords[0].y = -f.t; coords[0].z = -1;
- coords[1].x = -f.l; coords[1].y = -f.b; coords[1].z = -1;
- coords[2].x = -f.r; coords[2].y = -f.b; coords[2].z = -1;
- coords[3].x = -f.r; coords[3].y = -f.t; coords[3].z = -1;
- break;
-
- default:
- ERR("Unexpected texture target %#x\n", This->texture_target);
- return;
+ dst_rect.left = src_rect.left;
+ dst_rect.right = src_rect.right;
+ dst_rect.top = src_rect.bottom;
+ dst_rect.bottom = src_rect.top;
}
-
- context = context_acquire(device, (IWineD3DSurface*)This, CTXUSAGE_BLIT);
-
- ENTER_GL();
-
- glEnable(bind_target);
- checkGLcall("glEnable(bind_target)");
- glBindTexture(bind_target, This->texture_name);
- checkGLcall("glBindTexture(bind_target, This->texture_name)");
- glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- checkGLcall("glTexParameteri");
- glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- checkGLcall("glTexParameteri");
-
- if (context->render_offscreen)
+ else
{
- LONG tmp = rect.top;
- rect.top = rect.bottom;
- rect.bottom = tmp;
+ dst_rect = src_rect;
}
- glBegin(GL_QUADS);
- glTexCoord3fv(&coords[0].x);
- glVertex2i(rect.left, rect.top);
-
- glTexCoord3fv(&coords[1].x);
- glVertex2i(rect.left, rect.bottom);
-
- glTexCoord3fv(&coords[2].x);
- glVertex2i(rect.right, rect.bottom);
-
- glTexCoord3fv(&coords[3].x);
- glVertex2i(rect.right, rect.top);
- glEnd();
- checkGLcall("glEnd");
+ if ((This->Flags & SFLAG_SWAPCHAIN) && This == ((IWineD3DSwapChainImpl *)This->container)->front_buffer)
+ surface_translate_frontbuffer_coords(This, context->win_handle, &dst_rect);
- glDisable(bind_target);
- checkGLcall("glDisable(bind_target)");
+ device->blitter->set_shader((IWineD3DDevice *) device, This);
+ ENTER_GL();
+ draw_textured_quad(This, &src_rect, &dst_rect, WINED3DTEXF_POINT);
LEAVE_GL();
- wglFlush(); /* Flush to ensure ordering across contexts. */
+ device->blitter->set_shader((IWineD3DDevice *) device, This);
- /* We changed the filtering settings on the texture. Inform the
- * container about this to get the filters reset properly next draw. */
- if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)This, &IID_IWineD3DBaseTexture, (void **)&texture)))
- {
- texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
- texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
- texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
- IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)texture);
- }
+ swapchain = (This->Flags & SFLAG_SWAPCHAIN) ? (IWineD3DSwapChainImpl *)This->container : NULL;
+ if (wined3d_settings.strict_draw_ordering || (swapchain
+ && (This == swapchain->front_buffer || swapchain->num_contexts > 1)))
+ wglFlush(); /* Flush to ensure ordering across contexts. */
context_release(context);
}
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
IWineD3DDeviceImpl *device = This->resource.device;
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
- GLenum format, internal, type;
+ struct wined3d_format_desc desc;
CONVERT_TYPES convert;
- int bpp;
int width, pitch, outpitch;
BYTE *mem;
BOOL drawable_read_ok = TRUE;
BOOL in_fbo = FALSE;
- if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
- if (surface_is_offscreen(iface))
+ if (This->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)
+ {
+ if (flag == SFLAG_INTEXTURE)
+ {
+ struct wined3d_context *context = context_acquire(device, NULL);
+ surface_load_ds_location(This, context, SFLAG_DS_OFFSCREEN);
+ context_release(context);
+ return WINED3D_OK;
+ }
+ else
+ {
+ FIXME("Unimplemented location %#x for depth/stencil buffers.\n", flag);
+ return WINED3DERR_INVALIDCALL;
+ }
+ }
+
+ if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+ {
+ if (surface_is_offscreen(This))
{
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets.
* Prefer SFLAG_INTEXTURE. */
{
struct wined3d_context *context = NULL;
- if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+ if (!device->isInDraw) context = context_acquire(device, NULL);
surface_bind_and_dirtify(This, !(This->Flags & SFLAG_INTEXTURE));
- surface_download_data(This);
+ surface_download_data(This, gl_info);
if (context) context_release(context);
}
if(This->Flags & SFLAG_INTEXTURE) {
surface_blt_to_drawable(This, rect);
} else {
+ int byte_count;
if((This->Flags & SFLAG_LOCATIONS) == SFLAG_INSRGBTEX) {
/* This needs a shader to convert the srgb data sampled from the GL texture into RGB
* values, otherwise we get incorrect values in the target. For now go the slow way
IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INSYSMEM, rect);
}
- d3dfmt_get_conv(This, TRUE /* We need color keying */, FALSE /* We won't use textures */, &format, &internal, &type, &convert, &bpp, FALSE);
+ d3dfmt_get_conv(This, FALSE /* We need color keying */, FALSE /* We won't use textures */, &desc, &convert);
/* The width is in 'length' not in bytes */
width = This->currentDesc.Width;
TRACE("Removing the pbo attached to surface %p\n", This);
- if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
- surface_remove_pbo(This);
+ if (!device->isInDraw) context = context_acquire(device, NULL);
+ surface_remove_pbo(This, gl_info);
if (context) context_release(context);
}
if((convert != NO_CONVERSION) && This->resource.allocatedMemory) {
int height = This->currentDesc.Height;
+ byte_count = desc.conv_byte_count;
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
- outpitch = width * bpp;
+ outpitch = width * byte_count;
outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
} else {
This->Flags &= ~SFLAG_CONVERTED;
mem = This->resource.allocatedMemory;
+ byte_count = desc.byte_count;
}
- flush_to_framebuffer_drawpixels(This, format, type, bpp, mem);
+ flush_to_framebuffer_drawpixels(This, desc.glFormat, desc.glType, byte_count, mem);
/* Don't delete PBO memory */
if((mem != This->resource.allocatedMemory) && !(This->Flags & SFLAG_PBO))
struct wined3d_context *context = NULL;
d3dfmt_get_conv(This, TRUE /* We need color keying */, TRUE /* We will use textures */,
- &format, &internal, &type, &convert, &bpp, srgb);
+ &desc, &convert);
if(srgb) {
if((This->Flags & (SFLAG_INTEXTURE | SFLAG_INSYSMEM)) == SFLAG_INTEXTURE) {
IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INSYSMEM, rect);
}
- if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+ if (!device->isInDraw) context = context_acquire(device, NULL);
- surface_prepare_texture(This, srgb);
+ surface_prepare_texture(This, gl_info, srgb);
surface_bind_and_dirtify(This, srgb);
if(This->CKeyFlags & WINEDDSD_CKSRCBLT) {
/* Don't use PBOs for converted surfaces. During PBO conversion we look at SFLAG_CONVERTED
* but it isn't set (yet) in all cases it is getting called. */
- if((convert != NO_CONVERSION) && (This->Flags & SFLAG_PBO)) {
+ if(((convert != NO_CONVERSION) || desc.convert) && (This->Flags & SFLAG_PBO)) {
TRACE("Removing the pbo attached to surface %p\n", This);
- surface_remove_pbo(This);
+ surface_remove_pbo(This, gl_info);
}
- if((convert != NO_CONVERSION) && This->resource.allocatedMemory) {
+ if(desc.convert) {
+ /* This code is entered for texture formats which need a fixup. */
int height = This->currentDesc.Height;
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
- outpitch = width * bpp;
+ outpitch = width * desc.conv_byte_count;
+ outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
+
+ mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
+ if(!mem) {
+ ERR("Out of memory %d, %d!\n", outpitch, height);
+ if (context) context_release(context);
+ return WINED3DERR_OUTOFVIDEOMEMORY;
+ }
+ desc.convert(This->resource.allocatedMemory, mem, pitch, width, height);
+ } else if((convert != NO_CONVERSION) && This->resource.allocatedMemory) {
+ /* This code is only entered for color keying fixups */
+ int height = This->currentDesc.Height;
+
+ /* Stick to the alignment for the converted surface too, makes it easier to load the surface */
+ outpitch = width * desc.conv_byte_count;
outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
return WINED3DERR_OUTOFVIDEOMEMORY;
}
d3dfmt_convert_surface(This->resource.allocatedMemory, mem, pitch, width, height, outpitch, convert, This);
- }
- else if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
- && (gl_info->supported[EXT_PALETTED_TEXTURE] || device->blitter->color_fixup_supported(This->resource.format_desc->color_fixup)))
- {
- d3dfmt_p8_upload_palette(iface, convert);
- mem = This->resource.allocatedMemory;
} else {
mem = This->resource.allocatedMemory;
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
LEAVE_GL();
- if ((This->Flags & SFLAG_NONPOW2) && !(This->Flags & SFLAG_OVERSIZE)) {
- TRACE("non power of two support\n");
- if (mem || (This->Flags & SFLAG_PBO)) {
- surface_upload_data(This, internal, This->currentDesc.Width, This->currentDesc.Height, format, type, mem);
- }
- } else {
- /* When making the realloc conditional, keep in mind that GL_APPLE_client_storage may be in use, and This->resource.allocatedMemory
- * changed. So also keep track of memory changes. In this case the texture has to be reallocated
- */
- if (mem || (This->Flags & SFLAG_PBO)) {
- surface_upload_data(This, internal, This->glRect.right - This->glRect.left, This->glRect.bottom - This->glRect.top, format, type, mem);
- }
- }
+ if (mem || (This->Flags & SFLAG_PBO))
+ surface_upload_data(This, gl_info, &desc, srgb, mem);
/* Restore the default pitch */
ENTER_GL();
} else if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
switch(wined3d_settings.offscreen_rendering_mode) {
case ORM_FBO: This->get_drawable_size = get_drawable_size_fbo; break;
- case ORM_PBUFFER: This->get_drawable_size = get_drawable_size_pbuffer; break;
case ORM_BACKBUFFER: This->get_drawable_size = get_drawable_size_backbuffer; break;
}
}
return hr;
}
-BOOL surface_is_offscreen(IWineD3DSurface *iface)
+BOOL surface_is_offscreen(IWineD3DSurfaceImpl *surface)
{
- IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
- IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *) This->container;
+ IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)surface->container;
/* Not on a swapchain - must be offscreen */
- if (!(This->Flags & SFLAG_SWAPCHAIN)) return TRUE;
+ if (!(surface->Flags & SFLAG_SWAPCHAIN)) return TRUE;
/* The front buffer is always onscreen */
- if(iface == swapchain->frontBuffer) return FALSE;
+ if (surface == swapchain->front_buffer) return FALSE;
/* If the swapchain is rendered to an FBO, the backbuffer is
* offscreen, otherwise onscreen */
IWineD3DSurfaceImpl_GetImplType,
IWineD3DSurfaceImpl_DrawOverlay
};
-#undef GLINFO_LOCATION
-#define GLINFO_LOCATION device->adapter->gl_info
static HRESULT ffp_blit_alloc(IWineD3DDevice *iface) { return WINED3D_OK; }
/* Context activation is done by the caller. */
static void ffp_blit_free(IWineD3DDevice *iface) { }
+/* This function is used in case of 8bit paletted textures using GL_EXT_paletted_texture */
+/* Context activation is done by the caller. */
+static void ffp_blit_p8_upload_palette(IWineD3DSurfaceImpl *surface, const struct wined3d_gl_info *gl_info)
+{
+ BYTE table[256][4];
+ BOOL colorkey_active = (surface->CKeyFlags & WINEDDSD_CKSRCBLT) ? TRUE : FALSE;
+
+ d3dfmt_p8_init_palette(surface, table, colorkey_active);
+
+ TRACE("Using GL_EXT_PALETTED_TEXTURE for 8-bit paletted texture support\n");
+ ENTER_GL();
+ GL_EXTCALL(glColorTableEXT(surface->texture_target, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, table));
+ LEAVE_GL();
+}
+
/* Context activation is done by the caller. */
-static HRESULT ffp_blit_set(IWineD3DDevice *iface, const struct GlPixelFormatDesc *format_desc,
- GLenum textype, UINT width, UINT height)
+static HRESULT ffp_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
{
+ IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
+ const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+ enum complex_fixup fixup = get_complex_fixup(surface->resource.format_desc->color_fixup);
+
+ /* When EXT_PALETTED_TEXTURE is around, palette conversion is done by the GPU
+ * else the surface is converted in software at upload time in LoadLocation.
+ */
+ if(fixup == COMPLEX_FIXUP_P8 && gl_info->supported[EXT_PALETTED_TEXTURE])
+ ffp_blit_p8_upload_palette(surface, gl_info);
+
ENTER_GL();
- glEnable(textype);
- checkGLcall("glEnable(textype)");
+ glEnable(surface->texture_target);
+ checkGLcall("glEnable(surface->texture_target)");
LEAVE_GL();
return WINED3D_OK;
}
LEAVE_GL();
}
-static BOOL ffp_blit_color_fixup_supported(struct color_fixup_desc fixup)
+static BOOL ffp_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
+ const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool,
+ const struct wined3d_format_desc *src_format_desc,
+ const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool,
+ const struct wined3d_format_desc *dst_format_desc)
{
+ enum complex_fixup src_fixup;
+
+ if (blit_op == BLIT_OP_COLOR_FILL)
+ {
+ if (!(dst_usage & WINED3DUSAGE_RENDERTARGET))
+ {
+ TRACE("Color fill not supported\n");
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ src_fixup = get_complex_fixup(src_format_desc->color_fixup);
if (TRACE_ON(d3d_surface) && TRACE_ON(d3d))
{
TRACE("Checking support for fixup:\n");
- dump_color_fixup_desc(fixup);
+ dump_color_fixup_desc(src_format_desc->color_fixup);
+ }
+
+ if (blit_op != BLIT_OP_BLIT)
+ {
+ TRACE("Unsupported blit_op=%d\n", blit_op);
+ return FALSE;
+ }
+
+ if (!is_identity_fixup(dst_format_desc->color_fixup))
+ {
+ TRACE("Destination fixups are not supported\n");
+ return FALSE;
+ }
+
+ if (src_fixup == COMPLEX_FIXUP_P8 && gl_info->supported[EXT_PALETTED_TEXTURE])
+ {
+ TRACE("P8 fixup supported\n");
+ return TRUE;
}
/* We only support identity conversions. */
- if (is_identity_fixup(fixup))
+ if (is_identity_fixup(src_format_desc->color_fixup))
{
TRACE("[OK]\n");
return TRUE;
return FALSE;
}
+static HRESULT ffp_blit_color_fill(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD fill_color)
+{
+ return IWineD3DDeviceImpl_ClearSurface(device, dst_surface, 1 /* Number of rectangles */,
+ (const WINED3DRECT*)dst_rect, WINED3DCLEAR_TARGET, fill_color, 0.0f /* Z */, 0 /* Stencil */);
+}
+
const struct blit_shader ffp_blit = {
ffp_blit_alloc,
ffp_blit_free,
ffp_blit_set,
ffp_blit_unset,
- ffp_blit_color_fixup_supported
+ ffp_blit_supported,
+ ffp_blit_color_fill
};
+
+static HRESULT cpu_blit_alloc(IWineD3DDevice *iface)
+{
+ return WINED3D_OK;
+}
+
+/* Context activation is done by the caller. */
+static void cpu_blit_free(IWineD3DDevice *iface)
+{
+}
+
+/* Context activation is done by the caller. */
+static HRESULT cpu_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
+{
+ return WINED3D_OK;
+}
+
+/* Context activation is done by the caller. */
+static void cpu_blit_unset(IWineD3DDevice *iface)
+{
+}
+
+static BOOL cpu_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
+ const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool,
+ const struct wined3d_format_desc *src_format_desc,
+ const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool,
+ const struct wined3d_format_desc *dst_format_desc)
+{
+ if (blit_op == BLIT_OP_COLOR_FILL)
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static HRESULT cpu_blit_color_fill(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD fill_color)
+{
+ WINEDDBLTFX BltFx;
+ memset(&BltFx, 0, sizeof(BltFx));
+ BltFx.dwSize = sizeof(BltFx);
+ BltFx.u5.dwFillColor = color_convert_argb_to_fmt(fill_color, dst_surface->resource.format_desc->format);
+ return IWineD3DBaseSurfaceImpl_Blt((IWineD3DSurface*)dst_surface, dst_rect, NULL, NULL, WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT);
+}
+
+const struct blit_shader cpu_blit = {
+ cpu_blit_alloc,
+ cpu_blit_free,
+ cpu_blit_set,
+ cpu_blit_unset,
+ cpu_blit_supported,
+ cpu_blit_color_fill
+};
+
+static BOOL fbo_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_operation blit_op,
+ const RECT *src_rect, DWORD src_usage, WINED3DPOOL src_pool,
+ const struct wined3d_format_desc *src_format_desc,
+ const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool,
+ const struct wined3d_format_desc *dst_format_desc)
+{
+ if ((wined3d_settings.offscreen_rendering_mode != ORM_FBO) || !gl_info->fbo_ops.glBlitFramebuffer)
+ return FALSE;
+
+ /* We only support blitting. Things like color keying / color fill should
+ * be handled by other blitters.
+ */
+ if (blit_op != BLIT_OP_BLIT)
+ return FALSE;
+
+ /* Source and/or destination need to be on the GL side */
+ if (src_pool == WINED3DPOOL_SYSTEMMEM || dst_pool == WINED3DPOOL_SYSTEMMEM)
+ return FALSE;
+
+ if(!((src_format_desc->Flags & WINED3DFMT_FLAG_FBO_ATTACHABLE) || (src_usage & WINED3DUSAGE_RENDERTARGET))
+ && ((dst_format_desc->Flags & WINED3DFMT_FLAG_FBO_ATTACHABLE) || (dst_usage & WINED3DUSAGE_RENDERTARGET)))
+ return FALSE;
+
+ if (!is_identity_fixup(src_format_desc->color_fixup) ||
+ !is_identity_fixup(dst_format_desc->color_fixup))
+ return FALSE;
+
+ if (!(src_format_desc->format == dst_format_desc->format
+ || (is_identity_fixup(src_format_desc->color_fixup)
+ && is_identity_fixup(dst_format_desc->color_fixup))))
+ return FALSE;
+
+ return TRUE;
+}