├── .gitignore
├── LICENSE
├── README.md
├── USAGE.md
├── android_gl_server
├── AndroidManifest.xml
├── jni
│ ├── Android.mk
│ ├── Application.mk
│ └── glstreaming_jni.cpp
├── libs
│ ├── armeabi-v7a
│ │ ├── gdb.setup
│ │ └── gdbserver
│ ├── armeabi
│ │ ├── gdb.setup
│ │ └── gdbserver
│ └── x86
│ │ ├── gdb.setup
│ │ └── gdbserver
├── project.properties
├── res
│ ├── layout
│ │ ├── config.xml
│ │ └── main.xml
│ ├── menu
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── com
│ └── kdt
│ └── glstreamserver
│ ├── GLStreamingActivity.java
│ ├── GLStreamingJNIWrapper.java
│ └── GLStreamingView.java
├── common
├── fastlog.h
├── fifo.c
├── fifo.h
├── gls_command.h
├── server.c
├── server.h
└── utils.h
├── contributors.txt
├── gl_client
├── Android.mk
├── Makefile
├── clientegl.c
├── clientgles.c
├── glclient.c
├── glclient.h
├── include
│ ├── EGL
│ │ ├── egl.h
│ │ ├── eglext.h
│ │ └── eglplatform.h
│ ├── GLES2
│ │ ├── gl2.h
│ │ └── gl2platform.h
│ └── KHR
│ │ └── khrplatform.h
├── samples
│ ├── Makefile
│ ├── glsutil.c
│ ├── glsutil.h
│ ├── model1.h
│ ├── sample1.c
│ ├── sample2
│ ├── sample2.c
│ └── texture1.bmp
└── todo_add.txt
├── gl_server
├── Android.mk
├── Makefile
├── glcontrol.c
├── glcontrol.h
├── glserver.c
├── glserver.h
├── main.c
├── main.h
├── serveregl.c
└── servergles.c
└── www
├── GLStreaming.png
├── Screenshot_2020-05-19-09-42-24.png
└── gl-streaming_small.png
/.gitignore:
--------------------------------------------------------------------------------
1 | # Object files
2 | *.o
3 | *.ko
4 |
5 | # Libraries
6 | *.lib
7 | *.a
8 |
9 | # Shared objects (inc. Windows DLLs)
10 | *.dll
11 | *.so
12 | *.so.*
13 | *.dylib
14 |
15 | # Executables
16 | *.exe
17 | *.out
18 | *.app
19 |
20 | # Android app generated files
21 | android_gl_server/*.s
22 | android_gl_server/bin
23 | android_gl_server/gen
24 | # Adding below remove even .so and .jar library!
25 | # android_gl_server/libs
26 | android_gl_server/obj
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, Shodruky Rhyammer
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | Redistributions in binary form must reproduce the above copyright notice, this
11 | list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 |
14 | Neither the name of the copyright holders nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # gl-streaming
2 |
3 |
4 | 
5 |
6 | Streaming opengl commands over network
7 |
8 | A fast, simple, lightweight and low latency framework suitable for embedded systems.
9 |
10 | > - Original image
11 | > 
12 |
13 | * gl_client : client framework and sample program
14 |
15 | The client system may not need to have any GPU. Even without GPU, opengl programs can be run on any system !
16 |
17 | (X Server is now required by client).
18 |
19 | Some codes are from @mittorn fork for base methods, @tinmaniac for base Android port and do my attempt on implement all stub methods to run on GL4ES.
20 |
21 | * gl_server : server framework
22 |
23 | gl_server is optimized for Android for now. Therefore, the client system can use opengl es 2.0.
24 |
25 | * android_gl_server : Android demo port app.
26 |
27 | ## Demo Video (RPi original video)
28 |
29 | [Demo Video1](https://youtu.be/6S-Epb6m6mI)
30 |
31 | [Demo Video2](https://youtu.be/y0eRwrwetcA)
32 |
33 | ## Demo Video (Android port)
34 |
35 | [Demo Video](https://youtu.be/uwM9uxLHH1M)
36 |
37 | ## TODO implement
38 | - [x] glGetActiveUniform
39 | - [x] glGetError
40 | - [x] glGetIntegerv
41 | - [x] glGetFloatv
42 | - [x] glReadPixels (experimental)
43 | - [x] glGetProgramiv
44 | - [x] glGetShaderiv
45 | - [x] glGetString
46 | - [x] glTexSubImage2D
47 |
48 | ## Current status
49 | - `es2_info`, `es2gears` and `es2tri` will work.
50 | - GL4ES apps/games may work but in blank textures (will see in `glxdemo` and `glxheads`).
51 |
52 | ## Notes
53 | - Current minimum SDK level is set to 21 (Android 5) but it may work on older Android devices by some modifies.
54 | - Default port of server: 18145, client: 18146.
55 |
56 | ## Known issue (Android)
57 | - Some old devices: put app to background will make app lost EGL context (not show anything).
58 |
59 | ## Quick start
60 | - See [USAGE.md](USAGE.md) for more instruction.
61 |
62 | ### Server
63 | - Build android_gl_server use Android Studio or other similar to.
64 | - Install android_gl_server apk to Android device or AVD.
65 | - Run it.
66 |
67 | ### Client
68 | - copy the gl_client directory to any computer.
69 |
70 | ``cd gl_client``
71 |
72 | ``make``
73 |
74 | ``./sample1 -s 192.168.0.2:18145 -c 192.168.0.3:18146 -j /dev/input/js0``
75 |
76 | ``./sample2 -s 192.168.0.2:18145 -c 192.168.0.3:18146 -j /dev/input/js0``
77 |
78 | (Usage: ./sampleX [-c my_ip_address:port] [-s server_ip_address:port] [-j joystick_device])
79 |
80 | ## License
81 |
82 | BSD 3-Clause license (except other's source code)
83 |
84 | about sample2 camel model:
85 | original model from http://opengameart.org/content/camel
86 | License:CC0 author: noway, sandsound
87 | (Thanks for sharing!)
88 |
89 | ## Bookmarks
90 | - [Parallella](http://www.parallella.org/)
91 | - [Raspberry Pi](http://www.raspberrypi.org/)
92 |
93 | ## Special Thanks
94 |
95 | Thank you very much for your interest and advices.
96 |
97 | - noway @opengameart.org /
98 | - sandsound @opengameart.org /
99 | - GClements @OpenGL forum /
100 | - The Little Body @OpenGL forum /
101 | - Stephen A @OpenGL forum /
102 | - over9000 @Parallella forum /
103 | - LamsonNguyen @Parallella forum /
104 | - Gravis @Parallella forum /
105 | - svartalf @Parallella forum /
106 | - Raspberry Pi Foundation /
107 | - Adapteva /
108 |
109 | (c) Shodruky Rhyammer
110 |
111 | since Oct 21, 2013
112 |
--------------------------------------------------------------------------------
/USAGE.md:
--------------------------------------------------------------------------------
1 | # Setup streaming environment
2 | ## Server setup
3 | - Build Server app using Android Studio with NDK installed.
4 | - Install server APK.
5 |
6 | ## Client setup
7 | ```
8 | cd /path/to/android-gl-streaming/gl_client
9 |
10 | # Make the client
11 | make
12 |
13 | # Install gl-streaming client
14 | make install
15 |
16 | # Copy GL4ES into (optional)
17 | cp /path/to/gl4es/lib/libGL.so.1 /usr/local/lib/gl-streaming
18 |
19 | # Override system libGLESv2.so.2, libEGL.so.1 and libGL.so.1
20 | export LD_LIBRARY_PATH=/usr/local/lib/gl-streaming:$LD_LIBRARY_PATH
21 | ```
22 |
23 | # Launch streaming!
24 | ## Launch server
25 | - Do as title: Launch server.
26 | - Enter server port and client address, or leave empty for default values.
27 |
28 | ## Launch client
29 | - Test: run `es2_info, es2gears, es2tri, glxinfo, glxgears, glxdemo or glxheads`
30 | - Run an program requires OpenGL or OpenGL ES (many: Xvfb, x-window-manager, etc...).
31 |
32 | # Variables on compile
33 | ## Sever
34 | ### • GL_DEBUG
35 | - Enable debug log write to `/sdard/mthr_log.txt`.
36 | - Disabled by default.
37 |
38 | ## Client
39 | ### USE_X11
40 | - Enable support for X11 apps.
41 | - Enabled by default.
42 | - Sample side doesn't use X11 so not enabled.
43 |
44 | ### • GLS_USE_SRVSIZE
45 | - Use server window size instead of X Window size.
46 | - Disabled by default.
47 | - This is enabled if USE_X11 is not enabled.
48 | - May useful for fixing draw size bugs.
49 |
50 | ### • GLS_EMULATE_VBO
51 | - Try to emulate client arrays with VBO.
52 | - Enabled by default.
53 | - This is experimental, disable may make:
54 | + `es2tri` or some programs show blank screen.
55 | + `glxheads` show a rotating triange around surface instead of middle.
56 | + `glxgears` jump to invalid address and segmentation fault.
57 |
58 | # Environment variable on launch
59 | ## Server
60 | - Nothing yet.
61 |
62 | ## Client
63 | ### • GLS_DEBUG
64 | - Log executing/flushing command to the console. Disabled by default.
65 | - 0: Disable command logging (default).
66 | - 1: Enable command logging.
67 |
68 | ### • GLS_SERVER_ADDR
69 | - Set server IP address and port.
70 | - Default value: `127.0.0.1:18145`.
71 |
72 |
--------------------------------------------------------------------------------
/android_gl_server/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/android_gl_server/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 | HERE_PATH := $(LOCAL_PATH)
3 |
4 | include $(HERE_PATH)/../../gl_server/Android.mk
5 | # include $(HERE_PATH)/../../gl_client/Android.mk
6 |
7 | LOCAL_PATH := $(HERE_PATH)
8 | include $(CLEAR_VARS)
9 | LOCAL_MODULE := glstreamserver
10 | LOCAL_LDLIBS := -lEGL -lGLESv2 -llog -landroid
11 | LOCAL_SRC_FILES := glstreaming_jni.cpp
12 | LOCAL_STATIC_LIBRARIES := libgl_server
13 | LOCAL_CFLAGS += -DGLS_SERVER
14 | ifeq ($(TARGET_ARCH_ABI),x86)
15 | LOCAL_CFLAGS += -ffast-math -mtune=atom -mssse3 -mfpmath=sse
16 | endif
17 | include $(BUILD_SHARED_LIBRARY)
18 |
19 |
--------------------------------------------------------------------------------
/android_gl_server/jni/Application.mk:
--------------------------------------------------------------------------------
1 | NDK_TOOLCHAIN_VERSION := 4.9
2 | APP_STL := gnustl_static
3 | APP_PLATFORM := android-21
4 | APP_ABI := all
5 | # arm64-v8a
6 |
--------------------------------------------------------------------------------
/android_gl_server/jni/glstreaming_jni.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include "main.h"
7 | #include "utils.h"
8 |
9 | bool need_init_glstream = true;
10 |
11 | extern "C"
12 | {
13 | JNIEXPORT void JNICALL Java_com_kdt_glstreamserver_GLStreamingJNIWrapper_initServer(JNIEnv* env, jobject thiz, jint serverPort, jstring clientAddr, jint clientPort)
14 | {
15 | var_server_port = serverPort;
16 | jstrclient_addr = clientAddr;
17 | var_client_port = clientPort;
18 |
19 | var_client_addr = env->GetStringUTFChars(jstrclient_addr, 0);
20 | /*
21 | var_path_shadercache = "/sdcard/games/.minecraft/shader_cache";
22 | var_file_fragment_shader = "/sdcard/games/.minecraft/shader_cache/fragment_shader.glsl";
23 | var_file_vertex_shader = "/sdcard/games/.minecraft/shader_cache/vertex_shader.glsl";
24 | */
25 | }
26 |
27 | JNIEXPORT void JNICALL Java_com_kdt_glstreamserver_GLStreamingJNIWrapper_setSurface(JNIEnv* env, jobject thiz, jobject surface) {
28 | glsurfaceview_window = ANativeWindow_fromSurface(env, surface);
29 | assert (glsurfaceview_window != NULL);
30 | }
31 |
32 | JNIEXPORT void JNICALL Java_com_kdt_glstreamserver_GLStreamingJNIWrapper_setGLSize(JNIEnv* env, jobject thiz, jint width, jint height)
33 | {
34 | // glmain_jnienv = env;
35 |
36 | glsurfaceview_width = width;
37 | glsurfaceview_height = height;
38 | }
39 |
40 | JNIEXPORT void JNICALL Java_com_kdt_glstreamserver_GLStreamingJNIWrapper_startServer(JNIEnv* env, jobject thiz)
41 | {
42 | /*
43 | glsurfaceview_width = 1280;
44 | glsurfaceview_height = 720;
45 | */
46 | init_android_main();
47 | env->ReleaseStringUTFChars(jstrclient_addr, var_client_addr);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/android_gl_server/libs/armeabi-v7a/gdb.setup:
--------------------------------------------------------------------------------
1 | set solib-search-path ./obj/local/armeabi-v7a
2 | directory /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/platforms/android-21/arch-arm/usr/include jni/../../gl_server jni/../../gl_server/../common /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/include /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/include/backward
3 |
--------------------------------------------------------------------------------
/android_gl_server/libs/armeabi-v7a/gdbserver:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khanhduytran0/android-gl-streaming/b4895522e210f38a4b5ddc93f34ff05e4533e47a/android_gl_server/libs/armeabi-v7a/gdbserver
--------------------------------------------------------------------------------
/android_gl_server/libs/armeabi/gdb.setup:
--------------------------------------------------------------------------------
1 | set solib-search-path ./obj/local/armeabi
2 | directory /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/platforms/android-21/arch-arm/usr/include jni/../../gl_server jni/../../gl_server/../common /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/include /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/include/backward
3 |
--------------------------------------------------------------------------------
/android_gl_server/libs/armeabi/gdbserver:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khanhduytran0/android-gl-streaming/b4895522e210f38a4b5ddc93f34ff05e4533e47a/android_gl_server/libs/armeabi/gdbserver
--------------------------------------------------------------------------------
/android_gl_server/libs/x86/gdb.setup:
--------------------------------------------------------------------------------
1 | set solib-search-path ./obj/local/x86
2 | directory /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/platforms/android-21/arch-x86/usr/include jni/../../gl_server jni/../../gl_server/../common /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/include /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include /data/data/com.aide.ui/no_backup/ndksupport-1710240001/android-ndk-aide/sources/cxx-stl/gnu-libstdc++/4.9/include/backward
3 |
--------------------------------------------------------------------------------
/android_gl_server/libs/x86/gdbserver:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khanhduytran0/android-gl-streaming/b4895522e210f38a4b5ddc93f34ff05e4533e47a/android_gl_server/libs/x86/gdbserver
--------------------------------------------------------------------------------
/android_gl_server/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-29
12 |
--------------------------------------------------------------------------------
/android_gl_server/res/layout/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
24 |
25 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/android_gl_server/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
19 |
20 |
25 |
26 |
31 |
32 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/android_gl_server/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/android_gl_server/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | GLStreamServer
4 |
5 |
--------------------------------------------------------------------------------
/android_gl_server/src/com/kdt/glstreamserver/GLStreamingActivity.java:
--------------------------------------------------------------------------------
1 | package com.kdt.glstreamserver;
2 |
3 | import android.app.Activity;
4 | import android.widget.TextView;
5 | import android.os.Bundle;
6 | import android.opengl.*;
7 | import android.app.*;
8 | import android.content.*;
9 | import android.view.*;
10 | import android.widget.*;
11 | import android.view.ContextMenu.*;
12 | import java.io.*;
13 | import android.util.*;
14 | import android.graphics.*;
15 |
16 | public class GLStreamingActivity extends Activity
17 | {
18 | private GLStreamingView mGLSurface;
19 | private AlertDialog createdDialog;
20 | private LinearLayout logLayout;
21 | private ScrollView logScroll;
22 | private TextView logText;
23 | @Override
24 | public void onCreate(Bundle savedInstanceState)
25 | {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.main);
28 |
29 | logLayout = (LinearLayout) findViewById(R.id.main_glstream_logview);
30 | logScroll = (ScrollView) findViewById(R.id.main_glstream_log_scroll);
31 | logText = (TextView) logScroll.getChildAt(0);
32 | logText.setTextIsSelectable(true);
33 | logText.setTypeface(Typeface.MONOSPACE);
34 |
35 | new Thread(new Runnable(){
36 | private String duplicateString = "empty";
37 | private int duplicateCount;
38 | @Override
39 | public void run() {
40 | try {
41 | String[] command = new String[]{"logcat"};
42 | Process process = Runtime.getRuntime().exec(command);
43 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
44 |
45 | final String line;
46 | while ((line = bufferedReader.readLine()) != null) {
47 | if (line.startsWith("V/PhoneWindow")) {
48 | // This is annoying, user select text and log print with that tag.
49 | continue;
50 | } else if (line.equals(duplicateString)) {
51 | duplicateCount++;
52 | continue;
53 | } else {
54 | duplicateString = line;
55 | if (duplicateCount > 0) {
56 | line = "...(more " + duplicateCount + " duplicate lines)\n " + line;
57 | duplicateCount = 0;
58 | }
59 | }
60 |
61 | final String fline = line;
62 | logText.post(new Runnable(){
63 |
64 | @Override
65 | public void run()
66 | {
67 | logText.append(" " + fline + "\n");
68 | logScroll.fullScroll(ScrollView.FOCUS_DOWN);
69 | }
70 | });
71 | }
72 | } catch (IOException ex) {
73 | Log.e("GLStreaming", "getLog failed", ex);
74 | }
75 | }
76 | }, "LogcatThread").start();
77 |
78 | System.out.println("The PID of GL Streaming server: " + android.os.Process.myPid());
79 |
80 | mGLSurface = (GLStreamingView) findViewById(R.id.main_glstream_surfaceview);
81 |
82 | AlertDialog.Builder dialog = new AlertDialog.Builder(this);
83 | dialog.setTitle(R.string.app_name);
84 | dialog.setView(R.layout.config);
85 | dialog.setPositiveButton(android.R.string.ok, null);
86 | dialog.setNegativeButton("Exit", new DialogInterface.OnClickListener(){
87 |
88 | @Override
89 | public void onClick(DialogInterface i, int p2) {
90 | finish();
91 | }
92 | });
93 | dialog.setCancelable(false);
94 | createdDialog = dialog.create();
95 | createdDialog.setOnShowListener(new DialogInterface.OnShowListener(){
96 |
97 | @Override
98 | public void onShow(DialogInterface p1)
99 | {
100 | final EditText editServerPort = (EditText) createdDialog.findViewById(R.id.config_edittext_serverport);
101 | final EditText editClientAddr = (EditText) createdDialog.findViewById(R.id.config_edittext_clientaddr);
102 |
103 | createdDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener(){
104 | @Override
105 | public void onClick(View p1) {
106 | String serverPortStr = editServerPort.getText().toString();
107 | int serverPort = 18145;
108 | String clientAddr = editClientAddr.getText().toString();
109 | String outClientAddr = "127.0.0.1";
110 | int outClientPort = 18146;
111 |
112 | if (serverPortStr.isEmpty()) {
113 | // Default server port
114 | } else if (serverPortStr.length() > 5) {
115 | editServerPort.setError("Server port is too long!");
116 | return;
117 | } else {
118 | serverPort = Integer.parseInt(serverPortStr);
119 | }
120 | if (clientAddr.isEmpty()) {
121 | // Default client address and port
122 | } else if (clientAddr.contains(":")) {
123 | String[] clientAddrPort = clientAddr.split(":");
124 | // Check if contains more than one ":".
125 | if (clientAddrPort.length > 2) {
126 | editClientAddr.setError("Must be only one \":\"");
127 | return;
128 | }
129 |
130 | if (!clientAddrPort[0].isEmpty()) outClientAddr = clientAddrPort[0];
131 | if (!clientAddrPort[1].isEmpty()) outClientPort = Integer.parseInt(clientAddrPort[1]);
132 | } else {
133 | outClientAddr = clientAddr;
134 | }
135 |
136 | createdDialog.dismiss();
137 |
138 | mGLSurface.init(/* true, */ serverPort, outClientAddr, outClientPort);
139 | }
140 | });
141 | }
142 | });
143 | createdDialog.show();
144 | }
145 |
146 | public void closeLog(View v) {
147 | logLayout.setVisibility(View.GONE);
148 | }
149 |
150 | @Override
151 | public boolean onCreateOptionsMenu(Menu menu) {
152 | MenuInflater inflater = getMenuInflater();
153 | inflater.inflate(R.menu.main, menu);
154 | return true;
155 | }
156 |
157 | @Override
158 | public boolean onOptionsItemSelected(MenuItem item)
159 | {
160 | // Handle item selection
161 | switch (item.getItemId()) {
162 | case R.id.menu_serverlog:
163 | logLayout.setVisibility(View.VISIBLE);
164 | return true;
165 | default:
166 | return super.onOptionsItemSelected(item);
167 | }
168 | }
169 |
170 | @Override
171 | protected void onPause() {
172 | super.onPause();
173 | // mGLSurface.onPause();
174 | }
175 |
176 | @Override
177 | protected void onResume() {
178 | super.onResume();
179 | // mGLSurface.onResume();
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/android_gl_server/src/com/kdt/glstreamserver/GLStreamingJNIWrapper.java:
--------------------------------------------------------------------------------
1 | package com.kdt.glstreamserver;
2 | import android.view.*;
3 |
4 | public class GLStreamingJNIWrapper
5 | {
6 | public static native void initServer(int serverPort, String clientAddr, int clientPort);
7 | public static native void setGLSize(int width, int height);
8 | public static native void setSurface(Surface surface);
9 | public static native void startServer();
10 |
11 | public static void step() {
12 | // TODO implement in native
13 | }
14 |
15 | static {
16 | System.loadLibrary("glstreamserver");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/android_gl_server/src/com/kdt/glstreamserver/GLStreamingView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.kdt.glstreamserver;
18 |
19 | import android.content.Context;
20 | import android.graphics.PixelFormat;
21 | import android.opengl.GLSurfaceView;
22 | import android.util.AttributeSet;
23 | import android.util.Log;
24 | import android.view.KeyEvent;
25 | import android.view.MotionEvent;
26 |
27 | import javax.microedition.khronos.egl.EGL10;
28 | import javax.microedition.khronos.egl.EGLConfig;
29 | import javax.microedition.khronos.egl.EGLContext;
30 | import javax.microedition.khronos.egl.EGLDisplay;
31 | import javax.microedition.khronos.opengles.GL10;
32 | import android.view.*;
33 | import android.opengl.GLES20;
34 | import android.graphics.*;
35 |
36 | public class GLStreamingView extends TextureView implements TextureView.SurfaceTextureListener {
37 | private boolean mSurfaceInit = false;
38 | public GLStreamingView(Context context) {
39 | this(context, null);
40 | }
41 |
42 | public GLStreamingView(Context context, AttributeSet attrs) {
43 | super(context, attrs);
44 | }
45 |
46 | @Override
47 | public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
48 | System.out.println("Intializing GLStreamServer");
49 | // System.out.println("w=" + width + ",h=" + height);
50 | GLStreamingJNIWrapper.setSurface(new Surface(texture));
51 | GLStreamingJNIWrapper.setGLSize(width, height);
52 | mSurfaceInit = true;
53 | }
54 |
55 | @Override
56 | public void onSurfaceTextureUpdated(SurfaceTexture texture) {
57 | // Unused
58 | }
59 |
60 | @Override
61 | public void onSurfaceTextureSizeChanged(final SurfaceTexture texture, final int width, final int height) {
62 | onSurfaceTextureAvailable(texture, width, height);
63 | }
64 |
65 | @Override
66 | public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {
67 | // onSurfaceTextureAvailable(texture, 0, 0);
68 | return false;
69 | }
70 |
71 | public void init(/* boolean translucent, */ int serverPort, String clientAddr, int clientPort) {
72 | GLStreamingJNIWrapper.initServer(serverPort, clientAddr, clientPort);
73 |
74 | setSurfaceTextureListener(this);
75 |
76 | if (isAvailable()) {
77 | onSurfaceTextureAvailable(getSurfaceTexture(), getWidth(), getHeight());
78 | }
79 |
80 | new Thread(new Runnable(){
81 | @Override
82 | public void run() {
83 | // TODO move to background Service
84 | try {
85 | // Wait until Surface is initialized
86 | while (!mSurfaceInit) Thread.sleep(100);
87 | } catch (InterruptedException e) {}
88 | GLStreamingJNIWrapper.startServer();
89 | }
90 | }, "GLStreaming").start();
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/common/fastlog.h:
--------------------------------------------------------------------------------
1 | #ifdef __ANDROID__
2 | #include
3 |
4 | #define TAG "GLStreamingNative"
5 | #endif
6 |
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 | #ifdef __ANDROID__
12 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
13 | #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
14 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
15 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
16 | #else
17 | #define LOGE(...) printf(__VA_ARGS__)
18 | #define LOGW(...) printf(__VA_ARGS__)
19 | #define LOGI(...) printf(__VA_ARGS__)
20 | #define LOGD(...) printf(__VA_ARGS__)
21 | #endif
22 |
23 | #ifdef __cplusplus
24 | }
25 | #endif
26 |
27 |
--------------------------------------------------------------------------------
/common/fifo.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 | #include
34 |
35 | #include "fifo.h"
36 |
37 | int fifo_init(fifo_t *fifo, unsigned int fifo_size_in_bits, unsigned int fifo_packet_size_in_bits)
38 | {
39 | fifo->fifo_size = 1 << fifo_size_in_bits;
40 | fifo->fifo_packet_size = 1 << fifo_packet_size_in_bits;
41 | unsigned int alignment = fifo->fifo_packet_size;
42 | fifo->buffer = (char *)malloc(fifo->fifo_size * fifo->fifo_packet_size + alignment);
43 | if (fifo->buffer == NULL)
44 | {
45 | return -1;
46 | }
47 | #if __WORDSIZE == 64
48 | fifo->p_start = (char *)(((uint64_t)fifo->buffer + alignment - 1) & (~ ((uint64_t)alignment - 1)));
49 | #else
50 | fifo->p_start = (char *)(((uint32_t)fifo->buffer + alignment - 1) & (~ ((uint32_t)alignment - 1)));
51 | #endif
52 | fifo->idx_reader = 0;
53 | fifo->idx_writer = 0;
54 | return 0;
55 | }
56 |
57 | int fifo_delete(fifo_t *fifo)
58 | {
59 | free(fifo->buffer);
60 | fifo->buffer = NULL;
61 | fifo->p_start = NULL;
62 | fifo->idx_reader = 0;
63 | fifo->idx_writer = 0;
64 | fifo->fifo_size = 0;
65 | fifo->fifo_packet_size = 0;
66 | return 0;
67 | }
68 |
--------------------------------------------------------------------------------
/common/fifo.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 |
34 |
35 | typedef struct
36 | {
37 | char *buffer;
38 | char *p_start;
39 | int idx_reader;
40 | int idx_writer;
41 | unsigned int fifo_size;
42 | unsigned int fifo_packet_size;
43 | } fifo_t;
44 |
45 | static inline char* fifo_push_ptr_get(fifo_t *fifo)
46 | {
47 | int next_idx = (fifo->idx_writer + 1) & (fifo->fifo_size - 1);
48 | if (next_idx == fifo->idx_reader)
49 | {
50 | return NULL;
51 | }
52 | return fifo->p_start + (fifo->idx_writer * fifo->fifo_packet_size);
53 | }
54 |
55 | static inline void fifo_push_ptr_next(fifo_t *fifo)
56 | {
57 | int next_idx = (fifo->idx_writer + 1) & (fifo->fifo_size - 1);
58 | if (next_idx != fifo->idx_reader)
59 | {
60 | fifo->idx_writer = next_idx;
61 | }
62 | }
63 |
64 | static inline char* fifo_pop_ptr_get(fifo_t *fifo)
65 | {
66 | if (fifo->idx_reader == fifo->idx_writer)
67 | {
68 | return NULL;
69 | }
70 | return fifo->p_start + (fifo->idx_reader * fifo->fifo_packet_size);
71 | }
72 |
73 | static inline void fifo_pop_ptr_next(fifo_t *fifo)
74 | {
75 | int next_idx = (fifo->idx_reader + 1) & (fifo->fifo_size - 1);
76 | if (fifo->idx_reader != fifo->idx_writer)
77 | {
78 | fifo->idx_reader = next_idx;
79 | }
80 | }
81 |
82 |
83 | #ifdef __cplusplus
84 | extern "C" {
85 | #endif
86 |
87 | int fifo_init(fifo_t *fifo, unsigned int fifo_size_in_bits, unsigned int fifo_packet_size_in_bits);
88 |
89 | int fifo_delete(fifo_t *fifo);
90 |
91 | #ifdef __cplusplus
92 | }
93 | #endif
94 |
95 |
--------------------------------------------------------------------------------
/common/server.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 |
39 | #include "server.h"
40 | #include "fastlog.h"
41 |
42 | #define TRUE 1
43 | #define FALSE 0
44 |
45 |
46 | void server_init(server_context_t *c)
47 | {
48 | c->err = FALSE;
49 | c->fifo_packet_size_in_bits = FIFO_PACKET_SIZE_IN_BITS;
50 | c->fifo_size_in_bits = FIFO_SIZE_IN_BITS;
51 | c->sleep_usec = SLEEP_USEC;
52 | c->max_mbps = MAX_MBPS;
53 | }
54 |
55 |
56 | void * server_thread(void * arg)
57 | {
58 | #ifdef GLS_SERVER // GLS_SERVER
59 | server_thread_args_t * a = (server_thread_args_t *)arg;
60 | #else // GL_CLIENT
61 | server_context_t * a = (server_context_t *)arg;
62 | #endif // GL_CLIENT
63 | int quit = FALSE;
64 |
65 | while (quit == FALSE) {
66 | #ifdef GLS_SERVER // GLS_SERVER
67 | char* pushptr = fifo_push_ptr_get(a->fifo);
68 | #else // GL_CLIENT
69 | char* pushptr = fifo_push_ptr_get(&a->fifo);
70 | #endif // GL_CLIENT
71 | if (pushptr == NULL) {
72 | LOGW("FIFO full!\n");
73 | usleep(a->sleep_usec);
74 | } else {
75 | int recive_size = recvfrom(a->sock_fd, pushptr, a->max_packet_size, 0, NULL, NULL);
76 | if (recive_size == -1) {
77 | LOGE("Socket recvfrom Error.\n");
78 | quit = TRUE;
79 | }
80 | #ifdef GLS_SERVER // GLS_SERVER
81 | fifo_push_ptr_next(a->fifo);
82 | #else // GL_CLIENT
83 | fifo_push_ptr_next(&a->fifo);
84 | #endif // GL_CLIENT
85 | }
86 | }
87 |
88 | pthread_exit(NULL);
89 | }
90 |
91 |
92 | void set_fifo_packet_size_in_bits(server_context_t *c, unsigned int bits)
93 | {
94 | c->fifo_packet_size_in_bits = bits;
95 | }
96 |
97 |
98 | void set_fifo_size_in_bits(server_context_t *c, unsigned int bits)
99 | {
100 | c->fifo_size_in_bits = bits;
101 | }
102 |
103 |
104 | void set_sleep_time(server_context_t *c, unsigned int usec)
105 | {
106 | c->sleep_usec = usec;
107 | }
108 |
109 |
110 | void set_max_mbps(server_context_t *c, unsigned int mbps)
111 | {
112 | c->max_mbps = mbps;
113 | }
114 |
115 |
116 | #ifdef GLS_SERVER
117 | void set_client_user_context(server_context_t *c, void *ptr)
118 | {
119 | c->popper_thread_arg.user_context_ptr = ptr;
120 | }
121 | #endif
122 |
123 | void set_server_address_port(server_context_t *c, char * addr, uint16_t port)
124 | {
125 | #ifdef GLS_SERVER
126 | strncpy(c->server_thread_arg.addr, addr, sizeof(c->server_thread_arg.addr));
127 | c->server_thread_arg.port = port;
128 | #else
129 | strncpy(c->addr, addr, sizeof(c->addr));
130 | c->port = port;
131 | #endif
132 | }
133 |
134 |
135 | void set_client_address_port(server_context_t *c, char * addr, uint16_t port)
136 | {
137 | #ifdef GLS_SERVER
138 | strncpy(c->popper_thread_arg.addr, addr, sizeof(c->popper_thread_arg.addr));
139 | c->popper_thread_arg.port = port;
140 | #else
141 | strncpy(c->bind_addr, addr, sizeof(c->bind_addr));
142 | c->bind_port = port;
143 | #endif
144 | }
145 |
146 | // #endif // GL_CLIENT
147 |
148 |
149 | void socket_open(server_context_t *c)
150 | {
151 | // There's nothing same to merge
152 | #ifdef GLS_SERVER // GLS_SERVER
153 | c->server_thread_arg.sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
154 | if (c->server_thread_arg.sock_fd == -1)
155 | {
156 | LOGE("Server Socket Open Error.");
157 | // exit(EXIT_FAILURE);
158 |
159 | return;
160 | }
161 |
162 | c->popper_thread_arg.sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
163 | if (c->popper_thread_arg.sock_fd == -1)
164 | {
165 | LOGE("Client Socket Open Error.");
166 | // exit(EXIT_FAILURE);
167 |
168 | return;
169 | }
170 |
171 | c->server_thread_arg.sai.sin_family = AF_INET;
172 | c->server_thread_arg.sai.sin_port = htons(c->server_thread_arg.port);
173 | c->server_thread_arg.sai.sin_addr.s_addr = inet_addr(c->server_thread_arg.addr);
174 |
175 | c->popper_thread_arg.sai.sin_family = AF_INET;
176 | c->popper_thread_arg.sai.sin_port = htons(c->popper_thread_arg.port);
177 | c->popper_thread_arg.sai.sin_addr.s_addr = inet_addr(c->popper_thread_arg.addr);
178 |
179 | if (bind(c->server_thread_arg.sock_fd, (struct sockaddr *)&c->server_thread_arg.sai, sizeof(struct sockaddr_in)) == -1)
180 | {
181 | LOGE("Socket Bind Error.");
182 | // exit(EXIT_FAILURE);
183 |
184 | return;
185 | }
186 | #else // GL_CLIENT
187 | struct sockaddr_in sai;
188 | c->sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
189 | if (c->sock_fd == -1)
190 | {
191 | printf("Server Socket Open Error.\n");
192 | exit(EXIT_FAILURE);
193 | }
194 |
195 | c->sai.sin_family = AF_INET;
196 | c->sai.sin_port = htons(c->port);
197 | c->sai.sin_addr.s_addr = inet_addr(c->addr);
198 |
199 | sai.sin_family = AF_INET;
200 | sai.sin_port = htons(c->bind_port);
201 | sai.sin_addr.s_addr = inet_addr(c->bind_addr);
202 |
203 | if (bind(c->sock_fd, (struct sockaddr *)&sai, sizeof(struct sockaddr_in)) == -1)
204 | {
205 | printf("Socket Bind Error.\n");
206 | exit(EXIT_FAILURE);
207 | }
208 | #endif // GL_CLIENT
209 | }
210 |
211 |
212 | void socket_close(server_context_t *c)
213 | {
214 | #ifdef GLS_SERVER // GLS_SERVER
215 | close(c->server_thread_arg.sock_fd);
216 | close(c->popper_thread_arg.sock_fd);
217 | #else // GL_CLIENT
218 | close(c->sock_fd);
219 | #endif // GL_CLIENT
220 | }
221 |
222 |
223 | // #ifdef GLS_SERVER // GLS_SERVER
224 | server_context_t *server_context;
225 | void server_run(server_context_t *ctx, void *(*popper_thread)(void *))
226 | {
227 | server_context_t *c;
228 | if (ctx == NULL) {
229 | c = server_context;
230 | } else {
231 | c = ctx;
232 | server_context = ctx;
233 | }
234 | fifo_init(&c->fifo, c->fifo_size_in_bits, c->fifo_packet_size_in_bits);
235 | c->server_thread_arg.fifo = &c->fifo;
236 | c->popper_thread_arg.fifo = &c->fifo;
237 | c->server_thread_arg.max_packet_size = 1 << c->fifo_packet_size_in_bits;
238 | c->popper_thread_arg.max_packet_size = 1 << c->fifo_packet_size_in_bits;
239 | c->server_thread_arg.sleep_usec = c->sleep_usec;
240 | c->popper_thread_arg.sleep_usec = c->sleep_usec;
241 | c->server_thread_arg.max_mbps = c->max_mbps;
242 | c->popper_thread_arg.max_mbps = c->max_mbps;
243 | socket_open(c);
244 | pthread_create(&c->server_th, NULL, (void* (*)(void*))server_thread, &c->server_thread_arg);
245 | pthread_create(&c->popper_th, NULL, popper_thread, &c->popper_thread_arg);
246 | pthread_join(c->popper_th, NULL);
247 |
248 | // From https://github.com/tinmaniac/gl-streaming/blob/master/gl_server/server.c#L188
249 | #ifdef __ANDROID__
250 | // this is wrong, but android has no pthread_cancel
251 | // see stack overflow for a better solution that uses a SIGUSR1 handler
252 | // that I don't have time to implement right now
253 | // http://stackoverflow.com/questions/4610086/pthread-cancel-alternatives-in-android-ndk
254 | pthread_kill(c->server_th, SIGUSR1);
255 | #else
256 | pthread_cancel(c->server_th);
257 | #endif
258 |
259 | socket_close(c);
260 | fifo_delete(&c->fifo);
261 | }
262 |
263 |
264 | #ifndef GLS_SERVER // GL_CLIENT
265 | void *server_start(server_context_t *c)
266 | {
267 | fifo_init(&c->fifo, c->fifo_size_in_bits, c->fifo_packet_size_in_bits);
268 | c->max_packet_size = 1 << c->fifo_packet_size_in_bits;
269 |
270 | socket_open(c);
271 |
272 | pthread_create(&c->server_th, NULL, (void* (*)(void*))server_thread, c);
273 | return c;
274 | }
275 |
276 |
277 | void server_stop(server_context_t *c)
278 | {
279 | #ifndef __ANDROID__
280 | pthread_cancel(c->server_th);
281 | #endif // GLS_SERVER
282 |
283 | socket_close(c);
284 | fifo_delete(&c->fifo);
285 | }
286 | #endif // GL_CLIENT
287 |
--------------------------------------------------------------------------------
/common/server.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 |
34 | #include "fifo.h"
35 | #include "pthread.h"
36 | #include "utils.h"
37 |
38 | #define SLEEP_USEC 1000
39 | #define FIFO_SIZE_IN_BITS 10
40 | #define FIFO_PACKET_SIZE_IN_BITS 11
41 | #define MAX_MBPS 100
42 |
43 |
44 | // GL_SERVER
45 | typedef struct
46 | {
47 | struct sockaddr_in sai;
48 | int sock_fd;
49 | char addr[256];
50 | uint16_t port;
51 | fifo_t * fifo;
52 | size_t max_packet_size;
53 | useconds_t sleep_usec;
54 | int max_mbps;
55 | void * user_context_ptr;
56 | } server_thread_args_t;
57 |
58 |
59 | typedef struct
60 | {
61 | pthread_t server_th, popper_th;
62 | int err;
63 | fifo_t fifo;
64 | int sock_fd;
65 | size_t max_packet_size;
66 | unsigned int fifo_packet_size_in_bits;
67 | unsigned int fifo_size_in_bits;
68 | unsigned int sleep_usec;
69 | unsigned int max_mbps;
70 |
71 | // GL_SERVER
72 | server_thread_args_t server_thread_arg, popper_thread_arg;
73 |
74 | // GL_CLIENT
75 | uint16_t port;
76 | char addr[256];
77 | char bind_addr[256];
78 | uint16_t bind_port;
79 | struct sockaddr_in sai;
80 | } server_context_t;
81 |
82 |
83 | #ifdef __cplusplus
84 | extern "C" {
85 | #endif
86 |
87 | void* server_thread(void* arg);
88 | void server_init(server_context_t *c);
89 | void set_fifo_packet_size_in_bits(server_context_t *c, unsigned int bits);
90 | void set_fifo_size_in_bits(server_context_t *c, unsigned int bits);
91 | void set_sleep_time(server_context_t *c, unsigned int usec);
92 | void set_max_mbps(server_context_t *c, unsigned int mbps);
93 | void set_server_address_port(server_context_t *c, char * addr, uint16_t port);
94 | void set_client_address_port(server_context_t *c, char * addr, uint16_t port);
95 |
96 | // GL_SERVER
97 | void set_client_user_context(server_context_t *c, void *ptr);
98 | void server_run(server_context_t *c, void *(*popper_thread)(void *));
99 |
100 | // GL_CLIENT
101 | void *server_start(server_context_t *c);
102 | void socket_open(server_context_t *c);
103 | void socket_close(server_context_t *c);
104 |
105 | #ifdef __cplusplus
106 | }
107 | #endif
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/common/utils.h:
--------------------------------------------------------------------------------
1 | #ifdef __ANDROID__
2 | #include
3 | #include
4 |
5 | jstring jstrclient_addr;
6 | ANativeWindow* glsurfaceview_window;
7 |
8 | #endif // __ANDROID__
9 |
10 | #ifdef USE_X11
11 | #include
12 | #include
13 |
14 | Display *xDisplay;
15 | int xScreenId;
16 | #if defined(GLS_SERVER) || !defined(USE_SERVER_SIZE)
17 | Window xWindow;
18 | #endif // GLS_SERVER || !USE_SERVER_SIZE
19 |
20 | #endif // USE_X11
21 |
22 | #ifdef GLS_SERVER
23 | int glsurfaceview_width;
24 | int glsurfaceview_height;
25 |
26 | int var_server_port;
27 | int var_client_port;
28 | const char* var_client_addr;
29 | /*
30 | const char* var_path_shadercache;
31 | const char* var_file_fragment_shader;
32 | const char* var_file_vertex_shader;
33 | */
34 | // JNIEnv* glmain_jnienv;
35 |
36 | #endif // GLS_SERVER
37 |
38 |
--------------------------------------------------------------------------------
/contributors.txt:
--------------------------------------------------------------------------------
1 | * The Little Body @OpenGL forum 10-25-2013, 06:54 PM
2 |
3 | http://www.opengl.org/discussion_boards/showthread.php/182966-gl-streaming-Lightweight-OpenGL-ES-command-streaming-framework?p=1255732&viewfull=1#post1255732
4 |
5 | This can work from a Linux box to another Linux box for that I make some tests ?
6 | (I does not have a Raspberry Pi )
7 |
8 | The GLS_POINTER / GLS_PUSH scheme can to be a little more ehanced for to make a more compact source code :
9 | (but any gain about the size or speed of the binary executable code because this only use #define)
10 |
11 | #define GLS_PTR_FUNC(PTR, FUNC) gls_FUNC_t *PTR = (gls_FUNC_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr); \
12 | PTR->cmd = GLSC_FUNC;
13 |
14 | #define GLS_PUSH_FUNC(FUNC) push_batch_command(sizeof(gls_FUNC_t))
15 |
16 |
17 | GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer)
18 | {
19 | GLS_POINTER_FUNC(c, glBindBuffer);
20 |
21 | c->target = target;
22 | c->buffer = buffer;
23 |
24 | GLS_PUSH_FUNC(glBindBuffer);
25 | }
26 |
27 |
28 |
29 | ----------------------------------------------------------------
30 |
31 |
32 |
33 | * The Little Body @OpenGL forum 10-25-2013, 06:11 PM
34 |
35 | http://www.opengl.org/discussion_boards/showthread.php/182966-gl-streaming-Lightweight-OpenGL-ES-command-streaming-framework?p=1255730&viewfull=1#post1255730
36 |
37 | I see too in gl_client/glclient.c a lot of deported glFuncs with systematicaly a very similar first line of code :
38 |
39 | gls_glBindBuffer_t *c = (gls_glBindBuffer_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr);
40 | gls_glBlendFuncSeparate_t *c = (gls_glBlendFuncSeparate_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr);
41 | ...
42 | gls_glDrawElements_t *c = (gls_glDrawElements_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr);
43 | gls_glBindAttribLocation_t *c = (gls_glBindAttribLocation_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr);
44 |
45 | => I think that this can to be replaced with a more generic #define pattern like this :
46 |
47 | #define GLS_POINTER(PTR, FUNC) gls_FUNC_t *PTR = (gls_FUNC_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr)
48 |
49 | The same thing about push_batch_command() calls that can use this #define for example
50 |
51 | #define GLS_PUSH(FUNC) push_batch_command(sizeof(gls_FUNC_t))
52 |
53 | and push_batch_command() calls to be generated by this #define
54 |
55 | GLS_PUSH(glBindBuffer);
56 | ...
57 | GLS_PUSH(glUniform1f);
58 | ...
59 | GLS_PUSH(command);
60 |
61 | This make a very more compact source code for the deported glBindBuffer() call by example :
62 |
63 | GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer)
64 |
65 | {
66 |
67 | GLS_POINTER(c, glBindBuffer);
68 |
69 | c->cmd = GLSC_glBindBuffer;
70 |
71 | c->target = target;
72 |
73 | c->buffer = buffer;
74 |
75 | GLS_PUSH(glBindBuffer);
76 |
77 | }
78 | ----------------------------------------------------------------
79 |
80 |
81 |
82 | * The Little Body @OpenGL forum 10-23-2013, 02:31 PM
83 |
84 |
85 | http://www.opengl.org/discussion_boards/showthread.php/182966-gl-streaming-Lightweight-OpenGL-ES-command-streaming-framework?p=1255697&viewfull=1#post1255697
86 |
87 | And about to regroup set_server_adress/set_server_port and set_client_adress/set_client_port ?
88 |
89 | void set_server_address_port(server_context_t *c, char * addr, uint16_t port)
90 |
91 | {
92 |
93 | strncpy(c->server_thread_arg.addr, addr, sizeof(c->server_thread_arg.addr));
94 |
95 | c->server_thread_arg.port = port;
96 |
97 | }
98 |
99 |
100 | void set_client_address_port(server_context_t *c, char * addr, uint16_t port)
101 |
102 | {
103 |
104 | strncpy(c->popper_thread_arg.addr, addr, sizeof(c->popper_thread_arg.addr));
105 |
106 | c->popper_thread_arg.port = port;
107 |
108 | }
109 |
110 | ----------------------------------------------------------------
111 |
112 |
113 |
--------------------------------------------------------------------------------
/gl_client/Android.mk:
--------------------------------------------------------------------------------
1 | # This Android.mk was created for testing only!
2 |
3 | LOCAL_PATH := $(call my-dir)
4 |
5 | include $(CLEAR_VARS)
6 | LOCAL_MODULE := GLESv2
7 | LOCAL_SRC_FILES := ../common/fifo.c \
8 | ../common/server.c \
9 | glclient.c \
10 | clientegl.c \
11 | clientgles.c
12 | LOCAL_C_INCLUDES := $(LOCAL_PATH) \
13 | $(LOCAL_PATH)/../common
14 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
15 |
16 | LOCAL_CFLAGS += -std=c99
17 | ifeq ($(TARGET_ARCH_ABI),x86)
18 | LOCAL_CFLAGS += -ffast-math -mtune=atom -mssse3 -mfpmath=sse
19 | endif
20 | include $(BUILD_SHARED_LIBRARY)
21 |
22 |
--------------------------------------------------------------------------------
/gl_client/Makefile:
--------------------------------------------------------------------------------
1 | CFLAGS=-O3 -Wall -I../common -I. -I./include -fPIC -g
2 |
3 | # Use X11
4 | CFLAGS+=-DUSE_X11
5 |
6 | # Use screen size from server.
7 | # CFLAGS+=-DGLS_USE_SRVSIZE
8 |
9 | # Try to emulate client arrays with VBO.
10 | CFLAGS+=-DGLS_EMULATE_VBO
11 |
12 | LIBS=-pthread -ldl -lX11
13 | CFLAGS+= $(LIBS)
14 | OBJS=fifo.o server.o clientegl.o clientgles.o glclient.o
15 |
16 | LIB_GLES=libGLESv2.so.2
17 |
18 | GLS_LIB_DIR=/usr/local/lib/gl-streaming
19 |
20 | EXES=$(LIB_GLES)
21 |
22 | all: $(EXES)
23 |
24 | fifo.o: ../common/fifo.c ../common/fifo.h
25 | gcc -c -o fifo.o $(CFLAGS) ../common/fifo.c
26 |
27 | server.o: ../common/server.c ../common/server.h fifo.o
28 | gcc -c -o server.o $(CFLAGS) ../common/server.c
29 |
30 | clientegl.o: clientegl.c include/EGL/egl.h
31 | gcc -c -o clientegl.o $(CFLAGS) clientegl.c
32 |
33 | clientgles.o: clientgles.c include/GLES2/gl2.h
34 | gcc -c -o clientgles.o $(CFLAGS) clientgles.c
35 |
36 | glclient.o: glclient.c glclient.h ../common/gls_command.h server.o
37 | gcc -c -o glclient.o $(CFLAGS) glclient.c
38 |
39 | $(LIB_GLES): $(OBJS)
40 | gcc -shared -o $(LIB_GLES) $(CFLAGS) $(OBJS) -Wl,-init,gls_init_library,--no-undefined $(LIBS)
41 |
42 | install:
43 | mkdir -p $(GLS_LIB_DIR)
44 | cp libGLESv2.so.2 $(GLS_LIB_DIR)/
45 | ln -s $(GLS_LIB_DIR)/libGLESv2.so.2 $(GLS_LIB_DIR)/libEGL.so.1; echo "To use streaming, type: export LD_LIBRARY_PATH=$(GLS_LIB_DIR)\nThen you are ready to get hardware acceleration!"
46 |
47 | clean:
48 | rm $(EXES) $(OBJS)
49 |
--------------------------------------------------------------------------------
/gl_client/clientegl.c:
--------------------------------------------------------------------------------
1 | // This file declare EGL methods for stubs or streaming
2 |
3 | #include
4 |
5 | #include "glclient.h"
6 |
7 | EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api)
8 | {
9 | gls_cmd_flush();
10 | GLS_SET_COMMAND_PTR(c, eglBindAPI);
11 | c->api = api;
12 | GLS_SEND_PACKET(eglBindAPI);
13 |
14 | wait_for_data("timeout:eglBindAPI");
15 | gls_ret_eglBindAPI_t *ret = (gls_ret_eglBindAPI_t *)glsc_global.tmp_buf.buf;
16 | return ret->success;
17 | }
18 |
19 | EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib( EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value )
20 | {
21 | #ifdef USE_X11
22 | if (xDisplay != NULL && attribute == EGL_NATIVE_VISUAL_ID) {
23 | *value = XVisualIDFromVisual(XDefaultVisual(xDisplay, xScreenId));
24 | return EGL_TRUE;
25 | }
26 | #endif
27 |
28 | for (int i = 0; i < client_config_size; i+=2) {
29 | if (client_config_keys[i] == attribute) {
30 | *value = client_config_values[i];
31 | return EGL_TRUE;
32 | }
33 | }
34 |
35 | /*
36 | gls_cmd_flush();
37 | GLS_SET_COMMAND_PTR(c, eglGetConfigAttrib);
38 | c->dpy = dpy;
39 | c->config = config;
40 | c->attribute = attribute;
41 | GLS_SEND_PACKET(eglGetConfigAttrib);
42 |
43 | wait_for_data("timeout:eglGetConfigAttrib");
44 | gls_ret_eglGetConfigAttrib_t *ret = (gls_ret_eglGetConfigAttrib_t *)glsc_global.tmp_buf.buf;
45 | *value = value;
46 |
47 | return ret->success;
48 | */
49 | }
50 |
51 | EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs( EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config )
52 | {
53 | /*
54 | gls_cmd_flush();
55 | GLS_SET_COMMAND_PTR(c, eglGetConfigs);
56 | c->dpy = dpy;
57 | c->config_size = config_size;
58 | GLS_SEND_PACKET(eglGetConfigs);
59 |
60 | wait_for_data("timeout:eglGetConfigs");
61 | gls_ret_eglGetConfigs_t *ret = (gls_ret_eglGetConfigs_t *)glsc_global.tmp_buf.buf;
62 | *num_config = ret->num_config;
63 | configs = ret->configs;
64 | return ret->success;
65 | */
66 |
67 | // Build a fake local config
68 | if (client_config_size > 0) {
69 | *num_config = client_config_size / 2;
70 | for (int i = 0; i < client_config_size; i+=2) {
71 | configs[i] = &client_config_values[i+1];
72 | }
73 | }
74 |
75 | return EGL_TRUE;
76 | }
77 |
78 | EGLAPI EGLint EGLAPIENTRY eglGetError( void )
79 | {
80 | if (client_egl_error != EGL_SUCCESS) {
81 | EGLint error = client_egl_error;
82 | client_egl_error = EGL_SUCCESS;
83 | return error;
84 | }
85 |
86 | gls_cmd_flush();
87 | GLS_SET_COMMAND_PTR(c, eglGetError);
88 | GLS_SEND_PACKET(eglGetError);
89 |
90 | wait_for_data("timeout:eglGetError");
91 | gls_ret_eglGetError_t *ret = (gls_ret_eglGetError_t *)glsc_global.tmp_buf.buf;
92 | return ret->error;
93 | }
94 |
95 | EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(NativeDisplayType display)
96 | {
97 | /*
98 | gls_cmd_flush();
99 | GLS_SET_COMMAND_PTR(c, eglGetDisplay);
100 | c->display = display;
101 | GLS_SEND_PACKET(eglGetDisplay);
102 |
103 | wait_for_data("timeout:eglGetDisplay");
104 | gls_ret_eglGetDisplay_t *ret = (gls_ret_eglGetDisplay_t *)glsc_global.tmp_buf.buf;
105 | return ret->display;
106 | */
107 |
108 | #ifdef USE_X11
109 | xDisplay = display;
110 | xScreenId = DefaultScreen(&xDisplay);
111 | #endif // USE_X11
112 |
113 | // Can't getting Android EGL display from Linux Native display?
114 | return eglGetCurrentDisplay();
115 | }
116 |
117 | EGLAPI EGLBoolean EGLAPIENTRY eglInitialize( EGLDisplay dpy, EGLint *major, EGLint *minor )
118 | {
119 | gls_cmd_flush();
120 | GLS_SET_COMMAND_PTR(c, eglInitialize);
121 | c->dpy = dpy;
122 | c->major = major;
123 | c->minor = minor;
124 | GLS_SEND_PACKET(eglInitialize);
125 |
126 | wait_for_data("timeout:eglInitialize");
127 | gls_ret_eglInitialize_t *ret = (gls_ret_eglInitialize_t *)glsc_global.tmp_buf.buf;
128 | return ret->success;
129 | }
130 |
131 | EGLAPI EGLBoolean EGLAPIENTRY eglTerminate( EGLDisplay dpy )
132 | {
133 | gls_cmd_flush();
134 | GLS_SET_COMMAND_PTR(c, eglTerminate);
135 | c->dpy = dpy;
136 | GLS_SEND_PACKET(eglTerminate);
137 |
138 | wait_for_data("timeout:eglTerminate");
139 | gls_ret_eglTerminate_t *ret = (gls_ret_eglTerminate_t *)glsc_global.tmp_buf.buf;
140 | return ret->success;
141 | }
142 |
143 |
144 | EGLAPI const char* EGLAPIENTRY eglQueryString( EGLDisplay dpy, EGLint name )
145 | {
146 | /*
147 | switch (name) {
148 | case EGL_VENDOR: return "gl-streaming wrapper";
149 | case EGL_VERSION: return "1.4";
150 | default: return "";
151 | }
152 | */
153 | gls_cmd_flush();
154 | GLS_SET_COMMAND_PTR(c, eglQueryString);
155 | c->dpy = dpy;
156 | c->name = name;
157 | GLS_SEND_PACKET(eglQueryString);
158 |
159 | wait_for_data("timeout:eglQueryString");
160 | gls_ret_eglQueryString_t *ret = (gls_ret_eglQueryString_t *)glsc_global.tmp_buf.buf;
161 | return &ret->params[0];
162 | }
163 |
164 |
165 | EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress( const char *procname )
166 | {
167 | // Do not implement streaming
168 | return dlsym(dlopen(NULL, RTLD_LOCAL), procname);
169 | }
170 |
171 | EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config )
172 | {
173 | /*
174 | gls_cmd_flush();
175 | gls_data_egl_attriblist_t *dat = (gls_data_egl_attriblist_t *)glsc_global.tmp_buf.buf;
176 | memcpy(dat->attrib_list, attrib_list, GLS_DATA_SIZE);
177 | gls_cmd_send_data(0, GLS_STRING_SIZE_PLUS, glsc_global.tmp_buf.buf);
178 |
179 | GLS_SET_COMMAND_PTR(c, eglChooseConfig);
180 | c->dpy = dpy;
181 | c->config_size = config_size;
182 | GLS_SEND_PACKET(eglChooseConfig);
183 |
184 | wait_for_data("timeout:eglChooseConfig");
185 | gls_ret_eglChooseConfig_t *ret = (gls_ret_eglChooseConfig_t *)glsc_global.tmp_buf.buf;
186 | *num_config = ret->num_config;
187 |
188 | // printf("eglChooseConfig()=%p. config_size=%i,num_config=%i\n", ret->success, config_size, ret->num_config);
189 |
190 | if (configs != NULL) {
191 | *configs = ret->configs;
192 | }
193 |
194 | return ret->success;
195 | */
196 |
197 | // Build a fake local config
198 | size_t config_arr_size = sizeof(attrib_list)/sizeof(attrib_list[0]);
199 | if (config_arr_size > 0) {
200 | client_config_size = config_arr_size;
201 | // Skip the last one if it is EGL_NONE
202 | if (attrib_list[client_config_size - 1] == EGL_NONE) {
203 | client_config_size -= 1;
204 | }
205 |
206 | // printf("client_config_size=%i\n", client_config_size);
207 | *num_config = client_config_size / 2;
208 | for (int i = 0; i < client_config_size; i+=2) {
209 | if (configs != NULL) configs[i] = &attrib_list[i];
210 | client_config_keys[i] = attrib_list[i];
211 | client_config_values[i] = attrib_list[i+1];
212 | }
213 | }
214 |
215 | return EGL_TRUE;
216 |
217 | // return eglGetConfigs(dpy, configs, config_size, num_config);
218 | }
219 |
220 | EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list )
221 | {
222 | if (sizeof(void*) != sizeof(window)) {
223 | client_egl_error = EGL_BAD_NATIVE_WINDOW;
224 | return EGL_NO_SURFACE;
225 | }
226 | #if !defined(GLS_USE_SRVSIZE) && defined(USE_X11)
227 | xWindow = window;
228 | #endif // GLS_USE_SRVSIZE
229 |
230 | return eglGetCurrentSurface(EGL_DRAW);
231 | }
232 |
233 | EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, NativePixmapType pixmap, const EGLint *attrib_list )
234 | {
235 | return eglGetCurrentSurface(EGL_DRAW);
236 | }
237 |
238 | EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list )
239 | {
240 | return eglGetCurrentSurface(EGL_DRAW);
241 | }
242 |
243 | EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface( EGLDisplay dpy, EGLSurface surface )
244 | {
245 | return EGL_TRUE;
246 | }
247 |
248 | EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value )
249 | {
250 | // This fix size assert in `es2gears` and `es2tri`.
251 | #if !defined(GLS_USE_SRVSIZE) && defined(USE_X11)
252 | if (xDisplay != NULL && xWindow != NULL && (attribute == EGL_WIDTH || attribute == EGL_HEIGHT)) {
253 | XWindowAttributes xWindowAttrs;
254 | if (!XGetWindowAttributes(xDisplay, xWindow /* XDefaultRootWindow(xDisplay) */, &xWindowAttrs)) {
255 | printf("Warning: XGetWindowAttributes failed!");
256 | } else {
257 | // printf("WIDTH=%d HEIGHT=%d\n", xWindowAttrs.width, xWindowAttrs.height);
258 | switch (attribute) {
259 | case EGL_WIDTH:
260 | *value = xWindowAttrs.width;
261 | return EGL_TRUE;
262 | case EGL_HEIGHT:
263 | *value = xWindowAttrs.height;
264 | return EGL_TRUE;
265 | }
266 | }
267 |
268 | // *value = 300;
269 | // return EGL_TRUE;
270 | }
271 | #endif // ndef GLS_USE_SRVSIZE && def USE_X11
272 |
273 | gls_cmd_flush();
274 | GLS_SET_COMMAND_PTR(c, eglQuerySurface);
275 | c->dpy = dpy;
276 | c->surface = surface;
277 | c->attribute = attribute;
278 | GLS_SEND_PACKET(eglQuerySurface);
279 |
280 | wait_for_data("timeout:eglQuerySurface");
281 | gls_ret_eglQuerySurface_t *ret = (gls_ret_eglQuerySurface_t *)glsc_global.tmp_buf.buf;
282 | *value = ret->value;
283 | return ret->success;
284 | }
285 |
286 | EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void)
287 | {
288 | // Current stub
289 | return EGL_TRUE;
290 | }
291 |
292 | /* EGL 1.1 render-to-texture APIs */
293 | EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
294 | {
295 | gls_cmd_flush();
296 | GLS_SET_COMMAND_PTR(c, eglSurfaceAttrib);
297 | c->dpy = dpy;
298 | c->surface = surface;
299 | c->attribute = attribute;
300 | c->value = value;
301 | GLS_SEND_PACKET(eglSurfaceAttrib);
302 |
303 | wait_for_data("timeout:eglSurfaceAttrib");
304 | gls_ret_eglSurfaceAttrib_t *ret = (gls_ret_eglSurfaceAttrib_t *)glsc_global.tmp_buf.buf;
305 | return ret->success;
306 | }
307 |
308 | EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
309 | {
310 | gls_cmd_flush();
311 | GLS_SET_COMMAND_PTR(c, eglBindTexImage);
312 | c->dpy = dpy;
313 | c->surface = surface;
314 | c->buffer = buffer;
315 | GLS_SEND_PACKET(eglBindTexImage);
316 |
317 | wait_for_data("timeout:eglBindTexImage");
318 | gls_ret_eglBindTexImage_t *ret = (gls_ret_eglBindTexImage_t *)glsc_global.tmp_buf.buf;
319 | return ret->success;
320 | }
321 |
322 | EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage( EGLDisplay dpy, EGLSurface surface, EGLint buffer )
323 | {
324 | gls_cmd_flush();
325 | GLS_SET_COMMAND_PTR(c, eglReleaseTexImage);
326 | c->dpy = dpy;
327 | c->surface = surface;
328 | c->buffer = buffer;
329 | GLS_SEND_PACKET(eglReleaseTexImage);
330 |
331 | wait_for_data("timeout:eglReleaseTexImage");
332 | gls_ret_eglReleaseTexImage_t *ret = (gls_ret_eglReleaseTexImage_t *)glsc_global.tmp_buf.buf;
333 | return ret->success;
334 | }
335 |
336 | /* EGL 1.1 swap control API */
337 | EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval( EGLDisplay dpy, EGLint interval )
338 | {
339 |
340 | }
341 |
342 | EGLAPI EGLContext EGLAPIENTRY eglCreateContext( EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list )
343 | {
344 | // return 1;
345 |
346 | // Stub: current
347 | return eglGetCurrentContext();
348 | }
349 |
350 | EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext( EGLDisplay dpy, EGLContext ctx )
351 | {
352 | return EGL_TRUE;
353 | }
354 |
355 | EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx )
356 | {
357 | return EGL_TRUE;
358 | }
359 |
360 | EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void)
361 | {
362 | gls_cmd_flush();
363 | GLS_SET_COMMAND_PTR(c, eglGetCurrentContext);
364 | GLS_SEND_PACKET(eglGetCurrentContext);
365 |
366 | wait_for_data("timeout:eglGetCurrentContext");
367 | gls_ret_eglGetCurrentContext_t *ret = (gls_ret_eglGetCurrentContext_t *)glsc_global.tmp_buf.buf;
368 | return ret->context;
369 | }
370 |
371 | EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void)
372 | {
373 | gls_cmd_flush();
374 | GLS_SET_COMMAND_PTR(c, eglGetCurrentDisplay);
375 | GLS_SEND_PACKET(eglGetCurrentDisplay);
376 |
377 | wait_for_data("timeout:eglGetCurrentDisplay");
378 | gls_ret_eglGetCurrentDisplay_t *ret = (gls_ret_eglGetCurrentDisplay_t *)glsc_global.tmp_buf.buf;
379 | return ret->display;
380 | }
381 |
382 | EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw)
383 | {
384 | gls_cmd_flush();
385 | GLS_SET_COMMAND_PTR(c, eglGetCurrentSurface);
386 | c->readdraw = readdraw;
387 | GLS_SEND_PACKET(eglGetCurrentSurface);
388 |
389 | wait_for_data("timeout:eglGetCurrentSurface");
390 | gls_ret_eglGetCurrentSurface_t *ret = (gls_ret_eglGetCurrentSurface_t *)glsc_global.tmp_buf.buf;
391 | return ret->surface;
392 | }
393 |
394 | EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext( EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value )
395 | {
396 | gls_cmd_flush();
397 | GLS_SET_COMMAND_PTR(c, eglQueryContext);
398 | c->dpy = dpy;
399 | c->ctx = ctx;
400 | c->attribute = attribute;
401 | GLS_SEND_PACKET(eglQueryContext);
402 |
403 | wait_for_data("timeout:eglQueryContext");
404 | gls_ret_eglQueryContext_t *ret = (gls_ret_eglQueryContext_t *)glsc_global.tmp_buf.buf;
405 | *value = ret->value;
406 | return ret->success;
407 | }
408 |
409 | EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL( void )
410 | {
411 | return // EGL_TRUE;
412 | EGL_FALSE;
413 | }
414 |
415 | EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative( EGLint engine )
416 | {
417 | return EGL_FALSE;
418 | }
419 |
420 | EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers( EGLDisplay dpy, EGLSurface draw )
421 | {
422 | static int frame;
423 | return gls_cmd_flip(frame++);
424 | }
425 |
426 | EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, NativePixmapType target )
427 | {
428 | return EGL_TRUE;
429 | }
430 |
431 |
--------------------------------------------------------------------------------
/gl_client/glclient.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #include "glclient.h"
37 |
38 |
39 | float get_diff_time(struct timeval start, struct timeval end)
40 | {
41 | float dt = (float)(end.tv_sec - start.tv_sec) + (float)(end.tv_usec - start.tv_usec) * 0.000001f;
42 | return dt;
43 | }
44 |
45 |
46 | int check_batch_overflow(size_t size, const char *msg)
47 | {
48 | if (size >= GLS_TMP_BUFFER_SIZE - BATCH_AUTO_FLUSH_SIZE)
49 | {
50 | perror(msg);
51 | return FALSE;
52 | }
53 | uint32_t ptr = next_ptr(glsc_global.tmp_buf.ptr, size, GLS_ALIGNMENT_BITS);
54 | if (ptr >= GLS_TMP_BUFFER_SIZE - BATCH_AUTO_FLUSH_SIZE)
55 | {
56 | gls_cmd_flush();
57 | }
58 | return TRUE;
59 | }
60 |
61 |
62 | void push_batch_command(size_t size)
63 | {
64 | glsc_global.tmp_buf.ptr = next_ptr(glsc_global.tmp_buf.ptr, size, GLS_ALIGNMENT_BITS);
65 | if (glsc_global.tmp_buf.ptr > BATCH_AUTO_FLUSH_SIZE)
66 | {
67 | gls_cmd_flush();
68 | }
69 | }
70 |
71 |
72 | int gls_init(server_context_t *arg)
73 | {
74 | memset(&glsc_global, 0, sizeof(glsc_global));
75 |
76 | const char* env_isDebugStr = getenv("GLS_DEBUG");
77 | int env_isDebug;
78 | if (env_isDebugStr == NULL) {
79 | env_isDebug = FALSE;
80 | } else {
81 | env_isDebug = atoi(env_isDebugStr);
82 | }
83 |
84 | if (env_isDebug == 0 || env_isDebug == 1) {
85 | glsc_global.is_debug = env_isDebug;
86 | } else {
87 | printf("gls error: GLS_DEBUG variable must be 0 or 1\n");
88 | exit(EXIT_FAILURE);
89 | return FALSE;
90 | }
91 |
92 | glsc_global.sta = arg;
93 | glsc_global.pack_alignment = 4;
94 | glsc_global.unpack_alignment = 4;
95 | glsc_global.screen_width = 1280;
96 | glsc_global.screen_height = 720;
97 | glsc_global.out_buf.buf = (char *)malloc(GLS_OUT_BUFFER_SIZE);
98 | if (glsc_global.out_buf.buf == NULL)
99 | {
100 | return FALSE;
101 | }
102 | glsc_global.tmp_buf.buf = (char *)malloc(GLS_TMP_BUFFER_SIZE);
103 | if (glsc_global.tmp_buf.buf == NULL)
104 | {
105 | free(glsc_global.out_buf.buf);
106 | return FALSE;
107 | }
108 | glsc_global.out_buf.size = GLS_OUT_BUFFER_SIZE;
109 | glsc_global.tmp_buf.size = GLS_TMP_BUFFER_SIZE;
110 | glsc_global.out_buf.ptr = 0;
111 | glsc_global.tmp_buf.ptr = 0;
112 | /*
113 | xDisplay = XOpenDisplay(NULL);
114 | if (xDisplay == NULL) {
115 | printf("gls error: could not open X11 display.\n");
116 | exit(EXIT_FAILURE);
117 | return FALSE;
118 | }
119 | xScreenId = DefaultScreen(xDisplay);
120 | */
121 | client_egl_error = EGL_SUCCESS;
122 |
123 | return TRUE;
124 | }
125 |
126 |
127 | void gls_init_library()
128 | {
129 | static server_context_t sc;
130 | static int init = FALSE;
131 | if(init)
132 | return;
133 | char my_ip[30]; // GLS_STRING_SIZE_PLUS
134 | char his_ip[30]; // GLS_STRING_SIZE_PLUS
135 | uint16_t my_port = 18146;
136 | uint16_t his_port = 18145;
137 |
138 | const char* env_serverAddr = getenv("GLS_SERVER_ADDR");
139 | if (env_serverAddr == NULL) {
140 | strncpy(his_ip, "127.0.0.1", 10);
141 | } else {
142 | printf("GLS_SERVER_ADDR is set to %s\n", env_serverAddr);
143 |
144 | char* env_serverAddr_search = ":";
145 | int env_serverAddr_length = strnlen(env_serverAddr, 0xA00000);
146 | char env_serverAddr_arr[env_serverAddr_length];
147 | strncpy(env_serverAddr_arr, env_serverAddr, env_serverAddr_length + 1);
148 |
149 | char* env_serverIp = strtok(env_serverAddr_arr, env_serverAddr_search);
150 | strncpy(his_ip, env_serverIp, strnlen(env_serverIp, 0xA00000) + 1);
151 | his_port = atoi(strtok(NULL, env_serverAddr_search));
152 |
153 | }
154 |
155 | strncpy(my_ip, "127.0.0.1", 10);
156 | server_init(&sc);
157 | set_client_address_port(&sc, my_ip, my_port);
158 | set_server_address_port(&sc, his_ip, his_port);
159 |
160 | server_start(&sc);
161 | gls_init(&sc);
162 | gls_cmd_get_context();
163 |
164 | // xDisplay = XOpenDisplay(NULL);
165 | // xScreenId = DefaultScreen(xDisplay);
166 |
167 | init = TRUE;
168 | }
169 |
170 |
171 | int gls_free()
172 | {
173 | #ifdef USE_X11
174 | XCloseDisplay(xDisplay);
175 | #endif
176 |
177 | free(glsc_global.out_buf.buf);
178 | free(glsc_global.tmp_buf.buf);
179 |
180 | return TRUE;
181 | }
182 |
183 |
184 | int send_packet(size_t size)
185 | {
186 | server_context_t *a = glsc_global.sta;
187 | if (sendto(a->sock_fd, glsc_global.out_buf.buf, size, 0, (struct sockaddr *)&a->sai, sizeof(struct sockaddr_in)) == -1)
188 | {
189 | return FALSE;
190 | }
191 | gls_sleep(a->max_mbps, size);
192 | return TRUE;
193 | }
194 |
195 |
196 | int gls_cmd_recv_data()
197 | {
198 | gls_cmd_send_data_t *c = (gls_cmd_send_data_t *)glsc_global.cmd_data;
199 | if ((c->offset + c->size > glsc_global.tmp_buf.size) || (glsc_global.tmp_buf.size == 0))
200 | {
201 | return c->isLast;
202 | }
203 | memcpy(&glsc_global.tmp_buf.buf[c->offset], c->data.data_char, c->size);
204 | return c->isLast;
205 | }
206 |
207 |
208 | int wait_for_data(char *str)
209 | {
210 | server_context_t *a = glsc_global.sta;
211 | struct timeval start_time, end_time;
212 | gettimeofday(&start_time, NULL);
213 | int quit = FALSE;
214 | while (quit == FALSE)
215 | {
216 | void *popptr = (void *)fifo_pop_ptr_get(&a->fifo);
217 | if (popptr == NULL)
218 | {
219 | gettimeofday(&end_time, NULL);
220 | float diff_time = get_diff_time(start_time, end_time);
221 | if (diff_time > GLS_TIMEOUT_SEC)
222 | {
223 | printf("\n%s\n", str);
224 | exit(EXIT_FAILURE);
225 | return FALSE;
226 | }
227 | usleep(a->sleep_usec);
228 | }
229 | else
230 | {
231 | gls_command_t *c = (gls_command_t *)popptr;
232 | glsc_global.cmd_data = popptr;
233 | switch (c->cmd)
234 | {
235 | case GLSC_SEND_DATA:
236 | if (gls_cmd_recv_data() == TRUE) {
237 | quit = TRUE;
238 | }
239 | break;
240 | default:
241 | break;
242 | }
243 | fifo_pop_ptr_next(&a->fifo);
244 | }
245 | }
246 | return TRUE;
247 | }
248 |
249 |
250 | int gls_cmd_send_data(uint32_t offset, uint32_t size, void *data)
251 | {
252 | if (data == NULL) {
253 | return TRUE;
254 | }
255 |
256 | gls_cmd_send_data_t *c = (gls_cmd_send_data_t *)glsc_global.out_buf.buf;
257 | c->cmd = GLSC_SEND_DATA;
258 |
259 | int success = TRUE;
260 | uint32_t glssize = GLS_DATA_SIZE * 4;
261 | char *data1 = (char *)data;
262 | uint32_t offset1;
263 | for (offset1 = 0; offset1 < size; offset1 += glssize)
264 | {
265 | unsigned int size1 = size - offset1;
266 | c->isLast = (size1 > glssize) ? FALSE : TRUE;
267 | size1 = (size1 > glssize) ? glssize : size1;
268 | memcpy(c->data.data_char, data1, size1);
269 | size_t sendbytes = (size_t)(&c->data.data_char[size1] - (char *)c);
270 | c->offset = offset + offset1;
271 | c->size = size1;
272 | if (send_packet(sendbytes) == FALSE)
273 | {
274 | success = FALSE;
275 | }
276 | data1 += glssize;
277 | }
278 | return success;
279 | }
280 |
281 |
282 | int gls_cmd_get_context()
283 | {
284 | gls_cmd_flush();
285 | gls_cmd_get_context_t *c = (gls_cmd_get_context_t *)glsc_global.out_buf.buf;
286 | c->cmd = GLSC_get_context;
287 | if (send_packet(sizeof(gls_cmd_get_context_t)) == FALSE)
288 | {
289 | return FALSE;
290 | }
291 |
292 | wait_for_data("timeout:gls_cmd_get_context");
293 | gls_ret_get_context_t *ret = (gls_ret_get_context_t *)glsc_global.tmp_buf.buf;
294 | if (ret->cmd == GLSC_get_context)
295 | {
296 | glsc_global.screen_width = ret->screen_width;
297 | glsc_global.screen_height = ret->screen_height;
298 | printf("\ngls info: width=%i, height=%i\n", ret->screen_width, ret->screen_height);
299 | if (ret->server_version != GLS_VERSION) {
300 | printf("\e[31m\e[1mgls error\e[0m: Incompatile version, server version %i but client version %i.\n", ret->server_version, GLS_VERSION);
301 | exit(EXIT_FAILURE);
302 | return FALSE;
303 | }
304 | }
305 | return TRUE;
306 | }
307 |
308 |
309 | int gls_cmd_flip(unsigned int frame)
310 | {
311 | gls_cmd_flush();
312 | gls_cmd_flip_t *c = (gls_cmd_flip_t *)glsc_global.out_buf.buf;
313 | c->cmd = GLSC_FLIP;
314 | c->frame = frame;
315 | if (send_packet(sizeof(gls_cmd_flip_t)) == FALSE)
316 | {
317 | return FALSE;
318 | }
319 |
320 | wait_for_data("timeout:gls_cmd_flip");
321 | return TRUE;
322 | }
323 |
324 | int gls_cmd_flush()
325 | {
326 | if (glsc_global.tmp_buf.ptr == 0)
327 | {
328 | return FALSE;
329 | }
330 | gls_command_t *c = (gls_command_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr);
331 | c->cmd = GLSC_BREAK;
332 | glsc_global.tmp_buf.ptr = next_ptr(glsc_global.tmp_buf.ptr, sizeof(gls_command_t), GLS_ALIGNMENT_BITS);
333 | gls_cmd_send_data(0, glsc_global.tmp_buf.ptr, (void *)glsc_global.tmp_buf.buf);
334 | glsc_global.tmp_buf.ptr = 0;
335 |
336 | c = (gls_command_t *)glsc_global.out_buf.buf;
337 | c->cmd = GLSC_FLUSH;
338 | send_packet(sizeof(gls_command_t));
339 | return TRUE;
340 | }
341 |
342 |
--------------------------------------------------------------------------------
/gl_client/glclient.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include
32 |
33 | #ifdef USE_X11
34 | #include
35 | #include
36 | #endif
37 |
38 | #include "EGL/egl.h"
39 | #include "GLES2/gl2.h"
40 | #include "gls_command.h"
41 | #include "server.h"
42 |
43 | typedef struct
44 | {
45 | gls_buffer_t tmp_buf;
46 | gls_buffer_t out_buf;
47 | server_context_t *sta;
48 | void *cmd_data;
49 | uint32_t screen_width;
50 | uint32_t screen_height;
51 | int32_t pack_alignment;
52 | int32_t unpack_alignment;
53 | int is_debug;
54 | } gls_context_t;
55 |
56 |
57 | #ifdef __cplusplus
58 | extern "C" {
59 | #endif
60 |
61 | #define GLS_OUT_BUFFER_SIZE 4096 // 2048
62 | #define BATCH_AUTO_FLUSH_SIZE 16256 // 8128
63 | #define GLS_TIMEOUT_SEC 3.0f
64 |
65 | // gls_glFunctionName_t *c = (gls_glFunctionName_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr);
66 | // c->cmd = GLSC_glFunctionName;
67 | #define GLS_SET_COMMAND_PTR_BATCH(PTR, FUNCNAME) gls_##FUNCNAME##_t *PTR = (gls_##FUNCNAME##_t *)(glsc_global.tmp_buf.buf + glsc_global.tmp_buf.ptr); PTR->cmd = GLSC_##FUNCNAME; if (glsc_global.is_debug == TRUE) printf("gls debug: executing command %s\n", #FUNCNAME);
68 |
69 | // push_batch_command(sizeof(gls_glFunctionName_t));
70 | #define GLS_PUSH_BATCH(FUNCNAME) push_batch_command(sizeof(gls_##FUNCNAME##_t))
71 |
72 | // gls_glFunctionName_t *c = (gls_glFunctionName_t *)glsc_global.out_buf.buf;
73 | // c->cmd = GLSC_glFunctionName;
74 | #define GLS_SET_COMMAND_PTR(PTR, FUNCNAME) gls_##FUNCNAME##_t *PTR = (gls_##FUNCNAME##_t *)glsc_global.out_buf.buf; PTR->cmd = GLSC_##FUNCNAME; if (glsc_global.is_debug == TRUE) printf("gls debug: executing command %s\n", #FUNCNAME);
75 |
76 | // send_packet(sizeof(gls_glFunctionName_t));
77 | #define GLS_SEND_PACKET(FUNCNAME) send_packet(sizeof(gls_##FUNCNAME##_t))
78 |
79 | #define TRUE 1
80 | #define FALSE 0
81 |
82 | gls_context_t glsc_global;
83 |
84 | #ifdef GLS_EMULATE_VBO
85 | static struct vbo_state
86 | {
87 | GLuint vbo, ibo, ibo_emu;
88 | } vbo;
89 | struct attrib_ptr_s {
90 | GLboolean isenabled;
91 | GLint size;
92 | GLenum type;
93 | GLsizei stride;
94 | GLboolean normalized;
95 | const GLvoid *ptr;
96 | GLuint vbo_id;
97 | GLuint webgl_vbo_id;
98 | } vt_attrib_pointer[16];
99 | #endif // GLS_EMUL
100 |
101 | uint32_t client_egl_error;
102 | uint32_t client_config_size;
103 | uint32_t client_config_keys[GLS_DATA_SIZE];
104 | uint32_t client_config_values[GLS_DATA_SIZE];
105 |
106 | float get_diff_time(struct timeval start, struct timeval end);
107 | int check_batch_overflow(size_t size, const char *msg);
108 | void push_batch_command(size_t size);
109 | int gls_cmd_flush();
110 |
111 | void gls_init_library();
112 |
113 | extern gls_context_t glsc_global;
114 | int gls_init(server_context_t *arg);
115 | int gls_free();
116 | int send_packet(size_t size);
117 | int gls_cmd_flip(unsigned int frame);
118 | int gls_cmd_send_data(uint32_t offset, uint32_t size, void *data);
119 | int gls_cmd_get_context();
120 | int gls_cmd_flush();
121 |
122 | #ifdef __cplusplus
123 | }
124 | #endif
125 |
--------------------------------------------------------------------------------
/gl_client/include/EGL/egl.h:
--------------------------------------------------------------------------------
1 | #ifndef __egl_h_
2 | #define __egl_h_ 1
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | /*
9 | ** Copyright (c) 2013-2017 The Khronos Group Inc.
10 | **
11 | ** Permission is hereby granted, free of charge, to any person obtaining a
12 | ** copy of this software and/or associated documentation files (the
13 | ** "Materials"), to deal in the Materials without restriction, including
14 | ** without limitation the rights to use, copy, modify, merge, publish,
15 | ** distribute, sublicense, and/or sell copies of the Materials, and to
16 | ** permit persons to whom the Materials are furnished to do so, subject to
17 | ** the following conditions:
18 | **
19 | ** The above copyright notice and this permission notice shall be included
20 | ** in all copies or substantial portions of the Materials.
21 | **
22 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
29 | */
30 | /*
31 | ** This header is generated from the Khronos EGL XML API Registry.
32 | ** The current version of the Registry, generator scripts
33 | ** used to make the header, and the header can be found at
34 | ** http://www.khronos.org/registry/egl
35 | **
36 | ** Khronos $Git commit SHA1: cb927ca98d $ on $Git commit date: 2019-08-08 01:05:38 -0700 $
37 | */
38 |
39 | #include
40 |
41 | #ifndef EGL_EGL_PROTOTYPES
42 | #define EGL_EGL_PROTOTYPES 1
43 | #endif
44 |
45 | /* Generated on date 20190808 */
46 |
47 | /* Generated C header for:
48 | * API: egl
49 | * Versions considered: .*
50 | * Versions emitted: .*
51 | * Default extensions included: None
52 | * Additional extensions included: _nomatch_^
53 | * Extensions removed: _nomatch_^
54 | */
55 |
56 | #ifndef EGL_VERSION_1_0
57 | #define EGL_VERSION_1_0 1
58 | typedef unsigned int EGLBoolean;
59 | typedef void *EGLDisplay;
60 | #include
61 | #include
62 | typedef void *EGLConfig;
63 | typedef void *EGLSurface;
64 | typedef void *EGLContext;
65 | typedef void (*__eglMustCastToProperFunctionPointerType)(void);
66 | #define EGL_ALPHA_SIZE 0x3021
67 | #define EGL_BAD_ACCESS 0x3002
68 | #define EGL_BAD_ALLOC 0x3003
69 | #define EGL_BAD_ATTRIBUTE 0x3004
70 | #define EGL_BAD_CONFIG 0x3005
71 | #define EGL_BAD_CONTEXT 0x3006
72 | #define EGL_BAD_CURRENT_SURFACE 0x3007
73 | #define EGL_BAD_DISPLAY 0x3008
74 | #define EGL_BAD_MATCH 0x3009
75 | #define EGL_BAD_NATIVE_PIXMAP 0x300A
76 | #define EGL_BAD_NATIVE_WINDOW 0x300B
77 | #define EGL_BAD_PARAMETER 0x300C
78 | #define EGL_BAD_SURFACE 0x300D
79 | #define EGL_BLUE_SIZE 0x3022
80 | #define EGL_BUFFER_SIZE 0x3020
81 | #define EGL_CONFIG_CAVEAT 0x3027
82 | #define EGL_CONFIG_ID 0x3028
83 | #define EGL_CORE_NATIVE_ENGINE 0x305B
84 | #define EGL_DEPTH_SIZE 0x3025
85 | #define EGL_DONT_CARE EGL_CAST(EGLint,-1)
86 | #define EGL_DRAW 0x3059
87 | #define EGL_EXTENSIONS 0x3055
88 | #define EGL_FALSE 0
89 | #define EGL_GREEN_SIZE 0x3023
90 | #define EGL_HEIGHT 0x3056
91 | #define EGL_LARGEST_PBUFFER 0x3058
92 | #define EGL_LEVEL 0x3029
93 | #define EGL_MAX_PBUFFER_HEIGHT 0x302A
94 | #define EGL_MAX_PBUFFER_PIXELS 0x302B
95 | #define EGL_MAX_PBUFFER_WIDTH 0x302C
96 | #define EGL_NATIVE_RENDERABLE 0x302D
97 | #define EGL_NATIVE_VISUAL_ID 0x302E
98 | #define EGL_NATIVE_VISUAL_TYPE 0x302F
99 | #define EGL_NONE 0x3038
100 | #define EGL_NON_CONFORMANT_CONFIG 0x3051
101 | #define EGL_NOT_INITIALIZED 0x3001
102 | #define EGL_NO_CONTEXT EGL_CAST(EGLContext,0)
103 | #define EGL_NO_DISPLAY EGL_CAST(EGLDisplay,0)
104 | #define EGL_NO_SURFACE EGL_CAST(EGLSurface,0)
105 | #define EGL_PBUFFER_BIT 0x0001
106 | #define EGL_PIXMAP_BIT 0x0002
107 | #define EGL_READ 0x305A
108 | #define EGL_RED_SIZE 0x3024
109 | #define EGL_SAMPLES 0x3031
110 | #define EGL_SAMPLE_BUFFERS 0x3032
111 | #define EGL_SLOW_CONFIG 0x3050
112 | #define EGL_STENCIL_SIZE 0x3026
113 | #define EGL_SUCCESS 0x3000
114 | #define EGL_SURFACE_TYPE 0x3033
115 | #define EGL_TRANSPARENT_BLUE_VALUE 0x3035
116 | #define EGL_TRANSPARENT_GREEN_VALUE 0x3036
117 | #define EGL_TRANSPARENT_RED_VALUE 0x3037
118 | #define EGL_TRANSPARENT_RGB 0x3052
119 | #define EGL_TRANSPARENT_TYPE 0x3034
120 | #define EGL_TRUE 1
121 | #define EGL_VENDOR 0x3053
122 | #define EGL_VERSION 0x3054
123 | #define EGL_WIDTH 0x3057
124 | #define EGL_WINDOW_BIT 0x0004
125 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLCHOOSECONFIGPROC) (EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
126 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOPYBUFFERSPROC) (EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
127 | typedef EGLContext (EGLAPIENTRYP PFNEGLCREATECONTEXTPROC) (EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
128 | typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPBUFFERSURFACEPROC) (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
129 | typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEPROC) (EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
130 | typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEWINDOWSURFACEPROC) (EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
131 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYCONTEXTPROC) (EGLDisplay dpy, EGLContext ctx);
132 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSURFACEPROC) (EGLDisplay dpy, EGLSurface surface);
133 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETCONFIGATTRIBPROC) (EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
134 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETCONFIGSPROC) (EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
135 | typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETCURRENTDISPLAYPROC) (void);
136 | typedef EGLSurface (EGLAPIENTRYP PFNEGLGETCURRENTSURFACEPROC) (EGLint readdraw);
137 | typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETDISPLAYPROC) (EGLNativeDisplayType display_id);
138 | typedef EGLint (EGLAPIENTRYP PFNEGLGETERRORPROC) (void);
139 | typedef __eglMustCastToProperFunctionPointerType (EGLAPIENTRYP PFNEGLGETPROCADDRESSPROC) (const char *procname);
140 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLINITIALIZEPROC) (EGLDisplay dpy, EGLint *major, EGLint *minor);
141 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLMAKECURRENTPROC) (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
142 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYCONTEXTPROC) (EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
143 | typedef const char *(EGLAPIENTRYP PFNEGLQUERYSTRINGPROC) (EGLDisplay dpy, EGLint name);
144 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
145 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSPROC) (EGLDisplay dpy, EGLSurface surface);
146 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLTERMINATEPROC) (EGLDisplay dpy);
147 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLWAITGLPROC) (void);
148 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLWAITNATIVEPROC) (EGLint engine);
149 | #if EGL_EGL_PROTOTYPES
150 | EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig (EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
151 | EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers (EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
152 | EGLAPI EGLContext EGLAPIENTRY eglCreateContext (EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
153 | EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
154 | EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface (EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
155 | EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface (EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
156 | EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext (EGLDisplay dpy, EGLContext ctx);
157 | EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface (EGLDisplay dpy, EGLSurface surface);
158 | EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib (EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
159 | EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs (EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
160 | EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay (void);
161 | EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface (EGLint readdraw);
162 | EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay (EGLNativeDisplayType display_id);
163 | EGLAPI EGLint EGLAPIENTRY eglGetError (void);
164 | EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress (const char *procname);
165 | EGLAPI EGLBoolean EGLAPIENTRY eglInitialize (EGLDisplay dpy, EGLint *major, EGLint *minor);
166 | EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
167 | EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext (EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
168 | EGLAPI const char *EGLAPIENTRY eglQueryString (EGLDisplay dpy, EGLint name);
169 | EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
170 | EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers (EGLDisplay dpy, EGLSurface surface);
171 | EGLAPI EGLBoolean EGLAPIENTRY eglTerminate (EGLDisplay dpy);
172 | EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL (void);
173 | EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative (EGLint engine);
174 | #endif
175 | #endif /* EGL_VERSION_1_0 */
176 |
177 | #ifndef EGL_VERSION_1_1
178 | #define EGL_VERSION_1_1 1
179 | #define EGL_BACK_BUFFER 0x3084
180 | #define EGL_BIND_TO_TEXTURE_RGB 0x3039
181 | #define EGL_BIND_TO_TEXTURE_RGBA 0x303A
182 | #define EGL_CONTEXT_LOST 0x300E
183 | #define EGL_MIN_SWAP_INTERVAL 0x303B
184 | #define EGL_MAX_SWAP_INTERVAL 0x303C
185 | #define EGL_MIPMAP_TEXTURE 0x3082
186 | #define EGL_MIPMAP_LEVEL 0x3083
187 | #define EGL_NO_TEXTURE 0x305C
188 | #define EGL_TEXTURE_2D 0x305F
189 | #define EGL_TEXTURE_FORMAT 0x3080
190 | #define EGL_TEXTURE_RGB 0x305D
191 | #define EGL_TEXTURE_RGBA 0x305E
192 | #define EGL_TEXTURE_TARGET 0x3081
193 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDTEXIMAGEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
194 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLRELEASETEXIMAGEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
195 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLSURFACEATTRIBPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
196 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPINTERVALPROC) (EGLDisplay dpy, EGLint interval);
197 | #if EGL_EGL_PROTOTYPES
198 | EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
199 | EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
200 | EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
201 | EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval (EGLDisplay dpy, EGLint interval);
202 | #endif
203 | #endif /* EGL_VERSION_1_1 */
204 |
205 | #ifndef EGL_VERSION_1_2
206 | #define EGL_VERSION_1_2 1
207 | typedef unsigned int EGLenum;
208 | typedef void *EGLClientBuffer;
209 | #define EGL_ALPHA_FORMAT 0x3088
210 | #define EGL_ALPHA_FORMAT_NONPRE 0x308B
211 | #define EGL_ALPHA_FORMAT_PRE 0x308C
212 | #define EGL_ALPHA_MASK_SIZE 0x303E
213 | #define EGL_BUFFER_PRESERVED 0x3094
214 | #define EGL_BUFFER_DESTROYED 0x3095
215 | #define EGL_CLIENT_APIS 0x308D
216 | #define EGL_COLORSPACE 0x3087
217 | #define EGL_COLORSPACE_sRGB 0x3089
218 | #define EGL_COLORSPACE_LINEAR 0x308A
219 | #define EGL_COLOR_BUFFER_TYPE 0x303F
220 | #define EGL_CONTEXT_CLIENT_TYPE 0x3097
221 | #define EGL_DISPLAY_SCALING 10000
222 | #define EGL_HORIZONTAL_RESOLUTION 0x3090
223 | #define EGL_LUMINANCE_BUFFER 0x308F
224 | #define EGL_LUMINANCE_SIZE 0x303D
225 | #define EGL_OPENGL_ES_BIT 0x0001
226 | #define EGL_OPENVG_BIT 0x0002
227 | #define EGL_OPENGL_ES_API 0x30A0
228 | #define EGL_OPENVG_API 0x30A1
229 | #define EGL_OPENVG_IMAGE 0x3096
230 | #define EGL_PIXEL_ASPECT_RATIO 0x3092
231 | #define EGL_RENDERABLE_TYPE 0x3040
232 | #define EGL_RENDER_BUFFER 0x3086
233 | #define EGL_RGB_BUFFER 0x308E
234 | #define EGL_SINGLE_BUFFER 0x3085
235 | #define EGL_SWAP_BEHAVIOR 0x3093
236 | #define EGL_UNKNOWN EGL_CAST(EGLint,-1)
237 | #define EGL_VERTICAL_RESOLUTION 0x3091
238 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDAPIPROC) (EGLenum api);
239 | typedef EGLenum (EGLAPIENTRYP PFNEGLQUERYAPIPROC) (void);
240 | typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPBUFFERFROMCLIENTBUFFERPROC) (EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
241 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLRELEASETHREADPROC) (void);
242 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLWAITCLIENTPROC) (void);
243 | #if EGL_EGL_PROTOTYPES
244 | EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI (EGLenum api);
245 | EGLAPI EGLenum EGLAPIENTRY eglQueryAPI (void);
246 | EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer (EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
247 | EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread (void);
248 | EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient (void);
249 | #endif
250 | #endif /* EGL_VERSION_1_2 */
251 |
252 | #ifndef EGL_VERSION_1_3
253 | #define EGL_VERSION_1_3 1
254 | #define EGL_CONFORMANT 0x3042
255 | #define EGL_CONTEXT_CLIENT_VERSION 0x3098
256 | #define EGL_MATCH_NATIVE_PIXMAP 0x3041
257 | #define EGL_OPENGL_ES2_BIT 0x0004
258 | #define EGL_VG_ALPHA_FORMAT 0x3088
259 | #define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B
260 | #define EGL_VG_ALPHA_FORMAT_PRE 0x308C
261 | #define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040
262 | #define EGL_VG_COLORSPACE 0x3087
263 | #define EGL_VG_COLORSPACE_sRGB 0x3089
264 | #define EGL_VG_COLORSPACE_LINEAR 0x308A
265 | #define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020
266 | #endif /* EGL_VERSION_1_3 */
267 |
268 | #ifndef EGL_VERSION_1_4
269 | #define EGL_VERSION_1_4 1
270 | #define EGL_DEFAULT_DISPLAY EGL_CAST(EGLNativeDisplayType,0)
271 | #define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200
272 | #define EGL_MULTISAMPLE_RESOLVE 0x3099
273 | #define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A
274 | #define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B
275 | #define EGL_OPENGL_API 0x30A2
276 | #define EGL_OPENGL_BIT 0x0008
277 | #define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400
278 | typedef EGLContext (EGLAPIENTRYP PFNEGLGETCURRENTCONTEXTPROC) (void);
279 | #if EGL_EGL_PROTOTYPES
280 | EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext (void);
281 | #endif
282 | #endif /* EGL_VERSION_1_4 */
283 |
284 | #ifndef EGL_VERSION_1_5
285 | #define EGL_VERSION_1_5 1
286 | typedef void *EGLSync;
287 | typedef intptr_t EGLAttrib;
288 | typedef khronos_utime_nanoseconds_t EGLTime;
289 | typedef void *EGLImage;
290 | #define EGL_CONTEXT_MAJOR_VERSION 0x3098
291 | #define EGL_CONTEXT_MINOR_VERSION 0x30FB
292 | #define EGL_CONTEXT_OPENGL_PROFILE_MASK 0x30FD
293 | #define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY 0x31BD
294 | #define EGL_NO_RESET_NOTIFICATION 0x31BE
295 | #define EGL_LOSE_CONTEXT_ON_RESET 0x31BF
296 | #define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT 0x00000001
297 | #define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT 0x00000002
298 | #define EGL_CONTEXT_OPENGL_DEBUG 0x31B0
299 | #define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE 0x31B1
300 | #define EGL_CONTEXT_OPENGL_ROBUST_ACCESS 0x31B2
301 | #define EGL_OPENGL_ES3_BIT 0x00000040
302 | #define EGL_CL_EVENT_HANDLE 0x309C
303 | #define EGL_SYNC_CL_EVENT 0x30FE
304 | #define EGL_SYNC_CL_EVENT_COMPLETE 0x30FF
305 | #define EGL_SYNC_PRIOR_COMMANDS_COMPLETE 0x30F0
306 | #define EGL_SYNC_TYPE 0x30F7
307 | #define EGL_SYNC_STATUS 0x30F1
308 | #define EGL_SYNC_CONDITION 0x30F8
309 | #define EGL_SIGNALED 0x30F2
310 | #define EGL_UNSIGNALED 0x30F3
311 | #define EGL_SYNC_FLUSH_COMMANDS_BIT 0x0001
312 | #define EGL_FOREVER 0xFFFFFFFFFFFFFFFFull
313 | #define EGL_TIMEOUT_EXPIRED 0x30F5
314 | #define EGL_CONDITION_SATISFIED 0x30F6
315 | #define EGL_NO_SYNC EGL_CAST(EGLSync,0)
316 | #define EGL_SYNC_FENCE 0x30F9
317 | #define EGL_GL_COLORSPACE 0x309D
318 | #define EGL_GL_COLORSPACE_SRGB 0x3089
319 | #define EGL_GL_COLORSPACE_LINEAR 0x308A
320 | #define EGL_GL_RENDERBUFFER 0x30B9
321 | #define EGL_GL_TEXTURE_2D 0x30B1
322 | #define EGL_GL_TEXTURE_LEVEL 0x30BC
323 | #define EGL_GL_TEXTURE_3D 0x30B2
324 | #define EGL_GL_TEXTURE_ZOFFSET 0x30BD
325 | #define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x30B3
326 | #define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x30B4
327 | #define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x30B5
328 | #define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x30B6
329 | #define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x30B7
330 | #define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x30B8
331 | #define EGL_IMAGE_PRESERVED 0x30D2
332 | #define EGL_NO_IMAGE EGL_CAST(EGLImage,0)
333 | typedef EGLSync (EGLAPIENTRYP PFNEGLCREATESYNCPROC) (EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
334 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCPROC) (EGLDisplay dpy, EGLSync sync);
335 | typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCPROC) (EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
336 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBPROC) (EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
337 | typedef EGLImage (EGLAPIENTRYP PFNEGLCREATEIMAGEPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
338 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEPROC) (EGLDisplay dpy, EGLImage image);
339 | typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYPROC) (EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
340 | typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEPROC) (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
341 | typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMPIXMAPSURFACEPROC) (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list);
342 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLWAITSYNCPROC) (EGLDisplay dpy, EGLSync sync, EGLint flags);
343 | #if EGL_EGL_PROTOTYPES
344 | EGLAPI EGLSync EGLAPIENTRY eglCreateSync (EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
345 | EGLAPI EGLBoolean EGLAPIENTRY eglDestroySync (EGLDisplay dpy, EGLSync sync);
346 | EGLAPI EGLint EGLAPIENTRY eglClientWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
347 | EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttrib (EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
348 | EGLAPI EGLImage EGLAPIENTRY eglCreateImage (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
349 | EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImage (EGLDisplay dpy, EGLImage image);
350 | EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay (EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
351 | EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
352 | EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurface (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list);
353 | EGLAPI EGLBoolean EGLAPIENTRY eglWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags);
354 | #endif
355 | #endif /* EGL_VERSION_1_5 */
356 |
357 | #ifdef __cplusplus
358 | }
359 | #endif
360 |
361 | #endif
362 |
--------------------------------------------------------------------------------
/gl_client/include/EGL/eglplatform.h:
--------------------------------------------------------------------------------
1 | #ifndef __eglplatform_h_
2 | #define __eglplatform_h_
3 |
4 | /*
5 | ** Copyright (c) 2007-2016 The Khronos Group Inc.
6 | **
7 | ** Permission is hereby granted, free of charge, to any person obtaining a
8 | ** copy of this software and/or associated documentation files (the
9 | ** "Materials"), to deal in the Materials without restriction, including
10 | ** without limitation the rights to use, copy, modify, merge, publish,
11 | ** distribute, sublicense, and/or sell copies of the Materials, and to
12 | ** permit persons to whom the Materials are furnished to do so, subject to
13 | ** the following conditions:
14 | **
15 | ** The above copyright notice and this permission notice shall be included
16 | ** in all copies or substantial portions of the Materials.
17 | **
18 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
25 | */
26 |
27 | /* Platform-specific types and definitions for egl.h
28 | * $Revision: 30994 $ on $Date: 2015-04-30 13:36:48 -0700 (Thu, 30 Apr 2015) $
29 | *
30 | * Adopters may modify khrplatform.h and this file to suit their platform.
31 | * You are encouraged to submit all modifications to the Khronos group so that
32 | * they can be included in future versions of this file. Please submit changes
33 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
34 | * by filing a bug against product "EGL" component "Registry".
35 | */
36 |
37 | #include
38 |
39 | /* Macros used in EGL function prototype declarations.
40 | *
41 | * EGL functions should be prototyped as:
42 | *
43 | * EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
44 | * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
45 | *
46 | * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
47 | */
48 |
49 | #ifndef EGLAPI
50 | #define EGLAPI KHRONOS_APICALL
51 | #endif
52 |
53 | #ifndef EGLAPIENTRY
54 | #define EGLAPIENTRY KHRONOS_APIENTRY
55 | #endif
56 | #define EGLAPIENTRYP EGLAPIENTRY*
57 |
58 | /* The types NativeDisplayType, NativeWindowType, and NativePixmapType
59 | * are aliases of window-system-dependent types, such as X Display * or
60 | * Windows Device Context. They must be defined in platform-specific
61 | * code below. The EGL-prefixed versions of Native*Type are the same
62 | * types, renamed in EGL 1.3 so all types in the API start with "EGL".
63 | *
64 | * Khronos STRONGLY RECOMMENDS that you use the default definitions
65 | * provided below, since these changes affect both binary and source
66 | * portability of applications using EGL running on different EGL
67 | * implementations.
68 | */
69 |
70 | #if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
71 | #ifndef WIN32_LEAN_AND_MEAN
72 | #define WIN32_LEAN_AND_MEAN 1
73 | #endif
74 | #include
75 |
76 | typedef HDC EGLNativeDisplayType;
77 | typedef HBITMAP EGLNativePixmapType;
78 | typedef HWND EGLNativeWindowType;
79 |
80 | #elif defined(__EMSCRIPTEN__)
81 |
82 | typedef int EGLNativeDisplayType;
83 | typedef int EGLNativePixmapType;
84 | typedef int EGLNativeWindowType;
85 |
86 | #elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
87 |
88 | typedef int EGLNativeDisplayType;
89 | typedef void *EGLNativePixmapType;
90 | typedef void *EGLNativeWindowType;
91 |
92 | #elif defined(WL_EGL_PLATFORM)
93 |
94 | typedef struct wl_display *EGLNativeDisplayType;
95 | typedef struct wl_egl_pixmap *EGLNativePixmapType;
96 | typedef struct wl_egl_window *EGLNativeWindowType;
97 |
98 | #elif defined(__GBM__)
99 |
100 | typedef struct gbm_device *EGLNativeDisplayType;
101 | typedef struct gbm_bo *EGLNativePixmapType;
102 | typedef void *EGLNativeWindowType;
103 |
104 | #elif defined(__ANDROID__) || defined(ANDROID)
105 |
106 | struct ANativeWindow;
107 | struct egl_native_pixmap_t;
108 |
109 | typedef void* EGLNativeDisplayType;
110 | typedef struct egl_native_pixmap_t* EGLNativePixmapType;
111 | typedef struct ANativeWindow* EGLNativeWindowType;
112 |
113 | #elif defined(USE_OZONE)
114 |
115 | typedef intptr_t EGLNativeDisplayType;
116 | typedef intptr_t EGLNativePixmapType;
117 | typedef intptr_t EGLNativeWindowType;
118 |
119 | #elif defined(__unix__) && defined(EGL_NO_X11)
120 |
121 | typedef void *EGLNativeDisplayType;
122 | typedef khronos_uintptr_t EGLNativePixmapType;
123 | typedef khronos_uintptr_t EGLNativeWindowType;
124 |
125 | #elif defined(__unix__) || defined(USE_X11)
126 |
127 | /* X11 (tentative) */
128 | #include
129 | #include
130 |
131 | typedef Display *EGLNativeDisplayType;
132 | typedef Pixmap EGLNativePixmapType;
133 | typedef Window EGLNativeWindowType;
134 |
135 | #elif defined(__APPLE__)
136 |
137 | typedef int EGLNativeDisplayType;
138 | typedef void *EGLNativePixmapType;
139 | typedef void *EGLNativeWindowType;
140 |
141 | #elif defined(__HAIKU__)
142 |
143 | #include
144 |
145 | typedef void *EGLNativeDisplayType;
146 | typedef khronos_uintptr_t EGLNativePixmapType;
147 | typedef khronos_uintptr_t EGLNativeWindowType;
148 |
149 | #else
150 | #error "Platform not recognized"
151 | #endif
152 |
153 | /* EGL 1.2 types, renamed for consistency in EGL 1.3 */
154 | typedef EGLNativeDisplayType NativeDisplayType;
155 | typedef EGLNativePixmapType NativePixmapType;
156 | typedef EGLNativeWindowType NativeWindowType;
157 |
158 |
159 | /* Define EGLint. This must be a signed integral type large enough to contain
160 | * all legal attribute names and values passed into and out of EGL, whether
161 | * their type is boolean, bitmask, enumerant (symbolic constant), integer,
162 | * handle, or other. While in general a 32-bit integer will suffice, if
163 | * handles are 64 bit types, then EGLint should be defined as a signed 64-bit
164 | * integer type.
165 | */
166 | typedef khronos_int32_t EGLint;
167 |
168 |
169 | /* C++ / C typecast macros for special EGL handle values */
170 | #if defined(__cplusplus)
171 | #define EGL_CAST(type, value) (static_cast(value))
172 | #else
173 | #define EGL_CAST(type, value) ((type) (value))
174 | #endif
175 |
176 | #endif /* __eglplatform_h */
177 |
--------------------------------------------------------------------------------
/gl_client/include/GLES2/gl2platform.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, Broadcom Europe Ltd
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above copyright
10 | notice, this list of conditions and the following disclaimer in the
11 | documentation and/or other materials provided with the distribution.
12 | * Neither the name of the copyright holder nor the
13 | names of its contributors may be used to endorse or promote products
14 | derived from this software without specific prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef __gl2platform_h_
28 | #define __gl2platform_h_
29 |
30 | /* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | /*
37 | * This document is licensed under the SGI Free Software B License Version
38 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
39 | */
40 |
41 | /* Platform-specific types and definitions for OpenGL ES 2.X gl2.h
42 | *
43 | * Adopters may modify khrplatform.h and this file to suit their platform.
44 | * You are encouraged to submit all modifications to the Khronos group so that
45 | * they can be included in future versions of this file. Please submit changes
46 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
47 | * by filing a bug against product "OpenGL-ES" component "Registry".
48 | */
49 |
50 | #include "../KHR/khrplatform.h"
51 |
52 | #ifndef GL_APICALL
53 | #define GL_APICALL KHRONOS_APICALL
54 | #endif
55 |
56 | #ifndef GL_APIENTRY
57 | #define GL_APIENTRY KHRONOS_APIENTRY
58 | #endif
59 |
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 |
64 | #endif /* __gl2platform_h_ */
65 |
--------------------------------------------------------------------------------
/gl_client/include/KHR/khrplatform.h:
--------------------------------------------------------------------------------
1 | #ifndef __khrplatform_h_
2 | #define __khrplatform_h_
3 |
4 | /*
5 | ** Copyright (c) 2008-2009 The Khronos Group Inc.
6 | **
7 | ** Permission is hereby granted, free of charge, to any person obtaining a
8 | ** copy of this software and/or associated documentation files (the
9 | ** "Materials"), to deal in the Materials without restriction, including
10 | ** without limitation the rights to use, copy, modify, merge, publish,
11 | ** distribute, sublicense, and/or sell copies of the Materials, and to
12 | ** permit persons to whom the Materials are furnished to do so, subject to
13 | ** the following conditions:
14 | **
15 | ** The above copyright notice and this permission notice shall be included
16 | ** in all copies or substantial portions of the Materials.
17 | **
18 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
25 | */
26 |
27 | /* Platform-specific types and definitions.
28 | * $Revision: 7244 $ on $Date: 2009-01-20 17:06:59 -0800 (Tue, 20 Jan 2009) $
29 | *
30 | * Adopters may modify this file to suit their platform. Adopters are
31 | * encouraged to submit platform specific modifications to the Khronos
32 | * group so that they can be included in future versions of this file.
33 | * Please submit changes by sending them to the public Khronos Bugzilla
34 | * (http://khronos.org/bugzilla) by filing a bug against product
35 | * "Khronos (general)" component "Registry".
36 | *
37 | * A predefined template which fills in some of the bug fields can be
38 | * reached using http://tinyurl.com/khrplatform-h-bugreport, but you
39 | * must create a Bugzilla login first.
40 | *
41 | *
42 | * See the Implementer's Guidelines for information about where this file
43 | * should be located on your system.
44 | * http://www.khronos.org/registry/implementers_guide.pdf
45 | *
46 | *
47 | * This file should be included as
48 | * #include
49 | * by the Khronos API header file that uses its types and defines.
50 | *
51 | * The types in this file should only be used to define API-specific types.
52 | * Types defined in this file:
53 | * khronos_int8_t signed 8 bit
54 | * khronos_uint8_t unsigned 8 bit
55 | * khronos_int16_t signed 16 bit
56 | * khronos_uint16_t unsigned 16 bit
57 | * khronos_int32_t signed 32 bit
58 | * khronos_uint32_t unsigned 32 bit
59 | * khronos_int64_t signed 64 bit
60 | * khronos_uint64_t unsigned 64 bit
61 | * khronos_intptr_t signed same number of bits as a pointer
62 | * khronos_uintptr_t unsigned same number of bits as a pointer
63 | * khronos_ssize_t signed size
64 | * khronos_usize_t unsigned size
65 | * khronos_float_t signed 32 bit floating point
66 | * khronos_time_ns_t unsigned 64 bit time in nanoseconds
67 | * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
68 | * nanoseconds
69 | * khronos_stime_nanoseconds_t signed time interval in nanoseconds
70 | *
71 | * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
72 | * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
73 | *
74 | *
75 | * Macros defined in this file:
76 | * KHRONOS_APICALL
77 | * KHRONOS_APIENTRY
78 | * KHRONOS_APIATTRIBUTES
79 | * These may be used in function prototypes as:
80 | * KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
81 | * int arg1,
82 | * int arg2) KHRONOS_APIATTRIBUTES;
83 | */
84 |
85 | #if 0
86 | #include "interface/khronos/common/khrn_client_mangle.h"
87 | #endif
88 |
89 | /*-------------------------------------------------------------------------
90 | * Definition of KHRONOS_APICALL
91 | *-------------------------------------------------------------------------
92 | * This precedes the return type of the function in the function prototype.
93 | */
94 | #ifndef KHAPI
95 | #define KHAPI extern
96 | #endif
97 | #define KHRONOS_APICALL KHAPI
98 |
99 | /*-------------------------------------------------------------------------
100 | * Definition of KHRONOS_APIENTRY
101 | *-------------------------------------------------------------------------
102 | * This follows the return type of the function and precedes the function
103 | * name in the function prototype.
104 | */
105 | #ifndef KHRONOS_APIENTRY
106 | #define KHRONOS_APIENTRY
107 | #endif
108 |
109 | /*-------------------------------------------------------------------------
110 | * Definition of KHRONOS_APIATTRIBUTES
111 | *-------------------------------------------------------------------------
112 | * This follows the closing parenthesis of the function prototype arguments.
113 | */
114 | #if defined (__ARMCC_2__)
115 | #define KHRONOS_APIATTRIBUTES __softfp
116 | #else
117 | #define KHRONOS_APIATTRIBUTES
118 | #endif
119 |
120 | /*-------------------------------------------------------------------------
121 | * basic type definitions
122 | *-----------------------------------------------------------------------*/
123 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
124 |
125 |
126 | /*
127 | * Using
128 | */
129 | #include
130 | typedef int32_t khronos_int32_t;
131 | typedef uint32_t khronos_uint32_t;
132 | typedef int64_t khronos_int64_t;
133 | typedef uint64_t khronos_uint64_t;
134 | #define KHRONOS_SUPPORT_INT64 1
135 | #define KHRONOS_SUPPORT_FLOAT 1
136 |
137 | #elif defined(__VMS ) || defined(__sgi)
138 |
139 | /*
140 | * Using
141 | */
142 | #include
143 | typedef int32_t khronos_int32_t;
144 | typedef uint32_t khronos_uint32_t;
145 | typedef int64_t khronos_int64_t;
146 | typedef uint64_t khronos_uint64_t;
147 | #define KHRONOS_SUPPORT_INT64 1
148 | #define KHRONOS_SUPPORT_FLOAT 1
149 |
150 | #elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
151 |
152 | /*
153 | * Win32
154 | */
155 | typedef __int32 khronos_int32_t;
156 | typedef unsigned __int32 khronos_uint32_t;
157 | typedef __int64 khronos_int64_t;
158 | typedef unsigned __int64 khronos_uint64_t;
159 | #define KHRONOS_SUPPORT_INT64 1
160 | #define KHRONOS_SUPPORT_FLOAT 1
161 |
162 | #elif defined(__sun__) || defined(__digital__)
163 |
164 | /*
165 | * Sun or Digital
166 | */
167 | typedef int khronos_int32_t;
168 | typedef unsigned int khronos_uint32_t;
169 | #if defined(__arch64__) || defined(_LP64)
170 | typedef long int khronos_int64_t;
171 | typedef unsigned long int khronos_uint64_t;
172 | #else
173 | typedef long long int khronos_int64_t;
174 | typedef unsigned long long int khronos_uint64_t;
175 | #endif /* __arch64__ */
176 | #define KHRONOS_SUPPORT_INT64 1
177 | #define KHRONOS_SUPPORT_FLOAT 1
178 |
179 | #elif defined(_VIDEOCORE)
180 |
181 | /*
182 | * VideoCore with Metaware compiler
183 | */
184 | #include
185 | typedef int32_t khronos_int32_t;
186 | typedef uint32_t khronos_uint32_t;
187 | typedef int64_t khronos_int64_t;
188 | typedef uint64_t khronos_uint64_t;
189 | #define KHRONOS_SUPPORT_INT64 1
190 | #define KHRONOS_SUPPORT_FLOAT 1
191 |
192 | #elif 0
193 |
194 | /*
195 | * Hypothetical platform with no float or int64 support
196 | */
197 | typedef int khronos_int32_t;
198 | typedef unsigned int khronos_uint32_t;
199 | #define KHRONOS_SUPPORT_INT64 0
200 | #define KHRONOS_SUPPORT_FLOAT 0
201 |
202 | #else
203 |
204 | /*
205 | * Generic fallback
206 | */
207 | #include
208 | typedef int32_t khronos_int32_t;
209 | typedef uint32_t khronos_uint32_t;
210 | typedef int64_t khronos_int64_t;
211 | typedef uint64_t khronos_uint64_t;
212 | #define KHRONOS_SUPPORT_INT64 1
213 | #define KHRONOS_SUPPORT_FLOAT 1
214 |
215 | #endif
216 |
217 |
218 | /*
219 | * Types that are (so far) the same on all platforms
220 | */
221 | typedef signed char khronos_int8_t;
222 | typedef unsigned char khronos_uint8_t;
223 | typedef signed short int khronos_int16_t;
224 | typedef unsigned short int khronos_uint16_t;
225 | typedef signed long int khronos_intptr_t;
226 | typedef unsigned long int khronos_uintptr_t;
227 | typedef signed long int khronos_ssize_t;
228 | typedef unsigned long int khronos_usize_t;
229 |
230 | #if KHRONOS_SUPPORT_FLOAT
231 | /*
232 | * Float type
233 | */
234 | typedef float khronos_float_t;
235 | #endif
236 |
237 | #if KHRONOS_SUPPORT_INT64
238 | /* Time types
239 | *
240 | * These types can be used to represent a time interval in nanoseconds or
241 | * an absolute Unadjusted System Time. Unadjusted System Time is the number
242 | * of nanoseconds since some arbitrary system event (e.g. since the last
243 | * time the system booted). The Unadjusted System Time is an unsigned
244 | * 64 bit value that wraps back to 0 every 584 years. Time intervals
245 | * may be either signed or unsigned.
246 | */
247 | typedef khronos_uint64_t khronos_utime_nanoseconds_t;
248 | typedef khronos_int64_t khronos_stime_nanoseconds_t;
249 | #endif
250 |
251 |
252 | #endif /* __khrplatform_h_ */
253 |
--------------------------------------------------------------------------------
/gl_client/samples/Makefile:
--------------------------------------------------------------------------------
1 | CFLAGS=-O3 -Wall -g
2 |
3 | INCLUDES=-I.. -I../include -I../../common
4 | LIBS=-lpthread -lm -ldl -lGLESv2 -lEGL
5 | OBJS=glsutil.o
6 | EXES=sample1 sample2
7 |
8 | all: $(EXES)
9 |
10 | glsutil.o: glsutil.c glsutil.h
11 | gcc -c -o glsutil.o $(CFLAGS) $(INCLUDES) glsutil.c
12 |
13 | sample1: sample1.c glsutil.o
14 | # ../glclient.o ../clientegl.o ../clientgles.o
15 | gcc -o sample1 $(CFLAGS) $(INCLUDES) sample1.c $(OBJS) $(LIBS)
16 |
17 | sample2: sample2.c glsutil.o
18 | # ../glclient.o ../clientegl.o ../clientgles.o
19 | gcc -o sample2 $(CFLAGS) $(INCLUDES) sample2.c $(OBJS) $(LIBS)
20 |
21 |
--------------------------------------------------------------------------------
/gl_client/samples/glsutil.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 | #include
34 | #include
35 | #include "glsutil.h"
36 |
37 |
38 | #define TRUE 1
39 | #define FALSE 0
40 |
41 |
42 | void mat_mul(float *a, float *b)
43 | {
44 | float c[16];
45 | c[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3];
46 | c[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3];
47 | c[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3];
48 | c[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3];
49 | c[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7];
50 | c[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7];
51 | c[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7];
52 | c[7] = a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7];
53 | c[8] = a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11];
54 | c[9] = a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11];
55 | c[10] = a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11];
56 | c[11] = a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11];
57 | c[12] = a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15];
58 | c[13] = a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15];
59 | c[14] = a[2] * b[12] + a[6] * b[13] + a[10] * b[14] + a[14] * b[15];
60 | c[15] = a[3] * b[12] + a[7] * b[13] + a[11] * b[14] + a[15] * b[15];
61 | /*
62 | for (int i = 0; i < 16; i++) {
63 | c[i] = i / 4 + 1;
64 | }
65 | */
66 | for (int i = 0; i < 16; i++) {
67 | a[i] = c[i];
68 | }
69 | }
70 |
71 |
72 | void mat_rotate_x(float *a, float angle)
73 | {
74 | float carr[8];
75 | float s = sin(angle);
76 | float c = cos(angle);
77 | /*
78 | carr[0] = a[4] * c + a[8] * s;
79 | carr[1] = a[5] * c + a[9] * s;
80 | carr[2] = a[6] * c + a[10] * s;
81 | carr[3] = a[7] * c + a[11] * s;
82 | carr[4] = a[8] * c - a[4] * s;
83 | carr[5] = a[9] * c - a[5] * s;
84 | carr[6] = a[10] * c - a[6] * s;
85 | carr[7] = a[11] * c - a[7] * s;
86 | */
87 | for (int i = 4; i < 12; i++) {
88 | carr[i - 4] = a[i] * c + (i < 8 ? (+a[i+4]) : (-a[i-4])) * s;
89 | }
90 |
91 | for (int i = 4; i < 12; i++) {
92 | a[i] = carr[i - 4];
93 | }
94 | }
95 |
96 |
97 | void mat_rotate_y(float *a, float angle)
98 | {
99 | float c0, c1, c2, c3, c8, c9, c10, c11;
100 | float s = sin(angle);
101 | float c = cos(angle);
102 | c0 = a[0] * c - a[8] * s;
103 | c1 = a[1] * c - a[9] * s;
104 | c2 = a[2] * c - a[10] * s;
105 | c3 = a[3] * c - a[11] * s;
106 | c8 = a[0] * s + a[8] * c;
107 | c9 = a[1] * s + a[9] * c;
108 | c10 = a[2] * s + a[10] * c;
109 | c11 = a[3] * s + a[11] * c;
110 | a[0] = c0; a[1] = c1; a[2] = c2; a[3] = c3;
111 | a[8] = c8; a[9] = c9; a[10] = c10; a[11] = c11;
112 | }
113 |
114 |
115 | void mat_rotate_z(float *a, float angle)
116 | {
117 | float c0, c1, c2, c3, c4, c5, c6, c7;
118 | float s = sin(angle);
119 | float c = cos(angle);
120 | c0 = a[0] * c + a[4] * s;
121 | c1 = a[1] * c + a[5] * s;
122 | c2 = a[2] * c + a[6] * s;
123 | c3 = a[3] * c + a[7] * s;
124 | c4 = a[4] * c - a[0] * s;
125 | c5 = a[5] * c - a[1] * s;
126 | c6 = a[6] * c - a[2] * s;
127 | c7 = a[7] * c - a[3] * s;
128 | a[0] = c0; a[1] = c1; a[2] = c2; a[3] = c3;
129 | a[4] = c4; a[5] = c5; a[6] = c6; a[7] = c7;
130 | }
131 |
132 |
133 | void mat_translate(float *a, float x, float y, float z)
134 | {
135 | float b12, b13, b14, b15;
136 | float barr[4];
137 | for (int i = 0; i < 4; i++) {
138 | barr[i] = a[i] * x + a[i + 4] * y + a[i + 8] * z + a[i + 12];
139 | }
140 | for (int i = 0; i < 4; i++) {
141 | a[i + 12] = barr[i];
142 | }
143 | /*
144 | b12 = a[0] * x + a[4] * y + a[8] * z + a[12];
145 | b13 = a[1] * x + a[5] * y + a[9] * z + a[13];
146 | b14 = a[2] * x + a[6] * y + a[10] * z + a[14];
147 | b15 = a[3] * x + a[7] * y + a[11] * z + a[15];
148 | a[12] = b12; a[13] = b13; a[14] = b14; a[15] = b15;
149 | */
150 | }
151 |
152 |
153 | void mat_identity(float *m)
154 | {
155 | for (int i = 0; i < 16; i++) {
156 | m[i] = i % 5 == 0 ? 1.0f : 0.0f;
157 | }
158 | /*
159 | m[0] = 1.0f; m[1] = 0.0f; m[2] = 0.0f; m[3] = 0.0f;
160 | m[4] = 0.0f; m[5] = 1.0f; m[6] = 0.0f; m[7] = 0.0f;
161 | m[8] = 0.0f; m[9] = 0.0f; m[10] = 1.0f; m[11] = 0.0f;
162 | m[12] = 0.0f; m[13] = 0.0f; m[14] = 0.0f; m[15] = 1.0f;
163 | */
164 | }
165 |
166 |
167 | void mat_transpose(float *m)
168 | {
169 | float a[16];
170 | a[1] = m[4]; a[2] = m[8]; a[3] = m[12];
171 | a[4] = m[1]; a[6] = m[9]; a[7] = m[13];
172 | a[8] = m[2]; a[9] = m[6]; a[11] = m[14];
173 | a[12] = m[3]; a[13] = m[7]; a[14] = m[11];
174 |
175 | m[1] = a[1]; m[2] = a[2]; m[3] = a[3];
176 | m[4] = a[4]; m[6] = a[6]; m[7] = a[7];
177 | m[8] = a[8]; m[9] = a[9]; m[11] = a[11];
178 | m[12] = a[12]; m[13] = a[13]; m[14] = a[14];
179 | }
180 |
181 |
182 | void mat_invert(float *m)
183 | {
184 | float a[16];
185 | mat_identity(a);
186 | for (int i = 12; i < 15; i++) {
187 | a[i] = -m[i];
188 | m[i] = 0.0f;
189 | }
190 | /*
191 | a[12] = -m[12]; a[13] = -m[13]; a[14] = -m[14];
192 | m[12] = 0.0f; m[13] = 0.0f; m[14] = 0.0f;
193 | */
194 | mat_transpose(m);
195 | mat_mul(m, a);
196 | }
197 |
198 |
199 | void mat_perspective(float *m, float aspect, float near, float far, float fview)
200 | {
201 | mat_identity(m);
202 | float t, dz;
203 | dz = far - near;
204 | t = 1.0f / tanf(M_PI * fview / 360.0f);
205 | aspect = (aspect == 0.0f) ? 0.0000001f : aspect;
206 | dz = (dz == 0.0f) ? 0.0000001f : dz;
207 | m[0] = t / aspect;
208 | m[5] = t;
209 | m[10] = - (far + near) / dz;
210 | m[11] = -1.0f;
211 | m[14] = -2.0f * near * far / dz;
212 | m[15] = 0.0f;
213 | }
214 |
215 |
216 | void mat_copy(float *a, float *b)
217 | {
218 | for (int i = 0; i < 16; i++) {
219 | a[i] = b[i];
220 | }
221 | }
222 |
223 |
224 | int gls_load_bitmap(gls_bitmap_t *bitmap, const char *filename)
225 | {
226 | gls_bmp_header_t header;
227 | FILE *file;
228 | bitmap->width = 0;
229 | bitmap->height = 0;
230 | bitmap->bitmap = NULL;
231 | file = fopen(filename, "rb");
232 | if (file == NULL)
233 | {
234 | perror("Error: gls_load_bitmap: file open error.\n");
235 | return FALSE;
236 | }
237 | if (fread(&header, 1, sizeof(header), file) != sizeof(header))
238 | {
239 | perror("Error: gls_load_bitmap: header read error.\n");
240 | fclose(file);
241 | return FALSE;
242 | }
243 | if (header.file_type != 0x4d42)
244 | {
245 | perror("Error: gls_load_bitmap: not a bmp file.\n");
246 | return FALSE;
247 | }
248 | if (header.bpp != 32)
249 | {
250 | perror("Error: gls_load_bitmap: only 32bit bmp supported.\n");
251 | return FALSE;
252 | }
253 | if (header.compression != 0)
254 | {
255 | perror("Error: gls_load_bitmap: no compression supported.\n");
256 | return FALSE;
257 | }
258 | bitmap->width = header.width;
259 | bitmap->height = header.height;
260 | size_t size = header.width * header.height * header.bpp / 8;
261 | char *tmpbuf = malloc(size);
262 | if (tmpbuf == NULL)
263 | {
264 | fclose(file);
265 | return FALSE;
266 | }
267 | bitmap->bitmap = malloc(size);
268 | if (bitmap->bitmap == NULL)
269 | {
270 | free(tmpbuf);
271 | fclose(file);
272 | return FALSE;
273 | }
274 | fseek(file, header.data_offset, SEEK_SET);
275 | size_t size1 = fread(tmpbuf, 1, size, file);
276 | if (size1 != size)
277 | {
278 | perror("Error: gls_load_bitmap: bitmap read error\n");
279 | free(bitmap->bitmap);
280 | bitmap->bitmap = NULL;
281 | free(tmpbuf);
282 | fclose(file);
283 | return FALSE;
284 | }
285 | unsigned int x, y;
286 | for (y = 0; y < header.height; y++)
287 | {
288 | for (x = 0; x < header.width; x++)
289 | {
290 | unsigned int offset = (y * header.width + x) * (header.bpp / 8);
291 | uint32_t argb = *(uint32_t *)(tmpbuf + offset);
292 | uint32_t a = argb >> 24;
293 | uint32_t r = (argb >> 16) & 0xff;
294 | uint32_t g = (argb >> 8) & 0xff;
295 | uint32_t b = argb & 0xff;
296 | uint32_t rgba = (a << 24) | (b << 16) | (g << 8) | r;
297 | *(uint32_t *)(bitmap->bitmap + offset) = rgba;
298 | }
299 | }
300 | free(tmpbuf);
301 | fclose(file);
302 | return TRUE;
303 | }
304 |
305 |
306 | void gls_delete_bitmap(gls_bitmap_t *bitmap)
307 | {
308 | free(bitmap->bitmap);
309 | bitmap->width = 0;
310 | bitmap->height = 0;
311 | bitmap->bitmap = NULL;
312 | }
313 |
314 |
315 |
--------------------------------------------------------------------------------
/gl_client/samples/glsutil.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 |
34 |
35 | typedef struct
36 | {
37 | uint16_t file_type;
38 | uint32_t file_size;
39 | uint16_t reserved1;
40 | uint16_t reserved2;
41 | uint32_t data_offset;
42 | uint32_t header_size;
43 | uint32_t width;
44 | uint32_t height;
45 | uint16_t plane;
46 | uint16_t bpp;
47 | uint32_t compression;
48 | uint32_t image_size;
49 | } __attribute__ ((__packed__)) gls_bmp_header_t;
50 |
51 |
52 | typedef struct
53 | {
54 | unsigned int width;
55 | unsigned int height;
56 | char *bitmap;
57 | } gls_bitmap_t;
58 |
59 |
60 | #ifdef __cplusplus
61 | extern "C" {
62 | #endif
63 |
64 | void mat_mul(float *a, float *b);
65 | void mat_rotate_x(float *a, float angle);
66 | void mat_rotate_y(float *a, float angle);
67 | void mat_rotate_z(float *a, float angle);
68 | void mat_translate(float *a, float x, float y, float z);
69 | void mat_identity(float *m);
70 | void mat_transpose(float *m);
71 | void mat_invert(float *m);
72 | void mat_perspective(float *m, float aspect, float near, float far, float fview);
73 | void mat_copy(float *a, float *b);
74 | int gls_load_bitmap(gls_bitmap_t *bitmap, const char *filename);
75 | void gls_delete_bitmap(gls_bitmap_t *bitmap);
76 |
77 | #ifdef __cplusplus
78 | }
79 | #endif
80 |
81 |
--------------------------------------------------------------------------------
/gl_client/samples/sample1.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 |
42 | #include "glclient.h"
43 | #include "GLES2/gl2.h"
44 | #include "glsutil.h"
45 |
46 | #define g_vsize_pos 3
47 | #define g_stride_pos (g_vsize_pos * sizeof(GLfloat))
48 | #define g_vsize_nor 3
49 | #define g_stride_nor (g_vsize_nor * sizeof(GLfloat))
50 |
51 |
52 | typedef struct
53 | {
54 | union
55 | {
56 | struct
57 | {
58 | uint8_t r;
59 | uint8_t g;
60 | uint8_t b;
61 | uint8_t a;
62 | };
63 | uint32_t rgba;
64 | };
65 | } color_t;
66 |
67 |
68 | typedef struct
69 | {
70 | float modelproj_mat[16];
71 | float nor_mat[16];
72 | uint32_t type;
73 | color_t color;
74 | float x;
75 | float y;
76 | float z;
77 | float dx;
78 | float dy;
79 | float dz;
80 | float rx;
81 | float ry;
82 | float rz;
83 | float drx;
84 | float dry;
85 | float drz;
86 | } obj_3d_t;
87 |
88 |
89 | static GLfloat light_pos[4] = {5.0, 5.0, 10.0, 1.0};
90 | static obj_3d_t obj[1024];
91 | static GLfloat proj_mat[16];
92 | static float model_mat[16];
93 | static float modelproj_mat[16];
94 | static float nor_mat[16];
95 | static float col[4];
96 |
97 |
98 | static GLfloat vtx_cube[] =
99 | {
100 | 1.000000,1.000000,-1.000000,
101 | 1.000000,-1.000000,-1.000000,
102 | -1.000000,-1.000000,-1.000000,
103 | 1.000000,0.999999,1.000000,
104 | -1.000000,1.000000,1.000000,
105 | 0.999999,-1.000001,1.000000,
106 | 1.000000,1.000000,-1.000000,
107 | 1.000000,0.999999,1.000000,
108 | 1.000000,-1.000000,-1.000000,
109 | 1.000000,-1.000000,-1.000000,
110 | 0.999999,-1.000001,1.000000,
111 | -1.000000,-1.000000,-1.000000,
112 | -1.000000,-1.000000,-1.000000,
113 | -1.000000,-1.000000,1.000000,
114 | -1.000000,1.000000,1.000000,
115 | 1.000000,0.999999,1.000000,
116 | 1.000000,1.000000,-1.000000,
117 | -1.000000,1.000000,1.000000,
118 | -1.000000,1.000000,-1.000000,
119 | -1.000000,-1.000000,1.000000,
120 | 1.000000,0.999999,1.000000,
121 | 0.999999,-1.000001,1.000000,
122 | 1.000000,-1.000000,-1.000000,
123 | -1.000000,-1.000000,1.000000,
124 | -1.000000,1.000000,-1.000000,
125 | -1.000000,1.000000,-1.000000,
126 | };
127 |
128 |
129 | static GLfloat nor_cube[] =
130 | {
131 | 0.000000,0.000000,-1.000000,
132 | 0.000000,0.000000,-1.000000,
133 | 0.000000,0.000000,-1.000000,
134 | -0.000000,-0.000000,1.000000,
135 | -0.000000,-0.000000,1.000000,
136 | -0.000000,-0.000000,1.000000,
137 | 1.000000,0.000000,-0.000000,
138 | 1.000000,0.000000,-0.000000,
139 | 1.000000,0.000000,-0.000000,
140 | -0.000000,-1.000000,-0.000000,
141 | -0.000000,-1.000000,-0.000000,
142 | -0.000000,-1.000000,-0.000000,
143 | -1.000000,0.000000,-0.000000,
144 | -1.000000,0.000000,-0.000000,
145 | -1.000000,0.000000,-0.000000,
146 | 0.000000,1.000000,0.000000,
147 | 0.000000,1.000000,0.000000,
148 | 0.000000,1.000000,0.000000,
149 | 0.000000,0.000000,-1.000000,
150 | 0.000000,-0.000000,1.000000,
151 | 1.000000,-0.000001,0.000000,
152 | 1.000000,-0.000001,0.000000,
153 | 1.000000,-0.000001,0.000000,
154 | -0.000000,-1.000000,0.000000,
155 | -1.000000,0.000000,-0.000000,
156 | 0.000000,1.000000,0.000000,
157 | };
158 |
159 |
160 | static GLushort ind_cube[] =
161 | {
162 | 0,1,2,
163 | 3,4,5,
164 | 6,7,8,
165 | 9,10,11,
166 | 12,13,14,
167 | 15,16,17,
168 | 18,0,2,
169 | 4,19,5,
170 | 20,21,22,
171 | 10,23,11,
172 | 24,12,14,
173 | 16,25,17,
174 | };
175 |
176 |
177 | static const GLchar *VShader1 =
178 | "attribute vec3 pos;\n"
179 | "attribute vec3 nor;\n"
180 | "uniform mat4 model_mat;\n"
181 | "uniform mat4 nor_mat;\n"
182 | "uniform vec4 light_pos;\n"
183 | "uniform vec4 col;\n"
184 | "varying vec4 fcol;\n"
185 | "void main(void)\n"
186 | "{\n"
187 | " vec3 eyenor = normalize(vec3(nor_mat * vec4(nor, 1.0)));\n"
188 | " vec3 lnor = normalize(light_pos.xyz);\n"
189 | " float diffuse = max(dot(eyenor, lnor), 0.0);\n"
190 | " fcol = vec4(vec3(diffuse * col), 1.0) ;\n"
191 | " gl_Position = model_mat * vec4(pos, 1.0);\n"
192 | "}\n";
193 |
194 |
195 | static const GLchar *FShader1 =
196 | "precision mediump float;\n"
197 | "varying vec4 fcol;\n"
198 | "void main(void)\n"
199 | "{\n"
200 | " gl_FragColor = fcol;\n"
201 | "}\n";
202 |
203 |
204 | typedef struct
205 | {
206 | uint32_t screen_width;
207 | uint32_t screen_height;
208 | GLuint vshader;
209 | GLuint fshader;
210 | GLuint program;
211 | GLuint vbo_pos;
212 | GLuint vbo_nor;
213 | GLuint vbo_ind;
214 | GLint vloc_pos;
215 | GLint vloc_nor;
216 | GLuint uloc_model;
217 | GLuint uloc_nor;
218 | GLuint uloc_light;
219 | GLuint uloc_col;
220 | GLfloat* vtx_pos;
221 | GLfloat* vtx_nor;
222 | } graphics_context_t;
223 |
224 |
225 | typedef struct
226 | {
227 | char joy_dev[GLS_STRING_SIZE_PLUS];
228 | } glclient_context_t;
229 |
230 |
231 | static inline float randf(void)
232 | {
233 | return (float)rand() / (float)RAND_MAX;
234 | }
235 |
236 | /*
237 | float get_diff_time(struct timeval start, struct timeval end)
238 | {
239 | float dt = (float)(end.tv_sec - start.tv_sec) + (float)(end.tv_usec - start.tv_usec) * 0.000001f;
240 | return dt;
241 | }
242 | */
243 |
244 | GLuint create_vbo(GLenum target, void *vtx, size_t size)
245 | {
246 | static GLuint vbo;
247 | glGenBuffers(1, &vbo);
248 | glBindBuffer(target, vbo);
249 | glBufferData(target, size, vtx, GL_STATIC_DRAW);
250 | glBindBuffer(target, 0);
251 | return vbo;
252 | }
253 |
254 |
255 | void release_vbo(GLenum target, GLuint vbo)
256 | {
257 | glBindBuffer(target, 0);
258 | glDeleteBuffers(1, &vbo);
259 | }
260 |
261 |
262 | void init_shader(graphics_context_t *gc, const GLchar *vs, const GLchar *fs)
263 | {
264 | gc->vshader = glCreateShader(GL_VERTEX_SHADER);
265 | glShaderSource(gc->vshader, 1, &vs, 0);
266 | glCompileShader(gc->vshader);
267 | gc->fshader = glCreateShader(GL_FRAGMENT_SHADER);
268 | glShaderSource(gc->fshader, 1, &fs, 0);
269 | glCompileShader(gc->fshader);
270 |
271 | gc->program = glCreateProgram();
272 | glAttachShader(gc->program, gc->vshader);
273 | glAttachShader(gc->program, gc->fshader);
274 | glLinkProgram(gc->program);
275 | }
276 |
277 |
278 | void release_shader(graphics_context_t *gc)
279 | {
280 | glDeleteProgram(gc->program);
281 | glDeleteShader(gc->vshader);
282 | glDeleteShader(gc->fshader);
283 | }
284 |
285 |
286 | void init_gl(graphics_context_t *gc)
287 | {
288 | init_shader(gc, VShader1, FShader1);
289 | gc->vbo_pos = create_vbo(GL_ARRAY_BUFFER, vtx_cube, sizeof(vtx_cube));
290 | gc->vbo_nor = create_vbo(GL_ARRAY_BUFFER, nor_cube, sizeof(nor_cube));
291 | gc->vbo_ind = create_vbo(GL_ELEMENT_ARRAY_BUFFER, ind_cube, sizeof(ind_cube));
292 | gc->vloc_pos = glGetAttribLocation(gc->program, "pos");
293 | gc->vloc_nor = glGetAttribLocation(gc->program, "nor");
294 | gc->uloc_model = glGetUniformLocation(gc->program, "model_mat");
295 | gc->uloc_nor = glGetUniformLocation(gc->program, "nor_mat");
296 | gc->uloc_light = glGetUniformLocation(gc->program, "light_pos");
297 | gc->uloc_col = glGetUniformLocation(gc->program, "col");
298 |
299 | glBindBuffer(GL_ARRAY_BUFFER, gc->vbo_pos);
300 | glVertexAttribPointer(gc->vloc_pos, g_vsize_pos, GL_FLOAT, GL_FALSE, g_stride_pos, (GLfloat *)0);
301 | glBindBuffer(GL_ARRAY_BUFFER, 0);
302 |
303 | glBindBuffer(GL_ARRAY_BUFFER, gc->vbo_nor);
304 | glVertexAttribPointer(gc->vloc_nor, g_vsize_nor, GL_FLOAT, GL_FALSE, g_stride_nor, (GLfloat *)0);
305 | glBindBuffer(GL_ARRAY_BUFFER, 0);
306 |
307 | glBindFramebuffer(GL_FRAMEBUFFER,0);
308 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
309 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
310 | glViewport(0, 0, gc->screen_width, gc->screen_height);
311 | glUseProgram(gc->program);
312 |
313 | glDisable(GL_BLEND);
314 |
315 | glEnable(GL_CULL_FACE);
316 | glEnable(GL_DEPTH_TEST);
317 | }
318 |
319 |
320 | void release_gl(graphics_context_t *gc)
321 | {
322 | release_shader(gc);
323 | release_vbo(GL_ARRAY_BUFFER, gc->vbo_pos);
324 | release_vbo(GL_ARRAY_BUFFER, gc->vbo_nor);
325 | release_vbo(GL_ELEMENT_ARRAY_BUFFER, gc->vbo_ind);
326 | }
327 |
328 |
329 | void * glclient_thread( /*v oid * arg */)
330 | {
331 | // server_thread_args_t * a = (server_thread_args_t *)arg;
332 | static graphics_context_t gc;
333 |
334 | static struct js_event joy;
335 | int joy_fd;
336 | static char button[32];
337 |
338 | joy_fd = -1;
339 |
340 | /*
341 | glclient_context_t *glcc = a->user_context_ptr;
342 |
343 | joy_fd = open(glcc->joy_dev, O_RDONLY);
344 | if (joy_fd == -1)
345 | {
346 | printf("Error: Joystick device open\n");
347 | }
348 | if (joy_fd != -1)
349 | {
350 | fcntl(joy_fd, F_SETFL, O_NONBLOCK);
351 | }
352 | */
353 | EGLDisplay eglDpy = eglGetCurrentDisplay();
354 | EGLSurface eglSurf = eglGetCurrentSurface(EGL_DRAW);
355 |
356 | // gls_init(a);
357 |
358 | // gls_cmd_get_context();
359 | eglQuerySurface(eglDpy, eglSurf, EGL_WIDTH, &gc.screen_width);
360 | eglQuerySurface(eglDpy, eglSurf, EGL_HEIGHT, &gc.screen_height);
361 | printf("width:%d height:%d\n",glsc_global.screen_width,glsc_global.screen_height);
362 | init_gl(&gc);
363 |
364 | float aspect = (float)gc.screen_width / (float)gc.screen_height;
365 |
366 | mat_perspective(proj_mat, aspect, 1.0f, 1024.0f, 60.0f);
367 | glUniform4fv(gc.uloc_light, 1, light_pos);
368 |
369 | int j;
370 | for (j = 0; j < 1024; j++)
371 | {
372 | obj[j].x = randf() * 60.0f - 30.0f;
373 | obj[j].y = randf() * 60.0f - 30.0f;
374 | obj[j].z = randf() * 300.0f - 300.0f;
375 | obj[j].dx = randf() * 0.0f - 0.00f;
376 | obj[j].dy = randf() * 0.0f - 0.00f;
377 | obj[j].dz = randf() * 1.3f - 0.3f;
378 | if (fabs(obj[j].dz) < 0.01f)
379 | {
380 | obj[j].dz = 0.01f;
381 | }
382 | obj[j].rx = randf() * 6.28;
383 | obj[j].ry = randf() * 6.28;
384 | obj[j].rz = randf() * 6.28;
385 | obj[j].drx = randf() * 0.1f - 0.05f;
386 | obj[j].dry = randf() * 0.1f - 0.05f;
387 | obj[j].drz = randf() * 0.1f - 0.05f;
388 | obj[j].color.r = (uint8_t)(randf() * 255.5f);
389 | obj[j].color.g = (uint8_t)(randf() * 255.5f);
390 | obj[j].color.b = (uint8_t)(randf() * 255.5f);
391 | obj[j].color.a = (uint8_t)255;
392 | }
393 |
394 | float x = 0.0f;
395 | float y = 0.0f;
396 | float rx = 0.0f;
397 | float ry = 0.0f;
398 |
399 | int i;
400 | for (i = 0; i < 432000; i++)
401 | {
402 | struct timeval times, timee;
403 | gettimeofday(×, NULL);
404 |
405 | if (joy_fd != -1)
406 | {
407 | while (read(joy_fd, &joy, sizeof(struct js_event)) == sizeof(struct js_event))
408 | {
409 | if ((joy.type & JS_EVENT_BUTTON) == JS_EVENT_BUTTON)
410 | {
411 | button[joy.number] = joy.value;
412 | }
413 | }
414 |
415 | if (button[4] > 0)
416 | {
417 | y += 0.01f;
418 | }
419 | if (button[6] > 0)
420 | {
421 | y += -0.01f;
422 | }
423 | if (button[5] > 0)
424 | {
425 | x += 0.01f * aspect;
426 | }
427 | if (button[7] > 0)
428 | {
429 | x += -0.01f * aspect;
430 | }
431 | if (button[12] > 0)
432 | {
433 | rx += -0.01f;
434 | }
435 | if (button[13] > 0)
436 | {
437 | ry += 0.01f;
438 | }
439 | if (button[14] > 0)
440 | {
441 | rx += 0.01f;
442 | }
443 | if (button[15] > 0)
444 | {
445 | ry += -0.01f;
446 | }
447 | }
448 |
449 | glUseProgram(gc.program);
450 | glBindBuffer(GL_ARRAY_BUFFER, gc.vbo_pos);
451 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gc.vbo_ind);
452 | glEnableVertexAttribArray(gc.vloc_pos);
453 | glEnableVertexAttribArray(gc.vloc_nor);
454 |
455 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
456 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
457 |
458 | for (j = 0; j < 240; j++)
459 | {
460 | obj[j].x += obj[j].dx;
461 | obj[j].y += obj[j].dy;
462 | obj[j].z += obj[j].dz + y;
463 | if (obj[j].z > 1.0f)
464 | {
465 | obj[j].x = randf() * 60.0f - 30.0f;
466 | obj[j].y = randf() * 60.0f - 30.0f;
467 | obj[j].z = -300.0f;
468 | }
469 | if (obj[j].z < -400.0f)
470 | {
471 | obj[j].x = randf() * 60.0f - 30.0f;
472 | obj[j].y = randf() * 60.0f - 30.0f;
473 | obj[j].z = 1.0f;
474 | }
475 | obj[j].rx += obj[j].drx;
476 | obj[j].ry += obj[j].dry;
477 | obj[j].rz += obj[j].drz;
478 |
479 | mat_identity(model_mat);
480 | mat_translate(model_mat, obj[j].x, obj[j].y, obj[j].z);
481 | mat_rotate_x(model_mat, obj[j].rx);
482 | mat_rotate_y(model_mat, obj[j].ry);
483 | mat_rotate_z(model_mat, obj[j].rz);
484 |
485 | mat_copy(nor_mat, model_mat);
486 | mat_invert(nor_mat);
487 | mat_transpose(nor_mat);
488 | glUniformMatrix4fv(gc.uloc_nor, 1, GL_FALSE, nor_mat);
489 | mat_copy(obj[j].nor_mat, nor_mat);
490 |
491 | mat_copy(modelproj_mat, proj_mat);
492 | mat_mul(modelproj_mat, model_mat);
493 | glUniformMatrix4fv(gc.uloc_model, 1, GL_FALSE, modelproj_mat);
494 | mat_copy(obj[j].modelproj_mat, modelproj_mat);
495 |
496 | col[0] = (float)obj[j].color.r * 0.00392156862745f;
497 | col[1] = (float)obj[j].color.g * 0.00392156862745f;
498 | col[2] = (float)obj[j].color.b * 0.00392156862745f;
499 | col[3] = (float)obj[j].color.a * 0.00392156862745f;
500 | glUniform4fv(gc.uloc_col, 1, col);
501 |
502 | glDrawElements(GL_TRIANGLES, sizeof(ind_cube) / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
503 | }
504 | glDisableVertexAttribArray(gc.vloc_nor);
505 | glDisableVertexAttribArray(gc.vloc_pos);
506 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
507 | glBindBuffer(GL_ARRAY_BUFFER, 0);
508 | eglSwapBuffers(eglDpy, eglSurf);
509 | gettimeofday(&timee, NULL);
510 | // printf("%d:%f ms ", i, get_diff_time(times, timee) * 1000.0f);
511 | }
512 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
513 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
514 | eglSwapBuffers(eglDpy, eglSurf);
515 | release_gl(&gc);
516 | // gls_free();
517 | if (joy_fd != -1)
518 | {
519 | close(joy_fd);
520 | }
521 | pthread_exit(NULL);
522 | }
523 |
524 |
525 | int main(int argc, char * argv[])
526 | {
527 | static glclient_context_t glcc;
528 | /*
529 | static server_context_t sc;
530 | int opt;
531 | char my_ip[GLS_STRING_SIZE_PLUS];
532 | char his_ip[GLS_STRING_SIZE_PLUS];
533 | uint16_t my_port = 18146;
534 | uint16_t his_port = 18145;
535 | strncpy(my_ip, "127.0.0.1", GLS_STRING_SIZE);
536 | strncpy(his_ip, "127.0.0.1", GLS_STRING_SIZE);
537 | */
538 | strncpy(glcc.joy_dev, "/dev/input/js0", GLS_STRING_SIZE);
539 | /*
540 | while ((opt = getopt(argc, argv, "s:c:j:h")) != -1)
541 | {
542 | switch (opt)
543 | {
544 | case 's':
545 | strncpy(his_ip, strtok(optarg, ":"), GLS_STRING_SIZE);
546 | his_port = atoi(strtok(NULL, ":"));
547 | break;
548 | case 'c':
549 | strncpy(my_ip, strtok(optarg, ":"), GLS_STRING_SIZE);
550 | my_port = atoi(strtok(NULL, ":"));
551 | break;
552 | case 'j':
553 | strncpy(glcc.joy_dev, optarg, GLS_STRING_SIZE);
554 | break;
555 | case 'h':
556 | default:
557 | printf("Usage: %s [-c my_ip_address:port] [-s server_ip_address:port] [-j joystick_device]\n", argv[0]);
558 | return 0;
559 | }
560 | }
561 | server_init(&sc);
562 | set_server_address_port(&sc, my_ip, my_port);
563 | set_client_address_port(&sc, his_ip, his_port);
564 | set_client_user_context(&sc, &glcc);
565 | */
566 | // server_run(&sc, glclient_thread);
567 | // server_run(NULL, glclient_thread);
568 |
569 | pthread_t threadID;
570 | int ret;
571 |
572 | ret = pthread_create(&threadID, NULL, glclient_thread, NULL);
573 |
574 | if (ret) {
575 | printf("pthread_create() error number=%d\n", ret);
576 | return -1;
577 | }
578 |
579 | pthread_exit(NULL);
580 |
581 | return 0;
582 | }
583 |
--------------------------------------------------------------------------------
/gl_client/samples/sample2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khanhduytran0/android-gl-streaming/b4895522e210f38a4b5ddc93f34ff05e4533e47a/gl_client/samples/sample2
--------------------------------------------------------------------------------
/gl_client/samples/sample2.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 |
42 | #include "glclient.h"
43 | #include "GLES2/gl2.h"
44 | #include "glsutil.h"
45 | #include "model1.h"
46 |
47 | #define g_vsize_pos 3
48 | #define g_stride_pos (g_vsize_pos * sizeof(GLfloat))
49 | #define g_vsize_nor 3
50 | #define g_stride_nor (g_vsize_nor * sizeof(GLfloat))
51 | #define g_vsize_tex 2
52 | #define g_stride_tex (g_vsize_tex * sizeof(GLfloat))
53 | #define TRUE 1
54 | #define FALSE 0
55 |
56 |
57 | typedef struct
58 | {
59 | float modelproj_mat[16];
60 | float nor_mat[16];
61 | uint32_t type;
62 | float x;
63 | float y;
64 | float z;
65 | float dx;
66 | float dy;
67 | float dz;
68 | float rx;
69 | float ry;
70 | float rz;
71 | float drx;
72 | float dry;
73 | float drz;
74 | } obj_3d_t;
75 |
76 |
77 | static GLfloat light_pos[4] = {5.0, 5.0, 10.0, 1.0};
78 | static obj_3d_t obj[1024];
79 | static GLfloat proj_mat[16];
80 | static float model_mat[16];
81 | static float modelproj_mat[16];
82 | static float nor_mat[16];
83 |
84 |
85 | static const GLchar *VShader1 =
86 | "attribute vec3 pos;\n"
87 | "attribute vec3 nor;\n"
88 | "attribute vec2 tex;\n"
89 | "uniform mat4 model_mat;\n"
90 | "uniform mat4 nor_mat;\n"
91 | "uniform vec4 light_pos;\n"
92 | "varying vec2 ftex;\n"
93 | "varying float fdif;\n"
94 | "void main(void)\n"
95 | "{\n"
96 | " ftex = tex;\n"
97 | " vec3 eyenor = normalize(vec3(nor_mat * vec4(nor, 1.0)));\n"
98 | " vec3 lnor = normalize(light_pos.xyz);\n"
99 | " fdif = 2.0 * max(dot(eyenor, lnor), 0.0);\n"
100 | " gl_Position = model_mat * vec4(pos, 1.0);\n"
101 | "}\n";
102 |
103 |
104 | static const GLchar *FShader1 =
105 | "precision mediump float;\n"
106 | "varying vec2 ftex;\n"
107 | "varying float fdif;\n"
108 | "uniform sampler2D img;\n"
109 | "void main(void)\n"
110 | "{\n"
111 | " vec4 col = texture2D(img, ftex);\n"
112 | " gl_FragColor = vec4(fdif * vec3(col), col.a);\n"
113 | "}\n";
114 |
115 |
116 | typedef struct
117 | {
118 | uint32_t screen_width;
119 | uint32_t screen_height;
120 | GLuint vshader;
121 | GLuint fshader;
122 | GLuint program;
123 | GLuint vbo_pos;
124 | GLuint vbo_nor;
125 | GLuint vbo_ind;
126 | GLuint vbo_tex;
127 | GLint vloc_pos;
128 | GLint vloc_nor;
129 | GLint vloc_tex;
130 | GLuint uloc_model;
131 | GLuint uloc_nor;
132 | GLuint uloc_light;
133 | GLuint texture;
134 | } graphics_context_t;
135 |
136 |
137 | typedef struct
138 | {
139 | char joy_dev[GLS_STRING_SIZE_PLUS];
140 | } glclient_context_t;
141 |
142 |
143 | static inline float randf(void)
144 | {
145 | return (float)rand() / (float)RAND_MAX;
146 | }
147 |
148 | /*
149 | static inline float get_diff_time(struct timeval start, struct timeval end)
150 | {
151 | float dt = (float)(end.tv_sec - start.tv_sec) + (float)(end.tv_usec - start.tv_usec) * 0.000001f;
152 | return dt;
153 | }
154 | */
155 |
156 | GLuint create_texture(const char *filename)
157 | {
158 | gls_bitmap_t bitmap1;
159 | if (gls_load_bitmap(&bitmap1, filename) == FALSE)
160 | {
161 | perror("error load bitmap\n");
162 | }
163 | GLuint texture;
164 | glGenTextures(1, &texture);
165 | glBindTexture(GL_TEXTURE_2D, texture);
166 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
167 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
168 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
169 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
170 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bitmap1.width, bitmap1.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap1.bitmap);
171 | gls_delete_bitmap(&bitmap1);
172 | return TRUE;
173 | }
174 |
175 |
176 | void release_texture(GLuint texture)
177 | {
178 | glBindTexture(GL_TEXTURE_2D, 0);
179 | glDeleteTextures(1, &texture);
180 | }
181 |
182 |
183 | GLuint create_vbo(GLenum target, void *vtx, size_t size)
184 | {
185 | static GLuint vbo;
186 | glGenBuffers(1, &vbo);
187 | glBindBuffer(target, vbo);
188 | glBufferData(target, size, vtx, GL_STATIC_DRAW);
189 | glBindBuffer(target, 0);
190 | return vbo;
191 | }
192 |
193 |
194 | void release_vbo(GLenum target, GLuint vbo)
195 | {
196 | glBindBuffer(target, 0);
197 | glDeleteBuffers(1, &vbo);
198 | }
199 |
200 |
201 | void init_shader(graphics_context_t *gc, const GLchar *vs, const GLchar *fs)
202 | {
203 | gc->vshader = glCreateShader(GL_VERTEX_SHADER);
204 | glShaderSource(gc->vshader, 1, &vs, 0);
205 | glCompileShader(gc->vshader);
206 | gc->fshader = glCreateShader(GL_FRAGMENT_SHADER);
207 | glShaderSource(gc->fshader, 1, &fs, 0);
208 | glCompileShader(gc->fshader);
209 |
210 | gc->program = glCreateProgram();
211 | glAttachShader(gc->program, gc->vshader);
212 | glAttachShader(gc->program, gc->fshader);
213 | glLinkProgram(gc->program);
214 | }
215 |
216 |
217 | void release_shader(graphics_context_t *gc)
218 | {
219 | glDeleteProgram(gc->program);
220 | glDeleteShader(gc->vshader);
221 | glDeleteShader(gc->fshader);
222 | }
223 |
224 |
225 | void init_gl(graphics_context_t *gc)
226 | {
227 | init_shader(gc, VShader1, FShader1);
228 | gc->vbo_pos = create_vbo(GL_ARRAY_BUFFER, vtx_model, sizeof(vtx_model));
229 | gc->vbo_nor = create_vbo(GL_ARRAY_BUFFER, nor_model, sizeof(nor_model));
230 | gc->vbo_tex = create_vbo(GL_ARRAY_BUFFER, tex_model, sizeof(tex_model));
231 | gc->vbo_ind = create_vbo(GL_ELEMENT_ARRAY_BUFFER, ind_model, sizeof(ind_model));
232 | gc->vloc_pos = glGetAttribLocation(gc->program, "pos");
233 | gc->vloc_nor = glGetAttribLocation(gc->program, "nor");
234 | gc->vloc_tex = glGetAttribLocation(gc->program, "tex");
235 | gc->uloc_model = glGetUniformLocation(gc->program, "model_mat");
236 | gc->uloc_nor = glGetUniformLocation(gc->program, "nor_mat");
237 | gc->uloc_light = glGetUniformLocation(gc->program, "light_pos");
238 |
239 | glBindBuffer(GL_ARRAY_BUFFER, gc->vbo_pos);
240 | glVertexAttribPointer(gc->vloc_pos, g_vsize_pos, GL_FLOAT, GL_FALSE, g_stride_pos, (GLfloat *)0);
241 | glBindBuffer(GL_ARRAY_BUFFER, 0);
242 |
243 | glBindBuffer(GL_ARRAY_BUFFER, gc->vbo_nor);
244 | glVertexAttribPointer(gc->vloc_nor, g_vsize_nor, GL_FLOAT, GL_FALSE, g_stride_nor, (GLfloat *)0);
245 | glBindBuffer(GL_ARRAY_BUFFER, 0);
246 |
247 | glBindBuffer(GL_ARRAY_BUFFER, gc->vbo_tex);
248 | glVertexAttribPointer(gc->vloc_tex, g_vsize_tex, GL_FLOAT, GL_FALSE, g_stride_tex, (GLfloat *)0);
249 | glBindBuffer(GL_ARRAY_BUFFER, 0);
250 |
251 | glBindFramebuffer(GL_FRAMEBUFFER,0);
252 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
253 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
254 | glViewport(0, 0, gc->screen_width, gc->screen_height);
255 | glUseProgram(gc->program);
256 |
257 | gc->texture = create_texture("texture1.bmp");
258 |
259 | glDisable(GL_BLEND);
260 |
261 | glEnable(GL_CULL_FACE);
262 | glEnable(GL_DEPTH_TEST);
263 | }
264 |
265 |
266 | void release_gl(graphics_context_t *gc)
267 | {
268 | release_texture(gc->texture);
269 | release_shader(gc);
270 | release_vbo(GL_ARRAY_BUFFER, gc->vbo_pos);
271 | release_vbo(GL_ARRAY_BUFFER, gc->vbo_nor);
272 | release_vbo(GL_ARRAY_BUFFER, gc->vbo_tex);
273 | release_vbo(GL_ELEMENT_ARRAY_BUFFER, gc->vbo_ind);
274 | }
275 |
276 |
277 | void * glclient_thread( /* void * arg */)
278 | {
279 | // server_thread_args_t * a = (server_thread_args_t *)arg;
280 | static graphics_context_t gc;
281 |
282 | static struct js_event joy;
283 | int joy_fd;
284 | static char button[32];
285 |
286 | // glclient_context_t *glcc = a->user_context_ptr;
287 |
288 | joy_fd = -1;
289 |
290 | /*
291 | joy_fd = open(glcc->joy_dev, O_RDONLY);
292 | if (joy_fd == -1)
293 | {
294 | printf("Error: Joystick device open\n");
295 | }
296 | if (joy_fd != -1)
297 | {
298 | fcntl(joy_fd, F_SETFL, O_NONBLOCK);
299 | }
300 | */
301 | EGLDisplay eglDpy = eglGetCurrentDisplay();
302 | EGLSurface eglSurf = eglGetCurrentSurface(EGL_DRAW);
303 |
304 | // gls_init(a);
305 |
306 | // gls_cmd_get_context();
307 | eglQuerySurface(eglDpy, eglSurf, EGL_WIDTH, &gc.screen_width);
308 | eglQuerySurface(eglDpy, eglSurf, EGL_HEIGHT, &gc.screen_height);
309 | printf("width:%d height:%d\n",glsc_global.screen_width,glsc_global.screen_height);
310 | init_gl(&gc);
311 |
312 | float aspect = (float)gc.screen_width / (float)gc.screen_height;
313 |
314 | mat_perspective(proj_mat, aspect, 0.1f, 1024.0f, 60.0f);
315 | glUniform4fv(gc.uloc_light, 1, light_pos);
316 |
317 | srand(0x12345678);
318 | int j;
319 | for (j = 0; j < 1024; j++)
320 | {
321 | obj[j].z = randf() * 8.0f - 10.0f;
322 | obj[j].x = (randf() * 2.0f - 1.0f) * obj[j].z;
323 | obj[j].y = (randf() * 1.0f - 0.5f) * obj[j].z;
324 | obj[j].dx = randf() * 0.0f - 0.0f;
325 | obj[j].dy = randf() * 0.0f - 0.0f;
326 | obj[j].dz = randf() * 0.0f - 0.0f;
327 | obj[j].rx = randf() * 6.28;
328 | obj[j].ry = randf() * 6.28;
329 | obj[j].rz = randf() * 6.28;
330 | obj[j].drx = randf() * 0.1f - 0.05f;
331 | obj[j].dry = randf() * 0.1f - 0.05f;
332 | obj[j].drz = randf() * 0.1f - 0.05f;
333 | }
334 |
335 | float x = 1.57f;
336 | float y = 0.0f;
337 | float z = -2.0f;
338 | int k = 1;
339 |
340 | int i;
341 | for (i = 0; i < 432000; i++)
342 | {
343 | struct timeval times, timee;
344 | gettimeofday(×, NULL);
345 |
346 | if (joy_fd != -1)
347 | {
348 | while (read(joy_fd, &joy, sizeof(struct js_event)) == sizeof(struct js_event))
349 | {
350 | if ((joy.type & JS_EVENT_BUTTON) == JS_EVENT_BUTTON)
351 | {
352 | button[joy.number] = joy.value;
353 | }
354 | }
355 |
356 | if (button[4] > 0)
357 | {
358 | y += 0.01f;
359 | }
360 | if (button[6] > 0)
361 | {
362 | y += -0.01f;
363 | }
364 | if (button[5] > 0)
365 | {
366 | x += 0.01f * aspect;
367 | }
368 | if (button[7] > 0)
369 | {
370 | x += -0.01f * aspect;
371 | }
372 | if (button[12] > 0)
373 | {
374 | z += -0.01f;
375 | }
376 | if (button[13] > 0)
377 | {
378 | k++;
379 | k = (k > 45) ? 45 : k;
380 | }
381 | if (button[14] > 0)
382 | {
383 | z += 0.01f;
384 | }
385 | if (button[15] > 0)
386 | {
387 | k--;
388 | k = (k < 1) ? 1 : k;
389 | }
390 | }
391 |
392 | glUseProgram(gc.program);
393 | glBindBuffer(GL_ARRAY_BUFFER, gc.vbo_pos);
394 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gc.vbo_ind);
395 | glEnableVertexAttribArray(gc.vloc_pos);
396 | glEnableVertexAttribArray(gc.vloc_nor);
397 | glEnableVertexAttribArray(gc.vloc_tex);
398 |
399 | glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
400 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
401 |
402 | for (j = 0; j < k; j++)
403 | {
404 | obj[j].rx += obj[j].drx;
405 | obj[j].ry += obj[j].dry;
406 | obj[j].rz += obj[j].drz;
407 |
408 | if (j == 0)
409 | {
410 | obj[j].x = 0.0f;
411 | obj[j].y = 0.0f;
412 | obj[j].z = z;
413 | obj[j].rx = -y;
414 | obj[j].ry = x;
415 | obj[j].rz = 0.0f;
416 | }
417 |
418 | mat_identity(model_mat);
419 | mat_translate(model_mat, obj[j].x, obj[j].y, obj[j].z);
420 | mat_rotate_x(model_mat, obj[j].rx);
421 | mat_rotate_y(model_mat, obj[j].ry);
422 | mat_rotate_z(model_mat, obj[j].rz);
423 |
424 | mat_copy(nor_mat, model_mat);
425 | mat_invert(nor_mat);
426 | mat_transpose(nor_mat);
427 | glUniformMatrix4fv(gc.uloc_nor, 1, GL_FALSE, nor_mat);
428 | mat_copy(obj[j].nor_mat, nor_mat);
429 |
430 | mat_copy(modelproj_mat, proj_mat);
431 | mat_mul(modelproj_mat, model_mat);
432 | glUniformMatrix4fv(gc.uloc_model, 1, GL_FALSE, modelproj_mat);
433 | mat_copy(obj[j].modelproj_mat, modelproj_mat);
434 |
435 | glDrawElements(GL_TRIANGLES, sizeof(ind_model) / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
436 | }
437 | glDisableVertexAttribArray(gc.vloc_tex);
438 | glDisableVertexAttribArray(gc.vloc_nor);
439 | glDisableVertexAttribArray(gc.vloc_pos);
440 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
441 | glBindBuffer(GL_ARRAY_BUFFER, 0);
442 | eglSwapBuffers(eglDpy, eglSurf);
443 | gettimeofday(&timee, NULL);
444 | //printf("%d:%f ms ", i, get_diff_time(times, timee) * 1000.0f);
445 | }
446 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
447 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
448 | eglSwapBuffers(eglDpy, eglSurf);
449 | release_gl(&gc);
450 | // gls_free();
451 | if (joy_fd != -1)
452 | {
453 | close(joy_fd);
454 | }
455 | pthread_exit(NULL);
456 | }
457 |
458 |
459 | int main(int argc, char * argv[])
460 | {
461 | static glclient_context_t glcc;
462 | /*
463 | static server_context_t sc;
464 | int opt;
465 | char my_ip[GLS_STRING_SIZE_PLUS];
466 | char his_ip[GLS_STRING_SIZE_PLUS];
467 | uint16_t my_port = 18146;
468 | uint16_t his_port = 18145;
469 | strncpy(my_ip, "127.0.0.1", GLS_STRING_SIZE);
470 | strncpy(his_ip, "127.0.0.1", GLS_STRING_SIZE);
471 | */
472 | strncpy(glcc.joy_dev, "/dev/input/js0", GLS_STRING_SIZE);
473 | /*
474 | while ((opt = getopt(argc, argv, "s:c:j:h")) != -1)
475 | {
476 | switch (opt)
477 | {
478 | case 's':
479 | strncpy(his_ip, strtok(optarg, ":"), GLS_STRING_SIZE);
480 | his_port = atoi(strtok(NULL, ":"));
481 | break;
482 | case 'c':
483 | strncpy(my_ip, strtok(optarg, ":"), GLS_STRING_SIZE);
484 | my_port = atoi(strtok(NULL, ":"));
485 | break;
486 | case 'j':
487 | strncpy(glcc.joy_dev, optarg, GLS_STRING_SIZE);
488 | break;
489 | case 'h':
490 | default:
491 | printf("Usage: %s [-c my_ip_address:port] [-s server_ip_address:port] [-j joystick_device]\n", argv[0]);
492 | return 0;
493 | }
494 | }
495 |
496 | server_init(&sc);
497 | set_server_address_port(&sc, my_ip, my_port);
498 | set_client_address_port(&sc, his_ip, his_port);
499 | set_client_user_context(&sc, &glcc);
500 | */
501 | // server_run(&sc, glclient_thread);
502 | pthread_t threadID;
503 | int ret;
504 |
505 | ret = pthread_create(&threadID, NULL, glclient_thread, NULL);
506 |
507 | if (ret) {
508 | printf("pthread_create() error number=%d\n", ret);
509 | return -1;
510 | }
511 |
512 | pthread_exit(NULL);
513 |
514 | return 0;
515 | }
516 |
--------------------------------------------------------------------------------
/gl_client/samples/texture1.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khanhduytran0/android-gl-streaming/b4895522e210f38a4b5ddc93f34ff05e4533e47a/gl_client/samples/texture1.bmp
--------------------------------------------------------------------------------
/gl_client/todo_add.txt:
--------------------------------------------------------------------------------
1 | glBindRenderbuffer (GLenum target, GLuint renderbuffer);
2 | glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
3 | glBlendEquation ( GLenum mode );
4 | glBlendFunc (GLenum sfactor, GLenum dfactor);
5 | glCheckFramebufferStatus (GLenum target);
6 | glClearDepthf (GLclampf depth);
7 | glClearStencil (GLint s);
8 | glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
9 | glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data);
10 | glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data);
11 | glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
12 | glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers);
13 | glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers);
14 | glDetachShader (GLuint program, GLuint shader);
15 | glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
16 | glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
17 | glFrontFace (GLenum mode);
18 | glGenerateMipmap (GLenum target);
19 | glGenFramebuffers (GLsizei n, GLuint* framebuffers);
20 | glGenRenderbuffers (GLsizei n, GLuint* renderbuffers);
21 | glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders);
22 | glGetBooleanv (GLenum pname, GLboolean* params);
23 | glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params);
24 | glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params);
25 | glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params);
26 | glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
27 | glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source);
28 | glGetTexParameterfv (GLenum target, GLenum pname, GLfloat* params);
29 | glGetTexParameteriv (GLenum target, GLenum pname, GLint* params);
30 | glGetUniformfv (GLuint program, GLint location, GLfloat* params);
31 | glGetUniformiv (GLuint program, GLint location, GLint* params);
32 | glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params);
33 | glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params);
34 | glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer);
35 | glIsBuffer (GLuint buffer);
36 | glIsEnabled (GLenum cap);
37 | glIsFramebuffer (GLuint framebuffer);
38 | glIsProgram (GLuint program);
39 | glIsRenderbuffer (GLuint renderbuffer);
40 | glIsShader (GLuint shader);
41 | glIsTexture (GLuint texture);
42 | glReleaseShaderCompiler (void);
43 | glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
44 | glSampleCoverage (GLclampf value, GLboolean invert);
45 | glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
46 | glShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length);
47 | glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask);
48 | glStencilMaskSeparate (GLenum face, GLuint mask);
49 | glStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
50 | glTexParameterf (GLenum target, GLenum pname, GLfloat param);
51 | glTexParameterfv (GLenum target, GLenum pname, const GLfloat* params);
52 | glTexParameteriv (GLenum target, GLenum pname, const GLint* params);
53 | glUniform1fv (GLint location, GLsizei count, const GLfloat* v);
54 | glUniform1i (GLint location, GLint x);
55 | glUniform1iv (GLint location, GLsizei count, const GLint* v);
56 | glUniform2f (GLint location, GLfloat x, GLfloat y);
57 | glUniform2fv (GLint location, GLsizei count, const GLfloat* v);
58 | glUniform2i (GLint location, GLint x, GLint y);
59 | glUniform2iv (GLint location, GLsizei count, const GLint* v);
60 | glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z);
61 | glUniform3fv (GLint location, GLsizei count, const GLfloat* v);
62 | glUniform3i (GLint location, GLint x, GLint y, GLint z);
63 | glUniform3iv (GLint location, GLsizei count, const GLint* v);
64 | glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
65 | glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w);
66 | glUniform4iv (GLint location, GLsizei count, const GLint* v);
67 | glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
68 | glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
69 | glValidateProgram (GLuint program);
70 |
71 |
--------------------------------------------------------------------------------
/gl_server/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 | LOCAL_MODULE := gl_server
5 | LOCAL_SRC_FILES := ../common/fifo.c \
6 | ../common/server.c \
7 | glcontrol.c \
8 | glserver.c \
9 | serveregl.c \
10 | servergles.c \
11 | main.c
12 | LOCAL_C_INCLUDES := $(LOCAL_PATH) \
13 | $(LOCAL_PATH)/../common
14 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
15 |
16 | LOCAL_CFLAGS += -DGLS_SERVER
17 | LOCAL_CFLAGS += -std=c99
18 | # Move to define in C code.
19 | # LOCAL_CFLAGS += -DGL_SERVER
20 | ifeq ($(TARGET_ARCH_ABI),x86)
21 | LOCAL_CFLAGS += -ffast-math -mtune=atom -mssse3 -mfpmath=sse
22 | endif
23 | include $(BUILD_STATIC_LIBRARY)
24 |
25 |
--------------------------------------------------------------------------------
/gl_server/Makefile:
--------------------------------------------------------------------------------
1 | CFLAGS=-O3 -Wall -DUSE_X11 -DGLS_SERVER
2 |
3 | LIBS=-L/opt/vc/lib/ -lX11 -lGLESv2 -lEGL -lpthread -lrt
4 | # -lopenmaxil -lbcm_host -lvcos -lvchiq_arm
5 | INCLUDES=-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I../common -I. -I./include
6 | OBJS=fifo.o glcontrol.o server.o serveregl.o servergles.o glserver.o
7 |
8 | all: $(OBJS) gl_server
9 |
10 | fifo.o: ../common/fifo.c ../common/fifo.h
11 | gcc -c -o fifo.o $(CFLAGS) ../common/fifo.c
12 |
13 | glcontrol.o: glcontrol.c glcontrol.h
14 | gcc -c -o glcontrol.o $(CFLAGS) $(INCLUDES) glcontrol.c
15 |
16 | server.o: ../common/server.c ../common/server.h fifo.o
17 | gcc -c -o server.o $(CFLAGS) ../common/server.c
18 |
19 | serveregl.o: serveregl.c glserver.h ../common/gls_command.h
20 | gcc -c -o serveregl.o $(CFLAGS) $(INCLUDES) serveregl.c
21 |
22 | servergles.o: servergles.c glserver.h ../common/gls_command.h
23 | gcc -c -o servergles.o $(CFLAGS) $(INCLUDES) servergles.c
24 |
25 | glserver.o: glserver.c glserver.h ../common/gls_command.h glcontrol.o server.o
26 | gcc -c -o glserver.o $(CFLAGS) $(INCLUDES) glserver.c
27 |
28 | gl_server: main.c glserver.o
29 | gcc -o gl_server $(CFLAGS) $(INCLUDES) main.c $(OBJS) $(LIBS)
30 |
31 | clean:
32 | rm gl_server $(OBJS)
33 |
--------------------------------------------------------------------------------
/gl_server/glcontrol.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 |
39 | #include "glcontrol.h"
40 |
41 | //#define DEBUG
42 | #define CASE_STRING( value ) case value: return #value;
43 | const char* eglGetErrorString(EGLint err)
44 | {
45 | switch(err) {
46 | CASE_STRING( EGL_SUCCESS )
47 | CASE_STRING( EGL_NOT_INITIALIZED )
48 | CASE_STRING( EGL_BAD_ACCESS )
49 | CASE_STRING( EGL_BAD_ALLOC )
50 | CASE_STRING( EGL_BAD_ATTRIBUTE )
51 | CASE_STRING( EGL_BAD_CONTEXT )
52 | CASE_STRING( EGL_BAD_CONFIG )
53 | CASE_STRING( EGL_BAD_CURRENT_SURFACE )
54 | CASE_STRING( EGL_BAD_DISPLAY )
55 | CASE_STRING( EGL_BAD_SURFACE )
56 | CASE_STRING( EGL_BAD_MATCH )
57 | CASE_STRING( EGL_BAD_PARAMETER )
58 | CASE_STRING( EGL_BAD_NATIVE_PIXMAP )
59 | CASE_STRING( EGL_BAD_NATIVE_WINDOW )
60 | CASE_STRING( EGL_CONTEXT_LOST )
61 |
62 | default: return ("EGL_BAD_ERROR_%p", err);
63 | }
64 | }
65 | const char* glGetErrorString(GLenum err)
66 | {
67 | switch(err) {
68 | CASE_STRING(GL_NO_ERROR)
69 | CASE_STRING(GL_INVALID_ENUM)
70 | CASE_STRING(GL_INVALID_VALUE)
71 | CASE_STRING(GL_INVALID_OPERATION)
72 | CASE_STRING(GL_OUT_OF_MEMORY)
73 | case 0x8031: /* not core */ return "GL_TABLE_TOO_LARGE_EXT";
74 | case 0x8065: /* not core */ return "GL_TEXTURE_TOO_LARGE_EXT";
75 | CASE_STRING(GL_INVALID_FRAMEBUFFER_OPERATION)
76 |
77 | default: return("GL_BAD_ERROR_%p", err);
78 | }
79 | }
80 | #undef CASE_STRING
81 |
82 | void base_check_egl_err(char* funcname) {
83 | int error = eglGetError();
84 | if (error != EGL_SUCCESS) {
85 | LOGD("eglGetError(%s) return error %s", funcname, eglGetErrorString(error));
86 | }
87 | #ifdef DEBUG
88 | assert(error == 0)
89 | #endif // DEBUG
90 | }
91 | void base_check_gl_err(char* funcname) {
92 | int error = glGetError();
93 | if (error != GL_NO_ERROR) {
94 | LOGD("glGetError(%s) return error %s", funcname, glGetErrorString(error));
95 | }
96 | #ifdef DEBUG
97 | assert(error == 0)
98 | #endif // DEBUG
99 | }
100 |
101 | void init_egl(graphics_context_t *gc)
102 | {
103 | EGLBoolean r;
104 | EGLint num_config;
105 |
106 | #ifdef RASPBERRY_PI
107 | VC_RECT_T dst_rect;
108 | VC_RECT_T src_rect;
109 | #endif
110 |
111 | #ifdef USE_X11
112 | Window win;
113 | #endif
114 |
115 | #ifdef RASPBERRY_PI
116 | bcm_host_init();
117 | #endif
118 |
119 | #ifdef USE_X11
120 | xDisplay = XOpenDisplay(NULL);
121 | if (!xDisplay) {
122 | printf("Error: couldn't open display %s\n", getenv("DISPLAY"));
123 | exit(EXIT_FAILURE);
124 | return;
125 | }
126 | gc->display = eglGetDisplay(xDisplay);
127 | #else
128 | gc->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
129 | #endif
130 | assert(gc->display != EGL_NO_DISPLAY);
131 | check_gl_err(eglGetDisplay);
132 |
133 | #ifdef RASPBERRY_PI
134 | int32_t ri = graphics_get_display_size(0, &gc->screen_width, &gc->screen_height);
135 | assert(ri >= 0);
136 |
137 | dst_rect.x = 0;
138 | dst_rect.y = 0;
139 | dst_rect.width = gc->screen_width;
140 | dst_rect.height = gc->screen_height;
141 |
142 | src_rect.x = 0;
143 | src_rect.y = 0;
144 | src_rect.width = gc->screen_width << 16;
145 | src_rect.height = gc->screen_height << 16;
146 |
147 | gc->d_display = vc_dispmanx_display_open(0);
148 | gc->d_update = vc_dispmanx_update_start(0);
149 | gc->d_element = vc_dispmanx_element_add(
150 | gc->d_update, gc->d_display,
151 | 0, &dst_rect, 0,
152 | &src_rect, DISPMANX_PROTECTION_NONE, 0 , 0, (DISPMANX_TRANSFORM_T)0);
153 | gc->d_window.element = gc->d_element;
154 | gc->d_window.width = gc->screen_width;
155 | gc->d_window.height = gc->screen_height;
156 | vc_dispmanx_update_submit_sync(gc->d_update);
157 | check_gl_err();
158 | gc->surface = eglCreateWindowSurface(gc->display, config, &gc->d_window, NULL);
159 | #elif defined(GLS_SERVER)
160 | gc->screen_width = glsurfaceview_width; // (gc->d_rect.right - gc->d_rect.left);
161 | gc->screen_height = glsurfaceview_height; // (gc->d_rect.bottom - gc->d_rect.top);
162 | // gc->d_window = glsurfaceview_window;
163 | // assert (glsurfaceview_window != NULL);
164 | #endif
165 | /*
166 | #ifdef __ANDROID__
167 | assert(gc->d_window != NULL);
168 | #elif defined(USE_X11)
169 | */
170 |
171 | #ifdef USE_X11
172 | make_egl_base(gc->display, "OpenGL ES 2.x streaming", 0, 0, glsurfaceview_width, glsurfaceview_height, &win, &gc->context, &gc->surface);
173 | XMapWindow(xDisplay, win);
174 | // gc->surface = eglCreateWindowSurface(gc->surface, config, win, NULL);
175 | #else
176 | make_egl_base(gc->display, &gc->context, &gc->surface);
177 | #endif
178 |
179 | if (gc->surface == EGL_NO_SURFACE) {
180 | gc->surface = eglGetCurrentSurface(EGL_DRAW);
181 | }
182 | assert(gc->surface != EGL_NO_SURFACE);
183 | check_gl_err(eglGetCurrentSurface);
184 |
185 | r = eglMakeCurrent(gc->display, gc->surface, gc->surface, gc->context);
186 | assert(EGL_FALSE != r);
187 | check_gl_err(eglMakeCurrent);
188 | }
189 |
190 |
191 | void release_egl(graphics_context_t *gc)
192 | {
193 | #ifdef RASPBERRY_PI
194 | vc_dispmanx_element_remove(gc->d_update, gc->d_element);
195 | vc_dispmanx_display_close(gc->d_display);
196 | #endif
197 |
198 | eglMakeCurrent(gc->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
199 | eglDestroySurface(gc->display, gc->surface);
200 | eglDestroyContext(gc->display, gc->context);
201 | eglTerminate(gc->display);
202 | eglReleaseThread();
203 | }
204 |
205 |
206 | /**************************************************************************
207 | *
208 | * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
209 | * All Rights Reserved.
210 | *
211 | **************************************************************************/
212 |
213 | /*
214 | * Create an RGB, double-buffered X window.
215 | * Return the window and context handles.
216 | */
217 |
218 | #ifdef USE_X11
219 | void make_egl_base(EGLDisplay egl_dpy, const char *name, int x, int y, int width, int height, Window *winRet, EGLContext *ctxRet, EGLSurface *surfRet)
220 | #else
221 | void make_egl_base(EGLDisplay egl_dpy, EGLContext *ctxRet, EGLSurface *surfRet)
222 | #endif
223 | {
224 | if (!eglInitialize(egl_dpy, NULL, NULL)) {
225 | printf("Error: eglInitialize() failed\n");
226 | return -1;
227 | }
228 |
229 | static const EGLint attribs[] = {
230 | EGL_RED_SIZE, 1,
231 | EGL_GREEN_SIZE, 1,
232 | EGL_BLUE_SIZE, 1,
233 | EGL_DEPTH_SIZE, 1,
234 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
235 | EGL_NONE
236 | };
237 | static const EGLint ctx_attribs[] = {
238 | EGL_CONTEXT_CLIENT_VERSION, 2,
239 | EGL_NONE
240 | };
241 |
242 | #ifdef USE_X11
243 | XSetWindowAttributes attr;
244 | unsigned long mask;
245 | Window root;
246 | Window win;
247 | XVisualInfo *visInfo, visTemplate;
248 | int num_visuals;
249 | #endif // USE_X11
250 |
251 | EGLContext ctx;
252 | EGLConfig config;
253 | EGLint num_configs;
254 | EGLint vid;
255 |
256 | #ifdef USE_X11
257 | xScreenId = DefaultScreen(xDisplay);
258 | root = RootWindow( xDisplay, xScreenId );
259 |
260 | /* The X window visual must match the EGL config */
261 | visTemplate.visualid = XVisualIDFromVisual(XDefaultVisual(xDisplay, xScreenId));
262 | visInfo = XGetVisualInfo(xDisplay, VisualIDMask, &visTemplate, &num_visuals);
263 | if (!visInfo) {
264 | printf("Error: couldn't get X visual\n");
265 | exit(1);
266 | }
267 |
268 | /* window attributes */
269 | attr.background_pixel = 0;
270 | attr.border_pixel = 0;
271 | attr.colormap = XCreateColormap( xDisplay, root, visInfo->visual, AllocNone);
272 | attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
273 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
274 |
275 | win = XCreateWindow( xDisplay, root, 0, 0, width, height,
276 | 0, visInfo->depth, InputOutput,
277 | visInfo->visual, mask, &attr );
278 |
279 | /* set hints and properties */
280 | {
281 | XSizeHints sizehints;
282 | sizehints.x = x;
283 | sizehints.y = y;
284 | sizehints.width = width;
285 | sizehints.height = height;
286 | sizehints.flags = USSize | USPosition;
287 | XSetNormalHints(xDisplay, win, &sizehints);
288 | XSetStandardProperties(xDisplay, win, name, name,
289 | None, (char **)NULL, 0, &sizehints);
290 | }
291 | #endif // USE_X11
292 |
293 | if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
294 | printf("Error: couldn't get an EGL visual config\n");
295 | exit(1);
296 | }
297 | assert(config);
298 | assert(num_configs > 0);
299 |
300 | if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
301 | printf("Error: eglGetConfigAttrib() failed\n");
302 | exit(1);
303 | }
304 |
305 | eglBindAPI(EGL_OPENGL_ES_API);
306 |
307 | ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
308 | if (!ctx) {
309 | printf("Error: eglCreateContext failed\n");
310 | exit(1);
311 | }
312 |
313 | // test eglQueryContext()
314 | {
315 | EGLint val;
316 | eglQueryContext(egl_dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &val);
317 | // assert(val == 2);
318 | }
319 |
320 | #ifdef USE_X11
321 | *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
322 | #elif defined(__ANDROID__)
323 | *surfRet = eglCreateWindowSurface(egl_dpy, config, glsurfaceview_window, NULL);
324 | #else
325 | printf("FIXME!!! on platform without X11 or Android? Windows?\n");
326 | exit(1);
327 | #endif
328 |
329 | if (!*surfRet) {
330 | printf("Error: eglCreateWindowSurface failed: %p\n", eglGetError());
331 | exit(1);
332 | }
333 |
334 | // sanity checks
335 | {
336 | EGLint val;
337 | assert(eglGetConfigAttrib(egl_dpy, config, EGL_SURFACE_TYPE, &val));
338 | assert(val & EGL_WINDOW_BIT);
339 | }
340 |
341 | #ifdef USE_X11
342 | XFree(visInfo);
343 | *winRet = win;
344 | #endif // USE_X11
345 |
346 | *ctxRet = ctx;
347 | }
348 |
349 |
350 |
--------------------------------------------------------------------------------
/gl_server/glcontrol.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include "fastlog.h"
32 | #include "GLES2/gl2.h"
33 | #include "EGL/egl.h"
34 | #include "EGL/eglext.h"
35 | #include "utils.h"
36 |
37 | typedef struct
38 | {
39 | uint32_t screen_width;
40 | uint32_t screen_height;
41 | EGLDisplay display;
42 | EGLSurface surface;
43 | EGLContext context;
44 | #ifdef __ANDROID__
45 | ANativeWindow* d_window;
46 | #endif // __ANDROID__
47 | } graphics_context_t;
48 |
49 | #define check_egl_err(FUNCNAME) base_check_egl_err(#FUNCNAME);
50 | #define check_gl_err(FUNCNAME) base_check_gl_err(#FUNCNAME);
51 |
52 | #ifdef __cplusplus
53 | extern "C" {
54 | #endif
55 |
56 | void base_check_egl_err(char* funcname);
57 | void base_check_gl_err(char* funcname);
58 |
59 | EGLConfig config;
60 | #ifdef USE_X11
61 | void make_egl_base(EGLDisplay egl_dpy, const char *name, int x, int y, int width, int height, Window *winRet, EGLContext *ctxRet, EGLSurface *surfRet);
62 | #else
63 | void make_egl_base(EGLDisplay egl_dpy, EGLContext *ctxRet, EGLSurface *surfRet);
64 | #endif // USE_X11
65 | void init_egl(graphics_context_t *gc);
66 | void release_egl(graphics_context_t *gc);
67 |
68 | #ifdef __cplusplus
69 | }
70 | #endif
71 |
--------------------------------------------------------------------------------
/gl_server/glserver.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 |
41 | #include "glserver.h"
42 |
43 | // #define GL_DEBUG
44 |
45 | glse_context_t glsec_global;
46 |
47 |
48 | void pop_batch_command(size_t size)
49 | {
50 | glsec_global.tmp_buf.ptr = next_ptr(glsec_global.tmp_buf.ptr, size, GLS_ALIGNMENT_BITS);
51 | }
52 |
53 |
54 | int send_packet(size_t size)
55 | {
56 | server_thread_args_t *a = glsec_global.sta;
57 | if (sendto(a->sock_fd, glsec_global.out_buf.buf, size, 0, (struct sockaddr *)&a->sai, sizeof(struct sockaddr_in)) == -1)
58 | {
59 | return FALSE;
60 | }
61 | gls_sleep(a->max_mbps, size);
62 | return TRUE;
63 | }
64 |
65 |
66 | int glse_cmd_send_data(uint32_t offset, uint32_t size, void *data)
67 | {
68 | gls_cmd_send_data_t *c = (gls_cmd_send_data_t *)glsec_global.out_buf.buf;
69 | c->cmd = GLSC_SEND_DATA;
70 |
71 | int success = TRUE;
72 | uint32_t glssize = GLS_DATA_SIZE * 4;
73 | char *data1 = (char *)data;
74 |
75 | uint32_t offset1;
76 | for (offset1 = 0; offset1 < size; offset1 += glssize)
77 | {
78 | unsigned int size1 = size - offset1;
79 | c->isLast = (size1 > glssize) ? FALSE : TRUE;
80 | size1 = (size1 > glssize) ? glssize : size1;
81 | memcpy(c->data.data_char, data1, size1);
82 | size_t sendbytes = (size_t)(&c->data.data_char[size1] - (char *)c);
83 | c->offset = offset + offset1;
84 | c->size = size1;
85 | if (send_packet(sendbytes) == FALSE)
86 | {
87 | success = FALSE;
88 | }
89 | data1 += glssize;
90 | }
91 | return success;
92 | }
93 |
94 |
95 | void glse_cmd_get_context()
96 | {
97 | gls_cmd_get_context_t *c = (gls_cmd_get_context_t *)glsec_global.cmd_data;
98 | graphics_context_t *gc = glsec_global.gc;
99 |
100 | gls_ret_get_context_t *ret = (gls_ret_get_context_t *)glsec_global.tmp_buf.buf;
101 | ret->cmd = c->cmd;
102 | ret->screen_width = gc->screen_width = glsurfaceview_width;
103 | ret->screen_height = gc->screen_height = glsurfaceview_height;
104 | ret->server_version = GLS_VERSION;
105 | size_t size = sizeof(gls_ret_get_context_t);
106 | glse_cmd_send_data(0, size, glsec_global.tmp_buf.buf);
107 | }
108 |
109 |
110 | void glse_cmd_flip()
111 | {
112 | gls_cmd_flip_t *c = (gls_cmd_flip_t *)glsec_global.cmd_data;
113 | graphics_context_t *gc = glsec_global.gc;
114 | eglSwapBuffers(gc->display, gc->surface);
115 | check_gl_err(eglSwapBuffers);
116 | gls_ret_flip_t *ret = (gls_ret_flip_t *)glsec_global.tmp_buf.buf;
117 | ret->cmd = c->cmd;
118 | ret->frame = c->frame;
119 | size_t size = sizeof(gls_ret_flip_t);
120 | glse_cmd_send_data(0, size, glsec_global.tmp_buf.buf);
121 | }
122 |
123 |
124 | int glse_cmd_recv_data()
125 | {
126 | gls_cmd_send_data_t *c = (gls_cmd_send_data_t *)glsec_global.cmd_data;
127 | if ((c->offset + c->size > glsec_global.tmp_buf.size) || (glsec_global.tmp_buf.size == 0))
128 | {
129 | return FALSE;
130 | }
131 | memcpy(&glsec_global.tmp_buf.buf[c->offset], c->data.data_char, c->size);
132 | return TRUE;
133 | }
134 |
135 |
136 | void glse_cmd_flush()
137 | {
138 | glsec_global.tmp_buf.ptr = 0;
139 | int quit = FALSE;
140 | while (quit == FALSE) {
141 | gls_command_t *c = (gls_command_t *)(glsec_global.tmp_buf.buf + glsec_global.tmp_buf.ptr);
142 | glsec_global.cmd_data = c;
143 | switch (c->cmd) {
144 | case GLSC_BREAK:
145 | quit = TRUE;
146 | break;
147 | default: {
148 | int result = egl_flushCommand(c);
149 | // Attempt to flush EGL first, if fail then attepmt to GLES.
150 | if (result == FALSE) {
151 | result = gles_flushCommand(c);
152 | }
153 |
154 | if (result == FALSE) {
155 | LOGE("Error: Command Flush %i", c->cmd);
156 | quit = TRUE;
157 | }
158 | break;
159 | }
160 | }
161 | }
162 | }
163 |
164 | void * glserver_thread(void * arg)
165 | {
166 | #ifdef GL_DEBUG
167 | FILE *fl;
168 | fl = fopen("/sdcard/mthr_log.txt", "w");
169 | #endif
170 | int quit = FALSE;
171 | server_thread_args_t * a = (server_thread_args_t *)arg;
172 | static graphics_context_t gc;
173 | memset(&glsec_global, 0, sizeof(glsec_global));
174 | memset(&gc, 0, sizeof(gc));
175 | #ifdef __ANDROID__
176 | assert (glsurfaceview_window != NULL);
177 | gc.d_window = glsurfaceview_window;
178 | #endif __ANDROID__
179 | init_egl(&gc);
180 |
181 | glsec_global.sta = a;
182 | glsec_global.gc = &gc;
183 | glsec_global.tmp_buf.buf = (char *)malloc(GLSE_TMP_BUFFER_SIZE);
184 | glsec_global.tmp_buf.size = GLSE_TMP_BUFFER_SIZE;
185 | glsec_global.out_buf.buf = (char *)malloc(GLSE_OUT_BUFFER_SIZE);
186 | glsec_global.out_buf.size = GLSE_OUT_BUFFER_SIZE;
187 |
188 |
189 | while (quit == FALSE)
190 | {
191 | void *popptr = (void *)fifo_pop_ptr_get(a->fifo);
192 | if (popptr == NULL) {
193 | usleep(a->sleep_usec);
194 | } else {
195 | gls_command_t *c = (gls_command_t *)popptr;
196 | glsec_global.cmd_data = c;
197 | #ifdef GL_DEBUG
198 | fprintf(fl,"@MainLoop: Attempting to execute command %i \n",c->cmd);
199 | #endif
200 |
201 | switch (c->cmd) {
202 | case GLSC_FLIP:
203 | glse_cmd_flip();
204 | break;
205 | case GLSC_SEND_DATA:
206 | glse_cmd_recv_data();
207 | break;
208 | case GLSC_FLUSH:
209 | #ifdef GL_DEBUG
210 | fprintf(fl,"@Exec: Flushing command buffer...\n");
211 | #endif
212 | glse_cmd_flush();
213 | break;
214 | case GLSC_get_context:
215 | #ifdef GL_DEBUG
216 | fprintf(fl,"@Exec: Feeding context to client...\n");
217 | #endif
218 | glse_cmd_get_context();
219 | break;
220 |
221 | default: {
222 | int result = egl_executeCommand(c);
223 | // Attempt to execute EGL first, if fail then attepmt to GLES.
224 | if (result == FALSE) {
225 | result = gles_executeCommand(c);
226 | }
227 |
228 | if (result == FALSE) {
229 | #ifdef GL_DEBUG
230 | fprintf(fl,"@Exec: %i : Undefined command\n",c->cmd);
231 | #endif
232 | LOGE("Error: Undefined command %i", c->cmd);
233 | }
234 | break;
235 | }
236 | }
237 | fifo_pop_ptr_next(a->fifo);
238 | }
239 | }
240 |
241 | release_egl(&gc);
242 |
243 | free(glsec_global.tmp_buf.buf);
244 | free(glsec_global.out_buf.buf);
245 | #ifdef GL_DEBUG
246 | fclose(fl);
247 | #endif
248 | pthread_exit(NULL);
249 | }
250 |
251 |
252 |
--------------------------------------------------------------------------------
/gl_server/glserver.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include "gls_command.h"
33 | #include "glcontrol.h"
34 | #include "server.h"
35 |
36 |
37 | #define TRUE 1
38 | #define FALSE 0
39 |
40 | #define GLSE_TMP_BUFFER_SIZE 2097152
41 | #define GLSE_OUT_BUFFER_SIZE 4096 // 2048
42 |
43 | #define GLSE_SET_COMMAND_PTR(PTR, FUNCNAME) gls_##FUNCNAME##_t *PTR = (gls_##FUNCNAME##_t *)glsec_global.cmd_data;
44 |
45 | typedef struct
46 | {
47 | gls_buffer_t tmp_buf;
48 | gls_buffer_t out_buf;
49 | server_thread_args_t *sta;
50 | graphics_context_t *gc;
51 | void *cmd_data;
52 | } glse_context_t;
53 |
54 |
55 | #ifdef __cplusplus
56 | extern "C" {
57 | #endif
58 |
59 | extern glse_context_t glsec_global;
60 | void pop_batch_command(size_t size);
61 | void * glserver_thread(void * arg);
62 |
63 | int egl_executeCommand(gls_command_t *c);
64 | int egl_flushCommand(gls_command_t *c);
65 |
66 | int gles_executeCommand(gls_command_t *c);
67 | int gles_flushCommand(gls_command_t *c);
68 |
69 | #ifdef __cplusplus
70 | }
71 | #endif
72 |
73 |
74 |
--------------------------------------------------------------------------------
/gl_server/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | Neither the name of the copyright holders nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 |
40 | #include "glserver.h"
41 | #include "main.h"
42 | // #include "fastlog.h"
43 |
44 | int main(int argc, char * argv[])
45 | {
46 | static server_context_t sc;
47 | int opt;
48 | char my_ip[GLS_STRING_SIZE_PLUS];
49 | char his_ip[GLS_STRING_SIZE_PLUS];
50 | uint16_t my_port = 18145;
51 | uint16_t his_port = 18146;
52 | strncpy(my_ip, "127.0.0.1", GLS_STRING_SIZE);
53 | strncpy(his_ip, "127.0.0.1", GLS_STRING_SIZE);
54 | while ((opt = getopt(argc, argv, "s:c:h")) != -1)
55 | {
56 | switch (opt)
57 | {
58 | case 's':
59 | strncpy(my_ip, strtok(optarg, ":"), GLS_STRING_SIZE);
60 | my_port = atoi(strtok(NULL, ":"));
61 | break;
62 | case 'c':
63 | strncpy(his_ip, strtok(optarg, ":"), GLS_STRING_SIZE);
64 | his_port = atoi(strtok(NULL, ":"));
65 | break;
66 | case 'h':
67 | default:
68 | printf("Usage: %s [-s my_ip_address:port] [-c client_ip_address:port]\n", argv[0]);
69 | return 0;
70 | }
71 | }
72 | server_init(&sc);
73 | set_server_address_port(&sc, my_ip, my_port);
74 | set_client_address_port(&sc, his_ip, his_port);
75 |
76 | server_run(&sc, glserver_thread);
77 |
78 | return 0;
79 | }
80 |
81 | void init_android_main()
82 | {
83 | static server_context_t sc;
84 | int opt;
85 | char server_ip[GLS_STRING_SIZE_PLUS];
86 | char client_ip[GLS_STRING_SIZE_PLUS];
87 | uint16_t server_port = var_server_port;
88 | uint16_t client_port = var_client_port;
89 | strncpy(server_ip, "127.0.0.1", GLS_STRING_SIZE);
90 | strncpy(client_ip, var_client_addr, GLS_STRING_SIZE);
91 | server_init(&sc);
92 | set_server_address_port(&sc, server_ip, server_port);
93 | set_client_address_port(&sc, client_ip, client_port);
94 |
95 | server_run(&sc, glserver_thread);
96 |
97 | // return 0;
98 | }
99 |
100 |
--------------------------------------------------------------------------------
/gl_server/main.h:
--------------------------------------------------------------------------------
1 |
2 | #ifdef __cplusplus
3 | extern "C" {
4 | #endif
5 |
6 | int main(int argc, char * argv[]);
7 | void init_android_main();
8 |
9 | #ifdef __cplusplus
10 | }
11 | #endif
12 |
--------------------------------------------------------------------------------
/gl_server/serveregl.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013, Shodruky Rhyammer
3 | All rights reserved.
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 | Redistributions of source code must retain the above copyright notice, this
7 | list of conditions and the following disclaimer.
8 | Redistributions in binary form must reproduce the above copyright notice, this
9 | list of conditions and the following disclaimer in the documentation and/or
10 | other materials provided with the distribution.
11 | Neither the name of the copyright holders nor the names of its
12 | contributors may be used to endorse or promote products derived from
13 | this software without specific prior written permission.
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 | */
25 |
26 | // This file declare EGL methods on server side
27 |
28 | #include "glserver.h"
29 |
30 |
31 | void glse_eglBindAPI()
32 | {
33 | GLSE_SET_COMMAND_PTR(c, eglBindAPI);
34 | EGLBoolean success = eglBindAPI(c->api);
35 |
36 | gls_ret_eglBindAPI_t *ret = (gls_ret_eglBindAPI_t *)glsec_global.tmp_buf.buf;
37 | ret->cmd = GLSC_eglBindAPI;
38 | ret->success = success;
39 | glse_cmd_send_data(0,sizeof(gls_ret_eglBindAPI_t),(char *)glsec_global.tmp_buf.buf);
40 | }
41 |
42 | void glse_eglChooseConfig()
43 | {
44 | GLSE_SET_COMMAND_PTR(c, eglChooseConfig);
45 |
46 | gls_data_egl_attriblist_t *dat = (gls_data_egl_attriblist_t *)glsec_global.tmp_buf.buf;
47 | gls_ret_eglChooseConfig_t *ret = (gls_ret_eglChooseConfig_t *)glsec_global.tmp_buf.buf;
48 |
49 | // EGLDisplay dpy = eglGetCurrentDisplay();
50 | EGLBoolean success = eglChooseConfig(c->dpy, dat->attrib_list, ret->configs, c->config_size, &ret->num_config);
51 |
52 | ret->success = success;
53 | // ret->configs =
54 | // ret->success = EGL_TRUE;
55 | ret->cmd = GLSC_eglChooseConfig;
56 | glse_cmd_send_data(0,sizeof(gls_ret_eglChooseConfig_t),(char *)glsec_global.tmp_buf.buf);
57 | }
58 |
59 | void glse_eglGetConfigAttrib()
60 | {
61 | GLSE_SET_COMMAND_PTR(c, eglGetConfigAttrib);
62 | gls_ret_eglGetConfigAttrib_t *ret = (gls_ret_eglGetConfigAttrib_t *)glsec_global.tmp_buf.buf;
63 |
64 | // EGLDisplay dpy = eglGetCurrentDisplay();
65 | EGLBoolean success = eglGetConfigAttrib(c->dpy, c->config, c->attribute, &ret->value);
66 |
67 | ret->cmd = GLSC_eglGetConfigAttrib;
68 | ret->success = success;
69 | glse_cmd_send_data(0,sizeof(gls_ret_eglGetConfigAttrib_t),(char *)glsec_global.tmp_buf.buf);
70 | }
71 |
72 | void glse_eglGetConfigs()
73 | {
74 | GLSE_SET_COMMAND_PTR(c, eglGetConfigs);
75 | gls_ret_eglGetConfigs_t *ret = (gls_ret_eglGetConfigs_t *)glsec_global.tmp_buf.buf;
76 |
77 | // EGLDisplay dpy = eglGetCurrentDisplay();
78 | EGLBoolean success = eglGetConfigs(c->dpy, ret->configs, c->config_size, &ret->num_config);
79 |
80 | ret->cmd = GLSC_eglGetConfigs;
81 | ret->success = success;
82 | glse_cmd_send_data(0,sizeof(gls_ret_eglGetConfigs_t),(char *)glsec_global.tmp_buf.buf);
83 | }
84 |
85 | void glse_eglGetCurrentContext()
86 | {
87 | EGLContext context = eglGetCurrentContext();
88 |
89 | gls_ret_eglGetCurrentContext_t *ret = (gls_ret_eglGetCurrentContext_t *)glsec_global.tmp_buf.buf;
90 | ret->cmd = GLSC_eglGetCurrentContext;
91 | ret->context = context;
92 | glse_cmd_send_data(0, sizeof(gls_ret_eglGetCurrentContext_t), (char *)glsec_global.tmp_buf.buf);
93 | }
94 |
95 | void glse_eglGetCurrentDisplay()
96 | {
97 | EGLDisplay display = eglGetCurrentDisplay();
98 |
99 | gls_ret_eglGetCurrentDisplay_t *ret = (gls_ret_eglGetCurrentDisplay_t *)glsec_global.tmp_buf.buf;
100 | ret->cmd = GLSC_eglGetCurrentDisplay;
101 | ret->display = display;
102 | glse_cmd_send_data(0, sizeof(gls_ret_eglGetCurrentDisplay_t), (char *)glsec_global.tmp_buf.buf);
103 | }
104 |
105 | void glse_eglGetCurrentSurface()
106 | {
107 | GLSE_SET_COMMAND_PTR(c, eglGetCurrentSurface);
108 | EGLSurface surface = eglGetCurrentSurface(c->readdraw);
109 |
110 | gls_ret_eglGetCurrentSurface_t *ret = (gls_ret_eglGetCurrentSurface_t *)glsec_global.tmp_buf.buf;
111 | ret->cmd = GLSC_eglGetCurrentSurface;
112 | ret->surface = surface;
113 | glse_cmd_send_data(0, sizeof(gls_ret_eglGetCurrentSurface_t), (char *)glsec_global.tmp_buf.buf);
114 | }
115 |
116 | void glse_eglGetError()
117 | {
118 | GLuint error = eglGetError();
119 | // Should check gl error inside eglGetError() ???
120 |
121 | gls_ret_eglGetError_t *ret = (gls_ret_eglGetError_t *)glsec_global.tmp_buf.buf;
122 | ret->cmd = GLSC_eglGetError;
123 | ret->error = error;
124 | glse_cmd_send_data(0, sizeof(gls_ret_eglGetError_t), (char *)glsec_global.tmp_buf.buf);
125 | }
126 |
127 | void glse_eglInitialize()
128 | {
129 | GLSE_SET_COMMAND_PTR(c, eglInitialize);
130 | EGLBoolean success = EGL_TRUE; // Current stub instead of real init
131 | // eglInitialize(c->dpy, c->major, c->minor);
132 |
133 | gls_ret_eglInitialize_t *ret = (gls_ret_eglInitialize_t *)glsec_global.tmp_buf.buf;
134 | ret->cmd = GLSC_eglInitialize;
135 | ret->success = success;
136 | glse_cmd_send_data(0,sizeof(gls_ret_eglInitialize_t),(char *)glsec_global.tmp_buf.buf);
137 | }
138 |
139 | void glse_eglQueryContext()
140 | {
141 | GLSE_SET_COMMAND_PTR(c, eglQueryContext);
142 | gls_ret_eglQueryContext_t *ret = (gls_ret_eglQueryContext_t *)glsec_global.tmp_buf.buf;
143 |
144 | EGLBoolean success = eglQueryContext(c->dpy, c->ctx, c->attribute, &ret->value);
145 |
146 | ret->cmd = GLSC_eglQueryContext;
147 | ret->success = success;
148 | glse_cmd_send_data(0,sizeof(gls_ret_eglQueryContext_t),(char *)glsec_global.tmp_buf.buf);
149 | }
150 |
151 | void glse_eglQueryString()
152 | {
153 | GLSE_SET_COMMAND_PTR(c, eglQueryString);
154 | gls_ret_eglQueryString_t *ret = (gls_ret_eglQueryString_t *)glsec_global.tmp_buf.buf;
155 |
156 | const char *params = eglQueryString(c->dpy, c->name);
157 |
158 | ret->cmd = GLSC_eglQueryString;
159 | // LOGD("Client asking for %i, return %s", c->name, params);
160 | // ret->params[GLS_STRING_SIZE_PLUS - 1] = '\0';
161 | strncpy(ret->params, params, GLS_STRING_SIZE);
162 | glse_cmd_send_data(0,sizeof(gls_ret_eglQueryString_t),(char *)glsec_global.tmp_buf.buf);
163 | }
164 |
165 | void glse_eglQuerySurface()
166 | {
167 | GLSE_SET_COMMAND_PTR(c, eglQuerySurface);
168 | gls_ret_eglQuerySurface_t *ret = (gls_ret_eglQuerySurface_t *)glsec_global.tmp_buf.buf;
169 |
170 | EGLBoolean success = eglQuerySurface(c->dpy, c->surface, c->attribute, &ret->value);
171 |
172 | ret->cmd = GLSC_eglQuerySurface;
173 | ret->success = success;
174 | glse_cmd_send_data(0,sizeof(gls_ret_eglQuerySurface_t),(char *)glsec_global.tmp_buf.buf);
175 | }
176 |
177 | void glse_eglTerminate()
178 | {
179 | GLSE_SET_COMMAND_PTR(c, eglTerminate);
180 | gls_ret_eglTerminate_t *ret = (gls_ret_eglTerminate_t *)glsec_global.tmp_buf.buf;
181 | ret->cmd = GLSC_eglTerminate;
182 | ret->success = EGL_TRUE; // Current stub instead of real init
183 | // eglTerminate(c->dpy);
184 |
185 | glse_cmd_send_data(0,sizeof(gls_ret_eglTerminate_t),(char *)glsec_global.tmp_buf.buf);
186 | }
187 |
188 | int egl_executeCommand(gls_command_t *c) {
189 | switch (c->cmd) {
190 | case GLSC_eglBindAPI:
191 | glse_eglBindAPI();
192 | break;
193 | case GLSC_eglChooseConfig:
194 | glse_eglChooseConfig();
195 | break;
196 | case GLSC_eglGetConfigAttrib:
197 | glse_eglGetConfigAttrib();
198 | break;
199 | case GLSC_eglGetConfigs:
200 | glse_eglGetConfigs();
201 | break;
202 | case GLSC_eglGetCurrentContext:
203 | glse_eglGetCurrentContext();
204 | break;
205 | case GLSC_eglGetCurrentDisplay:
206 | glse_eglGetCurrentDisplay();
207 | break;
208 | case GLSC_eglGetCurrentSurface:
209 | glse_eglGetCurrentSurface();
210 | break;
211 | case GLSC_eglGetError:
212 | glse_eglGetError();
213 | break;
214 | case GLSC_eglInitialize:
215 | glse_eglInitialize();
216 | break;
217 | case GLSC_eglQueryContext:
218 | glse_eglQueryContext();
219 | break;
220 | case GLSC_eglQueryString:
221 | glse_eglQueryString();
222 | break;
223 | case GLSC_eglQuerySurface:
224 | glse_eglQuerySurface();
225 | break;
226 | case GLSC_eglTerminate:
227 | glse_eglTerminate();
228 | break;
229 | /*
230 | case GLSC_eglXXX:
231 | glse_eglXXX();
232 | break:
233 | */
234 | default:
235 | return FALSE;
236 | }
237 |
238 | check_egl_err(c->cmd);
239 | return TRUE;
240 | }
241 |
242 | int egl_flushCommand(gls_command_t *c) {
243 | switch (c->cmd) {
244 | // Nothing here to flush
245 | default:
246 | return FALSE;
247 | }
248 |
249 | check_egl_err(c->cmd);
250 | return TRUE;
251 | }
252 |
253 |
--------------------------------------------------------------------------------
/www/GLStreaming.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khanhduytran0/android-gl-streaming/b4895522e210f38a4b5ddc93f34ff05e4533e47a/www/GLStreaming.png
--------------------------------------------------------------------------------
/www/Screenshot_2020-05-19-09-42-24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khanhduytran0/android-gl-streaming/b4895522e210f38a4b5ddc93f34ff05e4533e47a/www/Screenshot_2020-05-19-09-42-24.png
--------------------------------------------------------------------------------
/www/gl-streaming_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/khanhduytran0/android-gl-streaming/b4895522e210f38a4b5ddc93f34ff05e4533e47a/www/gl-streaming_small.png
--------------------------------------------------------------------------------