Condensed 2.0 example, tested on win 8.1 with d3d11

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
tahsmith
Gnoblar
Posts: 4
Joined: Fri Aug 01, 2014 6:46 am

Condensed 2.0 example, tested on win 8.1 with d3d11

Post by tahsmith » Wed Aug 06, 2014 4:58 am

Hi All,

I've been evaluating Ogre 2.0 for a project, in the processes of which I made a minimal example of Ogre 2.0 code. I was going to contribute this to the wiki, since there didn't seem to be something working like that for 2.0 yet, but first I was going to open it up to comment here.

The project is a rewrite of visualisation tool, originally written with ogre 1.7.

About the example:

Are there any simple examples that can be done on D3D11 without using the RTShader system? Otherwise ShaderGeneratorTechniqueResolverListener seems like a necessity.

Also, removing the camera from the root scene node to begin with seems to be what you would always want to do with a new camera, right?

I'm also not sure that everything is necessarily in the most 'canonical' order, esp. the initialisation of the compositor.

The whole code can be found here

Code: Select all

int main()
{
	// Start up ogre
	Ogre::Root root("", "", "OgreLog.txt");

	loadPlugins({
		"RenderSystem_Direct3D11",
		"Plugin_ParticleFX",
		"Plugin_CgProgramManager"
	});

	// Use the first available renderer
	Ogre::RenderSystem* renderSys = root.getAvailableRenderers()[0];
	root.setRenderSystem(renderSys);

	// Set video mode
	renderSys->setConfigOption("Full Screen", "No");
	renderSys->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour");

	// Make the window
	Ogre::RenderWindow* pRenderWin = root.initialise(true);

	// Start compositor
	root.initialiseCompositor();

	// Resources necessary for the real-time shader.
	loadResources("Essential", {
		R"(media\RTShaderLib)",
		R"(media\RTShaderLib\materials)",
		R"(media\RTShaderLib\hlsl)",
		R"(media\RTShaderLib\cg)"
	});

	bool ok = Ogre::RTShader::ShaderGenerator::initialize();
	auto &shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingleton();

	// Necessary for D3D11. It has no fixed function pipeline.
	ShaderGeneratorTechniqueResolverListener sgtrl(&shaderGenerator);
	Ogre::MaterialManager::getSingleton().addListener(&sgtrl);

	// Set up scene manager and one camera
	Ogre::SceneManager* pSceneMgr = root.createSceneManager(
		Ogre::ST_GENERIC,
		1,
		Ogre::INSTANCING_CULLING_SINGLETHREAD
	);

	// Add scene manager to shader generator
	shaderGenerator.addSceneManager(pSceneMgr);

	loadResources("General", {
		R"(media\models)",
		R"(media\materials\scripts)",
		R"(media\materials\textures)",
		R"(media\materials\programs)",
		R"(media\materials\programs\cg)",
		R"(media\materials\programs\hlsl)",
		R"(media\packs\cubemapsJS.zip)"
	});
	
	// Done with the machinery, we can actually set up the scene now

	// Make camera
	Ogre::Camera* pCamera = pSceneMgr->createCamera("Camera");

	// Set up workspace
	Ogre::CompositorManager2* pCompositorManager = root.getCompositorManager2();
	const Ogre::String workspaceName = "scene workspace";
	pCompositorManager->createBasicWorkspaceDef(workspaceName, Ogre::ColourValue::Black);
	pCompositorManager->addWorkspace(pSceneMgr, pRenderWin, pCamera, workspaceName, true);

	// Make a simple scene. Mostly following the camera track example.
	pSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");

	// setup some basic lighting for our scene
	pSceneMgr->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.3));
	Ogre::SceneNode *lightNode = pSceneMgr->getRootSceneNode()->createChildSceneNode();
	lightNode->setPosition(20, 80, 50);
	lightNode->attachObject(pSceneMgr->createLight());

	// create an ogre head entity and attach it to a node
	Ogre::Entity* head = pSceneMgr->createEntity("ogrehead.mesh");
	head->setName("Head");
	Ogre::SceneNode* headNode = pSceneMgr->getRootSceneNode()->createChildSceneNode();
	headNode->attachObject(head);

	pCamera->setAutoTracking(true, headNode);   // make the camera face the head

	// create a camera node and attach camera to it
	Ogre::SceneNode* camNode = pSceneMgr->getRootSceneNode()->createChildSceneNode();
	pCamera->detachFromParent();
	camNode->attachObject(pCamera);

	// set up a 10 second animation for our camera, using spline interpolation for nice curves
	Ogre::Animation* anim = pSceneMgr->createAnimation("CameraTrack", 10);
	anim->setInterpolationMode(Ogre::Animation::IM_SPLINE);

	// create a track to animate the camera's node
	Ogre::NodeAnimationTrack* track = anim->createNodeTrack(camNode);

	// create keyframes for our track
	track->createNodeKeyFrame(0)->setTranslate(Ogre::Vector3(200, 0, 0));
	track->createNodeKeyFrame(2.5)->setTranslate(Ogre::Vector3(0, -50, 100));
	track->createNodeKeyFrame(5)->setTranslate(Ogre::Vector3(-500, 100, 0));
	track->createNodeKeyFrame(7.5)->setTranslate(Ogre::Vector3(0, 200, -300));
	track->createNodeKeyFrame(10)->setTranslate(Ogre::Vector3(200, 0, 0));

	// create a new animation state to track this
	Ogre::AnimationState* pAnimState = pSceneMgr->createAnimationState("CameraTrack");
	pAnimState->setEnabled(true);

	// Listens for window close events and frame events.
	Listener listener(pRenderWin);

	listener.doEachFrame([=] (const Ogre::FrameEvent& evt) {
		pAnimState->addTime(evt.timeSinceLastFrame);
	});

	root.startRendering();

	return 0;
}
0 x

