Exemplo n.º 1
0
void WinEGLView::CreateContext()
{
	EGLint contextAttributes[32];
	uint i = 0;
	switch (mGLESVersion)
	{
	case 2:
		contextAttributes[i++] = EGL_CONTEXT_CLIENT_VERSION;
		contextAttributes[i++] = 2;
		break;
	case 3:
		contextAttributes[i++] = EGL_CONTEXT_CLIENT_VERSION;
		contextAttributes[i++] = 3;
		break;
	case 1:
	default:
		contextAttributes[i++] = EGL_CONTEXT_CLIENT_VERSION;
		contextAttributes[i++] = 1;
		break;
	}

	contextAttributes[i] = EGL_NONE;


	mEGLContext = eglCreateContext(mEGLDisplay, mEGLConfig, nullptr, contextAttributes);
	MEDUSA_ASSERT_NOT_EQUAL(mEGLContext, EGL_NO_CONTEXT, "");
	MEDUSA_ASSERT_FALSE(GetEGLError(), "");
}
Exemplo n.º 2
0
void IMaterial::AddTexture( ITexture* texture )
{
	MEDUSA_ASSERT_NOT_NULL(texture,"");
	MEDUSA_ASSERT_FALSE(mTextures.ContainsKey(texture->Unit()),"Duplicate add texture of same unit");
	MEDUSA_ASSERT_FALSE(mTextureSamplerDict.ContainsKey(texture->SamplerName()),"Duplicate add texture of same sampler name");

	texture->Retain();
	mTextures.Add(texture->Unit(),texture);
	mTextureSamplerDict.Add(texture->SamplerName(), texture);

	EnableBlend(texture->IsBlend());
	
	if (mFirstTexture==nullptr)
	{
		mFirstTexture=texture;
	}
}
Exemplo n.º 3
0
void WinEGLView::CreateSurface()
{
	EGLint	surfaceAttributes[16];
	uint i = 0;

	surfaceAttributes[i++] = EGL_NONE;

	if (mIsNeedPixmap)
	{
		mEGLSurface = eglCreatePixmapSurface(mEGLDisplay, mEGLConfig, mBitmapPixmap, surfaceAttributes);
	}
	else
	{
		mEGLSurface = eglCreateWindowSurface(mEGLDisplay, mEGLConfig, mEGLNativeWindow, surfaceAttributes);
		if (mEGLSurface == EGL_NO_SURFACE)
		{
			eglGetError(); // Clear error
			mEGLSurface = eglCreateWindowSurface(mEGLDisplay, mEGLConfig, nullptr, surfaceAttributes);
		}
	}

	MEDUSA_ASSERT_NOT_EQUAL(mEGLSurface, EGL_NO_SURFACE, "");
	MEDUSA_ASSERT_FALSE(GetEGLError(), "");
}
Exemplo n.º 4
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;

}