Skip to content

Commit f5742fc

Browse files
committed
Merge pull request #74 from 9prady9/api_changes
API & Framework changes
2 parents af20b88 + b5f891a commit f5742fc

File tree

131 files changed

+9300
-5703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+9300
-5703
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ INCLUDE(${CMAKE_MODULE_PATH}/Version.cmake)
5353

5454
FIND_PACKAGE(OpenGL REQUIRED)
5555
FIND_PACKAGE(GLEWmx REQUIRED)
56-
IF(GLEWmx_FOUND AND OPENGL_FOUND)
56+
FIND_PACKAGE(FreeImage REQUIRED)
57+
IF(GLEWmx_FOUND AND OPENGL_FOUND AND FREEIMAGE_FOUND)
5758
ADD_DEFINITIONS(-DGLEW_MX)
5859
ELSE()
5960
IF(NOT GLEWmx_FOUND)
@@ -62,12 +63,16 @@ ELSE()
6263
IF(NOT OPENGL_FOUND)
6364
MESSAGE(FATAL_ERROR "OpenGL not found")
6465
ENDIF()
66+
IF(NOT FREEIMAGE_FOUND)
67+
MESSAGE(FATAL_ERROR "FreeImage not found")
68+
ENDIF()
6569
ENDIF()
6670

6771
INCLUDE_DIRECTORIES(
6872
"${PROJECT_SOURCE_DIR}/include"
6973
${OPENGL_INCLUDE_DIR}
7074
${GLEW_INCLUDE_DIR}
75+
${FREEIMAGE_INCLUDE_PATH}
7176
)
7277

7378
SET(X11_LIBS "")
@@ -77,7 +82,9 @@ IF(APPLE)
7782
SET(X11_LIBS ${X11_LIBRARIES})
7883
ENDIF(APPLE)
7984

80-
ADD_SUBDIRECTORY(src)
85+
ADD_EXECUTABLE(glsl2cpp "${CMAKE_MODULE_PATH}/glsl2cpp.cpp")
86+
87+
ADD_SUBDIRECTORY(src/backend/opengl)
8188

8289
IF(BUILD_EXAMPLES)
8390
ADD_SUBDIRECTORY(examples)

CMakeModules/FindFreeImage.cmake

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# Try to find the FreeImage library and include path.
3+
# Once done this will define
4+
#
5+
# FREEIMAGE_FOUND
6+
# FREEIMAGE_INCLUDE_PATH
7+
# FREEIMAGE_LIBRARY
8+
# FREEIMAGE_STATIC_LIBRARY
9+
# FREEIMAGE_DYNAMIC_LIBRARY
10+
#
11+
12+
OPTION(USE_FREEIMAGE_STATIC "Use Static FreeImage Lib" OFF)
13+
14+
FIND_PATH( FREEIMAGE_INCLUDE_PATH
15+
NAMES FreeImage.h
16+
HINTS ${PROJECT_SOURCE_DIR}/extern/FreeImage
17+
PATHS
18+
/usr/include
19+
/usr/local/include
20+
/sw/include
21+
/opt/local/include
22+
DOC "The directory where FreeImage.h resides")
23+
24+
FIND_LIBRARY( FREEIMAGE_DYNAMIC_LIBRARY
25+
NAMES FreeImage freeimage
26+
HINTS ${PROJECT_SOURCE_DIR}/FreeImage
27+
PATHS
28+
/usr/lib64
29+
/usr/lib
30+
/usr/local/lib64
31+
/usr/local/lib
32+
/sw/lib
33+
/opt/local/lib
34+
DOC "The FreeImage library")
35+
36+
SET(PX ${CMAKE_STATIC_LIBRARY_PREFIX})
37+
SET(SX ${CMAKE_STATIC_LIBRARY_SUFFIX})
38+
FIND_LIBRARY( FREEIMAGE_STATIC_LIBRARY
39+
NAMES ${PX}FreeImageLIB${SX} ${PX}FreeImage${SX} ${PX}freeimage${SX}
40+
HINTS ${PROJECT_SOURCE_DIR}/FreeImage
41+
PATHS
42+
/usr/lib64
43+
/usr/lib
44+
/usr/local/lib64
45+
/usr/local/lib
46+
/sw/lib
47+
/opt/local/lib
48+
DOC "The FreeImage library")
49+
UNSET(PX)
50+
UNSET(SX)
51+
52+
IF(USE_FREEIMAGE_STATIC)
53+
MESSAGE(STATUS "Using Static FreeImage Lib")
54+
ADD_DEFINITIONS(-DFREEIMAGE_LIB)
55+
SET(FREEIMAGE_LIBRARY ${FREEIMAGE_STATIC_LIBRARY})
56+
ELSE(USE_FREEIMAGE_STATIC)
57+
MESSAGE(STATUS "Using Dynamic FreeImage Lib")
58+
REMOVE_DEFINITIONS(-DFREEIMAGE_LIB)
59+
SET(FREEIMAGE_LIBRARY ${FREEIMAGE_DYNAMIC_LIBRARY})
60+
ENDIF(USE_FREEIMAGE_STATIC)
61+
62+
MARK_AS_ADVANCED(
63+
FREEIMAGE_DYNAMIC_LIBRARY
64+
FREEIMAGE_STATIC_LIBRARY
65+
)
66+
67+
INCLUDE(FindPackageHandleStandardArgs)
68+
69+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FREEIMAGE DEFAULT_MSG FREEIMAGE_INCLUDE_PATH FREEIMAGE_LIBRARY)

