dx8 dxgsg

This commit is contained in:
cxgeorge 2001-12-05 01:40:31 +00:00
parent 4bb585169c
commit f4a3d7d340
26 changed files with 15115 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#define DIRECTORY_IF_DX yes
// 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 \
dxgsg8 wdxdisplay8
#define LOCAL_LIBS gsgbase display express gobj
#define OTHER_LIBS dtoolconfig dtool
#if $[BUILD_DX8]
#begin metalib_target
#define TARGET pandadx8
#define SOURCES pandadx8.cxx
#end metalib_target
#endif

View File

@ -0,0 +1,23 @@
// Filename: pandadx.cxx
// Created by: drose (15May00)
//
////////////////////////////////////////////////////////////////////
#include "pandadx8.h"
#include <config_dxgsg8.h>
#include <config_wdxdisplay8.h>
////////////////////////////////////////////////////////////////////
// Function: init_libpandadx
// 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_libpandadx8() {
init_libdxgsg8();
init_libwdxdisplay8();
}

View File

@ -0,0 +1,13 @@
// Filename: pandadx.h
// Created by: drose (2Jan01)
//
////////////////////////////////////////////////////////////////////
#ifndef PANDADX8_H
#define PANDADX8_H
#include <pandabase.h>
EXPCL_PANDADX void init_libpandadx8();
#endif

View File

@ -0,0 +1,31 @@
#define DIRECTORY_IF_DX yes
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
dtoolutil:c dtoolbase:c dtool:m
#define USE_DX yes
#if $[BUILD_DX8]
#begin lib_target
#define TARGET dxgsg8
#define LOCAL_LIBS \
cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display light \
putil linmath sgraph mathutil pnmimage event
#define COMBINED_SOURCES $[TARGET]_composite1.cxx
#define SOURCES \
config_dxgsg8.h dxGraphicsStateGuardian8.I \
dxGraphicsStateGuardian8.cxx dxGraphicsStateGuardian8.h \
dxSavedFrameBuffer8.I dxSavedFrameBuffer8.h \
dxTextureContext8.h dxGeomNodeContext8.h dxGeomNodeContext8.I
#define INCLUDED_SOURCES \
config_dxgsg8.cxx dxSavedFrameBuffer8.cxx dxTextureContext8.cxx dxGeomNodeContext8.cxx
#define INSTALL_HEADERS \
dxGraphicsStateGuardian8.I dxGraphicsStateGuardian8.h \
dxSavedFrameBuffer8.I dxSavedFrameBuffer8.h dxTextureContext8.h
#end lib_target
#endif

View File

@ -0,0 +1,138 @@
// Filename: config_dxgsg.cxx
// Created by: drose (06Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "config_dxgsg8.h"
#include "dxGraphicsStateGuardian8.h"
#include "dxSavedFrameBuffer8.h"
#include "dxTextureContext8.h"
#include <dconfig.h>
Configure(config_dxgsg);
NotifyCategoryDef(dxgsg, ":display:gsg");
// Configure this variable true to cause the DXGSG to show each
// transform space it renders by drawing a little unit axis. This
// cannot be enabled when the player is compiled in NDEBUG mode.
bool dx_show_transforms = config_dxgsg.GetBool("dx-show-transforms", false);
// Configure this to TRUE if you want DirectX to control the entire screen,
// If false, it will just blit into a window.
bool dx_full_screen = config_dxgsg.GetBool("dx-full-screen", false);
// Configure this true to force the rendering to sync to the video
// refresh, or false to let your frame rate go as high as it can,
// irrespective of the video refresh.
bool dx_sync_video = config_dxgsg.GetBool("sync-video", true);
// enable this to turn on full-screen anti-aliasing, if the HW supports it
// this var is also used in wdxGraphicsWindows.cxx
bool dx_full_screen_antialiasing = config_dxgsg.GetBool("dx-antialias", false);
// Configure this true to perform a cull traversal over the geometry
// by default, false otherwise. The cull traversal provides support
// for state-sorting, z-sorting, and binning.
bool dx_cull_traversal = config_dxgsg.GetBool("dx-cull-traversal", true);
// if true, if card only supports per-vertex fog, it will be treated as no-HW fog capability
bool dx_no_vertex_fog = config_dxgsg.GetBool("dx-no-vertex-fog", false);
// Configure this true to cause all lighting normals to automatically
// be normalized by the CPU before rendering. This is
// necessary if you intend to render things under scale transforms and
// expect lighting to work correctly. Maybe one day there will be
// another way to set this at runtime, instead of only as a configure
// variable
bool dx_auto_normalize_lighting = config_dxgsg.GetBool("auto-normalize-lighting", false);
bool dx_show_fps_meter = config_dxgsg.GetBool("show-fps-meter", false);
float dx_fps_meter_update_interval = max(0.5,config_dxgsg.GetFloat("fps-meter-update-interval", 1.7));
#ifndef NDEBUG
// debugging flag
// values are same as D3DCULL enumtype, 0 - no force, 1 - force none, 2 - force CW, 3 - force CCW
int dx_force_backface_culling = config_dxgsg.GetInt("dx-force-backface-culling", 0);
#endif
bool dx_mipmap_everything = config_dxgsg.GetBool("dx-mipmap-everything", false);
bool dx_ignore_mipmaps = config_dxgsg.GetBool("dx-ignore-mipmaps", false);
// if this is set, more accurate but more expensive fog computations are performed
bool dx_use_rangebased_fog = config_dxgsg.GetBool("dx-use-rangebased-fog", false);
#ifdef _DEBUG
float dx_global_miplevel_bias = config_dxgsg.GetFloat("dx-global-miplevel-bias", 0.0);
bool dx_debug_view_mipmaps = config_dxgsg.GetBool("dx-debug-view-mipmaps", false);
bool dx_force_16bpptextures = config_dxgsg.GetBool("dx-force-16bpptextures", false);
bool dx_force_anisotropic_filtering = config_dxgsg.GetBool("dx-force-anisotropic-filtering", false);
//int dx_print_texstats = config_dxgsg.GetBool("dx-print-texstats", 0);
#endif
// set 'retained-mode #t' and this to have prepare_geom concatenate all tristrips within a geom
// together using degenerate tris
const bool link_tristrips = config_dxgsg.GetBool("link-tristrips", false);
// note: offset currently disabled since it wasnt working properly
DXDecalType dx_decal_type = GDT_offset;
static DXDecalType
parse_decal_type(const string &type) {
if (type == "mask") {
return GDT_mask;
} else if (type == "blend") {
return GDT_blend;
} else if (type == "offset") {
return GDT_offset;
}
dxgsg_cat.error() << "Invalid dx-decal-type: " << type << "\n";
return GDT_offset;
}
ConfigureFn(config_dxgsg) {
init_libdxgsg8();
}
////////////////////////////////////////////////////////////////////
// Function: init_libdxgsg
// 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_libdxgsg8() {
static bool initialized = false;
if (initialized) {
return;
}
initialized = true;
string decal_type = config_dxgsg.GetString("dx-decal-type", "");
if (!decal_type.empty()) {
dx_decal_type = parse_decal_type(decal_type);
}
DXGraphicsStateGuardian::init_type();
DXSavedFrameBuffer::init_type();
DXTextureContext::init_type();
DXGeomNodeContext::init_type();
GraphicsStateGuardian::get_factory().register_factory
(DXGraphicsStateGuardian::get_class_type(),
DXGraphicsStateGuardian::make_DXGraphicsStateGuardian);
}

