static void wined3d_cs_exec_set_render_state(struct wined3d_cs *cs, const void *data) { const struct wined3d_cs_set_render_state *op = data; cs->state.render_states[op->state] = op->value; device_invalidate_state(cs->device, STATE_RENDER(op->state)); }
static void wined3d_cs_exec_set_depth_stencil_view(struct wined3d_cs *cs, const void *data) { const struct wined3d_cs_set_depth_stencil_view *op = data; struct wined3d_device *device = cs->device; struct wined3d_rendertarget_view *prev; if ((prev = cs->state.fb->depth_stencil)) { struct wined3d_surface *prev_surface = wined3d_rendertarget_view_get_surface(prev); if (prev_surface && (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL || prev_surface->flags & SFLAG_DISCARD)) { surface_modify_ds_location(prev_surface, WINED3D_LOCATION_DISCARDED, prev->width, prev->height); if (prev_surface == device->onscreen_depth_stencil) { wined3d_surface_decref(device->onscreen_depth_stencil); device->onscreen_depth_stencil = NULL; } } } cs->fb.depth_stencil = op->view; if (!prev != !op->view) { /* Swapping NULL / non NULL depth stencil affects the depth and tests */ device_invalidate_state(device, STATE_RENDER(WINED3D_RS_ZENABLE)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILENABLE)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } else if (prev && (prev->format_flags & WINED3DFMT_FLAG_FLOAT) != (op->view->format_flags & WINED3DFMT_FLAG_FLOAT)) { device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } device_invalidate_state(device, STATE_FRAMEBUFFER); }
static void wined3d_cs_exec_set_depth_stencil(struct wined3d_cs *cs, const void *data) { const struct wined3d_cs_set_depth_stencil *op = data; struct wined3d_device *device = cs->device; struct wined3d_surface *prev; if ((prev = cs->state.fb->depth_stencil)) { if (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL || prev->flags & SFLAG_DISCARD) { surface_modify_ds_location(prev, WINED3D_LOCATION_DISCARDED, prev->resource.width, prev->resource.height); if (prev == device->onscreen_depth_stencil) { wined3d_surface_decref(device->onscreen_depth_stencil); device->onscreen_depth_stencil = NULL; } } } cs->fb.depth_stencil = op->depth_stencil; if (!prev != !op->depth_stencil) { /* Swapping NULL / non NULL depth stencil affects the depth and tests */ device_invalidate_state(device, STATE_RENDER(WINED3D_RS_ZENABLE)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILENABLE)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } else if (prev && prev->resource.format->depth_size != op->depth_stencil->resource.format->depth_size) { device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); } device_invalidate_state(device, STATE_FRAMEBUFFER); }
/* A GL context is provided by the caller */ static void swapchain_blit(const struct wined3d_swapchain *swapchain, struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect) { struct wined3d_surface *backbuffer = swapchain->back_buffers[0]; UINT src_w = src_rect->right - src_rect->left; UINT src_h = src_rect->bottom - src_rect->top; GLenum gl_filter; const struct wined3d_gl_info *gl_info = context->gl_info; RECT win_rect; UINT win_h; TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n", swapchain, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect)); if (src_w == dst_rect->right - dst_rect->left && src_h == dst_rect->bottom - dst_rect->top) gl_filter = GL_NEAREST; else gl_filter = GL_LINEAR; GetClientRect(swapchain->win_handle, &win_rect); win_h = win_rect.bottom - win_rect.top; if (gl_info->fbo_ops.glBlitFramebuffer && is_identity_fixup(backbuffer->resource.format->color_fixup)) { DWORD location = SFLAG_INTEXTURE; if (backbuffer->resource.multisample_type) { location = SFLAG_INRB_RESOLVED; surface_load_location(backbuffer, location, NULL); } ENTER_GL(); context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, backbuffer, NULL, location); glReadBuffer(GL_COLOR_ATTACHMENT0); context_check_fbo_status(context, GL_READ_FRAMEBUFFER); context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER, swapchain->front_buffer, NULL, SFLAG_INDRAWABLE); context_set_draw_buffer(context, GL_BACK); context_invalidate_state(context, STATE_FRAMEBUFFER); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3)); glDisable(GL_SCISSOR_TEST); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE)); /* Note that the texture is upside down */ gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, dst_rect->left, win_h - dst_rect->top, dst_rect->right, win_h - dst_rect->bottom, GL_COLOR_BUFFER_BIT, gl_filter); checkGLcall("Swapchain present blit(EXT_framebuffer_blit)\n"); LEAVE_GL(); } else { struct wined3d_device *device = swapchain->device; struct wined3d_context *context2; float tex_left = src_rect->left; float tex_top = src_rect->top; float tex_right = src_rect->right; float tex_bottom = src_rect->bottom; context2 = context_acquire(device, swapchain->back_buffers[0]); context_apply_blit_state(context2, device); if (backbuffer->flags & SFLAG_NORMCOORD) { tex_left /= src_w; tex_right /= src_w; tex_top /= src_h; tex_bottom /= src_h; } if (is_complex_fixup(backbuffer->resource.format->color_fixup)) gl_filter = GL_NEAREST; ENTER_GL(); context_apply_fbo_state_blit(context2, GL_FRAMEBUFFER, swapchain->front_buffer, NULL, SFLAG_INDRAWABLE); /* Set up the texture. The surface is not in a wined3d_texture * container, so there are no D3D texture settings to dirtify. */ device->blitter->set_shader(device->blit_priv, context2, backbuffer); glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter); glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter); context_set_draw_buffer(context, GL_BACK); /* Set the viewport to the destination rectandle, disable any projection * transformation set up by context_apply_blit_state(), and draw a * (-1,-1)-(1,1) quad. * * Back up viewport and matrix to avoid breaking last_was_blit * * Note that context_apply_blit_state() set up viewport and ortho to * match the surface size - we want the GL drawable(=window) size. */ glPushAttrib(GL_VIEWPORT_BIT); glViewport(dst_rect->left, win_h - dst_rect->bottom, dst_rect->right, win_h - dst_rect->top); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glBegin(GL_QUADS); /* bottom left */ glTexCoord2f(tex_left, tex_bottom); glVertex2i(-1, -1); /* top left */ glTexCoord2f(tex_left, tex_top); glVertex2i(-1, 1); /* top right */ glTexCoord2f(tex_right, tex_top); glVertex2i(1, 1); /* bottom right */ glTexCoord2f(tex_right, tex_bottom); glVertex2i(1, -1); glEnd(); glPopMatrix(); glPopAttrib(); device->blitter->unset_shader(context->gl_info); checkGLcall("Swapchain present blit(manual)\n"); LEAVE_GL(); context_release(context2); } }
static void wined3d_cs_exec_set_color_key(struct wined3d_cs *cs, const void *data) { const struct wined3d_cs_set_color_key *op = data; struct wined3d_texture *texture = op->texture; if (op->set) { switch (op->flags) { case WINED3D_CKEY_DST_BLT: texture->async.dst_blt_color_key = op->color_key; texture->async.color_key_flags |= WINED3D_CKEY_DST_BLT; break; case WINED3D_CKEY_DST_OVERLAY: texture->async.dst_overlay_color_key = op->color_key; texture->async.color_key_flags |= WINED3D_CKEY_DST_OVERLAY; break; case WINED3D_CKEY_SRC_BLT: if (texture == cs->state.textures[0]) { device_invalidate_state(cs->device, STATE_COLOR_KEY); if (!(texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT)) device_invalidate_state(cs->device, STATE_RENDER(WINED3D_RS_COLORKEYENABLE)); } texture->async.src_blt_color_key = op->color_key; texture->async.color_key_flags |= WINED3D_CKEY_SRC_BLT; break; case WINED3D_CKEY_SRC_OVERLAY: texture->async.src_overlay_color_key = op->color_key; texture->async.color_key_flags |= WINED3D_CKEY_SRC_OVERLAY; break; } } else { switch (op->flags) { case WINED3D_CKEY_DST_BLT: texture->async.color_key_flags &= ~WINED3D_CKEY_DST_BLT; break; case WINED3D_CKEY_DST_OVERLAY: texture->async.color_key_flags &= ~WINED3D_CKEY_DST_OVERLAY; break; case WINED3D_CKEY_SRC_BLT: if (texture == cs->state.textures[0] && texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT) device_invalidate_state(cs->device, STATE_RENDER(WINED3D_RS_COLORKEYENABLE)); texture->async.color_key_flags &= ~WINED3D_CKEY_SRC_BLT; break; case WINED3D_CKEY_SRC_OVERLAY: texture->async.color_key_flags &= ~WINED3D_CKEY_SRC_OVERLAY; break; } } }
static void wined3d_cs_exec_set_texture(struct wined3d_cs *cs, const void *data) { const struct wined3d_d3d_info *d3d_info = &cs->device->adapter->d3d_info; const struct wined3d_cs_set_texture *op = data; struct wined3d_texture *prev; BOOL old_use_color_key = FALSE, new_use_color_key = FALSE; prev = cs->state.textures[op->stage]; cs->state.textures[op->stage] = op->texture; if (op->texture) { const struct wined3d_format *new_format = op->texture->resource.format; const struct wined3d_format *old_format = prev ? prev->resource.format : NULL; unsigned int old_fmt_flags = prev ? prev->resource.format_flags : 0; unsigned int new_fmt_flags = op->texture->resource.format_flags; if (InterlockedIncrement(&op->texture->resource.bind_count) == 1) op->texture->sampler = op->stage; if (!prev || op->texture->target != prev->target || !is_same_fixup(new_format->color_fixup, old_format->color_fixup) || (new_fmt_flags & WINED3DFMT_FLAG_SHADOW) != (old_fmt_flags & WINED3DFMT_FLAG_SHADOW)) device_invalidate_state(cs->device, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL)); if (!prev && op->stage < d3d_info->limits.ffp_blend_stages) { /* The source arguments for color and alpha ops have different * meanings when a NULL texture is bound, so the COLOR_OP and * ALPHA_OP have to be dirtified. */ device_invalidate_state(cs->device, STATE_TEXTURESTAGE(op->stage, WINED3D_TSS_COLOR_OP)); device_invalidate_state(cs->device, STATE_TEXTURESTAGE(op->stage, WINED3D_TSS_ALPHA_OP)); } if (!op->stage && op->texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT) new_use_color_key = TRUE; } if (prev) { if (InterlockedDecrement(&prev->resource.bind_count) && prev->sampler == op->stage) { unsigned int i; /* Search for other stages the texture is bound to. Shouldn't * happen if applications bind textures to a single stage only. */ TRACE("Searching for other stages the texture is bound to.\n"); for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) { if (cs->state.textures[i] == prev) { TRACE("Texture is also bound to stage %u.\n", i); prev->sampler = i; break; } } } if (!op->texture && op->stage < d3d_info->limits.ffp_blend_stages) { device_invalidate_state(cs->device, STATE_TEXTURESTAGE(op->stage, WINED3D_TSS_COLOR_OP)); device_invalidate_state(cs->device, STATE_TEXTURESTAGE(op->stage, WINED3D_TSS_ALPHA_OP)); } if (!op->stage && prev->async.color_key_flags & WINED3D_CKEY_SRC_BLT) old_use_color_key = TRUE; } device_invalidate_state(cs->device, STATE_SAMPLER(op->stage)); if (new_use_color_key != old_use_color_key) device_invalidate_state(cs->device, STATE_RENDER(WINED3D_RS_COLORKEYENABLE)); if (new_use_color_key) device_invalidate_state(cs->device, STATE_COLOR_KEY); }
/* Tesselates a high order rectangular patch into single triangles using gl evaluators * * The problem is that OpenGL does not offer a direct way to return the tesselated primitives, * and they can't be sent off for rendering directly either. Tesselating is slow, so we want * to cache the patches in a vertex buffer. But more importantly, gl can't bind generated * attributes to numbered shader attributes, so we have to store them and rebind them as needed * in drawprim. * * To read back, the opengl feedback mode is used. This creates a problem because we want * untransformed, unlit vertices, but feedback runs everything through transform and lighting. * Thus disable lighting and set identity matrices to get unmodified colors and positions. * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale * them to [-1.0;+1.0] and set the viewport up to scale them back. * * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the * resulting colors back to the normals. * * NOTE: This function activates a context for blitting, modifies matrices & viewport, but * does not restore it because normally a draw follows immediately afterwards. The caller is * responsible of taking care that either the gl states are restored, or the context activated * for drawing to reset the lastWasBlit flag. */ HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This, struct WineD3DRectPatch *patch) { unsigned int i, j, num_quads, out_vertex_size, buffer_size, d3d_out_vertex_size; float max_x = 0.0f, max_y = 0.0f, max_z = 0.0f, neg_z = 0.0f; struct wined3d_stream_info stream_info; struct wined3d_stream_info_element *e; struct wined3d_context *context; const BYTE *data; const WINED3DRECTPATCH_INFO *info = &patch->RectPatchInfo; DWORD vtxStride; GLenum feedback_type; GLfloat *feedbuffer; /* Simply activate the context for blitting. This disables all the things we don't want and * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the * patch (as opposed to normal draws) will most likely need different changes anyway. */ context = context_acquire(This, NULL, CTXUSAGE_BLIT); /* First, locate the position data. This is provided in a vertex buffer in the stateblock. * Beware of vbos */ device_stream_info_from_declaration(This, FALSE, &stream_info, NULL); e = &stream_info.elements[WINED3D_FFP_POSITION]; if (e->buffer_object) { struct wined3d_buffer *vb; vb = (struct wined3d_buffer *)This->stateBlock->streamSource[e->stream_idx]; e->data = (BYTE *)((unsigned long)e->data + (unsigned long)buffer_get_sysmem(vb)); } vtxStride = e->stride; data = e->data + vtxStride * info->Stride * info->StartVertexOffsetHeight + vtxStride * info->StartVertexOffsetWidth; /* Not entirely sure about what happens with transformed vertices */ if (stream_info.position_transformed) FIXME("Transformed position in rectpatch generation\n"); if(vtxStride % sizeof(GLfloat)) { /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes. * I don't see how the stride could not be a multiple of 4, but make sure * to check it */ ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n"); } if(info->Basis != WINED3DBASIS_BEZIER) { FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info->Basis)); } if(info->Degree != WINED3DDEGREE_CUBIC) { FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info->Degree)); } /* First, get the boundary cube of the input data */ for(j = 0; j < info->Height; j++) { for(i = 0; i < info->Width; i++) { const float *v = (const float *)(data + vtxStride * i + vtxStride * info->Stride * j); if(fabs(v[0]) > max_x) max_x = fabs(v[0]); if(fabs(v[1]) > max_y) max_y = fabs(v[1]); if(fabs(v[2]) > max_z) max_z = fabs(v[2]); if(v[2] < neg_z) neg_z = v[2]; } } /* This needs some improvements in the vertex decl code */ FIXME("Cannot find data to generate. Only generating position and normals\n"); patch->has_normals = TRUE; patch->has_texcoords = FALSE; ENTER_GL(); glMatrixMode(GL_PROJECTION); checkGLcall("glMatrixMode(GL_PROJECTION)"); glLoadIdentity(); checkGLcall("glLoadIndentity()"); glScalef(1.0f / (max_x), 1.0f / (max_y), max_z == 0.0f ? 1.0f : 1.0f / (2.0f * max_z)); glTranslatef(0.0f, 0.0f, 0.5f); checkGLcall("glScalef"); glViewport(-max_x, -max_y, 2 * (max_x), 2 * (max_y)); checkGLcall("glViewport"); /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse * our feedback buffer parser */ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)"); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_FILLMODE)); if(patch->has_normals) { static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f}; static const GLfloat red[] = {1.0f, 0.0f, 0.0f, 0.0f}; static const GLfloat green[] = {0.0f, 1.0f, 0.0f, 0.0f}; static const GLfloat blue[] = {0.0f, 0.0f, 1.0f, 0.0f}; static const GLfloat white[] = {1.0f, 1.0f, 1.0f, 1.0f}; glEnable(GL_LIGHTING); checkGLcall("glEnable(GL_LIGHTING)"); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, black); checkGLcall("glLightModel for MODEL_AMBIENT"); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_AMBIENT)); for (i = 3; i < context->gl_info->limits.lights; ++i) { glDisable(GL_LIGHT0 + i); checkGLcall("glDisable(GL_LIGHT0 + i)"); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(i)); } IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(0)); glLightfv(GL_LIGHT0, GL_DIFFUSE, red); glLightfv(GL_LIGHT0, GL_SPECULAR, black); glLightfv(GL_LIGHT0, GL_AMBIENT, black); glLightfv(GL_LIGHT0, GL_POSITION, red); glEnable(GL_LIGHT0); checkGLcall("Setting up light 1"); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(1)); glLightfv(GL_LIGHT1, GL_DIFFUSE, green); glLightfv(GL_LIGHT1, GL_SPECULAR, black); glLightfv(GL_LIGHT1, GL_AMBIENT, black); glLightfv(GL_LIGHT1, GL_POSITION, green); glEnable(GL_LIGHT1); checkGLcall("Setting up light 2"); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(2)); glLightfv(GL_LIGHT2, GL_DIFFUSE, blue); glLightfv(GL_LIGHT2, GL_SPECULAR, black); glLightfv(GL_LIGHT2, GL_AMBIENT, black); glLightfv(GL_LIGHT2, GL_POSITION, blue); glEnable(GL_LIGHT2); checkGLcall("Setting up light 3"); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_MATERIAL); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_COLORVERTEX)); glDisable(GL_COLOR_MATERIAL); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white); checkGLcall("Setting up materials"); } /* Enable the needed maps. * GL_MAP2_VERTEX_3 is needed for positional data. * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL. * GL_MAP2_TEXTURE_COORD_4 for texture coords */ num_quads = ceilf(patch->numSegs[0]) * ceilf(patch->numSegs[1]); out_vertex_size = 3 /* position */; d3d_out_vertex_size = 3; glEnable(GL_MAP2_VERTEX_3); if(patch->has_normals && patch->has_texcoords) { FIXME("Texcoords not handled yet\n"); feedback_type = GL_3D_COLOR_TEXTURE; out_vertex_size += 8; d3d_out_vertex_size += 7; glEnable(GL_AUTO_NORMAL); glEnable(GL_MAP2_TEXTURE_COORD_4); } else if(patch->has_texcoords) { FIXME("Texcoords not handled yet\n"); feedback_type = GL_3D_COLOR_TEXTURE; out_vertex_size += 7; d3d_out_vertex_size += 4; glEnable(GL_MAP2_TEXTURE_COORD_4); } else if(patch->has_normals) { feedback_type = GL_3D_COLOR; out_vertex_size += 4; d3d_out_vertex_size += 3; glEnable(GL_AUTO_NORMAL); } else { feedback_type = GL_3D; } checkGLcall("glEnable vertex attrib generation"); buffer_size = num_quads * out_vertex_size * 2 /* triangle list */ * 3 /* verts per tri */ + 4 * num_quads /* 2 triangle markers per quad + num verts in tri */; feedbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buffer_size * sizeof(float) * 8); glMap2f(GL_MAP2_VERTEX_3, 0.0f, 1.0f, vtxStride / sizeof(float), info->Width, 0.0f, 1.0f, info->Stride * vtxStride / sizeof(float), info->Height, (const GLfloat *)data); checkGLcall("glMap2f"); if(patch->has_texcoords) { glMap2f(GL_MAP2_TEXTURE_COORD_4, 0.0f, 1.0f, vtxStride / sizeof(float), info->Width, 0.0f, 1.0f, info->Stride * vtxStride / sizeof(float), info->Height, (const GLfloat *)data); checkGLcall("glMap2f"); } glMapGrid2f(ceilf(patch->numSegs[0]), 0.0f, 1.0f, ceilf(patch->numSegs[1]), 0.0f, 1.0f); checkGLcall("glMapGrid2f"); glFeedbackBuffer(buffer_size * 2, feedback_type, feedbuffer); checkGLcall("glFeedbackBuffer"); glRenderMode(GL_FEEDBACK); glEvalMesh2(GL_FILL, 0, ceilf(patch->numSegs[0]), 0, ceilf(patch->numSegs[1])); checkGLcall("glEvalMesh2"); i = glRenderMode(GL_RENDER); if(i == -1) { LEAVE_GL(); ERR("Feedback failed. Expected %d elements back\n", buffer_size); HeapFree(GetProcessHeap(), 0, feedbuffer); context_release(context); return WINED3DERR_DRIVERINTERNALERROR; } else if(i != buffer_size) { LEAVE_GL(); ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size, i); HeapFree(GetProcessHeap(), 0, feedbuffer); context_release(context); return WINED3DERR_DRIVERINTERNALERROR; } else { TRACE("Got %d elements as expected\n", i); } HeapFree(GetProcessHeap(), 0, patch->mem); patch->mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num_quads * 6 * d3d_out_vertex_size * sizeof(float) * 8); i = 0; for(j = 0; j < buffer_size; j += (3 /* num verts */ * out_vertex_size + 2 /* tri marker */)) { if(feedbuffer[j] != GL_POLYGON_TOKEN) { ERR("Unexpected token: %f\n", feedbuffer[j]); continue; } if(feedbuffer[j + 1] != 3) { ERR("Unexpected polygon: %f corners\n", feedbuffer[j + 1]); continue; } /* Somehow there are different ideas about back / front facing, so fix up the * vertex order */ patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 2 + 2]; /* x, triangle 2 */ patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 2 + 3]; /* y, triangle 2 */ patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 2 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 3 */ if(patch->has_normals) { patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 2 + 5]; patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 2 + 6]; patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 2 + 7]; } i += d3d_out_vertex_size; patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 1 + 2]; /* x, triangle 2 */ patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 1 + 3]; /* y, triangle 2 */ patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 1 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 2 */ if(patch->has_normals) { patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 1 + 5]; patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 1 + 6]; patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 1 + 7]; } i += d3d_out_vertex_size; patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 0 + 2]; /* x, triangle 1 */ patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 0 + 3]; /* y, triangle 1 */ patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 0 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 1 */ if(patch->has_normals) { patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 0 + 5]; patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 0 + 6]; patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 0 + 7]; } i += d3d_out_vertex_size; } if(patch->has_normals) { /* Now do the same with reverse light directions */ static const GLfloat x[] = {-1.0f, 0.0f, 0.0f, 0.0f}; static const GLfloat y[] = { 0.0f, -1.0f, 0.0f, 0.0f}; static const GLfloat z[] = { 0.0f, 0.0f, -1.0f, 0.0f}; glLightfv(GL_LIGHT0, GL_POSITION, x); glLightfv(GL_LIGHT1, GL_POSITION, y); glLightfv(GL_LIGHT2, GL_POSITION, z); checkGLcall("Setting up reverse light directions"); glRenderMode(GL_FEEDBACK); checkGLcall("glRenderMode(GL_FEEDBACK)"); glEvalMesh2(GL_FILL, 0, ceilf(patch->numSegs[0]), 0, ceilf(patch->numSegs[1])); checkGLcall("glEvalMesh2"); i = glRenderMode(GL_RENDER); checkGLcall("glRenderMode(GL_RENDER)"); i = 0; for(j = 0; j < buffer_size; j += (3 /* num verts */ * out_vertex_size + 2 /* tri marker */)) { if(feedbuffer[j] != GL_POLYGON_TOKEN) { ERR("Unexpected token: %f\n", feedbuffer[j]); continue; } if(feedbuffer[j + 1] != 3) { ERR("Unexpected polygon: %f corners\n", feedbuffer[j + 1]); continue; } if(patch->mem[i + 3] == 0.0f) patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 2 + 5]; if(patch->mem[i + 4] == 0.0f) patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 2 + 6]; if(patch->mem[i + 5] == 0.0f) patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 2 + 7]; normalize_normal(patch->mem + i + 3); i += d3d_out_vertex_size; if(patch->mem[i + 3] == 0.0f) patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 1 + 5]; if(patch->mem[i + 4] == 0.0f) patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 1 + 6]; if(patch->mem[i + 5] == 0.0f) patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 1 + 7]; normalize_normal(patch->mem + i + 3); i += d3d_out_vertex_size; if(patch->mem[i + 3] == 0.0f) patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 0 + 5]; if(patch->mem[i + 4] == 0.0f) patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 0 + 6]; if(patch->mem[i + 5] == 0.0f) patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 0 + 7]; normalize_normal(patch->mem + i + 3); i += d3d_out_vertex_size; } } glDisable(GL_MAP2_VERTEX_3); glDisable(GL_AUTO_NORMAL); glDisable(GL_MAP2_NORMAL); glDisable(GL_MAP2_TEXTURE_COORD_4); checkGLcall("glDisable vertex attrib generation"); LEAVE_GL(); context_release(context); HeapFree(GetProcessHeap(), 0, feedbuffer); vtxStride = 3 * sizeof(float); if(patch->has_normals) { vtxStride += 3 * sizeof(float); } if(patch->has_texcoords) { vtxStride += 4 * sizeof(float); } memset(&patch->strided, 0, sizeof(patch->strided)); patch->strided.position.format = WINED3DFMT_R32G32B32_FLOAT; patch->strided.position.lpData = (BYTE *) patch->mem; patch->strided.position.dwStride = vtxStride; if(patch->has_normals) { patch->strided.normal.format = WINED3DFMT_R32G32B32_FLOAT; patch->strided.normal.lpData = (BYTE *) patch->mem + 3 * sizeof(float) /* pos */; patch->strided.normal.dwStride = vtxStride; } if(patch->has_texcoords) { patch->strided.texCoords[0].format = WINED3DFMT_R32G32B32A32_FLOAT; patch->strided.texCoords[0].lpData = (BYTE *) patch->mem + 3 * sizeof(float) /* pos */; if(patch->has_normals) { patch->strided.texCoords[0].lpData += 3 * sizeof(float); } patch->strided.texCoords[0].dwStride = vtxStride; } return WINED3D_OK; }
/* A GL context is provided by the caller */ static void swapchain_blit(IWineD3DSwapChainImpl *This, struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect) { IWineD3DDeviceImpl *device = This->device; IWineD3DSurfaceImpl *backbuffer = ((IWineD3DSurfaceImpl *) This->backBuffer[0]); UINT src_w = src_rect->right - src_rect->left; UINT src_h = src_rect->bottom - src_rect->top; GLenum gl_filter; const struct wined3d_gl_info *gl_info = context->gl_info; TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n", This, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect)); if (src_w == dst_rect->right - dst_rect->left && src_h == dst_rect->bottom - dst_rect->top) gl_filter = GL_NEAREST; else gl_filter = GL_LINEAR; if (0 && gl_info->fbo_ops.glBlitFramebuffer && is_identity_fixup(backbuffer->resource.format_desc->color_fixup)) { ENTER_GL(); context_bind_fbo(context, GL_READ_FRAMEBUFFER, &context->src_fbo); context_attach_surface_fbo(context, GL_READ_FRAMEBUFFER, 0, backbuffer); context_attach_depth_stencil_fbo(context, GL_READ_FRAMEBUFFER, NULL, FALSE); context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL); context_set_draw_buffer(context, GL_BACK); glDisable(GL_SCISSOR_TEST); IWineD3DDeviceImpl_MarkStateDirty(This->device, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE)); /* Note that the texture is upside down */ gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, dst_rect->left, dst_rect->bottom, dst_rect->right, dst_rect->top, GL_COLOR_BUFFER_BIT, gl_filter); checkGLcall("Swapchain present blit(EXT_framebuffer_blit)\n"); LEAVE_GL(); } else { struct wined3d_context *context2; float tex_left = src_rect->left; float tex_top = src_rect->top; float tex_right = src_rect->right; float tex_bottom = src_rect->bottom; context2 = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_BLIT); if(backbuffer->Flags & SFLAG_NORMCOORD) { tex_left /= src_w; tex_right /= src_w; tex_top /= src_h; tex_bottom /= src_h; } if (is_complex_fixup(backbuffer->resource.format_desc->color_fixup)) gl_filter = GL_NEAREST; ENTER_GL(); context_bind_fbo(context2, GL_DRAW_FRAMEBUFFER, NULL); /* Set up the texture. The surface is not in a IWineD3D*Texture container, * so there are no d3d texture settings to dirtify */ device->blitter->set_shader((IWineD3DDevice *) device, backbuffer); glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter); glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter); context_set_draw_buffer(context, GL_BACK); /* Set the viewport to the destination rectandle, disable any projection * transformation set up by CTXUSAGE_BLIT, and draw a (-1,-1)-(1,1) quad. * * Back up viewport and matrix to avoid breaking last_was_blit * * Note that CTXUSAGE_BLIT set up viewport and ortho to match the surface * size - we want the GL drawable(=window) size. */ glPushAttrib(GL_VIEWPORT_BIT); glViewport(dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glBegin(GL_QUADS); /* bottom left */ glTexCoord2f(tex_left, tex_bottom); glVertex2i(-1, -1); /* top left */ glTexCoord2f(tex_left, tex_top); glVertex2i(-1, 1); /* top right */ glTexCoord2f(tex_right, tex_top); glVertex2i(1, 1); /* bottom right */ glTexCoord2f(tex_right, tex_bottom); glVertex2i(1, -1); glEnd(); glPopMatrix(); glPopAttrib(); device->blitter->unset_shader((IWineD3DDevice *) device); checkGLcall("Swapchain present blit(manual)\n"); LEAVE_GL(); context_release(context2); } }