[Gcblue-commits] gcb_wx/src/graphics tcGraphicsInfo.cpp, NONE, 1.1 tc3DTerrain.cpp, 1.21, 1.22 tc3D
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-09-24 19:50:25
|
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv11768/src/graphics Modified Files: tc3DTerrain.cpp tc3DViewer.cpp tc3DWindow.cpp tcDatabaseInfoPanel.cpp tcDisplayModes.cpp tcDisplaySettingsView.cpp tcMapView.cpp tcTerrainTextureFactory.cpp Added Files: tcGraphicsInfo.cpp Removed Files: tcGraphicsEngine.cpp Log Message: Upgraded to OSG 1.2. Tried Demeter 4.0 but had to go back. It's not backwards compatible. Added border to 3D view, alt-f to toggle frame counter Fix for passive torpedo bug Index: tcDatabaseInfoPanel.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcDatabaseInfoPanel.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tcDatabaseInfoPanel.cpp 20 Aug 2006 22:24:02 -0000 1.2 --- tcDatabaseInfoPanel.cpp 24 Sep 2006 19:50:20 -0000 1.3 *************** *** 248,251 **** --- 248,257 ---- s.Printf("ERROR: Launcher not found (%s)", launcherClass.c_str()); } + + if (s.size() > 70) + { + s = s.SubString(0, 69) + "..."; + } + PrintText(20.0, y, "%s", s.c_str()); } Index: tc3DTerrain.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DTerrain.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** tc3DTerrain.cpp 23 Mar 2006 01:11:02 -0000 1.21 --- tc3DTerrain.cpp 24 Sep 2006 19:50:20 -0000 1.22 *************** *** 250,254 **** void tc3DTerrain::UpdateElevations() { - wxASSERT(mapData); --- 250,253 ---- *************** *** 389,393 **** texFactory(0) { - terrainShaderOn = tcOptions::Get()->terrainShaderOn; --- 388,391 ---- Index: tcTerrainTextureFactory.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcTerrainTextureFactory.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcTerrainTextureFactory.cpp 23 Mar 2006 01:11:02 -0000 1.13 --- tcTerrainTextureFactory.cpp 24 Sep 2006 19:50:20 -0000 1.14 *************** *** 34,37 **** --- 34,38 ---- #endif // WX_PRECOM + //#include <GL/glew.h> // to avoid gl.h included before glew.h error #include "tcTerrainTextureFactory.h" #include <osg/Image> Index: tc3DViewer.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DViewer.cpp,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** tc3DViewer.cpp 5 Sep 2006 01:04:25 -0000 1.37 --- tc3DViewer.cpp 24 Sep 2006 19:50:20 -0000 1.38 *************** *** 27,30 **** --- 27,31 ---- #endif + //#include <GL/glew.h> // to avoid gl.h included before glew.h error #include "wx/glcanvas.h" *************** *** 68,71 **** --- 69,73 ---- #include "tcDatabase.h" #include "tcTime.h" + #include "wxcommands.h" *************** *** 85,88 **** --- 87,91 ---- EVT_MOVE(tc3DViewer::OnMove) EVT_LEFT_DOWN(tc3DViewer::OnLButtonDown) + EVT_LEFT_DCLICK(tc3DViewer::OnLButtonDClick) EVT_LEFT_UP(tc3DViewer::OnLButtonUp) EVT_RIGHT_DOWN(tc3DViewer::OnRButtonDown) *************** *** 289,292 **** --- 292,304 ---- } + void tc3DViewer::OnLButtonDClick(wxMouseEvent& event) + { + wxCommandEvent cmd(wxEVT_COMMAND_BUTTON_CLICKED, ID_SET3D); + cmd.SetEventObject(this); + cmd.SetExtraLong(0); // 0 to deactivate 3D view + + AddPendingEvent(cmd); + } + void tc3DViewer::OnLButtonUp(wxMouseEvent& event) { *************** *** 383,386 **** --- 395,400 ---- viewerText->setPosition(osg::Vec3(20.0f,(float)mnHeight * 0.9f,0.0f)); + UpdateBorder(); + databaseView->setViewport(pos.x, correctedY, size.GetWidth(), size.GetHeight()); } *************** *** 603,606 **** --- 617,647 ---- } + void tc3DViewer::SetBorderActive(bool state) + { + if (isBorderActive == state) return; // ignore if state not changed + + if ((!borderGeode.valid()) || (!border.valid())) return; + + + size_t nParents = border->getNumParents(); + + if (state) + { + if (nParents == 0) + { + borderGeode->addDrawable(border.get()); + } + } + else + { + if (nParents > 0) + { + borderGeode->removeDrawable(border.get()); + } + } + + isBorderActive = state; + } + /** * @param az camera az in radians for lookat modes *************** *** 821,824 **** --- 862,866 ---- } + void tc3DViewer::CreateScene() { *************** *** 890,893 **** --- 932,936 ---- InitText(); + UpdateBorder(); skyTransform->addChild(sky.get()); *************** *** 1065,1068 **** --- 1108,1159 ---- } + + + void tc3DViewer::UpdateBorder() + { + if (!borderGeode.valid()) + { + borderGeode = new osg::Geode; + hudObjects->addChild(borderGeode.get()); + } + wxASSERT(borderGeode.valid()); + + if (!border.valid()) + { + border = new osg::Geometry; + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 0.7f)); // sets border color + border->setColorArray(colors); + border->setColorBinding(osg::Geometry::BIND_OVERALL); + border->setUseDisplayList(true); + + // set state + osg::StateSet* stateSet = border->getOrCreateStateSet(); + stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); + stateSet->setMode(GL_DEPTH_WRITEMASK, osg::StateAttribute::OFF); + stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); + // osg::LineWidth *lw = new osg::LineWidth(1.5); + // stateSet->setAttribute(lw, osg::StateAttribute::ON); + + borderGeode->addDrawable(border.get()); + isBorderActive = true; + } + + // create vertex array + osg::Vec3Array* vertices = new osg::Vec3Array; + border->setVertexArray(vertices); + + float w = float(mnWidth-1); + float h = float(mnHeight-1); + + vertices->push_back(osg::Vec3(0, 0, 0)); + vertices->push_back(osg::Vec3(0, h, 0)); + vertices->push_back(osg::Vec3(w, h, 0)); + vertices->push_back(osg::Vec3(w, 0, 0)); + border->addPrimitiveSet(new osg::DrawArrays(GL_LINE_LOOP,0,4)); + } + + /** * Version for 3D database object view *************** *** 1195,1198 **** --- 1286,1290 ---- } + void tc3DViewer::UpdateCameraSpin() { *************** *** 1445,1453 **** displaySettings->setMinimumNumStencilBits(8); displaySettings->setDoubleBuffer(true); } databaseView->setDisplaySettings(displaySettings.get()); databaseView->setDefaults(); ! databaseView->setState(sceneView->getState()); --- 1537,1547 ---- displaySettings->setMinimumNumStencilBits(8); displaySettings->setDoubleBuffer(true); + displaySettings->setMinimumNumAlphaBits(8); } databaseView->setDisplaySettings(displaySettings.get()); databaseView->setDefaults(); ! ! databaseView->getState()->setContextID(2); // (sceneView->getState()); *************** *** 1489,1492 **** --- 1583,1587 ---- guiDisplaySettings->setMinimumNumStencilBits(8); guiDisplaySettings->setDoubleBuffer(true); + guiDisplaySettings->setMinimumNumAlphaBits(8); *************** *** 1494,1498 **** --- 1589,1597 ---- guiView->setDisplaySettings(guiDisplaySettings); guiView->setDefaults(); + //guiView->setState(sceneView->getState()); + + guiView->getState()->setContextID(1); + //guiView->getState()->setContextID(0); *************** *** 1546,1549 **** --- 1645,1651 ---- displaySettings->setDepthBuffer(true); displaySettings->setMinimumNumStencilBits(8); + displaySettings->setDoubleBuffer(true); + displaySettings->setMinimumNumAlphaBits(8); + // displaySettings->setRGB(true); *************** *** 1624,1637 **** displaySettings->setDepthBuffer(true); displaySettings->setMinimumNumStencilBits(8); } - // displaySettings->setRGB(true); - //displaySettings->setDoubleBuffer(true); - //displaySettings->setMinimumNumAlphaBits(4); sceneViewFar->setDisplaySettings(displaySettings.get()); sceneViewFar->setDefaults(); //sceneViewFar->setState(sceneView->getState()); ! //sceneViewFar->getState()->setContextID(0); wxWindow *parent = wxWindow::GetParent(); --- 1726,1739 ---- displaySettings->setDepthBuffer(true); displaySettings->setMinimumNumStencilBits(8); + displaySettings->setDoubleBuffer(true); + displaySettings->setMinimumNumAlphaBits(8); } sceneViewFar->setDisplaySettings(displaySettings.get()); sceneViewFar->setDefaults(); + //sceneViewFar->setState(sceneView->getState()); ! sceneViewFar->getState()->setContextID(0); wxWindow *parent = wxWindow::GetParent(); *************** *** 2124,2128 **** cameraWalkOffset(0, 0, 0), cameraSpinRate(0), ! lastSpinCount(0) { glCanvas = parent; --- 2226,2231 ---- cameraWalkOffset(0, 0, 0), cameraSpinRate(0), ! lastSpinCount(0), ! isBorderActive(false) { glCanvas = parent; Index: tcDisplaySettingsView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcDisplaySettingsView.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** tcDisplaySettingsView.cpp 23 Mar 2006 01:11:02 -0000 1.9 --- tcDisplaySettingsView.cpp 24 Sep 2006 19:50:20 -0000 1.10 *************** *** 32,35 **** --- 32,36 ---- #include "wxcommands.h" #include "tc3DWindow.h" + #include "tcGraphicsInfo.h" #ifdef _DEBUG *************** *** 81,84 **** --- 82,91 ---- osg::Vec4(1, 1, 1, 1), 16.0f, LEFT_BASE_LINE); + std::string driverInfo = tcGraphicsInfo::Get()->GetDriverInfo(); + driverInfo = std::string("Driver info: ") + driverInfo; + DrawTextR(driverInfo.c_str(), + 25.0f, 110.0f, defaultFont.get(), + osg::Vec4(1, 1, 1, 1), 16.0f, LEFT_BASE_LINE); + unsigned nModes = tcDisplayModes::Get()->GetModeCount(); Index: tcMapView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapView.cpp,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** tcMapView.cpp 16 Sep 2006 14:01:24 -0000 1.48 --- tcMapView.cpp 24 Sep 2006 19:50:20 -0000 1.49 *************** *** 45,48 **** --- 45,49 ---- #include <osg/Geometry> #include <osg/Vec4> + #include <osg/LineWidth> #include <math.h> *************** *** 355,377 **** mrectViewBounds.Set(0,0,0,0); - - /* - mpPen = new Pen(Color(0xFEFFFFFF),2); - if (mpPen == NULL) {WTL("tcMapView - mpPen creation failed\n");} - - mpPenThin = new Pen(Color(0xFEFFFFFF),1); - if (mpPenThin == NULL) {WTL("tcMapView - mpPenThin creation failed\n");} - - FontFamily ff(L"Arial"); - mpFont = new Font(&ff,16,FontStyleBold,UnitPixel); - - if (mpFont == NULL) {WTL("tcMapView - mpFont creation failed\n");} - mpFontSmall = new Font(&ff,9,FontStyleBold,UnitPixel); - - if (mpFontSmall == NULL) {WTL("tcMapView - mpFontSmall creation failed\n");} - mpBrush = new SolidBrush(Color(0xFEFFFFFF)); // color is ARGB - if (mpBrush == NULL) {WTL("tcMapView - mpBrush creation failed\n");} - */ - specialGraphics.clear(); } --- 356,359 ---- *************** *** 761,794 **** /*** Draw date and time text ***/ ! tcString sText; ! ! // draw top info string based on mnGameMode, this function should go elsewhere? strange to have in map ! osg::Vec4 color(0.1, 0.1, 0.2, 1); ! ! if (mnGameMode == GAMEMODE_NORMAL) ! { ! if (mfFrameRate != 0) ! { ! sText.Format("%s [%3.1f FPS]",dateTime.c_str(),mfFrameRate); ! } ! else ! { ! sText.Format("%s [ -- FPS]",dateTime.c_str()); ! } ! } ! else if (mnGameMode == GAMEMODE_PAUSED) ! { ! sText.Format("%s ",dateTime.c_str()); ! color.set(1, 0.5, 0.5, 1); ! } ! else ! { ! sText.Format("%s (PAUSED -- EDIT)",dateTime.c_str()); ! //mpBrush->SetColor(Color(254,105,15,25)); ! color.set(0.1, 0.06, 0.42, 1); ! } ! ! DrawTextR(sText.GetBuffer(), leftMargin + 50.0, 50.0, ! defaultFont.get(), color, 16.0, LEFT_BASE_LINE); #if 0 --- 743,748 ---- /*** Draw date and time text ***/ ! DrawTime(); ! #if 0 *************** *** 853,856 **** --- 807,852 ---- } + void tcTacticalMapView::DrawTime() + { + tcString sText; + + // draw top info string based on mnGameMode, this function should go elsewhere? strange to have in map + osg::Vec4 color(1.0, 1.0, 1.0, 1); + + if (mnGameMode == GAMEMODE_NORMAL) + { + if (showFrameCounter) + { + if (mfFrameRate != 0) + { + sText.Format("%s [%3.1f FPS]", dateTime.c_str(), mfFrameRate); + } + else + { + sText.Format("%s [ -- FPS]", dateTime.c_str()); + } + } + else + { + sText.Format("%s", dateTime.c_str()); + } + } + else if (mnGameMode == GAMEMODE_PAUSED) + { + sText.Format("%s ",dateTime.c_str()); + color.set(1, 0.5, 0.5, 1); + } + else + { + sText.Format("%s (PAUSED -- EDIT)",dateTime.c_str()); + //mpBrush->SetColor(Color(254,105,15,25)); + color.set(0.1, 0.06, 0.42, 1); + } + + DrawTextR(sText.GetBuffer(), leftMargin + 50.0, 50.0, + defaultFont.get(), color, 16.0, LEFT_BASE_LINE); + } + + osg::Image* tcTacticalMapView::LoadSymbolImage(const char *azSymbolName) { *************** *** 954,957 **** --- 950,957 ---- stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); + + // osg::LineWidth *lw = new osg::LineWidth(1.5); + // stateSet->setAttribute(lw, osg::StateAttribute::ON); + stateSet->setRenderBinDetails(baseRenderBin + rectRenderBin, "RenderBin"); *************** *** 1005,1008 **** --- 1005,1009 ---- symbol->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, primitiveBaseIdx, nPoints)); } + /** * Creates osg::Geometry object for requested NTDS symbol *************** *** 1024,1027 **** --- 1025,1082 ---- symbol->setVertexArray(vertices); + switch (affil) + { + case FRIENDLY: + case NEUTRAL: + { + AddArcPrimitive(symbol, vertices, 0, 0, 2*w, 2*w, -180, 180, 32); + break; + } + case UNKNOWN: + { + float wu = 0.9 * w; + + vertices->push_back(osg::Vec3(-wu, wu, 0)); + vertices->push_back(osg::Vec3(-wu, -wu, 0)); + vertices->push_back(osg::Vec3(wu, -wu, 0)); + vertices->push_back(osg::Vec3(wu, wu, 0)); + symbol->addPrimitiveSet(new osg::DrawArrays(GL_LINE_LOOP,0,4)); + break; + } + case HOSTILE: + { + vertices->push_back(osg::Vec3(0, w, 0)); + vertices->push_back(osg::Vec3(-w, 0, 0)); + vertices->push_back(osg::Vec3(0, -w, 0)); + vertices->push_back(osg::Vec3(w, 0, 0)); + symbol->addPrimitiveSet(new osg::DrawArrays(GL_LINE_LOOP,0,4)); + break; + } + } + + return symbol; + } + + + + /** + * Creates osg::Geometry object for requested NTDS symbol + */ + osg::Geometry* tcTacticalMapView::DrawNTDSCarrier(teAffiliation affil) + { + float w = 8.0f; + + osg::Geometry* symbol = CreateSymbolGeometry(); + + // set color + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(GetAffiliationColor(affil)); + symbol->setColorArray(colors); + symbol->setColorBinding(osg::Geometry::BIND_OVERALL); + + // create vertex array + osg::Vec3Array* vertices = new osg::Vec3Array; + symbol->setVertexArray(vertices); + switch (affil) *************** *** 1031,1034 **** --- 1086,1097 ---- { AddArcPrimitive(symbol, vertices, 0, 0, 2*w, 2*w, -180, 180, 32); + + size_t v_idx = vertices->size(); + vertices->push_back(osg::Vec3(-2, 1-w, 0)); + vertices->push_back(osg::Vec3(-2, w-1, 0)); + vertices->push_back(osg::Vec3(2, 1-w, 0)); + vertices->push_back(osg::Vec3(2, w-1, 0)); + symbol->addPrimitiveSet(new osg::DrawArrays(GL_LINES, v_idx, 4)); + break; } *************** *** 1042,1045 **** --- 1105,1117 ---- vertices->push_back(osg::Vec3(wu, wu, 0)); symbol->addPrimitiveSet(new osg::DrawArrays(GL_LINE_LOOP,0,4)); + + size_t v_idx = vertices->size(); + vertices->push_back(osg::Vec3(-2, 1-wu, 0)); + vertices->push_back(osg::Vec3(-2, wu-1, 0)); + vertices->push_back(osg::Vec3(2, 1-wu, 0)); + vertices->push_back(osg::Vec3(2, wu-1, 0)); + symbol->addPrimitiveSet(new osg::DrawArrays(GL_LINES, v_idx, 4)); + + break; } *************** *** 1051,1054 **** --- 1123,1134 ---- vertices->push_back(osg::Vec3(w, 0, 0)); symbol->addPrimitiveSet(new osg::DrawArrays(GL_LINE_LOOP,0,4)); + + size_t v_idx = vertices->size(); + vertices->push_back(osg::Vec3(-2, 3-w, 0)); + vertices->push_back(osg::Vec3(-2, w-3, 0)); + vertices->push_back(osg::Vec3(2, 3-w, 0)); + vertices->push_back(osg::Vec3(2, w-3, 0)); + symbol->addPrimitiveSet(new osg::DrawArrays(GL_LINES, v_idx, 4)); + break; } *************** *** 1058,1061 **** --- 1138,1142 ---- } + /** * "Mark" symbol is for known objects such as shells and sonobuoys that do *************** *** 1186,1196 **** return symbol; - - #if 0 - apGraphics->DrawLine(mpPen,x-symbsize/2,y+symbsize/2,x-symbsize/2,y-symbsize/2); - apGraphics->DrawLine(mpPen,x+symbsize/2,y+symbsize/2,x+symbsize/2,y-symbsize/2); - apGraphics->DrawLine(mpPen,x-symbsize/2,y-symbsize/2,x+symbsize/2,y-symbsize/2); - apGraphics->DrawLine(mpPen,x-symbsize/2,y+symbsize/2,x+symbsize/2,y+symbsize/2); - #endif } --- 1267,1270 ---- *************** *** 1526,1530 **** // carrier symbol ! osg::Geometry* pCarrier = DrawNTDSSurface((teAffiliation)nAffiliation); --- 1600,1604 ---- // carrier symbol ! osg::Geometry* pCarrier = DrawNTDSCarrier((teAffiliation)nAffiliation); *************** *** 1770,1773 **** --- 1844,1852 ---- + bool tcTacticalMapView::GetShowFrameCounter() const + { + return showFrameCounter; + } + /** * @returns symbol image pointer based on symbology mode *************** *** 2415,2418 **** --- 2494,2502 ---- } + void tcTacticalMapView::SetShowFrameCounter(bool state) + { + showFrameCounter = state; + } + /** * *************** *** 2544,2550 **** } void tcTacticalMapView::OnLButtonDClick(wxMouseEvent& event) { ! ClearHook(); } --- 2628,2659 ---- } + /** + * Send double click hook event (for customized command) if dclick on hooked obj + * Otherwise clear the current hook + */ void tcTacticalMapView::OnLButtonDClick(wxMouseEvent& event) { ! if (hookedId.size() != 1) return; ! ! wxPoint pos = event.GetPosition(); ! ! long closestId = GetClosest(pos); ! ! if (closestId == hookedId[0]) ! { ! long flags = 0; ! if (event.ShiftDown()) flags += 1; ! if (event.ControlDown()) flags += 2; ! if (event.AltDown()) flags += 4; ! ! wxCommandEvent command(wxEVT_COMMAND_BUTTON_CLICKED, ID_DCLICKHOOK) ; ! command.SetEventObject(this); ! command.m_extraLong = flags; ! AddPendingEvent(command); ! } ! else ! { ! ClearHook(); ! } } *************** *** 2836,2840 **** } ! void tcTacticalMapView::UpdateScreenNavPoints(void) { maNavPointScreen.clear(); --- 2945,2949 ---- } ! void tcTacticalMapView::UpdateScreenNavPoints() { maNavPointScreen.clear(); *************** *** 2877,2882 **** scrollDirection(0.0), mfHookLat(0), ! mfHookLon(0) ! { terrainView = new tcTerrainView(parent, pos, size, true); --- 2986,2991 ---- scrollDirection(0.0), mfHookLat(0), ! mfHookLon(0), ! showFrameCounter(false) { terrainView = new tcTerrainView(parent, pos, size, true); *************** *** 2910,2913 **** --- 3019,3027 ---- ClearMapObjects(); + + #ifdef _DEBUG + showFrameCounter = true; + #endif + } *************** *** 2924,2928 **** /* void ClearMapObjects(void); ! int CreateSurfaces(tcGraphicsEngine* apGraphicsEngine); int Draw(void); void DrawGrid(Graphics *apGraphics); --- 3038,3042 ---- /* void ClearMapObjects(void); ! int CreateSurfaces(tcGraphicsInfo* apGraphicsEngine); int Draw(void); void DrawGrid(Graphics *apGraphics); *************** *** 2944,2948 **** } /***********************************************************************************/ ! int tcWorldMapView::CreateSurfaces(tcGraphicsEngine* apGraphicsEngine) { #if 0 --- 3058,3062 ---- } /***********************************************************************************/ ! int tcWorldMapView::CreateSurfaces(tcGraphicsInfo* apGraphicsEngine) { #if 0 --- tcGraphicsEngine.cpp DELETED --- Index: tc3DWindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DWindow.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** tc3DWindow.cpp 5 Sep 2006 01:04:25 -0000 1.39 --- tc3DWindow.cpp 24 Sep 2006 19:50:20 -0000 1.40 *************** *** 45,49 **** #include "tc3DWindow.h" ! #include "tcGraphicsEngine.h" #include "AError.h" #include <stdio.h> --- 45,49 ---- #include "tc3DWindow.h" ! #include "tcGraphicsInfo.h" #include "AError.h" #include <stdio.h> Index: tcDisplayModes.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcDisplayModes.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcDisplayModes.cpp 23 Mar 2006 01:11:02 -0000 1.4 --- tcDisplayModes.cpp 24 Sep 2006 19:50:20 -0000 1.5 *************** *** 183,188 **** { tcDisplayModes::Info& info = modeInfo[n]; ! fprintf(stdout, "Display mode %d: W: %d, H: %d, Bits: %d Freq: %d\n", ! n, info.width, info.height, info.bits, info.frequency); } } --- 183,188 ---- { tcDisplayModes::Info& info = modeInfo[n]; ! fprintf(stdout, "Display mode %d: W: %d, H: %d, Bits: %d Freq: %d (%s)\n", ! n, info.width, info.height, info.bits, info.frequency, info.deviceDescription.c_str()); } } *************** *** 216,220 **** info.width = winModeInfo.dmPelsWidth; info.frequency = winModeInfo.dmDisplayFrequency; ! bool matchesLast = ((info.bits == lastBits)&& (info.width == lastWidth)&& --- 216,225 ---- info.width = winModeInfo.dmPelsWidth; info.frequency = winModeInfo.dmDisplayFrequency; ! ! unsigned int driverVersion = winModeInfo.dmDriverVersion; ! wxString description = wxString::Format("%s %d.%d", winModeInfo.dmDeviceName, ! (driverVersion & 0xFF), ((driverVersion >> 8) & 0xFF)); ! info.deviceDescription = description.c_str(); ! bool matchesLast = ((info.bits == lastBits)&& (info.width == lastWidth)&& --- NEW FILE: tcGraphicsInfo.cpp --- // tcGraphicsInfo.cpp: implementation of the tcGraphicsInfo class. /* ** Copyright (C) 2003 Dewitt Colclough (de...@gc...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "stdwx.h" // precompiled header file #ifndef WX_PRECOMP #include "wx/wx.h" #ifdef WIN32 #include "wx/msw/private.h" // for MS Windows specific definitions #endif // WIN32 #endif // WX_PRECOMP #include "tcGraphicsInfo.h" #include <GL/gl.h> // Header file for the OpenGL32 library #include <GL/glu.h> // Header file for the GLu32 library #include <GL/glaux.h> // Header file for the GLaux library #include "AError.h" #include <math.h> #include "tcString.h" #include "tcFile.h" #include <iostream> #include "wx/dcscreen.h" #include "tcDisplayModes.h" #include <osg/MatrixTransform> #if _MSC_VER > 1000 #pragma warning( disable: 4312) //'type cast' : conversion from 'WXHDC' to 'HDC' of greater size #endif #ifndef GL_EXT_bgra #pragma message( "Warning, BGRA extension not supported" ) // TODO also check dynamically for BGRA ext in code #endif #ifdef _DEBUG #define new DEBUG_NEW #endif using std::cout; tcGraphicsInfo* tcGraphicsInfo::Get() { static tcGraphicsInfo instance; return &instance; } /** * @return string with driver name and version */ std::string tcGraphicsInfo::GetDriverInfo() { std::string s; s = (char*)glGetString(GL_VENDOR); s += " "; s += (char*)glGetString(GL_RENDERER); s += " "; s += (char*)glGetString(GL_VERSION); return s; } /** * writes OpenGL driver info to stdout. Call after OpenGL * is initialized to avoid crash. */ void tcGraphicsInfo::LogGLInfo() { fprintf(stdout, "------- Driver info -------\n"); fprintf(stdout, "%s\n", glGetString(GL_VENDOR)); fprintf(stdout, "%s\n", glGetString(GL_RENDERER)); fprintf(stdout, "%s\n", glGetString(GL_VERSION)); fprintf(stdout, "%s\n\n", glGetString(GL_EXTENSIONS)); } /** * Enumerates graphics modes and logs information to stdout. * Writes best (according to old algorithm) format to stdout. * TODO rework to support Linux, need linux or wxWindows version * of HDC type. */ void tcGraphicsInfo::LogPixelFormats() { wxScreenDC wxdc; HDC hdc = (HDC)wxdc.GetHDC(); // get number of formats int nFormats = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); int best_format = 0; int best_bits = 0; int best_alpha = 0; int best_z = 0; for(int n=1;n<=nFormats;n++) { PIXELFORMATDESCRIPTOR pfd; memset(&pfd,0,sizeof(pfd)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; DescribePixelFormat(hdc, n, sizeof(PIXELFORMATDESCRIPTOR), &pfd); DWORD flags = pfd.dwFlags; bool generic_accel =((flags & PFD_GENERIC_FORMAT) && (flags & PFD_GENERIC_ACCELERATED)); bool software =((flags & PFD_GENERIC_FORMAT) && !(flags & PFD_GENERIC_ACCELERATED)); bool hw_accel =(!(flags & PFD_GENERIC_FORMAT) && !(flags & PFD_GENERIC_ACCELERATED)); bool supportsGL = (flags & PFD_SUPPORT_OPENGL) != 0; bool usesRGBA = (pfd.iPixelType & PFD_TYPE_RGBA) != 0; bool usesPalette = (pfd.iPixelType & PFD_TYPE_COLORINDEX) != 0; bool drawToWindow = (flags & PFD_DRAW_TO_WINDOW) != 0; bool doubleBuffer = (flags & PFD_DOUBLEBUFFER) != 0; if (hw_accel && supportsGL && !usesPalette && drawToWindow && doubleBuffer && (pfd.cAlphaBits > 0)) { if (pfd.cColorBits > best_bits) { best_bits = pfd.cColorBits; best_alpha = pfd.cAlphaBits; best_z = pfd.cDepthBits; best_format = n; } else if (pfd.cColorBits == best_bits) { if (pfd.cAlphaBits > best_alpha) { best_bits = pfd.cColorBits; best_alpha = pfd.cAlphaBits; best_z = pfd.cDepthBits; best_format = n; } else if (pfd.cAlphaBits == best_alpha) { if (pfd.cDepthBits > best_z) { best_bits = pfd.cColorBits; best_alpha = pfd.cAlphaBits; best_z = pfd.cDepthBits; best_format = n; } } } } fprintf(stdout," [%d] color: %d, alpha: %d, stencil: %d, z: %d hw_accel:%d gen_accel:%d soft:%d GL:%d RGBA:%d Pal:%d DB:%d \n", n, pfd.cColorBits, pfd.cAlphaBits, pfd.cStencilBits, pfd.cDepthBits, hw_accel, generic_accel, software, supportsGL, usesRGBA, usesPalette, doubleBuffer); } //fprintf(stdout,"Best: [%d] color: %d, alpha: %d, z: %d \n\n", // best_format, best_bits, best_alpha, best_z); } void tcGraphicsInfo::CheckGLError(const char* location) { GLenum eErrCode; const GLubyte *zErrString; if ((eErrCode = glGetError()) != GL_NO_ERROR) { zErrString = gluErrorString(eErrCode); fprintf(stderr, "OpenGL Error: %s (%s)\n",(char*)zErrString, location); } } /** * @return false if using software generic driver (no hardware accel) */ bool tcGraphicsInfo::Is3DCapable() { wxScreenDC wxdc; HDC hdc = (HDC)wxdc.GetHDC(); // get number of formats int nFormats = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); for(int n=1;n<=nFormats;n++) { PIXELFORMATDESCRIPTOR pfd; memset(&pfd,0,sizeof(pfd)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; DescribePixelFormat(hdc, n, sizeof(PIXELFORMATDESCRIPTOR), &pfd); DWORD flags = pfd.dwFlags; bool hw_accel =(!(flags & PFD_GENERIC_FORMAT) && !(flags & PFD_GENERIC_ACCELERATED)); bool supportsGL = (flags & PFD_SUPPORT_OPENGL) != 0; // bool doubleBuffer = (flags & PFD_DOUBLEBUFFER) != 0; // int nAlpha = pfd.cAlphaBits; if (hw_accel && supportsGL) return true; } return false; } /** * @return false if 3D hardware accel doesn't support alpha blending */ bool tcGraphicsInfo::Is3DAlphaCapable() { wxScreenDC wxdc; HDC hdc = (HDC)wxdc.GetHDC(); // get number of formats int nFormats = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); for(int n=1;n<=nFormats;n++) { PIXELFORMATDESCRIPTOR pfd; memset(&pfd,0,sizeof(pfd)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; DescribePixelFormat(hdc, n, sizeof(PIXELFORMATDESCRIPTOR), &pfd); DWORD flags = pfd.dwFlags; bool hw_accel =(!(flags & PFD_GENERIC_FORMAT) && !(flags & PFD_GENERIC_ACCELERATED)); bool supportsGL = (flags & PFD_SUPPORT_OPENGL) != 0; // bool doubleBuffer = (flags & PFD_DOUBLEBUFFER) != 0; int nAlpha = pfd.cAlphaBits; if (hw_accel && supportsGL && (nAlpha > 0)) return true; } return false; } tcGraphicsInfo::tcGraphicsInfo() { mbInitialized = true; LogGLInfo(); LogPixelFormats(); // display mode is not set using this sytem so ignore fflush (stdout); if (!Is3DCapable()) { std::string text = "GCB requires OpenGL-compatible 3D hardware acceleration." " ("; text += GetDriverInfo(); text += ")\n"; throw(text); } if (!Is3DAlphaCapable()) { std::string text = "Failed to find suitable 3D driver." "This may result in slow performance. ("; text += GetDriverInfo(); text += ")\n"; wxMessageBox(text.c_str(),"Warning",wxICON_WARNING); } tcDisplayModes::Get()->LogModeInfo(); } /** * Never used. */ tcGraphicsInfo::tcGraphicsInfo(const tcGraphicsInfo& src) { wxASSERT(false); } tcGraphicsInfo::~tcGraphicsInfo() { } |