예제 #1
0
bool AndroidEGLGraphicsContext::Init(ANativeWindow *wnd, int backbufferWidth, int backbufferHeight, int backbufferFormat) {
	wnd_ = wnd;
	gl = HostGL_CreateGLInterface();
	if (!gl) {
		ELOG("ERROR: Failed to create GL interface");
		return false;
	}
	ILOG("EGL interface created. Desired backbuffer size: %dx%d", backbufferWidth, backbufferHeight);

	// Apparently we still have to set this through Java through setFixedSize on the bufferHolder for it to take effect...
	gl->SetBackBufferDimensions(backbufferWidth, backbufferHeight);
	gl->SetMode(MODE_DETECT_ES);

	bool use565 = false;
	switch (backbufferFormat) {
	case 4:  // PixelFormat.RGB_565
		use565 = true;
		break;
	}

	if (!gl->Create(wnd, false, use565)) {
		ELOG("EGL creation failed! (use565=%d)", (int)use565);
		// TODO: What do we do now?
		delete gl;
		return false;
	}
	gl->MakeCurrent();
	return true;
}
예제 #2
0
bool AndroidEGLGraphicsContext::Init(ANativeWindow *wnd, int backbufferWidth, int backbufferHeight, int backbufferFormat, int androidVersion) {
	wnd_ = wnd;
	gl = HostGL_CreateGLInterface();
	if (!gl) {
		ELOG("ERROR: Failed to create GL interface");
		return false;
	}
	ILOG("EGL interface created. Desired backbuffer size: %dx%d", backbufferWidth, backbufferHeight);

	// Apparently we still have to set this through Java through setFixedSize on the bufferHolder for it to take effect...
	gl->SetBackBufferDimensions(backbufferWidth, backbufferHeight);
	gl->SetMode(MODE_DETECT_ES);

	bool use565 = false;

	// This workaround seems only be needed on some really old devices.
	if (androidVersion < ANDROID_VERSION_ICS) {
		switch (backbufferFormat) {
		case 4:	// PixelFormat.RGB_565
			use565 = true;
			break;
		default:
			break;
		}
	}

	if (!gl->Create(wnd, false, use565)) {
		ELOG("EGL creation failed! (use565=%d)", (int)use565);
		// TODO: What do we do now?
		delete gl;
		return false;
	}
	gl->MakeCurrent();
	CheckGLExtensions();
	draw_ = Draw::T3DCreateGLContext();
	return true;
}
예제 #3
0
파일: GLUtil.cpp 프로젝트: BhaaLseN/dolphin
void InitInterface()
{
	GLInterface = HostGL_CreateGLInterface();
}
예제 #4
0
extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(JNIEnv *env, jobject obj, jobject _surf) {
	ANativeWindow *wnd = ANativeWindow_fromSurface(env, _surf);

	WLOG("runEGLRenderLoop. display_xres=%d display_yres=%d", display_xres, display_yres);

	if (wnd == nullptr) {
		ELOG("Error: Surface is null.");
		return false;
	}

	cInterfaceBase *gl = HostGL_CreateGLInterface();
	if (!gl) {
		ELOG("ERROR: Failed to create GL interface");
		return false;
	}
	ILOG("EGL interface created. Desired backbuffer size: %dx%d", desiredBackbufferSizeX, desiredBackbufferSizeY);

	// Apparently we still have to set this through Java through setFixedSize on the bufferHolder for it to take effect...
	gl->SetBackBufferDimensions(desiredBackbufferSizeX, desiredBackbufferSizeY);
	gl->SetMode(MODE_DETECT_ES);

	bool use565 = false;
	switch (backbuffer_format) {
	case 4:  // PixelFormat.RGB_565
		use565 = true;
		break;
	}

	if (!gl->Create(wnd, false, use565)) {
		ELOG("EGL creation failed");
		// TODO: What do we do now?
		return false;
	}
	gl->MakeCurrent();

	if (!renderer_inited) {
		NativeInitGraphics();
		renderer_inited = true;
	}

	exitRenderLoop = false;
	renderLoopRunning = true;

	while (!exitRenderLoop) {
		static bool hasSetThreadName = false;
		if (!hasSetThreadName) {
			hasSetThreadName = true;
			setCurrentThreadName("AndroidRender");
		}

		// TODO: Look into if these locks are a perf loss
		{
			lock_guard guard(input_state.lock);

			input_state.pad_lstick_x = left_joystick_x_async;
			input_state.pad_lstick_y = left_joystick_y_async;
			input_state.pad_rstick_x = right_joystick_x_async;
			input_state.pad_rstick_y = right_joystick_y_async;

			UpdateInputState(&input_state);
		}
		NativeUpdate(input_state);

		{
			lock_guard guard(input_state.lock);
			EndInputState(&input_state);
		}

		NativeRender();
		time_update();

		gl->Swap();

		lock_guard guard(frameCommandLock);
		while (!frameCommands.empty()) {
			FrameCommand frameCmd;
			frameCmd = frameCommands.front();
			frameCommands.pop();

			WLOG("frameCommand! '%s' '%s'", frameCmd.command.c_str(), frameCmd.params.c_str());

			jstring cmd = env->NewStringUTF(frameCmd.command.c_str());
			jstring param = env->NewStringUTF(frameCmd.params.c_str());
			env->CallVoidMethod(nativeActivity, postCommand, cmd, param);
			env->DeleteLocalRef(cmd);
			env->DeleteLocalRef(param);
		}
	}

	// Restore lost device objects. TODO: This feels like the wrong place for this.
	NativeDeviceLost();
	ILOG("NativeDeviceLost completed.");

	NativeShutdownGraphics();
	renderer_inited = false;

	gl->ClearCurrent();
	delete gl;

	ANativeWindow_release(wnd);
	renderLoopRunning = false;
	WLOG("Render loop exited;");
	return true;
}