User avatar
Thyrion
Goblin
Posts: 224
Joined: Wed Jul 31, 2013 1:58 pm
Location: germany

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by Thyrion » Wed Aug 06, 2014 5:03 pm

cool ... still didnt try 2.0, but it seems it is time for it 8)
0 x

mtsr
Gnoblar
Posts: 5
Joined: Thu Sep 10, 2009 12:27 pm

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by mtsr » Thu Aug 07, 2014 1:46 pm

I tried 2.0, but I got build errors. Can't wait until it's slightly more done.
0 x

drwbns
Orc Shaman
Posts: 777
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by drwbns » Thu Aug 07, 2014 6:30 pm

I'm still wrapping my head around 1.9 :)
0 x

tahsmith
Gnoblar
Posts: 4
Joined: Fri Aug 01, 2014 6:46 am

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by tahsmith » Mon Aug 11, 2014 3:42 am

mtsr wrote:I tried 2.0, but I got build errors. Can't wait until it's slightly more done.

What errors did you get? It will require a modern C++ compiler. I used VS2013.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4078
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 232
Contact:

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by dark_sylinc » Mon Aug 11, 2014 11:22 pm

Yes, which build errors? even with an old compiler (VS 2008), it should compile.
0 x

tahsmith
Gnoblar
Posts: 4
Joined: Fri Aug 01, 2014 6:46 am

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by tahsmith » Wed Aug 13, 2014 9:46 am

As far as the example goes it will require at least VS2012 I think. I used initializer_list construction for some things. I know that is not available in VS2010.
0 x

mtsr
Gnoblar
Posts: 5
Joined: Thu Sep 10, 2009 12:27 pm

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by mtsr » Wed Aug 13, 2014 10:56 am

tahsmith wrote:What errors did you get? It will require a modern C++ compiler. I used VS2013.
Seems like it is only the SampleBrowser and OgreHlms failing to build. Didn't look to closely last time, but just switched to 1.9.

On OS X with Xcode 5:

CMake: cmake -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64 ..
Build: xcodebuild -configuration RelWithDebInfo

SampleBrowser fails with:

Code: Select all

=== BUILD TARGET SampleBrowser OF PROJECT OGRE WITH CONFIGURATION RelWithDebInfo ===

Check dependencies

Write auxiliary files
/bin/mkdir -p /Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build
write-file /Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Script-893F4ED95E684FE688BD4216.sh
chmod 0755 /Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Script-893F4ED95E684FE688BD4216.sh
/bin/mkdir -p /Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Objects-normal/x86_64
write-file /Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Objects-normal/x86_64/SampleBrowser.LinkFileList