View File

@ -0,0 +1,64 @@
// Filename: config_dxgsg.h
// Created by: drose (06Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef CONFIG_DXGSG_H
#define CONFIG_DXGSG_H
#include <pandabase.h>
#include <notifyCategoryProxy.h>
NotifyCategoryDecl(dxgsg, EXPCL_PANDADX, EXPTP_PANDADX);
extern bool dx_full_screen;
extern bool dx_sync_video;
extern bool dx_cull_traversal;
extern bool dx_show_fps_meter;
extern bool dx_no_vertex_fog;
extern bool dx_full_screen_antialiasing;
extern float dx_fps_meter_update_interval;
extern bool dx_auto_normalize_lighting;
extern bool dx_use_rangebased_fog;
extern const bool link_tristrips;
// debug flags
extern bool dx_ignore_mipmaps;
extern bool dx_mipmap_everything;
extern bool dx_show_transforms;
#ifndef NDEBUG
extern int dx_force_backface_culling;
#endif
#ifdef _DEBUG
extern float dx_global_miplevel_bias;
extern bool dx_debug_view_mipmaps;
extern bool dx_force_16bpptextures;
extern bool dx_force_anisotropic_filtering;
#endif
// Ways to implement decals.
enum DXDecalType {
GDT_mask, // GL 1.0 style, involving three steps and double-draw of polygon
GDT_blend, // As above, but slower; use blending to disable colorbuffer writes
GDT_offset // The fastest, using GL 1.1 style glPolygonOffset
};
extern DXDecalType dx_decal_type;
extern EXPCL_PANDADX void init_libdxgsg8();
#endif

View File

@ -0,0 +1,31 @@
// Filename: dxGeomNodeContext.I
// Created by: drose (12Jun01)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: dxGeomNodeContext::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE DXGeomNodeContext::
DXGeomNodeContext(GeomNode *node) : GeomNodeContext(node)
{
_num_verts = 0;
_pVB = NULL;
_pXformed_VB = NULL;
}

View File

@ -0,0 +1,33 @@
// Filename: dxGeomNodeContext.cxx
// Created by: drose (12Jun01)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "dxGeomNodeContext8.h"
TypeHandle DXGeomNodeContext::_type_handle;
DXGeomNodeContext::~DXGeomNodeContext()
{
if(_pXformed_VB!=NULL)
_pXformed_VB->Release();
_pXformed_VB=NULL;
if(_pVB!=NULL)
_pVB->Release();
_pVB=NULL;
}

View File

