Пример #1
0
bool OpenGLContext::MakeContextCurrent()
{
    CCLOG("OpenGLContext::MakeContextCurrent %dx%d",
          _size.width(), _size.height());

    // Lazily create the Pepper context.
    if (_graphics3d.is_null())
    {
        int32_t attribs[] = {
            PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
            PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
            PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
            PP_GRAPHICS3DATTRIB_SAMPLES, 0,
            PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
            PP_GRAPHICS3DATTRIB_WIDTH, _size.width(),
            PP_GRAPHICS3DATTRIB_HEIGHT, _size.height(),
            PP_GRAPHICS3DATTRIB_NONE
        };
        _graphics3d = pp::Graphics3D(_instance, pp::Graphics3D(), attribs);
        if (_graphics3d.is_null())
        {
            glSetCurrentContextPPAPI(0);
            return false;
        }
        bool rtn = _instance->BindGraphics(_graphics3d);
        assert(rtn && "BindGraphics failed");
        if (!rtn)
          return false;
    }

    CCLOG("glSetCurrentContextPPAPI: %p", (void*)_graphics3d.pp_resource());
    glSetCurrentContextPPAPI(_graphics3d.pp_resource());
    return true;
}
void eUSPInstance::Draw()
{
	if(!inited || !gl_context)
		return;
	gl_context->MakeCurrent(this);
	gles2->Draw(size.width(), size.height());
	gl_context->Flush();
}
Пример #3
0
void OpenGLContext::ResizeContext(const pp::Size& size)
{
    m_Size = size;
    if( !m_Context.is_null() )
    {
        m_Context.ResizeBuffers( size.width(), size.height() );
    }
}
Пример #4
0
void OpenGLContext::ResizeContext(const pp::Size& size) {

	width = size.width();
	height = size.height();

	if (!context_.is_null()) {
		context_.ResizeBuffers(size.width(), size.height());
	}
}
Пример #5
0
/// Resize the context.
void OpenGLContext::ResizeContext(const pp::Size& size)
{
MFDebug_Message("ogl: resize");
	size_ = size;
	if(!context_.is_null())
	{
		context_.ResizeBuffers(size.width(), size.height());
MFDebug_Message("ogl: resized");
	}
}
Пример #6
0
void OpenGLContext::ResizeContext(int width, int height)
{
    CCLOG("OpenGLContext::ResizeContext %dx%d", width, height);
    _size.SetSize(width, height);
    if (!_graphics3d.is_null())
    {
        _graphics3d.ResizeBuffers(width, height);
    }
}
Пример #7
0
bool eUSPInstance::HandleInputEvent(const pp::InputEvent& ev)
{
	switch(ev.GetType())
	{
	case PP_INPUTEVENT_TYPE_KEYDOWN:
		{
			pp::KeyboardInputEvent event(ev);
			if(SpecialKeyDown(event))
				return true;
			int key = event.GetKeyCode();
			dword flags = KF_DOWN|OpJoyKeyFlags();
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_ALTKEY)		flags |= KF_ALT;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_SHIFTKEY)	flags |= KF_SHIFT;
			TranslateKey(key, flags);
			if(key || flags)
			{
				Handler()->OnKey(key, flags);
				return true;
			}
		}
		break;
	case PP_INPUTEVENT_TYPE_KEYUP:
		{
			pp::KeyboardInputEvent event(ev);
			int key = event.GetKeyCode();
			dword flags = 0;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_ALTKEY)		flags |= KF_ALT;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_SHIFTKEY)	flags |= KF_SHIFT;
			TranslateKey(key, flags);
			if(key || flags)
			{
				Handler()->OnKey(key, OpJoyKeyFlags());
				return true;
			}
		}
		break;
	case PP_INPUTEVENT_TYPE_MOUSEMOVE:
		if(mouse_locked)
		{
			pp::MouseInputEvent event(ev);
			float z = OpZoom();
			float sx, sy;
			GetScaleWithAspectRatio43(&sx, &sy, size.width(), size.height());
			float scale_x = 320.0f/size.width()/sx/z;
			float scale_y = 240.0f/size.height()/sy/z;
			mouse_delta += eMouseDelta(event.GetMovement(), scale_x, scale_y);
			int dx = mouse_delta.x;
			int dy = mouse_delta.y;
			if(dx || dy)
			{
				mouse_delta.x -= dx;
				mouse_delta.y -= dy;
				Handler()->OnMouse(MA_MOVE, dx, -dy);
			}
			return true;
		}
		break;
	case PP_INPUTEVENT_TYPE_MOUSEDOWN:
		if(!mouse_locked)
		{
			LockMouse(callback.NewCallback(&eUSPInstance::DidLockMouse));
		}
		//no break
	case PP_INPUTEVENT_TYPE_MOUSEUP:
		if(mouse_locked)
		{
			pp::MouseInputEvent event(ev);
			Handler()->OnMouse(MA_BUTTON, event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT, ev.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN);
			return true;
		}
		break;
	default:
		break;
	}
	return false;
}