Create product structure
/bin/mkdir -p /Users/username/Development/ogre/build.2.0/bin/RelWithDebInfo/SampleBrowser.app/Contents
/bin/mkdir -p /Users/username/Development/ogre/build.2.0/bin/RelWithDebInfo/SampleBrowser.app/Contents/MacOS

ProcessInfoPlistFile build.2.0/bin/RelWithDebInfo/SampleBrowser.app/Contents/Info.plist build.2.0/Samples/Browser/CMakeFiles/SampleBrowser.dir/Info.plist
    cd /Users/username/Development/ogre
    builtin-infoPlistUtility /Users/username/Development/ogre/build.2.0/Samples/Browser/CMakeFiles/SampleBrowser.dir/Info.plist -genpkginfo /Users/username/Development/ogre/build.2.0/bin/RelWithDebInfo/SampleBrowser.app/Contents/PkgInfo -expandbuildsettings -platform macosx -o /Users/username/Development/ogre/build.2.0/bin/RelWithDebInfo/SampleBrowser.app/Contents/Info.plist

CompileC build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Objects-normal/x86_64/SampleBrowser.o Samples/Browser/src/SampleBrowser.cpp normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/username/Development/ogre
    export LANG=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c++ -arch x86_64 -fmessage-length=212 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -std=c++11 -stdlib=libc++ -Wno-trigraphs -fpascal-strings -O2 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-implicit-atomic-properties -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -Wno-c++11-extensions -DCMAKE_INTDIR=\"RelWithDebInfo\" -DINCLUDE_RTSHADER_SYSTEM -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.7 -g -fvisibility=hidden -Wno-sign-conversion -I/Users/username/Development/ogre/build.2.0/bin/RelWithDebInfo/include -I/Users/username/Development/ogre/OgreMain/include -I/Users/username/Development/ogre/build.2.0/include -I/Users/username/Development/ogre/OgreMain/include/OSX -I/Users/username/Development/ogre/Dependencies/include -I/usr/local/include/freetype2 -I/Users/username/Development/ogre/Dependencies/include/OIS -I/Library/Frameworks/Cg.framework/Headers -I/Users/username/Development/ogre -I/Users/username/Development/ogre/OgreMain/include/Threading -I/Users/username/Development/ogre/Samples/Common/include -I/Users/username/Development/ogre/Components/RTShaderSystem/include -I/Users/username/Development/ogre/Components/Overlay/include -I/Users/username/Development/ogre/Samples/Browser/include -I/Users/username/Development/ogre/RenderSystems/GL/include -I/Users/username/Development/ogre/RenderSystems/GL/include/OSX -I/Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/DerivedSources/x86_64 -I/Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/Users/username/Development/ogre/build.2.0/bin/RelWithDebInfo -F/Library/Frameworks -msse -msse2 -Wall -Winit-self -Wno-overloaded-virtual -Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers -Wno-long-long -DNDEBUG -DOGRE_GCC_VISIBILITY -fvisibility=hidden -x objective-c++ -MMD -MT dependencies -MF /Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Objects-normal/x86_64/SampleBrowser.d --serialize-diagnostics /Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Objects-normal/x86_64/SampleBrowser.dia -c /Users/username/Development/ogre/Samples/Browser/src/SampleBrowser.cpp -o /Users/username/Development/ogre/build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Objects-normal/x86_64/SampleBrowser.o
In file included from /Users/username/Development/ogre/Samples/Browser/src/SampleBrowser.cpp:40:
In file included from /Users/username/Development/ogre/Samples/Browser/include/SampleBrowser_OSX.h:45:
In file included from /Users/username/Development/ogre/Samples/Browser/include/SampleBrowser.h:31:
In file included from /Users/username/Development/ogre/OgreMain/include/Ogre.h:40:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreBillboardChain.h:37:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreMovableObject.h:37:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreSceneNode.h:33:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreNode.h:34:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreRenderable.h:42:
/Users/username/Development/ogre/OgreMain/include/OgreHlms.h:104:28: warning: field 'type' will be initialized after field 'result' [-Wreorder]
            Expression() : type( EXPR_VAR ), result( false ), negated( false ) {}
                           ^
