Skip to content

Commit 09fe73d

Browse files
committed
v4l and opengl revamp
1 parent acc9203 commit 09fe73d

26 files changed

+1116
-787
lines changed

opencl/benchmarks.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
- <https://compubench.com> Also from Kishonti who makes GFXBench.
44
- <http://geekbench.com/> Proprietary by <http://www.primatelabs.com/>, looks like similar business model to Kishonti (license source).
5+
- <https://github.com/vetter/shoc> BSD

opencl/introduction.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ OpenCL, like any other language has versions. As of 2013 the latest version is O
2323

2424
## OpenCL and OpenGL integration
2525

26-
- <http://stackoverflow.com/questions/4005935/mix-opencl-with-opengl>
2726
- <http://enja.org/2010/08/27/adventures-in-opencl-part-2-particles-with-opengl/>
27+
- <http://stackoverflow.com/questions/17899514/opencl-opengl-interop-performance>
28+
- <http://stackoverflow.com/questions/4005935/mix-opencl-with-opengl>
29+
- <http://stackoverflow.com/questions/7907510/opengl-vs-opencl-which-to-choose-and-why>
30+
- <http://stackoverflow.com/questions/8824269/gl-cl-interoperability-shared-texture>
31+
- <https://github.com/9prady9/CLGLInterop>
2832

29-
Also see compute shaders for OpenGL, they seem to integrate better.
33+
Also see compute shaders for OpenGL 4.X, they seem to integrate better.

opengl/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@
4949
1. [IBO](glfw_ibo.c)
5050
1. [transform](glfw_transform.c)
5151
1. [gl_FragCoord](glfw_gl_frag_coord.c)
52-
1. [heatmap](glfw_heatmap.c)
5352
1. [Texture](glfw_texture.c)
53+
1. [Image processing](glfw_image_processing.c.off)
54+
1. [Recursive](glfw_recursive.c.off)
55+
1. [heatmap](glfw_heatmap.c)
5456
1. Naughty
5557
1. [Infinite loop shader](glfw_infinite_loop_shader.c.off)
5658
1. [Memory overflow shader](glfw_memory_overflow_shader.c.off)

opengl/TODO.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
- HUD, billboards, draw pixel on screen:
8383
- people suggest: glOrtho + disable depth tests
8484
- could think about a transparent texture right on top of the camera
85-
- http://stackoverflow.com/questions/10040961/opengl-pixel-perfect-2d-drawing
8685
- http://stackoverflow.com/questions/4282036/rendering-2d-sprites-in-a-3d-world/36568461#36568461
8786
- http://stackoverflow.com/questions/6151135/in-opengl-can-i-draw-a-pixel-that-exactly-at-the-coordinates-5-5
8887
- http://gamedev.stackexchange.com/questions/5959/rendering-2d-sprites-into-a-3d-world/119739#119739
@@ -91,6 +90,11 @@
9190
- http://stackoverflow.com/questions/18362058/opengl-draw-pixels-directly
9291
- http://stackoverflow.com/questions/6644248/how-to-draw-opencl-calculated-pixels-to-the-screen-with-opengl
9392
- also useful to render "particles": things that are so far / so small that a billboards approximate well enough with less overhead
93+
- 2D acceleration (translation, rotation, alpha blending, z-order) and pixel perfectness:
94+
- http://stackoverflow.com/questions/10040961/opengl-pixel-perfect-2d-drawing
95+
- http://stackoverflow.com/questions/3919307/is-there-a-2d-graphics-api-with-both-pixel-perfect-drawing-and-2d-hardware-accel
96+
- <http://stackoverflow.com/questions/7922526/opengl-deterministic-rendering-between-gpu-vendor>
97+
- <http://stackoverflow.com/questions/671395/a-simple-2d-cross-platform-graphics-library-for-c-or-c/718384#718384>
9498
- text, fonts
9599
- glut does it
96100
- non trivial: most fonts are specified in vector formats with Bezier curves, and OpenGL does not have any primitives for that

opengl/benchmarks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Free:
1212

1313
Non free:
1414

15-
- GFXBench: <https://gfxbench.com/result.jsp>
15+
- GFXBench: <https://gfxbench.com/result.jsp> By a company called Koshonti. You can run it for free on most devices, but they license the source (and TODO more complete versions?) to companies as a business model.

opengl/bibliography.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Tutorials with runnable version tracked code:
3636

3737
Samples without tutorial:
3838

39+
- <https://github.com/openglsuperbible/sb7code> MIT licensed samples from OpenGL superbible book by AMD employee. Very good.
3940
- <https://github.com/g-truc/ogl-samples> Many precise examples of specific OpenGL API features, organized by API version.
4041

4142
Tutorials with runnable code that is not version tracked:
@@ -62,7 +63,6 @@ Demos:
6263

