1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4     (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 
30 
31 #include "Ogre.h"
32 #include "OgreRenderSystemCapabilitiesSerializer.h"
33 #include <iostream>
34 #include <sys/stat.h>
35 
36 using namespace std;
37 using namespace Ogre;
38 
39 
help(void)40 void help(void)
41 {
42     // Print help message
43     cout << endl << "rcapsdump: Queries GPU capabilities and dumps them into .rendercaps files" << endl;
44 
45     cout << endl << "Usage: rcapsdump" << endl;
46 }
47 
48 
49 
setUpGLRenderSystemOptions(Ogre::RenderSystem * rs)50 void setUpGLRenderSystemOptions(Ogre::RenderSystem* rs)
51 {
52 	using namespace Ogre;
53 	ConfigOptionMap options = rs->getConfigOptions();
54 	// set default options
55 	// this should work on every semi-normal system
56 	rs->setConfigOption(String("Colour Depth"), String("32"));
57 	rs->setConfigOption(String("FSAA"), String("0"));
58 	rs->setConfigOption(String("Full Screen"), String("No"));
59 	rs->setConfigOption(String("VSync"), String("No"));
60 	rs->setConfigOption(String("Video Mode"), String("800 x 600"));
61 
62 	// use the best RTT
63 	ConfigOption optionRTT = options["RTT Preferred Mode"];
64 
65 	if(find(optionRTT.possibleValues.begin(), optionRTT.possibleValues.end(), "FBO") != optionRTT.possibleValues.end())
66 	{
67 		rs->setConfigOption(String("RTT Preferred Mode"), String("FBO"));
68 	}
69 	else if(find(optionRTT.possibleValues.begin(), optionRTT.possibleValues.end(), "PBuffer") != optionRTT.possibleValues.end())
70 	{
71 		rs->setConfigOption(String("RTT Preferred Mode"), String("PBuffer"));
72 	}
73 	else
74 		rs->setConfigOption(String("RTT Preferred Mode"), String("Copy"));
75 }
76 
77 
setUpD3D9RenderSystemOptions(Ogre::RenderSystem * rs)78 void setUpD3D9RenderSystemOptions(Ogre::RenderSystem* rs)
79 {
80 	using namespace Ogre;
81 	ConfigOptionMap options = rs->getConfigOptions();
82 	// set default options
83 	// this should work on every semi-normal system
84 	rs->setConfigOption(String("Anti aliasing"), String("None"));
85 	rs->setConfigOption(String("Full Screen"), String("No"));
86 	rs->setConfigOption(String("VSync"), String("No"));
87 	rs->setConfigOption(String("Video Mode"), String("800 x 600 @ 32-bit colour"));
88 
89 	// pick first available device
90 	ConfigOption optionDevice = options["Rendering Device"];
91 
92 	rs->setConfigOption(optionDevice.name, optionDevice.currentValue);
93 }
94 
95 
main(int numargs,char ** args)96 int main(int numargs, char** args)
97 {
98     if (numargs != 1)
99     {
100         help();
101         return -1;
102     }
103 
104     RenderSystemCapabilities* glCaps = 0;
105     RenderSystemCapabilities* d3d9Caps = 0;
106 
107     RenderSystemCapabilitiesSerializer serializer;
108 
109     // query openGL for caps if available
110     Root* root = new Root("plugins.cfg");
111     RenderSystem* rsGL = root->getRenderSystemByName("OpenGL Rendering Subsystem");
112     if(rsGL)
113     {
114         setUpGLRenderSystemOptions(rsGL);
115 		root->setRenderSystem(rsGL);
116 		root->initialise(true, "OGRE rcapsdump GL Window");
117 		glCaps = const_cast<RenderSystemCapabilities *>(rsGL->getCapabilities());
118     }
119     if(glCaps)
120     {
121         serializer.writeScript(glCaps, glCaps->getDeviceName(), "rcapsdump_gl.rendercaps");
122     }
123 
124     delete root;
125 
126     // query D3D9 for caps if available
127     root = new Root("plugins.cfg");
128     RenderSystem* rsD3D9 = root->getRenderSystemByName("Direct3D9 Rendering Subsystem");
129     if(rsD3D9)
130     {
131         setUpD3D9RenderSystemOptions(rsD3D9);
132 		root->setRenderSystem(rsD3D9);
133 		root->initialise(true, "OGRE rcapsdump D3D9 Window");
134 		d3d9Caps = const_cast<RenderSystemCapabilities *>(rsD3D9->getCapabilities());
135     }
136     if(d3d9Caps)
137     {
138         serializer.writeScript(d3d9Caps, d3d9Caps->getDeviceName(), "rcapsdump_d3d9.rendercaps");
139     }
140 
141     delete root;
142 
143     return 0;
144 
145 }
146 
147