mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
fix cubemap-to-ram
This commit is contained in:
parent
a41279a303
commit
942e64ae60
@ -1386,7 +1386,35 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend
|
||||
int xo, yo, w, h;
|
||||
dr->get_region_pixels_i(xo, yo, w, h);
|
||||
|
||||
tex->setup_2d_texture(w, h, Texture::T_unsigned_byte, Texture::F_rgb);
|
||||
Texture::Format format = tex->get_format();
|
||||
Texture::ComponentType component_type = tex->get_component_type();
|
||||
|
||||
switch (format) {
|
||||
case Texture::F_depth_component:
|
||||
case Texture::F_stencil_index:
|
||||
// Sorry, not (yet?) supported in pandadx.
|
||||
return false;
|
||||
|
||||
default:
|
||||
format = Texture::F_rgb;
|
||||
component_type = Texture::T_unsigned_byte;
|
||||
}
|
||||
|
||||
Texture::TextureType texture_type;
|
||||
if (z >= 0) {
|
||||
texture_type = Texture::TT_cube_map;
|
||||
} else {
|
||||
texture_type = Texture::TT_2d_texture;
|
||||
}
|
||||
|
||||
if (tex->get_x_size() != w || tex->get_y_size() != h ||
|
||||
tex->get_component_type() != component_type ||
|
||||
tex->get_format() != format ||
|
||||
tex->get_texture_type() != texture_type) {
|
||||
// Re-setup the texture; its properties have changed.
|
||||
tex->setup_texture(texture_type, w, h, tex->get_z_size(),
|
||||
component_type, format);
|
||||
}
|
||||
|
||||
rect.top = yo;
|
||||
rect.left = xo;
|
||||
@ -1488,7 +1516,7 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend
|
||||
}
|
||||
|
||||
DXTextureContext8::d3d_surface_to_texture(rect, temp_surface,
|
||||
copy_inverted, tex);
|
||||
copy_inverted, tex, z);
|
||||
|
||||
RELEASE(temp_surface, dxgsg8, "temp_surface", RELEASE_ONCE);
|
||||
|
||||
@ -2500,7 +2528,7 @@ do_issue_texture() {
|
||||
{
|
||||
_d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX,
|
||||
texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
|
||||
texcoord_dimensions = 4;
|
||||
texcoord_dimensions = 3;
|
||||
CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
|
||||
tex_mat = tex_mat->compose(camera_transform);
|
||||
}
|
||||
@ -2509,7 +2537,7 @@ do_issue_texture() {
|
||||
case TexGenAttrib::M_eye_position:
|
||||
_d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX,
|
||||
texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
|
||||
texcoord_dimensions = 4;
|
||||
texcoord_dimensions = 3;
|
||||
tex_mat = tex_mat->compose(_inv_cs_transform);
|
||||
break;
|
||||
|
||||
@ -2536,9 +2564,10 @@ do_issue_texture() {
|
||||
LMatrix4f m = tex_mat->get_mat();
|
||||
_d3d_device->SetTransform(get_tex_mat_sym(i), (D3DMATRIX *)m.get_data());
|
||||
DWORD transform_flags = texcoord_dimensions;
|
||||
//if (m.get_col3(3) != LVecBase3f::zero())
|
||||
{
|
||||
transform_flags |= D3DTTFF_PROJECTED;
|
||||
if (m.get_col(3) != LVecBase4f(0.0f, 0.0f, 0.0f, 1.0f)) {
|
||||
// If we have a projected texture matrix, we also need to
|
||||
// set D3DTTFF_COUNT4.
|
||||
transform_flags = D3DTTFF_COUNT4 | D3DTTFF_PROJECTED;
|
||||
}
|
||||
_d3d_device->SetTextureStageState(i, D3DTSS_TEXTURETRANSFORMFLAGS,
|
||||
transform_flags);
|
||||
|
@ -711,7 +711,7 @@ delete_texture() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
HRESULT DXTextureContext8::
|
||||
d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface8 *d3d_surface,
|
||||
bool inverted, Texture *result) {
|
||||
bool inverted, Texture *result, int z) {
|
||||
// still need custom conversion since d3d/d3dx has no way to convert
|
||||
// arbitrary fmt to ARGB in-memory user buffer
|
||||
|
||||
@ -723,8 +723,11 @@ d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface8 *d3d_surface,
|
||||
nassertr((num_components == 3) || (num_components == 4), E_FAIL); // cant handle anything else now
|
||||
nassertr(IS_VALID_PTR(d3d_surface), E_FAIL);
|
||||
|
||||
PTA_uchar ram_image = result->modify_ram_image();
|
||||
BYTE *buf = ram_image.p();
|
||||
BYTE *buf = result->modify_ram_image();
|
||||
if (z >= 0) {
|
||||
nassertr(z < result->get_z_size(), E_FAIL);
|
||||
buf += z * result->get_expected_ram_page_size();
|
||||
}
|
||||
|
||||
if (IsBadWritePtr(d3d_surface, sizeof(DWORD))) {
|
||||
dxgsg8_cat.error()
|
||||
|
@ -43,7 +43,8 @@ public:
|
||||
|
||||
static HRESULT d3d_surface_to_texture(RECT &source_rect,
|
||||
IDirect3DSurface8 *d3d_surface,
|
||||
bool inverted, Texture *result);
|
||||
bool inverted, Texture *result,
|
||||
int z);
|
||||
|
||||
private:
|
||||
HRESULT fill_d3d_texture_pixels();
|
||||
|
Loading…
x
Reference in New Issue
Block a user