6364
- <https://github.com/prideout/recipes>
6465
- <https://www.youtube.com/watch?v=H-3yPXXZUC8>
65-
- <https://github.com/premsasidharan/gpu_img_proc/tree/master/test/edge_camera> <https://www.youtube.com/watch?v=fJtOdJ9MHsA> GLSL Linux camera real time edge detection shown on screen. Getting started: <https://github.com/premsasidharan/gpu_img_proc/issues/1#issuecomment-257504913>
6666

6767
Unevaluated:
6868

opengl/glfw_gl_frag_coord.c

+26-24
Original file line numberDiff line numberDiff line change
@@ -34,48 +34,50 @@ static const GLfloat vertices[] = {
3434

3535
int main(void) {
3636
GLFWwindow *window;
37-
GLint attribute_coord2d, program;
38-
GLuint vbo;
37+
GLint attribute_coord2d;
38+
GLuint program, vbo;
3939
const char *attribute_name = "coord2d";
4040

41+
/* Window system. */
4142
glfwInit();
43+
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
4244
window = glfwCreateWindow(WIDTH, HEIGHT, __FILE__, NULL, NULL);
4345
glfwMakeContextCurrent(window);
4446
glewInit();
4547

48+
/* Shader setup. */
4649
program = common_get_shader_program(vertex_shader_source, fragment_shader_source);
4750
attribute_coord2d = glGetAttribLocation(program, attribute_name);
48-
if (attribute_coord2d == -1) {
49-
fprintf(stderr, "error: attribute_coord2d: %s\n", attribute_name);
50-
return EXIT_FAILURE;
51-
}
52-
53-
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
54-
glUseProgram(program);
55-
glViewport(0, 0, WIDTH, HEIGHT);
5651

52+
/* vbo */
5753
glGenBuffers(1, &vbo);
5854
glBindBuffer(GL_ARRAY_BUFFER, vbo);
5955
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
6056

57+
/* Draw. */
58+
glViewport(0, 0, WIDTH, HEIGHT);
59+
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
60+
glClear(GL_COLOR_BUFFER_BIT);
61+
glUseProgram(program);
62+
glEnableVertexAttribArray(attribute_coord2d);
63+
glVertexAttribPointer(
64+
attribute_coord2d,
65+
2,
66+
GL_FLOAT,
67+
GL_FALSE,
68+
0,
69+
0
70+
);
71+
glDrawArrays(GL_TRIANGLES, 0, 6);
72+
glDisableVertexAttribArray(attribute_coord2d);
73+
glfwSwapBuffers(window);
74+
75+
/* Main loop. */
6176
while (!glfwWindowShouldClose(window)) {
6277
glfwPollEvents();
63-
glClear(GL_COLOR_BUFFER_BIT);
64-
glEnableVertexAttribArray(attribute_coord2d);
65-
glVertexAttribPointer(
66-
attribute_coord2d,
67-
2,
68-
GL_FLOAT,
69-
GL_FALSE,
70-
0,
71-
0
72-
);
73-
glDrawArrays(GL_TRIANGLES, 0, 6);
74-
glDisableVertexAttribArray(attribute_coord2d);
75-
glfwSwapBuffers(window);
76-
glfwSwapBuffers(window);
7778
}
7879

80+
/* Cleanup. */
7981
glDeleteBuffers(1, &vbo);
8082
glDeleteProgram(program);
8183
glfwTerminate();

opengl/glfw_heatmap.c

+23-36
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ static const GLchar* fragment_shader_source =
1212
"#version 120\n"
1313
"uniform float pi2;\n"
1414
"uniform float time;\n"
15-
"uniform float width;\n"
16-
"uniform float height;\n"
17-
"uniform float periods_x;\n"
18-
"uniform float periods_y;\n"
15+
"uniform vec2 win_dim;\n"
16+
"uniform vec2 periods;\n"
1917
"void main(void) {\n"
20-
" float center_x = width / 2.0;"
21-
" float center_y = height / 2.0;"
22-
" float x = (gl_FragCoord.x - center_x) * periods_x / width;"
23-
" float y = (gl_FragCoord.y - center_y) * periods_y / height;"
24-
" gl_FragColor[0] = 0.5 * (1.0 + (sin((pi2 * (sqrt(x*x + y*y) + time)))));\n"
18+
" vec2 center = win_dim / 2.0;"
19+
" vec2 xy = (gl_FragCoord.xy - center) * periods / win_dim;"
20+
" gl_FragColor[0] = 0.5 * (1.0 + (sin((pi2 * (length(xy) + time)))));\n"
2521
" gl_FragColor[1] = 0.0;\n"
2622
" gl_FragColor[2] = 0.0;\n"
2723
"}\n";
@@ -41,15 +37,12 @@ int main(void) {
4137
GLint
4238
attribute_coord2d,
4339
ibo_size,
44-
width_location,
45-
height_location,
46-
time_location,
47-
periods_x_location,
48-
periods_y_location,
40+
periods_location,
4941
pi2_location,
50-
program
42+
time_location,
43+
win_dim_location
5144
;
52-
GLuint ibo, vbo;
45+
GLuint ibo, program, vbo;
5346
const char *attribute_name = "coord2d";
5447
const float
5548
periods_x = 5.0,
@@ -66,12 +59,10 @@ int main(void) {
6659
/* Shader setup. */
6760
program = common_get_shader_program(vertex_shader_source, fragment_shader_source);
6861
attribute_coord2d = glGetAttribLocation(program, attribute_name);
69-
height_location = glGetUniformLocation(program, "height");
70-
periods_x_location = glGetUniformLocation(program, "periods_x");
71-
periods_y_location = glGetUniformLocation(program, "periods_y");
62+
periods_location = glGetUniformLocation(program, "periods");
7263
pi2_location = glGetUniformLocation(program, "pi2");
7364
time_location = glGetUniformLocation(program, "time");
74-
width_location = glGetUniformLocation(program, "width");
65+
win_dim_location = glGetUniformLocation(program, "win_dim");
7566

7667
/* Global settings. */
7768
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@@ -82,6 +73,15 @@ int main(void) {
8273
glGenBuffers(1, &vbo);
8374
glBindBuffer(GL_ARRAY_BUFFER, vbo);
8475
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
76+
glVertexAttribPointer(
77+
attribute_coord2d,
78+
2,
79+
GL_FLOAT,
80+
GL_FALSE,
81+
0,
82+
0
83+
);
84+
glEnableVertexAttribArray(attribute_coord2d);
8585

8686
/* ibo */
8787
glGenBuffers(1, &ibo);
@@ -91,35 +91,22 @@ int main(void) {
9191

9292
/* Uniforms. */
9393
glUniform1f(pi2_location, pi2);
94-
glUniform1f(width_location, WIDTH);
95-
glUniform1f(height_location, HEIGHT);
96-
glUniform1f(periods_x_location, periods_x);
97-
glUniform1f(periods_y_location, periods_y);
94+
glUniform2f(win_dim_location, WIDTH, HEIGHT);
95+
glUniform2f(periods_location, periods_x, periods_y);
9896

9997
/* Main loop. */
10098
common_fps_init();
10199
while (!glfwWindowShouldClose(window)) {
102100
glfwPollEvents();
103101
glClear(GL_COLOR_BUFFER_BIT);
104-
glEnableVertexAttribArray(attribute_coord2d);
105-
glBindBuffer(GL_ARRAY_BUFFER, vbo);
106-
glVertexAttribPointer(
107-
attribute_coord2d,
108-
2,
109-
GL_FLOAT,
110-
GL_FALSE,
111-
0,
112-
0
113-
);
114-
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
115102
glUniform1f(time_location, glfwGetTime());
116103
glDrawElements(GL_TRIANGLES, ibo_size / sizeof(indexes[0]), GL_UNSIGNED_INT, 0);
117-
glDisableVertexAttribArray(attribute_coord2d);
118104
glfwSwapBuffers(window);
119105
common_fps_print();
120106
}
121107

122108
/* Cleanup. */
109+
glDisableVertexAttribArray(attribute_coord2d);
123110
glDeleteBuffers(1, &ibo);
124111
glDeleteBuffers(1, &vbo);
125112
glDeleteProgram(program);

opengl/glfw_image_process.c.off

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
The principle is that fragment shaders can access any byte of a texture,
3+
and so do operations over multiple pixels.
4+
5+
- <http://stackoverflow.com/questions/13693946/image-processing-with-glsl-shaders>
6+
- <https://github.com/premsasidharan/gpu_img_proc/tree/master/test/edge_camera>
7+
<https://www.youtube.com/watch?v=fJtOdJ9MHsA> GLSL Linux camera real time edge detection shown on screen. Getting started: <https://github.com/premsasidharan/gpu_img_proc/issues/1#issuecomment-257504913>
8+
9+
Post processing is equivalent to image processing (unless there is some
10+
magic Krhonos way to bypass the CPU camera image copy to texture):
11+
12+
- <https://en.wikibooks.org/wiki/OpenGL_Programming/Post-Processing>
13+
- r3dux tori demo <https://www.youtube.com/watch?v=9nDxIbj3mPU>
14+
*/

opengl/glfw_recursive.c.off

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Recursive calculations where the input to the next frame is the previous frame.
3+
4+
Conway's game of life is a popular example:
5+
6+
- http://nullprogram.com/blog/2014/06/10/
7+
- http://gamedev.stackexchange.com/questions/87213/how-to-read-neighbor-pixels-in-glsl
8+
*/

0 commit comments

Comments
 (0)