In file included from /Users/username/Development/ogre/Samples/Browser/src/SampleBrowser.cpp:40:
/Users/username/Development/ogre/Samples/Browser/include/SampleBrowser_OSX.h:159:14: error: no member named 'cerr' in namespace 'std'
        std::cerr << "An exception has occurred: " <<
        ~~~~~^
1 warning and 1 error generated.

** BUILD FAILED **


The following build commands failed:
	CompileC build.2.0/Samples/Browser/OGRE.build/RelWithDebInfo/SampleBrowser.build/Objects-normal/x86_64/SampleBrowser.o Samples/Browser/src/SampleBrowser.cpp normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
OgreHlms fails with:

Code: Select all

=== BUILD TARGET OgreHlms OF PROJECT OGRE WITH CONFIGURATION RelWithDebInfo ===

Check dependencies

CompileC build.2.0/Tools/Hlms/OGRE.build/RelWithDebInfo/OgreHlms.build/Objects-normal/x86_64/HlmsCmd.o Tools/Hlms/src/HlmsCmd.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/username/Development/ogre
    export LANG=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=212 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -std=c++11 -stdlib=libc++ -Wno-trigraphs -fpascal-strings -O2 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR=\"RelWithDebInfo\" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.7 -g -fvisibility=hidden -Wno-sign-conversion -I/Users/username/Development/ogre/build.2.0/bin/RelWithDebInfo/include -I/Users/username/Development/ogre/OgreMain/include -I/Users/username/Development/ogre/build.2.0/include -I/Users/username/Development/ogre/OgreMain/include/OSX -I/Users/username/Development/ogre/Dependencies/include -I/usr/local/include/freetype2 -I/Users/username/Development/ogre/Dependencies/include/OIS -I/Library/Frameworks/Cg.framework/Headers -I/Users/username/Development/ogre -I/Users/username/Development/ogre/OgreMain/include/Threading -I/Users/username/Development/ogre/Tools/Hlms/include -I/Users/username/Development/ogre/build.2.0/Tools/Hlms/OGRE.build/RelWithDebInfo/OgreHlms.build/DerivedSources/x86_64 -I/Users/username/Development/ogre/build.2.0/Tools/Hlms/OGRE.build/RelWithDebInfo/OgreHlms.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/Users/username/Development/ogre/build.2.0/bin/RelWithDebInfo -F/Library/Frameworks -msse -msse2 -Wall -Winit-self -Wno-overloaded-virtual -Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers -Wno-long-long -DNDEBUG -DOGRE_GCC_VISIBILITY -fvisibility=hidden -MMD -MT dependencies -MF /Users/username/Development/ogre/build.2.0/Tools/Hlms/OGRE.build/RelWithDebInfo/OgreHlms.build/Objects-normal/x86_64/HlmsCmd.d --serialize-diagnostics /Users/username/Development/ogre/build.2.0/Tools/Hlms/OGRE.build/RelWithDebInfo/OgreHlms.build/Objects-normal/x86_64/HlmsCmd.dia -c /Users/username/Development/ogre/Tools/Hlms/src/HlmsCmd.cpp -o /Users/username/Development/ogre/build.2.0/Tools/Hlms/OGRE.build/RelWithDebInfo/OgreHlms.build/Objects-normal/x86_64/HlmsCmd.o
In file included from /Users/username/Development/ogre/Tools/Hlms/src/HlmsCmd.cpp:40:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreRoot.h:34:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreSceneManagerEnumerator.h:33:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreSceneManager.h:41:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreAutoParamDataSource.h:33:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreLight.h:35:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreMovableObject.h:37:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreSceneNode.h:33:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreNode.h:34:
In file included from /Users/username/Development/ogre/OgreMain/include/OgreRenderable.h:42:
/Users/username/Development/ogre/OgreMain/include/OgreHlms.h:104:28: warning: field 'type' will be initialized after field 'result' [-Wreorder]
            Expression() : type( EXPR_VAR ), result( false ), negated( false ) {}
                           ^
/Users/username/Development/ogre/Tools/Hlms/src/HlmsCmd.cpp:103:9: warning: unused variable 'startIdx' [-Wunused-variable]
    int startIdx = findCommandLineOpts( numargs, args, unOptList, binOptList );
        ^
