Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API & Framework changes #74

Merged
merged 61 commits into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
83519f0
Reorganized code to enable multiple plot rendering
9prady9 Jan 18, 2016
c459539
code reorganization progress update
9prady9 Jan 19, 2016
4f8d944
code reorganization progress update
9prady9 Jan 20, 2016
3587caa
code reorganization finished
9prady9 Jan 21, 2016
42e95bc
Added documentation for Chart class
9prady9 Jan 21, 2016
697deb7
Added legend rendering for charts
9prady9 Jan 21, 2016
511737d
Removed hard coded point size from marker shader
9prady9 Jan 22, 2016
4be14d6
minimalistic interactivity support for windows
9prady9 Jan 25, 2016
9817068
virtual trackball rotations via interactions
9prady9 Jan 25, 2016
5bbadd0
Limit transformations to viewport
9prady9 Jan 26, 2016
f984fcf
Alpha blending for image renderable
9prady9 Jan 27, 2016
21a9a03
alpha blending for histogram, plots & surface
9prady9 Jan 27, 2016
5a73f5c
Fixed 2d & 3d plot classes hierarchy
9prady9 Feb 1, 2016
d569c0e
Moved axes labels to outside chart area
9prady9 Feb 1, 2016
c9e6f21
Corrected axes tick alignments w.r.t to ticks
9prady9 Feb 1, 2016
9acad90
support for per vertex marker size in scatter plots
9prady9 Feb 1, 2016
a32199c
Fixed alpha blending
9prady9 Feb 1, 2016
b2d5a6c
changes in marker shader equations to draw solid markers
9prady9 Feb 1, 2016
14fb507
bubble chart example for cpu backend
9prady9 Feb 1, 2016
9c175b1
Removed stray printfs used for debugging
9prady9 Feb 3, 2016
53875c1
Moved y-axis title in 2d plots to left finally :)
9prady9 Feb 3, 2016
95825ce
Corrected window names in examples
9prady9 Feb 3, 2016
12e367b
Updated README with sample images of renderables
9prady9 Feb 3, 2016
302a5e0
font glyph packing finished
9prady9 Feb 6, 2016
5fc72ca
Changed outline stroke parameters for font rendering
9prady9 Feb 8, 2016
d572d1b
Added copyright notice related to font_atlas.cpp file
9prady9 Feb 9, 2016
9ebd08f
Changed orientation of characters in vertical axes labels
9prady9 Feb 10, 2016
51a3cc9
Support for shader utility fns to handle geometry shaders
9prady9 Feb 12, 2016
9ae7cda
fixed 2d plot rendering overflow into axes area
9prady9 Feb 13, 2016
f3bda20
Changed chart colors
9prady9 Feb 13, 2016
33266c0
Moved legend renderings to last stage of chart pipeline
9prady9 Feb 13, 2016
9283f51
Added grid lines in 2d charts for better visibility of plot points
9prady9 Feb 13, 2016
9b0dacc
added grid lines in 3d charts
9prady9 Feb 13, 2016
cbafba1
typo fix in release mode code stub
9prady9 Feb 19, 2016
de7fe51
Corrected the name of a color array variable
9prady9 Feb 20, 2016
f76d2fb
Renamed CUDA error check macro in CUDA copy helper header
9prady9 Feb 23, 2016
4927ab7
Changed cpu-copy helper fn's to non-template versions
9prady9 Feb 23, 2016
8b3b756
Added default fonts for window
9prady9 Feb 23, 2016
c04b609
Moved typedefs to namespace fg
9prady9 Feb 23, 2016
2c481e7
Removed std::string from API headers
9prady9 Feb 23, 2016
ad85ef7
Removed std::vector from API headers
9prady9 Feb 23, 2016
9d7e0ee
Support to programmatically save framebuffer to disk
9prady9 Feb 23, 2016
67b6961
Fixed the order of rendering in charts
9prady9 Feb 23, 2016
6d89f5c
Removed double-buffer PBO mechanism from widgets
9prady9 Feb 23, 2016
f06f4cb
Reorganized to enable easy addition of C-API and new backends
9prady9 Mar 3, 2016
a49ffec
Fixed typo in glfw toolkit for opengl backend
9prady9 Mar 3, 2016
d75064b
Added cmake options to turn off building cuda/opencl examples
9prady9 Mar 3, 2016
b4c70b0
Fixed histogram example for all backends
9prady9 Mar 4, 2016
d84f805
Corrected depth related state variables for alpha blending
9prady9 Mar 4, 2016
f58fda0
Enable depth testing globally
9prady9 Mar 4, 2016
d437188
Add checks for transparency code in surface
9prady9 Mar 4, 2016
a00d91f
Change CPU surface example to be static rendering
9prady9 Mar 4, 2016
5f55b1c
typo fixes
9prady9 Mar 8, 2016
3c32c27
Changed FG_ERR_FREEIMAGE_* enum values to be sequential
9prady9 Mar 8, 2016
041532d
Added const qualifier for fg_* handles in C-API
9prady9 Mar 8, 2016
84ea778
Added c-style handle based construtors for common::* classes
9prady9 Mar 8, 2016
3e40cc9
Moved common chart renderable's methods into base class
9prady9 Mar 13, 2016
515de5f
Fix CUDA & OpenCL histogram examples
9prady9 Mar 24, 2016
67fa20c
Change CUDA & OpenCL examples to be consistent with CPU
9prady9 Mar 24, 2016
e912de2
Rename enums
9prady9 Mar 25, 2016
b5f891a
rename types enum
9prady9 Mar 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ INCLUDE(${CMAKE_MODULE_PATH}/Version.cmake)

