为什么仅当我在 SDL2 中设置非零 Alpha 大小时才获得 sRGB 帧缓冲区?

2024-03-31

我正在尝试通过以下方式以伽玛正确的方式渲染典型的 OpenGL 颜色三角形本指南 https://learnopengl.com/#!Advanced-Lighting/Gamma-Correction并查阅 SDL2 文档,了解如何在默认帧缓冲区上启用 SRGB 支持。

这是我编写的绘制三角形的代码:

#include <SDL.h>

// Header file generated with glLoadGen
#include "gl_core_3_3.h"

#include <cstdlib>

void sdl_loop(SDL_Window* window);

static const char* const vertexSource = R"(
#version 330

in vec2 position;
in vec3 color;

out vec3 vs_color;

void main()
{
    gl_Position = vec4(position, 0.0, 1.0);
    vs_color = color;
}
)";

static const char* const fragmentSource = R"(
#version 330

in vec3 vs_color;
out vec4 fragColor;

void main()
{
    fragColor = vec4(vs_color, 1.0);
}
)";

static const float vertices[] = {
    // X    Y     R     G     B
    -0.9f, -0.9f, 1.0f, 0.0f, 0.0f,
    0.9f, -0.9f, 0.0f, 1.0f, 0.0f,
    0.0f,  0.9f, 0.0f, 0.0f, 1.0f,
};

static const unsigned short indices[] = { 0, 1, 2 };

void sdl_loop(SDL_Window* window)
{
    glClearColor(0.0f, 0.1f, 0.2f, 1.0f);

    glEnable(GL_FRAMEBUFFER_SRGB);

    auto program = glCreateProgram();
    auto vertexShader = glCreateShader(GL_VERTEX_SHADER);
    auto fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

    glShaderSource(vertexShader, 1, &vertexSource, nullptr);
    glShaderSource(fragmentShader, 1, &fragmentSource, nullptr);

    glCompileShader(vertexShader);
    glCompileShader(fragmentShader);

    glAttachShader(program, vertexShader);
    glAttachShader(program, fragmentShader);

    glBindFragDataLocation(program, 0, "fragColor");

    glLinkProgram(program);

    glDetachShader(program, vertexShader);
    glDetachShader(program, fragmentShader);

    glDeleteShader(vertexShader);
    glDeleteShader(fragmentShader);

    auto positionAttr = glGetAttribLocation(program, "position");
    auto colorAttr = glGetAttribLocation(program, "color");

    unsigned vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    unsigned vertexBuffer;
    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    unsigned indexBuffer;
    glGenBuffers(1, &indexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

    size_t stride = 5 * sizeof(float);
    size_t offset = 0;
    glEnableVertexAttribArray(positionAttr);
    glVertexAttribPointer(positionAttr, 2, GL_FLOAT, false, stride, (void*) offset);
    offset += 2 * sizeof(float);

    glEnableVertexAttribArray(colorAttr);
    glVertexAttribPointer(colorAttr, 3, GL_FLOAT, false, stride, (void*) offset);
    offset += 3 * sizeof(float);

    glUseProgram(program);

    SDL_Event evt;
    for (;;) {
        while (SDL_PollEvent(&evt)) {
            if (evt.type == SDL_QUIT) {
                goto out;
            }
        }

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

        glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, nullptr);

        SDL_GL_SwapWindow(window);
    }

out:
    glDeleteProgram(program);
    glDeleteBuffers(1, &vertexBuffer);
    glDeleteBuffers(1, &indexBuffer);
    glDeleteVertexArrays(1, &vao);
}

int main()
{
    if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
                     "Couldn't initialize SDL: %s", SDL_GetError());
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                                 "Couldn't initialize SDL", SDL_GetError(), nullptr);
        return EXIT_FAILURE;
    }

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8);

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    // Commenting this line out doesn't give you an sRGB framebuffer on Intel GPUs
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
    SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);

    auto* window = SDL_CreateWindow("Hello OpenGL 3!",
                                    SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                    800, 600,
                                    SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);

    if (window == nullptr) {
        SDL_LogError(
            SDL_LOG_CATEGORY_APPLICATION,
            "Couldn't initialize SDL window: %s", SDL_GetError());
        SDL_ShowSimpleMessageBox(
            SDL_MESSAGEBOX_ERROR,
            "Couldn't create SDL window", SDL_GetError(), nullptr);
        return EXIT_FAILURE;
    }

    auto context = SDL_GL_CreateContext(window);
    SDL_GL_MakeCurrent(window, context);
    SDL_GL_SetSwapInterval(1);

    ogl_LoadFunctions();

    sdl_loop(window);

    SDL_GL_DeleteContext(context);
    SDL_DestroyWindow(window);

    SDL_Quit();

    return EXIT_SUCCESS;
}

