Skip to content

Commit

Permalink
Merge pull request #43 from AlwinEsch/Leia-change
Browse files Browse the repository at this point in the history
complete rewrite, update CMakeLists.txt to 3.5 and change fPIC
  • Loading branch information
AlwinEsch authored Aug 26, 2019
2 parents 7dac679 + f7c1e28 commit e6fe746
Show file tree
Hide file tree
Showing 67 changed files with 3,343 additions and 2,113 deletions.
63 changes: 22 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,62 +1,42 @@
cmake_minimum_required(VERSION 3.5)
project(visualization.shadertoy)

cmake_minimum_required(VERSION 2.6)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})

find_package(Kodi REQUIRED)
find_package(p8-platform REQUIRED)

add_subdirectory(lib/kissfft)

set(DEPLIBS kissfft)

if (NOT WIN32)
if(APPLE)
set(DEPLIBS ${DEPLIBS} "-framework CoreVideo")
endif()

add_options(CXX ALL_BUILDS -std=c++11)

if(NOT WIN32)
if(APP_RENDER_SYSTEM STREQUAL "gl" OR NOT APP_RENDER_SYSTEM)
find_package(OpenGL)
if(OPENGL_FOUND)
set(INCLUDES ${OpenGL_INCLUDE_DIR})
add_definitions(-DHAS_OPENGL)
set(DEPLIBS ${DEPLIBS} ${OPENGL_LIBRARIES})
set(APP_RENDER_SYSTEM gl)
endif()
find_package(OpenGl REQUIRED)
set(DEPLIBS ${OPENGL_LIBRARIES})
set(includes ${OPENGL_INCLUDE_DIR})
add_definitions(${OPENGL_DEFINITIONS})
else()
find_package(OpenGLES REQUIRED)
set(DEPLIBS ${OPENGLES_LIBRARIES})
set(includes ${OPENGLES_INCLUDE_DIR})
add_definitions(${OPENGLES_DEFINITIONS})
endif()

if(APP_RENDER_SYSTEM STREQUAL "gles" OR NOT APP_RENDER_SYSTEM)
find_package(OpenGLES2)
if(OPENGLES2_FOUND)
set(INCLUDES ${OPENGLES2_INCLUDE_DIR})
add_definitions(-DHAS_GLES2 -DHAS_GLES ${OpenGLES2_CFLAGS_OTHER})
set(DEPLIBS ${DEPLIBS} ${OPENGLES2_LIBRARIES})
set(APP_RENDER_SYSTEM gles)
endif()
endif()
if(NOT APP_RENDER_SYSTEM)
message(FATAL_ERROR "No rendering API found. Bailing")
endif()
include_directories(${GLM_INCLUDE_DIR}
${KODI_INCLUDE_DIR}/.. # Hack way with "/..", need bigger Kodi cmake rework to match right include ways
${PROJECT_SOURCE_DIR}/lib)

include_directories(${OpenGL_INCLUDE_DIR}
${KODI_INCLUDE_DIR}/.. # Hack way with "/..", need bigger Kodi cmake rework to match right include ways (becomes done in future)
${p8-platform_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/lib/kissfft
${CMAKE_INCLUDE_PATH})
if(${CORE_SYSTEM_NAME} STREQUAL "osx" OR
${CORE_SYSTEM_NAME} STREQUAL "ios" OR
${CORE_SYSTEM_NAME} STREQUAL "darwin_embedded")
list(APPEND DEPLIBS "-framework CoreVideo")
endif()

set(SHADERTOY_SOURCES src/lodepng.cpp
src/main.cpp)

set(SHADERTOY_HEADERS src/lodepng.h
src/WICTextureLoader.h)

set(DEPLIBS ${DEPLIBS} ${OPENGL_LIBRARIES})

src/main.h)
elseif(WIN32)
set(APP_RENDER_SYSTEM dx11)
include_directories(${KODI_INCLUDE_DIR}/.. # Hack way with "/..", need bigger Kodi cmake rework to match right include ways (becomes done in future)
${p8-platform_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/lib/kissfft
Expand All @@ -69,7 +49,8 @@ elseif(WIN32)
src/WICTextureLoader.h)
endif()

message(STATUS "Configured render system: ${APP_RENDER_SYSTEM}")
list(APPEND DEPLIBS kissfft)
list(APPEND DEPENDS glm)

build_addon(visualization.shadertoy SHADERTOY DEPLIBS)

Expand Down
56 changes: 56 additions & 0 deletions FindOpenGLES.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#.rst:
# FindOpenGLES
# ------------
# Finds the OpenGLES2 and OpenGLES3 library
#
# This will define the following variables:
#
# OPENGLES_FOUND - system has OpenGLES
# OPENGLES_INCLUDE_DIRS - the OpenGLES include directory
# OPENGLES_LIBRARIES - the OpenGLES libraries
# OPENGLES_DEFINITIONS - the OpenGLES definitions
#

if(CORE_PLATFORM_NAME_LC STREQUAL rbpi)
set(_brcmprefix brcm)
endif()

if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_OPENGLES ${_brcmprefix}glesv2 QUIET)
endif()