FIND_PACKAGE(OpenGL REQUIRED)
FIND_PACKAGE(GLEWmx REQUIRED)
IF(GLEWmx_FOUND AND OPENGL_FOUND)
FIND_PACKAGE(FreeImage REQUIRED)
IF(GLEWmx_FOUND AND OPENGL_FOUND AND FREEIMAGE_FOUND)
ADD_DEFINITIONS(-DGLEW_MX)
ELSE()
IF(NOT GLEWmx_FOUND)
Expand All @@ -62,12 +63,16 @@ ELSE()
IF(NOT OPENGL_FOUND)
MESSAGE(FATAL_ERROR "OpenGL not found")
ENDIF()
IF(NOT FREEIMAGE_FOUND)
MESSAGE(FATAL_ERROR "FreeImage not found")
ENDIF()
ENDIF()

INCLUDE_DIRECTORIES(
"${PROJECT_SOURCE_DIR}/include"
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${FREEIMAGE_INCLUDE_PATH}
)

SET(X11_LIBS "")
Expand All @@ -77,7 +82,9 @@ IF(APPLE)
SET(X11_LIBS ${X11_LIBRARIES})
ENDIF(APPLE)

ADD_SUBDIRECTORY(src)
ADD_EXECUTABLE(glsl2cpp "${CMAKE_MODULE_PATH}/glsl2cpp.cpp")

ADD_SUBDIRECTORY(src/backend/opengl)

IF(BUILD_EXAMPLES)
ADD_SUBDIRECTORY(examples)
Expand Down
69 changes: 69 additions & 0 deletions CMakeModules/FindFreeImage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# Try to find the FreeImage library and include path.
# Once done this will define
#
# FREEIMAGE_FOUND
# FREEIMAGE_INCLUDE_PATH
# FREEIMAGE_LIBRARY
# FREEIMAGE_STATIC_LIBRARY
# FREEIMAGE_DYNAMIC_LIBRARY
#

OPTION(USE_FREEIMAGE_STATIC "Use Static FreeImage Lib" OFF)

FIND_PATH( FREEIMAGE_INCLUDE_PATH
NAMES FreeImage.h
HINTS ${PROJECT_SOURCE_DIR}/extern/FreeImage
PATHS
/usr/include
/usr/local/include
/sw/include
/opt/local/include
DOC "The directory where FreeImage.h resides")

FIND_LIBRARY( FREEIMAGE_DYNAMIC_LIBRARY
NAMES FreeImage freeimage
HINTS ${PROJECT_SOURCE_DIR}/FreeImage
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
DOC "The FreeImage library")

SET(PX ${CMAKE_STATIC_LIBRARY_PREFIX})
SET(SX ${CMAKE_STATIC_LIBRARY_SUFFIX})
FIND_LIBRARY( FREEIMAGE_STATIC_LIBRARY
NAMES ${PX}FreeImageLIB${SX} ${PX}FreeImage${SX} ${PX}freeimage${SX}
HINTS ${PROJECT_SOURCE_DIR}/FreeImage
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
DOC "The FreeImage library")
UNSET(PX)
UNSET(SX)

