加速嵌套循环绘制

问题描述 投票:0回答:0

我有这个代码:

/* extract single color component from hexadecimal color */
uint8_t ext_col(uint32_t value, int color) {
    return (value >> (color * 8)) & 0xff;
}

glBegin(GL_POINTS);

for (uint16_t y = 0; y < image->height; y+=1) {
    for (uint16_t x = 0; x < image->width; x+=1) {
    uint32_t p = image->data[y * image->width + x]; /* get pixel data */
            
        glColor3ub(
            ext_col(p, 0),  /* red */
            ext_col(p, 1),  /* green */
            ext_col(p, 2)); /* blue */
        glVertex2i(x, y);
    }
}

glEnd();

它工作正常,但有点慢,是否有进一步加快速度的方法,也许是一些组装技巧?

这是我对之前的实例进行的最优化(快 5 倍),但它仍然以低于 60 fps 的速度渲染 750x350 图像。

c nested glut freeglut
© www.soinside.com 2019 - 2024. All rights reserved.