static bool renderchain_set_pass_size(cg_renderchain_t *chain, unsigned pass_index, unsigned width, unsigned height) { Pass *pass = (Pass*)&chain->passes[pass_index]; if (width != pass->info.tex_w || height != pass->info.tex_h) { d3d_texture_free(pass->tex); pass->info.tex_w = width; pass->info.tex_h = height; pass->tex = d3d_texture_new(chain->dev, NULL, width, height, 1, D3DUSAGE_RENDERTARGET, chain->passes.back().info.pass->fbo.fp_fbo ? D3DFMT_A32B32G32R32F : D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, 0, 0, 0, NULL, NULL); if (!pass->tex) return false; d3d_set_texture(chain->dev, 0, pass->tex); d3d_set_sampler_address_u(chain->dev, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(chain->dev, 0, D3DTADDRESS_BORDER); d3d_set_texture(chain->dev, 0, NULL); } return true; }
static bool renderchain_create_first_pass(void *data, const video_info_t *info) { d3d_video_t *d3d = (d3d_video_t*)data; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; xdk_renderchain_t *chain = (xdk_renderchain_t*)d3d->renderchain_data; chain->vertex_buf = d3d_vertex_buffer_new(d3dr, 4 * sizeof(Vertex), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, NULL); if (!chain->vertex_buf) return false; chain->tex = (LPDIRECT3DTEXTURE)d3d_texture_new(d3dr, NULL, chain->tex_w, chain->tex_h, 1, 0, info->rgb32 ? D3DFMT_LIN_X8R8G8B8 : D3DFMT_LIN_R5G6B5, 0, 0, 0, 0, NULL, NULL); if (!chain->tex) return false; d3d_set_sampler_address_u(d3dr, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(d3dr, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); #ifdef _XBOX1 d3dr->SetRenderState(D3DRS_LIGHTING, FALSE); #endif d3dr->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); d3dr->SetRenderState(D3DRS_ZENABLE, FALSE); if (!xdk_renderchain_init_shader_fvf(chain, chain)) return false; return true; }
static bool renderchain_create_first_pass(cg_renderchain_t *chain, const LinkInfo *info, unsigned fmt) { unsigned i; Pass pass; D3DXMATRIX ident; if (!chain) return false; D3DXMatrixIdentity(&ident); d3d_set_transform(chain->dev, D3DTS_WORLD, &ident); d3d_set_transform(chain->dev, D3DTS_VIEW, &ident); pass.info = *info; pass.last_width = 0; pass.last_height = 0; chain->prev.ptr = 0; for (i = 0; i < TEXTURES; i++) { chain->prev.last_width[i] = 0; chain->prev.last_height[i] = 0; chain->prev.vertex_buf[i] = d3d_vertex_buffer_new( chain->dev, 4 * sizeof(Vertex), 0, 0, D3DPOOL_DEFAULT, NULL); if (!chain->prev.vertex_buf[i]) return false; chain->prev.tex[i] = d3d_texture_new(chain->dev, NULL, info->tex_w, info->tex_h, 1, 0, (fmt == RETRO_PIXEL_FORMAT_RGB565) ? D3DFMT_R5G6B5 : D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, 0, 0, 0, NULL, NULL); if (!chain->prev.tex[i]) return false; d3d_set_texture(chain->dev, 0, chain->prev.tex[i]); d3d_set_sampler_minfilter(chain->dev, 0, d3d_translate_filter(info->pass->filter)); d3d_set_sampler_magfilter(chain->dev, 0, d3d_translate_filter(info->pass->filter)); d3d_set_sampler_address_u(chain->dev, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(chain->dev, 0, D3DTADDRESS_BORDER); d3d_set_texture(chain->dev, 0, NULL); } d3d9_cg_load_program(chain, &pass.fPrg, &pass.vPrg, info->pass->source.path, true); if (!cg_d3d9_renderchain_init_shader_fvf(chain, &pass)) return false; chain->passes.push_back(pass); return true; }
static void video_texture_png_load_d3d(struct texture_image *ti, enum texture_filter_type filter_type, uintptr_t *id) { id = (uintptr_t*)d3d_texture_new(NULL, NULL, ti->width, ti->height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 0, 0, 0, NULL, NULL); }
static bool d3d_overlay_load(void *data, const void *image_data, unsigned num_images) { unsigned i, y; d3d_video_t *d3d = (d3d_video_t*)data; const struct texture_image *images = (const struct texture_image*) image_data; if (!d3d) return false; d3d_free_overlays(d3d); d3d->overlays.resize(num_images); for (i = 0; i < num_images; i++) { D3DLOCKED_RECT d3dlr; unsigned width = images[i].width; unsigned height = images[i].height; overlay_t *overlay = (overlay_t*)&d3d->overlays[i]; overlay->tex = d3d_texture_new(d3d->dev, NULL, width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 0, 0, 0, NULL, NULL); if (!overlay->tex) { RARCH_ERR("[D3D]: Failed to create overlay texture\n"); return false; } if (d3d_lock_rectangle(overlay->tex, 0, &d3dlr, NULL, 0, D3DLOCK_NOSYSLOCK)) { uint32_t *dst = (uint32_t*)(d3dlr.pBits); const uint32_t *src = images[i].pixels; unsigned pitch = d3dlr.Pitch >> 2; for (y = 0; y < height; y++, dst += pitch, src += width) memcpy(dst, src, width << 2); d3d_unlock_rectangle(overlay->tex); } overlay->tex_w = width; overlay->tex_h = height; /* Default. Stretch to whole screen. */ d3d_overlay_tex_geom(d3d, i, 0, 0, 1, 1); d3d_overlay_vertex_geom(d3d, i, 0, 0, 1, 1); }
static bool cg_d3d9_renderchain_add_pass(void *data, const void *info_data) { Pass pass; const LinkInfo *info = (const LinkInfo*)info_data; cg_renderchain_t *chain = (cg_renderchain_t*)data; pass.info = *info; pass.last_width = 0; pass.last_height = 0; d3d9_cg_load_program(chain, &pass.fPrg, &pass.vPrg, info->pass->source.path, true); if (!cg_d3d9_renderchain_init_shader_fvf(chain, &pass)) return false; pass.vertex_buf = d3d_vertex_buffer_new(chain->dev, 4 * sizeof(Vertex), 0, 0, D3DPOOL_DEFAULT, NULL); if (!pass.vertex_buf) return false; pass.tex = d3d_texture_new( chain->dev, NULL, info->tex_w, info->tex_h, 1, D3DUSAGE_RENDERTARGET, chain->passes.back().info.pass->fbo.fp_fbo ? D3DFMT_A32B32G32R32F : D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, 0, 0, 0, NULL, NULL); if (!pass.tex) return false; d3d_set_texture(chain->dev, 0, pass.tex); d3d_set_sampler_address_u(chain->dev, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(chain->dev, 0, D3DTADDRESS_BORDER); d3d_set_texture(chain->dev, 0, NULL); chain->passes.push_back(pass); renderchain_log_info(chain, info); return true; }
static bool cg_d3d9_renderchain_add_lut(void *data, const char *id, const char *path, bool smooth) { lut_info info; cg_renderchain_t *chain = (cg_renderchain_t*)data; LPDIRECT3DTEXTURE lut = d3d_texture_new( chain->dev, path, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 0, 0, D3DFMT_FROM_FILE, D3DPOOL_MANAGED, smooth ? D3DX_FILTER_LINEAR : D3DX_FILTER_POINT, 0, 0, NULL, NULL ); RARCH_LOG("[D3D]: LUT texture loaded: %s.\n", path); info.tex = lut; info.smooth = smooth; strcpy(info.id, id); if (!lut) return false; d3d_set_texture(chain->dev, 0, lut); d3d_set_sampler_address_u(chain->dev, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(chain->dev, 0, D3DTADDRESS_BORDER); d3d_set_texture(chain->dev, 0, NULL); chain->luts.push_back(info); return true; }