Пример #1
0
bool MedusaModule::OnLoad(IEventArg& e /*= IEventArg::Empty*/)
{
	NodeEditorFactory::Instance().Initialize();
	ResolutionAdapter::Instance().Initialize(ApplicationSettings::Instance().ResultWinSize());
	ResolutionAdapter::Instance().InitializeCameras();


	RenderEngine::Instance().InitializeBeforeWindow(!MEDUSA_FLAG_HAS(ApplicationSettings::Instance().Features(),EngineFeatures::MultipleThreadRendering));

	auto game = Application::Instance().Game();
	//1. create window
	mWindow = WindowFactory::Create((MedusaWindowHandle)nullptr, game->Name());
	MEDUSA_ASSERT_NOT_NULL(mWindow, "");
	mWindow->SetSize(ResolutionAdapter::Instance().WinSize());
	MEDUSA_ASSERT_TRUE(mWindow->Initialize(), "");

	//2.create egl view
	mRootView = ViewFactory::CreateGLView(game->Name());
	mWindow->AddView(mRootView);
	MEDUSA_ASSERT_NOT_NULL(mRootView, "");
	mRootView->SetSize(ResolutionAdapter::Instance().WinSize());
	MEDUSA_ASSERT_TRUE(mRootView->Initialize(), "");

	//show window
	mWindow->Show();

	RenderEngine::Instance().InitializeAfterWindow(!MEDUSA_FLAG_HAS(ApplicationSettings::Instance().Features(), EngineFeatures::MultipleThreadRendering));


	mUpdateSystemStage.Add( ResourceManager::InstancePtr());
	mUpdateSystemStage.Add(AnimationManager::InstancePtr());
	mUpdateSystemStage.Add(ParticleManager::InstancePtr());
	mUpdateSystemStage.Add(InputManager::InstancePtr());
#ifdef MEDUSA_AL
	mUpdateSystemStage.Add(AudioEngine::InstancePtr());	//must be after resource manager
#endif

	mUpdateSystemStage.Initialize();
	mUpdateSystemStage.ApplyOptionToAll(!MEDUSA_FLAG_HAS(ApplicationSettings::Instance().Features(), EngineFeatures::MultipleThreadUpdating) ? ExecuteOption::Sync : ExecuteOption::Async);


	SceneManager::Instance().Initialize(!MEDUSA_FLAG_HAS(ApplicationSettings::Instance().Features(), EngineFeatures::MultipleThreadRendering));

	return true;
}
Пример #2
0
bool WinEGLView::Initialize()
{
	RETURN_FALSE_IF_FALSE(BaseRenderView::Initialize());


	MEDUSA_ASSERT_TRUE(mParent->IsA<IWindow>(), "");
	WinWindow* window = (WinWindow*)(INode*)mParent;

	EGLNativeWindowType eglNativeWindow = window->WindowHandle();

	mEGLNativeWindow = eglNativeWindow;
	mEGLNativeDisplay = EGL_DEFAULT_DISPLAY;
	mEGLDisplay = EGL_NO_DISPLAY;
	mEGLConfig = 0;
	mEGLSurface = EGL_NO_SURFACE;
	mEGLContext = EGL_NO_CONTEXT;

	mPixmapDisplay = 0;
	mBitmapPixmap = 0;
	mBitmapPixmapOld = 0;

	/*
	Step 0 - Create a NativeWindowType that we can use for OpenGL ES output
	*/


	/*
	Step 1 - Get the default display.
	EGL uses the concept of a "display" which in most environments
	corresponds to a single physical screen. Since we usually want
	to draw to the main screen or only have a single screen to begin
	with, we let EGL pick the default display.
	Querying other displays is platform specific.
	*/
	mEGLNativeDisplay = GetDC(mEGLNativeWindow);

	mEGLDisplay = eglGetDisplay(mEGLNativeDisplay);
	if (mEGLDisplay == EGL_NO_DISPLAY)
	{
		mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	}
	MEDUSA_ASSERT_NOT_EQUAL(mEGLDisplay, EGL_NO_DISPLAY, "");

	if (mIsNeedPixmap)
	{
		mPixmapDisplay = CreateCompatibleDC(mEGLNativeDisplay);
		Size2F screenSize = ResolutionAdapter::Instance().WinSize();
		mBitmapPixmap = CreateCompatibleBitmap(mEGLNativeDisplay, (uint)screenSize.Width, (uint)screenSize.Height);
	}

	/*
	Step 2 - Initialize EGL.
	EGL has to be initialized with the display obtained in the
	previous step. We cannot use other EGL functions except
	eglGetDisplay and eglGetError before eglInitialize has been
	called.
	If we're not interested in the EGL version number we can just
	pass nullptr for the second and third parameters.
	*/

	EGLint majorVersion, minorVersion;
	EGLBoolean result = eglInitialize(mEGLDisplay, &majorVersion, &minorVersion);
	MEDUSA_ASSERT_NOT_ZERO(result, "");

	//ASSERT_NOT_EQUAL(majorVersion,1);

	/*
	Step 3 - Specify the required configuration attributes.
	An EGL "configuration" describes the pixel format and type of
	surfaces that can be used for drawing.
	For now we just want to use a 16 bit RGB surface that is a
	Window surface, i.e. it will be visible on screen. The list
	has to contain key/value pairs, terminated with EGL_NONE.
	*/
	eglBindAPI(EGL_OPENGL_ES_API);
	MEDUSA_ASSERT_FALSE(GetEGLError(), "");

	/*
	Step 4 - Find a config that matches all requirements.
	eglChooseConfig provides a list of all available configurations
	that meet or exceed the requirements given as the second
	argument. In most cases we just want the first config that meets
	all criteria, so we can limit the number of configs returned to 1.
	*/

	mEGLConfig = ChooseConfig();

	/*
	Step 5 - Create a surface to draw to.
	Use the config picked in the previous step and the native window
	handle when available to create a window surface. A window surface
	is one that will be visible on screen inside the native display (or
	full screen if there is no windowing system).
	Pixmaps and pbuffers are surfaces which only exist in off-screen
	memory.
	*/
	CreateSurface();


	/*
	Step 6 - Create a context.
	EGL has to create a context for OpenGL ES. Our OpenGL ES resources
	like textures will only be valid inside this context
	(or shared contexts)
	*/
	CreateContext();


	/*
	Step 7 - Bind the context to the current thread and use our
	window surface for drawing and reading.
	Contexts are bound to a thread. This means you don't have to
	worry about other threads and processes interfering with your
	OpenGL ES application.
	We need to specify a surface that will be the target of all
	subsequent drawing operations, and one that will be the source
	of read operations. They can be the same surface.
	*/

	//ASSERT_NOT_EQUAL(eglSurface,EGL_NO_SURFACE,0);

	eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
	MEDUSA_ASSERT_FALSE(GetEGLError(), "");
	/*
	Step 8 - Draw something with OpenGL ES.
	At this point everything is initialized and we're ready to use
	OpenGL ES to draw something on the screen.
	*/
	if (mIsNeedPixmap)
	{
		mBitmapPixmapOld = (EGLNativePixmapType)SelectObject(mPixmapDisplay, mBitmapPixmap);
	}
	//SetForegroundWindow(mEGLNativeWindow);

	RenderEngine::Instance().Initialize();

	return true;

}
Пример #3
0
EGLConfig WinEGLView::ChooseConfig() const
{
	EGLint configAttribures[32];
	EGLConfig config = (EGLConfig)0;
	uint i = 0;

	if (mConfigId != EGL_DONT_CARE)
	{
		configAttribures[i++] = EGL_CONFIG_ID;
		configAttribures[i++] = mConfigId;
	}
	else
	{
		configAttribures[i++] = EGL_LEVEL;
		configAttribures[i++] = 0;

		configAttribures[i++] = EGL_RENDERABLE_TYPE;
		configAttribures[i++] = mRenderableType;

		/*configAttribures[i++]=EGL_BUFFER_SIZE;
		configAttribures[i++]=mColorBufferSize;*/

		if (mNativeRenderable != EGL_DONT_CARE)
		{
			configAttribures[i++] = EGL_NATIVE_RENDERABLE;
			configAttribures[i++] = mNativeRenderable;
		}

		if (GraphicsContext::Instance().NeedDepthBuffer())
		{
			configAttribures[i++] = EGL_DEPTH_SIZE;
			configAttribures[i++] = GraphicsContext::Instance().DepthBufferSize();
		}

		if (GraphicsContext::Instance().NeedStencilBuffer())
		{
			configAttribures[i++] = EGL_STENCIL_SIZE;
			configAttribures[i++] = GraphicsContext::Instance().StencilBufferSize();
		}

		configAttribures[i++] = EGL_SURFACE_TYPE;
		configAttribures[i] = EGL_WINDOW_BIT;
		if (mIsNeedPBuffer)
		{
			configAttribures[i] |= EGL_PBUFFER_BIT;
		}
		if (mIsNeedPixmap)
		{
			configAttribures[i] |= EGL_PIXMAP_BIT;
		}
		i++;

		if (GraphicsContext::Instance().NeedMultipleSampling())
		{
			configAttribures[i++] = EGL_SAMPLE_BUFFERS;
			configAttribures[i++] = 1;

			configAttribures[i++] = EGL_SAMPLES;
			configAttribures[i++] = GraphicsContext::Instance().SampleCount();
		}
		else
		{
			configAttribures[i++] = EGL_SAMPLE_BUFFERS;
			configAttribures[i++] = 0;
		}

	}
	//configAttribures[i++]=EGL_DEPTH_SIZE;
	//configAttribures[i++]=EGL_DONT_CARE;

	configAttribures[i++] = EGL_NONE;
	EGLint configCount;
	EGLint result = eglChooseConfig(mEGLDisplay, configAttribures, &config, 1, &configCount);
	MEDUSA_ASSERT_TRUE(result&&configCount == 1, "");
	return config;
}