This commit is contained in:
fxia22 2020-02-12 17:06:02 -08:00
parent 0531d9b0f3
commit efafee76f2
6 changed files with 97 additions and 3 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "gibson2/core/render/pybind11"]
path = gibson2/core/render/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "gibson2/core/render/glfw"]
path = gibson2/core/render/glfw
url = https://github.com/glfw/glfw

View File

@ -46,7 +46,7 @@ if __name__ == '__main__':
while True:
with Profiler('Render'):
frame = renderer.render(modes=('rgb', 'normal', '3d'))
frame = renderer.render(modes=('rgb', 'seg', 'normal', '3d'))
cv2.imshow('test', cv2.cvtColor(np.concatenate(frame, axis=1), cv2.COLOR_RGB2BGR))
q = cv2.waitKey(1)
if q == ord('w'):

View File

@ -12,25 +12,39 @@ endif()
add_subdirectory(pybind11)
# Find GLFW and OpenVR
set(GLFW_DIR glfw)
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")
add_subdirectory("${GLFW_DIR}")
include_directories("${GLFW_DIR}/include")
find_package(CUDA REQUIRED)
set(CUDA_LIBRARIES PUBLIC ${CUDA_LIBRARIES})
cuda_add_library(MeshRendererContext MODULE glad/egl.cpp glad/gl.cpp cpp/Mesh_renderer.cpp)
add_library(CGLUtils MODULE glad/egl.cpp glad/gl.cpp cpp/cgl_utils.cpp)
add_library(tinyobjloader MODULE cpp/tinyobjloader/tiny_obj_loader.cc cpp/tinyobjloader/bindings.cc)
add_library(GLFWRendererContext MODULE glad/gl.cpp cpp/glfw_mesh_renderer.cpp)
if (USE_GLAD)
target_link_libraries(MeshRendererContext PRIVATE pybind11::module dl pthread)
target_link_libraries(CGLUtils PRIVATE pybind11::module dl pthread)
target_link_libraries(GLFWRendererContext PRIVATE pybind11::module dl glfw ${GLFW_LIBRARIES})
else ()
target_link_libraries(MeshRendererContext PRIVATE pybind11::module dl pthread EGL ${OPENGL_LIBRARIES})
target_link_libraries(CGLUtils PRIVATE pybind11::module dl pthread EGL ${OPENGL_LIBRARIES})
target_link_libraries(CGLUtils PRIVATE pybind11::module dl pthread EGL ${OPENGL_LIBRARIES})
target_link_libraries(GLFWRendererContext PRIVATE pybind11::module dl glfw ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES})
endif()
target_link_libraries(tinyobjloader PRIVATE pybind11::module)
set_target_properties(MeshRendererContext PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
set_target_properties(GLFWRendererContext PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
set_target_properties(CGLUtils PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
set_target_properties(tinyobjloader PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"

View File

@ -0,0 +1,76 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <glad/gl.h>
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
namespace py = pybind11;
class GLFWRendererContext {
public:
GLFWRendererContext(int w, int h) :m_windowHeight(h), m_windowWidth(w) {};
int m_windowWidth;
int m_windowHeight;
int init() {
// Initialize GLFW context and window
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW.\n");
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Hide GLFW window by default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow* window = glfwCreateWindow(m_windowHeight, m_windowHeight, "Gibson VR Renderer", NULL, NULL);
if (window == NULL) {
fprintf(stderr, "Failed to create GLFW window.\n");
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
// Load all OpenGL function pointers through GLAD
if (!gladLoadGL(glfwGetProcAddress))
{
fprintf(stderr, "Failed to load OpenGL function pointers through GLAD.\n");
exit(EXIT_FAILURE);
}
printf("Succesfully initialized GLFW context and window!\n");
return 0;
}
void release() {
glfwTerminate();
}
};
PYBIND11_MODULE(GLFWRendererContext, m) {
m.doc() = "C++ GLFW bindings";
py::class_<GLFWRendererContext>(m, "GLFWRendererContext")
.def(py::init<int, int>())
.def("init", &GLFWRendererContext::init)
.def("release", &GLFWRendererContext::release);
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;
#else
m.attr("__version__") = "dev";
#endif
}

@ -0,0 +1 @@
Subproject commit 76406c7894912125afae59e6e5be00222ba10b48

View File

@ -11,7 +11,7 @@ import numpy as np
from gibson2.core.render.mesh_renderer.glutils.meshutil import perspective, lookat, xyz2mat, quat2rotmat, mat2xyz, safemat2quat
from transforms3d.quaternions import axangle2quat, mat2quat
from transforms3d.euler import quat2euler, mat2euler
from gibson2.core.render.mesh_renderer import MeshRendererContext, CGLUtils
from gibson2.core.render.mesh_renderer import MeshRendererContext, CGLUtils, GLFWRendererContext
from gibson2.core.render.mesh_renderer.get_available_devices import get_available_devices
from gibson2.core.render.mesh_renderer.glutils.utils import colormap, loadTexture
import gibson2.core.render.mesh_renderer as mesh_renderer