mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -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;
|
int xo, yo, w, h;
|
||||||
dr->get_region_pixels_i(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.top = yo;
|
||||||
rect.left = xo;
|
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,
|
DXTextureContext8::d3d_surface_to_texture(rect, temp_surface,
|
||||||
copy_inverted, tex);
|
copy_inverted, tex, z);
|
||||||
|
|
||||||
RELEASE(temp_surface, dxgsg8, "temp_surface", RELEASE_ONCE);
|
RELEASE(temp_surface, dxgsg8, "temp_surface", RELEASE_ONCE);
|
||||||
|
|
||||||
@ -2500,7 +2528,7 @@ do_issue_texture() {
|
|||||||
{
|
{
|
||||||
_d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX,
|
_d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX,
|
||||||
texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
|
texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
|
||||||
texcoord_dimensions = 4;
|
texcoord_dimensions = 3;
|
||||||
CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
|
CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
|
||||||
tex_mat = tex_mat->compose(camera_transform);
|
tex_mat = tex_mat->compose(camera_transform);
|
||||||
}
|
}
|
||||||
@ -2509,7 +2537,7 @@ do_issue_texture() {
|
|||||||
case TexGenAttrib::M_eye_position:
|
case TexGenAttrib::M_eye_position:
|
||||||
_d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX,
|
_d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX,
|
||||||
texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
|
texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
|
||||||
texcoord_dimensions = 4;
|
texcoord_dimensions = 3;
|
||||||
tex_mat = tex_mat->compose(_inv_cs_transform);
|
tex_mat = tex_mat->compose(_inv_cs_transform);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2536,9 +2564,10 @@ do_issue_texture() {
|
|||||||
LMatrix4f m = tex_mat->get_mat();
|
LMatrix4f m = tex_mat->get_mat();
|
||||||
_d3d_device->SetTransform(get_tex_mat_sym(i), (D3DMATRIX *)m.get_data());
|
_d3d_device->SetTransform(get_tex_mat_sym(i), (D3DMATRIX *)m.get_data());
|
||||||
DWORD transform_flags = texcoord_dimensions;
|
DWORD transform_flags = texcoord_dimensions;
|
||||||
//if (m.get_col3(3) != LVecBase3f::zero())
|
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
|
||||||
transform_flags |= D3DTTFF_PROJECTED;
|
// set D3DTTFF_COUNT4.
|
||||||
|
transform_flags = D3DTTFF_COUNT4 | D3DTTFF_PROJECTED;
|
||||||
}
|
}
|
||||||
_d3d_device->SetTextureStageState(i, D3DTSS_TEXTURETRANSFORMFLAGS,
|
_d3d_device->SetTextureStageState(i, D3DTSS_TEXTURETRANSFORMFLAGS,
|
||||||
transform_flags);
|
transform_flags);
|
||||||
|
@ -711,7 +711,7 @@ delete_texture() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
HRESULT DXTextureContext8::
|
HRESULT DXTextureContext8::
|
||||||
d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface8 *d3d_surface,
|
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
|
// still need custom conversion since d3d/d3dx has no way to convert
|
||||||
// arbitrary fmt to ARGB in-memory user buffer
|
// 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((num_components == 3) || (num_components == 4), E_FAIL); // cant handle anything else now
|
||||||
nassertr(IS_VALID_PTR(d3d_surface), E_FAIL);
|
nassertr(IS_VALID_PTR(d3d_surface), E_FAIL);
|
||||||
|
|
||||||
PTA_uchar ram_image = result->modify_ram_image();
|
BYTE *buf = result->modify_ram_image();
|
||||||
BYTE *buf = ram_image.p();
|
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))) {
|
if (IsBadWritePtr(d3d_surface, sizeof(DWORD))) {
|
||||||
dxgsg8_cat.error()
|
dxgsg8_cat.error()
|
||||||
|
@ -43,7 +43,8 @@ public:
|
|||||||
|
|
||||||
static HRESULT d3d_surface_to_texture(RECT &source_rect,
|
static HRESULT d3d_surface_to_texture(RECT &source_rect,
|
||||||
IDirect3DSurface8 *d3d_surface,
|
IDirect3DSurface8 *d3d_surface,
|
||||||
bool inverted, Texture *result);
|
bool inverted, Texture *result,
|
||||||
|
int z);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HRESULT fill_d3d_texture_pixels();
|
HRESULT fill_d3d_texture_pixels();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user