/Users/username/Development/ogre/Tools/Hlms/src/HlmsCmd.cpp:346:22: error: no member named 'macBundlePath' in namespace 'Ogre'
    archName = Ogre::macBundlePath() + "/Contents/Resources/Media";
               ~~~~~~^
2 warnings and 1 error generated.

** BUILD FAILED **


The following build commands failed:
	CompileC build.2.0/Tools/Hlms/OGRE.build/RelWithDebInfo/OgreHlms.build/Objects-normal/x86_64/HlmsCmd.o Tools/Hlms/src/HlmsCmd.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
0 x

darkheron
Kobold
Posts: 28
Joined: Fri Aug 29, 2014 9:05 pm

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by darkheron » Fri Aug 29, 2014 9:46 pm

hello everyone.
I have recently started testing upgrading my application from Ogre 1.9 to 2.0. For the most part it is going pretty well, however I have run into one problem.

I kept getting "pure virtual methods called" errors upon shutdown. So, using this code as a template I stripped it down to the bare bones, and modified it to work on Linux. Instead of using the ogre head as a model I just used a little cube mesh. Here is the little code snippet to create some test nodes with red cubes:

Code: Select all

	
Ogre::SceneNode* headNode = pSceneMgr->getRootSceneNode()->createChildSceneNode();
for (int i = 0; i < 99; ++i)
{
	Ogre::SceneNode* newNode = headNode->createChildSceneNode();
	Ogre::Entity* newEntity = pSceneMgr->createEntity("Cube.mesh");
	newEntity->setMaterialName("red");
	newNode->attachObject(newEntity);
}
This code will generate the "pure virtual methods called" error with a callstack that looks like the attachment. Clearly that looks a bit wrong.

The funny thing is if I change the value 99 to 98 I do not receive this error. Am I doing something wrong or have I stumbled upon a bug? Maybe some kind of symbol problem? Does anyone else get an error with this code?

I can provide extra data if needed.
Attachments
callstackss.png
Callstack at time of error
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4078
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 232
Contact:

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by dark_sylinc » Sat Aug 30, 2014 3:54 pm

Interesting... I will investigate. Thanks.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4078
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 232
Contact:

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by dark_sylinc » Sat Aug 30, 2014 4:13 pm

Is it possible for you to upload the sample so I can test it?
Thanks.
0 x

darkheron
Kobold
Posts: 28
Joined: Fri Aug 29, 2014 9:05 pm

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by darkheron » Sat Aug 30, 2014 7:08 pm

Here you go. This problem could be my fault since, while I know my way around Ogre 1.9 pretty darn well, I just started exploring conversion to 2.0 yesterday :)
Anyway, I just used the base sample in the original post ( since I am assuming it is the barest bones 2.0 sample available), cut out all the windows stuff, changed the path slashes, hardcoded paths, etc, and cut out anything that didn't seem essential to the problem.. ie the animation.

Note also I am now using the full debug builds ( built with Debug and not RelWithDebInfo ) but had the same problem with the default build. I have built my sample with all the same flags needed for an Ogre 2.0 Debug build.

Also uploaded as an attachment if that is easier. Err at least I think.. I now have about 10 main.cpp files I've been testing with but I think I got the right one.

I do have some other questions too, but I am not sure where to discuss these things like...
- What is the point of the OGRE_FLEXIBILITY_LEVEL defines used to define virtual? They all seem the same except for level 0. I've not seen that done before and was just curious.
- Why is addChild in Node not virtual? As far as I can tell it is the only method that modifies the mChildren vector that is not virtual. This might make derived classes from a custom factory that act as gatekeepers of sorts hard to write since the mChildren vector could be modified via a base pointer with addChildren and the custom class wouldn't know about it.

Anyway I keep coming up with questions like this but I'm not sure where to ask them.. where is the correct place?

Thank you for your time.

Code: Select all

#include <vector>
#include <string>
#include <iostream>
#include <functional>
 
#include "OGRE/Ogre.h"
#include "OGRE/OgreFrameListener.h"
#include "OGRE/Compositor/OgreCompositorManager2.h"
#include "OGRE/RTShaderSystem/OgreRTShaderSystem.h"
 
