Browse Source

fix bugs with shaders and with pre-compressed textures

David Rose 17 years ago
parent
commit
d6f8308127

+ 10 - 6
panda/src/dxgsg8/dxTextureContext8.cxx

@@ -342,7 +342,7 @@ create_texture(DXScreenData &scrn) {
                         target_pixel_format = D3DFMT_##FMT;                 \
                         target_pixel_format = D3DFMT_##FMT;                 \
                         goto found_matching_format; }
                         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
     // if the texture is already compressed, we need to choose the
     // corresponding format, otherwise we might end up
     // corresponding format, otherwise we might end up
     // cross-compressing from e.g. DXT5 to DXT3
     // cross-compressing from e.g. DXT5 to DXT3
@@ -363,9 +363,8 @@ create_texture(DXScreenData &scrn) {
       CHECK_FOR_FMT(DXT5);
       CHECK_FOR_FMT(DXT5);
       break;
       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) {
   if (compress_texture) {
@@ -1485,7 +1484,7 @@ fill_d3d_texture_pixels(DXScreenData &scrn) {
   D3DFORMAT source_format = _d3d_format;
   D3DFORMAT source_format = _d3d_format;
 
 
   // check for compressed textures and adjust source_format accordingly
   // check for compressed textures and adjust source_format accordingly
-  switch (tex->get_ram_image_compression()) {
+  switch (image_compression) {
   case Texture::CM_dxt1:
   case Texture::CM_dxt1:
     source_format = D3DFMT_DXT1;
     source_format = D3DFMT_DXT1;
     break;
     break;
@@ -1579,7 +1578,12 @@ fill_d3d_volume_texture_pixels(DXScreenData &scrn) {
     image_compression = tex->get_ram_image_compression();
     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 = tex->get_uncompressed_ram_image();
     image_compression = Texture::CM_off;
     image_compression = Texture::CM_off;
   }    
   }    

+ 12 - 11
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -1383,7 +1383,7 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
   _vertex_array_shader_context = _current_shader_context;
   _vertex_array_shader_context = _current_shader_context;
 
 
   const GeomVertexFormat *format = _data_reader->get_format ( );
   const GeomVertexFormat *format = _data_reader->get_format ( );
-  const GeomVertexArrayDataHandle *data;
+  const GeomVertexArrayDataHandle *data = NULL;
   int number_of_arrays = _data_reader -> get_num_arrays ( );
   int number_of_arrays = _data_reader -> get_num_arrays ( );
 
 
   if (_current_shader_context && number_of_arrays > 1) {
   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)
           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);
     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);
   nassertr(vbc != (VertexBufferContext *)NULL, false);
   if (!apply_vertex_buffer(vbc, _current_shader_context, data, force, name)) {
   if (!apply_vertex_buffer(vbc, _current_shader_context, data, force, name)) {
     return false;
     return false;

+ 10 - 6
panda/src/dxgsg9/dxTextureContext9.cxx

@@ -352,7 +352,7 @@ create_texture(DXScreenData &scrn) {
                         target_pixel_format = D3DFMT_##FMT;                 \
                         target_pixel_format = D3DFMT_##FMT;                 \
                         goto found_matching_format; }
                         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
     // if the texture is already compressed, we need to choose the
     // corresponding format, otherwise we might end up
     // corresponding format, otherwise we might end up
     // cross-compressing from e.g. DXT5 to DXT3
     // cross-compressing from e.g. DXT5 to DXT3
@@ -373,9 +373,8 @@ create_texture(DXScreenData &scrn) {
       CHECK_FOR_FMT(DXT5);
       CHECK_FOR_FMT(DXT5);
       break;
       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) {
   if (compress_texture) {
@@ -1662,7 +1661,12 @@ fill_d3d_texture_pixels(DXScreenData &scrn) {
     image_compression = tex->get_ram_image_compression();
     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 = tex->get_uncompressed_ram_image();
     image_compression = Texture::CM_off;
     image_compression = Texture::CM_off;
   }    
   }    
@@ -1718,7 +1722,7 @@ fill_d3d_texture_pixels(DXScreenData &scrn) {
   D3DFORMAT source_format = _d3d_format;
   D3DFORMAT source_format = _d3d_format;
   
   
   // check for compressed textures and adjust source_format accordingly
   // check for compressed textures and adjust source_format accordingly
-  switch (tex->get_ram_image_compression()) {
+  switch (image_compression) {
   case Texture::CM_dxt1:
   case Texture::CM_dxt1:
     source_format = D3DFMT_DXT1;
     source_format = D3DFMT_DXT1;
     break;
     break;

+ 4 - 0
panda/src/glstuff/glShaderContext_src.cxx

@@ -386,6 +386,10 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg) {
     GLP(Enable)(target);
     GLP(Enable)(target);
 
 
     gsg->apply_texture(tc);
     gsg->apply_texture(tc);
+    if (!gsg->update_texture(tc, false)) {
+      GLP(Disable)(target);
+      continue;
+    }
   }
   }
   cg_report_errors();
   cg_report_errors();
   if (glGetError() != GL_NO_ERROR) {
   if (glGetError() != GL_NO_ERROR) {