我在 Ubuntu 16.04(带有 HWE 驱动程序)上运行,我使用的机器既有 Intel HD 4000 GPU 又有带有 Optimus 的专用 nvidia GPU。理论上,我应该得到一个 sRGB 帧缓冲区。但是,只有在 nvidia GPU 下运行或使用 ApiTrace 时,我才会获得 sRGB 帧缓冲区。如果我在 Intel GPU 下运行,如果我使用 SDL2 指定非零 alpha 大小,我只会获得 sRGB 帧缓冲区。如果我为 Alpha 指定零大小(或者根本不指定大小),我将得到一个线性帧缓冲区。

This is how my example looks when running under the nvidia GPU (and the Intel GPU with a non-zero alpha bit size): nvidia GPU and Intel GPU with non-zero alpha bit size

This is how it looks when running under the Intel GPU with a zero alpha bit size (sRGB incorrect): Intel GPU with zero alpha bit size

And this is what I get with ApiTrace: ApiTrace

我也跑了glxinfo -t据我所知,即使设置了零 alpha 位,我也应该获得 sRGB 支持(EDIT: 事实并非如此。的输出glxinfo应该显示ses 在 sRGB 列中,但由于某种原因不会发生):

40 GLX Visuals
Vis   Vis   Visual Trans  buff lev render DB ste  r   g   b   a      s  aux dep ste  accum buffer   MS   MS         
 ID  Depth   Type  parent size el   type     reo sz  sz  sz  sz flt rgb buf th  ncl  r   g   b   a  num bufs caveats
--------------------------------------------------------------------------------------------------------------------
0x 21 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x 22 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x b7 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   0   0   None
0x b8 24 TrueColor    0     32  0  rgba   0   0   8   8   8   8  .   .   0    0  0   0   0   0   0   0   0   None
0x b9 24 TrueColor    0     32  0  rgba   0   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x ba 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   0   0   None
0x bb 24 TrueColor    0     24  0  rgba   0   0   8   8   8   0  .   .   0    0  0   0   0   0   0   0   0   None
0x bc 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x bd 24 TrueColor    0     24  0  rgba   0   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x be 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8  16  16  16  16   0   0   Slow
0x bf 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x c0 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8  16  16  16   0   0   0   Slow
0x c1 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   4   1   None
0x c2 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   8   1   None
0x c3 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   4   1   None
0x c4 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   8   1   None
0x c5 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   4   1   None
0x c6 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   8   1   None
0x c7 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   4   1   None
0x c8 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   8   1   None
0x c9 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   0   0   None
0x ca 24 DirectColor  0     32  0  rgba   0   0   8   8   8   8  .   .   0    0  0   0   0   0   0   0   0   None
0x cb 24 DirectColor  0     32  0  rgba   0   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x cc 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   0   0   None
0x cd 24 DirectColor  0     24  0  rgba   0   0   8   8   8   0  .   .   0    0  0   0   0   0   0   0   0   None
0x ce 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x cf 24 DirectColor  0     24  0  rgba   0   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x d0 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x d1 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8  16  16  16  16   0   0   Slow
0x d2 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x d3 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8  16  16  16   0   0   0   Slow
0x d4 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   4   1   None
0x d5 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   8   1   None
0x d6 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   4   1   None
0x d7 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   8   1   None
0x d8 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   4   1   None
0x d9 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   8   1   None
0x da 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   4   1   None
0x db 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   8   1   None
0x 76 32 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None

64 GLXFBConfigs:
Vis   Vis   Visual Trans  buff lev render DB ste  r   g   b   a      s  aux dep ste  accum buffer   MS   MS         
 ID  Depth   Type  parent size el   type     reo sz  sz  sz  sz flt rgb buf th  ncl  r   g   b   a  num bufs caveats
