我在一个std::optional
实现中遇到了这个代码:
template <class T, class U>
struct is_assignable
{
template <class X, class Y>
constexpr static bool has_assign(...) { return false; }
template <class X, class Y, size_t S = sizeof((std::declval<X>() = std::declval<Y>(), true)) >
// the comma operator is necessary for the cases where operator= returns void
constexpr static bool has_assign(bool) { return true; }
constexpr static bool value = has_assign<T, U>(true);
};
Run Code Online (Sandbox Code Playgroud)
我无法理解它是如何工作或如何评估的部分是size_t S = sizeof((std::declval<X>() = std::declval<Y>(), true))
我知道如果赋值操作失败,它将回退到返回false的has_assign的第一个定义,但我不知道为什么它有该, true)
部分.
我使用在assign操作符上返回void的结构进行了一些测试,并删除了, …
我即将实现一个非常基本的渲染模块.现在是时候改变使用VBO渲染基元到现代方法的旧方法,到目前为止我理解它是如何工作的但我不能让我的PoC工作.
加载基本模型(三角形)没有生成opengl错误(glBindVertexArray是glBindVertexArrayAPPLE的宏):
float pos[] = {
-1.0f, -1.0f,-5.0f,
-1.0f, 1.0f, -5.0f,
1.0f,1.0f,-5.0f,
};
printf("%d %d", map_VAO, map_VBO);
checkGLError();
glGenVertexArrays(1, &map_VAO);
checkGLError();
glGenBuffers(1, &map_VBO);
printf("%d %d", map_VAO, map_VBO); // here with 4.1 map_VAO is 0
checkGLError();
glEnableClientState(GL_VERTEX_ARRAY);
glBindVertexArrays(map_VAO);
glBindBuffer(GL_ARRAY_BUFFER, map_VBO);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(float), &pos[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArrays(0);
glDisableClientState(GL_VERTEX_ARRAY);
return 0;
Run Code Online (Sandbox Code Playgroud)
并在主循环(绘图部分):
// .. clear buffers load identity etc...
glColor3f(0.33f,0.0f,0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, map_VBO);
glBindVertexArrayAPPLE(map_VAO);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindBuffer(GL_ARRAY_BUFFER, 0 );
glBindVertexArrayAPPLE(0);
glDisableClientState(GL_VERTEX_ARRAY); …
Run Code Online (Sandbox Code Playgroud)