第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

glfw 拖動窗口最初在 macOS 上是滯后的

glfw 拖動窗口最初在 macOS 上是滯后的

Go
拉風(fēng)的咖菲貓 2022-07-11 15:13:11
我剛剛使用 glfw 創(chuàng)建了一個窗口并在 macOS 上運(yùn)行。問題是:如果我拖動窗口并四處移動,窗口的移動最初是超級滯后的,但后來變得平滑。Linux (Ubuntu) 上不會出現(xiàn)此問題。為什么以及如何解決它?系統(tǒng):macOS 10.15.7 (19H2) 代碼:package mainimport (    "fmt"    "runtime"    "github.com/go-gl/gl/v4.1-core/gl"    "github.com/go-gl/glfw/v3.3/glfw")func init() {    runtime.LockOSThread()}func main() {    err := glfw.Init()    if err != nil {        panic(fmt.Errorf("failed to initialize GLFW: %w", err))    }    defer glfw.Terminate()    glfw.WindowHint(glfw.Resizable, glfw.False)    glfw.WindowHint(glfw.ContextVersionMajor, 4)    glfw.WindowHint(glfw.ContextVersionMinor, 1)    glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)    glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)    win, err := glfw.CreateWindow(800, 600, "glfw", nil, nil)    if err != nil {        panic(err)    }    defer win.Destroy()    win.MakeContextCurrent()    if err := gl.Init(); err != nil {        panic(err)    }    win.SetTitle(fmt.Sprintf("%s", gl.GoStr(gl.GetString(gl.VERSION))))    gl.ClearColor(1.0, 1.0, 1.0, 1.0)    for !win.ShouldClose() {        gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)        win.SwapBuffers()        glfw.PollEvents()    }}
查看完整描述

1 回答

?
拉丁的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個贊

這個問題與 Go 無關(guān)。用 C 編寫的示例也重現(xiàn)了該問題:


#include <GLFW/glfw3.h>


int main(void)

{

    GLFWwindow* window;


    /* Initialize the library */

    if (!glfwInit())

        return -1;


    /* Create a windowed mode window and its OpenGL context */

    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);

    if (!window)

    {

        glfwTerminate();

        return -1;

    }


    /* Make the window's context current */

    glfwMakeContextCurrent(window);


    /* Loop until the user closes the window */

    while (!glfwWindowShouldClose(window))

    {

        /* Render here */

        glClear(GL_COLOR_BUFFER_BIT);


        /* Swap front and back buffers */

        glfwSwapBuffers(window);


        /* Poll for and process events */

        glfwPollEvents();

    }


    glfwTerminate();

    return 0;

}

簡短的回答是:glfwWaitEvents在 macOS 上使用。


長答案是 glfwPollEvents 處理事件(如果有)。否則,它會立即返回。這意味著(微不足道的)程序正在盡可能快地一遍又一遍地清除屏幕,消耗大量的 CPU 時間。替代方案 glfwWaitEvents 在沒有事件等待時阻塞,消耗很少或不消耗 CPU 時間??梢哉f,使用大量 CPU 的程序不應(yīng)導(dǎo)致窗口滯后,但這實(shí)際上取決于操作系統(tǒng)及其分配資源的方式。


至于使用這兩個函數(shù)中的哪一個,完全取決于我們還想讓我們的程序做什么。如果我們只想對用戶輸入做出反應(yīng)而沒有別的,glfwWaitEvents 可能是要走的路。如果我們想在事件循環(huán)中做其他事情,glfwPollEvents 可能更合適,特別是如果我們想獨(dú)立于用戶輸入重繪窗口內(nèi)容。


另外:glfwSwapInterval(1) 也可能會避免延遲,因?yàn)樗鼤?dǎo)致 glfwSwapBuffers 阻塞幾毫秒,再次讓 CPU 休息。


查看完整回答
反對 回復(fù) 2022-07-11
  • 1 回答
  • 0 關(guān)注
  • 184 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號