Panda3D
|
00001 // Filename: dxGraphicsStateGuardian8.I 00002 // Created by: mike (02Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: DXGraphicsStateGuardian8::LColor_to_D3DCOLOR 00018 // Access: Public, Static 00019 // Description: Converts Panda's floating-point LColor structure to 00020 // DirectX's D3DCOLOR packed structure. 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE DWORD DXGraphicsStateGuardian8:: 00023 LColor_to_D3DCOLOR(const LColor &cLColor) { 00024 // MS VC defines _M_IX86 for x86. gcc should define _X86_ 00025 #if (defined(_M_IX86) || defined(_X86_)) && !defined(STDFLOAT_DOUBLE) 00026 DWORD d3dcolor, tempcolorval=255; 00027 00028 // note the default FPU rounding mode will give 255*0.5f=0x80, not 0x7F as VC would force it to by resetting rounding mode 00029 // don't think this makes much difference 00030 00031 __asm { 00032 push ebx ; want to save this in case this fn is inlined 00033 push ecx 00034 mov ecx, cLColor 00035 fild tempcolorval 00036 fld DWORD PTR [ecx] 00037 fmul ST(0), ST(1) 00038 fistp tempcolorval ; no way to store directly to int register 00039 mov eax, tempcolorval 00040 shl eax, 16 00041 00042 fld DWORD PTR [ecx+4] ;grn 00043 fmul ST(0), ST(1) 00044 fistp tempcolorval 00045 mov ebx, tempcolorval 00046 shl ebx, 8 00047 or eax, ebx 00048 00049 fld DWORD PTR [ecx+8] ;blue 00050 fmul ST(0), ST(1) 00051 fistp tempcolorval 00052 or eax, tempcolorval 00053 00054 fld DWORD PTR [ecx+12] ;alpha 00055 fmul ST(0), ST(1) 00056 fistp tempcolorval 00057 ; simulate pop 255.0 off FP stack w/o store, mark top as empty and increment stk ptr 00058 ffree ST(0) 00059 fincstp 00060 mov ebx, tempcolorval 00061 shl ebx, 24 00062 or eax, ebx 00063 mov d3dcolor, eax 00064 pop ecx 00065 pop ebx 00066 } 00067 00068 // dxgsg8_cat.debug() << (void*)d3dcolor << endl; 00069 return d3dcolor; 00070 #else //!_X86_ 00071 return MY_D3DRGBA(cLColor[0], cLColor[1], cLColor[2], cLColor[3]); 00072 #endif //!_X86_ 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: DXGraphicsStateGuardian8::get_texture_wrap_mode 00077 // Access: Protected, Static 00078 // Description: Maps from the Texture's internal wrap mode symbols to 00079 // GL's. 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE D3DTEXTUREADDRESS DXGraphicsStateGuardian8:: 00082 get_texture_wrap_mode(Texture::WrapMode wm) { 00083 switch (wm) { 00084 case Texture::WM_clamp: 00085 return D3DTADDRESS_CLAMP; 00086 case Texture::WM_repeat: 00087 return D3DTADDRESS_WRAP; 00088 case Texture::WM_mirror: 00089 return D3DTADDRESS_MIRROR; 00090 case Texture::WM_mirror_once: 00091 return D3DTADDRESS_MIRRORONCE; 00092 case Texture::WM_border_color: 00093 return D3DTADDRESS_BORDER; 00094 } 00095 dxgsg8_cat.error() << "Invalid Texture::Mode value" << endl; 00096 return D3DTADDRESS_WRAP; 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: DXGraphicsStateGuardian8::get_fog_mode_type 00101 // Access: Protected, Static 00102 // Description: Maps from the fog types to gl version 00103 //////////////////////////////////////////////////////////////////// 00104 INLINE D3DFOGMODE DXGraphicsStateGuardian8:: 00105 get_fog_mode_type(Fog::Mode m) { 00106 switch (m) { 00107 case Fog::M_linear: 00108 return D3DFOG_LINEAR; 00109 case Fog::M_exponential: 00110 return D3DFOG_EXP; 00111 case Fog::M_exponential_squared: 00112 return D3DFOG_EXP2; 00113 } 00114 dxgsg8_cat.error() << "Invalid Fog::Mode value" << endl; 00115 return D3DFOG_EXP; 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: DXGraphicsStateGuardian8::get_tex_mat_sym 00120 // Access: Protected, Static 00121 // Description: Returns the nth D3DTS_TEXTURE(n) constant. 00122 //////////////////////////////////////////////////////////////////// 00123 INLINE D3DTRANSFORMSTATETYPE DXGraphicsStateGuardian8:: 00124 get_tex_mat_sym(int stage_index) { 00125 return (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0 + stage_index); 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: DXGraphicsStateGuardian8::get_safe_buffer_start 00130 // Access: Protected, Static 00131 // Description: Returns the address of a 64K buffer that is allocated 00132 // at the beginning of a 64K block. 00133 //////////////////////////////////////////////////////////////////// 00134 INLINE unsigned char *DXGraphicsStateGuardian8:: 00135 get_safe_buffer_start() { 00136 if (_temp_buffer == NULL) { 00137 // Guarantee we get a buffer of size 0x10000 bytes that begins 00138 // on an even multiple of 0x10000. We do this by allocating 00139 // double the required buffer, and then pointing to the first 00140 // multiple of 0x10000 within that buffer. 00141 _temp_buffer = new unsigned char[0x1ffff]; 00142 _safe_buffer_start = (unsigned char *)(((long)_temp_buffer + 0xffff) & ~0xffff); 00143 } 00144 00145 return _safe_buffer_start; 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: DXGraphicsStateGuardian8::get_supports_render_texture 00150 // Access: Published 00151 // Description: Returns true if this particular GSG can render 00152 // from a wdxGraphicsBuffer8 directly into a texture, or 00153 // false if it must always copy-to-texture at the end of 00154 // each frame to achieve this effect. 00155 //////////////////////////////////////////////////////////////////// 00156 INLINE bool DXGraphicsStateGuardian8:: 00157 get_supports_render_texture() const { 00158 return _supports_render_texture; 00159 }