if(NOT CORE_SYSTEM_NAME STREQUAL ios AND
NOT CORE_SYSTEM_NAME STREQUAL darwin_embedded)
find_path(OPENGLES_INCLUDE_DIR GLES2/gl2.h
PATHS ${PC_OPENGLES_INCLUDEDIR})
find_library(OPENGLES_gl_LIBRARY NAMES ${_brcmprefix}GLESv2
PATHS ${PC_OPENGLES_LIBDIR})
else()
find_library(OPENGLES_gl_LIBRARY NAMES OpenGLES
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
PATH_SUFFIXES Frameworks
NO_DEFAULT_PATH)
set(OPENGLES_INCLUDE_DIR ${OPENGLES_gl_LIBRARY}/Headers)
endif()

find_path(OPENGLES3_INCLUDE_DIR GLES3/gl3.h)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenGLES
REQUIRED_VARS OPENGLES_gl_LIBRARY OPENGLES_INCLUDE_DIR)

find_path(OPENGLES3_INCLUDE_DIR GLES3/gl3.h
PATHS ${PC_OPENGLES_INCLUDEDIR})

if(OPENGLES_FOUND)
set(OPENGLES_LIBRARIES ${OPENGLES_gl_LIBRARY})
if(OPENGLES3_INCLUDE_DIR)
set(OPENGLES_INCLUDE_DIRS ${OPENGLES_INCLUDE_DIR} ${OPENGLES3_INCLUDE_DIR})
set(OPENGLES_DEFINITIONS -DHAS_GLES=3)
mark_as_advanced(OPENGLES_INCLUDE_DIR OPENGLES3_INCLUDE_DIR OPENGLES_gl_LIBRARY)
else()
set(OPENGLES_INCLUDE_DIRS ${OPENGLES_INCLUDE_DIR})
set(OPENGLES_DEFINITIONS -DHAS_GLES=2)
mark_as_advanced(OPENGLES_INCLUDE_DIR OPENGLES_gl_LIBRARY)
endif()
endif()
36 changes: 0 additions & 36 deletions FindOpenGLES2.cmake

This file was deleted.

41 changes: 41 additions & 0 deletions FindOpenGl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#.rst:
# FindOpenGl
# ----------
# Finds the FindOpenGl library
#
# This will define the following variables::
#
# OPENGL_FOUND - system has OpenGl
# OPENGL_INCLUDE_DIRS - the OpenGl include directory
# OPENGL_LIBRARIES - the OpenGl libraries
# OPENGL_DEFINITIONS - the OpenGl definitions

if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_OPENGL gl QUIET)
endif()

if(NOT CORE_SYSTEM_NAME STREQUAL osx)
find_path(OPENGL_INCLUDE_DIR GL/gl.h
PATHS ${PC_OPENGL_gl_INCLUDEDIR})
find_library(OPENGL_gl_LIBRARY NAMES GL
PATHS ${PC_OPENGL_gl_LIBDIR})
else()
find_library(OPENGL_gl_LIBRARY NAMES OpenGL
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
PATH_SUFFIXES Frameworks
NO_DEFAULT_PATH)
set(OPENGL_INCLUDE_DIR ${OPENGL_gl_LIBRARY}/Headers)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenGl
REQUIRED_VARS OPENGL_gl_LIBRARY OPENGL_INCLUDE_DIR)

if(OPENGL_FOUND)
set(OPENGL_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
set(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY})
set(OPENGL_DEFINITIONS -DHAS_GL=1)
endif()

mark_as_advanced(OPENGL_INCLUDE_DIR OPENGL_gl_LIBRARY)