--------------------------------------------------------------------------------------------------------------------
0x 77  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0    0  0   0   0   0   0   0   0   None
0x 78  0 TrueColor    0     16  0  rgba   0   0   5   6   5   0  .   .   0    0  0   0   0   0   0   0   0   None
0x 79  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0   0   0   0   0   0   0   None
0x 7a  0 TrueColor    0     16  0  rgba   0   0   5   6   5   0  .   .   0   16  0   0   0   0   0   0   0   None
0x 7b  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0   24  8   0   0   0   0   0   0   None
0x 7c  0 TrueColor    0     16  0  rgba   0   0   5   6   5   0  .   .   0   24  8   0   0   0   0   0   0   None
0x 7d 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   0   0   None
0x 7e 24 TrueColor    0     32  0  rgba   0   0   8   8   8   8  .   .   0    0  0   0   0   0   0   0   0   None
0x 7f 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x 80 24 TrueColor    0     32  0  rgba   0   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x 81 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   0   0   None
0x 82 24 TrueColor    0     24  0  rgba   0   0   8   8   8   0  .   .   0    0  0   0   0   0   0   0   0   None
0x 83 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x 84 24 TrueColor    0     24  0  rgba   0   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x 85  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0   0   0   0   0   0   0   None
0x 86  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0  16  16  16   0   0   0   Slow
0x 87 32 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x 88 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8  16  16  16  16   0   0   Slow
0x 89 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x 8a 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8  16  16  16   0   0   0   Slow
0x 8b  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0    0  0   0   0   0   0   4   1   None
0x 8c  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0    0  0   0   0   0   0   8   1   None
0x 8d  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0   0   0   0   0   4   1   None
0x 8e  0 TrueColor    0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0   0   0   0   0   8   1   None
0x 8f 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   4   1   None
0x 90 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   8   1   None
0x 91 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   4   1   None
0x 92 24 TrueColor    0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   8   1   None
0x 93 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   4   1   None
0x 94 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   8   1   None
0x 95 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   4   1   None
0x 96 24 TrueColor    0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   8   1   None
0x 97  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0    0  0   0   0   0   0   0   0   None
0x 98  0 DirectColor  0     16  0  rgba   0   0   5   6   5   0  .   .   0    0  0   0   0   0   0   0   0   None
0x 99  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0   0   0   0   0   0   0   None
0x 9a  0 DirectColor  0     16  0  rgba   0   0   5   6   5   0  .   .   0   16  0   0   0   0   0   0   0   None
0x 9b  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0   24  8   0   0   0   0   0   0   None
0x 9c  0 DirectColor  0     16  0  rgba   0   0   5   6   5   0  .   .   0   24  8   0   0   0   0   0   0   None
0x 9d 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   0   0   None
0x 9e 24 DirectColor  0     32  0  rgba   0   0   8   8   8   8  .   .   0    0  0   0   0   0   0   0   0   None
0x 9f 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x a0 24 DirectColor  0     32  0  rgba   0   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x a1 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   0   0   None
0x a2 24 DirectColor  0     24  0  rgba   0   0   8   8   8   0  .   .   0    0  0   0   0   0   0   0   0   None
0x a3 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x a4 24 DirectColor  0     24  0  rgba   0   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x a5  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0   0   0   0   0   0   0   None
0x a6  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0  16  16  16   0   0   0   Slow
0x a7 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   0   0   None
0x a8 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8  16  16  16  16   0   0   Slow
0x a9 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   0   0   None
0x aa 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8  16  16  16   0   0   0   Slow
0x ab  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0    0  0   0   0   0   0   4   1   None
0x ac  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0    0  0   0   0   0   0   8   1   None
0x ad  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0   0   0   0   0   4   1   None
0x ae  0 DirectColor  0     16  0  rgba   1   0   5   6   5   0  .   .   0   16  0   0   0   0   0   8   1   None
0x af 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   4   1   None
0x b0 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0    0  0   0   0   0   0   8   1   None
0x b1 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   4   1   None
0x b2 24 DirectColor  0     32  0  rgba   1   0   8   8   8   8  .   .   0   24  8   0   0   0   0   8   1   None
0x b3 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   4   1   None
0x b4 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0    0  0   0   0   0   0   8   1   None
0x b5 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   4   1   None
0x b6 24 DirectColor  0     24  0  rgba   1   0   8   8   8   0  .   .   0   24  8   0   0   0   0   8   1   None