using std::vector;
using std::string;
using std::function;
 
class Listener : public Ogre::FrameListener, public Ogre::WindowEventListener
{
	bool running { true };
	function<void(const Ogre::FrameEvent&)> frameHandler { nullptr };
public:
 
	Listener(Ogre::RenderWindow* pWindow)
	{
		Ogre::WindowEventUtilities::addWindowEventListener(pWindow, this);
		Ogre::Root::getSingleton().addFrameListener(this);
	}
 
	void doEachFrame(function<void(const Ogre::FrameEvent&)> handler)
	{
		frameHandler = handler;
	}
 
private:
	bool frameStarted(const Ogre::FrameEvent& evt) override
	{
		if (frameHandler) frameHandler(evt);
		return running;
	}
 
	bool windowClosing(Ogre::RenderWindow*)
	{
		running = false;
		return false;
	}
};
 
Ogre::String rootFolder()
{
	static Ogre::String ogreRoot("/home/darkheron/Projects/Ogre2Test/dist/Debug");
	return ogreRoot;
}
 
void loadPlugins(vector<string> plugins)
{
	// Load listed plugins
	for (string name : plugins)
	{
		Ogre::Root::getSingleton().loadPlugin("/usr/local/lib/OGRE/" + name);
	}
}
 
void loadResources(string name, vector<string> paths)
{
	for (string path : paths)
	{
		string type;
		if (path.substr(path.length() - 4, 4) == ".zip")
		{
			type = "Zip";
		}
		else
		{
			type = "FileSystem";
		}
		Ogre::ResourceGroupManager::getSingleton().addResourceLocation(rootFolder() + "/" + path, type, name);
	}
 
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(name);
}
 
int main()
{
	// Start up ogre
	Ogre::Root root("", "", "OgreLog.txt");
 
	loadPlugins({
		"RenderSystem_GL_d",
		"Plugin_ParticleFX_d",
		"Plugin_CgProgramManager_d"
	});
 
	// Use the first available renderer
	// Note assumes there is one renderer... AV if not
	Ogre::RenderSystem* renderSys = root.getAvailableRenderers()[0];
	root.setRenderSystem(renderSys);
 
	// Set video mode
	renderSys->setConfigOption("Full Screen", "No");
	renderSys->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour");
 
	// Make the window
	Ogre::RenderWindow* pRenderWin = root.initialise(true);
 
	// Start compositor
	root.initialiseCompositor();
 
	// Resources necessary for the real-time shader.
	loadResources("Essential", {
		R"(media/RTShaderLib)",
		R"(media/RTShaderLib/materials)",
		R"(media/RTShaderLib/cg)"
	});
 
	bool ok = Ogre::RTShader::ShaderGenerator::initialize();
	auto &shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingleton();
 
	// Set up scene manager and one camera
	Ogre::SceneManager* pSceneMgr = root.createSceneManager(
		Ogre::ST_GENERIC,
		1,
		Ogre::INSTANCING_CULLING_SINGLETHREAD
	);
 
	// Add scene manager to shader generator
	shaderGenerator.addSceneManager(pSceneMgr);
 
	loadResources("General", {
		R"(media/models)",
		R"(media/materials/scripts)",
		R"(media/materials/textures)",
		R"(media/materials/programs)",
		R"(media/packs/cubemapsJS.zip)"
	});
	
	// Done with the machinery, we can actually set up the scene now
 
	// Make camera
	Ogre::Camera* pCamera = pSceneMgr->createCamera("Camera");
 
	// Set up workspace
	Ogre::CompositorManager2* pCompositorManager = root.getCompositorManager2();
	const Ogre::String workspaceName = "scene workspace";
	pCompositorManager->createBasicWorkspaceDef(workspaceName, Ogre::ColourValue::Black);
	pCompositorManager->addWorkspace(pSceneMgr, pRenderWin, pCamera, workspaceName, true);
 
 	// Took this out for testing.
	// pSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");
 
	// setup some basic lighting for our scene
	pSceneMgr->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.3));
	Ogre::SceneNode *lightNode = pSceneMgr->getRootSceneNode()->createChildSceneNode();
	lightNode->setPosition(20, 80, 50);
	lightNode->attachObject(pSceneMgr->createLight());
 
	// create an ogre head entity and attach it to a node
	// Ogre::Entity* head = pSceneMgr->createEntity("ogrehead.mesh");
	// head->setName("Head");
	Ogre::SceneNode* headNode = pSceneMgr->getRootSceneNode()->createChildSceneNode();
	// headNode->attachObject(head);

	// I just used a little test cube here, but the ogre head blows up too.
	for (int i = 0; i < 99; ++i)
	// If I reduce this ^^ to 98 I don't get the error.
	{
		Ogre::SceneNode* newNode = headNode->createChildSceneNode();
		Ogre::Entity* newEntity = pSceneMgr->createEntity("Cube.mesh");
		newEntity->setMaterialName("red");
		newNode->attachObject(newEntity);
	}
 
	// Listens for window close events and frame events.
	Listener listener(pRenderWin);
 
 	// No animation, for test so no need for incrementing time.
	// listener.doEachFrame([=] (const Ogre::FrameEvent& evt) {
	// 	pAnimState->addTime(evt.timeSinceLastFrame);
	// });
 
	root.startRendering();
 
	return 0;
}
Attachments
main.cpp
(4.77 KiB) Downloaded 70 times
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4078
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 232
Contact:

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by dark_sylinc » Sat Aug 30, 2014 7:36 pm