@ -0,0 +1,94 @@
// Filename: dxGeomNodeContext.h
// Created by: drose (12Jun01)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef DXGEOMNODECONTEXT_H
#define DXGEOMNODECONTEXT_H
#include <pandabase.h>
#ifdef WIN32_VC
// Must include windows.h before dx.h on NT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif
#include <geomNodeContext.h>
#include <geomNode.h>
#include "pvector.h"
#define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h
#include <d3d.h>
typedef struct {
DWORD nVerts;
D3DPRIMITIVETYPE primtype;
} DPInfo;
////////////////////////////////////////////////////////////////////
// Class : DXGeomNodeContext
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDADX DXGeomNodeContext : public GeomNodeContext {
public:
INLINE DXGeomNodeContext(GeomNode *node);
~DXGeomNodeContext();
// A list of the dynamic Geoms within the GeomNode; these aren't
// part of the above display list and must be drawn separately
typedef pvector<PT(dDrawable) > Geoms;
Geoms _cached_geoms,_other_geoms;
// VB's are already reference-counted by D3D, no need to make separate panda object to do that
// but we will want a way to know if VB has already been xformed by ProcessVerts this frame
// if multiple geomnodes share VBs
LPDIRECT3DVERTEXBUFFER7 _pVB;
LPDIRECT3DVERTEXBUFFER7 _pXformed_VB;
int _start_index; // starting offset of this geom's verts within the VB
int _num_verts; // number of verts used by this geomcontext within the VB
BYTE *_pEndofVertData; // ptr to end of current vert data in VB (note: only used/valid during setup)
// for multiple geoms per VB, either will have to regen lengths based on per* flags, or store
// per geom vector of perprim vectors lengths
vector<DPInfo> _PrimInfo;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
GeomNodeContext::init_type();
register_type(_type_handle, "DXGeomNodeContext",
GeomNodeContext::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 "dxGeomNodeContext8.I"
#endif

View File

@ -0,0 +1,398 @@
// Filename: dxGraphicsStateGuardian.I
// Created by: mike (02Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "config_dxgsg8.h"
#include <graphicsWindow.h>
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_line_smooth
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_line_smooth(bool val) {
if(_line_smooth_enabled != val) {
_line_smooth_enabled = val;
#ifdef NDEBUG
{
if(val && (_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASEDGES))
dxgsg_cat.error() << "no HW support for line smoothing!!\n";
}
#endif
_d3dDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, (DWORD)val);
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_lighting
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_lighting(bool val) {
if (_lighting_enabled != val) {
_d3dDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, (DWORD)val);
if(_lighting_enabled = val)
_lighting_enabled_this_frame = true;
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_dither
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_dither(bool val) {
if (_dither_enabled != val) {
#ifdef _DEBUG
{
if(val && !(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_DITHER))
dxgsg_cat.error() << "no HW support for color dithering!!\n";
return;
}
#endif
_dither_enabled = val;
_d3dDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, (DWORD)val);
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_stencil_test
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_stencil_test(bool val) {
if (_stencil_test_enabled != val) {
_stencil_test_enabled = val;
_d3dDevice->SetRenderState(D3DRENDERSTATE_STENCILENABLE, (DWORD)val);
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_color_material
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_color_material(bool val) {
if (_color_material_enabled != val) {
_color_material_enabled = val;
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_clip_plane
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_clip_plane(int clip_plane, bool val)
{
if (_clip_plane_enabled[clip_plane] != val)
{
_clip_plane_enabled[clip_plane] = val;
DWORD ClipPlaneBits;
_d3dDevice->GetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , &ClipPlaneBits);
if (val)
ClipPlaneBits |= 1 << clip_plane;
else
ClipPlaneBits &= ~(1 << clip_plane);
_d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , ClipPlaneBits);
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_blend
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_blend(bool val) {
if (_blend_enabled != val) {
_blend_enabled = val;
_d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, (DWORD)val);
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_blend
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
set_shademode(D3DSHADEMODE val) {
if (_CurShadeMode != val) {
_CurShadeMode = val;
_d3dDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, (DWORD)val);
}
}
INLINE void DXGraphicsStateGuardian::
enable_primitive_clipping(bool val) {
if (_clipping_enabled != val) {
_clipping_enabled = val;
_d3dDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, (DWORD)val);
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_fog
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_fog(bool val) {
if ((_fog_enabled != val) && (_doFogType!=None)) {
_fog_enabled = val;
_d3dDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, (DWORD)val);
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_alpha_test
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_alpha_test(bool val )
{
if (_alpha_test_enabled != val) {
_alpha_test_enabled = val;
_d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, (DWORD)val);
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::call_dxLightModelAmbient
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
call_dxLightModelAmbient( const Colorf& color)
{
if (_lmodel_ambient != color) {
_lmodel_ambient = color;
#ifdef GSG_VERBOSE
dxgsg_cat.debug() << "dxLightModel(LIGHT_MODEL_AMBIENT, " << color << ")" << endl;
#endif
_d3dDevice->SetRenderState( D3DRENDERSTATE_AMBIENT,
D3DRGBA(color[0], color[1], color[2], color[3]));
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::call_glAlphaFunc
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
call_dxAlphaFunc(D3DCMPFUNC func, DWORD ref)
{
if (_alpha_func != func || _alpha_func_ref != ref) {
_alpha_func = func;
_alpha_func_ref = ref;
#ifdef GSG_VERBOSE
dxgsg_cat.debug() << "dxAlphaFunc(";
switch (func) {
case D3DCMP_NEVER:
dxgsg_cat.debug(false) << "D3DCMP_NEVER, ";
break;
case D3DCMP_LESS:
dxgsg_cat.debug(false) << "D3DCMP_LESS, ";
break;
case D3DCMP_EQUAL:
dxgsg_cat.debug(false) << "D3DCMP_EQUAL, ";
break;
case D3DCMP_LEQUAL:
dxgsg_cat.debug(false) << "D3DCMP_LEQUAL, ";
break;
case D3DCMP_GREATER:
dxgsg_cat.debug(false) << "D3DCMP_GREATER, ";
break;
case D3DCMP_NOTEQUAL:
dxgsg_cat.debug(false) << "D3DCMP_NOTEQUAL, ";
break;
case D3DCMP_GEQUAL:
dxgsg_cat.debug(false) << "D3DCMP_GEQUAL, ";
break;
case D3DCMP_ALWAYS:
dxgsg_cat.debug(false) << "D3DCMP_ALWAYS, ";
break;
}
dxgsg_cat.debug() << ref << ")" << endl;
#endif
_d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC, func);
_d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF, ref);
}
}
INLINE void DXGraphicsStateGuardian::
call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc )
{
if (_blend_source_func != sfunc)
{
_blend_source_func = sfunc;
_d3dDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, sfunc);
#ifdef GSG_VERBOSE
dxgsg_cat.debug() << "dxSrcBlendFunc(";
switch (sfunc)
{
case D3DBLEND_ZERO:
dxgsg_cat.debug(false) << "ZERO, ";
break;
case D3DBLEND_ONE:
dxgsg_cat.debug(false) << "ONE, ";
break;
case D3DBLEND_DESTCOLOR:
dxgsg_cat.debug(false) << "DESTCOLOR, ";
break;
case D3DBLEND_INVDESTCOLOR:
dxgsg_cat.debug(false) << "INVDESTCOLOR, ";
break;
case D3DBLEND_SRCALPHA:
dxgsg_cat.debug(false) << "SRCALPHA, ";
break;
case D3DBLEND_INVSRCALPHA:
dxgsg_cat.debug(false) << "INVSRCALPHA, ";
break;
case D3DBLEND_DESTALPHA:
dxgsg_cat.debug(false) << "DESTALPHA, ";
break;
case D3DBLEND_INVDESTALPHA:
dxgsg_cat.debug(false) << "INVDESTALPHA, ";
break;
case D3DBLEND_SRCALPHASAT:
dxgsg_cat.debug(false) << "SRCALPHASAT, ";
break;
default:
dxgsg_cat.debug(false) << "unknown, ";
break;
}
dxgsg_cat.debug(false) << endl;
#endif
}
if ( _blend_dest_func != dfunc)
{
_blend_dest_func = dfunc;
_d3dDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, dfunc);
#ifdef GSG_VERBOSE
dxgsg_cat.debug() << "dxDstBlendFunc(";
switch (dfunc)
{
case D3DBLEND_ZERO:
dxgsg_cat.debug(false) << "ZERO, ";
break;
case D3DBLEND_ONE:
dxgsg_cat.debug(false) << "ONE, ";
break;
case D3DBLEND_DESTCOLOR:
dxgsg_cat.debug(false) << "DESTCOLOR, ";
break;
case D3DBLEND_INVDESTCOLOR:
dxgsg_cat.debug(false) << "INVDESTCOLOR, ";
break;
case D3DBLEND_SRCALPHA:
dxgsg_cat.debug(false) << "SRCALPHA, ";
break;
case D3DBLEND_INVSRCALPHA:
dxgsg_cat.debug(false) << "INVSRCALPHA, ";
break;
case D3DBLEND_DESTALPHA:
dxgsg_cat.debug(false) << "DESTALPHA, ";
break;
case D3DBLEND_INVDESTALPHA:
dxgsg_cat.debug(false) << "INVDESTALPHA, ";
break;
case D3DBLEND_SRCALPHASAT:
dxgsg_cat.debug(false) << "SRCALPHASAT, ";
break;
}
dxgsg_cat.debug(false) << endl;
#endif
}
}
INLINE void DXGraphicsStateGuardian::
enable_zwritemask(bool val) {
if (_depth_write_enabled != val) {
_depth_write_enabled = val;
_d3dDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, val);
}
}
/** unimplemented
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_multisample
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_multisample(bool val) {
_multisample_enabled = val;
#ifdef NDEBUG
dxgsg_cat.error() << "dx multisample unimplemented!!\n";
#endif
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_multisample_alpha_one
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_multisample_alpha_one(bool val) {
if (_multisample_alpha_one_enabled != val) {
_multisample_alpha_one_enabled = val;
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_multisample_alpha_mask
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_multisample_alpha_mask(bool val) {
if (_multisample_alpha_mask_enabled != val) {
_multisample_alpha_mask_enabled = val;
}
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::enable_point_smooth
// Access:
// Description:
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
enable_point_smooth(bool val) {
// _point_smooth_enabled = val;
#ifdef NDEBUG
dxgsg_cat.error() << "dx point smoothing unimplemented!!\n";
#endif
}
*/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,494 @@
// Filename: dxGraphicsStateGuardian.h
// Created by: mike (02Feb99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef DXGRAPHICSSTATEGUARDIAN8_H
#define DXGRAPHICSSTATEGUARDIAN8_H
//#define GSG_VERBOSE
#include <pandabase.h>
#include <graphicsStateGuardian.h>
#include <geomprimitives.h>
#include <texture.h>
#include <pixelBuffer.h>
#include <displayRegion.h>
#include <material.h>
#include <textureApplyProperty.h>
#include <depthTestProperty.h>
#include <stencilProperty.h>
#include <fog.h>
#include <renderModeProperty.h>
#include <colorMatrixTransition.h>
#include <alphaTransformTransition.h>
#include <pointerToArray.h>
#include <planeNode.h>
#include "dxGeomNodeContext8.h"
#include "dxTextureContext8.h"
extern char * ConvD3DErrorToString(const HRESULT &error); // defined in wdxGraphicsPipe.cxx
class PlaneNode;
class Light;
#ifdef GSG_VERBOSE
ostream &output_gl_enum(ostream &out, GLenum v);
INLINE ostream &operator << (ostream &out, GLenum v) {
return output_gl_enum(out, v);
}
#endif
#ifdef DO_PSTATS
#define DO_PSTATS_STUFF(XX) XX;
#else
#define DO_PSTATS_STUFF(XX)
#endif
#define DX_DECLARE_CLEAN(type, var) \
type var; \
ZeroMemory(&var, sizeof(type)); \
var.dwSize = sizeof(type);
// #define DEBUG_RELEASES
// this is bDoDownToZero argument to RELEASE()
#define RELEASE_DOWN_TO_ZERO true
#ifdef DEBUG_RELEASES
#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) \
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(); dxgsg_cat.debug() << STR << " refcnt = " << (OBJECT)->Release() << endl; }
#else
#define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero) \
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
//#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS)
#ifdef _DEBUG
// This function now serves both to print a debug message to the
// console, as well as to notify PStats about the change in texture
// memory. Thus, we compile it in if we are building with support for
// either notify debug messages or PStats; otherwise, we compile it
// out.
extern void dbgPrintVidMem(LPDIRECTDRAW7 pDD, LPDDSCAPS2 lpddsCaps,const char *pMsg);
#define PRINTVIDMEM(pDD,pCaps,pMsg) dbgPrintVidMem(pDD,pCaps,pMsg)
#else
#define PRINTVIDMEM(pDD,pCaps,pMsg)
#endif
////////////////////////////////////////////////////////////////////
// Class : DXGraphicsStateGuardian
// Description : A GraphicsStateGuardian specialized for rendering
// into DX. There should be no DX calls
// outside of this object.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDADX DXGraphicsStateGuardian : public GraphicsStateGuardian {
friend class wdxGraphicsWindow;
friend class DXTextureContext;
public:
DXGraphicsStateGuardian(GraphicsWindow *win);
~DXGraphicsStateGuardian();
virtual void reset();
virtual void clear(const RenderBuffer &buffer);
virtual void clear(const RenderBuffer &buffer, const DisplayRegion* region);
virtual void prepare_display_region();
virtual void render_frame();
virtual void render_scene(Node *root, ProjectionNode *projnode);
virtual void render_subgraph(RenderTraverser *traverser,
Node *subgraph, ProjectionNode *projnode,
const AllTransitionsWrapper &net_trans);
virtual void render_subgraph(RenderTraverser *traverser,
Node *subgraph,
const AllTransitionsWrapper &net_trans);
virtual void draw_point(GeomPoint *geom, GeomContext *gc);
virtual void draw_line(GeomLine *geom, GeomContext *gc);
virtual void draw_linestrip(GeomLinestrip *geom, GeomContext *gc);
void draw_linestrip_base(Geom *geom, GeomContext *gc, bool bConnectEnds);
virtual void draw_sprite(GeomSprite *geom, GeomContext *gc);
virtual void draw_polygon(GeomPolygon *geom, GeomContext *gc);
virtual void draw_quad(GeomQuad *geom, GeomContext *gc);
virtual void draw_tri(GeomTri *geom, GeomContext *gc);
virtual void draw_tristrip(GeomTristrip *geom, GeomContext *gc);
virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc);
virtual void draw_sphere(GeomSphere *geom, GeomContext *gc);
virtual GeomNodeContext *prepare_geom_node(GeomNode *node);
virtual void draw_geom_node(GeomNode *node, GeomNodeContext *gnc);
virtual void release_geom_node(GeomNodeContext *gnc);
virtual TextureContext *prepare_texture(Texture *tex);
virtual void apply_texture(TextureContext *tc);
virtual void release_texture(TextureContext *tc);
virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr);
virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr,
const RenderBuffer &rb);
virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr);
virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr,
const RenderBuffer &rb);
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb);
virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
const DisplayRegion *dr);
virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr);
virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
const RenderBuffer &rb);
virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
const NodeTransitions& na=NodeTransitions());
virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
const RenderBuffer &rb,
const NodeTransitions& na=NodeTransitions());
virtual void apply_material(const Material *material);
virtual void apply_fog(Fog *fog);
virtual void apply_light(PointLight* light);
virtual void apply_light(DirectionalLight* light);
virtual void apply_light(Spotlight* light);
virtual void apply_light(AmbientLight* light);
virtual void issue_transform(const TransformTransition *attrib);
virtual void issue_tex_matrix(const TexMatrixTransition *attrib);
virtual void issue_color(const ColorTransition *attrib);
virtual void issue_color_transform(const ColorMatrixTransition *);
virtual void issue_alpha_transform(const AlphaTransformTransition *);
virtual void issue_texture(const TextureTransition *attrib);
virtual void issue_light(const LightTransition *attrib);
virtual void issue_material(const MaterialTransition *attrib);
virtual void issue_render_mode(const RenderModeTransition *attrib);
virtual void issue_color_blend(const ColorBlendTransition *attrib);
virtual void issue_texture_apply(const TextureApplyTransition *attrib);
virtual void issue_color_mask(const ColorMaskTransition *attrib);
virtual void issue_depth_test(const DepthTestTransition *attrib);
virtual void issue_depth_write(const DepthWriteTransition *attrib);
virtual void issue_tex_gen(const TexGenTransition *attrib);
virtual void issue_cull_face(const CullFaceTransition *attrib);
virtual void issue_stencil(const StencilTransition *attrib);
virtual void issue_clip_plane(const ClipPlaneTransition *attrib);
virtual void issue_transparency(const TransparencyTransition *attrib);
virtual void issue_fog(const FogTransition *attrib);
virtual void issue_linesmooth(const LinesmoothTransition *attrib);
virtual bool wants_normals(void) const;
virtual bool wants_texcoords(void) const;
virtual bool wants_colors(void) const;
virtual void begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib);
virtual void end_decal(GeomNode *base_geom);
INLINE float compute_distance_to(const LPoint3f &point) const;
virtual void set_color_clear_value(const Colorf& value);
public:
// recreate_tex_callback needs these to be public
LPDIRECT3DDEVICE7 _d3dDevice;
LPDDPIXELFORMAT _pTexPixFmts;
int _cNumTexPixFmts;
protected:
void free_pointers(); // free local internal buffers
void free_dxgsg_objects(void); // free the DirectX objects we create
virtual PT(SavedFrameBuffer) save_frame_buffer(const RenderBuffer &buffer,
CPT(DisplayRegion) dr);
virtual void restore_frame_buffer(SavedFrameBuffer *frame_buffer);
void set_draw_buffer(const RenderBuffer &rb);
void set_read_buffer(const RenderBuffer &rb);
void bind_texture(TextureContext *tc);
// for storage of the flexible vertex format
char *_pCurFvfBufPtr,*_pFvfBufBasePtr;
INLINE void add_to_FVFBuf(void *data, size_t bytes) ;
WORD *_index_buf; // base of malloced array
bool _dx_ready;
HRESULT _last_testcooplevel_result;
bool _bIsTNLDevice;
LPDIRECTDRAWSURFACE7 _back;
LPDIRECTDRAWSURFACE7 _zbuf;
LPDIRECT3D7 _d3d;
LPDIRECTDRAWSURFACE7 _pri;
LPDIRECTDRAW7 _pDD;
RECT _view_rect;
RECT clip_rect;
HDC _front_hdc;
DXTextureContext *_pCurTexContext;
bool _bTransformIssued; // decaling needs to tell when a transform has been issued
D3DMATRIX _SavedTransform;
RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation
D3DDEVICEDESC7 _D3DDevDesc;
void GenerateSphere(void *pVertexSpace,DWORD dwVertSpaceByteSize,
void *pIndexSpace,DWORD dwIndexSpaceByteSize,
D3DVECTOR *pCenter, float fRadius,
DWORD wNumRings, DWORD wNumSections, float sx, float sy, float sz,
DWORD *pNumVertices,DWORD *pNumIndices,DWORD fvfFlags,DWORD dwVertSize);
HRESULT RestoreAllVideoSurfaces(void);
HRESULT RecreateAllVideoSurfaces(void);
HRESULT DeleteAllVideoSurfaces(void);
/*
INLINE void enable_multisample_alpha_one(bool val);
INLINE void enable_multisample_alpha_mask(bool val);
INLINE void enable_multisample(bool val);
*/
INLINE void enable_color_material(bool val);
INLINE void enable_clip_plane(int clip_plane, bool val);
INLINE void enable_fog(bool val);
INLINE void enable_zwritemask(bool val);
INLINE void set_shademode(D3DSHADEMODE val);
INLINE D3DTEXTUREADDRESS get_texture_wrap_mode(Texture::WrapMode wm) const;
INLINE D3DCMPFUNC get_depth_func_type(DepthTestProperty::Mode m) const;
INLINE D3DFOGMODE get_fog_mode_type(Fog::Mode m) const;
INLINE D3DCMPFUNC get_stencil_func_type(StencilProperty::Mode m) const;
INLINE D3DSTENCILOP get_stencil_action_type(StencilProperty::Action a) const;
INLINE void enable_primitive_clipping(bool val);
INLINE void enable_alpha_test(bool val);
INLINE void enable_line_smooth(bool val);
INLINE void enable_blend(bool val);
INLINE void enable_point_smooth(bool val);
INLINE void enable_texturing(bool val);
INLINE void call_dxLightModelAmbient(const Colorf& color);
INLINE void call_dxAlphaFunc(D3DCMPFUNC func, DWORD ref);
INLINE void call_dxBlendFunc(D3DBLEND sfunc, D3DBLEND dfunc);
INLINE void enable_lighting(bool val);
INLINE void enable_dither(bool val);
INLINE void enable_stencil_test(bool val);
bool enable_light(int light, bool val);
void report_texmgr_stats();
void draw_multitri(Geom *geom, D3DPRIMITIVETYPE tri_id);
void draw_prim_inner_loop(int nVerts, const Geom *geom, ushort perFlags);
void draw_prim_inner_loop_coordtexonly(int nVerts, const Geom *geom);
size_t draw_prim_setup(const Geom *geom) ;
// for drawing primitives
Normalf p_normal; // still used to hold G_OVERALL, G_PER_PRIM values
TexCoordf p_texcoord;
D3DCOLOR _curD3Dcolor;
DWORD _curFVFflags;
DWORD _perPrim,_perVertex,_perComp; // these hold DrawLoopFlags bitmask values
bool _issued_color_enabled; // WBD ADDED
bool _enable_all_color;
Colorf _issued_color; // WBD ADDED
D3DCOLOR _issued_color_D3DCOLOR; // WBD ADDED
D3DCOLOR _d3dcolor_clear_value;
D3DSHADEMODE _CurShadeMode;
bool _bDrawPrimDoSetupVertexBuffer; // if true, draw methods just copy vertex data into pCurrentGeomContext
DXGeomNodeContext *_pCurrentGeomContext; // used in vertex buffer setup
// iterators for primitives
Geom::VertexIterator vi;
Geom::NormalIterator ni;
Geom::TexCoordIterator ti;
Geom::ColorIterator ci;
// these are used for fastpaths that bypass the iterators above
// pointers to arrays in current geom, used to traverse indexed and non-indexed arrays
Vertexf *_coord_array,*_pCurCoord;
ushort *_coordindex_array,*_pCurCoordIndex;
TexCoordf *_texcoord_array,*_pCurTexCoord;
ushort *_texcoordindex_array,*_pCurTexCoordIndex;
/*
PTA_Normalf _norms;
PTA_Colorf _colors;
PTA_ushort _cindexes,_nindexes;
*/
Colorf _lmodel_ambient;
float _material_ambient;
float _material_diffuse;
float _material_specular;
float _material_shininess;
float _material_emission;
typedef enum {None,
PerVertexFog=D3DRENDERSTATE_FOGVERTEXMODE,
PerPixelFog=D3DRENDERSTATE_FOGTABLEMODE
} DxgsgFogType;
DxgsgFogType _doFogType;
bool _fog_enabled;
/*
TODO: cache fog state
float _fog_start;
float _fog_end;
float _fog_density;
float _fog_color;
*/
float _alpha_func_ref;
D3DCMPFUNC _alpha_func;
D3DBLEND _blend_source_func;
D3DBLEND _blend_dest_func;
bool _line_smooth_enabled;
bool* _light_enabled; // bool[_max_lights]
bool _color_material_enabled;
bool _lighting_enabled;
bool _lighting_enabled_this_frame;
bool _texturing_enabled;
bool _clipping_enabled;
bool _dither_enabled;
bool _stencil_test_enabled;
bool* _clip_plane_enabled; // bool[_max_clip_planes]
bool _blend_enabled;
bool _depth_test_enabled;
bool _depth_write_enabled;
bool _alpha_test_enabled;
int _decal_level;
RenderModeProperty::Mode _current_fill_mode; //poinr/wireframe/solid
GraphicsChannel *_panda_gfx_channel; // cache the 1 channel dx supports
// Cur Texture State
TextureApplyProperty::Mode _CurTexBlendMode;
Texture::FilterType _CurTexMagFilter,_CurTexMinFilter;
DWORD _CurTexAnisoDegree;
Texture::WrapMode _CurTexWrapModeU,_CurTexWrapModeV;
PTA(Light*) _available_light_ids;
int _max_lights;
bool* _cur_light_enabled;
int _cur_light_id;
Colorf _cur_ambient_light;
LMatrix4f _current_projection_mat;
int _projection_mat_stack_count;
PTA(PlaneNode*) _available_clip_plane_ids;
int _max_clip_planes;
bool* _cur_clip_plane_enabled;
int _cur_clip_plane_id;
CPT(DisplayRegion) _actual_display_region;
// Color/Alpha Matrix Transition stuff
INLINE void transform_color(Colorf &InColor,D3DCOLOR &OutColor);
bool _color_transform_required; // _color_transform_enabled || _alpha_transform_enabled
bool _color_transform_enabled;
bool _alpha_transform_enabled;
LMatrix4f _current_color_mat;
float _current_alpha_offset;
float _current_alpha_scale;
// vars for frames/sec meter
DWORD _start_time;
DWORD _start_frame_count;
DWORD _cur_frame_count;
float _current_fps;
DWORD *_fpsmeter_verts;
DWORD _fpsmeter_fvfflags;
LPDIRECTDRAWSURFACE7 _fpsmeter_font_surf;
float _fps_u_usedwidth,_fps_v_usedheight; // fraction of fps font texture actually used
DWORD _fps_vertexsize; // size of verts used to render fps meter
void SetFPSMeterPosition(RECT &view_rect);
void FillFPSMeterTexture(void);
public:
static GraphicsStateGuardian*
make_DXGraphicsStateGuardian(const FactoryParams &params);
static TypeHandle get_class_type(void);
static void init_type(void);
virtual TypeHandle get_type(void) const;
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
LPDIRECT3DDEVICE7 GetD3DDevice() { return _d3dDevice; }
LPDIRECTDRAW7 GetDDInterface() { return _pDD; }
LPDIRECTDRAWSURFACE7 GetBackBuffer() { return _back; }
LPDIRECTDRAWSURFACE7 GetZBuffer() { return _zbuf; }
INLINE void Set_HDC(HDC hdc) { _front_hdc = hdc; }
void adjust_view_rect(int x, int y);
INLINE void SetDXReady(bool stat) { _dx_ready = stat; }
INLINE bool GetDXReady(void) { return _dx_ready;}
void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode TexBlendMode,bool bJustEnable);
void dx_cleanup(bool bRestoreDisplayMode,bool bAtExitFnCalled);
#define DO_REACTIVATE_WINDOW true
bool CheckCooperativeLevel(bool bDoReactivateWindow = false);
void dx_setup_after_resize(RECT viewrect,HWND mwindow) ;
void show_frame();
void show_full_screen_frame();
void show_windowed_frame();
void dx_init( LPDIRECTDRAW7 context,
LPDIRECTDRAWSURFACE7 pri,
LPDIRECTDRAWSURFACE7 back,
LPDIRECTDRAWSURFACE7 zbuf,
LPDIRECT3D7 d3d,
LPDIRECT3DDEVICE7 d3dDevice,
RECT viewrect);
friend HRESULT CALLBACK EnumTexFmtsCallback( LPDDPIXELFORMAT pddpf, VOID* param );
private:
static TypeHandle _type_handle;
};
#define ISPOW2(X) (((X) & ((X)-1))==0)
#include "dxGraphicsStateGuardian8.I"
#endif