在这种情况下,为什么我没有获得 sRGB 帧缓冲区?我是否可能遇到了英特尔驱动程序错误?


显然罪魁祸首是this bug https://bugs.freedesktop.org/show_bug.cgi?id=92759在 Intel Mesa 驱动程序中(感谢 SO 用户 genpfault 在 freedesktop bugzilla 中找到它)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么仅当我在 SDL2 中设置非零 Alpha 大小时才获得 sRGB 帧缓冲区? 的相关文章

  • 结构化绑定中缺少类型信息

    我刚刚了解了 C 中的结构化绑定 但有一件事我不喜欢 auto x y some func is that auto正在隐藏类型x and y 我得抬头看看some func的声明来了解类型x and y 或者 我可以写 T1 x T2 y
  • 如何将 std::string& 转换为 C# 引用字符串

    我正在尝试将 C 函数转换为std string参考C 我的 API 如下所示 void GetStringDemo std string str 理想情况下 我希望在 C 中看到类似的东西 void GetStringDemoWrap r
  • C++11 删除重写方法

    Preface 这是一个关于最佳实践的问题 涉及 C 11 中引入的删除运算符的新含义 当应用于覆盖继承父类的虚拟方法的子类时 背景 根据标准 引用的第一个用例是明确禁止调用某些类型的函数 否则转换将是隐式的 例如最新版本第 8 4 3 节
  • free 和 malloc 在 C 中如何工作?

    我试图弄清楚如果我尝试 从中间 释放指针会发生什么 例如 看下面的代码 char ptr char malloc 10 sizeof char for char i 0 i lt 10 i ptr i i 10 ptr ptr ptr pt
  • 传递给函数时多维数组的指针类型是什么? [复制]

    这个问题在这里已经有答案了 我在大学课堂上学习了 C 语言和指针 除了多维数组和指针之间的相似性之外 我认为我已经很好地掌握了这个概念 我认为由于所有数组 甚至多维 都存储在连续内存中 因此您可以安全地将其转换为int 假设给定的数组是in
  • 从经典 ASP 调用 .Net C# DLL 方法

    我正在开发一个经典的 asp 项目 该项目需要将字符串发送到 DLL DLL 会将其序列化并发送到 Zebra 热敏打印机 我已经构建了我的 DLL 并使用它注册了regasm其次是 代码库这使得 IIS 能够识别它 虽然我可以设置我的对象
  • -webkit-box-shadow 与 QtWebKit 模糊?

    当时有什么方法可以实现 webkit box shadow 的工作模糊吗 看完这篇评论错误报告 https bugs webkit org show bug cgi id 23291 我认识到这仍然是一个问题 尽管错误报告被标记为RESOL
  • 无限循环与无限递归。两者都是未定义的吗?

    无副作用的无限循环是未定义的行为 看here https coliru stacked crooked com view id 24e0a58778f67cd4举个例子参考参数 https en cppreference com w cpp
  • 对类 static constexpr 结构的未定义引用,g++ 与 clang

    这是我的代码 a cp p struct int2 int x y struct Foo static constexpr int bar1 1 static constexpr int2 bar2 1 2 int foo1 return
  • 为什么这个字符串用AesCryptoServiceProvider第二次解密时不相等?

    我在 C VS2012 NET 4 5 中的文本加密和解密方面遇到问题 具体来说 当我加密并随后解密字符串时 输出与输入不同 然而 奇怪的是 如果我复制加密的输出并将其硬编码为字符串文字 解密就会起作用 以下代码示例说明了该问题 我究竟做错
  • 为什么 C# 2.0 之后没有 ISO 或 ECMA 标准化?

    我已经开始学习 C 并正在寻找标准规范 但发现大于 2 0 的 C 版本并未由 ISO 或 ECMA 标准化 或者是我从 Wikipedia 收集到的 这有什么原因吗 因为编写 审查 验证 发布 处理反馈 修订 重新发布等复杂的规范文档需要
  • C# xml序列化必填字段

    我需要将一些字段标记为需要写入 XML 文件 但没有成功 我有一个包含约 30 个属性的配置类 这就是为什么我不能像这样封装所有属性 public string SomeProp get return someProp set if som
  • 如何在当前 Visual Studio 主机内的 Visual Studio 扩展中调试使用 Roslyn 编译的代码?

    我有一个 Visual Studio 扩展 它使用 Roslyn 获取当前打开的解决方案中的项目 编译它并从中运行方法 程序员可以修改该项目 我已从当前 VisualStudioWorkspace 成功编译了 Visual Studio 扩
  • 在 WPF 中使用 ReactiveUI 提供长时间运行命令反馈的正确方法

    我有一个 C WPF NET 4 5 应用程序 用户将用它来打开某些文件 然后 应用程序将经历很多动作 读取文件 通过许多插件和解析器传递它 这些文件可能相当大 gt 100MB 因此这可能需要一段时间 我想让用户了解 UI 中发生的情况
  • C# 中的 IPC 机制 - 用法和最佳实践

    不久前我在 Win32 代码中使用了 IPC 临界区 事件和信号量 NET环境下场景如何 是否有任何教程解释所有可用选项以及何时使用以及为什么 微软最近在IPC方面的东西是Windows 通信基础 http en wikipedia org
  • C# 中最小化字符串长度

    我想减少字符串的长度 喜欢 这串 string foo Lorem ipsum dolor sit amet consectetur adipiscing elit Aenean in vehicula nulla Phasellus li
  • DotNetZip:如何提取文件,但忽略zip文件中的路径?

    尝试将文件提取到给定文件夹 忽略 zip 文件中的路径 但似乎没有办法 考虑到其中实现的所有其他好东西 这似乎是一个相当基本的要求 我缺少什么 代码是 using Ionic Zip ZipFile zf Ionic Zip ZipFile
  • 在OpenGL中,我可以在坐标(5, 5)处精确地绘制一个像素吗?

    我所说的 5 5 正是指第五行第五列 我发现使用屏幕坐标来绘制东西非常困难 OpenGL 中的所有坐标都是相对的 通常范围从 1 0 到 1 0 为什么阻止程序员使用屏幕坐标 窗口坐标如此严重 最简单的方法可能是通过以下方式设置投影以匹配渲
  • 指针和内存范围

    我已经用 C 语言编程有一段时间了 但对 C 语言还是很陌生 有时我对 C 处理内存的方式感到困惑 考虑以下有效的 C 代码片段 const char string void where is this pointer variable l
  • Mono 应用程序在非阻塞套接字发送时冻结

    我在 debian 9 上的 mono 下运行一个服务器应用程序 大约有 1000 2000 个客户端连接 并且应用程序经常冻结 CPU 使用率达到 100 我执行 kill QUIT pid 来获取线程堆栈转储 但它总是卡在这个位置

