Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

OpenGL backend (stage 1) #535

Merged
merged 19 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ endif()

option(USE_STDCPP "Use -stdlib=libc++" OFF)
option(TI_WITH_CUDA "Build with CUDA support" OFF)
option(TI_WITH_OPENGL "Build with OpenGL backend" ON)
option(GLEW_USE_STATIC_LIBS OFF)

include_directories(${CMAKE_SOURCE_DIR})
include_directories(external/xxhash)
Expand Down Expand Up @@ -53,6 +55,29 @@ if (TI_WITH_CUDA)
endif()
endif()

if (TI_WITH_OPENGL)
if(NOT GLEW_VERSION)
set(GLEW_VERSION 2.0.0)
endif()
find_package(GLEW ${GLEW_VERSION})
if (GLEW_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_OPENGL")
message("Building with GLEW ${GLEW_VERSION}")
message("Using GLEW: ${GLEW_LIBRARIES}")
target_include_directories(${LIBRARY_NAME} PUBLIC ${GLEW_INCLUDE_DIRS})
target_link_libraries(${LIBRARY_NAME} ${GLEW_LIBRARIES} GLEW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGLEW_STATIC")
find_package(glfw3 REQUIRED)
if (NOT glfw3_FOUND)
message(FATAL_ERROR "glfw3 not found.")
endif()
message("Building with glfw ${glfw3_VERSION}")
target_link_libraries(${LIBRARY_NAME} glfw)
else()
message(WARNING "GLEW not found, ignoring TI_WITH_OPENGL.")
endif()
endif()

# http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
find_package(LLVM REQUIRED CONFIG 8.0)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
Expand Down
2 changes: 1 addition & 1 deletion examples/mpm99.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import taichi as ti
ti.init(arch=ti.cuda) # Try to run on GPU
ti.init(arch=ti.cuda) # Try to run on GPU. Use arch=ti.opengl on old GPUs
quality = 1 # Use a larger value for higher-res simulations
n_particles, n_grid = 9000 * quality ** 2, 128 * quality
dx, inv_dx = 1 / n_grid, float(n_grid)
Expand Down
3 changes: 3 additions & 0 deletions python/taichi/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
x64 = core.x64
cuda = core.cuda
metal = core.metal
opengl = core.opengl
profiler_print = lambda: core.get_current_program().profiler_print()
profiler_clear = lambda: core.get_current_program().profiler_clear()
profiler_start = lambda n: core.get_current_program().profiler_start(n)
Expand Down Expand Up @@ -222,6 +223,8 @@ def supported_archs():
archs.append(cuda)
if ti.core.with_metal():
archs.append(metal)
if ti.core.with_opengl():
archs.append(opengl)
return archs

class _ArchCheckers(object):
Expand Down
Loading