View File

@ -0,0 +1,39 @@
// Filename: dxSavedFrameBuffer.I
// Created by: drose (06Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: DXSavedFrameBuffer::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE DXSavedFrameBuffer::
DXSavedFrameBuffer(const RenderBuffer &buffer, CPT(DisplayRegion) dr) :
SavedFrameBuffer(buffer, dr)
{
}
////////////////////////////////////////////////////////////////////
// Function: DXSavedFrameBuffer::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE DXSavedFrameBuffer::
~DXSavedFrameBuffer() {
}

View File

@ -0,0 +1,21 @@
// Filename: dxSavedFrameBuffer.cxx
// Created by: drose (06Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "dxSavedFrameBuffer8.h"
TypeHandle DXSavedFrameBuffer::_type_handle;

View File

@ -0,0 +1,64 @@
// Filename: dxSavedFrameBuffer.h
// Created by: drose (06Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef DXSAVEDFRAMEBUFFER8_H
#define DXSAVEDFRAMEBUFFER8_H
#include <pandabase.h>
#include <savedFrameBuffer.h>
#include <texture.h>
#include <textureContext.h>
#include <pixelBuffer.h>
////////////////////////////////////////////////////////////////////
// Class : DXSavedFrameBuffer
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDADX DXSavedFrameBuffer : public SavedFrameBuffer {
public:
INLINE DXSavedFrameBuffer(const RenderBuffer &buffer,
CPT(DisplayRegion) dr);
INLINE ~DXSavedFrameBuffer();
PT(Texture) _back_rgba;
PT(PixelBuffer) _depth;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
SavedFrameBuffer::init_type();
register_type(_type_handle, "DXSavedFrameBuffer",
SavedFrameBuffer::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 "dxSavedFrameBuffer8.I"
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,89 @@
// Filename: dxTextureContext.h
// Created by: drose (07Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef DXTEXTURECONTEXT8_H
#define DXTEXTURECONTEXT8_H
#include <pandabase.h>
#define WIN32_LEAN_AND_MEAN
#ifndef STRICT
// enable strict type checking in windows.h, see msdn
#define STRICT
#endif
#include <windows.h>
#include <ddraw.h>
#define D3D_OVERLOADS // get D3DVECTOR '+' operator, etc from d3dtypes.h
#include <d3d.h>
#undef WIN32_LEAN_AND_MEAN
#include <texture.h>
#include <textureContext.h>
#define MAX_DX_TEXPIXFMTS 20 // should be enough for any card
////////////////////////////////////////////////////////////////////
// Class : DXTextureContext
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDADX DXTextureContext : public TextureContext {
friend class DXGraphicsStateGuardian;
friend class wdxGraphicsWindow;
public:
DXTextureContext(Texture *tex);
~DXTextureContext();
LPDIRECTDRAWSURFACE7 _surface;
Texture *_tex; // ptr to parent, primarily for access to namestr
LPDIRECTDRAWSURFACE7 CreateTexture(LPDIRECT3DDEVICE7 pd3dDevice, int cNumTexPixFmts, LPDDPIXELFORMAT pTexPixFmts);
bool _bHasMipMaps;
DWORD _PixBufConversionType; // enum ConversionType
// must be public since called from global callback fns
void DeleteTexture(void);
HRESULT FillDDSurfTexturePixels(void);
protected:
unsigned int get_bits_per_pixel(PixelBuffer::Format format, int *alphbits);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TextureContext::init_type();
register_type(_type_handle, "DXTextureContext",
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;
};
#endif

View File

@ -0,0 +1,4 @@
#include "config_dxgsg8.cxx"
#include "dxSavedFrameBuffer8.cxx"
#include "dxTextureContext8.cxx"
#include "dxGeomNodeContext8.cxx"

View File

@ -0,0 +1,20 @@
#define DIRECTORY_IF_DX yes
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
dtoolutil:c dtoolbase:c dtool:m
#define USE_DX yes
#if $[BUILD_DX8]
#begin lib_target
#define TARGET wdxdisplay8
#define LOCAL_LIBS dxgsg8
#define COMBINED_SOURCES $[TARGET]_composite1.cxx
#define SOURCES \
config_wdxdisplay8.h wdxGraphicsPipe8.h wdxGraphicsWindow8.cxx wdxGraphicsWindow8.h
#define INCLUDED_SOURCES config_wdxdisplay8.cxx wdxGraphicsPipe8.cxx
#end lib_target
#endif

View File

@ -0,0 +1,80 @@
// Filename: config_wdxdisplay.cxx
// Created by: mike (07Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "config_wdxdisplay8.h"
#include "wdxGraphicsPipe8.h"
#include "wdxGraphicsWindow8.h"
#include <dconfig.h>
Configure(config_wdxdisplay);
NotifyCategoryDef(wdxdisplay, "display");
ConfigureFn(config_wdxdisplay) {
init_libwdxdisplay8();
}
bool dx_force_16bpp_zbuffer = config_wdxdisplay.GetBool("dx-force-16bpp-zbuffer", false);
bool bResponsive_minimized_fullscreen_window = config_wdxdisplay.GetBool("responsive-minimized-fullscreen-window",false);
extern void AtExitFn(void);
////////////////////////////////////////////////////////////////////
// Function: init_libwdxdisplay
// 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_libwdxdisplay8() {
static bool initialized = false;
if (initialized) {
return;
}
initialized = true;
atexit(AtExitFn);
wdxGraphicsPipe::init_type();
GraphicsPipe::get_factory().register_factory(
wdxGraphicsPipe::get_class_type(),
wdxGraphicsPipe::make_wdxGraphicsPipe);
wdxGraphicsWindow::init_type();
GraphicsWindow::get_factory().register_factory(
wdxGraphicsWindow::get_class_type(),
wdxGraphicsWindow::make_wdxGraphicsWindow);
set_global_parameters();
}
// cant use global var cleanly because global var static init executed after init_libwdxdisplay(), incorrectly reiniting var
Filename get_icon_filename() {
string iconname = config_wdxdisplay.GetString("win32-window-icon","");
return ExecutionEnvironment::expand_string(iconname);
}
Filename get_color_cursor_filename() {
string cursorname = config_wdxdisplay.GetString("win32-color-cursor","");
return ExecutionEnvironment::expand_string(cursorname);
}
Filename get_mono_cursor_filename() {
string cursorname = config_wdxdisplay.GetString("win32-mono-cursor","");
return ExecutionEnvironment::expand_string(cursorname);
}

View File

@ -0,0 +1,36 @@
// Filename: config_wdxdisplay.h
// Created by: mike (07Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef __CONFIG_WDXDISPLAY8_H__
#define __CONFIG_WDXDISPLAY8_H__
#include <pandabase.h>
#include <filename.h>
#include <notifyCategoryProxy.h>
NotifyCategoryDecl(wdxdisplay, EXPCL_PANDADX, EXPTP_PANDADX);
extern bool bResponsive_minimized_fullscreen_window;
extern bool dx_force_16bpp_zbuffer;
extern Filename get_icon_filename();
extern Filename get_mono_cursor_filename();
extern Filename get_color_cursor_filename();
extern EXPCL_PANDADX void init_libwdxdisplay8();
#endif /* __CONFIG_WDXDISPLAY_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,82 @@
// Filename: wdxGraphicsPipe.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef WDXGRAPHICSPIPE8_H
#define WDXGRAPHICSPIPE8_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include <pandabase.h>
#include <string>
#include <interactiveGraphicsPipe.h>
#include "wdxGraphicsWindow8.h"
#ifndef STRICT
#define STRICT
#endif
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#undef WINDOWS_LEAN_AND_MEAN
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
class Xclass;
extern char * ConvD3DErrorToString(const HRESULT &error);
////////////////////////////////////////////////////////////////////
// Class : wdxGraphicsPipe
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDADX wdxGraphicsPipe : public InteractiveGraphicsPipe {
public:
wdxGraphicsPipe(const PipeSpecifier&);
wdxGraphicsWindow* find_window(HWND win);
// ButtonHandle lookup_key(WPARAM wparam) const;
virtual TypeHandle get_window_type() const;
public:
static GraphicsPipe* make_wdxGraphicsPipe(const FactoryParams &params);
static TypeHandle get_class_type(void);
static void init_type(void);
virtual TypeHandle get_type(void) const;
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
// int _width;
// int _height;
bool _shift;
protected:
wdxGraphicsPipe(void);
wdxGraphicsPipe(const wdxGraphicsPipe&);
wdxGraphicsPipe& operator=(const wdxGraphicsPipe&);
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,144 @@
// Filename: wdxGraphicsWindow.h
// Created by: mike (09Jan97)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef WDXGRAPHICSWINDOW8_H
#define WDXGRAPHICSWINDOW8_H
//#define WBD_GL_MODE 1 // if setting this, do it in dxGraphicsStateGuardian.h too
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include <pandabase.h>
#include <graphicsWindow.h>
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#undef WINDOWS_LEAN_AND_MEAN
#include <d3d.h>
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
class wdxGraphicsPipe;
const int WDXWIN_CONFIGURE = 4;
const int WDXWIN_EVENT = 8;
////////////////////////////////////////////////////////////////////
// Class : wdxGraphicsWindow
// Description :
////////////////////////////////////////////////////////////////////
class EXPCL_PANDADX wdxGraphicsWindow : public GraphicsWindow {
friend class DXGraphicsStateGuardian;
friend class DXTextureContext;
public:
wdxGraphicsWindow(GraphicsPipe* pipe);
wdxGraphicsWindow(GraphicsPipe* pipe,
const GraphicsWindow::Properties& props);
virtual ~wdxGraphicsWindow(void);
virtual bool supports_update() const;
virtual void update(void);
virtual void end_frame( void );
virtual TypeHandle get_gsg_type() const;
static GraphicsWindow* make_wdxGraphicsWindow(const FactoryParams &params);
void CreateScreenBuffersAndDevice(DWORD dwRenderWidth, DWORD dwRenderHeight,
LPDIRECTDRAW7 pDD,LPDIRECT3D7 pD3DI,
D3DDEVICEDESC7 *pD3DDevDesc);
LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
void process_events(void);
INLINE bool mouse_entry_enabled(void) { return _mouse_entry_enabled; }
INLINE bool mouse_motion_enabled(void) { return _mouse_motion_enabled; }
INLINE bool mouse_passive_motion_enabled(void) {
return _mouse_passive_motion_enabled;
}
void handle_window_move( int x, int y );
void handle_mouse_motion( int x, int y );
void handle_mouse_entry( int state, HCURSOR hMouseCursor );
void handle_keypress( ButtonHandle key, int x, int y );
void handle_keyrelease( ButtonHandle key);
void dx_setup();
virtual void begin_frame( void );
void show_frame();
DXGraphicsStateGuardian *_dxgsg;
virtual void resize(unsigned int xsize,unsigned int ysize);
virtual unsigned int verify_window_sizes(unsigned int numsizes,unsigned int *dimen);
virtual int get_depth_bitwidth(void);
protected:
void CreateScreenBuffersAndDevice(LPDIRECTDRAW7 pDD,LPDIRECT3D7 pD3DI);
ButtonHandle lookup_key(WPARAM wparam) const;
virtual void config( void );
void setup_colormap(void);
void enable_mouse_input(bool val);
void enable_mouse_motion(bool val);
void enable_mouse_passive_motion(bool val);
void enable_mouse_entry(bool val);
void check_for_color_cursor_support(void);
DDDEVICEIDENTIFIER2 _DXDeviceID;
public:
HWND _mwindow;
HWND _hOldForegroundWindow;
UINT_PTR _PandaPausedTimer;
private:
HDC _hdc;
HPALETTE _colormap;
typedef enum { NotAdjusting,MovingOrResizing,Resizing } WindowAdjustType;
WindowAdjustType _WindowAdjustingType;
bool _bIsLowVidMemCard;
bool _bLoadedCustomCursor;
HCURSOR _hMouseCursor;
bool _bSizeIsMaximized;
bool _mouse_input_enabled;
bool _mouse_motion_enabled;
bool _mouse_passive_motion_enabled;
bool _mouse_entry_enabled;
bool _exiting_window;
bool _window_inactive;
bool _active_minimized_fullscreen;
bool _return_control_to_app;
int _depth_buffer_bpp;
public:
static TypeHandle get_class_type(void);
static void init_type(void);
virtual TypeHandle get_type(void) const;
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
void DestroyMe(bool bAtExitFnCalled);
virtual void do_close_window();
void deactivate_window(void);
void reactivate_window(void);
void handle_reshape(bool bDoDXReset);
private:
static TypeHandle _type_handle;
};
extern void set_global_parameters(void);
extern void restore_global_parameters(void);
#endif

View File

@ -0,0 +1,4 @@
#include "config_wdxdisplay8.cxx"
#include "wdxGraphicsPipe8.cxx"