IF(USE_FREEIMAGE_STATIC)
MESSAGE(STATUS "Using Static FreeImage Lib")
ADD_DEFINITIONS(-DFREEIMAGE_LIB)
SET(FREEIMAGE_LIBRARY ${FREEIMAGE_STATIC_LIBRARY})
ELSE(USE_FREEIMAGE_STATIC)
MESSAGE(STATUS "Using Dynamic FreeImage Lib")
REMOVE_DEFINITIONS(-DFREEIMAGE_LIB)
SET(FREEIMAGE_LIBRARY ${FREEIMAGE_DYNAMIC_LIBRARY})
ENDIF(USE_FREEIMAGE_STATIC)

MARK_AS_ADVANCED(
FREEIMAGE_DYNAMIC_LIBRARY
FREEIMAGE_STATIC_LIBRARY
)

INCLUDE(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(FREEIMAGE DEFAULT_MSG FREEIMAGE_INCLUDE_PATH FREEIMAGE_LIBRARY)
61 changes: 61 additions & 0 deletions CMakeModules/GLSLtoH.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Function to turn an GLSL shader source file into a C string within a source file.
# xxd uses its input's filename to name the string and its length, so we
# need to move them to a name that depends only on the path output, not its
# input. Otherwise, builds in different relative locations would put the
# source into different variable names, and everything would fall over.
# The actual name will be filename (.s replaced with underscores), and length
# name_len.
#
# Usage example:
#
# set(KERNELS a.cl b/c.cl)
# resource_to_cxx_source(
# SOURCES ${KERNELS}
# VARNAME OUTPUTS
# )
# add_executable(foo ${OUTPUTS})
#
# The namespace they are placed in is taken from filename.namespace.
#
# For example, if the input file is kernel.cl, the two variables will be
# unsigned char ns::kernel_cl[];
# unsigned int ns::kernel_cl_len;
#
# where ns is the contents of kernel.cl.namespace.

INCLUDE(CMakeParseArguments)

SET(GLSL2CPP_PROGRAM "glsl2cpp")

FUNCTION(GLSL_TO_H)
CMAKE_PARSE_ARGUMENTS(RTCS "" "VARNAME;EXTENSION;OUTPUT_DIR;TARGETS;NAMESPACE;EOF" "SOURCES" ${ARGN})

SET(_output_files "")
FOREACH(_input_file ${RTCS_SOURCES})
GET_FILENAME_COMPONENT(_path "${_input_file}" PATH)
GET_FILENAME_COMPONENT(_name "${_input_file}" NAME)
GET_FILENAME_COMPONENT(var_name "${_input_file}" NAME_WE)

SET(_namespace "${RTCS_NAMESPACE}")
STRING(REPLACE "." "_" var_name ${var_name})

SET(_output_path "${CMAKE_CURRENT_BINARY_DIR}/${RTCS_OUTPUT_DIR}")
SET(_output_file "${_output_path}/${var_name}.${RTCS_EXTENSION}")

ADD_CUSTOM_COMMAND(
OUTPUT ${_output_file}
DEPENDS ${_input_file} ${GLSL2CPP_PROGRAM}
COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_path}"
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\<${_path}/${var_name}.hpp\\>" >>"${_output_file}"
COMMAND ${GLSL2CPP_PROGRAM} --file ${_name} --namespace ${_namespace} --output ${_output_file} --name ${var_name} --eof ${RTCS_EOF}
WORKING_DIRECTORY "${_path}"
COMMENT "Converting ${_input_file} to GLSL source string"
)

LIST(APPEND _output_files ${_output_file})
ENDFOREACH()
ADD_CUSTOM_TARGET(${RTCS_NAMESPACE}_bin_target DEPENDS ${_output_files})

SET("${RTCS_VARNAME}" ${_output_files} PARENT_SCOPE)
SET("${RTCS_TARGETS}" ${RTCS_NAMESPACE}_bin_target PARENT_SCOPE)
ENDFUNCTION(GLSL_TO_H)
184 changes: 184 additions & 0 deletions CMakeModules/glsl2cpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Umar Arshad
// Copyright 2015-2019
//
// Modified by Pradeep Garigipati on Dec 30, 2015 for Forge
// Purpose of modification: To use the program to convert
// GLSL shader files into compile time constant string literals

#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <memory>

using namespace std;
typedef map<string, string> opt_t;