CMakeModules/GLSLtoH.cmake

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Function to turn an GLSL shader source file into a C string within a source file.
2+
# xxd uses its input's filename to name the string and its length, so we
3+
# need to move them to a name that depends only on the path output, not its
4+
# input. Otherwise, builds in different relative locations would put the
5+
# source into different variable names, and everything would fall over.
6+
# The actual name will be filename (.s replaced with underscores), and length
7+
# name_len.
8+
#
9+
# Usage example:
10+
#
11+
# set(KERNELS a.cl b/c.cl)
12+
# resource_to_cxx_source(
13+
# SOURCES ${KERNELS}
14+
# VARNAME OUTPUTS
15+
# )
16+
# add_executable(foo ${OUTPUTS})
17+
#
18+
# The namespace they are placed in is taken from filename.namespace.
19+
#
20+
# For example, if the input file is kernel.cl, the two variables will be
21+
# unsigned char ns::kernel_cl[];
22+
# unsigned int ns::kernel_cl_len;
23+
#
24+
# where ns is the contents of kernel.cl.namespace.
25+
26+
INCLUDE(CMakeParseArguments)
27+
28+
SET(GLSL2CPP_PROGRAM "glsl2cpp")
29+
30+
FUNCTION(GLSL_TO_H)
31+
CMAKE_PARSE_ARGUMENTS(RTCS "" "VARNAME;EXTENSION;OUTPUT_DIR;TARGETS;NAMESPACE;EOF" "SOURCES" ${ARGN})
32+
33+
SET(_output_files "")
34+
FOREACH(_input_file ${RTCS_SOURCES})
35+
GET_FILENAME_COMPONENT(_path "${_input_file}" PATH)
36+
GET_FILENAME_COMPONENT(_name "${_input_file}" NAME)
37+
GET_FILENAME_COMPONENT(var_name "${_input_file}" NAME_WE)
38+
39+
SET(_namespace "${RTCS_NAMESPACE}")
40+
STRING(REPLACE "." "_" var_name ${var_name})
41+
42+
SET(_output_path "${CMAKE_CURRENT_BINARY_DIR}/${RTCS_OUTPUT_DIR}")
43+
SET(_output_file "${_output_path}/${var_name}.${RTCS_EXTENSION}")
44+
45+
ADD_CUSTOM_COMMAND(
46+
OUTPUT ${_output_file}
47+
DEPENDS ${_input_file} ${GLSL2CPP_PROGRAM}
48+
COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_path}"
49+
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\<${_path}/${var_name}.hpp\\>" >>"${_output_file}"
50+
COMMAND ${GLSL2CPP_PROGRAM} --file ${_name} --namespace ${_namespace} --output ${_output_file} --name ${var_name} --eof ${RTCS_EOF}
51+
WORKING_DIRECTORY "${_path}"
52+
COMMENT "Converting ${_input_file} to GLSL source string"
53+
)
54+
55+
LIST(APPEND _output_files ${_output_file})
56+
ENDFOREACH()
57+
ADD_CUSTOM_TARGET(${RTCS_NAMESPACE}_bin_target DEPENDS ${_output_files})
58+
59+
SET("${RTCS_VARNAME}" ${_output_files} PARENT_SCOPE)
60+
SET("${RTCS_TARGETS}" ${RTCS_NAMESPACE}_bin_target PARENT_SCOPE)
61+
ENDFUNCTION(GLSL_TO_H)