随机推荐

  • 使用希伯来数字自定义
      编号

    我想要一个使用希伯来字母数字的编号列表 就像希伯来语书籍中常见的那样 拉丁语表示法使用数字 0 9 而希伯来语则按字母顺序编号 但有时值会发生变化 我不知道这在 CSS 中是否可行 但也许在 JavaScript 中可行 我基本上想要这样的
  • Selenium webdriver 无法点击页面外的链接

    我在使用 Selenium WebDriver 时遇到问题 我尝试单击窗口页面外部的链接 您需要向上滚动才能看到它 我当前的代码相当标准 menuItem driver findElement By id MTP menuItem clic
  • 无法更改 iTunes Connect 中的主要语言

    我已向 App Store 提交了我的第一个应用程序 不幸的是 我注意到主要语言设置为德语而不是英语 我尝试更改主要语言 但出现错误 为了将此应用程序的主要语言更改为英语 美国 每个版本必须已经具有所需的英语 美国 屏幕截图 但我已经上传了
  • 如何在另一个应用程序中使用一个 gwt 应用程序的源代码

    我有两个不同的 gwt 项目 并且想要在另一个模块中使用一个 gwt 应用程序的类 有什么办法可以做到这一点吗 我遵循以下方法 在第二个项目中添加了以下两行
  • 我应该使用公共变量还是私有变量?

    我第一次做一个大型项目 我有很多类 其中一些具有公共变量 一些具有带有 setter 和 getter 方法的私有变量 并且相同具有两种类型 我决定重写此代码以主要仅使用一种类型 但我不知道应该使用哪个 仅用于同一对象中的方法的变量始终是私
  • Visual Studio 2005/2012:如何将第一个花括号保持在同一行?

    尝试让我的 css C 函数看起来像这样 body color 222 而不是这个 body color 222 当我自动格式化代码时 C In the Tools菜单点击Options Click 显示所有参数 左下角的复选框 显示所有设
  • 使用 C# 按创建日期降序获取目录中的文件列表

    我想使用 C 获取按创建日期排序的文件夹中的文件列表 我正在使用以下代码 if Directory Exists folderpath DirectoryInfo dir new DirectoryInfo folderpath FileI
  • URL 问号后面的部分是什么术语?

    http www example com foo 该术语是什么foo网址的一部分 这是query 或者有时请求参数 从中捏取有用的图表URI RFC https datatracker ietf org doc html rfc3986 s
  • lua检查多个值是否相等

    我喜欢用 Roblox 制作游戏 并用 lua 编写代码 在编写游戏时 我发现自己经常问一个值是否等于另一个值 这可能会产生很长的代码行 并且可能非常重复 例如 如果 x ClassName 衬衫 或x ClassName 附件 或x Cl
  • (转)发送http请求时如何控制gzip压缩?

    我想问一下大家在请求HTTP Post消息时如何控制gzip压缩 Accept Encoding gzip 作为 Http 请求标头始终添加到我发送的 http 请求中 但我不想使用 gzip 压缩 我该如何处理 在执行http NewRe
  • 在onPause而不是onDestroy中释放资源

    这是关于后蜂窝状 即Android 3 0 以及下面的引用来自https developer android com reference android app Activity html https developer android c
  • Rails 应用程序错误 - ActiveRecord::PendingMigrationError 迁移正在挂起;运行“rake db:migrate RAILS_ENV=development”来解决此问题

    数据库已创建 表已创建 数据已存在 但是当我重新启动Rails应用程序后 我收到了这个错误 该应用程序正在使用 MySQL 这里有什么问题 先感谢您 Solution 只需运行 rake db migrate 在服务器启动之前需要运行一些迁
  • 如何向java简单日期格式添加天数

    如何在使用简单日期格式获得的当前日期上添加 120 天 我看过一些关于它的帖子 但无法让它发挥作用 我的代码如下 SimpleDateFormat dateFormat new SimpleDateFormat dd MM yyyy get
  • 使用 JavaScript 打开另一个 html 页面时传递变量

    这可能是一个非常愚蠢的问题 但我在网上找不到它 而且我已经寻找了至少一个小时 我有一个链接 a href MusicMe html Instruments a 我想在单击后获取它的 ID 因为我需要将一些变量传递到我打开的页面以知道仪器链接
  • 2 个 2D 向量的叉积

    任何人都可以提供一个返回叉积的函数的示例TWO二维向量 我正在尝试实施这个算法 http www blackpawn com texts pointinpoly default html C 代码会很棒 谢谢 EDIT 找到了另一种适用于
  • 查找 NxN 网格中所有路径的算法

    想象一个机器人坐在 NxN 网格的左上角 机器人只能向两个方向移动 向右和向下 机器人有多少种可能的路径 我可以在谷歌上找到这个问题的解决方案 但我对解释不是很清楚 我试图清楚地理解如何解决这个问题并用Java实现的逻辑 任何帮助表示赞赏
  • Android 自定义视图应扩展 AppCompatTextView

    我创建了简单的自定义视图 它扩展自TextView 在 Android Studio 中我收到此警告 This custom view should extend android support v7 widget AppCompatTex
  • 独立移动应用程序上的 WebRTC

    我知道WebRTC是为浏览器设计的 但是可以直接在移动应用程序上使用WebRTC库吗 Thanks 截至5月14日here https github com pchab AndroidRTC是一个android项目 使用WebRTC效果很好
  • 为什么我不能在 kotlin 中使用 lambda 接口? [复制]

    这个问题在这里已经有答案了 看 我有一个 Java 类 public final class JavaReceiveSingle public static void useSingle Single single single doSth
  • 为什么仅当我在 SDL2 中设置非零 Alpha 大小时才获得 sRGB 帧缓冲区?

    我正在尝试通过以下方式以伽玛正确的方式渲染典型的 OpenGL 颜色三角形本指南 https learnopengl com Advanced Lighting Gamma Correction并查阅 SDL2 文档 了解如何在默认帧缓冲区