implement copy_pixel_buffer

This commit is contained in:
cxgeorge 2001-02-24 03:45:48 +00:00
parent 32052691ad
commit 1fa8b1c6c0
2 changed files with 3534 additions and 3583 deletions

View File

@ -117,6 +117,8 @@ DXGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) {
_pDD = NULL;
_d3dDevice = NULL;
_cur_read_pixel_buffer=RenderBuffer::T_front;
ZeroMemory(&matIdentity,sizeof(D3DMATRIX));
matIdentity._11 = matIdentity._22 = matIdentity._33 = matIdentity._44 = 1.0f;
@ -206,8 +208,8 @@ reset() {
_alpha_func_ref = 0;
// _polygon_mode = GL_FILL;
_pack_alignment = 4;
_unpack_alignment = 4;
// _pack_alignment = 4;
// _unpack_alignment = 4;
// Set up all the enabled/disabled flags to GL's known initial
// values: everything off.
@ -230,8 +232,7 @@ reset() {
_dx_ready = false;
}
HRESULT CALLBACK EnumTexFmtsCallback( LPDDPIXELFORMAT pddpf, VOID* param )
{
HRESULT CALLBACK EnumTexFmtsCallback( LPDDPIXELFORMAT pddpf, VOID* param ) {
// wont build if its a member fn, so had to do this stuff
DXGraphicsStateGuardian *mystate = (DXGraphicsStateGuardian *) param;
assert(mystate->_cNumTexPixFmts < MAX_DX_TEXPIXFMTS);
@ -253,8 +254,7 @@ init_dx( LPDIRECTDRAW7 context,
LPDIRECTDRAWSURFACE7 zbuf,
LPDIRECT3D7 pD3D,
LPDIRECT3DDEVICE7 pDevice,
RECT viewrect)
{
RECT viewrect) {
_pDD = context;
_pri = pri;
_back = back;
@ -287,6 +287,7 @@ init_dx( LPDIRECTDRAW7 context,
if ((dx_decal_type==GDT_offset) && !(_D3DDevDesc.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_ZBIAS)) {
#ifdef _DEBUG
// dx7 doesnt support PLANEMASK renderstate
#if(DIRECT3D_VERSION < 0x700)
dxgsg_cat.error() << "dx-decal-type 'offset' not supported by hardware, switching to decal masking\n";
@ -509,10 +510,8 @@ clear(const RenderBuffer &buffer, const DisplayRegion *region) {
// Description:
////////////////////////////////////////////////////////////////////
bool DXGraphicsStateGuardian::
enable_light(int light, bool val)
{
if ( _light_enabled[light] != val )
{
enable_light(int light, bool val) {
if (_light_enabled[light] != val) {
_light_enabled[light] = val;
HRESULT res = _d3dDevice->LightEnable( light, val );
@ -575,6 +574,7 @@ prepare_display_region() {
// Description: Useless in DX at the present time
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::set_clipper(RECT cliprect) {
#if 0
LPDIRECTDRAWCLIPPER Clipper;
HRESULT result;
@ -597,23 +597,22 @@ void DXGraphicsStateGuardian::set_clipper(RECT cliprect) {
HRGN hrgn = CreateRectRgn(cliprect.left, cliprect.top, cliprect.right, cliprect.bottom);
GetRegionData(hrgn, sizeof(RGNDATAHEADER) + sizeof(RECT), rgn_data);
if (_pri->GetClipper(&Clipper) != DD_OK)
{
if (_pri->GetClipper(&Clipper) != DD_OK) {
result = _pDD->CreateClipper(0, &Clipper, NULL);
result = Clipper->SetClipList(rgn_data, 0);
result = _pri->SetClipper(Clipper);
}
else {
} else {
result = Clipper->SetClipList(rgn_data, 0 );
if (result == DDERR_CLIPPERISUSINGHWND)
{
if (result == DDERR_CLIPPERISUSINGHWND) {
result = _pri->SetClipper(NULL);
result = _pDD->CreateClipper(0, &Clipper, NULL);
result = Clipper->SetClipList(rgn_data, 0 ) ;
result = _pri->SetClipper(Clipper);
}
}
free(rgn_data);
DeleteObject(hrgn);
#endif
}
////////////////////////////////////////////////////////////////////
@ -646,29 +645,22 @@ render_frame(const AllAttributesWrapper &initial_state) {
// Now render each of our layers in order.
int max_channel_index = _win->get_max_channel_index();
for (int c = 0; c < max_channel_index; c++)
{
if (_win->is_channel_defined(c))
{
for (int c = 0; c < max_channel_index; c++) {
if (_win->is_channel_defined(c)) {
GraphicsChannel *chan = _win->get_channel(c);
if (chan->is_active())
{
if (chan->is_active()) {
int num_layers = chan->get_num_layers();
for (int l = 0; l < num_layers; l++)
{
for (int l = 0; l < num_layers; l++) {
GraphicsLayer *layer = chan->get_layer(l);
if (layer->is_active())
{
if (layer->is_active()) {
int num_drs = layer->get_num_drs();
for (int d = 0; d < num_drs; d++)
{
for (int d = 0; d < num_drs; d++) {
DisplayRegion *dr = layer->get_dr(d);
Camera *cam = dr->get_camera();
// For each display region, render from the camera's view.
if (dr->is_active() && cam != (Camera *)NULL &&
cam->is_active() && cam->get_scene() != (Node *)NULL)
{
cam->is_active() && cam->get_scene() != (Node *)NULL) {
DisplayRegionStack old_dr = push_display_region(dr);
prepare_display_region();
render_scene(cam->get_scene(), cam, initial_state);
@ -687,8 +679,7 @@ render_frame(const AllAttributesWrapper &initial_state) {
// cache--to force the lights to be reissued next frame, in case
// their parameters or positions have changed between frames.
for (int i = 0; i < _max_lights; i++)
{
for (int i = 0; i < _max_lights; i++) {
enable_light(i, false);
_available_light_ids[i] = NULL;
}
@ -910,8 +901,7 @@ render_subgraph(RenderTraverser *traverser, Node *subgraph,
// Description: This adds data to the flexible vertex format
////////////////////////////////////////////////////////////////////
INLINE void DXGraphicsStateGuardian::
add_to_FVFBuf(void *data, size_t bytes)
{
add_to_FVFBuf(void *data, size_t bytes) {
memcpy(_pCurFvfBufPtr, data, bytes);
_pCurFvfBufPtr += bytes;
@ -920,7 +910,9 @@ add_to_FVFBuf(void *data, size_t bytes)
// generates slightly fewer instrs
#define add_DWORD_to_FVFBuf(data) { *((DWORD *)_pCurFvfBufPtr) = (DWORD) data; _pCurFvfBufPtr += sizeof(DWORD);}
typedef enum {FlatVerts,IndexedVerts,MixedFmtVerts} GeomVertFormat;
typedef enum {
FlatVerts,IndexedVerts,MixedFmtVerts
} GeomVertFormat;
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::draw_point
@ -1126,16 +1118,12 @@ draw_line(const GeomLine* geom) {
nassertv(_pCurFvfBufPtr == NULL); // make sure the storage pointer is clean.
// nassertv(nPrims * 2 * vertex_size < VERT_BUFFER_SIZE);
if (nPrims * 2 * vertex_size > VERT_BUFFER_SIZE)
{
if (nPrims * 2 * vertex_size > VERT_BUFFER_SIZE) {
_pCurFvfBufPtr = _tmp_fvf = new char[nPrims * 2 * vertex_size];
}
else _pCurFvfBufPtr = _pFvfBufBasePtr; // _pCurFvfBufPtr changes, _pFvfBufBasePtr doesn't
} else _pCurFvfBufPtr = _pFvfBufBasePtr; // _pCurFvfBufPtr changes, _pFvfBufBasePtr doesn't
for (int i = 0; i < nPrims; i++)
{
if (perPrim & PerColor)
{
for (int i = 0; i < nPrims; i++) {
if (perPrim & PerColor) {
p_color = geom->get_next_color(ci); // set primitive color if there is one.
p_colr = D3DRGBA(p_color[0], p_color[1], p_color[2], p_color[3]);
}
@ -1256,10 +1244,8 @@ draw_linestrip(const GeomLinestrip* geom) {
size_t vertex_size = draw_prim_setup(geom);
for (int i = 0; i < nPrims; i++)
{
if (perPrim & PerColor)
{
for (int i = 0; i < nPrims; i++) {
if (perPrim & PerColor) {
p_color = geom->get_next_color(ci); // set primitive color if there is one.
p_colr = D3DRGBA(p_color[0], p_color[1], p_color[2], p_color[3]);
}
@ -1750,8 +1736,7 @@ draw_prim_setup(const Geom *geom) {
vertex_size += sizeof(float) * 2;
}
if (geom->get_binding(G_COLOR) == G_OVERALL)
{
if (geom->get_binding(G_COLOR) == G_OVERALL) {
p_color = geom->get_next_color(ci); // set overall color if there is one
p_colr = D3DRGBA(p_color[0], p_color[1], p_color[2], p_color[3]);
}
@ -1783,10 +1768,8 @@ draw_prim_setup(const Geom *geom) {
void DXGraphicsStateGuardian::
draw_prim_inner_loop(int loops, const Geom *geom) {
while (--loops >= 0)
{
switch(perVertex)
{
while (--loops >= 0) {
switch (perVertex) {
case 0x3:
p_normal = geom->get_next_normal(ni);
case 0x1:
@ -1995,8 +1978,7 @@ draw_tri(const GeomTri *geom) {
// iterate through the triangle primitive
for (int i = 0; i < nPrims; i++) {
if (perPrim & PerColor)
{
if (perPrim & PerColor) {
p_color = geom->get_next_color(ci); // set primitive color if there is one.
p_colr = D3DRGBA(p_color[0], p_color[1], p_color[2], p_color[3]);
}
@ -2376,8 +2358,7 @@ draw_multitri(const Geom *geom, D3DPRIMITIVETYPE trilisttype) {
for (int i = 0; i < nPrims; i++) {
if (perPrim & PerColor)
{
if (perPrim & PerColor) {
p_color = geom->get_next_color(ci); // set primitive color if there is one.
p_colr = D3DRGBA(p_color[0], p_color[1], p_color[2], p_color[3]);
}
@ -2392,8 +2373,7 @@ draw_multitri(const Geom *geom, D3DPRIMITIVETYPE trilisttype) {
nassertv(nVerts * vertex_size < VERT_BUFFER_SIZE);
_pCurFvfBufPtr = _pFvfBufBasePtr; // _pCurFvfBufPtr changes, _pFvfBufBasePtr doesn't
if (perComp & PerColor)
{
if (perComp & PerColor) {
p_color = geom->get_next_color(ci); // set overall color if there is one
p_colr = D3DRGBA(p_color[0], p_color[1], p_color[2], p_color[3]);
}
@ -2935,8 +2915,7 @@ issue_color_transform(const ColorMatrixAttribute *attrib) {
if (_current_color_mat == LMatrix4f::ident_mat()) {
_color_transform_enabled = false;
}
else {
} else {
_color_transform_enabled = true;
}
}
@ -2953,8 +2932,7 @@ issue_alpha_transform(const AlphaTransformAttribute *attrib) {
if (_current_alpha_offset == 0 && _current_alpha_scale == 1) {
_alpha_transform_enabled = false;
}
else {
} else {
_alpha_transform_enabled = true;
}
}
@ -3020,6 +2998,7 @@ apply_texture(TextureContext *tc) {
#ifdef WBD_GL_MODE
bind_texture(tc);
#else
// specify_texture(tc->_texture);
// Note: if this code changes, make sure to change initialization SetTSS code in init_dx as well
// so DX TSS renderstate matches dxgsg state
@ -3385,69 +3364,32 @@ texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb,
void DXGraphicsStateGuardian::
copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) {
dxgsg_cat.fatal() << "DXGSG copy_pixel_buffer unimplemented!!!";
return;
extern HRESULT ConvertDDSurftoPixBuf(PixelBuffer *pixbuf,LPDIRECTDRAWSURFACE7 pDDSurf);
#ifdef WBD_GL_MODE
nassertv(pb != NULL && dr != NULL);
activate();
set_pack_alignment(1);
NodeAttributes state;
// Bug fix for RE, RE2, and VTX - need to disable texturing in order
// for glReadPixels() to work
// NOTE: reading the depth buffer is *much* slower than reading the
// color buffer
state.set_attribute(TextureTransition::get_class_type(),
new TextureAttribute);
set_state(state, false);
int xo, yo, w, h;
dr->get_region_pixels(xo, yo, w, h);
#ifdef GSG_VERBOSE
dxgsg_cat.debug()
<< "glReadPixels(" << pb->get_xorg() << ", " << pb->get_yorg()
<< ", " << pb->get_xsize() << ", " << pb->get_ysize()
<< ", ";
switch (get_external_image_format(pb->get_format())) {
case GL_DEPTH_COMPONENT:
dxgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, ";
break;
case GL_RGB:
dxgsg_cat.debug(false) << "GL_RGB, ";
break;
case GL_RGBA:
dxgsg_cat.debug(false) << "GL_RGBA, ";
break;
default:
dxgsg_cat.debug(false) << "unknown, ";
break;
}
switch (get_image_type(pb->get_image_type())) {
case GL_UNSIGNED_BYTE:
dxgsg_cat.debug(false) << "GL_UNSIGNED_BYTE, ";
break;
case GL_float:
dxgsg_cat.debug(false) << "GL_float, ";
break;
default:
dxgsg_cat.debug(false) << "unknown, ";
break;
}
dxgsg_cat.debug(false)
<< (void *)pb->_image.p() << ")" << endl;
#endif
// only handled simple case
nassertv(xo==0);
nassertv(yo==0);
nassertv(w==pb->get_xsize());
nassertv(h==pb->get_ysize());
/*
set_pack_alignment(1);
glReadPixels( pb->get_xorg() + xo, pb->get_yorg() + yo,
pb->get_xsize(), pb->get_ysize(),
get_external_image_format(pb->get_format()),
get_image_type(pb->get_image_type()),
pb->_image.p() );
*/
(void) ConvertDDSurftoPixBuf(pb,((_cur_read_pixel_buffer & RenderBuffer::T_back) ? _back : _pri));
nassertv(!pb->_image.empty());
#endif // WBD_GL_MODE
}
////////////////////////////////////////////////////////////////////
@ -3458,7 +3400,6 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) {
void DXGraphicsStateGuardian::
copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
const RenderBuffer &rb) {
activate();
set_read_buffer(rb);
copy_pixel_buffer(pb, dr);
}
@ -3611,8 +3552,7 @@ draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr,
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::apply_material( Material* material )
{
void DXGraphicsStateGuardian::apply_material( Material* material ) {
D3DMATERIAL7 cur_material;
cur_material.dcvDiffuse = *(D3DCOLORVALUE *)(material->get_diffuse().get_data());
cur_material.dcvAmbient = *(D3DCOLORVALUE *)(material->get_ambient().get_data());
@ -3634,8 +3574,7 @@ apply_fog(Fog *fog) {
_d3dDevice->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE,
get_fog_mode_type(fog->get_mode()));
switch(fog->get_mode())
{
switch (fog->get_mode()) {
case Fog::M_linear:
{
float fog_start = fog->get_start();
@ -3668,8 +3607,7 @@ apply_fog(Fog *fog) {
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::apply_light( PointLight* light )
{
void DXGraphicsStateGuardian::apply_light( PointLight* light ) {
// The light position will be relative to the current matrix, so
// we have to know what the current matrix is. Find a better
// solution later.
@ -3752,8 +3690,7 @@ void DXGraphicsStateGuardian::apply_light( PointLight* light )
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::apply_light( DirectionalLight* light )
{
void DXGraphicsStateGuardian::apply_light( DirectionalLight* light ) {
// The light position will be relative to the current matrix, so
// we have to know what the current matrix is. Find a better
// solution later.
@ -3837,8 +3774,7 @@ void DXGraphicsStateGuardian::apply_light( DirectionalLight* light )
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::apply_light( Spotlight* light )
{
void DXGraphicsStateGuardian::apply_light( Spotlight* light ) {
// The light position will be relative to the current matrix, so
// we have to know what the current matrix is. Find a better
// solution later.
@ -3923,8 +3859,7 @@ void DXGraphicsStateGuardian::apply_light( Spotlight* light )
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::apply_light( AmbientLight* light )
{
void DXGraphicsStateGuardian::apply_light( AmbientLight* light ) {
_cur_ambient_light = _cur_ambient_light + light->get_color();
}
@ -4005,13 +3940,11 @@ issue_tex_matrix(const TexMatrixAttribute *attrib) {
void DXGraphicsStateGuardian::
issue_color(const ColorAttribute *attrib) {
activate();
if (attrib->is_on()&& attrib->is_real())
{
if (attrib->is_on()&& attrib->is_real()) {
_issued_color_enabled = true;
Colorf c = attrib->get_color();
_issued_color = D3DRGBA(c[0], c[1], c[2], c[3]);
}
else _issued_color_enabled = false;
} else _issued_color_enabled = false;
}
#endif
@ -4138,8 +4071,7 @@ issue_render_mode(const RenderModeAttribute *attrib) {
RenderModeProperty::Mode mode = attrib->get_mode();
switch(mode)
{
switch (mode) {
case RenderModeProperty::M_filled:
_d3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID);
break;
@ -4160,8 +4092,7 @@ issue_render_mode(const RenderModeAttribute *attrib) {
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::issue_light(const LightAttribute *attrib )
{
void DXGraphicsStateGuardian::issue_light(const LightAttribute *attrib ) {
nassertv(attrib->get_properties_is_on());
activate();
@ -4259,8 +4190,7 @@ void DXGraphicsStateGuardian::issue_light(const LightAttribute *attrib )
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::
reset_ambient()
{
reset_ambient() {
_lmodel_ambient += 2.0f;
}
@ -4451,12 +4381,10 @@ issue_depth_test(const DepthTestAttribute *attrib) {
DepthTestProperty::Mode mode = attrib->get_mode();
if (mode == DepthTestProperty::M_none)
{
if (mode == DepthTestProperty::M_none) {
_depth_test_enabled = false;
_d3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
}
else {
} else {
_depth_test_enabled = true;
_d3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
_d3dDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, get_depth_func_type(mode));
@ -4534,8 +4462,7 @@ issue_cull_face(const CullFaceAttribute *attrib) {
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::
issue_clip_plane(const ClipPlaneAttribute *attrib)
{
issue_clip_plane(const ClipPlaneAttribute *attrib) {
activate();
// Initialize the currently enabled clip plane list
@ -4619,8 +4546,7 @@ issue_clip_plane(const ClipPlaneAttribute *attrib)
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::
issue_transparency(const TransparencyAttribute *attrib )
{
issue_transparency(const TransparencyAttribute *attrib ) {
activate();
TransparencyProperty::Mode mode = attrib->get_mode();
@ -4749,6 +4675,7 @@ begin_decal(GeomNode *base_geom) {
if (dx_decal_type == GDT_offset) {
#define POLYGON_OFFSET_MULTIPLIER 2
// Just draw the base geometry normally.
base_geom->draw(this);
_d3dDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8!
@ -4870,7 +4797,7 @@ end_decal(GeomNode *base_geom) {
// indicated point, assumed to be in modelview
// coordinates, from the camera plane.
////////////////////////////////////////////////////////////////////
float DXGraphicsStateGuardian::
INLINE float DXGraphicsStateGuardian::
compute_distance_to(const LPoint3f &point) const {
// In the case of a DXGraphicsStateGuardian, we know that the
// modelview matrix already includes the relative transform from the
@ -4937,56 +4864,20 @@ set_draw_buffer(const RenderBuffer &rb) {
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::set_read_buffer
// Access: Protected
// Description: Sets up the glReadBuffer 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.
// Description: Vestigial analog of glReadBuffer
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::
set_read_buffer(const RenderBuffer &rb) {
dxgsg_cat.fatal() << "DX set_read_buffer unimplemented!!!";
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 {
dxgsg_cat.error() << "Invalid or unimplemented Argument to set_read_buffer!\n";
}
return;
#ifdef WBD_GL_MODE
switch (rb._buffer_type & RenderBuffer::T_color) {
case RenderBuffer::T_front:
call_glReadBuffer(GL_FRONT);
break;
case RenderBuffer::T_back:
call_glReadBuffer(GL_BACK);
break;
case RenderBuffer::T_right:
call_glReadBuffer(GL_RIGHT);
break;
case RenderBuffer::T_left:
call_glReadBuffer(GL_LEFT);
break;
case RenderBuffer::T_front_right:
call_glReadBuffer(GL_FRONT_RIGHT);
break;
case RenderBuffer::T_front_left:
call_glReadBuffer(GL_FRONT_LEFT);
break;
case RenderBuffer::T_back_right:
call_glReadBuffer(GL_BACK_RIGHT);
break;
case RenderBuffer::T_back_left:
call_glReadBuffer(GL_BACK_LEFT);
break;
default:
call_glReadBuffer(GL_FRONT_AND_BACK);
}
#endif // WBD_GL_MODE
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::get_texture_wrap_mode
@ -4996,18 +4887,13 @@ set_read_buffer(const RenderBuffer &rb) {
////////////////////////////////////////////////////////////////////
INLINE D3DTEXTUREADDRESS DXGraphicsStateGuardian::
get_texture_wrap_mode(Texture::WrapMode wm) {
/*
switch (wm) {
case Texture::WM_clamp:
return D3DTADDRESS_CLAMP;
case Texture::WM_repeat:
return D3DTADDRESS_WRAP;
}
*/
if (wm == Texture::WM_clamp)
return D3DTADDRESS_CLAMP;
else if (wm != Texture::WM_repeat) {
dxgsg_cat.error() << "Invalid Texture::WrapMode value!\n";
#ifdef _DEBUG
dxgsg_cat.error() << "Invalid or Unimplemented Texture::WrapMode value!\n";
#endif
}
return D3DTADDRESS_WRAP;
@ -5019,10 +4905,8 @@ get_texture_wrap_mode(Texture::WrapMode wm) {
// Description: Maps from the depth func modes to gl version
////////////////////////////////////////////////////////////////////
INLINE D3DCMPFUNC DXGraphicsStateGuardian::
get_depth_func_type(DepthTestProperty::Mode m) const
{
switch(m)
{
get_depth_func_type(DepthTestProperty::Mode m) const {
switch (m) {
case DepthTestProperty::M_never: return D3DCMP_NEVER;
case DepthTestProperty::M_less: return D3DCMP_LESS;
case DepthTestProperty::M_equal: return D3DCMP_EQUAL;
@ -5043,8 +4927,7 @@ get_depth_func_type(DepthTestProperty::Mode m) const
// Description: Maps from the stencil func modes to dx version
////////////////////////////////////////////////////////////////////
INLINE D3DCMPFUNC DXGraphicsStateGuardian::
get_stencil_func_type(StencilProperty::Mode m) const
{
get_stencil_func_type(StencilProperty::Mode m) const {
switch (m) {
case StencilProperty::M_never: return D3DCMP_NEVER;
case StencilProperty::M_less: return D3DCMP_LESS;
@ -5067,8 +4950,7 @@ get_stencil_func_type(StencilProperty::Mode m) const
// Description: Maps from the stencil action modes to dx version
////////////////////////////////////////////////////////////////////
INLINE D3DSTENCILOP DXGraphicsStateGuardian::
get_stencil_action_type(StencilProperty::Action a) const
{
get_stencil_action_type(StencilProperty::Action a) const {
switch (a) {
case StencilProperty::A_keep: return D3DSTENCILOP_KEEP;
case StencilProperty::A_zero: return D3DSTENCILOP_ZERO;
@ -5144,6 +5026,11 @@ free_pointers() {
PT(SavedFrameBuffer) DXGraphicsStateGuardian::
save_frame_buffer(const RenderBuffer &buffer,
CPT(DisplayRegion) dr) {
dxgsg_cat.error() << "save_frame_buffer unimplemented!!\n";
return NULL;
#if 0
DXSavedFrameBuffer *sfb = new DXSavedFrameBuffer(buffer, dr);
if (buffer._buffer_type & RenderBuffer::T_depth) {
@ -5161,6 +5048,7 @@ save_frame_buffer(const RenderBuffer &buffer,
}
return sfb;
#endif
}
////////////////////////////////////////////////////////////////////
@ -5170,6 +5058,11 @@ save_frame_buffer(const RenderBuffer &buffer,
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::
restore_frame_buffer(SavedFrameBuffer *frame_buffer) {
dxgsg_cat.error() << "restore_frame_buffer unimplemented!!\n";
return;
#if 0
DXSavedFrameBuffer *sfb = DCAST(DXSavedFrameBuffer, frame_buffer);
if (sfb->_back_rgba != (Texture *)NULL &&
@ -5184,6 +5077,7 @@ restore_frame_buffer(SavedFrameBuffer *frame_buffer) {
// Restore the depth buffer.
draw_pixel_buffer(sfb->_depth, sfb->_display_region, sfb->_buffer);
}
#endif
}
// factory and type stuff
@ -5255,8 +5149,7 @@ dx_cleanup() {
// Description: Recreate the back buffer and zbuffers at the new size
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::
dx_setup_after_resize(RECT viewrect, HWND mwindow)
{
dx_setup_after_resize(RECT viewrect, HWND mwindow) {
if (_back == NULL) // nothing created yet
return;
@ -5378,7 +5271,68 @@ void DXGraphicsStateGuardian::show_frame(void) {
if (dx_full_screen) {
HRESULT hr = _pri->Flip( NULL, DDFLIP_WAIT ); // bugbug: dont we want triple buffering instead of wasting time waiting for vsync?
if (hr == DDERR_SURFACELOST) {
if (hr == DDERR_SURFACELOST || hr == DDERR_SURFACEBUSY) {
#if 0
if (hr == DDERR_SURFACELOST || hr == DDERR_SURFACEBUSY) {
HRESULT hr;
// TestCooperativeLevel returns DD_OK: If the current mode is same as the one which the App set.
// The following two errors are returned to NORMALMODE (windowed)apps only.
//
// DDERR_WRONGMODE: If the App is a windowed app and the current mode is
// not the same as the one in which the app was created.
// DDERR_EXCLUSIVEMODEALREADYSET: If another app took exclusivemode access
//
// The following error is returned only for exclusivemode apps.
// DDERR_NOEXCLUSIVEMODE: Some other app took exclusive mode.
//
hr = _pDD->TestCooperativeLevel();
if (SUCCEEDED( hr )) {
// 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 (FAILED( m_pDD->RestoreAllSurfaces() ))
return hr;
// Re-fill the contents of textures and vertex buffers
// which just got restored now.
// You will need to destroy and recreate
// optimized vertex buffers however, restoring is not enough.
RefillAppSurfaces();
} else if (hr == DDERR_NOEXCLUSIVEMODE) {
// This means that some app took exclusive mode access
// we need to sit in a loop till we get back to the right mode.
do {
// Dont consume CPU.
Sleep( 500 );
} while (DDERR_NOEXCLUSIVEMODE==
(hr = m_pDD->TestCooperativeLevel()));
if (SUCCEEDED( hr )) {
// This means that the exclusive mode app relinquished its
// control and we are back to the safe mode, so simply restore
if (FAILED( m_pDD->RestoreAllSurfaces() ))
return hr;
// Re-fill the contents of textures and vertex buffers
// which just got restored now.
// You will need to destroy and recreate
// optimized vertex buffers however, restoring is not enough.
RefillAppSurfaces();
} else {
// Busted!!
return hr;
}
} else {
// Busted!!
return hr;
}
}
#endif
// Check/restore the primary surface
if (( _pri!=NULL ) && _pri->IsLost())
_pri->Restore();
@ -5435,10 +5389,8 @@ void DXGraphicsStateGuardian::show_frame(void) {
// Access:
// Description: we receive the new x and y position of the client
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::adjust_view_rect(int x, int y)
{
if (_view_rect.left != x || _view_rect.top != y)
{
void DXGraphicsStateGuardian::adjust_view_rect(int x, int y) {
if (_view_rect.left != x || _view_rect.top != y) {
_view_rect.right = x + _view_rect.right - _view_rect.left;
_view_rect.left = x;
_view_rect.bottom = y + _view_rect.bottom - _view_rect.top;
@ -5455,8 +5407,7 @@ void DXGraphicsStateGuardian::adjust_view_rect(int x, int y)
// function builds a 4x4 view matrix.
//-----------------------------------------------------------------------------
HRESULT SetViewMatrix( D3DMATRIX& mat, D3DVECTOR& vFrom, D3DVECTOR& vAt,
D3DVECTOR& vWorldUp )
{
D3DVECTOR& vWorldUp ) {
// Get the z basis vector, which points straight ahead. This is the
// difference from the eyepoint to the lookat point.
D3DVECTOR vView = vAt - vFrom;
@ -5476,13 +5427,11 @@ HRESULT SetViewMatrix( D3DMATRIX& mat, D3DVECTOR& vFrom, D3DVECTOR& vAt,
// If this vector has near-zero length because the input specified a
// bogus up vector, let's try a default up vector
if( 1e-6f > ( fLength = Magnitude( vUp ) ) )
{
if (1e-6f > ( fLength = Magnitude( vUp ) )) {
vUp = D3DVECTOR( 0.0f, 1.0f, 0.0f ) - vView.y * vView;
// If we still have near-zero length, resort to a different axis.
if( 1e-6f > ( fLength = Magnitude( vUp ) ) )
{
if (1e-6f > ( fLength = Magnitude( vUp ) )) {
vUp = D3DVECTOR( 0.0f, 0.0f, 1.0f ) - vView.z * vView;
if (1e-6f > ( fLength = Magnitude( vUp ) ))

View File

@ -169,7 +169,7 @@ public:
virtual void begin_decal(GeomNode *base_geom);
virtual void end_decal(GeomNode *base_geom);
virtual float compute_distance_to(const LPoint3f &point) const;
INLINE float compute_distance_to(const LPoint3f &point) const;
void reset_ambient();
@ -207,6 +207,8 @@ protected:
LPDDPIXELFORMAT _pTexPixFmts;
DXTextureContext *_pCurTexContext;
RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation
bool _color_transform_enabled;
bool _alpha_transform_enabled;
@ -307,8 +309,8 @@ protected:
D3DBLEND _blend_source_func;
D3DBLEND _blend_dest_func;
int _pack_alignment;
int _unpack_alignment;
// int _pack_alignment;
// int _unpack_alignment;
bool _issued_color_enabled; // WBD ADDED
D3DCOLOR _issued_color; // WBD ADDED