CMakeModules/glsl2cpp.cpp

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// Umar Arshad
2+
// Copyright 2015-2019
3+
//
4+
// Modified by Pradeep Garigipati on Dec 30, 2015 for Forge
5+
// Purpose of modification: To use the program to convert
6+
// GLSL shader files into compile time constant string literals
7+
8+
#include <fstream>
9+
#include <sstream>
10+
#include <iostream>
11+
#include <string>
12+
#include <vector>
13+
#include <map>
14+
#include <memory>
15+
16+
using namespace std;
17+
typedef map<string, string> opt_t;
18+
19+
static
20+
void print_usage() {
21+
cout << R"delimiter(GLSL2CPP
22+
Converts OpenGL shader files to C++ headers. It is similar to bin2c and xxd but adds
23+
support for namespaces.
24+
25+
| --name | name of the variable (default: var) |
26+
| --file | input file |
27+
| --output | output file (If no output is specified then it prints to stdout) |
28+
| --type | Type of variable (default: char) |
29+
| --namespace | A space seperated list of namespaces |
30+
| --formatted | Tabs for formatting |
31+
| --version | Prints my name |
32+
| --help | Prints usage info |
33+
34+
Example
35+
-------
36+
Command:
37+
./glsl2cpp --file blah.txt --namespace shaders --formatted --name image_vs
38+
39+
Will produce the following:
40+
#pragma once
41+
#include <cstddef>
42+
namespace shaders {
43+
static const char image_vs[] = R"shader(
44+
#version 330
45+
46+
layout(location = 0) in vec3 pos;
47+
layout(location = 1) in vec2 tex;
48+
49+
uniform mat4 matrix;
50+
51+
out vec2 texcoord;
52+
53+
void main() {
54+
texcoord = tex;
55+
gl_Position = matrix * vec4(pos,1.0);
56+
}
57+
)shader";
58+
}
59+
)delimiter";
60+
exit(0);
61+
}
62+
63+
static bool formatted;
64+
65+
static
66+
void add_tabs(const int level)
67+
{
68+
if(formatted) {
69+
for(int i =0; i < level; i++) {
70+
cout << "\t";
71+
}
72+
}
73+
}
74+
75+
static
76+
opt_t parse_options(const vector<string>& args)
77+
{
78+
opt_t options;
79+
80+
options["--name"] = "";
81+
options["--type"] = "";
82+
options["--file"] = "";
83+
options["--output"] = "";
84+
options["--namespace"] = "";
85+
options["--eof"] = "";
86+
87+
//Parse Arguments
88+
string curr_opt;
89+
bool verbose = false;
90+
for(auto arg : args) {
91+
if(arg == "--verbose") {
92+
verbose = true;
93+
} else if(arg == "--formatted") {
94+
formatted = true;
95+
} else if(arg == "--version") {
96+
cout << args[0] << " Original Author: Umar Arshad;\n Modified later by: Pradeep Garigipati." << endl;
97+
} else if(arg == "--help") {
98+
print_usage();
99+
} else if(options.find(arg) != options.end()) {
100+
curr_opt = arg;
101+
} else if(curr_opt.empty()) {
102+
//cerr << "Invalid Argument: " << arg << endl;
103+
} else {
104+
if(options[curr_opt] != "") {
105+
options[curr_opt] += " " + arg;
106+
}
107+
else {
108+
options[curr_opt] += arg;
109+
}
110+
}
111+
}
112+
113+
if(verbose) {
114+
for(auto opts : options) {
115+
cout << get<0>(opts) << " " << get<1>(opts) << endl;
116+
}
117+
}
118+
return options;
119+
}
120+
121+
int main(int argc, const char * const * const argv)
122+
{
123+
124+
vector<string> args(argv, argv+argc);
125+
126+
opt_t&& options = parse_options(args);
127+
128+
//Save default cout buffer. Need this to prevent crash.
129+
auto bak = cout.rdbuf();
130+
unique_ptr<ofstream> outfile;
131+
132+
// Set defaults
133+
if(options["--name"] == "") { options["--name"] = "var"; }
134+
if(options["--output"] != "") {
135+
//redirect stream if output file is specified
136+
outfile.reset(new ofstream(options["--output"]));
137+
cout.rdbuf(outfile->rdbuf());
138+
}
139+
140+
cout << "#pragma once\n";
141+
cout << "#include <string>\n"; // defines std::string
142+
143+
int ns_cnt = 0;
144+
int level = 0;
145+
if(options["--namespace"] != "") {
146+
std::stringstream namespaces(options["--namespace"]);
147+
string name;
148+
namespaces >> name;
149+
do {
150+
add_tabs(level++);
151+
cout << "namespace " << name << "\n{\n";
152+
ns_cnt++;
153+
namespaces >> name;
154+
} while(!namespaces.fail());
155+
}
156+
157+
if(options["--type"] == "") {
158+
options["--type"] = "std::string";
159+
}
160+
add_tabs(level);
161+
cout << "static const " << options["--type"] << " " << options["--name"] << " = R\"shader(\n";
162+
level++;
163+
164+
ifstream input(options["--file"]);
165+
166+
for(std::string line; std::getline(input, line);) {
167+
add_tabs(level);
168+
cout << line << endl;
169+
}
170+
171+
if (options["--eof"].c_str()[0] == '1') {
172+
// Add end of file character
173+
cout << "0x0";
174+
}
175+
176+
add_tabs(--level);
177+
cout << ")shader\";\n";
178+
179+
while(ns_cnt--) {
180+
add_tabs(--level);
181+
cout << "}\n";
182+
}
183+
cout.rdbuf(bak);
184+
}

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ A prototype of the OpenGL interop library that can be used with ArrayFire. The g
1717
* On `Linux` and `OS X`, [fontconfig](http://www.freedesktop.org/wiki/Software/fontconfig/) is required.
1818

1919
Above dependencies are available through package managers on most of the Unix/Linux based distributions. We have provided an option in `CMake` for `Forge` to build it's own internal `freetype` version if you choose to not install it on your machine.
20+
21+
### Sample Images
22+
| | |
23+
|-----|-----|
24+
| <img src="./docs/images/image.png" width=150 height=100>Image</img> | <img src="./docs/images/plot.png" width=150 height=100>2D Plot</img> |
25+
| <img src="./docs/images/plot31.png" width=150 height=100>3d Plot</img> | <img src="./docs/images/plot32.png" width=150 height=100>Rotated 3d Plot</img> |
26+
| <img src="./docs/images/hist.png" width=150 height=100>histogram</img> | <img src="./docs/images/surface.png" width=150 height=100>Surface</img> |

docs/images/bubble.png

42.2 KB
Loading

docs/images/hist.png

218 KB
Loading

docs/images/image.png

17.4 KB
Loading

docs/images/plot.png

34.6 KB
Loading

docs/images/plot31.png

40.4 KB
Loading

0 commit comments

Comments
 (0)