瀏覽代碼

deferred

opengl-renderer-broken
Martin Dørum 4 年之前
父節點
當前提交
c52aaa0c68
共有 2 個檔案被更改,包括 11 行新增1 行删除
  1. 9
    0
      libcygnet/include/cygnet/util.h
  2. 2
    1
      libcygnet/samples/hello-triangle/hello-triangle.cc

+ 9
- 0
libcygnet/include/cygnet/util.h 查看文件

@@ -34,4 +34,13 @@ public:
template<typename T, void (*Func)(T *)>
using CPtr = std::unique_ptr<T, CPtrDeleter<T, Func>>;

// Take a function, run it when the object goes out of scope
template<void (*Func)()>
class Deferred: NonCopyable {
public:
Deferred() = default;
~Deferred() { Func(); }
};


}

+ 2
- 1
libcygnet/samples/hello-triangle/hello-triangle.cc 查看文件

@@ -18,6 +18,7 @@ const char *fragmentSource = R"(

int main() {
SDL_Init(SDL_INIT_VIDEO);
Cygnet::Deferred<SDL_Quit> sdl;
Cygnet::Window win("Hello Triangle", 640, 480);

Cygnet::GlShader vertex(vertexSource, Cygnet::GlShader::Type::VERTEX);
@@ -53,5 +54,5 @@ int main() {
}

exit:
SDL_Quit();
return EXIT_SUCCESS;
}

Loading…
取消
儲存