小编The*_*ver的帖子

何时使用C++ 11互斥锁,lock,unique_lock,shared_lock等

  1. 是什么区别shared_lockshared_mutex.lock_shared()其他比的析构函数shared_lock解锁相关的互斥?
  2. shared_mutex我唯一可以使用的互斥类shared_lock吗?
  3. 为什么有人想用lock_guard而不是unique_lock
  4. 如果我有很多线程不断锁定read(shared_lock)一个变量,并且我有一个变量试图将其锁定为write(unique_lock),那么这个写入线程是否优先于其他线程?
  5. 对于#4,是否有可能出现死锁?

c++ multithreading mutex locking c++11

8
推荐指数
1
解决办法
1951
查看次数

vao外面的OpenGL glBindBuffer(0)?

我目前这样做来设置我的vao:

glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);

...

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBindVertexArray(0);
Run Code Online (Sandbox Code Playgroud)

我的问题是:我是否需要绑定空缓冲区以防止我的vbo和ibo在我完成vao之后更改或者绑定null vao时它还解除当前缓冲区的绑定?例如,我会做以下事情:

glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Run Code Online (Sandbox Code Playgroud)

opengl vao

4
推荐指数
1
解决办法
2094
查看次数

在try catch块中没有捕获异常

我做了一个简单的抛出"TEST THROW"并没有捕到我的catch(std :: exception&e).是因为我正在捕捉一个std :: exception&e?我的意思是,只有从std :: exception派生的异常类才被捕获?如果没有,我做错了什么还是正常的?顺便说一下,两个catch块都没有捕获抛出异常.

int main()
{
try
{
    throw "TEST THROW"; // TEST
    Core core;

    core.Init();
    core.Load();

    while (!core.requestCloseWindow)
    {
        core.HandleInput();

        core.Update();
        core.Draw();
    }

    core.Unload();
    core.window->close();
}
catch (std::exception& e)
{
    std::cerr << e.what() << std::endl;
    try
    {
        time_t rawTime;
        struct tm* timeInfo;
        char timeBuffer [80];

        time(&rawTime);
        timeInfo = localtime(&rawTime);

        strftime(timeBuffer, 80, "%F %T", timeInfo);
        puts(timeBuffer);

        std::ofstream ofs; // Pas besoin de close, car le destructeur le fait.
        ofs.exceptions(std::ofstream::failbit …
Run Code Online (Sandbox Code Playgroud)

c++ exception

3
推荐指数
2
解决办法
4448
查看次数

多纹理理论与纹理对象和采样器

我找不到任何关于如何使用纹理对象或纹理对象加上采样器来编码多纹理的理论文章.我只是不知道如何管理glActiveTexture功能以及它究竟做了什么.

glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0 + 0); // Number between 0 and GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, img.getSize().x, img.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.getPixelsPtr()); // Not in sampler
glGenerateMipmap(GL_TEXTURE_2D); // Not in sampler

/* Values associated with the texture and not with sampler (sampler has priority over texture).
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);*/

glGenSamplers(1, &textureSampler);
glBindSampler(0, textureSampler);
glSamplerParameteri(textureSampler, GL_TEXTURE_WRAP_S, GL_REPEAT);
glSamplerParameteri(textureSampler, GL_TEXTURE_WRAP_T, GL_REPEAT);
glSamplerParameteri(textureSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glSamplerParameteri(textureSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

glUniform1i(glGetUniformLocation(colorShader->program, "textureSampler"), 0); // 0 …
Run Code Online (Sandbox Code Playgroud)

opengl textures

3
推荐指数
1
解决办法
643
查看次数

将union的变量公开为类成员变量

我已经成功编译了这段代码:

template <typename T, unsigned int N>
struct Vector
{
    struct Vec1
    {
        T x;
    };

    struct Vec2 : public Vec1
    {
        T y;
    };

    struct Vec3 : public Vec2
    {
        T z;
    };

    struct Vec4 : public Vec3
    {
        T w;
    };

    template <unsigned int N>
    union Data
    {
        std::array<T, N> components;
    };

    template <>
    union Data<1>
    {
        Vec1 vec;
        std::array<T, 1> components;
    };

    template <>
    union Data<2>
    {
        Vec2 vec;
        std::array<T, 2> components;
    };

    template <>
    union Data<3> …
Run Code Online (Sandbox Code Playgroud)

c++ union templates

-2
推荐指数
1
解决办法
54
查看次数

标签 统计

c++ ×3

opengl ×2

c++11 ×1

exception ×1

locking ×1

multithreading ×1

mutex ×1

templates ×1

textures ×1

union ×1

vao ×1