diff --git a/CMakeLists.txt b/CMakeLists.txt index b1a8d529..2f2b4c9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.0) PROJECT(FORGE) SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) @@ -51,27 +51,12 @@ ENDIF(UNIX) INCLUDE(${CMAKE_MODULE_PATH}/Version.cmake) -FIND_PACKAGE(OpenGL REQUIRED) -FIND_PACKAGE(GLEWmx REQUIRED) FIND_PACKAGE(FreeImage REQUIRED) -IF(GLEWmx_FOUND AND OPENGL_FOUND AND FREEIMAGE_FOUND) - ADD_DEFINITIONS(-DGLEW_MX) -ELSE() - IF(NOT GLEWmx_FOUND) - MESSAGE(FATAL_ERROR "GLEW-MX not found") - ENDIF() - IF(NOT OPENGL_FOUND) - MESSAGE(FATAL_ERROR "OpenGL not found") - ENDIF() - IF(NOT FREEIMAGE_FOUND) - MESSAGE(FATAL_ERROR "FreeImage not found") - ENDIF() -ENDIF() +FIND_PACKAGE(OpenGL REQUIRED) INCLUDE_DIRECTORIES( "${PROJECT_SOURCE_DIR}/include" ${OPENGL_INCLUDE_DIR} - ${GLEW_INCLUDE_DIR} ${FREEIMAGE_INCLUDE_PATH} ) @@ -100,7 +85,7 @@ ENDIF(BUILD_DOCUMENTATION) #-------------------------------------------------------------------- INCLUDE(CMakePackageConfigHelpers) -configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/ForgeConfig.cmake.in" +configure_package_config_file("${CMAKE_MODULE_PATH}/ForgeConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/ForgeConfig.cmake" INSTALL_DESTINATION ${FG_INSTALL_CMAKE_DIR} PATH_VARS CMAKE_INSTALL_PREFIX diff --git a/ForgeConfig.cmake.in b/CMakeModules/ForgeConfig.cmake.in similarity index 100% rename from ForgeConfig.cmake.in rename to CMakeModules/ForgeConfig.cmake.in diff --git a/ForgeConfigVersion.cmake.in b/CMakeModules/ForgeConfigVersion.cmake.in similarity index 100% rename from ForgeConfigVersion.cmake.in rename to CMakeModules/ForgeConfigVersion.cmake.in diff --git a/CMakeModules/build_glbinding.cmake b/CMakeModules/build_glbinding.cmake new file mode 100644 index 00000000..e77bfce3 --- /dev/null +++ b/CMakeModules/build_glbinding.cmake @@ -0,0 +1,57 @@ +INCLUDE(ExternalProject) + +SET(prefix ${CMAKE_BINARY_DIR}/third_party/glb) + +SET(LIB_POSTFIX "") +IF (${CMAKE_BUILD_TYPE} STREQUAL "Debug") + SET(LIB_POSTFIX "d") +ENDIF() + +SET(glbinding_location ${prefix}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}glbinding${LIB_POSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}) + +IF(CMAKE_VERSION VERSION_LESS 3.2) + IF(CMAKE_GENERATOR MATCHES "Ninja") + MESSAGE(WARNING "Building with Ninja has known issues with CMake older than 3.2") + endif() + SET(byproducts) +ELSE() + SET(byproducts BYPRODUCTS ${glbinding_location}) +ENDIF() + +IF(UNIX) + SET(CXXFLAGS "${CMAKE_CXX_FLAGS} -w -fPIC") + SET(CFLAGS "${CMAKE_C_FLAGS} -w -fPIC") +ENDIF(UNIX) + +ExternalProject_Add( + glb-ext + GIT_REPOSITORY https://github.com/cginternals/glbinding.git + GIT_TAG v2.1.1 + UPDATE_COMMAND "" + PREFIX "${prefix}" + INSTALL_DIR "${prefix}" + CONFIGURE_COMMAND ${CMAKE_COMMAND} -Wno-dev "-G${CMAKE_GENERATOR}" + -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} + -DCMAKE_CXX_FLAGS:STRING=${CXXFLAGS} + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} + -DCMAKE_C_FLAGS:STRING=${CFLAGS} + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX:PATH= + -DBUILD_SHARED_LIBS:BOOL=OFF + -DOPTION_BUILD_TESTS:BOOL=OFF + -DGLFW_LIBRARY_RELEASE:PATH=${GLFW_LIBRARY} + -DGLFW_LIBRARY_DEBUG:PATH=${GLFW_LIBRARY} + ${byproducts} + ) + +ADD_LIBRARY(glbinding IMPORTED STATIC) + +ExternalProject_Get_Property(glb-ext install_dir) + +SET_TARGET_PROPERTIES(glbinding PROPERTIES IMPORTED_LOCATION ${glbinding_location}) + +ADD_DEPENDENCIES(glbinding glb-ext) + +SET(GLBINDING_INCLUDE_DIRS ${install_dir}/include CACHE INTERNAL "" FORCE) +SET(GLBINDING_LIBRARIES ${glbinding_location} CACHE INTERNAL "" FORCE) +SET(GLBINDING_FOUND ON CACHE INTERNAL "" FORCE) diff --git a/docs/pages/README.md b/docs/pages/README.md index c02c27a1..33001dcd 100644 --- a/docs/pages/README.md +++ b/docs/pages/README.md @@ -10,9 +10,10 @@ goal of Forge is to provide high performance OpenGL visualizations for C/C++ applications that use CUDA/OpenCL. ## Upstream dependencies -* [GLEW](http://glew.sourceforge.net/) +* [glbinding](https://github.com/cginternals/glbinding) * [GLFW](http://www.glfw.org/) * [freetype](http://www.freetype.org/) +* [FreeImage](http://freeimage.sourceforge.net/) * On `Linux` and `OS X`, [fontconfig](http://www.freedesktop.org/wiki/Software/fontconfig/) is required. Above dependecies are available through package managers on most of the @@ -30,5 +31,13 @@ Currently supported alternatives: Alternatives to GLFW which are currently under consideration are given below: * [Qt5](https://wiki.qt.io/Qt_5) +## Example Dependencies +* CPU examples doesn't need any additional dependencies. +* CUDA Interop examples requires [CUDA toolkit](https://developer.nvidia.com/cuda-toolkit) +* OpenCL Interop examples requires OpenCL libraries. + - [AMD](http://developer.amd.com/tools-and-sdks/opencl-zone/) + - [INTEL](https://software.intel.com/en-us/intel-opencl) + - [NVIDIA](https://developer.nvidia.com/opencl) + #### Email * Engineering: technical@arrayfire.com diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 524ddc8b..21d23d73 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -27,29 +27,35 @@ MACRO(BUILD_EXAMPLE EX_NAME EX_SRC COMPUTE_NAME FG_LIBS COMPUTE_LIBS) ENDMACRO() IF(TARGET forge) + # Building with Forge Source SET(FORGE_FOUND False) + ELSE(TARGET forge) + SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) - FIND_PACKAGE(GLEWmx REQUIRED) FIND_PACKAGE(FreeImage REQUIRED) FIND_PACKAGE(OpenGL REQUIRED) FIND_PACKAGE(Forge REQUIRED) + SET(X11_LIBS "") - IF(APPLE) - FIND_PACKAGE(X11 REQUIRED) - INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR}) - ENDIF(APPLE) + INCLUDE_DIRECTORIES( ${FORGE_INCLUDE_DIRS} - ${OPENGL_INCLUDE_DIR} - ${GLEW_INCLUDE_DIR} ${FREEIMAGE_INCLUDE_PATH} ) - ADD_DEFINITIONS(-DGLEW_MX) + # OS Definitions IF(UNIX) ADD_DEFINITIONS(-Wall -std=c++11 -fvisibility=hidden) + + # GCC 5.3 and above give errors for mempcy from + # This is a (temporary) fix for that + IF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.3.0") + ADD_DEFINITIONS(-D_FORCE_INLINES) + ENDIF() + + # MacOS specific environment settings IF(APPLE) ADD_DEFINITIONS(-DOS_MAC) SET(CMAKE_MACOSX_RPATH ON) @@ -62,6 +68,10 @@ ELSE(TARGET forge) IF("${isSystemDir}" STREQUAL "-1") SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}") ENDIF("${isSystemDir}" STREQUAL "-1") + + FIND_PACKAGE(X11 REQUIRED) + INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR}) + ELSE(APPLE) ADD_DEFINITIONS(-DOS_LNX) ENDIF(APPLE) @@ -70,6 +80,10 @@ ELSE(TARGET forge) ENDIF(UNIX) ENDIF(TARGET forge) +IF(UNIX) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-unused-function") +ENDIF() + FILE(GLOB CPU_EXAMPLE_SRC_FILES "cpu/*.cpp") FOREACH(FILE ${CPU_EXAMPLE_SRC_FILES}) GET_FILENAME_COMPONENT(EXAMPLE ${FILE} NAME_WE) @@ -78,10 +92,10 @@ FOREACH(FILE ${CPU_EXAMPLE_SRC_FILES}) IF(TARGET forge) BUILD_EXAMPLE(${EXAMPLE} ${FILE} ${DIR_NAME} forge - "${FREEIMAGE_LIBRARY};${GLEWmx_LIBRARY};${OPENGL_gl_LIBRARY}") + "${FREEIMAGE_LIBRARY};${OPENGL_gl_LIBRARY}") ELSE(TARGET forge) BUILD_EXAMPLE(${EXAMPLE} ${FILE} ${DIR_NAME} ${FORGE_LIBRARIES} - "${FREEIMAGE_LIBRARY};${GLEWmx_LIBRARY};${OPENGL_gl_LIBRARY};${X11_LIBS};") + "${FREEIMAGE_LIBRARY};${OPENGL_gl_LIBRARY};${X11_LIBS};") ENDIF() ENDFOREACH() @@ -116,7 +130,7 @@ IF (BUILD_EXAMPLES_CUDA) "${FREEIMAGE_LIBRARY};${CUDA_LIBRARIES}") ELSE(TARGET forge) BUILD_EXAMPLE(${EXAMPLE} ${FILE} ${DIR_NAME} ${FORGE_LIBRARIES} - "${FREEIMAGE_LIBRARY};${GLEWmx_LIBRARY};${OPENGL_gl_LIBRARY};${X11_LIBS};${CUDA_LIBRARIES}") + "${FREEIMAGE_LIBRARY};${OPENGL_gl_LIBRARY};${X11_LIBS};${CUDA_LIBRARIES}") ENDIF() ENDFOREACH() ELSE() @@ -127,9 +141,6 @@ ENDIF() IF (BUILD_EXAMPLES_OPENCL) FIND_PACKAGE(OpenCL QUIET) IF(OpenCL_FOUND) - IF(UNIX) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-unused-function") - ENDIF() FILE(GLOB OpenCL_EXAMPLE_SRC_FILES "opencl/*.cpp") INCLUDE_DIRECTORIES( "${CMAKE_CURRENT_SOURCE_DIR}/opencl" @@ -143,10 +154,10 @@ IF (BUILD_EXAMPLES_OPENCL) IF(TARGET forge) BUILD_EXAMPLE(${EXAMPLE} ${FILE} ${DIR_NAME} forge - "${FREEIMAGE_LIBRARY};${GLEWmx_LIBRARY};${OPENGL_gl_LIBRARY};${OpenCL_LIBRARIES}") + "${FREEIMAGE_LIBRARY};${OPENGL_gl_LIBRARY};${OpenCL_LIBRARIES}") ELSE(TARGET forge) BUILD_EXAMPLE(${EXAMPLE} ${FILE} ${DIR_NAME} ${FORGE_LIBRARIES} - "${FREEIMAGE_LIBRARY};${GLEWmx_LIBRARY};${OPENGL_gl_LIBRARY};${X11_LIBS};${OpenCL_LIBRARIES}") + "${FREEIMAGE_LIBRARY};${OPENGL_gl_LIBRARY};${X11_LIBS};${OpenCL_LIBRARIES}") ENDIF() ENDFOREACH() ELSE() diff --git a/examples/cpu/bubblechart.cpp b/examples/cpu/bubblechart.cpp index 855fc42e..eff77da1 100644 --- a/examples/cpu/bubblechart.cpp +++ b/examples/cpu/bubblechart.cpp @@ -69,20 +69,20 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Bubble chart with Transparency Demo"); + forge::Window wnd(DIMX, DIMY, "Bubble chart with Transparency Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_2D); + forge::Chart chart(FG_CHART_2D); chart.setAxesLimits(FRANGE_START, FRANGE_END, -1.0f, 1.0f); /* Create several plot objects which creates the necessary * vertex buffer objects to hold the different plot types */ - fg::Plot plt1 = chart.plot(cosData.size()/2, fg::f32, + forge::Plot plt1 = chart.plot(cosData.size()/2, forge::f32, FG_PLOT_LINE, FG_MARKER_TRIANGLE); //or specify a specific plot type - fg::Plot plt2 = chart.plot(tanData.size()/2, fg::f32, + forge::Plot plt2 = chart.plot(tanData.size()/2, forge::f32, FG_PLOT_LINE, FG_MARKER_CIRCLE); //last parameter specifies marker shape /* Set plot colors */ @@ -94,7 +94,7 @@ int main(void) /* set plot global marker size */ plt1.setMarkerSize(20); /* copy your data into the opengl buffer object exposed by - * fg::Plot class and then proceed to rendering. + * forge::Plot class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/cpu/field.cpp b/examples/cpu/field.cpp index ffcba2fc..684ce031 100644 --- a/examples/cpu/field.cpp +++ b/examples/cpu/field.cpp @@ -47,21 +47,21 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Vector Field Demo"); + forge::Window wnd(DIMX, DIMY, "Vector Field Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_2D); + forge::Chart chart(FG_CHART_2D); chart.setAxesLimits(MINIMUM-1.0f, MAXIMUM, MINIMUM-1.0f, MAXIMUM); chart.setAxesTitles("x-axis", "y-axis"); - fg::Plot divPoints = chart.plot(4, fg::u32, FG_PLOT_SCATTER, FG_MARKER_CIRCLE); + forge::Plot divPoints = chart.plot(4, forge::u32, FG_PLOT_SCATTER, FG_MARKER_CIRCLE); divPoints.setColor(0.9f, 0.9f, 0.0f, 1.f); divPoints.setLegend("Convergence Points"); divPoints.setMarkerSize(24); - fg::VectorField field = chart.vectorField(NELEMS*NELEMS, fg::f32); + forge::VectorField field = chart.vectorField(NELEMS*NELEMS, forge::f32); field.setColor(0.f, 0.6f, 0.3f, 1.f); std::vector points; diff --git a/examples/cpu/fractal.cpp b/examples/cpu/fractal.cpp index 74a9970e..18789716 100644 --- a/examples/cpu/fractal.cpp +++ b/examples/cpu/fractal.cpp @@ -34,9 +34,9 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Fractal Demo"); + forge::Window wnd(DIMX, DIMY, "Fractal Demo"); wnd.makeCurrent(); /* create an font object and load necessary font @@ -45,7 +45,7 @@ int main(void) * * NOTE: THIS IS OPTIONAL STEP, BY DEFAULT WINDOW WILL * HAVE FONT ALREADY SETUP*/ - fg::Font fnt; + forge::Font fnt; #ifdef OS_WIN fnt.loadSystemFont("Calibri"); #else @@ -56,9 +56,9 @@ int main(void) /* Create an image object which creates the necessary * textures and pixel buffer objects to hold the image * */ - fg::Image img(DIMX, DIMY, FG_RGBA, fg::u8); + forge::Image img(DIMX, DIMY, FG_RGBA, forge::u8); /* copy your data into the pixel buffer object exposed by - * fg::Image class and then proceed to rendering. + * forge::Image class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/cpu/histogram.cpp b/examples/cpu/histogram.cpp index 66e14379..c719575c 100644 --- a/examples/cpu/histogram.cpp +++ b/examples/cpu/histogram.cpp @@ -57,9 +57,9 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Histogram Demo"); + forge::Window wnd(DIMX, DIMY, "Histogram Demo"); wnd.makeCurrent(); /* @@ -67,9 +67,9 @@ int main(void) */ wnd.grid(WIN_ROWS, WIN_COLS); - fg::Image img(IMGW, IMGH, FG_RGBA, fg::u8); + forge::Image img(IMGW, IMGH, FG_RGBA, forge::u8); - fg::Chart chart(FG_CHART_2D); + forge::Chart chart(FG_CHART_2D); /* set x axis limits to maximum and minimum values of data * and y axis limits to range [0, number of pixels ideally] * but practically total number of pixels as y range will skew @@ -80,7 +80,7 @@ int main(void) /* * Create histogram object specifying number of bins */ - fg::Histogram hist = chart.histogram(NBINS, fg::s32); + forge::Histogram hist = chart.histogram(NBINS, forge::s32); /* * Set histogram colors */ @@ -101,10 +101,10 @@ int main(void) copyToGLBuffer(handles[0], (ComputeResourceHandle)bmp.ptr, img.size()); - //fg::copy(img, (const void*)bmp.ptr); + //forge::copy(img, (const void*)bmp.ptr); /* copy your data into the vertex buffer object exposed by - * fg::Histogram class and then proceed to rendering. + * forge::Histogram class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/cpu/plot3.cpp b/examples/cpu/plot3.cpp index 1515ef14..36526603 100644 --- a/examples/cpu/plot3.cpp +++ b/examples/cpu/plot3.cpp @@ -42,16 +42,16 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Three dimensional line plot demo"); + forge::Window wnd(DIMX, DIMY, "Three dimensional line plot demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_3D); + forge::Chart chart(FG_CHART_3D); chart.setAxesLimits(-1.1f, 1.1f, -1.1f, 1.1f, 0.f, 10.f); chart.setAxesTitles("x-axis", "y-axis", "z-axis"); - fg::Plot plot3 = chart.plot(ZSIZE, fg::f32); + forge::Plot plot3 = chart.plot(ZSIZE, forge::f32); //generate a surface std::vector function; @@ -62,7 +62,7 @@ int main(void) createGLBuffer(&handle, plot3.vertices(), FORGE_VBO); /* copy your data into the pixel buffer object exposed by - * fg::Plot class and then proceed to rendering. + * forge::Plot class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/cpu/plotting.cpp b/examples/cpu/plotting.cpp index 52cf1be1..e042f37a 100644 --- a/examples/cpu/plotting.cpp +++ b/examples/cpu/plotting.cpp @@ -47,21 +47,21 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Plotting Demo"); + forge::Window wnd(DIMX, DIMY, "Plotting Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_2D); + forge::Chart chart(FG_CHART_2D); chart.setAxesLimits(FRANGE_START, FRANGE_END, -1.0f, 1.0f); /* Create several plot objects which creates the necessary * vertex buffer objects to hold the different plot types */ - fg::Plot plt0 = chart.plot(sinData.size()/2, fg::f32); //create a default plot - fg::Plot plt1 = chart.plot(cosData.size()/2, fg::f32, FG_PLOT_LINE, FG_MARKER_NONE); //or specify a specific plot type - fg::Plot plt2 = chart.plot(tanData.size()/2, fg::f32, FG_PLOT_LINE, FG_MARKER_TRIANGLE); //last parameter specifies marker shape - fg::Plot plt3 = chart.plot(logData.size()/2, fg::f32, FG_PLOT_SCATTER, FG_MARKER_CROSS); + forge::Plot plt0 = chart.plot(sinData.size()/2, forge::f32); //create a default plot + forge::Plot plt1 = chart.plot(cosData.size()/2, forge::f32, FG_PLOT_LINE, FG_MARKER_NONE); //or specify a specific plot type + forge::Plot plt2 = chart.plot(tanData.size()/2, forge::f32, FG_PLOT_LINE, FG_MARKER_TRIANGLE); //last parameter specifies marker shape + forge::Plot plt3 = chart.plot(logData.size()/2, forge::f32, FG_PLOT_SCATTER, FG_MARKER_CROSS); /* * Set plot colors @@ -69,7 +69,7 @@ int main(void) plt0.setColor(FG_RED); plt1.setColor(FG_BLUE); plt2.setColor(FG_YELLOW); //use a forge predefined color - plt3.setColor((fg::Color) 0x257973FF); //or any hex-valued color + plt3.setColor((forge::Color) 0x257973FF); //or any hex-valued color /* * Set plot legends */ @@ -85,7 +85,7 @@ int main(void) createGLBuffer(&handles[3], plt3.vertices(), FORGE_VBO); /* copy your data into the pixel buffer object exposed by - * fg::Plot class and then proceed to rendering. + * forge::Plot class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/cpu/stream.cpp b/examples/cpu/stream.cpp index 4f6810f4..320fa4fb 100644 --- a/examples/cpu/stream.cpp +++ b/examples/cpu/stream.cpp @@ -89,19 +89,19 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "3D Vector Field Demo"); + forge::Window wnd(DIMX, DIMY, "3D Vector Field Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_3D); + forge::Chart chart(FG_CHART_3D); chart.setAxesLimits(MINIMUM-1.0f, MAXIMUM, MINIMUM-1.0f, MAXIMUM, MINIMUM-1.0f, MAXIMUM); chart.setAxesTitles("x-axis", "y-axis", "z-axis"); int numElems = NELEMS*NELEMS*NELEMS; - fg::VectorField field = chart.vectorField(numElems, fg::f32); + forge::VectorField field = chart.vectorField(numElems, forge::f32); field.setColor(0.f, 1.f, 0.f, 1.f); std::vector points; diff --git a/examples/cpu/surface.cpp b/examples/cpu/surface.cpp index 6826b298..8cbd21e5 100644 --- a/examples/cpu/surface.cpp +++ b/examples/cpu/surface.cpp @@ -44,16 +44,16 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(1024, 768, "3d Surface Demo"); + forge::Window wnd(1024, 768, "3d Surface Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_3D); + forge::Chart chart(FG_CHART_3D); chart.setAxesLimits(-10.f, 10.f, -10.f, 10.f, -0.5f, 1.f); chart.setAxesTitles("x-axis", "y-axis", "z-axis"); - fg::Surface surf = chart.surface(XSIZE, YSIZE, fg::f32); + forge::Surface surf = chart.surface(XSIZE, YSIZE, forge::f32); surf.setColor(FG_YELLOW); //generate a surface @@ -65,7 +65,7 @@ int main(void) createGLBuffer(&handle, surf.vertices(), FORGE_VBO); /* copy your data into the pixel buffer object exposed by - * fg::Plot class and then proceed to rendering. + * forge::Plot class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/cuda/fractal.cu b/examples/cuda/fractal.cu index 1a03daa8..571e457d 100644 --- a/examples/cuda/fractal.cu +++ b/examples/cuda/fractal.cu @@ -16,7 +16,7 @@ const unsigned DIMX = 512; const unsigned DIMY = 512; -const size_t SIZE = DIMX*DIMY*4; +const size_t TOT_SIZE = DIMX*DIMY*4; void kernel(unsigned char* dev_out); @@ -27,15 +27,15 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Fractal Demo"); + forge::Window wnd(DIMX, DIMY, "Fractal Demo"); wnd.makeCurrent(); /* Create an image object which creates the necessary * textures and pixel buffer objects to hold the image * */ - fg::Image img(DIMX, DIMY, FG_RGBA, fg::u8); + forge::Image img(DIMX, DIMY, FG_RGBA, forge::u8); GfxHandle* handle = 0; @@ -43,12 +43,12 @@ int main(void) createGLBuffer(&handle, img.pbo(), FORGE_PBO); /* copy your data into the pixel buffer object exposed by - * fg::Image class and then proceed to rendering. + * forge::Image class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task */ - FORGE_CUDA_CHECK(cudaMalloc((void**)&dev_out, SIZE)); + FORGE_CUDA_CHECK(cudaMalloc((void**)&dev_out, TOT_SIZE)); kernel(dev_out); // copy the data from compute buffer to graphics buffer diff --git a/examples/cuda/histogram.cu b/examples/cuda/histogram.cu index afa505ae..025de9e7 100644 --- a/examples/cuda/histogram.cu +++ b/examples/cuda/histogram.cu @@ -68,9 +68,9 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Histogram Demo"); + forge::Window wnd(DIMX, DIMY, "Histogram Demo"); wnd.makeCurrent(); /* @@ -78,9 +78,9 @@ int main(void) */ wnd.grid(WIN_ROWS, WIN_COLS); - fg::Image img(IMGW, IMGH, FG_RGBA, fg::u8); + forge::Image img(IMGW, IMGH, FG_RGBA, forge::u8); - fg::Chart chart(FG_CHART_2D); + forge::Chart chart(FG_CHART_2D); /* set x axis limits to maximum and minimum values of data * and y axis limits to range [0, number of pixels ideally] * but practically total number of pixels as y range will skew @@ -91,7 +91,7 @@ int main(void) /* * Create histogram object specifying number of bins */ - fg::Histogram hist = chart.histogram(NBINS, fg::s32); + forge::Histogram hist = chart.histogram(NBINS, forge::s32); /* * Set histogram colors */ diff --git a/examples/cuda/plot3.cu b/examples/cuda/plot3.cu index 9e569903..4c7a7f1d 100644 --- a/examples/cuda/plot3.cu +++ b/examples/cuda/plot3.cu @@ -33,16 +33,16 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Three dimensional line plot demo"); + forge::Window wnd(DIMX, DIMY, "Three dimensional line plot demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_3D); + forge::Chart chart(FG_CHART_3D); chart.setAxesLimits(-1.1f, 1.1f, -1.1f, 1.1f, 0.f, 10.f); chart.setAxesTitles("x-axis", "y-axis", "z-axis"); - fg::Plot plot3 = chart.plot(ZSIZE, fg::f32); + forge::Plot plot3 = chart.plot(ZSIZE, forge::f32); static float t=0; FORGE_CUDA_CHECK(cudaMalloc((void**)&dev_out, ZSIZE * 3 * sizeof(float) )); @@ -52,7 +52,7 @@ int main(void) createGLBuffer(&handle, plot3.vertices(), FORGE_VBO); /* copy your data into the vertex buffer object exposed by - * fg::Plot class and then proceed to rendering. + * forge::Plot class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/cuda/plotting.cu b/examples/cuda/plotting.cu index b0b74fb4..96aab9b6 100644 --- a/examples/cuda/plotting.cu +++ b/examples/cuda/plotting.cu @@ -35,21 +35,21 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Plotting Demo"); + forge::Window wnd(DIMX, DIMY, "Plotting Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_2D); + forge::Chart chart(FG_CHART_2D); chart.setAxesLimits(FRANGE_START, FRANGE_END, -1.0f, 1.0f); /* Create several plot objects which creates the necessary * vertex buffer objects to hold the different plot types */ - fg::Plot plt0 = chart.plot( DATA_SIZE, fg::f32); //create a default plot - fg::Plot plt1 = chart.plot( DATA_SIZE, fg::f32, FG_PLOT_LINE, FG_MARKER_NONE); //or specify a specific plot type - fg::Plot plt2 = chart.plot( DATA_SIZE, fg::f32, FG_PLOT_LINE, FG_MARKER_TRIANGLE); //last parameter specifies marker shape - fg::Plot plt3 = chart.plot( DATA_SIZE, fg::f32, FG_PLOT_SCATTER, FG_MARKER_CROSS); + forge::Plot plt0 = chart.plot( DATA_SIZE, forge::f32); //create a default plot + forge::Plot plt1 = chart.plot( DATA_SIZE, forge::f32, FG_PLOT_LINE, FG_MARKER_NONE); //or specify a specific plot type + forge::Plot plt2 = chart.plot( DATA_SIZE, forge::f32, FG_PLOT_LINE, FG_MARKER_TRIANGLE); //last parameter specifies marker shape + forge::Plot plt3 = chart.plot( DATA_SIZE, forge::f32, FG_PLOT_SCATTER, FG_MARKER_CROSS); /* * Set plot colors @@ -57,7 +57,7 @@ int main(void) plt0.setColor(FG_RED); plt1.setColor(FG_BLUE); plt2.setColor(FG_YELLOW); //use a forge predefined color - plt3.setColor((fg::Color) 0x257973FF); //or any hex-valued color + plt3.setColor((forge::Color) 0x257973FF); //or any hex-valued color /* * Set plot legends */ @@ -83,7 +83,7 @@ int main(void) createGLBuffer(&handles[3], plt3.vertices(), FORGE_VBO); /* copy your data into the vertex buffer object exposed by - * fg::Plot class and then proceed to rendering. + * forge::Plot class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/cuda/surface.cu b/examples/cuda/surface.cu index cc989ae1..667c6201 100644 --- a/examples/cuda/surface.cu +++ b/examples/cuda/surface.cu @@ -33,16 +33,16 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(1024, 768, "3d Surface Demo"); + forge::Window wnd(1024, 768, "3d Surface Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_3D); + forge::Chart chart(FG_CHART_3D); chart.setAxesLimits(-10.f, 10.f, -10.f, 10.f, -0.5f, 1.f); chart.setAxesTitles("x-axis", "y-axis", "z-axis"); - fg::Surface surf = chart.surface(XSIZE, YSIZE, fg::f32); + forge::Surface surf = chart.surface(XSIZE, YSIZE, forge::f32); surf.setColor(FG_YELLOW); FORGE_CUDA_CHECK(cudaMalloc((void**)&dev_out, XSIZE * YSIZE * 3 * sizeof(float) )); @@ -51,7 +51,7 @@ int main(void) GfxHandle* handle; createGLBuffer(&handle, surf.vertices(), FORGE_VBO); /* copy your data into the vertex buffer object exposed by - * fg::Plot class and then proceed to rendering. + * forge::Plot class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task diff --git a/examples/opencl/cl_helpers.h b/examples/opencl/cl_helpers.h index e8cb1f4f..2e96ee23 100644 --- a/examples/opencl/cl_helpers.h +++ b/examples/opencl/cl_helpers.h @@ -24,12 +24,13 @@ using namespace cl; #if defined (OS_MAC) +#include static const std::string CL_GL_SHARING_EXT = "cl_APPLE_gl_sharing"; #else static const std::string CL_GL_SHARING_EXT = "cl_khr_gl_sharing"; #endif -bool checkGLInterop(const cl::Platform &plat, const cl::Device &pDevice, const fg::Window &wnd) +bool checkGLInterop(const cl::Platform &plat, const cl::Device &pDevice, const forge::Window &wnd) { bool ret_val = false; // find the extension required @@ -48,11 +49,22 @@ bool checkGLInterop(const cl::Platform &plat, const cl::Device &pDevice, const #if !defined(OS_MAC) // Check on Linux, Windows // Check if current OpenCL device is belongs to the OpenGL context + +#if defined(OS_LNX) cl_context_properties cps[] = { CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(), + CL_GLX_DISPLAY_KHR, (cl_context_properties)wnd.display(), CL_CONTEXT_PLATFORM, (cl_context_properties)plat(), 0 }; +#else /* OS_WIN */ + cl_context_properties cps[] = { + CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(), + CL_WGL_HDC_KHR, (cl_context_properties)wnd.display(), + CL_CONTEXT_PLATFORM, (cl_context_properties)plat(), + 0 + }; +#endif // Load the extension // If cl_khr_gl_sharing is available, this function should be present @@ -61,13 +73,14 @@ bool checkGLInterop(const cl::Platform &plat, const cl::Device &pDevice, const clGetExtensionFunctionAddressForPlatform(plat(), "clGetGLContextInfoKHR"); if (!func) return false; + // Get all devices associated with opengl context std::vector devices(16); size_t ret = 0; cl_int err = func(cps, CL_DEVICES_FOR_GL_CONTEXT_KHR, devices.size() * sizeof(cl_device_id), - &devices[0], + devices.data(), &ret); if (err != CL_SUCCESS) return false; @@ -77,16 +90,14 @@ bool checkGLInterop(const cl::Platform &plat, const cl::Device &pDevice, const // Check if current device is present in the associated devices cl_device_id current_device = pDevice(); - auto res = std::find(std::begin(devices), - std::end(devices), - current_device); + auto res = std::find(std::begin(devices), std::end(devices), current_device); ret_val = res != std::end(devices); #endif return ret_val; } -cl::Context createCLGLContext(const fg::Window &wnd) +cl::Context createCLGLContext(const forge::Window &wnd) { std::vector platforms; Platform::get(&platforms); diff --git a/examples/opencl/fractal.cpp b/examples/opencl/fractal.cpp index 2aa56fc2..2aad3edf 100644 --- a/examples/opencl/fractal.cpp +++ b/examples/opencl/fractal.cpp @@ -110,15 +110,15 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Fractal Demo"); + forge::Window wnd(DIMX, DIMY, "Fractal Demo"); wnd.makeCurrent(); /* Create an image object which creates the necessary * textures and pixel buffer objects to hold the image * */ - fg::Image img(DIMX, DIMY, FG_RGBA, fg::u8); + forge::Image img(DIMX, DIMY, FG_RGBA, forge::u8); /* * Helper function to create a CLGL interop context. @@ -131,7 +131,7 @@ int main(void) queue = CommandQueue(context, device); /* copy your data into the pixel buffer object exposed by - * fg::Image class and then proceed to rendering. + * forge::Image class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task @@ -155,7 +155,7 @@ int main(void) // destroy GL-CPU Interop buffer releaseGLBuffer(handle); - }catch (fg::Error err) { + }catch (forge::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; } catch (cl::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; diff --git a/examples/opencl/histogram.cpp b/examples/opencl/histogram.cpp index b4781001..9985ee9c 100644 --- a/examples/opencl/histogram.cpp +++ b/examples/opencl/histogram.cpp @@ -263,9 +263,9 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Histogram Demo"); + forge::Window wnd(DIMX, DIMY, "Histogram Demo"); wnd.makeCurrent(); /* @@ -273,9 +273,9 @@ int main(void) */ wnd.grid(WIN_ROWS, WIN_COLS); - fg::Image img(IMGW, IMGH, FG_RGBA, fg::u8); + forge::Image img(IMGW, IMGH, FG_RGBA, forge::u8); - fg::Chart chart(FG_CHART_2D); + forge::Chart chart(FG_CHART_2D); /* set x axis limits to maximum and minimum values of data * and y axis limits to range [0, number of pixels ideally] * but practically total number of pixels as y range will skew @@ -286,7 +286,7 @@ int main(void) /* * Create histogram object specifying number of bins */ - fg::Histogram hist = chart.histogram(NBINS, fg::s32); + forge::Histogram hist = chart.histogram(NBINS, forge::s32); /* * Set histogram colors */ @@ -337,7 +337,7 @@ int main(void) releaseGLBuffer(handles[1]); releaseGLBuffer(handles[2]); - }catch (fg::Error err) { + }catch (forge::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; } catch (cl::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; diff --git a/examples/opencl/plot3.cpp b/examples/opencl/plot3.cpp index bea0f61b..27caa964 100644 --- a/examples/opencl/plot3.cpp +++ b/examples/opencl/plot3.cpp @@ -78,16 +78,16 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Three dimensional line plot demo"); + forge::Window wnd(DIMX, DIMY, "Three dimensional line plot demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_3D); + forge::Chart chart(FG_CHART_3D); chart.setAxesLimits(-1.1f, 1.1f, -1.1f, 1.1f, 0.f, 10.f); chart.setAxesTitles("x-axis", "y-axis", "z-axis"); - fg::Plot plot3 = chart.plot(ZSIZE, fg::f32); + forge::Plot plot3 = chart.plot(ZSIZE, forge::f32); /* * Helper function to create a CLGL interop context. @@ -106,7 +106,7 @@ int main(void) GfxHandle* handle; createGLBuffer(&handle, plot3.vertices(), FORGE_VBO); /* copy your data into the pixel buffer object exposed by - * fg::Surface class and then proceed to rendering. + * forge::Surface class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task @@ -122,7 +122,7 @@ int main(void) releaseGLBuffer(handle); - }catch (fg::Error err) { + }catch (forge::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; } catch (cl::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; diff --git a/examples/opencl/plotting.cpp b/examples/opencl/plotting.cpp index a987459f..a70a6ee5 100644 --- a/examples/opencl/plotting.cpp +++ b/examples/opencl/plotting.cpp @@ -82,21 +82,21 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(DIMX, DIMY, "Plotting Demo"); + forge::Window wnd(DIMX, DIMY, "Plotting Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_2D); + forge::Chart chart(FG_CHART_2D); chart.setAxesLimits(FRANGE_START, FRANGE_END, -1.0f, 1.0f); /* Create several plot objects which creates the necessary * vertex buffer objects to hold the different plot types */ - fg::Plot plt0 = chart.plot(DATA_SIZE, fg::f32); //create a default plot - fg::Plot plt1 = chart.plot(DATA_SIZE, fg::f32, FG_PLOT_LINE, FG_MARKER_NONE); //or specify a specific plot type - fg::Plot plt2 = chart.plot(DATA_SIZE, fg::f32, FG_PLOT_LINE, FG_MARKER_TRIANGLE); //last parameter specifies marker shape - fg::Plot plt3 = chart.plot(DATA_SIZE, fg::f32, FG_PLOT_SCATTER, FG_MARKER_CROSS); + forge::Plot plt0 = chart.plot(DATA_SIZE, forge::f32); //create a default plot + forge::Plot plt1 = chart.plot(DATA_SIZE, forge::f32, FG_PLOT_LINE, FG_MARKER_NONE); //or specify a specific plot type + forge::Plot plt2 = chart.plot(DATA_SIZE, forge::f32, FG_PLOT_LINE, FG_MARKER_TRIANGLE); //last parameter specifies marker shape + forge::Plot plt3 = chart.plot(DATA_SIZE, forge::f32, FG_PLOT_SCATTER, FG_MARKER_CROSS); /* * Set plot colors @@ -104,7 +104,7 @@ int main(void) plt0.setColor(FG_RED); plt1.setColor(FG_BLUE); plt2.setColor(FG_YELLOW); //use a forge predefined color - plt3.setColor((fg::Color) 0x257973FF); //or any hex-valued color + plt3.setColor((forge::Color) 0x257973FF); //or any hex-valued color /* * Set plot legends */ @@ -138,7 +138,7 @@ int main(void) createGLBuffer(&handles[2], plt2.vertices(), FORGE_VBO); createGLBuffer(&handles[3], plt3.vertices(), FORGE_VBO); /* copy your data into the vertex buffer object exposed by - * fg::Plot class and then proceed to rendering. + * forge::Plot class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task @@ -157,7 +157,7 @@ int main(void) releaseGLBuffer(handles[2]); releaseGLBuffer(handles[3]); - }catch (fg::Error err) { + }catch (forge::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; } catch (cl::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; diff --git a/examples/opencl/surface.cpp b/examples/opencl/surface.cpp index e3cfcce8..f832f034 100644 --- a/examples/opencl/surface.cpp +++ b/examples/opencl/surface.cpp @@ -105,16 +105,16 @@ int main(void) /* * First Forge call should be a window creation call * so that necessary OpenGL context is created for any - * other fg::* object to be created successfully + * other forge::* object to be created successfully */ - fg::Window wnd(1024, 768, "3d Surface Demo"); + forge::Window wnd(1024, 768, "3d Surface Demo"); wnd.makeCurrent(); - fg::Chart chart(FG_CHART_3D); + forge::Chart chart(FG_CHART_3D); chart.setAxesLimits(-10.f, 10.f, -10.f, 10.f, -0.5f, 1.f); chart.setAxesTitles("x-axis", "y-axis", "z-axis"); - fg::Surface surf = chart.surface(XSIZE, YSIZE, fg::f32); + forge::Surface surf = chart.surface(XSIZE, YSIZE, forge::f32); surf.setColor(FG_YELLOW); /* @@ -134,7 +134,7 @@ int main(void) GfxHandle* handle; createGLBuffer(&handle, surf.vertices(), FORGE_VBO); /* copy your data into the pixel buffer object exposed by - * fg::Surface class and then proceed to rendering. + * forge::Surface class and then proceed to rendering. * To help the users with copying the data from compute * memory to display memory, Forge provides copy headers * along with the library to help with this task @@ -146,7 +146,7 @@ int main(void) } while(!wnd.close()); releaseGLBuffer(handle); - }catch (fg::Error err) { + }catch (forge::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; } catch (cl::Error err) { std::cout << err.what() << "(" << err.err() << ")" << std::endl; diff --git a/include/ComputeCopy.h b/include/ComputeCopy.h index 3c303d96..5c3d9adb 100644 --- a/include/ComputeCopy.h +++ b/include/ComputeCopy.h @@ -24,6 +24,8 @@ extern "C" { #elif defined(USE_FORGE_CUDA_COPY_HELPERS) #include +// gl.h is required by cuda_gl_interop to be included before it +#include #include #include #include @@ -43,10 +45,10 @@ extern "C" { - cudaGraphicsResource in CUDA - cl_mem in OpenCL - - GLuint from standard cpu + - unsigned from standard cpu */ #if defined(USE_FORGE_CPU_COPY_HELPERS) -typedef GLuint GfxResourceHandle; +typedef unsigned GfxResourceHandle; #elif defined(USE_FORGE_CUDA_COPY_HELPERS) typedef cudaGraphicsResource* GfxResourceHandle; #elif defined(USE_FORGE_OPENCL_COPY_HELPERS) @@ -99,11 +101,11 @@ void copyToGLBuffer(GfxHandle* pGLDestination, ComputeResourceHandle pSource, c { GfxHandle* temp = pGLDestination; - GLenum target = (temp->mTarget==FORGE_PBO ? GL_PIXEL_UNPACK_BUFFER : GL_ARRAY_BUFFER); - - glBindBuffer(target, temp->mId); - glBufferSubData(target, 0, pSize, pSource); - glBindBuffer(target, 0); + if (temp->mTarget==FORGE_PBO) { + fg_update_vertex_buffer(temp->mId, pSize, pSource); + } else if (temp->mTarget==FORGE_VBO) { + fg_update_pixel_buffer(temp->mId, pSize, pSource); + } } #endif @@ -214,7 +216,7 @@ void copyToGLBuffer(GfxHandle* pGLDestination, ComputeResourceHandle pSource, c cl_mem src = (cl_mem)pSource; cl_mem dst = pGLDestination->mId; - glFinish(); + fg_finish(); FORGE_OCL_CHECK(clEnqueueAcquireGLObjects(queue, 1, &dst, 0, NULL, &waitEvent), "Failed in clEnqueueAcquireGLObjects"); diff --git a/include/fg/chart.h b/include/fg/chart.h index c8d87087..240fc60d 100644 --- a/include/fg/chart.h +++ b/include/fg/chart.h @@ -21,46 +21,179 @@ extern "C" { #endif +/** \addtogroup chart_functions + * @{ + */ + +/** + Create a Chart object with given dimensional property + + \param[out] pHandle will be set to point to the chart object in memory + \param[in] pChartType is chart dimension property + + \return \ref fg_err error code + */ FGAPI fg_err fg_create_chart(fg_chart *pHandle, const fg_chart_type pChartType); +/** + Destroy the chart object + + \param[in] pHandle is chart handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_destroy_chart(fg_chart pHandle); +/** + Set axes titles for the chart + + \param[in] pHandle is chart handle + \param[in] pX is x-axis title label + \param[in] pY is y-axis title label + \param[in] pZ is z-axis title label + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_chart_axes_titles(fg_chart pHandle, const char* pX, const char* pY, const char* pZ); +/** + Set axes data ranges + + \param[in] pHandle is chart handle + \param[in] pXmin is x-axis minimum data value + \param[in] pXmax is x-axis maximum data value + \param[in] pYmin is y-axis minimum data value + \param[in] pYmax is y-axis maximum data value + \param[in] pZmin is z-axis minimum data value + \param[in] pZmax is z-axis maximum data value + + \ingroup chart_functions + */ FGAPI fg_err fg_set_chart_axes_limits(fg_chart pHandle, const float pXmin, const float pXmax, const float pYmin, const float pYmax, const float pZmin, const float pZmax); +/** + Set legend position for Chart + + \param[in] pHandle is chart handle + \param[in] pX is horizontal position in normalized coordinates + \param[in] pY is vertical position in normalized coordinates + + \return \ref fg_err error code + + \note By normalized coordinates, the range of these coordinates is expected to be [0-1]. + (0,0) is the bottom hand left corner. + */ FGAPI fg_err fg_set_chart_legend_position(fg_chart pHandle, const float pX, const float pY); +/** + Create and add an Image object to the current chart + + \param[out] pImage is the handle of the image object created + \param[in] pHandle is chart handle to which image object will be added. + \param[in] pWidth Width of the image + \param[in] pHeight Height of the image + \param[in] pFormat Color channel format of image, uses one of the values + of \ref fg_channel_format + \param[in] pType takes one of the values of \ref fg_dtype that indicates + the integral data type of histogram data + + \return \ref fg_err error code + */ FGAPI fg_err fg_add_image_to_chart(fg_image* pImage, fg_chart pHandle, const uint pWidth, const uint pHeight, const fg_channel_format pFormat, const fg_dtype pType); +/** + Create and add an Histogram object to the current chart + + \param[out] pHistogram is the handle of the histogram object created + \param[in] pHandle is chart handle + \param[in] pNBins is number of bins the data is sorted out + \param[in] pType takes one of the values of \ref fg_dtype that indicates + the integral data type of histogram data + + \return \ref fg_err error code + */ FGAPI fg_err fg_add_histogram_to_chart(fg_histogram* pHistogram, fg_chart pHandle, const uint pNBins, const fg_dtype pType); +/** + Create and add an Plot object to the current chart + + \param[out] pPlot is the handle of the plot object created + \param[in] pHandle is chart handle + \param[in] pNPoints is number of data points to display + \param[in] pType takes one of the values of \ref fg_dtype that indicates + the integral data type of plot data + \param[in] pPlotType dictates the type of plot/graph, + it can take one of the values of \ref fg_plot_type + \param[in] pMarkerType indicates which symbol is rendered as marker. It can take one of + the values of \ref fg_marker_type. + + \return \ref fg_err error code + */ FGAPI fg_err fg_add_plot_to_chart(fg_plot* pPlot, fg_chart pHandle, const uint pNPoints, const fg_dtype pType, const fg_plot_type pPlotType, const fg_marker_type pMarkerType); +/** + Create and add an Plot object to the current chart + + \param[out] pSurface is the handle of the surface object created + \param[in] pHandle is chart handle + \param[in] pXPoints is number of data points along X dimension + \param[in] pYPoints is number of data points along Y dimension + \param[in] pType takes one of the values of \ref fg_dtype that indicates + the integral data type of plot data + \param[in] pPlotType is the render type which can be one of \ref fg_plot_type (valid choices + are FG_PLOT_SURFACE and FG_PLOT_SCATTER) + \param[in] pMarkerType is the type of \ref fg_marker_type to draw for \ref FG_PLOT_SCATTER plot type + + \return \ref fg_err error code + */ FGAPI fg_err fg_add_surface_to_chart(fg_surface* pSurface, fg_chart pHandle, const uint pXPoints, const uint pYPoints, const fg_dtype pType, const fg_plot_type pPlotType, const fg_marker_type pMarkerType); +/** + Create and add an Vector Field object to the current chart + + \param[out] pField is the handle of the Vector Field object created + \param[in] pHandle is chart handle + \param[in] pNPoints is number of data points to display + \param[in] pType takes one of the values of \ref fg_dtype that indicates the integral data type of vector field data + + \return \ref fg_err error code + */ FGAPI fg_err fg_add_vector_field_to_chart(fg_vector_field* pField, fg_chart pHandle, const uint pNPoints, const fg_dtype pType); +/** + Render the chart to given window + + \param[in] pWindow is target window to where chart will be rendered + \param[in] pChart is chart handle + \param[in] pX is x coordinate of origin of viewport in window coordinates + \param[in] pY is y coordinate of origin of viewport in window coordinates + \param[in] pWidth is the width of the viewport + \param[in] pHeight is the height of the viewport + + \return \ref fg_err error code + */ FGAPI fg_err fg_render_chart(const fg_window pWindow, const fg_chart pChart, const int pX, const int pY, const int pWidth, const int pHeight); +/** @} */ + #ifdef __cplusplus } #endif @@ -68,7 +201,7 @@ FGAPI fg_err fg_render_chart(const fg_window pWindow, #ifdef __cplusplus -namespace fg +namespace forge { /** @@ -77,8 +210,8 @@ namespace fg \brief Chart is base canvas where other plottable objects are rendered. Charts come in two types: - - \ref FG_2D - Two dimensional charts - - \ref FG_3D - Three dimensional charts + - \ref FG_CHART_2D - Two dimensional charts + - \ref FG_CHART_3D - Three dimensional charts */ class Chart { private: @@ -210,8 +343,8 @@ class Chart { \param[in] pDataType takes one of the values of \ref dtype that indicates the integral data type of plot data \param[in] pPlotType is the render type which can be one of \ref PlotType (valid choices - are FG_SURFACE and FG_SCATTER) - \param[in] pMarkerType is the type of \ref MarkerType to draw for \ref FG_SCATTER plot type + are FG_PLOT_SURFACE and FG_PLOT_SCATTER) + \param[in] pMarkerType is the type of \ref MarkerType to draw for \ref FG_PLOT_SCATTER plot type */ FGAPI Surface surface(const uint pNumXPoints, const uint pNumYPoints, const dtype pDataType, const PlotType pPlotType=FG_PLOT_SURFACE, const MarkerType pMarkerType=FG_MARKER_NONE); diff --git a/include/fg/defines.h b/include/fg/defines.h index e1f2eb8d..eb03ac3d 100644 --- a/include/fg/defines.h +++ b/include/fg/defines.h @@ -40,14 +40,8 @@ #define FG_API_VERSION FG_API_VERSION_CURRENT #endif -#include #include -/** - Requirment by GLEWmx - */ -FGAPI GLEWContext* glewGetContext(); - typedef void* fg_window; typedef void* fg_font; typedef void* fg_chart; @@ -189,7 +183,7 @@ typedef enum { #ifdef __cplusplus -namespace fg +namespace forge { typedef fg_err ErrorCode; typedef fg_channel_format ChannelFormat; diff --git a/include/fg/exception.h b/include/fg/exception.h index 07381f0f..e3425f3b 100644 --- a/include/fg/exception.h +++ b/include/fg/exception.h @@ -17,7 +17,7 @@ static const int MAX_ERR_STR_LEN = 1024; -namespace fg +namespace forge { class FGAPI Error : public std::logic_error diff --git a/include/fg/font.h b/include/fg/font.h index c9156b9b..27a6e6a4 100644 --- a/include/fg/font.h +++ b/include/fg/font.h @@ -14,14 +14,50 @@ extern "C" { #endif +/** \addtogroup font_functions + * @{ + */ + +/** + Create a Font object + + \param[out] pFont will point to the font object created after this function returns + + \return \ref fg_err error code + */ FGAPI fg_err fg_create_font(fg_font* pFont); +/** + Destroy font object + + \param[in] pFont is the font handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_destroy_font(fg_font pFont); +/** + Load a given font file + + \param[in] pFont is the font handle + \param[in] pFileFullPath True Type Font file path + + \return \ref fg_err error code + */ FGAPI fg_err fg_load_font_file(fg_font pFont, const char* const pFileFullPath); +/** + Load a system font based on the name + + \param[in] pFont is the font handle + \param[in] pFontName True Type Font name + + \return \ref fg_err error code + */ FGAPI fg_err fg_load_system_font(fg_font pFont, const char* const pFontName); +/** @} */ + #ifdef __cplusplus } #endif @@ -29,7 +65,7 @@ FGAPI fg_err fg_load_system_font(fg_font pFont, const char* const pFontName); #ifdef __cplusplus -namespace fg +namespace forge { /** diff --git a/include/fg/histogram.h b/include/fg/histogram.h index 55b328aa..a5caaa1a 100644 --- a/include/fg/histogram.h +++ b/include/fg/histogram.h @@ -16,28 +16,124 @@ extern "C" { #endif +/** \addtogroup hist_functions + * @{ + */ + +/** + Creates a Histogram object + + \param[out] pHistogram will point to the histogram object created after this function call + \param[in] pNBins is number of bins the data is sorted out + \param[in] pDataType takes one of the values of \ref fg_dtype that indicates + the integral data type of histogram data + + \return \ref fg_err error code + */ FGAPI fg_err fg_create_histogram(fg_histogram *pHistogram, - const uint nbins, const fg_dtype type); + const uint pNBins, const fg_dtype pDataType); +/** + Destroy Histogram object + + \param[in] pHistogram is the histogram handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_destroy_histogram(fg_histogram pHistogram); +/** + Set the color of bar in the bar graph(histogram) + + This is global alpha value for the histogram rendering that takes + effect if individual bar alphas are not set by calling the following + member functions + - Histogram::alphas() + - Histogram::alphasSize() + + \param[in] pHistogram is the histogram handle + \param[in] pRed is Red component in range [0, 1] + \param[in] pGreen is Green component in range [0, 1] + \param[in] pBlue is Blue component in range [0, 1] + \param[in] pAlpha is Alpha component in range [0, 1] + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_histogram_color(fg_histogram pHistogram, const float pRed, const float pGreen, const float pBlue, const float pAlpha); +/** + Set legend for histogram plot + + \param[in] pHistogram is the histogram handle + \param[in] pLegend + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_histogram_legend(fg_histogram pHistogram, const char* pLegend); -FGAPI fg_err fg_get_histogram_vbo(uint* out, const fg_histogram pHistogram); +/** + Get the resource identifier for vertices buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pHistogram is the histogram handle + + \return \ref fg_err error code + */ +FGAPI fg_err fg_get_histogram_vbo(uint* pOut, const fg_histogram pHistogram); + +/** + Get the resource identifier for colors buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pHistogram is the histogram handle + + \return \ref fg_err error code + */ +FGAPI fg_err fg_get_histogram_cbo(uint* pOut, const fg_histogram pHistogram); + +/** + Get the resource identifier for alpha values buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pHistogram is the histogram handle + + \return \ref fg_err error code + */ +FGAPI fg_err fg_get_histogram_abo(uint* pOut, const fg_histogram pHistogram); -FGAPI fg_err fg_get_histogram_cbo(uint* out, const fg_histogram pHistogram); +/** + Get the vertices buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pHistogram is the histogram handle + + \return \ref fg_err error code + */ +FGAPI fg_err fg_get_histogram_vbo_size(uint* pOut, const fg_histogram pHistogram); -FGAPI fg_err fg_get_histogram_abo(uint* out, const fg_histogram pHistogram); +/** + Get the colors buffer size in bytes -FGAPI fg_err fg_get_histogram_vbo_size(uint* out, const fg_histogram pHistogram); + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pHistogram is the histogram handle -FGAPI fg_err fg_get_histogram_cbo_size(uint* out, const fg_histogram pHistogram); + \return \ref fg_err error code + */ +FGAPI fg_err fg_get_histogram_cbo_size(uint* pOut, const fg_histogram pHistogram); + +/** + Get the alpha values buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pHistogram is the histogram handle + + \return \ref fg_err error code + */ +FGAPI fg_err fg_get_histogram_abo_size(uint* pOut, const fg_histogram pHistogram); -FGAPI fg_err fg_get_histogram_abo_size(uint* out, const fg_histogram pHistogram); +/** @} */ #ifdef __cplusplus } @@ -46,7 +142,7 @@ FGAPI fg_err fg_get_histogram_abo_size(uint* out, const fg_histogram pHistogram) #ifdef __cplusplus -namespace fg +namespace forge { /** @@ -63,7 +159,7 @@ class Histogram { Creates a Histogram object \param[in] pNBins is number of bins the data is sorted out - \param[in] pDataType takes one of the values of \ref dtype that indicates + \param[in] pDataType takes one of the values of \ref fg_dtype that indicates the integral data type of histogram data */ FGAPI Histogram(const uint pNBins, const dtype pDataType); @@ -83,7 +179,7 @@ class Histogram { /** Set the color of bar in the bar graph(histogram) - \param[in] pColor takes values of type fg::Color to define bar color + \param[in] pColor takes values of type forge::Color to define bar color **/ FGAPI void setColor(const Color pColor); diff --git a/include/fg/image.h b/include/fg/image.h index 8046a236..e72986ac 100644 --- a/include/fg/image.h +++ b/include/fg/image.h @@ -16,32 +16,134 @@ extern "C" { #endif +/** \addtogroup image_functions + * @{ + */ + +/** + Create a Image object + + \param[out] pImage will be set to created Image object + \param[in] pWidth Width of the image + \param[in] pHeight Height of the image + \param[in] pFormat Color channel format of image, uses one of the values + of \ref fg_channel_format + \param[in] pType takes one of the values of \ref fg_dtype that indicates + the integral data type of histogram data + + \return \ref fg_err error code + */ FGAPI fg_err fg_create_image(fg_image* pImage, const uint pWidth, const uint pHeight, const fg_channel_format pFormat, const fg_dtype pType); +/** + Destroy image object + + \param[in] pImage is the image handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_destroy_image(fg_image pImage); +/** + Set a global alpha value for rendering the image + + \param[in] pImage is the image handle + \param[in] pAlpha + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_image_alpha(fg_image pImage, const float pAlpha); +/** + Set option to inform whether to maintain aspect ratio of original image + + \param[in] pImage is the image handle + \param[in] pKeepRatio informs the image object if original aspect ratio has to be maintained + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_image_aspect_ratio(fg_image pImage, const bool pKeepRatio); +/** + Get the width of the image + + \param[out] pOut will be set to the width of the image + \param[in] pImage is the image handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_image_width(uint *pOut, const fg_image pImage); +/** + Get the height of the image + + \param[out] pOut will be set to the height of the image + \param[in] pImage is the image handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_image_height(uint *pOut, const fg_image pImage); +/** + Get the channel format of the image + + \param[out] pOut will be set to the channel format of the image + \param[in] pImage is the image handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_image_pixelformat(fg_channel_format* pOut, const fg_image pImage); +/** + Get the pixel data type of the image + + \param[out] pOut will be set to the pixel data type of the image + \param[in] pImage is the image handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_image_type(fg_dtype* pOut, const fg_image pImage); +/** + Get the image buffer resource identifier + + \param[out] pOut will be set to the image resource identifier + \param[in] pImage is the image handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_image_pbo(uint* pOut, const fg_image pImage); +/** + Get the image buffer size in bytes + + \param[out] pOut will be set to the image buffer size in bytes + \param[in] pImage is the image handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_image_pbo_size(uint* pOut, const fg_image pImage); +/** + Render the image to given window + + \param[in] pWindow is target window to where image will be rendered + \param[in] pImage is the image handle + \param[in] pX is x coordinate of origin of viewport in window coordinates + \param[in] pY is y coordinate of origin of viewport in window coordinates + \param[in] pWidth is the width of the viewport + \param[in] pHeight is the height of the viewport + + \return \ref fg_err error code + */ FGAPI fg_err fg_render_image(const fg_window pWindow, const fg_image pImage, const int pX, const int pY, const int pWidth, const int pHeight); +/** @} */ + #ifdef __cplusplus } #endif @@ -49,7 +151,7 @@ FGAPI fg_err fg_render_image(const fg_window pWindow, #ifdef __cplusplus -namespace fg +namespace forge { class Window; diff --git a/include/fg/plot.h b/include/fg/plot.h index 56173900..edbf2a9f 100644 --- a/include/fg/plot.h +++ b/include/fg/plot.h @@ -16,38 +16,160 @@ extern "C" { #endif +/** \addtogroup plot_functions + * @{ + */ + +/** + Create a Plot object + + \param[out] pPlot will be set to plot handle upon creating the plot object + \param[in] pNPoints is number of data points to display + \param[in] pType takes one of the values of \ref fg_dtype that indicates + the integral data type of plot data + \param[in] pChartType dictates the dimensionality of the chart + \param[in] pPlotType dictates the type of plot/graph, + it can take one of the values of \ref fg_plot_type + \param[in] pMarkerType indicates which symbol is rendered as marker. It can take one of + the values of \ref fg_marker_type. + + \return \ref fg_err error code + */ FGAPI fg_err fg_create_plot(fg_plot *pPlot, const uint pNPoints, const fg_dtype pType, const fg_chart_type pChartType, const fg_plot_type pPlotType, const fg_marker_type pMarkerType); +/** + Destroy plot object + + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_destroy_plot(fg_plot pPlot); +/** + Set the color of line graph(plot) + + \param[in] pPlot is the plot handle + \param[in] pRed is Red component in range [0, 1] + \param[in] pGreen is Green component in range [0, 1] + \param[in] pBlue is Blue component in range [0, 1] + \param[in] pAlpha is Blue component in range [0, 1] + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_plot_color(fg_plot pPlot, const float pRed, const float pGreen, const float pBlue, const float pAlpha); +/** + Set plot legend + + \param[in] pPlot is the plot handle + \param[in] pLegend + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_plot_legend(fg_plot pPlot, const char* pLegend); +/** + Set global marker size + + This size will be used for rendering markers if no per vertex marker sizes are provided. + This value defaults to 10 + + \param[in] pPlot is the plot handle + \param[in] pMarkerSize is the target marker size for scatter plots or line plots with markers + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_plot_marker_size(fg_plot pPlot, const float pMarkerSize); +/** + Get the resource identifier for vertices buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_plot_vbo(uint* pOut, const fg_plot pPlot); +/** + Get the resource identifier for colors buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_plot_cbo(uint* pOut, const fg_plot pPlot); +/** + Get the resource identifier for alpha values buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_plot_abo(uint* pOut, const fg_plot pPlot); +/** + Get the resource identifier for markers sizes buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_plot_mbo(uint* pOut, const fg_plot pPlot); +/** + Get the vertices buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_plot_vbo_size(uint* pOut, const fg_plot pPlot); +/** + Get the colors buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_plot_cbo_size(uint* pOut, const fg_plot pPlot); +/** + Get the alpha values buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_plot_abo_size(uint* pOut, const fg_plot pPlot); +/** + Get the markers buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pPlot is the plot handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_plot_mbo_size(uint* pOut, const fg_plot pPlot); +/** @} */ + #ifdef __cplusplus } #endif @@ -55,7 +177,7 @@ FGAPI fg_err fg_get_plot_mbo_size(uint* pOut, const fg_plot pPlot); #ifdef __cplusplus -namespace fg +namespace forge { /** @@ -98,9 +220,9 @@ class Plot { /** Set the color of line graph(plot) - \param[in] pColor takes values of fg::Color to define plot color + \param[in] pColor takes values of forge::Color to define plot color */ - FGAPI void setColor(const fg::Color pColor); + FGAPI void setColor(const forge::Color pColor); /** Set the color of line graph(plot) diff --git a/include/fg/surface.h b/include/fg/surface.h index 5e9d8185..02da23b8 100644 --- a/include/fg/surface.h +++ b/include/fg/surface.h @@ -15,39 +15,134 @@ extern "C" { #endif +/** \addtogroup surf_functions + * @{ + */ + +/** + Create a Surface object + + \param[out] pSurface will be set to surface handle upon creating the surface object + \param[in] pXPoints is number of data points along X dimension + \param[in] pYPoints is number of data points along Y dimension + \param[in] pType takes one of the values of \ref fg_dtype that indicates + the integral data type of surface data + \param[in] pPlotType dictates the type of surface/graph, + it can take one of the values of \ref fg_plot_type + \param[in] pMarkerType indicates which symbol is rendered as marker. It can take one of + the values of \ref fg_marker_type. + + \return \ref fg_err error code + */ FGAPI fg_err fg_create_surface(fg_surface *pSurface, const uint pXPoints, const uint pYPoints, const fg_dtype pType, const fg_plot_type pPlotType, const fg_marker_type pMarkerType); +/** + Destroy surface object + + \param[in] pSurface is the surface handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_destroy_surface(fg_surface pSurface); +/** + Set the color of surface + + \param[in] pSurface is the surface handle + \param[in] pRed is Red component in range [0, 1] + \param[in] pGreen is Green component in range [0, 1] + \param[in] pBlue is Blue component in range [0, 1] + \param[in] pAlpha is Blue component in range [0, 1] + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_surface_color(fg_surface pSurface, const float pRed, const float pGreen, const float pBlue, const float pAlpha); +/** + Set surface legend + + \param[in] pSurface is the surface handle + \param[in] pLegend + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_surface_legend(fg_surface pSurface, const char* pLegend); +/** + Get the resource identifier for vertices buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pSurface is the surface handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_surface_vbo(uint* pOut, const fg_surface pSurface); +/** + Get the resource identifier for colors buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pSurface is the surface handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_surface_cbo(uint* pOut, const fg_surface pSurface); +/** + Get the resource identifier for alpha values buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pSurface is the surface handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_surface_abo(uint* pOut, const fg_surface pSurface); +/** + Get the vertices buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pSurface is the surface handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_surface_vbo_size(uint* pOut, const fg_surface pSurface); +/** + Get the colors buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pSurface is the surface handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_surface_cbo_size(uint* pOut, const fg_surface pSurface); +/** + Get the alpha values buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pSurface is the surface handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_surface_abo_size(uint* pOut, const fg_surface pSurface); +/** @} */ + #ifdef __cplusplus } #endif #ifdef __cplusplus -namespace fg +namespace forge { /** @@ -66,35 +161,35 @@ class Surface { \param[in] pNumXPoints is number of data points along X dimension \param[in] pNumYPoints is number of data points along Y dimension \param[in] pDataType takes one of the values of \ref dtype that indicates - the integral data type of plot data + the integral data type of surface data \param[in] pPlotType is the render type which can be one of \ref PlotType (valid choices - are FG_SURFACE and FG_SCATTER) - \param[in] pMarkerType is the type of \ref MarkerType to draw for \ref FG_SCATTER plot type + are FG_PLOT_SURFACE and FG_PLOT_SCATTER) + \param[in] pMarkerType is the type of \ref MarkerType to draw for \ref FG_PLOT_SCATTER plot type */ FGAPI Surface(const uint pNumXPoints, const uint pNumYPoints, const dtype pDataType, const PlotType pPlotType=FG_PLOT_SURFACE, const MarkerType pMarkerType=FG_MARKER_NONE); /** - Copy constructor for Plot + Copy constructor for surface - \param[in] pOther is the Plot of which we make a copy of. + \param[in] pOther is the surface of which we make a copy of. */ FGAPI Surface(const Surface& pOther); /** - Plot Destructor + surface Destructor */ FGAPI ~Surface(); /** - Set the color of line graph(plot) + Set the color of line graph(surface) - \param[in] pColor takes values of fg::Color to define plot color + \param[in] pColor takes values of forge::Color to define surface color */ - FGAPI void setColor(const fg::Color pColor); + FGAPI void setColor(const forge::Color pColor); /** - Set the color of line graph(plot) + Set the color of line graph(surface) \param[in] pRed is Red component in range [0, 1] \param[in] pGreen is Green component in range [0, 1] @@ -105,7 +200,7 @@ class Surface { const float pBlue, const float pAlpha); /** - Set plot legend + Set surface legend \param[in] pLegend */ diff --git a/include/fg/util.h b/include/fg/util.h new file mode 100644 index 00000000..36334929 --- /dev/null +++ b/include/fg/util.h @@ -0,0 +1,93 @@ +/******************************************************* + * Copyright (c) 2015-2019, ArrayFire + * All rights reserved. + * + * This file is distributed under 3-clause BSD license. + * The complete license agreement can be obtained at: + * http://arrayfire.com/licenses/BSD-3-Clause + ********************************************************/ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** \addtogroup util_functions + * @{ + */ + +/** + Update backend specific vertex buffer from given host side memory + + \param[in] pBufferId is the buffer identifier + \param[in] pBufferSize is the buffer size in bytes + \param[in] pBufferData is the pointer of the host side memory + + \return \ref fg_err error code + */ +FGAPI fg_err fg_update_vertex_buffer(const unsigned pBufferId, + const size_t pBufferSize, + const void* pBufferData); + +/** + Update backend specific pixel buffer from given host side memory + + \param[in] pBufferId is the buffer identifier + \param[in] pBufferSize is the buffer size in bytes + \param[in] pBufferData is the pointer of the host side memory + + \return \ref fg_err error code + */ +FGAPI fg_err fg_update_pixel_buffer(const unsigned pBufferId, + const size_t pBufferSize, + const void* pBufferData); + +/** + Sync all rendering operations till this point + + \return \ref fg_err error code + */ +FGAPI fg_err fg_finish(); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +namespace forge +{ + +/** + Update backend specific vertex buffer from given host side memory + + \param[in] pBufferId is the buffer identifier + \param[in] pBufferSize is the buffer size in bytes + \param[in] pBufferData is the pointer of the host side memory + */ +FGAPI void updateVertexBuffer(const unsigned pBufferId, + const size_t pBufferSize, + const void* pBufferData); + +/** + Update backend specific pixel buffer from given host side memory + + \param[in] pBufferId is the buffer identifier + \param[in] pBufferSize is the buffer size in bytes + \param[in] pBufferData is the pointer of the host side memory + */ +FGAPI void updatePixelBuffer(const unsigned pBufferId, + const size_t pBufferSize, + const void* pBufferData); + +/** + Sync all rendering operations till this point + */ +FGAPI void finish(); + +} +#endif diff --git a/include/fg/vector_field.h b/include/fg/vector_field.h index 00e61c8a..bf6d590e 100644 --- a/include/fg/vector_field.h +++ b/include/fg/vector_field.h @@ -16,35 +16,142 @@ extern "C" { #endif +/** \addtogroup vfield_functions + * @{ + */ + +/** + Create a Vector field object + + \param[out] pField will be set to surface handle upon creating the surface object + \param[in] pNPoints is number of data points + \param[in] pType takes one of the values of \ref fg_dtype that indicates + the integral data type of surface data + \param[in] pChartType dictates the dimensionality of the chart + + \return \ref fg_err error code + */ FGAPI fg_err fg_create_vector_field(fg_vector_field *pField, const uint pNPoints, const fg_dtype pType, const fg_chart_type pChartType); +/** + Destroy vector field object + + \param[in] pField is the surface handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_destroy_vector_field(fg_vector_field pField); +/** + Set the color of vector field + + \param[in] pField is the surface handle + \param[in] pRed is Red component in range [0, 1] + \param[in] pGreen is Green component in range [0, 1] + \param[in] pBlue is Blue component in range [0, 1] + \param[in] pAlpha is Blue component in range [0, 1] + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_vector_field_color(fg_vector_field pField, const float pRed, const float pGreen, const float pBlue, const float pAlpha); +/** + Set vector field legend + + \param[in] pField is the vector field handle + \param[in] pLegend + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_vector_field_legend(fg_vector_field pField, const char* pLegend); +/** + Get the resource identifier for vertices buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pField is the vector field handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_vector_field_vbo(uint* pOut, const fg_vector_field pField); +/** + Get the resource identifier for colors buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pField is the vector field handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_vector_field_cbo(uint* pOut, const fg_vector_field pField); +/** + Get the resource identifier for alpha values buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pField is the vector field handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_vector_field_abo(uint* pOut, const fg_vector_field pField); +/** + Get the resource identifier for directions buffer + + \param[out] pOut will have the buffer identifier after this function is called + \param[in] pField is the vector field handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_vector_field_dbo(uint* pOut, const fg_vector_field pField); +/** + Get the vertices buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pField is the vector field handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_vector_field_vbo_size(uint* pOut, const fg_vector_field pField); +/** + Get the colors buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pField is the vector field handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_vector_field_cbo_size(uint* pOut, const fg_vector_field pField); +/** + Get the alpha values buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pField is the vector field handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_vector_field_abo_size(uint* pOut, const fg_vector_field pField); +/** + Get the directions buffer size in bytes + + \param[out] pOut will have the buffer size in bytes after this function is called + \param[in] pField is the vector field handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_vector_field_dbo_size(uint* pOut, const fg_vector_field pField); +/** @} */ + #ifdef __cplusplus } #endif @@ -52,7 +159,7 @@ FGAPI fg_err fg_get_vector_field_dbo_size(uint* pOut, const fg_vector_field pFie #ifdef __cplusplus -namespace fg +namespace forge { /** @@ -90,9 +197,9 @@ class VectorField { /** Set global color for the field lines - \param[in] pColor takes values of fg::Color to define VectorField color + \param[in] pColor takes values of forge::Color to define VectorField color */ - FGAPI void setColor(const fg::Color pColor); + FGAPI void setColor(const forge::Color pColor); /** Set global color for the field lines diff --git a/include/fg/window.h b/include/fg/window.h index f3462e2a..50e52893 100644 --- a/include/fg/window.h +++ b/include/fg/window.h @@ -21,56 +21,252 @@ extern "C" { #endif +/** \addtogroup win_functions + * @{ + */ + +/** + Create a Window object. + + \param[out] pWindow is set to the window created + \param[in] pWidth Width of the display window + \param[in] pHeight Height of the display window + \param[in] pTitle window Title + \param[in] pShareWindow is an already existing window with which the window to + be created should share the OpenGL context. + \param[in] pInvisible indicates if the window is created in invisible mode. + + \return \ref fg_err error code + */ FGAPI fg_err fg_create_window(fg_window *pWindow, const int pWidth, const int pHeight, const char* pTitle, const fg_window pShareWindow, const bool pInvisible); +/** + Destroy Window Object + + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_destroy_window(fg_window pWindow); +/** + Set font object to be used by Window Object + + \param[in] pWindow is Window handle + \param[in] pFont is Font handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_window_font(fg_window pWindow, fg_font pFont); +/** + Set the title of Window Object + + \param[in] pWindow is Window handle + \param[in] pTitle is the window tile + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_window_title(fg_window pWindow, const char* pTitle); +/** + Set the window origin of Window Object w.r.t screen origin + + \param[in] pWindow is Window handle + \param[in] pX is the x coordinate of window top left corner + \param[in] pY is the y coordinate of window top left corner + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_window_position(fg_window pWindow, const int pX, const int pY); +/** + Set the window dimensions of Window Object + + \param[in] pWindow is Window handle + \param[in] pWidth is the width of window + \param[in] pHeight is the height of window + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_window_size(fg_window pWindow, const uint pWidth, const uint pHeight); +/** + Set the colormap to be used by the Window Object + + \param[in] pWindow is Window handle + \param[in] pColorMap takes one of the values of enum \ref fg_color_map + + \return \ref fg_err error code + */ FGAPI fg_err fg_set_window_colormap(fg_window pWindow, const fg_color_map pColorMap); +/** + Get the backend specific context handle of Window + + \param[out] pContext is set to the backend specific context handle + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_window_context_handle(long long *pContext, const fg_window pWindow); +/** + Get the display device handle of Window + + \param[out] pDisplay is set to the display device handle + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_window_display_handle(long long *pDisplay, const fg_window pWindow); +/** + Get the width of Window + + \param[out] pWidth is set to the width of the Window + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_window_width(int *pWidth, const fg_window pWindow); +/** + Get the height of Window + + \param[out] pHeight is set to the height of the Window + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_get_window_height(int *pHeight, const fg_window pWindow); +/** + Make the window's backend specific context the active context in given thread + + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_make_window_current(const fg_window pWindow); +/** + Hide the Window + + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_hide_window(const fg_window pWindow); +/** + Show the Window + + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_show_window(const fg_window pWindow); +/** + Check if the Window is closed + + \param[out] pIsClosed is set to boolean value if the window is closed + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_close_window(bool* pIsClosed, const fg_window pWindow); +/** + Render given image to Window + + \param[in] pWindow is Window handle + \param[in] pImage is Image handle + \param[in] pKeepAspectRatio is boolean indicating if the image aspect ratio has to be maintained while rendering the image + + \return \ref fg_err error code + */ FGAPI fg_err fg_draw_image(const fg_window pWindow, const fg_image pImage, const bool pKeepAspectRatio); +/** + Render given chart to Window + + \param[in] pWindow is Window handle + \param[in] pChart is chart handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_draw_chart(const fg_window pWindow, const fg_chart pChart); +/** + Setup grid layout for multiple view rendering on Window + + \param[in] pRows is the number of rows in multiview mode + \param[in] pCols is the number of columns in multiview mode + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_setup_window_layout(int pRows, int pCols, fg_window pWindow); +/** + Render given image to Window's particular sub-view + + \param[in] pWindow is Window handle + \param[in] pColId is the column identifier of sub-view where image is to be rendered + \param[in] pRowId is the row identifier of sub-view where image is to be rendered + \param[in] pImage is image handle + \param[in] pTitle is the title of the sub-view + \param[in] pKeepAspectRatio is boolean indicating if the image aspect ratio has to be maintained while rendering the image + + \return \ref fg_err error code + */ FGAPI fg_err fg_draw_image_to_cell(const fg_window pWindow, int pColId, int pRowId, const fg_image pImage, const char* pTitle, const bool pKeepAspectRatio); +/** + Render given chart to Window's particular sub-view + + \param[in] pWindow is Window handle + \param[in] pColId is the column identifier of sub-view where image is to be rendered + \param[in] pRowId is the row identifier of sub-view where image is to be rendered + \param[in] pChart is chart handle + \param[in] pTitle is the title of the sub-view + + \return \ref fg_err error code + */ FGAPI fg_err fg_draw_chart_to_cell(const fg_window pWindow, int pColId, int pRowId, const fg_chart pChart, const char* pTitle); +/** + Swap back buffer with front buffer + + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_swap_window_buffers(const fg_window pWindow); +/** + Save the current frame buffer to a file at provided path. + + The frame buffer stored to the disk is saved in the image format based on the extension + provided in the full file path string. + + \param[in] pFullPath is the path at which frame buffer is stored. + \param[in] pWindow is Window handle + + \return \ref fg_err error code + */ FGAPI fg_err fg_save_window_framebuffer(const char* pFullPath, const fg_window pWindow); +/** @} */ + #ifdef __cplusplus } #endif @@ -78,7 +274,7 @@ FGAPI fg_err fg_save_window_framebuffer(const char* pFullPath, const fg_window p #ifdef __cplusplus -namespace fg +namespace forge { /** diff --git a/include/forge.h b/include/forge.h index dd8e0edc..d008c557 100644 --- a/include/forge.h +++ b/include/forge.h @@ -9,7 +9,29 @@ #pragma once +/** + +\defgroup c_api_functions C API functions +Categorically divided into groups based on the renderable +they are related to. +@{ + + \defgroup chart_functions Chart + \defgroup font_functions Font + \defgroup hist_functions Histogram + \defgroup image_functions Image + \defgroup plot_functions Plot + \defgroup surf_functions Surface + \defgroup util_functions Utility & Helper Functions + \defgroup vfield_functions Vector Field + \defgroup win_functions Window + +@} + +*/ + #include "fg/defines.h" +#include "fg/util.h" #include "fg/exception.h" #include "fg/window.h" #include "fg/font.h" diff --git a/src/api/c/chart.cpp b/src/api/c/chart.cpp index a0a247a0..d8cd63e9 100644 --- a/src/api/c/chart.cpp +++ b/src/api/c/chart.cpp @@ -23,6 +23,8 @@ #include #include +using namespace forge; + fg_err fg_create_chart(fg_chart *pHandle, const fg_chart_type pChartType) { @@ -86,7 +88,7 @@ fg_err fg_add_image_to_chart(fg_image* pImage, fg_chart pHandle, const fg_dtype pType) { try { - common::Image* img = new common::Image(pWidth, pHeight, pFormat, (fg::dtype)pType); + common::Image* img = new common::Image(pWidth, pHeight, pFormat, (forge::dtype)pType); getChart(pHandle)->addRenderable(img->impl()); *pImage = getHandle(img); } @@ -102,11 +104,11 @@ fg_err fg_add_histogram_to_chart(fg_histogram* pHistogram, fg_chart pHandle, common::Chart* chrt = getChart(pHandle); if (chrt->chartType()== FG_CHART_2D) { - common::Histogram* hist = new common::Histogram(pNBins, (fg::dtype)pType); + common::Histogram* hist = new common::Histogram(pNBins, (forge::dtype)pType); chrt->addRenderable(hist->impl()); *pHistogram = getHandle(hist); } else { - throw fg::ArgumentError("Chart::render", __LINE__, 5, + throw forge::ArgumentError("Chart::render", __LINE__, 5, "Can add histogram to a 2d chart only"); } } @@ -121,15 +123,15 @@ fg_err fg_add_plot_to_chart(fg_plot* pPlot, fg_chart pHandle, { try { common::Chart* chrt = getChart(pHandle); - fg::ChartType ctype = chrt->chartType(); + forge::ChartType ctype = chrt->chartType(); if (ctype == FG_CHART_2D) { - common::Plot* plt = new common::Plot(pNPoints, (fg::dtype)pType, pPlotType, + common::Plot* plt = new common::Plot(pNPoints, (forge::dtype)pType, pPlotType, pMarkerType, FG_CHART_2D); chrt->addRenderable(plt->impl()); *pPlot = getHandle(plt); } else { - common::Plot* plt = new common::Plot(pNPoints, (fg::dtype)pType, pPlotType, + common::Plot* plt = new common::Plot(pNPoints, (forge::dtype)pType, pPlotType, pMarkerType, FG_CHART_3D); chrt->addRenderable(plt->impl()); *pPlot = getHandle(plt); @@ -146,15 +148,15 @@ fg_err fg_add_surface_to_chart(fg_surface* pSurface, fg_chart pHandle, { try { common::Chart* chrt = getChart(pHandle); - fg::ChartType ctype = chrt->chartType(); + forge::ChartType ctype = chrt->chartType(); if (ctype == FG_CHART_3D) { - common::Surface* surf = new common::Surface(pXPoints, pYPoints, (fg::dtype)pType, + common::Surface* surf = new common::Surface(pXPoints, pYPoints, (forge::dtype)pType, pPlotType, pMarkerType); chrt->addRenderable(surf->impl()); *pSurface = getHandle(surf); } else { - throw fg::ArgumentError("Chart::render", __LINE__, 5, + throw forge::ArgumentError("Chart::render", __LINE__, 5, "Can add surface plot to a 3d chart only"); } } @@ -169,7 +171,7 @@ fg_err fg_add_vector_field_to_chart(fg_vector_field* pField, fg_chart pHandle, try { common::Chart* chrt = getChart(pHandle); common::VectorField* field = new common::VectorField(pNPoints, - (fg::dtype)pType, + (forge::dtype)pType, chrt->chartType()); chrt->addRenderable(field->impl()); *pField = getHandle(field); @@ -185,7 +187,7 @@ fg_err fg_render_chart(const fg_window pWindow, const fg_chart pChart, try { getChart(pChart)->render(getWindow(pWindow)->getID(), pX, pY, pWidth, pHeight, - IDENTITY); + IDENTITY, IDENTITY); } CATCHALL diff --git a/src/api/c/font.cpp b/src/api/c/font.cpp index 542210d9..c3bfc6bc 100644 --- a/src/api/c/font.cpp +++ b/src/api/c/font.cpp @@ -12,6 +12,8 @@ #include #include +using namespace forge; + fg_err fg_create_font(fg_font* pFont) { try { diff --git a/src/api/c/histogram.cpp b/src/api/c/histogram.cpp index 1da870bd..c7df0f47 100644 --- a/src/api/c/histogram.cpp +++ b/src/api/c/histogram.cpp @@ -12,11 +12,13 @@ #include #include +using namespace forge; + fg_err fg_create_histogram(fg_histogram *pHistogram, const uint pNBins, const fg_dtype pType) { try { - *pHistogram = getHandle(new common::Histogram(pNBins, (fg::dtype)pType)); + *pHistogram = getHandle(new common::Histogram(pNBins, (forge::dtype)pType)); } CATCHALL diff --git a/src/api/c/image.cpp b/src/api/c/image.cpp index c4add0fb..6f562315 100644 --- a/src/api/c/image.cpp +++ b/src/api/c/image.cpp @@ -18,12 +18,14 @@ #include #include +using namespace forge; + fg_err fg_create_image(fg_image* pImage, const uint pWidth, const uint pHeight, const fg_channel_format pFormat, const fg_dtype pType) { try { - *pImage = getHandle(new common::Image(pWidth, pHeight, pFormat, (fg::dtype)pType)); + *pImage = getHandle(new common::Image(pWidth, pHeight, pFormat, (forge::dtype)pType)); } CATCHALL @@ -127,7 +129,7 @@ fg_err fg_render_image(const fg_window pWindow, try { getImage(pImage)->render(getWindow(pWindow)->getID(), pX, pY, pWidth, pHeight, - IDENTITY); + IDENTITY, IDENTITY); } CATCHALL diff --git a/src/api/c/plot.cpp b/src/api/c/plot.cpp index dfc63b79..17dfbced 100644 --- a/src/api/c/plot.cpp +++ b/src/api/c/plot.cpp @@ -12,6 +12,8 @@ #include #include +using namespace forge; + fg_err fg_create_plot(fg_plot *pPlot, const uint pNPoints, const fg_dtype pType, const fg_chart_type pChartType, @@ -19,7 +21,7 @@ fg_err fg_create_plot(fg_plot *pPlot, const fg_marker_type pMarkerType) { try { - *pPlot = getHandle(new common::Plot(pNPoints, (fg::dtype)pType, pPlotType, + *pPlot = getHandle(new common::Plot(pNPoints, (forge::dtype)pType, pPlotType, pMarkerType, pChartType)); } CATCHALL diff --git a/src/api/c/surface.cpp b/src/api/c/surface.cpp index 4816729a..0f9148f8 100644 --- a/src/api/c/surface.cpp +++ b/src/api/c/surface.cpp @@ -12,6 +12,8 @@ #include #include +using namespace forge; + fg_err fg_create_surface(fg_surface *pSurface, const uint pXPoints, const uint pYPoints, const fg_dtype pType, @@ -19,7 +21,7 @@ fg_err fg_create_surface(fg_surface *pSurface, const fg_marker_type pMarkerType) { try { - *pSurface = getHandle(new common::Surface(pXPoints, pYPoints, (fg::dtype)pType, + *pSurface = getHandle(new common::Surface(pXPoints, pYPoints, (forge::dtype)pType, pPlotType, pMarkerType)); } CATCHALL diff --git a/src/api/c/vector_field.cpp b/src/api/c/vector_field.cpp index 071cacb3..9099c5b0 100644 --- a/src/api/c/vector_field.cpp +++ b/src/api/c/vector_field.cpp @@ -12,13 +12,15 @@ #include #include +using namespace forge; + fg_err fg_create_vector_field(fg_vector_field *pField, const uint pNPoints, const fg_dtype pType, const fg_chart_type pChartType) { try { - *pField = getHandle(new common::VectorField(pNPoints, (fg::dtype)pType, pChartType)); + *pField = getHandle(new common::VectorField(pNPoints, (forge::dtype)pType, pChartType)); } CATCHALL diff --git a/src/api/c/window.cpp b/src/api/c/window.cpp index a99c1d41..d07ee82c 100644 --- a/src/api/c/window.cpp +++ b/src/api/c/window.cpp @@ -13,6 +13,8 @@ #include #include +using namespace forge; + fg_err fg_create_window(fg_window *pWindow, const int pWidth, const int pHeight, const char* pTitle, diff --git a/src/api/cpp/chart.cpp b/src/api/cpp/chart.cpp index 20545154..fb50941a 100644 --- a/src/api/cpp/chart.cpp +++ b/src/api/cpp/chart.cpp @@ -22,7 +22,7 @@ #include #include -namespace fg +namespace forge { Chart::Chart(const ChartType cType) @@ -148,7 +148,7 @@ void Chart::render(const Window& pWindow, { getChart(mValue)->render(getWindow(pWindow.get())->getID(), pX, pY, pVPW, pVPH, - IDENTITY); + IDENTITY, IDENTITY); } fg_chart Chart::get() const diff --git a/src/api/cpp/exception.cpp b/src/api/cpp/exception.cpp index 79c5b462..bcbf255e 100644 --- a/src/api/cpp/exception.cpp +++ b/src/api/cpp/exception.cpp @@ -18,7 +18,7 @@ using std::string; using std::stringstream; using std::cerr; -std::string getName(fg::dtype pType) +std::string getName(forge::dtype pType) { // TODO return std::string("test"); @@ -33,7 +33,7 @@ void stringcopy(char* dest, const char* src, size_t len) #endif } -namespace fg +namespace forge { Error::Error(const char * const pFuncName, const int pLine, @@ -56,7 +56,7 @@ Error::~Error() throw() {} TypeError::TypeError(const char * const pFuncName, const int pLine, - const int pIndex, const fg::dtype pType) + const int pIndex, const forge::dtype pType) : Error(pFuncName, pLine, "Invalid data type", FG_ERR_INVALID_TYPE), mArgIndex(pIndex) { std::string str = getName(pType); /* TODO getName has to be defined */ diff --git a/src/api/cpp/font.cpp b/src/api/cpp/font.cpp index 91bd7410..4bce661d 100644 --- a/src/api/cpp/font.cpp +++ b/src/api/cpp/font.cpp @@ -12,7 +12,7 @@ #include #include -namespace fg +namespace forge { Font::Font() diff --git a/src/api/cpp/histogram.cpp b/src/api/cpp/histogram.cpp index 9a1f7370..98758a41 100644 --- a/src/api/cpp/histogram.cpp +++ b/src/api/cpp/histogram.cpp @@ -12,7 +12,7 @@ #include #include -namespace fg +namespace forge { Histogram::Histogram(const uint pNBins, const dtype pDataType) diff --git a/src/api/cpp/image.cpp b/src/api/cpp/image.cpp index 46c9f28f..db96432c 100644 --- a/src/api/cpp/image.cpp +++ b/src/api/cpp/image.cpp @@ -17,7 +17,7 @@ #include #include -namespace fg +namespace forge { Image::Image(const uint pWidth, const uint pHeight, @@ -61,12 +61,12 @@ ChannelFormat Image::pixelFormat() const return getImage(mValue)->pixelFormat(); } -fg::dtype Image::channelType() const +forge::dtype Image::channelType() const { return getImage(mValue)->channelType(); } -GLuint Image::pbo() const +uint Image::pbo() const { return getImage(mValue)->pbo(); } @@ -81,7 +81,7 @@ void Image::render(const Window& pWindow, { getImage(mValue)->render(getWindow(pWindow.get())->getID(), pX, pY, pVPW, pVPH, - IDENTITY); + IDENTITY, IDENTITY); } diff --git a/src/api/cpp/plot.cpp b/src/api/cpp/plot.cpp index 47d90347..a577b0c9 100644 --- a/src/api/cpp/plot.cpp +++ b/src/api/cpp/plot.cpp @@ -12,7 +12,7 @@ #include #include -namespace fg +namespace forge { Plot::Plot(const uint pNumPoints, const dtype pDataType, const ChartType pChartType, diff --git a/src/api/cpp/surface.cpp b/src/api/cpp/surface.cpp index c18fc42c..bcebb2c1 100644 --- a/src/api/cpp/surface.cpp +++ b/src/api/cpp/surface.cpp @@ -12,7 +12,7 @@ #include #include -namespace fg +namespace forge { Surface::Surface(unsigned pNumXPoints, unsigned pNumYPoints, dtype pDataType, PlotType pPlotType, MarkerType pMarkerType) diff --git a/src/api/cpp/vector_field.cpp b/src/api/cpp/vector_field.cpp index 42ae1463..86965b78 100644 --- a/src/api/cpp/vector_field.cpp +++ b/src/api/cpp/vector_field.cpp @@ -12,7 +12,7 @@ #include #include -namespace fg +namespace forge { VectorField::VectorField(const uint pNumPoints, const dtype pDataType, const ChartType pChartType) diff --git a/src/api/cpp/window.cpp b/src/api/cpp/window.cpp index 516a7f47..6cd5d7ed 100644 --- a/src/api/cpp/window.cpp +++ b/src/api/cpp/window.cpp @@ -12,7 +12,7 @@ #include #include -namespace fg +namespace forge { Window::Window(int pWidth, int pHeight, const char* pTitle, const Window* pWindow, const bool invisible) diff --git a/src/backend/chart.hpp b/src/backend/chart.hpp index 00c4a384..7ed95495 100644 --- a/src/backend/chart.hpp +++ b/src/backend/chart.hpp @@ -18,23 +18,25 @@ #include +namespace forge +{ namespace common { class Chart { private: - fg::ChartType mChartType; + forge::ChartType mChartType; std::shared_ptr mChart; public: - Chart(const fg::ChartType cType) + Chart(const forge::ChartType cType) : mChartType(cType) { if (cType == FG_CHART_2D) { mChart = std::make_shared(); } else if (cType == FG_CHART_3D) { mChart = std::make_shared(); } else { - throw fg::ArgumentError("Chart::Chart", + throw forge::ArgumentError("Chart::Chart", __LINE__, 0, "Invalid chart type"); } @@ -44,7 +46,7 @@ class Chart { mChart = reinterpret_cast(pOther)->impl(); } - inline fg::ChartType chartType() const { + inline forge::ChartType chartType() const { return mChartType; } @@ -74,9 +76,10 @@ class Chart { inline void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView) const { - mChart->render(pWindowId, pX, pY, pVPW, pVPH, pView); + const glm::mat4 &pView, const glm::mat4 &pOrient) const { + mChart->render(pWindowId, pX, pY, pVPW, pVPH, pView, pOrient); } }; } +} diff --git a/src/backend/chart_common.hpp b/src/backend/chart_common.hpp index a3f8b9b2..3d860b62 100644 --- a/src/backend/chart_common.hpp +++ b/src/backend/chart_common.hpp @@ -13,6 +13,8 @@ #include +namespace forge +{ namespace common { @@ -45,15 +47,15 @@ class ChartRenderableBase { mShrdPtr->setLegend(pLegend); } - inline GLuint vbo() const { + inline uint vbo() const { return mShrdPtr->vbo(); } - inline GLuint cbo() const { + inline uint cbo() const { return mShrdPtr->cbo(); } - inline GLuint abo() const { + inline uint abo() const { return mShrdPtr->abo(); } @@ -77,3 +79,4 @@ class ChartRenderableBase { }; } +} diff --git a/src/backend/chart_renderables.hpp b/src/backend/chart_renderables.hpp index 6e635642..0b5893ec 100644 --- a/src/backend/chart_renderables.hpp +++ b/src/backend/chart_renderables.hpp @@ -18,12 +18,14 @@ #include +namespace forge +{ namespace common { class Histogram : public ChartRenderableBase { public: - Histogram(uint pNBins, fg::dtype pDataType) + Histogram(uint pNBins, forge::dtype pDataType) : ChartRenderableBase( std::make_shared(pNBins, pDataType)) { } @@ -36,9 +38,9 @@ class Histogram : public ChartRenderableBase { class Plot : public ChartRenderableBase { public: - Plot(const uint pNumPoints, const fg::dtype pDataType, - const fg::PlotType pPlotType, const fg::MarkerType pMarkerType, - const fg::ChartType pChartType) { + Plot(const uint pNumPoints, const forge::dtype pDataType, + const forge::PlotType pPlotType, const forge::MarkerType pMarkerType, + const forge::ChartType pChartType) { if (pChartType == FG_CHART_2D) { mShrdPtr = std::make_shared< detail::plot2d_impl >(pNumPoints, pDataType, pPlotType, pMarkerType); @@ -57,7 +59,7 @@ class Plot : public ChartRenderableBase { mShrdPtr->setMarkerSize(pMarkerSize); } - inline GLuint mbo() const { + inline uint mbo() const { return mShrdPtr->markers(); } @@ -69,8 +71,8 @@ class Plot : public ChartRenderableBase { class Surface : public ChartRenderableBase { public: Surface(const uint pNumXPoints, const uint pNumYPoints, - const fg::dtype pDataType, const fg::PlotType pPlotType=FG_PLOT_SURFACE, - const fg::MarkerType pMarkerType=FG_MARKER_NONE) { + const forge::dtype pDataType, const forge::PlotType pPlotType=FG_PLOT_SURFACE, + const forge::MarkerType pMarkerType=FG_MARKER_NONE) { switch(pPlotType){ case(FG_PLOT_SURFACE): mShrdPtr = std::make_shared(pNumXPoints, pNumYPoints, pDataType, pMarkerType); @@ -92,8 +94,8 @@ class Surface : public ChartRenderableBase { class VectorField : public ChartRenderableBase { public: VectorField(const uint pNumPoints, - const fg::dtype pDataType, - const fg::ChartType pChartType) { + const forge::dtype pDataType, + const forge::ChartType pChartType) { if (pChartType == FG_CHART_2D) { mShrdPtr = std::make_shared< detail::vector_field2d_impl >(pNumPoints, pDataType); } else { @@ -106,7 +108,7 @@ class VectorField : public ChartRenderableBase { reinterpret_cast(pOther)->impl()) { } - inline GLuint dbo() const { + inline uint dbo() const { return mShrdPtr->directions(); } @@ -116,3 +118,4 @@ class VectorField : public ChartRenderableBase { }; } +} diff --git a/src/backend/err_common.cpp b/src/backend/err_common.cpp index 56624088..89893814 100644 --- a/src/backend/err_common.cpp +++ b/src/backend/err_common.cpp @@ -15,7 +15,7 @@ #include #include -using namespace fg; +using namespace forge; using std::string; using std::stringstream; diff --git a/src/backend/font.hpp b/src/backend/font.hpp index 4947785d..39c36f46 100644 --- a/src/backend/font.hpp +++ b/src/backend/font.hpp @@ -14,6 +14,8 @@ #include +namespace forge +{ namespace common { @@ -46,3 +48,4 @@ class Font { }; } +} diff --git a/src/backend/handle.cpp b/src/backend/handle.cpp index a2a2697b..3f1f1f2d 100644 --- a/src/backend/handle.cpp +++ b/src/backend/handle.cpp @@ -9,6 +9,8 @@ #include +using namespace forge; + fg_window getHandle(common::Window* pValue) { return reinterpret_cast(pValue); diff --git a/src/backend/handle.hpp b/src/backend/handle.hpp index 459bddfd..7aecfff3 100644 --- a/src/backend/handle.hpp +++ b/src/backend/handle.hpp @@ -17,34 +17,34 @@ #include #include -fg_window getHandle(common::Window* pValue); +fg_window getHandle(forge::common::Window* pValue); -fg_font getHandle(common::Font* pValue); +fg_font getHandle(forge::common::Font* pValue); -fg_image getHandle(common::Image* pValue); +fg_image getHandle(forge::common::Image* pValue); -fg_chart getHandle(common::Chart* pValue); +fg_chart getHandle(forge::common::Chart* pValue); -fg_histogram getHandle(common::Histogram* pValue); +fg_histogram getHandle(forge::common::Histogram* pValue); -fg_plot getHandle(common::Plot* pValue); +fg_plot getHandle(forge::common::Plot* pValue); -fg_surface getHandle(common::Surface* pValue); +fg_surface getHandle(forge::common::Surface* pValue); -fg_vector_field getHandle(common::VectorField* pValue); +fg_vector_field getHandle(forge::common::VectorField* pValue); -common::Window* getWindow(const fg_window& pValue); +forge::common::Window* getWindow(const fg_window& pValue); -common::Font* getFont(const fg_font& pValue); +forge::common::Font* getFont(const fg_font& pValue); -common::Image* getImage(const fg_image& pValue); +forge::common::Image* getImage(const fg_image& pValue); -common::Chart* getChart(const fg_chart& pValue); +forge::common::Chart* getChart(const fg_chart& pValue); -common::Histogram* getHistogram(const fg_histogram& pValue); +forge::common::Histogram* getHistogram(const fg_histogram& pValue); -common::Plot* getPlot(const fg_plot& pValue); +forge::common::Plot* getPlot(const fg_plot& pValue); -common::Surface* getSurface(const fg_surface& pValue); +forge::common::Surface* getSurface(const fg_surface& pValue); -common::VectorField* getVectorField(const fg_vector_field& pValue); +forge::common::VectorField* getVectorField(const fg_vector_field& pValue); diff --git a/src/backend/image.hpp b/src/backend/image.hpp index 8d399b71..da8f5a50 100644 --- a/src/backend/image.hpp +++ b/src/backend/image.hpp @@ -16,6 +16,8 @@ #include +namespace forge +{ namespace common { @@ -25,7 +27,7 @@ class Image { public: Image(const uint pWidth, const uint pHeight, - const fg::ChannelFormat pFormat, const fg::dtype pDataType) + const forge::ChannelFormat pFormat, const forge::dtype pDataType) : mImage(std::make_shared(pWidth, pHeight, pFormat, pDataType)) {} Image(const fg_image pOther) { @@ -42,19 +44,20 @@ class Image { inline uint height() const { return mImage->height(); } - inline fg::ChannelFormat pixelFormat() const { return mImage->pixelFormat(); } + inline forge::ChannelFormat pixelFormat() const { return mImage->pixelFormat(); } - inline fg::dtype channelType() const { return mImage->channelType(); } + inline forge::dtype channelType() const { return mImage->channelType(); } - inline GLuint pbo() const { return mImage->pbo(); } + inline uint pbo() const { return mImage->pbo(); } inline size_t size() const { return mImage->size(); } inline void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView) const { - mImage->render(pWindowId, pX, pY, pVPW, pVPH, pView); + const glm::mat4 &pView, const glm::mat4 &pOrient) const { + mImage->render(pWindowId, pX, pY, pVPW, pVPH, pView, pOrient); } }; } +} diff --git a/src/backend/opengl/CMakeLists.txt b/src/backend/opengl/CMakeLists.txt index bcb55766..08051cc6 100755 --- a/src/backend/opengl/CMakeLists.txt +++ b/src/backend/opengl/CMakeLists.txt @@ -1,10 +1,11 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.0) # Prior to GLM 0.9.7.0, the package is found by the FindGLM.cmake module. # This was removed with GLM 0.9.7.0, instead a glm-config.cmake configuration # file is provided. Therefore, both FIND_PACKAGE calls are necessary. FIND_PACKAGE(GLM QUIET) FIND_PACKAGE(glm QUIET) +INCLUDE("${CMAKE_MODULE_PATH}/build_glbinding.cmake") INCLUDE("${CMAKE_MODULE_PATH}/GLSLtoH.cmake") IF((NOT glm_FOUND AND NOT GLM_FOUND) OR (${USE_LOCAL_GLM})) @@ -71,6 +72,7 @@ INCLUDE_DIRECTORIES( ${FREETYPE_INCLUDE_DIRS} ${GLM_INCLUDE_DIRS} ${WTK_INCLUDE_DIRS} + ${GLBINDING_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} "${PROJECT_SOURCE_DIR}/src/api/c" @@ -184,12 +186,12 @@ TARGET_LINK_LIBRARIES(forge PRIVATE ${FREETYPE_LIBRARIES} PRIVATE ${WTK_LIBRARIES} PRIVATE ${OPENGL_gl_LIBRARY} - PRIVATE ${GLEWmx_LIBRARY} + PRIVATE ${GLBINDING_LIBRARIES} PRIVATE ${FREEIMAGE_LIBRARY} PRIVATE ${X11_LIBS} ) -ADD_DEPENDENCIES(forge ${glsl_shader_targets}) +ADD_DEPENDENCIES(forge ${glsl_shader_targets} glbinding) INSTALL(TARGETS forge EXPORT FORGE diff --git a/src/backend/opengl/backend.hpp b/src/backend/opengl/backend.hpp index 07d9c745..52e05738 100644 --- a/src/backend/opengl/backend.hpp +++ b/src/backend/opengl/backend.hpp @@ -11,4 +11,4 @@ #include -namespace detail = opengl; +namespace detail = forge::opengl; diff --git a/src/backend/opengl/chart_impl.cpp b/src/backend/opengl/chart_impl.cpp index 9fee0ee3..e5070795 100644 --- a/src/backend/opengl/chart_impl.cpp +++ b/src/backend/opengl/chart_impl.cpp @@ -31,14 +31,16 @@ #include #include +using namespace gl; using namespace std; + typedef std::vector::const_iterator StringIter; static const int CHART2D_FONT_SIZE = 16; -const std::shared_ptr& getChartFont() +const std::shared_ptr& getChartFont() { - static common::Font gChartFont; + static forge::common::Font gChartFont; static std::once_flag flag; std::call_once(flag, []() { @@ -67,6 +69,8 @@ void pushPoint(vector &points, T x, T y, T z) points.push_back(z); } +namespace forge +{ namespace opengl { @@ -120,8 +124,9 @@ AbstractChart::AbstractChart(const int pLeftMargin, const int pRightMargin, mLeftMargin(pLeftMargin), mRightMargin(pRightMargin), mTopMargin(pTopMargin), mBottomMargin(pBottomMargin), mXMax(1), mXMin(0), mYMax(1), mYMin(0), mZMax(1), mZMin(0), - mXTitle("X-Axis"), mYTitle("Y-Axis"), mZTitle("Z-Axis"), - mDecorVBO(-1), mBorderProgram(-1), mSpriteProgram(-1), + mXTitle("X-Axis"), mYTitle("Y-Axis"), mZTitle("Z-Axis"), mDecorVBO(-1), + mBorderProgram(glsl::chart_vs.c_str(), glsl::chart_fs.c_str()), + mSpriteProgram(glsl::chart_vs.c_str(), glsl::tick_fs.c_str()), mBorderAttribPointIndex(-1), mBorderUniformColorIndex(-1), mBorderUniformMatIndex(-1), mSpriteUniformMatIndex(-1), mSpriteUniformTickcolorIndex(-1), mSpriteUniformTickaxisIndex(-1), @@ -135,16 +140,13 @@ AbstractChart::AbstractChart(const int pLeftMargin, const int pRightMargin, * are loaded into the shared Font object */ getChartFont(); - mBorderProgram = initShaders(glsl::chart_vs.c_str(), glsl::chart_fs.c_str()); - mSpriteProgram = initShaders(glsl::chart_vs.c_str(), glsl::tick_fs.c_str()); + mBorderAttribPointIndex = mBorderProgram.getAttributeLocation("point"); + mBorderUniformColorIndex = mBorderProgram.getUniformLocation("color"); + mBorderUniformMatIndex = mBorderProgram.getUniformLocation("transform"); - mBorderAttribPointIndex = glGetAttribLocation (mBorderProgram, "point"); - mBorderUniformColorIndex = glGetUniformLocation(mBorderProgram, "color"); - mBorderUniformMatIndex = glGetUniformLocation(mBorderProgram, "transform"); - - mSpriteUniformTickcolorIndex = glGetUniformLocation(mSpriteProgram, "tick_color"); - mSpriteUniformMatIndex = glGetUniformLocation(mSpriteProgram, "transform"); - mSpriteUniformTickaxisIndex = glGetUniformLocation(mSpriteProgram, "isYAxis"); + mSpriteUniformTickcolorIndex = mSpriteProgram.getUniformLocation("tick_color"); + mSpriteUniformMatIndex = mSpriteProgram.getUniformLocation("transform"); + mSpriteUniformTickaxisIndex = mSpriteProgram.getUniformLocation("isYAxis"); CheckGL("End AbstractChart::AbstractChart"); } @@ -157,8 +159,6 @@ AbstractChart::~AbstractChart() glDeleteVertexArrays(1, &vao); } glDeleteBuffers(1, &mDecorVBO); - glDeleteProgram(mBorderProgram); - glDeleteProgram(mSpriteProgram); CheckGL("End AbstractChart::~AbstractChart"); } @@ -328,8 +328,7 @@ void chart2d_impl::generateChartData() glDeleteBuffers(1, &mDecorVBO); /* create vbo that has the border and axis data */ - mDecorVBO = createBuffer(GL_ARRAY_BUFFER, decorData.size(), - &(decorData.front()), GL_STATIC_DRAW); + mDecorVBO = createBuffer(GL_ARRAY_BUFFER, decorData.size(), &(decorData.front()), GL_STATIC_DRAW); CheckGL("End chart2d_impl::generateChartData"); } @@ -380,7 +379,7 @@ chart2d_impl::chart2d_impl() void chart2d_impl::render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4& pView) + const glm::mat4& pView, const glm::mat4& pOrient) { CheckGL("Begin chart2d_impl::renderChart"); @@ -403,11 +402,11 @@ void chart2d_impl::render(const int pWindowId, /* Draw grid */ chart2d_impl::bindResources(pWindowId); - glUseProgram(mBorderProgram); + mBorderProgram.bind(); glUniformMatrix4fv(mBorderUniformMatIndex, 1, GL_FALSE, glm::value_ptr(trans)); glUniform4fv(mBorderUniformColorIndex, 1, GRAY); glDrawArrays(GL_LINES, 4+2*mTickCount, 4*mTickCount); - glUseProgram(0); + mBorderProgram.unbind(); chart2d_impl::unbindResources(); glEnable(GL_SCISSOR_TEST); @@ -415,23 +414,23 @@ void chart2d_impl::render(const int pWindowId, /* render all renderables */ for (auto renderable : mRenderables) { renderable->setRanges(mXMin, mXMax, mYMin, mYMax, mZMin, mZMax); - renderable->render(pWindowId, pX, pY, pVPW, pVPH, pView * trans); + renderable->render(pWindowId, pX, pY, pVPW, pVPH, pView * trans, pOrient); } glDisable(GL_SCISSOR_TEST); chart2d_impl::bindResources(pWindowId); - glUseProgram(mBorderProgram); + mBorderProgram.bind(); glUniformMatrix4fv(mBorderUniformMatIndex, 1, GL_FALSE, glm::value_ptr(trans)); glUniform4fv(mBorderUniformColorIndex, 1, BLACK); /* Draw borders */ glDrawArrays(GL_LINE_LOOP, 0, 4); - glUseProgram(0); + mBorderProgram.unbind(); /* bind the sprite shader program to * draw ticks on x and y axes */ glPointSize((GLfloat)mTickSize); - glUseProgram(mSpriteProgram); + mSpriteProgram.bind(); glUniform4fv(mSpriteUniformTickcolorIndex, 1, BLACK); glUniformMatrix4fv(mSpriteUniformMatIndex, 1, GL_FALSE, glm::value_ptr(trans)); @@ -442,7 +441,7 @@ void chart2d_impl::render(const int pWindowId, glUniform1i(mSpriteUniformTickaxisIndex, 0); glDrawArrays(GL_POINTS, 4+mTickCount, mTickCount); - glUseProgram(0); + mSpriteProgram.unbind(); glPointSize(1); chart2d_impl::unbindResources(); @@ -711,7 +710,7 @@ chart3d_impl::chart3d_impl() void chart3d_impl::render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4& pView) + const glm::mat4& pView, const glm::mat4& pOrient) { /* set uniform attributes of shader * for drawing the plot borders */ @@ -728,11 +727,11 @@ void chart3d_impl::render(const int pWindowId, /* draw grid */ chart3d_impl::bindResources(pWindowId); - glUseProgram(mBorderProgram); + mBorderProgram.bind(); glUniformMatrix4fv(mBorderUniformMatIndex, 1, GL_FALSE, glm::value_ptr(PVM)); glUniform4fv(mBorderUniformColorIndex, 1, GRAY); glDrawArrays(GL_LINES, 6+3*mTickCount, 12*mTickCount); - glUseProgram(0); + mBorderProgram.unbind(); chart3d_impl::unbindResources(); glEnable(GL_SCISSOR_TEST); @@ -741,24 +740,24 @@ void chart3d_impl::render(const int pWindowId, /* render all the renderables */ for (auto renderable : mRenderables) { renderable->setRanges(mXMin, mXMax, mYMin, mYMax, mZMin, mZMax); - renderable->render(pWindowId, pX, pY, pVPW, pVPH, renderableMat); + renderable->render(pWindowId, pX, pY, pVPW, pVPH, renderableMat, pOrient); } glDisable(GL_SCISSOR_TEST); /* Draw borders */ chart3d_impl::bindResources(pWindowId); - glUseProgram(mBorderProgram); + mBorderProgram.bind(); glUniformMatrix4fv(mBorderUniformMatIndex, 1, GL_FALSE, glm::value_ptr(PVM)); glUniform4fv(mBorderUniformColorIndex, 1, BLACK); glDrawArrays(GL_LINES, 0, 6); - glUseProgram(0); + mBorderProgram.unbind(); /* bind the sprite shader program to * draw ticks on x and y axes */ glEnable(GL_PROGRAM_POINT_SIZE); glPointSize((GLfloat)mTickSize); - glUseProgram(mSpriteProgram); + mSpriteProgram.bind(); glUniform4fv(mSpriteUniformTickcolorIndex, 1, BLACK); glUniformMatrix4fv(mSpriteUniformMatIndex, 1, GL_FALSE, glm::value_ptr(PVM)); @@ -772,8 +771,8 @@ void chart3d_impl::render(const int pWindowId, glUniform1i(mSpriteUniformTickaxisIndex, 0); glDrawArrays(GL_POINTS, 6 + (2*mTickCount), mTickCount); - glUseProgram(0); - glPointSize(1); + mSpriteProgram.unbind(); + glPointSize((GLfloat)1); glDisable(GL_PROGRAM_POINT_SIZE); chart3d_impl::unbindResources(); @@ -818,3 +817,4 @@ void chart3d_impl::render(const int pWindowId, } } +} diff --git a/src/backend/opengl/chart_impl.hpp b/src/backend/opengl/chart_impl.hpp index 37aaef72..746eead2 100644 --- a/src/backend/opengl/chart_impl.hpp +++ b/src/backend/opengl/chart_impl.hpp @@ -17,6 +17,8 @@ #include #include +namespace forge +{ namespace opengl { @@ -47,22 +49,22 @@ class AbstractChart : public AbstractRenderable { std::string mYTitle; std::string mZTitle; /* OpenGL Objects */ - GLuint mDecorVBO; - GLuint mBorderProgram; - GLuint mSpriteProgram; + gl::GLuint mDecorVBO; + ShaderProgram mBorderProgram; + ShaderProgram mSpriteProgram; /* shader uniform variable locations */ - GLuint mBorderAttribPointIndex; - GLuint mBorderUniformColorIndex; - GLuint mBorderUniformMatIndex; - GLuint mSpriteUniformMatIndex; - GLuint mSpriteUniformTickcolorIndex; - GLuint mSpriteUniformTickaxisIndex; + gl::GLuint mBorderAttribPointIndex; + gl::GLuint mBorderUniformColorIndex; + gl::GLuint mBorderUniformMatIndex; + gl::GLuint mSpriteUniformMatIndex; + gl::GLuint mSpriteUniformTickcolorIndex; + gl::GLuint mSpriteUniformTickaxisIndex; /* Chart legend position*/ float mLegendX; float mLegendY; /* VAO map to store a vertex array object * for each valid window context */ - std::map mVAOMap; + std::map mVAOMap; /* list of renderables to be displayed on the chart*/ std::vector< std::shared_ptr > mRenderables; @@ -132,7 +134,7 @@ class chart2d_impl : public AbstractChart { void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView); + const glm::mat4 &pView, const glm::mat4 &pOrient); }; class chart3d_impl : public AbstractChart { @@ -153,7 +155,8 @@ class chart3d_impl : public AbstractChart { void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView); + const glm::mat4 &pView, const glm::mat4 &pOrient); }; } +} diff --git a/src/backend/opengl/colormap_impl.cpp b/src/backend/opengl/colormap_impl.cpp index aaa51815..2c80b6b1 100644 --- a/src/backend/opengl/colormap_impl.cpp +++ b/src/backend/opengl/colormap_impl.cpp @@ -11,9 +11,13 @@ #include #include +using namespace gl; + #define CREATE_UNIFORM_BUFFER(color_array, size) \ createBuffer(GL_UNIFORM_BUFFER, 4*size, color_array, GL_STATIC_DRAW) +namespace forge +{ namespace opengl { @@ -122,3 +126,4 @@ GLuint colormap_impl::blueLen() const } } +} diff --git a/src/backend/opengl/colormap_impl.hpp b/src/backend/opengl/colormap_impl.hpp index 7e781391..f0cfd339 100644 --- a/src/backend/opengl/colormap_impl.hpp +++ b/src/backend/opengl/colormap_impl.hpp @@ -12,6 +12,8 @@ #include #include +namespace forge +{ namespace opengl { @@ -30,42 +32,43 @@ class colormap_impl { * the size of array declared in the shaders * used by *_impl objects to reflect appropriate * size */ - GLuint mDefaultMapBuffer; - GLuint mSpecMapBuffer; - GLuint mColorsMapBuffer; - GLuint mRedMapBuffer; - GLuint mMoodMapBuffer; - GLuint mHeatMapBuffer; - GLuint mBlueMapBuffer; + gl::GLuint mDefaultMapBuffer; + gl::GLuint mSpecMapBuffer; + gl::GLuint mColorsMapBuffer; + gl::GLuint mRedMapBuffer; + gl::GLuint mMoodMapBuffer; + gl::GLuint mHeatMapBuffer; + gl::GLuint mBlueMapBuffer; /* Current color map lengths */ - GLuint mDefMapLen; - GLuint mSpecMapLen; - GLuint mColsMapLen; - GLuint mRedMapLen; - GLuint mMoodMapLen; - GLuint mHeatMapLen; - GLuint mBlueMapLen; + gl::GLuint mDefMapLen; + gl::GLuint mSpecMapLen; + gl::GLuint mColsMapLen; + gl::GLuint mRedMapLen; + gl::GLuint mMoodMapLen; + gl::GLuint mHeatMapLen; + gl::GLuint mBlueMapLen; public: /* constructors and destructors */ colormap_impl(); ~colormap_impl(); - GLuint defaultMap() const; - GLuint spectrum() const; - GLuint colors() const; - GLuint red() const; - GLuint mood() const; - GLuint heat() const; - GLuint blue() const; + gl::GLuint defaultMap() const; + gl::GLuint spectrum() const; + gl::GLuint colors() const; + gl::GLuint red() const; + gl::GLuint mood() const; + gl::GLuint heat() const; + gl::GLuint blue() const; - GLuint defaultLen() const; - GLuint spectrumLen() const; - GLuint colorsLen() const; - GLuint redLen() const; - GLuint moodLen() const; - GLuint heatLen() const; - GLuint blueLen() const; + gl::GLuint defaultLen() const; + gl::GLuint spectrumLen() const; + gl::GLuint colorsLen() const; + gl::GLuint redLen() const; + gl::GLuint moodLen() const; + gl::GLuint heatLen() const; + gl::GLuint blueLen() const; }; } +} diff --git a/src/backend/opengl/common.cpp b/src/backend/opengl/common.cpp index d071b142..08318058 100644 --- a/src/backend/opengl/common.cpp +++ b/src/backend/opengl/common.cpp @@ -18,7 +18,8 @@ #include #include -using namespace fg; +using namespace gl; +using namespace forge; using namespace std; #define PI 3.14159 @@ -29,7 +30,7 @@ typedef struct { GLuint geometry; } Shaders; -GLenum dtype2gl(const fg::dtype pValue) +GLenum dtype2gl(const forge::dtype pValue) { switch(pValue) { case s8: return GL_BYTE; @@ -79,7 +80,7 @@ void printShaderInfoLog(GLint pShader) glGetShaderInfoLog(pShader, infoLogLen, &charsWritten, infoLog); std::cerr << "InfoLog:" << std::endl << infoLog << std::endl; delete [] infoLog; - throw fg::Error("printShaderInfoLog", __LINE__, + throw forge::Error("printShaderInfoLog", __LINE__, "OpenGL Shader compilation failed", FG_ERR_GL_ERROR); } } @@ -98,7 +99,7 @@ void printLinkInfoLog(GLint pProgram) glGetProgramInfoLog(pProgram, infoLogLen, &charsWritten, infoLog); std::cerr << "InfoLog:" << std::endl << infoLog << std::endl; delete [] infoLog; - throw fg::Error("printLinkInfoLog", __LINE__, + throw forge::Error("printLinkInfoLog", __LINE__, "OpenGL Shader linking failed", FG_ERR_GL_ERROR); } } @@ -116,7 +117,7 @@ void attachAndLinkProgram(GLuint pProgram, Shaders pShaders) glGetProgramiv(pProgram,GL_LINK_STATUS, &linked); if (!linked) { std::cerr << "Program did not link." << std::endl; - throw fg::Error("attachAndLinkProgram", __LINE__, + throw forge::Error("attachAndLinkProgram", __LINE__, "OpenGL program linking failed", FG_ERR_GL_ERROR); } printLinkInfoLog(pProgram); @@ -169,12 +170,63 @@ Shaders loadShaders(const char* pVertexShaderSrc, return out; } -GLuint initShaders(const char* pVertShaderSrc, const char* pFragShaderSrc, const char* pGeomShaderSrc) +namespace forge +{ +namespace opengl +{ + +ShaderProgram::ShaderProgram(const char* pVertShaderSrc, + const char* pFragShaderSrc, + const char* pGeomShaderSrc) + : mVertex(0), mFragment(0), mGeometry(0), mProgram(0) { Shaders shrds = loadShaders(pVertShaderSrc, pFragShaderSrc, pGeomShaderSrc); - GLuint shaderProgram = glCreateProgram(); - attachAndLinkProgram(shaderProgram, shrds); - return shaderProgram; + mProgram = glCreateProgram(); + attachAndLinkProgram(mProgram, shrds); + mVertex = shrds.vertex; + mFragment = shrds.fragment; + mGeometry = shrds.geometry; +} + +ShaderProgram::~ShaderProgram() +{ + if (mVertex ) glDeleteShader ( mVertex ); + if (mFragment) glDeleteShader ( mFragment); + if (mGeometry) glDeleteShader ( mGeometry); + if (mProgram ) glDeleteProgram( mProgram ); +} + +gl::GLuint ShaderProgram::getProgramId() const +{ + return mProgram; +} + +GLuint ShaderProgram::getUniformLocation(const char* pAttributeName) +{ + return gl::glGetUniformLocation(mProgram, pAttributeName); +} + +GLuint ShaderProgram::getUniformBlockIndex(const char* pAttributeName) +{ + return gl::glGetUniformBlockIndex(mProgram, pAttributeName); +} + +GLuint ShaderProgram::getAttributeLocation(const char* pAttributeName) +{ + return gl::glGetAttribLocation(mProgram, pAttributeName); +} + +void ShaderProgram::bind() +{ + glUseProgram(mProgram); +} + +void ShaderProgram::unbind() +{ + glUseProgram(0); +} + +} } float clampTo01(const float pValue) @@ -202,7 +254,7 @@ void getFontFilePaths(std::vector& pFiles, StringCchLength(pDir.c_str(), MAX_PATH, &length_of_arg); if (length_of_arg > (MAX_PATH - 3)) { - throw fg::Error("getImageFilePaths", __LINE__, + throw forge::Error("getImageFilePaths", __LINE__, "WIN API call: Directory path is too long", FG_ERR_FILE_NOT_FOUND); } @@ -217,7 +269,7 @@ void getFontFilePaths(std::vector& pFiles, // Find the first file in the directory. hFind = FindFirstFile(szDir, &ffd); if (INVALID_HANDLE_VALUE == hFind) { - throw fg::Error("getImageFilePaths", __LINE__, + throw forge::Error("getImageFilePaths", __LINE__, "WIN API call: file fetch in DIR failed", FG_ERR_FILE_NOT_FOUND); } @@ -237,7 +289,7 @@ void getFontFilePaths(std::vector& pFiles, dwError = GetLastError(); if (dwError != ERROR_NO_MORE_FILES) { - throw fg::Error("getImageFilePaths", __LINE__, + throw forge::Error("getImageFilePaths", __LINE__, "WIN API call: files fetch returned no files", FG_ERR_FILE_NOT_FOUND); } @@ -321,12 +373,15 @@ std::ostream& operator<<(std::ostream& pOut, const glm::mat4& pMat) glm::vec3 trackballPoint(const float pX, const float pY, const float pWidth, const float pHeight) { - float d, a; - float x, y, z; - x = (2*pX - pWidth)/pWidth; - y = (pHeight - 2*pY)/pHeight; - d = sqrt(x*x+y*y); - z = cos((PI/2.0) * ((d < 1.0) ? d : 1.0)); - a = 1.0f / sqrt(x*x + y*y + z*z); - return glm::vec3(x*a,y*a,z*a); + glm::vec3 P = glm::vec3(1.0*pX/pWidth*2 - 1.0, 1.0*pY/pHeight*2 - 1.0, 0); + + P.y = -P.y; + float OP_squared = P.x * P.x + P.y * P.y; + if (OP_squared <= 1*1) { + P.z = sqrt(1*1 - OP_squared); + } else { + P.z = 0; + P = glm::normalize(P); + } + return P; } diff --git a/src/backend/opengl/common.hpp b/src/backend/opengl/common.hpp index 76a6e1c2..39ac799c 100644 --- a/src/backend/opengl/common.hpp +++ b/src/backend/opengl/common.hpp @@ -13,6 +13,9 @@ #include #include +#include +#include + #define GLM_FORCE_RADIANS #include #include @@ -38,7 +41,7 @@ float clampTo01(const float pValue); * * @return GL_* typedef for data type */ -GLenum dtype2gl(const fg::dtype pValue); +gl::GLenum dtype2gl(const forge::dtype pValue); /* Convert forge channel format enum to OpenGL enum to indicate color component layout * @@ -46,7 +49,7 @@ GLenum dtype2gl(const fg::dtype pValue); * * @return OpenGL enum indicating color component layout */ -GLenum ctype2gl(const fg::ChannelFormat pMode); +gl::GLenum ctype2gl(const forge::ChannelFormat pMode); /* Convert forge channel format enum to OpenGL enum to indicate color component layout * @@ -57,17 +60,7 @@ GLenum ctype2gl(const fg::ChannelFormat pMode); * * @return OpenGL enum indicating color component layout */ -GLenum ictype2gl(const fg::ChannelFormat pMode); - -/* Compile OpenGL GLSL vertex and fragment shader sources - * - * @pVertShaderSrc is the vertex shader source code string - * @pFragShaderSrc is the vertex shader source code string - * @pGeomShaderSrc is the vertex shader source code string - * - * @return GLSL program unique identifier for given shader duo - */ -GLuint initShaders(const char* pVertShaderSrc, const char* pFragShaderSrc, const char* pGeomShaderSrc=NULL); +gl::GLenum ictype2gl(const forge::ChannelFormat pMode); /* Create OpenGL buffer object * @@ -79,13 +72,13 @@ GLuint initShaders(const char* pVertShaderSrc, const char* pFragShaderSrc, const * @return OpenGL buffer object identifier */ template -GLuint createBuffer(GLenum pTarget, size_t pSize, const T* pPtr, GLenum pUsage) +gl::GLuint createBuffer(gl::GLenum pTarget, size_t pSize, const T* pPtr, gl::GLenum pUsage) { - GLuint retVal = 0; - glGenBuffers(1, &retVal); - glBindBuffer(pTarget, retVal); - glBufferData(pTarget, pSize*sizeof(T), pPtr, pUsage); - glBindBuffer(pTarget, 0); + gl::GLuint retVal = 0; + gl::glGenBuffers(1, &retVal); + gl::glBindBuffer(pTarget, retVal); + gl::glBufferData(pTarget, pSize*sizeof(T), pPtr, pUsage); + gl::glBindBuffer(pTarget, 0); return retVal; } @@ -112,7 +105,7 @@ std::string toString(const float pVal, const int pPrecision = 2); /* Get a vertex buffer object for quad that spans the screen */ -GLuint screenQuadVBO(const int pWindowId); +gl::GLuint screenQuadVBO(const int pWindowId); /* Get a vertex array object that uses screenQuadVBO * @@ -122,7 +115,7 @@ GLuint screenQuadVBO(const int pWindowId); * * `glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);` */ -GLuint screenQuadVAO(const int pWindowId); +gl::GLuint screenQuadVAO(const int pWindowId); /* Print glm::mat4 to std::cout stream */ std::ostream& operator<<(std::ostream&, const glm::mat4&); @@ -131,6 +124,8 @@ std::ostream& operator<<(std::ostream&, const glm::mat4&); glm::vec3 trackballPoint(const float pX, const float pY, const float pWidth, const float pHeight); +namespace forge +{ namespace opengl { @@ -138,6 +133,30 @@ typedef unsigned int uint; typedef unsigned short ushort; typedef unsigned char uchar; +class ShaderProgram { + private: + gl::GLuint mVertex; + gl::GLuint mFragment; + gl::GLuint mGeometry; + gl::GLuint mProgram; + + public: + ShaderProgram(const char* pVertShaderSrc, + const char* pFragShaderSrc, + const char* pGeomShaderSrc=NULL); + + ~ShaderProgram(); + + gl::GLuint getProgramId() const; + + gl::GLuint getUniformLocation(const char* pAttributeName); + gl::GLuint getUniformBlockIndex(const char* pAttributeName); + gl::GLuint getAttributeLocation(const char* pAttributeName); + + void bind(); + void unbind(); +}; + /* Basic renderable class * * Any object that is renderable to a window should inherit from this @@ -146,14 +165,14 @@ typedef unsigned char uchar; class AbstractRenderable { protected: /* OpenGL buffer objects */ - GLuint mVBO; - GLuint mCBO; - GLuint mABO; + gl::GLuint mVBO; + gl::GLuint mCBO; + gl::GLuint mABO; size_t mVBOSize; size_t mCBOSize; size_t mABOSize; - GLfloat mColor[4]; - GLfloat mRange[6]; + gl::GLfloat mColor[4]; + gl::GLfloat mRange[6]; std::string mLegend; bool mIsPVCOn; bool mIsPVAOn; @@ -166,9 +185,9 @@ class AbstractRenderable { * cbo is for colors of those vertices * abo is for alpha values for those vertices */ - GLuint vbo() const { return mVBO; } - GLuint cbo() { mIsPVCOn = true; return mCBO; } - GLuint abo() { mIsPVAOn = true; return mABO; } + gl::GLuint vbo() const { return mVBO; } + gl::GLuint cbo() { mIsPVCOn = true; return mCBO; } + gl::GLuint abo() { mIsPVAOn = true; return mABO; } size_t vboSize() const { return mVBOSize; } size_t cboSize() const { return mCBOSize; } size_t aboSize() const { return mABOSize; } @@ -219,7 +238,7 @@ class AbstractRenderable { /* virtual function to set colormap, a derviced class might * use it or ignore it if it doesnt have a need for color maps. */ - virtual void setColorMapUBOParams(const GLuint pUBO, const GLuint pSize) { + virtual void setColorMapUBOParams(const gl::GLuint pUBO, const gl::GLuint pSize) { } /* render is a pure virtual function. @@ -238,7 +257,8 @@ class AbstractRenderable { */ virtual void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView) = 0; + const glm::mat4 &pView, const glm::mat4 &pOrient) = 0; }; } +} diff --git a/src/backend/opengl/err_opengl.cpp b/src/backend/opengl/err_opengl.cpp index 2fdfc245..3ba53231 100644 --- a/src/backend/opengl/err_opengl.cpp +++ b/src/backend/opengl/err_opengl.cpp @@ -15,6 +15,8 @@ #include #include +using namespace gl; + void commonErrorCheck(const char *pMsg, const char* pFile, int pLine) { GLenum x = glGetError(); @@ -23,7 +25,7 @@ void commonErrorCheck(const char *pMsg, const char* pFile, int pLine) std::stringstream ss; ss << "GL Error at: "<< pFile << ":"< #include +using namespace gl; + +namespace forge +{ namespace opengl { @@ -108,15 +112,15 @@ FontAtlas::FontAtlas(const size_t pWidth, const size_t pHeight, const size_t pDe { CheckGL("Begin FontAtlas::FontAtlas"); if (!((pDepth == 1) || (pDepth == 3) || (pDepth == 4))) { - throw fg::Error("Font Atlas", __LINE__, "Invalid depth argument", FG_ERR_INTERNAL); + throw forge::Error("Font Atlas", __LINE__, "Invalid depth argument", FG_ERR_INTERNAL); } glGenTextures(1, &mId); glBindTexture(GL_TEXTURE_2D, mId); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, static_cast(GL_CLAMP_TO_EDGE)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, static_cast(GL_CLAMP_TO_EDGE)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast(GL_LINEAR)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, static_cast(GL_LINEAR)); glBindTexture(GL_TEXTURE_2D, 0); // one pixel border around the whole atlas to @@ -243,21 +247,21 @@ void FontAtlas::upload() if (mDepth == 4) { #ifdef GL_UNSIGNED_INT_8_8_8_8_REV - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_BGRA, + glTexImage2D(GL_TEXTURE_2D, 0, static_cast(GL_RGBA), mWidth, mHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, mData.data()); #else - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, + glTexImage2D(GL_TEXTURE_2D, 0, static_cast(GL_RGBA), mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mData.data()); #endif } else if (mDepth == 3) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mWidth, mHeight, 0, GL_RGB, + glTexImage2D(GL_TEXTURE_2D, 0, static_cast(GL_RGB), mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, mData.data()); } else { #if defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, mWidth, mHeight, 0, GL_LUMINANCE, + glTexImage2D(GL_TEXTURE_2D, 0, static_cast(GL_LUMINANCE), mWidth, mHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, mData.data()); #else - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, mWidth, mHeight, 0, GL_RED, + glTexImage2D(GL_TEXTURE_2D, 0, static_cast(GL_RED), mWidth, mHeight, 0, GL_RED, GL_UNSIGNED_BYTE, mData.data()); #endif } @@ -282,3 +286,4 @@ GLuint FontAtlas::atlasTextureId() const } } +} diff --git a/src/backend/opengl/font_atlas_impl.hpp b/src/backend/opengl/font_atlas_impl.hpp index 37cbc982..e7efef52 100644 --- a/src/backend/opengl/font_atlas_impl.hpp +++ b/src/backend/opengl/font_atlas_impl.hpp @@ -28,6 +28,8 @@ #include +namespace forge +{ namespace opengl { @@ -37,7 +39,7 @@ class FontAtlas { size_t mHeight; size_t mDepth; size_t mUsed; - GLuint mId; + gl::GLuint mId; std::vector mData; std::vector nodes; @@ -62,7 +64,7 @@ class FontAtlas { void upload(); void clear(); - GLuint atlasTextureId() const; + gl::GLuint atlasTextureId() const; }; struct Glyph { @@ -86,3 +88,4 @@ struct Glyph { }; } +} diff --git a/src/backend/opengl/font_impl.cpp b/src/backend/opengl/font_impl.cpp index e81e7057..374c17f3 100644 --- a/src/backend/opengl/font_impl.cpp +++ b/src/backend/opengl/font_impl.cpp @@ -48,15 +48,19 @@ static const struct { #define START_CHAR 32 #define END_CHAR 126 +using namespace gl; + /* freetype library types */ +namespace forge +{ namespace opengl { #ifdef NDEBUG /* Relase Mode */ #define FT_THROW_ERROR(msg, error) \ - throw fg::Error("Freetype library", __LINE__, msg, error); + throw forge::Error("Freetype library", __LINE__, msg, error); #else /* Debug Mode */ @@ -65,7 +69,7 @@ namespace opengl std::ostringstream ss; \ ss << "FT_Error (0x"<< std::hex << FT_Errors[err].code <<") : " \ << FT_Errors[err].message << std::endl; \ - throw fg::Error(ss.str().c_str(), __LINE__, msg, err); \ + throw forge::Error(ss.str().c_str(), __LINE__, msg, err); \ } while(0); #endif @@ -133,29 +137,6 @@ void font_impl::loadAtlasWithGlyphs(const size_t pFontSize) FT_THROW_ERROR("FT_Get_Glyph", FG_ERR_FREETYPE_ERROR); } - ////FIXME Renable when outline strokes are working - ///* use stroker to get outline */ - //FT_Stroker stroker; - //bError = FT_Stroker_New(library, &stroker); - //if (bError) { - // FT_Stroker_Done(stroker); - // FT_Done_Face(face); - // FT_Done_FreeType(library); - // FT_THROW_ERROR("FT_Stroker_New", fg::FG_ERR_FREETYPE_ERROR); - //} - - //FT_Stroker_Set(stroker, 16, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); - - ///* stroke the outline to current glyph */ - //bError = FT_Glyph_Stroke(&currGlyph, stroker, 1); - //if (bError) { - // FT_Stroker_Done(stroker); - // FT_Done_Face(face); - // FT_Done_FreeType(library); - // FT_THROW_ERROR("FT_Glyph_Stroke", fg::FG_ERR_FREETYPE_ERROR); - //} - //FT_Stroker_Done(stroker); - /* fixed channel depth of 1 */ bError = FT_Glyph_To_Bitmap(&currGlyph, FT_RENDER_MODE_NORMAL, 0, 1); if (bError) { @@ -255,14 +236,14 @@ void font_impl::destroyGLResources() } font_impl::font_impl() - : mTTFfile(""), mIsFontLoaded(false), mAtlas(new FontAtlas(1024, 1024, 1)), - mVBO(0), mProgram(0), mOrthoW(1), mOrthoH(1) + : mTTFfile(""), mIsFontLoaded(false), mAtlas(new FontAtlas(1024, 1024, 1)), mVBO(0), + mProgram(glsl::font_vs.c_str(), glsl::font_fs.c_str()), + mOrthoW(1), mOrthoH(1) { - mProgram = initShaders(glsl::font_vs.c_str(), glsl::font_fs.c_str()); - mPMatIndex = glGetUniformLocation(mProgram, "projectionMatrix"); - mMMatIndex = glGetUniformLocation(mProgram, "modelViewMatrix"); - mTexIndex = glGetUniformLocation(mProgram, "tex"); - mClrIndex = glGetUniformLocation(mProgram, "textColor"); + mPMatIndex = mProgram.getUniformLocation("projectionMatrix"); + mMMatIndex = mProgram.getUniformLocation("modelViewMatrix"); + mTexIndex = mProgram.getUniformLocation("tex"); + mClrIndex = mProgram.getUniformLocation("textColor"); mGlyphLists.resize(MAX_FONT_SIZE-MIN_FONT_SIZE+1, GlyphList()); } @@ -270,7 +251,6 @@ font_impl::font_impl() font_impl::~font_impl() { destroyGLResources(); - if (mProgram) glDeleteProgram(mProgram); } void font_impl::setOthro2D(int pWidth, int pHeight) @@ -353,14 +333,14 @@ void font_impl::loadSystemFont(const char* const pName) // use fontconfig to get the file FcConfig* config = FcInitLoadConfigAndFonts(); if (!config) { - throw fg::Error("Fontconfig init failed", + throw forge::Error("Fontconfig init failed", __LINE__, __PRETTY_FUNCTION__, FG_ERR_FONTCONFIG_ERROR); } // configure the search pattern, FcPattern* pat = FcNameParse((const FcChar8*)(pName)); if (!pat) { - throw fg::Error("Fontconfig name parse failed", + throw forge::Error("Fontconfig name parse failed", __LINE__, __PRETTY_FUNCTION__, FG_ERR_FONTCONFIG_ERROR); } @@ -426,7 +406,7 @@ void font_impl::render(int pWindowId, glDepthFunc(GL_ALWAYS); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glUseProgram(mProgram); + mProgram.bind(); glUniformMatrix4fv(mPMatIndex, 1, GL_FALSE, (GLfloat*)&mProjMat); glUniform4fv(mClrIndex, 1, pColor); @@ -480,7 +460,7 @@ void font_impl::render(int pWindowId, unbindResources(); - glUseProgram(0); + mProgram.unbind(); glDisable(GL_BLEND); glDepthMask(GL_TRUE); glDepthFunc(GL_LESS); @@ -489,3 +469,4 @@ void font_impl::render(int pWindowId, } } +} diff --git a/src/backend/opengl/font_impl.hpp b/src/backend/opengl/font_impl.hpp index 004cb2b5..536665d6 100644 --- a/src/backend/opengl/font_impl.hpp +++ b/src/backend/opengl/font_impl.hpp @@ -19,6 +19,8 @@ static const size_t MIN_FONT_SIZE = 8; static const size_t MAX_FONT_SIZE = 36; +namespace forge +{ namespace opengl { @@ -28,14 +30,14 @@ class font_impl { private: /* VAO map to store a vertex array object * for each valid window context */ - std::map mVAOMap; + std::map mVAOMap; /* attributes */ std::string mTTFfile; bool mIsFontLoaded; FontAtlas* mAtlas; - GLuint mVBO; - GLuint mProgram; + gl::GLuint mVBO; + ShaderProgram mProgram; int mOrthoW; int mOrthoH; @@ -43,10 +45,10 @@ class font_impl { /* OpenGL Data */ glm::mat4 mProjMat; - GLuint mPMatIndex; - GLuint mMMatIndex; - GLuint mTexIndex; - GLuint mClrIndex; + gl::GLuint mPMatIndex; + gl::GLuint mMMatIndex; + gl::GLuint mTexIndex; + gl::GLuint mClrIndex; /* load all glyphs and create character atlas */ void loadAtlasWithGlyphs(const size_t pFontSize); @@ -74,3 +76,4 @@ class font_impl { }; } +} diff --git a/src/backend/opengl/gl_native_handles.cpp b/src/backend/opengl/gl_native_handles.cpp new file mode 100644 index 00000000..eec8fc1e --- /dev/null +++ b/src/backend/opengl/gl_native_handles.cpp @@ -0,0 +1,58 @@ +/******************************************************* +* Copyright (c) 2015-2019, ArrayFire +* All rights reserved. +* +* This file is distributed under 3-clause BSD license. +* The complete license agreement can be obtained at: +* http://arrayfire.com/licenses/BSD-3-Clause +********************************************************/ + +#include + +#ifdef OS_WIN +#include +#elif OS_MAC +#include +#else +#include +#endif + +namespace forge +{ +namespace opengl +{ + +ContextHandle getCurrentContextHandle() +{ + auto id = ContextHandle{0}; + +#if defined(OS_WIN) + const auto context = wglGetCurrentContext(); +#elif defined(OS_LNX) + const auto context = glXGetCurrentContext(); +#else + const auto context = CGLGetCurrentContext(); +#endif + id = reinterpret_cast(context); + + return id; +} + +DisplayHandle getCurrentDisplayHandle() +{ + auto id = DisplayHandle{0}; + +#if defined(OS_WIN) + const auto display = wglGetCurrentDC(); +#elif defined(OS_LNX) + const auto display = glXGetCurrentDisplay(); +#else + const DisplayHandle display = 0; +#endif + id = reinterpret_cast(display); + + return id; +} + +} +} diff --git a/src/backend/opengl/gl_native_handles.hpp b/src/backend/opengl/gl_native_handles.hpp new file mode 100644 index 00000000..93a1397b --- /dev/null +++ b/src/backend/opengl/gl_native_handles.hpp @@ -0,0 +1,25 @@ +/******************************************************* +* Copyright (c) 2015-2019, ArrayFire +* All rights reserved. +* +* This file is distributed under 3-clause BSD license. +* The complete license agreement can be obtained at: +* http://arrayfire.com/licenses/BSD-3-Clause +********************************************************/ + +#pragma once + +namespace forge +{ +namespace opengl +{ + +using ContextHandle = long long; +using DisplayHandle = long long; + +ContextHandle getCurrentContextHandle(); + +DisplayHandle getCurrentDisplayHandle(); + +} +} diff --git a/src/backend/opengl/glfw/window.cpp b/src/backend/opengl/glfw/window.cpp index 6cb6a803..e03f0f7e 100644 --- a/src/backend/opengl/glfw/window.cpp +++ b/src/backend/opengl/glfw/window.cpp @@ -9,18 +9,25 @@ #include #include +#include #include -#include - using glm::rotate; using glm::translate; using glm::scale; +using namespace gl; + +#include +#include +#include + #define GLFW_THROW_ERROR(msg, err) \ - throw fg::Error("Window constructor", __LINE__, msg, err); + throw forge::Error("Window constructor", __LINE__, msg, err); +namespace forge +{ namespace wtk { @@ -51,13 +58,13 @@ Widget::Widget(int pWidth, int pHeight, const char* pTitle, const Widget* pWindo glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, static_cast(GL_TRUE)); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); if (invisible) - glfwWindowHint(GLFW_VISIBLE, GL_FALSE); + glfwWindowHint(GLFW_VISIBLE, static_cast(GL_FALSE)); else - glfwWindowHint(GLFW_VISIBLE, GL_TRUE); + glfwWindowHint(GLFW_VISIBLE, static_cast(GL_TRUE)); glfwWindowHint(GLFW_SAMPLES, 4); mWindow = glfwCreateWindow(pWidth, pHeight, pTitle, nullptr, @@ -126,24 +133,12 @@ void Widget::makeContextCurrent() const long long Widget::getGLContextHandle() { -#ifdef OS_WIN - return reinterpret_cast(glfwGetWGLContext(mWindow)); -#elif OS_LNX - return reinterpret_cast(glfwGetGLXContext(mWindow)); -#else - return 0; -#endif + return opengl::getCurrentContextHandle(); } long long Widget::getDisplayHandle() { -#ifdef OS_WIN - return reinterpret_cast(GetDC(glfwGetWin32Window(mWindow))); -#elif OS_LNX - return reinterpret_cast(glfwGetX11Display()); -#else - return 0; -#endif + return opengl::getCurrentDisplayHandle(); } void Widget::setTitle(const char* pTitle) @@ -220,11 +215,11 @@ void Widget::cursorHandler(const float pXPos, const float pYPos) int r, c; getViewIds(&r, &c); - glm::mat4& mvp = mViewMatrices[r+c*mRows]; + glm::mat4& viewMat = mViewMatrices[r+c*mRows]; if (mButton == GLFW_MOUSE_BUTTON_LEFT) { // Translate - mvp = translate(mvp, glm::vec3(-deltaX, deltaY, 0.0f) * SPEED); + viewMat = translate(viewMat, glm::vec3(-deltaX, deltaY, 0.0f) * SPEED); } else if (mButton == GLFW_MOUSE_BUTTON_LEFT + 10 * GLFW_MOD_ALT || mButton == GLFW_MOUSE_BUTTON_LEFT + 10 * GLFW_MOD_CONTROL) { @@ -233,27 +228,27 @@ void Widget::cursorHandler(const float pXPos, const float pYPos) if(deltaY < 0) { deltaY = 1.0 / (-deltaY); } - mvp = scale(mvp, glm::vec3(pow(deltaY, SPEED))); + viewMat = scale(viewMat, glm::vec3(pow(deltaY, SPEED))); } } else if (mButton == GLFW_MOUSE_BUTTON_RIGHT) { + glm::mat4& orientationMat = mOrientMatrices[r+c*mRows]; // Rotation int width, height; glfwGetWindowSize(mWindow, &width, &height); - glm::vec3 curPos = trackballPoint(pXPos, pYPos, width, height); - glm::vec3 delta = mLastPos - curPos; - float angle = glm::radians(90.0f * sqrt(delta.x*delta.x + delta.y*delta.y + delta.z*delta.z)); - glm::vec3 axis( - mLastPos.y*curPos.z-mLastPos.z*curPos.y, - mLastPos.z*curPos.x-mLastPos.x*curPos.z, - mLastPos.x*curPos.y-mLastPos.y*curPos.x - ); - float dMag = sqrt(dot(delta, delta)); - float aMag = sqrt(dot(axis, axis)); - if (dMag>0 && aMag>0) { - mvp = rotate(mvp, angle, axis); + if (mLastXPos != pXPos || mLastYPos != pYPos) { + glm::vec3 op1 = trackballPoint(mLastXPos, mLastYPos, width, height); + glm::vec3 op2 = trackballPoint(pXPos, pYPos, width, height); + + float angle = std::acos(std::min(1.0f, glm::dot(op1, op2))); + + glm::vec3 axisInCamCoord = glm::cross(op1, op2); + + glm::mat3 camera2object = glm::inverse(glm::mat3(viewMat)); + glm::vec3 axisInObjCoord = camera2object * axisInCamCoord; + + orientationMat = glm::rotate(orientationMat, glm::degrees(angle), axisInObjCoord); } - mLastPos = curPos; } mLastXPos = pXPos; @@ -262,6 +257,11 @@ void Widget::cursorHandler(const float pXPos, const float pYPos) void Widget::mouseButtonHandler(int pButton, int pAction, int pMods) { + double x, y; + glfwGetCursorPos(mWindow, &x, &y); + mLastXPos = x; + mLastYPos = y; + mButton = -1; if (pAction == GLFW_PRESS) { switch(pButton) { @@ -278,6 +278,7 @@ void Widget::mouseButtonHandler(int pButton, int pAction, int pMods) int r, c; getViewIds(&r, &c); mViewMatrices[r+c*mRows] = glm::mat4(1); + mOrientMatrices[r+c*mRows] = glm::mat4(1); } } @@ -301,3 +302,4 @@ void Widget::resizePixelBuffers() } } +} diff --git a/src/backend/opengl/glfw/window.hpp b/src/backend/opengl/glfw/window.hpp index 6274da8e..0a974c92 100644 --- a/src/backend/opengl/glfw/window.hpp +++ b/src/backend/opengl/glfw/window.hpp @@ -9,28 +9,20 @@ #pragma once -#ifdef OS_WIN - #define GLFW_EXPOSE_NATIVE_WIN32 - #define GLFW_EXPOSE_NATIVE_WGL -#endif - -#ifdef OS_LNX - #define GLFW_EXPOSE_NATIVE_X11 - #define GLFW_EXPOSE_NATIVE_GLX -#endif - +#include +#define GLFW_INCLUDE_NONE #include -#ifndef OS_MAC -#include -#endif - #include /* the short form wtk stands for * Windowing Tool Kit */ +namespace forge +{ namespace wtk { +using namespace gl; + class Widget { private: GLFWwindow* mWindow; @@ -56,6 +48,7 @@ class Widget { int mCellWidth; int mCellHeight; std::vector mViewMatrices; + std::vector mOrientMatrices; GLuint mFramePBO; @@ -102,3 +95,4 @@ class Widget { }; } +} diff --git a/src/backend/opengl/histogram_impl.cpp b/src/backend/opengl/histogram_impl.cpp index e65b1f4d..bd1c7abd 100644 --- a/src/backend/opengl/histogram_impl.cpp +++ b/src/backend/opengl/histogram_impl.cpp @@ -19,8 +19,11 @@ #include +using namespace gl; using namespace std; +namespace forge +{ namespace opengl { @@ -67,31 +70,27 @@ void histogram_impl::unbindResources() const glBindVertexArray(0); } -histogram_impl::histogram_impl(const uint pNBins, const fg::dtype pDataType) +histogram_impl::histogram_impl(const uint pNBins, const forge::dtype pDataType) : mDataType(pDataType), mGLType(dtype2gl(mDataType)), mNBins(pNBins), - mProgram(0), mYMaxIndex(-1), mNBinsIndex(-1), mMatIndex(-1), mPointIndex(-1), + mProgram(glsl::histogram_vs.c_str(), glsl::histogram_fs.c_str()), + mYMaxIndex(-1), mNBinsIndex(-1), mMatIndex(-1), mPointIndex(-1), mFreqIndex(-1), mColorIndex(-1), mAlphaIndex(-1), mPVCIndex(-1), mPVAIndex(-1), mBColorIndex(-1) { CheckGL("Begin histogram_impl::histogram_impl"); - mIsPVCOn = false; - mIsPVAOn = false; setColor(0.8f, 0.6f, 0.0f, 1.0f); - mLegend = std::string(""); - - mProgram = initShaders(glsl::histogram_vs.c_str(), glsl::histogram_fs.c_str()); - mYMaxIndex = glGetUniformLocation(mProgram, "ymax" ); - mNBinsIndex = glGetUniformLocation(mProgram, "nbins" ); - mMatIndex = glGetUniformLocation(mProgram, "transform"); - mPVCIndex = glGetUniformLocation(mProgram, "isPVCOn" ); - mPVAIndex = glGetUniformLocation(mProgram, "isPVAOn" ); - mBColorIndex = glGetUniformLocation(mProgram, "barColor" ); - mPointIndex = glGetAttribLocation (mProgram, "point" ); - mFreqIndex = glGetAttribLocation (mProgram, "freq" ); - mColorIndex = glGetAttribLocation (mProgram, "color" ); - mAlphaIndex = glGetAttribLocation (mProgram, "alpha" ); + mYMaxIndex = mProgram.getUniformLocation("ymax" ); + mNBinsIndex = mProgram.getUniformLocation("nbins" ); + mMatIndex = mProgram.getUniformLocation("transform"); + mPVCIndex = mProgram.getUniformLocation("isPVCOn" ); + mPVAIndex = mProgram.getUniformLocation("isPVAOn" ); + mBColorIndex = mProgram.getUniformLocation("barColor" ); + mPointIndex = mProgram.getAttributeLocation("point"); + mFreqIndex = mProgram.getAttributeLocation("freq" ); + mColorIndex = mProgram.getAttributeLocation("color"); + mAlphaIndex = mProgram.getAttributeLocation("alpha"); mVBOSize = mNBins; mCBOSize = 3*mVBOSize; @@ -112,7 +111,7 @@ histogram_impl::histogram_impl(const uint pNBins, const fg::dtype pDataType) case GL_SHORT : HIST_CREATE_BUFFERS(short) ; break; case GL_UNSIGNED_SHORT : HIST_CREATE_BUFFERS(ushort); break; case GL_UNSIGNED_BYTE : HIST_CREATE_BUFFERS(float) ; break; - default: fg::TypeError("histogram_impl::histogram_impl", __LINE__, 1, mDataType); + default: forge::TypeError("histogram_impl::histogram_impl", __LINE__, 1, mDataType); } #undef HIST_CREATE_BUFFERS @@ -126,23 +125,19 @@ histogram_impl::~histogram_impl() GLuint vao = it->second; glDeleteVertexArrays(1, &vao); } - glDeleteBuffers(1, &mVBO); - glDeleteBuffers(1, &mCBO); - glDeleteBuffers(1, &mABO); - glDeleteProgram(mProgram); CheckGL("End histogram_impl::~histogram_impl"); } void histogram_impl::render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4& pView) + const glm::mat4& pView, const glm::mat4& pOrient) { CheckGL("Begin histogram_impl::render"); glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glUseProgram(mProgram); + mProgram.bind(); glUniform1f(mYMaxIndex, mRange[3]); glUniform1f(mNBinsIndex, (GLfloat)mNBins); @@ -158,10 +153,11 @@ void histogram_impl::render(const int pWindowId, glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, mNBins); histogram_impl::unbindResources(); - glUseProgram(0); + mProgram.unbind(); glDisable(GL_BLEND); glDepthMask(GL_TRUE); CheckGL("End histogram_impl::render"); } } +} diff --git a/src/backend/opengl/histogram_impl.hpp b/src/backend/opengl/histogram_impl.hpp index 22314dad..5787fff7 100644 --- a/src/backend/opengl/histogram_impl.hpp +++ b/src/backend/opengl/histogram_impl.hpp @@ -14,32 +14,34 @@ #include #include +namespace forge +{ namespace opengl { class histogram_impl : public AbstractRenderable { private: /* plot points characteristics */ - fg::dtype mDataType; - GLenum mGLType; - GLuint mNBins; + forge::dtype mDataType; + gl::GLenum mGLType; + gl::GLuint mNBins; /* OpenGL Objects */ - GLuint mProgram; + ShaderProgram mProgram; /* internal shader attributes for mProgram * shader program to render histogram bars for each * bin*/ - GLuint mYMaxIndex; - GLuint mNBinsIndex; - GLuint mMatIndex; - GLuint mPointIndex; - GLuint mFreqIndex; - GLuint mColorIndex; - GLuint mAlphaIndex; - GLuint mPVCIndex; - GLuint mPVAIndex; - GLuint mBColorIndex; - - std::map mVAOMap; + gl::GLuint mYMaxIndex; + gl::GLuint mNBinsIndex; + gl::GLuint mMatIndex; + gl::GLuint mPointIndex; + gl::GLuint mFreqIndex; + gl::GLuint mColorIndex; + gl::GLuint mAlphaIndex; + gl::GLuint mPVCIndex; + gl::GLuint mPVAIndex; + gl::GLuint mBColorIndex; + + std::map mVAOMap; /* bind and unbind helper functions * for rendering resources */ @@ -47,12 +49,13 @@ class histogram_impl : public AbstractRenderable { void unbindResources() const; public: - histogram_impl(const uint pNBins, const fg::dtype pDataType); + histogram_impl(const uint pNBins, const forge::dtype pDataType); ~histogram_impl(); void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView); + const glm::mat4 &pView, const glm::mat4 &pOrient); }; } +} diff --git a/src/backend/opengl/image_impl.cpp b/src/backend/opengl/image_impl.cpp index 96e2390a..02aa7ed0 100644 --- a/src/backend/opengl/image_impl.cpp +++ b/src/backend/opengl/image_impl.cpp @@ -21,6 +21,10 @@ #include #include +using namespace gl; + +namespace forge +{ namespace opengl { @@ -35,32 +39,33 @@ void image_impl::unbindResources() const } image_impl::image_impl(const uint pWidth, const uint pHeight, - const fg::ChannelFormat pFormat, const fg::dtype pDataType) + const forge::ChannelFormat pFormat, const forge::dtype pDataType) : mWidth(pWidth), mHeight(pHeight), mFormat(pFormat), mGLformat(ctype2gl(mFormat)), mGLiformat(ictype2gl(mFormat)), mDataType(pDataType), mGLType(dtype2gl(mDataType)), mAlpha(1.0f), - mKeepARatio(true), mFormatSize(1), mMatIndex(-1), mTexIndex(-1), - mNumCIndex(-1), mAlphaIndex(-1), mCMapLenIndex(-1), mCMapIndex(-1) + mKeepARatio(true), mFormatSize(1), mPBOsize(1), mPBO(0), mTex(0), + mProgram(glsl::image_vs.c_str(), glsl::image_fs.c_str()), + mMatIndex(-1), mTexIndex(-1), mNumCIndex(-1), + mAlphaIndex(-1), mCMapLenIndex(-1), mCMapIndex(-1) { CheckGL("Begin image_impl::image_impl"); - mProgram = initShaders(glsl::image_vs.c_str(), glsl::image_fs.c_str()); - mMatIndex = glGetUniformLocation(mProgram, "matrix"); - mCMapIndex = glGetUniformBlockIndex(mProgram, "ColorMap"); - mCMapLenIndex = glGetUniformLocation(mProgram, "cmaplen"); - mTexIndex = glGetUniformLocation(mProgram, "tex"); - mNumCIndex = glGetUniformLocation(mProgram, "numcomps"); - mAlphaIndex = glGetUniformLocation(mProgram, "alpha"); + mMatIndex = mProgram.getUniformLocation("matrix"); + mCMapIndex = mProgram.getUniformBlockIndex("ColorMap"); + mCMapLenIndex = mProgram.getUniformLocation("cmaplen"); + mTexIndex = mProgram.getUniformLocation("tex"); + mNumCIndex = mProgram.getUniformLocation("numcomps"); + mAlphaIndex = mProgram.getUniformLocation("alpha"); // Initialize OpenGL Items glGenTextures(1, &(mTex)); glBindTexture(GL_TEXTURE_2D, mTex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, static_cast(GL_CLAMP_TO_EDGE)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, static_cast(GL_CLAMP_TO_EDGE)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast(GL_NEAREST)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, static_cast(GL_NEAREST)); - glTexImage2D(GL_TEXTURE_2D, 0, mGLiformat, mWidth, mHeight, 0, mGLformat, mGLType, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, static_cast(mGLiformat), mWidth, mHeight, 0, mGLformat, mGLType, NULL); CheckGL("Before PBO Initialization"); glGenBuffers(1, &mPBO); @@ -98,7 +103,6 @@ image_impl::~image_impl() CheckGL("Begin image_impl::~image_impl"); glDeleteBuffers(1, &mPBO); glDeleteTextures(1, &mTex); - glDeleteProgram(mProgram); CheckGL("End image_impl::~image_impl"); } @@ -122,9 +126,9 @@ uint image_impl::width() const { return mWidth; } uint image_impl::height() const { return mHeight; } -fg::ChannelFormat image_impl::pixelFormat() const { return mFormat; } +forge::ChannelFormat image_impl::pixelFormat() const { return mFormat; } -fg::dtype image_impl::channelType() const { return mDataType; } +forge::dtype image_impl::channelType() const { return mDataType; } uint image_impl::pbo() const { return mPBO; } @@ -132,7 +136,7 @@ uint image_impl::size() const { return (uint)mPBOsize; } void image_impl::render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView) + const glm::mat4 &pView, const glm::mat4 &pOrient) { CheckGL("Begin image_impl::render"); @@ -158,7 +162,7 @@ void image_impl::render(const int pWindowId, glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glUseProgram(mProgram); + mProgram.bind(); glUniform1i(mNumCIndex, mFormatSize); glUniform1f(mAlphaIndex, mAlpha); @@ -177,7 +181,7 @@ void image_impl::render(const int pWindowId, glUniform1f(mCMapLenIndex, (GLfloat)mUBOSize); glBindBufferBase(GL_UNIFORM_BUFFER, 0, mColorMapUBO); - glUniformBlockBinding(mProgram, mCMapIndex, 0); + glUniformBlockBinding(mProgram.getProgramId(), mCMapIndex, 0); // Draw to screen bindResources(pWindowId); @@ -188,7 +192,8 @@ void image_impl::render(const int pWindowId, glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); // ubind the shader program - glUseProgram(0); + mProgram.unbind(); + glDisable(GL_BLEND); glDepthMask(GL_TRUE); @@ -196,3 +201,4 @@ void image_impl::render(const int pWindowId, } } +} diff --git a/src/backend/opengl/image_impl.hpp b/src/backend/opengl/image_impl.hpp index d6c47800..32ebbbfc 100644 --- a/src/backend/opengl/image_impl.hpp +++ b/src/backend/opengl/image_impl.hpp @@ -13,6 +13,8 @@ #include +namespace forge +{ namespace opengl { @@ -20,28 +22,28 @@ class image_impl : public AbstractRenderable { private: uint mWidth; uint mHeight; - fg::ChannelFormat mFormat; - GLenum mGLformat; - GLenum mGLiformat; - fg::dtype mDataType; - GLenum mGLType; + forge::ChannelFormat mFormat; + gl::GLenum mGLformat; + gl::GLenum mGLiformat; + forge::dtype mDataType; + gl::GLenum mGLType; float mAlpha; bool mKeepARatio; size_t mFormatSize; /* internal resources for interop */ size_t mPBOsize; - GLuint mPBO; - GLuint mTex; - GLuint mProgram; - GLuint mMatIndex; - GLuint mTexIndex; - GLuint mNumCIndex; - GLuint mAlphaIndex; - GLuint mCMapLenIndex; - GLuint mCMapIndex; + gl::GLuint mPBO; + gl::GLuint mTex; + ShaderProgram mProgram; + gl::GLuint mMatIndex; + gl::GLuint mTexIndex; + gl::GLuint mNumCIndex; + gl::GLuint mAlphaIndex; + gl::GLuint mCMapLenIndex; + gl::GLuint mCMapIndex; /* color map details */ - GLuint mColorMapUBO; - GLuint mUBOSize; + gl::GLuint mColorMapUBO; + gl::GLuint mUBOSize; /* helper functions to bind and unbind * resources for render quad primitive */ @@ -50,23 +52,24 @@ class image_impl : public AbstractRenderable { public: image_impl(const uint pWidth, const uint pHeight, - const fg::ChannelFormat pFormat, const fg::dtype pDataType); + const forge::ChannelFormat pFormat, const forge::dtype pDataType); ~image_impl(); - void setColorMapUBOParams(const GLuint pUBO, const GLuint pSize); + void setColorMapUBOParams(const gl::GLuint pUBO, const gl::GLuint pSize); void setAlpha(const float pAlpha); void keepAspectRatio(const bool pKeep=true); uint width() const; uint height() const; - fg::ChannelFormat pixelFormat() const; - fg::dtype channelType() const; + forge::ChannelFormat pixelFormat() const; + forge::dtype channelType() const; uint pbo() const; uint size() const; void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView); + const glm::mat4 &pView, const glm::mat4 &pOrient); }; } +} diff --git a/src/backend/opengl/plot_impl.cpp b/src/backend/opengl/plot_impl.cpp index e4e7d360..7ff18175 100644 --- a/src/backend/opengl/plot_impl.cpp +++ b/src/backend/opengl/plot_impl.cpp @@ -17,8 +17,11 @@ #include +using namespace gl; using namespace std; +namespace forge +{ namespace opengl { @@ -60,7 +63,7 @@ void plot_impl::unbindResources() const glBindVertexArray(0); } -glm::mat4 plot_impl::computeTransformMat(const glm::mat4 pView) +glm::mat4 plot_impl::computeTransformMat(const glm::mat4 pView, const glm::mat4 pOrient) { static const glm::mat4 MODEL = glm::rotate(glm::mat4(1.0f), -glm::radians(90.f), glm::vec3(0,1,0)) * glm::rotate(glm::mat4(1.0f), -glm::radians(90.f), glm::vec3(1,0,0)); @@ -69,22 +72,19 @@ glm::mat4 plot_impl::computeTransformMat(const glm::mat4 pView) float yRange = mRange[3] - mRange[2]; float zRange = mRange[5] - mRange[4]; - float xDataScale = std::abs(xRange) < 1.0e-3 ? 0.0f : 2/(xRange); - float yDataScale = std::abs(yRange) < 1.0e-3 ? 0.0f : 2/(yRange); - float zDataScale = std::abs(zRange) < 1.0e-3 ? 0.0f : 2/(zRange); + float xDataScale = std::abs(xRange) < 1.0e-3 ? 1.0f : 2/(xRange); + float yDataScale = std::abs(yRange) < 1.0e-3 ? 1.0f : 2/(yRange); + float zDataScale = std::abs(zRange) < 1.0e-3 ? 1.0f : 2/(zRange); float xDataOffset = (-mRange[0] * xDataScale); float yDataOffset = (-mRange[2] * yDataScale); float zDataOffset = (-mRange[4] * zDataScale); - glm::vec3 scaleVector(xDataScale, -1.0f * yDataScale, zDataScale); + glm::vec3 scaleVector(xDataScale, yDataScale, zDataScale); - glm::vec3 shiftVector(-(mRange[0]+mRange[1])/2.0f, - -(mRange[2]+mRange[3])/2.0f, - -(mRange[4]+mRange[5])/2.0f); - shiftVector += glm::vec3(-1 + xDataOffset, -1 + yDataOffset, -1 + zDataOffset); + glm::vec3 shiftVector = glm::vec3(-1 + xDataOffset, -1 + yDataOffset, -1 + zDataOffset); - return pView * glm::translate(glm::scale(MODEL, scaleVector), shiftVector); + return pView * pOrient * MODEL * glm::scale(glm::translate(IDENTITY, shiftVector), scaleVector); } void plot_impl::bindDimSpecificUniforms() @@ -92,32 +92,28 @@ void plot_impl::bindDimSpecificUniforms() glUniform2fv(mPlotRangeIndex, 3, mRange); } -plot_impl::plot_impl(const uint pNumPoints, const fg::dtype pDataType, - const fg::PlotType pPlotType, const fg::MarkerType pMarkerType, const int pD) +plot_impl::plot_impl(const uint pNumPoints, const forge::dtype pDataType, + const forge::PlotType pPlotType, const forge::MarkerType pMarkerType, const int pD) : mDimension(pD), mMarkerSize(12), mNumPoints(pNumPoints), mDataType(pDataType), mGLType(dtype2gl(mDataType)), mMarkerType(pMarkerType), mPlotType(pPlotType), mIsPVROn(false), - mPlotProgram(-1), mMarkerProgram(-1), mRBO(-1), mPlotMatIndex(-1), mPlotPVCOnIndex(-1), - mPlotPVAOnIndex(-1), mPlotUColorIndex(-1), mPlotRangeIndex(-1), mPlotPointIndex(-1), - mPlotColorIndex(-1), mPlotAlphaIndex(-1), mMarkerPVCOnIndex(-1), mMarkerPVAOnIndex(-1), - mMarkerTypeIndex(-1), mMarkerColIndex(-1), mMarkerMatIndex(-1), mMarkerPointIndex(-1), - mMarkerColorIndex(-1), mMarkerAlphaIndex(-1), mMarkerRadiiIndex(-1) + mPlotProgram(pD==2 ? glsl::marker2d_vs.c_str() : glsl::plot3_vs.c_str(), + pD==2 ? glsl::histogram_fs.c_str(): glsl::plot3_fs.c_str()), + mMarkerProgram(pD==2 ? glsl::marker2d_vs.c_str() : glsl::plot3_vs.c_str(), glsl::marker_fs.c_str()), + mRBO(-1), mPlotMatIndex(-1), mPlotPVCOnIndex(-1), mPlotPVAOnIndex(-1), + mPlotUColorIndex(-1), mPlotRangeIndex(-1), mPlotPointIndex(-1), mPlotColorIndex(-1), + mPlotAlphaIndex(-1), mMarkerPVCOnIndex(-1), mMarkerPVAOnIndex(-1), mMarkerTypeIndex(-1), + mMarkerColIndex(-1), mMarkerMatIndex(-1), mMarkerPointIndex(-1), mMarkerColorIndex(-1), + mMarkerAlphaIndex(-1), mMarkerRadiiIndex(-1) { CheckGL("Begin plot_impl::plot_impl"); - mIsPVCOn = false; - mIsPVAOn = false; setColor(0, 1, 0, 1); - mLegend = std::string(""); if (mDimension==2) { - mPlotProgram = initShaders(glsl::marker2d_vs.c_str(), glsl::histogram_fs.c_str()); - mMarkerProgram = initShaders(glsl::marker2d_vs.c_str(), glsl::marker_fs.c_str()); - mPlotUColorIndex = glGetUniformLocation(mPlotProgram, "barColor"); + mPlotUColorIndex = mPlotProgram.getUniformLocation("barColor"); mVBOSize = 2*mNumPoints; } else { - mPlotProgram = initShaders(glsl::plot3_vs.c_str(), glsl::plot3_fs.c_str()); - mMarkerProgram = initShaders(glsl::plot3_vs.c_str(), glsl::marker_fs.c_str()); - mPlotRangeIndex = glGetUniformLocation(mPlotProgram, "minmaxs"); + mPlotRangeIndex = mPlotProgram.getUniformLocation("minmaxs"); mVBOSize = 3*mNumPoints; } @@ -125,24 +121,24 @@ plot_impl::plot_impl(const uint pNumPoints, const fg::dtype pDataType, mABOSize = mNumPoints; mRBOSize = mNumPoints; - mPlotMatIndex = glGetUniformLocation(mPlotProgram, "transform"); - mPlotPVCOnIndex = glGetUniformLocation(mPlotProgram, "isPVCOn"); - mPlotPVAOnIndex = glGetUniformLocation(mPlotProgram, "isPVAOn"); - mPlotPointIndex = glGetAttribLocation (mPlotProgram, "point"); - mPlotColorIndex = glGetAttribLocation (mPlotProgram, "color"); - mPlotAlphaIndex = glGetAttribLocation (mPlotProgram, "alpha"); - - mMarkerMatIndex = glGetUniformLocation(mMarkerProgram, "transform"); - mMarkerPVCOnIndex = glGetUniformLocation(mMarkerProgram, "isPVCOn"); - mMarkerPVAOnIndex = glGetUniformLocation(mMarkerProgram, "isPVAOn"); - mMarkerPVROnIndex = glGetUniformLocation(mMarkerProgram, "isPVROn"); - mMarkerTypeIndex = glGetUniformLocation(mMarkerProgram, "marker_type"); - mMarkerColIndex = glGetUniformLocation(mMarkerProgram, "marker_color"); - mMarkerPSizeIndex = glGetUniformLocation(mMarkerProgram, "psize"); - mMarkerPointIndex = glGetAttribLocation (mMarkerProgram, "point"); - mMarkerColorIndex = glGetAttribLocation (mMarkerProgram, "color"); - mMarkerAlphaIndex = glGetAttribLocation (mMarkerProgram, "alpha"); - mMarkerRadiiIndex = glGetAttribLocation (mMarkerProgram, "pointsize"); + mPlotMatIndex = mPlotProgram.getUniformLocation("transform"); + mPlotPVCOnIndex = mPlotProgram.getUniformLocation("isPVCOn"); + mPlotPVAOnIndex = mPlotProgram.getUniformLocation("isPVAOn"); + mPlotPointIndex = mPlotProgram.getAttributeLocation ("point"); + mPlotColorIndex = mPlotProgram.getAttributeLocation ("color"); + mPlotAlphaIndex = mPlotProgram.getAttributeLocation ("alpha"); + + mMarkerMatIndex = mMarkerProgram.getUniformLocation("transform"); + mMarkerPVCOnIndex = mMarkerProgram.getUniformLocation("isPVCOn"); + mMarkerPVAOnIndex = mMarkerProgram.getUniformLocation("isPVAOn"); + mMarkerPVROnIndex = mMarkerProgram.getUniformLocation("isPVROn"); + mMarkerTypeIndex = mMarkerProgram.getUniformLocation("marker_type"); + mMarkerColIndex = mMarkerProgram.getUniformLocation("marker_color"); + mMarkerPSizeIndex = mMarkerProgram.getUniformLocation("psize"); + mMarkerPointIndex = mMarkerProgram.getAttributeLocation ("point"); + mMarkerColorIndex = mMarkerProgram.getAttributeLocation ("color"); + mMarkerAlphaIndex = mMarkerProgram.getAttributeLocation ("alpha"); + mMarkerRadiiIndex = mMarkerProgram.getAttributeLocation ("pointsize"); #define PLOT_CREATE_BUFFERS(type) \ mVBO = createBuffer(GL_ARRAY_BUFFER, mVBOSize, NULL, GL_DYNAMIC_DRAW); \ @@ -161,10 +157,10 @@ plot_impl::plot_impl(const uint pNumPoints, const fg::dtype pDataType, case GL_SHORT : PLOT_CREATE_BUFFERS(short) ; break; case GL_UNSIGNED_SHORT : PLOT_CREATE_BUFFERS(ushort); break; case GL_UNSIGNED_BYTE : PLOT_CREATE_BUFFERS(float) ; break; - default: fg::TypeError("plot_impl::plot_impl", __LINE__, 1, mDataType); + default: forge::TypeError("plot_impl::plot_impl", __LINE__, 1, mDataType); } #undef PLOT_CREATE_BUFFERS - CheckGL("End plot_impl::plot_impl"); + CheckGL("End plot_impl::plot_impl"); } plot_impl::~plot_impl() @@ -174,11 +170,7 @@ plot_impl::~plot_impl() GLuint vao = it->second; glDeleteVertexArrays(1, &vao); } - glDeleteBuffers(1, &mVBO); - glDeleteBuffers(1, &mCBO); - glDeleteBuffers(1, &mABO); - glDeleteProgram(mPlotProgram); - glDeleteProgram(mMarkerProgram); + glDeleteBuffers(1, &mRBO); CheckGL("End plot_impl::~plot_impl"); } @@ -200,7 +192,7 @@ size_t plot_impl::markersSizes() const void plot_impl::render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4& pView) + const glm::mat4& pView, const glm::mat4& pOrient) { CheckGL("Begin plot_impl::render"); if (mIsPVAOn) { @@ -209,10 +201,10 @@ void plot_impl::render(const int pWindowId, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - glm::mat4 viewModelMatrix = this->computeTransformMat(pView); + glm::mat4 viewModelMatrix = this->computeTransformMat(pView, pOrient); if (mPlotType == FG_PLOT_LINE) { - glUseProgram(mPlotProgram); + mPlotProgram.bind(); this->bindDimSpecificUniforms(); glUniformMatrix4fv(mPlotMatIndex, 1, GL_FALSE, glm::value_ptr(viewModelMatrix)); @@ -223,12 +215,12 @@ void plot_impl::render(const int pWindowId, glDrawArrays(GL_LINE_STRIP, 0, mNumPoints); plot_impl::unbindResources(); - glUseProgram(0); + mPlotProgram.unbind(); } if (mMarkerType != FG_MARKER_NONE) { glEnable(GL_PROGRAM_POINT_SIZE); - glUseProgram(mMarkerProgram); + mMarkerProgram.bind(); glUniformMatrix4fv(mMarkerMatIndex, 1, GL_FALSE, glm::value_ptr(viewModelMatrix)); glUniform1i(mMarkerPVCOnIndex, mIsPVCOn); @@ -242,7 +234,7 @@ void plot_impl::render(const int pWindowId, glDrawArrays(GL_POINTS, 0, mNumPoints); plot_impl::unbindResources(); - glUseProgram(0); + mMarkerProgram.unbind(); glDisable(GL_PROGRAM_POINT_SIZE); } @@ -253,7 +245,7 @@ void plot_impl::render(const int pWindowId, CheckGL("End plot_impl::render"); } -glm::mat4 plot2d_impl::computeTransformMat(const glm::mat4 pView) +glm::mat4 plot2d_impl::computeTransformMat(const glm::mat4 pView, const glm::mat4 pOrient) { float xRange = mRange[1] - mRange[0]; float yRange = mRange[3] - mRange[2]; @@ -261,10 +253,13 @@ glm::mat4 plot2d_impl::computeTransformMat(const glm::mat4 pView) float xDataScale = std::abs(xRange) < 1.0e-3 ? 1.0f : 2/(xRange); float yDataScale = std::abs(yRange) < 1.0e-3 ? 1.0f : 2/(yRange); - glm::vec3 shiftVector(-(mRange[0]+mRange[1])/2.0f, -(mRange[2]+mRange[3])/2.0f, 0.0f); + float xDataOffset = (-mRange[0] * xDataScale); + float yDataOffset = (-mRange[2] * yDataScale); + glm::vec3 scaleVector(xDataScale, yDataScale, 1); + glm::vec3 shiftVector = glm::vec3(-1 + xDataOffset, -1 + yDataOffset, 0); - return pView * glm::translate(glm::scale(IDENTITY, scaleVector), shiftVector); + return pView * glm::scale(glm::translate(IDENTITY, shiftVector), scaleVector); } void plot2d_impl::bindDimSpecificUniforms() @@ -273,3 +268,4 @@ void plot2d_impl::bindDimSpecificUniforms() } } +} diff --git a/src/backend/opengl/plot_impl.hpp b/src/backend/opengl/plot_impl.hpp index 9996db9f..ac2ca3aa 100644 --- a/src/backend/opengl/plot_impl.hpp +++ b/src/backend/opengl/plot_impl.hpp @@ -19,84 +19,87 @@ #include #include +namespace forge +{ namespace opengl { class plot_impl : public AbstractRenderable { protected: - GLuint mDimension; - GLfloat mMarkerSize; + gl::GLuint mDimension; + gl::GLfloat mMarkerSize; /* plot points characteristics */ - GLuint mNumPoints; - fg::dtype mDataType; - GLenum mGLType; - fg::MarkerType mMarkerType; - fg::PlotType mPlotType; - bool mIsPVROn; + gl::GLuint mNumPoints; + forge::dtype mDataType; + gl::GLenum mGLType; + forge::MarkerType mMarkerType; + forge::PlotType mPlotType; + bool mIsPVROn; /* OpenGL Objects */ - GLuint mPlotProgram; - GLuint mMarkerProgram; - GLuint mRBO; - size_t mRBOSize; + ShaderProgram mPlotProgram; + ShaderProgram mMarkerProgram; + gl::GLuint mRBO; + size_t mRBOSize; /* shader variable index locations */ - GLuint mPlotMatIndex; - GLuint mPlotPVCOnIndex; - GLuint mPlotPVAOnIndex; - GLuint mPlotUColorIndex; - GLuint mPlotRangeIndex; - GLuint mPlotPointIndex; - GLuint mPlotColorIndex; - GLuint mPlotAlphaIndex; - - GLuint mMarkerPVCOnIndex; - GLuint mMarkerPVAOnIndex; - GLuint mMarkerPVROnIndex; - GLuint mMarkerTypeIndex; - GLuint mMarkerColIndex; - GLuint mMarkerMatIndex; - GLuint mMarkerPSizeIndex; - GLuint mMarkerPointIndex; - GLuint mMarkerColorIndex; - GLuint mMarkerAlphaIndex; - GLuint mMarkerRadiiIndex; - - std::map mVAOMap; + gl::GLuint mPlotMatIndex; + gl::GLuint mPlotPVCOnIndex; + gl::GLuint mPlotPVAOnIndex; + gl::GLuint mPlotUColorIndex; + gl::GLuint mPlotRangeIndex; + gl::GLuint mPlotPointIndex; + gl::GLuint mPlotColorIndex; + gl::GLuint mPlotAlphaIndex; + + gl::GLuint mMarkerPVCOnIndex; + gl::GLuint mMarkerPVAOnIndex; + gl::GLuint mMarkerPVROnIndex; + gl::GLuint mMarkerTypeIndex; + gl::GLuint mMarkerColIndex; + gl::GLuint mMarkerMatIndex; + gl::GLuint mMarkerPSizeIndex; + gl::GLuint mMarkerPointIndex; + gl::GLuint mMarkerColorIndex; + gl::GLuint mMarkerAlphaIndex; + gl::GLuint mMarkerRadiiIndex; + + std::map mVAOMap; /* bind and unbind helper functions * for rendering resources */ void bindResources(const int pWindowId); void unbindResources() const; - virtual glm::mat4 computeTransformMat(const glm::mat4 pView); + virtual glm::mat4 computeTransformMat(const glm::mat4 pView, const glm::mat4 pOrient); virtual void bindDimSpecificUniforms(); // has to be called only after shaders are bound public: - plot_impl(const uint pNumPoints, const fg::dtype pDataType, - const fg::PlotType pPlotType, const fg::MarkerType pMarkerType, + plot_impl(const uint pNumPoints, const forge::dtype pDataType, + const forge::PlotType pPlotType, const forge::MarkerType pMarkerType, const int pDimension=3); ~plot_impl(); void setMarkerSize(const float pMarkerSize); - GLuint markers(); + uint markers(); size_t markersSizes() const; virtual void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView); + const glm::mat4 &pView, const glm::mat4 &pOrient); }; class plot2d_impl : public plot_impl { protected: - glm::mat4 computeTransformMat(const glm::mat4 pView) override; + glm::mat4 computeTransformMat(const glm::mat4 pView, const glm::mat4 pOrient) override; void bindDimSpecificUniforms() override; // has to be called only after shaders are bound public: - plot2d_impl(const uint pNumPoints, const fg::dtype pDataType, - const fg::PlotType pPlotType, const fg::MarkerType pMarkerType) + plot2d_impl(const uint pNumPoints, const forge::dtype pDataType, + const forge::PlotType pPlotType, const forge::MarkerType pMarkerType) : plot_impl(pNumPoints, pDataType, pPlotType, pMarkerType, 2) {} }; } +} diff --git a/src/backend/opengl/sdl/window.cpp b/src/backend/opengl/sdl/window.cpp index 75068ba6..e62394d0 100644 --- a/src/backend/opengl/sdl/window.cpp +++ b/src/backend/opengl/sdl/window.cpp @@ -9,23 +9,22 @@ #include #include +#include #include - -#ifndef OS_WIN -#include -#else -#include -#endif #include +using namespace gl; + using glm::rotate; using glm::translate; using glm::scale; #define SDL_THROW_ERROR(msg, err) \ - throw fg::Error("Window constructor", __LINE__, msg, err); + throw forge::Error("Window constructor", __LINE__, msg, err); +namespace forge +{ namespace wtk { @@ -108,22 +107,12 @@ void Widget::makeContextCurrent() const long long Widget::getGLContextHandle() { -#ifdef OS_WIN - return reinterpret_cast(wglGetCurrentContext()); -#endif -#ifdef OS_LNX - return reinterpret_cast(glXGetCurrentContext()); -#endif + return opengl::getCurrentContextHandle(); } long long Widget::getDisplayHandle() { -#ifdef OS_WIN - return reinterpret_cast(wglGetCurrentDC()); -#endif -#ifdef OS_LNX - return reinterpret_cast(glXGetCurrentDisplay()); -#endif + return opengl::getCurrentDisplayHandle(); } void Widget::setTitle(const char* pTitle) @@ -202,23 +191,24 @@ void Widget::pollEvents() if (evnt.type == SDL_KEYDOWN) { switch(evnt.key.keysym.sym) { - case SDLK_ESCAPE: mClose = true ; break; - case SDLK_LALT : mMod = SDLK_LALT; break; - case SDLK_RALT : mMod = SDLK_RALT; break; + case SDLK_ESCAPE: + mClose = true; break; + default: + mMod = evnt.key.keysym.sym; + break; } } else if (evnt.type == SDL_KEYUP) { - switch(evnt.key.keysym.sym) { - case SDLK_LALT: mMod = -1; break; - case SDLK_RALT: mMod = -1; break; - } + mMod = -1; } + // reset UI transforms upon mouse middle click if(evnt.type == SDL_MOUSEBUTTONUP) { - if(evnt.button.button == SDL_BUTTON_MIDDLE && mMod == SDLK_LALT) { + if(evnt.button.button == SDL_BUTTON_MIDDLE && + (mMod == SDLK_LCTRL || mMod==SDLK_RCTRL)) { int r, c; getViewIds(&r, &c); - glm::mat4& mvp = mMVPs[r+c*mRows]; - mvp = glm::mat4(1.0f); + mViewMatrices[r+c*mRows] = glm::mat4(1); + mOrientMatrices[r+c*mRows] = glm::mat4(1); } } @@ -228,7 +218,7 @@ void Widget::pollEvents() int r, c; getViewIds(&r, &c); - glm::mat4& mvp = mMVPs[r+c*mRows]; + glm::mat4& viewMat = mViewMatrices[r+c*mRows]; if(evnt.motion.state == SDL_BUTTON_LMASK && (mMod == SDLK_LALT || mMod == SDLK_RALT)) { @@ -237,29 +227,33 @@ void Widget::pollEvents() if(deltaY < 0) { deltaY = 1.0 / (-deltaY); } - mvp = scale(mvp, glm::vec3(pow(deltaY, SPEED))); + viewMat = scale(viewMat, glm::vec3(pow(deltaY, SPEED))); } } else if (evnt.motion.state == SDL_BUTTON_LMASK) { // Translate - mvp = translate(mvp, glm::vec3(-deltaX, deltaY, 0.0f) * SPEED); + viewMat = translate(viewMat, glm::vec3(-deltaX, deltaY, 0.0f) * SPEED); } else if (evnt.motion.state == SDL_BUTTON_RMASK) { + glm::mat4& orientationMat = mOrientMatrices[r+c*mRows]; // Rotations int width, height; SDL_GetWindowSize(mWindow, &width, &height); - glm::vec3 curPos = trackballPoint(evnt.motion.x, evnt.motion.y, width, height); - glm::vec3 delta = mLastPos - curPos; - float angle = glm::radians(90.0f * sqrt(delta.x*delta.x + delta.y*delta.y + delta.z*delta.z)); - glm::vec3 axis( - mLastPos.y*curPos.z-mLastPos.z*curPos.y, - mLastPos.z*curPos.x-mLastPos.x*curPos.z, - mLastPos.x*curPos.y-mLastPos.y*curPos.x - ); - float dMag = sqrt(dot(delta, delta)); - float aMag = sqrt(dot(axis, axis)); - if (dMag>0 && aMag>0) { - mvp = rotate(mvp, angle, axis); + + int xPos = evnt.motion.x; + int yPos = evnt.motion.y; + + if (mLastXPos != xPos || mLastYPos != yPos) { + glm::vec3 op1 = trackballPoint(mLastXPos, mLastYPos, width, height); + glm::vec3 op2 = trackballPoint(xPos, yPos, width, height); + + float angle = std::acos(std::min(1.0f, glm::dot(op1, op2))); + + glm::vec3 axisInCamCoord = glm::cross(op1, op2); + + glm::mat3 camera2object = glm::inverse(glm::mat3(viewMat)); + glm::vec3 axisInObjCoord = camera2object * axisInCamCoord; + + orientationMat = glm::rotate(orientationMat, glm::degrees(angle), axisInObjCoord); } - mLastPos = curPos; } mLastXPos = evnt.motion.x; @@ -283,3 +277,4 @@ void Widget::resizePixelBuffers() } } +} diff --git a/src/backend/opengl/sdl/window.hpp b/src/backend/opengl/sdl/window.hpp index 020bfddf..7a8baeb7 100644 --- a/src/backend/opengl/sdl/window.hpp +++ b/src/backend/opengl/sdl/window.hpp @@ -15,6 +15,8 @@ /* the short form wtk stands for * Windowing Tool Kit */ +namespace forge +{ namespace wtk { @@ -45,9 +47,10 @@ class Widget { int mCols; int mCellWidth; int mCellHeight; - std::vector mMVPs; + std::vector mViewMatrices; + std::vector mOrientMatrices; - GLuint mFramePBO; + uint mFramePBO; /* Constructors and methods */ Widget(int pWidth, int pHeight, const char* pTitle, const Widget* pWindow, const bool invisible); @@ -88,3 +91,4 @@ class Widget { }; } +} diff --git a/src/backend/opengl/surface_impl.cpp b/src/backend/opengl/surface_impl.cpp index 4ada51e8..0bb3ee2c 100644 --- a/src/backend/opengl/surface_impl.cpp +++ b/src/backend/opengl/surface_impl.cpp @@ -20,6 +20,7 @@ #include +using namespace gl; using namespace std; void generateGridIndices(unsigned short rows, unsigned short cols, unsigned short *indices) @@ -43,6 +44,8 @@ for(unsigned short r = 0; r < rows-1; ++r){ } } +namespace forge +{ namespace opengl { @@ -80,37 +83,36 @@ void surface_impl::unbindResources() const glBindVertexArray(0); } -glm::mat4 surface_impl::computeTransformMat(const glm::mat4& pView) +glm::mat4 surface_impl::computeTransformMat(const glm::mat4& pView, const glm::mat4& pOrient) { static const glm::mat4 MODEL = glm::rotate(glm::mat4(1.0f), -glm::radians(90.f), glm::vec3(0,1,0)) * glm::rotate(glm::mat4(1.0f), -glm::radians(90.f), glm::vec3(1,0,0)); - float range_x = mRange[1] - mRange[0]; - float range_y = mRange[3] - mRange[2]; - float range_z = mRange[5] - mRange[4]; + float xRange = mRange[1] - mRange[0]; + float yRange = mRange[3] - mRange[2]; + float zRange = mRange[5] - mRange[4]; // set scale to zero if input is constant array // otherwise compute scale factor by standard equation - float graph_scale_x = std::abs(range_x) < 1.0e-3 ? 1.0f : 2/(range_x); - float graph_scale_y = std::abs(range_y) < 1.0e-3 ? 1.0f : 2/(range_y); - float graph_scale_z = std::abs(range_z) < 1.0e-3 ? 1.0f : 2/(range_z); + float xDataScale = std::abs(xRange) < 1.0e-3 ? 1.0f : 2/(xRange); + float yDataScale = std::abs(yRange) < 1.0e-3 ? 1.0f : 2/(yRange); + float zDataScale = std::abs(zRange) < 1.0e-3 ? 1.0f : 2/(zRange); + + float xDataOffset = (-mRange[0] * xDataScale); + float yDataOffset = (-mRange[2] * yDataScale); + float zDataOffset = (-mRange[4] * zDataScale); - float coor_offset_x = (-mRange[0] * graph_scale_x); - float coor_offset_y = (-mRange[2] * graph_scale_y); - float coor_offset_z = (-mRange[4] * graph_scale_z); + glm::vec3 scaleVector(xDataScale, yDataScale, zDataScale); - glm::mat4 sMat = glm::scale(MODEL, - glm::vec3(graph_scale_x, -1.0f * graph_scale_y, graph_scale_z)); - glm::mat4 tMat = glm::translate(sMat, - glm::vec3(-1 + coor_offset_x, -1 + coor_offset_y, -1 + coor_offset_z)); + glm::vec3 shiftVector = glm::vec3(-1 + xDataOffset, -1 + yDataOffset, -1 + zDataOffset); - return pView * tMat; + return pView * pOrient * MODEL * glm::scale(glm::translate(IDENTITY, shiftVector), scaleVector); } void surface_impl::renderGraph(const int pWindowId, const glm::mat4& transform) { CheckGL("Begin surface_impl::renderGraph"); - glUseProgram(mSurfProgram); + mSurfProgram.bind(); glUniformMatrix4fv(mSurfMatIndex, 1, GL_FALSE, glm::value_ptr(transform)); glUniform2fv(mSurfRangeIndex, 3, mRange); @@ -120,11 +122,11 @@ void surface_impl::renderGraph(const int pWindowId, const glm::mat4& transform) bindResources(pWindowId); glDrawElements(GL_TRIANGLE_STRIP, mIBOSize, GL_UNSIGNED_SHORT, (void*)0 ); unbindResources(); - glUseProgram(0); + mSurfProgram.unbind(); if(mMarkerType != FG_MARKER_NONE) { glEnable(GL_PROGRAM_POINT_SIZE); - glUseProgram(mMarkerProgram); + mMarkerProgram.bind(); glUniformMatrix4fv(mMarkerMatIndex, 1, GL_FALSE, glm::value_ptr(transform)); glUniform1i(mMarkerPVCIndex, mIsPVCOn); @@ -136,7 +138,7 @@ void surface_impl::renderGraph(const int pWindowId, const glm::mat4& transform) glDrawElements(GL_POINTS, mIBOSize, GL_UNSIGNED_SHORT, (void*)0); unbindResources(); - glUseProgram(0); + mMarkerProgram.unbind(); glDisable(GL_PROGRAM_POINT_SIZE); } CheckGL("End surface_impl::renderGraph"); @@ -144,38 +146,35 @@ void surface_impl::renderGraph(const int pWindowId, const glm::mat4& transform) surface_impl::surface_impl(unsigned pNumXPoints, unsigned pNumYPoints, - fg::dtype pDataType, fg::MarkerType pMarkerType) + forge::dtype pDataType, forge::MarkerType pMarkerType) : mNumXPoints(pNumXPoints),mNumYPoints(pNumYPoints), mDataType(dtype2gl(pDataType)), - mMarkerType(pMarkerType), mIBO(0), mIBOSize(0), mMarkerProgram(-1), mSurfProgram(-1), + mMarkerType(pMarkerType), mIBO(0), mIBOSize(0), + mMarkerProgram(glsl::plot3_vs.c_str(), glsl::marker_fs.c_str()), + mSurfProgram(glsl::plot3_vs.c_str(), glsl::plot3_fs.c_str()), mMarkerMatIndex(-1), mMarkerPointIndex(-1), mMarkerColorIndex(-1), mMarkerAlphaIndex(-1), mMarkerPVCIndex(-1), mMarkerPVAIndex(-1), mMarkerTypeIndex(-1), mMarkerColIndex(-1), mSurfMatIndex(-1), mSurfRangeIndex(-1), mSurfPointIndex(-1), mSurfColorIndex(-1), mSurfAlphaIndex(-1), mSurfPVCIndex(-1), mSurfPVAIndex(-1) { CheckGL("Begin surface_impl::surface_impl"); - mIsPVCOn = false; - mIsPVAOn = false; setColor(0.9, 0.5, 0.6, 1.0); - mLegend = std::string(""); - - mMarkerProgram = initShaders(glsl::plot3_vs.c_str(), glsl::marker_fs.c_str()); - mMarkerMatIndex = glGetUniformLocation(mMarkerProgram, "transform"); - mMarkerPVCIndex = glGetUniformLocation(mMarkerProgram, "isPVCOn"); - mMarkerPVAIndex = glGetUniformLocation(mMarkerProgram, "isPVAOn"); - mMarkerTypeIndex = glGetUniformLocation(mMarkerProgram, "marker_type"); - mMarkerColIndex = glGetUniformLocation(mMarkerProgram, "marker_color"); - mMarkerPointIndex= glGetAttribLocation (mMarkerProgram, "point"); - mMarkerColorIndex= glGetAttribLocation (mMarkerProgram, "color"); - mMarkerAlphaIndex= glGetAttribLocation (mMarkerProgram, "alpha"); - - mSurfProgram = initShaders(glsl::plot3_vs.c_str(), glsl::plot3_fs.c_str()); - mSurfMatIndex = glGetUniformLocation(mSurfProgram, "transform"); - mSurfRangeIndex = glGetUniformLocation(mSurfProgram, "minmaxs"); - mSurfPVCIndex = glGetUniformLocation(mSurfProgram, "isPVCOn"); - mSurfPVAIndex = glGetUniformLocation(mSurfProgram, "isPVAOn"); - mSurfPointIndex = glGetAttribLocation (mSurfProgram, "point"); - mSurfColorIndex = glGetAttribLocation (mSurfProgram, "color"); - mSurfAlphaIndex = glGetAttribLocation (mSurfProgram, "alpha"); + + mMarkerMatIndex = mMarkerProgram.getUniformLocation("transform"); + mMarkerPVCIndex = mMarkerProgram.getUniformLocation("isPVCOn"); + mMarkerPVAIndex = mMarkerProgram.getUniformLocation("isPVAOn"); + mMarkerTypeIndex = mMarkerProgram.getUniformLocation("marker_type"); + mMarkerColIndex = mMarkerProgram.getUniformLocation("marker_color"); + mMarkerPointIndex= mMarkerProgram.getAttributeLocation("point"); + mMarkerColorIndex= mMarkerProgram.getAttributeLocation("color"); + mMarkerAlphaIndex= mMarkerProgram.getAttributeLocation("alpha"); + + mSurfMatIndex = mSurfProgram.getUniformLocation("transform"); + mSurfRangeIndex = mSurfProgram.getUniformLocation("minmaxs"); + mSurfPVCIndex = mSurfProgram.getUniformLocation("isPVCOn"); + mSurfPVAIndex = mSurfProgram.getUniformLocation("isPVAOn"); + mSurfPointIndex = mSurfProgram.getAttributeLocation ("point"); + mSurfColorIndex = mSurfProgram.getAttributeLocation ("color"); + mSurfAlphaIndex = mSurfProgram.getAttributeLocation ("alpha"); unsigned totalPoints = mNumXPoints * mNumYPoints; @@ -197,7 +196,7 @@ surface_impl::surface_impl(unsigned pNumXPoints, unsigned pNumYPoints, case GL_SHORT : SURF_CREATE_BUFFERS(short) ; break; case GL_UNSIGNED_SHORT : SURF_CREATE_BUFFERS(ushort); break; case GL_UNSIGNED_BYTE : SURF_CREATE_BUFFERS(float) ; break; - default: fg::TypeError("surface_impl::surface_impl", __LINE__, 1, pDataType); + default: forge::TypeError("surface_impl::surface_impl", __LINE__, 1, pDataType); } #undef SURF_CREATE_BUFFERS @@ -217,18 +216,13 @@ surface_impl::~surface_impl() GLuint vao = it->second; glDeleteVertexArrays(1, &vao); } - glDeleteBuffers(1, &mVBO); - glDeleteBuffers(1, &mCBO); - glDeleteBuffers(1, &mABO); glDeleteBuffers(1, &mIBO); - glDeleteProgram(mMarkerProgram); - glDeleteProgram(mSurfProgram); CheckGL("End Plot::~Plot"); } void surface_impl::render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4& pView) + const glm::mat4& pView, const glm::mat4& pOrient) { CheckGL("Begin surface_impl::render"); // FIXME: even when per vertex alpha is enabled @@ -240,7 +234,7 @@ void surface_impl::render(const int pWindowId, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - renderGraph(pWindowId, computeTransformMat(pView)); + renderGraph(pWindowId, computeTransformMat(pView, pOrient)); if (mIsPVAOn) { glDisable(GL_BLEND); @@ -253,7 +247,7 @@ void scatter3_impl::renderGraph(const int pWindowId, const glm::mat4& transform) { if(mMarkerType != FG_MARKER_NONE) { glEnable(GL_PROGRAM_POINT_SIZE); - glUseProgram(mMarkerProgram); + mMarkerProgram.bind(); glUniformMatrix4fv(mMarkerMatIndex, 1, GL_FALSE, glm::value_ptr(transform)); glUniform1i(mMarkerPVCIndex, mIsPVCOn); @@ -265,9 +259,10 @@ void scatter3_impl::renderGraph(const int pWindowId, const glm::mat4& transform) glDrawElements(GL_POINTS, mIBOSize, GL_UNSIGNED_SHORT, (void*)0); unbindResources(); - glUseProgram(0); + mMarkerProgram.unbind(); glDisable(GL_PROGRAM_POINT_SIZE); } } } +} diff --git a/src/backend/opengl/surface_impl.hpp b/src/backend/opengl/surface_impl.hpp index 1be9119b..4b9486f6 100644 --- a/src/backend/opengl/surface_impl.hpp +++ b/src/backend/opengl/surface_impl.hpp @@ -16,58 +16,60 @@ #include #include +namespace forge +{ namespace opengl { class surface_impl : public AbstractRenderable { protected: /* plot points characteristics */ - GLuint mNumXPoints; - GLuint mNumYPoints; - GLenum mDataType; - bool mIsPVCOn; - bool mIsPVAOn; - fg::MarkerType mMarkerType; + gl::GLuint mNumXPoints; + gl::GLuint mNumYPoints; + gl::GLenum mDataType; + bool mIsPVCOn; + bool mIsPVAOn; + forge::MarkerType mMarkerType; /* OpenGL Objects */ - GLuint mIBO; - size_t mIBOSize; - GLuint mMarkerProgram; - GLuint mSurfProgram; + gl::GLuint mIBO; + size_t mIBOSize; + ShaderProgram mMarkerProgram; + ShaderProgram mSurfProgram; /* shared variable index locations */ - GLuint mMarkerMatIndex; - GLuint mMarkerPointIndex; - GLuint mMarkerColorIndex; - GLuint mMarkerAlphaIndex; - GLuint mMarkerPVCIndex; - GLuint mMarkerPVAIndex; - GLuint mMarkerTypeIndex; - GLuint mMarkerColIndex; - - GLuint mSurfMatIndex; - GLuint mSurfRangeIndex; - GLuint mSurfPointIndex; - GLuint mSurfColorIndex; - GLuint mSurfAlphaIndex; - GLuint mSurfPVCIndex; - GLuint mSurfPVAIndex; - - std::map mVAOMap; + gl::GLuint mMarkerMatIndex; + gl::GLuint mMarkerPointIndex; + gl::GLuint mMarkerColorIndex; + gl::GLuint mMarkerAlphaIndex; + gl::GLuint mMarkerPVCIndex; + gl::GLuint mMarkerPVAIndex; + gl::GLuint mMarkerTypeIndex; + gl::GLuint mMarkerColIndex; + + gl::GLuint mSurfMatIndex; + gl::GLuint mSurfRangeIndex; + gl::GLuint mSurfPointIndex; + gl::GLuint mSurfColorIndex; + gl::GLuint mSurfAlphaIndex; + gl::GLuint mSurfPVCIndex; + gl::GLuint mSurfPVAIndex; + + std::map mVAOMap; /* bind and unbind helper functions * for rendering resources */ void bindResources(const int pWindowId); void unbindResources() const; - glm::mat4 computeTransformMat(const glm::mat4& pView); + glm::mat4 computeTransformMat(const glm::mat4& pView, const glm::mat4& pOrient); virtual void renderGraph(const int pWindowId, const glm::mat4& transform); public: surface_impl(const uint pNumXpoints, const uint pNumYpoints, - const fg::dtype pDataType, const fg::MarkerType pMarkerType); + const forge::dtype pDataType, const forge::MarkerType pMarkerType); ~surface_impl(); void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView); + const glm::mat4 &pView, const glm::mat4 &pOrient); inline void usePerVertexColors(const bool pFlag=true) { mIsPVCOn = pFlag; @@ -84,8 +86,9 @@ class scatter3_impl : public surface_impl { public: scatter3_impl(const uint pNumXPoints, const uint pNumYPoints, - const fg::dtype pDataType, const fg::MarkerType pMarkerType=FG_MARKER_NONE) + const forge::dtype pDataType, const forge::MarkerType pMarkerType=FG_MARKER_NONE) : surface_impl(pNumXPoints, pNumYPoints, pDataType, pMarkerType) {} }; } +} diff --git a/src/backend/opengl/util.cpp b/src/backend/opengl/util.cpp new file mode 100644 index 00000000..fc2d6733 --- /dev/null +++ b/src/backend/opengl/util.cpp @@ -0,0 +1,82 @@ +/******************************************************* + * Copyright (c) 2015-2019, ArrayFire + * All rights reserved. + * + * This file is distributed under 3-clause BSD license. + * The complete license agreement can be obtained at: + * http://arrayfire.com/licenses/BSD-3-Clause + ********************************************************/ + +#include +#include +#include + +using namespace gl; + +fg_err fg_update_vertex_buffer(const unsigned pBufferId, + const size_t pBufferSize, + const void* pBufferData) +{ + try { + glBindBuffer(GL_ARRAY_BUFFER, pBufferId); + glBufferSubData(GL_ARRAY_BUFFER, 0, pBufferSize, pBufferData); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + CATCHALL + + return FG_ERR_NONE; +} + +fg_err fg_update_pixel_buffer(const unsigned pBufferId, + const size_t pBufferSize, + const void* pBufferData) +{ + try { + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pBufferId); + glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, pBufferSize, pBufferData); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + } + CATCHALL + + return FG_ERR_NONE; +} + +fg_err fg_finish() +{ + try { + glFinish(); + } + CATCHALL + + return FG_ERR_NONE; +} + +namespace forge +{ + +void updateVertexBuffer(const unsigned pBufferId, + const size_t pBufferSize, + const void* pBufferData) +{ + fg_err val = fg_update_vertex_buffer(pBufferId, pBufferSize, pBufferData); + if (val!=FG_ERR_NONE) + throw forge::Error(__PRETTY_FUNCTION__, __LINE__, "Vertex Buffer Object update failed", val); +} + +void updatePixelBuffer(const unsigned pBufferId, + const size_t pBufferSize, + const void* pBufferData) +{ + fg_err val = fg_update_pixel_buffer(pBufferId, pBufferSize, pBufferData); + if (val!=FG_ERR_NONE) + throw forge::Error(__PRETTY_FUNCTION__, __LINE__, "Pixel Buffer Object update failed", val); +} + +void finish() +{ + fg_err val = fg_finish(); + if (val!=FG_ERR_NONE) + throw forge::Error(__PRETTY_FUNCTION__, __LINE__, "glFinish failed", val); +} + +} diff --git a/src/backend/opengl/vector_field_impl.cpp b/src/backend/opengl/vector_field_impl.cpp index ab65ee83..4460e26a 100644 --- a/src/backend/opengl/vector_field_impl.cpp +++ b/src/backend/opengl/vector_field_impl.cpp @@ -17,11 +17,14 @@ #include +using namespace gl; using namespace std; // identity matrix static const glm::mat4 I(1.0f); +namespace forge +{ namespace opengl { @@ -63,7 +66,7 @@ void vector_field_impl::unbindResources() const glBindVertexArray(0); } -glm::mat4 vector_field_impl::computeModelMatrix() +glm::mat4 vector_field_impl::computeModelMatrix(const glm::mat4& pOrient) { float xRange = mRange[1] - mRange[0]; float yRange = mRange[3] - mRange[2]; @@ -84,32 +87,28 @@ glm::mat4 vector_field_impl::computeModelMatrix() -(mRange[4]+mRange[5])/2.0f); shiftVector += glm::vec3(-1 + xDataOffset, -1 + yDataOffset, -1 + zDataOffset); - return glm::translate(glm::scale(IDENTITY, scaleVector), shiftVector); + return glm::translate(glm::scale(pOrient, scaleVector), shiftVector); } -vector_field_impl::vector_field_impl(const uint pNumPoints, const fg::dtype pDataType, const int pD) - : mDimension(pD), mNumPoints(pNumPoints), mDataType(pDataType), mGLType(dtype2gl(mDataType)), - mFieldProgram(-1), mDBO(-1), mDBOSize(0), mFieldPointIndex(-1), +vector_field_impl::vector_field_impl(const uint pNumPoints, const forge::dtype pDataType, const int pD) + : mDimension(pD), mNumPoints(pNumPoints), mDataType(pDataType), + mGLType(dtype2gl(mDataType)), + mFieldProgram(pD==2 ? glsl::vector_field2d_vs.c_str() : glsl::vector_field_vs.c_str(), + glsl::histogram_fs.c_str(), + pD==2 ? glsl::vector_field2d_gs.c_str() : glsl::vector_field_gs.c_str()), + mDBO(-1), mDBOSize(0), mFieldPointIndex(-1), mFieldColorIndex(-1), mFieldAlphaIndex(-1), mFieldDirectionIndex(-1), mFieldPVMatIndex(-1), mFieldModelMatIndex(-1), mFieldAScaleMatIndex(-1), mFieldPVCOnIndex(-1), mFieldPVAOnIndex(-1), mFieldUColorIndex(-1) { CheckGL("Begin vector_field_impl::vector_field_impl"); - mIsPVCOn = false; - mIsPVAOn = false; setColor(0, 1, 0, 1); - mLegend = std::string(""); - // FIXME if (mDimension==2) { - mFieldProgram = initShaders(glsl::vector_field2d_vs.c_str(), glsl::histogram_fs.c_str(), - glsl::vector_field2d_gs.c_str()); mVBOSize = 2*mNumPoints; mDBOSize = 2*mNumPoints; } else { - mFieldProgram = initShaders(glsl::vector_field_vs.c_str(), glsl::histogram_fs.c_str(), - glsl::vector_field_gs.c_str()); mVBOSize = 3*mNumPoints; mDBOSize = 3*mNumPoints; } @@ -117,18 +116,18 @@ vector_field_impl::vector_field_impl(const uint pNumPoints, const fg::dtype pDat mCBOSize = 3*mNumPoints; mABOSize = mNumPoints; - mFieldPointIndex = glGetAttribLocation (mFieldProgram, "point"); - mFieldColorIndex = glGetAttribLocation (mFieldProgram, "color"); - mFieldAlphaIndex = glGetAttribLocation (mFieldProgram, "alpha"); - mFieldDirectionIndex = glGetAttribLocation (mFieldProgram, "direction"); + mFieldPointIndex = mFieldProgram.getAttributeLocation("point"); + mFieldColorIndex = mFieldProgram.getAttributeLocation("color"); + mFieldAlphaIndex = mFieldProgram.getAttributeLocation("alpha"); + mFieldDirectionIndex = mFieldProgram.getAttributeLocation("direction"); - mFieldPVMatIndex = glGetUniformLocation(mFieldProgram, "viewMat"); - mFieldModelMatIndex = glGetUniformLocation(mFieldProgram, "modelMat"); - mFieldAScaleMatIndex = glGetUniformLocation(mFieldProgram, "arrowScaleMat"); + mFieldPVMatIndex = mFieldProgram.getUniformLocation("viewMat"); + mFieldModelMatIndex = mFieldProgram.getUniformLocation("modelMat"); + mFieldAScaleMatIndex = mFieldProgram.getUniformLocation("arrowScaleMat"); - mFieldPVCOnIndex = glGetUniformLocation(mFieldProgram, "isPVCOn"); - mFieldPVAOnIndex = glGetUniformLocation(mFieldProgram, "isPVAOn"); - mFieldUColorIndex = glGetUniformLocation(mFieldProgram, "barColor"); + mFieldPVCOnIndex = mFieldProgram.getUniformLocation("isPVCOn"); + mFieldPVAOnIndex = mFieldProgram.getUniformLocation("isPVAOn"); + mFieldUColorIndex = mFieldProgram.getUniformLocation("barColor"); #define PLOT_CREATE_BUFFERS(type) \ mVBO = createBuffer(GL_ARRAY_BUFFER, mVBOSize, NULL, GL_DYNAMIC_DRAW); \ @@ -147,7 +146,7 @@ vector_field_impl::vector_field_impl(const uint pNumPoints, const fg::dtype pDat case GL_SHORT : PLOT_CREATE_BUFFERS(short) ; break; case GL_UNSIGNED_SHORT : PLOT_CREATE_BUFFERS(ushort); break; case GL_UNSIGNED_BYTE : PLOT_CREATE_BUFFERS(float) ; break; - default: fg::TypeError("vector_field_impl::vector_field_impl", __LINE__, 1, mDataType); + default: forge::TypeError("vector_field_impl::vector_field_impl", __LINE__, 1, mDataType); } #undef PLOT_CREATE_BUFFERS CheckGL("End vector_field_impl::vector_field_impl"); @@ -160,11 +159,7 @@ vector_field_impl::~vector_field_impl() GLuint vao = it->second; glDeleteVertexArrays(1, &vao); } - glDeleteBuffers(1, &mVBO); - glDeleteBuffers(1, &mCBO); - glDeleteBuffers(1, &mABO); glDeleteBuffers(1, &mDBO); - glDeleteProgram(mFieldProgram); CheckGL("End vector_field_impl::~vector_field_impl"); } @@ -180,7 +175,7 @@ size_t vector_field_impl::directionsSize() const void vector_field_impl::render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4& pView) + const glm::mat4& pView, const glm::mat4& pOrient) { static const glm::mat4 ArrowScaleMat = glm::scale(glm::mat4(1), glm::vec3(0.1,0.1,0.1)); @@ -191,9 +186,9 @@ void vector_field_impl::render(const int pWindowId, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - glm::mat4 model = this->computeModelMatrix(); + glm::mat4 model = this->computeModelMatrix(pOrient); - glUseProgram(mFieldProgram); + mFieldProgram.bind(); glUniformMatrix4fv(mFieldPVMatIndex, 1, GL_FALSE, glm::value_ptr(pView)); glUniformMatrix4fv(mFieldModelMatIndex, 1, GL_FALSE, glm::value_ptr(model)); @@ -210,7 +205,7 @@ void vector_field_impl::render(const int pWindowId, if (mDimension==3) glDisable(GL_CULL_FACE); - glUseProgram(0); + mFieldProgram.unbind(); if (mIsPVAOn) { glDisable(GL_BLEND); @@ -219,7 +214,7 @@ void vector_field_impl::render(const int pWindowId, CheckGL("End vector_field_impl::render"); } -glm::mat4 vector_field2d_impl::computeModelMatrix() +glm::mat4 vector_field2d_impl::computeModelMatrix(const glm::mat4& pOrient) { float xRange = mRange[1] - mRange[0]; float yRange = mRange[3] - mRange[2]; @@ -234,3 +229,4 @@ glm::mat4 vector_field2d_impl::computeModelMatrix() } } +} diff --git a/src/backend/opengl/vector_field_impl.hpp b/src/backend/opengl/vector_field_impl.hpp index 2f215f86..a35b42a8 100644 --- a/src/backend/opengl/vector_field_impl.hpp +++ b/src/backend/opengl/vector_field_impl.hpp @@ -19,63 +19,66 @@ #include #include +namespace forge +{ namespace opengl { class vector_field_impl : public AbstractRenderable { protected: - GLuint mDimension; + gl::GLuint mDimension; /* plot points characteristics */ - GLuint mNumPoints; - fg::dtype mDataType; - GLenum mGLType; + gl::GLuint mNumPoints; + forge::dtype mDataType; + gl::GLenum mGLType; /* OpenGL Objects */ - GLuint mFieldProgram; - GLuint mDBO; + ShaderProgram mFieldProgram; + gl::GLuint mDBO; size_t mDBOSize; /* shader variable index locations */ /* vertex shader */ - GLuint mFieldPointIndex; - GLuint mFieldColorIndex; - GLuint mFieldAlphaIndex; - GLuint mFieldDirectionIndex; + gl::GLuint mFieldPointIndex; + gl::GLuint mFieldColorIndex; + gl::GLuint mFieldAlphaIndex; + gl::GLuint mFieldDirectionIndex; /* geometry shader */ - GLuint mFieldPVMatIndex; - GLuint mFieldModelMatIndex; - GLuint mFieldAScaleMatIndex; + gl::GLuint mFieldPVMatIndex; + gl::GLuint mFieldModelMatIndex; + gl::GLuint mFieldAScaleMatIndex; /* fragment shader */ - GLuint mFieldPVCOnIndex; - GLuint mFieldPVAOnIndex; - GLuint mFieldUColorIndex; + gl::GLuint mFieldPVCOnIndex; + gl::GLuint mFieldPVAOnIndex; + gl::GLuint mFieldUColorIndex; - std::map mVAOMap; + std::map mVAOMap; /* bind and unbind helper functions * for rendering resources */ void bindResources(const int pWindowId); void unbindResources() const; - virtual glm::mat4 computeModelMatrix(); + virtual glm::mat4 computeModelMatrix(const glm::mat4& pOrient); public: - vector_field_impl(const uint pNumPoints, const fg::dtype pDataType, + vector_field_impl(const uint pNumPoints, const forge::dtype pDataType, const int pDimension=3); ~vector_field_impl(); - GLuint directions(); + gl::GLuint directions(); size_t directionsSize() const; virtual void render(const int pWindowId, const int pX, const int pY, const int pVPW, const int pVPH, - const glm::mat4 &pView); + const glm::mat4 &pView, const glm::mat4 &pOrient); }; class vector_field2d_impl : public vector_field_impl { protected: - glm::mat4 computeModelMatrix() override; + glm::mat4 computeModelMatrix(const glm::mat4& pOrient) override; public: - vector_field2d_impl(const uint pNumPoints, const fg::dtype pDataType) + vector_field2d_impl(const uint pNumPoints, const forge::dtype pDataType) : vector_field_impl(pNumPoints, pDataType, 2) {} }; } +} diff --git a/src/backend/opengl/window_impl.cpp b/src/backend/opengl/window_impl.cpp index 6f0995f7..a1e847fc 100644 --- a/src/backend/opengl/window_impl.cpp +++ b/src/backend/opengl/window_impl.cpp @@ -20,14 +20,8 @@ #include -using namespace fg; - -static GLEWContext* current = nullptr; - -GLEWContext* glewGetContext() -{ - return current; -} +using namespace gl; +using namespace forge; /* following function is thread safe */ int getNextUniqueId() @@ -82,6 +76,8 @@ class FI_BitmapResource FIBITMAP * pBitmap; }; +namespace forge +{ namespace opengl { @@ -89,7 +85,6 @@ void MakeContextCurrent(const window_impl* pWindow) { if (pWindow != NULL) { pWindow->get()->makeContextCurrent(); - current = pWindow->glewContext(); } } @@ -99,41 +94,16 @@ window_impl::window_impl(int pWidth, int pHeight, const char* pTitle, { if (auto observe = pWindow.lock()) { mWindow = new wtk::Widget(pWidth, pHeight, pTitle, observe->get(), invisible); - /* create glew context so that it will bind itself to windows */ - mGLEWContext = observe->glewContext(); } else { /* when windows are not sharing any context, just create * a dummy wtk::Widget object and pass it on */ mWindow = new wtk::Widget(pWidth, pHeight, pTitle, nullptr, invisible); - /* create glew context so that it will bind itself to windows */ - mGLEWContext = new GLEWContext(); - if (mGLEWContext == NULL) { - std::cerr << "Error: Could not create GLEW Context!\n"; - throw fg::Error("window_impl constructor", __LINE__, - "GLEW context creation failed", FG_ERR_GL_ERROR); - } - } - /* Set context (before glewInit()) */ - MakeContextCurrent(this); - - /* GLEW Initialization - Must be done */ - glewExperimental = GL_TRUE; - GLenum err = glewInit(); - if (err != GLEW_OK) { - char buffer[128]; - sprintf(buffer, "GLEW init failed: Error: %s\n", glewGetErrorString(err)); - throw fg::Error("window_impl constructor", __LINE__, buffer, FG_ERR_GL_ERROR); - } - err = glGetError(); - if (err!=GL_NO_ERROR && err!=GL_INVALID_ENUM) { - /* ignore this error, as GLEW is known to - * have this issue with 3.2+ core profiles - * they are yet to fix this in GLEW - */ - ForceCheckGL("GLEW initilization failed"); - throw fg::Error("window_impl constructor", __LINE__, - "GLEW initilization failed", FG_ERR_GL_ERROR); } + /* Set context (before glewInit()) */ + MakeContextCurrent(this); + + glbinding::Binding::useCurrentContext(); + glbinding::Binding::initialize(false); // lazy function pointer evaluation mCxt = mWindow->getGLContextHandle(); mDsp = mWindow->getDisplayHandle(); @@ -146,7 +116,6 @@ window_impl::window_impl(int pWidth, int pHeight, const char* pTitle, mCMap = std::make_shared(); } - mWindow->resizePixelBuffers(); /* set the colormap to default */ @@ -155,8 +124,11 @@ window_impl::window_impl(int pWidth, int pHeight, const char* pTitle, glEnable(GL_MULTISAMPLE); std::vector& mats = mWindow->mViewMatrices; + std::vector& omats = mWindow->mOrientMatrices; mats.resize(mWindow->mRows*mWindow->mCols); + omats.resize(mWindow->mRows*mWindow->mCols); std::fill(mats.begin(), mats.end(), glm::mat4(1)); + std::fill(omats.begin(), omats.end(), glm::mat4(1)); /* setup default window font */ mFont = std::make_shared(); @@ -195,7 +167,7 @@ void window_impl::setSize(unsigned pW, unsigned pH) mWindow->setSize(pW, pH); } -void window_impl::setColorMap(fg::ColorMap cmap) +void window_impl::setColorMap(forge::ColorMap cmap) { switch(cmap) { case FG_COLOR_MAP_DEFAULT: @@ -254,11 +226,6 @@ int window_impl::height() const return mWindow->mHeight; } -GLEWContext* window_impl::glewContext() const -{ - return mGLEWContext; -} - const wtk::Widget* window_impl::get() const { return mWindow; @@ -292,13 +259,15 @@ void window_impl::draw(const std::shared_ptr& pRenderable) glViewport(0, 0, mWindow->mWidth, mWindow->mHeight); const glm::mat4& viewMatrix = mWindow->mViewMatrices[0]; + const glm::mat4& orientMatrix = mWindow->mOrientMatrices[0]; // clear color and depth buffers glClearColor(WHITE[0], WHITE[1], WHITE[2], WHITE[3]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set colormap call is equivalent to noop for non-image renderables pRenderable->setColorMapUBOParams(mColorMapUBO, mUBOSize); - pRenderable->render(mID, 0, 0, mWindow->mWidth, mWindow->mHeight, viewMatrix); + pRenderable->render(mID, 0, 0, mWindow->mWidth, mWindow->mHeight, + viewMatrix, orientMatrix); mWindow->swapBuffers(); mWindow->pollEvents(); @@ -337,6 +306,7 @@ void window_impl::draw(int pColId, int pRowId, int y_off = (mWindow->mRows - 1 - r) * mWindow->mCellHeight; const glm::mat4& viewMatrix = mWindow->mViewMatrices[r+c*mWindow->mRows]; + const glm::mat4& orientMatrix = mWindow->mOrientMatrices[r+c*mWindow->mRows]; /* following margins are tested out for various * aspect ratios and are working fine. DO NOT CHANGE. * */ @@ -353,7 +323,8 @@ void window_impl::draw(int pColId, int pRowId, // set colormap call is equivalent to noop for non-image renderables pRenderable->setColorMapUBOParams(mColorMapUBO, mUBOSize); - pRenderable->render(mID, x_off, y_off, mWindow->mCellWidth, mWindow->mCellHeight, viewMatrix); + pRenderable->render(mID, x_off, y_off, mWindow->mCellWidth, mWindow->mCellHeight, + viewMatrix, orientMatrix); glDisable(GL_SCISSOR_TEST); glViewport(x_off, y_off, mWindow->mCellWidth, mWindow->mCellHeight); @@ -378,7 +349,7 @@ void window_impl::swapBuffers() void window_impl::saveFrameBuffer(const char* pFullPath) { if (!pFullPath) { - throw fg::ArgumentError("window_impl::saveFrameBuffer", __LINE__, 1, + throw forge::ArgumentError("window_impl::saveFrameBuffer", __LINE__, 1, "Empty path string"); } @@ -395,12 +366,12 @@ void window_impl::saveFrameBuffer(const char* pFullPath) format = FreeImage_GetFIFFromFilename(pFullPath); } if (format == FIF_UNKNOWN) { - throw fg::Error("window_impl::saveFrameBuffer", __LINE__, + throw forge::Error("window_impl::saveFrameBuffer", __LINE__, "Freeimage: unrecognized image format", FG_ERR_FREEIMAGE_UNKNOWN_FORMAT); } if (!(format==FIF_BMP || format==FIF_PNG)) { - throw fg::ArgumentError("window_impl::saveFrameBuffer", __LINE__, 1, + throw forge::ArgumentError("window_impl::saveFrameBuffer", __LINE__, 1, "Supports only bmp and png as of now"); } @@ -411,7 +382,7 @@ void window_impl::saveFrameBuffer(const char* pFullPath) FIBITMAP* bmp = FreeImage_Allocate(w, h, d); if (!bmp) { - throw fg::Error("window_impl::saveFrameBuffer", __LINE__, + throw forge::Error("window_impl::saveFrameBuffer", __LINE__, "Freeimage: allocation failed", FG_ERR_FREEIMAGE_BAD_ALLOC); } @@ -459,3 +430,4 @@ void window_impl::saveFrameBuffer(const char* pFullPath) } } +} diff --git a/src/backend/opengl/window_impl.hpp b/src/backend/opengl/window_impl.hpp index cd4254d4..282b81a7 100644 --- a/src/backend/opengl/window_impl.hpp +++ b/src/backend/opengl/window_impl.hpp @@ -24,6 +24,8 @@ #include +namespace forge +{ namespace opengl { @@ -33,13 +35,12 @@ class window_impl { long long mDsp; int mID; wtk::Widget* mWindow; - GLEWContext* mGLEWContext; std::shared_ptr mFont; std::shared_ptr mCMap; - GLuint mColorMapUBO; - GLuint mUBOSize; + gl::GLuint mColorMapUBO; + gl::GLuint mUBOSize; public: window_impl(int pWidth, int pHeight, const char* pTitle, @@ -51,14 +52,13 @@ class window_impl { void setTitle(const char* pTitle); void setPos(int pX, int pY); void setSize(unsigned pWidth, unsigned pHeight); - void setColorMap(fg::ColorMap cmap); + void setColorMap(forge::ColorMap cmap); int getID() const; long long context() const; long long display() const; int width() const; int height() const; - GLEWContext* glewContext() const; const wtk::Widget* get() const; const std::shared_ptr& colorMapPtr() const; @@ -82,3 +82,4 @@ class window_impl { void MakeContextCurrent(const window_impl* pWindow); } +} diff --git a/src/backend/window.hpp b/src/backend/window.hpp index aae58969..6bbedb97 100644 --- a/src/backend/window.hpp +++ b/src/backend/window.hpp @@ -18,6 +18,8 @@ #include +namespace forge +{ namespace common { @@ -65,7 +67,7 @@ class Window { mWindow->setSize(pWidth, pHeight); } - inline void setColorMap(fg::ColorMap cmap) { + inline void setColorMap(forge::ColorMap cmap) { mWindow->setColorMap(cmap); } @@ -139,3 +141,4 @@ class Window { }; } +}