From c9b27bd43665e427232a8225659bf79dc9c6d5ac Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 13 Jan 2006 21:50:04 +0000 Subject: [PATCH] formally remove pandadx7 support --- panda/metalibs/pandadx7/Sources.pp | 23 - panda/metalibs/pandadx7/pandadx7.cxx | 27 - panda/metalibs/pandadx7/pandadx7.h | 13 - panda/src/dxgsg7/Sources.pp | 36 - panda/src/dxgsg7/config_dxgsg7.cxx | 139 - panda/src/dxgsg7/config_dxgsg7.h | 60 - panda/src/dxgsg7/dxGeomMunger7.I | 46 - panda/src/dxgsg7/dxGeomMunger7.cxx | 156 - panda/src/dxgsg7/dxGeomMunger7.h | 74 - panda/src/dxgsg7/dxGraphicsStateGuardian7.I | 130 - panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx | 2519 ----------------- panda/src/dxgsg7/dxGraphicsStateGuardian7.h | 239 -- panda/src/dxgsg7/dxTextureContext7.I | 29 - panda/src/dxgsg7/dxTextureContext7.cxx | 1955 ------------- panda/src/dxgsg7/dxTextureContext7.h | 78 - panda/src/dxgsg7/dxgsg7_composite.cxx | 1 - panda/src/dxgsg7/dxgsg7_composite1.cxx | 7 - panda/src/dxgsg7/dxgsg7base.cxx | 1516 ---------- panda/src/dxgsg7/dxgsg7base.h | 129 - panda/src/dxgsg7/wdxGraphicsPipe7.I | 17 - panda/src/dxgsg7/wdxGraphicsPipe7.cxx | 126 - panda/src/dxgsg7/wdxGraphicsPipe7.h | 75 - panda/src/dxgsg7/wdxGraphicsWindow7.I | 17 - panda/src/dxgsg7/wdxGraphicsWindow7.cxx | 1330 --------- panda/src/dxgsg7/wdxGraphicsWindow7.h | 87 - 25 files changed, 8829 deletions(-) delete mode 100644 panda/metalibs/pandadx7/Sources.pp delete mode 100644 panda/metalibs/pandadx7/pandadx7.cxx delete mode 100644 panda/metalibs/pandadx7/pandadx7.h delete mode 100644 panda/src/dxgsg7/Sources.pp delete mode 100644 panda/src/dxgsg7/config_dxgsg7.cxx delete mode 100644 panda/src/dxgsg7/config_dxgsg7.h delete mode 100644 panda/src/dxgsg7/dxGeomMunger7.I delete mode 100755 panda/src/dxgsg7/dxGeomMunger7.cxx delete mode 100644 panda/src/dxgsg7/dxGeomMunger7.h delete mode 100644 panda/src/dxgsg7/dxGraphicsStateGuardian7.I delete mode 100644 panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx delete mode 100644 panda/src/dxgsg7/dxGraphicsStateGuardian7.h delete mode 100755 panda/src/dxgsg7/dxTextureContext7.I delete mode 100644 panda/src/dxgsg7/dxTextureContext7.cxx delete mode 100644 panda/src/dxgsg7/dxTextureContext7.h delete mode 100644 panda/src/dxgsg7/dxgsg7_composite.cxx delete mode 100644 panda/src/dxgsg7/dxgsg7_composite1.cxx delete mode 100644 panda/src/dxgsg7/dxgsg7base.cxx delete mode 100644 panda/src/dxgsg7/dxgsg7base.h delete mode 100644 panda/src/dxgsg7/wdxGraphicsPipe7.I delete mode 100644 panda/src/dxgsg7/wdxGraphicsPipe7.cxx delete mode 100644 panda/src/dxgsg7/wdxGraphicsPipe7.h delete mode 100644 panda/src/dxgsg7/wdxGraphicsWindow7.I delete mode 100644 panda/src/dxgsg7/wdxGraphicsWindow7.cxx delete mode 100644 panda/src/dxgsg7/wdxGraphicsWindow7.h diff --git a/panda/metalibs/pandadx7/Sources.pp b/panda/metalibs/pandadx7/Sources.pp deleted file mode 100644 index ffd0ccc6da..0000000000 --- a/panda/metalibs/pandadx7/Sources.pp +++ /dev/null @@ -1,23 +0,0 @@ -#define BUILD_DIRECTORY $[HAVE_DX] - -// DIR_TYPE "metalib" indicates we are building a shared library that -// consists mostly of references to other shared libraries. Under -// Windows, this directly produces a DLL (as opposed to the regular -// src libraries, which don't produce anything but a pile of OBJ files -// under Windows). - -#define DIR_TYPE metalib -#define BUILDING_DLL BUILDING_PANDADX - -#define COMPONENT_LIBS \ - dxgsg7 -#define LOCAL_LIBS gsgbase display express -#define OTHER_LIBS dtoolconfig dtool - -#begin metalib_target - #define TARGET pandadx7 - #define SOURCES pandadx7.cxx - #define WIN_SYS_LIBS \ - ddraw.lib dxguid.lib winmm.lib \ - kernel32.lib gdi32.lib user32.lib $[WIN_SYS_LIBS] -#end metalib_target diff --git a/panda/metalibs/pandadx7/pandadx7.cxx b/panda/metalibs/pandadx7/pandadx7.cxx deleted file mode 100644 index a718930f58..0000000000 --- a/panda/metalibs/pandadx7/pandadx7.cxx +++ /dev/null @@ -1,27 +0,0 @@ -// Filename: pandadx7.cxx -// Created by: drose (15May00) -// -//////////////////////////////////////////////////////////////////// - -#include "pandadx7.h" - -#include "config_dxgsg7.h" - -// By including checkPandaVersion.h, we guarantee that runtime -// attempts to load libpandadx7.dll will fail if they -// inadvertently link with the wrong version of libdtool.dll. - -#include "checkPandaVersion.h" - -//////////////////////////////////////////////////////////////////// -// Function: init_libpandadx7 -// Description: Initializes the library. This must be called at -// least once before any of the functions or classes in -// this library can be used. Normally it will be -// called by the static initializers and need not be -// called explicitly, but special cases exist. -//////////////////////////////////////////////////////////////////// -void -init_libpandadx7() { - init_libdxgsg7(); -} diff --git a/panda/metalibs/pandadx7/pandadx7.h b/panda/metalibs/pandadx7/pandadx7.h deleted file mode 100644 index c9a20ce245..0000000000 --- a/panda/metalibs/pandadx7/pandadx7.h +++ /dev/null @@ -1,13 +0,0 @@ -// Filename: pandadx7.h -// Created by: drose (2Jan01) -// -//////////////////////////////////////////////////////////////////// - -#ifndef PANDADX7_H -#define PANDADX7_H - -#include "pandabase.h" - -EXPCL_PANDADX void init_libpandadx7(); - -#endif diff --git a/panda/src/dxgsg7/Sources.pp b/panda/src/dxgsg7/Sources.pp deleted file mode 100644 index 445c5d5f9f..0000000000 --- a/panda/src/dxgsg7/Sources.pp +++ /dev/null @@ -1,36 +0,0 @@ -#define BUILD_DIRECTORY $[HAVE_DX] - -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m -#define USE_PACKAGES dx - -// We link with the DX8 libraries, because they're a superset of DX7 -// anyway, and it means we don't need to have the DX7 SDK available. -#define WIN_SYS_LIBS \ - d3d8.lib d3dx8.lib dxerr8.lib - -#begin lib_target - - #define TARGET dxgsg7 - #define LOCAL_LIBS \ - gsgmisc gsgbase gobj display windisplay \ - putil linmath mathutil pnmimage event - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx - - #define SOURCES \ - dxGraphicsStateGuardian7.cxx \ - dxGeomMunger7.I dxGeomMunger7.h \ - dxTextureContext7.I dxTextureContext7.h \ - wdxGraphicsPipe7.I wdxGraphicsPipe7.h \ - wdxGraphicsWindow7.I wdxGraphicsWindow7.h - $[INSTALL_HEADERS] - - #define INCLUDED_SOURCES \ - config_dxgsg7.cxx \ - dxgsg7base.cxx \ - dxGeomMunger7.cxx \ - dxTextureContext7.cxx \ - wdxGraphicsPipe7.cxx wdxGraphicsWindow7.cxx - -#end lib_target diff --git a/panda/src/dxgsg7/config_dxgsg7.cxx b/panda/src/dxgsg7/config_dxgsg7.cxx deleted file mode 100644 index dc4a520ea1..0000000000 --- a/panda/src/dxgsg7/config_dxgsg7.cxx +++ /dev/null @@ -1,139 +0,0 @@ -// Filename: config_dxgsg.cxx -// Created by: drose (06Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#include "config_dxgsg7.h" -#include "dxGraphicsStateGuardian7.h" -#include "dxTextureContext7.h" -#include "dxGeomMunger7.h" -#include "wdxGraphicsPipe7.h" -#include "wdxGraphicsWindow7.h" -#include "graphicsPipeSelection.h" -#include "pandaSystem.h" - -#include "dconfig.h" - -Configure(config_dxgsg7); -NotifyCategoryDef(dxgsg7, ":display:gsg"); -NotifyCategoryDef(wdxdisplay7, "display"); - -// Configure this to TRUE if you want DirectX to control the entire screen, -// If false, it will just blit into a window. -ConfigVariableBool dx_full_screen -("dx-full-screen", false); - -// enable this to turn on full-screen anti-aliasing, if the HW supports it -// this var is also used in wdxGraphicsWindows.cxx -ConfigVariableBool dx_full_screen_antialiasing -("dx-antialias", false); - -// if true, if card only supports per-vertex fog, it will be treated as no-HW fog capability -ConfigVariableBool dx_no_vertex_fog -("dx-no-vertex-fog", false); - -#ifndef NDEBUG -// debugging flag -// values are same as D3DCULL enumtype, 0 - no force, 1 - force none, 2 - force CW, 3 - force CCW -ConfigVariableInt dx_force_backface_culling -("dx-force-backface-culling", 0); -#endif - -ConfigVariableBool dx_mipmap_everything -("dx-mipmap-everything", false); -ConfigVariableBool dx_ignore_mipmaps -("dx-ignore-mipmaps", false); - -// if this is set, more accurate but more expensive fog computations are performed -ConfigVariableBool dx_use_rangebased_fog -("dx-use-rangebased-fog", false); -ConfigVariableBool dx_force_16bpptextures -("dx-force-16bpptextures", false); -ConfigVariableBool dx_no_dithering -("dx-no-dithering", false); -ConfigVariableBool dx_force_16bpp_zbuffer -("dx-force-16bpp-zbuffer", false); -ConfigVariableBool dx_do_vidmemsize_check -("do-vidmemsize-check", true); -// Setting this true theoretically hinders render performance, because -// it forces the FPU to go through some extra work to clean itself up -// after rendering a frame, but the performance cost seems to be -// small. On the other hand, setting it false can force the -// application to run in single-precision arithmetic mode, even if -// it believes it is using double-precision variables. -ConfigVariableBool dx_preserve_fpu_state -("dx-preserve-fpu-state", true); - -ConfigVariableBool dx_broken_max_index -("dx-broken-max-index", false, - PRC_DESC("Configure this true if you have a buggy graphics driver that " - "doesn't correctly implement the third parameter, NumVertices, " - "of DrawIndexedPrimitive(). In particular, the NVIDIA Quadro " - "driver version 6.14.10.7184 seems to treat this as a maximum " - "vertex index, rather than a delta between the maximum and " - "minimum vertex index. Turn this on if you are seeing stray " - "triangles, or you are not seeing all of your triangles. Enabling " - "this should work around this bug, at the cost of some additional " - "rendering overhead on the GPU.")); - -#ifdef _DEBUG -ConfigVariableDouble dx_global_miplevel_bias -("dx-global-miplevel-bias", 0.0); -ConfigVariableBool dx_debug_view_mipmaps -("dx-debug-view-mipmaps", false); -ConfigVariableBool dx_force_anisotropic_filtering -("dx-force-anisotropic-filtering", false); -#endif - -// set 'retained-mode #t' and this to have prepare_geom concatenate all tristrips within a geom -// together using degenerate tris -ConfigVariableBool link_tristrips -("link-tristrips", false); - -ConfigureFn(config_dxgsg7) { - init_libdxgsg7(); -} - -//////////////////////////////////////////////////////////////////// -// Function: init_libdxgsg7 -// Description: Initializes the library. This must be called at -// least once before any of the functions or classes in -// this library can be used. Normally it will be -// called by the static initializers and need not be -// called explicitly, but special cases exist. -//////////////////////////////////////////////////////////////////// -void -init_libdxgsg7() { - static bool initialized = false; - if (initialized) { - return; - } - initialized = true; - - DXGraphicsStateGuardian7::init_type(); - DXTextureContext7::init_type(); - DXGeomMunger7::init_type(); - - wdxGraphicsPipe7::init_type(); - wdxGraphicsWindow7::init_type(); - - GraphicsPipeSelection *selection = GraphicsPipeSelection::get_global_ptr(); - selection->add_pipe_type(wdxGraphicsPipe7::get_class_type(), - wdxGraphicsPipe7::pipe_constructor); - - PandaSystem *ps = PandaSystem::get_global_ptr(); - ps->add_system("DirectX7"); -} diff --git a/panda/src/dxgsg7/config_dxgsg7.h b/panda/src/dxgsg7/config_dxgsg7.h deleted file mode 100644 index 9d3a529453..0000000000 --- a/panda/src/dxgsg7/config_dxgsg7.h +++ /dev/null @@ -1,60 +0,0 @@ -// Filename: config_dxgsg7.h -// Created by: drose (06Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_DXGSG7_H -#define CONFIG_DXGSG7_H - -#include "pandabase.h" -#include "notifyCategoryProxy.h" -#include "configVariableBool.h" -#include "configVariableInt.h" -#include "configVariableDouble.h" - -NotifyCategoryDecl(dxgsg7, EXPCL_PANDADX, EXPTP_PANDADX); -NotifyCategoryDecl(wdxdisplay7, EXPCL_PANDADX, EXPTP_PANDADX); - -extern ConfigVariableBool dx_full_screen; -extern ConfigVariableBool dx_no_vertex_fog; -extern ConfigVariableBool dx_full_screen_antialiasing; -extern ConfigVariableBool dx_use_rangebased_fog; -extern ConfigVariableBool link_tristrips; - -// debug flags we might want to use in full optimized build -extern ConfigVariableBool dx_ignore_mipmaps; -extern ConfigVariableBool dx_mipmap_everything; -extern ConfigVariableBool dx_force_16bpptextures; -extern ConfigVariableBool dx_no_dithering; -extern ConfigVariableBool dx_force_16bpp_zbuffer; -extern ConfigVariableBool dx_do_vidmemsize_check; -extern ConfigVariableBool dx_preserve_fpu_state; - -#ifndef NDEBUG -extern ConfigVariableInt dx_force_backface_culling; -#endif - -extern ConfigVariableBool dx_broken_max_index; - -#ifdef _DEBUG -extern ConfigVariableDouble dx_global_miplevel_bias; -extern ConfigVariableBool dx_debug_view_mipmaps; -extern ConfigVariableBool dx_force_anisotropic_filtering; -#endif - -extern EXPCL_PANDADX void init_libdxgsg7(); - -#endif diff --git a/panda/src/dxgsg7/dxGeomMunger7.I b/panda/src/dxgsg7/dxGeomMunger7.I deleted file mode 100644 index 99a1556681..0000000000 --- a/panda/src/dxgsg7/dxGeomMunger7.I +++ /dev/null @@ -1,46 +0,0 @@ -// Filename: dxGeomMunger7.I -// Created by: drose (11Mar05) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: DXGeomMunger7::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DXGeomMunger7:: -DXGeomMunger7(GraphicsStateGuardian *gsg, const RenderState *state) : - StandardMunger(gsg, state, 1, NT_packed_dabc, C_color), - _texture(state->get_texture()), - _tex_gen(state->get_tex_gen()) -{ - if (_texture != (TextureAttrib *)NULL) { - _texture = _texture->filter_to_max(gsg->get_max_texture_stages()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGeomMunger7::operator new -// Access: Public -// Description: Calls up to do_operator_new() to implement the -// low-overhead allocation/deallocation for this type of -// GeomMunger. -//////////////////////////////////////////////////////////////////// -INLINE void *DXGeomMunger7:: -operator new(size_t size) { - return do_operator_new(size, &_deleted_chain); -} diff --git a/panda/src/dxgsg7/dxGeomMunger7.cxx b/panda/src/dxgsg7/dxGeomMunger7.cxx deleted file mode 100755 index 1bc3c4f728..0000000000 --- a/panda/src/dxgsg7/dxGeomMunger7.cxx +++ /dev/null @@ -1,156 +0,0 @@ -// Filename: dxGeomMunger7.cxx -// Created by: drose (11Mar05) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#include "dxGeomMunger7.h" -#include "geomVertexReader.h" -#include "geomVertexWriter.h" -#include "config_dxgsg7.h" - -GeomMunger *DXGeomMunger7::_deleted_chain = NULL; -TypeHandle DXGeomMunger7::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DXGeomMunger7::munge_format_impl -// Access: Protected, Virtual -// Description: Given a source GeomVertexFormat, converts it if -// necessary to the appropriate format for rendering. -//////////////////////////////////////////////////////////////////// -CPT(GeomVertexFormat) DXGeomMunger7:: -munge_format_impl(const GeomVertexFormat *orig, - const GeomVertexAnimationSpec &animation) { - nassertr(animation.get_animation_type() != AT_hardware, NULL); - - // We have to build a completely new format that includes only the - // appropriate components, in the appropriate order, in just one - // array. - PT(GeomVertexFormat) new_format = new GeomVertexFormat(*orig); - PT(GeomVertexArrayFormat) new_array_format = new GeomVertexArrayFormat; - - const GeomVertexColumn *vertex_type = orig->get_vertex_column(); - const GeomVertexColumn *normal_type = orig->get_normal_column(); - const GeomVertexColumn *color_type = orig->get_color_column(); - - if (vertex_type != (const GeomVertexColumn *)NULL) { - new_array_format->add_column - (InternalName::get_vertex(), 3, NT_float32, - vertex_type->get_contents()); - new_format->remove_column(vertex_type->get_name()); - - } else { - // If we don't have a vertex type, not much we can do. - return orig; - } - - if (normal_type != (const GeomVertexColumn *)NULL) { - new_array_format->add_column - (InternalName::get_normal(), 3, NT_float32, C_vector); - new_format->remove_column(normal_type->get_name()); - } - - if (color_type != (const GeomVertexColumn *)NULL) { - new_array_format->add_column - (InternalName::get_color(), 1, NT_packed_dabc, C_color); - new_format->remove_column(color_type->get_name()); - } - - // To support multitexture, we will need to add all of the relevant - // texcoord types, and in the correct order. - - // Now set up each of the active texture coordinate stages--or at - // least those for which we're not generating texture coordinates - // automatically. - - // Now copy all of the texture coordinates in, in order by stage - // index. But we have to reuse previous columns. - if (_texture != (TextureAttrib *)NULL) { - typedef pset UsedStages; - UsedStages used_stages; - - int num_stages = _texture->get_num_on_stages(); - for (int i = 0; i < num_stages; ++i) { - TextureStage *stage = _texture->get_on_stage(i); - - const InternalName *name = stage->get_texcoord_name(); - if (used_stages.insert(name).second) { - // This is the first time we've encountered this texcoord name. - const GeomVertexColumn *texcoord_type = orig->get_column(name); - - if (texcoord_type != (const GeomVertexColumn *)NULL) { - new_array_format->add_column - (name, texcoord_type->get_num_values(), NT_float32, C_texcoord); - } else { - // We have to add something as a placeholder, even if the - // texture coordinates aren't defined. - new_array_format->add_column(name, 2, NT_float32, C_texcoord); - } - new_format->remove_column(name); - } - } - } - - // Make sure the FVF-style array we just built up is first in the - // list. - new_format->insert_array(0, new_array_format); - - return GeomVertexFormat::register_format(new_format); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGeomMunger7::compare_to_impl -// Access: Protected, Virtual -// Description: Called to compare two GeomMungers who are known to be -// of the same type, for an apples-to-apples comparison. -// This will never be called on two pointers of a -// different type. -//////////////////////////////////////////////////////////////////// -int DXGeomMunger7:: -compare_to_impl(const GeomMunger *other) const { - const DXGeomMunger7 *om = DCAST(DXGeomMunger7, other); - if (_texture != om->_texture) { - return _texture < om->_texture ? -1 : 1; - } - if (_tex_gen != om->_tex_gen) { - return _tex_gen < om->_tex_gen ? -1 : 1; - } - - return StandardMunger::compare_to_impl(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGeomMunger7::geom_compare_to_impl -// Access: Protected, Virtual -// Description: Called to compare two GeomMungers who are known to be -// of the same type, for an apples-to-apples comparison. -// This will never be called on two pointers of a -// different type. -//////////////////////////////////////////////////////////////////// -int DXGeomMunger7:: -geom_compare_to_impl(const GeomMunger *other) const { - // Unlike GLGeomMunger, we do consider _texture and _tex_gen - // important for this purpose, since they control the number and - // order of texture coordinates we might put into the FVF. - const DXGeomMunger7 *om = DCAST(DXGeomMunger7, other); - if (_texture != om->_texture) { - return _texture < om->_texture ? -1 : 1; - } - if (_tex_gen != om->_tex_gen) { - return _tex_gen < om->_tex_gen ? -1 : 1; - } - - return StandardMunger::geom_compare_to_impl(other); -} diff --git a/panda/src/dxgsg7/dxGeomMunger7.h b/panda/src/dxgsg7/dxGeomMunger7.h deleted file mode 100644 index 456542e9c6..0000000000 --- a/panda/src/dxgsg7/dxGeomMunger7.h +++ /dev/null @@ -1,74 +0,0 @@ -// Filename: dxGeomMunger7.h -// Created by: drose (11Mar05) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DXGEOMMUNGER7_H -#define DXGEOMMUNGER7_H - -#include "pandabase.h" -#include "standardMunger.h" -#include "graphicsStateGuardian.h" - -//////////////////////////////////////////////////////////////////// -// Class : DXGeomMunger7 -// Description : This specialization on GeomMunger finesses vertices -// for DirectX rendering. In particular, it makes sure -// colors are stored in DirectX's packed_argb format, -// and that all relevant components are packed into a -// single array, in the correct order. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDADX DXGeomMunger7 : public StandardMunger { -public: - INLINE DXGeomMunger7(GraphicsStateGuardian *gsg, const RenderState *state); - -protected: - virtual CPT(GeomVertexFormat) munge_format_impl(const GeomVertexFormat *orig, - const GeomVertexAnimationSpec &animation); - - virtual int compare_to_impl(const GeomMunger *other) const; - virtual int geom_compare_to_impl(const GeomMunger *other) const; - -public: - INLINE void *operator new(size_t size); - -private: - CPT(TextureAttrib) _texture; - CPT(TexGenAttrib) _tex_gen; - - static GeomMunger *_deleted_chain; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - StandardMunger::init_type(); - register_type(_type_handle, "DXGeomMunger7", - StandardMunger::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "dxGeomMunger7.I" - -#endif diff --git a/panda/src/dxgsg7/dxGraphicsStateGuardian7.I b/panda/src/dxgsg7/dxGraphicsStateGuardian7.I deleted file mode 100644 index 90a27c65be..0000000000 --- a/panda/src/dxgsg7/dxGraphicsStateGuardian7.I +++ /dev/null @@ -1,130 +0,0 @@ -// Filename: dxGraphicsStateGuardian7.I -// Created by: mike (02Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::Colorf_to_D3DCOLOR -// Access: Public, Static -// Description: Converts Panda's floating-point Colorf structure to -// DirectX's D3DCOLOR packed structure. -//////////////////////////////////////////////////////////////////// -INLINE DWORD DXGraphicsStateGuardian7:: -Colorf_to_D3DCOLOR(const Colorf &cColorf) { -// MS VC defines _M_IX86 for x86. gcc should define _X86_ -#if defined(_M_IX86) || defined(_X86_) - DWORD d3dcolor,tempcolorval=255; - - // note the default FPU rounding mode will give 255*0.5f=0x80, not 0x7F as VC would force it to by resetting rounding mode - // dont think this makes much difference - - __asm { - push ebx ; want to save this in case this fn is inlined - push ecx - mov ecx, cColorf - fild tempcolorval - fld DWORD PTR [ecx] - fmul ST(0),ST(1) - fistp tempcolorval ; no way to store directly to int register - mov eax, tempcolorval - shl eax, 16 - - fld DWORD PTR [ecx+4] ;grn - fmul ST(0),ST(1) - fistp tempcolorval - mov ebx,tempcolorval - shl ebx, 8 - or eax,ebx - - fld DWORD PTR [ecx+8] ;blue - fmul ST(0),ST(1) - fistp tempcolorval - or eax,tempcolorval - - fld DWORD PTR [ecx+12] ;alpha - fmul ST(0),ST(1) - fistp tempcolorval - ; simulate pop 255.0 off FP stack w/o store, mark top as empty and increment stk ptr - ffree ST(0) - fincstp - mov ebx,tempcolorval - shl ebx, 24 - or eax,ebx - mov d3dcolor,eax - pop ecx - pop ebx - } - - // dxgsg7_cat.debug() << (void*)d3dcolor << endl; - return d3dcolor; -#else //!_X86_ - return MY_D3DRGBA(cColorf[0], cColorf[1], cColorf[2], cColorf[3]); -#endif //!_X86_ -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_texture_wrap_mode -// Access: Protected, Static -// Description: Maps from the Texture's internal wrap mode symbols to -// GL's. -//////////////////////////////////////////////////////////////////// -INLINE D3DTEXTUREADDRESS DXGraphicsStateGuardian7:: -get_texture_wrap_mode(Texture::WrapMode wm) { - switch (wm) { - case Texture::WM_clamp: - return D3DTADDRESS_CLAMP; - case Texture::WM_repeat: - return D3DTADDRESS_WRAP; - case Texture::WM_mirror: - return D3DTADDRESS_MIRROR; - case Texture::WM_mirror_once: - return D3DTADDRESS_BORDER; - case Texture::WM_border_color: - return D3DTADDRESS_BORDER; - } - dxgsg7_cat.error() << "Invalid Texture::Mode value" << endl; - return D3DTADDRESS_WRAP; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_fog_mode_type -// Access: Protected, Static -// Description: Maps from the fog types to gl version -//////////////////////////////////////////////////////////////////// -INLINE D3DFOGMODE DXGraphicsStateGuardian7:: -get_fog_mode_type(Fog::Mode m) { - switch (m) { - case Fog::M_linear: - return D3DFOG_LINEAR; - case Fog::M_exponential: - return D3DFOG_EXP; - case Fog::M_exponential_squared: - return D3DFOG_EXP2; - } - dxgsg7_cat.error() << "Invalid Fog::Mode value" << endl; - return D3DFOG_EXP; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_tex_mat_sym -// Access: Protected, Static -// Description: Returns the nth D3DTRANSFORMSTATE_TEXTURE(n) constant. -//////////////////////////////////////////////////////////////////// -INLINE D3DTRANSFORMSTATETYPE DXGraphicsStateGuardian7:: -get_tex_mat_sym(int stage_index) { - return (D3DTRANSFORMSTATETYPE)(D3DTRANSFORMSTATE_TEXTURE0 + stage_index); -} diff --git a/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx b/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx deleted file mode 100644 index c8740477ba..0000000000 --- a/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx +++ /dev/null @@ -1,2519 +0,0 @@ -// Filename: dxGraphicsStateGuardian7.cxx -// Created by: mike (02Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#include "dxGraphicsStateGuardian7.h" -#include "config_dxgsg7.h" -#include "displayRegion.h" -#include "renderBuffer.h" -#include "geom.h" -#include "graphicsWindow.h" -#include "graphicsEngine.h" -#include "lens.h" -#include "ambientLight.h" -#include "directionalLight.h" -#include "pointLight.h" -#include "spotlight.h" -#include "textureAttrib.h" -#include "texGenAttrib.h" -#include "shadeModelAttrib.h" -#include "cullFaceAttrib.h" -#include "transparencyAttrib.h" -#include "alphaTestAttrib.h" -#include "depthTestAttrib.h" -#include "depthWriteAttrib.h" -#include "colorWriteAttrib.h" -#include "texMatrixAttrib.h" -#include "materialAttrib.h" -#include "renderModeAttrib.h" -#include "rescaleNormalAttrib.h" -#include "fogAttrib.h" -#include "depthOffsetAttrib.h" -#include "fog.h" -#include "throw_event.h" -#include "geomVertexFormat.h" -#include "geomVertexData.h" -#include "geomTriangles.h" -#include "geomTristrips.h" -#include "geomTrifans.h" -#include "geomLines.h" -#include "geomLinestrips.h" -#include "geomPoints.h" -#include "GeomVertexReader.h" -#include "dxGeomMunger7.h" -#include "config_gobj.h" -#include "pStatTimer.h" -#include "pStatCollector.h" - -#include -#include - -TypeHandle DXGraphicsStateGuardian7::_type_handle; - -D3DMATRIX DXGraphicsStateGuardian7::_d3d_ident_mat; - -#define MY_D3DRGBA(r, g, b, a) ((D3DCOLOR) D3DCOLOR_COLORVALUE(r, g, b, a)) - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DXGraphicsStateGuardian7:: -DXGraphicsStateGuardian7(const FrameBufferProperties &properties) : - GraphicsStateGuardian(properties, CS_yup_left) -{ - _screen = NULL; - _d3d_device = NULL; - - _dx_is_ready = false; - _vertex_blending_enabled = false; - _tex_stats_retrieval_impossible = false; - - _active_vbuffer = NULL; - _active_ibuffer = NULL; - - // This is a static member, but we initialize it here in the - // constructor anyway. It won't hurt if it gets repeatedly - // initalized. - ZeroMemory(&_d3d_ident_mat, sizeof(D3DMATRIX)); - _d3d_ident_mat._11 = _d3d_ident_mat._22 = _d3d_ident_mat._33 = _d3d_ident_mat._44 = 1.0f; - - _cur_read_pixel_buffer = RenderBuffer::T_front; - set_color_clear_value(_color_clear_value); - - // DirectX drivers seem to consistently invert the texture when - // they copy framebuffer-to-texture. Ok. - _copy_texture_inverted = true; - - _supported_geom_rendering = - Geom::GR_point | Geom::GR_indexed_other | Geom::GR_flat_first_vertex; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DXGraphicsStateGuardian7:: -~DXGraphicsStateGuardian7() { - if (IS_VALID_PTR(_d3d_device)) { - _d3d_device->SetTexture(0, NULL); // this frees reference to the old texture - } - free_nondx_resources(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::prepare_texture -// Access: Public, Virtual -// Description: Creates a new retained-mode representation of the -// given texture, and returns a newly-allocated -// TextureContext pointer to reference it. It is the -// responsibility of the calling function to later -// call release_texture() with this same pointer (which -// will also delete the pointer). -// -// This function should not be called directly to -// prepare a texture. Instead, call Texture::prepare(). -//////////////////////////////////////////////////////////////////// -TextureContext *DXGraphicsStateGuardian7:: -prepare_texture(Texture *tex) { - DXTextureContext7 *dtc = new DXTextureContext7(tex); - if (dtc->create_texture(_d3d_device, _num_tex_formats, _tex_formats, - &_screen->D3DDevDesc) == NULL) { - delete dtc; - return NULL; - } - - return dtc; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::apply_texture -// Access: Public -// Description: Makes the texture the currently available texture for -// rendering on the ith stage. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -apply_texture(int i, TextureContext *tc) { - if (tc == (TextureContext *)NULL) { - // The texture wasn't bound properly or something, so ensure - // texturing is disabled and just return. - _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE); - return; - } - -#ifdef DO_PSTATS - add_to_texture_record(tc); -#endif - - DXTextureContext7 *dtc = DCAST(DXTextureContext7, tc); - - int dirty = dtc->get_dirty_flags(); - - // If the texture image has changed, or if its use of mipmaps has - // changed, we need to re-create the image. Ignore other types of - // changes, which aren't significant for DX. - - if ((dirty & (Texture::DF_image | Texture::DF_mipmap)) != 0) { - // If this is *only* because of a mipmap change, issue a - // warning--it is likely that this change is the result of an - // error or oversight. - if ((dirty & Texture::DF_image) == 0) { - dxgsg7_cat.warning() - << "Texture " << *dtc->_texture << " has changed mipmap state.\n"; - } - - if (!dtc->create_texture(_d3d_device, _num_tex_formats, _tex_formats, - &_screen->D3DDevDesc)) { - // Oops, we can't re-create the texture for some reason. - dxgsg7_cat.error() - << "Unable to re-create texture " << *dtc->_texture << endl; - _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE); - return; - } - } - - Texture *tex = tc->_texture; - Texture::WrapMode wrap_u, wrap_v, wrap_w; - wrap_u = tex->get_wrap_u(); - wrap_v = tex->get_wrap_v(); - wrap_w = tex->get_wrap_w(); - - _d3d_device->SetTextureStageState(i, D3DTSS_ADDRESSU, get_texture_wrap_mode(wrap_u)); - _d3d_device->SetTextureStageState(i, D3DTSS_ADDRESSV, get_texture_wrap_mode(wrap_v)); - - _d3d_device->SetTextureStageState(i, D3DTSS_BORDERCOLOR, - Colorf_to_D3DCOLOR(tex->get_border_color())); - - uint aniso_degree = tex->get_anisotropic_degree(); - Texture::FilterType ft = tex->get_magfilter(); - - _d3d_device->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, aniso_degree); - - D3DTEXTUREMAGFILTER new_mag_filter; - new_mag_filter = ((ft != Texture::FT_nearest) ? D3DTFG_LINEAR : D3DTFG_POINT); - - _d3d_device->SetTextureStageState(i, D3DTSS_MAGFILTER, new_mag_filter); - - // map Panda composite min+mip filter types to d3d's separate min & mip filter types - D3DTEXTUREMINFILTER new_min_filter = get_d3d_min_type(tex->get_minfilter()); - D3DTEXTUREMIPFILTER new_mip_filter = get_d3d_mip_type(tex->get_minfilter()); - - if (!tex->might_have_ram_image()) { - // If the texture is completely dynamic, don't try to issue - // mipmaps--pandadx doesn't support auto-generated mipmaps at this - // point. - new_mip_filter = D3DTFP_NONE; - } - -#ifndef NDEBUG - // sanity check - if ((!dtc->has_mipmaps()) && (new_mip_filter != D3DTFP_NONE)) { - dxgsg7_cat.error() - << "Trying to set mipmap filtering for texture with no generated mipmaps!! texname[" - << tex->get_name() << "], filter(" - << tex->get_minfilter() << ")\n"; - new_mip_filter = D3DTFP_NONE; - } -#endif - - _d3d_device->SetTextureStageState(i, D3DTSS_MINFILTER, new_min_filter); - _d3d_device->SetTextureStageState(i, D3DTSS_MIPFILTER, new_mip_filter); - - _d3d_device->SetTexture(i, dtc->_surface); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::release_texture -// Access: Public, Virtual -// Description: Frees the GL resources previously allocated for the -// texture. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -release_texture(TextureContext *tc) { - DXTextureContext7 *dtc = DCAST(DXTextureContext7, tc); - delete dtc; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::make_geom_munger -// Access: Public, Virtual -// Description: Creates a new GeomMunger object to munge vertices -// appropriate to this GSG for the indicated state. -//////////////////////////////////////////////////////////////////// -PT(GeomMunger) DXGraphicsStateGuardian7:: -make_geom_munger(const RenderState *state) { - PT(DXGeomMunger7) munger = new DXGeomMunger7(this, state); - return GeomMunger::register_munger(munger); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_color_clear_value -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -set_color_clear_value(const Colorf& value) { - _color_clear_value = value; - _d3dcolor_clear_value = Colorf_to_D3DCOLOR(value); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_clear -// Access: Public, Virtual -// Description: Clears all of the indicated buffers to their assigned -// colors. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_clear(const RenderBuffer &buffer) { - nassertv(buffer._gsg == this); - int buffer_type = buffer._buffer_type; - - int flags = 0; - - if (buffer_type & RenderBuffer::T_depth) { - flags |= D3DCLEAR_ZBUFFER; - nassertv(_screen->pddsZBuf!=NULL); - } - if (buffer_type & RenderBuffer::T_back) { - flags |= D3DCLEAR_TARGET; - } - - HRESULT hr = _d3d_device->Clear(0, NULL, flags, _d3dcolor_clear_value, - (D3DVALUE) _depth_clear_value, 0); - if (hr != DD_OK) { - dxgsg7_cat.error() - << "clear_buffer failed: Clear returned " << ConvD3DErrorToString(hr) - << endl; - throw_event("panda3d-render-error"); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::prepare_display_region -// Access: Public, Virtual -// Description: Prepare a display region for rendering (set up -// scissor region and viewport) -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -prepare_display_region() { - if (_current_display_region == (DisplayRegion*)0L) { - dxgsg7_cat.error() - << "Invalid NULL display region in prepare_display_region()\n"; - - } else if (_current_display_region != _actual_display_region) { - _actual_display_region = _current_display_region; - - int l, u, w, h; - _actual_display_region->get_region_pixels_i(l, u, w, h); - - // Create the viewport - D3DVIEWPORT7 vp = { l, u, w, h, 0.0f, 1.0f }; - HRESULT hr = _screen->pD3DDevice->SetViewport(&vp); - if (FAILED(hr)) { - dxgsg7_cat.error() - << "SetViewport(" << l << ", " << u << ", " << w << ", " << h - << ") failed : result = " << ConvD3DErrorToString(hr) - << endl; - throw_event("panda3d-render-error"); - } - - // Note: for DX9, also change scissor clipping state here - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::prepare_lens -// Access: Public, Virtual -// Description: Makes the current lens (whichever lens was most -// recently specified with set_scene()) active, so -// that it will transform future rendered geometry. -// Normally this is only called from the draw process, -// and usually it is called by set_scene(). -// -// The return value is true if the lens is acceptable, -// false if it is not. -//////////////////////////////////////////////////////////////////// -bool DXGraphicsStateGuardian7:: -prepare_lens() { - if (_current_lens == (Lens *)NULL) { - return false; - } - - if (!_current_lens->is_linear()) { - return false; - } - - // Start with the projection matrix from the lens. - const LMatrix4f &lens_mat = _current_lens->get_projection_mat(); - - // The projection matrix must always be left-handed Y-up internally, - // to match DirectX's convention, even if our coordinate system of - // choice is otherwise. - const LMatrix4f &convert_mat = - LMatrix4f::convert_mat(CS_yup_left, _current_lens->get_coordinate_system()); - - // DirectX also uses a Z range of 0 to 1, whereas the Panda - // convention is for the projection matrix to produce a Z range of - // -1 to 1. We have to rescale to compensate. - static const LMatrix4f rescale_mat - (1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 0.5, 0, - 0, 0, 0.5, 1); - - _projection_mat = convert_mat * lens_mat * rescale_mat; - - if (_scene_setup->get_inverted()) { - // If the scene is supposed to be inverted, then invert the - // projection matrix. - static LMatrix4f invert_mat = LMatrix4f::scale_mat(1.0f, -1.0f, 1.0f); - _projection_mat *= invert_mat; - } - - HRESULT hr = - _d3d_device->SetTransform(D3DTRANSFORMSTATE_PROJECTION, - (D3DMATRIX*)_projection_mat.get_data()); - return SUCCEEDED(hr); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::begin_frame -// Access: Public, Virtual -// Description: Called before each frame is rendered, to allow the -// GSG a chance to do any internal cleanup before -// beginning the frame. -// -// The return value is true if successful (in which case -// the frame will be drawn and end_frame() will be -// called later), or false if unsuccessful (in which -// case nothing will be drawn and end_frame() will not -// be called). -//////////////////////////////////////////////////////////////////// -bool DXGraphicsStateGuardian7:: -begin_frame() { - return GraphicsStateGuardian::begin_frame(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::begin_scene -// Access: Public, Virtual -// Description: Called between begin_frame() and end_frame() to mark -// the beginning of drawing commands for a "scene" -// (usually a particular DisplayRegion) within a frame. -// All 3-D drawing commands, except the clear operation, -// must be enclosed within begin_scene() .. end_scene(). -// -// The return value is true if successful (in which case -// the scene will be drawn and end_scene() will be -// called later), or false if unsuccessful (in which -// case nothing will be drawn and end_scene() will not -// be called). -//////////////////////////////////////////////////////////////////// -bool DXGraphicsStateGuardian7:: -begin_scene() { - if (!GraphicsStateGuardian::begin_scene()) { - return false; - } - - HRESULT hr = _screen->pD3DDevice->BeginScene(); - - if (FAILED(hr)) { - if ((hr == DDERR_SURFACELOST) || (hr == DDERR_SURFACEBUSY)) { - if (dxgsg7_cat.is_debug()) { - dxgsg7_cat.debug() - << "BeginScene returns " << ConvD3DErrorToString(hr) << endl; - } - - check_cooperative_level(); - - } else { - dxgsg7_cat.error() - << "BeginScene failed, unhandled error hr == " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - return false; - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::end_scene -// Access: Public, Virtual -// Description: Called between begin_frame() and end_frame() to mark -// the end of drawing commands for a "scene" (usually a -// particular DisplayRegion) within a frame. All 3-D -// drawing commands, except the clear operation, must be -// enclosed within begin_scene() .. end_scene(). -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -end_scene() { - HRESULT hr = _screen->pD3DDevice->EndScene(); - - if (FAILED(hr)) { - if ((hr == DDERR_SURFACELOST) || (hr == DDERR_SURFACEBUSY)) { - if (dxgsg7_cat.is_debug()) { - dxgsg7_cat.debug() - << "EndScene returns " << ConvD3DErrorToString(hr) << endl; - } - - check_cooperative_level(); - - } else { - dxgsg7_cat.error() - << "EndScene failed, unhandled error hr == " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - } - - GraphicsStateGuardian::end_scene(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::end_frame -// Access: Public, Virtual -// Description: Called after each frame is rendered, to allow the -// GSG a chance to do any internal cleanup after -// rendering the frame, and before the window flips. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -end_frame() { - -#if defined(DO_PSTATS) - if (_texmgrmem_total_pcollector.is_active()) { -#define TICKS_PER_GETTEXINFO (2.5*1000) // 2.5 second interval - static DWORD last_tick_count = 0; - DWORD cur_tick_count = GetTickCount(); - - if (cur_tick_count - last_tick_count > TICKS_PER_GETTEXINFO) { - last_tick_count = cur_tick_count; - report_texmgr_stats(); - } - } -#endif - - // Note: regular GraphicsWindow::end_frame is being called, - // but we override gsg::end_frame, so need to explicitly call it here - // (currently it's an empty fn) - GraphicsStateGuardian::end_frame(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::begin_draw_primitives -// Access: Public, Virtual -// Description: Called before a sequence of draw_primitive() -// functions are called, this should prepare the vertex -// data for rendering. It returns true if the vertices -// are ok, false to abort this group of primitives. -//////////////////////////////////////////////////////////////////// -bool DXGraphicsStateGuardian7:: -begin_draw_primitives(const Geom *geom, const GeomMunger *munger, - const GeomVertexData *vertex_data) { - if (!GraphicsStateGuardian::begin_draw_primitives(geom, munger, vertex_data)) { - return false; - } - nassertr(_vertex_data != (GeomVertexData *)NULL, false); - determine_fvf(); - - if (_transform_stale && !_vertex_data->is_vertex_transformed()) { - D3DMATRIX *d3d_mat = (D3DMATRIX *)(const D3DMATRIX *)_internal_transform->get_mat().get_data(); - _screen->pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, d3d_mat); - _transform_stale = false; - } - - if (_vertex_data->is_vertex_transformed()) { - // If the vertex data claims to be already transformed into clip - // coordinates, wipe out the current projection and modelview - // matrix (so we don't attempt to transform it again). - - // It's tempting just to use the D3DFVF_XYZRHW specification on - // these vertices, but that turns out to be a bigger hammer than - // we want: that also prevents lighting calculations and user clip - // planes. - _screen->pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &_d3d_ident_mat); - static const LMatrix4f rescale_mat - (1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 0.5, 0, - 0, 0, 0.5, 1); - _transform_stale = true; - - _screen->pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, (D3DMATRIX *)rescale_mat.get_data()); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::determine_fvf -// Access: Public -// Description: Computes the FVF code for the current vertex data. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -determine_fvf() { - // The munger should have put the FVF data in the first array. - const GeomVertexArrayData *data = _vertex_data->get_array(0); - - const GeomVertexArrayFormat *array_format = data->get_array_format(); - - // We have to start with the vertex data, and work up from there in - // order, since that's the way the FVF is defined. - int n = 0; - int num_columns = array_format->get_num_columns(); - - _fvf = 0; - - if (n < num_columns && - array_format->get_column(n)->get_name() == InternalName::get_vertex()) { - ++n; - } - - if (n < num_columns && - array_format->get_column(n)->get_name() == InternalName::get_normal()) { - _fvf |= D3DFVF_NORMAL; - ++n; - } - if (n < num_columns && - array_format->get_column(n)->get_name() == InternalName::get_color()) { - _fvf |= D3DFVF_DIFFUSE; - ++n; - } - - // Now look for all of the texcoord names and enable them in the - // same order they appear in the array. - int texcoord_index = 0; - while (n < num_columns && - array_format->get_column(n)->get_contents() == Geom::C_texcoord) { - const GeomVertexColumn *column = array_format->get_column(n); - switch (column->get_num_values()) { - case 1: - _fvf |= D3DFVF_TEXCOORDSIZE1(texcoord_index); - ++n; - break; - case 2: - _fvf |= D3DFVF_TEXCOORDSIZE2(texcoord_index); - ++n; - break; - case 3: - _fvf |= D3DFVF_TEXCOORDSIZE3(texcoord_index); - ++n; - break; - case 4: - _fvf |= D3DFVF_TEXCOORDSIZE4(texcoord_index); - ++n; - break; - } - ++texcoord_index; - } - - switch (texcoord_index) { - case 0: - break; - case 1: - _fvf |= D3DFVF_TEX1; - break; - case 2: - _fvf |= D3DFVF_TEX2; - break; - case 3: - _fvf |= D3DFVF_TEX3; - break; - case 4: - _fvf |= D3DFVF_TEX4; - break; - case 5: - _fvf |= D3DFVF_TEX5; - break; - case 6: - _fvf |= D3DFVF_TEX6; - break; - case 7: - _fvf |= D3DFVF_TEX7; - break; - case 8: - _fvf |= D3DFVF_TEX8; - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::draw_triangles -// Access: Public, Virtual -// Description: Draws a series of disconnected triangles. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -draw_triangles(const GeomTriangles *primitive) { - _vertices_tri_pcollector.add_level(primitive->get_num_vertices()); - _primitive_batches_tri_pcollector.add_level(1); - - if (primitive->is_indexed()) { - // Indexed, client arrays. - _d3d_device->DrawIndexedPrimitive - (D3DPT_TRIANGLELIST, _fvf, - (LPVOID)_vertex_data->get_array(0)->get_data().p(), - primitive->get_max_vertex() + 1, - (LPWORD)primitive->get_data().p(), - primitive->get_num_vertices(), - NULL); - - } else { - // Nonindexed, client arrays. - int stride = _vertex_data->get_format()->get_array(0)->get_stride(); - unsigned int first_vertex = primitive->get_first_vertex(); - - // Interestingly, my ATI driver seems to fail to draw anything in - // this call if the address range of the buffer supplied crosses - // over a multiple of 0x10000. I refuse to hack around this lame - // driver bug. - _screen->pD3DDevice->DrawPrimitive - (D3DPT_TRIANGLELIST, _fvf, - (LPVOID)(_vertex_data->get_array(0)->get_data() + stride * first_vertex), - primitive->get_num_vertices(), NULL); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::draw_lines -// Access: Public, Virtual -// Description: Draws a series of disconnected line segments. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -draw_lines(const GeomLines *primitive) { - _vertices_other_pcollector.add_level(primitive->get_num_vertices()); - _primitive_batches_other_pcollector.add_level(1); - - if (primitive->is_indexed()) { - // Indexed, client arrays. - _d3d_device->DrawIndexedPrimitive - (D3DPT_LINELIST, _fvf, - (LPVOID)_vertex_data->get_array(0)->get_data().p(), - primitive->get_max_vertex() + 1, - (LPWORD)primitive->get_data().p(), - primitive->get_num_vertices(), - NULL); - - } else { - // Nonindexed, client arrays. - int stride = _vertex_data->get_format()->get_array(0)->get_stride(); - unsigned int first_vertex = primitive->get_first_vertex(); - _screen->pD3DDevice->DrawPrimitive - (D3DPT_LINELIST, _fvf, - (LPVOID)(_vertex_data->get_array(0)->get_data() + stride * first_vertex), - primitive->get_num_vertices(), NULL); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::draw_points -// Access: Public, Virtual -// Description: Draws a series of disconnected points. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -draw_points(const GeomPoints *primitive) { - _vertices_other_pcollector.add_level(primitive->get_num_vertices()); - _primitive_batches_other_pcollector.add_level(1); - - // The munger should have protected us from indexed points--DirectX - // doesn't support them. - nassertv(!primitive->is_indexed()); - - // Nonindexed, client arrays. - int stride = _vertex_data->get_format()->get_array(0)->get_stride(); - unsigned int first_vertex = primitive->get_first_vertex(); - _screen->pD3DDevice->DrawPrimitive - (D3DPT_POINTLIST, _fvf, - (LPVOID)(_vertex_data->get_array(0)->get_data() + stride * first_vertex), - primitive->get_num_vertices(), NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::end_draw_primitives() -// Access: Public, Virtual -// Description: Called after a sequence of draw_primitive() -// functions are called, this should do whatever cleanup -// is appropriate. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -end_draw_primitives() { - if (_vertex_data->is_vertex_transformed()) { - // Restore the projection matrix that we wiped out above. - prepare_lens(); - } - - GraphicsStateGuardian::end_draw_primitives(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::framebuffer_copy_to_texture -// Access: Public, Virtual -// Description: Copy the pixels within the indicated display -// region from the framebuffer into texture memory. -// -// If z > -1, it is the cube map index into which to -// copy. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, - const RenderBuffer &rb) { - // For a DX7, go the slow route through RAM, just 'cause no one - // really cares about DX7 anyway. - framebuffer_copy_to_ram(tex, z, dr, rb); -} - - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian9::framebuffer_copy_to_ram -// Access: Public, Virtual -// Description: Copy the pixels within the indicated display region -// from the framebuffer into system memory, not texture -// memory. Returns true on success, false on failure. -// -// This completely redefines the ram image of the -// indicated texture. -//////////////////////////////////////////////////////////////////// -bool DXGraphicsStateGuardian7:: -framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb) { - set_read_buffer(rb); - - nassertr(tex != NULL && dr != NULL, false); - - int xo, yo, w, h; - dr->get_region_pixels_i(xo, yo, w, h); - - 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 = 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); - } - - extern HRESULT ConvertDDSurftoPixBuf(Texture *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf); - ConvertDDSurftoPixBuf(tex,((_cur_read_pixel_buffer & RenderBuffer::T_back) ? _screen->pddsBack : _screen->pddsPrimary)); - - nassertr(tex->has_ram_image(), false); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::reset -// Access: Public, Virtual -// Description: Resets all internal state as if the gsg were newly -// created. The GraphicsWindow pointer represents a -// typical window that might be used for this context; -// it may be required to set up the frame buffer -// properly the first time. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -reset() { - GraphicsStateGuardian::reset(); - - _auto_rescale_normal = false; - - // overwrite gsg defaults with these values - - // Lamely assume we have both a color and a depth buffer. - _buffer_mask = RenderBuffer::T_color | RenderBuffer::T_depth; - - HRESULT hr; - - // make sure gsg passes all current state down to us - // set_state_and_transform(RenderState::make_empty(), - // TransformState::make_identity()); - // want gsg to pass all state settings down so any non-matching defaults we set here get overwritten - - assert(_screen->pDD!=NULL); - assert(_screen->pD3D!=NULL); - assert(_screen->pD3DDevice!=NULL); - assert(_screen->pddsPrimary!=NULL); - assert(_screen->pddsBack!=NULL); - - _screen->pD3DDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, 0x0); - - _clip_plane_bits = 0; - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , 0x0); - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, false); - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false); - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, false); - - assert(_screen->pddsBack!=NULL); // dxgsg7 is always double-buffered right now - - _last_testcooplevel_result = S_OK; - - DX_DECLARE_CLEAN(DDCAPS,ddCaps); - if (FAILED(hr = _screen->pDD->GetCaps(&ddCaps,NULL))) { - dxgsg7_cat.fatal() << "GetCaps failed on DDraw! hr = " << ConvD3DErrorToString(hr) << "\n"; - exit(1); - } - - // s3 virge drivers sometimes give crap values for these - if(_screen->D3DDevDesc.dwMaxTextureWidth==0) - _screen->D3DDevDesc.dwMaxTextureWidth=256; - - if(_screen->D3DDevDesc.dwMaxTextureHeight==0) - _screen->D3DDevDesc.dwMaxTextureHeight=256; - -#define REQUIRED_BLENDCAPS (D3DPBLENDCAPS_ZERO|D3DPBLENDCAPS_ONE| \ - D3DPBLENDCAPS_SRCALPHA|D3DPBLENDCAPS_INVSRCALPHA) - - if (((_screen->D3DDevDesc.dpcTriCaps.dwSrcBlendCaps & REQUIRED_BLENDCAPS)!=REQUIRED_BLENDCAPS) || - ((_screen->D3DDevDesc.dpcTriCaps.dwDestBlendCaps & REQUIRED_BLENDCAPS)!=REQUIRED_BLENDCAPS)) { - dxgsg7_cat.error() << "device is missing alpha blending capabilities, blending may not work correctly: SrcBlendCaps: 0x"<< (void*) _screen->D3DDevDesc.dpcTriCaps.dwSrcBlendCaps << " DestBlendCaps: "<< (void*) _screen->D3DDevDesc.dpcTriCaps.dwDestBlendCaps << endl; - } - - if (!(_screen->D3DDevDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_TRANSPARENCY)) { - dxgsg7_cat.error() << "device is missing texture transparency capability, transparency may not work correctly! TextureCaps: 0x"<< (void*) _screen->D3DDevDesc.dpcTriCaps.dwTextureCaps << endl; - } - - // just require trilinear. if it can do that, it can probably do all the lesser point-sampling variations too -#define REQUIRED_TEXFILTERCAPS (D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_LINEAR) - if ((_screen->D3DDevDesc.dpcTriCaps.dwTextureFilterCaps & REQUIRED_TEXFILTERCAPS)!=REQUIRED_TEXFILTERCAPS) { - dxgsg7_cat.error() << "device is missing texture bilinear filtering capability, textures may appear blocky! TextureFilterCaps: 0x"<< (void*) _screen->D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; - } -#define REQUIRED_MIPMAP_TEXFILTERCAPS (D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_LINEARMIPLINEAR) - - if (!(ddCaps.ddsCaps.dwCaps & DDSCAPS_MIPMAP)) { - dxgsg7_cat.debug() << "device does not have mipmap texturing filtering capability! TextureFilterCaps: 0x"<< (void*) _screen->D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; - dx_ignore_mipmaps = TRUE; - } else if ((_screen->D3DDevDesc.dpcTriCaps.dwTextureFilterCaps & REQUIRED_MIPMAP_TEXFILTERCAPS)!=REQUIRED_MIPMAP_TEXFILTERCAPS) { - dxgsg7_cat.debug() << "device is missing tri-linear mipmap filtering capability, texture mipmaps may not supported! TextureFilterCaps: 0x"<< (void*) _screen->D3DDevDesc.dpcTriCaps.dwTextureFilterCaps << endl; - } - -#define REQUIRED_TEXBLENDCAPS (D3DTEXOPCAPS_MODULATE | D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_SELECTARG2) - if ((_screen->D3DDevDesc.dwTextureOpCaps & REQUIRED_TEXBLENDCAPS)!=REQUIRED_TEXBLENDCAPS) { - dxgsg7_cat.error() << "device is missing some required texture blending capabilities, texture blending may not work properly! TextureOpCaps: 0x"<< (void*) _screen->D3DDevDesc.dwTextureOpCaps << endl; - } - - if(_screen->D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) { - // watch out for drivers that emulate per-pixel fog with per-vertex fog (Riva128, Matrox Millen G200) - // some of these require gouraud-shading to be set to work, as if you were using vertex fog - _do_fog_type=PerPixelFog; - } else { - // every card is going to have vertex fog, since it's implemented in d3d runtime - assert((_screen->D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX )!=0); - - // vtx fog may look crappy if you have large polygons in the foreground and they get clipped, - // so you may want to disable it - - if(dx_no_vertex_fog) { - _do_fog_type = None; - } else { - _do_fog_type = PerVertexFog; - - // range-based fog only works with vertex fog in dx7/8 - if(dx_use_rangebased_fog && (_screen->D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGRANGE)) - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_RANGEFOGENABLE, true); - } - } - - SetRect(&_screen->clip_rect, 0,0,0,0); // no clip rect set - - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, false); - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING,true); - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILENABLE, false); - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); - - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); - - // initial clip rect - SetRect(&_screen->clip_rect, 0,0,0,0); // no clip rect set - - _screen->pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE); // disables texturing - - // this code must match apply_texture() code for states above - // so DX TSS renderstate matches dxgsg7 state - - _screen->pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_POINT); - _screen->pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFP_POINT); - _screen->pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTFP_NONE); - _screen->pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); - - _max_vertices_per_array = 65536; - _max_vertices_per_primitive = 1024; - _max_texture_stages = 1; - _max_texture_dimension = - min(_screen->D3DDevDesc.dwMaxTextureWidth, - _screen->D3DDevDesc.dwMaxTextureHeight); - - _supports_texture_combine = false; - _supports_texture_saved_result = false; - _supports_texture_dot3 = false; - _supports_3d_texture = false; - _supports_cube_map = false; - - _max_lights = 8; - _max_clip_planes = 8; - _max_vertex_transforms = 0; - _max_vertex_transform_indices = 0; - - _projection_mat = LMatrix4f::ident_mat(); - _has_scene_graph_color = false; - - _last_testcooplevel_result = D3D_OK; - - - _tex_formats = new DDPIXELFORMAT[MAX_DX_TEXPIXFMTS]; - _num_tex_formats = 0; - - _d3d_device->EnumTextureFormats(enum_tex_formats_callback, this); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::apply_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -apply_fog(Fog *fog) { - if (_do_fog_type == None) - return; - - Fog::Mode panda_fogmode = fog->get_mode(); - D3DFOGMODE d3dfogmode = get_fog_mode_type(panda_fogmode); - - _d3d_device->SetRenderState((D3DRENDERSTATETYPE)_do_fog_type, d3dfogmode); - - const Colorf &fog_colr = fog->get_color(); - _d3d_device->SetRenderState(D3DRENDERSTATE_FOGCOLOR, - D3DRGBA(fog_colr[0], fog_colr[1], fog_colr[2], 0.0f)); // Alpha bits are not used - - // do we need to adjust fog start/end values based on D3DPRASTERCAPS_WFOG/D3DPRASTERCAPS_ZFOG ? - // if not WFOG, then docs say we need to adjust values to range [0, 1] - - switch (panda_fogmode) { - case Fog::M_linear: - { - float onset, opaque; - fog->get_linear_range(onset, opaque); - - _d3d_device->SetRenderState(D3DRENDERSTATE_FOGSTART, - *((LPDWORD) (&onset))); - _d3d_device->SetRenderState(D3DRENDERSTATE_FOGEND, - *((LPDWORD) (&opaque))); - } - break; - case Fog::M_exponential: - case Fog::M_exponential_squared: - { - // Exponential fog is always camera-relative. - float fog_density = fog->get_exp_density(); - _d3d_device->SetRenderState(D3DRENDERSTATE_FOGDENSITY, - *((LPDWORD) (&fog_density))); - } - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_transform -// Access: Protected -// Description: Sends the indicated transform matrix to the graphics -// API to be applied to future vertices. -// -// This transform is the internal_transform, already -// converted into the GSG's internal coordinate system. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_transform() { - const TransformState *transform = _internal_transform; - DO_PSTATS_STUFF(_transform_state_pcollector.add_level(1)); - - const D3DMATRIX *d3d_mat = (const D3DMATRIX *)transform->get_mat().get_data(); - _d3d_device->SetTransform(D3DTRANSFORMSTATE_WORLD, (LPD3DMATRIX)d3d_mat); - _transform_stale = false; - - if (_auto_rescale_normal) { - do_auto_rescale_normal(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_alpha_test -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_alpha_test() { - const AlphaTestAttrib *attrib = _target._alpha_test; - AlphaTestAttrib::PandaCompareFunc mode = attrib->get_mode(); - if (mode == AlphaTestAttrib::M_none) { - _d3d_device->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, FALSE); - - } else { - // AlphaTestAttrib::PandaCompareFunc === D3DCMPFUNC - _d3d_device->SetRenderState(D3DRENDERSTATE_ALPHAFUNC, (D3DCMPFUNC)mode); - _d3d_device->SetRenderState(D3DRENDERSTATE_ALPHAREF, (UINT) (attrib->get_reference_alpha()*255.0f)); //d3d uses 0x0-0xFF, not a float - _d3d_device->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, TRUE); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_render_mode -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_render_mode() { - const RenderModeAttrib *attrib = _target._render_mode; - RenderModeAttrib::Mode mode = attrib->get_mode(); - - switch (mode) { - case RenderModeAttrib::M_unchanged: - case RenderModeAttrib::M_filled: - _d3d_device->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); - break; - - case RenderModeAttrib::M_wireframe: - _d3d_device->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME); - break; - - case RenderModeAttrib::M_point: - _d3d_device->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_POINT); - break; - - default: - dxgsg7_cat.error() - << "Unknown render mode " << (int)mode << endl; - } - - _current_fill_mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_rescale_normal -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_rescale_normal() { - const RescaleNormalAttrib *attrib = _target._rescale_normal; - RescaleNormalAttrib::Mode mode = attrib->get_mode(); - - _auto_rescale_normal = false; - - switch (mode) { - case RescaleNormalAttrib::M_none: - _d3d_device->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, false); - break; - - case RescaleNormalAttrib::M_rescale: - case RescaleNormalAttrib::M_normalize: - _d3d_device->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, true); - break; - - case RescaleNormalAttrib::M_auto: - _auto_rescale_normal = true; - do_auto_rescale_normal(); - break; - - default: - dxgsg7_cat.error() - << "Unknown rescale_normal mode " << (int)mode << endl; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_depth_test -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_depth_test() { - const DepthTestAttrib *attrib = _target._depth_test; - DepthTestAttrib::PandaCompareFunc mode = attrib->get_mode(); - if (mode == DepthTestAttrib::M_none) { - _d3d_device->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); - } else { - _d3d_device->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE); - _d3d_device->SetRenderState(D3DRENDERSTATE_ZFUNC, (D3DCMPFUNC) mode); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_depth_write -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_depth_write() { - const DepthWriteAttrib *attrib = _target._depth_write; - if (attrib->get_mode() == DepthWriteAttrib::M_on) { - _d3d_device->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE); - } else { - _d3d_device->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_cull_face -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_cull_face() { - const CullFaceAttrib *attrib = _target._cull_face; - _cull_face_mode = attrib->get_effective_mode(); - - switch (_cull_face_mode) { - case CullFaceAttrib::M_cull_none: - _d3d_device->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); - break; - case CullFaceAttrib::M_cull_clockwise: - _d3d_device->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW); - break; - case CullFaceAttrib::M_cull_counter_clockwise: - _d3d_device->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); - break; - default: - dxgsg7_cat.error() - << "invalid cull face mode " << (int)_cull_face_mode << endl; - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_fog -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_fog() { - const FogAttrib *attrib = _target._fog; - if (!attrib->is_off()) { - _d3d_device->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE); - Fog *fog = attrib->get_fog(); - nassertv(fog != (Fog *)NULL); - apply_fog(fog); - } else { - _d3d_device->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_depth_offset -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_depth_offset() { - const DepthOffsetAttrib *attrib = _target._depth_offset; - int offset = attrib->get_offset(); - _d3d_device->SetRenderState(D3DRENDERSTATE_ZBIAS, offset); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_shade_model -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_shade_model() { - const ShadeModelAttrib *attrib = _target._shade_model; - switch (attrib->get_mode()) { - case ShadeModelAttrib::M_smooth: - _d3d_device->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD); - break; - - case ShadeModelAttrib::M_flat: - _d3d_device->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT); - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_state_and_transform -// Access: Public, Virtual -// Description: Simultaneously resets the render state and the -// transform state. -// -// This transform specified is the "external" net -// transform, expressed in the external coordinate -// space; internally, it will be pretransformed by -// get_cs_transform() to express it in the GSG's -// internal coordinate space. -// -// Special case: if (state==NULL), then the target -// state is already stored in _target. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -set_state_and_transform(const RenderState *target, - const TransformState *transform) { -#ifndef NDEBUG - if (gsg_cat.is_spam()) { - gsg_cat.spam() << "Setting GSG state to " << (void *)target << ":\n"; - target->write(gsg_cat.spam(false), 2); - } -#endif - _state_pcollector.add_level(1); - - if (transform != _external_transform) { - _state_pcollector.add_level(1); - _external_transform = transform; - _internal_transform = _cs_transform->compose(transform); - do_issue_transform(); - } - - if (target == _state_rs) { - return; - } - _target_rs = target; - _target.clear_to_defaults(); - target->store_into_slots(&_target); - _state_rs = 0; - - // There might be some physical limits to the actual target - // attributes we issue. Impose them now. - _target._texture = _target._texture->filter_to_max(_max_texture_stages); - - if (_target._alpha_test != _state._alpha_test) { - do_issue_alpha_test(); - _state._alpha_test = _target._alpha_test; - } - - if (_target._antialias != _state._antialias) { - // Antialias not implemented under DX7 - _state._antialias = _target._antialias; - } - - if (_target._clip_plane != _state._clip_plane) { - do_issue_clip_plane(); - _state._clip_plane = _target._clip_plane; - } - - if (_target._color != _state._color) { - do_issue_color(); - _state._color = _target._color; - } - - if (_target._color_scale != _state._color_scale) { - do_issue_color_scale(); - _state._color_scale = _target._color_scale; - } - - if (_target._cull_face != _state._cull_face) { - do_issue_cull_face(); - _state._cull_face = _target._cull_face; - } - - if (_target._depth_offset != _state._depth_offset) { - do_issue_depth_offset(); - _state._depth_offset = _target._depth_offset; - } - - if (_target._depth_test != _state._depth_test) { - do_issue_depth_test(); - _state._depth_test = _target._depth_test; - } - - if (_target._depth_write != _state._depth_write) { - do_issue_depth_write(); - _state._depth_write = _target._depth_write; - } - - if (_target._fog != _state._fog) { - do_issue_fog(); - _state._fog = _target._fog; - } - - if (_target._render_mode != _state._render_mode) { - do_issue_render_mode(); - _state._render_mode = _target._render_mode; - } - - if (_target._rescale_normal != _state._rescale_normal) { - do_issue_rescale_normal(); - _state._rescale_normal = _target._rescale_normal; - } - - if (_target._shade_model != _state._shade_model) { - do_issue_shade_model(); - _state._shade_model = _target._shade_model; - } - - // Shaders not implemented under DX7 - if (_target._shader != _state._shader) { - _state._shader = _target._shader; - } - - if (_target._tex_gen != _state._tex_gen) { - _state._texture = 0; - _state._tex_gen = _target._tex_gen; - } - - if (_target._tex_matrix != _state._tex_matrix) { - _state._tex_matrix = _target._tex_matrix; - } - - if ((_target._transparency != _state._transparency)|| - (_target._color_write != _state._color_write)|| - (_target._color_blend != _state._color_blend)) { - do_issue_blending(); - _state._transparency = _target._transparency; - _state._color_write = _target._color_write; - _state._color_blend = _target._color_blend; - } - - if (_target._texture != _state._texture) { - do_issue_texture(); - _state._texture = _target._texture; - } - - if (_target._material != _state._material) { - do_issue_material(); - _state._material = _target._material; - } - - if (_target._light != _state._light) { - do_issue_light(); - _state._light = _target._light; - } - - _state_rs = _target_rs; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::bind_light -// Access: Public, Virtual -// Description: Called the first time a particular light has been -// bound to a given id within a frame, this should set -// up the associated hardware light with the light's -// properties. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -bind_light(PointLight *light_obj, const NodePath &light, int light_id) { - // Get the light in "world coordinates". This means the light in - // the coordinate space of the camera, converted to DX's coordinate - // system. - CPT(TransformState) transform = light.get_transform(_scene_setup->get_camera_path()); - const LMatrix4f &light_mat = transform->get_mat(); - LMatrix4f rel_mat = light_mat * LMatrix4f::convert_mat(CS_yup_left, CS_default); - LPoint3f pos = light_obj->get_point() * rel_mat; - - D3DCOLORVALUE black; - black.r = black.g = black.b = black.a = 0.0f; - D3DLIGHT7 alight; - alight.dltType = D3DLIGHT_POINT; - alight.dcvDiffuse = *(D3DCOLORVALUE *)(light_obj->get_color().get_data()); - alight.dcvAmbient = black ; - alight.dcvSpecular = *(D3DCOLORVALUE *)(light_obj->get_specular_color().get_data()); - - // Position needs to specify x, y, z, and w - // w == 1 implies non-infinite position - alight.dvPosition = *(D3DVECTOR *)pos.get_data(); - - alight.dvRange = D3DLIGHT_RANGE_MAX; - alight.dvFalloff = 1.0f; - - const LVecBase3f &att = light_obj->get_attenuation(); - alight.dvAttenuation0 = (D3DVALUE)att[0]; - alight.dvAttenuation1 = (D3DVALUE)att[1]; - alight.dvAttenuation2 = (D3DVALUE)att[2]; - - HRESULT res = _screen->pD3DDevice->SetLight(light_id, &alight); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::bind_light -// Access: Public, Virtual -// Description: Called the first time a particular light has been -// bound to a given id within a frame, this should set -// up the associated hardware light with the light's -// properties. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -bind_light(DirectionalLight *light_obj, const NodePath &light, int light_id) { - // Get the light in "world coordinates". This means the light in - // the coordinate space of the camera, converted to DX's coordinate - // system. - CPT(TransformState) transform = light.get_transform(_scene_setup->get_camera_path()); - const LMatrix4f &light_mat = transform->get_mat(); - LMatrix4f rel_mat = light_mat * LMatrix4f::convert_mat(CS_yup_left, CS_default); - LVector3f dir = light_obj->get_direction() * rel_mat; - - D3DCOLORVALUE black; - black.r = black.g = black.b = black.a = 0.0f; - - D3DLIGHT7 alight; - ZeroMemory(&alight, sizeof(D3DLIGHT7)); - - alight.dltType = D3DLIGHT_DIRECTIONAL; - alight.dcvDiffuse = *(D3DCOLORVALUE *)(light_obj->get_color().get_data()); - alight.dcvAmbient = black ; - alight.dcvSpecular = *(D3DCOLORVALUE *)(light_obj->get_specular_color().get_data()); - - alight.dvDirection = *(D3DVECTOR *)dir.get_data(); - - alight.dvRange = D3DLIGHT_RANGE_MAX; - alight.dvFalloff = 1.0f; - - alight.dvAttenuation0 = 1.0f; // constant - alight.dvAttenuation1 = 0.0f; // linear - alight.dvAttenuation2 = 0.0f; // quadratic - - HRESULT res = _screen->pD3DDevice->SetLight(light_id, &alight); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::bind_light -// Access: Public, Virtual -// Description: Called the first time a particular light has been -// bound to a given id within a frame, this should set -// up the associated hardware light with the light's -// properties. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -bind_light(Spotlight *light_obj, const NodePath &light, int light_id) { - Lens *lens = light_obj->get_lens(); - nassertv(lens != (Lens *)NULL); - - // Get the light in "world coordinates". This means the light in - // the coordinate space of the camera, converted to DX's coordinate - // system. - CPT(TransformState) transform = light.get_transform(_scene_setup->get_camera_path()); - const LMatrix4f &light_mat = transform->get_mat(); - LMatrix4f rel_mat = light_mat * LMatrix4f::convert_mat(CS_yup_left, CS_default); - LPoint3f pos = lens->get_nodal_point() * rel_mat; - LVector3f dir = lens->get_view_vector() * rel_mat; - - D3DCOLORVALUE black; - black.r = black.g = black.b = black.a = 0.0f; - - D3DLIGHT7 alight; - ZeroMemory(&alight, sizeof(D3DLIGHT7)); - - alight.dltType = D3DLIGHT_SPOT; - alight.dcvAmbient = black ; - alight.dcvDiffuse = *(D3DCOLORVALUE *)(light_obj->get_color().get_data()); - alight.dcvSpecular = *(D3DCOLORVALUE *)(light_obj->get_specular_color().get_data()); - - alight.dvPosition = *(D3DVECTOR *)pos.get_data(); - - alight.dvDirection = *(D3DVECTOR *)dir.get_data(); - - alight.dvRange = D3DLIGHT_RANGE_MAX; - alight.dvFalloff = 1.0f; - alight.dvTheta = 0.0f; - alight.dvPhi = deg_2_rad(lens->get_hfov()); - - const LVecBase3f &att = light_obj->get_attenuation(); - alight.dvAttenuation0 = (D3DVALUE)att[0]; - alight.dvAttenuation1 = (D3DVALUE)att[1]; - alight.dvAttenuation2 = (D3DVALUE)att[2]; - - HRESULT hr = _screen->pD3DDevice->SetLight(light_id, &alight); - if (FAILED(hr)) { - wdxdisplay7_cat.warning() - << "Could not set light properties for " << light - << " to id " << light_id << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_material -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_material() { - static Material empty; - const Material *material; - if (_target._material == (MaterialAttrib *)NULL || - _target._material->is_off()) { - material = ∅ - } else { - material = _target._material->get_material(); - } - - D3DMATERIAL7 cur_material; - cur_material.dcvDiffuse = *(D3DCOLORVALUE *)(material->get_diffuse().get_data()); - cur_material.dcvAmbient = *(D3DCOLORVALUE *)(material->get_ambient().get_data()); - cur_material.dcvSpecular = *(D3DCOLORVALUE *)(material->get_specular().get_data()); - cur_material.dcvEmissive = *(D3DCOLORVALUE *)(material->get_emission().get_data()); - cur_material.dvPower = material->get_shininess(); - - if (material->has_diffuse()) { - // If the material specifies an diffuse color, use it. - _d3d_device->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); - } else { - // Otherwise, the diffuse color comes from the object color. - if (_has_material_force_color) { - cur_material.dcvDiffuse = *(D3DCOLORVALUE *)_material_force_color.get_data(); - _d3d_device->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); - } else { - _d3d_device->SetRenderState(D3DRENDERSTATE_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); - } - } - if (material->has_ambient()) { - // If the material specifies an ambient color, use it. - _d3d_device->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); - } else { - // Otherwise, the ambient color comes from the object color. - if (_has_material_force_color) { - cur_material.dcvAmbient = *(D3DCOLORVALUE *)_material_force_color.get_data(); - _d3d_device->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); - } else { - _d3d_device->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); - } - } - - if (material->has_specular()) { - _d3d_device->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, TRUE); - } else { - _d3d_device->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, FALSE); - } - - if (material->get_local()) { - _d3d_device->SetRenderState(D3DRENDERSTATE_LOCALVIEWER, TRUE); - } else { - _d3d_device->SetRenderState(D3DRENDERSTATE_LOCALVIEWER, FALSE); - } - - _d3d_device->SetMaterial(&cur_material); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_issue_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_texture() { - DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1)); - - int num_stages = _target._texture->get_num_on_stages(); - int num_old_stages = _max_texture_stages; - if (_state._texture != (TextureAttrib *)NULL) { - num_old_stages = _state._texture->get_num_on_stages(); - } - - nassertv(num_stages <= _max_texture_stages && - num_old_stages <= _max_texture_stages); - - _texture_involves_color_scale = false; - - // We have to match up the texcoord stage index to the order written - // out by the DXGeomMunger. This means the texcoord names are - // written in the order they are referenced by the TextureAttrib, - // except that if a name is repeated its index number is reused from - // the first time. - typedef pmap UsedTexcoordIndex; - UsedTexcoordIndex used_texcoord_index; - - int i; - for (i = 0; i < num_stages; i++) { - TextureStage *stage = _target._texture->get_on_stage(i); - Texture *texture = _target._texture->get_on_texture(stage); - nassertv(texture != (Texture *)NULL); - - const InternalName *name = stage->get_texcoord_name(); - - // This pair of lines will get the next consecutive texcoord index - // number if this is the first time we have referenced this - // particular texcoord name; otherwise, it will return the same - // index number it returned before. - UsedTexcoordIndex::iterator ti = used_texcoord_index.insert(UsedTexcoordIndex::value_type(name, (int)used_texcoord_index.size())).first; - int texcoord_index = (*ti).second; - - // We always reissue every stage in DX, just in case the texcoord - // index or texgen mode or some other property has changed. - TextureContext *tc = texture->prepare_now(_prepared_objects, this); - apply_texture(i, tc); - set_texture_blend_mode(i, stage); - - int texcoord_dimensions = 0; - - CPT(TransformState) tex_mat = TransformState::make_identity(); - if (_state._tex_matrix->has_stage(stage)) { - tex_mat = _state._tex_matrix->get_transform(stage); - } - - // Issue the texgen mode. - TexGenAttrib::Mode mode = _state._tex_gen->get_mode(stage); - bool any_point_sprite = false; - - switch (mode) { - case TexGenAttrib::M_off: - case TexGenAttrib::M_light_vector: - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, texcoord_index); - break; - - case TexGenAttrib::M_eye_sphere_map: - { - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, - texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); - // This texture matrix, applied on top of the texcoord - // computed by D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR, - // approximates the effect produced by OpenGL's GL_SPHERE_MAP. - static CPT(TransformState) sphere_map = - TransformState::make_mat(LMatrix4f(0.33f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.33f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.0f, 1.0f)); - tex_mat = tex_mat->compose(sphere_map); - texcoord_dimensions = 3; - } - break; - - case TexGenAttrib::M_world_cube_map: - // To achieve world reflection vector, we must transform camera - // coordinates to world coordinates; i.e. apply the camera - // transform. In the case of a vector, we should not apply the - // pos component of the transform. - { - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, - texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); - texcoord_dimensions = 3; - CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform); - tex_mat = tex_mat->compose(camera_transform->set_pos(LVecBase3f::zero())); - } - break; - - case TexGenAttrib::M_eye_cube_map: - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, - texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); - tex_mat = tex_mat->compose(_inv_cs_transform); - texcoord_dimensions = 3; - break; - - case TexGenAttrib::M_world_normal: - // To achieve world normal, we must transform camera coordinates - // to world coordinates; i.e. apply the camera transform. In - // the case of a normal, we should not apply the pos component - // of the transform. - { - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, - texcoord_index | D3DTSS_TCI_CAMERASPACENORMAL); - texcoord_dimensions = 3; - CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform); - tex_mat = tex_mat->compose(camera_transform->set_pos(LVecBase3f::zero())); - } - break; - - case TexGenAttrib::M_eye_normal: - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, - texcoord_index | D3DTSS_TCI_CAMERASPACENORMAL); - texcoord_dimensions = 3; - tex_mat = tex_mat->compose(_inv_cs_transform); - break; - - case TexGenAttrib::M_world_position: - // To achieve world position, we must transform camera - // coordinates to world coordinates; i.e. apply the - // camera transform. - { - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, - texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION); - texcoord_dimensions = 3; - CPT(TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform); - tex_mat = tex_mat->compose(camera_transform); - } - break; - - case TexGenAttrib::M_eye_position: - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, - texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION); - texcoord_dimensions = 3; - tex_mat = tex_mat->compose(_inv_cs_transform); - break; - - case TexGenAttrib::M_point_sprite: - _d3d_device->SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, texcoord_index); - any_point_sprite = true; - break; - } - // Dx7 doesn't support point sprites anyway. - nassertv(!any_point_sprite); - - if (!tex_mat->is_identity()) { - if (tex_mat->is_2d() && texcoord_dimensions <= 2) { - // For 2-d texture coordinates, we have to reorder the matrix. - LMatrix4f m = tex_mat->get_mat(); - m.set(m(0, 0), m(0, 1), m(0, 3), 0.0f, - m(1, 0), m(1, 1), m(1, 3), 0.0f, - m(3, 0), m(3, 1), m(3, 3), 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); - _d3d_device->SetTransform(get_tex_mat_sym(i), (D3DMATRIX *)m.get_data()); - _d3d_device->SetTextureStageState(i, D3DTSS_TEXTURETRANSFORMFLAGS, - D3DTTFF_COUNT2); - } else { - 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_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); - } - - } else { - _d3d_device->SetTextureStageState(i, D3DTSS_TEXTURETRANSFORMFLAGS, - D3DTTFF_DISABLE); - // For some reason, "disabling" texture coordinate transforms - // doesn't seem to be sufficient. We'll load an identity matrix - // to underscore the point. - _d3d_device->SetTransform(get_tex_mat_sym(i), &_d3d_ident_mat); - } - } - - // Disable the texture stages that are no longer used. - for (i = num_stages; i < num_old_stages; i++) { - _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::enable_lighting -// Access: Protected, Virtual -// Description: Intended to be overridden by a derived class to -// enable or disable the use of lighting overall. This -// is called by issue_light() according to whether any -// lights are in use or not. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -enable_lighting(bool enable) { - _d3d_device->SetRenderState(D3DRENDERSTATE_LIGHTING, (DWORD)enable); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_ambient_light -// Access: Protected, Virtual -// Description: Intended to be overridden by a derived class to -// indicate the color of the ambient light that should -// be in effect. This is called by issue_light() after -// all other lights have been enabled or disabled. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -set_ambient_light(const Colorf &color) { - Colorf c = color; - c.set(c[0] * _light_color_scale[0], - c[1] * _light_color_scale[1], - c[2] * _light_color_scale[2], - c[3] * _light_color_scale[3]); - - _d3d_device->SetRenderState(D3DRENDERSTATE_AMBIENT, Colorf_to_D3DCOLOR(c)); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::enable_light -// Access: Protected, Virtual -// Description: Intended to be overridden by a derived class to -// enable the indicated light id. A specific Light will -// already have been bound to this id via bind_light(). -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -enable_light(int light_id, bool enable) { - HRESULT hr = _d3d_device->LightEnable(light_id, enable); - - if (FAILED(hr)) { - wdxdisplay7_cat.warning() - << "Could not enable light " << light_id << ": " - << D3DERRORSTRING(hr) << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::enable_clip_plane -// Access: Protected, Virtual -// Description: Intended to be overridden by a derived class to -// enable the indicated clip_plane id. A specific -// PlaneNode will already have been bound to this id via -// bind_clip_plane(). -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -enable_clip_plane(int plane_id, bool enable) { - if (enable) { - _clip_plane_bits |= ((DWORD)1 << plane_id); - } else { - _clip_plane_bits &= ~((DWORD)1 << plane_id); - } - _d3d_device->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE, _clip_plane_bits); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::bind_clip_plane -// Access: Protected, Virtual -// Description: Called the first time a particular clip_plane has been -// bound to a given id within a frame, this should set -// up the associated hardware clip_plane with the clip_plane's -// properties. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -bind_clip_plane(const NodePath &plane, int plane_id) { - // Get the plane in "world coordinates". This means the plane in - // the coordinate space of the camera, converted to DX's coordinate - // system. - CPT(TransformState) transform = plane.get_transform(_scene_setup->get_camera_path()); - const LMatrix4f &plane_mat = transform->get_mat(); - LMatrix4f rel_mat = plane_mat * LMatrix4f::convert_mat(CS_yup_left, CS_default); - const PlaneNode *plane_node; - DCAST_INTO_V(plane_node, plane.node()); - Planef world_plane = plane_node->get_plane() * rel_mat; - - HRESULT hr = _d3d_device->SetClipPlane(plane_id, (D3DVALUE*)world_plane.get_data()); - if (FAILED(hr)) { - wdxdisplay7_cat.warning() - << "Could not set clip plane for " << plane - << " to id " << plane_id << ": " << D3DERRORSTRING(hr) << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_blend_mode -// Access: Protected, Virtual -// Description: Called after any of the things that might change -// blending state have changed, this function is -// responsible for setting the appropriate color -// blending mode based on the current properties. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_issue_blending() { - - // Handle the color_write attrib. If color_write is off, then - // all the other blending-related stuff doesn't matter. If the - // device doesn't support color-write, we use blending tricks - // to effectively disable color write. - if (_target._color_write->get_channels() == ColorWriteAttrib::C_off) { - if (_target._color_write != _state._color_write) { - _d3d_device->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); - _d3d_device->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ZERO); - _d3d_device->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE); - } - return; - } - - CPT(ColorBlendAttrib) color_blend = _target._color_blend; - ColorBlendAttrib::Mode color_blend_mode = _target._color_blend->get_mode(); - TransparencyAttrib::Mode transparency_mode = _target._transparency->get_mode(); - - // Is there a color blend set? - if (color_blend_mode != ColorBlendAttrib::M_none) { - _d3d_device->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); - - // DX7 supports only ColorBlendAttrib::M_add. Assume that's what - // we've got; if the user asked for anything else, give him M_add - // instead. - _d3d_device->SetRenderState(D3DRENDERSTATE_SRCBLEND, get_blend_func(color_blend->get_operand_a())); - _d3d_device->SetRenderState(D3DRENDERSTATE_DESTBLEND, get_blend_func(color_blend->get_operand_b())); - } - - // No color blend; is there a transparency set? - switch (transparency_mode) { - case TransparencyAttrib::M_none: - case TransparencyAttrib::M_binary: - break; - - case TransparencyAttrib::M_alpha: - case TransparencyAttrib::M_multisample: - case TransparencyAttrib::M_multisample_mask: - case TransparencyAttrib::M_dual: - _d3d_device->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true); - _d3d_device->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA); - _d3d_device->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA); - return; - - default: - dxgsg7_cat.error() - << "invalid transparency mode " << (int)transparency_mode << endl; - break; - } - - // Nothing's set, so disable blending. - _d3d_device->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::free_nondx_resources -// Access: Public -// Description: Frees some memory that was explicitly allocated -// within the dxgsg. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -free_nondx_resources() { -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::free_d3d_device -// Access: Public -// Description: setup for re-calling dx_init(), this is not the final -// exit cleanup routine (see dx_cleanup) -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -free_d3d_device() { - // dont want a full reset of gsg, just a state clear - _state_rs = 0; - _state.clear_to_zero(); - // want gsg to pass all state settings through - - _dx_is_ready = false; - - if (_d3d_device != NULL) - _d3d_device->SetTexture(0, NULL); // d3d should release this stuff internally anyway, but whatever - - release_all(); - - if (_d3d_device != NULL) - RELEASE(_d3d_device, dxgsg7, "d3dDevice", RELEASE_DOWN_TO_ZERO); - - free_nondx_resources(); - - // obviously we dont release ID3D7, just ID3DDevice7 -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_draw_buffer -// Access: Protected -// Description: Sets up the glDrawBuffer to render into the buffer -// indicated by the RenderBuffer object. This only sets -// up the color bits; it does not affect the depth, -// stencil, accum layers. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -set_draw_buffer(const RenderBuffer &rb) { - dxgsg7_cat.fatal() << "DX set_draw_buffer unimplemented!!!"; - return; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_read_buffer -// Access: Protected -// Description: Vestigial analog of glReadBuffer -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -set_read_buffer(const RenderBuffer &rb) { - if (rb._buffer_type & RenderBuffer::T_front) { - _cur_read_pixel_buffer = RenderBuffer::T_front; - } else if (rb._buffer_type & RenderBuffer::T_back) { - _cur_read_pixel_buffer = RenderBuffer::T_back; - } else { - dxgsg7_cat.error() << "Invalid or unimplemented Argument to set_read_buffer!\n"; - } - return; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::do_auto_rescale_normal -// Access: Protected -// Description: Issues the appropriate GL commands to either rescale -// or normalize the normals according to the current -// transform. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -do_auto_rescale_normal() { - if (_external_transform->has_identity_scale()) { - // If there's no scale, don't normalize anything. - _d3d_device->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, false); - - } else { - // If there is a scale, turn on normalization. - _d3d_device->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, true); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::get_light_color -// Access: Public -// Description: Returns the array of four floats that should be -// issued as the light's color, as scaled by the current -// value of _light_color_scale, in the case of -// color_scale_via_lighting. -//////////////////////////////////////////////////////////////////// -const D3DCOLORVALUE &DXGraphicsStateGuardian7:: -get_light_color(Light *light) const { - static Colorf c; - c = light->get_color(); - c.set(c[0] * _light_color_scale[0], - c[1] * _light_color_scale[1], - c[2] * _light_color_scale[2], - c[3] * _light_color_scale[3]); - return *(D3DCOLORVALUE *)c.get_data(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_blend_func -// Access: Protected, Static -// Description: Maps from ColorBlendAttrib::Operand to D3DBLEND -// value. -//////////////////////////////////////////////////////////////////// -D3DBLEND DXGraphicsStateGuardian7:: -get_blend_func(ColorBlendAttrib::Operand operand) { - switch (operand) { - case ColorBlendAttrib::O_zero: - return D3DBLEND_ZERO; - - case ColorBlendAttrib::O_one: - return D3DBLEND_ONE; - - case ColorBlendAttrib::O_incoming_color: - return D3DBLEND_SRCCOLOR; - - case ColorBlendAttrib::O_one_minus_incoming_color: - return D3DBLEND_INVSRCCOLOR; - - case ColorBlendAttrib::O_fbuffer_color: - return D3DBLEND_DESTCOLOR; - - case ColorBlendAttrib::O_one_minus_fbuffer_color: - return D3DBLEND_INVDESTCOLOR; - - case ColorBlendAttrib::O_incoming_alpha: - return D3DBLEND_SRCALPHA; - - case ColorBlendAttrib::O_one_minus_incoming_alpha: - return D3DBLEND_INVSRCALPHA; - - case ColorBlendAttrib::O_fbuffer_alpha: - return D3DBLEND_DESTALPHA; - - case ColorBlendAttrib::O_one_minus_fbuffer_alpha: - return D3DBLEND_INVDESTALPHA; - - case ColorBlendAttrib::O_constant_color: - // Not supported by DX. - return D3DBLEND_SRCCOLOR; - - case ColorBlendAttrib::O_one_minus_constant_color: - // Not supported by DX. - return D3DBLEND_INVSRCCOLOR; - - case ColorBlendAttrib::O_constant_alpha: - // Not supported by DX. - return D3DBLEND_SRCALPHA; - - case ColorBlendAttrib::O_one_minus_constant_alpha: - // Not supported by DX. - return D3DBLEND_INVSRCALPHA; - - case ColorBlendAttrib::O_incoming_color_saturate: - return D3DBLEND_SRCALPHASAT; - } - - dxgsg7_cat.error() - << "Unknown color blend operand " << (int)operand << endl; - return D3DBLEND_ZERO; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::report_texmgr_stats -// Access: Protected -// Description: Reports the DX texture manager's activity to PStats. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -report_texmgr_stats() { - -#ifdef DO_PSTATS -#ifdef TEXMGRSTATS_USES_GETAVAILVIDMEM - DWORD dwTexTotal, dwTexFree, dwVidTotal, dwVidFree; - - if (_total_texmem_pcollector.is_active()) { - DDSCAPS2 ddsCaps; - - ZeroMemory(&ddsCaps, sizeof(ddsCaps)); - - ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE; - if (FAILED( hr = _d3d_device->GetAvailableVidMem(&ddsCaps, &dwVidTotal, &dwVidFree))) { - dxgsg7_cat.fatal() << "report_texmgr GetAvailableVidMem for VIDMEM failed : result = " << D3DERRORSTRING(hr); - throw_event("panda3d-render-error"); - return; - } - - ddsCaps.dwCaps = DDSCAPS_TEXTURE; - if (FAILED( hr = _d3d_device->GetAvailableVidMem(&ddsCaps, &dwTexTotal, &dwTexFree))) { - dxgsg7_cat.fatal() << "report_texmgr GetAvailableVidMem for TEXTURE failed : result = " << D3DERRORSTRING(hr); - throw_event("panda3d-render-error"); - return; - } - } -#endif // TEXMGRSTATS_USES_GETAVAILVIDMEM -#endif // DO_PSTATS -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_context -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -set_context(DXScreenData *new_context) { - nassertv(new_context != NULL); - _screen = new_context; - _d3d_device = _screen->pD3DDevice; //copy this one field for speed of deref -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_render_target -// Access: Protected -// Description: Set render target to the backbuffer of current swap -// chain. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -set_render_target() { -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::set_texture_blend_mode -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -set_texture_blend_mode(int i, const TextureStage *stage) { - _d3d_device->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_MODULATE); - _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TEXTURE); - _d3d_device->SetTextureStageState(i, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - _d3d_device->SetTextureStageState(i, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::dx_cleanup -// Access: Protected -// Description: Clean up the DirectX environment, accounting for exit() -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -dx_cleanup() { - if (!_d3d_device) { - return; - } - - free_nondx_resources(); - - // Do a safe check for releasing the D3DDEVICE. RefCount should be zero. - // if we're called from exit(), _d3d_device may already have been released - RELEASE(_d3d_device, dxgsg7, "d3dDevice", RELEASE_DOWN_TO_ZERO); - _d3d_device = NULL; - _screen->pD3DDevice = NULL; - - // Releasing pD3D is now the responsibility of the GraphicsPipe destructor -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::check_cooperative_level -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -bool DXGraphicsStateGuardian7:: -check_cooperative_level() { - HRESULT hr = _screen->pDD->TestCooperativeLevel(); - - if (SUCCEEDED(_last_testcooplevel_result)) { - if (SUCCEEDED(hr)) { - // this means this was just a safety check, dont need to restore surfs - return true; - } - - // otherwise something just went wrong - if (hr == DDERR_NOEXCLUSIVEMODE || hr == DDERR_EXCLUSIVEMODEALREADYSET) { - // This means that mode changes had taken place, surfaces - // were lost but still we are in the original mode, so we - // simply restore all surfaces and keep going. - - if (dxgsg7_cat.is_debug()) { - dxgsg7_cat.debug() - << "Another app has DDRAW exclusive mode, waiting...\n"; - } - - // This doesn't seem to be necessary. - /* - if (_dx_ready) { - _win->deactivate_window(); - _dx_ready = FALSE; - } - */ - - } else if (hr == DDERR_WRONGMODE) { - // This means that the desktop mode has changed. need to - // destroy all of dx stuff and recreate everything back again, - // which is a big hit - dxgsg7_cat.error() - << "detected display mode change in TestCoopLevel, must recreate all DDraw surfaces, D3D devices, this is not handled yet. hr == " << ConvD3DErrorToString(hr) << endl; - exit(1); - } else if (FAILED(hr)) { - dxgsg7_cat.error() - << "unexpected return code from TestCoopLevel: " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - } else { - // testcooplvl was failing, handle case where it now succeeds - - if (SUCCEEDED(hr)) { - if (_last_testcooplevel_result == DDERR_EXCLUSIVEMODEALREADYSET || - _last_testcooplevel_result == DDERR_NOEXCLUSIVEMODE) { - if (dxgsg7_cat.is_debug()) { - dxgsg7_cat.debug() - << "other app relinquished exclusive mode, refilling surfs...\n"; - } - } - - // This isn't necessary either. - /* - if (bDoReactivateWindow) { - _win->reactivate_window(); - } - */ - - release_all(); - - // _dx_ready = TRUE; - - } else if (hr == DDERR_WRONGMODE) { - // This means that the desktop mode has changed. need to - // destroy all of dx stuff and recreate everything back again, - // which is a big hit - dxgsg7_cat.error() - << "detected desktop display mode change in TestCoopLevel, must recreate all DDraw surfaces & D3D devices, this is not handled yet. " << ConvD3DErrorToString(hr) << endl; - //_win->close_window(); - exit(1); - } else if ((hr!=DDERR_NOEXCLUSIVEMODE) && (hr!=DDERR_EXCLUSIVEMODEALREADYSET)) { - dxgsg7_cat.error() - << "unexpected return code from TestCoopLevel: " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - } - - _last_testcooplevel_result = hr; - return SUCCEEDED(hr); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::show_frame -// Access: Protected -// Description: redraw primary buffer -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -show_frame() { - if(_screen->pddsPrimary==NULL) - return; - - // DO_PSTATS_STUFF(PStatTimer timer(_win->_swap_pcollector)); // this times just the flip, so it must go here in dxgsg7, instead of wdxdisplay, which would time the whole frame - - if (_screen->bIsFullScreen) { - show_full_screen_frame(); - } else { - show_windowed_frame(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: show_full_screen_frame -// Access: -// Description: Repaint primary buffer from back buffer -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7::show_full_screen_frame() { - HRESULT hr; - - // Flip the front and back buffers, to make what we just rendered - // visible. - - DWORD dwFlipFlags = DDFLIP_WAIT; - hr = _screen->pddsPrimary->Flip( NULL, dwFlipFlags); - - if(FAILED(hr)) { - if((hr == DDERR_SURFACELOST) || (hr == DDERR_SURFACEBUSY)) { - check_cooperative_level(); - } else { - dxgsg7_cat.error() << "show_frame() - Flip failed w/unexpected error code: " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: show_windowed_frame -// Access: Public -// Description: Repaint primary buffer from back buffer (windowed -// mode only) -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7::show_windowed_frame() { - HRESULT hr; - - hr = _screen->pDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); - if(hr != DD_OK) { - dxgsg7_cat.error() - << "WaitForVerticalBlank() failed : " << ConvD3DErrorToString(hr) - << endl; - throw_event("panda3d-render-error"); - } - - DX_DECLARE_CLEAN(DDBLTFX, bltfx); - - bltfx.dwDDFX |= DDBLTFX_NOTEARING; // hmm, does any driver actually recognize this flag? - hr = _screen->pddsPrimary->Blt( &_screen->view_rect, _screen->pddsBack, NULL, DDBLT_DDFX | DDBLT_WAIT, &bltfx ); - - if(FAILED(hr)) { - if((hr == DDERR_SURFACELOST) || (hr == DDERR_SURFACEBUSY)) { - check_cooperative_level(); - } else { - dxgsg7_cat.error() << "show_frame() - Blt failed : " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - } - -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::copy_pres_reset -// Access: Protected -// Description: copies the PresReset from passed DXScreenData -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian7:: -copy_pres_reset(DXScreenData *screen) { -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_d3d_min_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -D3DTEXTUREMINFILTER DXGraphicsStateGuardian7:: -get_d3d_min_type(Texture::FilterType filter_type) { - switch (filter_type) { - case Texture::FT_nearest: - return D3DTFN_POINT; - - case Texture::FT_linear: - return D3DTFN_LINEAR; - - case Texture::FT_nearest_mipmap_nearest: - return D3DTFN_POINT; - - case Texture::FT_linear_mipmap_nearest: - return D3DTFN_LINEAR; - - case Texture::FT_nearest_mipmap_linear: - return D3DTFN_POINT; - - case Texture::FT_linear_mipmap_linear: - return D3DTFN_LINEAR; - } - - dxgsg7_cat.error() - << "Invalid FilterType value (" << (int)filter_type << ")\n"; - return D3DTFN_POINT; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_d3d_mip_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -D3DTEXTUREMIPFILTER DXGraphicsStateGuardian7:: -get_d3d_mip_type(Texture::FilterType filter_type) { - switch (filter_type) { - case Texture::FT_nearest: - return D3DTFP_NONE; - - case Texture::FT_linear: - return D3DTFP_NONE; - - case Texture::FT_nearest_mipmap_nearest: - return D3DTFP_POINT; - - case Texture::FT_linear_mipmap_nearest: - return D3DTFP_POINT; - - case Texture::FT_nearest_mipmap_linear: - return D3DTFP_LINEAR; - - case Texture::FT_linear_mipmap_linear: - return D3DTFP_LINEAR; - } - - dxgsg7_cat.error() - << "Invalid FilterType value (" << (int)filter_type << ")\n"; - return D3DTFP_NONE; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_texture_operation -// Access: Public, Static -// Description: Returns the D3DTEXTUREOP value corresponding to the -// indicated TextureStage::CombineMode enumerated type. -//////////////////////////////////////////////////////////////////// -D3DTEXTUREOP DXGraphicsStateGuardian7:: -get_texture_operation(TextureStage::CombineMode mode, int scale) { - return D3DTOP_SELECTARG1; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_texture_argument -// Access: Public, Static -// Description: Returns the D3DTA value corresponding to the -// indicated TextureStage::CombineSource and -// TextureStage::CombineOperand enumerated types. -//////////////////////////////////////////////////////////////////// -DWORD DXGraphicsStateGuardian7:: -get_texture_argument(TextureStage::CombineSource source, - TextureStage::CombineOperand operand) { - return D3DTA_CURRENT; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::get_texture_argument_modifier -// Access: Public, Static -// Description: Returns the extra bits that modify the D3DTA -// argument, according to the indicated -// TextureStage::CombineOperand enumerated type. -//////////////////////////////////////////////////////////////////// -DWORD DXGraphicsStateGuardian7:: -get_texture_argument_modifier(TextureStage::CombineOperand operand) { - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian7::enum_tex_formats_callback -// Access: Public, Static -// Description: This is attached as a callback to the -// EnumTextureFormats() call, which gets all of the -// available texture formats for the display device. -//////////////////////////////////////////////////////////////////// -HRESULT CALLBACK DXGraphicsStateGuardian7:: -enum_tex_formats_callback(LPDDPIXELFORMAT pddpf, void *param) { - DXGraphicsStateGuardian7 *gsg = (DXGraphicsStateGuardian7 *)param; - nassertr(gsg->_num_tex_formats < MAX_DX_TEXPIXFMTS, E_FAIL); - memcpy(&(gsg->_tex_formats[gsg->_num_tex_formats]), pddpf, - sizeof(DDPIXELFORMAT)); - gsg->_num_tex_formats++; - - return DDENUMRET_OK; -} diff --git a/panda/src/dxgsg7/dxGraphicsStateGuardian7.h b/panda/src/dxgsg7/dxGraphicsStateGuardian7.h deleted file mode 100644 index 7e5097b049..0000000000 --- a/panda/src/dxgsg7/dxGraphicsStateGuardian7.h +++ /dev/null @@ -1,239 +0,0 @@ -// Filename: dxGraphicsStateGuardian7.h -// Created by: mike (02Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DXGRAPHICSSTATEGUARDIAN7_H -#define DXGRAPHICSSTATEGUARDIAN7_H - -#include "dxgsg7base.h" -#include "dxTextureContext7.h" -#include "config_dxgsg7.h" - -#include "graphicsStateGuardian.h" -#include "texture.h" -#include "displayRegion.h" -#include "material.h" -#include "depthTestAttrib.h" -#include "cullFaceAttrib.h" -#include "renderModeAttrib.h" -#include "fog.h" -#include "pointerToArray.h" - -class Light; - -class DXVertexBufferContext7; -class DXIndexBufferContext7; - -//////////////////////////////////////////////////////////////////// -// Class : DXGraphicsStateGuardian7 -// Description : A GraphicsStateGuardian for rendering into DirectX7 -// contexts. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDADX DXGraphicsStateGuardian7 : public GraphicsStateGuardian { -public: - DXGraphicsStateGuardian7(const FrameBufferProperties &properties); - ~DXGraphicsStateGuardian7(); - - virtual TextureContext *prepare_texture(Texture *tex); - void apply_texture(int i, TextureContext *tc); - virtual void release_texture(TextureContext *tc); - - virtual PT(GeomMunger) make_geom_munger(const RenderState *state); - - virtual void set_color_clear_value(const Colorf &value); - - virtual void do_clear(const RenderBuffer &buffer); - - virtual void prepare_display_region(); - virtual bool prepare_lens(); - - virtual bool begin_frame(); - virtual bool begin_scene(); - virtual void end_scene(); - virtual void end_frame(); - - virtual bool begin_draw_primitives(const Geom *geom, - const GeomMunger *munger, - const GeomVertexData *vertex_data); - void determine_fvf(); - virtual void draw_triangles(const GeomTriangles *primitive); - virtual void draw_lines(const GeomLines *primitive); - virtual void draw_points(const GeomPoints *primitive); - virtual void end_draw_primitives(); - - virtual void framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, - const RenderBuffer &rb); - virtual bool framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, - const RenderBuffer &rb); - - virtual void reset(); - - virtual void apply_fog(Fog *fog); - - virtual void bind_light(PointLight *light_obj, const NodePath &light, - int light_id); - virtual void bind_light(DirectionalLight *light_obj, const NodePath &light, - int light_id); - virtual void bind_light(Spotlight *light_obj, const NodePath &light, - int light_id); - - INLINE static DWORD Colorf_to_D3DCOLOR(const Colorf &cColorf); - - virtual void set_state_and_transform(const RenderState *state, - const TransformState *transform); - -protected: - void do_issue_transform(); - void do_issue_alpha_test(); - void do_issue_render_mode(); - void do_issue_rescale_normal(); - void do_issue_color_write(); - void do_issue_depth_test(); - void do_issue_depth_write(); - void do_issue_cull_face(); - void do_issue_fog(); - void do_issue_depth_offset(); - void do_issue_tex_gen(); - void do_issue_shade_model(); - void do_issue_material(); - void do_issue_texture(); - void do_issue_blending(); - - virtual void enable_lighting(bool enable); - virtual void set_ambient_light(const Colorf &color); - virtual void enable_light(int light_id, bool enable); - - virtual void enable_clip_plane(int plane_id, bool enable); - virtual void bind_clip_plane(const NodePath &plane, int plane_id); - - void free_nondx_resources(); - void free_d3d_device(); - - void set_draw_buffer(const RenderBuffer &rb); - void set_read_buffer(const RenderBuffer &rb); - - void do_auto_rescale_normal(); - -protected: - INLINE static D3DTEXTUREADDRESS get_texture_wrap_mode(Texture::WrapMode wm); - INLINE static D3DFOGMODE get_fog_mode_type(Fog::Mode m); - const D3DCOLORVALUE &get_light_color(Light *light) const; - INLINE static D3DTRANSFORMSTATETYPE get_tex_mat_sym(int stage_index); - - static D3DBLEND get_blend_func(ColorBlendAttrib::Operand operand); - void report_texmgr_stats(); - - void set_context(DXScreenData *new_context); - void set_render_target(); - - void set_texture_blend_mode(int i, const TextureStage *stage); - - void dx_cleanup(); - - bool check_cooperative_level(); - - void show_frame(); - void show_full_screen_frame(); - void show_windowed_frame(); - - void copy_pres_reset(DXScreenData *new_context); - - static D3DTEXTUREMINFILTER get_d3d_min_type(Texture::FilterType filter_type); - static D3DTEXTUREMIPFILTER get_d3d_mip_type(Texture::FilterType filter_type); - static D3DTEXTUREOP get_texture_operation(TextureStage::CombineMode mode, int scale); - static DWORD get_texture_argument(TextureStage::CombineSource source, - TextureStage::CombineOperand operand); - static DWORD get_texture_argument_modifier(TextureStage::CombineOperand operand); - - static HRESULT CALLBACK enum_tex_formats_callback(LPDDPIXELFORMAT pddpf, void *param); - -protected: - DXScreenData *_screen; - LPDIRECT3DDEVICE7 _d3d_device; // same as _screen->_d3d_device, cached for spd - - bool _dx_is_ready; - HRESULT _last_testcooplevel_result; - - bool _vertex_blending_enabled; - - RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation - bool _auto_rescale_normal; - - D3DCOLOR _d3dcolor_clear_value; - UINT _color_writemask; - - float _material_ambient; - float _material_diffuse; - float _material_specular; - float _material_shininess; - float _material_emission; - - enum DxgsgFogType { - None, - PerVertexFog=D3DRENDERSTATE_FOGVERTEXMODE, - PerPixelFog=D3DRENDERSTATE_FOGTABLEMODE - }; - DxgsgFogType _do_fog_type; - - DWORD _clip_plane_bits; - CullFaceAttrib::Mode _cull_face_mode; - RenderModeAttrib::Mode _current_fill_mode; //point/wireframe/solid - - LMatrix4f _projection_mat; - - CPT(DisplayRegion) _actual_display_region; - const DXVertexBufferContext7 *_active_vbuffer; - const DXIndexBufferContext7 *_active_ibuffer; - - bool _tex_stats_retrieval_impossible; - - int _fvf; - LPDDPIXELFORMAT _tex_formats; - int _num_tex_formats; - - static D3DMATRIX _d3d_ident_mat; - -public: - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - - static TypeHandle get_class_type() { - return _type_handle; - } - -public: - static void init_type() { - GraphicsStateGuardian::init_type(); - register_type(_type_handle, "DXGraphicsStateGuardian7", - GraphicsStateGuardian::get_class_type()); - } - -private: - static TypeHandle _type_handle; - - friend class wdxGraphicsWindow7; - friend class wdxGraphicsPipe7; - friend class wdxGraphicsWindowGroup7; - friend class DXTextureContext7; -}; - -#include "dxGraphicsStateGuardian7.I" - -#endif - diff --git a/panda/src/dxgsg7/dxTextureContext7.I b/panda/src/dxgsg7/dxTextureContext7.I deleted file mode 100755 index a0841b925f..0000000000 --- a/panda/src/dxgsg7/dxTextureContext7.I +++ /dev/null @@ -1,29 +0,0 @@ -// Filename: dxTextureContext7.I -// Created by: drose (26Oct05) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: DXTextureContext7::has_mipmaps -// Access: Public -// Description: Returns true if the texture was created with mipmaps, -// false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool DXTextureContext7:: -has_mipmaps() const { - return _has_mipmaps; -} diff --git a/panda/src/dxgsg7/dxTextureContext7.cxx b/panda/src/dxgsg7/dxTextureContext7.cxx deleted file mode 100644 index 62446a7cf6..0000000000 --- a/panda/src/dxgsg7/dxTextureContext7.cxx +++ /dev/null @@ -1,1955 +0,0 @@ -// Filename: dxTextureContext7.cxx -// Created by: drose (07Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#include -#include -#include "dxTextureContext7.h" -#include "config_dxgsg7.h" -#include "dxGraphicsStateGuardian7.h" -#include "pnmImage.h" - -static const DWORD g_LowByteMask = 0x000000FF; - -//#define FORCE_16bpp_1555 - -#define PANDA_BGRA_ORDER - -#ifdef PANDA_BGRA_ORDER -// assume Panda uses byte-order BGRA/LA to store pixels, which when read into little-endian word is ARGB/AL -// these macros GET from Texture, (wont work from DDSurface) -#define GET_RED_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD >> 16) & g_LowByteMask)) -#define GET_BLUE_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD) & g_LowByteMask)) -#else -// otherwise Panda uses int ABGR (big-endian RGBA order), (byte-order RGBA or RGB) -#define GET_RED_BYTE(PIXEL_DWORD) ((BYTE)(PIXEL_DWORD & g_LowByteMask)) -#define GET_BLUE_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD >> 16) & g_LowByteMask)) -#endif - -#define GET_GREEN_BYTE(PIXEL_DWORD) ((BYTE)((PIXEL_DWORD >> 8) & g_LowByteMask)) -#define GET_ALPHA_BYTE(PIXEL_DWORD) ((BYTE)(((DWORD)PIXEL_DWORD) >> 24)) // unsigned >> shifts in 0's, so dont need to mask off upper bits - -typedef enum { - None,Conv32to32,Conv32to32_NoAlpha,Conv32to24,Conv32to16_X555, - Conv32to16_1555,Conv32to16_0565,Conv32to16_4444,Conv24to32,Conv24to24, - Conv24to16_X555,Conv24to16_0565,ConvLum16to16_1555,ConvLum16to16_4444, - ConvLum16to32,ConvLum16to16,ConvLum8to8,ConvLum8to24,ConvLum8to32,ConvLum8to16_X555,ConvLum8to16_0565, - ConvAlpha8to16_4444,ConvAlpha8to32,ConvAlpha8to8 -} ConversionType; - -#ifndef NDEBUG -char *ConvNameStrs[] = {"None","Conv32to32","Conv32to32_NoAlpha","Conv32to24","Conv32to16_X555", - "Conv32to16_1555","Conv32to16_0565","Conv32to16_4444","Conv24to32","Conv24to24", - "Conv24to16_X555","Conv24to16_0565","ConvLum16to16_1555","ConvLum16to16_4444", - "ConvLum16to32","ConvLum16to16","ConvLum8to8","ConvLum8to24","ConvLum8to32", - "ConvLum8to16_X555","ConvLum8to16_0565","ConvAlpha8to16_4444","ConvAlpha8to32","ConvAlpha8to8" -}; -#endif - -char *PandaFilterNameStrs[] = {"FT_nearest","FT_linear","FT_nearest_mipmap_nearest","FT_linear_mipmap_nearest", - "FT_nearest_mipmap_linear", "FT_linear_mipmap_linear" -}; - -TypeHandle DXTextureContext7::_type_handle; - -#define SWAPDWORDS(X,Y) { DWORD temp=X; X=Y; Y=temp; } - -#ifdef _DEBUG -static void DebugPrintPixFmt(DDPIXELFORMAT* pddpf) { - static int iddpfnum=0; - ostream *dbgout = &dxgsg7_cat.debug(); - - *dbgout << "DDPF[" << iddpfnum << "]: RGBBitCount:" << pddpf->dwRGBBitCount - << " Flags:" << (void *)pddpf->dwFlags ; - - if(pddpf->dwFlags & DDPF_RGB) { - *dbgout << " RGBmask:" << (void *) (pddpf->dwRBitMask | pddpf->dwGBitMask | pddpf->dwBBitMask); - *dbgout << " Rmask:" << (void *) (pddpf->dwRBitMask); - } - - if(pddpf->dwFlags & DDPF_ALPHAPIXELS) { - *dbgout << " Amask:" << (void *) pddpf->dwRGBAlphaBitMask; - } - - if(pddpf->dwFlags & DDPF_LUMINANCE) { - *dbgout << " Lummask:" << (void *) pddpf->dwLuminanceBitMask; - } - - *dbgout << endl; - - iddpfnum++; -} - -void PrintLastError(char *msgbuf) { - DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; - - if(msgbuf==NULL) { - LPVOID lpMsgBuf; - dwFlags|=FORMAT_MESSAGE_ALLOCATE_BUFFER; - FormatMessage( dwFlags, - NULL,GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf,0,NULL ); - MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); - LocalFree(lpMsgBuf); - } else { - FormatMessage( dwFlags, - NULL,GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) msgbuf,500,NULL ); - } -} - -#endif - - -/* for reference -enum Format { - F_color_index, - F_stencil_index, - F_depth_component, - F_red, - F_green, - F_blue, - F_alpha, - F_rgb, // any suitable RGB mode, whatever the hardware prefers - F_rgb5, // specifically, 5 bits per R,G,B channel - F_rgb8, // 8 bits per R,G,B channel - F_rgb12, // 12 bits per R,G,B channel - F_rgb332, // 3 bits per R & G, 2 bits for B - F_rgba, // any suitable RGBA mode, whatever the hardware prefers - F_rgbm, // as above, but only requires 1 bit for alpha (i.e. mask) - F_rgba4, // 4 bits per R,G,B,A channel - F_rgba5, // 5 bits per R,G,B channel, 1 bit alpha - F_rgba8, // 8 bits per R,G,B,A channel - F_rgba12, // 12 bits per R,G,B,A channel - F_luminance, - F_luminance_alpha -}; - - enum Type { - T_unsigned_byte, // 1 byte per channel - T_unsigned_short, // 2 byte per channel - T_unsigned_byte_332, // RGB in 1 byte - T_float, // 1 channel stored as float - }; -*/ - -//////////////////////////////////////////////////////////////////// -// Function: DXTextureContext7::get_bits_per_pixel -// Access: Protected -// Description: Maps from the Texture's Format symbols -// to bpp. returns # of alpha bits -// Note: Texture's format indicates REQUESTED final format, -// not the stored format, which is indicated by pixelbuffer type -//////////////////////////////////////////////////////////////////// - -unsigned int DXTextureContext7:: -get_bits_per_pixel(Texture::Format format, int *alphbits) { - *alphbits = 0; // assume no alpha bits - switch(format) { - case Texture::F_alpha: - *alphbits = 8; - return 8; - case Texture::F_color_index: - case Texture::F_red: - case Texture::F_green: - case Texture::F_blue: - case Texture::F_rgb332: - case Texture::F_luminance_alphamask: - *alphbits = 1; - return 16; - case Texture::F_luminance_alpha: - *alphbits = 8; - return 16; - case Texture::F_luminance: - return 8; - case Texture::F_rgba4: - *alphbits = 4; - return 16; - case Texture::F_rgba5: - *alphbits = 1; - return 16; - case Texture::F_depth_component: - case Texture::F_rgb5: - return 16; - case Texture::F_rgb8: - case Texture::F_rgb: - return 24; - case Texture::F_rgba8: - case Texture::F_rgba: - *alphbits = 8; - return 32; - case Texture::F_rgbm: - *alphbits = 1; - return 32; - case Texture::F_rgb12: - return 36; - case Texture::F_rgba12: - *alphbits = 12; - return 48; - } - return 8; -} - -HRESULT ConvertPixBuftoDDSurf(ConversionType ConvNeeded,BYTE *pbuf,LPDIRECTDRAWSURFACE7 pDDSurf) { - HRESULT hr; - DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd); - - if(IsBadWritePtr(pDDSurf,sizeof(DWORD))) { - dxgsg7_cat.error() << "ConvertPixBuftoDDSurf failed: bad pDDSurf ptr value (" << ((void*)pDDSurf) << ")\n"; - exit(1); - } - - if(FAILED( hr = pDDSurf->Lock( NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL ))) { - dxgsg7_cat.error() << "create_texture failed: _surface->Lock() failed on texture! hr = " << ConvD3DErrorToString(hr) << "\n"; - return hr; - } - - //pbuf contains raw ARGB in Texture byteorder - - DWORD lPitch = ddsd.lPitch; - BYTE* pDDSurfBytes = (BYTE*)ddsd.lpSurface; - DWORD dwOrigWidth=ddsd.dwWidth,dwOrigHeight=ddsd.dwHeight; - - switch(ConvNeeded) { - case Conv32to32: - case Conv32to32_NoAlpha: { - -#ifdef PANDA_BGRA_ORDER - if(ConvNeeded==Conv32to32) { - memcpy(pDDSurfBytes,(BYTE*) pbuf,dwOrigWidth*dwOrigHeight*sizeof(DWORD)); - } else { - DWORD *pSrcWord = (DWORD *) pbuf; - DWORD *pDstWord; - - // need to set all pixels alpha to 0xFF - for(DWORD y=0; y>16) & 0x00008000) | dwAlphaMaskOn; // just copy high bit - g = GET_GREEN_BYTE(dwPixel) >> 3; - b = GET_BLUE_BYTE(dwPixel) >> 3; - r = GET_RED_BYTE(dwPixel) >> 3; - - // truncates 8 bit values to 5 bit (or 1 for alpha) - - *pDstWord = (abit | (r << 10)| (g << 5) | b); - } - } - break; - } - - case Conv32to16_0565: { // could merge this w/above case, but whatever - DWORD *pSrcWord = (DWORD *) pbuf; - WORD *pDstWord; - - assert(ddsd.ddpfPixelFormat.dwRBitMask==0xF800); - // for some reason, bits are 'in-order' when converting to 16bit - - for(DWORD y=0; y> 2; - b = GET_BLUE_BYTE(dwPixel) >> 3; - r = GET_RED_BYTE(dwPixel) >> 3; - *pDstWord = ((r << 11)| (g << 5) | b); - } - } - break; - } - - case Conv32to16_4444: { - DWORD *pSrcWord = (DWORD *) pbuf; - WORD *pDstWord; - - assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0xf000); // assumes ARGB - assert(ddsd.ddpfPixelFormat.dwRBitMask==0x0f00); // assumes ARGB - - for(DWORD y=0; y> 4; - g = GET_GREEN_BYTE(dwPixel) >> 4; - b = GET_BLUE_BYTE(dwPixel) >> 4; - r = GET_RED_BYTE(dwPixel) >> 4; - - *pDstWord = (a << 12) | (r << 8)| (g << 4) | b; - } - } - break; - } - - case Conv32to24: { - - DWORD *pSrcWord = (DWORD *) pbuf; - BYTE *pDstWord; - - for(DWORD y=0; y> 3; - r = *(pSrcWord+2) >> 3; - #else - r = *pSrcWord >> 3; - b = *(pSrcWord+2) >> 3; - #endif - g = *(pSrcWord+1) >> 3; - - *pDstWord = 0x8000 | (r << 10)| (g << 5) | b; - } - } - break; - } - - case Conv24to16_0565: { - BYTE *pSrcWord = (BYTE *) pbuf; - WORD *pDstWord; - - assert(ddsd.ddpfPixelFormat.dwRBitMask==0xF800); - - for(DWORD y=0; y> 3; - g = *(pSrcWord+1) >> 2; - r = *(pSrcWord+2) >> 3; - #else - r = *pSrcWord >> 3; - g = *(pSrcWord+1) >> 2; - b = *(pSrcWord+2) >> 3; - #endif - // code truncates 8 bit values to 5 bit - *pDstWord = (r << 11)| (g << 5) | b; - } - } - break; - } - - case Conv24to32: { - BYTE *pSrcWord = (BYTE *) pbuf; - DWORD *pDstWord; - - for(DWORD y=0; y> 8; - lum = dwPixel & 0xFF; - *pDstWord = (a<<24) | lum | (lum << 8) | (lum << 16); - } - } - break; - } - - case ConvLum16to16_4444: { - WORD *pSrcWord = (WORD *) pbuf; - WORD *pDstWord; - - assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0xf000); // assumes ARGB - - for(DWORD y=0; y>8) >> 4; - lum = (BYTE)(dwPixel & 0x000000ff) >> 4; - - *pDstWord = (a << 12) | lum | (lum << 4)| (lum << 8); - } - } - break; - } - - case ConvLum16to16_1555: { - WORD *pSrcWord = (WORD *) pbuf; - WORD *pDstWord; - - assert(ddsd.ddpfPixelFormat.dwRGBAlphaBitMask==0x8000); // assumes ARGB - - for(DWORD y=0; y> 3; - - *pDstWord = (dwPixel & 0x8000) | lum | (lum << 5) | (lum << 10); - } - } - break; - } - - case ConvLum16to16: { - // All bytes are in same order? - CopyMemory(pDDSurfBytes,pbuf,dwOrigWidth*dwOrigHeight*2); - break; - } - - case ConvLum8to16_0565: - case ConvLum8to16_X555: { - BYTE *pSrcWord = (BYTE *) pbuf; - WORD *pDstWord; - DWORD FarShift,OrVal,MiddleRoundShift; - - if(ConvNeeded==ConvLum8to16_X555) { - FarShift=10; OrVal=0x8000; // turn on alpha bit, just in case - MiddleRoundShift = 3; - assert(ddsd.ddpfPixelFormat.dwRBitMask==0x7C00); - } else { - FarShift=11; OrVal=0x0; - MiddleRoundShift = 2; - assert(ddsd.ddpfPixelFormat.dwRBitMask==0xF800); - } - - for(DWORD y=0; y> 3; - GrnVal = (BYTE) dwPixel >> MiddleRoundShift; - - // code truncates 8 bit values to 5 bit (set alpha=1 for opaque) - - *pDstWord = ((r << FarShift)| (GrnVal << 5) | r) | OrVal; - } - } - break; - } - - case ConvLum8to8: { - CopyMemory(pDDSurfBytes,pbuf,dwOrigWidth*dwOrigHeight); - break; - } - - case ConvLum8to32: { - - // this is kind of a waste of space, but we trade it for lum resolution - BYTE *pSrcWord = (BYTE *) pbuf; - DWORD *pDstWord; - - for(DWORD y=0; y>4); - *pDstWord = (a << 12) | 0x0FFF; // OR alpha with full white - } - } - break; - } - - default: - dxgsg7_cat.error() << "create_texture failed! unhandled texture conversion type: "<< ConvNeeded <<" \n"; - pDDSurf->Unlock(NULL); - return E_INVALIDARG; - } - - pDDSurf->Unlock(NULL); - - return S_OK; -} - -HRESULT ConvertDDSurftoPixBuf(Texture *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf) { - - HRESULT hr; - DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd); - - DWORD dwNumComponents=pixbuf->get_num_components(); - - assert((dwNumComponents==3) || (dwNumComponents==4)); // cant handle anything else now - - BYTE *pbuf=pixbuf->modify_ram_image().p(); - - if(IsBadWritePtr(pDDSurf,sizeof(DWORD))) { - dxgsg7_cat.error() << "ConvertDDSurftoPixBuf failed: bad pDDSurf ptr value (" << ((void*)pDDSurf) << ")\n"; - exit(1); - } - - if(FAILED( hr = pDDSurf->Lock( NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL ))) { - dxgsg7_cat.error() << "ConvertDDSurftoPixBuf Lock() failed! hr = " << ConvD3DErrorToString(hr) << "\n"; - return hr; - } - - DWORD dwXWindowOffset=0,dwYWindowOffset=0; - DWORD dwCopyWidth=ddsd.dwWidth,dwCopyHeight=ddsd.dwHeight; - - // get window offset so we know where to start grabbing pixels. note for - // fullscreen primary no clipper will be attached, that 'error' should be ignored - LPDIRECTDRAWCLIPPER pDDClipper; - hr = pDDSurf->GetClipper(&pDDClipper); - -#ifdef _DEBUG - if(FAILED(hr) && !((hr == DDERR_NOCLIPPERATTACHED) && dx_full_screen)) { - dxgsg7_cat.error() << "ConvertDDSurftoPixBuf GetClipper failed! hr = " << ConvD3DErrorToString(hr) << "\n"; - return hr; - } -#endif - - if(hr==S_OK) { - HWND hWin; - - if(FAILED(hr = pDDClipper->GetHWnd(&hWin))) { - dxgsg7_cat.error() << "ConvertDDSurftoPixBuf GetHwnd failed! hr = " << ConvD3DErrorToString(hr) << "\n"; - return hr; - } - - RECT view_rect; - GetClientRect( hWin, &view_rect ); - ClientToScreen( hWin, (POINT*)&view_rect.left ); - ClientToScreen( hWin, (POINT*)&view_rect.right ); - - dwXWindowOffset=view_rect.left; - dwYWindowOffset=view_rect.top; - dwCopyWidth=view_rect.right-view_rect.left; - dwCopyHeight=view_rect.bottom-view_rect.top; - - pDDClipper->Release(); // dec ref cnt - } - - //make sure there's enough space in the pixbuf, its size must match (especially xsize) - // or scanlines will be too long - - if(!((dwCopyWidth==pixbuf->get_x_size()) && (dwCopyHeight<=(DWORD)pixbuf->get_y_size()))) { - pDDSurf->Unlock(NULL); - assert(0); - dxgsg7_cat.error() << "ConvertDDSurftoPixBuf, PixBuf incorrect size to hold display surface!\n"; - return E_FAIL; - } - - // others not handled yet - assert((ddsd.ddpfPixelFormat.dwRGBBitCount==32)||(ddsd.ddpfPixelFormat.dwRGBBitCount==16)||(ddsd.ddpfPixelFormat.dwRGBBitCount==24)); - - //pbuf contains raw ARGB in Texture byteorder - - DWORD lPitch = ddsd.lPitch; - BYTE* pDDSurfBytes = (BYTE*)ddsd.lpSurface; - - // writes out last line in DDSurf first in PixelBuf, so Y line order precedes inversely - - if(dxgsg7_cat.is_debug()) - dxgsg7_cat.debug() << "ConvertDDSurftoPixBuf converting " << ddsd.ddpfPixelFormat.dwRGBBitCount << "bpp DDSurf to " - << dwNumComponents << "-channel panda Texture\n"; - - - if(dwNumComponents==4) { - DWORD *pDstWord = (DWORD *) pbuf; - switch(ddsd.ddpfPixelFormat.dwRGBBitCount) { - - case 32: { - DWORD *pSrcWord; - #ifdef PANDA_BGRA_ORDER - BYTE *pDstLine = (BYTE*)pDstWord; - #endif - - pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1); - for(DWORD y=0; y> 16) & g_LowByteMask); - b = (BYTE) (dwPixel & g_LowByteMask); - - // want to write out ABGR - *pDstWord = (dwPixel & 0xFF00FF00) | (b<<16) | r; - } - #endif - } - break; - } - - case 24: { - BYTE *pSrcByte; - - pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1); - for(DWORD y=0; y> greenshift; - r = (dwPixel & redmask) >> redshift; - - #ifdef PANDA_BGRA_ORDER - *pDstWord = 0xFF000000 | (r << 16) | (g << 8) | b; - #else - *pDstWord = 0xFF000000 | (b << 16) | (g << 8) | r; - #endif - } - } - } - break; - } - } else { // convert to 24bpp pixbuf - BYTE *pDstByte = (BYTE *) pbuf; - switch(ddsd.ddpfPixelFormat.dwRGBBitCount) { - - case 32: { - DWORD *pSrcWord; - - pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1); - for(DWORD y=0; y>16) & g_LowByteMask); - g = (BYTE)((dwPixel>> 8) & g_LowByteMask); - b = (BYTE)((dwPixel ) & g_LowByteMask); - - #ifdef PANDA_BGRA_ORDER - *pDstByte++ = b; - *pDstByte++ = g; - *pDstByte++ = r; - #else - *pDstByte++ = r; - *pDstByte++ = g; - *pDstByte++ = b; - #endif - } - } - break; - } - - case 24: { - BYTE *pSrcByte; - - pDDSurfBytes+=ddsd.lPitch*(dwYWindowOffset+dwCopyHeight-1); - for(DWORD y=0; y> greenshift; - r = (dwPixel & redmask) >> redshift; - - #ifdef PANDA_BGRA_ORDER - *pDstByte++ = b; - *pDstByte++ = g; - *pDstByte++ = r; - #else - *pDstByte++ = r; - *pDstByte++ = g; - *pDstByte++ = b; - #endif - } - } - } - break; - } - } - - - pDDSurf->Unlock(NULL); - - return S_OK; -} - -//----------------------------------------------------------------------------- -// Name: CreateTextureFromBitmap() -// Desc: Use a bitmap to create a texture for the specified device. This code -// gets the attributes of the texture from the bitmap, creates the -// texture, and then copies the bitmap into the texture. -//----------------------------------------------------------------------------- -LPDIRECTDRAWSURFACE7 DXTextureContext7::create_texture(LPDIRECT3DDEVICE7 pd3dDevice, - int cNumTexPixFmts, DDPIXELFORMAT *pTexFmts,LPD3DDEVICEDESC7 pD3DDevDesc) - { - HRESULT hr; - int i,cNumAlphaBits; // number of alpha bits in texture pixfmt - DDPIXELFORMAT *pDesiredPixFmt; - LPDIRECTDRAWSURFACE7 pddsRender; - LPDIRECTDRAW7 pDD = NULL; - ConversionType ConvNeeded; - - assert(_texture!=NULL); - delete_texture(); - clear_dirty_flags(Texture::DF_image | Texture::DF_mipmap); - - DDPIXELFORMAT *pTexPixFmts = new DDPIXELFORMAT[cNumTexPixFmts]; - - // make local copy of array so I can muck with it during searches for this texture fmt - // (such as marking pixfmts that no search will be interested in) - // probably should do this faster way - - memcpy(pTexPixFmts,pTexFmts,cNumTexPixFmts*sizeof(DDPIXELFORMAT)); - - // bpp indicates requested fmt, not pixbuf fmt - DWORD bpp = get_bits_per_pixel(_texture->get_format(), &cNumAlphaBits); - Texture::ComponentType pixbuf_type = _texture->get_component_type(); - DWORD cNumColorChannels = _texture->get_num_components(); - - DWORD dwOrigWidth = (DWORD)_texture->get_x_size(); - DWORD dwOrigHeight = (DWORD)_texture->get_y_size(); - - // Use the device caps so we can check if the device has any constraints - // when using textures. - - assert((pD3DDevDesc->dwMaxTextureWidth>0) && (pD3DDevDesc->dwMaxTextureHeight>0)); - - // Setup the new surface desc for the texture. Note how we are using the - // texture manage attribute, so Direct3D does alot of dirty work for us - DDSURFACEDESC2 ddsd; - ZeroMemory( &ddsd, sizeof(DDSURFACEDESC2) ); - ddsd.dwSize = sizeof(DDSURFACEDESC2); - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH - | DDSD_PIXELFORMAT ; - - ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); - - // setup ddpf to match against avail fmts - - ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; - - if((_texture->get_format() == Texture::F_luminance_alpha)|| - (_texture->get_format() == Texture::F_luminance_alphamask) || - (_texture->get_format() == Texture::F_luminance)) { - ddsd.ddpfPixelFormat.dwFlags = DDPF_LUMINANCE; - } - - ddsd.ddpfPixelFormat.dwRGBBitCount = bpp; - - if(cNumAlphaBits) { - if(bpp == 8 && cNumAlphaBits == 8) { // handle special case: Alpha only buffer - ddsd.dwFlags |= DDPF_ALPHA; - ddsd.dwAlphaBitDepth = 8; - ddsd.ddpfPixelFormat.dwAlphaBitDepth = 8; - ddsd.ddpfPixelFormat.dwFlags = DDPF_ALPHA; - ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff; - } else { - ddsd.ddpfPixelFormat.dwFlags |= DDPF_ALPHAPIXELS; - if(cNumAlphaBits == 8) - ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000; - else if(cNumAlphaBits == 4) - ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xf000; - } - } - - ddsd.dwWidth = dwOrigWidth; - ddsd.dwHeight = dwOrigHeight; - - if(!ISPOW2(ddsd.dwWidth) || !ISPOW2(ddsd.dwHeight)) { - dxgsg7_cat.error() << "ERROR: texture dimensions are not a power of 2 for " << _tex->get_name() << "!!!!! \n"; - #ifdef _DEBUG - exit(1); // want to catch badtexsize errors - #else - goto error_exit; - #endif - } - - bool bShrinkOriginal; - bShrinkOriginal=false; - - if((dwOrigWidth>pD3DDevDesc->dwMaxTextureWidth)||(dwOrigHeight>pD3DDevDesc->dwMaxTextureHeight)) { - #ifdef _DEBUG - dxgsg7_cat.error() << "WARNING: " <<_tex->get_name() << ": Image size exceeds max texture dimensions of (" << pD3DDevDesc->dwMaxTextureWidth << "," << pD3DDevDesc->dwMaxTextureHeight << ") !!\n" - << "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," < ("<< pD3DDevDesc->dwMaxTextureWidth << "," << pD3DDevDesc->dwMaxTextureHeight << ") !\n"; - #endif - - if(dwOrigWidth>pD3DDevDesc->dwMaxTextureWidth) - ddsd.dwWidth=pD3DDevDesc->dwMaxTextureWidth; - if(dwOrigHeight>pD3DDevDesc->dwMaxTextureHeight) - ddsd.dwHeight=pD3DDevDesc->dwMaxTextureHeight; - bShrinkOriginal=true; - } - - // checks for SQUARE reqmt (nvidia riva128 needs this) - if((ddsd.dwWidth != ddsd.dwHeight) && (pD3DDevDesc->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )) { - - // assume pow2 textures. sum exponents, divide by 2 rounding down to get sq size - int i,width_exp,height_exp; - for(i=ddsd.dwWidth,width_exp=0;i>1;width_exp++,i>>=1); - for(i=ddsd.dwHeight,height_exp=0;i>1;height_exp++,i>>=1); - ddsd.dwHeight = ddsd.dwWidth = 1<<((width_exp+height_exp)>>1); - bShrinkOriginal=true; - -#ifdef _DEBUG - dxgsg7_cat.debug() << "Scaling "<< _tex->get_name() << " ("<< dwOrigWidth<<"," < ("<< ddsd.dwWidth<<"," << ddsd.dwHeight << ") to meet HW square texture reqmt\n"; -#endif - } - - if(bShrinkOriginal) { - // need 2 add checks for errors - PNMImage pnmi_src; - PNMImage *pnmi = new PNMImage(ddsd.dwWidth, ddsd.dwHeight, cNumColorChannels); - _texture->store(pnmi_src); - pnmi->quick_filter_from(pnmi_src,0,0); - - _texture->load(*pnmi); // violates device independence of pixbufs - - dwOrigWidth = (DWORD)_texture->get_x_size(); - dwOrigHeight = (DWORD)_texture->get_y_size(); - delete pnmi; - } - -#if 0 -//#ifdef _DEBUG -// easier to use dxcapsviewer instead of this - { static BOOL bPrinted=FALSE; - if(!bPrinted) { - dxgsg7_cat.debug() << "Gfx card supported TexFmts:\n"; - for(i=0;idwFlags & (DDPF_BUMPLUMINANCE|DDPF_BUMPDUDV) ) || - ( pCurPixFmt->dwFourCC != 0 ) || - ((cNumAlphaBits==0) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS))) { - - // Make sure to skip any FourCC formats, bump formats - // they are not handled by this code yet - - // note: I'm screening out alpha if no alpha requested, so - // search fails if 32-rgba avail, but not 32-bit rgb - // I could recode for that case too, hopefully this case will not pop up - - pCurPixFmt->dwRGBBitCount+=1; // incr so it wont be an exact match anymore - } - } - - // handle each bitdepth separately - - switch(bpp) { // bpp is REQUESTED bpp, not what exists in the pixbuf array - - case 32: - -#ifdef _DEBUG - if(!dx_force_16bpptextures) -#endif - for(i=0,pCurPixFmt=pTexPixFmts;idwRGBBitCount==32) && - (((pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)!=0)==(cNumAlphaBits!=0))) { - // we should have a match - assert(pCurPixFmt->dwRGBAlphaBitMask==0xFF000000); - ConvNeeded=((cNumColorChannels==3) ? Conv24to32 : Conv32to32); - goto found_matching_format; - break; - } - } - - if(cNumAlphaBits>0) { - // no 32-bit fmt, look for 16 bit w/alpha (1-15) - - // 32 bit RGBA was requested, but only 16 bit alpha fmts are avail - // by default, convert to 4-4-4-4 which has 4-bit alpha for blurry edges - // if we know tex only needs 1 bit alpha (i.e. for a mask), use 1555 instead - - ConversionType ConvTo1=Conv32to16_4444,ConvTo2=Conv32to16_1555; - DWORD dwAlphaMask1=0xF000,dwAlphaMask2=0x8000; - // assume ALPHAMASK is x8000 and RGBMASK is x7fff to simplify 32->16 conversion - // this should be true on most cards. - -#ifndef FORCE_16bpp_1555 - if(cNumAlphaBits==1) -#endif - { - ConvTo1=Conv32to16_1555; - dwAlphaMask1=0x8000; - } - - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) - && (pCurPixFmt->dwRGBAlphaBitMask==dwAlphaMask1)) { - ConvNeeded=ConvTo1; - goto found_matching_format; - } - } - -#ifdef FORCE_16bpp_1555 - break; -#endif - - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) - && (pCurPixFmt->dwRGBAlphaBitMask==dwAlphaMask2)) { - ConvNeeded=ConvTo2; - goto found_matching_format; - } - } - - // at this point, bail. dont worry about converting to non-alpha formats yet, - // I think this will be a very rare case - szErrorMsg = "create_texture failed: couldn't find compatible Tex DDPIXELFORMAT! no available 16 or 32-bit alpha formats!\n"; - } - - break; - - case 24: - - assert(cNumAlphaBits==0); // dont know how to handle non-zero alpha for 24bit total - - if(!dx_force_16bpptextures) - for(i=0,pCurPixFmt=pTexPixFmts;idwFlags & DDPF_RGB)&&(pCurPixFmt->dwRGBBitCount==24)) { - ConvNeeded=((cNumColorChannels==3) ? Conv24to24 : Conv32to24); - goto found_matching_format; - } - } - - if(!dx_force_16bpptextures) { - // no 24-bit fmt. look for 32 bit fmt (note: this is memory-hogging choice - // instead I could look for memory-conserving 16-bit fmt). - // check mask to ensure ARGB, not RGBA (which I am not handling here) - for(i=0,pCurPixFmt=pTexPixFmts;idwRGBBitCount==32) && (pCurPixFmt->dwFlags & DDPF_RGB) - && ((pCurPixFmt->dwRBitMask|pCurPixFmt->dwGBitMask|pCurPixFmt->dwBBitMask)==0xFFFFFF) - ) { - // I'm allowing alpha formats here. will set alpha to opaque - ConvNeeded=((cNumColorChannels==3) ? Conv24to32 : Conv32to32_NoAlpha); - goto found_matching_format; - } - } - } - - // no 24-bit or 32 fmt. look for 16 bit fmt - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];i16 conversion, should be true on most cards. - if((pCurPixFmt->dwFlags & DDPF_RGB) && (pCurPixFmt->dwRGBBitCount==16) - && !(pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)) { // no alpha fmts - // if numchan==4,this means user has requested we throw away the input alpha channel - if(pCurPixFmt->dwGBitMask==0x7E0) { - // assumes GBitMask is the biggest one, if we have 16 bit 3-channel - ConvNeeded=((cNumColorChannels==3) ? Conv24to16_0565 : Conv32to16_0565); - } else { - assert((pCurPixFmt->dwRBitMask|pCurPixFmt->dwGBitMask|pCurPixFmt->dwBBitMask)==0x7FFF); - ConvNeeded=((cNumColorChannels==3) ? Conv24to16_X555 : Conv32to16_X555); - } - goto found_matching_format; - } - } - - // at this point, bail. - break; - - case 16: - - if(ddsd.ddpfPixelFormat.dwFlags & DDPF_LUMINANCE) { - // look for native lum fmt - if(!dx_force_16bpptextures) { - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) && - (pCurPixFmt->dwFlags & DDPF_LUMINANCE)) { - ConvNeeded=ConvLum16to16; - goto found_matching_format; - } - } - - // else look for 32bpp ARGB - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==32) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) && - (pCurPixFmt->dwFlags & DDPF_RGB)) { - ConvNeeded=ConvLum16to32; - goto found_matching_format; - } - } - } - - // find compatible 16bpp fmt - ConversionType ConvTo1=ConvLum16to16_4444,ConvTo2=ConvLum16to16_1555; - DWORD dwAlphaMask1=0xF000,dwAlphaMask2=0x8000; - // assume ALPHAMASK is x8000 and RGBMASK is x7fff to simplify 32->16 conversion - // this should be true on most cards. - -#ifndef FORCE_16bpp_1555 - if(cNumAlphaBits==1) -#endif - { - ConvTo1=ConvLum16to16_1555; - dwAlphaMask1=0x8000; - } - - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) - && (pCurPixFmt->dwRGBAlphaBitMask==dwAlphaMask1)) { - ConvNeeded=ConvTo1; - goto found_matching_format; - } - } - -#ifdef FORCE_16bpp_1555 - break; -#endif - - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) - && (pCurPixFmt->dwRGBAlphaBitMask==dwAlphaMask2)) { - ConvNeeded=ConvTo2; - goto found_matching_format; - } - } - - } else - - // look for compatible 16bit fmts, if none then give up - // (dont worry about other bitdepths for 16 bit) - - for(i=0,pCurPixFmt=pTexPixFmts;idwRGBBitCount==16)&&(pCurPixFmt->dwFlags & DDPF_RGB)) { - switch(cNumAlphaBits) { - case 0: - if(!(pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)) { - // if numchan==4,this means user has requested we throw away the input alpha channel - if(pCurPixFmt->dwGBitMask==0x7E0) { - // assumes GBitMask is the biggest one, if we have 16 bit 3-channel - ConvNeeded=((cNumColorChannels==3) ? Conv24to16_0565 : Conv32to16_0565); - } else { - assert((pCurPixFmt->dwRBitMask|pCurPixFmt->dwGBitMask|pCurPixFmt->dwBBitMask)==0x7FFF); - ConvNeeded=((cNumColorChannels==3) ? Conv24to16_X555 : Conv32to16_X555); - } - goto found_matching_format; - } - break; - case 1: - if((pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)&& - (pCurPixFmt->dwRGBAlphaBitMask==0x8000)) { - ConvNeeded=Conv32to16_1555; - goto found_matching_format; - } - break; - case 4: - if((pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)&& - (pCurPixFmt->dwRGBAlphaBitMask==0xF000)) { - ConvNeeded=Conv32to16_4444; - goto found_matching_format; - } - break; - } - } - } - - break; - - case 8: - if(ddsd.ddpfPixelFormat.dwFlags & DDPF_LUMINANCE) { - // look for native lum fmt - - assert(cNumAlphaBits==0); // dont handle those other 8bit lum fmts like 4-4, since 16 8-8 is usually supported too - if(!dx_force_16bpptextures) - { - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==8) && (pCurPixFmt->dwFlags & DDPF_LUMINANCE) && - (pCurPixFmt->dwLuminanceBitMask==0xFF)) { - ConvNeeded=ConvLum8to8; - goto found_matching_format; - } - } - - // else look for 24bpp RGB - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==24) && (pCurPixFmt->dwFlags & DDPF_RGB)) { - ConvNeeded=ConvLum8to24; - goto found_matching_format; - } - } - - // else look for 32bpp RGB - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==32) && (pCurPixFmt->dwFlags & DDPF_RGB)) { - ConvNeeded=ConvLum8to32; - goto found_matching_format; - } - } - } - - // find compatible 16bpp fmt, just look for any 565, then 0555 - DWORD dwMasks[2] = {0xF800, 0x7C00}; - ConversionType ConvType[2] = {ConvLum8to16_0565,ConvLum8to16_X555}; - - for(DWORD modenum=0;modenum<2;modenum++) - for(i=0,pCurPixFmt=&pTexPixFmts[0];idwRGBBitCount==16) && (pCurPixFmt->dwFlags & DDPF_RGB) - && (!(pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)) - && (pCurPixFmt->dwRBitMask==dwMasks[modenum])) { - ConvNeeded=ConvType[modenum]; - goto found_matching_format; - } - } - } else if(ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHA) { - // look for 32-bit ARGB, else 16-4444. - // skip 8bit alpha only, because I think only voodoo supports it - // and the voodoo support isn't the kind of blending model we need - // w/color assumed to be white (but need to verify this) - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==32) && (pCurPixFmt->dwFlags & DDPF_RGB) && - (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS)) { - ConvNeeded=ConvAlpha8to32; - goto found_matching_format; - } - } - - for(i=0,pCurPixFmt=&pTexPixFmts[cNumTexPixFmts-1];idwRGBBitCount==16) - && (pCurPixFmt->dwFlags & DDPF_RGB) - && (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) - && (pCurPixFmt->dwRGBAlphaBitMask==0xF000)) { - ConvNeeded=ConvAlpha8to16_4444; - goto found_matching_format; - } - } - } - break; - - default: - szErrorMsg = "create_texture failed: unhandled pixel bitdepth in DX loader"; - } - - // if we've gotten here, haven't found a match - - dxgsg7_cat.error() << szErrorMsg << "; requested tex bitdepth: " << bpp << "\n"; - goto error_exit; - - /////////////////////////////////////////////////////////// - - found_matching_format: - - ddsd.ddpfPixelFormat = *pCurPixFmt; - - // Get the device's render target, so we can then use the render target to - // get a ptr to a DDraw object. We need the DirectDraw interface for - // creating surfaces. - - pd3dDevice->GetRenderTarget( &pddsRender ); - pddsRender->GetDDInterface( (VOID**)&pDD ); - pddsRender->Release(); - - ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; - - if(pD3DDevDesc->dwDevCaps & D3DDEVCAPS_HWRASTERIZATION) { - ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE // Turn on texture management - | DDSCAPS2_HINTSTATIC; // BUGBUG: is this ok for ALL textures? - } else { - ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; - } - - // validate magfilter setting - // degrade filtering if no HW support - - Texture::FilterType ft; - - ft =_tex->get_magfilter(); - if((ft!=Texture::FT_linear) && ft!=Texture::FT_nearest) { - if(ft==Texture::FT_nearest_mipmap_nearest) - ft=Texture::FT_nearest; - else ft=Texture::FT_linear; - } - - if((ft==Texture::FT_linear) && !(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR)) { - ft=Texture::FT_nearest; - } - _tex->set_magfilter(ft); - - // figure out if we are mipmapping this texture - ft =_tex->get_minfilter(); - _has_mipmaps=FALSE; - - if(!dx_ignore_mipmaps) { // set if no HW mipmap capable - switch(ft) { - case Texture::FT_nearest_mipmap_nearest: - case Texture::FT_linear_mipmap_nearest: - case Texture::FT_nearest_mipmap_linear: // pick nearest in each, interpolate linearly b/w them - case Texture::FT_linear_mipmap_linear: - _has_mipmaps=TRUE; - } - - if(dx_mipmap_everything) { // debug toggle, ok to leave in since its just a creation cost - _has_mipmaps=TRUE; - if(ft != Texture::FT_linear_mipmap_linear) { - dxgsg7_cat.spam() << "Forcing mipmap filtering on DX texture [" << _tex->get_name() << "]\n"; - } - ft = Texture::FT_linear_mipmap_linear; - _tex->set_minfilter(ft); - } - } else if((ft==Texture::FT_nearest_mipmap_nearest) || // cvt to no-mipmap filter types - (ft==Texture::FT_nearest_mipmap_linear)) { - ft=Texture::FT_nearest; - } else if((ft==Texture::FT_linear_mipmap_nearest) || - (ft==Texture::FT_linear_mipmap_linear)) { - ft=Texture::FT_linear; - } - - assert((pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST)!=0); - - switch(ft) { - case Texture::FT_nearest_mipmap_linear: - if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST)) - ft=Texture::FT_nearest_mipmap_nearest; - break; - case Texture::FT_linear_mipmap_nearest: - if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR)) - ft=Texture::FT_nearest_mipmap_nearest; - break; - case Texture::FT_linear_mipmap_linear: - if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR)) { - if(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR) - ft=Texture::FT_linear_mipmap_nearest; - else ft=Texture::FT_nearest_mipmap_nearest; // if you cant do linear in a level, you probably cant do linear b/w levels, so just do nearest-all - } - break; - case Texture::FT_linear: - if(!(pD3DDevDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR)) - ft=Texture::FT_nearest; - break; - } - - _tex->set_minfilter(ft); - - uint aniso_degree; - - aniso_degree=1; - if(pD3DDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANISOTROPY) { - aniso_degree=_tex->get_anisotropic_degree(); - if((aniso_degree>pD3DDevDesc->dwMaxAnisotropy) -#ifdef _DEBUG - || dx_force_anisotropic_filtering -#endif - ) - aniso_degree=pD3DDevDesc->dwMaxAnisotropy; - } - _tex->set_anisotropic_degree(aniso_degree); -#ifdef _DEBUG - dxgsg7_cat.spam() << "create_texture: setting aniso degree for "<< _tex->get_name() << " to: " << aniso_degree << endl; -#endif - - if(_has_mipmaps) { - // We dont specify mipmapcount, so CreateSurface will auto-create surfs - // for all mipmaps down to 1x1 (if driver supports deep-mipmaps, otherwise Nx1) - ddsd.ddsCaps.dwCaps |= (DDSCAPS_MIPMAP | DDSCAPS_COMPLEX); - dxgsg7_cat.debug() << "create_texture: generating mipmaps for "<< _tex->get_name() << endl; - } - - if(pD3DDevDesc->dwDevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES) { - // must assign a texture to a specific stage - // for now I'm just going to use stage 0 for all - ddsd.dwTextureStage=0; - ddsd.dwFlags |= DDSD_TEXTURESTAGE; - } - - // Create a new surface for the texture - if(FAILED( hr = pDD->CreateSurface( &ddsd, &_surface, NULL ) )) { - dxgsg7_cat.error() << "create_texture failed: pDD->CreateSurface() failed! hr = " << ConvD3DErrorToString(hr) << "\n"; - goto error_exit; - } - - -#ifdef _DEBUG - dxgsg7_cat.debug() << "create_texture: "<< _tex->get_name() <<" converted " << ConvNameStrs[ConvNeeded] << " \n"; -#endif - - _PixBufConversionType=ConvNeeded; - - hr = FillDDSurfTexturePixels(); - if(FAILED(hr)) { - goto error_exit; - } - - // Done with DDraw - pDD->Release(); - - delete [] pTexPixFmts; - - // Return the newly created texture - return _surface; - - error_exit: - - if(pDD!=NULL) - pDD->Release(); - if(_surface!=NULL) { - _surface->Release(); - _surface = NULL; - } - - delete [] pTexPixFmts; - return NULL; -} - -// Converts from multiple bytes per component to a single byte per -// component, for the convenience of the routines in this module which -// assume just one byte per component. This loses precision on -// high-precision textures, too bad. -PTA_uchar -downsample_image(uchar *source, int num_pixels, int component_width) { - PTA_uchar result = PTA_uchar::empty_array(num_pixels); - uchar *p = source + component_width - 1; - for (int ti = 0; ti < num_pixels; ti++) { - result[ti] = *p; - p += component_width; - } - - return result; -} - -HRESULT DXTextureContext7:: -FillDDSurfTexturePixels() { - - CPTA_uchar orig_image = _texture->get_ram_image(); - if (orig_image.empty()) { - dxgsg7_cat.fatal() << "create_texture: get_ram_image() failed\n"; - // The texture doesn't have an image to load. - return E_FAIL; - } - - PTA_uchar image = (PTA_uchar &)orig_image; - if (_texture->get_component_width() != 1) { - image = downsample_image(image, - _texture->get_x_size() * _texture->get_y_size() * _texture->get_num_components(), - _texture->get_component_width()); - } - - HRESULT hr = ConvertPixBuftoDDSurf((ConversionType)_PixBufConversionType,image.p(),_surface); - if(FAILED(hr)) { - return hr; - } - - DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd); - - _surface->GetSurfaceDesc(&ddsd); - - if(_has_mipmaps) { - DWORD i,oldcurxsize,oldcurysize,curxsize,curysize,cMipMapCount=ddsd.dwMipMapCount; - assert(ddsd.dwMipMapCount<20); - - DWORD cNumColorChannels = _texture->get_num_components(); - - curxsize=ddsd.dwWidth; curysize=ddsd.dwHeight; - - // all mipmap sublevels require 1/3 of total original space. alloc 1/2 for safety - BYTE *pMipMapPixBufSpace = new BYTE[((curxsize*curysize*cNumColorChannels)/2)+1024]; - - LPDIRECTDRAWSURFACE7 pCurDDSurf=_surface; - pCurDDSurf->AddRef(); // so final release doesnt release the surface - - BYTE *pDstWord = pMipMapPixBufSpace; - BYTE *pLastMipLevelStart = (BYTE *) image.p(); -// clock_t start1,finish1; -// start1=clock(); - for(i=1;i>1,1); - curxsize = max(curxsize>>1,1); - - assert(!((oldcurxsize==1)&&(oldcurysize==1))); - - BYTE *pSrcWord; - BYTE *pSrcLineStart=pLastMipLevelStart; - - // inc img start to DWORD boundary - while(((DWORD)pDstWord) & 0x11) - pDstWord++; - - pLastMipLevelStart = pDstWord; - - DWORD x,y,cPixelSize=cNumColorChannels; - DWORD src_row_bytelength=oldcurxsize*cPixelSize; - DWORD two_src_row_bytelength=2*src_row_bytelength; - - #define GENMIPMAP_DO_INTEGER_DIV // should be a little faster, but no rounding up - #ifdef GENMIPMAP_DO_INTEGER_DIV - DWORD DivShift=2; - if((oldcurxsize==1)||(oldcurysize==1)) - DivShift = 1; - #else - float numpixels_per_filter=4.0f; - if((oldcurxsize==1)||(oldcurysize==1)) - numpixels_per_filter=2.0f; - #endif - - DWORD x_srcptr_inc = ((oldcurxsize==1)? cPixelSize: (2*cPixelSize)); - - // box-filter shrink down, avg 4 pixels at a time - for(y=0; y1) // handle 1x[X], [X]x1 cases - colr += *(pSrcWord+cPixelSize+c); - if(oldcurysize>1) { - colr += *(pSrcWord+src_row_bytelength+c); - if(oldcurxsize>1) - colr += *(pSrcWord+src_row_bytelength+cPixelSize+c); - } - #ifdef GENMIPMAP_DO_INTEGER_DIV - colr >>= DivShift; - #else - colr = (DWORD) ((((float)colr)/numpixels_per_filter)+0.5f); - #endif - - *(pDstWord+c)=(BYTE)colr; - } - } - } - - // now copy pixbuf to final DD surf - - DDSCAPS2 ddsCaps; - LPDIRECTDRAWSURFACE7 pMipLevel_DDSurf; - ZeroMemory(&ddsCaps,sizeof(DDSCAPS2)); - ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP; - ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL; - - hr = pCurDDSurf->GetAttachedSurface(&ddsCaps, &pMipLevel_DDSurf); - if(FAILED(hr)) { - dxgsg7_cat.error() << "create_texture failed creating mipmaps: GetAttachedSurf hr = " << ConvD3DErrorToString(hr) << "\n"; - delete [] pMipMapPixBufSpace; - pCurDDSurf->Release(); - return hr; - } - - hr = ConvertPixBuftoDDSurf((ConversionType)_PixBufConversionType,pLastMipLevelStart,pMipLevel_DDSurf); - if(FAILED(hr)) { - delete [] pMipMapPixBufSpace; - pCurDDSurf->Release(); - return hr; - } - - pCurDDSurf->Release(); - pCurDDSurf=pMipLevel_DDSurf; - } - - // finish1=clock(); - // double elapsed_time = (double)(finish1 - start1) / CLOCKS_PER_SEC; - // cerr << "mipmap gen takes " << elapsed_time << " secs for this texture\n"; - - delete [] pMipMapPixBufSpace; - pCurDDSurf->Release(); - -#ifdef _DEBUG - if(dx_debug_view_mipmaps) { -#if 0 - if(!(ddcaps.dwCaps & DDCAPS_BLTSTRETCH)) { - dxgsg7_cat.error() << "create_texture failed debug-viewing mipmaps, BLT stretching not supported! ( we need to do SW stretch) \n"; - return hr; - } -#endif - - // display mipmaps on primary surf - HDC hTexDC; - LPDIRECTDRAWSURFACE7 pTextureCurrent,pTexturePrev = _surface; - int cury,curx; - HDC hScreenDC; - RECT scrnrect; - hScreenDC=GetDC(NULL); - - scrnrect.left=scrnrect.top=0; - scrnrect.bottom=GetDeviceCaps(hScreenDC,VERTRES); - scrnrect.right=GetDeviceCaps(hScreenDC,HORZRES); - char msg[500]; - - pTexturePrev->AddRef(); - - for(i = 0,curx=scrnrect.left,cury=scrnrect.top; i < ddsd.dwMipMapCount; i++) { - - DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd_cur); - pTexturePrev->GetSurfaceDesc(&ddsd_cur); - - hr = pTexturePrev->GetDC(&hTexDC); - if(FAILED(hr)) { - dxgsg7_cat.error() << "GetDC failed hr = " << ConvD3DErrorToString(hr) << "\n"; - break; - } - - BOOL res; - // res = BitBlt(_dxgsg7->_hdc,0,0,ddsd.dwWidth,ddsd.dwHeight, TexDC,0,0,SRCCOPY); - // loader inverts y, so use StretchBlt to re-invert it - // res = StretchBlt(_dxgsg7->hdc,0,ddsd_cur.dwHeight+cury,ddsd_cur.dwWidth,-ddsd_cur.dwHeight, TexDC,0,0,ddsd_cur.dwWidth,ddsd_cur.dwHeight,SRCCOPY); -#if 0 - if(cNumAlphaBits>0) { - BLENDFUNCTION bf; - bf.BlendOp = AC_SRC_OVER; bf.BlendFlags=0; - bf.SourceConstantAlpha=255; bf.AlphaFormat=AC_SRC_ALPHA; - res = AlphaBlend(hScreenDC,curx,cury,ddsd_cur.dwWidth,ddsd_cur.dwHeight, TexDC,0,0,ddsd_cur.dwWidth,ddsd_cur.dwHeight,bf); - if(!res) { - PrintLastError(msg); - dxgsg7_cat.error() << "AlphaBlend BLT failed: "<scrnrect.right) { - curx=0; cury+=(scrnrect.bottom-scrnrect.top)/2; - } - - hr = pTexturePrev->ReleaseDC(hTexDC); - - if(FAILED(hr)) { - dxgsg7_cat.error() << "tex ReleaseDC failed for mip "<Release(); - continue; - } - - DDSCAPS2 ddsCaps; - ZeroMemory(&ddsCaps,sizeof(DDSCAPS2)); - ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP; - ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL; - hr = pTexturePrev->GetAttachedSurface(&ddsCaps, &pTextureCurrent); - if(FAILED(hr)) { - dxgsg7_cat.error() << " failed displaying mipmaps: GetAttachedSurf hr = " << ConvD3DErrorToString(hr) << "\n"; - } - // done with the previous texture - pTexturePrev->Release(); - pTexturePrev = pTextureCurrent; - } - - ReleaseDC(0,hScreenDC); - - HANDLE hArr[1]; - MSG winmsg; - hArr[0]=GetStdHandle(STD_INPUT_HANDLE); - GetMessage(&winmsg,NULL,0,0); - - int val=MsgWaitForMultipleObjects(1,hArr,TRUE,INFINITE,QS_KEY); - if(val==-1) { - PrintLastError(msg); - dxgsg7_cat.error() << " MsgWaitForMultipleObjects returns " << val << " " <get_name() << "\n"; - } - -#ifdef DEBUG_RELEASES - if(_surface) { - LPDIRECTDRAW7 pDD; - _surface->GetDDInterface( (VOID**)&pDD ); - pDD->Release(); - - PRINTREFCNT(pDD,"before DeleteTex, IDDraw7"); - RELEASE(_surface,dxgsg7,"texture",false); - PRINTREFCNT(pDD,"after DeleteTex, IDDraw7"); - } -#else - RELEASE(_surface,dxgsg7,"texture",false); -#endif -} - - -//////////////////////////////////////////////////////////////////// -// Function: DXTextureContext7::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DXTextureContext7:: -DXTextureContext7(Texture *tex) : -TextureContext(tex) { -//#ifdef NDEBUG - if(dxgsg7_cat.is_spam()) { - dxgsg7_cat.spam() << "Creating DX texture [" << tex->get_name() << "], minfilter(" << PandaFilterNameStrs[tex->get_minfilter()] << "), magfilter("<get_magfilter()] << "), anisodeg(" << tex->get_anisotropic_degree() << ")\n"; - } -//#endif - _surface = NULL; - _has_mipmaps = FALSE; - _tex = tex; -} - -DXTextureContext7:: -~DXTextureContext7() { - delete_texture(); - TextureContext::~TextureContext(); - _tex = NULL; -} - diff --git a/panda/src/dxgsg7/dxTextureContext7.h b/panda/src/dxgsg7/dxTextureContext7.h deleted file mode 100644 index d4bdae49d9..0000000000 --- a/panda/src/dxgsg7/dxTextureContext7.h +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: dxTextureContext7.h -// Created by: drose (07Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DXTEXTURECONTEXT7_H -#define DXTEXTURECONTEXT7_H - -#include "dxgsg7base.h" - -#include "texture.h" -#include "textureContext.h" - -//////////////////////////////////////////////////////////////////// -// Class : DXTextureContext7 -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDADX DXTextureContext7 : public TextureContext { - friend class DXGraphicsStateGuardian7; - friend class wdxGraphicsWindow7; - -public: - DXTextureContext7(Texture *tex); - ~DXTextureContext7(); - - LPDIRECTDRAWSURFACE7 _surface; - Texture *_tex; // ptr to parent, primarily for access to namestr - -// static is_unused_texpixelformat(DDPIXELFORMAT *) - - LPDIRECTDRAWSURFACE7 create_texture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, DDPIXELFORMAT *pTexFmts,LPD3DDEVICEDESC7 pD3DDevDesc); - void delete_texture(); - - INLINE bool has_mipmaps() const; - - bool _has_mipmaps; - DWORD _PixBufConversionType; // enum ConversionType - - HRESULT FillDDSurfTexturePixels(); - -protected: - unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits); - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TextureContext::init_type(); - register_type(_type_handle, "DXTextureContext7", - TextureContext::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "dxTextureContext7.I" - -#endif - diff --git a/panda/src/dxgsg7/dxgsg7_composite.cxx b/panda/src/dxgsg7/dxgsg7_composite.cxx deleted file mode 100644 index 5c48b58ce6..0000000000 --- a/panda/src/dxgsg7/dxgsg7_composite.cxx +++ /dev/null @@ -1 +0,0 @@ -#include "dxgsg7_composite1.cxx" diff --git a/panda/src/dxgsg7/dxgsg7_composite1.cxx b/panda/src/dxgsg7/dxgsg7_composite1.cxx deleted file mode 100644 index 0c43fe4376..0000000000 --- a/panda/src/dxgsg7/dxgsg7_composite1.cxx +++ /dev/null @@ -1,7 +0,0 @@ -#include "dxgsg7base.h" -#include "dxgsg7base.cxx" -#include "config_dxgsg7.cxx" -#include "dxGeomMunger7.cxx" -#include "dxTextureContext7.cxx" -#include "wdxGraphicsPipe7.cxx" -#include "wdxGraphicsWindow7.cxx" diff --git a/panda/src/dxgsg7/dxgsg7base.cxx b/panda/src/dxgsg7/dxgsg7base.cxx deleted file mode 100644 index f3da352de5..0000000000 --- a/panda/src/dxgsg7/dxgsg7base.cxx +++ /dev/null @@ -1,1516 +0,0 @@ -// Filename: dxgsg7base.cxx -// Created by: drose (02Jan03) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#include "dxgsg7base.h" - -#include - -const char * -ConvD3DErrorToString(HRESULT error) { - switch (error) { - case E_FAIL: - return "Unspecified error E_FAIL"; - - case DD_OK: - return "No error."; - case D3DERR_BADMAJORVERSION : // (700) - return "D3DERR_BADMAJORVERSION"; - case D3DERR_BADMINORVERSION : // (701) - return "D3DERR_BADMINORVERSION"; - case D3DERR_INVALID_DEVICE : // (705) - return "D3DERR_INVALID_DEVICE"; - case D3DERR_INITFAILED : // (706) - return "D3DERR_INITFAILED"; - case D3DERR_DEVICEAGGREGATED : // (707) - return "D3DERR_DEVICEAGGREGATED"; - case D3DERR_EXECUTE_CREATE_FAILED : // (710) - return "D3DERR_EXECUTE_CREATE_FAILED"; - case D3DERR_EXECUTE_DESTROY_FAILED : // (711) - return "D3DERR_EXECUTE_DESTROY_FAILED"; - case D3DERR_EXECUTE_LOCK_FAILED : // (712) - return "D3DERR_EXECUTE_LOCK_FAILED"; - case D3DERR_EXECUTE_UNLOCK_FAILED : // (713) - return "D3DERR_EXECUTE_UNLOCK_FAILED"; - case D3DERR_EXECUTE_LOCKED : // (714) - return "D3DERR_EXECUTE_LOCKED"; - case D3DERR_EXECUTE_NOT_LOCKED : // (715) - return "D3DERR_EXECUTE_NOT_LOCKED"; - case D3DERR_EXECUTE_FAILED : // (716) - return "D3DERR_EXECUTE_FAILED"; - case D3DERR_EXECUTE_CLIPPED_FAILED : // (717) - return "D3DERR_EXECUTE_CLIPPED_FAILED"; - case D3DERR_TEXTURE_NO_SUPPORT : // (720) - return "D3DERR_TEXTURE_NO_SUPPORT"; - case D3DERR_TEXTURE_CREATE_FAILED : // (721) - return "D3DERR_TEXTURE_CREATE_FAILED"; - case D3DERR_TEXTURE_DESTROY_FAILED : // (722) - return "D3DERR_TEXTURE_DESTROY_FAILED"; - case D3DERR_TEXTURE_LOCK_FAILED : // (723) - return "D3DERR_TEXTURE_LOCK_FAILED"; - case D3DERR_TEXTURE_UNLOCK_FAILED : // (724) - return "D3DERR_TEXTURE_UNLOCK_FAILED"; - case D3DERR_TEXTURE_LOAD_FAILED : // (725) - return "D3DERR_TEXTURE_LOAD_FAILED"; - case D3DERR_TEXTURE_SWAP_FAILED : // (726) - return "D3DERR_TEXTURE_SWAP_FAILED"; - case D3DERR_TEXTURE_LOCKED : // (727) - return "D3DERR_TEXTURE_LOCKED"; - case D3DERR_TEXTURE_NOT_LOCKED : // (728) - return "D3DERR_TEXTURE_NOT_LOCKED"; - case D3DERR_TEXTURE_GETSURF_FAILED : // (729) - return "D3DERR_TEXTURE_GETSURF_FAILED"; - case D3DERR_MATRIX_CREATE_FAILED : // (730) - return "D3DERR_MATRIX_CREATE_FAILED"; - case D3DERR_MATRIX_DESTROY_FAILED : // (731) - return "D3DERR_MATRIX_DESTROY_FAILED"; - case D3DERR_MATRIX_SETDATA_FAILED : // (732) - return "D3DERR_MATRIX_SETDATA_FAILED"; - case D3DERR_MATRIX_GETDATA_FAILED : // (733) - return "D3DERR_MATRIX_GETDATA_FAILED"; - case D3DERR_SETVIEWPORTDATA_FAILED : // (734) - return "D3DERR_SETVIEWPORTDATA_FAILED"; - case D3DERR_INVALIDCURRENTVIEWPORT : // (735) - return "D3DERR_INVALIDCURRENTVIEWPORT"; - case D3DERR_INVALIDPRIMITIVETYPE : // (736) - return "D3DERR_INVALIDPRIMITIVETYPE"; - case D3DERR_INVALIDVERTEXTYPE : // (737) - return "D3DERR_INVALIDVERTEXTYPE"; - case D3DERR_TEXTURE_BADSIZE : // (738) - return "D3DERR_TEXTURE_BADSIZE"; - case D3DERR_INVALIDRAMPTEXTURE : // (739) - return "D3DERR_INVALIDRAMPTEXTURE"; - case D3DERR_MATERIAL_CREATE_FAILED : // (740) - return "D3DERR_MATERIAL_CREATE_FAILED"; - case D3DERR_MATERIAL_DESTROY_FAILED : // (741) - return "D3DERR_MATERIAL_DESTROY_FAILED"; - case D3DERR_MATERIAL_SETDATA_FAILED : // (742) - return "D3DERR_MATERIAL_SETDATA_FAILED"; - case D3DERR_MATERIAL_GETDATA_FAILED : // (743) - return "D3DERR_MATERIAL_GETDATA_FAILED"; - case D3DERR_INVALIDPALETTE : // (744) - return "D3DERR_INVALIDPALETTE"; - case D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY : // (745) - return "D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY"; - case D3DERR_ZBUFF_NEEDS_VIDEOMEMORY : // (746) - return "D3DERR_ZBUFF_NEEDS_VIDEOMEMORY"; - case D3DERR_SURFACENOTINVIDMEM : // (747) - return "D3DERR_SURFACENOTINVIDMEM"; - case D3DERR_LIGHT_SET_FAILED : // (750) - return "D3DERR_LIGHT_SET_FAILED"; - case D3DERR_LIGHTHASVIEWPORT : // (751) - return "D3DERR_LIGHTHASVIEWPORT"; - case D3DERR_LIGHTNOTINTHISVIEWPORT : // (752) - return "D3DERR_LIGHTNOTINTHISVIEWPORT"; - case D3DERR_SCENE_IN_SCENE : // (760) - return "D3DERR_SCENE_IN_SCENE"; - case D3DERR_SCENE_NOT_IN_SCENE : // (761) - return "D3DERR_SCENE_NOT_IN_SCENE"; - case D3DERR_SCENE_BEGIN_FAILED : // (762) - return "D3DERR_SCENE_BEGIN_FAILED"; - case D3DERR_SCENE_END_FAILED : // (763) - return "D3DERR_SCENE_END_FAILED"; - case D3DERR_INBEGIN : // (770) - return "D3DERR_INBEGIN"; - case D3DERR_NOTINBEGIN : // (771) - return "D3DERR_NOTINBEGIN"; - case D3DERR_NOVIEWPORTS : // (772) - return "D3DERR_NOVIEWPORTS"; - case D3DERR_VIEWPORTDATANOTSET : // (773) - return "D3DERR_VIEWPORTDATANOTSET"; - case D3DERR_VIEWPORTHASNODEVICE : // (774) - return "D3DERR_VIEWPORTHASNODEVICE"; - case D3DERR_NOCURRENTVIEWPORT : // (775) - return "D3DERR_NOCURRENTVIEWPORT"; - case D3DERR_INVALIDVERTEXFORMAT : // (2048) - return "D3DERR_INVALIDVERTEXFORMAT"; - case D3DERR_COLORKEYATTACHED : // (2050) - return "D3DERR_COLORKEYATTACHED"; - case D3DERR_VERTEXBUFFEROPTIMIZED : // (2060) - return "D3DERR_VERTEXBUFFEROPTIMIZED"; - case D3DERR_VBUF_CREATE_FAILED : // (2061) - return "D3DERR_VBUF_CREATE_FAILED"; - case D3DERR_VERTEXBUFFERLOCKED : // (2062) - return "D3DERR_VERTEXBUFFERLOCKED"; - case D3DERR_ZBUFFER_NOTPRESENT : // (2070) - return "D3DERR_ZBUFFER_NOTPRESENT"; - case D3DERR_STENCILBUFFER_NOTPRESENT : // (2071) - return "D3DERR_STENCILBUFFER_NOTPRESENT"; - case D3DERR_WRONGTEXTUREFORMAT : // (2072) - return "D3DERR_WRONGTEXTUREFORMAT"; - case D3DERR_UNSUPPORTEDCOLOROPERATION : // (2073) - return "D3DERR_UNSUPPORTEDCOLOROPERATION"; - case D3DERR_UNSUPPORTEDCOLORARG : // (2074) - return "D3DERR_UNSUPPORTEDCOLORARG"; - case D3DERR_UNSUPPORTEDALPHAOPERATION : // (2075) - return "D3DERR_UNSUPPORTEDALPHAOPERATION"; - case D3DERR_UNSUPPORTEDALPHAARG : // (2076) - return "D3DERR_UNSUPPORTEDALPHAARG"; - case D3DERR_TOOMANYOPERATIONS : // (2077) - return "D3DERR_TOOMANYOPERATIONS"; - case D3DERR_CONFLICTINGTEXTUREFILTER : // (2078) - return "D3DERR_CONFLICTINGTEXTUREFILTER"; - case D3DERR_UNSUPPORTEDFACTORVALUE : // (2079) - return "D3DERR_UNSUPPORTEDFACTORVALUE"; - case D3DERR_CONFLICTINGRENDERSTATE : // (2081) - return "D3DERR_CONFLICTINGRENDERSTATE"; - case D3DERR_UNSUPPORTEDTEXTUREFILTER : // (2082) - return "D3DERR_UNSUPPORTEDTEXTUREFILTER"; - case D3DERR_TOOMANYPRIMITIVES : // (2083) - return "D3DERR_TOOMANYPRIMITIVES"; - case D3DERR_INVALIDMATRIX : // (2084) - return "D3DERR_INVALIDMATRIX"; - case D3DERR_TOOMANYVERTICES : // (2085) - return "D3DERR_TOOMANYVERTICES"; - case D3DERR_CONFLICTINGTEXTUREPALETTE : // (2086) - return "D3DERR_CONFLICTINGTEXTUREPALETTE"; - //#if DX7 - case D3DERR_VERTEXBUFFERUNLOCKFAILED : // (2063) - return "D3DERR_VERTEXBUFFERUNLOCKFAILED"; - case D3DERR_INVALIDSTATEBLOCK : // (2100) - return "D3DERR_INVALIDSTATEBLOCK"; - case D3DERR_INBEGINSTATEBLOCK : // (2101) - return "D3DERR_INBEGINSTATEBLOCK"; - case D3DERR_NOTINBEGINSTATEBLOCK : // (2102) - return "D3DERR_NOTINBEGINSTATEBLOCK"; - //case D3DERR_INOVERLAYSTATEBLOCK : // (2103) - // return "D3DERR_INOVERLAYSTATEBLOCK"; - case DDERR_NOSTEREOHARDWARE : // ( 181 ) - return "DDERR_NOSTEREOHARDWARE "; - case DDERR_NOSURFACELEFT : // ( 182 ) - return "DDERR_NOSURFACELEFT "; - case DDERR_DDSCAPSCOMPLEXREQUIRED : // ( 542 ) - return "DDERR_DDSCAPSCOMPLEXREQUIRED"; - case DDERR_NOTONMIPMAPSUBLEVEL : // ( 603 ) - return "DDERR_NOTONMIPMAPSUBLEVEL"; - case DDERR_TESTFINISHED : // ( 692 ) - return "DDERR_TESTFINISHED"; - case DDERR_NEWMODE : // ( 693 ) - return "DDERR_NEWMODE"; - //#endif - //case D3DERR_COMMAND_UNPARSED : // (3000) - /// return "case";//D3DERR_COMMAND_UNPARSED : // (3000) - - case DDERR_ALREADYINITIALIZED : // ( 5 ) - return "DDERR_ALREADYINITIALIZED "; - case DDERR_CANNOTATTACHSURFACE : // ( 10 ) - return "DDERR_CANNOTATTACHSURFACE "; - case DDERR_CANNOTDETACHSURFACE : // ( 20 ) - return "DDERR_CANNOTDETACHSURFACE "; - case DDERR_CURRENTLYNOTAVAIL : // ( 40 ) - return "DDERR_CURRENTLYNOTAVAIL "; - case DDERR_EXCEPTION : // ( 55 ) - return "DDERR_EXCEPTION "; - case DDERR_HEIGHTALIGN : // ( 90 ) - return "DDERR_HEIGHTALIGN "; - case DDERR_INCOMPATIBLEPRIMARY : // ( 95 ) - return "DDERR_INCOMPATIBLEPRIMARY "; - case DDERR_INVALIDCAPS : // ( 100 ) - return "DDERR_INVALIDCAPS "; - case DDERR_INVALIDCLIPLIST : // ( 110 ) - return "DDERR_INVALIDCLIPLIST "; - case DDERR_INVALIDMODE : // ( 120 ) - return "DDERR_INVALIDMODE "; - case DDERR_INVALIDOBJECT : // ( 130 ) - return "DDERR_INVALIDOBJECT "; - case DDERR_INVALIDPIXELFORMAT : // ( 145 ) - return "DDERR_INVALIDPIXELFORMAT "; - case DDERR_INVALIDRECT : // ( 150 ) - return "DDERR_INVALIDRECT "; - case DDERR_LOCKEDSURFACES : // ( 160 ) - return "DDERR_LOCKEDSURFACES "; - case DDERR_NO3D : // ( 170 ) - return "DDERR_NO3D "; - case DDERR_NOALPHAHW : // ( 180 ) - return "DDERR_NOALPHAHW "; - case DDERR_NOCLIPLIST : // ( 205 ) - return "DDERR_NOCLIPLIST "; - case DDERR_NOCOLORCONVHW : // ( 210 ) - return "DDERR_NOCOLORCONVHW "; - case DDERR_NOCOOPERATIVELEVELSET : // ( 212 ) - return "DDERR_NOCOOPERATIVELEVELSET "; - case DDERR_NOCOLORKEY : // ( 215 ) - return "DDERR_NOCOLORKEY "; - case DDERR_NOCOLORKEYHW : // ( 220 ) - return "DDERR_NOCOLORKEYHW "; - case DDERR_NODIRECTDRAWSUPPORT : // ( 222 ) - return "DDERR_NODIRECTDRAWSUPPORT "; - case DDERR_NOEXCLUSIVEMODE : // ( 225 ) - return "DDERR_NOEXCLUSIVEMODE "; - case DDERR_NOFLIPHW : // ( 230 ) - return "DDERR_NOFLIPHW "; - case DDERR_NOGDI : // ( 240 ) - return "DDERR_NOGDI "; - case DDERR_NOMIRRORHW : // ( 250 ) - return "DDERR_NOMIRRORHW "; - case DDERR_NOTFOUND : // ( 255 ) - return "DDERR_NOTFOUND "; - case DDERR_NOOVERLAYHW : // ( 260 ) - return "DDERR_NOOVERLAYHW "; - case DDERR_OVERLAPPINGRECTS : // ( 270 ) - return "DDERR_OVERLAPPINGRECTS "; - case DDERR_NORASTEROPHW : // ( 280 ) - return "DDERR_NORASTEROPHW "; - case DDERR_NOROTATIONHW : // ( 290 ) - return "DDERR_NOROTATIONHW "; - case DDERR_NOSTRETCHHW : // ( 310 ) - return "DDERR_NOSTRETCHHW "; - case DDERR_NOT4BITCOLOR : // ( 316 ) - return "DDERR_NOT4BITCOLOR "; - case DDERR_NOT4BITCOLORINDEX : // ( 317 ) - return "DDERR_NOT4BITCOLORINDEX "; - case DDERR_NOT8BITCOLOR : // ( 320 ) - return "DDERR_NOT8BITCOLOR "; - case DDERR_NOTEXTUREHW : // ( 330 ) - return "DDERR_NOTEXTUREHW "; - case DDERR_NOVSYNCHW : // ( 335 ) - return "DDERR_NOVSYNCHW "; - case DDERR_NOZBUFFERHW : // ( 340 ) - return "DDERR_NOZBUFFERHW "; - case DDERR_NOZOVERLAYHW : // ( 350 ) - return "DDERR_NOZOVERLAYHW "; - case DDERR_OUTOFCAPS : // ( 360 ) - return "DDERR_OUTOFCAPS "; - case DDERR_OUTOFVIDEOMEMORY : // ( 380 ) - return "DDERR_OUTOFVIDEOMEMORY "; - case DDERR_OVERLAYCANTCLIP : // ( 382 ) - return "DDERR_OVERLAYCANTCLIP "; - case DDERR_OVERLAYCOLORKEYONLYONEACTIVE : // ( 384 ) - return "DDERR_OVERLAYCOLORKEYONLYONEACTIVE "; - case DDERR_PALETTEBUSY : // ( 387 ) - return "DDERR_PALETTEBUSY "; - case DDERR_COLORKEYNOTSET : // ( 400 ) - return "DDERR_COLORKEYNOTSET "; - case DDERR_SURFACEALREADYATTACHED : // ( 410 ) - return "DDERR_SURFACEALREADYATTACHED "; - case DDERR_SURFACEALREADYDEPENDENT : // ( 420 ) - return "DDERR_SURFACEALREADYDEPENDENT "; - case DDERR_SURFACEBUSY : // ( 430 ) - return "DDERR_SURFACEBUSY "; - case DDERR_CANTLOCKSURFACE : // ( 435 ) - return "DDERR_CANTLOCKSURFACE"; - case DDERR_SURFACEISOBSCURED : // ( 440 ) - return "DDERR_SURFACEISOBSCURED "; - case DDERR_SURFACELOST : // ( 450 ) - return "DDERR_SURFACELOST "; - case DDERR_SURFACENOTATTACHED : // ( 460 ) - return "DDERR_SURFACENOTATTACHED "; - case DDERR_TOOBIGHEIGHT : // ( 470 ) - return "DDERR_TOOBIGHEIGHT "; - case DDERR_TOOBIGSIZE : // ( 480 ) - return "DDERR_TOOBIGSIZE "; - case DDERR_TOOBIGWIDTH : // ( 490 ) - return "DDERR_TOOBIGWIDTH "; - case DDERR_UNSUPPORTEDFORMAT : // ( 510 ) - return "DDERR_UNSUPPORTEDFORMAT "; - case DDERR_UNSUPPORTEDMASK : // ( 520 ) - return "DDERR_UNSUPPORTEDMASK "; - case DDERR_INVALIDSTREAM : // ( 521 ) - return "DDERR_INVALIDSTREAM"; - case DDERR_VERTICALBLANKINPROGRESS : // ( 537 ) - return "DDERR_VERTICALBLANKINPROGRESS "; - case DDERR_WASSTILLDRAWING : // ( 540 ) - return "DDERR_WASSTILLDRAWING "; - case DDERR_XALIGN : // ( 560 ) - return "DDERR_XALIGN "; - case DDERR_INVALIDDIRECTDRAWGUID : // ( 561 ) - return "DDERR_INVALIDDIRECTDRAWGUID "; - case DDERR_DIRECTDRAWALREADYCREATED : // ( 562 ) - return "DDERR_DIRECTDRAWALREADYCREATED "; - case DDERR_NODIRECTDRAWHW : // ( 563 ) - return "DDERR_NODIRECTDRAWHW "; - case DDERR_PRIMARYSURFACEALREADYEXISTS : // ( 564 ) - return "DDERR_PRIMARYSURFACEALREADYEXISTS "; - case DDERR_NOEMULATION : // ( 565 ) - return "DDERR_NOEMULATION "; - case DDERR_REGIONTOOSMALL : // ( 566 ) - return "DDERR_REGIONTOOSMALL "; - case DDERR_CLIPPERISUSINGHWND : // ( 567 ) - return "DDERR_CLIPPERISUSINGHWND "; - case DDERR_NOCLIPPERATTACHED : // ( 568 ) - return "DDERR_NOCLIPPERATTACHED "; - case DDERR_NOHWND : // ( 569 ) - return "DDERR_NOHWND "; - case DDERR_HWNDSUBCLASSED : // ( 570 ) - return "DDERR_HWNDSUBCLASSED "; - case DDERR_HWNDALREADYSET : // ( 571 ) - return "DDERR_HWNDALREADYSET "; - case DDERR_NOPALETTEATTACHED : // ( 572 ) - return "DDERR_NOPALETTEATTACHED "; - case DDERR_NOPALETTEHW : // ( 573 ) - return "DDERR_NOPALETTEHW "; - case DDERR_BLTFASTCANTCLIP : // ( 574 ) - return "DDERR_BLTFASTCANTCLIP "; - case DDERR_NOBLTHW : // ( 575 ) - return "DDERR_NOBLTHW "; - case DDERR_NODDROPSHW : // ( 576 ) - return "DDERR_NODDROPSHW "; - case DDERR_OVERLAYNOTVISIBLE : // ( 577 ) - return "DDERR_OVERLAYNOTVISIBLE "; - case DDERR_NOOVERLAYDEST : // ( 578 ) - return "DDERR_NOOVERLAYDEST "; - case DDERR_INVALIDPOSITION : // ( 579 ) - return "DDERR_INVALIDPOSITION "; - case DDERR_NOTAOVERLAYSURFACE : // ( 580 ) - return "DDERR_NOTAOVERLAYSURFACE "; - case DDERR_EXCLUSIVEMODEALREADYSET : // ( 581 ) - return "DDERR_EXCLUSIVEMODEALREADYSET "; - case DDERR_NOTFLIPPABLE : // ( 582 ) - return "DDERR_NOTFLIPPABLE "; - case DDERR_CANTDUPLICATE : // ( 583 ) - return "DDERR_CANTDUPLICATE "; - case DDERR_NOTLOCKED : // ( 584 ) - return "DDERR_NOTLOCKED "; - case DDERR_CANTCREATEDC : // ( 585 ) - return "DDERR_CANTCREATEDC "; - case DDERR_NODC : // ( 586 ) - return "DDERR_NODC "; - case DDERR_WRONGMODE : // ( 587 ) - return "DDERR_WRONGMODE "; - case DDERR_IMPLICITLYCREATED : // ( 588 ) - return "DDERR_IMPLICITLYCREATED "; - case DDERR_NOTPALETTIZED : // ( 589 ) - return "DDERR_NOTPALETTIZED "; - case DDERR_UNSUPPORTEDMODE : // ( 590 ) - return "DDERR_UNSUPPORTEDMODE "; - case DDERR_NOMIPMAPHW : // ( 591 ) - return "DDERR_NOMIPMAPHW "; - case DDERR_INVALIDSURFACETYPE : // ( 592 ) - return "DDERR_INVALIDSURFACETYPE"; - case DDERR_NOOPTIMIZEHW : // ( 600 ) - return "DDERR_NOOPTIMIZEHW"; - case DDERR_NOTLOADED : // ( 601 ) - return "DDERR_NOTLOADED"; - case DDERR_NOFOCUSWINDOW : // ( 602 ) - return "DDERR_NOFOCUSWINDOW"; - case DDERR_DCALREADYCREATED : // ( 620 ) - return "DDERR_DCALREADYCREATED "; - case DDERR_NONONLOCALVIDMEM : // ( 630 ) - return "DDERR_NONONLOCALVIDMEM"; - case DDERR_CANTPAGELOCK : // ( 640 ) - return "DDERR_CANTPAGELOCK "; - case DDERR_CANTPAGEUNLOCK : // ( 660 ) - return "DDERR_CANTPAGEUNLOCK "; - case DDERR_NOTPAGELOCKED : // ( 680 ) - return "DDERR_NOTPAGELOCKED "; - case DDERR_MOREDATA : // ( 690 ) - return "DDERR_MOREDATA "; - case DDERR_EXPIRED : // ( 691 ) - return "DDERR_EXPIRED"; - case DDERR_VIDEONOTACTIVE : // ( 695 ) - return "DDERR_VIDEONOTACTIVE "; - case DDERR_DEVICEDOESNTOWNSURFACE : // ( 699 ) - return "DDERR_DEVICEDOESNTOWNSURFACE "; - case DXFILEERR_BADOBJECT : // (850) - return "DXFILEERR_BADOBJECT"; - case DXFILEERR_BADVALUE : // (851) - return "DXFILEERR_BADVALUE"; - case DXFILEERR_BADTYPE : // (852) - return "DXFILEERR_BADTYPE"; - case DXFILEERR_BADSTREAMHANDLE : // (853) - return "DXFILEERR_BADSTREAMHANDLE"; - case DXFILEERR_BADALLOC : // (854) - return "DXFILEERR_BADALLOC"; - case DXFILEERR_NOTFOUND : // (855) - return "DXFILEERR_NOTFOUND"; - case DXFILEERR_NOTDONEYET : // (856) - return "DXFILEERR_NOTDONEYET"; - case DXFILEERR_FILENOTFOUND : // (857) - return "DXFILEERR_FILENOTFOUND"; - case DXFILEERR_RESOURCENOTFOUND : // (858) - return "DXFILEERR_RESOURCENOTFOUND"; - case DXFILEERR_URLNOTFOUND : // (859) - return "DXFILEERR_URLNOTFOUND"; - case DXFILEERR_BADRESOURCE : // (860) - return "DXFILEERR_BADRESOURCE"; - case DXFILEERR_BADFILETYPE : // (861) - return "DXFILEERR_BADFILETYPE"; - case DXFILEERR_BADFILEVERSION : // (862) - return "DXFILEERR_BADFILEVERSION"; - case DXFILEERR_BADFILEFLOATSIZE : // (863) - return "DXFILEERR_BADFILEFLOATSIZE"; - case DXFILEERR_BADFILECOMPRESSIONTYPE : // (864) - return "DXFILEERR_BADFILECOMPRESSIONTYPE"; - case DXFILEERR_BADFILE : // (865) - return "DXFILEERR_BADFILE"; - case DXFILEERR_PARSEERROR : // (866) - return "DXFILEERR_PARSEERROR"; - case DXFILEERR_NOTEMPLATE : // (867) - return "DXFILEERR_NOTEMPLATE"; - case DXFILEERR_BADARRAYSIZE : // (868) - return "DXFILEERR_BADARRAYSIZE"; - case DXFILEERR_BADDATAREFERENCE : // (869) - return "DXFILEERR_BADDATAREFERENCE"; - case DXFILEERR_INTERNALERROR : // (870) - return "DXFILEERR_INTERNALERROR"; - case DXFILEERR_NOMOREOBJECTS : // (871) - return "DXFILEERR_NOMOREOBJECTS"; - case DXFILEERR_BADINTRINSICS : // (872) - return "DXFILEERR_BADINTRINSICS"; - case DXFILEERR_NOMORESTREAMHANDLES : // (873) - return "DXFILEERR_NOMORESTREAMHANDLES"; - case DXFILEERR_NOMOREDATA : // (874) - return "DXFILEERR_NOMOREDATA"; - case DXFILEERR_BADCACHEFILE : // (875) - return "DXFILEERR_BADCACHEFILE"; - case DXFILEERR_NOINTERNET : // (876) - return "DXFILEERR_NOINTERNET"; - - case E_UNEXPECTED : - return "E_UNEXPECTED "; - case E_NOTIMPL : - return "E_NOTIMPL "; - case E_OUTOFMEMORY : - return "E_OUTOFMEMORY "; - case E_INVALIDARG : - return "E_INVALIDARG or DDERR_INVALIDPARAMS"; - case E_NOINTERFACE : - return "E_NOINTERFACE "; - case E_POINTER : - return "E_POINTER "; - case E_HANDLE : - return "E_HANDLE "; - case E_ABORT : - return "E_ABORT "; - // case E_FAIL : - // return "E_FAIL "; - case E_ACCESSDENIED : - return "E_ACCESSDENIED "; - case E_PENDING : - return "E_PENDING "; - case CO_E_INIT_TLS : - return "CO_E_INIT_TLS "; - case CO_E_INIT_SHARED_ALLOCATOR : - return "CO_E_INIT_SHARED_ALLOCATOR "; - case CO_E_INIT_MEMORY_ALLOCATOR : - return "CO_E_INIT_MEMORY_ALLOCATOR "; - case CO_E_INIT_CLASS_CACHE : - return "CO_E_INIT_CLASS_CACHE "; - case CO_E_INIT_RPC_CHANNEL : - return "CO_E_INIT_RPC_CHANNEL "; - case CO_E_INIT_TLS_SET_CHANNEL_CONTROL : - return "CO_E_INIT_TLS_SET_CHANNEL_CONTROL "; - case CO_E_INIT_TLS_CHANNEL_CONTROL : - return "CO_E_INIT_TLS_CHANNEL_CONTROL "; - case CO_E_INIT_UNACCEPTED_USER_ALLOCATOR : - return "CO_E_INIT_UNACCEPTED_USER_ALLOCATOR "; - case CO_E_INIT_SCM_MUTEX_EXISTS : - return "CO_E_INIT_SCM_MUTEX_EXISTS "; - case CO_E_INIT_SCM_FILE_MAPPING_EXISTS : - return "CO_E_INIT_SCM_FILE_MAPPING_EXISTS "; - case CO_E_INIT_SCM_MAP_VIEW_OF_FILE : - return "CO_E_INIT_SCM_MAP_VIEW_OF_FILE "; - case CO_E_INIT_SCM_EXEC_FAILURE : - return "CO_E_INIT_SCM_EXEC_FAILURE "; - case CO_E_INIT_ONLY_SINGLE_THREADED : - return "CO_E_INIT_ONLY_SINGLE_THREADED "; - case CO_E_CANT_REMOTE : - return "CO_E_CANT_REMOTE "; - case CO_E_BAD_SERVER_NAME : - return "CO_E_BAD_SERVER_NAME "; - case CO_E_WRONG_SERVER_IDENTITY : - return "CO_E_WRONG_SERVER_IDENTITY "; - case CO_E_OLE1DDE_DISABLED : - return "CO_E_OLE1DDE_DISABLED "; - case CO_E_RUNAS_SYNTAX : - return "CO_E_RUNAS_SYNTAX "; - case CO_E_CREATEPROCESS_FAILURE : - return "CO_E_CREATEPROCESS_FAILURE "; - case CO_E_RUNAS_CREATEPROCESS_FAILURE : - return "CO_E_RUNAS_CREATEPROCESS_FAILURE "; - case CO_E_RUNAS_LOGON_FAILURE : - return "CO_E_RUNAS_LOGON_FAILURE "; - case CO_E_LAUNCH_PERMSSION_DENIED : - return "CO_E_LAUNCH_PERMSSION_DENIED "; - case CO_E_START_SERVICE_FAILURE : - return "CO_E_START_SERVICE_FAILURE "; - case CO_E_REMOTE_COMMUNICATION_FAILURE : - return "CO_E_REMOTE_COMMUNICATION_FAILURE "; - case CO_E_SERVER_START_TIMEOUT : - return "CO_E_SERVER_START_TIMEOUT "; - case CO_E_CLSREG_INCONSISTENT : - return "CO_E_CLSREG_INCONSISTENT "; - case CO_E_IIDREG_INCONSISTENT : - return "CO_E_IIDREG_INCONSISTENT "; - case CO_E_NOT_SUPPORTED : - return "CO_E_NOT_SUPPORTED "; - case CO_E_RELOAD_DLL : - return "CO_E_RELOAD_DLL "; - case CO_E_MSI_ERROR : - return "CO_E_MSI_ERROR "; - case OLE_E_OLEVERB : - return "OLE_E_OLEVERB "; - case OLE_E_ADVF : - return "OLE_E_ADVF "; - case OLE_E_ENUM_NOMORE : - return "OLE_E_ENUM_NOMORE "; - case OLE_E_ADVISENOTSUPPORTED : - return "OLE_E_ADVISENOTSUPPORTED "; - case OLE_E_NOCONNECTION : - return "OLE_E_NOCONNECTION "; - case OLE_E_NOTRUNNING : - return "OLE_E_NOTRUNNING "; - case OLE_E_NOCACHE : - return "OLE_E_NOCACHE "; - case OLE_E_BLANK : - return "OLE_E_BLANK "; - case OLE_E_CLASSDIFF : - return "OLE_E_CLASSDIFF "; - case OLE_E_CANT_GETMONIKER : - return "OLE_E_CANT_GETMONIKER "; - case OLE_E_CANT_BINDTOSOURCE : - return "OLE_E_CANT_BINDTOSOURCE "; - case OLE_E_STATIC : - return "OLE_E_STATIC "; - case OLE_E_PROMPTSAVECANCELLED : - return "OLE_E_PROMPTSAVECANCELLED "; - case OLE_E_INVALIDRECT : - return "OLE_E_INVALIDRECT "; - case OLE_E_WRONGCOMPOBJ : - return "OLE_E_WRONGCOMPOBJ "; - case OLE_E_INVALIDHWND : - return "OLE_E_INVALIDHWND "; - case OLE_E_NOT_INPLACEACTIVE : - return "OLE_E_NOT_INPLACEACTIVE "; - case OLE_E_CANTCONVERT : - return "OLE_E_CANTCONVERT "; - case OLE_E_NOSTORAGE : - return "OLE_E_NOSTORAGE "; - case DV_E_FORMATETC : - return "DV_E_FORMATETC "; - case DV_E_DVTARGETDEVICE : - return "DV_E_DVTARGETDEVICE "; - case DV_E_STGMEDIUM : - return "DV_E_STGMEDIUM "; - case DV_E_STATDATA : - return "DV_E_STATDATA "; - case DV_E_LINDEX : - return "DV_E_LINDEX "; - case DV_E_TYMED : - return "DV_E_TYMED "; - case DV_E_CLIPFORMAT : - return "DV_E_CLIPFORMAT "; - case DV_E_DVASPECT : - return "DV_E_DVASPECT "; - case DV_E_DVTARGETDEVICE_SIZE : - return "DV_E_DVTARGETDEVICE_SIZE "; - case DV_E_NOIVIEWOBJECT : - return "DV_E_NOIVIEWOBJECT "; - case DRAGDROP_E_NOTREGISTERED : - return "DRAGDROP_E_NOTREGISTERED "; - case DRAGDROP_E_ALREADYREGISTERED : - return "DRAGDROP_E_ALREADYREGISTERED "; - case DRAGDROP_E_INVALIDHWND : - return "DRAGDROP_E_INVALIDHWND "; - case CLASS_E_NOAGGREGATION : - return "CLASS_E_NOAGGREGATION "; - case CLASS_E_CLASSNOTAVAILABLE : - return "CLASS_E_CLASSNOTAVAILABLE "; - case CLASS_E_NOTLICENSED : - return "CLASS_E_NOTLICENSED "; - case VIEW_E_DRAW : - return "VIEW_E_DRAW "; - case REGDB_E_READREGDB : - return "REGDB_E_READREGDB "; - case REGDB_E_WRITEREGDB : - return "REGDB_E_WRITEREGDB "; - case REGDB_E_KEYMISSING : - return "REGDB_E_KEYMISSING "; - case REGDB_E_INVALIDVALUE : - return "REGDB_E_INVALIDVALUE "; - case REGDB_E_CLASSNOTREG : - return "REGDB_E_CLASSNOTREG "; - case REGDB_E_IIDNOTREG : - return "REGDB_E_IIDNOTREG "; - case CAT_E_CATIDNOEXIST : - return "CAT_E_CATIDNOEXIST "; - case CAT_E_NODESCRIPTION : - return "CAT_E_NODESCRIPTION "; - case CS_E_PACKAGE_NOTFOUND : - return "CS_E_PACKAGE_NOTFOUND "; - case CS_E_NOT_DELETABLE : - return "CS_E_NOT_DELETABLE "; - case CS_E_CLASS_NOTFOUND : - return "CS_E_CLASS_NOTFOUND "; - case CS_E_INVALID_VERSION : - return "CS_E_INVALID_VERSION "; - case CS_E_NO_CLASSSTORE : - return "CS_E_NO_CLASSSTORE "; - case CACHE_E_NOCACHE_UPDATED : - return "CACHE_E_NOCACHE_UPDATED "; - case OLEOBJ_E_NOVERBS : - return "OLEOBJ_E_NOVERBS "; - case OLEOBJ_E_INVALIDVERB : - return "OLEOBJ_E_INVALIDVERB "; - case INPLACE_E_NOTUNDOABLE : - return "INPLACE_E_NOTUNDOABLE "; - case INPLACE_E_NOTOOLSPACE : - return "INPLACE_E_NOTOOLSPACE "; - case CONVERT10_E_OLESTREAM_GET : - return "CONVERT10_E_OLESTREAM_GET "; - case CONVERT10_E_OLESTREAM_PUT : - return "CONVERT10_E_OLESTREAM_PUT "; - case CONVERT10_E_OLESTREAM_FMT : - return "CONVERT10_E_OLESTREAM_FMT "; - case CONVERT10_E_OLESTREAM_BITMAP_TO_DIB : - return "CONVERT10_E_OLESTREAM_BITMAP_TO_DIB "; - case CONVERT10_E_STG_FMT : - return "CONVERT10_E_STG_FMT "; - case CONVERT10_E_STG_NO_STD_STREAM : - return "CONVERT10_E_STG_NO_STD_STREAM "; - case CONVERT10_E_STG_DIB_TO_BITMAP : - return "CONVERT10_E_STG_DIB_TO_BITMAP "; - case CLIPBRD_E_CANT_OPEN : - return "CLIPBRD_E_CANT_OPEN "; - case CLIPBRD_E_CANT_EMPTY : - return "CLIPBRD_E_CANT_EMPTY "; - case CLIPBRD_E_CANT_SET : - return "CLIPBRD_E_CANT_SET "; - case CLIPBRD_E_BAD_DATA : - return "CLIPBRD_E_BAD_DATA "; - case CLIPBRD_E_CANT_CLOSE : - return "CLIPBRD_E_CANT_CLOSE "; - case MK_E_CONNECTMANUALLY : - return "MK_E_CONNECTMANUALLY "; - case MK_E_EXCEEDEDDEADLINE : - return "MK_E_EXCEEDEDDEADLINE "; - case MK_E_NEEDGENERIC : - return "MK_E_NEEDGENERIC "; - case MK_E_UNAVAILABLE : - return "MK_E_UNAVAILABLE "; - case MK_E_SYNTAX : - return "MK_E_SYNTAX "; - case MK_E_NOOBJECT : - return "MK_E_NOOBJECT "; - case MK_E_INVALIDEXTENSION : - return "MK_E_INVALIDEXTENSION "; - case MK_E_INTERMEDIATEINTERFACENOTSUPPORTED : - return "MK_E_INTERMEDIATEINTERFACENOTSUPPORTED "; - case MK_E_NOTBINDABLE : - return "MK_E_NOTBINDABLE "; - case MK_E_NOTBOUND : - return "MK_E_NOTBOUND "; - case MK_E_CANTOPENFILE : - return "MK_E_CANTOPENFILE "; - case MK_E_MUSTBOTHERUSER : - return "MK_E_MUSTBOTHERUSER "; - case MK_E_NOINVERSE : - return "MK_E_NOINVERSE "; - case MK_E_NOSTORAGE : - return "MK_E_NOSTORAGE "; - case MK_E_NOPREFIX : - return "MK_E_NOPREFIX "; - case MK_E_ENUMERATION_FAILED : - return "MK_E_ENUMERATION_FAILED "; - case CO_E_NOTINITIALIZED : - return "CO_E_NOTINITIALIZED "; - case CO_E_ALREADYINITIALIZED : - return "CO_E_ALREADYINITIALIZED "; - case CO_E_CANTDETERMINECLASS : - return "CO_E_CANTDETERMINECLASS "; - case CO_E_CLASSSTRING : - return "CO_E_CLASSSTRING "; - case CO_E_IIDSTRING : - return "CO_E_IIDSTRING "; - case CO_E_APPNOTFOUND : - return "CO_E_APPNOTFOUND "; - case CO_E_APPSINGLEUSE : - return "CO_E_APPSINGLEUSE "; - case CO_E_ERRORINAPP : - return "CO_E_ERRORINAPP "; - case CO_E_DLLNOTFOUND : - return "CO_E_DLLNOTFOUND "; - case CO_E_ERRORINDLL : - return "CO_E_ERRORINDLL "; - case CO_E_WRONGOSFORAPP : - return "CO_E_WRONGOSFORAPP "; - case CO_E_OBJNOTREG : - return "CO_E_OBJNOTREG "; - case CO_E_OBJISREG : - return "CO_E_OBJISREG "; - case CO_E_OBJNOTCONNECTED : - return "CO_E_OBJNOTCONNECTED "; - case CO_E_APPDIDNTREG : - return "CO_E_APPDIDNTREG "; - case CO_E_RELEASED : - return "CO_E_RELEASED "; - case CO_E_FAILEDTOIMPERSONATE : - return "CO_E_FAILEDTOIMPERSONATE "; - case CO_E_FAILEDTOGETSECCTX : - return "CO_E_FAILEDTOGETSECCTX "; - case CO_E_FAILEDTOOPENTHREADTOKEN : - return "CO_E_FAILEDTOOPENTHREADTOKEN "; - case CO_E_FAILEDTOGETTOKENINFO : - return "CO_E_FAILEDTOGETTOKENINFO "; - case CO_E_TRUSTEEDOESNTMATCHCLIENT : - return "CO_E_TRUSTEEDOESNTMATCHCLIENT "; - case CO_E_FAILEDTOQUERYCLIENTBLANKET : - return "CO_E_FAILEDTOQUERYCLIENTBLANKET "; - case CO_E_FAILEDTOSETDACL : - return "CO_E_FAILEDTOSETDACL "; - case CO_E_ACCESSCHECKFAILED : - return "CO_E_ACCESSCHECKFAILED "; - case CO_E_NETACCESSAPIFAILED : - return "CO_E_NETACCESSAPIFAILED "; - case CO_E_WRONGTRUSTEENAMESYNTAX : - return "CO_E_WRONGTRUSTEENAMESYNTAX "; - case CO_E_INVALIDSID : - return "CO_E_INVALIDSID "; - case CO_E_CONVERSIONFAILED : - return "CO_E_CONVERSIONFAILED "; - case CO_E_NOMATCHINGSIDFOUND : - return "CO_E_NOMATCHINGSIDFOUND "; - case CO_E_LOOKUPACCSIDFAILED : - return "CO_E_LOOKUPACCSIDFAILED "; - case CO_E_NOMATCHINGNAMEFOUND : - return "CO_E_NOMATCHINGNAMEFOUND "; - case CO_E_LOOKUPACCNAMEFAILED : - return "CO_E_LOOKUPACCNAMEFAILED "; - case CO_E_SETSERLHNDLFAILED : - return "CO_E_SETSERLHNDLFAILED "; - case CO_E_FAILEDTOGETWINDIR : - return "CO_E_FAILEDTOGETWINDIR "; - case CO_E_PATHTOOLONG : - return "CO_E_PATHTOOLONG "; - case CO_E_FAILEDTOGENUUID : - return "CO_E_FAILEDTOGENUUID "; - case CO_E_FAILEDTOCREATEFILE : - return "CO_E_FAILEDTOCREATEFILE "; - case CO_E_FAILEDTOCLOSEHANDLE : - return "CO_E_FAILEDTOCLOSEHANDLE "; - case CO_E_EXCEEDSYSACLLIMIT : - return "CO_E_EXCEEDSYSACLLIMIT "; - case CO_E_ACESINWRONGORDER : - return "CO_E_ACESINWRONGORDER "; - case CO_E_INCOMPATIBLESTREAMVERSION : - return "CO_E_INCOMPATIBLESTREAMVERSION "; - case CO_E_FAILEDTOOPENPROCESSTOKEN : - return "CO_E_FAILEDTOOPENPROCESSTOKEN "; - case CO_E_DECODEFAILED : - return "CO_E_DECODEFAILED "; - case CO_E_ACNOTINITIALIZED : - return "CO_E_ACNOTINITIALIZED "; - case OLE_S_USEREG : - return "OLE_S_USEREG "; - case OLE_S_STATIC : - return "OLE_S_STATIC "; - case OLE_S_MAC_CLIPFORMAT : - return "OLE_S_MAC_CLIPFORMAT "; - case DRAGDROP_S_DROP : - return "DRAGDROP_S_DROP "; - case DRAGDROP_S_CANCEL : - return "DRAGDROP_S_CANCEL "; - case DRAGDROP_S_USEDEFAULTCURSORS : - return "DRAGDROP_S_USEDEFAULTCURSORS "; - case DATA_S_SAMEFORMATETC : - return "DATA_S_SAMEFORMATETC "; - case VIEW_S_ALREADY_FROZEN : - return "VIEW_S_ALREADY_FROZEN "; - case CACHE_S_FORMATETC_NOTSUPPORTED : - return "CACHE_S_FORMATETC_NOTSUPPORTED "; - case CACHE_S_SAMECACHE : - return "CACHE_S_SAMECACHE "; - case CACHE_S_SOMECACHES_NOTUPDATED : - return "CACHE_S_SOMECACHES_NOTUPDATED "; - case OLEOBJ_S_INVALIDVERB : - return "OLEOBJ_S_INVALIDVERB "; - case OLEOBJ_S_CANNOT_DOVERB_NOW : - return "OLEOBJ_S_CANNOT_DOVERB_NOW "; - case OLEOBJ_S_INVALIDHWND : - return "OLEOBJ_S_INVALIDHWND "; - case INPLACE_S_TRUNCATED : - return "INPLACE_S_TRUNCATED "; - case CONVERT10_S_NO_PRESENTATION : - return "CONVERT10_S_NO_PRESENTATION "; - case MK_S_REDUCED_TO_SELF : - return "MK_S_REDUCED_TO_SELF "; - case MK_S_ME : - return "MK_S_ME "; - case MK_S_HIM : - return "MK_S_HIM "; - case MK_S_US : - return "MK_S_US "; - case MK_S_MONIKERALREADYREGISTERED : - return "MK_S_MONIKERALREADYREGISTERED "; - case CO_E_CLASS_CREATE_FAILED : - return "CO_E_CLASS_CREATE_FAILED "; - case CO_E_SCM_ERROR : - return "CO_E_SCM_ERROR "; - case CO_E_SCM_RPC_FAILURE : - return "CO_E_SCM_RPC_FAILURE "; - case CO_E_BAD_PATH : - return "CO_E_BAD_PATH "; - case CO_E_SERVER_EXEC_FAILURE : - return "CO_E_SERVER_EXEC_FAILURE "; - case CO_E_OBJSRV_RPC_FAILURE : - return "CO_E_OBJSRV_RPC_FAILURE "; - case MK_E_NO_NORMALIZED : - return "MK_E_NO_NORMALIZED "; - case CO_E_SERVER_STOPPING : - return "CO_E_SERVER_STOPPING "; - case MEM_E_INVALID_ROOT : - return "MEM_E_INVALID_ROOT "; - case MEM_E_INVALID_LINK : - return "MEM_E_INVALID_LINK "; - case MEM_E_INVALID_SIZE : - return "MEM_E_INVALID_SIZE "; - case CO_S_NOTALLINTERFACES : - return "CO_S_NOTALLINTERFACES "; - case DISP_E_UNKNOWNINTERFACE : - return "DISP_E_UNKNOWNINTERFACE "; - case DISP_E_MEMBERNOTFOUND : - return "DISP_E_MEMBERNOTFOUND "; - case DISP_E_PARAMNOTFOUND : - return "DISP_E_PARAMNOTFOUND "; - case DISP_E_TYPEMISMATCH : - return "DISP_E_TYPEMISMATCH "; - case DISP_E_UNKNOWNNAME : - return "DISP_E_UNKNOWNNAME "; - case DISP_E_NONAMEDARGS : - return "DISP_E_NONAMEDARGS "; - case DISP_E_BADVARTYPE : - return "DISP_E_BADVARTYPE "; - case DISP_E_EXCEPTION : - return "DISP_E_EXCEPTION "; - case DISP_E_OVERFLOW : - return "DISP_E_OVERFLOW "; - case DISP_E_BADINDEX : - return "DISP_E_BADINDEX "; - case DISP_E_UNKNOWNLCID : - return "DISP_E_UNKNOWNLCID "; - case DISP_E_ARRAYISLOCKED : - return "DISP_E_ARRAYISLOCKED "; - case DISP_E_BADPARAMCOUNT : - return "DISP_E_BADPARAMCOUNT "; - case DISP_E_PARAMNOTOPTIONAL : - return "DISP_E_PARAMNOTOPTIONAL "; - case DISP_E_BADCALLEE : - return "DISP_E_BADCALLEE "; - case DISP_E_NOTACOLLECTION : - return "DISP_E_NOTACOLLECTION "; - case DISP_E_DIVBYZERO : - return "DISP_E_DIVBYZERO "; - case TYPE_E_BUFFERTOOSMALL : - return "TYPE_E_BUFFERTOOSMALL "; - case TYPE_E_FIELDNOTFOUND : - return "TYPE_E_FIELDNOTFOUND "; - case TYPE_E_INVDATAREAD : - return "TYPE_E_INVDATAREAD "; - case TYPE_E_UNSUPFORMAT : - return "TYPE_E_UNSUPFORMAT "; - case TYPE_E_REGISTRYACCESS : - return "TYPE_E_REGISTRYACCESS "; - case TYPE_E_LIBNOTREGISTERED : - return "TYPE_E_LIBNOTREGISTERED "; - case TYPE_E_UNDEFINEDTYPE : - return "TYPE_E_UNDEFINEDTYPE "; - case TYPE_E_QUALIFIEDNAMEDISALLOWED : - return "TYPE_E_QUALIFIEDNAMEDISALLOWED "; - case TYPE_E_INVALIDSTATE : - return "TYPE_E_INVALIDSTATE "; - case TYPE_E_WRONGTYPEKIND : - return "TYPE_E_WRONGTYPEKIND "; - case TYPE_E_ELEMENTNOTFOUND : - return "TYPE_E_ELEMENTNOTFOUND "; - case TYPE_E_AMBIGUOUSNAME : - return "TYPE_E_AMBIGUOUSNAME "; - case TYPE_E_NAMECONFLICT : - return "TYPE_E_NAMECONFLICT "; - case TYPE_E_UNKNOWNLCID : - return "TYPE_E_UNKNOWNLCID "; - case TYPE_E_DLLFUNCTIONNOTFOUND : - return "TYPE_E_DLLFUNCTIONNOTFOUND "; - case TYPE_E_BADMODULEKIND : - return "TYPE_E_BADMODULEKIND "; - case TYPE_E_SIZETOOBIG : - return "TYPE_E_SIZETOOBIG "; - case TYPE_E_DUPLICATEID : - return "TYPE_E_DUPLICATEID "; - case TYPE_E_INVALIDID : - return "TYPE_E_INVALIDID "; - case TYPE_E_TYPEMISMATCH : - return "TYPE_E_TYPEMISMATCH "; - case TYPE_E_OUTOFBOUNDS : - return "TYPE_E_OUTOFBOUNDS "; - case TYPE_E_IOERROR : - return "TYPE_E_IOERROR "; - case TYPE_E_CANTCREATETMPFILE : - return "TYPE_E_CANTCREATETMPFILE "; - case TYPE_E_CANTLOADLIBRARY : - return "TYPE_E_CANTLOADLIBRARY "; - case TYPE_E_INCONSISTENTPROPFUNCS : - return "TYPE_E_INCONSISTENTPROPFUNCS "; - case TYPE_E_CIRCULARTYPE : - return "TYPE_E_CIRCULARTYPE "; - case STG_E_INVALIDFUNCTION : - return "STG_E_INVALIDFUNCTION "; - case STG_E_FILENOTFOUND : - return "STG_E_FILENOTFOUND "; - case STG_E_PATHNOTFOUND : - return "STG_E_PATHNOTFOUND "; - case STG_E_TOOMANYOPENFILES : - return "STG_E_TOOMANYOPENFILES "; - case STG_E_ACCESSDENIED : - return "STG_E_ACCESSDENIED "; - case STG_E_INVALIDHANDLE : - return "STG_E_INVALIDHANDLE "; - case STG_E_INSUFFICIENTMEMORY : - return "STG_E_INSUFFICIENTMEMORY "; - case STG_E_INVALIDPOINTER : - return "STG_E_INVALIDPOINTER "; - case STG_E_NOMOREFILES : - return "STG_E_NOMOREFILES "; - case STG_E_DISKISWRITEPROTECTED : - return "STG_E_DISKISWRITEPROTECTED "; - case STG_E_SEEKERROR : - return "STG_E_SEEKERROR "; - case STG_E_WRITEFAULT : - return "STG_E_WRITEFAULT "; - case STG_E_READFAULT : - return "STG_E_READFAULT "; - case STG_E_SHAREVIOLATION : - return "STG_E_SHAREVIOLATION "; - case STG_E_LOCKVIOLATION : - return "STG_E_LOCKVIOLATION "; - case STG_E_FILEALREADYEXISTS : - return "STG_E_FILEALREADYEXISTS "; - case STG_E_INVALIDPARAMETER : - return "STG_E_INVALIDPARAMETER "; - case STG_E_MEDIUMFULL : - return "STG_E_MEDIUMFULL "; - case STG_E_PROPSETMISMATCHED : - return "STG_E_PROPSETMISMATCHED "; - case STG_E_ABNORMALAPIEXIT : - return "STG_E_ABNORMALAPIEXIT "; - case STG_E_INVALIDHEADER : - return "STG_E_INVALIDHEADER "; - case STG_E_INVALIDNAME : - return "STG_E_INVALIDNAME "; - case STG_E_UNKNOWN : - return "STG_E_UNKNOWN "; - case STG_E_UNIMPLEMENTEDFUNCTION : - return "STG_E_UNIMPLEMENTEDFUNCTION "; - case STG_E_INVALIDFLAG : - return "STG_E_INVALIDFLAG "; - case STG_E_INUSE : - return "STG_E_INUSE "; - case STG_E_NOTCURRENT : - return "STG_E_NOTCURRENT "; - case STG_E_REVERTED : - return "STG_E_REVERTED "; - case STG_E_CANTSAVE : - return "STG_E_CANTSAVE "; - case STG_E_OLDFORMAT : - return "STG_E_OLDFORMAT "; - case STG_E_OLDDLL : - return "STG_E_OLDDLL "; - case STG_E_SHAREREQUIRED : - return "STG_E_SHAREREQUIRED "; - case STG_E_NOTFILEBASEDSTORAGE : - return "STG_E_NOTFILEBASEDSTORAGE "; - case STG_E_EXTANTMARSHALLINGS : - return "STG_E_EXTANTMARSHALLINGS "; - case STG_E_DOCFILECORRUPT : - return "STG_E_DOCFILECORRUPT "; - case STG_E_BADBASEADDRESS : - return "STG_E_BADBASEADDRESS "; - case STG_E_INCOMPLETE : - return "STG_E_INCOMPLETE "; - case STG_E_TERMINATED : - return "STG_E_TERMINATED "; - case STG_S_CONVERTED : - return "STG_S_CONVERTED "; - case STG_S_BLOCK : - return "STG_S_BLOCK "; - case STG_S_RETRYNOW : - return "STG_S_RETRYNOW "; - case STG_S_MONITORING : - return "STG_S_MONITORING "; - case STG_S_MULTIPLEOPENS : - return "STG_S_MULTIPLEOPENS "; - case STG_S_CONSOLIDATIONFAILED : - return "STG_S_CONSOLIDATIONFAILED "; - case STG_S_CANNOTCONSOLIDATE : - return "STG_S_CANNOTCONSOLIDATE "; - case RPC_E_CALL_REJECTED : - return "RPC_E_CALL_REJECTED "; - case RPC_E_CALL_CANCELED : - return "RPC_E_CALL_CANCELED "; - case RPC_E_CANTPOST_INSENDCALL : - return "RPC_E_CANTPOST_INSENDCALL "; - case RPC_E_CANTCALLOUT_INASYNCCALL : - return "RPC_E_CANTCALLOUT_INASYNCCALL "; - case RPC_E_CANTCALLOUT_INEXTERNALCALL : - return "RPC_E_CANTCALLOUT_INEXTERNALCALL "; - case RPC_E_CONNECTION_TERMINATED : - return "RPC_E_CONNECTION_TERMINATED "; - case RPC_E_SERVER_DIED : - return "RPC_E_SERVER_DIED "; - case RPC_E_CLIENT_DIED : - return "RPC_E_CLIENT_DIED "; - case RPC_E_INVALID_DATAPACKET : - return "RPC_E_INVALID_DATAPACKET "; - case RPC_E_CANTTRANSMIT_CALL : - return "RPC_E_CANTTRANSMIT_CALL "; - case RPC_E_CLIENT_CANTMARSHAL_DATA : - return "RPC_E_CLIENT_CANTMARSHAL_DATA "; - case RPC_E_CLIENT_CANTUNMARSHAL_DATA : - return "RPC_E_CLIENT_CANTUNMARSHAL_DATA "; - case RPC_E_SERVER_CANTMARSHAL_DATA : - return "RPC_E_SERVER_CANTMARSHAL_DATA "; - case RPC_E_SERVER_CANTUNMARSHAL_DATA : - return "RPC_E_SERVER_CANTUNMARSHAL_DATA "; - case RPC_E_INVALID_DATA : - return "RPC_E_INVALID_DATA "; - case RPC_E_INVALID_PARAMETER : - return "RPC_E_INVALID_PARAMETER "; - case RPC_E_CANTCALLOUT_AGAIN : - return "RPC_E_CANTCALLOUT_AGAIN "; - case RPC_E_SERVER_DIED_DNE : - return "RPC_E_SERVER_DIED_DNE "; - case RPC_E_SYS_CALL_FAILED : - return "RPC_E_SYS_CALL_FAILED "; - case RPC_E_OUT_OF_RESOURCES : - return "RPC_E_OUT_OF_RESOURCES "; - case RPC_E_ATTEMPTED_MULTITHREAD : - return "RPC_E_ATTEMPTED_MULTITHREAD "; - case RPC_E_NOT_REGISTERED : - return "RPC_E_NOT_REGISTERED "; - case RPC_E_FAULT : - return "RPC_E_FAULT "; - case RPC_E_SERVERFAULT : - return "RPC_E_SERVERFAULT "; - case RPC_E_CHANGED_MODE : - return "RPC_E_CHANGED_MODE "; - case RPC_E_INVALIDMETHOD : - return "RPC_E_INVALIDMETHOD "; - case RPC_E_DISCONNECTED : - return "RPC_E_DISCONNECTED "; - case RPC_E_RETRY : - return "RPC_E_RETRY "; - case RPC_E_SERVERCALL_RETRYLATER : - return "RPC_E_SERVERCALL_RETRYLATER "; - case RPC_E_SERVERCALL_REJECTED : - return "RPC_E_SERVERCALL_REJECTED "; - case RPC_E_INVALID_CALLDATA : - return "RPC_E_INVALID_CALLDATA "; - case RPC_E_CANTCALLOUT_ININPUTSYNCCALL : - return "RPC_E_CANTCALLOUT_ININPUTSYNCCALL "; - case RPC_E_WRONG_THREAD : - return "RPC_E_WRONG_THREAD "; - case RPC_E_THREAD_NOT_INIT : - return "RPC_E_THREAD_NOT_INIT "; - case RPC_E_VERSION_MISMATCH : - return "RPC_E_VERSION_MISMATCH "; - case RPC_E_INVALID_HEADER : - return "RPC_E_INVALID_HEADER "; - case RPC_E_INVALID_EXTENSION : - return "RPC_E_INVALID_EXTENSION "; - case RPC_E_INVALID_IPID : - return "RPC_E_INVALID_IPID "; - case RPC_E_INVALID_OBJECT : - return "RPC_E_INVALID_OBJECT "; - case RPC_S_CALLPENDING : - return "RPC_S_CALLPENDING "; - case RPC_S_WAITONTIMER : - return "RPC_S_WAITONTIMER "; - case RPC_E_CALL_COMPLETE : - return "RPC_E_CALL_COMPLETE "; - case RPC_E_UNSECURE_CALL : - return "RPC_E_UNSECURE_CALL "; - case RPC_E_TOO_LATE : - return "RPC_E_TOO_LATE "; - case RPC_E_NO_GOOD_SECURITY_PACKAGES : - return "RPC_E_NO_GOOD_SECURITY_PACKAGES "; - case RPC_E_ACCESS_DENIED : - return "RPC_E_ACCESS_DENIED "; - case RPC_E_REMOTE_DISABLED : - return "RPC_E_REMOTE_DISABLED "; - case RPC_E_INVALID_OBJREF : - return "RPC_E_INVALID_OBJREF "; - case RPC_E_NO_CONTEXT : - return "RPC_E_NO_CONTEXT "; - case RPC_E_TIMEOUT : - return "RPC_E_TIMEOUT "; - case RPC_E_NO_SYNC : - return "RPC_E_NO_SYNC "; - case RPC_E_UNEXPECTED : - return "RPC_E_UNEXPECTED "; - case NTE_BAD_UID : - return "NTE_BAD_UID "; - case NTE_BAD_HASH : - return "NTE_BAD_HASH "; - //case NTE_BAD_HASH : - //return "NTE_BAD_HASH "; - case NTE_BAD_KEY : - return "NTE_BAD_KEY "; - case NTE_BAD_LEN : - return "NTE_BAD_LEN "; - case NTE_BAD_DATA : - return "NTE_BAD_DATA "; - case NTE_BAD_SIGNATURE : - return "NTE_BAD_SIGNATURE "; - case NTE_BAD_VER : - return "NTE_BAD_VER "; - case NTE_BAD_ALGID : - return "NTE_BAD_ALGID "; - case NTE_BAD_FLAGS : - return "NTE_BAD_FLAGS "; - case NTE_BAD_TYPE : - return "NTE_BAD_TYPE "; - case NTE_BAD_KEY_STATE : - return "NTE_BAD_KEY_STATE "; - case NTE_BAD_HASH_STATE : - return "NTE_BAD_HASH_STATE "; - case NTE_NO_KEY : - return "NTE_NO_KEY "; - case NTE_NO_MEMORY : - return "NTE_NO_MEMORY "; - case NTE_EXISTS : - return "NTE_EXISTS "; - case NTE_PERM : - return "NTE_PERM "; - case NTE_NOT_FOUND : - return "NTE_NOT_FOUND "; - case NTE_DOUBLE_ENCRYPT : - return "NTE_DOUBLE_ENCRYPT "; - case NTE_BAD_PROVIDER : - return "NTE_BAD_PROVIDER "; - case NTE_BAD_PROV_TYPE : - return "NTE_BAD_PROV_TYPE "; - case NTE_BAD_PUBLIC_KEY : - return "NTE_BAD_PUBLIC_KEY "; - case NTE_BAD_KEYSET : - return "NTE_BAD_KEYSET "; - case NTE_PROV_TYPE_NOT_DEF : - return "NTE_PROV_TYPE_NOT_DEF "; - case NTE_PROV_TYPE_ENTRY_BAD : - return "NTE_PROV_TYPE_ENTRY_BAD "; - case NTE_KEYSET_NOT_DEF : - return "NTE_KEYSET_NOT_DEF "; - case NTE_KEYSET_ENTRY_BAD : - return "NTE_KEYSET_ENTRY_BAD "; - case NTE_PROV_TYPE_NO_MATCH : - return "NTE_PROV_TYPE_NO_MATCH "; - case NTE_SIGNATURE_FILE_BAD : - return "NTE_SIGNATURE_FILE_BAD "; - case NTE_PROVIDER_DLL_FAIL : - return "NTE_PROVIDER_DLL_FAIL "; - case NTE_PROV_DLL_NOT_FOUND : - return "NTE_PROV_DLL_NOT_FOUND "; - case NTE_BAD_KEYSET_PARAM : - return "NTE_BAD_KEYSET_PARAM "; - case NTE_FAIL : - return "NTE_FAIL "; - case NTE_SYS_ERR : - return "NTE_SYS_ERR "; - case CRYPT_E_MSG_ERROR : - return "CRYPT_E_MSG_ERROR "; - case CRYPT_E_UNKNOWN_ALGO : - return "CRYPT_E_UNKNOWN_ALGO "; - case CRYPT_E_OID_FORMAT : - return "CRYPT_E_OID_FORMAT "; - case CRYPT_E_INVALID_MSG_TYPE : - return "CRYPT_E_INVALID_MSG_TYPE "; - case CRYPT_E_UNEXPECTED_ENCODING : - return "CRYPT_E_UNEXPECTED_ENCODING "; - case CRYPT_E_AUTH_ATTR_MISSING : - return "CRYPT_E_AUTH_ATTR_MISSING "; - case CRYPT_E_HASH_VALUE : - return "CRYPT_E_HASH_VALUE "; - case CRYPT_E_INVALID_INDEX : - return "CRYPT_E_INVALID_INDEX "; - case CRYPT_E_ALREADY_DECRYPTED : - return "CRYPT_E_ALREADY_DECRYPTED "; - case CRYPT_E_NOT_DECRYPTED : - return "CRYPT_E_NOT_DECRYPTED "; - case CRYPT_E_RECIPIENT_NOT_FOUND : - return "CRYPT_E_RECIPIENT_NOT_FOUND "; - case CRYPT_E_CONTROL_TYPE : - return "CRYPT_E_CONTROL_TYPE "; - case CRYPT_E_ISSUER_SERIALNUMBER : - return "CRYPT_E_ISSUER_SERIALNUMBER "; - case CRYPT_E_SIGNER_NOT_FOUND : - return "CRYPT_E_SIGNER_NOT_FOUND "; - case CRYPT_E_ATTRIBUTES_MISSING : - return "CRYPT_E_ATTRIBUTES_MISSING "; - case CRYPT_E_STREAM_MSG_NOT_READY : - return "CRYPT_E_STREAM_MSG_NOT_READY "; - case CRYPT_E_STREAM_INSUFFICIENT_DATA : - return "CRYPT_E_STREAM_INSUFFICIENT_DATA "; - case CRYPT_E_BAD_LEN : - return "CRYPT_E_BAD_LEN "; - case CRYPT_E_BAD_ENCODE : - return "CRYPT_E_BAD_ENCODE "; - case CRYPT_E_FILE_ERROR : - return "CRYPT_E_FILE_ERROR "; - case CRYPT_E_NOT_FOUND : - return "CRYPT_E_NOT_FOUND "; - case CRYPT_E_EXISTS : - return "CRYPT_E_EXISTS "; - case CRYPT_E_NO_PROVIDER : - return "CRYPT_E_NO_PROVIDER "; - case CRYPT_E_SELF_SIGNED : - return "CRYPT_E_SELF_SIGNED "; - case CRYPT_E_DELETED_PREV : - return "CRYPT_E_DELETED_PREV "; - case CRYPT_E_NO_MATCH : - return "CRYPT_E_NO_MATCH "; - case CRYPT_E_UNEXPECTED_MSG_TYPE : - return "CRYPT_E_UNEXPECTED_MSG_TYPE "; - case CRYPT_E_NO_KEY_PROPERTY : - return "CRYPT_E_NO_KEY_PROPERTY "; - case CRYPT_E_NO_DECRYPT_CERT : - return "CRYPT_E_NO_DECRYPT_CERT "; - case CRYPT_E_BAD_MSG : - return "CRYPT_E_BAD_MSG "; - case CRYPT_E_NO_SIGNER : - return "CRYPT_E_NO_SIGNER "; - case CRYPT_E_PENDING_CLOSE : - return "CRYPT_E_PENDING_CLOSE "; - case CRYPT_E_REVOKED : - return "CRYPT_E_REVOKED "; - case CRYPT_E_NO_REVOCATION_DLL : - return "CRYPT_E_NO_REVOCATION_DLL "; - case CRYPT_E_NO_REVOCATION_CHECK : - return "CRYPT_E_NO_REVOCATION_CHECK "; - case CRYPT_E_REVOCATION_OFFLINE : - return "CRYPT_E_REVOCATION_OFFLINE "; - case CRYPT_E_NOT_IN_REVOCATION_DATABASE : - return "CRYPT_E_NOT_IN_REVOCATION_DATABASE "; - case CRYPT_E_INVALID_NUMERIC_STRING : - return "CRYPT_E_INVALID_NUMERIC_STRING "; - case CRYPT_E_INVALID_PRINTABLE_STRING : - return "CRYPT_E_INVALID_PRINTABLE_STRING "; - case CRYPT_E_INVALID_IA5_STRING : - return "CRYPT_E_INVALID_IA5_STRING "; - case CRYPT_E_INVALID_X500_STRING : - return "CRYPT_E_INVALID_X500_STRING "; - case CRYPT_E_NOT_CHAR_STRING : - return "CRYPT_E_NOT_CHAR_STRING "; - case CRYPT_E_FILERESIZED : - return "CRYPT_E_FILERESIZED "; - case CRYPT_E_SECURITY_SETTINGS : - return "CRYPT_E_SECURITY_SETTINGS "; - case CRYPT_E_NO_VERIFY_USAGE_DLL : - return "CRYPT_E_NO_VERIFY_USAGE_DLL "; - case CRYPT_E_NO_VERIFY_USAGE_CHECK : - return "CRYPT_E_NO_VERIFY_USAGE_CHECK "; - case CRYPT_E_VERIFY_USAGE_OFFLINE : - return "CRYPT_E_VERIFY_USAGE_OFFLINE "; - case CRYPT_E_NOT_IN_CTL : - return "CRYPT_E_NOT_IN_CTL "; - case CRYPT_E_NO_TRUSTED_SIGNER : - return "CRYPT_E_NO_TRUSTED_SIGNER "; - case CRYPT_E_OSS_ERROR : - return "CRYPT_E_OSS_ERROR "; - case CERTSRV_E_BAD_REQUESTSUBJECT : - return "CERTSRV_E_BAD_REQUESTSUBJECT "; - case CERTSRV_E_NO_REQUEST : - return "CERTSRV_E_NO_REQUEST "; - case CERTSRV_E_BAD_REQUESTSTATUS : - return "CERTSRV_E_BAD_REQUESTSTATUS "; - case CERTSRV_E_PROPERTY_EMPTY : - return "CERTSRV_E_PROPERTY_EMPTY "; - //case CERTDB_E_JET_ERROR : - //return "CERTDB_E_JET_ERROR "; - case TRUST_E_SYSTEM_ERROR : - return "TRUST_E_SYSTEM_ERROR "; - case TRUST_E_NO_SIGNER_CERT : - return "TRUST_E_NO_SIGNER_CERT "; - case TRUST_E_COUNTER_SIGNER : - return "TRUST_E_COUNTER_SIGNER "; - case TRUST_E_CERT_SIGNATURE : - return "TRUST_E_CERT_SIGNATURE "; - case TRUST_E_TIME_STAMP : - return "TRUST_E_TIME_STAMP "; - case TRUST_E_BAD_DIGEST : - return "TRUST_E_BAD_DIGEST "; - case TRUST_E_BASIC_CONSTRAINTS : - return "TRUST_E_BASIC_CONSTRAINTS "; - case TRUST_E_FINANCIAL_CRITERIA : - return "TRUST_E_FINANCIAL_CRITERIA "; - case TRUST_E_PROVIDER_UNKNOWN : - return "TRUST_E_PROVIDER_UNKNOWN "; - case TRUST_E_ACTION_UNKNOWN : - return "TRUST_E_ACTION_UNKNOWN "; - case TRUST_E_SUBJECT_FORM_UNKNOWN : - return "TRUST_E_SUBJECT_FORM_UNKNOWN "; - case TRUST_E_SUBJECT_NOT_TRUSTED : - return "TRUST_E_SUBJECT_NOT_TRUSTED "; - case DIGSIG_E_ENCODE : - return "DIGSIG_E_ENCODE "; - case DIGSIG_E_DECODE : - return "DIGSIG_E_DECODE "; - case DIGSIG_E_EXTENSIBILITY : - return "DIGSIG_E_EXTENSIBILITY "; - case DIGSIG_E_CRYPTO : - return "DIGSIG_E_CRYPTO "; - case PERSIST_E_SIZEDEFINITE : - return "PERSIST_E_SIZEDEFINITE "; - case PERSIST_E_SIZEINDEFINITE : - return "PERSIST_E_SIZEINDEFINITE "; - case PERSIST_E_NOTSELFSIZING : - return "PERSIST_E_NOTSELFSIZING "; - case TRUST_E_NOSIGNATURE : - return "TRUST_E_NOSIGNATURE "; - case CERT_E_EXPIRED : - return "CERT_E_EXPIRED "; - case CERT_E_VALIDITYPERIODNESTING : - return "CERT_E_VALIDITYPERIODNESTING "; - case CERT_E_ROLE : - return "CERT_E_ROLE "; - case CERT_E_PATHLENCONST : - return "CERT_E_PATHLENCONST "; - case CERT_E_CRITICAL : - return "CERT_E_CRITICAL "; - case CERT_E_PURPOSE : - return "CERT_E_PURPOSE "; - case CERT_E_ISSUERCHAINING : - return "CERT_E_ISSUERCHAINING "; - case CERT_E_MALFORMED : - return "CERT_E_MALFORMED "; - case CERT_E_UNTRUSTEDROOT : - return "CERT_E_UNTRUSTEDROOT "; - case CERT_E_CHAINING : - return "CERT_E_CHAINING "; - case TRUST_E_FAIL : - return "TRUST_E_FAIL "; - case CERT_E_REVOKED : - return "CERT_E_REVOKED "; - case CERT_E_UNTRUSTEDTESTROOT : - return "CERT_E_UNTRUSTEDTESTROOT "; - case CERT_E_REVOCATION_FAILURE : - return "CERT_E_REVOCATION_FAILURE "; - case CERT_E_CN_NO_MATCH : - return "CERT_E_CN_NO_MATCH "; - case CERT_E_WRONG_USAGE : - return "CERT_E_WRONG_USAGE "; - case SPAPI_E_EXPECTED_SECTION_NAME : - return "SPAPI_E_EXPECTED_SECTION_NAME "; - case SPAPI_E_BAD_SECTION_NAME_LINE : - return "SPAPI_E_BAD_SECTION_NAME_LINE "; - case SPAPI_E_SECTION_NAME_TOO_LONG : - return "SPAPI_E_SECTION_NAME_TOO_LONG "; - case SPAPI_E_GENERAL_SYNTAX : - return "SPAPI_E_GENERAL_SYNTAX "; - case SPAPI_E_WRONG_INF_STYLE : - return "SPAPI_E_WRONG_INF_STYLE "; - case SPAPI_E_SECTION_NOT_FOUND : - return "SPAPI_E_SECTION_NOT_FOUND "; - case SPAPI_E_LINE_NOT_FOUND : - return "SPAPI_E_LINE_NOT_FOUND "; - case SPAPI_E_NO_ASSOCIATED_CLASS : - return "SPAPI_E_NO_ASSOCIATED_CLASS "; - case SPAPI_E_CLASS_MISMATCH : - return "SPAPI_E_CLASS_MISMATCH "; - case SPAPI_E_DUPLICATE_FOUND : - return "SPAPI_E_DUPLICATE_FOUND "; - case SPAPI_E_NO_DRIVER_SELECTED : - return "SPAPI_E_NO_DRIVER_SELECTED "; - case SPAPI_E_KEY_DOES_NOT_EXIST : - return "SPAPI_E_KEY_DOES_NOT_EXIST "; - case SPAPI_E_INVALID_DEVINST_NAME : - return "SPAPI_E_INVALID_DEVINST_NAME "; - case SPAPI_E_INVALID_CLASS : - return "SPAPI_E_INVALID_CLASS "; - case SPAPI_E_DEVINST_ALREADY_EXISTS : - return "SPAPI_E_DEVINST_ALREADY_EXISTS "; - case SPAPI_E_DEVINFO_NOT_REGISTERED : - return "SPAPI_E_DEVINFO_NOT_REGISTERED "; - case SPAPI_E_INVALID_REG_PROPERTY : - return "SPAPI_E_INVALID_REG_PROPERTY "; - case SPAPI_E_NO_INF : - return "SPAPI_E_NO_INF "; - case SPAPI_E_NO_SUCH_DEVINST : - return "SPAPI_E_NO_SUCH_DEVINST "; - case SPAPI_E_CANT_LOAD_CLASS_ICON : - return "SPAPI_E_CANT_LOAD_CLASS_ICON "; - case SPAPI_E_INVALID_CLASS_INSTALLER : - return "SPAPI_E_INVALID_CLASS_INSTALLER "; - case SPAPI_E_DI_DO_DEFAULT : - return "SPAPI_E_DI_DO_DEFAULT "; - case SPAPI_E_DI_NOFILECOPY : - return "SPAPI_E_DI_NOFILECOPY "; - case SPAPI_E_INVALID_HWPROFILE : - return "SPAPI_E_INVALID_HWPROFILE "; - case SPAPI_E_NO_DEVICE_SELECTED : - return "SPAPI_E_NO_DEVICE_SELECTED "; - case SPAPI_E_DEVINFO_LIST_LOCKED : - return "SPAPI_E_DEVINFO_LIST_LOCKED "; - case SPAPI_E_DEVINFO_DATA_LOCKED : - return "SPAPI_E_DEVINFO_DATA_LOCKED "; - case SPAPI_E_DI_BAD_PATH : - return "SPAPI_E_DI_BAD_PATH "; - case SPAPI_E_NO_CLASSINSTALL_PARAMS : - return "SPAPI_E_NO_CLASSINSTALL_PARAMS "; - case SPAPI_E_FILEQUEUE_LOCKED : - return "SPAPI_E_FILEQUEUE_LOCKED "; - case SPAPI_E_BAD_SERVICE_INSTALLSECT : - return "SPAPI_E_BAD_SERVICE_INSTALLSECT "; - case SPAPI_E_NO_CLASS_DRIVER_LIST : - return "SPAPI_E_NO_CLASS_DRIVER_LIST "; - case SPAPI_E_NO_ASSOCIATED_SERVICE : - return "SPAPI_E_NO_ASSOCIATED_SERVICE "; - case SPAPI_E_NO_DEFAULT_DEVICE_INTERFACE : - return "SPAPI_E_NO_DEFAULT_DEVICE_INTERFACE "; - case SPAPI_E_DEVICE_INTERFACE_ACTIVE : - return "SPAPI_E_DEVICE_INTERFACE_ACTIVE "; - case SPAPI_E_DEVICE_INTERFACE_REMOVED : - return "SPAPI_E_DEVICE_INTERFACE_REMOVED "; - case SPAPI_E_BAD_INTERFACE_INSTALLSECT : - return "SPAPI_E_BAD_INTERFACE_INSTALLSECT "; - case SPAPI_E_NO_SUCH_INTERFACE_CLASS : - return "SPAPI_E_NO_SUCH_INTERFACE_CLASS "; - case SPAPI_E_INVALID_REFERENCE_STRING : - return "SPAPI_E_INVALID_REFERENCE_STRING "; - case SPAPI_E_INVALID_MACHINENAME : - return "SPAPI_E_INVALID_MACHINENAME "; - case SPAPI_E_REMOTE_COMM_FAILURE : - return "SPAPI_E_REMOTE_COMM_FAILURE "; - case SPAPI_E_MACHINE_UNAVAILABLE : - return "SPAPI_E_MACHINE_UNAVAILABLE "; - case SPAPI_E_NO_CONFIGMGR_SERVICES : - return "SPAPI_E_NO_CONFIGMGR_SERVICES "; - case SPAPI_E_INVALID_PROPPAGE_PROVIDER : - return "SPAPI_E_INVALID_PROPPAGE_PROVIDER "; - case SPAPI_E_NO_SUCH_DEVICE_INTERFACE : - return "SPAPI_E_NO_SUCH_DEVICE_INTERFACE "; - case SPAPI_E_DI_POSTPROCESSING_REQUIRED : - return "SPAPI_E_DI_POSTPROCESSING_REQUIRED "; - case SPAPI_E_INVALID_COINSTALLER : - return "SPAPI_E_INVALID_COINSTALLER "; - case SPAPI_E_NO_COMPAT_DRIVERS : - return "SPAPI_E_NO_COMPAT_DRIVERS "; - case SPAPI_E_NO_DEVICE_ICON : - return "SPAPI_E_NO_DEVICE_ICON "; - case SPAPI_E_INVALID_INF_LOGCONFIG : - return "SPAPI_E_INVALID_INF_LOGCONFIG "; - case SPAPI_E_DI_DONT_INSTALL : - return "SPAPI_E_DI_DONT_INSTALL "; - case SPAPI_E_INVALID_FILTER_DRIVER : - return "SPAPI_E_INVALID_FILTER_DRIVER "; - case SPAPI_E_ERROR_NOT_INSTALLED : - return "SPAPI_E_ERROR_NOT_INSTALLED "; - - default: - static char buff[1000]; - sprintf(buff, "Unrecognized error value: %08X\0", error); - - return buff; - } -} diff --git a/panda/src/dxgsg7/dxgsg7base.h b/panda/src/dxgsg7/dxgsg7base.h deleted file mode 100644 index fe1a997ee8..0000000000 --- a/panda/src/dxgsg7/dxgsg7base.h +++ /dev/null @@ -1,129 +0,0 @@ -// Filename: dxTextureContext7.h -// Created by: drose (07Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DXGSGBASE_H -#define DXGSGBASE_H - -#include "pandabase.h" - -#define WIN32_LEAN_AND_MEAN // get rid of mfc win32 hdr stuff -#ifndef STRICT -// enable strict type checking in windows.h, see msdn -#define STRICT -#endif - -#include -#include - -#define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h -#include -#undef WIN32_LEAN_AND_MEAN - -#if DIRECT3D_VERSION != 0x0700 -#error DX7 headers not available, you need to install MS Platform SDK or DirectX 8+ SDK! -#endif - -#define D3DERRORSTRING(HRESULT) " at (" << __FILE__ << ":" << __LINE__ << "), hr=" << ConvD3DErrorToString(HRESULT) << endl - -// disable nameless struct 'warning' -#pragma warning (disable : 4201) - -#define MAX_DX_TEXPIXFMTS 20 // should be enough for any card - -#define ISPOW2(X) (((X) & ((X)-1))==0) - -#define DX_DECLARE_CLEAN(type, var) \ - type var; \ - ZeroMemory(&var, sizeof(type)); \ - var.dwSize = sizeof(type); - -#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } -#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } } -#define SAFE_FREELIB(hDLL) { if(hDLL!=NULL) { FreeLibrary(hDLL); hDLL = NULL; } } -#define IS_VALID_PTR(PTR) (!IsBadWritePtr(PTR,sizeof(void*))) - -// this is bDoDownToZero argument to RELEASE() -#define RELEASE_DOWN_TO_ZERO true -#define RELEASE_ONCE false - -#define DEBUG_RELEASES - -#ifdef DEBUG_RELEASES -#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) { \ - ULONG refcnt; \ - if(((OBJECT)!=NULL)&&(!IsBadWritePtr((OBJECT),4))) { \ - refcnt = (OBJECT)->Release(); \ - MODULE##_cat.debug() << DBGSTR << " released, refcnt = " << refcnt << endl; \ - if((bDoDownToZero) && (refcnt>0)) { \ - MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \ - do { \ - refcnt = (OBJECT)->Release(); \ - } while(refcnt>0); \ - } \ - (OBJECT) = NULL; \ - } else { \ - MODULE##_cat.debug() << DBGSTR << " not released, ptr == NULL" << endl; \ - } } - -#define PRINTREFCNT(OBJECT,STR) { (OBJECT)->AddRef(); dxgsg7_cat.debug() << STR << " refcnt = " << (OBJECT)->Release() << endl; } -#else -#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) { \ - ULONG refcnt; \ - if(((OBJECT)!=NULL)&&(!IsBadWritePtr((OBJECT),4))) { \ - refcnt=(OBJECT)->Release(); \ - if((bDoDownToZero) && (refcnt>0)) { \ - MODULE##_cat.warning() << DBGSTR << " released but still has a non-zero refcnt(" << refcnt << "), multi-releasing it down to zero!\n"; \ - do { \ - refcnt = (OBJECT)->Release(); \ - } while(refcnt>0); \ - } \ - (OBJECT) = NULL; \ - } } - -#define PRINTREFCNT(OBJECT,STR) -#endif - -#ifdef DO_PSTATS -#define DO_PSTATS_STUFF(XX) XX; -#else -#define DO_PSTATS_STUFF(XX) -#endif - -const char *ConvD3DErrorToString(HRESULT error); - -typedef struct { - LPDIRECT3DDEVICE7 pD3DDevice; - LPDIRECTDRAW7 pDD; - LPDIRECT3D7 pD3D; - LPDIRECTDRAWSURFACE7 pddsPrimary,pddsBack,pddsZBuf; - HWND hWnd; - HMONITOR hMon; - DWORD dwRenderWidth,dwRenderHeight,dwFullScreenBitDepth; - RECT view_rect,clip_rect; - DWORD MaxAvailVidMem; - bool bIsLowVidMemCard; - bool bIsTNLDevice; - bool bIsSWRast; - bool bIsFullScreen; - WORD depth_buffer_bitdepth; //GetSurfaceDesc is not reliable so must store this explicitly - WORD CardIDNum; // its posn in DisplayArray, for dbgprint purposes - DDDEVICEIDENTIFIER2 DXDeviceID; - D3DDEVICEDESC7 D3DDevDesc; -} DXScreenData; -#endif - diff --git a/panda/src/dxgsg7/wdxGraphicsPipe7.I b/panda/src/dxgsg7/wdxGraphicsPipe7.I deleted file mode 100644 index cc598fd57a..0000000000 --- a/panda/src/dxgsg7/wdxGraphicsPipe7.I +++ /dev/null @@ -1,17 +0,0 @@ -// Filename: wdxGraphicsPipe7.I -// Created by: drose (20Dec02) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// diff --git a/panda/src/dxgsg7/wdxGraphicsPipe7.cxx b/panda/src/dxgsg7/wdxGraphicsPipe7.cxx deleted file mode 100644 index 0c37c165e6..0000000000 --- a/panda/src/dxgsg7/wdxGraphicsPipe7.cxx +++ /dev/null @@ -1,126 +0,0 @@ -// Filename: wdxGraphicsPipe7.cxx -// Created by: drose (20Dec02) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#include "wdxGraphicsPipe7.h" -#include "wdxGraphicsWindow7.h" -#include "config_dxgsg7.h" - -TypeHandle wdxGraphicsPipe7::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsPipe7::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -wdxGraphicsPipe7:: -wdxGraphicsPipe7() { - _hDDrawDLL = NULL; - _is_valid = init(); -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsPipe7::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -wdxGraphicsPipe7:: -~wdxGraphicsPipe7() { - SAFE_FREELIB(_hDDrawDLL); -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsPipe7::get_interface_name -// Access: Published, Virtual -// Description: Returns the name of the rendering interface -// associated with this GraphicsPipe. This is used to -// present to the user to allow him/her to choose -// between several possible GraphicsPipes available on a -// particular platform, so the name should be meaningful -// and unique for a given platform. -//////////////////////////////////////////////////////////////////// -string wdxGraphicsPipe7:: -get_interface_name() const { - return "DirectX7"; -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsPipe7::pipe_constructor -// Access: Public, Static -// Description: This function is passed to the GraphicsPipeSelection -// object to allow the user to make a default -// wdxGraphicsPipe7. -//////////////////////////////////////////////////////////////////// -PT(GraphicsPipe) wdxGraphicsPipe7:: -pipe_constructor() { - return new wdxGraphicsPipe7; -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsPipe7::make_window -// Access: Protected, Virtual -// Description: Creates a new window on the pipe, if possible. -//////////////////////////////////////////////////////////////////// -PT(GraphicsWindow) wdxGraphicsPipe7:: -make_window(GraphicsStateGuardian *gsg, const string &name) { - // thanks to the dumb threading requirements this constructor actually does nothing but create an empty c++ object - // no windows are really opened until wdxGraphicsWindow8->open_window() is called - - return new wdxGraphicsWindow7(this, gsg, name); -} - - -PT(GraphicsStateGuardian) wdxGraphicsPipe7:: -make_gsg(const FrameBufferProperties &properties, - GraphicsStateGuardian *share_with) { - if (share_with != (GraphicsStateGuardian *)NULL) { - wdxdisplay7_cat.error() - << "wdxGraphicsPipe7 does not presently support sharing texture contexts.\n"; - return NULL; - } - - // FrameBufferProperties really belongs as part of the window/renderbuffer specification - // put here because of GLX multithreading requirement - PT(DXGraphicsStateGuardian7) gsg = new DXGraphicsStateGuardian7(properties); - return gsg.p(); -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsPipe7::init -// Access: Private -// Description: Performs some initialization steps to load up -// function pointers from the relevant DLL's, and -// determine the number and type of available graphics -// adapters, etc. Returns true on success, false on -// failure. -//////////////////////////////////////////////////////////////////// -bool wdxGraphicsPipe7:: -init() { - - if(!MyLoadLib(_hDDrawDLL,"ddraw.dll")) { - goto error; - } - - if(!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawCreateEx, "DirectDrawCreateEx")) { - goto error; - } - - return true; - -error: - return false; -} diff --git a/panda/src/dxgsg7/wdxGraphicsPipe7.h b/panda/src/dxgsg7/wdxGraphicsPipe7.h deleted file mode 100644 index dac6835cd2..0000000000 --- a/panda/src/dxgsg7/wdxGraphicsPipe7.h +++ /dev/null @@ -1,75 +0,0 @@ -// Filename: wdxGraphicsPipe7.h -// Created by: drose (20Dec02) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#ifndef WDXGRAPHICSPIPE7_H -#define WDXGRAPHICSPIPE7_H - -#include "pandabase.h" -#include "winGraphicsPipe.h" - -//////////////////////////////////////////////////////////////////// -// Class : wdxGraphicsPipe7 -// Description : This graphics pipe represents the interface for -// creating DirectX graphics windows. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDADX wdxGraphicsPipe7 : public WinGraphicsPipe { -public: - wdxGraphicsPipe7(); - virtual ~wdxGraphicsPipe7(); - - virtual string get_interface_name() const; - static PT(GraphicsPipe) pipe_constructor(); - virtual PT(GraphicsStateGuardian) make_gsg(const FrameBufferProperties &properties, - GraphicsStateGuardian *share_with); - -protected: - virtual PT(GraphicsWindow) make_window(GraphicsStateGuardian *gsg, const string &name); - -private: - bool init(); - -private: - HINSTANCE _hDDrawDLL; - - typedef HRESULT (WINAPI * LPDIRECTDRAWCREATEEX)(GUID FAR * lpGuid, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter); - LPDIRECTDRAWCREATEEX _DirectDrawCreateEx; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - WinGraphicsPipe::init_type(); - register_type(_type_handle, "wdxGraphicsPipe7", - WinGraphicsPipe::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - - -private: - static TypeHandle _type_handle; - - friend class wdxGraphicsWindow7; -}; - -#include "wdxGraphicsPipe7.I" - -#endif diff --git a/panda/src/dxgsg7/wdxGraphicsWindow7.I b/panda/src/dxgsg7/wdxGraphicsWindow7.I deleted file mode 100644 index 27bc051586..0000000000 --- a/panda/src/dxgsg7/wdxGraphicsWindow7.I +++ /dev/null @@ -1,17 +0,0 @@ -// Filename: wdxGraphicsWindow7.I -// Created by: drose (20Dec02) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// diff --git a/panda/src/dxgsg7/wdxGraphicsWindow7.cxx b/panda/src/dxgsg7/wdxGraphicsWindow7.cxx deleted file mode 100644 index 7a45ba9067..0000000000 --- a/panda/src/dxgsg7/wdxGraphicsWindow7.cxx +++ /dev/null @@ -1,1330 +0,0 @@ -// Filename: wdxGraphicsWindow7.cxx -// Created by: drose (20Dec02) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#include "wdxGraphicsWindow7.h" -#include "config_dxgsg7.h" -#include "config_windisplay.h" -#include "wdxGraphicsPipe7.h" -#include "dxGraphicsStateGuardian7.h" -#include "pStatTimer.h" - -#include - -static DWORD -BitDepth_2_DDBDMask(DWORD iBitDepth) { - switch (iBitDepth) { - case 16: return DDBD_16; - case 32: return DDBD_32; - case 24: return DDBD_24; - case 8: return DDBD_8; - case 1: return DDBD_1; - case 2: return DDBD_2; - case 4: return DDBD_4; - } - return 0x0; -} - -#define MAX_DX_ZBUF_FMTS 20 -static int cNumZBufFmts; - -HRESULT CALLBACK -EnumZBufFmtsCallback(LPDDPIXELFORMAT pddpf, VOID *param) { - DDPIXELFORMAT *ZBufFmtsArr = (DDPIXELFORMAT *) param; - assert(cNumZBufFmts < MAX_DX_ZBUF_FMTS); - memcpy(&(ZBufFmtsArr[cNumZBufFmts]), pddpf, sizeof(DDPIXELFORMAT)); - cNumZBufFmts++; - return DDENUMRET_OK; -} - -HRESULT CALLBACK -EnumDevicesCallback(LPSTR pDeviceDescription, LPSTR pDeviceName, - LPD3DDEVICEDESC7 pD3DDeviceDesc,LPVOID pContext) { - D3DDEVICEDESC7 *pd3ddevs = (D3DDEVICEDESC7 *)pContext; -#ifdef _DEBUG - wdxdisplay7_cat.spam() - << "Enumerating Device " << pDeviceName << " : " - << pDeviceDescription << endl; -#endif - -#define REGHALIDX 0 -#define TNLHALIDX 1 -#define SWRASTIDX 2 - - if (IsEqualGUID(pD3DDeviceDesc->deviceGUID, IID_IDirect3DHALDevice)) { - CopyMemory(&pd3ddevs[REGHALIDX], pD3DDeviceDesc, sizeof(D3DDEVICEDESC7)); - } else if (IsEqualGUID(pD3DDeviceDesc->deviceGUID, IID_IDirect3DTnLHalDevice)) { - CopyMemory(&pd3ddevs[TNLHALIDX], pD3DDeviceDesc, sizeof(D3DDEVICEDESC7)); - } else if(IsEqualGUID(pD3DDeviceDesc->deviceGUID, IID_IDirect3DRGBDevice)) { - CopyMemory(&pd3ddevs[SWRASTIDX], pD3DDeviceDesc, sizeof(D3DDEVICEDESC7)); - } - return DDENUMRET_OK; -} - -#define MAX_DISPLAY_MODES 100 // probably dont need this much, since i already screen for width&hgt -typedef struct { - DWORD maxWidth,maxHeight; - DWORD supportedBitDepths; // uses DDBD_* flags - LPDDSURFACEDESC2 pDDSD_Arr; - DWORD cNumSurfDescs; -} DisplayModeInfo; - -HRESULT WINAPI -EnumDisplayModesCallBack(LPDDSURFACEDESC2 lpDDSurfaceDesc,LPVOID lpContext) { - DisplayModeInfo *pDMI = (DisplayModeInfo *) lpContext; - - // ddsd_search should assure this is true - assert((lpDDSurfaceDesc->dwWidth == pDMI->maxWidth) && (lpDDSurfaceDesc->dwHeight == pDMI->maxHeight)); - - // ignore refresh rates under 60Hz (and special values of 0 & 1) - if ((lpDDSurfaceDesc->dwRefreshRate > 1) && - (lpDDSurfaceDesc->dwRefreshRate < 60)) { - return DDENUMRET_OK; - } - - assert(pDMI->cNumSurfDescs < MAX_DISPLAY_MODES); - memcpy(&(pDMI->pDDSD_Arr[pDMI->cNumSurfDescs]), lpDDSurfaceDesc, sizeof(DDSURFACEDESC2)); - pDMI->cNumSurfDescs++; - pDMI->supportedBitDepths |= BitDepth_2_DDBDMask(lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount); - - return DDENUMRET_OK; -} - -// imperfect method to ID NVid? could also scan desc str, but that isnt fullproof either -#define IS_NVIDIA(DDDEVICEID) ((DDDEVICEID.dwVendorId==0x10DE) || (DDDEVICEID.dwVendorId==0x12D2)) -#define IS_ATI(DDDEVICEID) (DDDEVICEID.dwVendorId==0x1002) -#define IS_MATROX(DDDEVICEID) (DDDEVICEID.dwVendorId==0x102B) - -TypeHandle wdxGraphicsWindow7::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -wdxGraphicsWindow7:: -wdxGraphicsWindow7(GraphicsPipe *pipe, GraphicsStateGuardian *gsg, - const string &name) : - WinGraphicsWindow(pipe, gsg, name) -{ - _dxgsg = DCAST(DXGraphicsStateGuardian7, gsg); - ZeroMemory(&_wcontext,sizeof(_wcontext)); -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -wdxGraphicsWindow7:: -~wdxGraphicsWindow7() { -} - -void wdxGraphicsWindow7:: -make_current() { - PStatTimer timer(_make_current_pcollector); - - DXGraphicsStateGuardian7 *dxgsg; - DCAST_INTO_V(dxgsg, _gsg); - //wglMakeCurrent(_hdc, wdxgsg->_context); - dxgsg->set_context(&_wcontext); - - // Now that we have made the context current to a window, we can - // reset the GSG state if this is the first time it has been used. - // (We can't just call reset() when we construct the GSG, because - // reset() requires having a current context.) - dxgsg->reset_if_new(); -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::open_window -// Access: Protected, Virtual -// Description: Opens the window right now. Called from the window -// thread. Returns true if the window is successfully -// opened, or false if there was a problem. -//////////////////////////////////////////////////////////////////// -bool wdxGraphicsWindow7:: -open_window() { - - if (!choose_device(0, NULL)) { - wdxdisplay7_cat.error() << "Unable to find suitable rendering device.\n"; - return false; - } - - if (!WinGraphicsWindow::open_window()) { - return false; - } - - _wcontext.hWnd = _hWnd; - wdxdisplay7_cat.debug() << "hWnd = " << _hWnd << "\n"; - set_coop_levels_and_display_modes(); - create_screen_buffers_and_device(_wcontext, dx_force_16bpp_zbuffer); - - make_current(); - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::end_flip -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// after begin_flip() has been called on all windows, to -// finish the exchange of the front and back buffers. -// -// This should cause the window to wait for the flip, if -// necessary. -//////////////////////////////////////////////////////////////////// -void wdxGraphicsWindow7:: -end_flip() { - if (_dxgsg != (DXGraphicsStateGuardian7 *)NULL && is_active()) { - _dxgsg->show_frame(); - } - GraphicsWindow::end_flip(); -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::fullscreen_restored -// Access: Protected, Virtual -// Description: This is a hook for derived classes to do something -// special, if necessary, when a fullscreen window has -// been restored after being minimized. The given -// WindowProperties struct will be applied to this -// window's properties after this function returns. -//////////////////////////////////////////////////////////////////// -void wdxGraphicsWindow7:: -fullscreen_restored(WindowProperties &properties) { - // For some reason, this message comes in twice, once while the - // fullscreen window is still minimized, and once again when it has - // been restored. - - // In DX7, it seems to be necessary to render one frame between the - // two cases, so we must set the minimized property to false even in - // the first case. - properties.set_minimized(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::handle_reshape -// Access: Protected, Virtual -// Description: Called in the window thread when the window size or -// location is changed, this updates the properties -// structure accordingly. -//////////////////////////////////////////////////////////////////// -void wdxGraphicsWindow7:: -handle_reshape() { - GdiFlush(); - WinGraphicsWindow::handle_reshape(); - - if (_dxgsg!=NULL) { - HRESULT hr; - - if (_wcontext.pddsBack == NULL) { - // assume this is initial creation reshape and ignore this call - return; - } - - // Clear the back/primary surface to black using ddraw - DX_DECLARE_CLEAN(DDBLTFX, bltfx); - bltfx.dwDDFX |= DDBLTFX_NOTEARING; - hr = _wcontext.pddsPrimary->Blt - (NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "Blt to Black of Primary Surf failed! : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - hr = _wcontext.pDD->TestCooperativeLevel(); - if (FAILED(hr)) { - wdxdisplay7_cat.error() - << "TestCooperativeLevel failed : result = " - << ConvD3DErrorToString(hr) << endl; - return; - } - - _dxgsg->release_all(); - - set_to_temp_rendertarget(); - - RECT view_rect; - get_client_rect_screen(_wcontext.hWnd, &view_rect); - // _dxgsg->dx_setup_after_resize(&view_rect); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::do_fullscreen_resize -// Access: Protected, Virtual -// Description: Called in the window thread to resize a fullscreen -// window. -//////////////////////////////////////////////////////////////////// -bool wdxGraphicsWindow7:: -do_fullscreen_resize(int x_size, int y_size) { - // _dxgsg->SetDXReady(false); - - HRESULT hr; - - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_curmode); - - hr = _wcontext.pDD->GetDisplayMode(&ddsd_curmode); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "resize() - GetDisplayMode failed, result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd_search); - - ddsd_search.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; - ddsd_search.dwWidth=x_size; - ddsd_search.dwHeight=y_size; - - // not requesting same refresh rate since changing res might not - // support same refresh rate - - DDSURFACEDESC2 DDSD_Arr[MAX_DISPLAY_MODES]; - DisplayModeInfo DMI; - ZeroMemory(&DDSD_Arr,sizeof(DDSD_Arr)); - ZeroMemory(&DMI,sizeof(DMI)); - DMI.maxWidth = x_size; - DMI.maxHeight = y_size; - DMI.pDDSD_Arr = DDSD_Arr; - - hr = _wcontext.pDD->EnumDisplayModes(DDEDM_REFRESHRATES, &ddsd_search, - &DMI, EnumDisplayModesCallBack); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "resize() - EnumDisplayModes failed, result = " - << ConvD3DErrorToString(hr) << endl; - return false; - } - - DMI.supportedBitDepths &= _wcontext.D3DDevDesc.dwDeviceRenderBitDepth; - - DWORD dwFullScreenBitDepth; - DWORD requested_bpp = ddsd_curmode.ddpfPixelFormat.dwRGBBitCount; - - // would like to match current bpp first. if that is not possible, - // try 16bpp, then 32 - DWORD requested_bpp_DDBD = BitDepth_2_DDBDMask(requested_bpp); - - if (DMI.supportedBitDepths & requested_bpp_DDBD) { - dwFullScreenBitDepth = requested_bpp; - } else if (DMI.supportedBitDepths & DDBD_16) { - dwFullScreenBitDepth = 16; - } else if (DMI.supportedBitDepths & DDBD_32) { - dwFullScreenBitDepth = 32; - } else { - wdxdisplay7_cat.error() - << "resize failed, no fullScreen resolutions at " << x_size - << "x" << y_size << endl; - return false; - } - - hr = _wcontext.pDD->TestCooperativeLevel(); - if (FAILED(hr)) { - wdxdisplay7_cat.error() - << "TestCooperativeLevel failed : result = " - << ConvD3DErrorToString(hr) << endl; - wdxdisplay7_cat.error() - << "Full screen app failed to get exclusive mode on resize, exiting..\n"; - return false; - } - - // _dxgsg->free_dxgsg_objects(); - - // let driver choose default refresh rate (hopefully its >=60Hz) - hr = _wcontext.pDD->SetDisplayMode(x_size, y_size, dwFullScreenBitDepth, - 0L, 0L); - if (FAILED(hr)) { - wdxdisplay7_cat.error() - << "resize failed to reset display mode to (" - << x_size << "x" << y_size << "x" - << dwFullScreenBitDepth << "): result = " - << ConvD3DErrorToString(hr) << endl; - } - - if (wdxdisplay7_cat.is_debug()) { - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd34); - _wcontext.pDD->GetDisplayMode(&ddsd34); - wdxdisplay7_cat.debug() - << "set displaymode to " << ddsd34.dwWidth << "x" << ddsd34.dwHeight - << " at "<< ddsd34.ddpfPixelFormat.dwRGBBitCount << "bpp, " - << ddsd34.dwRefreshRate << "Hz\n"; - } - - _wcontext.dwRenderWidth = x_size; - _wcontext.dwRenderHeight = y_size; - - create_screen_buffers_and_device(_wcontext, dx_force_16bpp_zbuffer); - _dxgsg->release_all(); - // _dxgsg->SetDXReady(true); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::set_to_temp_rendertarget -// Access: Private -// Description: Constructs a temporary tiny render target for the d3d -// device (and sets the d3d device to use it). This is -// called by handle_reshape() just before the full-sized -// rendertargets are constructed, in order to save video -// memory and thereby allow resizing of the window to -// work on 4MB cards. -//////////////////////////////////////////////////////////////////// -bool wdxGraphicsWindow7:: -set_to_temp_rendertarget() { - return true; - - LPDIRECTDRAWSURFACE7 pddsDummy = NULL, pddsDummyZ = NULL; - HRESULT hr; - - DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd); - - _wcontext.pddsBack->GetSurfaceDesc(&ddsd); - LPDIRECTDRAW7 pDD = _wcontext.pDD; - - ddsd.dwFlags &= ~DDSD_PITCH; - ddsd.dwWidth = 1; - ddsd.dwHeight = 1; - ddsd.ddsCaps.dwCaps &= ~(DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER); - - hr = pDD->CreateSurface(&ddsd, &pddsDummy, NULL); - if (FAILED(hr)) { - wdxdisplay7_cat.error() - << "Resize CreateSurface for temp backbuf failed : result = " - << ConvD3DErrorToString(hr) << endl; - return false; - } - - if (_wcontext.pddsZBuf != NULL) { - DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsdZ); - _wcontext.pddsZBuf->GetSurfaceDesc(&ddsdZ); - ddsdZ.dwFlags &= ~DDSD_PITCH; - ddsdZ.dwWidth = 1; - ddsdZ.dwHeight = 1; - - hr = pDD->CreateSurface(&ddsdZ, &pddsDummyZ, NULL); - if (FAILED(hr)) { - wdxdisplay7_cat.error() - << "Resize CreateSurface for temp zbuf failed : result = " - << ConvD3DErrorToString(hr) << endl; - return false; - } - - hr = pddsDummy->AddAttachedSurface(pddsDummyZ); - if (FAILED(hr)) { - wdxdisplay7_cat.error() - << "Resize AddAttachedSurf for temp zbuf failed : result = " - << ConvD3DErrorToString(hr) << endl; - return false; - } - } - - hr = _wcontext.pD3DDevice->SetRenderTarget(pddsDummy, 0x0); - if (FAILED(hr)) { - wdxdisplay7_cat.error() - << "Resize failed to set render target to temporary surface, result = " - << ConvD3DErrorToString(hr) << endl; - return false; - } - - RELEASE(pddsDummyZ, wdxdisplay7, "dummy resize zbuffer", false); - RELEASE(pddsDummy, wdxdisplay7, "dummy resize rendertarget buffer", false); - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::create_screen_buffers_and_device -// Access: Private -// Description: Called whenever the window is resized, this recreates -// the necessary buffers for rendering. -//////////////////////////////////////////////////////////////////// -void wdxGraphicsWindow7:: -create_screen_buffers_and_device(DXScreenData &Display, bool force_16bpp_zbuffer) { - DWORD dwRenderWidth=Display.dwRenderWidth; - DWORD dwRenderHeight=Display.dwRenderHeight; - LPDIRECT3D7 pD3DI=Display.pD3D; - LPDIRECTDRAW7 pDD=Display.pDD; - D3DDEVICEDESC7 *pD3DDevDesc=&Display.D3DDevDesc; - - LPDIRECTDRAWSURFACE7 pPrimaryDDSurf,pBackDDSurf,pZDDSurf; - LPDIRECT3DDEVICE7 pD3DDevice; - RECT view_rect; - int i; - HRESULT hr; - DX_DECLARE_CLEAN(DDSURFACEDESC2, SurfaceDesc); - - assert(pDD!=NULL); - assert(pD3DI!=NULL); - - DX_DECLARE_CLEAN(DDCAPS, DDCaps); - pDD->GetCaps(&DDCaps, NULL); - - // if window is not foreground in exclusive mode, ddraw thinks you - // are 'not active', so it changes your WM_ACTIVATEAPP from true to - // false, causing us to go into a 'wait-for WM_ACTIVATEAPP true' - // loop, and the event never comes so we hang in fullscreen wait. - SetForegroundWindow(Display.hWnd); - - if (is_fullscreen()) { - // Setup to create the primary surface w/backbuffer - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd); - ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT; - ddsd.ddsCaps.dwCaps = - DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | - DDSCAPS_FLIP | DDSCAPS_COMPLEX; - ddsd.dwBackBufferCount = 1; - Display.bIsFullScreen=true; - - if (dx_full_screen_antialiasing) { - // cant check that d3ddevice has this capability yet, so got to - // set it anyway. hope this is OK. - ddsd.ddsCaps.dwCaps2 |= DDSCAPS2_HINTANTIALIASING; - } - - // Create the primary surface for the fullscreen window - hr = pDD->CreateSurface(&ddsd, &pPrimaryDDSurf, NULL); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "CreateSurface failed for primary surface: result = " - << ConvD3DErrorToString(hr) << endl; - - if (((hr == DDERR_OUTOFVIDEOMEMORY)||(hr == DDERR_OUTOFMEMORY)) && - (Display.dwFullScreenBitDepth > 16)) { - // emergency fallback to 16bpp (shouldnt have to do this - // unless GetAvailVidMem lied) will this work for multimon? - // what if surfs are already created on 1st mon? - Display.dwFullScreenBitDepth=16; - - wdxdisplay7_cat.info() - << "GetAvailVidMem lied, not enough VidMem for 32bpp, so trying 16bpp on device #" - << Display.CardIDNum << endl; - - hr = pDD->SetDisplayMode(Display.dwRenderWidth, - Display.dwRenderHeight, - Display.dwFullScreenBitDepth, 0, 0); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "SetDisplayMode failed to set (" - << Display.dwRenderWidth << "x" << Display.dwRenderHeight - << "x" << Display.dwFullScreenBitDepth << ") on device #" - << Display.CardIDNum << ": result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - create_screen_buffers_and_device(Display, true); - return; - } else { - exit(1); - } - } - - // Clear the primary surface to black - DX_DECLARE_CLEAN(DDBLTFX, bltfx); - bltfx.dwDDFX |= DDBLTFX_NOTEARING; - hr = pPrimaryDDSurf->Blt(NULL, NULL, NULL, - DDBLT_COLORFILL | DDBLT_WAIT, &bltfx); - - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "Blt to Black of Primary Surf failed! : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - // Get the backbuffer, which was created along with the primary. - DDSCAPS2 ddscaps = { - DDSCAPS_BACKBUFFER, 0, 0, 0 - }; - hr = pPrimaryDDSurf->GetAttachedSurface(&ddscaps, &pBackDDSurf); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "Can't get the backbuffer: result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - hr = pBackDDSurf->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&bltfx); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "Blt to Black of Back Surf failed! : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - SetRect(&view_rect, 0, 0, dwRenderWidth, dwRenderHeight); - // end create full screen buffers - - } else { // CREATE WINDOWED BUFFERS - if (!(DDCaps.dwCaps2 & DDCAPS2_CANRENDERWINDOWED)) { - wdxdisplay7_cat.fatal() - << "the 3D HW cannot render windowed, exiting..." << endl; - exit(1); - } - - hr = pDD->GetDisplayMode(&SurfaceDesc); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "GetDisplayMode failed result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - if (SurfaceDesc.ddpfPixelFormat.dwRGBBitCount <= 8) { - wdxdisplay7_cat.fatal() - << "Can't run windowed in an 8-bit or less display mode" << endl; - exit(1); - } - - if (!(BitDepth_2_DDBDMask(SurfaceDesc.ddpfPixelFormat.dwRGBBitCount) & pD3DDevDesc->dwDeviceRenderBitDepth)) { - wdxdisplay7_cat.fatal() - << "3D Device doesnt support rendering at " - << SurfaceDesc.ddpfPixelFormat.dwRGBBitCount - << "bpp (current desktop bitdepth)" << endl; - exit(1); - } - - // Get the dimensions of the viewport and screen bounds - get_client_rect_screen(Display.hWnd, &view_rect); - - dwRenderWidth = view_rect.right - view_rect.left; - dwRenderHeight = view_rect.bottom - view_rect.top; - - // _properties should reflect view rectangle - WindowProperties properties; - properties.set_origin(view_rect.left, view_rect.top); - properties.set_size(dwRenderWidth, dwRenderHeight); - system_changed_properties(properties); - - // Initialize the description of the primary surface - ZeroMemory(&SurfaceDesc, sizeof(DDSURFACEDESC2)); - SurfaceDesc.dwSize = sizeof(DDSURFACEDESC2); - SurfaceDesc.dwFlags = DDSD_CAPS ; - SurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - // Create the primary surface for windowed mode. This includes - // all of the visible window, so no need to specify height/width. - hr = pDD->CreateSurface(&SurfaceDesc, &pPrimaryDDSurf, NULL); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "CreateSurface failed for primary surface: result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - // Create a clipper object which handles all our clipping for - // cases when our window is partially obscured by other windows. - LPDIRECTDRAWCLIPPER Clipper; - hr = pDD->CreateClipper(0, &Clipper, NULL); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "CreateClipper failed : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - // Associate the clipper with our window. Note that, afterwards, - // the clipper is internally referenced by the primary surface, so - // it is safe to release our local reference to it. - Clipper->SetHWnd(0, Display.hWnd); - pPrimaryDDSurf->SetClipper(Clipper); - Clipper->Release(); - - // Clear the primary surface to black - DX_DECLARE_CLEAN(DDBLTFX, bltfx); - - hr = pPrimaryDDSurf->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&bltfx); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "Blt to Black of Primary Surf failed! : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - // Set up a surface description to create a backbuffer. - SurfaceDesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; - SurfaceDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY; - SurfaceDesc.dwWidth = dwRenderWidth; - SurfaceDesc.dwHeight = dwRenderHeight; - - if (dx_full_screen_antialiasing) { - // cant check that d3ddevice has this capability yet, so got to - // set it anyway. hope this is OK. - SurfaceDesc.ddsCaps.dwCaps2 |= DDSCAPS2_HINTANTIALIASING; - } - - // Create the backbuffer. (might want to handle failure due to - // running out of video memory) - hr = pDD->CreateSurface(&SurfaceDesc, &pBackDDSurf, NULL); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "CreateSurface failed for backbuffer : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - hr = pBackDDSurf->Blt(NULL,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&bltfx); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "Blt to Black of Back Surf failed! : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - } // end create windowed buffers - - // ======================================================== - - // resized(dwRenderWidth, dwRenderHeight); // update panda channel/display rgn info - - int frame_buffer_mode = _gsg->get_properties().get_frame_buffer_mode(); - -#ifndef NDEBUG - if ((frame_buffer_mode & FrameBufferProperties::FM_depth) == 0) { - wdxdisplay7_cat.info() - << "no zbuffer requested, skipping zbuffer creation\n"; - } -#endif - - // Check if the device supports z-bufferless hidden surface - // removal. If so, we don't really need a z-buffer - if ((!(pD3DDevDesc->dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBUFFERLESSHSR )) && - ((frame_buffer_mode & FrameBufferProperties::FM_depth) != 0)) { - - // Get z-buffer dimensions from the render target - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd); - pBackDDSurf->GetSurfaceDesc( &ddsd ); - - // Setup the surface desc for the z-buffer. - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT; - ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | ((_wcontext.bIsSWRast) ? DDSCAPS_SYSTEMMEMORY : DDSCAPS_VIDEOMEMORY); - - DDPIXELFORMAT ZBufPixFmts[MAX_DX_ZBUF_FMTS]; - cNumZBufFmts=0; - - // Get an appropiate pixel format from enumeration of the - // formats. On the first pass, we look for a zbuffer dpeth which - // is equal to the frame buffer depth (as some cards unfornately - // require this). - hr = pD3DI->EnumZBufferFormats((Display.bIsTNLDevice ? IID_IDirect3DHALDevice : IID_IDirect3DTnLHalDevice), - EnumZBufFmtsCallback, - (VOID*)&ZBufPixFmts); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() << "EnumZBufferFormats failed" << endl; - exit(1); - } - -#ifdef _DEBUG - { - static BOOL bPrinted=FALSE; - if (!bPrinted) { - for (i = 0; i < cNumZBufFmts; i++) { - DebugPrintPixFmt(&ZBufPixFmts[i]); - } - bPrinted=TRUE; - } - } -#endif - - // should we pay attn to these at some point? - //int want_depth_bits = _props._want_depth_bits; - //int want_color_bits = _props._want_color_bits; - bool bWantStencil = ((frame_buffer_mode & FrameBufferProperties::FM_stencil) != 0); - - LPDDPIXELFORMAT pCurPixFmt, pz16 = NULL, pz24 = NULL, pz32 = NULL; - for (i = 0, pCurPixFmt = ZBufPixFmts; - i < cNumZBufFmts; - i++, pCurPixFmt++) { - if (bWantStencil == ((pCurPixFmt->dwFlags & DDPF_STENCILBUFFER)!=0)) { - switch (pCurPixFmt->dwRGBBitCount) { - case 16: - pz16 = pCurPixFmt; - break; - case 24: - pz24 = pCurPixFmt; - break; - case 32: - pz32 = pCurPixFmt; - break; - } - } - } - - if ((pz16 == NULL) && (pz24 == NULL) && (pz32 == NULL)) { - if (bWantStencil) { - wdxdisplay7_cat.fatal() - << "stencil buffer requested, device has no stencil capability\n"; - } else { - wdxdisplay7_cat.fatal() - << "failed to find adequate zbuffer capability\n"; - } - exit(1); - } - -#define SET_ZBUF_DEPTH(DEPTH) { assert(pz##DEPTH != NULL); Display.depth_buffer_bitdepth=DEPTH; ddsd.ddpfPixelFormat = *pz##DEPTH;} - - if (_wcontext.bIsSWRast) { - SET_ZBUF_DEPTH(16); // need this for fast path rasterizers - } else { - if (IS_NVIDIA(Display.DXDeviceID)) { - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_pri); - pPrimaryDDSurf->GetSurfaceDesc(&ddsd_pri); - - // must pick zbuf depth to match primary surface depth for nvidia - if (ddsd_pri.ddpfPixelFormat.dwRGBBitCount==16) { - SET_ZBUF_DEPTH(16); - } else { - if (force_16bpp_zbuffer) { - wdxdisplay7_cat.fatal() - << "'dx-force-16bpp-zbuffer #t' requires a 16bpp desktop on nvidia cards\n"; - exit(1); - } - // take the smaller of 24 or 32. (already assured to match stencil capability) - if(pz24 != NULL) { - SET_ZBUF_DEPTH(24); - } else { - SET_ZBUF_DEPTH(32); - } - } - } else { - if (force_16bpp_zbuffer) { - if (pz16 == NULL) { - wdxdisplay7_cat.fatal() - << "'dx-force-16bpp-zbuffer #t', but no 16bpp zbuf fmts available on this card\n"; - exit(1); - } - - if(wdxdisplay7_cat.is_debug()) { - wdxdisplay7_cat.debug() << "forcing use of 16bpp Z-Buffer\n"; - } - SET_ZBUF_DEPTH(16); - ddsd.ddpfPixelFormat = *pz16; - - } else { - // pick the highest res zbuffer format avail. Note: this is - // choosing to waste vid-memory and possibly perf for more - // accuracy, less z-fighting at long distance (std 16bpp - // would be smaller, maybe faster) order of preference 24: - // (should be enough), 32: probably means 24 of Z, then 16 - - if (bWantStencil && (pz32!=NULL)) { - // dont want to select 16/8 z/stencil over 24/8 z/stenc - SET_ZBUF_DEPTH(32); - } else { - if (pz24!=NULL) { - SET_ZBUF_DEPTH(24); - } else if (pz32!=NULL) { - SET_ZBUF_DEPTH(32); - } else { - SET_ZBUF_DEPTH(16); - } - } - } - } - } - -#ifdef _DEBUG - wdxdisplay7_cat.info() - << "Creating " << ddsd.ddpfPixelFormat.dwRGBBitCount << "bpp zbuffer\n"; -#endif - - // Create and attach a z-buffer - hr = pDD->CreateSurface(&ddsd, &pZDDSurf, NULL); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "CreateSurface failed for Z buffer: result = " - << ConvD3DErrorToString(hr) << endl; - - if (((hr==DDERR_OUTOFVIDEOMEMORY)||(hr==DDERR_OUTOFMEMORY)) && - ((Display.dwFullScreenBitDepth>16)||(ddsd.ddpfPixelFormat.dwRGBBitCount>16))) { - Display.dwFullScreenBitDepth=16; - // emergency fallback to 16bpp (shouldnt have to do this - // unless GetAvailVidMem lied) will this work for multimon? - // what if surfs are already created on 1st mon? - - wdxdisplay7_cat.info() - << "GetAvailVidMem lied, not enough VidMem for 32bpp, so trying 16bpp on device #" - << Display.CardIDNum << endl; - - // free pri and back (maybe should just free pri since created - // as complex chain?) - RELEASE(pBackDDSurf, wdxdisplay7, "backbuffer", false); - RELEASE(pPrimaryDDSurf, wdxdisplay7, "primary surface", false); - - hr = pDD->SetDisplayMode(Display.dwRenderWidth, - Display.dwRenderHeight, - Display.dwFullScreenBitDepth, - 0, 0); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "SetDisplayMode failed to set (" - << Display.dwRenderWidth << "x" << Display.dwRenderHeight - << "x" << Display.dwFullScreenBitDepth << ") on device #" - << Display.CardIDNum << ": result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - create_screen_buffers_and_device(Display, true); - return; - - } else { - exit(1); - } - } - - hr = pBackDDSurf->AddAttachedSurface(pZDDSurf); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "AddAttachedSurface failed : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - } - - // Create the device. The device is created off of our back buffer, - // which becomes the render target for the newly created device. - hr = pD3DI->CreateDevice(pD3DDevDesc->deviceGUID, pBackDDSurf, &pD3DDevice); - if (hr != DD_OK) { - wdxdisplay7_cat.fatal() - << "CreateDevice failed : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - // No reason to create a viewport at this point. - /* - // Create the viewport - WindowProperties properties = get_properties(); - D3DVIEWPORT7 vp = { - 0, 0, - properties.get_x_size(), properties.get_y_size(), - 0.0f, 1.0f - }; - hr = pD3DDevice->SetViewport(&vp); - if (hr != DD_OK) { - wdxdisplay7_cat.fatal() - << "SetViewport failed : result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - */ - - Display.pD3DDevice = pD3DDevice; - Display.pddsPrimary = pPrimaryDDSurf; - Display.pddsBack = pBackDDSurf; - Display.pddsZBuf = pZDDSurf; - Display.view_rect = view_rect; - - _dxgsg->set_context(&Display); - //pDD, pPrimaryDDSurf, pBackDDSurf, pZDDSurf, pD3DI, pD3DDevice, view_rect); - // _dxgsg->dx_init(); - - // do not SetDXReady() yet since caller may want to do more work - // before letting rendering proceed - - // Oh, go ahead and call it. - // _dxgsg->SetDXReady(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::choose_device -// Access: Private -// Description: Searches for a suitable hardware device for -// rendering. -//////////////////////////////////////////////////////////////////// -bool wdxGraphicsWindow7:: -choose_device(int devnum, DXDeviceInfo *pDevinfo) { - wdxGraphicsPipe7 *dxpipe; - DCAST_INTO_R(dxpipe, _pipe, false); - - WindowProperties properties = get_properties(); - FrameBufferProperties fbprops = _dxgsg->get_properties(); - - int mode = fbprops.get_frame_buffer_mode(); - bool hardware = ((mode & FrameBufferProperties::FM_hardware) != 0); - bool software = ((mode & FrameBufferProperties::FM_software) != 0); - - // If the user specified neither hardware nor software frame buffer, - // he gets either one. - if (!hardware && !software) { - hardware = true; - software = true; - } - - DWORD dwRenderWidth = properties.get_x_size(); - DWORD dwRenderHeight = properties.get_y_size(); - LPDIRECTDRAW7 pDD=NULL; - HRESULT hr; - - assert(_dxgsg != NULL); - - GUID *pDDDeviceGUID; - if (pDevinfo == NULL) { - pDDDeviceGUID = NULL; - } else { - pDDDeviceGUID = &pDevinfo->guidDeviceIdentifier; - } - - assert(dxpipe->_DirectDrawCreateEx != NULL); - -#if 0 //test code - // lets try a little cleanup - if (_wcontext.pddsPrimary) { - _wcontext.pddsPrimary->Release(); - _wcontext.pddsPrimary = NULL; - } - if (_wcontext.pddsBack) { - _wcontext.pddsBack->Release(); - _wcontext.pddsBack = NULL; - } - if (_wcontext.pddsZBuf) { - _wcontext.pddsZBuf->Release(); - _wcontext.pddsZBuf = NULL; - } - - if (_wcontext.pD3D) { - _wcontext.pD3D->Release(); - _wcontext.pD3D = NULL; - } - if (_wcontext.pDD) { - _wcontext.pDD->Release(); - _wcontext.pDD = NULL; - } -#endif - - // Create the Direct Draw Objects - hr = (*dxpipe->_DirectDrawCreateEx)(pDDDeviceGUID, (void **)&pDD, - IID_IDirectDraw7, NULL); - if ((hr != DD_OK) || (pDD == NULL)) { - wdxdisplay7_cat.fatal() - << "DirectDrawCreateEx failed for monitor(" << devnum - << "): result = " << ConvD3DErrorToString(hr) << endl; - return false; - } - - _wcontext.pDD = pDD; - - // GetDeviceID bug writes an extra 4 bytes, so need xtra space - BYTE id_arr[sizeof(DDDEVICEIDENTIFIER2) + 4]; - pDD->GetDeviceIdentifier((DDDEVICEIDENTIFIER2 *)&id_arr, 0x0); - - memcpy(&_wcontext.DXDeviceID, id_arr, sizeof(DDDEVICEIDENTIFIER2)); - - if (wdxdisplay7_cat.is_info()) { - DDDEVICEIDENTIFIER2 *pDevID = &_wcontext.DXDeviceID; - wdxdisplay7_cat.info() - << "GfxCard: " << pDevID->szDescription << "; DriverFile: '" - << pDevID->szDriver - << "'; VendorID: 0x" << (void*)pDevID->dwVendorId - << "; DeviceID: 0x" << (void*)pDevID->dwDeviceId - << "; DriverVer: " - << HIWORD(pDevID->liDriverVersion.HighPart) << "." - << LOWORD(pDevID->liDriverVersion.HighPart) << "." - << HIWORD(pDevID->liDriverVersion.LowPart) << "." - << LOWORD(pDevID->liDriverVersion.LowPart) << endl; - } - - // Query DirectDraw for access to Direct3D - hr = pDD->QueryInterface(IID_IDirect3D7, (VOID**)&_wcontext.pD3D); - if(hr != DD_OK) { - wdxdisplay7_cat.fatal() - << "QI for D3D failed : result = " << ConvD3DErrorToString(hr) << endl; - goto error_exit; - } - - D3DDEVICEDESC7 d3ddevs[3]; // put HAL in 0, TnLHAL in 1, SW rast in 2 - - // just look for HAL and TnL devices right now. I dont think - // we have any interest in the sw rasts at this point - - ZeroMemory(d3ddevs,3*sizeof(D3DDEVICEDESC7)); - - hr = _wcontext.pD3D->EnumDevices(EnumDevicesCallback, d3ddevs); - if(hr != DD_OK) { - wdxdisplay7_cat.fatal() - << "EnumDevices failed : result = " << ConvD3DErrorToString(hr) << endl; - goto error_exit; - } - - WORD DeviceIdx; - - // select TNL if present - if (hardware && (d3ddevs[TNLHALIDX].dwDevCaps & D3DDEVCAPS_HWRASTERIZATION)) { - DeviceIdx = TNLHALIDX; - } else if (hardware && (d3ddevs[REGHALIDX].dwDevCaps & D3DDEVCAPS_HWRASTERIZATION)) { - DeviceIdx = REGHALIDX; - } else if (software) { - DeviceIdx = SWRASTIDX; - } else { - wdxdisplay7_cat.error() - << "No 3D graphics present on device #" << devnum << ", skipping it... (" - << _wcontext.DXDeviceID.szDescription<<")\n"; - goto error_exit; - } - - memcpy(&_wcontext.D3DDevDesc, &d3ddevs[DeviceIdx], - sizeof(D3DDEVICEDESC7)); - - _wcontext.bIsTNLDevice = (DeviceIdx == TNLHALIDX); - - // Get Current VidMem avail. Note this is only an estimate, when we - // switch to fullscreen mode from desktop, more vidmem will be - // available (typically 1.2 meg). I dont want to switch to - // fullscreen more than once due to the annoying monitor flicker, so - // try to figure out optimal mode using this estimate - DDSCAPS2 ddsGAVMCaps; - DWORD dwVidMemTotal, dwVidMemFree; - dwVidMemTotal = dwVidMemFree = 0; - ZeroMemory(&ddsGAVMCaps, sizeof(DDSCAPS2)); - ddsGAVMCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM; // dont count AGP mem! - hr = pDD->GetAvailableVidMem(&ddsGAVMCaps,&dwVidMemTotal,&dwVidMemFree); - if (FAILED(hr)) { - wdxdisplay7_cat.error() - << "GetAvailableVidMem failed for device #" << devnum - << ": result = " << ConvD3DErrorToString(hr) << endl; - // goto skip_device; - exit(1); // probably want to exit, since it may be my fault - } - - // after SetDisplayMode, GetAvailVidMem totalmem seems to go down by - // 1.2 meg (contradicting above comment and what I think would be - // correct behavior (shouldnt FS mode release the desktop vidmem?), - // so this is the true value - _wcontext.MaxAvailVidMem = dwVidMemTotal; - -#define LOWVIDMEMTHRESHOLD 5500000 -#define CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD 1000000 // every vidcard we deal with should have at least 1MB - - // assume buggy drivers (this means you, FireGL2) may return zero for dwVidMemTotal, so ignore value if its < CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD - _wcontext.bIsLowVidMemCard = - ((dwVidMemTotal>CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD) && - (dwVidMemTotal< LOWVIDMEMTHRESHOLD)); - - if (!dx_do_vidmemsize_check) { - _wcontext.MaxAvailVidMem = 0xFFFFFFFF; - _wcontext.bIsLowVidMemCard = false; - } - - if (DeviceIdx == SWRASTIDX) { - // this will force 640x480x16, is this what we want for all sw rast? - _wcontext.bIsLowVidMemCard = true; - _wcontext.bIsSWRast = true; - dx_force_16bpp_zbuffer = true; - } - - if (is_fullscreen()) { - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_search); - ddsd_search.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; - ddsd_search.dwWidth = dwRenderWidth; - ddsd_search.dwHeight = dwRenderHeight; - - DDSURFACEDESC2 DDSD_Arr[MAX_DISPLAY_MODES]; - DisplayModeInfo DMI; - ZeroMemory(&DDSD_Arr, sizeof(DDSD_Arr)); - ZeroMemory(&DMI, sizeof(DMI)); - DMI.maxWidth = dwRenderWidth; - DMI.maxHeight = dwRenderHeight; - DMI.pDDSD_Arr = DDSD_Arr; - - hr= pDD->EnumDisplayModes(DDEDM_REFRESHRATES, &ddsd_search, - &DMI, EnumDisplayModesCallBack); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "EnumDisplayModes failed for device #" << devnum - << " (" << _wcontext.DXDeviceID.szDescription - << "), result = " << ConvD3DErrorToString(hr) << endl; - // goto skip_device; - exit(1); // probably want to exit, since it may be my fault - } - - if (wdxdisplay7_cat.is_info()) { - wdxdisplay7_cat.info() - << "Before fullscreen switch: GetAvailableVidMem for device #" - << devnum << " returns Total: " << dwVidMemTotal/1000000.0 - << " Free: " << dwVidMemFree/1000000.0 << endl; - } - - // Now we try to figure out if we can use requested screen - // resolution and best rendertarget bpp and still have at least 2 - // meg of texture vidmem - - DMI.supportedBitDepths &= _wcontext.D3DDevDesc.dwDeviceRenderBitDepth; - - DWORD dwFullScreenBitDepth; - - // note: this chooses 32bpp, which may not be preferred over 16 - // for memory & speed reasons - if (DMI.supportedBitDepths & DDBD_32) { - dwFullScreenBitDepth = 32; // go for 32bpp if its avail - } else if (DMI.supportedBitDepths & DDBD_24) { - dwFullScreenBitDepth = 24; // go for 24bpp if its avail - } else if (DMI.supportedBitDepths & DDBD_16) { - dwFullScreenBitDepth = 16; // do 16bpp - } else { - wdxdisplay7_cat.fatal() - << "No Supported FullScreen resolutions at " << dwRenderWidth - << "x" << dwRenderHeight << " for device #" << devnum - << " (" << _wcontext.DXDeviceID.szDescription - << "), skipping device...\n"; - goto error_exit; - } - - if (_wcontext.bIsLowVidMemCard) { - { - // hack: figuring out exactly what res to use is tricky, - // instead I will just use 640x480 if we have < 3 meg avail - - dwFullScreenBitDepth = 16; - dwRenderWidth = 640; - dwRenderHeight = 480; - dx_force_16bpptextures = true; - - if (wdxdisplay7_cat.is_info()) - wdxdisplay7_cat.info() - << "Available VidMem (" << dwVidMemFree << ") is under " - << LOWVIDMEMTHRESHOLD - << ", using 640x480 16bpp rendertargets to save tex vidmem.\n"; - } - } - - _wcontext.dwFullScreenBitDepth = dwFullScreenBitDepth; - } - - _wcontext.dwRenderWidth = dwRenderWidth; - _wcontext.dwRenderHeight = dwRenderHeight; - if (pDevinfo) { - _wcontext.hMon = pDevinfo->hMon; - } - _wcontext.CardIDNum = devnum; // add ID tag for dbgprint purposes - - return true; - - // handle errors within this for device loop - - error_exit: - if (_wcontext.pD3D != NULL) - _wcontext.pD3D->Release(); - if (_wcontext.pDD != NULL) - _wcontext.pDD->Release(); - - _wcontext.pDD = NULL; - _wcontext.pD3D = NULL; - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: wdxGraphicsWindow7::set_coop_levels_and_display_modes -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void wdxGraphicsWindow7:: -set_coop_levels_and_display_modes() { - HRESULT hr; - DWORD SCL_FPUFlag; - - if (dx_preserve_fpu_state) { - // tell d3d to preserve the fpu state across calls. this hurts - // perf, but is good for dbgging - SCL_FPUFlag = DDSCL_FPUPRESERVE; - } else { - SCL_FPUFlag = DDSCL_FPUSETUP; - } - - // DXScreenData *pScrn = &_dxgsg->scrn; - - if (!is_fullscreen()) { - hr = _wcontext.pDD->SetCooperativeLevel(_hWnd, - SCL_FPUFlag | DDSCL_NORMAL); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "SetCooperativeLevel failed : result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - return; - } - - DWORD SCL_FLAGS = SCL_FPUFlag | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT; - - // The following code would be done per window if were supporting - // multiple fullscreen windows on different graphics cards. TODO: - // restore that functionality. - DWORD devnum = 0; - { - // DXScreenData *pScrn = &_dxgsg->scrn; - - // need to set focus/device windows for multimon - // focus window is primary monitor that will receive keybd input - // all ddraw objs need to have same focus window - /* - if(_windows.size()>1) { - if(FAILED(hr = pScrn->pDD->SetCooperativeLevel(_hParentWindow, DDSCL_SETFOCUSWINDOW))) { - wdxdisplay7_cat.fatal() << "SetCooperativeLevel SetFocusWindow failed on device 0: result = " << ConvD3DErrorToString(hr) << endl; - exit(1); - } - } - */ - - // s3 savage2000 on w95 seems to set EXCLUSIVE_MODE only if you call - // SetCoopLevel twice. so we do it, it really shouldnt be necessary - // if drivers werent buggy - for (int jj=0; jj<2; jj++) { - hr = _wcontext.pDD->SetCooperativeLevel(_wcontext.hWnd, SCL_FLAGS); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "SetCooperativeLevel failed for device #" << devnum - << ": result = " << ConvD3DErrorToString(hr) << endl; - exit(1); //let it run, see what happens - } - } - - hr = _wcontext.pDD->TestCooperativeLevel(); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "TestCooperativeLevel failed: result = " << ConvD3DErrorToString(hr) - << endl; - wdxdisplay7_cat.fatal() - << "Full screen app failed to get exclusive mode on init, exiting..\n"; - exit(1); - } - - // note: its important we call SetDisplayMode on all cards before - // creating surfaces on any of them to let driver choose default - // refresh rate (hopefully its >=60Hz) - hr = _wcontext.pDD->SetDisplayMode(_wcontext.dwRenderWidth, - _wcontext.dwRenderHeight, - _wcontext.dwFullScreenBitDepth, 0, 0); - if (FAILED(hr)) { - wdxdisplay7_cat.fatal() - << "SetDisplayMode failed to set (" << _wcontext.dwRenderWidth - << "x" <<_wcontext.dwRenderHeight << "x" << _wcontext.dwFullScreenBitDepth - << ") on device #" << _wcontext.CardIDNum << ": result = " - << ConvD3DErrorToString(hr) << endl; - exit(1); - } - - if(wdxdisplay7_cat.is_debug()) { - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd_temp); - _wcontext.pDD->GetDisplayMode(&ddsd_temp); - wdxdisplay7_cat.debug() - << "set displaymode to " << ddsd_temp.dwWidth << "x" << ddsd_temp.dwHeight - << " at " << ddsd_temp.ddpfPixelFormat.dwRGBBitCount << "bpp, " - << ddsd_temp.dwRefreshRate<< "Hz\n"; - } - } -} diff --git a/panda/src/dxgsg7/wdxGraphicsWindow7.h b/panda/src/dxgsg7/wdxGraphicsWindow7.h deleted file mode 100644 index e715fd931d..0000000000 --- a/panda/src/dxgsg7/wdxGraphicsWindow7.h +++ /dev/null @@ -1,87 +0,0 @@ -// Filename: wdxGraphicsWindow7.h -// Created by: drose (20Dec02) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - -#ifndef WDXGRAPHICSWINDOW7_H -#define WDXGRAPHICSWINDOW7_H - -#include "pandabase.h" -#include "winGraphicsWindow.h" -#include "pvector.h" - -class DXGraphicsStateGuardian7; - -typedef struct { - char szDriver[MAX_DDDEVICEID_STRING]; - char szDescription[MAX_DDDEVICEID_STRING]; - GUID guidDeviceIdentifier; - HMONITOR hMon; -} DXDeviceInfo; -typedef pvector DXDeviceInfoVec; - -typedef HRESULT (WINAPI * LPDIRECTDRAWCREATEEX)(GUID FAR * lpGuid, LPVOID *lplpDD, REFIID iid,IUnknown FAR *pUnkOuter); - -//////////////////////////////////////////////////////////////////// -// Class : wdxGraphicsWindow7 -// Description : A single graphics window for rendering DirectX under -// Microsoft Windows. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDADX wdxGraphicsWindow7 : public WinGraphicsWindow { -public: - wdxGraphicsWindow7(GraphicsPipe *pipe, GraphicsStateGuardian *gsg, - const string &name); - virtual ~wdxGraphicsWindow7(); - virtual void end_flip(); - virtual void make_current(); - virtual bool open_window(); - -protected: - virtual void fullscreen_restored(WindowProperties &properties); - virtual void handle_reshape(); - virtual bool do_fullscreen_resize(int x_size, int y_size); - -private: - bool set_to_temp_rendertarget(); - void create_screen_buffers_and_device(DXScreenData &Display, - bool force_16bpp_zbuffer); - bool choose_device(int devnum, DXDeviceInfo *pDevinfo); - void set_coop_levels_and_display_modes(); - - DXGraphicsStateGuardian7 *_dxgsg; - DXScreenData _wcontext; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - WinGraphicsWindow::init_type(); - register_type(_type_handle, "wdxGraphicsWindow7", - WinGraphicsWindow::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "wdxGraphicsWindow7.I" - -#endif