示例#1
0
int imguiInit(uint16_t viewWidth, uint16_t viewHeight)
{
    if (gIm) {
        assert(false);
        return -1;
    }

    BX_BEGINP("Initializing ImGui Integration");

    bx::AllocatorI* alloc = &gAlloc;
    gIm = BX_NEW(alloc, ImGuiImpl);
    if (!gIm) {
        BX_END_FATAL();
        return -2;
    }
    gIm->alloc = alloc;
    VertexPosCoordColor::init();

    // Create Graphic objects
    bgfx::ShaderHandle fragmentShader = bgfx::createShader(bgfx::makeRef(imgui_fsb_h, sizeof(imgui_fsb_h)));
	if (!IS_VALID(fragmentShader)) {
        BX_END_FATAL();
		BX_FATAL("Creating fragment-shader failed");
        return -1;
    }

	bgfx::ShaderHandle vertexShader = bgfx::createShader(bgfx::makeRef(imgui_vsb_h, sizeof(imgui_vsb_h)));
	if (!IS_VALID(vertexShader)) {
        BX_END_FATAL();
		BX_FATAL("Creating vertex-shader failed");
        return -1;
    }

    gIm->progHandle = bgfx::createProgram(vertexShader, fragmentShader, true);
	if (!IS_VALID(gIm->progHandle)) {
        BX_END_FATAL();
		BX_FATAL("Creating GPU Program failed");
        return -1;
    }
    gIm->uniformTexture = bgfx::createUniform("u_texture", bgfx::UniformType::Int1);

    gIm->vertexBuffer = bgfx::createDynamicVertexBuffer(MAX_VERTICES, VertexPosCoordColor::Decl);
    gIm->indexBuffer = bgfx::createDynamicIndexBuffer(MAX_INDICES);
	if (!IS_VALID(gIm->vertexBuffer) || !IS_VALID(gIm->indexBuffer)) {
		BX_END_FATAL();
		BX_FATAL("Creating GPU VertexBuffer failed");
		return -1;
	}

    // Setup ImGui
    ImGuiIO& conf = ImGui::GetIO();
    conf.DisplaySize = ImVec2((float)viewWidth, (float)viewHeight);
    conf.RenderDrawListsFn = imguiDrawLists;
    conf.MemAllocFn = imguiAlloc;
    conf.MemFreeFn = imguiFree;

    conf.KeyMap[ImGuiKey_Tab] = SDLK_TAB;
    conf.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT;
    conf.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT;
    conf.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP;
    conf.KeyMap[ImGuiKey_DownArrow] = SDL_SCANCODE_DOWN;
    conf.KeyMap[ImGuiKey_Home] = SDL_SCANCODE_HOME;
    conf.KeyMap[ImGuiKey_End] = SDL_SCANCODE_END;
	conf.KeyMap[ImGuiKey_Delete] = SDLK_DELETE;
	conf.KeyMap[ImGuiKey_Backspace] = SDLK_BACKSPACE;
    conf.KeyMap[ImGuiKey_Enter] = SDLK_RETURN;
    conf.KeyMap[ImGuiKey_Escape] = SDLK_ESCAPE;
    conf.KeyMap[ImGuiKey_A] = SDLK_a;
    conf.KeyMap[ImGuiKey_C] = SDLK_c;
    conf.KeyMap[ImGuiKey_V] = SDLK_v;
    conf.KeyMap[ImGuiKey_X] = SDLK_x;
    conf.KeyMap[ImGuiKey_Y] = SDLK_y;
    conf.KeyMap[ImGuiKey_Z] = SDLK_z;

    uint8_t* fontData;
    int fontWidth, fontHeight, bpp;
    conf.Fonts->GetTexDataAsAlpha8(&fontData, &fontWidth, &fontHeight, &bpp);

	gIm->fontTexHandle = bgfx::createTexture2D((uint16_t)fontWidth, (uint16_t)fontHeight, 1, bgfx::TextureFormat::A8,
		BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT,
		bgfx::makeRef(fontData, fontWidth*fontHeight*bpp));
	if (!IS_VALID(gIm->fontTexHandle)) {
        BX_END_FATAL();
		BX_FATAL("ImGui: Could not create font texture");
        return -1;
    }
    conf.Fonts->TexID = (void*)&gIm->fontTexHandle;

	ImGui::GetStyle().AntiAliasedLines = false;

    ImGui::NewFrame();

    BX_END_OK();
    return 0;
}
示例#2
0
	SwapChainGL* GlContext::createSwapChain(void* _nwh)
	{
		return BX_NEW(g_allocator, SwapChainGL)( (::Window)_nwh, m_visualInfo, m_context);
	}
示例#3
0
	SwapChainGL* GlContext::createSwapChain(void* _nwh)
	{
		return BX_NEW(g_allocator, SwapChainGL)(m_display, m_config, m_context, (EGLNativeWindowType)_nwh);
	}