From d6f8308127999cb355c21961dc6019bedec76ead Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 2 Sep 2008 21:48:13 +0000 Subject: [PATCH] fix bugs with shaders and with pre-compressed textures --- panda/src/dxgsg8/dxTextureContext8.cxx | 16 ++++++++----- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 23 ++++++++++--------- panda/src/dxgsg9/dxTextureContext9.cxx | 16 ++++++++----- panda/src/glstuff/glShaderContext_src.cxx | 4 ++++ 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/panda/src/dxgsg8/dxTextureContext8.cxx b/panda/src/dxgsg8/dxTextureContext8.cxx index 75a42209d8..b9aecf680a 100644 --- a/panda/src/dxgsg8/dxTextureContext8.cxx +++ b/panda/src/dxgsg8/dxTextureContext8.cxx @@ -342,7 +342,7 @@ create_texture(DXScreenData &scrn) { target_pixel_format = D3DFMT_##FMT; \ goto found_matching_format; } - if (texture_stored_compressed){ + if (texture_stored_compressed && compress_texture) { // if the texture is already compressed, we need to choose the // corresponding format, otherwise we might end up // cross-compressing from e.g. DXT5 to DXT3 @@ -363,9 +363,8 @@ create_texture(DXScreenData &scrn) { CHECK_FOR_FMT(DXT5); break; } - // if we can't support the texture's compressed image, we can't - // load the texture. - goto error_exit; + + // We don't support the compressed format. Fall through. } if (compress_texture) { @@ -1485,7 +1484,7 @@ fill_d3d_texture_pixels(DXScreenData &scrn) { D3DFORMAT source_format = _d3d_format; // check for compressed textures and adjust source_format accordingly - switch (tex->get_ram_image_compression()) { + switch (image_compression) { case Texture::CM_dxt1: source_format = D3DFMT_DXT1; break; @@ -1579,7 +1578,12 @@ fill_d3d_volume_texture_pixels(DXScreenData &scrn) { image_compression = tex->get_ram_image_compression(); } - if (!scrn._dxgsg8->get_supports_compressed_texture_format(image_compression)) { + if (!scrn._dxgsg8->get_supports_compressed_texture_format(image_compression) || + tex->get_x_size() < 4 || tex->get_y_size() < 4) { + // If we don't support this particular compression method, or in + // any case if the texture is too small (DirectX won't accept a + // small compressed texture), then fetch and load the uncompressed + // version instead. image = tex->get_uncompressed_ram_image(); image_compression = Texture::CM_off; } diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 22070687c0..0cd1d6f034 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -1383,7 +1383,7 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, _vertex_array_shader_context = _current_shader_context; const GeomVertexFormat *format = _data_reader->get_format ( ); - const GeomVertexArrayDataHandle *data; + const GeomVertexArrayDataHandle *data = NULL; int number_of_arrays = _data_reader -> get_num_arrays ( ); if (_current_shader_context && number_of_arrays > 1) { @@ -1444,15 +1444,13 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, if (number_of_columns >= vertex_element_array -> total_elements) { -// check not implemented yet -dxgsg9_cat.error ( ) << "vertex_element_type_array check not implemented yet\n"; - -// build a vertex_element_type_array from data - -// compare both vertex_element_type_array for a match -vertex_element_array -> vertex_element_type_array; - - + // check not implemented yet + dxgsg9_cat.error ( ) << "vertex_element_type_array check not implemented yet\n"; + + // build a vertex_element_type_array from data + + // compare both vertex_element_type_array for a match + vertex_element_array -> vertex_element_type_array; } } @@ -1490,7 +1488,10 @@ vertex_element_array -> vertex_element_type_array; data = _data_reader->get_array_reader(0); } - VertexBufferContext *vbc = ((GeomVertexArrayData *)(data->get_object()))->prepare_now(get_prepared_objects(), this); + nassertr(data != (GeomVertexArrayDataHandle *)NULL, false); + GeomVertexArrayData *data_obj = (GeomVertexArrayData *)data->get_object(); + nassertr(data_obj != (GeomVertexArrayData *)NULL, false); + VertexBufferContext *vbc = data_obj->prepare_now(get_prepared_objects(), this); nassertr(vbc != (VertexBufferContext *)NULL, false); if (!apply_vertex_buffer(vbc, _current_shader_context, data, force, name)) { return false; diff --git a/panda/src/dxgsg9/dxTextureContext9.cxx b/panda/src/dxgsg9/dxTextureContext9.cxx index 7f994cf002..c3655491e9 100755 --- a/panda/src/dxgsg9/dxTextureContext9.cxx +++ b/panda/src/dxgsg9/dxTextureContext9.cxx @@ -352,7 +352,7 @@ create_texture(DXScreenData &scrn) { target_pixel_format = D3DFMT_##FMT; \ goto found_matching_format; } - if (texture_stored_compressed){ + if (texture_stored_compressed && compress_texture) { // if the texture is already compressed, we need to choose the // corresponding format, otherwise we might end up // cross-compressing from e.g. DXT5 to DXT3 @@ -373,9 +373,8 @@ create_texture(DXScreenData &scrn) { CHECK_FOR_FMT(DXT5); break; } - // if we can't support the texture's compressed image, we can't - // load the texture. - goto error_exit; + + // We don't support the compressed format. Fall through. } if (compress_texture) { @@ -1662,7 +1661,12 @@ fill_d3d_texture_pixels(DXScreenData &scrn) { image_compression = tex->get_ram_image_compression(); } - if (!scrn._dxgsg9->get_supports_compressed_texture_format(image_compression)) { + if (!scrn._dxgsg9->get_supports_compressed_texture_format(image_compression) || + tex->get_x_size() < 4 || tex->get_y_size() < 4) { + // If we don't support this particular compression method, or in + // any case if the texture is too small (DirectX won't accept a + // small compressed texture), then fetch and load the uncompressed + // version instead. image = tex->get_uncompressed_ram_image(); image_compression = Texture::CM_off; } @@ -1718,7 +1722,7 @@ fill_d3d_texture_pixels(DXScreenData &scrn) { D3DFORMAT source_format = _d3d_format; // check for compressed textures and adjust source_format accordingly - switch (tex->get_ram_image_compression()) { + switch (image_compression) { case Texture::CM_dxt1: source_format = D3DFMT_DXT1; break; diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 0ed61a3b7c..c57f98c746 100755 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -386,6 +386,10 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg) { GLP(Enable)(target); gsg->apply_texture(tc); + if (!gsg->update_texture(tc, false)) { + GLP(Disable)(target); + continue; + } } cg_report_errors(); if (glGetError() != GL_NO_ERROR) {