mesa.c
来自「Wine-20031016」· C语言 代码 · 共 1,666 行 · 第 1/5 页
C
1,666 行
switch (d3dvt) { case D3DVT_VERTEX: { strided.position.lpvData = &((D3DVERTEX *) lpvertex)->u1.x; strided.position.dwStride = sizeof(D3DVERTEX); strided.normal.lpvData = &((D3DVERTEX *) lpvertex)->u4.nx; strided.normal.dwStride = sizeof(D3DVERTEX); strided.textureCoords[0].lpvData = &((D3DVERTEX *) lpvertex)->u7.tu; strided.textureCoords[0].dwStride = sizeof(D3DVERTEX); draw_primitive_strided(This, d3dpt, D3DFVF_VERTEX, &strided, 0 /* Unused */, index, maxvert, 0 /* Unused */); } break; case D3DVT_LVERTEX: { strided.position.lpvData = &((D3DLVERTEX *) lpvertex)->u1.x; strided.position.dwStride = sizeof(D3DLVERTEX); strided.diffuse.lpvData = &((D3DLVERTEX *) lpvertex)->u4.color; strided.diffuse.dwStride = sizeof(D3DLVERTEX); strided.specular.lpvData = &((D3DLVERTEX *) lpvertex)->u5.specular; strided.specular.dwStride = sizeof(D3DLVERTEX); strided.textureCoords[0].lpvData = &((D3DLVERTEX *) lpvertex)->u6.tu; strided.textureCoords[0].dwStride = sizeof(D3DLVERTEX); draw_primitive_strided(This, d3dpt, D3DFVF_LVERTEX, &strided, 0 /* Unused */, index, maxvert, 0 /* Unused */); } break; case D3DVT_TLVERTEX: { strided.position.lpvData = &((D3DTLVERTEX *) lpvertex)->u1.sx; strided.position.dwStride = sizeof(D3DTLVERTEX); strided.diffuse.lpvData = &((D3DTLVERTEX *) lpvertex)->u5.color; strided.diffuse.dwStride = sizeof(D3DTLVERTEX); strided.specular.lpvData = &((D3DTLVERTEX *) lpvertex)->u6.specular; strided.specular.dwStride = sizeof(D3DTLVERTEX); strided.textureCoords[0].lpvData = &((D3DTLVERTEX *) lpvertex)->u7.tu; strided.textureCoords[0].dwStride = sizeof(D3DTLVERTEX); draw_primitive_strided(This, d3dpt, D3DFVF_TLVERTEX, &strided, 0 /* Unused */, index, maxvert, 0 /* Unused */); } break; default: FIXME("Unhandled vertex type %08x\n", d3dvt); break; }}HRESULT WINAPIGL_IDirect3DDeviceImpl_2_DrawPrimitive(LPDIRECT3DDEVICE2 iface, D3DPRIMITIVETYPE d3dptPrimitiveType, D3DVERTEXTYPE d3dvtVertexType, LPVOID lpvVertices, DWORD dwVertexCount, DWORD dwFlags){ ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface); TRACE("(%p/%p)->(%08x,%08x,%p,%08lx,%08lx)\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwVertexCount, dwFlags); if (TRACE_ON(ddraw)) { TRACE(" - flags : "); dump_DPFLAGS(dwFlags); } draw_primitive(This, dwVertexCount, NULL, d3dvtVertexType, d3dptPrimitiveType, lpvVertices); return DD_OK;}HRESULT WINAPIGL_IDirect3DDeviceImpl_2_DrawIndexedPrimitive(LPDIRECT3DDEVICE2 iface, D3DPRIMITIVETYPE d3dptPrimitiveType, D3DVERTEXTYPE d3dvtVertexType, LPVOID lpvVertices, DWORD dwVertexCount, LPWORD dwIndices, DWORD dwIndexCount, DWORD dwFlags){ ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface); TRACE("(%p/%p)->(%08x,%08x,%p,%08lx,%p,%08lx,%08lx)\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwVertexCount, dwIndices, dwIndexCount, dwFlags); if (TRACE_ON(ddraw)) { TRACE(" - flags : "); dump_DPFLAGS(dwFlags); } draw_primitive(This, dwIndexCount, dwIndices, d3dvtVertexType, d3dptPrimitiveType, lpvVertices); return DD_OK;}HRESULT WINAPIGL_IDirect3DDeviceImpl_1_CreateExecuteBuffer(LPDIRECT3DDEVICE iface, LPD3DEXECUTEBUFFERDESC lpDesc, LPDIRECT3DEXECUTEBUFFER* lplpDirect3DExecuteBuffer, IUnknown* pUnkOuter){ ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface); IDirect3DExecuteBufferImpl *ret; HRESULT ret_value; TRACE("(%p/%p)->(%p,%p,%p)\n", This, iface, lpDesc, lplpDirect3DExecuteBuffer, pUnkOuter); ret_value = d3dexecutebuffer_create(&ret, This->d3d, This, lpDesc); *lplpDirect3DExecuteBuffer = ICOM_INTERFACE(ret, IDirect3DExecuteBuffer); TRACE(" returning %p.\n", *lplpDirect3DExecuteBuffer); return ret_value;}static void flush_zbuffer_to_GL(IDirect3DDeviceImpl *d3d_dev, LPCRECT pRect, IDirectDrawSurfaceImpl *surf) { static BOOLEAN first = TRUE; IDirect3DDeviceGLImpl* gl_d3d_dev = (IDirect3DDeviceGLImpl*) d3d_dev; int row; GLenum type; if (first == TRUE) { MESSAGE("Warning : application does direct locking of ZBuffer - expect slowdowns on many GL implementations :-)\n"); first = FALSE; } TRACE("flushing ZBuffer back to GL\n"); if (gl_d3d_dev->transform_state != GL_TRANSFORM_ORTHO) { gl_d3d_dev->transform_state = GL_TRANSFORM_ORTHO; d3ddevice_set_ortho(d3d_dev); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (gl_d3d_dev->depth_test == 0) glEnable(GL_DEPTH_TEST); if (d3d_dev->state_block.render_state[D3DRENDERSTATE_ZFUNC - 1] != D3DCMP_ALWAYS) glDepthFunc(GL_ALWAYS); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); /* This loop here is to prevent using PixelZoom that may be unoptimized for the 1.0 / -1.0 case in some drivers... */ switch (surf->surface_desc.u4.ddpfPixelFormat.u1.dwZBufferBitDepth) { case 16: type = GL_UNSIGNED_SHORT; break; case 32: type = GL_UNSIGNED_INT; break; default: FIXME("Unhandled ZBuffer format !\n"); goto restore_state; } for (row = 0; row < surf->surface_desc.dwHeight; row++) { /* glRasterPos3d(0.0, row + 1.0, 0.5); */ glRasterPos2i(0, row + 1); glDrawPixels(surf->surface_desc.dwWidth, 1, GL_DEPTH_COMPONENT, type, ((unsigned char *) surf->surface_desc.lpSurface) + (row * surf->surface_desc.u1.lPitch)); } restore_state: glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); if (d3d_dev->state_block.render_state[D3DRENDERSTATE_ZFUNC - 1] != D3DCMP_ALWAYS) glDepthFunc(convert_D3D_compare_to_GL(d3d_dev->state_block.render_state[D3DRENDERSTATE_ZFUNC - 1])); if (gl_d3d_dev->depth_test == 0) glDisable(GL_DEPTH_TEST);}/* These are the various handler used in the generic path */inline static void handle_xyz(D3DVALUE *coords) { glVertex3fv(coords);}inline static void handle_xyzrhw(D3DVALUE *coords) { if (coords[3] < 1e-8) glVertex3fv(coords); else { GLfloat w = 1.0 / coords[3]; glVertex4f(coords[0] * w, coords[1] * w, coords[2] * w, w); }}inline static void handle_normal(D3DVALUE *coords) { glNormal3fv(coords);}inline static void handle_diffuse_base(STATEBLOCK *sb, DWORD *color) { if ((sb->render_state[D3DRENDERSTATE_ALPHATESTENABLE - 1] == TRUE) || (sb->render_state[D3DRENDERSTATE_ALPHABLENDENABLE - 1] == TRUE)) { glColor4ub((*color >> 16) & 0xFF, (*color >> 8) & 0xFF, (*color >> 0) & 0xFF, (*color >> 24) & 0xFF); } else { glColor3ub((*color >> 16) & 0xFF, (*color >> 8) & 0xFF, (*color >> 0) & 0xFF); }}inline static void handle_specular_base(STATEBLOCK *sb, DWORD *color) { glColor4ub((*color >> 16) & 0xFF, (*color >> 8) & 0xFF, (*color >> 0) & 0xFF, (*color >> 24) & 0xFF); /* No idea if the alpha field is really used.. */}inline static void handle_diffuse(STATEBLOCK *sb, DWORD *color, BOOLEAN lighted) { if ((lighted == FALSE) && (sb->render_state[D3DRENDERSTATE_LIGHTING - 1] == TRUE) && (sb->render_state[D3DRENDERSTATE_COLORVERTEX - 1] == TRUE)) { if (sb->render_state[D3DRENDERSTATE_DIFFUSEMATERIALSOURCE - 1] == D3DMCS_COLOR1) { glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); handle_diffuse_base(sb, color); } if (sb->render_state[D3DRENDERSTATE_AMBIENTMATERIALSOURCE - 1] == D3DMCS_COLOR1) { glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); handle_diffuse_base(sb, color); } if ((sb->render_state[D3DRENDERSTATE_SPECULARMATERIALSOURCE - 1] == D3DMCS_COLOR1) && (sb->render_state[D3DRENDERSTATE_SPECULARENABLE - 1] == TRUE)) { glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); handle_diffuse_base(sb, color); } if (sb->render_state[D3DRENDERSTATE_EMISSIVEMATERIALSOURCE - 1] == D3DMCS_COLOR1) { glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION); handle_diffuse_base(sb, color); } } else { handle_diffuse_base(sb, color); } }inline static void handle_specular(STATEBLOCK *sb, DWORD *color, BOOLEAN lighted) { if ((lighted == FALSE) && (sb->render_state[D3DRENDERSTATE_LIGHTING - 1] == TRUE) && (sb->render_state[D3DRENDERSTATE_COLORVERTEX - 1] == TRUE)) { if (sb->render_state[D3DRENDERSTATE_DIFFUSEMATERIALSOURCE - 1] == D3DMCS_COLOR2) { glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); handle_specular_base(sb, color); } if (sb->render_state[D3DRENDERSTATE_AMBIENTMATERIALSOURCE - 1] == D3DMCS_COLOR2) { glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); handle_specular_base(sb, color); } if ((sb->render_state[D3DRENDERSTATE_SPECULARMATERIALSOURCE - 1] == D3DMCS_COLOR2) && (sb->render_state[D3DRENDERSTATE_SPECULARENABLE - 1] == TRUE)) { glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); handle_specular_base(sb, color); } if (sb->render_state[D3DRENDERSTATE_EMISSIVEMATERIALSOURCE - 1] == D3DMCS_COLOR2) { glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION); handle_specular_base(sb, color); } } /* No else here as we do not know how to handle 'specular' on its own in any case.. */}inline static void handle_diffuse_and_specular(STATEBLOCK *sb, BYTE *fog_table, DWORD *color_d, DWORD *color_s, BOOLEAN lighted) { if (lighted == TRUE) { DWORD color = *color_d; if (sb->render_state[D3DRENDERSTATE_FOGENABLE - 1] == TRUE) { /* Special case where the specular value is used to do fogging */ BYTE fog_intensity = *color_s >> 24; /* The alpha value of the specular component is the fog 'intensity' for this vertex */ color &= 0xFF000000; /* Only keep the alpha component */ color |= fog_table[((*color_d >> 0) & 0xFF) << 8 | fog_intensity] << 0; color |= fog_table[((*color_d >> 8) & 0xFF) << 8 | fog_intensity] << 8; color |= fog_table[((*color_d >> 16) & 0xFF) << 8 | fog_intensity] << 16; } if (sb->render_state[D3DRENDERSTATE_SPECULARENABLE - 1] == TRUE) { /* Standard specular value in transformed mode. TODO */ } handle_diffuse_base(sb, &color); } else { if (sb->render_state[D3DRENDERSTATE_LIGHTING - 1] == TRUE) { handle_diffuse(sb, color_d, FALSE); handle_specular(sb, color_s, FALSE); } else { /* In that case, only put the diffuse color... */ handle_diffuse_base(sb, color_d); } }}inline static void handle_texture(D3DVALUE *coords) { glTexCoord2fv(coords);}inline static void handle_textures(D3DVALUE *coords, int tex_stage) { if (GL_extensions.glMultiTexCoord2fv) { GL_extensions.glMultiTexCoord2fv(GL_TEXTURE0_WINE + tex_stage, coords); } else { if (tex_stage == 0) glTexCoord2fv(coords); }}static void draw_primitive_strided(IDirect3DDeviceImpl *This, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD d3dvtVertexType, LPD3DDRAWPRIMITIVESTRIDEDDATA lpD3DDrawPrimStrideData, DWORD dwVertexCount, LPWORD dwIndices, DWORD dwIndexCount, DWORD dwFlags){ BOOLEAN vertex_lighted = FALSE; IDirect3DDeviceGLImpl* glThis = (IDirect3DDeviceGLImpl*) This; int num_active_stages = 0; /* I put the trace before the various locks... So as to better understand where locks occur :-) */ if (TRACE_ON(ddraw)) { TRACE(" Vertex format : "); dump_flexible_vertex(d3dvtVertexType); } /* This is to prevent 'thread contention' between a thread locking the device and another doing 3D display on it... */ EnterCriticalSection(&(This->crit)); ENTER_GL(); if (glThis->state[WINE_GL_BUFFER_BACK] == SURFACE_MEMORY_DIRTY) { This->flush_to_framebuffer(This, &(glThis->lock_rect[WINE_GL_BUFFER_BACK]), glThis->lock_surf[WINE_GL_BUFFER_BACK]); } glThis->state[WINE_GL_BUFFER_BACK] = SURFACE_GL; if (This->current_zbuffer == NULL) { /* Search for an attached ZBuffer */ static const DDSCAPS2 zbuf_caps = { DDSCAPS_ZBUFFER, 0, 0, 0 }; LPDIRECTDRAWSURFACE7 zbuf; HRESULT hr; hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This->surface, IDirectDrawSurface7), (DDSCAPS2 *) &zbuf_caps, &zbuf); if (!FAILED(hr)) { This->current_zbuffer = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, zbuf); IDirectDrawSurface7_Release(zbuf); } } if (This->current_zbuffer != NULL) { if (This->current_zbuffer->get_dirty_status(This->current_zbuffer, NULL)) { flush_zbuffer_to_GL(This, NULL, This->current_zbuffer); } } if ( ((d3dvtVertexType & D3DFVF_POSITION_MASK) != D3DFVF_XYZ) || ((d3dvtVertexType & D3DFVF_NORMAL) == 0) ) vertex_lighted = TRUE; /* Compute the number of active texture stages and set the various texture parameters */ num_active_stages = draw_primitive_handle_textures(This); /* And restore to handle '0' in the case we use glTexCorrd calls */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?