1 change: 1 addition & 0 deletions depends/common/glm/flags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-DGLM_TEST_ENABLE_CXX_11=1 -DGLM_TEST_ENABLE=0 -DGLM_TEST_ENABLE_SIMD_SSE2=0 -DCMAKE_INSTALL_LIBDIR=lib
1 change: 1 addition & 0 deletions depends/common/glm/glm.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7f093f11c49877716bab96813c2e834db6839095281c8c0c65c60c8bdb9504a3
1 change: 1 addition & 0 deletions depends/common/glm/glm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
glm https://github.com/g-truc/glm/archive/47031aa4b7b079716e4cac496819e7f464b6a713.tar.gz
1 change: 1 addition & 0 deletions depends/osx/glm/flags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-DGLM_TEST_ENABLE_CXX_11=1 -DGLM_TEST_ENABLE=0 -DGLM_TEST_ENABLE_SIMD_SSE2=1 -DCMAKE_INSTALL_LIBDIR=lib
1 change: 1 addition & 0 deletions depends/osx/glm/glm.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7f093f11c49877716bab96813c2e834db6839095281c8c0c65c60c8bdb9504a3
1 change: 1 addition & 0 deletions depends/osx/glm/glm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
glm https://github.com/g-truc/glm/archive/47031aa4b7b079716e4cac496819e7f464b6a713.tar.gz
10 changes: 2 additions & 8 deletions lib/kissfft/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
cmake_minimum_required(VERSION 3.5)
project(kissfft)

enable_language(C)

cmake_minimum_required(VERSION 2.6)

set(SOURCES kiss_fft.c)

if(NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif()

add_library(kissfft STATIC ${SOURCES})
set_property(TARGET kissfft PROPERTY POSITION_INDEPENDENT_CODE ON)
111 changes: 111 additions & 0 deletions lib/kodi/gui/gl/GL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (C) 2005-2019 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#pragma once

//==============================================================================
///
/// \defgroup cpp_kodi_gui_gl OpenGL helpers
/// \ingroup cpp_kodi_gui
/// \brief Auxiliary functions for Open GL
///
/// This group includes help for definitions, functions, and classes for
/// OpenGL.
///
/// To use OpenGL for your system, add the \ref GL.h "#include <kodi/gui/gl/GL.h>".
///
///
///-----------------------------------------------------------------------------
///
/// The \ref HAS_GL is declared if Open GL is required and \ref HAS_GLES if Open GL
/// Embedded Systems (ES) is required, with ES the version is additionally given
/// in the definition, this can be "2" or "3".
///
///
///-----------------------------------------------------------------------------
///
/// Following \ref GL_TYPE_STRING define can be used, for example, to manage
/// different folders for GL and GLES and make the selection easier.
/// This are on OpenGL <b>"GL"</b> and on Open GL|ES <b>"GLES"</b>.
///
/// **Example:**
/// ~~~~~~~~~~~~~~~~~{.cpp}
/// kodi::GetAddonPath("resources/shaders/" GL_TYPE_STRING "/frag.glsl");
/// ~~~~~~~~~~~~~~~~~
///
///
///----------------------------------------------------------------------------
///
/// In addition, \ref BUFFER_OFFSET is declared in it which can be used to give an
/// offset on the array to GL.
///
/// **Example:**
/// ~~~~~~~~~~~~~~~~~{.cpp}
/// const struct PackedVertex {
/// float position[3]; // Position x, y, z
/// float color[4]; // Color r, g, b, a
/// } vertices[3] = {
/// { { -0.5f, -0.5f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
/// { { 0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
/// { { 0.0f, 0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }
/// };
///
/// glVertexAttribPointer(m_aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, position)));
/// glEnableVertexAttribArray(m_aPosition);
///
/// glVertexAttribPointer(m_aColor, 4, GL_FLOAT, GL_FALSE, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, color)));
/// glEnableVertexAttribArray(m_aColor);
/// ~~~~~~~~~~~~~~~~~

#if HAS_GL
#define GL_TYPE_STRING "GL"
// always define GL_GLEXT_PROTOTYPES before include gl headers
#if !defined(GL_GLEXT_PROTOTYPES)
#define GL_GLEXT_PROTOTYPES
#endif
#if defined(TARGET_LINUX)
#include <GL/gl.h>
#include <GL/glext.h>
#elif defined(TARGET_FREEBSD)
#include <GL/gl.h>
#elif defined(TARGET_DARWIN)
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#elif defined(WIN32)
#error Use of GL under Windows is not possible
#endif
#elif HAS_GLES >= 2
#define GL_TYPE_STRING "GLES"
#if defined(WIN32)
#if defined(HAS_ANGLE)
#include <angle_gl.h>
#else
#error Use of GLES only be available under Windows by the use of angle
#endif
#elif defined(TARGET_DARWIN)
#if HAS_GLES == 3
#include <OpenGLES/ES3/gl.h>
#include <OpenGLES/ES3/glext.h>
#else
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#endif
#else
#if HAS_GLES == 3
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#else
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#endif
#endif
#endif

#ifndef BUFFER_OFFSET
#define BUFFER_OFFSET(i) ((char *)nullptr + (i))
#endif
Loading

0 comments on commit e6fe746

Please sign in to comment.