69 #include <Cg/cgD3D9.h> 76 #define tostring(x) #x 77 #define SDK_VERSION(major,minor) tostring(major) << "." << tostring(minor) 78 #define DIRECTX_SDK_VERSION SDK_VERSION (_DXSDK_PRODUCT_MAJOR, _DXSDK_PRODUCT_MINOR) << "." << SDK_VERSION (_DXSDK_BUILD_MAJOR, _DXSDK_BUILD_MINOR) 84 TypeHandle DXGraphicsStateGuardian9::_type_handle;
86 D3DMATRIX DXGraphicsStateGuardian9::_d3d_ident_mat;
88 unsigned char *DXGraphicsStateGuardian9::_temp_buffer =
nullptr;
89 unsigned char *DXGraphicsStateGuardian9::_safe_buffer_start =
nullptr;
92 LPDIRECT3DDEVICE9 DXGraphicsStateGuardian9::_cg_device =
nullptr;
95 #define __D3DLIGHT_RANGE_MAX ((PN_stdfloat)sqrt(FLT_MAX)) //for some reason this is missing in dx9 hdrs 97 #define MY_D3DRGBA(r, g, b, a) ((D3DCOLOR) D3DCOLOR_COLORVALUE(r, g, b, a)) 102 DXGraphicsStateGuardian9::
106 if (dxgsg9_cat.is_debug()) {
108 <<
"DXGraphicsStateGuardian9 " <<
this <<
" constructing\n";
116 _d3d_device =
nullptr;
118 _dx_is_ready =
false;
119 _vertex_blending_enabled =
false;
120 _overlay_windows_supported =
false;
121 _tex_stats_retrieval_impossible =
false;
122 _supports_render_texture =
false;
124 _active_ibuffer =
nullptr;
128 ZeroMemory(&_d3d_ident_mat,
sizeof(D3DMATRIX));
129 _d3d_ident_mat._11 = _d3d_ident_mat._22 = _d3d_ident_mat._33 = _d3d_ident_mat._44 = 1.0f;
131 _cur_read_pixel_buffer = RenderBuffer::T_front;
135 _copy_texture_inverted =
true;
137 _gsg_managed_textures = dx_management | dx_texture_management;
138 _gsg_managed_vertex_buffers = dx_management;
139 _gsg_managed_index_buffers = dx_management;
142 _num_bound_streams = 0;
143 _white_vbuffer =
nullptr;
145 _vertex_shader_version_major = 0;
146 _vertex_shader_version_minor = 0;
147 _pixel_shader_version_major = 0;
148 _pixel_shader_version_minor = 0;
150 _vertex_shader_profile = 0;
151 _pixel_shader_profile = 0;
153 _vertex_shader_maximum_constants = 0;
155 _supports_stream_offset =
false;
162 atexit (atexit_function);
168 DXGraphicsStateGuardian9::
169 ~DXGraphicsStateGuardian9() {
170 if (dxgsg9_cat.is_debug()) {
172 <<
"DXGraphicsStateGuardian9 " <<
this <<
" destructing\n";
175 if (IS_VALID_PTR(_d3d_device)) {
176 _d3d_device->SetTexture(0,
nullptr);
179 free_nondx_resources();
197 << *dtc->
get_texture() <<
" is stored in an unsupported compressed format.\n";
251 if (aniso_degree >= 1) {
255 int supports_anisotropic_mag_filter;
256 D3DTEXTUREFILTERTYPE new_mag_filter;
258 supports_anisotropic_mag_filter = (_screen -> _d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) != 0;
259 if (aniso_degree <= 1 || supports_anisotropic_mag_filter == 0) {
260 new_mag_filter = ((ft != SamplerState::FT_nearest) ? D3DTEXF_LINEAR : D3DTEXF_POINT);
262 new_mag_filter = D3DTEXF_ANISOTROPIC;
269 <<
"ERROR: set_sampler_state (D3DSAMP_MAGFILTER, " 270 << new_mag_filter <<
") failed for sampler: " << sampler << endl;
281 new_mip_filter = D3DTEXF_NONE;
286 new_mip_filter = D3DTEXF_NONE;
289 if (aniso_degree >= 2) {
290 new_min_filter = D3DTEXF_ANISOTROPIC;
324 <<
"Unable to re-create texture " << *tex << endl;
328 dtc->
enqueue_lru(&_prepared_objects->_graphics_memory_lru);
342 << *tex <<
" is stored in an unsupported compressed format.\n";
350 if (_effective_incomplete_render && !force) {
354 !_loader.is_null()) {
357 async_reload_texture(dtc);
361 return dtc->create_simple_texture(*_screen);
393 for (
int view = 0; view < num_views; ++view) {
395 nassertr(tc !=
nullptr,
false);
414 case Shader::SL_GLSL:
416 <<
"Tried to load GLSL shader, but GLSL shaders not supported by Direct3D 9.\n";
421 if (_supports_basic_shaders) {
425 <<
"Tried to load Cg shader, but basic shaders not supported.\n";
430 <<
"Tried to load Cg shader, but Cg support not compiled in.\n";
436 <<
"Tried to load shader with unsupported shader language!\n";
468 if (_screen->_managed_vertex_buffers) {
469 pool = D3DPOOL_MANAGED;
470 usage = D3DUSAGE_WRITEONLY;
472 pool = D3DPOOL_DEFAULT;
473 usage = D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC;
476 int num_bytes = data->get_data_size_bytes();
478 PStatTimer timer(_create_vertex_buffer_pcollector, Thread::get_current_thread());
484 hr = _screen->_d3d_device->CreateVertexBuffer(num_bytes, usage, dvbc->_fvf, pool, &dvbc->_vbuffer,
nullptr);
491 if (dxgsg9_cat.is_debug() && DXdebug_buffers9) {
493 <<
"creating vertex buffer " << dvbc->_vbuffer <<
": " 494 << data->get_num_rows() <<
" vertices " 495 << *data->get_array_format() <<
"\n";
502 <<
"CreateVertexBuffer failed" << D3DERRORSTRING(hr);
504 dvbc->_vbuffer =
nullptr;
521 int num_bytes = reader->get_data_size_bytes();
523 if (dxgsg9_cat.is_debug() && DXdebug_buffers9) {
525 <<
"copying " << num_bytes
526 <<
" bytes into vertex buffer " << dvbc->_vbuffer <<
"\n";
530 if ( num_bytes != 0 ) {
532 if (client_pointer ==
nullptr) {
536 PStatTimer timer(_load_vertex_buffer_pcollector, reader->get_current_thread());
541 dvbc->create_vbuffer(*_screen, reader);
547 if (_screen->_managed_vertex_buffers) {
548 hr = dvbc->_vbuffer->Lock(0, num_bytes, (
void **) &local_pointer, 0);
550 hr = dvbc->_vbuffer->Lock(0, num_bytes, (
void **) &local_pointer, D3DLOCK_DISCARD);
554 <<
"VertexBuffer::Lock failed" << D3DERRORSTRING(hr);
558 memcpy(local_pointer, client_pointer, num_bytes);
560 dvbc->_vbuffer->Unlock();
562 _data_transferred_pcollector.add_level(num_bytes);
567 dvbc->
enqueue_lru(&_prepared_objects->_graphics_memory_lru);
583 if (dxgsg9_cat.is_debug() && DXdebug_buffers9) {
585 <<
"deleting vertex buffer " << dvbc->_vbuffer <<
"\n";
589 dvbc->_vbuffer->Release();
590 dvbc->_vbuffer =
nullptr;
615 nassertr(vbc !=
nullptr,
false);
648 if (dibc->_ibuffer ==
nullptr) {
652 if (dibc->_ibuffer !=
nullptr) {
658 _d3d_device->SetIndices(dibc->_ibuffer);
659 _active_ibuffer = dibc;
663 _d3d_device->SetIndices(
nullptr);
664 _active_ibuffer =
nullptr;
679 _active_ibuffer =
nullptr;
682 if (_active_ibuffer != dibc) {
683 _d3d_device->SetIndices(dibc->_ibuffer);
684 _active_ibuffer = dibc;
688 dibc->
enqueue_lru(&_prepared_objects->_graphics_memory_lru);
717 nassertv(_supports_occlusion_query);
718 nassertv(_current_occlusion_query ==
nullptr);
720 IDirect3DQuery9 *query;
721 HRESULT hr = _d3d_device->CreateQuery(D3DQUERYTYPE_OCCLUSION, &query);
724 <<
"Occlusion query failed.\n";
730 if (dxgsg9_cat.is_debug()) {
732 <<
"beginning occlusion query " << query <<
"\n";
735 query->Issue(D3DISSUE_BEGIN);
736 _current_occlusion_query = queryobj;
746 end_occlusion_query() {
747 if (_current_occlusion_query ==
nullptr) {
755 if (dxgsg9_cat.is_debug()) {
757 <<
"ending occlusion query " << query <<
"\n";
760 _current_occlusion_query =
nullptr;
761 query->Issue(D3DISSUE_END);
773 return GeomMunger::register_munger(munger, current_thread);
782 DWORD main_flags = 0;
799 main_flags |= D3DCLEAR_TARGET;
803 _screen->_presentation_params.EnableAutoDepthStencil) {
804 aux_flags |= D3DCLEAR_ZBUFFER;
809 if (_screen->_presentation_params.EnableAutoDepthStencil &&
810 IS_STENCIL_FORMAT(_screen->_presentation_params.AutoDepthStencilFormat)) {
811 aux_flags |= D3DCLEAR_STENCIL;
815 if ((main_flags | aux_flags) != 0) {
816 HRESULT hr = _d3d_device->Clear(0,
nullptr, main_flags | aux_flags, color_clear_value,
817 depth_clear_value, stencil_clear_value);
818 if (FAILED(hr) && main_flags == D3DCLEAR_TARGET && aux_flags != 0) {
821 hr = _d3d_device->Clear(0,
nullptr, D3DCLEAR_TARGET, color_clear_value,
822 depth_clear_value, stencil_clear_value);
827 aux_flags |= D3DCLEAR_ZBUFFER;
828 HRESULT hr2 = _d3d_device->Clear(0,
nullptr, D3DCLEAR_ZBUFFER, color_clear_value,
829 depth_clear_value, stencil_clear_value);
832 <<
"Unable to clear depth buffer; removing.\n";
838 aux_flags |= D3DCLEAR_STENCIL;
839 HRESULT hr2 = _d3d_device->Clear(0,
nullptr, D3DCLEAR_STENCIL, color_clear_value,
840 stencil_clear_value, stencil_clear_value);
843 <<
"Unable to clear stencil buffer; removing.\n";
846 _supports_stencil =
false;
854 <<
"clear_buffer failed: Clear returned " << D3DERRORSTRING(hr);
864 nassertv(dr !=
nullptr);
871 D3DVIEWPORT9 vp = { (DWORD)l, (DWORD)u, (DWORD)w, (DWORD)h, 0.0f, 1.0f };
872 _current_viewport = vp;
873 HRESULT hr = _d3d_device->SetViewport(&_current_viewport);
876 <<
"_screen->_swap_chain = " << _screen->_swap_chain <<
" _swap_chain = " << _swap_chain <<
"\n";
878 <<
"SetViewport(" << l <<
", " << u <<
", " << w <<
", " << h
879 <<
") failed" << D3DERRORSTRING(hr);
882 _d3d_device->GetViewport(&vp_old);
884 <<
"GetViewport(" << vp_old.X <<
", " << vp_old.Y <<
", " << vp_old.Width <<
", " 885 << vp_old.Height <<
") returned: Trying to set that vp---->\n";
886 hr = _d3d_device->SetViewport(&vp_old);
890 dxgsg9_cat.error() <<
"Failed again\n";
891 throw_event(
"panda3d-render-error");
896 if (_screen->_can_direct_disable_color_writes) {
910 calc_projection_mat(
const Lens *lens) {
911 if (lens ==
nullptr) {
922 static const LMatrix4 rescale_mat
929 LMatrix4::convert_mat(CS_yup_left, _current_lens->get_coordinate_system()) *
933 if (_scene_setup->get_inverted()) {
936 result *= LMatrix4::scale_mat(1.0f, -1.0f, 1.0f);
939 return TransformState::make_mat(result);
952 LMatrix4f mat = LCAST(
float, _projection_mat->get_mat());
954 _d3d_device->SetTransform(D3DTS_PROJECTION,
955 (D3DMATRIX*)mat.get_data());
956 return SUCCEEDED(hr);
972 if (_d3d_device ==
nullptr) {
974 <<
this <<
"::begin_frame(): no device.\n";
978 HRESULT hr = _d3d_device->BeginScene();
981 if (hr == D3DERR_DEVICELOST) {
982 if (dxgsg9_cat.is_debug()) {
984 <<
"BeginScene returns D3DERR_DEVICELOST" << endl;
987 check_cooperative_level();
991 <<
"BeginScene failed, unhandled error hr == " 992 << D3DERRORSTRING(hr) << endl;
993 throw_event(
"panda3d-render-error");
998 if (_current_properties->get_srgb_color()) {
1058 if (_vertex_array_shader_context != 0) {
1060 _vertex_array_shader =
nullptr;
1061 _vertex_array_shader_context =
nullptr;
1063 if (_texture_binding_shader_context != 0) {
1065 _texture_binding_shader =
nullptr;
1066 _texture_binding_shader_context =
nullptr;
1068 if (_current_shader_context != 0) {
1069 _current_shader_context->
unbind(
this);
1070 _current_shader =
nullptr;
1071 _current_shader_context =
nullptr;
1105 HRESULT hr = _d3d_device->EndScene();
1108 if (hr == D3DERR_DEVICELOST) {
1109 if (dxgsg9_cat.is_debug()) {
1111 <<
"EndScene returns DeviceLost\n";
1113 check_cooperative_level();
1117 <<
"EndScene failed, unhandled error hr == " << D3DERRORSTRING(hr);
1118 throw_event(
"panda3d-render-error");
1123 #if defined(DO_PSTATS) 1124 if (_texmgrmem_total_pcollector.is_active()) {
1125 #define TICKS_PER_GETTEXINFO (2.5*1000) // 2.5 second interval 1126 static DWORD last_tick_count = 0;
1127 DWORD cur_tick_count = GetTickCount();
1129 if (cur_tick_count - last_tick_count > TICKS_PER_GETTEXINFO) {
1130 last_tick_count = cur_tick_count;
1131 report_texmgr_stats();
1154 nassertr(_data_reader !=
nullptr,
false);
1189 const TransformTable *table = data_reader->get_transform_table();
1190 if (table !=
nullptr) {
1193 table->
get_transform(i)->mult_matrix(mat, _internal_transform->get_mat());
1194 const D3DMATRIX *d3d_mat = (
const D3DMATRIX *)mat.get_data();
1195 _d3d_device->SetTransform(D3DTS_WORLDMATRIX(i), d3d_mat);
1200 _transform_stale =
true;
1202 _vertex_blending_enabled =
true;
1206 if (_vertex_blending_enabled) {
1209 _vertex_blending_enabled =
false;
1212 if (_transform_stale && !_data_reader->is_vertex_transformed()) {
1213 const D3DMATRIX *d3d_mat = (
const D3DMATRIX *)_internal_transform->get_mat().get_data();
1214 _d3d_device->SetTransform(D3DTS_WORLD, d3d_mat);
1215 _transform_stale =
false;
1219 if (_data_reader->is_vertex_transformed()) {
1227 _d3d_device->SetTransform(D3DTS_WORLD, &_d3d_ident_mat);
1228 static const LMatrix4f rescale_mat
1233 _transform_stale =
true;
1235 _d3d_device->SetTransform(D3DTS_PROJECTION, (
const D3DMATRIX *)rescale_mat.get_data());
1238 if (_current_shader_context == 0 ) {
1240 if (_vertex_array_shader_context != 0) {
1243 if (!update_standard_vertex_arrays(force)) {
1248 if (_vertex_array_shader_context == 0) {
1249 disable_standard_vertex_arrays();
1254 if (!_current_shader_context->
1255 update_shader_vertex_arrays(_vertex_array_shader_context,
this, force)) {
1261 _vertex_array_shader = _current_shader;
1262 _vertex_array_shader_context = _current_shader_context;
1273 bool DXGraphicsStateGuardian9::
1274 update_standard_vertex_arrays(
bool force) {
1279 int number_of_arrays = _data_reader->get_num_arrays();
1280 for (
int array_index = 0; array_index < number_of_arrays; ++array_index ) {
1282 if ( array_reader ==
nullptr ) {
1283 dxgsg9_cat.error() <<
"Unable to get reader for array " << array_index <<
"\n";
1290 dxgsg9_cat.error() <<
"Unable to setup vertex buffer for array " << array_index <<
"\n";
1296 hr = _d3d_device->SetStreamSource( array_index, dvbc->_vbuffer, 0, array_format->
get_stride() );
1298 dxgsg9_cat.error() <<
"SetStreamSource failed" << D3DERRORSTRING(hr);
1306 hr = _d3d_device->SetFVF( fvf );
1308 dxgsg9_cat.error() <<
"SetFVF failed" << D3DERRORSTRING(hr);
1321 void DXGraphicsStateGuardian9::
1322 disable_standard_vertex_arrays() {
1323 for (
int array_index = 0; array_index < _num_bound_streams; ++array_index )
1325 _d3d_device->SetStreamSource( array_index,
nullptr, 0, 0 );
1327 _num_bound_streams = 0;
1337 _vertices_tri_pcollector.add_level(reader->get_num_vertices());
1338 _primitive_batches_tri_pcollector.add_level(1);
1340 if (reader->is_indexed()) {
1341 int min_vertex = dx_broken_max_index ? 0 : reader->get_min_vertex();
1342 int max_vertex = reader->get_max_vertex();
1346 nassertr(ibc !=
nullptr,
false);
1351 _d3d_device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,
1353 min_vertex, max_vertex - min_vertex + 1,
1354 0, reader->get_num_primitives() );
1358 const unsigned char *index_pointer = reader->get_read_pointer(force);
1359 if (index_pointer ==
nullptr) {
1363 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1364 if (vertex_pointer ==
nullptr) {
1368 draw_indexed_primitive_up( D3DPT_TRIANGLELIST,
1369 min_vertex, max_vertex,
1370 reader->get_num_primitives(),
1371 index_pointer, index_type, vertex_pointer,
1372 _data_reader->get_format()->get_array(0)->get_stride() );
1376 _d3d_device->DrawPrimitive( D3DPT_TRIANGLELIST,
1377 reader->get_first_vertex(),
1378 reader->get_num_primitives() );
1382 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1383 if (vertex_pointer ==
nullptr) {
1387 draw_primitive_up(D3DPT_TRIANGLELIST, reader->get_num_primitives(),
1388 reader->get_first_vertex(),
1389 reader->get_num_vertices(), vertex_pointer,
1390 _data_reader->get_format()->get_array(0)->get_stride());
1404 if (connect_triangle_strips && _current_fill_mode != RenderModeAttrib::M_wireframe) {
1407 _vertices_tristrip_pcollector.add_level(reader->get_num_vertices());
1408 _primitive_batches_tristrip_pcollector.add_level(1);
1410 if (reader->is_indexed()) {
1411 int min_vertex = dx_broken_max_index ? 0 : reader->get_min_vertex();
1412 int max_vertex = reader->get_max_vertex();
1416 nassertr(ibc !=
nullptr,
false);
1421 _d3d_device->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP,
1423 min_vertex, max_vertex - min_vertex + 1,
1424 0, reader->get_num_vertices() - 2 );
1428 const unsigned char *index_pointer = reader->get_read_pointer(force);
1429 if (index_pointer ==
nullptr) {
1433 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1434 if (vertex_pointer ==
nullptr) {
1438 draw_indexed_primitive_up
1439 (D3DPT_TRIANGLESTRIP,
1440 min_vertex, max_vertex,
1441 reader->get_num_vertices() - 2,
1442 index_pointer, index_type, vertex_pointer,
1443 _data_reader->get_format()->get_array(0)->get_stride());
1447 _d3d_device->DrawPrimitive( D3DPT_TRIANGLESTRIP,
1448 reader->get_first_vertex(),
1449 reader->get_num_vertices() - 2 );
1453 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1454 if (vertex_pointer ==
nullptr) {
1457 draw_primitive_up(D3DPT_TRIANGLESTRIP,
1458 reader->get_num_vertices() - 2,
1459 reader->get_first_vertex(),
1460 reader->get_num_vertices(), vertex_pointer,
1461 _data_reader->get_format()->get_array(0)->get_stride());
1468 CPTA_int ends = reader->get_ends();
1469 _primitive_batches_tristrip_pcollector.add_level(ends.size());
1471 if (reader->is_indexed()) {
1472 CPTA_int ends = reader->get_ends();
1473 int index_stride = reader->get_index_stride();
1474 _primitive_batches_tristrip_pcollector.add_level(ends.size());
1478 nassertr(reader->get_mins()->get_num_rows() == (int)ends.size() &&
1479 reader->get_maxs()->get_num_rows() == (int)ends.size(),
false);
1483 nassertr(ibc !=
nullptr,
false);
1488 unsigned int start = 0;
1489 for (
size_t i = 0; i < ends.size(); i++) {
1490 _vertices_tristrip_pcollector.add_level(ends[i] - start);
1491 unsigned int min = mins.get_data1i();
1492 unsigned int max = maxs.get_data1i();
1493 _d3d_device->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP,
1496 start, ends[i] - start - 2 );
1497 start = ends[i] + 2;
1502 int stride = _data_reader->get_format()->get_array(0)->get_stride();
1503 const unsigned char *index_pointer = reader->get_read_pointer(force);
1504 if (index_pointer ==
nullptr) {
1508 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1509 if (vertex_pointer ==
nullptr) {
1513 unsigned int start = 0;
1514 for (
size_t i = 0; i < ends.size(); i++) {
1515 _vertices_tristrip_pcollector.add_level(ends[i] - start);
1516 unsigned int min = mins.get_data1i();
1517 unsigned int max = maxs.get_data1i();
1518 draw_indexed_primitive_up
1519 (D3DPT_TRIANGLESTRIP,
1521 ends[i] - start - 2,
1522 index_pointer + start * index_stride, index_type,
1523 vertex_pointer, stride);
1525 start = ends[i] + 2;
1529 unsigned int first_vertex = reader->get_first_vertex();
1532 unsigned int start = 0;
1533 for (
size_t i = 0; i < ends.size(); i++) {
1534 _vertices_tristrip_pcollector.add_level(ends[i] - start);
1535 _d3d_device->DrawPrimitive( D3DPT_TRIANGLESTRIP,
1536 first_vertex + start,
1537 ends[i] - start - 2 );
1538 start = ends[i] + 2;
1543 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1544 if (vertex_pointer ==
nullptr) {
1547 int stride = _data_reader->get_format()->get_array(0)->get_stride();
1549 unsigned int start = 0;
1550 for (
size_t i = 0; i < ends.size(); i++) {
1551 _vertices_tristrip_pcollector.add_level(ends[i] - start);
1552 draw_primitive_up(D3DPT_TRIANGLESTRIP, ends[i] - start - 2,
1553 first_vertex + start,
1555 vertex_pointer, stride);
1557 start = ends[i] + 2;
1572 CPTA_int ends = reader->get_ends();
1573 _primitive_batches_trifan_pcollector.add_level(ends.size());
1575 if (reader->is_indexed()) {
1576 int min_vertex = dx_broken_max_index ? 0 : reader->get_min_vertex();
1577 int max_vertex = reader->get_max_vertex();
1581 int index_stride = reader->get_index_stride();
1585 nassertr(reader->get_mins()->get_num_rows() == (int)ends.size() &&
1586 reader->get_maxs()->get_num_rows() == (int)ends.size(),
false);
1590 nassertr(ibc !=
nullptr,
false);
1595 unsigned int start = 0;
1596 for (
size_t i = 0; i < ends.size(); i++) {
1597 _vertices_trifan_pcollector.add_level(ends[i] - start);
1598 unsigned int min = mins.get_data1i();
1599 unsigned int max = maxs.get_data1i();
1600 _d3d_device->DrawIndexedPrimitive( D3DPT_TRIANGLEFAN,
1603 start, ends[i] - start - 2 );
1609 int stride = _data_reader->get_format()->get_array(0)->get_stride();
1610 const unsigned char *index_pointer = reader->get_read_pointer(force);
1611 if (index_pointer ==
nullptr) {
1615 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1616 if (vertex_pointer ==
nullptr) {
1620 unsigned int start = 0;
1621 for (
size_t i = 0; i < ends.size(); i++) {
1622 _vertices_trifan_pcollector.add_level(ends[i] - start);
1623 unsigned int min = mins.get_data1i();
1624 unsigned int max = maxs.get_data1i();
1625 draw_indexed_primitive_up
1628 ends[i] - start - 2,
1629 index_pointer + start * index_stride, index_type,
1630 vertex_pointer, stride);
1636 unsigned int first_vertex = reader->get_first_vertex();
1639 unsigned int start = 0;
1640 for (
size_t i = 0; i < ends.size(); i++) {
1641 _vertices_trifan_pcollector.add_level(ends[i] - start);
1642 _d3d_device->DrawPrimitive( D3DPT_TRIANGLEFAN,
1643 first_vertex + start,
1644 ends[i] - start - 2 );
1650 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1651 if (vertex_pointer ==
nullptr) {
1654 int stride = _data_reader->get_format()->get_array(0)->get_stride();
1656 unsigned int start = 0;
1657 for (
size_t i = 0; i < ends.size(); i++) {
1658 _vertices_trifan_pcollector.add_level(ends[i] - start);
1659 draw_primitive_up(D3DPT_TRIANGLEFAN,
1660 ends[i] - start - 2,
1663 vertex_pointer, stride);
1678 _vertices_other_pcollector.add_level(reader->get_num_vertices());
1679 _primitive_batches_other_pcollector.add_level(1);
1681 if (reader->is_indexed()) {
1682 int min_vertex = dx_broken_max_index ? 0 : reader->get_min_vertex();
1683 int max_vertex = reader->get_max_vertex();
1687 nassertr(ibc !=
nullptr,
false);
1692 _d3d_device->DrawIndexedPrimitive( D3DPT_LINELIST,
1694 min_vertex, max_vertex - min_vertex + 1,
1695 0, reader->get_num_primitives() );
1699 const unsigned char *index_pointer = reader->get_read_pointer(force);
1700 if (index_pointer ==
nullptr) {
1704 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1705 if (vertex_pointer ==
nullptr) {
1709 draw_indexed_primitive_up
1711 min_vertex, max_vertex,
1712 reader->get_num_primitives(),
1713 index_pointer, index_type, vertex_pointer,
1714 _data_reader->get_format()->get_array(0)->get_stride());
1718 _d3d_device->DrawPrimitive( D3DPT_LINELIST,
1719 reader->get_first_vertex(),
1720 reader->get_num_primitives() );
1724 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1725 if (vertex_pointer ==
nullptr) {
1728 draw_primitive_up(D3DPT_LINELIST, reader->get_num_primitives(),
1729 reader->get_first_vertex(),
1730 reader->get_num_vertices(), vertex_pointer,
1731 _data_reader->get_format()->get_array(0)->get_stride());
1752 _vertices_other_pcollector.add_level(reader->get_num_vertices());
1753 _primitive_batches_other_pcollector.add_level(1);
1757 nassertr(!reader->is_indexed(),
false);
1760 _d3d_device->DrawPrimitive( D3DPT_POINTLIST,
1761 reader->get_first_vertex(),
1762 reader->get_num_primitives() );
1766 const unsigned char *vertex_pointer = _data_reader->get_array_reader(0)->get_read_pointer(force);
1767 if (vertex_pointer ==
nullptr) {
1770 draw_primitive_up(D3DPT_POINTLIST, reader->get_num_primitives(),
1771 reader->get_first_vertex(),
1772 reader->get_num_vertices(), vertex_pointer,
1773 _data_reader->get_format()->get_array(0)->get_stride());
1786 if (_vertex_blending_enabled) {
1789 _vertex_blending_enabled =
false;
1792 if (_data_reader->is_vertex_transformed()) {
1794 LMatrix4f mat = LCAST(
float, _projection_mat->get_mat());
1795 _d3d_device->SetTransform(D3DTS_PROJECTION,
1796 (D3DMATRIX*)mat.get_data());
1811 set_read_buffer(rb);
1825 if (tc ==
nullptr) {
1832 <<
"Unable to re-create texture " << *dtc->
get_texture() << endl;
1843 IDirect3DSurface9 *tex_level_0;
1846 dxgsg9_cat.error() <<
"GetSurfaceLev failed in copy_texture" << D3DERRORSTRING(hr);
1851 D3DSURFACE_DESC texdesc;
1852 hr = tex_level_0->GetDesc(&texdesc);
1854 dxgsg9_cat.error() <<
"GetDesc failed in copy_texture" << D3DERRORSTRING(hr);
1855 SAFE_RELEASE(tex_level_0);
1862 SAFE_RELEASE(tex_level_0);
1866 <<
"Unable to re-create texture " << *dtc->
get_texture() << endl;
1871 dxgsg9_cat.error() <<
"GetSurfaceLev failed in copy_texture" << D3DERRORSTRING(hr);
1874 hr = tex_level_0->GetDesc(&texdesc);
1876 dxgsg9_cat.error() <<
"GetDesc 2 failed in copy_texture" << D3DERRORSTRING(hr);
1877 SAFE_RELEASE(tex_level_0);
1886 <<
"Unable to copy to texture, texture is wrong size: " << *dtc->
get_texture() << endl;
1887 SAFE_RELEASE(tex_level_0);
1892 DWORD render_target_index;
1893 IDirect3DSurface9 *render_target;
1896 render_target_index = 0;
1898 hr = _d3d_device->GetRenderTarget(render_target_index, &render_target);
1901 <<
"GetRenderTarget failed in framebuffer_copy_to_texture" 1902 << D3DERRORSTRING(hr);
1903 SAFE_RELEASE(tex_level_0);
1910 src_rect.right = xo+w;
1912 src_rect.bottom = yo+h;
1918 D3DTEXTUREFILTERTYPE filter;
1920 filter = D3DTEXF_POINT;
1923 hr = _d3d_device->StretchRect(render_target, &src_rect,
1924 tex_level_0, &src_rect,
1928 <<
"StretchRect failed in framebuffer_copy_to_texture" 1929 << D3DERRORSTRING(hr);
1933 SAFE_RELEASE(render_target);
1934 SAFE_RELEASE(tex_level_0);
1938 dtc->
enqueue_lru(&_prepared_objects->_graphics_memory_lru);
1972 set_read_buffer(rb);
1975 nassertr(tex !=
nullptr && dr !=
nullptr,
false);
1984 case Texture::F_depth_stencil:
1989 format = Texture::F_rgb;
1990 component_type = Texture::T_unsigned_byte;
1993 Texture::TextureType texture_type;
1995 texture_type = Texture::TT_cube_map;
1997 texture_type = Texture::TT_2d_texture;
2006 component_type, format);
2011 rect.right = xo + w;
2012 rect.bottom = yo + h;
2013 bool copy_inverted =
false;
2015 IDirect3DSurface9 *temp_surface =
nullptr;
2021 if (_cur_read_pixel_buffer & RenderBuffer::T_back) {
2022 DWORD render_target_index;
2023 IDirect3DSurface9 *backbuffer =
nullptr;
2027 render_target_index = 0;
2028 hr = _d3d_device->GetRenderTarget(render_target_index, &backbuffer);
2031 dxgsg9_cat.error() <<
"GetRenderTarget failed" << D3DERRORSTRING(hr);
2038 D3DSURFACE_DESC surface_description;
2040 backbuffer -> GetDesc (&surface_description);
2042 pool = D3DPOOL_SYSTEMMEM;
2043 hr = _d3d_device->CreateOffscreenPlainSurface(
2044 surface_description.Width,
2045 surface_description.Height,
2046 surface_description.Format,
2052 <<
"CreateImageSurface failed in copy_pixel_buffer()" 2053 << D3DERRORSTRING(hr);
2054 backbuffer->Release();
2059 hr = _d3d_device -> GetRenderTargetData (backbuffer, temp_surface);
2061 dxgsg9_cat.error() <<
"GetRenderTargetData failed" << D3DERRORSTRING(hr);
2062 temp_surface->Release();
2063 backbuffer->Release();
2067 copy_inverted =
true;
2069 RELEASE(backbuffer, dxgsg9,
"backbuffer", RELEASE_ONCE);
2071 }
else if (_cur_read_pixel_buffer & RenderBuffer::T_front) {
2073 if (_screen->_presentation_params.Windowed) {
2080 minfo.cbSize =
sizeof(MONITORINFO);
2081 GetMonitorInfo(_screen->_monitor, &minfo);
2083 w = RECT_XSIZE(minfo.rcMonitor);
2084 h = RECT_YSIZE(minfo.rcMonitor);
2087 ClientToScreen(_screen->_window, (POINT*)&rect.left);
2088 ClientToScreen(_screen->_window, (POINT*)&rect.right);
2093 hr = _d3d_device->CreateOffscreenPlainSurface(w, h, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &temp_surface,
nullptr);
2096 <<
"CreateImageSurface failed in copy_pixel_buffer()" 2097 << D3DERRORSTRING(hr);
2104 hr = _d3d_device->GetFrontBufferData(swap_chain,temp_surface);
2106 if (hr == D3DERR_DEVICELOST) {
2108 <<
"copy_pixel_buffer failed: device lost\n";
2109 temp_surface->Release();
2113 copy_inverted =
true;
2117 <<
"copy_pixel_buffer: unhandled current_read_pixel_buffer type\n";
2118 temp_surface->Release();
2123 copy_inverted = !copy_inverted;
2126 copy_inverted, tex, view, z);
2128 RELEASE(temp_surface, dxgsg9,
"temp_surface", RELEASE_ONCE);
2134 void DXGraphicsStateGuardian9::reset_render_states (
void)
2137 int maximum_texture_stages;
2139 maximum_texture_stages = D3D_MAXTEXTURESTAGES;
2142 memset (_render_state_array, -1,
sizeof (_render_state_array));
2143 memset (_texture_stage_states_array, -1,
sizeof (_texture_stage_states_array));
2147 _render_state_array [D3DRS_FOGCOLOR] = 0;
2148 _render_state_array [D3DRS_AMBIENT] = 0;
2152 memset (_texture_render_states_array, 0,
sizeof (_texture_render_states_array));
2156 for (index = 0; index < MAXIMUM_TEXTURES; index++) {
2157 TextureRenderStates *texture_render_states;
2159 texture_render_states = &_texture_render_states_array [index];
2160 texture_render_states -> state_array [D3DSAMP_MAGFILTER] = D3DTEXF_POINT;
2161 texture_render_states -> state_array [D3DSAMP_MINFILTER] = D3DTEXF_POINT;
2162 texture_render_states -> state_array [D3DSAMP_MAXANISOTROPY] = 1;
2164 _num_active_texture_stages = 0;
2183 _inv_state_mask.clear_bit(ShaderAttrib::get_class_slot());
2184 _inv_state_mask.clear_bit(AlphaTestAttrib::get_class_slot());
2185 _inv_state_mask.clear_bit(ClipPlaneAttrib::get_class_slot());
2186 _inv_state_mask.clear_bit(ColorAttrib::get_class_slot());
2187 _inv_state_mask.clear_bit(ColorScaleAttrib::get_class_slot());
2188 _inv_state_mask.clear_bit(CullFaceAttrib::get_class_slot());
2189 _inv_state_mask.clear_bit(DepthOffsetAttrib::get_class_slot());
2190 _inv_state_mask.clear_bit(DepthTestAttrib::get_class_slot());
2191 _inv_state_mask.clear_bit(DepthWriteAttrib::get_class_slot());
2192 _inv_state_mask.clear_bit(RenderModeAttrib::get_class_slot());
2193 _inv_state_mask.clear_bit(RescaleNormalAttrib::get_class_slot());
2194 _inv_state_mask.clear_bit(ShadeModelAttrib::get_class_slot());
2195 _inv_state_mask.clear_bit(TransparencyAttrib::get_class_slot());
2196 _inv_state_mask.clear_bit(ColorWriteAttrib::get_class_slot());
2197 _inv_state_mask.clear_bit(ColorBlendAttrib::get_class_slot());
2198 _inv_state_mask.clear_bit(TextureAttrib::get_class_slot());
2199 _inv_state_mask.clear_bit(TexGenAttrib::get_class_slot());
2200 _inv_state_mask.clear_bit(TexMatrixAttrib::get_class_slot());
2201 _inv_state_mask.clear_bit(MaterialAttrib::get_class_slot());
2202 _inv_state_mask.clear_bit(LightAttrib::get_class_slot());
2203 _inv_state_mask.clear_bit(StencilAttrib::get_class_slot());
2204 _inv_state_mask.clear_bit(FogAttrib::get_class_slot());
2205 _inv_state_mask.clear_bit(ScissorAttrib::get_class_slot());
2210 _supported_geom_rendering =
2211 Geom::GR_point | Geom::GR_point_uniform_size |
2212 Geom::GR_point_perspective | Geom::GR_point_sprite |
2213 Geom::GR_indexed_other |
2214 Geom::GR_triangle_strip | Geom::GR_triangle_fan |
2215 Geom::GR_flat_first_vertex |
2216 Geom::GR_render_mode_wireframe | Geom::GR_render_mode_point;
2227 nassertv(_screen->_d3d9 !=
nullptr);
2229 if (_d3d_device ==
nullptr) {
2234 _d3d_device->GetDeviceCaps(&d3d_caps);
2236 _vertex_shader_version_major = D3DSHADER_VERSION_MAJOR (d3d_caps.VertexShaderVersion);
2237 _vertex_shader_version_minor = D3DSHADER_VERSION_MINOR (d3d_caps.VertexShaderVersion);
2238 _pixel_shader_version_major = D3DSHADER_VERSION_MAJOR (d3d_caps.PixelShaderVersion);
2239 _pixel_shader_version_minor = D3DSHADER_VERSION_MINOR (d3d_caps.PixelShaderVersion);
2241 _supports_hlsl = (_pixel_shader_version_major != 0);
2243 _vertex_shader_profile = (
char *) D3DXGetVertexShaderProfile (_d3d_device);
2244 _pixel_shader_profile = (
char *) D3DXGetPixelShaderProfile (_d3d_device);
2246 _vertex_shader_maximum_constants = d3d_caps.MaxVertexShaderConst;
2248 switch (_pixel_shader_version_major)
2251 _shader_model = SM_00;
2254 _shader_model = SM_11;
2258 _shader_model = SM_20;
2259 if (d3d_caps.PS20Caps.NumInstructionSlots >= 512) {
2260 _shader_model = SM_2X;
2264 _shader_model = SM_30;
2267 _shader_model = SM_40;
2271 _shader_model = SM_50;
2275 _auto_detect_shader_model = _shader_model;
2280 _cg_context = cgCreateContext();
2282 if (cgD3D9IsProfileSupported(CG_PROFILE_PS_2_0) &&
2283 cgD3D9IsProfileSupported(CG_PROFILE_VS_2_0)) {
2284 _supports_basic_shaders =
true;
2285 _shader_caps._active_vprofile = (int)cgD3D9GetLatestVertexProfile();
2286 _shader_caps._active_fprofile = (int)cgD3D9GetLatestPixelProfile();
2287 _shader_caps._ultimate_vprofile = (int)CG_PROFILE_VS_3_0;
2288 _shader_caps._ultimate_fprofile = (int)CG_PROFILE_PS_3_0;
2297 if (dxgsg9_cat.is_debug()) {
2298 CGprofile vertex_profile;
2299 CGprofile pixel_profile;
2301 vertex_profile = cgD3D9GetLatestVertexProfile();
2302 pixel_profile = cgD3D9GetLatestPixelProfile();
2304 const char *vertex_profile_str =
2305 cgGetProfileString(vertex_profile);
2306 const char *pixel_profile_str =
2307 cgGetProfileString(pixel_profile);
2309 if (vertex_profile_str ==
nullptr) {
2310 vertex_profile_str =
"(null)";
2312 if (pixel_profile_str ==
nullptr) {
2313 pixel_profile_str =
"(null)";
2317 <<
"\nCg latest vertex profile = " << vertex_profile_str <<
" id = " << vertex_profile
2318 <<
"\nCg latest pixel profile = " << pixel_profile_str <<
" id = " << pixel_profile
2319 <<
"\nshader model = " << _shader_model
2324 _supports_stream_offset = (d3d_caps.DevCaps2 & D3DDEVCAPS2_STREAMOFFSET) != 0;
2325 _screen->_supports_dynamic_textures = ((d3d_caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) != 0);
2326 _screen->_supports_automatic_mipmap_generation = ((d3d_caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP) != 0);
2328 if (support_stencil) {
2329 int min_stencil = D3DSTENCILCAPS_ZERO | D3DSTENCILCAPS_REPLACE | D3DSTENCILCAPS_INCR | D3DSTENCILCAPS_DECR;
2330 if ((d3d_caps.StencilCaps & min_stencil) == min_stencil) {
2331 if (dxgsg9_cat.is_debug()) {
2333 <<
"Checking for stencil; mode = " 2334 << D3DFormatStr(_screen->_presentation_params.AutoDepthStencilFormat)
2337 switch (_screen->_presentation_params.AutoDepthStencilFormat) {
2341 case D3DFMT_D24X4S4:
2342 _supports_stencil =
true;
2343 if (dxgsg9_cat.is_debug()) {
2345 <<
"Stencils supported.\n";
2350 if (dxgsg9_cat.is_debug()) {
2352 <<
"Stencils NOT supported.\n";
2358 _supports_stencil_wrap = (d3d_caps.StencilCaps & D3DSTENCILCAPS_INCR) && (d3d_caps.StencilCaps & D3DSTENCILCAPS_DECR);
2359 _supports_two_sided_stencil = ((d3d_caps.StencilCaps & D3DSTENCILCAPS_TWOSIDED) != 0);
2361 _max_color_targets = d3d_caps.NumSimultaneousRTs;
2363 _supports_depth_bias = ((d3d_caps.RasterCaps & (D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS)) == (D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS));
2365 _supports_gamma_calibration = ((d3d_caps.Caps2 & D3DCAPS2_CANCALIBRATEGAMMA) != 0);
2368 hr = _d3d_device->CreateQuery(D3DQUERYTYPE_OCCLUSION,
nullptr);
2369 _supports_occlusion_query = !FAILED(hr);
2371 if (dxgsg9_cat.is_error()) {
2373 <<
"\nHwTransformAndLight = " << ((d3d_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0)
2374 <<
"\nMaxTextureWidth = " << d3d_caps.MaxTextureWidth
2375 <<
"\nMaxTextureHeight = " << d3d_caps.MaxTextureHeight
2376 <<
"\nMaxVolumeExtent = " << d3d_caps.MaxVolumeExtent
2377 <<
"\nMaxTextureAspectRatio = " << d3d_caps.MaxTextureAspectRatio
2378 <<
"\nTexCoordCount = " << (d3d_caps.FVFCaps & D3DFVFCAPS_TEXCOORDCOUNTMASK)
2379 <<
"\nMaxTextureBlendStages = " << d3d_caps.MaxTextureBlendStages
2380 <<
"\nMaxSimultaneousTextures = " << d3d_caps.MaxSimultaneousTextures
2381 <<
"\nMaxActiveLights = " << d3d_caps.MaxActiveLights
2382 <<
"\nMaxUserClipPlanes = " << d3d_caps.MaxUserClipPlanes
2383 <<
"\nMaxVertexBlendMatrices = " << d3d_caps.MaxVertexBlendMatrices
2384 <<
"\nMaxVertexBlendMatrixIndex = " << d3d_caps.MaxVertexBlendMatrixIndex
2385 <<
"\nMaxPointSize = " << d3d_caps.MaxPointSize
2386 <<
"\nMaxPrimitiveCount = " << d3d_caps.MaxPrimitiveCount
2387 <<
"\nMaxVertexIndex = " << d3d_caps.MaxVertexIndex
2388 <<
"\nMaxStreams = " << d3d_caps.MaxStreams
2389 <<
"\nMaxStreamStride = " << d3d_caps.MaxStreamStride
2390 <<
"\nD3DTEXOPCAPS_MULTIPLYADD = " << ((d3d_caps.TextureOpCaps & D3DTEXOPCAPS_MULTIPLYADD) != 0)
2391 <<
"\nD3DTEXOPCAPS_LERP = " << ((d3d_caps.TextureOpCaps & D3DTEXOPCAPS_LERP) != 0)
2392 <<
"\nD3DPMISCCAPS_TSSARGTEMP = " << ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) != 0)
2393 <<
"\nD3DPRASTERCAPS_DEPTHBIAS = " << ((d3d_caps.RasterCaps & D3DPRASTERCAPS_DEPTHBIAS) != 0)
2394 <<
"\nD3DPRASTERCAPS_SLOPESCALEDEPTHBIAS = " << ((d3d_caps.RasterCaps & D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS) != 0)
2395 <<
"\nVertexShaderVersion = " << _vertex_shader_version_major <<
"." << _vertex_shader_version_minor
2396 <<
"\nPixelShaderVersion = " << _pixel_shader_version_major <<
"." << _pixel_shader_version_minor
2397 <<
"\nMaxVertexShaderConst = " << _vertex_shader_maximum_constants
2398 <<
"\nsupports_stream_offset = " << _supports_stream_offset
2399 <<
"\nsupports_dynamic_textures = " << _screen->_supports_dynamic_textures
2400 <<
"\nsupports_automatic_mipmap_generation = " << _screen->_supports_automatic_mipmap_generation
2401 <<
"\nsupports_stencil_wrap = " << _supports_stencil_wrap
2402 <<
"\nsupports_two_sided_stencil = " << _supports_two_sided_stencil
2403 <<
"\nsupports_occlusion_query = " << _supports_occlusion_query
2404 <<
"\nsupports_gamma_calibration = " << _supports_gamma_calibration
2405 <<
"\nMaxAnisotropy = " << d3d_caps.MaxAnisotropy
2406 <<
"\nNumSimultaneousRTs = " << d3d_caps.NumSimultaneousRTs
2407 <<
"\nD3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING = " << ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING) != 0)
2408 <<
"\nDirectX SDK version " DIRECTX_SDK_VERSION
2413 _screen->_supports_automatic_mipmap_generation =
false;
2415 reset_render_states();
2417 _max_vertices_per_array = d3d_caps.MaxVertexIndex;
2418 _max_vertices_per_primitive = d3d_caps.MaxPrimitiveCount;
2420 _max_texture_stages = d3d_caps.MaxSimultaneousTextures;
2422 _max_texture_dimension = min(d3d_caps.MaxTextureWidth, d3d_caps.MaxTextureHeight);
2424 _supports_tex_non_pow2 = !(d3d_caps.TextureCaps & D3DPTEXTURECAPS_POW2);
2426 _supports_texture_combine = ((d3d_caps.TextureOpCaps & D3DTEXOPCAPS_LERP) != 0);
2427 _supports_texture_saved_result = ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) != 0);
2428 _supports_texture_constant_color = ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_PERSTAGECONSTANT) != 0);
2429 _supports_texture_dot3 =
true;
2431 if (_supports_texture_constant_color) {
2432 _constant_color_operand = D3DTA_CONSTANT;
2434 _constant_color_operand = D3DTA_TFACTOR;
2437 _screen->_managed_textures = _gsg_managed_textures;
2438 _screen->_managed_vertex_buffers = _gsg_managed_vertex_buffers;
2439 _screen->_managed_index_buffers = _gsg_managed_index_buffers;
2441 UINT available_texture_memory;
2443 available_texture_memory = _d3d_device->GetAvailableTextureMem ( );
2444 if (dxgsg9_cat.is_debug()) {
2445 dxgsg9_cat.debug() <<
"*** GetAvailableTextureMem = " << available_texture_memory <<
"\n";
2447 _available_texture_memory = available_texture_memory;
2450 D3DDEVICE_CREATION_PARAMETERS creation_parameters;
2452 _supports_render_texture =
false;
2453 _screen->_render_to_texture_d3d_format = D3DFMT_UNKNOWN;
2454 _screen->_framebuffer_d3d_format = D3DFMT_UNKNOWN;
2456 #define TOTAL_RENDER_TO_TEXTURE_FORMATS 3 2458 D3DFORMAT render_to_texture_formats [TOTAL_RENDER_TO_TEXTURE_FORMATS] =
2465 render_to_texture_formats [TOTAL_RENDER_TO_TEXTURE_FORMATS - 1] = _screen->_display_mode.Format;
2467 hr = _d3d_device->GetCreationParameters (&creation_parameters);
2468 if (SUCCEEDED (hr)) {
2469 _screen->_framebuffer_d3d_format = _screen->_display_mode.Format;
2472 for (index = 0; index < TOTAL_RENDER_TO_TEXTURE_FORMATS; index++) {
2473 hr = _screen->_d3d9->CheckDeviceFormat (
2474 creation_parameters.AdapterOrdinal,
2475 creation_parameters.DeviceType,
2476 _screen->_display_mode.Format,
2477 D3DUSAGE_RENDERTARGET,
2479 render_to_texture_formats [index]);
2480 if (SUCCEEDED (hr)) {
2481 _screen->_render_to_texture_d3d_format = render_to_texture_formats [index];
2482 _supports_render_texture =
true;
2484 if (_supports_render_texture) {
2489 if (dxgsg9_cat.is_debug()) {
2490 dxgsg9_cat.debug() <<
"Render to Texture Support = " << _supports_render_texture <<
"\n";
2496 _supports_3d_texture = ((d3d_caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) != 0);
2497 if (_supports_3d_texture) {
2498 _max_3d_texture_dimension = d3d_caps.MaxVolumeExtent;
2500 _supports_cube_map = ((d3d_caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) != 0);
2501 if (_supports_cube_map) {
2502 _max_cube_map_dimension = _max_texture_dimension;
2505 _max_lights = (int)d3d_caps.MaxActiveLights;
2506 _max_clip_planes = (
int)d3d_caps.MaxUserClipPlanes;
2507 _max_vertex_transforms = d3d_caps.MaxVertexBlendMatrices;
2508 _max_vertex_transform_indices = d3d_caps.MaxVertexBlendMatrixIndex;
2512 _clip_plane_bits = 0;
2530 _has_scene_graph_color =
false;
2532 _last_testcooplevel_result = D3D_OK;
2534 if (dxgsg9_cat.is_debug()) {
2535 dxgsg9_cat.debug() <<
"Supported texture formats:\n";
2538 for(
int i = 0; i < MAX_POSSIBLE_TEXFMTS; i++) {
2540 D3DFORMAT_FLAG fmtflag = D3DFORMAT_FLAG(1 << i);
2541 hr = _screen->_d3d9->CheckDeviceFormat(_screen->_card_id, D3DDEVTYPE_HAL, _screen->_display_mode.Format,
2542 0x0, D3DRTYPE_TEXTURE, g_D3DFORMATmap[fmtflag]);
2543 if (SUCCEEDED(hr)) {
2544 if (dxgsg9_cat.is_debug()) {
2545 dxgsg9_cat.debug() <<
" " << D3DFormatStr(g_D3DFORMATmap[fmtflag]) <<
"\n";
2547 _screen->_supported_tex_formats_mask |= fmtflag;
2551 _supports_depth_stencil = ((_screen->_supported_tex_formats_mask & D24S8_FLAG) != 0);
2552 _supports_depth_texture = _supports_depth_stencil ||
2553 (_screen->_supported_tex_formats_mask & D16_FLAG) != 0 ||
2554 (_screen->_supported_tex_formats_mask & D32_FLAG) != 0 ||
2555 (_screen->_supported_tex_formats_mask & D24X8_FLAG) != 0;
2561 _supports_shadow_filter = _supports_depth_texture;
2564 #define CHECK_COMPRESSED_FMT(mode, fmt) \ 2565 if (_screen->_supported_tex_formats_mask & fmt##_FLAG) {\ 2566 if (dxgsg9_cat.is_debug()) {\ 2567 dxgsg9_cat.debug() << "Compressed texture format " << #fmt << " supported\n";\ 2569 _supports_compressed_texture = true;\ 2570 _compressed_texture_formats.set_bit(Texture::mode);\ 2573 if (_screen->_intel_compressed_texture_bug) {
2575 <<
"Buggy Intel driver detected; disabling compressed textures.\n";
2576 _screen->_supported_tex_formats_mask &=
2577 ~(DXT1_FLAG | DXT2_FLAG | DXT3_FLAG | DXT4_FLAG | DXT5_FLAG);
2581 CHECK_COMPRESSED_FMT(CM_dxt1, DXT1);
2582 CHECK_COMPRESSED_FMT(CM_dxt2, DXT2);
2583 CHECK_COMPRESSED_FMT(CM_dxt3, DXT3);
2584 CHECK_COMPRESSED_FMT(CM_dxt4, DXT4);
2585 CHECK_COMPRESSED_FMT(CM_dxt5, DXT5);
2586 CHECK_COMPRESSED_FMT(CM_rgtc, ATI1);
2587 CHECK_COMPRESSED_FMT(CM_rgtc, ATI2);
2590 #undef CHECK_COMPRESSED_FMT 2592 _screen->_supports_rgba16f_texture_format =
false;
2593 hr = _screen->_d3d9->CheckDeviceFormat(_screen->_card_id, D3DDEVTYPE_HAL, _screen->_display_mode.Format, 0x0, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F);
2595 _screen->_supports_rgba16f_texture_format =
true;
2597 _screen->_supports_rgba32_texture_format =
false;
2598 hr = _screen->_d3d9->CheckDeviceFormat(_screen->_card_id, D3DDEVTYPE_HAL, _screen->_display_mode.Format, 0x0, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F);
2600 _screen->_supports_rgba32_texture_format =
true;
2604 if (_screen->_d3dcaps.MaxTextureWidth == 0)
2605 _screen->_d3dcaps.MaxTextureWidth = 256;
2607 if (_screen->_d3dcaps.MaxTextureHeight == 0)
2608 _screen->_d3dcaps.MaxTextureHeight = 256;
2610 if (_screen->_d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) {
2614 _do_fog_type = PerPixelFog;
2618 nassertv((_screen->_d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGVERTEX) != 0);
2623 if (dx_no_vertex_fog) {
2624 _do_fog_type = None;
2626 _do_fog_type = PerVertexFog;
2629 if (dx_use_rangebased_fog && (_screen->_d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGRANGE)) {
2635 _screen->_can_direct_disable_color_writes = ((_screen->_d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE) != 0);
2641 bool dither_enabled = ((!dx_no_dithering) && IS_16BPP_DISPLAY_FORMAT(_screen->_presentation_params.BackBufferFormat)
2642 && (_screen->_d3dcaps.RasterCaps & D3DPRASTERCAPS_DITHER));
2649 if (_supports_two_sided_stencil) {
2657 _current_fill_mode = RenderModeAttrib::M_filled;
2664 _cull_face_mode = CullFaceAttrib::M_cull_none;
2677 _current_shader =
nullptr;
2678 _current_shader_context =
nullptr;
2679 _vertex_array_shader =
nullptr;
2680 _vertex_array_shader_context =
nullptr;
2681 _texture_binding_shader =
nullptr;
2682 _texture_binding_shader_context =
nullptr;
2684 PRINT_REFCNT(dxgsg9, _d3d_device);
2694 void DXGraphicsStateGuardian9::
2695 apply_fog(
Fog *fog) {
2696 if (_do_fog_type == None)
2699 Fog::Mode panda_fogmode = fog->get_mode();
2700 D3DFOGMODE d3dfogmode = get_fog_mode_type(panda_fogmode);
2704 const LColor &fog_colr = fog->
get_color();
2706 MY_D3DRGBA(fog_colr[0], fog_colr[1], fog_colr[2], 0.0f));
2712 switch (panda_fogmode) {
2715 PN_stdfloat onset, opaque;
2719 *((LPDWORD) (&onset)));
2721 *((LPDWORD) (&opaque)));
2724 case Fog::M_exponential:
2725 case Fog::M_exponential_squared:
2730 *((LPDWORD) (&fog_density)));
2743 void DXGraphicsStateGuardian9::
2744 do_issue_transform() {
2746 DO_PSTATS_STUFF(_transform_state_pcollector.add_level(1));
2748 if (_current_shader_context) {
2754 LMatrix4f mat = LCAST(
float, transform->
get_mat());
2755 const D3DMATRIX *d3d_mat = (
const D3DMATRIX *)mat.get_data();
2756 _d3d_device->SetTransform(D3DTS_WORLD, d3d_mat);
2760 LMatrix4f mat = LCAST(
float, transform->
get_mat());
2761 const D3DMATRIX *d3d_mat = (
const D3DMATRIX *)mat.get_data();
2762 _d3d_device->SetTransform(D3DTS_WORLD, d3d_mat);
2777 _transform_stale =
false;
2783 void DXGraphicsStateGuardian9::
2784 do_issue_alpha_test() {
2785 if (_target_shader->get_flag(ShaderAttrib::F_subsume_alpha_test)) {
2789 AlphaTestAttrib::PandaCompareFunc mode = target_alpha_test->
get_mode();
2790 if (mode == AlphaTestAttrib::M_none) {
2804 void DXGraphicsStateGuardian9::
2809 if (_target_shader) {
2810 shader = (
Shader *)(_target_shader->get_shader());
2816 if (context == 0 || (context && context -> valid (
this) ==
false)) {
2817 if (_current_shader_context != 0) {
2818 _current_shader_context->
unbind(
this);
2819 _current_shader = 0;
2820 _current_shader_context = 0;
2821 disable_standard_texture_bindings();
2826 if (context != _current_shader_context) {
2829 if (_current_shader_context != 0) {
2830 _current_shader_context->
unbind(
this);
2831 _current_shader_context = 0;
2832 _current_shader = 0;
2833 disable_standard_texture_bindings();
2836 context->
bind(
this);
2837 _current_shader = shader;
2838 _current_shader_context = context;
2849 void DXGraphicsStateGuardian9::
2850 do_issue_render_mode() {
2852 _target_rs->get_attrib_def(target_render_mode);
2853 RenderModeAttrib::Mode mode = target_render_mode->
get_mode();
2856 case RenderModeAttrib::M_unchanged:
2857 case RenderModeAttrib::M_filled:
2858 case RenderModeAttrib::M_filled_flat:
2862 case RenderModeAttrib::M_wireframe:
2866 case RenderModeAttrib::M_point:
2872 <<
"Unknown render mode " << (int)mode << endl;
2876 PN_stdfloat point_size = target_render_mode->
get_thickness();
2882 LVector3 height(0.0f, point_size, 1.0f);
2883 height = height * _projection_mat->get_mat();
2884 PN_stdfloat s = height[1] / point_size;
2886 PN_stdfloat zero = 0.0f;
2887 PN_stdfloat one_over_s2 = 1.0f / (s * s);
2896 _current_fill_mode = mode;
2902 void DXGraphicsStateGuardian9::
2903 do_issue_rescale_normal() {
2904 RescaleNormalAttrib::Mode mode = RescaleNormalAttrib::M_none;
2907 if (_target_rs->get_attrib(target_rescale_normal)) {
2908 mode = target_rescale_normal->
get_mode();
2912 case RescaleNormalAttrib::M_none:
2916 case RescaleNormalAttrib::M_rescale:
2917 case RescaleNormalAttrib::M_normalize:
2923 <<
"Unknown rescale_normal mode " << (int)mode << endl;
2930 void DXGraphicsStateGuardian9::
2931 do_issue_depth_test() {
2933 DepthTestAttrib::PandaCompareFunc mode = target_depth_test->
get_mode();
2934 if (mode == DepthTestAttrib::M_none) {
2945 void DXGraphicsStateGuardian9::
2946 do_issue_depth_write() {
2948 DepthWriteAttrib::Mode mode = target_depth_write->
get_mode();
2949 if (mode == DepthWriteAttrib::M_on) {
2959 void DXGraphicsStateGuardian9::
2960 do_issue_cull_face() {
2964 switch (_cull_face_mode) {
2965 case CullFaceAttrib::M_cull_none:
2971 case CullFaceAttrib::M_cull_clockwise:
2977 case CullFaceAttrib::M_cull_counter_clockwise:
2985 <<
"invalid cull face mode " << (int)_cull_face_mode << endl;
2993 void DXGraphicsStateGuardian9::
2995 const FogAttrib *target_fog = DCAST(
FogAttrib, _target_rs->get_attrib_def(FogAttrib::get_class_slot()));
2996 if (!target_fog->
is_off()) {
2999 nassertv(fog !=
nullptr);
3009 void DXGraphicsStateGuardian9::
3010 do_issue_depth_offset() {
3012 int offset = target_depth_offset->
get_offset();
3014 if (_supports_depth_bias && !dx_broken_depth_bias) {
3021 static const PN_stdfloat bias_scale = dx_depth_bias_scale;
3022 D3DVIEWPORT9 vp = _current_viewport;
3023 vp.MinZ -= bias_scale * offset;
3024 vp.MaxZ -= bias_scale * offset;
3025 _d3d_device->SetViewport(&vp);
3032 void DXGraphicsStateGuardian9::
3033 do_issue_shade_model() {
3035 switch (target_shade_model->
get_mode()) {
3036 case ShadeModelAttrib::M_smooth:
3040 case ShadeModelAttrib::M_flat:
3062 if (gsg_cat.is_spam()) {
3063 gsg_cat.spam() <<
"Setting GSG state to " << (
void *)target <<
":\n";
3064 target->write(gsg_cat.spam(
false), 2);
3067 _state_pcollector.add_level(1);
3068 PStatTimer timer1(_draw_set_state_pcollector);
3070 if (transform != _internal_transform) {
3072 _state_pcollector.add_level(1);
3073 _internal_transform = transform;
3074 do_issue_transform();
3077 if (target == _state_rs && (_state_mask | _inv_state_mask).is_all_on()) {
3080 _target_rs = target;
3082 determine_target_shader();
3084 int alpha_test_slot = AlphaTestAttrib::get_class_slot();
3085 if (_target_rs->get_attrib(alpha_test_slot) != _state_rs->get_attrib(alpha_test_slot) ||
3086 !_state_mask.get_bit(alpha_test_slot)) {
3088 do_issue_alpha_test();
3089 _state_mask.set_bit(alpha_test_slot);
3092 int clip_plane_slot = ClipPlaneAttrib::get_class_slot();
3093 if (_target_rs->get_attrib(clip_plane_slot) != _state_rs->get_attrib(clip_plane_slot) ||
3094 !_state_mask.get_bit(clip_plane_slot)) {
3096 do_issue_clip_plane();
3097 _state_mask.set_bit(clip_plane_slot);
3100 int color_slot = ColorAttrib::get_class_slot();
3101 int color_scale_slot = ColorScaleAttrib::get_class_slot();
3102 if (_target_rs->get_attrib(color_slot) != _state_rs->get_attrib(color_slot) ||
3103 _target_rs->get_attrib(color_scale_slot) != _state_rs->get_attrib(color_scale_slot) ||
3104 !_state_mask.get_bit(color_slot) ||
3105 !_state_mask.get_bit(color_scale_slot)) {
3108 do_issue_color_scale();
3109 _state_mask.set_bit(color_slot);
3110 _state_mask.set_bit(color_scale_slot);
3111 if (_current_shader_context) {
3117 int cull_face_slot = CullFaceAttrib::get_class_slot();
3118 if (_target_rs->get_attrib(cull_face_slot) != _state_rs->get_attrib(cull_face_slot) ||
3119 !_state_mask.get_bit(cull_face_slot)) {
3121 do_issue_cull_face();
3122 _state_mask.set_bit(cull_face_slot);
3125 int depth_offset_slot = DepthOffsetAttrib::get_class_slot();
3126 if (_target_rs->get_attrib(depth_offset_slot) != _state_rs->get_attrib(depth_offset_slot) ||
3127 !_state_mask.get_bit(depth_offset_slot)) {
3129 do_issue_depth_offset();
3130 _state_mask.set_bit(depth_offset_slot);
3133 int depth_test_slot = DepthTestAttrib::get_class_slot();
3134 if (_target_rs->get_attrib(depth_test_slot) != _state_rs->get_attrib(depth_test_slot) ||
3135 !_state_mask.get_bit(depth_test_slot)) {
3137 do_issue_depth_test();
3138 _state_mask.set_bit(depth_test_slot);
3141 int depth_write_slot = DepthWriteAttrib::get_class_slot();
3142 if (_target_rs->get_attrib(depth_write_slot) != _state_rs->get_attrib(depth_write_slot) ||
3143 !_state_mask.get_bit(depth_write_slot)) {
3145 do_issue_depth_write();
3146 _state_mask.set_bit(depth_write_slot);
3149 int render_mode_slot = RenderModeAttrib::get_class_slot();
3150 if (_target_rs->get_attrib(render_mode_slot) != _state_rs->get_attrib(render_mode_slot) ||
3151 !_state_mask.get_bit(render_mode_slot)) {
3153 do_issue_render_mode();
3154 _state_mask.set_bit(render_mode_slot);
3157 int rescale_normal_slot = RescaleNormalAttrib::get_class_slot();
3158 if (_target_rs->get_attrib(rescale_normal_slot) != _state_rs->get_attrib(rescale_normal_slot) ||
3159 !_state_mask.get_bit(rescale_normal_slot)) {
3161 do_issue_rescale_normal();
3162 _state_mask.set_bit(rescale_normal_slot);
3165 int shade_model_slot = ShadeModelAttrib::get_class_slot();
3166 if (_target_rs->get_attrib(shade_model_slot) != _state_rs->get_attrib(shade_model_slot) ||
3167 !_state_mask.get_bit(shade_model_slot)) {
3169 do_issue_shade_model();
3170 _state_mask.set_bit(shade_model_slot);
3173 int transparency_slot = TransparencyAttrib::get_class_slot();
3174 int color_write_slot = ColorWriteAttrib::get_class_slot();
3175 int color_blend_slot = ColorBlendAttrib::get_class_slot();
3176 if (_target_rs->get_attrib(transparency_slot) != _state_rs->get_attrib(transparency_slot) ||
3177 _target_rs->get_attrib(color_write_slot) != _state_rs->get_attrib(color_write_slot) ||
3178 _target_rs->get_attrib(color_blend_slot) != _state_rs->get_attrib(color_blend_slot) ||
3179 !_state_mask.get_bit(transparency_slot) ||
3180 !_state_mask.get_bit(color_write_slot) ||
3181 !_state_mask.get_bit(color_blend_slot) ||
3182 (_target_shader->get_flag(ShaderAttrib::F_disable_alpha_write) !=
3183 _state_shader->get_flag(ShaderAttrib::F_disable_alpha_write))) {
3185 do_issue_blending();
3186 _state_mask.set_bit(transparency_slot);
3187 _state_mask.set_bit(color_write_slot);
3188 _state_mask.set_bit(color_blend_slot);
3191 if (_target_shader != _state_shader) {
3194 _state_shader = _target_shader;
3195 _state_mask.clear_bit(TextureAttrib::get_class_slot());
3198 int texture_slot = TextureAttrib::get_class_slot();
3199 int tex_matrix_slot = TexMatrixAttrib::get_class_slot();
3200 int tex_gen_slot = TexGenAttrib::get_class_slot();
3201 if (_target_rs->get_attrib(texture_slot) != _state_rs->get_attrib(texture_slot) ||
3202 _target_rs->get_attrib(tex_matrix_slot) != _state_rs->get_attrib(tex_matrix_slot) ||
3203 _target_rs->get_attrib(tex_gen_slot) != _state_rs->get_attrib(tex_gen_slot) ||
3204 !_state_mask.get_bit(texture_slot) ||
3205 !_state_mask.get_bit(tex_matrix_slot) ||
3206 !_state_mask.get_bit(tex_gen_slot)) {
3208 determine_target_texture();
3211 _state_texture = _target_texture;
3212 _state_mask.set_bit(texture_slot);
3213 _state_mask.set_bit(tex_matrix_slot);
3214 _state_mask.set_bit(tex_gen_slot);
3217 int material_slot = MaterialAttrib::get_class_slot();
3218 if (_target_rs->get_attrib(material_slot) != _state_rs->get_attrib(material_slot) ||
3219 !_state_mask.get_bit(material_slot)) {
3221 do_issue_material();
3222 _state_mask.set_bit(material_slot);
3223 if (_current_shader_context) {
3228 int light_slot = LightAttrib::get_class_slot();
3229 if (_target_rs->get_attrib(light_slot) != _state_rs->get_attrib(light_slot) ||
3230 !_state_mask.get_bit(light_slot)) {
3233 _state_mask.set_bit(light_slot);
3236 int stencil_slot = StencilAttrib::get_class_slot();
3237 if (_target_rs->get_attrib(stencil_slot) != _state_rs->get_attrib(stencil_slot) ||
3238 !_state_mask.get_bit(stencil_slot)) {
3241 _state_mask.set_bit(stencil_slot);
3244 int fog_slot = FogAttrib::get_class_slot();
3245 if (_target_rs->get_attrib(fog_slot) != _state_rs->get_attrib(fog_slot) ||
3246 !_state_mask.get_bit(fog_slot)) {
3249 _state_mask.set_bit(fog_slot);
3250 if (_current_shader_context) {
3255 int scissor_slot = ScissorAttrib::get_class_slot();
3256 if (_target_rs->get_attrib(scissor_slot) != _state_rs->get_attrib(scissor_slot) ||
3257 !_state_mask.get_bit(scissor_slot)) {
3260 _state_mask.set_bit(scissor_slot);
3263 _state_rs = _target_rs;
3277 const LMatrix4 &light_mat = transform->
get_mat();
3278 LMatrix4 rel_mat = light_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
3279 LPoint3f pos = LCAST(
float, light_obj->
get_point() * rel_mat);
3281 D3DCOLORVALUE black;
3282 black.r = black.g = black.b = black.a = 0.0f;
3284 alight.Type = D3DLIGHT_POINT;
3285 alight.Diffuse = get_light_color(light_obj);
3286 alight.Ambient = black ;
3288 alight.Specular = *(D3DCOLORVALUE *)(color.get_data());
3292 alight.Position = *(D3DVECTOR *)pos.get_data();
3294 alight.Range = __D3DLIGHT_RANGE_MAX;
3295 alight.Falloff = 1.0f;
3298 alight.Attenuation0 = att[0];
3299 alight.Attenuation1 = att[1];
3300 alight.Attenuation2 = att[2];
3302 HRESULT hr = _d3d_device->SetLight(light_id, &alight);
3304 wdxdisplay9_cat.warning()
3305 <<
"Could not set light properties for " << light
3306 <<
" to id " << light_id <<
": " << D3DERRORSTRING(hr) <<
"\n";
3317 static PStatCollector _draw_set_state_light_bind_directional_pcollector(
"Draw:Set State:Light:Bind:Directional");
3320 std::pair<DirectionalLights::iterator, bool> lookup = _dlights.insert(DirectionalLights::value_type(light, D3DLIGHT9()));
3321 D3DLIGHT9 &fdata = (*lookup.first).second;
3322 if (lookup.second) {
3327 const LMatrix4 &light_mat = transform->
get_mat();
3328 LMatrix4 rel_mat = light_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
3329 LVector3f dir = LCAST(
float, light_obj->
get_direction() * rel_mat);
3331 D3DCOLORVALUE black;
3332 black.r = black.g = black.b = black.a = 0.0f;
3334 ZeroMemory(&fdata,
sizeof(D3DLIGHT9));
3336 fdata.Type = D3DLIGHT_DIRECTIONAL;
3337 fdata.Ambient = black ;
3339 fdata.Specular = *(D3DCOLORVALUE *)(color.get_data());
3341 fdata.Direction = *(D3DVECTOR *)dir.get_data();
3343 fdata.Range = __D3DLIGHT_RANGE_MAX;
3344 fdata.Falloff = 1.0f;
3346 fdata.Attenuation0 = 1.0f;
3347 fdata.Attenuation1 = 0.0f;
3348 fdata.Attenuation2 = 0.0f;
3354 fdata.Diffuse = get_light_color(light_obj);
3356 HRESULT hr = _d3d_device->SetLight(light_id, &fdata);
3358 wdxdisplay9_cat.warning()
3359 <<
"Could not set light properties for " << light
3360 <<
" to id " << light_id <<
": " << D3DERRORSTRING(hr) <<
"\n";
3372 nassertv(lens !=
nullptr);
3378 const LMatrix4 &light_mat = transform->
get_mat();
3379 LMatrix4 rel_mat = light_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
3383 D3DCOLORVALUE black;
3384 black.r = black.g = black.b = black.a = 0.0f;
3387 ZeroMemory(&alight,
sizeof(D3DLIGHT9));
3389 alight.Type = D3DLIGHT_SPOT;
3390 alight.Ambient = black ;
3391 alight.Diffuse = get_light_color(light_obj);
3393 alight.Specular = *(D3DCOLORVALUE *)(color.get_data());
3395 alight.Position = *(D3DVECTOR *)pos.get_data();
3397 alight.Direction = *(D3DVECTOR *)dir.get_data();
3399 alight.Range = __D3DLIGHT_RANGE_MAX;
3403 PN_stdfloat fov = lens->
get_hfov();
3404 alight.Falloff = light_obj->
get_exponent() * (fov * fov * fov) / 1620000.0f;
3406 alight.Theta = 0.0f;
3407 alight.Phi = deg_2_rad(fov);
3410 alight.Attenuation0 = att[0];
3411 alight.Attenuation1 = att[1];
3412 alight.Attenuation2 = att[2];
3414 HRESULT hr = _d3d_device->SetLight(light_id, &alight);
3416 wdxdisplay9_cat.warning()
3417 <<
"Could not set light properties for " << light
3418 <<
" to id " << light_id <<
": " << D3DERRORSTRING(hr) <<
"\n";
3427 switch (numeric_type) {
3429 case Geom::NT_uint8:
3430 case Geom::NT_uint16:
3431 return D3DFMT_INDEX16;
3433 case Geom::NT_uint32:
3434 return D3DFMT_INDEX32;
3438 <<
"Invalid index NumericType value (" << (int)numeric_type <<
")\n";
3439 return D3DFMT_INDEX16;
3445 void DXGraphicsStateGuardian9::
3446 do_issue_material() {
3450 if (target_material->
is_off()) {
3456 D3DMATERIAL9 cur_material;
3457 LColorf color = LCAST(
float, material->
get_diffuse());
3458 cur_material.Diffuse = *(D3DCOLORVALUE *)(color.get_data());
3460 cur_material.Ambient = *(D3DCOLORVALUE *)(color.get_data());
3462 cur_material.Specular = *(D3DCOLORVALUE *)(color.get_data());
3464 cur_material.Emissive = *(D3DCOLORVALUE *)(color.get_data());
3472 if (_has_material_force_color) {
3473 color = LCAST(
float, _material_force_color);
3474 cur_material.Diffuse = *(D3DCOLORVALUE *)color.get_data();
3485 if (_has_material_force_color) {
3486 color = LCAST(
float, _material_force_color);
3487 cur_material.Ambient = *(D3DCOLORVALUE *)color.get_data();
3506 _d3d_device->SetMaterial(&cur_material);
3512 void DXGraphicsStateGuardian9::
3513 do_issue_texture() {
3514 DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
3516 if (_texture_binding_shader_context==0) {
3517 if (_current_shader_context==0) {
3518 update_standard_texture_bindings();
3520 disable_standard_texture_bindings();
3524 if (_current_shader_context==0) {
3526 update_standard_texture_bindings();
3528 _current_shader_context->
3529 update_shader_texture_bindings(_texture_binding_shader_context,
this);
3532 _texture_binding_shader = _current_shader;
3533 _texture_binding_shader_context = _current_shader_context;
3539 void DXGraphicsStateGuardian9::
3540 disable_standard_texture_bindings() {
3542 for (
int i = 0; i < _num_active_texture_stages; i++) {
3545 hr = _d3d_device -> SetTexture (i,
nullptr);
3550 <<
", NULL) failed " 3551 << D3DERRORSTRING(hr);
3556 _num_active_texture_stages = 0;
3562 void DXGraphicsStateGuardian9::
3563 update_standard_texture_bindings() {
3564 DO_PSTATS_STUFF(_texture_state_pcollector.add_level(1));
3566 int num_stages = _target_texture->get_num_on_ff_stages();
3567 int num_old_stages = _max_texture_stages;
3568 if (_state_texture !=
nullptr) {
3569 num_old_stages = _state_texture->get_num_on_ff_stages();
3572 nassertv(num_stages <= _max_texture_stages &&
3573 _num_active_texture_stages <= _max_texture_stages);
3575 _texture_involves_color_scale =
false;
3582 for (si = 0; si < num_stages; si++) {
3583 TextureStage *stage = _target_texture->get_on_ff_stage(si);
3584 int texcoord_index = _target_texture->get_ff_tc_index(si);
3586 Texture *texture = _target_texture->get_on_texture(stage);
3587 nassertv(texture !=
nullptr);
3588 const SamplerState &sampler = _target_texture->get_on_sampler(stage);
3595 set_texture_blend_mode(si, stage);
3597 int texcoord_dimensions = 2;
3601 if (target_tex_matrix->has_stage(stage)) {
3602 tex_mat = target_tex_matrix->get_transform(stage);
3606 TexGenAttrib::Mode mode = _target_tex_gen->get_mode(stage);
3607 bool any_point_sprite =
false;
3610 case TexGenAttrib::M_off:
3611 case TexGenAttrib::M_unused2:
3615 case TexGenAttrib::M_eye_sphere_map:
3618 texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
3623 TransformState::make_mat(LMatrix4(0.33, 0.0f, 0.0f, 0.0f,
3624 0.0f, 0.33, 0.0f, 0.0f,
3625 0.0f, 0.0f, 1.0f, 0.0f,
3626 0.5f, 0.5f, 0.0f, 1.0f));
3627 tex_mat = tex_mat->compose(sphere_map);
3628 texcoord_dimensions = 3;
3632 case TexGenAttrib::M_world_cube_map:
3639 texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
3640 texcoord_dimensions = 3;
3641 CPT(
TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
3642 tex_mat = tex_mat->compose(camera_transform->set_pos(LVecBase3::zero()));
3646 case TexGenAttrib::M_eye_cube_map:
3648 texcoord_index | D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
3649 tex_mat = tex_mat->compose(_inv_cs_transform);
3650 texcoord_dimensions = 3;
3653 case TexGenAttrib::M_world_normal:
3659 texcoord_index | D3DTSS_TCI_CAMERASPACENORMAL);
3660 texcoord_dimensions = 3;
3661 CPT(
TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
3662 tex_mat = tex_mat->compose(camera_transform->set_pos(LVecBase3::zero()));
3666 case TexGenAttrib::M_eye_normal:
3668 texcoord_index | D3DTSS_TCI_CAMERASPACENORMAL);
3669 texcoord_dimensions = 3;
3670 tex_mat = tex_mat->compose(_inv_cs_transform);
3673 case TexGenAttrib::M_world_position:
3678 texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
3679 texcoord_dimensions = 3;
3680 CPT(
TransformState) camera_transform = _scene_setup->get_camera_transform()->compose(_inv_cs_transform);
3681 tex_mat = tex_mat->compose(camera_transform);
3685 case TexGenAttrib::M_eye_position:
3687 texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
3688 texcoord_dimensions = 3;
3689 tex_mat = tex_mat->compose(_inv_cs_transform);
3692 case TexGenAttrib::M_point_sprite:
3694 any_point_sprite =
true;
3697 case TexGenAttrib::M_constant:
3710 texcoord_index | D3DTSS_TCI_CAMERASPACEPOSITION);
3711 texcoord_dimensions = 3;
3713 const LTexCoord3 &v = _target_tex_gen->get_constant_value(stage);
3715 TransformState::make_pos_hpr_scale(v, LVecBase3::zero(),
3717 tex_mat = tex_mat->compose(squash);
3724 if (!tex_mat->is_identity()) {
3725 if ( texcoord_dimensions <= 2) {
3727 LMatrix4 m = tex_mat->get_mat();
3729 mf.set(m(0, 0), m(0, 1), m(0, 3), 0.0f,
3730 m(1, 0), m(1, 1), m(1, 3), 0.0f,
3731 m(3, 0), m(3, 1), m(3, 3), 0.0f,
3732 0.0f, 0.0f, 0.0f, 1.0f);
3733 _d3d_device->SetTransform(get_tex_mat_sym(si), (D3DMATRIX *)mf.get_data());
3737 LMatrix4f mf = LCAST(
float, tex_mat->get_mat());
3738 _d3d_device->SetTransform(get_tex_mat_sym(si), (D3DMATRIX *)mf.get_data());
3739 DWORD transform_flags = texcoord_dimensions;
3740 if (mf.get_col(3) != LVecBase4f(0.0f, 0.0f, 0.0f, 1.0f)) {
3743 transform_flags = D3DTTFF_COUNT4 | D3DTTFF_PROJECTED;
3755 _d3d_device->SetTransform(get_tex_mat_sym(si), &_d3d_ident_mat);
3760 for (si = num_stages; si < _num_active_texture_stages; si++) {
3762 _d3d_device->SetTexture(si,
nullptr);
3766 _num_active_texture_stages = num_stages;
3774 void DXGraphicsStateGuardian9::
3775 do_issue_blending() {
3780 unsigned int color_channels =
3781 target_color_write->
get_channels() & _color_write_mask;
3782 if (_target_shader->get_flag(ShaderAttrib::F_disable_alpha_write)) {
3783 color_channels &= ~(ColorWriteAttrib::C_alpha);
3785 if (color_channels == ColorWriteAttrib::C_off) {
3786 if (_screen->_can_direct_disable_color_writes) {
3796 if (_screen->_can_direct_disable_color_writes) {
3802 _target_rs->get_attrib_def(color_blend);
3803 ColorBlendAttrib::Mode color_blend_mode = color_blend->
get_mode();
3806 _target_rs->get_attrib_def(target_transparency);
3807 TransparencyAttrib::Mode transparency_mode = target_transparency->
get_mode();
3810 if (color_blend_mode != ColorBlendAttrib::M_none) {
3823 switch (transparency_mode) {
3824 case TransparencyAttrib::M_none:
3825 case TransparencyAttrib::M_binary:
3828 case TransparencyAttrib::M_alpha:
3829 case TransparencyAttrib::M_multisample:
3830 case TransparencyAttrib::M_multisample_mask:
3831 case TransparencyAttrib::M_dual:
3833 if (old_alpha_blend) {
3846 case TransparencyAttrib::M_premultiplied_alpha:
3856 <<
"invalid transparency mode " << (int)transparency_mode << endl;
3869 void DXGraphicsStateGuardian9::
3870 reissue_transforms() {
3872 do_issue_transform();
3880 void DXGraphicsStateGuardian9::
3881 enable_lighting(
bool enable) {
3890 void DXGraphicsStateGuardian9::
3891 set_ambient_light(
const LColor &color) {
3893 c.set(c[0] * _light_color_scale[0],
3894 c[1] * _light_color_scale[1],
3895 c[2] * _light_color_scale[2],
3896 c[3] * _light_color_scale[3]);
3906 void DXGraphicsStateGuardian9::
3907 enable_light(
int light_id,
bool enable) {
3908 HRESULT hr = _d3d_device->LightEnable(light_id, enable);
3911 wdxdisplay9_cat.warning()
3912 <<
"Could not enable light " << light_id <<
": " 3913 << D3DERRORSTRING(hr) <<
"\n";
3922 void DXGraphicsStateGuardian9::
3923 enable_clip_plane(
int plane_id,
bool enable) {
3925 _clip_plane_bits |= ((DWORD)1 << plane_id);
3927 _clip_plane_bits &= ~((DWORD)1 << plane_id);
3937 void DXGraphicsStateGuardian9::
3938 bind_clip_plane(
const NodePath &plane,
int plane_id) {
3943 const LMatrix4 &plane_mat = transform->
get_mat();
3944 LMatrix4 rel_mat = plane_mat * LMatrix4::convert_mat(CS_yup_left, CS_default);
3946 DCAST_INTO_V(plane_node, plane.
node());
3947 LPlanef world_plane = LCAST(
float, plane_node->
get_plane() * rel_mat);
3949 HRESULT hr = _d3d_device->SetClipPlane(plane_id, world_plane.get_data());
3951 wdxdisplay9_cat.warning()
3952 <<
"Could not set clip plane for " << plane
3953 <<
" to id " << plane_id <<
": " << D3DERRORSTRING(hr) <<
"\n";
3962 void DXGraphicsStateGuardian9::
3964 GraphicsStateGuardian::close_gsg();
3966 if (_prepared_objects.is_null()) {
3970 if (dxgsg9_cat.is_debug()) {
3972 <<
"Closing GSG, prepared_objects count = " 3973 << _prepared_objects->get_ref_count() <<
"\n";
3978 if (_prepared_objects->get_ref_count() == 1) {
3983 _prepared_objects->begin_frame(
this, current_thread);
3984 _prepared_objects->end_frame(current_thread);
3991 void DXGraphicsStateGuardian9::
3992 free_nondx_resources() {
3995 cgDestroyContext(_cg_context);
4005 void DXGraphicsStateGuardian9::
4008 _state_rs = RenderState::make_empty();
4009 _state_mask.clear();
4013 _dx_is_ready =
false;
4015 if (_d3d_device !=
nullptr) {
4016 for(
int i = 0; i < D3D_MAXTEXTURESTAGES; i++) {
4018 _d3d_device->SetTexture(i,
nullptr);
4024 if (_d3d_device !=
nullptr) {
4025 RELEASE(_d3d_device, dxgsg9,
"d3dDevice", RELEASE_DOWN_TO_ZERO);
4028 free_nondx_resources();
4038 void DXGraphicsStateGuardian9::
4040 dxgsg9_cat.fatal() <<
"DX set_draw_buffer unimplemented!!!";
4047 void DXGraphicsStateGuardian9::
4049 if (rb._buffer_type & RenderBuffer::T_front) {
4050 _cur_read_pixel_buffer = RenderBuffer::T_front;
4051 }
else if (rb._buffer_type & RenderBuffer::T_back) {
4052 _cur_read_pixel_buffer = RenderBuffer::T_back;
4053 }
else if (rb._buffer_type & RenderBuffer::T_aux_rgba_ALL) {
4054 _cur_read_pixel_buffer = RenderBuffer::T_back;
4056 dxgsg9_cat.error() <<
"Invalid or unimplemented Argument to set_read_buffer!\n";
4066 const D3DCOLORVALUE &DXGraphicsStateGuardian9::
4067 get_light_color(
Light *light)
const {
4070 cf.set(c[0] * _light_color_scale[0],
4071 c[1] * _light_color_scale[1],
4072 c[2] * _light_color_scale[2],
4073 c[3] * _light_color_scale[3]);
4074 return *(D3DCOLORVALUE *)cf.get_data();
4080 D3DBLENDOP DXGraphicsStateGuardian9::
4081 get_blend_mode(ColorBlendAttrib::Mode mode) {
4083 case ColorBlendAttrib::M_add:
4084 return D3DBLENDOP_ADD;
4086 case ColorBlendAttrib::M_subtract:
4087 return D3DBLENDOP_SUBTRACT;
4089 case ColorBlendAttrib::M_inv_subtract:
4090 return D3DBLENDOP_REVSUBTRACT;
4092 case ColorBlendAttrib::M_min:
4093 return D3DBLENDOP_MIN;
4095 case ColorBlendAttrib::M_max:
4096 return D3DBLENDOP_MAX;
4100 <<
"Unknown color blend mode " << (int)mode << endl;
4101 return D3DBLENDOP_ADD;
4107 D3DBLEND DXGraphicsStateGuardian9::
4108 get_blend_func(ColorBlendAttrib::Operand operand) {
4110 case ColorBlendAttrib::O_zero:
4111 return D3DBLEND_ZERO;
4113 case ColorBlendAttrib::O_one:
4114 return D3DBLEND_ONE;
4116 case ColorBlendAttrib::O_incoming_color:
4117 return D3DBLEND_SRCCOLOR;
4119 case ColorBlendAttrib::O_one_minus_incoming_color:
4120 return D3DBLEND_INVSRCCOLOR;
4122 case ColorBlendAttrib::O_fbuffer_color:
4123 return D3DBLEND_DESTCOLOR;
4125 case ColorBlendAttrib::O_one_minus_fbuffer_color:
4126 return D3DBLEND_INVDESTCOLOR;
4128 case ColorBlendAttrib::O_incoming_alpha:
4129 return D3DBLEND_SRCALPHA;
4131 case ColorBlendAttrib::O_one_minus_incoming_alpha:
4132 return D3DBLEND_INVSRCALPHA;
4134 case ColorBlendAttrib::O_fbuffer_alpha:
4135 return D3DBLEND_DESTALPHA;
4137 case ColorBlendAttrib::O_one_minus_fbuffer_alpha:
4138 return D3DBLEND_INVDESTALPHA;
4140 case ColorBlendAttrib::O_constant_color:
4142 return D3DBLEND_SRCCOLOR;
4144 case ColorBlendAttrib::O_one_minus_constant_color:
4146 return D3DBLEND_INVSRCCOLOR;
4148 case ColorBlendAttrib::O_constant_alpha:
4150 return D3DBLEND_SRCALPHA;
4152 case ColorBlendAttrib::O_one_minus_constant_alpha:
4154 return D3DBLEND_INVSRCALPHA;
4156 case ColorBlendAttrib::O_incoming_color_saturate:
4157 return D3DBLEND_SRCALPHASAT;
4159 case ColorBlendAttrib::O_incoming1_color:
4160 return (D3DBLEND)16;
4162 case ColorBlendAttrib::O_one_minus_incoming1_color:
4163 return (D3DBLEND)17;
4165 case ColorBlendAttrib::O_incoming1_alpha:
4167 return (D3DBLEND)18;
4169 case ColorBlendAttrib::O_one_minus_incoming1_alpha:
4171 return (D3DBLEND)19;
4175 <<
"Unknown color blend operand " << (int)operand << endl;
4176 return D3DBLEND_ZERO;
4182 void DXGraphicsStateGuardian9::
4183 report_texmgr_stats() {
4189 #ifdef TEXMGRSTATS_USES_GETAVAILVIDMEM 4190 DWORD dwTexTotal, dwTexFree, dwVidTotal, dwVidFree;
4192 if (_total_texmem_pcollector.is_active()) {
4195 ZeroMemory(&ddsCaps,
sizeof(ddsCaps));
4197 ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
4198 if (FAILED( hr = _d3d_device->GetAvailableVidMem(&ddsCaps, &dwVidTotal, &dwVidFree))) {
4199 dxgsg9_cat.fatal() <<
"report_texmgr GetAvailableVidMem for VIDMEM failed : result = " << D3DERRORSTRING(hr);
4200 throw_event(
"panda3d-render-error");
4204 ddsCaps.dwCaps = DDSCAPS_TEXTURE;
4205 if (FAILED( hr = _d3d_device->GetAvailableVidMem(&ddsCaps, &dwTexTotal, &dwTexFree))) {
4206 dxgsg9_cat.fatal() <<
"report_texmgr GetAvailableVidMem for TEXTURE failed : result = " << D3DERRORSTRING(hr);
4207 throw_event(
"panda3d-render-error");
4211 #endif // TEXMGRSTATS_USES_GETAVAILVIDMEM 4213 D3DDEVINFO_RESOURCEMANAGER all_resource_stats;
4214 ZeroMemory(&all_resource_stats,
sizeof(D3DDEVINFO_RESOURCEMANAGER));
4241 if (_texmgrmem_total_pcollector.is_active()) {
4243 _texmgrmem_total_pcollector.set_level(all_resource_stats.stats[D3DRTYPE_TEXTURE].TotalBytes);
4244 _texmgrmem_resident_pcollector.set_level(all_resource_stats.stats[D3DRTYPE_TEXTURE].WorkingSetBytes);
4246 #ifdef TEXMGRSTATS_USES_GETAVAILVIDMEM 4247 if (_total_texmem_pcollector.is_active()) {
4248 _total_texmem_pcollector.set_level(dwTexTotal);
4249 _used_texmem_pcollector.set_level(dwTexTotal - dwTexFree);
4251 #endif // TEXMGRSTATS_USES_GETAVAILVIDMEM 4258 void DXGraphicsStateGuardian9::
4260 nassertv(new_context !=
nullptr);
4261 _screen = new_context;
4262 _d3d_device = _screen->_d3d_device;
4263 _swap_chain = _screen->_swap_chain;
4265 _screen->_dxgsg9 =
this;
4272 void DXGraphicsStateGuardian9::
4273 set_render_target() {
4274 if (_d3d_device ==
nullptr) {
4278 LPDIRECT3DSURFACE9 back =
nullptr, stencil =
nullptr;
4286 _d3d_device->GetBackBuffer(swap_chain, 0, D3DBACKBUFFER_TYPE_MONO, &back);
4288 _swap_chain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &back);
4293 _d3d_device->GetDepthStencilSurface(&stencil);
4296 DWORD render_target_index;
4297 render_target_index = 0;
4298 _d3d_device->SetRenderTarget(render_target_index, back);
4311 void DXGraphicsStateGuardian9::
4312 set_texture_blend_mode(
int i,
const TextureStage *stage) {
4314 case TextureStage::M_modulate:
4315 case TextureStage::M_modulate_glow:
4316 case TextureStage::M_modulate_gloss:
4326 case TextureStage::M_decal:
4336 case TextureStage::M_replace:
4344 case TextureStage::M_add:
4354 case TextureStage::M_blend:
4355 case TextureStage::M_blend_color_scale:
4368 case TextureStage::M_combine:
4379 (i, D3DTSS_COLORARG0,
4386 (i, D3DTSS_COLORARG2,
4393 (i, D3DTSS_COLORARG1,
4410 (i, D3DTSS_ALPHAARG0,
4417 (i, D3DTSS_ALPHAARG2,
4424 (i, D3DTSS_ALPHAARG1,
4436 <<
"Unknown texture mode " << (int)stage->
get_mode() << endl;
4449 D3DCOLOR constant_color;
4452 color.set(color[0] * _current_color_scale[0],
4453 color[1] * _current_color_scale[1],
4454 color[2] * _current_color_scale[2],
4455 color[3] * _current_color_scale[3]);
4456 _texture_involves_color_scale =
true;
4461 if (_supports_texture_constant_color) {
4475 void DXGraphicsStateGuardian9::
4481 free_nondx_resources();
4482 PRINT_REFCNT(dxgsg9, _d3d_device);
4486 RELEASE(_d3d_device, dxgsg9,
"d3dDevice", RELEASE_DOWN_TO_ZERO);
4487 _screen->_d3d_device =
nullptr;
4499 HRESULT DXGraphicsStateGuardian9::
4500 reset_d3d_device(D3DPRESENT_PARAMETERS *presentation_params,
4504 nassertr(IS_VALID_PTR(presentation_params), E_FAIL);
4505 nassertr(IS_VALID_PTR(_screen->_d3d9), E_FAIL);
4506 nassertr(IS_VALID_PTR(_d3d_device), E_FAIL);
4510 _screen->_d3d9->GetAdapterDisplayMode(_screen->_card_id, &_screen->_display_mode);
4511 presentation_params->BackBufferFormat = _screen->_display_mode.Format;
4518 if (
true || !(_screen->_swap_chain)
4519 || (_presentation_reset.BackBufferWidth < presentation_params->BackBufferWidth)
4520 || (_presentation_reset.BackBufferHeight < presentation_params->BackBufferHeight)) {
4521 if (wdxdisplay9_cat.is_debug()) {
4522 wdxdisplay9_cat.debug()
4523 <<
"swap_chain = " << _screen->_swap_chain <<
" _presentation_reset = " 4524 << _presentation_reset.BackBufferWidth <<
"x" << _presentation_reset.BackBufferHeight
4525 <<
" presentation_params = " 4526 << presentation_params->BackBufferWidth <<
"x" << presentation_params->BackBufferHeight <<
"\n";
4531 if (_screen->_swap_chain) {
4532 _presentation_reset.BackBufferWidth = max(_presentation_reset.BackBufferWidth, presentation_params->BackBufferWidth);
4533 _presentation_reset.BackBufferHeight = max(_presentation_reset.BackBufferHeight, presentation_params->BackBufferHeight);
4536 _presentation_reset.BackBufferWidth = presentation_params->BackBufferWidth;
4537 _presentation_reset.BackBufferHeight = presentation_params->BackBufferHeight;
4549 if (_white_vbuffer !=
nullptr) {
4550 _white_vbuffer->Release();
4551 _white_vbuffer =
nullptr;
4556 _prepared_objects->begin_frame(
this, current_thread);
4561 std::list <wdxGraphicsBuffer9 **>::iterator graphics_buffer_iterator;
4563 for (graphics_buffer_iterator = _graphics_buffer_list.begin( ); graphics_buffer_iterator != _graphics_buffer_list.end( ); graphics_buffer_iterator++)
4565 graphics_buffer = **graphics_buffer_iterator;
4566 if (graphics_buffer -> _color_backing_store)
4568 graphics_buffer -> _color_backing_store -> Release ( );
4569 graphics_buffer -> _color_backing_store = 0;
4571 if (graphics_buffer -> _depth_backing_store)
4573 graphics_buffer -> _depth_backing_store -> Release ( );
4574 graphics_buffer -> _depth_backing_store = 0;
4580 hr = _d3d_device->Reset(&_presentation_reset);
4581 if (FAILED(hr) && hr != D3DERR_DEVICELOST) {
4590 if (presentation_params != &_screen->_presentation_params) {
4591 memcpy(&_screen->_presentation_params, presentation_params,
sizeof(D3DPRESENT_PARAMETERS));
4598 if (_screen && _screen->_swap_chain) {
4599 _screen->_swap_chain->Release();
4600 wdxdisplay9_cat.debug()
4601 <<
"swap chain " << _screen->_swap_chain <<
" is released\n";
4602 _screen->_swap_chain =
nullptr;
4603 hr = _d3d_device->CreateAdditionalSwapChain(presentation_params, &_screen->_swap_chain);
4605 if (SUCCEEDED(hr)) {
4606 if (presentation_params != &_screen->_presentation_params) {
4607 memcpy(&_screen->_presentation_params, presentation_params,
sizeof(D3DPRESENT_PARAMETERS));
4619 bool DXGraphicsStateGuardian9::
4620 check_cooperative_level() {
4621 bool bDoReactivateWindow =
false;
4622 if (_d3d_device ==
nullptr) {
4626 HRESULT hr = _d3d_device->TestCooperativeLevel();
4628 if (SUCCEEDED(hr)) {
4629 nassertr(SUCCEEDED(_last_testcooplevel_result),
false);
4634 case D3DERR_DEVICENOTRESET:
4635 _dx_is_ready =
false;
4638 _prepared_objects->begin_frame(
this, Thread::get_current_thread());
4640 hr = reset_d3d_device(&_screen->_presentation_params);
4645 <<
"check_cooperative_level Reset() failed, hr = " << D3DERRORSTRING(hr);
4648 hr = _d3d_device->TestCooperativeLevel();
4652 <<
"TestCooperativeLevel following Reset() failed, hr = " << D3DERRORSTRING(hr);
4656 _dx_is_ready = TRUE;
4659 case D3DERR_DEVICELOST:
4663 if (SUCCEEDED(_last_testcooplevel_result)) {
4665 _dx_is_ready =
false;
4666 if (dxgsg9_cat.is_debug()) {
4667 dxgsg9_cat.debug() <<
"D3D Device was Lost, waiting...\n";
4673 _last_testcooplevel_result = hr;
4674 return SUCCEEDED(hr);
4680 void DXGraphicsStateGuardian9::
4682 if (_d3d_device ==
nullptr) {
4692 hr = _swap_chain->Present(
nullptr,
nullptr, (HWND)
nullptr,
nullptr, flags);
4694 hr = _d3d_device->Present(
nullptr,
nullptr, (HWND)
nullptr,
nullptr);
4698 if (hr == D3DERR_DEVICELOST) {
4699 check_cooperative_level();
4702 <<
"show_frame() - Present() failed" << D3DERRORSTRING(hr);
4703 throw_event(
"panda3d-render-error");
4711 bool DXGraphicsStateGuardian9::
4719 hr = new_context->_d3d_device->CreateAdditionalSwapChain(&new_context->_presentation_params, &new_context->_swap_chain);
4721 wdxdisplay9_cat.debug() <<
"Swapchain creation failed :"<<D3DERRORSTRING(hr)<<
"\n";
4730 bool DXGraphicsStateGuardian9::
4733 if (new_context->_swap_chain) {
4734 hr = new_context->_swap_chain->Release();
4736 wdxdisplay9_cat.debug() <<
"Swapchain release failed:" << D3DERRORSTRING(hr) <<
"\n";
4746 void DXGraphicsStateGuardian9::
4748 memcpy(&_presentation_reset, &_screen->_presentation_params,
sizeof(D3DPRESENT_PARAMETERS));
4754 D3DTEXTUREFILTERTYPE DXGraphicsStateGuardian9::
4755 get_d3d_min_type(SamplerState::FilterType filter_type) {
4756 switch (filter_type) {
4757 case SamplerState::FT_nearest:
4758 return D3DTEXF_POINT;
4760 case SamplerState::FT_linear:
4761 return D3DTEXF_LINEAR;
4763 case SamplerState::FT_nearest_mipmap_nearest:
4764 return D3DTEXF_POINT;
4766 case SamplerState::FT_linear_mipmap_nearest:
4767 return D3DTEXF_LINEAR;
4769 case SamplerState::FT_nearest_mipmap_linear:
4770 return D3DTEXF_POINT;
4772 case SamplerState::FT_linear_mipmap_linear:
4773 return D3DTEXF_LINEAR;
4775 case SamplerState::FT_shadow:
4776 case SamplerState::FT_default:
4777 return D3DTEXF_LINEAR;
4781 <<
"Invalid FilterType value (" << (int)filter_type <<
")\n";
4782 return D3DTEXF_POINT;
4788 D3DTEXTUREFILTERTYPE DXGraphicsStateGuardian9::
4789 get_d3d_mip_type(SamplerState::FilterType filter_type) {
4790 switch (filter_type) {
4791 case SamplerState::FT_nearest:
4792 return D3DTEXF_NONE;
4794 case SamplerState::FT_linear:
4795 return D3DTEXF_NONE;
4797 case SamplerState::FT_nearest_mipmap_nearest:
4798 return D3DTEXF_POINT;
4800 case SamplerState::FT_linear_mipmap_nearest:
4801 return D3DTEXF_POINT;
4803 case SamplerState::FT_nearest_mipmap_linear:
4804 return D3DTEXF_LINEAR;
4806 case SamplerState::FT_linear_mipmap_linear:
4807 return D3DTEXF_LINEAR;
4809 case SamplerState::FT_shadow:
4810 case SamplerState::FT_default:
4811 return D3DTEXF_NONE;
4815 <<
"Invalid FilterType value (" << (int)filter_type <<
")\n";
4816 return D3DTEXF_NONE;
4823 D3DTEXTUREOP DXGraphicsStateGuardian9::
4824 get_texture_operation(TextureStage::CombineMode mode,
int scale) {
4826 case TextureStage::CM_undefined:
4827 case TextureStage::CM_replace:
4828 return D3DTOP_SELECTARG1;
4830 case TextureStage::CM_modulate:
4832 return D3DTOP_MODULATE;
4833 }
else if (scale < 4) {
4834 return D3DTOP_MODULATE2X;
4836 return D3DTOP_MODULATE4X;
4839 case TextureStage::CM_add:
4842 case TextureStage::CM_add_signed:
4844 return D3DTOP_ADDSIGNED;
4846 return D3DTOP_ADDSIGNED2X;
4849 case TextureStage::CM_interpolate:
4852 case TextureStage::CM_subtract:
4853 return D3DTOP_SUBTRACT;
4855 case TextureStage::CM_dot3_rgb:
4856 case TextureStage::CM_dot3_rgba:
4857 return D3DTOP_DOTPRODUCT3;
4861 <<
"Invalid TextureStage::CombineMode value (" << (int)mode <<
")\n";
4862 return D3DTOP_DISABLE;
4870 DWORD DXGraphicsStateGuardian9::
4871 get_texture_argument(TextureStage::CombineSource source,
4872 TextureStage::CombineOperand operand)
const {
4874 case TextureStage::CS_undefined:
4875 case TextureStage::CS_texture:
4876 return D3DTA_TEXTURE | get_texture_argument_modifier(operand);
4878 case TextureStage::CS_constant:
4879 case TextureStage::CS_constant_color_scale:
4880 return _constant_color_operand | get_texture_argument_modifier(operand);
4882 case TextureStage::CS_primary_color:
4883 return D3DTA_DIFFUSE | get_texture_argument_modifier(operand);
4885 case TextureStage::CS_previous:
4886 return D3DTA_CURRENT | get_texture_argument_modifier(operand);
4888 case TextureStage::CS_last_saved_result:
4889 return D3DTA_TEMP | get_texture_argument_modifier(operand);
4892 <<
"Invalid TextureStage::CombineSource value (" << (int)source <<
")\n";
4893 return D3DTA_CURRENT;
4900 DWORD DXGraphicsStateGuardian9::
4901 get_texture_argument_modifier(TextureStage::CombineOperand operand) {
4903 case TextureStage::CO_src_color:
4906 case TextureStage::CO_one_minus_src_color:
4907 return D3DTA_COMPLEMENT;
4909 case TextureStage::CO_src_alpha:
4910 return D3DTA_ALPHAREPLICATE;
4912 case TextureStage::CO_one_minus_src_alpha:
4913 return D3DTA_ALPHAREPLICATE | D3DTA_COMPLEMENT;
4915 case TextureStage::CO_undefined:
4919 <<
"Invalid TextureStage::CombineOperand value (" << (int)operand <<
")\n";
4928 void DXGraphicsStateGuardian9::
4929 draw_primitive_up(D3DPRIMITIVETYPE primitive_type,
4930 unsigned int primitive_count,
4931 unsigned int first_vertex,
4932 unsigned int num_vertices,
4933 const unsigned char *buffer,
size_t stride) {
4940 const unsigned char *buffer_start = buffer + stride * first_vertex;
4941 const unsigned char *buffer_end = buffer_start + stride * num_vertices;
4943 if (buffer_end - buffer_start > 0x10000) {
4946 _d3d_device->DrawPrimitiveUP(primitive_type, primitive_count,
4947 buffer_start, stride);
4949 }
else if ((((uintptr_t)buffer_end ^ (uintptr_t)buffer_start) & ~0xffff) == 0) {
4951 _d3d_device->DrawPrimitiveUP(primitive_type, primitive_count,
4952 buffer_start, stride);
4957 unsigned char *safe_buffer_start = get_safe_buffer_start();
4958 memcpy(safe_buffer_start, buffer_start, buffer_end - buffer_start);
4959 _d3d_device->DrawPrimitiveUP(primitive_type, primitive_count,
4960 safe_buffer_start, stride);
4972 void DXGraphicsStateGuardian9::
4973 draw_indexed_primitive_up(D3DPRIMITIVETYPE primitive_type,
4974 unsigned int min_index,
unsigned int max_index,
4975 unsigned int num_primitives,
4976 const unsigned char *index_data,
4977 D3DFORMAT index_type,
4978 const unsigned char *buffer,
size_t stride) {
4981 const unsigned char *buffer_start = buffer + stride * min_index;
4982 const unsigned char *buffer_end = buffer + stride * (max_index + 1);
4984 if (buffer_end - buffer_start > 0x10000) {
4987 _d3d_device->DrawIndexedPrimitiveUP
4988 (primitive_type, min_index, max_index - min_index + 1, num_primitives,
4989 index_data, index_type, buffer, stride);
4991 }
else if ((((uintptr_t)buffer_end ^ (uintptr_t)buffer_start) & ~0xffff) == 0) {
4993 _d3d_device->DrawIndexedPrimitiveUP
4994 (primitive_type, min_index, max_index - min_index + 1, num_primitives,
4995 index_data, index_type, buffer, stride);
5000 unsigned char *safe_buffer_start = get_safe_buffer_start();
5001 memcpy(safe_buffer_start, buffer_start, buffer_end - buffer_start);
5002 _d3d_device->DrawIndexedPrimitiveUP
5003 (primitive_type, min_index, max_index - min_index + 1, num_primitives,
5004 index_data, index_type, safe_buffer_start - stride * min_index, stride);
5027 case D3DERR_OUTOFVIDEOMEMORY:
5031 size_t current_size = _prepared_objects->_graphics_memory_lru.get_total_size();
5032 size_t target_size = max(current_size - allocation_size * attempts, (
size_t) 0);
5033 _prepared_objects->_graphics_memory_lru.evict_to(target_size);
5035 <<
"Evicted " << current_size - _prepared_objects->_graphics_memory_lru.get_total_size() <<
" bytes of texture memory to make room for more.\n";
5036 if (_prepared_objects->_graphics_memory_lru.get_total_size() < current_size) {
5051 static int dx_stencil_comparison_function_array[] = {
5058 D3DCMP_GREATEREQUAL,
5062 static int dx_stencil_operation_array[] = {
5065 D3DSTENCILOP_REPLACE,
5068 D3DSTENCILOP_INVERT,
5070 D3DSTENCILOP_INCRSAT,
5071 D3DSTENCILOP_DECRSAT,
5077 void DXGraphicsStateGuardian9::
5078 do_issue_stencil() {
5079 if (!_supports_stencil) {
5085 if (stencil !=
nullptr) {
5088 dxgsg9_cat.debug() <<
"STENCIL STATE CHANGE\n";
5089 dxgsg9_cat.debug() <<
"\n" 5090 <<
"SRS_front_comparison_function " << stencil->
get_render_state(StencilAttrib::SRS_front_comparison_function) <<
"\n" 5091 <<
"SRS_front_stencil_fail_operation " << stencil->
get_render_state(StencilAttrib::SRS_front_stencil_fail_operation) <<
"\n" 5092 <<
"SRS_front_stencil_pass_z_fail_operation " << stencil->
get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation) <<
"\n" 5093 <<
"SRS_front_stencil_pass_z_pass_operation " << stencil->
get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation) <<
"\n" 5094 <<
"SRS_reference " << stencil->
get_render_state(StencilAttrib::SRS_reference) <<
"\n" 5095 <<
"SRS_read_mask " << stencil->
get_render_state(StencilAttrib::SRS_read_mask) <<
"\n" 5096 <<
"SRS_write_mask " << stencil->
get_render_state(StencilAttrib::SRS_write_mask) <<
"\n" 5097 <<
"SRS_back_comparison_function " << stencil->
get_render_state(StencilAttrib::SRS_back_comparison_function) <<
"\n" 5098 <<
"SRS_back_stencil_fail_operation " << stencil->
get_render_state(StencilAttrib::SRS_back_stencil_fail_operation) <<
"\n" 5099 <<
"SRS_back_stencil_pass_z_fail_operation " << stencil->
get_render_state(StencilAttrib::SRS_back_stencil_pass_z_fail_operation) <<
"\n" 5100 <<
"SRS_back_stencil_pass_z_pass_operation " << stencil->
get_render_state(StencilAttrib::SRS_back_stencil_pass_z_pass_operation) <<
"\n";
5105 unsigned int front_compare;
5106 front_compare = stencil->
get_render_state(StencilAttrib::SRS_front_comparison_function);
5108 if (front_compare != RenderAttrib::M_none) {
5110 set_render_state(D3DRS_STENCILFUNC, dx_stencil_comparison_function_array[front_compare]);
5112 stencil->
get_render_state(StencilAttrib::SRS_front_stencil_fail_operation)]);
5114 stencil->
get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation)]);
5116 stencil->
get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation)]);
5122 if (_supports_two_sided_stencil) {
5123 unsigned int back_compare;
5124 back_compare = stencil->
get_render_state(StencilAttrib::SRS_back_comparison_function);
5126 if (back_compare != RenderAttrib::M_none) {
5128 set_render_state(D3DRS_CCW_STENCILFUNC, dx_stencil_comparison_function_array[back_compare]);
5130 stencil->
get_render_state(StencilAttrib::SRS_back_stencil_fail_operation)]);
5132 stencil->
get_render_state(StencilAttrib::SRS_back_stencil_pass_z_fail_operation)]);
5134 stencil->
get_render_state(StencilAttrib::SRS_back_stencil_pass_z_pass_operation)]);
5148 _d3d_device->Clear(0,
nullptr, D3DCLEAR_STENCIL, 0, 0.0f, stencil->
get_render_state(StencilAttrib::SRS_clear_value));
5154 dxgsg9_cat.debug() <<
"STENCIL STATE CHANGE TO OFF\n";
5158 if (_supports_two_sided_stencil) {
5167 void DXGraphicsStateGuardian9::
5168 do_issue_scissor() {
5170 const LVecBase4 &frame = target_scissor->
get_frame();
5173 r.left = _current_viewport.X + _current_viewport.Width * frame[0];
5174 r.top = _current_viewport.Y + _current_viewport.Height * (1.0f - frame[3]);
5175 r.right = _current_viewport.X + _current_viewport.Width * frame[1];
5176 r.bottom = _current_viewport.Y + _current_viewport.Height * (1.0f - frame[2]);
5177 _d3d_device->SetScissorRect(&r);
5187 DWORD multisampletype, DWORD multisamplequality) {
5190 int r=0, g=0, b=0, a=0;
5192 case D3DFMT_R8G8B8: r=8; g=8; b=8; a=0;
break;
5193 case D3DFMT_A8R8G8B8: r=8; g=8; b=8; a=8;
break;
5194 case D3DFMT_X8R8G8B8: r=8; g=8; b=8; a=0;
break;
5195 case D3DFMT_R5G6B5: r=5; g=6; b=5; a=0;
break;
5196 case D3DFMT_X1R5G5B5: r=5; g=5; b=5; a=0;
break;
5197 case D3DFMT_A1R5G5B5: r=5; g=5; b=5; a=1;
break;
5198 case D3DFMT_A4R4G4B4: r=4; g=4; b=4; a=4;
break;
5199 case D3DFMT_R3G3B2: r=3; g=3; b=2; a=0;
break;
5200 case D3DFMT_A8R3G3B2: r=3; g=3; b=2; a=8;
break;
5201 case D3DFMT_X4R4G4B4: r=4; g=4; b=4; a=0;
break;
5202 case D3DFMT_A2B10G10R10: r=10;g=10;b=10;a=2;
break;
5203 case D3DFMT_A8P8: index=8; a=8;
break;
5204 case D3DFMT_P8: index=8; a=0;
break;
5208 props.set_rgb_color(0);
5209 props.set_indexed_color(1);
5211 }
else if (r + g + b > 0) {
5212 props.set_rgb_color(1);
5213 props.set_indexed_color(0);
5216 props.set_alpha_bits(a);
5221 case D3DFMT_D32: depth=32; stencil=0;
break;
5222 case D3DFMT_D15S1: depth=15; stencil=1;
break;
5223 case D3DFMT_D24S8: depth=24; stencil=8;
break;
5224 case D3DFMT_D16: depth=16; stencil=0;
break;
5225 case D3DFMT_D24X8: depth=24; stencil=0;
break;
5226 case D3DFMT_D24X4S4: depth=24; stencil=4;
break;
5229 props.set_depth_bits(depth);
5230 props.set_stencil_bits(stencil);
5231 if (multisampletype == D3DMULTISAMPLE_NONMASKABLE) {
5232 props.set_multisamples(2);
5234 props.set_multisamples(multisampletype);
5240 #define GAMMA_1 (255.0 * 256.0) 5242 static bool _gamma_table_initialized =
false;
5243 static unsigned short _original_gamma_table [256 * 3];
5245 void _create_gamma_table_dx9 (PN_stdfloat gamma,
unsigned short *original_red_table,
unsigned short *original_green_table,
unsigned short *original_blue_table,
unsigned short *red_table,
unsigned short *green_table,
unsigned short *blue_table) {
5247 double gamma_correction;
5253 gamma_correction = 1.0 / (double) gamma;
5255 for (i = 0; i < 256; i++) {
5260 if (original_red_table) {
5261 r = (double) original_red_table [i] / GAMMA_1;
5262 g = (double) original_green_table [i] / GAMMA_1;
5263 b = (double) original_blue_table [i] / GAMMA_1;
5266 r = ((double) i / 255.0);
5271 r = pow (r, gamma_correction);
5272 g = pow (g, gamma_correction);
5273 b = pow (b, gamma_correction);
5290 green_table [i] = g;
5303 if (_gamma_table_initialized ==
false) {
5304 HDC hdc = GetDC(
nullptr);
5307 if (GetDeviceGammaRamp (hdc, (LPVOID) _original_gamma_table)) {
5308 _gamma_table_initialized =
true;
5312 ReleaseDC (
nullptr, hdc);
5325 HDC hdc = GetDC(
nullptr);
5329 unsigned short ramp [256 * 3];
5331 if (restore && _gamma_table_initialized) {
5332 _create_gamma_table_dx9 (gamma, &_original_gamma_table [0], &_original_gamma_table [256], &_original_gamma_table [512], &ramp [0], &ramp [256], &ramp [512]);
5335 _create_gamma_table_dx9 (gamma, 0, 0, 0, &ramp [0], &ramp [256], &ramp [512]);
5338 if (SetDeviceGammaRamp (hdc, ramp)) {
5342 ReleaseDC (
nullptr, hdc);
5389 CGprofile profile = cgGetProfile(name.c_str());
5391 if (profile == CG_PROFILE_UNKNOWN) {
5392 dxgsg9_cat.error() << name <<
", unknown Cg-profile\n";
5395 return cgD3D9IsProfileSupported(cgGetProfile(name.c_str())) != 0;
5406 if (_cg_device != cg_device) {
5407 cgD3D9SetDevice(cg_device);
5408 _cg_device = cg_device;
5418 if (_white_vbuffer !=
nullptr) {
5419 return _white_vbuffer;
5422 LPDIRECT3DVERTEXBUFFER9 vbuffer;
5424 hr = _screen->_d3d_device->CreateVertexBuffer(
sizeof(D3DCOLOR), D3DUSAGE_WRITEONLY, D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vbuffer,
nullptr);
5428 <<
"CreateVertexBuffer failed" << D3DERRORSTRING(hr);
5432 D3DCOLOR *local_pointer;
5433 hr = vbuffer->Lock(0,
sizeof(D3DCOLOR), (
void **) &local_pointer, D3DLOCK_DISCARD);
5436 <<
"VertexBuffer::Lock failed" << D3DERRORSTRING(hr);
5440 *local_pointer = D3DCOLOR_ARGB(255, 255, 255, 255);
5443 _white_vbuffer = vbuffer;
5447 typedef std::string KEY;
5449 typedef struct _KEY_ELEMENT
5453 int secondary_count;
5455 struct _KEY_ELEMENT *next;
5459 typedef struct _KEY_LIST
5461 int total_key_elements;
5462 KEY_ELEMENT *key_element;
5466 KEY_ELEMENT *new_key_element (KEY key, KEY_LIST *key_list)
5468 KEY_ELEMENT *key_element;
5470 key_element =
new KEY_ELEMENT;
5471 key_element -> key = key;
5472 key_element -> count = 1;
5473 key_element -> secondary_count = 0;
5474 key_element -> next = 0;
5476 key_list -> total_key_elements++;
5481 KEY_ELEMENT *first_key_element (KEY_LIST *key_list)
5483 return key_list -> key_element;
5486 KEY_ELEMENT *next_key_element (KEY_ELEMENT *key_element)
5488 return key_element -> next;
5491 void delete_key_list (KEY_LIST *key_list)
5495 KEY_ELEMENT *key_element;
5496 KEY_ELEMENT *key_element_next;
5498 key_element = first_key_element (key_list);
5501 key_element_next = next_key_element (key_element);
5503 key_element = key_element_next;
5510 KEY_LIST *new_key_list (
void)
5514 key_list =
new KEY_LIST;
5515 memset (key_list, 0,
sizeof (KEY_LIST));
5520 KEY_ELEMENT *add_to_key_list (KEY key, KEY_LIST *key_list)
5522 KEY_ELEMENT *key_element;
5523 KEY_ELEMENT *last_key_element;
5524 KEY_ELEMENT *current_key_element;
5527 last_key_element = 0;
5528 current_key_element = key_list -> key_element;
5529 if (current_key_element == 0)
5531 key_element = new_key_element (key, key_list);
5532 key_list -> key_element = key_element;
5536 while (current_key_element)
5538 if (key < current_key_element -> key)
5540 key_element = new_key_element (key, key_list);
5541 key_element -> next = current_key_element;
5543 if (last_key_element == 0)
5545 key_list -> key_element = key_element;
5549 last_key_element -> next = key_element;
5555 if (key > current_key_element -> key)
5557 if (current_key_element -> next == 0)
5559 key_element = new_key_element (key, key_list);
5560 current_key_element -> next = key_element;
5570 current_key_element -> count++;
5575 last_key_element = current_key_element;
5576 current_key_element = current_key_element -> next;
CombineSource get_combine_alpha_source2() const
Get source2 of combine_alpha_mode.
void get_linear_range(PN_stdfloat &onset, PN_stdfloat &opaque)
Retrieves the current onset and offset ranges.
get_animation_type
Returns the type of animation represented by this spec.
virtual bool is_linear() const
Returns true if the lens represents a linear projection (e.g.
IDirect3DTexture9 * get_d3d_2d_texture() const
Returns the Direct3D object that represents the texture, in the case of a 1-d or 2-d texture.
A light shining from infinitely far away in a particular direction, like sunlight.
get_y_size
Returns the height of the texture image in texels.
static bool is_srgb(Format format)
Returns true if the indicated format is in the sRGB color space, false otherwise.
Texture * get_texture() const
Returns the pointer to the associated Texture object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool was_modified(const GeomVertexArrayDataHandle *reader) const
Returns true if the data has been modified since the last time mark_loaded() was called.
get_mode
Returns the shade mode.
get_wrap_u
Returns the wrap mode of the texture in the U direction.
bool setup_array_data(DXVertexBufferContext9 *&vbc, const GeomVertexArrayDataHandle *data, bool force)
Internal function to bind a buffer object for the indicated data array, if appropriate,...
The abstract interface to all kinds of lights.
HRESULT set_sampler_state(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value)
This function creates a common layer between DX and Panda.
virtual void end_frame(Thread *current_thread)
Called after each frame is rendered, to allow the GSG a chance to do any internal cleanup after rende...
Encapsulates the data from a DisplayRegion, pre-fetched for one stage of the pipeline.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void release_shader(ShaderContext *sc)
Releases the resources allocated by prepare_shader.
bool do_framebuffer_copy_to_ram(Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb, bool inverted)
This is the implementation of framebuffer_copy_to_ram(); it adds one additional parameter,...
get_tex_view_offset
Returns the current setting of the tex_view_offset.
get_mode
Returns the transparency mode.
This is a base class for GraphicsWindow (actually, GraphicsOutput) and DisplayRegion,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Enables or disables writing to the depth buffer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void clear(DrawableRegion *clearable)
Clears all of the indicated buffers to their assigned colors.
LPDIRECT3DVERTEXBUFFER9 get_white_vbuffer()
Returns a vertex buffer containing only a full-white color.
A base class for any number of different kinds of lenses, linear and otherwise.
has_ambient
Returns true if the ambient color has been explicitly set for this material, false otherwise.
get_z_size
Returns the depth of the texture image in texels.
CombineOperand get_combine_alpha_operand0() const
Get operand0 of combine_alpha_mode.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static bool static_set_gamma(bool restore, PN_stdfloat gamma)
Static function for setting gamma which is needed for atexit.
Enables or disables writing to the color buffer.
HRESULT set_texture_stage_state(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value)
This function creates a common layer between DX and Panda.
get_component_type
Returns the numeric interpretation of each component of the texture.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_reference_alpha
Returns the alpha reference value.
virtual bool extract_texture_data(Texture *tex)
This method should only be called by the GraphicsEngine.
bool might_have_ram_image() const
Returns true if the texture's image contents are currently available in main RAM, or there is reason ...
void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const
Similar to get_region_pixels(), but returns the upper left corner, and the pixel numbers are numbered...
Indicates which, if any, material should be applied to geometry.
This object describes how the vertex animation, if any, represented in a GeomVertexData is encoded.
Enables or disables writing to the depth buffer.
virtual void prepare_display_region(DisplayRegionPipelineReader *dr)
Makes the specified DisplayRegion current.
bool bind(GSG *gsg)
This function is to be called to enable a new shader.
virtual void end_draw_primitives()
Called after a sequence of draw_primitive() functions are called, this should do whatever cleanup is ...
void release_all()
Releases all prepared objects.
This controls the enabling of transparency.
virtual bool draw_triangles(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of disconnected triangles.
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
This is a special class object that holds all the information returned by a particular GSG to indicat...
get_fog
If the FogAttrib is not an 'off' FogAttrib, returns the fog that is associated.
get_mode
Returns the render mode.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Caches a GeomVertexArrayData in the DirectX device as a vertex buffer.
get_effective_magfilter
Returns the filter mode of the texture for magnification, with special treatment for FT_default.
get_texture_type
Returns the overall interpretation of the texture.
void setup_texture(TextureType texture_type, int x_size, int y_size, int z_size, ComponentType component_type, Format format)
Sets the texture to the indicated type and dimensions, presumably in preparation for calling read() o...
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Specifies whether flat shading (per-polygon) or smooth shading (per-vertex) is in effect.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void apply_texture(int i, TextureContext *tc, const SamplerState &sampler)
Makes the texture the currently available texture for rendering on the ith stage.
This is a special class object that holds all the information returned by a particular GSG to indicat...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_point
Returns the point in space at which the light is located.
virtual VertexBufferContext * prepare_vertex_buffer(GeomVertexArrayData *data)
Creates a new retained-mode representation of the given data, and returns a newly-allocated VertexBuf...
void unbind(GSG *gsg)
This function disables a currently-bound shader.
bool create_texture(DXScreenData &scrn)
Use panda texture's pixelbuffer to create a texture for the specified device.
get_wrap_w
Returns the wrap mode of the texture in the W direction.
static D3DFORMAT get_index_type(Geom::NumericType numeric_type)
Maps from the Geom's internal numeric type symbols to DirectX's.
void issue_parameters(GSG *gsg, int altered)
This function gets called whenever the RenderState or TransformState has changed, but the Shader itse...
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void disable_shader_texture_bindings(GSG *gsg)
Disable all the texture bindings used by this shader.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Caches a GeomPrimitive in the DirectX device as an index buffer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool was_simple_image_modified() const
Returns true if the texture's "simple" image has been modified since the last time mark_simple_loaded...
get_clear_stencil
Returns the current clear stencil value.
virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader, const GeomVertexDataPipelineReader *data_reader, bool force)
Called before a sequence of draw_primitive() functions are called, this should prepare the vertex dat...
PN_stdfloat get_hfov() const
Returns the horizontal component of fov only.
int get_num_combine_alpha_operands() const
Returns the number of meaningful operands that may be retrieved via get_combine_alpha_sourceN() and g...
get_clear_color
Returns the current clear color value.
virtual void set_state_and_transform(const RenderState *state, const TransformState *transform)
Simultaneously resets the render state and the transform state.
CombineOperand get_combine_rgb_operand1() const
Get operand1 of combine_rgb_mode.
This data object is returned by GeomVertexArrayData::get_handle() or modify_handle().
Encapsulates the data from a Geom, pre-fetched for one stage of the pipeline.
void do_issue_color()
This method is defined in the base class because it is likely that this functionality will be used fo...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_effective_minfilter
Returns the filter mode of the texture for minification, with special treatment for FT_default.
void mark_loaded(const GeomVertexArrayDataHandle *reader)
Should be called after the VertexBufferContext has been loaded into graphics memory,...
get_specular_color
Returns the color of specular highlights generated by the light.
bool has_ram_image() const
Returns true if the Texture has its image contents available in main RAM, false if it exists only in ...
get_mode
Returns the depth write mode.
bool has_mipmaps() const
Returns true if the texture was created with mipmaps, false otherwise.
virtual void end_scene()
Called between begin_frame() and end_frame() to mark the end of drawing commands for a "scene" (usual...
ShaderLanguage get_language() const
Returns the shader language in which this shader was written.
static bool get_gamma_table(void)
Static function for getting the original gamma.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool framebuffer_copy_to_texture(Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)
Copy the pixels within the indicated display region from the framebuffer into texture memory.
get_channels
Returns the mask of color channels that are enabled by this attrib.
get_local
Returns the local viewer flag.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CombineSource get_combine_rgb_source1() const
Get source1 of combine_rgb_mode.
get_diffuse
Returns the diffuse color setting, if it has been set.
static void atexit_function(void)
This function is passed to the atexit function.
get_rgb_scale
See set_rgb_scale().
has_base_color
Returns true if the base color has been explicitly set for this material, false otherwise.
get_emission
Returns the emission color setting, if it has been set.
The ShaderContext is meant to contain the compiled version of a shader string.
void disable_shader_vertex_arrays(GSG *gsg)
Disable all the vertex arrays used by this shader.
get_alpha_mode
Returns the blending mode for the alpha channel.
void enqueue_lru(AdaptiveLru *lru)
Adds the page to the LRU for the first time, or marks it recently-accessed if it has already been add...
get_operand_b
Returns the RGB multiplier for the second component.
GraphicsEngine * get_engine() const
Returns the graphics engine that created this GSG.
Lens * get_lens(int index=0) const
Returns a pointer to the particular Lens associated with this LensNode, or NULL if there is not yet a...
has_diffuse
Returns true if the diffuse color has been explicitly set for this material, false otherwise.
Indicates which faces should be culled based on their vertex ordering.
virtual bool begin_draw_primitives(const GeomPipelineReader *geom_reader, const GeomVertexDataPipelineReader *data_reader, bool force)
Called before a sequence of draw_primitive() functions are called, this should prepare the vertex dat...
void reset_all_windows(bool swapchain)
Resets the framebuffer of the current window.
Applies a Fog to the geometry at and below this node.
get_mode
Return the mode of this stage.
set_render_to_texture
Sets a flag on the texture that indicates whether the texture is intended to be used as a direct-rend...
void set_size_padded(int x=1, int y=1, int z=1)
Changes the size of the texture, padding if necessary, and setting the pad region as well.
A lightweight class that represents a single element that may be timed and/or counted via stats.
get_wrap_v
Returns the wrap mode of the texture in the V direction.
get_mode
Returns the blending mode for the RGB channels.
get_exp_density
Returns the density of the fog for exponential calculations.
get_format
Returns the format of the texture, which represents both the semantic meaning of the texels and,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_current_thread
Returns a pointer to the currently-executing Thread object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_num_transforms
This is only meaningful for animation_type AT_hardware.
CombineSource get_combine_alpha_source0() const
Get source0 of combine_alpha_mode.
bool was_modified(const GeomPrimitivePipelineReader *reader) const
Returns true if the data has been modified since the last time mark_loaded() was called.
An offscreen render buffer.
bool check_dx_allocation(HRESULT result, int allocation_size, int attempts)
This function is called after the creation of textures, vertex buffers, and index buffers to check if...
get_effective_anisotropic_degree
Returns the degree of anisotropic filtering that should be applied to the texture.
get_offset
Returns the depth offset represented by this attrib.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A StencilAttrib is a collection of all stencil render states.
bool extract_texture_data(DXScreenData &scrn)
This method will be called in the draw thread to download the texture memory's image into its ram_ima...
CombineSource get_combine_rgb_source2() const
Get source2 of combine_rgb_mode.
virtual bool get_supports_cg_profile(const std::string &name) const
Returns true if this particular GSG supports the specified Cg Shader Profile.
void restore_gamma()
Restore original gamma.
IDirect3DBaseTexture9 * get_d3d_texture() const
Returns the Direct3D object that represents the texture, whatever kind of texture it is.
get_shininess
Returns the shininess exponent of the material.
static void set_cg_device(LPDIRECT3DDEVICE9 cg_device)
Sets the global Cg device pointer.
const LPlane & get_plane() const
Returns the plane represented by the PlaneNode.
void mark_new()
Marks the GSG as "new", so that the next call to reset_if_new() will be effective.
virtual void reset()
Resets all internal state as if the gsg were newly created.
virtual bool draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of line strips.
Specifies how atmospheric fog effects are applied to geometry.
bool get_clear_color_active() const
Returns the current setting of the flag that indicates whether the color buffer should be cleared eve...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CombineOperand get_combine_rgb_operand0() const
Get operand0 of combine_rgb_mode.
get_lod_bias
Returns the bias that will be added to the texture level of detail when sampling this texture.
An object to create GraphicsOutputs that share a particular 3-D API.
bool get_clear_depth_active() const
Returns the current setting of the flag that indicates whether the depth buffer should be cleared eve...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ShaderContext * prepare_shader(Shader *se)
Compile a vertex/fragment shader body.
virtual void begin_occlusion_query()
Begins a new occlusion query.
This specialization on GeomMunger finesses vertices for DirectX rendering.
A light originating from a single point in space, and shining in a particular direction,...
get_ambient
Returns the ambient color setting, if it has been set.
int get_num_combine_rgb_operands() const
Returns the number of meaningful operands that may be retrieved via get_combine_rgb_sourceN() and get...
get_exponent
Returns the exponent that controls the amount of light falloff from the center of the spotlight.
virtual void do_issue_light()
This implementation of do_issue_light() assumes we have a limited number of hardware lights available...
void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const
Similar to get_region_pixels(), but returns the upper left corner, and the pixel numbers are numbered...
bool apply_index_buffer(IndexBufferContext *ibc, const GeomPrimitivePipelineReader *reader, bool force)
Updates the index buffer with the current data, and makes it the current index buffer for rendering.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_saved_result
Returns the current setting of the saved_result flag.
bool get_clear_stencil_active() const
Returns the current setting of the flag that indicates whether the color buffer should be cleared eve...
get_indexed_transforms
This is only meaningful for animation_type AT_hardware.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool set_gamma(PN_stdfloat gamma)
Non static version of setting gamma.
CombineMode get_combine_alpha_mode() const
Get combine_alpha_mode.
get_mode
Returns the depth write mode.
set_color_bits
Sets the number of requested color bits as a single number that represents the sum of the individual ...
virtual void end_frame(Thread *current_thread)
Called after each frame is rendered, to allow the GSG a chance to do any internal cleanup after rende...
get_alpha_scale
See set_alpha_scale().
get_clear_depth
Returns the current clear depth value.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void end_draw_primitives()
Called after a sequence of draw_primitive() functions are called, this should do whatever cleanup is ...
get_color
return the color for this stage
Enables or disables writing of pixel to framebuffer based on its alpha value relative to a reference ...
CombineOperand get_combine_alpha_operand1() const
Get operand1 of combine_alpha_mode.
virtual bool update_texture(TextureContext *tc, bool force)
Ensures that the current Texture data is refreshed onto the GSG.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines the way an object appears in the presence of lighting.
bool upload_data(const GeomPrimitivePipelineReader *reader, bool force)
Copies the latest data from the client store to DirectX.
get_color
Returns the color of the fog.
get_nodal_point
Returns the center point of the lens: the point from which the lens is viewing.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
get_num_views
Returns the number of "views" in the texture.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void add_gsg(GraphicsStateGuardianBase *gsg)
Called by a GSG after it has been initialized, to add a new GSG to the available list.
Represents a set of settings that indicate how a texture is sampled.
CPT(TransformState) DXGraphicsStateGuardian9
Given a lens, calculates the appropriate projection matrix for use with this gsg.
void mark_loaded(const GeomPrimitivePipelineReader *reader)
Should be called after the IndexBufferContext has been loaded into graphics memory,...
virtual TextureContext * prepare_texture(Texture *tex, int view)
Creates a new retained-mode representation of the given texture, and returns a newly-allocated Textur...
TextureContext * prepare_now(int view, PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg)
Creates a context for the texture on the particular GSG, if it does not already exist.
virtual void bind_light(PointLight *light_obj, const NodePath &light, int light_id)
Called the first time a particular light has been bound to a given id within a frame,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool apply_vertex_buffer(VertexBufferContext *vbc, const GeomVertexArrayDataHandle *reader, bool force)
Updates the vertex buffer with the current data, and makes it the current vertex buffer for rendering...
const unsigned char * get_read_pointer(bool force) const
Returns a readable pointer to the beginning of the actual data stream, or NULL if the data is not cur...
PT(OcclusionQueryContext) DXGraphicsStateGuardian9
Ends a previous call to begin_occlusion_query().
Applies a transform matrix to UV's before they are rendered.
get_material
If the MaterialAttrib is not an 'off' MaterialAttrib, returns the material that is associated.
virtual bool get_supports_compressed_texture_format(int compression_mode) const
Returns true if this GSG can accept textures pre-compressed in the indicated format.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static DWORD LColor_to_D3DCOLOR(const LColor &cLColor)
Converts Panda's floating-point LColor structure to DirectX's D3DCOLOR packed structure.
get_frame
Returns the left, right, bottom, top coordinates of the scissor frame.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const LMatrix4 & get_projection_mat(StereoChannel channel=SC_mono) const
Returns the complete transformation matrix from a 3-d point in space to a point on the film,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool prepare_lens()
Makes the current lens (whichever lens was most recently specified with set_scene()) active,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This specifies how colors are blended into the frame buffer, for special effects.
get_effective_mode
Returns the effective culling mode.
CombineMode get_combine_rgb_mode() const
Get the combine_rgb_mode.
PandaNode * node() const
Returns the referenced node of the path.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CombineSource get_combine_rgb_source0() const
Get source0 of combine_rgb_mode.
void set_rgba_bits(int r, int g, int b, int a)
Convenience method for setting the red, green, blue and alpha bits in one go.
bool update_shader_vertex_arrays(DXShaderContext9 *prev, GSG *gsg, bool force)
Disables all vertex arrays used by the previous shader, then enables all the vertex arrays needed by ...
virtual bool draw_lines(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of disconnected line segments.
get_mode
Returns the render mode.
A thread; that is, a lightweight process.
void update_data_size_bytes(size_t new_data_size_bytes)
Should be called (usually by a derived class) when the on-card size of this object has changed.
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
virtual void prepare_display_region(DisplayRegionPipelineReader *dr)
Prepare a display region for rendering (set up scissor region and viewport)
get_direction
Returns the direction in which the light is aimed.
get_border_color
Returns the solid color of the texture's border.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a special kind of attribute that instructs the graphics driver to apply an offset or bias to ...
virtual bool begin_frame(Thread *current_thread)
Called before each frame is rendered, to allow the GSG a chance to do any internal cleanup before beg...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool involves_color_scale() const
Returns true if the TextureStage is affected by the setting of the current ColorScaleAttrib,...
get_alpha_operand_a
Returns the alpha multiplier for the first component.
void mark_loaded()
Should be called after the texture has been loaded into graphics memory, this updates the internal fl...
This is a special class object that holds all the information returned by a particular GSG to indicat...
virtual void release_vertex_buffer(VertexBufferContext *vbc)
Frees the GL resources previously allocated for the data.
Encapsulates all the communication with a particular instance of a given rendering backend.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Specifies how polygons are to be drawn.
unsigned int get_render_state(StencilRenderState render_state_identifier) const
Returns render state.
void set_active(bool flag)
Changes the active flag associated with this object.
bool is_off() const
Returns true if the MaterialAttrib is an 'off' MaterialAttrib, indicating that it should disable the ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void end_scene()
Called between begin_frame() and end_frame() to mark the end of drawing commands for a "scene" (usual...
get_thickness
Returns the line width or point thickness.
get_color
Returns the basic color of the light.
bool changed_size(const GeomVertexArrayDataHandle *reader) const
Returns true if the data has changed size since the last time mark_loaded() was called.
FrameBufferProperties calc_fb_properties(DWORD cformat, DWORD dformat, DWORD multisampletype, DWORD multisamplequality)
Convert DirectX framebuffer format ids into a FrameBufferProperties structure.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_perspective
Returns the perspective flag.
Specifies how polygons are to be drawn.
int release_all_index_buffers()
Frees the resources for all index buffers associated with this GSG.
A rectangular subregion within a window for rendering into.
CombineOperand get_combine_rgb_operand2() const
Get operand2 of combine_rgb_mode.
virtual bool draw_trifans(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of triangle fans.
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
int release_all_vertex_buffers()
Frees the resources for all vertex buffers associated with this GSG.
CombineSource get_combine_alpha_source1() const
Get source1 of combine_alpha_mode.
CombineOperand get_combine_alpha_operand2() const
Get operand2 of combine_alpha_mode.
get_prepared_objects
Returns the set of texture and geom objects that have been prepared with this GSG (and possibly other...
This restricts rendering to within a rectangular region of the scene, without otherwise affecting the...
bool uses_color() const
Returns true if the TextureStage makes use of whatever color is specified in set_color(),...
virtual void release_texture(TextureContext *tc)
Frees the GL resources previously allocated for the texture.
Returned from a GSG in response to begin_occlusion_query() .
This class is the main interface to controlling the render process.
virtual void reset()
Resets all internal state as if the gsg were newly created.
void mark_unloaded()
Should be called after the texture has been forced out of texture memory.
virtual bool begin_scene()
Called between begin_frame() and end_frame() to mark the beginning of drawing commands for a "scene" ...
get_operand_a
Returns the RGB multiplier for the first component.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
has_simple_ram_image
Returns true if the Texture has a "simple" image available in main RAM.
virtual bool begin_frame(Thread *current_thread)
Called before each frame is rendered, to allow the GSG a chance to do any internal cleanup before beg...
void create_ibuffer(DXScreenData &scrn, const GeomPrimitivePipelineReader *reader)
Creates a new index buffer (but does not upload data to it).
virtual IndexBufferContext * prepare_index_buffer(GeomPrimitive *data)
Creates a new retained-mode representation of the given data, and returns a newly-allocated IndexBuff...
TypeHandle is the identifier used to differentiate C++ class types.
const TransformState * get_transform(Thread *current_thread=Thread::get_current_thread()) const
Returns the complete transform object set on this node.
get_specular
Returns the specular color setting, if it has been set.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of triangle strips.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
bool is_off() const
Returns true if the FogAttrib is an 'off' FogAttrib, indicating that it should disable fog.
get_mode
Returns the alpha write mode.
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
bool changed_size(const GeomPrimitivePipelineReader *reader) const
Returns true if the data has changed size since the last time mark_loaded() was called.
get_specular_color
Returns the color of specular highlights generated by the light.
Defines the properties of a named stage of the multitexture pipeline.
bool upload_texture(DXTextureContext9 *dtc, bool force)
Creates a texture surface on the graphics card and fills it with its pixel data.
void update_shader_texture_bindings(DXShaderContext9 *prev, GSG *gsg)
Disables all texture bindings used by the previous shader, then enables all the texture bindings need...
get_attenuation
Returns the terms of the attenuation equation for the light.
ShaderContext * prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg)
Creates a context for the shader on the particular GSG, if it does not already exist.
HRESULT set_render_state(D3DRENDERSTATETYPE state, DWORD value)
This function creates a common layer between DX and Panda for SetRenderState.
get_alpha_operand_b
Returns the alpha multiplier for the second component.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer,...
bool was_modified() const
Returns true if the texture properties or image have been modified since the last time mark_loaded() ...
virtual bool framebuffer_copy_to_ram(Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)
Copy the pixels within the indicated display region from the framebuffer into system memory,...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
virtual bool draw_points(const GeomPrimitivePipelineReader *reader, bool force)
Draws a series of disconnected points.
const LVector3 & get_view_vector() const
Returns the axis along which the lens is facing.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A light originating from a single point in space, and shining in all directions.
void delete_texture()
Release the surface used to store the texture.
get_x_size
Returns the width of the texture image in texels.
A node that contains a plane.
has_specular
Returns true if the specular color has been explicitly set for this material, false otherwise.
Similar to PointerToArray, except that its contents may not be modified.
This is the data for one array of a GeomVertexData structure.
get_attenuation
Returns the terms of the attenuation equation for the light.
virtual bool begin_scene()
Called between begin_frame() and end_frame() to mark the beginning of drawing commands for a "scene" ...
get_specular_color
Returns the color of specular highlights generated by the light.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_ram_image_compression
Returns the compression mode in which the ram image is already stored pre- compressed.
static HRESULT d3d_surface_to_texture(RECT &source_rect, IDirect3DSurface9 *d3d_surface, bool inverted, Texture *result, int view, int z)
copies source_rect in pD3DSurf to upper left of texture
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void release_index_buffer(IndexBufferContext *ibc)
Frees the GL resources previously allocated for the data.
bool has_uncompressed_ram_image() const
Returns true if the Texture has its image contents available in main RAM and is uncompressed,...