├── .gitattributes ├── .gitignore ├── LICENSE.md ├── README.md ├── include └── c4g_runtime.h ├── lib ├── ios │ └── c4grt_ios.framework │ │ ├── Headers │ │ └── c4g_runtime.h │ │ ├── Info.plist │ │ ├── Modules │ │ └── module.modulemap │ │ ├── _CodeSignature │ │ └── CodeResources │ │ └── c4grt_ios ├── macos │ └── c4grt_macos.framework │ │ ├── Headers │ │ ├── Modules │ │ ├── Resources │ │ ├── Versions │ │ ├── A │ │ │ ├── Headers │ │ │ │ └── c4g_runtime.h │ │ │ ├── Modules │ │ │ │ └── module.modulemap │ │ │ ├── Resources │ │ │ │ └── Info.plist │ │ │ └── c4grt_macos │ │ └── Current │ │ └── c4grt_macos ├── x64 │ ├── c4grt.dll │ ├── freeglut.dll │ └── glew32.dll └── x86 │ ├── c4grt.dll │ ├── freeglut.dll │ └── glew32.dll ├── redist └── vc_redist.x64.exe ├── src ├── c4grt.sln ├── c4grt.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── c4grt_ios │ ├── c4grt_ios.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── c4grt_ios │ │ ├── Info.plist │ │ └── c4grt_ios.h ├── c4grt_macos │ ├── c4grt_macos.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── c4grt_macos │ │ ├── Info.plist │ │ └── c4grt_macos.h ├── data │ └── comp.vert ├── makefile ├── runtime │ ├── c4g_context_ios.h │ ├── c4g_context_ios.mm │ ├── c4g_context_linux.cpp │ ├── c4g_context_linux.hpp │ ├── c4g_context_macos.h │ ├── c4g_context_macos.mm │ ├── c4g_context_win.cpp │ ├── c4g_context_win.hpp │ ├── c4g_gl.cpp │ ├── c4g_gl.hpp │ ├── c4g_glpass.cpp │ ├── c4g_glpass.hpp │ ├── c4g_glsl.cpp │ ├── c4g_glsl.hpp │ ├── c4g_runtime.cpp │ ├── c4g_runtime.h │ ├── c4g_utils.cpp │ ├── c4g_utils.hpp │ ├── freeglut │ │ ├── Copying.txt │ │ ├── Readme.txt │ │ ├── bin │ │ │ ├── freeglut.dll │ │ │ └── x64 │ │ │ │ └── freeglut.dll │ │ ├── include │ │ │ └── GL │ │ │ │ ├── freeglut.h │ │ │ │ ├── freeglut_ext.h │ │ │ │ ├── freeglut_std.h │ │ │ │ └── glut.h │ │ └── lib │ │ │ ├── freeglut.lib │ │ │ └── x64 │ │ │ └── freeglut.lib │ ├── glew │ │ ├── LICENSE.txt │ │ ├── bin │ │ │ └── Release │ │ │ │ ├── Win32 │ │ │ │ ├── glew32.dll │ │ │ │ ├── glewinfo.exe │ │ │ │ └── visualinfo.exe │ │ │ │ └── x64 │ │ │ │ ├── glew32.dll │ │ │ │ ├── glewinfo.exe │ │ │ │ └── visualinfo.exe │ │ ├── doc │ │ │ ├── advanced.html │ │ │ ├── basic.html │ │ │ ├── build.html │ │ │ ├── credits.html │ │ │ ├── github.png │ │ │ ├── glew.css │ │ │ ├── glew.html │ │ │ ├── glew.png │ │ │ ├── glew.txt │ │ │ ├── glxew.html │ │ │ ├── gpl.txt │ │ │ ├── index.html │ │ │ ├── install.html │ │ │ ├── khronos.txt │ │ │ ├── log.html │ │ │ ├── mesa.txt │ │ │ ├── new.png │ │ │ ├── ogl_sm.jpg │ │ │ ├── travis.png │ │ │ └── wglew.html │ │ ├── include │ │ │ └── GL │ │ │ │ ├── eglew.h │ │ │ │ ├── glew.h │ │ │ │ ├── glxew.h │ │ │ │ └── wglew.h │ │ └── lib │ │ │ └── Release │ │ │ ├── Win32 │ │ │ ├── glew32.lib │ │ │ └── glew32s.lib │ │ │ └── x64 │ │ │ ├── glew32.lib │ │ │ └── glew32s.lib │ ├── runtime.vcxproj │ └── runtime.vcxproj.filters └── shell │ ├── c4g.cpp │ ├── c4g.vcxproj │ └── c4g.vcxproj.filters └── test ├── c4grt.dll ├── c4grt_eval.exe ├── c_eval.exe ├── c_eval └── c_eval.c ├── cs_eval.exe ├── freeglut.dll ├── glew32.dll ├── prog.bas ├── prog.cs ├── prog.vert ├── test.bas └── test.vert /.gitattributes: -------------------------------------------------------------------------------- 1 | src/runtime/freeglut/include/GL/* linguist-vendored 2 | src/runtime/freeglut/* linguist-vendored 3 | src/runtime/glew/include/GL/* linguist-vendored 4 | src/runtime/glew/* linguist-vendored 5 | lib/ios/c4grt_ios.framework/Headers/* linguist-vendored 6 | lib/macos/c4grt_macos.framework/Versions/A/Headers/* linguist-vendored 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /output 2 | /src/c4grt.VC.db 3 | /src/.vs 4 | /src/.vs/c4g/v14/.suo 5 | /temp 6 | /test/c4grt_eval.log 7 | .DS_Store 8 | *.user 9 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # C4GPU Runtime 2 | 3 | ## The MIT License 4 | 5 | **Copyright (C) 2017 [Wang Renxin](https://github.com/paladin-t). All rights reserved.** 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The C4GPU Runtime 2 | 3 | [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT) 4 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 5 | 6 |
7 | 8 | [简体中文](#简介) 9 | 10 | ## Introduction 11 | 12 | ### 1. Gist 13 | 14 | Welcome to the C4GPU Runtime. The C4GPU Runtime accelerated computing library is a free, general purpose, open source library that simplifies the process of developing software that targets parallel and massively parallel computing benefits by hardware acceleration with GPU. Let's call it C4GRT for short. It implements a GPGPU method with [Transform Feedback](https://www.khronos.org/opengl/wiki/Transform_Feedback) and programming with [GLSL](https://en.wikipedia.org/wiki/GLSL). With this library, you don't need to care about how to manipulate GPU API. The only thing you need to do is use the C API, and write standard GLSL shader for evaluation. 15 | 16 | ### 2. Why use GLSL for GPGPU 17 | 18 | There are some other GPGPU techniques available. But GLSL is almost the sole option if you'd like to write legal cross platform GPU program, although it's designed as a graphics shadering language. 19 | 20 | C4GRT is an abstraction layer of GPGPU with OpenGL. 21 | 22 | ## Compatibility 23 | 24 | The repository contains some precompiled libraries as follow. 25 | 26 | Platform | Path | Usage 27 | ----- | ----- | ----- 28 | Windows | [/lib/x64/c4grt.dll](lib/x64/c4grt.dll), [/lib/x86/c4grt.dll](lib/x86/c4grt.dll) | Dynamic libraries 29 | macOS | [/lib/macos/c4grt_macos.framework](lib/macos/c4grt_macos.framework) | Framework 30 | iOS | [/lib/ios/c4grt_ios.framework](lib/ios/c4grt_ios.framework) | Framework 31 | Linux | TO BE ADDED | - 32 | Android | TO BE ADDED | - 33 | Raspberry Pi | TO BE ADDED | - 34 | 35 | You have to use a C++11 compatible compiler to make a build manually. 36 | 37 | ## Performance 38 | 39 | There are various profiling programs in the [`/test`](test) directory. 40 | 41 | This repository only contains test programs for Windows for the moment. It requires VC++ 2015 x64 runtime to run C++ based programs, please use [`/redist/vc_redist.x64.exe`](https://c4gpu.github.io/c4gpu_runtime/redist/vc_redist.x64.exe) to install it. 42 | 43 | ### 1. C4GRT 44 | 45 | Run the `/test/c4grt_eval.exe` to profile with C4GRT. I used one of my other project [MY-BASIC](https://github.com/paladin-t/my_basic) for a scripting driven purpose. 46 | 47 | * It accepts a `.bas` file as optional argument, uses [`prog.bas`](test/prog.bas) as default; 48 | * A `.bas` operates the C4GRT system, and evaluates using a vertex shader with prepared data; 49 | * It's possible to modify the `.bas` and `.vert` vertex shader files to profile. 50 | 51 | ### 2. C 52 | 53 | Run the `/test/c_eval.exe` to profile with native C. The source code file is [`/test/c_eval/c_eval.c`](test/c_eval/c_eval.c). 54 | 55 | ### 3. C Sharp 56 | 57 | Run the `/test/cs_eval.exe` to profile with C#. 58 | 59 | * It accepts a `.cs` file as optional argument, uses [`prog.cs`](test/prog.cs) as default; 60 | * It compiles and invokes the `.cs` source code on the fly; 61 | * It's possible to midify the `.cs` file to profile. 62 | 63 | ### 4. Comparisons 64 | 65 | I've tested the profiler programs on a desktop computer as follow. 66 | 67 | Intel Core i5-6500 CPU, 3.2GHz 68 | DDR4 2.4GHz RAM, 8GB 69 | NVIDIA GeForce GTX950 GPU, 2GB 70 | 71 | They result approximately as follow. 72 | 73 | Host | Program | Time cost 74 | ----- | ----- | ----- 75 | C4GRT | [prog.bas](test/prog.bas)/[prog.vert](test/prog.vert) | 230ms 76 | C | - | 2.5min 77 | C# | [prog.cs](test/prog.cs) | 4.8min 78 | 79 | The result may be different according to specific hardwares. But without doubt the performance of the GPGPU solution stands out remarkably. 80 | 81 | ## Principles 82 | 83 | ### 1. Runtime 84 | 85 | #### 1.1 Data types 86 | 87 | It's able to pass the following data types. 88 | 89 | * Basic data types; 90 | * Texture data; 91 | * Customized struct (TO BE IMPLEMENTED). 92 | 93 | #### 1.2 Work flow 94 | 95 | Shader computation. 96 | 97 | 1. Creates context, binds shader; 98 | 2. Inputs data; 99 | 3. Computes shadering; 100 | 4. Outputs data; 101 | 5. Clears context. 102 | 103 | ## How to use it as a lib 104 | 105 | The C4GRT is implemented with C++11, and has exposed an ANSI C interface. You can see [`/src/runtime`](src/runtime) for the implementation source code. But for most cases, you may only include the [`/include/c4g_runtime.h`](include/c4g_runtime.h) header file to use the library. 106 | 107 | ## Code at a glance 108 | 109 | Read the [`/test/test.bas`](test/test.bas) and [`/test/test.vert`](test/test.vert) for a quick tutorial. You could also read the [`/src/shell/c4g.cpp`](src/shell/c4g.cpp) to see how to use it with C/C++ programs. 110 | 111 | A common workflow works as follow. 112 | 113 | ~~~~~~~~~~bas 114 | rt = runtime() ' Creates a C4GRT instance. 115 | rt.begin_proc() ' Begins processing, actives current context. 116 | p0 = rt.add_pass() ' Adds an evaluation pass. 117 | rt.use_gpu_program_file(p0, "prog.vert", "o0") ' Uses a GPU program, with Transform Feedback varyings. 118 | 119 | rt.prepare_buffers(p0, 0, len(ina0), len(outa0)) ' Prepares buffers. 120 | rt.prepare_uniform(p0, una0) ' Prepares uniform data. 121 | rt.prepare_in(p0, ina0) ' Prepares input data. 122 | rt.prepare_out(p0, outa0) ' Prepares output buffer. 123 | 124 | rt.compute(p0) ' Does evaluation. 125 | 126 | rt.map_out(p0) ' Maps output data. 127 | rt.finish() ' Finishes. 128 | rt.end_proc() ' Ends processing. 129 | ~~~~~~~~~~ 130 | 131 | It's also possible to link several evaluation passes into an evaluation sequence, in which a pass will use some of the output data of previous pass as its input. Use the follow code to link two passes. 132 | 133 | ~~~~~~~~~~bas 134 | p0 = rt.add_pass() ' Adds the first pass. 135 | p1 = rt.add_pass(p0) ' Adds the second pass, and uses p0 as its previous. 136 | rt.set_pass_pipe(p0, true, "o0", "v0", "o1", "v1") ' Sets how to pass output data from p0 to p1 as input. 137 | ~~~~~~~~~~ 138 | 139 | In the above code, the first parameter of `set_pass_pipe` specifies the ahead pass, and the second boolean parameter indicates whether the output data would flow to its following pass. The rest variadic arguments list in a form of key-value pairs tells the naming rules of data flow. Here `p0`'s output `o0` links to `p1`'s input `v0`, `p0`'s `o1` links to `p1`'s `v1`. 140 | 141 | Without invoking `set_pass_pipe`, the linked passes work as a sequence one by one, but without output to input data flow. 142 | 143 | It's also possible to partially set some of the data by piping, and the rest by common prepared input buffers. 144 | 145 | ## Limitations 146 | 147 | It requires OpenGL 2.0 or OpenGL ES 3.0 to use the Transform Feedback. Some GPUs didn't implement texture sampler in vertex shader. 148 | 149 |
150 | 151 | [English](#introduction) 152 | 153 | ## 简介 154 | 155 | ### 1. 主旨 156 | 157 | 欢迎来到 C4GPU Runtime。C4GPU Runtime 计算加速库是一个免费、通用、开源的程序库,得益于 GPU 硬件加速,用以简化面向并行及大规模并行计算的软件开发过程。下文均用 C4GRT 代指本项目。其利用 [Transform Feedback](https://www.khronos.org/opengl/wiki/Transform_Feedback) 和 [GLSL](https://en.wikipedia.org/wiki/GLSL) 实现了 GPGPU 的一种方法。使用本库你不需要关心如何操作 GPU API。你唯一需要关注的就是调用 C API,以及编写标准 GLSL 着色程序用以计算。 158 | 159 | ### 2. 为何使用 GLSL 做 GPGPU 160 | 161 | 能用来做 GPGPU 的技术有很多。但是如果你想写合法的跨平台 GPU 程序,GLSL 差不多是唯一的选择了,尽管其设计初衷是作为图形着色语言。 162 | 163 | C4GRT 是针对 GPGPU 的 OpenGL 调用的一层抽象。 164 | 165 | ## 兼容性 166 | 167 | 本源码仓库包含一些预编译库文件,如下。 168 | 169 | 平台 | 路径 | 使用 170 | ----- | ----- | ----- 171 | Windows | [/lib/x64/c4grt.dll](lib/x64/c4grt.dll), [/lib/x86/c4grt.dll](lib/x86/c4grt.dll) | 动态链接库 172 | macOS | [/lib/macos/c4grt_macos.framework](lib/macos/c4grt_macos.framework) | Framework 173 | iOS | [/lib/ios/c4grt_ios.framework](lib/ios/c4grt_ios.framework) | Framework 174 | Linux | TO BE ADDED | - 175 | Android | TO BE ADDED | - 176 | Raspberry Pi | TO BE ADDED | - 177 | 178 | 如需手动构建,你需要使用一个兼容 C++11 的编译器。 179 | 180 | ## 性能 181 | 182 | 在 [`/test`](test) 文件夹下有多个性能测试程序。 183 | 184 | 本源码仓库暂时只提供针对 Windows 平台的测试程序。基于 C++ 的程序运行需要 VC++ 2015 x64 运行时支持,请使用 [`/redist/vc_redist.x64.exe`](https://c4gpu.github.io/c4gpu_runtime/redist/vc_redist.x64.exe) 进行安装。 185 | 186 | ### 1. C4GRT 187 | 188 | 运行 `/test/c4grt_eval.exe` 进行 C4GRT 测试。我使用了我的另一个项目 [MY-BASIC](https://github.com/paladin-t/my_basic) 作为脚本驱动。 189 | 190 | * 程序接受一个 `.bas` 文件作为可选参数,缺省使用 [`prog.bas`](test/prog.bas); 191 | * `.bas` 脚本操作 C4GRT 系统,并使用一个 vertex shader 来对准备好的数据求值; 192 | * 可对 `.bas` 和 `.vert` vertex shader 文件做测试修改。 193 | 194 | ### 2. C 195 | 196 | 运行 `/test/c_eval.exe` 进行本地 C 测试。其源码在 [`/test/c_eval/c_eval.c`](test/c_eval/c_eval.c)。 197 | 198 | ### 3. C Sharp 199 | 200 | 运行 `/test/cs_eval.exe` 进行 C# 测试。 201 | 202 | * 程序接受一个 `.cs` 文件作为可选参数,缺省使用 [`prog.cs`](test/prog.cs); 203 | * 程序会动态编译执行 `.cs` 源代码; 204 | * 可对 `.cs` 文件做测试修改。 205 | 206 | ### 4. 对比 207 | 208 | 本人在一台台式机上运行效率测试程序,配置如下。 209 | 210 | Intel Core i5-6500 CPU, 3.2GHz 211 | DDR4 2.4GHz RAM, 8GB 212 | NVIDIA GeForce GTX950 GPU, 2GB 213 | 214 | 大致运行结果如下。 215 | 216 | 宿主 | 程序 | 耗时 217 | ----- | ----- | ----- 218 | C4GRT | [prog.bas](test/prog.bas)/[prog.vert](test/prog.vert) | 230ms 219 | C | - | 2.5min 220 | C# | [prog.cs](test/prog.cs) | 4.8min 221 | 222 | 不同硬件可能导致结果不同。但毫无疑问 GPGPU 解决方案的效率明显胜出。 223 | 224 | ## 原理 225 | 226 | ### 1. 运行时 227 | 228 | #### 1.1 数据类型 229 | 230 | 可传递以下类型的数据。 231 | 232 | * 基础数据类型; 233 | * 纹理数据; 234 | * 自定义结构体(待实现)。 235 | 236 | #### 1.2 工作流程 237 | 238 | Shader 计算。 239 | 240 | 1. 创建上下文,绑定 Shader; 241 | 2. 输入数据; 242 | 3. 计算着色; 243 | 4. 输出数据; 244 | 5. 清理上下文。 245 | 246 | ## 如何使用库文件 247 | 248 | C4GRT 使用 C++11 实现,并且其接口为 ANSI C 导出。如需查看实现源码,请看 [`/src/runtime`](src/runtime) 文件夹。但对于大多数使用情景来说,包含 [`/include/c4g_runtime.h`](include/c4g_runtime.h) 头文件就足够了。 249 | 250 | ## 示例 251 | 252 | 阅读 [`/test/test.bas`](test/test.bas) 以及 [`/test/test.vert`](test/test.vert) 作为快速入门。你也可以查看 [`/src/shell/c4g.cpp`](src/shell/c4g.cpp) 以了解如何在 C/C++ 程序中使用它。 253 | 254 | 一个典型工作流程如下。 255 | 256 | ~~~~~~~~~~bas 257 | rt = runtime() ' 创建一个 C4GRT 实例。 258 | rt.begin_proc() ' 开始处理,激活当前上下文。 259 | p0 = rt.add_pass() ' 添加一个计算 pass。 260 | rt.use_gpu_program_file(p0, "prog.vert", "o0") ' 使用某个 GPU 程序,附带 Transform Feedback 传出命名。 261 | 262 | rt.prepare_buffers(p0, 0, len(ina0), len(outa0)) ' 准备 buffer。 263 | rt.prepare_uniform(p0, una0) ' 准备 uniform 数据。 264 | rt.prepare_in(p0, ina0) ' 准备输入数据。 265 | rt.prepare_out(p0, outa0) ' 准备输出缓存。 266 | 267 | rt.compute(p0) ' 进行计算。 268 | 269 | rt.map_out(p0) ' 映射输出数据。 270 | rt.finish() ' 完成。 271 | rt.end_proc() ' 完成处理。 272 | ~~~~~~~~~~ 273 | 274 | 同时系统允许把多个计算 pass 连接成一个计算序列,其中某一 pass 会使用其前一 pass 的某些输出数据作为输入。使用如下代码来连接两个 pass。 275 | 276 | ~~~~~~~~~~bas 277 | p0 = rt.add_pass() ' 添加第一个 pass。 278 | p1 = rt.add_pass(p0) ' 添加第二个 pass,且使用 p0 作为其前置 pass。 279 | rt.set_pass_pipe(p0, true, "o0", "v0", "o1", "v1") ' 设置如何将 p0 输出传递给 p1 作为输入。 280 | ~~~~~~~~~~ 281 | 282 | 在上述代码中,`set_pass_pipe` 的第一个参数指定首 pass,第二个 boolean 参数指定其输出数据会流向其后继 pass。其余以“键值对”存在的变长参数列表为数据流向定义命名规则。在这里 `p0` 的输出 `o0` 连接到 `p1` 的输入 `v0`,`p0` 的 `o1` 连接到 `p1` 的 `v1`。 283 | 284 | 如果没有调用 `set_pass_pipe`,则已连接到 pass 只是一个接一个的被计算,并不会有输出到输入的数据流向。 285 | 286 | 程序中同样支持部分指定数据流向管道,其余数据使用常规输入缓存。 287 | 288 | ## 限制 289 | 290 | 使用 Transform Feedback 特性要求 OpenGL 2.0 或 OpenGL ES 3.0 及以上版本。某些 GPU 不允许在 vertes shader 里使用纹理采样。 291 | -------------------------------------------------------------------------------- /lib/ios/c4grt_ios.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/ios/c4grt_ios.framework/Info.plist -------------------------------------------------------------------------------- /lib/ios/c4grt_ios.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module c4grt_ios { 2 | umbrella header "c4grt_ios.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /lib/ios/c4grt_ios.framework/_CodeSignature/CodeResources: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | files 6 | 7 | Headers/c4g_runtime.h 8 | 9 | TIhictyiv3i/wFl3NsZkzy4REZg= 10 | 11 | Info.plist 12 | 13 | 1gEWXhabAfTcO4w7ABCGm5Tvfqs= 14 | 15 | Modules/module.modulemap 16 | 17 | vFNDngtql9vp4bko/10I9RUpTuo= 18 | 19 | 20 | files2 21 | 22 | Headers/c4g_runtime.h 23 | 24 | hash 25 | 26 | TIhictyiv3i/wFl3NsZkzy4REZg= 27 | 28 | hash2 29 | 30 | mJTTs1ZUQRWV+i+Z3xgxk09CNfn7goLS4aWgvW6WdEM= 31 | 32 | 33 | Modules/module.modulemap 34 | 35 | hash 36 | 37 | vFNDngtql9vp4bko/10I9RUpTuo= 38 | 39 | hash2 40 | 41 | Kzf/b+gRlRHZFgiQSMXPWo+Whd/YZtbhrzwPMQKe0KU= 42 | 43 | 44 | 45 | rules 46 | 47 | ^ 48 | 49 | ^.*\.lproj/ 50 | 51 | optional 52 | 53 | weight 54 | 1000 55 | 56 | ^.*\.lproj/locversion.plist$ 57 | 58 | omit 59 | 60 | weight 61 | 1100 62 | 63 | ^Base\.lproj/ 64 | 65 | weight 66 | 1010 67 | 68 | ^version.plist$ 69 | 70 | 71 | rules2 72 | 73 | .*\.dSYM($|/) 74 | 75 | weight 76 | 11 77 | 78 | ^ 79 | 80 | weight 81 | 20 82 | 83 | ^(.*/)?\.DS_Store$ 84 | 85 | omit 86 | 87 | weight 88 | 2000 89 | 90 | ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ 91 | 92 | nested 93 | 94 | weight 95 | 10 96 | 97 | ^.* 98 | 99 | ^.*\.lproj/ 100 | 101 | optional 102 | 103 | weight 104 | 1000 105 | 106 | ^.*\.lproj/locversion.plist$ 107 | 108 | omit 109 | 110 | weight 111 | 1100 112 | 113 | ^Base\.lproj/ 114 | 115 | weight 116 | 1010 117 | 118 | ^Info\.plist$ 119 | 120 | omit 121 | 122 | weight 123 | 20 124 | 125 | ^PkgInfo$ 126 | 127 | omit 128 | 129 | weight 130 | 20 131 | 132 | ^[^/]+$ 133 | 134 | nested 135 | 136 | weight 137 | 10 138 | 139 | ^embedded\.provisionprofile$ 140 | 141 | weight 142 | 20 143 | 144 | ^version\.plist$ 145 | 146 | weight 147 | 20 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /lib/ios/c4grt_ios.framework/c4grt_ios: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/ios/c4grt_ios.framework/c4grt_ios -------------------------------------------------------------------------------- /lib/macos/c4grt_macos.framework/Headers: -------------------------------------------------------------------------------- 1 | XSym 2 | 0024 3 | 86c63de7bd8775780ac77380b5c049c4 4 | Versions/Current/Headers 5 | -------------------------------------------------------------------------------- /lib/macos/c4grt_macos.framework/Modules: -------------------------------------------------------------------------------- 1 | XSym 2 | 0024 3 | 61518f95f1594f4c10ae354eb27b4d91 4 | Versions/Current/Modules 5 | -------------------------------------------------------------------------------- /lib/macos/c4grt_macos.framework/Resources: -------------------------------------------------------------------------------- 1 | XSym 2 | 0026 3 | e58c4cf10cc7c8ef7d7167ccb641aeb4 4 | Versions/Current/Resources 5 | -------------------------------------------------------------------------------- /lib/macos/c4grt_macos.framework/Versions/A/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module c4grt_macos { 2 | umbrella header "c4grt_macos.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /lib/macos/c4grt_macos.framework/Versions/A/Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 16D32 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | c4grt_macos 11 | CFBundleIdentifier 12 | com.tonywang.c4grt-macos.c4grt-macos 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | c4grt_macos 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSupportedPlatforms 22 | 23 | MacOSX 24 | 25 | CFBundleVersion 26 | 1 27 | DTCompiler 28 | com.apple.compilers.llvm.clang.1_0 29 | DTPlatformBuild 30 | 8C1002 31 | DTPlatformVersion 32 | GM 33 | DTSDKBuild 34 | 16C58 35 | DTSDKName 36 | macosx10.12 37 | DTXcode 38 | 0821 39 | DTXcodeBuild 40 | 8C1002 41 | NSHumanReadableCopyright 42 | Copyright © 2017年 wrx. All rights reserved. 43 | 44 | 45 | -------------------------------------------------------------------------------- /lib/macos/c4grt_macos.framework/Versions/A/c4grt_macos: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/macos/c4grt_macos.framework/Versions/A/c4grt_macos -------------------------------------------------------------------------------- /lib/macos/c4grt_macos.framework/Versions/Current: -------------------------------------------------------------------------------- 1 | XSym 2 | 0001 3 | 7fc56270e7a70fa81a5935b72eacbe29 4 | A 5 | -------------------------------------------------------------------------------- /lib/macos/c4grt_macos.framework/c4grt_macos: -------------------------------------------------------------------------------- 1 | XSym 2 | 0028 3 | c48218b259111c86f53fb89b4532fd7a 4 | Versions/Current/c4grt_macos 5 | -------------------------------------------------------------------------------- /lib/x64/c4grt.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/x64/c4grt.dll -------------------------------------------------------------------------------- /lib/x64/freeglut.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/x64/freeglut.dll -------------------------------------------------------------------------------- /lib/x64/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/x64/glew32.dll -------------------------------------------------------------------------------- /lib/x86/c4grt.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/x86/c4grt.dll -------------------------------------------------------------------------------- /lib/x86/freeglut.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/x86/freeglut.dll -------------------------------------------------------------------------------- /lib/x86/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/lib/x86/glew32.dll -------------------------------------------------------------------------------- /redist/vc_redist.x64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/redist/vc_redist.x64.exe -------------------------------------------------------------------------------- /src/c4grt.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c4g", "shell\c4g.vcxproj", "{B520B141-DC24-422E-A3D2-ACF161C79211}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104} = {EC9339D7-BBEB-46DB-A9A7-EA0126F43104} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c4grt", "runtime\runtime.vcxproj", "{EC9339D7-BBEB-46DB-A9A7-EA0126F43104}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | debug|x64 = debug|x64 16 | debug|x86 = debug|x86 17 | release|x64 = release|x64 18 | release|x86 = release|x86 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {B520B141-DC24-422E-A3D2-ACF161C79211}.debug|x64.ActiveCfg = debug|x64 22 | {B520B141-DC24-422E-A3D2-ACF161C79211}.debug|x64.Build.0 = debug|x64 23 | {B520B141-DC24-422E-A3D2-ACF161C79211}.debug|x86.ActiveCfg = debug|Win32 24 | {B520B141-DC24-422E-A3D2-ACF161C79211}.debug|x86.Build.0 = debug|Win32 25 | {B520B141-DC24-422E-A3D2-ACF161C79211}.release|x64.ActiveCfg = release|x64 26 | {B520B141-DC24-422E-A3D2-ACF161C79211}.release|x64.Build.0 = release|x64 27 | {B520B141-DC24-422E-A3D2-ACF161C79211}.release|x86.ActiveCfg = release|Win32 28 | {B520B141-DC24-422E-A3D2-ACF161C79211}.release|x86.Build.0 = release|Win32 29 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104}.debug|x64.ActiveCfg = debug|x64 30 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104}.debug|x64.Build.0 = debug|x64 31 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104}.debug|x86.ActiveCfg = debug|Win32 32 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104}.debug|x86.Build.0 = debug|Win32 33 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104}.release|x64.ActiveCfg = release|x64 34 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104}.release|x64.Build.0 = release|x64 35 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104}.release|x86.ActiveCfg = release|Win32 36 | {EC9339D7-BBEB-46DB-A9A7-EA0126F43104}.release|x86.Build.0 = release|Win32 37 | EndGlobalSection 38 | GlobalSection(SolutionProperties) = preSolution 39 | HideSolutionNode = FALSE 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /src/c4grt.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/c4grt_ios/c4grt_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/c4grt_ios/c4grt_ios/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/c4grt_ios/c4grt_ios/c4grt_ios.h: -------------------------------------------------------------------------------- 1 | #ifndef __C4GRT_IOS_H__ 2 | #define __C4GRT_IOS_H__ 3 | 4 | #endif /* __C4GRT_IOS_H__ */ 5 | -------------------------------------------------------------------------------- /src/c4grt_macos/c4grt_macos.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/c4grt_macos/c4grt_macos/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSHumanReadableCopyright 22 | Copyright © 2017年 wrx. All rights reserved. 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/c4grt_macos/c4grt_macos/c4grt_macos.h: -------------------------------------------------------------------------------- 1 | #ifndef __C4GRT_MACOS_H__ 2 | #define __C4GRT_MACOS_H__ 3 | 4 | #endif /* __C4GRT_MACOS_H__ */ 5 | -------------------------------------------------------------------------------- /src/data/comp.vert: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | 3 | uniform sampler2D s0; 4 | uniform vec4 u0; 5 | in vec4 v0; 6 | in vec4 v1; 7 | out vec4 o0; 8 | out vec4 o1; 9 | 10 | void main() { 11 | o0 = v0 + v1 + u0; 12 | o1 = texture2D(s0, vec2(1, 1)) + u0; 13 | } 14 | -------------------------------------------------------------------------------- /src/makefile: -------------------------------------------------------------------------------- 1 | # This is a placeholder. 2 | -------------------------------------------------------------------------------- /src/runtime/c4g_context_ios.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #ifndef __C4G_CONTEXT_IOS_H__ 10 | #define __C4G_CONTEXT_IOS_H__ 11 | 12 | #include "c4g_runtime.h" 13 | 14 | #if defined C4G_RUNTIME_OS_IOS || defined C4G_RUNTIME_OS_IOS 15 | 16 | namespace c4g { 17 | 18 | namespace gl { 19 | 20 | struct Context; 21 | 22 | C4G_RUNTIME_IMPL Context* createContext(void); 23 | C4G_RUNTIME_IMPL void finishCreatingContext(Context* ctx); 24 | C4G_RUNTIME_IMPL void destroyContext(Context* ctx); 25 | 26 | C4G_RUNTIME_IMPL void pushContext(Context* ctx); 27 | C4G_RUNTIME_IMPL void popContext(Context* ctx); 28 | C4G_RUNTIME_IMPL bool isContext(Context* ctx); 29 | 30 | } 31 | 32 | } 33 | 34 | #endif /* defined C4G_RUNTIME_OS_IOS || defined C4G_RUNTIME_OS_IOS */ 35 | 36 | #endif /* __C4G_CONTEXT_IOS_H__ */ 37 | -------------------------------------------------------------------------------- /src/runtime/c4g_context_ios.mm: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_context_ios.h" 10 | #include 11 | 12 | #if defined C4G_RUNTIME_OS_IOS || defined C4G_RUNTIME_OS_IOS 13 | 14 | namespace c4g { 15 | 16 | namespace gl { 17 | 18 | struct Context { 19 | EAGLContext* _context = nullptr; 20 | EAGLContext* _oldContext = nullptr; 21 | }; 22 | 23 | Context* createContext(void) { 24 | Context* result = new Context(); 25 | 26 | result->_context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES3]; 27 | pushContext(result); 28 | 29 | return result; 30 | } 31 | 32 | void finishCreatingContext(Context* ctx) { 33 | popContext(ctx); 34 | } 35 | 36 | void destroyContext(Context* ctx) { 37 | if (!ctx) return; 38 | 39 | ctx->_context = nullptr; 40 | 41 | delete ctx; 42 | } 43 | 44 | void pushContext(Context* ctx) { 45 | if (!ctx) return; 46 | 47 | ctx->_oldContext = [EAGLContext currentContext]; 48 | [EAGLContext setCurrentContext: ctx->_context]; 49 | } 50 | 51 | void popContext(Context* ctx) { 52 | if (!ctx) return; 53 | 54 | [EAGLContext setCurrentContext: ctx->_oldContext]; 55 | ctx->_oldContext = nullptr; 56 | } 57 | 58 | bool isContext(Context* ctx) { 59 | if (!ctx) return false; 60 | 61 | return ctx->_context == [EAGLContext currentContext]; 62 | } 63 | 64 | } 65 | 66 | } 67 | 68 | #endif /* defined C4G_RUNTIME_OS_IOS || defined C4G_RUNTIME_OS_IOS */ 69 | -------------------------------------------------------------------------------- /src/runtime/c4g_context_linux.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_context_linux.hpp" 10 | 11 | #ifdef C4G_RUNTIME_OS_LINUX 12 | 13 | namespace c4g { 14 | 15 | namespace gl { 16 | 17 | struct Context { 18 | int _context = 0; 19 | int _oldContext = 0; 20 | }; 21 | 22 | Context* createContext(void) { 23 | Context* result = new Context(); 24 | 25 | //result->_context = CreateContext(); 26 | pushContext(result); 27 | 28 | return result; 29 | } 30 | 31 | void finishCreatingContext(Context* ctx) { 32 | popContext(ctx); 33 | } 34 | 35 | void destroyContext(Context* ctx) { 36 | if (!ctx) return; 37 | 38 | //DestroyContext(result->_context); 39 | 40 | delete ctx; 41 | } 42 | 43 | void pushContext(Context* ctx) { 44 | if (!ctx) return; 45 | 46 | //ctx->_oldContext = GetCurrentContext(); 47 | //SetCurrentContext(ctx->_context); 48 | } 49 | 50 | void popContext(Context* ctx) { 51 | if (!ctx) return; 52 | 53 | //SetCurrentContext(ctx->_oldContext); 54 | //ctx->_oldContext = nullptr; 55 | } 56 | 57 | bool isContext(Context* ctx) { 58 | if (!ctx) return false; 59 | 60 | //return ctx->_context == GetCurrentContext(); 61 | return true; 62 | } 63 | 64 | } 65 | 66 | } 67 | 68 | #endif /* C4G_RUNTIME_OS_LINUX */ 69 | -------------------------------------------------------------------------------- /src/runtime/c4g_context_linux.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #ifndef __C4G_CONTEXT_LINUX_H__ 10 | #define __C4G_CONTEXT_LINUX_H__ 11 | 12 | #include "c4g_runtime.h" 13 | 14 | #ifdef C4G_RUNTIME_OS_LINUX 15 | 16 | namespace c4g { 17 | 18 | namespace gl { 19 | 20 | struct Context; 21 | 22 | C4G_RUNTIME_IMPL Context* createContext(void); 23 | C4G_RUNTIME_IMPL void finishCreatingContext(Context* ctx); 24 | C4G_RUNTIME_IMPL void destroyContext(Context* ctx); 25 | 26 | C4G_RUNTIME_IMPL void pushContext(Context* ctx); 27 | C4G_RUNTIME_IMPL void popContext(Context* ctx); 28 | C4G_RUNTIME_IMPL bool isContext(Context* ctx); 29 | 30 | } 31 | 32 | } 33 | 34 | #endif /* C4G_RUNTIME_OS_LINUX */ 35 | 36 | #endif /* __C4G_CONTEXT_LINUX_H__ */ 37 | -------------------------------------------------------------------------------- /src/runtime/c4g_context_macos.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #ifndef __C4G_CONTEXT_MACOS_H__ 10 | #define __C4G_CONTEXT_MACOS_H__ 11 | 12 | #include "c4g_runtime.h" 13 | 14 | #ifdef C4G_RUNTIME_OS_MAC 15 | 16 | namespace c4g { 17 | 18 | namespace gl { 19 | 20 | struct Context; 21 | 22 | C4G_RUNTIME_IMPL Context* createContext(void); 23 | C4G_RUNTIME_IMPL void finishCreatingContext(Context* ctx); 24 | C4G_RUNTIME_IMPL void destroyContext(Context* ctx); 25 | 26 | C4G_RUNTIME_IMPL void pushContext(Context* ctx); 27 | C4G_RUNTIME_IMPL void popContext(Context* ctx); 28 | C4G_RUNTIME_IMPL bool isContext(Context* ctx); 29 | 30 | } 31 | 32 | } 33 | 34 | #endif /* C4G_RUNTIME_OS_MAC */ 35 | 36 | #endif /* __C4G_CONTEXT_MACOS_H__ */ 37 | -------------------------------------------------------------------------------- /src/runtime/c4g_context_macos.mm: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_context_macos.h" 10 | #include 11 | 12 | #ifdef C4G_RUNTIME_OS_MAC 13 | 14 | namespace c4g { 15 | 16 | namespace gl { 17 | 18 | struct Context { 19 | CGLContextObj _context = nullptr; 20 | CGLContextObj _oldContext = nullptr; 21 | }; 22 | 23 | Context* createContext(void) { 24 | Context* result = new Context(); 25 | 26 | CGLPixelFormatAttribute pixelFormatAttributes[] = { 27 | kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, 28 | kCGLPFAColorSize, (CGLPixelFormatAttribute)24, 29 | kCGLPFAAlphaSize, (CGLPixelFormatAttribute)8, 30 | kCGLPFAAccelerated, 31 | (CGLPixelFormatAttribute)0 32 | }; 33 | CGLPixelFormatObj pixelFormat; 34 | GLint numberOfPixels; 35 | CGLChoosePixelFormat(pixelFormatAttributes, &pixelFormat, &numberOfPixels); 36 | CGLCreateContext(pixelFormat, 0, &result->_context); 37 | CGLDestroyPixelFormat(pixelFormat); 38 | pushContext(result); 39 | 40 | return result; 41 | } 42 | 43 | void finishCreatingContext(Context* ctx) { 44 | popContext(ctx); 45 | } 46 | 47 | void destroyContext(Context* ctx) { 48 | if (!ctx) return; 49 | 50 | CGLDestroyContext(ctx->_context); 51 | 52 | delete ctx; 53 | } 54 | 55 | void pushContext(Context* ctx) { 56 | if (!ctx) return; 57 | 58 | ctx->_oldContext = CGLGetCurrentContext(); 59 | CGLSetCurrentContext(ctx->_context); 60 | } 61 | 62 | void popContext(Context* ctx) { 63 | if (!ctx) return; 64 | 65 | CGLSetCurrentContext(ctx->_oldContext); 66 | ctx->_oldContext = nullptr; 67 | } 68 | 69 | bool isContext(Context* ctx) { 70 | if (!ctx) return false; 71 | 72 | return ctx->_context == CGLGetCurrentContext(); 73 | } 74 | 75 | } 76 | 77 | } 78 | 79 | #endif /* C4G_RUNTIME_OS_MAC */ 80 | -------------------------------------------------------------------------------- /src/runtime/c4g_context_win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_context_win.hpp" 10 | 11 | #ifdef C4G_RUNTIME_OS_WIN 12 | 13 | #include 14 | 15 | namespace c4g { 16 | 17 | namespace gl { 18 | 19 | struct Context { 20 | HWND hWnd = nullptr; 21 | HDC hDC = nullptr; 22 | HGLRC hRC = nullptr; 23 | HDC hOldDC = nullptr; 24 | HGLRC hOldRC = nullptr; 25 | }; 26 | 27 | C4G_RUNTIME_IMPL static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { 28 | switch (message) { 29 | case WM_CREATE: 30 | break; 31 | default: 32 | return DefWindowProc(hWnd, message, wParam, lParam); 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | C4G_RUNTIME_IMPL static int createWindow(HWND* hWnd) { 39 | if (!hWnd) 40 | return -1; 41 | 42 | HINSTANCE hInstance = 0; 43 | MSG msg = { 0 }; 44 | WNDCLASS wc = { 0 }; 45 | wc.lpfnWndProc = WndProc; 46 | wc.hInstance = hInstance; 47 | wc.lpszClassName = L"c4g"; 48 | wc.style = CS_OWNDC; 49 | if (!RegisterClass(&wc)) 50 | return 1; 51 | 52 | *hWnd = CreateWindowW(wc.lpszClassName, L"c4g", WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, 0, 0, hInstance, 0); 53 | 54 | return 0; 55 | } 56 | 57 | Context* createContext(void) { 58 | Context* result = new Context(); 59 | 60 | PIXELFORMATDESCRIPTOR pfd; 61 | int iFormat; 62 | 63 | createWindow(&result->hWnd); 64 | result->hDC = GetDC(result->hWnd); 65 | 66 | ZeroMemory(&pfd, sizeof(pfd)); 67 | pfd.nSize = sizeof(pfd); 68 | pfd.nVersion = 1; 69 | pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 70 | pfd.iPixelType = PFD_TYPE_RGBA; 71 | pfd.cColorBits = 24; 72 | pfd.cDepthBits = 16; 73 | pfd.iLayerType = PFD_MAIN_PLANE; 74 | iFormat = ChoosePixelFormat(result->hDC, &pfd); 75 | SetPixelFormat(result->hDC, iFormat, &pfd); 76 | 77 | result->hRC = wglCreateContext(result->hDC); 78 | pushContext(result); 79 | 80 | return result; 81 | } 82 | 83 | void finishCreatingContext(Context* ctx) { 84 | popContext(ctx); 85 | } 86 | 87 | void destroyContext(Context* ctx) { 88 | if (!ctx) return; 89 | 90 | wglDeleteContext(ctx->hRC); 91 | ReleaseDC(ctx->hWnd, ctx->hDC); 92 | 93 | delete ctx; 94 | } 95 | 96 | void pushContext(Context* ctx) { 97 | if (!ctx) return; 98 | 99 | ctx->hOldDC = wglGetCurrentDC(); 100 | ctx->hOldRC = wglGetCurrentContext(); 101 | wglMakeCurrent(ctx->hDC, ctx->hRC); 102 | } 103 | 104 | void popContext(Context* ctx) { 105 | if (!ctx) return; 106 | 107 | wglMakeCurrent(ctx->hOldDC, ctx->hOldRC); 108 | ctx->hOldDC = nullptr; 109 | ctx->hOldRC = nullptr; 110 | } 111 | 112 | bool isContext(Context* ctx) { 113 | if (!ctx) return false; 114 | 115 | return ctx->hDC == wglGetCurrentDC() && ctx->hRC == wglGetCurrentContext(); 116 | } 117 | 118 | } 119 | 120 | } 121 | 122 | #endif /* C4G_RUNTIME_OS_WIN */ 123 | -------------------------------------------------------------------------------- /src/runtime/c4g_context_win.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #ifndef __C4G_CONTEXT_WIN_H__ 10 | #define __C4G_CONTEXT_WIN_H__ 11 | 12 | #include "c4g_runtime.h" 13 | 14 | #ifdef C4G_RUNTIME_OS_WIN 15 | 16 | namespace c4g { 17 | 18 | namespace gl { 19 | 20 | struct Context; 21 | 22 | C4G_RUNTIME_IMPL Context* createContext(void); 23 | C4G_RUNTIME_IMPL void finishCreatingContext(Context* ctx); 24 | C4G_RUNTIME_IMPL void destroyContext(Context* ctx); 25 | 26 | C4G_RUNTIME_IMPL void pushContext(Context* ctx); 27 | C4G_RUNTIME_IMPL void popContext(Context* ctx); 28 | C4G_RUNTIME_IMPL bool isContext(Context* ctx); 29 | 30 | } 31 | 32 | } 33 | 34 | #endif /* C4G_RUNTIME_OS_WIN */ 35 | 36 | #endif /* __C4G_CONTEXT_WIN_H__ */ 37 | -------------------------------------------------------------------------------- /src/runtime/c4g_gl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_context_ios.h" 10 | #include "c4g_context_linux.hpp" 11 | #include "c4g_context_macos.h" 12 | #include "c4g_context_win.hpp" 13 | #include "c4g_gl.hpp" 14 | 15 | namespace c4g { 16 | 17 | namespace gl { 18 | 19 | OpenGL::OpenGL() { 20 | } 21 | 22 | OpenGL::~OpenGL() { 23 | clearPasses(); 24 | } 25 | 26 | bool OpenGL::open(struct C4GRT_Runtime* rt) { 27 | _runtime = rt; 28 | 29 | _context = createContext(); 30 | 31 | #ifdef C4G_RUNTIME_OS_WIN 32 | glewInit(); 33 | #endif /* C4G_RUNTIME_OS_WIN */ 34 | 35 | int major, minor; 36 | c4g::gl::OpenGL::getVersion(&major, &minor); 37 | if (major < 2) { 38 | const char* const msg = "Support for OpenGL 2.0 is required."; 39 | printf("%s\n", msg); 40 | 41 | finishCreatingContext(_context); 42 | 43 | return false; 44 | } 45 | 46 | setupGLParameters(); 47 | 48 | finishCreatingContext(_context); 49 | 50 | return true; 51 | } 52 | 53 | bool OpenGL::close(void) { 54 | destroyContext(_context); 55 | 56 | return true; 57 | } 58 | 59 | bool OpenGL::begin(void) { 60 | pushContext(_context); 61 | 62 | return true; 63 | } 64 | 65 | bool OpenGL::end(void) { 66 | popContext(_context); 67 | 68 | return true; 69 | } 70 | 71 | bool OpenGL::isCurrent(void) const { 72 | return isContext(_context); 73 | } 74 | 75 | struct C4GRT_Runtime* OpenGL::getRuntime(void) const { 76 | return _runtime; 77 | } 78 | 79 | void OpenGL::showDriverInfo(void) const { 80 | char device[256]; 81 | memset(device, 0, sizeof(device)); 82 | c4g::gl::OpenGL::getDevice(device, sizeof(device)); 83 | printf("%s", device); 84 | int major, minor; 85 | c4g::gl::OpenGL::getVersion(&major, &minor); 86 | printf("OpenGL Version: %d.%d.\n", major, minor); 87 | } 88 | 89 | const ErrorHandler &OpenGL::getErrorHandler(void) const { 90 | return _errorHandler; 91 | } 92 | 93 | void OpenGL::setErrorHandler(const ErrorHandler &callback) { 94 | _errorHandler = callback; 95 | } 96 | 97 | C4GRT_PassId OpenGL::addPass(C4GRT_PassId prev) { 98 | C4GRT_PassId result = _passIdSeed++; 99 | if (!result) 100 | result = _passIdSeed++; 101 | 102 | _passes[result] = new Pass(this, result); 103 | 104 | Pass* ppass = getPass(prev); 105 | if (ppass) 106 | ppass->next(result); 107 | 108 | if (!_headPass) 109 | _headPass = result; 110 | 111 | return result; 112 | } 113 | 114 | Pass* OpenGL::getPass(C4GRT_PassId id) { 115 | auto it = _passes.find(id); 116 | if (it == _passes.end()) 117 | return nullptr; 118 | 119 | return it->second; 120 | } 121 | 122 | void OpenGL::clearPasses(void) { 123 | for (auto it : _passes) 124 | delete it.second; 125 | _passes.clear(); 126 | } 127 | 128 | bool OpenGL::compute(C4GRT_PassId head, bool mapImm, const ErrorHandler &&callback) { 129 | if (_passes.empty()) return false; 130 | 131 | C4GRT_PassId id = head ? head : _headPass; 132 | while (id) { 133 | Pass* p = getPass(id); 134 | if (!p) break; 135 | auto handler = [=] (const char* const msg) { if (callback != nullptr) { callback(_runtime, id, msg); return true; } return false; }; 136 | if (!p->compute(mapImm, std::move(handler))) 137 | return false; 138 | id = p->next(); 139 | } 140 | 141 | return true; 142 | } 143 | 144 | size_t OpenGL::finishAll(const SimpleErrorHandler &&callback) { 145 | size_t result = 0; 146 | for (auto it : _passes) { 147 | if (it.second->finish(std::move(callback))) 148 | ++result; 149 | } 150 | 151 | return result; 152 | } 153 | 154 | void OpenGL::getDevice(char* device, size_t ds) { 155 | const char* vendor = (const char*)glGetString(GL_VENDOR); 156 | const char* renderer = (const char*)glGetString(GL_RENDERER); 157 | if (vendor && renderer) { 158 | snprintf(device, ds, "Device: %s by %s.\n", renderer, vendor); 159 | } 160 | } 161 | 162 | void OpenGL::getVersion(int* major, int* minor) { 163 | const char* verstr = (const char*)glGetString(GL_VERSION); 164 | if (!verstr || sscanf(verstr, "%d.%d", major, minor) != 2) { 165 | *major = *minor = 0; 166 | fprintf(stderr, "Invalid GL_VERSION format.\n"); 167 | } 168 | } 169 | 170 | void OpenGL::setupGLParameters(void) { 171 | #if !defined C4G_RUNTIME_OS_IOS && !defined C4G_RUNTIME_OS_IOS_SIM 172 | glEnable(GL_TEXTURE_1D); 173 | #endif 174 | glEnable(GL_TEXTURE_2D); 175 | glEnable(GL_TEXTURE_3D); 176 | } 177 | 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /src/runtime/c4g_gl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #ifndef __C4G_GL_H__ 10 | #define __C4G_GL_H__ 11 | 12 | #include "c4g_glpass.hpp" 13 | 14 | namespace c4g { 15 | 16 | namespace gl { 17 | 18 | struct Context; 19 | 20 | class C4G_RUNTIME_IMPL OpenGL final { 21 | 22 | public: 23 | OpenGL(); 24 | ~OpenGL(); 25 | 26 | bool open(struct C4GRT_Runtime* rt); 27 | bool close(void); 28 | 29 | bool begin(void); 30 | bool end(void); 31 | bool isCurrent(void) const; 32 | 33 | struct C4GRT_Runtime* getRuntime(void) const; 34 | void showDriverInfo(void) const; 35 | const ErrorHandler &getErrorHandler(void) const; 36 | void setErrorHandler(const ErrorHandler &callback); 37 | 38 | C4GRT_PassId addPass(C4GRT_PassId prev); 39 | Pass* getPass(C4GRT_PassId id); 40 | void clearPasses(void); 41 | 42 | bool compute(C4GRT_PassId head, bool mapImm = false, const ErrorHandler &&callback = nullptr); 43 | 44 | size_t finishAll(const SimpleErrorHandler &&callback = nullptr); 45 | 46 | static void getDevice(char* device, size_t ds); 47 | static void getVersion(int* major, int* minor); 48 | 49 | private: 50 | void setupGLParameters(void); 51 | 52 | private: 53 | struct C4GRT_Runtime* _runtime = nullptr; 54 | Context* _context = nullptr; 55 | C4GRT_PassId _headPass = 0; 56 | C4GRT_PassId _passIdSeed = 1; 57 | PassDict _passes; 58 | ErrorHandler _errorHandler; 59 | 60 | }; 61 | 62 | } 63 | 64 | } 65 | 66 | #endif /* __C4G_GL_H__ */ 67 | -------------------------------------------------------------------------------- /src/runtime/c4g_glpass.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #ifndef __C4G_GLPASS_H__ 10 | #define __C4G_GLPASS_H__ 11 | 12 | #include "c4g_glsl.hpp" 13 | #include "c4g_utils.hpp" 14 | #include 15 | 16 | namespace c4g { 17 | 18 | namespace gl { 19 | 20 | class OpenGL; 21 | 22 | class C4G_RUNTIME_IMPL Pass final { 23 | 24 | private: 25 | typedef std::map PipeNameDict; 26 | 27 | public: 28 | Pass(OpenGL* owner, C4GRT_PassId id); 29 | ~Pass(); 30 | 31 | const C4GRT_PassId &id(void) const; 32 | C4GRT_PassId &id(void); 33 | 34 | const C4GRT_PassId &next(void) const; 35 | C4GRT_PassId &next(void); 36 | Pass &next(C4GRT_PassId n); 37 | const Pass* nextPass(void) const; 38 | Pass* nextPass(void); 39 | 40 | bool getPipe(void) const; 41 | bool setPipe(bool p, const char* const * const pars, size_t ps); 42 | 43 | bool use(Program &&prog); 44 | bool prepareBuffers(size_t ts, size_t is, size_t os, const SimpleErrorHandler &&callback); 45 | bool prepareTex(const C4GRT_Tex* const pd, size_t ds, const SimpleErrorHandler &&callback); 46 | bool prepareUniform(const C4GRT_Data* const pd, size_t ds, const SimpleErrorHandler &&callback); 47 | bool prepareIn(const C4GRT_Data* const pd, size_t ds, const SimpleErrorHandler &&callback); 48 | bool prepareIn(BufferList &bd, const PipeNameDict &pipes, const SimpleErrorHandler &&callback); 49 | bool prepareOut(const C4GRT_Data* const pd, size_t ds, const SimpleErrorHandler &&callback); 50 | bool compute(bool mapImm, const SimpleErrorHandler &&callback); 51 | bool mapOut(const SimpleErrorHandler &&callback); 52 | bool finish(const SimpleErrorHandler &&callback); 53 | 54 | private: 55 | bool tryCheckError(const SimpleErrorHandler &&callback); 56 | 57 | private: 58 | OpenGL* _owner = nullptr; 59 | C4GRT_PassId _id = 0; 60 | C4GRT_PassId _next = 0; 61 | bool _pipe = false; 62 | PipeNameDict _pipeNames; 63 | GLsizei _pipedCount = 0; 64 | bool _mapped = false; 65 | Program _computeProg; 66 | BufferList _tex; 67 | GLuint _texSlotBegin = 0; 68 | GLuint _vao = 0; 69 | BufferList _in; 70 | BufferList _out; 71 | 72 | }; 73 | 74 | class C4G_RUNTIME_IMPL PassDict final : public std::map { 75 | 76 | public: 77 | PassDict(); 78 | ~PassDict(); 79 | 80 | }; 81 | 82 | } 83 | 84 | } 85 | 86 | #endif /* __C4G_GLPASS_H__ */ 87 | -------------------------------------------------------------------------------- /src/runtime/c4g_glsl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_glsl.hpp" 10 | #include 11 | 12 | namespace c4g { 13 | 14 | namespace gl { 15 | 16 | Shader::Shader() { 17 | } 18 | 19 | Shader::Shader(ShaderTypes type) : _type(type) { 20 | } 21 | 22 | Shader::~Shader() { 23 | if (_code) 24 | free(_code); 25 | } 26 | 27 | bool Shader::readFile(const char* const file) { 28 | // Gets file length. 29 | FILE* fp = fopen(file, "rb"); 30 | int l = -1; 31 | if (!fp) 32 | return false; 33 | 34 | fseek(fp, 0, SEEK_END); 35 | l = (int)(ftell(fp) + 1); 36 | 37 | // Reads code. 38 | _code = (GLchar*)malloc(sizeof(GLchar) * l); 39 | 40 | // Get the shader from a file. 41 | fseek(fp, 0, SEEK_SET); 42 | l = (int)fread(_code, sizeof(GLchar), l, fp); 43 | _code[l] = '\0'; 44 | 45 | if (ferror(fp)) 46 | l = 0; 47 | 48 | fclose(fp); 49 | 50 | if (!l) { 51 | printf("Cannot read the file %s.\n", file); 52 | 53 | return false; 54 | } 55 | 56 | return true; 57 | } 58 | 59 | bool Shader::readString(const char* const str) { 60 | if (!str) 61 | return false; 62 | 63 | #ifdef C4G_RUNTIME_OS_WIN 64 | _code = _strdup(str); 65 | #else /* C4G_RUNTIME_OS_WIN */ 66 | _code = strdup(str); 67 | #endif /* C4G_RUNTIME_OS_WIN */ 68 | 69 | return true; 70 | } 71 | 72 | bool Shader::compile(const SimpleErrorHandler &&callback) { 73 | if (!_code) return false; 74 | 75 | GLint status = 0; 76 | 77 | switch (_type) { 78 | case ST_VERT: 79 | _object = glCreateShader(GL_VERTEX_SHADER); 80 | 81 | break; 82 | case ST_FRAG: 83 | _object = glCreateShader(GL_FRAGMENT_SHADER); 84 | 85 | break; 86 | default: 87 | return false; 88 | } 89 | 90 | glShaderSource(_object, 1, &_code, nullptr); 91 | 92 | glCompileShader(_object); 93 | glGetShaderiv(_object, GL_COMPILE_STATUS, &status); 94 | 95 | if (status != GL_TRUE) { 96 | char errorLog[1024]; 97 | GLsizei len = 0; 98 | glGetShaderInfoLog(_object, sizeof(errorLog), &len, errorLog); 99 | if (callback != nullptr) 100 | callback(errorLog); 101 | else 102 | printf("%s\n", errorLog); 103 | 104 | return false; 105 | } 106 | 107 | return true; 108 | } 109 | 110 | GLuint Shader::object(void) { 111 | return _object; 112 | } 113 | 114 | Program::Program() { 115 | } 116 | 117 | Program::~Program() { 118 | if (_prog) { 119 | glDeleteProgram(_prog); 120 | _prog = 0; 121 | } 122 | } 123 | 124 | bool Program::link(Shader &&vert, Shader &&frag) { 125 | GLint linked = 0; 126 | 127 | std::swap(_vert, vert); 128 | std::swap(_frag, frag); 129 | 130 | _prog = glCreateProgram(); 131 | glAttachShader(_prog, _vert.object()); 132 | glAttachShader(_prog, _frag.object()); 133 | 134 | glLinkProgram(_prog); 135 | glGetProgramiv(_prog, GL_LINK_STATUS, &linked); 136 | 137 | glDetachShader(_prog, _vert.object()); 138 | glDetachShader(_prog, _frag.object()); 139 | glDeleteShader(_vert.object()); 140 | glDeleteShader(_frag.object()); 141 | 142 | if (!linked) 143 | return false; 144 | 145 | return true; 146 | } 147 | 148 | bool Program::link(Shader &&vert, Shader &&frag, const char* const varyings[], size_t vs) { 149 | GLint linked = 0; 150 | 151 | std::swap(_vert, vert); 152 | std::swap(_frag, frag); 153 | 154 | _prog = glCreateProgram(); 155 | glAttachShader(_prog, _vert.object()); 156 | glAttachShader(_prog, _frag.object()); 157 | 158 | glTransformFeedbackVaryings(_prog, (GLsizei)vs, varyings, GL_SEPARATE_ATTRIBS); 159 | 160 | glLinkProgram(_prog); 161 | glGetProgramiv(_prog, GL_LINK_STATUS, &linked); 162 | 163 | glDetachShader(_prog, _vert.object()); 164 | glDetachShader(_prog, _frag.object()); 165 | glDeleteShader(_vert.object()); 166 | glDeleteShader(_frag.object()); 167 | 168 | if (!linked) 169 | return false; 170 | 171 | return true; 172 | } 173 | 174 | bool Program::use(void) { 175 | glUseProgram(_prog); 176 | 177 | return true; 178 | } 179 | 180 | GLint Program::attributeLocation(const char* const name) { 181 | return glGetAttribLocation(_prog, name); 182 | } 183 | 184 | GLint Program::uniformLocation(const char* const name) { 185 | return glGetUniformLocation(_prog, name); 186 | } 187 | 188 | void Program::uniform(int loc, float f0) { 189 | glUniform1f((GLint)loc, f0); 190 | } 191 | 192 | void Program::uniform(int loc, float f0, float f1) { 193 | glUniform2f((GLint)loc, f0, f1); 194 | } 195 | 196 | void Program::uniform(int loc, float f0, float f1, float f2) { 197 | glUniform3f((GLint)loc, f0, f1, f2); 198 | } 199 | 200 | void Program::uniform(int loc, float f0, float f1, float f2, float f3) { 201 | glUniform4f((GLint)loc, f0, f1, f2, f3); 202 | } 203 | 204 | void Program::uniform(int loc, int i0) { 205 | glUniform1i((GLint)loc, i0); 206 | } 207 | 208 | void Program::uniform(int loc, int i0, int i1) { 209 | glUniform2i((GLint)loc, i0, i1); 210 | } 211 | 212 | void Program::uniform(int loc, int i0, int i1, int i2) { 213 | glUniform3i((GLint)loc, i0, i1, i2); 214 | } 215 | 216 | void Program::uniform(int loc, int i0, int i1, int i2, int i3) { 217 | glUniform4i((GLint)loc, i0, i1, i2, i3); 218 | } 219 | 220 | GLuint Program::object(void) { 221 | return _prog; 222 | } 223 | 224 | } 225 | 226 | } 227 | -------------------------------------------------------------------------------- /src/runtime/c4g_glsl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #ifndef __C4G_GLSL_H__ 10 | #define __C4G_GLSL_H__ 11 | 12 | #include "c4g_runtime.h" 13 | #ifdef C4G_RUNTIME_OS_WIN 14 | # include 15 | # include 16 | #elif defined C4G_RUNTIME_OS_APPLE 17 | # if defined C4G_RUNTIME_OS_IOS || defined C4G_RUNTIME_OS_IOS_SIM 18 | # include 19 | # else 20 | # include 21 | # endif 22 | #elif defined C4G_RUNTIME_OS_LINUX 23 | # include 24 | # include 25 | # include 26 | # include 27 | # include 28 | #endif /* C4G_RUNTIME_OS_WIN */ 29 | #include 30 | #include 31 | 32 | #ifndef GL_INVALID_INDEX 33 | # define GL_INVALID_INDEX -1 34 | #endif /* GL_INVALID_INDEX */ 35 | 36 | namespace c4g { 37 | 38 | namespace gl { 39 | 40 | typedef std::vector GLuintArray; 41 | 42 | typedef std::function ErrorHandler; 43 | 44 | typedef std::function SimpleErrorHandler; 45 | 46 | enum ShaderTypes { 47 | ST_NONE, 48 | ST_VERT, 49 | ST_FRAG 50 | }; 51 | 52 | class C4G_RUNTIME_IMPL Shader final { 53 | 54 | public: 55 | Shader(); 56 | Shader(ShaderTypes type); 57 | ~Shader(); 58 | 59 | bool readFile(const char* const file); 60 | bool readString(const char* const str); 61 | bool compile(const SimpleErrorHandler &&callback); 62 | 63 | GLuint object(void); 64 | 65 | private: 66 | ShaderTypes _type = ST_NONE; 67 | GLchar* _code = nullptr; 68 | GLuint _object = 0; 69 | 70 | }; 71 | 72 | class C4G_RUNTIME_IMPL Program final { 73 | 74 | public: 75 | Program(); 76 | ~Program(); 77 | 78 | bool link(Shader &&vert, Shader &&frag); 79 | bool link(Shader &&vert, Shader &&frag, const char* const varyings[], size_t vs); 80 | bool use(void); 81 | 82 | GLint attributeLocation(const char* const name); 83 | GLint uniformLocation(const char* const name); 84 | void uniform(int loc, float f0); 85 | void uniform(int loc, float f0, float f1); 86 | void uniform(int loc, float f0, float f1, float f2); 87 | void uniform(int loc, float f0, float f1, float f2, float f3); 88 | void uniform(int loc, int i0); 89 | void uniform(int loc, int i0, int i1); 90 | void uniform(int loc, int i0, int i1, int i2); 91 | void uniform(int loc, int i0, int i1, int i2, int i3); 92 | 93 | GLuint object(void); 94 | 95 | private: 96 | Shader _vert; 97 | Shader _frag; 98 | GLuint _prog = 0; 99 | 100 | }; 101 | 102 | } 103 | 104 | } 105 | 106 | #endif /* __C4G_GLSL_H__ */ 107 | -------------------------------------------------------------------------------- /src/runtime/c4g_runtime.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_gl.hpp" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | #define C4GRT_FRAG_SHADER "#version 300 es\n\nvoid main() {\n}\n" 16 | 17 | #define C4GRT_CONTEXT_ACTIVED_MESSAGE "The context is already actived." 18 | #define C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE "The context is not actived." 19 | 20 | typedef struct C4GRT_Runtime { 21 | c4g::gl::OpenGL _gl; 22 | } C4GRT_Runtime; 23 | 24 | C4G_RUNTIME_IMPL static bool _on_error(struct C4GRT_Runtime* rt, C4GRT_PassId pass, const char* const msg) { 25 | auto callback = rt->_gl.getErrorHandler(); 26 | if (callback != nullptr) { 27 | callback(rt, pass, msg); 28 | 29 | return true; 30 | } 31 | 32 | return false; 33 | } 34 | 35 | struct C4GRT_Runtime* c4grt_open(void) { 36 | C4GRT_Runtime* result = new C4GRT_Runtime(); 37 | if (result) 38 | result->_gl.open(result); 39 | 40 | return result; 41 | } 42 | 43 | void c4grt_close(struct C4GRT_Runtime* rt) { 44 | if (!rt) return; 45 | 46 | rt->_gl.close(); 47 | delete rt; 48 | } 49 | 50 | C4GRT_States c4grt_begin(struct C4GRT_Runtime* rt) { 51 | if (!rt) return ST_INVALID_ARGUMENT; 52 | 53 | if (rt->_gl.isCurrent()) { 54 | _on_error(rt, 0, C4GRT_CONTEXT_ACTIVED_MESSAGE); 55 | 56 | return ST_CONTEXT_ACTIVED; 57 | } 58 | 59 | rt->_gl.begin(); 60 | 61 | return ST_OK; 62 | } 63 | 64 | C4GRT_States c4grt_end(struct C4GRT_Runtime* rt) { 65 | if (!rt) return ST_INVALID_ARGUMENT; 66 | 67 | if (!rt->_gl.isCurrent()) { 68 | _on_error(rt, 0, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 69 | 70 | return ST_CONTEXT_NOT_ACTIVED; 71 | } 72 | 73 | rt->_gl.end(); 74 | 75 | return ST_OK; 76 | } 77 | 78 | C4GRT_States c4grt_set_error_handler(struct C4GRT_Runtime* rt, C4GRT_ErrorHandler callback) { 79 | if (!rt) return ST_INVALID_ARGUMENT; 80 | 81 | if (!rt->_gl.isCurrent()) { 82 | _on_error(rt, 0, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 83 | 84 | return ST_CONTEXT_NOT_ACTIVED; 85 | } 86 | 87 | rt->_gl.setErrorHandler(callback); 88 | 89 | return ST_OK; 90 | } 91 | 92 | C4G_RUNTIME_API C4GRT_States c4grt_set_error_handler_plusplus(struct C4GRT_Runtime* rt, const std::function &callback) { 93 | if (!rt) return ST_INVALID_ARGUMENT; 94 | 95 | if (!rt->_gl.isCurrent()) { 96 | _on_error(rt, 0, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 97 | 98 | return ST_CONTEXT_NOT_ACTIVED; 99 | } 100 | 101 | rt->_gl.setErrorHandler(callback); 102 | 103 | return ST_OK; 104 | } 105 | 106 | C4GRT_States c4grt_show_driver_info(struct C4GRT_Runtime* rt) { 107 | if (!rt) return ST_INVALID_ARGUMENT; 108 | 109 | if (!rt->_gl.isCurrent()) { 110 | _on_error(rt, 0, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 111 | 112 | return ST_CONTEXT_NOT_ACTIVED; 113 | } 114 | 115 | rt->_gl.showDriverInfo(); 116 | 117 | return ST_OK; 118 | } 119 | 120 | C4GRT_PassId c4grt_add_pass(struct C4GRT_Runtime* rt, C4GRT_PassId prev) { 121 | if (!rt) return 0; 122 | 123 | if (!rt->_gl.isCurrent()) { 124 | _on_error(rt, 0, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 125 | 126 | return 0; 127 | } 128 | 129 | return rt->_gl.addPass(prev); 130 | } 131 | 132 | C4GRT_States c4grt_set_pass_flow(struct C4GRT_Runtime* rt, C4GRT_PassId pass, C4GRT_PassId next) { 133 | if (!rt) return ST_INVALID_ARGUMENT; 134 | 135 | if (!rt->_gl.isCurrent()) { 136 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 137 | 138 | return ST_CONTEXT_NOT_ACTIVED; 139 | } 140 | 141 | c4g::gl::Pass* ppass = rt->_gl.getPass(pass); 142 | if (!ppass) return ST_INVALID_ARGUMENT; 143 | if (next) { 144 | c4g::gl::Pass* npass = rt->_gl.getPass(next); 145 | if (npass) ppass->next(next); 146 | else ppass->next(0); 147 | } else { 148 | ppass->next(0); 149 | } 150 | 151 | return ST_OK; 152 | } 153 | 154 | C4GRT_States c4grt_set_pass_pipe(struct C4GRT_Runtime* rt, C4GRT_PassId pass, C4GRT_Bool pipe, const char* const * const pars, size_t ps) { 155 | if (!rt) return ST_INVALID_ARGUMENT; 156 | if (!pass) return ST_INVALID_ARGUMENT; 157 | 158 | if (!rt->_gl.isCurrent()) { 159 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 160 | 161 | return ST_CONTEXT_NOT_ACTIVED; 162 | } 163 | 164 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 165 | if (!p) return ST_INVALID_ARGUMENT; 166 | if (pipe) { 167 | c4g::gl::Pass* f = rt->_gl.getPass(p->next()); 168 | if (!f) return ST_INVALID_ARGUMENT; 169 | p->setPipe(true, pars, ps); 170 | } else { 171 | p->setPipe(false, pars, ps); 172 | } 173 | 174 | return ST_OK; 175 | } 176 | 177 | C4GRT_States c4grt_use_gpu_program_file(struct C4GRT_Runtime* rt, C4GRT_PassId pass, const char* const f, const char* const varyings[], size_t vs) { 178 | if (!rt) return ST_INVALID_ARGUMENT; 179 | if (!f) return ST_INVALID_ARGUMENT; 180 | 181 | if (!rt->_gl.isCurrent()) { 182 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 183 | 184 | return ST_CONTEXT_NOT_ACTIVED; 185 | } 186 | 187 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 188 | if (!p) return ST_INVALID_ARGUMENT; 189 | 190 | C4GRT_States result = ST_OK; 191 | 192 | c4g::gl::Shader vert(c4g::gl::ST_VERT); 193 | vert.readFile(f); 194 | vert.compile([&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 195 | 196 | c4g::gl::Shader frag(c4g::gl::ST_FRAG); 197 | frag.readString(C4GRT_FRAG_SHADER); 198 | frag.compile([&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 199 | 200 | c4g::gl::Program comp; 201 | comp.link(std::move(vert), std::move(frag), varyings, vs); 202 | comp.use(); 203 | 204 | p->use(std::move(comp)); 205 | 206 | return result; 207 | } 208 | 209 | C4GRT_States c4grt_use_gpu_program_string(struct C4GRT_Runtime* rt, C4GRT_PassId pass, const char* const c, const char* const varyings[], size_t vs) { 210 | if (!rt) return ST_INVALID_ARGUMENT; 211 | if (!c) return ST_INVALID_ARGUMENT; 212 | 213 | if (!rt->_gl.isCurrent()) { 214 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 215 | 216 | return ST_CONTEXT_NOT_ACTIVED; 217 | } 218 | 219 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 220 | if (!p) return ST_INVALID_ARGUMENT; 221 | 222 | C4GRT_States result = ST_OK; 223 | 224 | c4g::gl::Shader vert(c4g::gl::ST_VERT); 225 | vert.readString(c); 226 | vert.compile([&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 227 | 228 | c4g::gl::Shader frag(c4g::gl::ST_FRAG); 229 | frag.readString(C4GRT_FRAG_SHADER); 230 | frag.compile([&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 231 | 232 | c4g::gl::Program comp; 233 | comp.link(std::move(vert), std::move(frag), varyings, vs); 234 | comp.use(); 235 | 236 | p->use(std::move(comp)); 237 | 238 | return result; 239 | } 240 | 241 | C4GRT_States c4grt_prepare_buffers(struct C4GRT_Runtime* rt, C4GRT_PassId pass, size_t ts, size_t is, size_t os) { 242 | if (!rt) return ST_INVALID_ARGUMENT; 243 | 244 | if (!rt->_gl.isCurrent()) { 245 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 246 | 247 | return ST_CONTEXT_NOT_ACTIVED; 248 | } 249 | 250 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 251 | if (!p) return ST_INVALID_ARGUMENT; 252 | 253 | C4GRT_States result = ST_OK; 254 | 255 | p->prepareBuffers(ts, is, os, [&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 256 | 257 | return result; 258 | } 259 | 260 | C4GRT_States c4grt_prepare_tex(struct C4GRT_Runtime* rt, C4GRT_PassId pass, const C4GRT_Tex* const pd, size_t ds) { 261 | if (!rt) return ST_INVALID_ARGUMENT; 262 | 263 | if (!rt->_gl.isCurrent()) { 264 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 265 | 266 | return ST_CONTEXT_NOT_ACTIVED; 267 | } 268 | 269 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 270 | if (!p) return ST_INVALID_ARGUMENT; 271 | 272 | C4GRT_States result = ST_OK; 273 | 274 | p->prepareTex(pd, ds, [&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 275 | 276 | return result; 277 | } 278 | 279 | C4GRT_States c4grt_prepare_uniform(struct C4GRT_Runtime* rt, C4GRT_PassId pass, const C4GRT_Data* const pd, size_t ds) { 280 | if (!rt) return ST_INVALID_ARGUMENT; 281 | if (!pd) return ST_INVALID_ARGUMENT; 282 | 283 | if (!rt->_gl.isCurrent()) { 284 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 285 | 286 | return ST_CONTEXT_NOT_ACTIVED; 287 | } 288 | 289 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 290 | if (!p) return ST_INVALID_ARGUMENT; 291 | 292 | C4GRT_States result = ST_OK; 293 | 294 | p->prepareUniform(pd, ds, [&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 295 | 296 | return result; 297 | } 298 | 299 | C4GRT_States c4grt_prepare_in(struct C4GRT_Runtime* rt, C4GRT_PassId pass, const C4GRT_Data* const pd, size_t ds) { 300 | if (!rt) return ST_INVALID_ARGUMENT; 301 | if (!pd || !ds) return ST_INVALID_ARGUMENT; 302 | 303 | if (!rt->_gl.isCurrent()) { 304 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 305 | 306 | return ST_CONTEXT_NOT_ACTIVED; 307 | } 308 | 309 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 310 | if (!p) return ST_INVALID_ARGUMENT; 311 | 312 | C4GRT_States result = ST_OK; 313 | 314 | p->prepareIn(pd, ds, [&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 315 | 316 | return result; 317 | } 318 | 319 | C4GRT_States c4grt_prepare_out(struct C4GRT_Runtime* rt, C4GRT_PassId pass, const C4GRT_Data* const pd, size_t ds) { 320 | if (!rt) return ST_INVALID_ARGUMENT; 321 | if (!pd || !ds) return ST_INVALID_ARGUMENT; 322 | 323 | if (!rt->_gl.isCurrent()) { 324 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 325 | 326 | return ST_CONTEXT_NOT_ACTIVED; 327 | } 328 | 329 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 330 | if (!p) return ST_INVALID_ARGUMENT; 331 | 332 | C4GRT_States result = ST_OK; 333 | 334 | p->prepareOut(pd, ds, [&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 335 | 336 | return result; 337 | } 338 | 339 | C4GRT_States c4grt_compute(struct C4GRT_Runtime* rt, C4GRT_PassId head, C4GRT_Bool mapimm) { 340 | if (!rt) return ST_INVALID_ARGUMENT; 341 | 342 | if (!rt->_gl.isCurrent()) { 343 | _on_error(rt, head, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 344 | 345 | return ST_CONTEXT_NOT_ACTIVED; 346 | } 347 | 348 | rt->_gl.compute(head, !!mapimm, std::move(rt->_gl.getErrorHandler())); 349 | 350 | return ST_OK; 351 | } 352 | 353 | C4GRT_States c4grt_map_out(struct C4GRT_Runtime* rt, C4GRT_PassId pass) { 354 | if (!rt) return ST_INVALID_ARGUMENT; 355 | 356 | if (!rt->_gl.isCurrent()) { 357 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 358 | 359 | return ST_CONTEXT_NOT_ACTIVED; 360 | } 361 | 362 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 363 | if (!p) return ST_INVALID_ARGUMENT; 364 | 365 | C4GRT_States result = ST_OK; 366 | 367 | p->mapOut([&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 368 | 369 | return result; 370 | } 371 | 372 | C4GRT_States c4grt_finish(struct C4GRT_Runtime* rt, C4GRT_PassId pass) { 373 | if (!rt) return ST_INVALID_ARGUMENT; 374 | 375 | if (!rt->_gl.isCurrent()) { 376 | _on_error(rt, pass, C4GRT_CONTEXT_NOT_ACTIVED_MESSAGE); 377 | 378 | return ST_CONTEXT_NOT_ACTIVED; 379 | } 380 | 381 | C4GRT_States result = ST_OK; 382 | 383 | if (pass) { 384 | c4g::gl::Pass* p = rt->_gl.getPass(pass); 385 | if (!p) return ST_INVALID_ARGUMENT; 386 | 387 | p->finish([&] (const char* const msg) { result = ST_ERROR_OCCURED; return _on_error(rt, pass, msg); }); 388 | } else { 389 | rt->_gl.finishAll(); 390 | } 391 | 392 | return result; 393 | } 394 | 395 | size_t c4grt_data_count(const C4GRT_Data* const pd) { 396 | if (!pd) return 0; 397 | 398 | return pd->_count; 399 | } 400 | 401 | size_t c4grt_data_size(const C4GRT_Data* const pd) { 402 | if (!pd) return 0; 403 | 404 | return pd->_count * pd->_sizePerElement; 405 | } 406 | 407 | size_t c4grt_data_size_per_element(const C4GRT_Data* const pd) { 408 | if (!pd) return 0; 409 | 410 | return pd->_sizePerElement; 411 | } 412 | 413 | #ifdef __cplusplus 414 | } 415 | #endif /* __cplusplus */ 416 | -------------------------------------------------------------------------------- /src/runtime/c4g_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_utils.hpp" 10 | #ifdef C4G_RUNTIME_OS_WIN 11 | # include 12 | #elif defined C4G_RUNTIME_OS_APPLE 13 | # if defined C4G_RUNTIME_OS_IOS || defined C4G_RUNTIME_OS_IOS_SIM 14 | # include 15 | # else 16 | # include 17 | # endif 18 | #else 19 | # include 20 | #endif /* C4G_RUNTIME_OS_WIN */ 21 | #include 22 | 23 | namespace c4g { 24 | 25 | namespace gl { 26 | 27 | Buffer::Buffer() { 28 | memset(_bytes, 0, sizeof(_bytes)); 29 | _pointer = _bytes; 30 | } 31 | 32 | Buffer::Buffer(Buffer &&o) { 33 | _type = o._type; 34 | _allocated = o._allocated; 35 | _size = o._size; 36 | _sizePerElement = o._sizePerElement; 37 | memcpy(_bytes, o._bytes, sizeof(_bytes)); 38 | if (o._pointer == o._bytes) _pointer = _bytes; 39 | else _pointer = o._pointer; 40 | _mapped = o._mapped; 41 | _name = o._name; 42 | _id = o._id; 43 | 44 | o._type = DT_INVALID; 45 | o._allocated = 0; 46 | o._size = 0; 47 | o._sizePerElement = 0; 48 | o._pointer = nullptr; 49 | o._mapped = false; 50 | o._name.clear(); 51 | o._id = 0; 52 | } 53 | 54 | Buffer::~Buffer() { 55 | tidy(); 56 | } 57 | 58 | Buffer &Buffer::operator = (Buffer &&o) { 59 | _type = o._type; 60 | _allocated = o._allocated; 61 | _size = o._size; 62 | _sizePerElement = o._sizePerElement; 63 | memcpy(_bytes, o._bytes, sizeof(_bytes)); 64 | if (o._pointer == o._bytes) _pointer = _bytes; 65 | else _pointer = o._pointer; 66 | _mapped = o._mapped; 67 | _name = o._name; 68 | _id = o._id; 69 | 70 | o._type = DT_INVALID; 71 | o._allocated = 0; 72 | o._size = 0; 73 | o._sizePerElement = 0; 74 | o._pointer = nullptr; 75 | o._mapped = false; 76 | o._name.clear(); 77 | o._id = 0; 78 | 79 | return *this; 80 | } 81 | 82 | size_t Buffer::map(const C4GRT_Data &in) { 83 | tidy(); 84 | _type = in._type; 85 | _mapped = true; 86 | _pointer = in._bytes; 87 | _size = c4grt_data_size(&in); 88 | _sizePerElement = c4grt_data_size_per_element(&in); 89 | if (in._name) _name = in._name; 90 | else _name.clear(); 91 | 92 | return _size; 93 | } 94 | 95 | size_t Buffer::fill(const Byte* const in, size_t is) { 96 | size_t ret = std::min(_size, is); 97 | memcpy(_pointer, in, ret); 98 | 99 | return ret; 100 | } 101 | 102 | void Buffer::resize(size_t s, size_t es) { 103 | if (_mapped) 104 | tidy(); 105 | if (_pointer == _bytes) { 106 | if (s <= C4GRT_BUFFER_SIZE) { 107 | _size = s; 108 | } else { 109 | _pointer = (unsigned char*)malloc(s); 110 | _allocated = s; 111 | _size = s; 112 | } 113 | } else { 114 | if (s <= _allocated) { 115 | _size = s; 116 | } else { 117 | _pointer = (unsigned char*)realloc(_pointer, s); 118 | _allocated = s; 119 | _size = s; 120 | } 121 | } 122 | _sizePerElement = es; 123 | } 124 | 125 | size_t Buffer::count(void) const { 126 | return _size / _sizePerElement; 127 | } 128 | 129 | size_t Buffer::size(void) const { 130 | return _size; 131 | } 132 | 133 | size_t Buffer::sizePerElement(void) const { 134 | return _sizePerElement; 135 | } 136 | 137 | size_t Buffer::countOfGLfloat(void) const { 138 | return _size / sizeof(GLfloat); 139 | } 140 | 141 | size_t Buffer::countOfGLint(void) const { 142 | return _size / sizeof(GLint); 143 | } 144 | 145 | C4GRT_DataTypes Buffer::type(void) const { 146 | return _type; 147 | } 148 | 149 | unsigned char* Buffer::ptr(void) const { 150 | return _pointer; 151 | } 152 | 153 | const char* Buffer::name(void) const { 154 | if (_name.empty()) return nullptr; 155 | 156 | return _name.c_str(); 157 | } 158 | 159 | const UInt &Buffer::id(void) const { 160 | return _id; 161 | } 162 | 163 | UInt &Buffer::id(void) { 164 | return _id; 165 | } 166 | 167 | void Buffer::tidy(void) { 168 | _type = DT_INVALID; 169 | if (!_mapped && _pointer != _bytes) 170 | free(_pointer); 171 | _allocated = _size = 0; 172 | _sizePerElement = 0; 173 | _pointer = _bytes; 174 | _mapped = false; 175 | } 176 | 177 | BufferList::BufferList() { 178 | } 179 | 180 | BufferList::~BufferList() { 181 | } 182 | 183 | BufferList &BufferList::push(void) { 184 | _list.push_back(Buffer()); 185 | 186 | return *this; 187 | } 188 | 189 | BufferList &BufferList::clear(void) { 190 | _list.clear(); 191 | 192 | return *this; 193 | } 194 | 195 | bool BufferList::empty(void) const { 196 | return _list.empty(); 197 | } 198 | 199 | size_t BufferList::count(void) const { 200 | return _list.size(); 201 | } 202 | 203 | size_t BufferList::totalSize(void) const { 204 | size_t result = 0; 205 | for (const Buffer &b : _list) 206 | result += b.size(); 207 | 208 | return result; 209 | } 210 | 211 | size_t BufferList::sizePerElement(void) const { 212 | size_t result = 0; 213 | for (const Buffer &b : _list) 214 | result += b.sizePerElement(); 215 | 216 | return result; 217 | } 218 | 219 | const Buffer &BufferList::front(void) const { 220 | return _list.front(); 221 | } 222 | 223 | Buffer &BufferList::front(void) { 224 | return _list.front(); 225 | } 226 | 227 | const Buffer &BufferList::back(void) const { 228 | return _list.back(); 229 | } 230 | 231 | Buffer &BufferList::back(void) { 232 | return _list.back(); 233 | } 234 | 235 | BufferList::List::iterator BufferList::begin(void) { 236 | return _list.begin(); 237 | } 238 | 239 | BufferList::List::const_iterator BufferList::begin(void) const { 240 | return _list.begin(); 241 | } 242 | 243 | BufferList::List::iterator BufferList::end(void) { 244 | return _list.end(); 245 | } 246 | 247 | BufferList::List::const_iterator BufferList::end(void) const { 248 | return _list.end(); 249 | } 250 | 251 | } 252 | 253 | } 254 | -------------------------------------------------------------------------------- /src/runtime/c4g_utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #ifndef __C4G_UTILS_H__ 10 | #define __C4G_UTILS_H__ 11 | 12 | #include "c4g_runtime.h" 13 | #include 14 | #include 15 | #include 16 | 17 | #ifndef C4G_COUNTOF 18 | # define C4G_COUNTOF(__a) (sizeof(__a) / sizeof(*(__a))) 19 | #endif /* C4G_COUNTOF */ 20 | 21 | #ifndef C4GRT_BUFFER_SIZE 22 | # define C4GRT_BUFFER_SIZE (1024 * 64) 23 | #endif /* C4GRT_BUFFER_SIZE */ 24 | 25 | namespace c4g { 26 | 27 | namespace gl { 28 | 29 | typedef unsigned char Byte; 30 | 31 | typedef unsigned int UInt; 32 | 33 | class C4G_RUNTIME_IMPL Buffer final { 34 | 35 | public: 36 | Buffer(); 37 | Buffer(Buffer &&o); 38 | ~Buffer(); 39 | 40 | Buffer &operator = (Buffer &&o); 41 | 42 | size_t map(const C4GRT_Data &in); 43 | size_t fill(const Byte* const in, size_t is); 44 | 45 | void resize(size_t s, size_t es); 46 | size_t count(void) const; 47 | size_t size(void) const; 48 | size_t sizePerElement(void) const; 49 | size_t countOfGLfloat(void) const; 50 | size_t countOfGLint(void) const; 51 | 52 | C4GRT_DataTypes type(void) const; 53 | 54 | unsigned char* ptr(void) const; 55 | template T* ptr(void) const { 56 | return static_cast(ptr()); 57 | } 58 | 59 | const char* name(void) const; 60 | 61 | const UInt &id(void) const; 62 | UInt &id(void); 63 | 64 | private: 65 | void tidy(void); 66 | 67 | private: 68 | C4GRT_DataTypes _type = DT_INVALID; 69 | size_t _allocated = 0; 70 | size_t _size = 0; 71 | size_t _sizePerElement = 0; 72 | unsigned char _bytes[C4GRT_BUFFER_SIZE]; 73 | unsigned char* _pointer = nullptr; 74 | bool _mapped = false; 75 | std::string _name; 76 | UInt _id = 0; 77 | 78 | }; 79 | 80 | class C4G_RUNTIME_IMPL BufferList final { 81 | 82 | public: 83 | typedef std::list List; 84 | 85 | public: 86 | BufferList(); 87 | ~BufferList(); 88 | 89 | BufferList &push(void); 90 | BufferList &clear(void); 91 | bool empty(void) const; 92 | size_t count(void) const; 93 | size_t totalSize(void) const; 94 | size_t sizePerElement(void) const; 95 | 96 | const Buffer &front(void) const; 97 | Buffer &front(void); 98 | const Buffer &back(void) const; 99 | Buffer &back(void); 100 | 101 | List::iterator begin(void); 102 | List::const_iterator begin(void) const; 103 | List::iterator end(void); 104 | List::const_iterator end(void) const; 105 | 106 | private: 107 | List _list; 108 | 109 | }; 110 | 111 | } 112 | 113 | } 114 | 115 | #endif /* __C4G_UTILS_H__ */ 116 | -------------------------------------------------------------------------------- /src/runtime/freeglut/Copying.txt: -------------------------------------------------------------------------------- 1 | 2 | Freeglut Copyright 3 | ------------------ 4 | 5 | Freeglut code without an explicit copyright is covered by the following 6 | copyright: 7 | 8 | Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies or substantial portions of the Software. 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 | PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | Except as contained in this notice, the name of Pawel W. Olszta shall not be 26 | used in advertising or otherwise to promote the sale, use or other dealings 27 | in this Software without prior written authorization from Pawel W. Olszta. 28 | -------------------------------------------------------------------------------- /src/runtime/freeglut/Readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/freeglut/Readme.txt -------------------------------------------------------------------------------- /src/runtime/freeglut/bin/freeglut.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/freeglut/bin/freeglut.dll -------------------------------------------------------------------------------- /src/runtime/freeglut/bin/x64/freeglut.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/freeglut/bin/x64/freeglut.dll -------------------------------------------------------------------------------- /src/runtime/freeglut/include/GL/freeglut.h: -------------------------------------------------------------------------------- 1 | #ifndef __FREEGLUT_H__ 2 | #define __FREEGLUT_H__ 3 | 4 | /* 5 | * freeglut.h 6 | * 7 | * The freeglut library include file 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 10 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 12 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | */ 16 | 17 | #include "freeglut_std.h" 18 | #include "freeglut_ext.h" 19 | 20 | /*** END OF FILE ***/ 21 | 22 | #endif /* __FREEGLUT_H__ */ 23 | -------------------------------------------------------------------------------- /src/runtime/freeglut/include/GL/freeglut_ext.h: -------------------------------------------------------------------------------- 1 | #ifndef __FREEGLUT_EXT_H__ 2 | #define __FREEGLUT_EXT_H__ 3 | 4 | /* 5 | * freeglut_ext.h 6 | * 7 | * The non-GLUT-compatible extensions to the freeglut library include file 8 | * 9 | * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. 10 | * Written by Pawel W. Olszta, 11 | * Creation date: Thu Dec 2 1999 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a 14 | * copy of this software and associated documentation files (the "Software"), 15 | * to deal in the Software without restriction, including without limitation 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | * and/or sell copies of the Software, and to permit persons to whom the 18 | * Software is furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included 21 | * in all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 27 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 28 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* 36 | * Additional GLUT Key definitions for the Special key function 37 | */ 38 | #define GLUT_KEY_NUM_LOCK 0x006D 39 | #define GLUT_KEY_BEGIN 0x006E 40 | #define GLUT_KEY_DELETE 0x006F 41 | #define GLUT_KEY_SHIFT_L 0x0070 42 | #define GLUT_KEY_SHIFT_R 0x0071 43 | #define GLUT_KEY_CTRL_L 0x0072 44 | #define GLUT_KEY_CTRL_R 0x0073 45 | #define GLUT_KEY_ALT_L 0x0074 46 | #define GLUT_KEY_ALT_R 0x0075 47 | 48 | /* 49 | * GLUT API Extension macro definitions -- behaviour when the user clicks on an "x" to close a window 50 | */ 51 | #define GLUT_ACTION_EXIT 0 52 | #define GLUT_ACTION_GLUTMAINLOOP_RETURNS 1 53 | #define GLUT_ACTION_CONTINUE_EXECUTION 2 54 | 55 | /* 56 | * Create a new rendering context when the user opens a new window? 57 | */ 58 | #define GLUT_CREATE_NEW_CONTEXT 0 59 | #define GLUT_USE_CURRENT_CONTEXT 1 60 | 61 | /* 62 | * Direct/Indirect rendering context options (has meaning only in Unix/X11) 63 | */ 64 | #define GLUT_FORCE_INDIRECT_CONTEXT 0 65 | #define GLUT_ALLOW_DIRECT_CONTEXT 1 66 | #define GLUT_TRY_DIRECT_CONTEXT 2 67 | #define GLUT_FORCE_DIRECT_CONTEXT 3 68 | 69 | /* 70 | * GLUT API Extension macro definitions -- the glutGet parameters 71 | */ 72 | #define GLUT_INIT_STATE 0x007C 73 | 74 | #define GLUT_ACTION_ON_WINDOW_CLOSE 0x01F9 75 | 76 | #define GLUT_WINDOW_BORDER_WIDTH 0x01FA 77 | #define GLUT_WINDOW_BORDER_HEIGHT 0x01FB 78 | #define GLUT_WINDOW_HEADER_HEIGHT 0x01FB /* Docs say it should always have been GLUT_WINDOW_BORDER_HEIGHT, keep this for backward compatibility */ 79 | 80 | #define GLUT_VERSION 0x01FC 81 | 82 | #define GLUT_RENDERING_CONTEXT 0x01FD 83 | #define GLUT_DIRECT_RENDERING 0x01FE 84 | 85 | #define GLUT_FULL_SCREEN 0x01FF 86 | 87 | #define GLUT_SKIP_STALE_MOTION_EVENTS 0x0204 88 | 89 | #define GLUT_GEOMETRY_VISUALIZE_NORMALS 0x0205 90 | 91 | #define GLUT_STROKE_FONT_DRAW_JOIN_DOTS 0x0206 /* Draw dots between line segments of stroke fonts? */ 92 | 93 | /* 94 | * New tokens for glutInitDisplayMode. 95 | * Only one GLUT_AUXn bit may be used at a time. 96 | * Value 0x0400 is defined in OpenGLUT. 97 | */ 98 | #define GLUT_AUX 0x1000 99 | 100 | #define GLUT_AUX1 0x1000 101 | #define GLUT_AUX2 0x2000 102 | #define GLUT_AUX3 0x4000 103 | #define GLUT_AUX4 0x8000 104 | 105 | /* 106 | * Context-related flags, see fg_state.c 107 | * Set the requested OpenGL version 108 | */ 109 | #define GLUT_INIT_MAJOR_VERSION 0x0200 110 | #define GLUT_INIT_MINOR_VERSION 0x0201 111 | #define GLUT_INIT_FLAGS 0x0202 112 | #define GLUT_INIT_PROFILE 0x0203 113 | 114 | /* 115 | * Flags for glutInitContextFlags, see fg_init.c 116 | */ 117 | #define GLUT_DEBUG 0x0001 118 | #define GLUT_FORWARD_COMPATIBLE 0x0002 119 | 120 | 121 | /* 122 | * Flags for glutInitContextProfile, see fg_init.c 123 | */ 124 | #define GLUT_CORE_PROFILE 0x0001 125 | #define GLUT_COMPATIBILITY_PROFILE 0x0002 126 | 127 | /* 128 | * Process loop function, see fg_main.c 129 | */ 130 | FGAPI void FGAPIENTRY glutMainLoopEvent( void ); 131 | FGAPI void FGAPIENTRY glutLeaveMainLoop( void ); 132 | FGAPI void FGAPIENTRY glutExit ( void ); 133 | 134 | /* 135 | * Window management functions, see fg_window.c 136 | */ 137 | FGAPI void FGAPIENTRY glutFullScreenToggle( void ); 138 | FGAPI void FGAPIENTRY glutLeaveFullScreen( void ); 139 | 140 | /* 141 | * Menu functions 142 | */ 143 | FGAPI void FGAPIENTRY glutSetMenuFont( int menuID, void* font ); 144 | 145 | /* 146 | * Window-specific callback functions, see fg_callbacks.c 147 | */ 148 | FGAPI void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) ); 149 | FGAPI void FGAPIENTRY glutPositionFunc( void (* callback)( int, int ) ); 150 | FGAPI void FGAPIENTRY glutCloseFunc( void (* callback)( void ) ); 151 | FGAPI void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) ); 152 | /* And also a destruction callback for menus */ 153 | FGAPI void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) ); 154 | 155 | /* 156 | * State setting and retrieval functions, see fg_state.c 157 | */ 158 | FGAPI void FGAPIENTRY glutSetOption ( GLenum option_flag, int value ); 159 | FGAPI int * FGAPIENTRY glutGetModeValues(GLenum mode, int * size); 160 | /* A.Donev: User-data manipulation */ 161 | FGAPI void* FGAPIENTRY glutGetWindowData( void ); 162 | FGAPI void FGAPIENTRY glutSetWindowData(void* data); 163 | FGAPI void* FGAPIENTRY glutGetMenuData( void ); 164 | FGAPI void FGAPIENTRY glutSetMenuData(void* data); 165 | 166 | /* 167 | * Font stuff, see fg_font.c 168 | */ 169 | FGAPI int FGAPIENTRY glutBitmapHeight( void* font ); 170 | FGAPI GLfloat FGAPIENTRY glutStrokeHeight( void* font ); 171 | FGAPI void FGAPIENTRY glutBitmapString( void* font, const unsigned char *string ); 172 | FGAPI void FGAPIENTRY glutStrokeString( void* font, const unsigned char *string ); 173 | 174 | /* 175 | * Geometry functions, see fg_geometry.c 176 | */ 177 | FGAPI void FGAPIENTRY glutWireRhombicDodecahedron( void ); 178 | FGAPI void FGAPIENTRY glutSolidRhombicDodecahedron( void ); 179 | FGAPI void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, double offset[3], double scale ); 180 | FGAPI void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, double offset[3], double scale ); 181 | FGAPI void FGAPIENTRY glutWireCylinder( double radius, double height, GLint slices, GLint stacks); 182 | FGAPI void FGAPIENTRY glutSolidCylinder( double radius, double height, GLint slices, GLint stacks); 183 | 184 | /* 185 | * Rest of functions for rendering Newell's teaset, found in fg_teapot.c 186 | * NB: front facing polygons have clockwise winding, not counter clockwise 187 | */ 188 | FGAPI void FGAPIENTRY glutWireTeacup( double size ); 189 | FGAPI void FGAPIENTRY glutSolidTeacup( double size ); 190 | FGAPI void FGAPIENTRY glutWireTeaspoon( double size ); 191 | FGAPI void FGAPIENTRY glutSolidTeaspoon( double size ); 192 | 193 | /* 194 | * Extension functions, see fg_ext.c 195 | */ 196 | typedef void (*GLUTproc)(); 197 | FGAPI GLUTproc FGAPIENTRY glutGetProcAddress( const char *procName ); 198 | 199 | /* 200 | * Multi-touch/multi-pointer extensions 201 | */ 202 | 203 | #define GLUT_HAS_MULTI 1 204 | 205 | /* TODO: add device_id parameter, 206 | cf. http://sourceforge.net/mailarchive/forum.php?thread_name=20120518071314.GA28061%40perso.beuc.net&forum_name=freeglut-developer */ 207 | FGAPI void FGAPIENTRY glutMultiEntryFunc( void (* callback)( int, int ) ); 208 | FGAPI void FGAPIENTRY glutMultiButtonFunc( void (* callback)( int, int, int, int, int ) ); 209 | FGAPI void FGAPIENTRY glutMultiMotionFunc( void (* callback)( int, int, int ) ); 210 | FGAPI void FGAPIENTRY glutMultiPassiveFunc( void (* callback)( int, int, int ) ); 211 | 212 | /* 213 | * Joystick functions, see fg_joystick.c 214 | */ 215 | /* USE OF THESE FUNCTIONS IS DEPRECATED !!!!! */ 216 | /* If you have a serious need for these functions in your application, please either 217 | * contact the "freeglut" developer community at freeglut-developer@lists.sourceforge.net, 218 | * switch to the OpenGLUT library, or else port your joystick functionality over to PLIB's 219 | * "js" library. 220 | */ 221 | int glutJoystickGetNumAxes( int ident ); 222 | int glutJoystickGetNumButtons( int ident ); 223 | int glutJoystickNotWorking( int ident ); 224 | float glutJoystickGetDeadBand( int ident, int axis ); 225 | void glutJoystickSetDeadBand( int ident, int axis, float db ); 226 | float glutJoystickGetSaturation( int ident, int axis ); 227 | void glutJoystickSetSaturation( int ident, int axis, float st ); 228 | void glutJoystickSetMinRange( int ident, float *axes ); 229 | void glutJoystickSetMaxRange( int ident, float *axes ); 230 | void glutJoystickSetCenter( int ident, float *axes ); 231 | void glutJoystickGetMinRange( int ident, float *axes ); 232 | void glutJoystickGetMaxRange( int ident, float *axes ); 233 | void glutJoystickGetCenter( int ident, float *axes ); 234 | 235 | /* 236 | * Initialization functions, see fg_init.c 237 | */ 238 | /* to get the typedef for va_list */ 239 | #include 240 | FGAPI void FGAPIENTRY glutInitContextVersion( int majorVersion, int minorVersion ); 241 | FGAPI void FGAPIENTRY glutInitContextFlags( int flags ); 242 | FGAPI void FGAPIENTRY glutInitContextProfile( int profile ); 243 | FGAPI void FGAPIENTRY glutInitErrorFunc( void (* callback)( const char *fmt, va_list ap ) ); 244 | FGAPI void FGAPIENTRY glutInitWarningFunc( void (* callback)( const char *fmt, va_list ap ) ); 245 | 246 | /* OpenGL >= 2.0 support */ 247 | FGAPI void FGAPIENTRY glutSetVertexAttribCoord3(GLint attrib); 248 | FGAPI void FGAPIENTRY glutSetVertexAttribNormal(GLint attrib); 249 | FGAPI void FGAPIENTRY glutSetVertexAttribTexCoord2(GLint attrib); 250 | 251 | /* Mobile platforms lifecycle */ 252 | FGAPI void FGAPIENTRY glutInitContextFunc(void (* callback)()); 253 | FGAPI void FGAPIENTRY glutAppStatusFunc(void (* callback)(int)); 254 | /* state flags that can be passed to callback set by glutAppStatusFunc */ 255 | #define GLUT_APPSTATUS_PAUSE 0x0001 256 | #define GLUT_APPSTATUS_RESUME 0x0002 257 | 258 | /* 259 | * GLUT API macro definitions -- the display mode definitions 260 | */ 261 | #define GLUT_CAPTIONLESS 0x0400 262 | #define GLUT_BORDERLESS 0x0800 263 | #define GLUT_SRGB 0x1000 264 | 265 | #ifdef __cplusplus 266 | } 267 | #endif 268 | 269 | /*** END OF FILE ***/ 270 | 271 | #endif /* __FREEGLUT_EXT_H__ */ 272 | -------------------------------------------------------------------------------- /src/runtime/freeglut/include/GL/glut.h: -------------------------------------------------------------------------------- 1 | #ifndef __GLUT_H__ 2 | #define __GLUT_H__ 3 | 4 | /* 5 | * glut.h 6 | * 7 | * The freeglut library include file 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 10 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 12 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | */ 16 | 17 | #include "freeglut_std.h" 18 | 19 | /*** END OF FILE ***/ 20 | 21 | #endif /* __GLUT_H__ */ 22 | -------------------------------------------------------------------------------- /src/runtime/freeglut/lib/freeglut.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/freeglut/lib/freeglut.lib -------------------------------------------------------------------------------- /src/runtime/freeglut/lib/x64/freeglut.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/freeglut/lib/x64/freeglut.lib -------------------------------------------------------------------------------- /src/runtime/glew/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The OpenGL Extension Wrangler Library 2 | Copyright (C) 2002-2007, Milan Ikits 3 | Copyright (C) 2002-2007, Marcelo E. Magallon 4 | Copyright (C) 2002, Lev Povalahev 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | * The name of the author may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | Mesa 3-D graphics library 32 | Version: 7.0 33 | 34 | Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a 37 | copy of this software and associated documentation files (the "Software"), 38 | to deal in the Software without restriction, including without limitation 39 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 40 | and/or sell copies of the Software, and to permit persons to whom the 41 | Software is furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included 44 | in all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 47 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 50 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 51 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 52 | 53 | 54 | Copyright (c) 2007 The Khronos Group Inc. 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a 57 | copy of this software and/or associated documentation files (the 58 | "Materials"), to deal in the Materials without restriction, including 59 | without limitation the rights to use, copy, modify, merge, publish, 60 | distribute, sublicense, and/or sell copies of the Materials, and to 61 | permit persons to whom the Materials are furnished to do so, subject to 62 | the following conditions: 63 | 64 | The above copyright notice and this permission notice shall be included 65 | in all copies or substantial portions of the Materials. 66 | 67 | THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 68 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 69 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 70 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 71 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 72 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 73 | MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 74 | -------------------------------------------------------------------------------- /src/runtime/glew/bin/Release/Win32/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/bin/Release/Win32/glew32.dll -------------------------------------------------------------------------------- /src/runtime/glew/bin/Release/Win32/glewinfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/bin/Release/Win32/glewinfo.exe -------------------------------------------------------------------------------- /src/runtime/glew/bin/Release/Win32/visualinfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/bin/Release/Win32/visualinfo.exe -------------------------------------------------------------------------------- /src/runtime/glew/bin/Release/x64/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/bin/Release/x64/glew32.dll -------------------------------------------------------------------------------- /src/runtime/glew/bin/Release/x64/glewinfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/bin/Release/x64/glewinfo.exe -------------------------------------------------------------------------------- /src/runtime/glew/bin/Release/x64/visualinfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/bin/Release/x64/visualinfo.exe -------------------------------------------------------------------------------- /src/runtime/glew/doc/advanced.html: -------------------------------------------------------------------------------- 1 | 2 | 33 | 34 | 35 | 36 | GLEW: The OpenGL Extension Wrangler Library 37 | 38 | 39 | 40 | 41 | 42 | 43 | 91 | 92 |
44 | 45 | 46 | 73 | 74 | 75 | 76 | 88 | 89 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 71 |
Latest Release: 2.2.0

GLEW Logo

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
Download
Usage
Building
Installation
Source Generation
Change Log

GitHub
Issues
Pull Requests
Authors
Licensing

SourceForge Page
70 |

72 |
77 | 78 | 79 | 85 | 86 |
Last Update: 07-24-16
80 | OpenGL Logo
81 | GitHub Logo
82 | Travis Logo
83 | SourceForge Logo 84 |
87 |
90 |
93 | 94 |

The OpenGL Extension Wrangler Library

95 | 96 | 97 | 98 | 99 |

Automatic Code Generation

100 | 101 |

102 | Starting from release 1.1.0, the source code and parts of the 103 | documentation are automatically generated from the extension 104 | specifications in a two-step process. In the first step, 105 | specification files from the OpenGL registry are downloaded and 106 | parsed. Skeleton descriptors are created for each extension. These 107 | descriptors contain all necessary information for creating the source 108 | code and documentation in a simple and compact format, including the 109 | name of the extension, url link to the specification, tokens, function 110 | declarations, typedefs and struct definitions. In the second step, 111 | the header files as well as the library and glewinfo source are 112 | generated from the descriptor files. The code generation scripts are 113 | located in the auto subdirectory. 114 |

115 | 116 |

117 | The code generation scripts require GNU make, wget, and perl. On 118 | Windows, the simplest way to get access to these tools is to install 119 | Cygwin, but make sure that the 120 | root directory is mounted in binary mode. The makefile in the 121 | auto directory provides the following build targets: 122 |

123 | 124 | 125 | 126 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 139 |
makeCreate the source files from the descriptors.
If the 127 | descriptors do not exist, create them from the spec files.
If the spec 128 | files do not exist, download them from the OpenGL repository.
make cleanDelete the source files.
make clobberDelete the source files and the descriptors.
make destroyDelete the source files, the descriptors, and the spec files.
make customCreate the source files for the extensions 137 | listed in auto/custom.txt.
See "Custom Code 138 | Generation" below for more details.
140 | 141 |

Adding a New Extension

142 | 143 |

144 | To add a new extension, create a descriptor file for the extension in 145 | auto/core and rerun the code generation scripts by typing 146 | make clean; make in the auto directory. 147 |

148 | 149 |

150 | The format of the descriptor file is given below. Items in 151 | brackets are optional. 152 |

153 | 154 |

155 | <Extension Name>
156 | [<URL of Specification File>]
157 |     [<Token Name> <Token Value>]
158 |     [<Token Name> <Token Value>]
159 |     ...
160 |     [<Typedef>]
161 |     [<Typedef>]
162 |     ...
163 |     [<Function Signature>]
164 |     [<Function Signature>]
165 |     ...
166 | 169 |

170 | 171 | 179 | 180 |

181 | Take a look at one of the files in auto/core for an 182 | example. Note that typedefs and function signatures should not be 183 | terminated with a semicolon. 184 |

185 | 186 |

Custom Code Generation

187 |

188 | Starting from GLEW 1.3.0, it is possible to control which extensions 189 | to include in the libarary by specifying a list in 190 | auto/custom.txt. This is useful when you do not need all the 191 | extensions and would like to reduce the size of the source files. 192 | Type make clean; make custom in the auto directory 193 | to rerun the scripts with the custom list of extensions. 194 |

195 | 196 |

197 | For example, the following is the list of extensions needed to get GLEW and the 198 | utilities to compile. 199 |

200 | 201 |

202 | WGL_ARB_extensions_string
203 | WGL_ARB_multisample
204 | WGL_ARB_pixel_format
205 | WGL_ARB_pbuffer
206 | WGL_EXT_extensions_string
207 | WGL_ATI_pixel_format_float
208 | WGL_NV_float_buffer
209 |

210 | 211 |

Separate Namespace

212 | 213 |

214 | To avoid name clashes when linking with libraries that include the 215 | same symbols, extension entry points are declared in a separate 216 | namespace (release 1.1.0 and up). This is achieved by aliasing OpenGL 217 | function names to their GLEW equivalents. For instance, 218 | glFancyFunction is simply an alias to 219 | glewFancyFunction. The separate namespace does not effect 220 | token and function pointer definitions. 221 |

222 | 223 |

Known Issues

224 | 225 |

226 | GLEW requires GLX 1.2 for compatibility with GLUT. 227 |

228 | 229 | 230 |
231 | 232 | 233 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/basic.html: -------------------------------------------------------------------------------- 1 | 2 | 33 | 34 | 35 | 36 | GLEW: The OpenGL Extension Wrangler Library 37 | 38 | 39 | 40 | 41 | 42 | 43 | 91 | 92 |
44 | 45 | 46 | 73 | 74 | 75 | 76 | 88 | 89 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 71 |
Latest Release: 2.2.0

GLEW Logo

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
Download
Usage
Building
Installation
Source Generation
Change Log

GitHub
Issues
Pull Requests
Authors
Licensing

SourceForge Page
70 |

72 |
77 | 78 | 79 | 85 | 86 |
Last Update: 07-24-16
80 | OpenGL Logo
81 | GitHub Logo
82 | Travis Logo
83 | SourceForge Logo 84 |
87 |
90 |
93 | 94 |

The OpenGL Extension Wrangler Library

95 | 96 | 97 | 98 | 99 |

Initializing GLEW

100 |

101 | First you need to create a valid OpenGL rendering context and call 102 | glewInit() to initialize the extension entry points. If 103 | glewInit() returns GLEW_OK, the initialization 104 | succeeded and you can use the available extensions as well as core 105 | OpenGL functionality. For example: 106 |

107 | 108 |

109 | #include <GL/glew.h>
110 | #include <GL/glut.h>
111 | ...
112 | glutInit(&argc, argv);
113 | glutCreateWindow("GLEW Test");
114 | GLenum err = glewInit();
115 | if (GLEW_OK != err)
116 | {
117 |   /* Problem: glewInit failed, something is seriously wrong. */
118 |   fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
119 |   ...
120 | }
121 | fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
122 |

123 | 124 |

Checking for Extensions

125 | 126 |

127 | Starting from GLEW 1.1.0, you can find out if a particular extension 128 | is available on your platform by querying globally defined variables 129 | of the form GLEW_{extension_name}: 130 |

131 | 132 |

133 | if (GLEW_ARB_vertex_program)
134 | {
135 |   /* It is safe to use the ARB_vertex_program extension here. */
136 |   glGenProgramsARB(...);
137 | }
138 |

139 | 140 |

141 | In GLEW 1.0.x, a global structure was used for this task. To ensure 142 | binary compatibility between releases, the struct was replaced with a 143 | set of variables. 144 |

145 | 146 |

147 | You can also check for core OpenGL functionality. For example, to 148 | see if OpenGL 1.3 is supported, do the following: 149 |

150 | 151 |

152 | if (GLEW_VERSION_1_3)
153 | {
154 |   /* Yay! OpenGL 1.3 is supported! */
155 | }
156 |

157 | 158 |

159 | In general, you can check if GLEW_{extension_name} or 160 | GLEW_VERSION_{version} is true or false. 161 |

162 | 163 |

164 | It is also possible to perform extension checks from string 165 | input. Starting from the 1.3.0 release, use glewIsSupported 166 | to check if the required core or extension functionality is 167 | available: 168 |

169 | 170 |

171 | if (glewIsSupported("GL_VERSION_1_4  GL_ARB_point_sprite"))
172 | {
173 |   /* Great, we have OpenGL 1.4 + point sprites. */
174 | }
175 |

176 | 177 |

178 | For extensions only, glewGetExtension provides a slower alternative 179 | (GLEW 1.0.x-1.2.x). Note that in the 1.3.0 release 180 | glewGetExtension was replaced with 181 | glewIsSupported. 182 |

183 | 184 |

185 | if (glewGetExtension("GL_ARB_fragment_program"))
186 | {
187 |   /* Looks like ARB_fragment_program is supported. */
188 | }
189 |

190 | 191 |

Experimental Drivers

192 | 193 |

194 | GLEW obtains information on the supported extensions from the graphics 195 | driver. Experimental or pre-release drivers, however, might not 196 | report every available extension through the standard mechanism, in 197 | which case GLEW will report it unsupported. To circumvent this 198 | situation, the glewExperimental global switch can be turned 199 | on by setting it to GL_TRUE before calling 200 | glewInit(), which ensures that all extensions with valid 201 | entry points will be exposed. 202 |

203 | 204 |

Platform Specific Extensions

205 | 206 |

207 | Platform specific extensions are separated into two header files: 208 | wglew.h and glxew.h, which define the available 209 | WGL and GLX extensions. To determine if a certain 210 | extension is supported, query WGLEW_{extension name} or 211 | GLXEW_{extension_name}. For example: 212 |

213 | 214 |

215 | #include <GL/wglew.h>
216 |
217 | if (WGLEW_ARB_pbuffer)
218 | {
219 |   /* OK, we can use pbuffers. */
220 | }
221 | else
222 | {
223 |   /* Sorry, pbuffers will not work on this platform. */
224 | }
225 |

226 | 227 |

228 | Alternatively, use wglewIsSupported or 229 | glxewIsSupported to check for extensions from a string: 230 |

231 | 232 |

233 | if (wglewIsSupported("WGL_ARB_pbuffer"))
234 | {
235 |   /* OK, we can use pbuffers. */
236 | }
237 |

238 | 239 |

Utilities

240 | 241 |

242 | GLEW provides two command-line utilities: one for creating a list of 243 | available extensions and visuals; and another for verifying extension 244 | entry points. 245 |

246 | 247 |

visualinfo: extensions and visuals

248 | 249 |

250 | visualinfo is an extended version of glxinfo. The 251 | Windows version creates a file called visualinfo.txt, which 252 | contains a list of available OpenGL, WGL, and GLU extensions as well 253 | as a table of visuals aka. pixel formats. Pbuffer and MRT capable 254 | visuals are also included. For additional usage information, type 255 | visualinfo -h. 256 |

257 | 258 |

glewinfo: extension verification utility

259 | 260 |

261 | glewinfo allows you to verify the entry points for the 262 | extensions supported on your platform. The Windows version 263 | reports the results to a text file called glewinfo.txt. The 264 | Unix version prints the results to stdout. 265 |

266 | 267 |

Windows usage:

268 |
glewinfo [-pf <id>]
269 | 270 |

where <id> is the pixel format id for which the 271 | capabilities are displayed.

272 | 273 |

Unix usage:

274 |
glewinfo [-display <dpy>] [-visual <id>]
275 | 276 |

where <dpy> is the X11 display and <id> is 277 | the visual id for which the capabilities are displayed.

278 | 279 | 280 |
281 | 282 | 283 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/build.html: -------------------------------------------------------------------------------- 1 | 2 | 33 | 34 | 35 | 36 | GLEW: The OpenGL Extension Wrangler Library 37 | 38 | 39 | 40 | 41 | 42 | 43 | 91 | 92 |
44 | 45 | 46 | 73 | 74 | 75 | 76 | 88 | 89 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 71 |
Latest Release: 2.2.0

GLEW Logo

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
Download
Usage
Building
Installation
Source Generation
Change Log

GitHub
Issues
Pull Requests
Authors
Licensing

SourceForge Page
70 |

72 |
77 | 78 | 79 | 85 | 86 |
Last Update: 07-24-16
80 | OpenGL Logo
81 | GitHub Logo
82 | Travis Logo
83 | SourceForge Logo 84 |
87 |
90 |
93 | 94 |

The OpenGL Extension Wrangler Library

95 | 96 | 97 | 98 | 99 |

Building GLEW

100 | 101 |

Windows

102 | 103 |

A MS Visual Studio project is provided in the build/vc6 directory.

104 |

Pre-built shared and static libraries are also available for download.

105 | 106 |

Makefile

107 | 108 |

For platforms other than MS Windows, the provided Makefile is used.

109 | 110 |

Command-line variables

111 | 112 | 113 | 114 | 116 | 117 | 118 |
SYSTEMautoTarget system to build: darwin, linux, solaris, etc.
For a full list of supported targets: ls config/Makefile.*
115 | config.guess is used to auto detect, as necessary.
GLEW_DEST/usrBase directory for installation.
119 | 120 |

Make targets

121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |
allBuild everything.
glew.libBuild static and dynamic GLEW libraries.
glew.lib.mxBuild static and dynamic GLEWmx libraries.
glew.binBuild glewinfo and visualinfo utilities.
cleanDelete temporary and built files.
install.allInstall everything.
installInstall GLEW libraries.
install.mxInstall GLEWmx libraries.
install.binInstall glewinfo and visualinfo utilities.
uninstallDelete installed files.
134 | 135 |

Requirements

136 | 137 |
    138 |
  • GNU make
  • 139 |
  • perl
  • 140 |
  • wget
  • 141 |
  • GNU sed
  • 142 |
  • gcc compiler
  • 143 |
  • git
  • 144 |
145 | 146 | Ubuntu:
sudo apt-get install libXmu-dev libXi-dev libgl-dev dos2unix git wget
147 | Fedora:
sudo yum install libXmu-devel libXi-devel libGL-devel dos2unix git wget
148 | 149 |
150 | 151 | 152 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/credits.html: -------------------------------------------------------------------------------- 1 | 2 | 33 | 34 | 35 | 36 | GLEW: The OpenGL Extension Wrangler Library 37 | 38 | 39 | 40 | 41 | 42 | 43 | 91 | 92 |
44 | 45 | 46 | 73 | 74 | 75 | 76 | 88 | 89 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 71 |
Latest Release: 2.2.0

GLEW Logo

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
Download
Usage
Building
Installation
Source Generation
Change Log

GitHub
Issues
Pull Requests
Authors
Licensing

SourceForge Page
70 |

72 |
77 | 78 | 79 | 85 | 86 |
Last Update: 07-24-16
80 | OpenGL Logo
81 | GitHub Logo
82 | Travis Logo
83 | SourceForge Logo 84 |
87 |
90 |
93 | 94 |

The OpenGL Extension Wrangler Library

95 | 96 | 97 | 98 | 99 |

100 | Author, copyright and licensing information on github.

101 | 102 |
103 | 104 | 105 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/doc/github.png -------------------------------------------------------------------------------- /src/runtime/glew/doc/glew.css: -------------------------------------------------------------------------------- 1 | h1 2 | { 3 | color: black; 4 | font: 23px "Verdana", "Arial", "Helvetica", sans-serif; 5 | font-weight: bold; 6 | text-align: center; 7 | margin-top: 12px; 8 | margin-bottom: 18px; 9 | } 10 | 11 | h2 12 | { 13 | color: black; 14 | font: 18px "Verdana", "Arial", "Helvetica", sans-serif; 15 | font-weight: bold; 16 | text-align: left; 17 | padding-top: 0px; 18 | padding-bottom: 0px; 19 | margin-top: 18px; 20 | margin-bottom: 12px; 21 | } 22 | 23 | h3 24 | { 25 | color: black; 26 | font: 17px "Verdana", "Arial", "Helvetica", sans-serif; 27 | text-align: left; 28 | padding-top: 0px; 29 | padding-bottom: 0px; 30 | margin-top: 12px; 31 | margin-bottom: 12px; 32 | } 33 | 34 | small 35 | { 36 | font: 8pt "Verdana", "Arial", "Helvetica", sans-serif; 37 | } 38 | 39 | body 40 | { 41 | color: black; 42 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 43 | text-align: left; 44 | } 45 | 46 | td 47 | { 48 | color: black; 49 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 50 | } 51 | 52 | tt 53 | { 54 | color: rgb(0,120,0); 55 | } 56 | /* color: maroon; */ 57 | 58 | td.num 59 | { 60 | color: lightgrey; 61 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 62 | text-align: right; 63 | } 64 | 65 | blockquote 66 | { 67 | color: rgb(0,120,0); 68 | background: #f0f0f0; 69 | text-align: left; 70 | margin-left: 40px; 71 | margin-right: 40px; 72 | margin-bottom: 6px; 73 | padding-bottom: 0px; 74 | margin-top: 0px; 75 | padding-top: 0px; 76 | border-top: 0px; 77 | border-width: 0px; 78 | } 79 | 80 | pre 81 | { 82 | color: rgb(0,120,0); 83 | background: #f0f0f0; 84 | text-align: left; 85 | margin-left: 40px; 86 | margin-right: 40px; 87 | margin-bottom: 6px; 88 | padding-bottom: 0px; 89 | margin-top: 0px; 90 | padding-top: 0px; 91 | border-top: 0px; 92 | border-width: 0px; 93 | } 94 | 95 | p 96 | { 97 | color: black; 98 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 99 | text-align: left; 100 | margin-bottom: 0px; 101 | padding-bottom: 6px; 102 | margin-top: 0px; 103 | padding-top: 0px; 104 | } 105 | 106 | p.right 107 | { 108 | color: black; 109 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 110 | text-align: right; 111 | margin-bottom: 0px; 112 | padding-bottom: 6px; 113 | margin-top: 0px; 114 | padding-top: 0px; 115 | } 116 | 117 | p.pre 118 | { 119 | color: rgb(0,120,0); 120 | font: 10pt "Courier New", "Courier", monospace; 121 | background: #f0f0f0; 122 | text-align: left; 123 | margin-top: 0px; 124 | margin-bottom: 6px; 125 | margin-left: 40px; 126 | margin-right: 40px; 127 | padding-top: 0px; 128 | padding-bottom: 6px; 129 | padding-left: 6px; 130 | padding-right: 6px; 131 | border-top: 0px; 132 | border-width: 0px; 133 | } 134 | 135 | a:link 136 | { 137 | color: rgb(0,0,139); 138 | text-decoration: none; 139 | } 140 | 141 | a:visited 142 | { 143 | color: rgb(220,20,60); 144 | text-decoration: none; 145 | } 146 | 147 | a:hover 148 | { 149 | color: rgb(220,20,60); 150 | text-decoration: underline; 151 | background: "#e8e8e8"; 152 | } 153 | 154 | ul 155 | { 156 | list-style-type: disc; 157 | text-align: left; 158 | margin-left: 40px; 159 | margin-top: 0px; 160 | padding-top: 0px; 161 | margin-bottom: 0px; 162 | padding-bottom: 3px; 163 | } 164 | 165 | ul.none 166 | { 167 | list-style-type: none; 168 | } 169 | 170 | ol 171 | { 172 | text-align: left; 173 | margin-left: 40px; 174 | margin-top: 0px; 175 | padding-top: 0px; 176 | margin-bottom: 0px; 177 | padding-bottom: 12px; 178 | } 179 | 180 | hr 181 | { 182 | color: maroon; 183 | background-color: maroon; 184 | height: 1px; 185 | border: 0px; 186 | width: 80%; 187 | } 188 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/glew.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/doc/glew.png -------------------------------------------------------------------------------- /src/runtime/glew/doc/glew.txt: -------------------------------------------------------------------------------- 1 | The OpenGL Extension Wrangler Library 2 | Copyright (C) 2008-2016, Nigel Stewart 3 | Copyright (C) 2002-2008, Milan Ikits 4 | Copyright (C) 2002-2008, Marcelo E. Magallon 5 | Copyright (C) 2002, Lev Povalahev 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | * The name of the author may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 | THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 33 | 34 | 35 | 36 | GLEW: The OpenGL Extension Wrangler Library 37 | 38 | 39 | 40 | 41 | 42 | 43 | 91 | 92 |
44 | 45 | 46 | 73 | 74 | 75 | 76 | 88 | 89 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 71 |
Latest Release: 2.2.0

GLEW Logo

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
Download
Usage
Building
Installation
Source Generation
Change Log

GitHub
Issues
Pull Requests
Authors
Licensing

SourceForge Page
70 |

72 |
77 | 78 | 79 | 85 | 86 |
Last Update: 07-24-16
80 | OpenGL Logo
81 | GitHub Logo
82 | Travis Logo
83 | SourceForge Logo 84 |
87 |
90 |
93 | 94 |

The OpenGL Extension Wrangler Library

95 | 96 | 97 | 98 | 99 |

100 | The OpenGL Extension Wrangler Library (GLEW) is a cross-platform 101 | open-source C/C++ extension loading library. GLEW provides efficient 102 | run-time mechanisms for determining which OpenGL extensions are 103 | supported on the target platform. OpenGL core and extension 104 | functionality is exposed in a single header file. GLEW has been 105 | tested on a variety of operating systems, including Windows, Linux, 106 | Mac OS X, FreeBSD, Irix, and Solaris. 107 |

108 | 109 |

Downloads

110 |

111 | GLEW is distributed 112 | as source and precompiled binaries.
113 | The latest release is 114 | 2.2.0[07-24-16]: 115 |

116 |

117 |

118 |

119 | 120 | 121 | 143 |
122 | 123 | 124 | 125 | 126 | 127 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 139 | 140 | 141 |
Source 128 | ZIP |  129 | TGZ
Binaries 137 | Windows 32-bit and 64-bit 138 |
142 |
144 | 145 |

146 |

147 | An up-to-date copy is also available using git: 148 |

149 |
    150 |
  • github
    151 | git clone https://github.com/nigels-com/glew.git glew
     
  • 152 |
153 | 154 |

Supported Extensions

155 |

156 | The latest release contains support for OpenGL 4.5, compatibility and forward-compatible contexts and the following extensions: 157 |

158 | 163 | 164 |

News

165 |
    166 |
  • [07-24-16] GLEW 2.0.0 adds support for forward-compatible contexts, adds new extensions, OSMesa and EGL support, MX discontinued and minor bug fixes
  • 167 |
  • [08-10-15] GLEW 1.13.0 adds support for new extensions, fixes minor bugs
  • 168 |
  • [26-01-15] GLEW 1.12.0 fixes minor bugs and adds new extensions
  • 169 |
  • [08-11-14] GLEW 1.11.0 adds support for OpenGL 4.5, new extensions
  • 170 |
  • [07-22-13] GLEW 1.10.0 adds support for OpenGL 4.4, new extensions
  • 171 |
  • [08-06-12] GLEW 1.9.0 adds support for OpenGL 4.3, new extensions
  • 172 |
  • [07-17-12] GLEW 1.8.0 fixes minor bugs and adds new extensions
  • 173 |
  • [08-26-11] GLEW 1.7.0 adds support for OpenGL 4.2, new extensions, fixes bugs
  • 174 |
  • [04-27-11] GLEW 1.6.0 fixes minor bugs and adds eight new extensions
  • 175 |
  • [01-31-11] GLEW 1.5.8 fixes minor bugs and adds two new extensions
  • 176 |
  • [11-03-10] GLEW 1.5.7 fixes minor bugs and adds one new extension
  • 177 |
  • [09-07-10] GLEW 1.5.6 adds support for OpenGL 4.1, fixes bugs
  • 178 |
  • [07-13-10] GLEW 1.5.5 fixes minor bugs and adds new extensions
  • 179 |
  • [04-21-10] GLEW 1.5.4 adds support for OpenGL 3.3, OpenGL 4.0 and new extensions, fixes bugs
  • 180 |
  • [02-28-10] GLEW 1.5.3 fixes minor bugs and adds three new extensions
  • 181 |
  • [12-31-09] GLEW 1.5.2 adds support for OpenGL 3.1, OpenGL 3.2 and new extensions
  • 182 |
  • [11-03-08] GLEW 1.5.1 adds support for OpenGL 3.0 and 31 new extensions
  • 183 |
  • [12-27-07] GLEW 1.5.0 is released under less restrictive licenses
  • 184 |
  • [04-27-07] GLEW 1.4.0 is released
  • 185 |
  • [03-08-07] GLEW is included in the NVIDIA OpenGL SDK
  • 186 |
  • [03-04-07] GLEW 1.3.6 is released
  • 187 |
  • [02-28-07] Repository is migrated to SVN
  • 188 |
  • [02-25-07] GLEW is included in the OpenGL SDK
  • 189 |
  • [11-21-06] GLEW 1.3.5 adds OpenGL 2.1 and NVIDIA G80 extensions
  • 190 |
  • [03-04-06] GLEW 1.3.4 adds support for five new extensions
  • 191 |
  • [05-16-05] GLEW 1.3.3 is released
  • 192 |
  • [03-16-05] GLEW 1.3.2 adds support for GL_APPLE_pixel_buffer
  • 193 |
  • [02-11-05] gljava and sdljava provide a Java binding to OpenGL via GLEW
  • 194 |
  • [02-02-05] GLEW 1.3.1 adds support for GL_EXT_framebuffer_object
  • 195 |
  • [01-04-05] GLEW 1.3.0 adds core OpenGL 2.0 support plus many enhancements
  • 196 |
  • [12-22-04] GLEWpy Python wrapper announced
  • 197 |
  • [12-12-04] Mailing lists created on sourceforge
  • 198 |
  • [12-06-04] GLEW 1.2.5 adds new extensions and support for FreeBSD
  • 199 |
200 | 201 |

Links

202 | 209 | 210 | 211 |
212 | 213 | 214 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/install.html: -------------------------------------------------------------------------------- 1 | 2 | 33 | 34 | 35 | 36 | GLEW: The OpenGL Extension Wrangler Library 37 | 38 | 39 | 40 | 41 | 42 | 43 | 91 | 92 |
44 | 45 | 46 | 73 | 74 | 75 | 76 | 88 | 89 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 71 |
Latest Release: 2.2.0

GLEW Logo

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
Download
Usage
Building
Installation
Source Generation
Change Log

GitHub
Issues
Pull Requests
Authors
Licensing

SourceForge Page
70 |

72 |
77 | 78 | 79 | 85 | 86 |
Last Update: 07-24-16
80 | OpenGL Logo
81 | GitHub Logo
82 | Travis Logo
83 | SourceForge Logo 84 |
87 |
90 |
93 | 94 |

The OpenGL Extension Wrangler Library

95 | 96 | 97 | 98 | 99 |

Installation

100 | 101 |

102 | To use the shared library version of GLEW, you need to copy the 103 | headers and libraries into their destination directories. On Windows 104 | this typically boils down to copying: 105 |

106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 |
bin/glew32.dll    to    %SystemRoot%/system32
lib/glew32.lib    to    {VC Root}/Lib
include/GL/glew.h    to    {VC Root}/Include/GL
include/GL/wglew.h    to    {VC Root}/Include/GL
117 |

118 |

119 | 120 |

121 | where {VC Root} is the Visual C++ root directory, typically 122 | C:/Program Files/Microsoft Visual Studio/VC98 for Visual 123 | Studio 6.0 or C:/Program Files/Microsoft Visual 124 | Studio .NET 2003/Vc7/PlatformSDK for Visual Studio .NET. 125 |

126 | 127 |

128 | On Unix, typing make install will attempt to install GLEW 129 | into /usr/include/GL and /usr/lib. You can 130 | customize the installation target via the GLEW_DEST 131 | environment variable if you do not have write access to these 132 | directories. 133 |

134 | 135 |

Building Your Project with GLEW

136 |

137 | There are two ways to build your project with GLEW. 138 |

139 |

Including the source files / project file

140 |

141 | The simpler but less flexible way is to include glew.h and 142 | glew.c into your project. On Windows, you also need to 143 | define the GLEW_STATIC preprocessor token when building a 144 | static library or executable, and the GLEW_BUILD preprocessor 145 | token when building a dll. You also need to replace 146 | <GL/gl.h> and <GL/glu.h> with 147 | <glew.h> in your code and set the appropriate include 148 | flag (-I) to tell the compiler where to look for it. For 149 | example: 150 |

151 |

152 | #include <glew.h>
153 | #include <GL/glut.h>
154 | <gl, glu, and glut functionality is available here>
155 |

156 |

157 | Depending on where you put glew.h you may also need to change 158 | the include directives in glew.c. Note that if you are using 159 | GLEW together with GLUT, you have to include glew.h first. 160 | In addition, glew.h includes glu.h, so you do not 161 | need to include it separately. 162 |

163 |

164 | On Windows, you also have the option of adding the supplied project 165 | file glew_static.dsp to your workspace (solution) and compile 166 | it together with your other projects. In this case you also need to 167 | change the GLEW_BUILD preprocessor constant to 168 | GLEW_STATIC when building a static library or executable, 169 | otherwise you get build errors. 170 |

171 |

172 | Note that GLEW does not use the C 173 | runtime library, so it does not matter which version (single-threaded, 174 | multi-threaded or multi-threaded DLL) it is linked with (without 175 | debugging information). It is, however, always a good idea to compile all 176 | your projects including GLEW with the same C runtime settings. 177 |

178 | 179 |

Using GLEW as a shared library

180 | 181 |

182 | Alternatively, you can use the provided project files / makefile to 183 | build a separate shared library you can link your projects with later. 184 | In this case the best practice is to install glew.h, 185 | glew32.lib, and glew32.dll / libGLEW.so to 186 | where the OpenGL equivalents gl.h, opengl32.lib, and 187 | opengl32.dll / libGL.so are located. Note that you 188 | need administrative privileges to do this. If you do not have 189 | administrator access and your system administrator will not do it for 190 | you, you can install GLEW into your own lib and include subdirectories 191 | and tell the compiler where to find it. Then you can just replace 192 | <GL/gl.h> with <GL/glew.h> in your 193 | program: 194 |

195 | 196 |

197 | #include <GL/glew.h>
198 | #include <GL/glut.h>
199 | <gl, glu, and glut functionality is available here>
200 |

201 | 202 |

203 | or: 204 |

205 | 206 |

207 | #include <GL/glew.h>
208 | <gl and glu functionality is available here>
209 |

210 | 211 |

212 | Remember to link your project with glew32.lib, 213 | glu32.lib, and opengl32.lib on Windows and 214 | libGLEW.so, libGLU.so, and libGL.so on 215 | Unix (-lGLEW -lGLU -lGL). 216 |

217 | 218 |

219 | It is important to keep in mind that glew.h includes neither 220 | windows.h nor gl.h. Also, GLEW will warn you by 221 | issuing a preprocessor error in case you have included gl.h, 222 | glext.h, or glATI.h before glew.h. 223 |

224 | 225 | 226 |
227 | 228 | 229 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/khronos.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 The Khronos Group Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and/or associated documentation files (the 5 | "Materials"), to deal in the Materials without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Materials, and to 8 | permit persons to whom the Materials are furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Materials. 13 | 14 | THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 21 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/mesa.txt: -------------------------------------------------------------------------------- 1 | Mesa 3-D graphics library 2 | Version: 7.0 3 | 4 | Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/runtime/glew/doc/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/doc/new.png -------------------------------------------------------------------------------- /src/runtime/glew/doc/ogl_sm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/doc/ogl_sm.jpg -------------------------------------------------------------------------------- /src/runtime/glew/doc/travis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/doc/travis.png -------------------------------------------------------------------------------- /src/runtime/glew/doc/wglew.html: -------------------------------------------------------------------------------- 1 | 2 | 33 | 34 | 35 | 36 | GLEW: The OpenGL Extension Wrangler Library 37 | 38 | 39 | 40 | 41 | 42 | 43 | 91 | 92 |
44 | 45 | 46 | 73 | 74 | 75 | 76 | 88 | 89 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 71 |
Latest Release: 2.2.0

GLEW Logo

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
Download
Usage
Building
Installation
Source Generation
Change Log

GitHub
Issues
Pull Requests
Authors
Licensing

SourceForge Page
70 |

72 |
77 | 78 | 79 | 85 | 86 |
Last Update: 07-24-16
80 | OpenGL Logo
81 | GitHub Logo
82 | Travis Logo
83 | SourceForge Logo 84 |
87 |
90 |
93 | 94 |

The OpenGL Extension Wrangler Library

95 | 96 | 97 | 98 | 99 |

Supported WGL Extensions

100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 |
1 3DFX_multisample

2 3DL_stereo_control

3 AMD_gpu_association

4 ARB_buffer_region
5 ARB_context_flush_control
6 ARB_create_context
7 ARB_create_context_profile
8 ARB_create_context_robustness
9 ARB_extensions_string
10 ARB_framebuffer_sRGB
11 ARB_make_current_read
12 ARB_multisample
13 ARB_pbuffer
14 ARB_pixel_format
15 ARB_pixel_format_float
16 ARB_render_texture
17 ARB_robustness_application_isolation
18 ARB_robustness_share_group_isolation

19 ATI_pixel_format_float
20 ATI_render_texture_rectangle

21 EXT_create_context_es2_profile
22 EXT_create_context_es_profile
23 EXT_depth_float
24 EXT_display_color_table
25 EXT_extensions_string
26 EXT_framebuffer_sRGB
27 EXT_make_current_read
28 EXT_multisample
29 EXT_pbuffer
30 EXT_pixel_format
31 EXT_pixel_format_packed_float
32 EXT_swap_control
33 EXT_swap_control_tear

34 I3D_digital_video_control
35 I3D_gamma
36 I3D_genlock
37 I3D_image_buffer
38 I3D_swap_frame_lock
39 I3D_swap_frame_usage

40 NV_DX_interop
41 NV_DX_interop2
42 NV_copy_image
43 NV_delay_before_swap
44 NV_float_buffer
45 NV_gpu_affinity
46 NV_multisample_coverage
47 NV_present_video
48 NV_render_depth_texture
49 NV_render_texture_rectangle
50 NV_swap_group
51 NV_vertex_array_range
52 NV_video_capture
53 NV_video_output

54 OML_sync_control
165 | 166 |
167 | 168 | 169 | -------------------------------------------------------------------------------- /src/runtime/glew/lib/Release/Win32/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/lib/Release/Win32/glew32.lib -------------------------------------------------------------------------------- /src/runtime/glew/lib/Release/Win32/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/lib/Release/Win32/glew32s.lib -------------------------------------------------------------------------------- /src/runtime/glew/lib/Release/x64/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/lib/Release/x64/glew32.lib -------------------------------------------------------------------------------- /src/runtime/glew/lib/Release/x64/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/src/runtime/glew/lib/Release/x64/glew32s.lib -------------------------------------------------------------------------------- /src/runtime/runtime.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | opengl 7 | 8 | 9 | utils 10 | 11 | 12 | opengl\platform\win 13 | 14 | 15 | opengl 16 | 17 | 18 | opengl 19 | 20 | 21 | opengl\platform\linux 22 | 23 | 24 | 25 | 26 | 27 | opengl 28 | 29 | 30 | utils 31 | 32 | 33 | opengl\platform\win 34 | 35 | 36 | opengl 37 | 38 | 39 | opengl 40 | 41 | 42 | opengl\platform\macos 43 | 44 | 45 | opengl\platform\ios 46 | 47 | 48 | opengl\platform\linux 49 | 50 | 51 | 52 | 53 | {420ad8c2-dd6e-41b1-b43f-0b9fb221586d} 54 | 55 | 56 | {49fa85f3-a50b-4d75-aa95-6a2a35790765} 57 | 58 | 59 | {137be5d0-5b0c-4b02-a418-e936a17fbbb5} 60 | 61 | 62 | {c2a7cedf-e610-4d9d-987e-db69a71ac1c2} 63 | 64 | 65 | {0f075d62-50be-4bfb-ad6e-1ddb1ea8c0ba} 66 | 67 | 68 | {57084d96-03ef-4542-a4b3-cafac16c5db1} 69 | 70 | 71 | {89d05d8f-28fb-47d3-929c-b3cda079206c} 72 | 73 | 74 | 75 | 76 | opengl\platform\macos 77 | 78 | 79 | opengl\platform\ios 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/shell/c4g.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | */ 8 | 9 | #include "c4g_runtime.h" 10 | #include 11 | #ifdef C4G_RUNTIME_OS_WIN 12 | # include 13 | #endif /* C4G_RUNTIME_OS_WIN */ 14 | 15 | #ifdef C4G_RUNTIME_OS_WIN 16 | # define RUNTIME_LIB_NAME L"c4grt.dll" 17 | #endif /* C4G_RUNTIME_OS_WIN */ 18 | 19 | #ifndef C4G_COUNTOF 20 | # define C4G_COUNTOF(__a) (sizeof(__a) / sizeof(*(__a))) 21 | #endif /* !C4G_COUNTOF */ 22 | 23 | struct Runtime final { 24 | #ifdef C4G_RUNTIME_OS_WIN 25 | HINSTANCE _hDll = nullptr; 26 | #endif /* C4G_RUNTIME_OS_WIN */ 27 | 28 | decltype(&c4grt_open) open = nullptr; 29 | decltype(&c4grt_close) close = nullptr; 30 | 31 | decltype(&c4grt_set_error_handler) setErrorHandler = nullptr; 32 | decltype(&c4grt_show_driver_info) showDriverInfo = nullptr; 33 | 34 | decltype(&c4grt_begin) begin = nullptr; 35 | decltype(&c4grt_end) end = nullptr; 36 | 37 | decltype(&c4grt_add_pass) addPass = nullptr; 38 | decltype(&c4grt_set_pass_flow) setPassFlow = nullptr; 39 | decltype(&c4grt_set_pass_pipe) setPassPipe = nullptr; 40 | 41 | decltype(&c4grt_use_gpu_program_file) useGpuProgramFile = nullptr; 42 | decltype(&c4grt_use_gpu_program_string) useGpuProgramString = nullptr; 43 | 44 | decltype(&c4grt_prepare_buffers) prepareBuffers = nullptr; 45 | decltype(&c4grt_prepare_tex) prepareTex = nullptr; 46 | decltype(&c4grt_prepare_uniform) prepareUniform = nullptr; 47 | decltype(&c4grt_prepare_in) prepareIn = nullptr; 48 | decltype(&c4grt_prepare_out) prepareOut = nullptr; 49 | decltype(&c4grt_compute) compute = nullptr; 50 | decltype(&c4grt_map_out) mapOut = nullptr; 51 | decltype(&c4grt_finish) finish = nullptr; 52 | 53 | bool load(void) { 54 | #ifdef C4G_RUNTIME_OS_WIN 55 | _hDll = LoadLibrary(RUNTIME_LIB_NAME); 56 | 57 | if (!_hDll) { 58 | wprintf(L"Cannot find library %s.\n", RUNTIME_LIB_NAME); 59 | 60 | return false; 61 | } 62 | 63 | open = (decltype(open))GetProcAddress(_hDll, "c4grt_open"); 64 | close = (decltype(close))GetProcAddress(_hDll, "c4grt_close"); 65 | setErrorHandler = (decltype(setErrorHandler))GetProcAddress(_hDll, "c4grt_set_error_handler"); 66 | showDriverInfo = (decltype(showDriverInfo))GetProcAddress(_hDll, "c4grt_show_driver_info"); 67 | begin = (decltype(begin))GetProcAddress(_hDll, "c4grt_begin"); 68 | end = (decltype(end))GetProcAddress(_hDll, "c4grt_end"); 69 | addPass = (decltype(addPass))GetProcAddress(_hDll, "c4grt_add_pass"); 70 | setPassFlow = (decltype(setPassFlow))GetProcAddress(_hDll, "c4grt_set_pass_flow"); 71 | setPassPipe = (decltype(setPassPipe))GetProcAddress(_hDll, "c4grt_set_pass_pipe"); 72 | useGpuProgramFile = (decltype(useGpuProgramFile))GetProcAddress(_hDll, "c4grt_use_gpu_program_file"); 73 | useGpuProgramString = (decltype(useGpuProgramString))GetProcAddress(_hDll, "c4grt_use_gpu_program_string"); 74 | prepareBuffers = (decltype(prepareBuffers))GetProcAddress(_hDll, "c4grt_prepare_buffers"); 75 | prepareTex = (decltype(prepareTex))GetProcAddress(_hDll, "c4grt_prepare_tex"); 76 | prepareUniform = (decltype(prepareUniform))GetProcAddress(_hDll, "c4grt_prepare_uniform"); 77 | prepareIn = (decltype(prepareIn))GetProcAddress(_hDll, "c4grt_prepare_in"); 78 | prepareOut = (decltype(prepareOut))GetProcAddress(_hDll, "c4grt_prepare_out"); 79 | compute = (decltype(compute))GetProcAddress(_hDll, "c4grt_compute"); 80 | mapOut = (decltype(mapOut))GetProcAddress(_hDll, "c4grt_map_out"); 81 | finish = (decltype(finish))GetProcAddress(_hDll, "c4grt_finish"); 82 | 83 | bool ret = ( 84 | !!open || 85 | !!close || 86 | !!setErrorHandler || 87 | !!showDriverInfo || 88 | !!begin || 89 | !!end || 90 | !!addPass || 91 | !!setPassFlow || 92 | !!setPassPipe || 93 | !!useGpuProgramFile || 94 | !!useGpuProgramString || 95 | !!prepareBuffers || 96 | !!prepareTex || 97 | !!prepareUniform || 98 | !!prepareIn || 99 | !!prepareOut || 100 | !!compute || 101 | !!mapOut || 102 | !!finish 103 | ); 104 | if (!ret) { 105 | wprintf(L"Incomplete library %s.\n", RUNTIME_LIB_NAME); 106 | 107 | return false; 108 | } 109 | #else 110 | open = c4grt_open; 111 | close = c4grt_close; 112 | setErrorHandler = c4grt_set_error_handler; 113 | showDriverInfo = c4grt_show_driver_info; 114 | begin = c4grt_begin; 115 | end = c4grt_end; 116 | addPass = c4grt_add_pass; 117 | setPassFlow = c4grt_set_pass_flow; 118 | setPassPipe = c4grt_set_pass_pipe; 119 | useGpuProgramFile = c4grt_use_gpu_program_file; 120 | useGpuProgramString = c4grt_use_gpu_program_string; 121 | prepareBuffers = c4grt_prepare_buffers; 122 | prepareTex = c4grt_prepare_tex; 123 | prepareUniform = c4grt_prepare_uniform; 124 | prepareIn = c4grt_prepare_in; 125 | prepareOut = c4grt_prepare_out; 126 | compute = c4grt_compute; 127 | mapOut = c4grt_map_out; 128 | finish = c4grt_finish; 129 | #endif 130 | 131 | return true; 132 | } 133 | bool unload(void) { 134 | #ifdef C4G_RUNTIME_OS_WIN 135 | if (!_hDll) 136 | return false; 137 | 138 | FreeLibrary(_hDll); 139 | #endif 140 | 141 | return true; 142 | } 143 | }; 144 | 145 | static void onError(struct C4GRT_Runtime* rt, C4GRT_PassId pass, const char* const msg) { 146 | printf("%s\n", msg); 147 | } 148 | 149 | int main(int argc, char* argv[]) { 150 | printf("C4G\n"); 151 | 152 | Runtime r; 153 | if (!r.load()) return -1; 154 | 155 | struct C4GRT_Runtime* rt = r.open(); 156 | 157 | r.begin(rt); 158 | r.setErrorHandler(rt, onError); 159 | r.showDriverInfo(rt); 160 | { 161 | const C4GRT_Vec4b ptx0[] = { { 64, 64, 64, 64 }, { 64, 64, 64, 64 }, { 64, 64, 64, 64 }, { 64, 64, 64, 64 } }; 162 | const C4GRT_Tex ptx[] = { 163 | { DT_VEC4B, (unsigned char*)ptx0, C4G_COUNTOF(ptx0), sizeof(C4GRT_Vec4b), "s0", { 2, 2 }, 2 } 164 | }; 165 | const C4GRT_Vec4b tx0[] = { { 128, 128, 128, 128 }, { 128, 128, 128, 128 }, { 128, 128, 128, 128 }, { 128, 128, 128, 128 } }; 166 | const C4GRT_Tex tx[] = { 167 | { DT_VEC4B, (unsigned char*)tx0, C4G_COUNTOF(tx0), sizeof(C4GRT_Vec4b), "s0", { 2, 2 }, 2 } 168 | }; 169 | const C4GRT_Vec4 un0 = { 100, 100, 100, 100 }; 170 | const C4GRT_Data un[] = { 171 | { DT_VEC4, (unsigned char*)&un0, 1, sizeof(C4GRT_Vec4), "u0" } 172 | }; 173 | const C4GRT_Vec4 in0[] = { { 1.3f, 1.4f, 2.1f, 0.123f }, { 2.2f, 1.5f, 0.001f, 0.123f }, { 1.6f, 0.02f, 1.1f, 0.123f }, { 0.05f, 0.03f, 1.2f, 0.123f } }; 174 | const C4GRT_Vec4 in1[] = { { 10, 20, 30, 40 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }; 175 | const C4GRT_Data in[] = { 176 | { DT_VEC4, (unsigned char*)in0, C4G_COUNTOF(in0), sizeof(C4GRT_Vec4), "v0" }, 177 | { DT_VEC4, (unsigned char*)in1, C4G_COUNTOF(in1), sizeof(C4GRT_Vec4), "v1" } 178 | }; 179 | C4GRT_Vec4 pout0[C4G_COUNTOF(in0)] = { 0.0f }; 180 | C4GRT_Vec4 pout1[C4G_COUNTOF(in0)] = { 0.0f }; 181 | const C4GRT_Data pout[] = { 182 | { DT_VEC4, (unsigned char*)pout0, C4G_COUNTOF(pout0), sizeof(C4GRT_Vec4), "o0" }, 183 | { DT_VEC4, (unsigned char*)pout1, C4G_COUNTOF(pout1), sizeof(C4GRT_Vec4), "o1" } 184 | }; 185 | C4GRT_Vec4 out0[C4G_COUNTOF(in0)] = { 0.0f }; 186 | C4GRT_Vec4 out1[C4G_COUNTOF(in0)] = { 0.0f }; 187 | const C4GRT_Data out[] = { 188 | { DT_VEC4, (unsigned char*)out0, C4G_COUNTOF(out0), sizeof(C4GRT_Vec4), "o0" }, 189 | { DT_VEC4, (unsigned char*)out1, C4G_COUNTOF(out1), sizeof(C4GRT_Vec4), "o1" } 190 | }; 191 | C4GRT_PassId p0 = r.addPass(rt, 0); 192 | C4GRT_PassId p1 = r.addPass(rt, p0); 193 | const char* const pipe[] = { "o0", "v0", "o1", "v1" }; 194 | r.setPassPipe(rt, p0, true, pipe, C4G_COUNTOF(pipe)); 195 | const char* const varyings[] = { "o0", "o1" }; 196 | r.useGpuProgramFile(rt, p0, "../data/comp.vert", varyings, C4G_COUNTOF(varyings)); 197 | r.useGpuProgramFile(rt, p1, "../data/comp.vert", varyings, C4G_COUNTOF(varyings)); 198 | r.prepareBuffers(rt, p0, C4G_COUNTOF(ptx), C4G_COUNTOF(in), C4G_COUNTOF(pout)); 199 | r.prepareBuffers(rt, p1, C4G_COUNTOF(tx), 0, C4G_COUNTOF(out)); 200 | { 201 | r.prepareTex(rt, p0, ptx, C4G_COUNTOF(ptx)); 202 | r.prepareTex(rt, p1, tx, C4G_COUNTOF(tx)); 203 | r.prepareUniform(rt, p0, un, C4G_COUNTOF(un)); 204 | r.prepareUniform(rt, p1, un, C4G_COUNTOF(un)); 205 | r.prepareIn(rt, p0, in, C4G_COUNTOF(in)); 206 | r.prepareOut(rt, p0, pout, C4G_COUNTOF(pout)); 207 | r.prepareOut(rt, p1, out, C4G_COUNTOF(out)); 208 | r.compute(rt, p0, false); 209 | r.mapOut(rt, p0); 210 | r.mapOut(rt, p1); 211 | } 212 | r.finish(rt, 0); 213 | } 214 | r.end(rt); 215 | 216 | r.close(rt); 217 | 218 | r.unload(); 219 | 220 | return 0; 221 | } 222 | -------------------------------------------------------------------------------- /src/shell/c4g.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | debug 6 | Win32 7 | 8 | 9 | release 10 | Win32 11 | 12 | 13 | debug 14 | x64 15 | 16 | 17 | release 18 | x64 19 | 20 | 21 | 22 | {B520B141-DC24-422E-A3D2-ACF161C79211} 23 | Win32Proj 24 | c4g 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | $(SolutionDir)..\temp\$(Platform)\$(Configuration)\$(ProjectName)\ 75 | $(SolutionDir)..\output\$(Platform)\$(Configuration)\ 76 | 77 | 78 | true 79 | $(SolutionDir)..\output\$(Platform)\$(Configuration)\ 80 | $(SolutionDir)..\temp\$(Platform)\$(Configuration)\$(ProjectName)\ 81 | 82 | 83 | false 84 | $(SolutionDir)..\temp\$(Platform)\$(Configuration)\$(ProjectName)\ 85 | $(SolutionDir)..\output\$(Platform)\$(Configuration)\ 86 | 87 | 88 | false 89 | $(SolutionDir)..\temp\$(Platform)\$(Configuration)\$(ProjectName)\ 90 | $(SolutionDir)..\output\$(Platform)\$(Configuration)\ 91 | 92 | 93 | 94 | 95 | 96 | Level3 97 | Disabled 98 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 99 | true 100 | ../compiler;$(SolutionDir)..\include;%(AdditionalIncludeDirectories) 101 | 102 | 103 | Console 104 | true 105 | 106 | 107 | 108 | 109 | 110 | 111 | Level3 112 | Disabled 113 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 114 | true 115 | ../compiler;$(SolutionDir)..\include;%(AdditionalIncludeDirectories) 116 | 117 | 118 | Console 119 | true 120 | 121 | 122 | 123 | 124 | Level3 125 | 126 | 127 | MaxSpeed 128 | true 129 | true 130 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 131 | true 132 | ../compiler;$(SolutionDir)..\include;%(AdditionalIncludeDirectories) 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | Level3 144 | 145 | 146 | MaxSpeed 147 | true 148 | true 149 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 150 | true 151 | ../compiler;$(SolutionDir)..\include;%(AdditionalIncludeDirectories) 152 | 153 | 154 | Console 155 | true 156 | true 157 | true 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /src/shell/c4g.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /test/c4grt.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/test/c4grt.dll -------------------------------------------------------------------------------- /test/c4grt_eval.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/test/c4grt_eval.exe -------------------------------------------------------------------------------- /test/c_eval.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/test/c_eval.exe -------------------------------------------------------------------------------- /test/c_eval/c_eval.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | ** 8 | ** The native C eval test. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #ifdef _MSC_VER 17 | # include 18 | # include 19 | #endif /* _MSC_VER */ 20 | #ifdef __clang__ 21 | # include 22 | #endif /* __clang__ */ 23 | 24 | typedef struct Vector2 { 25 | float x, y; 26 | } Vector2; 27 | 28 | typedef struct Vector4 { 29 | float x, y, z, w; 30 | } Vector4; 31 | 32 | static float vec2_length(Vector2* p) { 33 | return (float)sqrt(p->x * p->x + p->y * p->y); 34 | } 35 | 36 | static void vec2_mul_float(Vector2* p, float q) { 37 | p->x *= q; 38 | p->y *= q; 39 | } 40 | 41 | static void vec2_mul_vec2(Vector2* p, Vector2* q) { 42 | p->x *= q->x; 43 | p->y *= q->y; 44 | } 45 | 46 | static void vec4_add_vec4(Vector4* p, Vector4* q) { 47 | p->x += q->x; 48 | p->y += q->y; 49 | p->z += q->z; 50 | p->w += q->w; 51 | } 52 | 53 | static void vec4_mul_float(Vector4* p, float q) { 54 | p->x *= q; 55 | p->y *= q; 56 | p->z *= q; 57 | p->w *= q; 58 | } 59 | 60 | static void accel(Vector2* out, Vector2* p) { 61 | float l = 1.0f / vec2_length(p); 62 | *out = *p; 63 | vec2_mul_float(out, -1 * (l * l * l)); 64 | } 65 | 66 | static void eval(Vector4* out, Vector4* u0, Vector4* v0) { 67 | Vector4 p = *u0; 68 | Vector4 v = *v0; 69 | const float dt = 0.1f; 70 | for (int i = 0; i < 10000; ++i) { 71 | Vector2 a1, a2; 72 | Vector2 m = { p.x, p.y }; 73 | Vector2 n = { p.z, p.w }; 74 | accel(&a1, &m); 75 | accel(&a2, &n); 76 | Vector4 a = { a1.x, a1.y, a2.x, a2.y }; 77 | Vector4 _v = v; 78 | vec4_mul_float(&_v, dt); 79 | vec4_add_vec4(&p, &_v); 80 | vec4_mul_float(&a, dt); 81 | vec4_add_vec4(&v, &a); 82 | } 83 | *out = p; 84 | } 85 | 86 | #if defined _MSC_VER || defined __BORLANDC__ 87 | static unsigned ticks(void) { 88 | LARGE_INTEGER li; 89 | double freq = 0.0; 90 | unsigned ret = 0; 91 | 92 | QueryPerformanceFrequency(&li); 93 | freq = (double)li.QuadPart / 1000.0; 94 | QueryPerformanceCounter(&li); 95 | ret = (unsigned)((double)li.QuadPart / freq); 96 | 97 | return ret; 98 | } 99 | #elif defined __clang__ 100 | static unsigned ticks(void) { 101 | struct timespec ts; 102 | struct timeval now; 103 | int rv = 0; 104 | 105 | rv = gettimeofday(&now, 0); 106 | if (rv) 107 | return 0; 108 | 109 | ts.tv_sec = now.tv_sec; 110 | ts.tv_nsec = now.tv_usec * 1000; 111 | 112 | return (unsigned)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); 113 | } 114 | #elif defined __GNUC__ || defined __GNUG__ 115 | static unsigned ticks(void) { 116 | struct timespec ts; 117 | 118 | clock_gettime(CLOCK_MONOTONIC, &ts); 119 | 120 | return (unsigned)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); 121 | } 122 | #endif /* _MSC_VER || __BORLANDC__ */ 123 | 124 | int main(int argc, char* argv[]) { 125 | size_t len = 0; 126 | Vector4 un0; 127 | Vector4* in0 = NULL; 128 | Vector4* out0 = NULL; 129 | size_t i = 0; 130 | unsigned t = 0; 131 | 132 | printf("Native C Eval\n"); 133 | 134 | // Prepares. 135 | printf("Preparing...\n"); 136 | len = 1000000; 137 | un0.x = 100; un0.y = 100; un0.z = 100; un0.w = 100; 138 | in0 = (Vector4*)malloc(sizeof(Vector4) * len); 139 | for (i = 0; i < len; ++i) { 140 | Vector4 v = { 1, 2, 3, 4 }; 141 | in0[i] = v; 142 | } 143 | out0 = (Vector4*)malloc(sizeof(Vector4) * len); 144 | memset(out0, 0, sizeof(Vector4) * len); 145 | 146 | // Computes. 147 | printf("Begin compute...\n"); 148 | t = ticks(); 149 | for (i = 0; i < len; ++i) { 150 | eval(&out0[i], &un0, &in0[i]); 151 | } 152 | printf("%dms cost.\n", ticks() - t); 153 | 154 | // Done. 155 | printf("Done.\n"); 156 | free(in0); 157 | free(out0); 158 | 159 | getchar(); 160 | 161 | return 0; 162 | } 163 | -------------------------------------------------------------------------------- /test/cs_eval.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/test/cs_eval.exe -------------------------------------------------------------------------------- /test/freeglut.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/test/freeglut.dll -------------------------------------------------------------------------------- /test/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paladin-t/c4gpu/82dda2014fd2ae5c745ebdc6a797bb5f87793816/test/glew32.dll -------------------------------------------------------------------------------- /test/prog.bas: -------------------------------------------------------------------------------- 1 | REM C4GPU. 2 | REM 3 | REM For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 4 | REM 5 | REM Copyright (C) 2017 Wang Renxin. All rights reserved. 6 | REM 7 | REM This is a MY-BASIC powered script. 8 | 9 | import "@c4g" 10 | import "@file" 11 | 12 | ' Config. 13 | write_to_file = false ' Change this to true to enable logging to file. 14 | 15 | ' Uniform. 16 | print "Prepare uniform data..."; 17 | un0 = vec4_array("u0") 18 | un0.push(100, 100, 100, 100) 19 | una0 = data_array() 20 | una0.push(un0) 21 | 22 | ' Input data. 23 | print "Prepare input buffer..."; 24 | in0 = vec4_array("v0") 25 | for i = 1 to 1000000 26 | in0.push(1, 2, 3, 4) 27 | next 28 | ina0 = data_array() 29 | ina0.push(in0) 30 | 31 | ' Output buffer. 32 | print "Prepare output buffer..."; 33 | out0 = vec4_array("o0") 34 | out0.resize(len(in0)) 35 | outa0 = data_array() 36 | outa0.push(out0) 37 | 38 | ' Prepares. 39 | print "Prepare context..."; 40 | rt = runtime() 41 | rt.begin_proc() 42 | rt.set_error_handler(lambda (_pass, _msg) ( print _msg; )) 43 | rt.show_driver_info() 44 | p0 = rt.add_pass() 45 | rt.use_gpu_program_file(p0, "prog.vert", "o0") 46 | 47 | rt.prepare_buffers(p0, 0, len(ina0), len(outa0)) 48 | rt.prepare_uniform(p0, una0) 49 | rt.prepare_in(p0, ina0) 50 | rt.prepare_out(p0, outa0) 51 | 52 | ' Computes. 53 | print "Begin compute..."; 54 | t = ticks() 55 | rt.compute(p0) 56 | t = ticks() - t 57 | print t, "ms cost."; 58 | 59 | ' Finishes. 60 | print "Finish..."; 61 | rt.map_out(p0) 62 | rt.finish() 63 | rt.end_proc() 64 | 65 | ' Write to file? 66 | if write_to_file then 67 | print "Write to file..."; 68 | fp = file() 69 | fp.open("c4grt_eval.log", "w") 70 | fp.write_line("Output 0:") 71 | fp.write(out0) 72 | fp.close() 73 | endif 74 | print "Done."; 75 | 76 | input 77 | -------------------------------------------------------------------------------- /test/prog.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ** C4GPU. 3 | ** 4 | ** For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 5 | ** 6 | ** Copyright (C) 2017 Wang Renxin. All rights reserved. 7 | ** 8 | ** The C# eval test. 9 | */ 10 | 11 | using System; 12 | using System.Diagnostics; 13 | using System.Threading.Tasks; 14 | 15 | public class Program 16 | { 17 | public struct Vector2 18 | { 19 | public float x, y; 20 | 21 | public Vector2(float _x, float _y) 22 | { 23 | x = _x; y = _y; 24 | } 25 | } 26 | 27 | public struct Vector4 28 | { 29 | public float x, y, z, w; 30 | 31 | public Vector4(float _x, float _y, float _z, float _w) 32 | { 33 | x = _x; y = _y; z = _z; w = _w; 34 | } 35 | } 36 | 37 | private unsafe static float vec2_length(Vector2* p) 38 | { 39 | return (float)Math.Sqrt(p->x * p->x + p->y * p->y); 40 | } 41 | 42 | private unsafe static void vec2_mul_float(Vector2* p, float q) 43 | { 44 | p->x *= q; 45 | p->y *= q; 46 | } 47 | 48 | private unsafe static void vec2_mul_vec2(Vector2* p, Vector2* q) 49 | { 50 | p->x *= q->x; 51 | p->y *= q->y; 52 | } 53 | 54 | private unsafe static void vec4_add_vec4(Vector4* p, Vector4* q) 55 | { 56 | p->x += q->x; 57 | p->y += q->y; 58 | p->z += q->z; 59 | p->w += q->w; 60 | } 61 | 62 | private unsafe static void vec4_mul_float(Vector4* p, float q) 63 | { 64 | p->x *= q; 65 | p->y *= q; 66 | p->z *= q; 67 | p->w *= q; 68 | } 69 | 70 | private unsafe static void accel(Vector2* o, Vector2* p) 71 | { 72 | float l = 1.0f / vec2_length(p); 73 | vec2_mul_float(o, -1 * (l * l * l)); 74 | } 75 | 76 | private unsafe static void eval(Vector4* o, Vector4* u0, Vector4* v0) 77 | { 78 | Vector4 p = *u0; 79 | Vector4 v = *v0; 80 | const float dt = 0.1f; 81 | for (int i = 0; i < 10000; ++i) 82 | { 83 | Vector2 a1, a2; 84 | Vector2 m = new Vector2(p.x, p.y); 85 | Vector2 n = new Vector2(p.z, p.w); 86 | accel(&a1, &m); 87 | accel(&a2, &n); 88 | Vector4 a = new Vector4(a1.x, a1.y, a2.x, a2.y); 89 | Vector4 _v = v; 90 | vec4_mul_float(&_v, dt); 91 | vec4_add_vec4(&p, &_v); 92 | vec4_mul_float(&a, dt); 93 | vec4_add_vec4(&v, &a); 94 | } 95 | *o = p; 96 | } 97 | 98 | public unsafe static void Main() 99 | { 100 | // Prepares. 101 | Console.Out.WriteLine("Preparing..."); 102 | Vector4 un0 = new Vector4(100, 100, 100, 100); 103 | Vector4[] in0 = new Vector4[1000000]; 104 | for (int i = 0; i < in0.Length; ++i) 105 | { 106 | in0[i] = new Vector4(1, 2, 3, 4); 107 | } 108 | Vector4[] out0 = new Vector4[in0.Length]; 109 | 110 | // Computes. 111 | Console.Out.WriteLine("Begin compute..."); 112 | Stopwatch sw = new Stopwatch(); 113 | sw.Start(); 114 | 115 | for (int i = 0; i < in0.Length; ++i) 116 | { 117 | fixed (Vector4* a = &out0[i], b = &in0[i]) 118 | { 119 | eval(a, &un0, b); 120 | } 121 | } 122 | 123 | sw.Stop(); 124 | Console.Out.WriteLine(string.Format("{0}ms cost.", sw.ElapsedMilliseconds)); 125 | 126 | // Done. 127 | Console.Out.WriteLine("Done."); 128 | 129 | Console.In.Read(); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /test/prog.vert: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | 3 | uniform vec4 u0; 4 | in vec4 v0; 5 | out vec4 o0; 6 | 7 | vec2 accel(vec2 p) { 8 | float l = 1.0 / length(p); 9 | return -p * (l * l * l); 10 | } 11 | 12 | void main() { 13 | vec4 p = u0; 14 | vec4 v = v0; 15 | const float dt = 0.1; 16 | for (int i = 0; i < 10000; ++i) { 17 | vec2 a1 = accel(vec2(p.x, p.y)); 18 | vec2 a2 = accel(vec2(p.z, p.w)); 19 | vec4 a = vec4(a1, a2); 20 | p += v * dt; 21 | v += a * dt; 22 | } 23 | o0 = p; 24 | } 25 | -------------------------------------------------------------------------------- /test/test.bas: -------------------------------------------------------------------------------- 1 | REM C4GPU. 2 | REM 3 | REM For the latest info, see https://github.com/c4gpu/c4gpu_runtime/ 4 | REM 5 | REM Copyright (C) 2017 Wang Renxin. All rights reserved. 6 | REM 7 | REM This is a MY-BASIC powered script. 8 | 9 | import "@c4g" 10 | import "@file" 11 | 12 | ' Config. 13 | write_to_file = false ' Change this to true to enable logging to file. 14 | 15 | ' Texture data. 16 | print "Prepare texture data..."; 17 | tx0 = vec4b_array("s0") 18 | tx0.push(128, 128, 128, 128) 19 | tx0.push(128, 128, 128, 128) 20 | tx0.push(128, 128, 128, 128) 21 | tx0.push(128, 128, 128, 128) 22 | txa0 = tex_array() 23 | txa0.push(tx0, 2, 2) 24 | 25 | ' Uniform. 26 | print "Prepare uniform data..."; 27 | un0 = vec4_array("u0") 28 | un0.push(100, 100, 100, 100) 29 | una0 = data_array() 30 | una0.push(un0) 31 | 32 | ' Input data. 33 | print "Prepare input buffer..."; 34 | in0 = vec4_array("v0") 35 | for i = 1 to 10000 36 | in0.push(1, 2, 3, 4) 37 | next 38 | in1 = vec4_array("v1") 39 | for i = 1 to 10000 40 | in1.push(1, 2, 3, 4) 41 | next 42 | ina0 = data_array() 43 | ina0.push(in0) 44 | ina0.push(in1) 45 | 46 | ' Output buffer. 47 | print "Prepare output buffer..."; 48 | out0 = vec4_array("o0") 49 | out1 = vec4_array("o1") 50 | out0.resize(len(in0)) 51 | out1.resize(len(in0)) 52 | outa0 = data_array() 53 | outa0.push(out0) 54 | outa0.push(out1) 55 | 56 | out2 = vec4_array("o0") 57 | out3 = vec4_array("o1") 58 | out2.resize(len(in0)) 59 | out3.resize(len(in0)) 60 | outa1 = data_array() 61 | outa1.push(out2) 62 | outa1.push(out3) 63 | 64 | ' Prepares. 65 | print "Prepare context..."; 66 | rt = runtime() 67 | rt.begin_proc() 68 | rt.set_error_handler(lambda (_pass, _msg) ( print _msg; )) 69 | rt.show_driver_info() 70 | p0 = rt.add_pass() 71 | p1 = rt.add_pass(p0) 72 | rt.set_pass_pipe(p0, true, "o0", "v0", "o1", "v1") 73 | rt.use_gpu_program_file(p0, "test.vert", "o0", "o1") 74 | rt.use_gpu_program_file(p1, "test.vert", "o0", "o1") 75 | 76 | rt.prepare_buffers(p0, len(txa0), len(ina0), len(outa0)) 77 | rt.prepare_buffers(p1, len(txa0), 0, len(outa1)) 78 | rt.prepare_tex(p0, txa0) 79 | rt.prepare_tex(p1, txa0) 80 | rt.prepare_uniform(p0, una0) 81 | rt.prepare_uniform(p1, una0) 82 | rt.prepare_in(p0, ina0) 83 | rt.prepare_out(p0, outa0) 84 | rt.prepare_out(p1, outa1) 85 | 86 | ' Computes. 87 | print "Begin compute..."; 88 | t = ticks() 89 | rt.compute(p0) 90 | t = ticks() - t 91 | print t, "ms cost."; 92 | 93 | ' Finishes. 94 | print "Finish..."; 95 | rt.map_out(p0) 96 | rt.map_out(p1) 97 | rt.finish() 98 | rt.end_proc() 99 | 100 | ' Write to file? 101 | if write_to_file then 102 | print "Write to file..."; 103 | fp = file() 104 | fp.open("c4grt_eval.log", "w") 105 | fp.write_line("Output 0:") 106 | fp.write(out2) 107 | fp.write_line() 108 | fp.write_line("Output 1:") 109 | fp.write(out3) 110 | fp.close() 111 | endif 112 | print "Done."; 113 | 114 | input 115 | -------------------------------------------------------------------------------- /test/test.vert: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | 3 | uniform sampler2D s0; 4 | uniform vec4 u0; 5 | in vec4 v0; 6 | in vec4 v1; 7 | out vec4 o0; 8 | out vec4 o1; 9 | 10 | void main() { 11 | o0 = v0 + v1 + u0; 12 | o1 = texture2D(s0, vec2(1, 1)) + u0; 13 | } 14 | --------------------------------------------------------------------------------