Hi, about the problem, I successfully reproduced it. Don't worry, it's not your fault. You hit a bug.
I'm debugging while I'm writing this post.
darkheron wrote:- What is the point of the OGRE_FLEXIBILITY_LEVEL defines used to define virtual? They all seem the same except for level 0. I've not seen that done before and was just curious.
Ogre 1.x had almost every single function virtual (which adds a performance overhead); even though like 90% of them were never, ever overloaded. Here's where flexibility levels appear.
We removed a lot of virtuals. But there are a few that are performance sensitive yet some people MIGHT want to overload them.
For example Node::setPosition doesn't need overloading, but some derived implementations may want to overload it. Node::getPosition is less likely to need overloading than Node::setPosition; but some implementations might want to overload it.
So these functions are declared like this:

Code: Select all

virtual_l1 void setPosition( const Vector3& pos );
virtual_l2 Vector3 getPosition(void) const;
When OGRE_FLEXIBILITY_LEVEL = 1; virtual_l1 defines to "virtual"; when OGRE_FLEXIBILITY_LEVEL = 2, both virtual_l1 & virtual_l2 define to "virtual".
This way users who want to use plugin "X" which needs a flexibility level = 2; can use their custom builds without penalizing the rest of the users who don't intend to use that plugin w/ useless virtual-ness.
If you notice that this isn't the behavior the code is doing, report it to me ;)
- Why is addChild in Node not virtual? As far as I can tell it is the only method that modifies the mChildren vector that is not virtual. This might make derived classes from a custom factory that act as gatekeepers of sorts hard to write since the mChildren vector could be modified via a base pointer with addChildren and the custom class wouldn't know about it.
Because the new Node class works with DOD (Data Oriented Design) and not OOP (Object Oriented Programming).
Calling addChild involves the ArrayMemoryManager to request a slot at the new hierarchy depth, copy the DOD data, and then release the old hiearchy depth's memory slot.
Nodes can also live in different ArrayMemoryManager (no implementation is provided yet; for the time being there is only just one). For example if we were to write an OctreeSceneManager, moving to another Octant would mean to migrate to a different ArrayMemoryManager. Same would happen with portals, etc.
This is something that is too big for a class like addChild to do, and should be done at a higher level. Allowing overload of addChild would be extremely dangerous and prone to bad patterns popping up.
Anyway I keep coming up with questions like this but I'm not sure where to ask them.. where is the correct place?
You can use this forum section.
You will probably be interested in the Porting manual (which can also be found in the Doc section of the repository) and the slides of the proposal for 2.0. Most of the content in the slides is already implemented, and while the actual implementation may have diverged a bit from what was proposed, it should help you clear many doubts.

Cheers
Matias
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4078
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 232
Contact:

Re: Condensed 2.0 example, tested on win 8.1 with d3d11

Post by dark_sylinc » Sat Aug 30, 2014 8:46 pm

Fixed in 846df98832c9.
0 x

Post Reply