static
void print_usage() {
cout << R"delimiter(GLSL2CPP
Converts OpenGL shader files to C++ headers. It is similar to bin2c and xxd but adds
support for namespaces.

| --name | name of the variable (default: var) |
| --file | input file |
| --output | output file (If no output is specified then it prints to stdout) |
| --type | Type of variable (default: char) |
| --namespace | A space seperated list of namespaces |
| --formatted | Tabs for formatting |
| --version | Prints my name |
| --help | Prints usage info |

Example
-------
Command:
./glsl2cpp --file blah.txt --namespace shaders --formatted --name image_vs

Will produce the following:
#pragma once
#include <cstddef>
namespace shaders {
static const char image_vs[] = R"shader(
#version 330

layout(location = 0) in vec3 pos;
layout(location = 1) in vec2 tex;

uniform mat4 matrix;

out vec2 texcoord;

void main() {
texcoord = tex;
gl_Position = matrix * vec4(pos,1.0);
}
)shader";
}
)delimiter";
exit(0);
}

static bool formatted;

static
void add_tabs(const int level)
{
if(formatted) {
for(int i =0; i < level; i++) {
cout << "\t";
}
}
}

static
opt_t parse_options(const vector<string>& args)
{
opt_t options;

options["--name"] = "";
options["--type"] = "";
options["--file"] = "";
options["--output"] = "";
options["--namespace"] = "";
options["--eof"] = "";

//Parse Arguments
string curr_opt;
bool verbose = false;
for(auto arg : args) {
if(arg == "--verbose") {
verbose = true;
} else if(arg == "--formatted") {
formatted = true;
} else if(arg == "--version") {
cout << args[0] << " Original Author: Umar Arshad;\n Modified later by: Pradeep Garigipati." << endl;
} else if(arg == "--help") {
print_usage();
} else if(options.find(arg) != options.end()) {
curr_opt = arg;
} else if(curr_opt.empty()) {
//cerr << "Invalid Argument: " << arg << endl;
} else {
if(options[curr_opt] != "") {
options[curr_opt] += " " + arg;
}
else {
options[curr_opt] += arg;
}
}
}

if(verbose) {
for(auto opts : options) {
cout << get<0>(opts) << " " << get<1>(opts) << endl;
}
}
return options;
}

int main(int argc, const char * const * const argv)
{

vector<string> args(argv, argv+argc);

opt_t&& options = parse_options(args);

//Save default cout buffer. Need this to prevent crash.
auto bak = cout.rdbuf();
unique_ptr<ofstream> outfile;

// Set defaults
if(options["--name"] == "") { options["--name"] = "var"; }
if(options["--output"] != "") {
//redirect stream if output file is specified
outfile.reset(new ofstream(options["--output"]));
cout.rdbuf(outfile->rdbuf());
}

cout << "#pragma once\n";
cout << "#include <string>\n"; // defines std::string

int ns_cnt = 0;
int level = 0;
if(options["--namespace"] != "") {
std::stringstream namespaces(options["--namespace"]);
string name;
namespaces >> name;
do {
add_tabs(level++);
cout << "namespace " << name << "\n{\n";
ns_cnt++;
namespaces >> name;
} while(!namespaces.fail());
}

if(options["--type"] == "") {
options["--type"] = "std::string";
}
add_tabs(level);
cout << "static const " << options["--type"] << " " << options["--name"] << " = R\"shader(\n";
level++;

ifstream input(options["--file"]);

for(std::string line; std::getline(input, line);) {
add_tabs(level);
cout << line << endl;
}

if (options["--eof"].c_str()[0] == '1') {
// Add end of file character
cout << "0x0";
}

add_tabs(--level);
cout << ")shader\";\n";

while(ns_cnt--) {
add_tabs(--level);
cout << "}\n";
}
cout.rdbuf(bak);
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ A prototype of the OpenGL interop library that can be used with ArrayFire. The g
* On `Linux` and `OS X`, [fontconfig](http://www.freedesktop.org/wiki/Software/fontconfig/) is required.

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.

### Sample Images
| | |
|-----|-----|
| <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> |
| <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> |
| <img src="./docs/images/hist.png" width=150 height=100>histogram</img> | <img src="./docs/images/surface.png" width=150 height=100>Surface</img> |
Binary file added docs/images/bubble.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/hist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/plot31.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/plot32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/surface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions docs/pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ install it on your machine.

We plan to provide support for alternatives to GLFW as windowing toolkit,
however GLFW is the default option. Should you chose to use an alternative, you
have to chose it explicity.
have to chose it explicity while building forge.

Alternatives to GLFW which are currently under consideration are given below:
Currently supported alternatives:
* [SDL2](https://www.libsdl.org/download-2.0.php)

Alternatives to GLFW which are currently under consideration are given below:
* [Qt5](https://wiki.qt.io/Qt_5)

#### Email
Expand Down
Loading