Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build*
_builds
_logs
.vscode
.vs
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ set(component_list "")
foreach(component_cmake ${components_cmake})
get_filename_component(component_dir ${component_cmake} DIRECTORY)
get_filename_component(component_name ${component_dir} NAME)
add_library(${component_name} "")
list(APPEND component_list ${component_name})
list(FIND component_list ${component_name} index)

if(index EQUAL -1)
add_library(${component_name} "")
list(APPEND component_list ${component_name})
endif()
endforeach()

foreach(component_cmake ${components_cmake})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef std::map<int,std::function<void(int)> > KeyhookMap;
struct PANGOLIN_EXPORT PangolinGl
{
PangolinGl();
PangolinGl(PangolinGl& other);
~PangolinGl();

void Run();
Expand Down Expand Up @@ -88,15 +89,15 @@ struct PANGOLIN_EXPORT PangolinGl
std::shared_ptr<WindowInterface> window;
std::shared_ptr<GlFont> font;

std::unique_ptr<ConsoleView> console_view;
std::shared_ptr<ConsoleView> console_view;
};

PangolinGl* GetCurrentContext();
void SetCurrentContext(PangolinGl* context);
void RegisterNewContext(const std::string& name, std::shared_ptr<PangolinGl> newcontext);
void DeleteContext(const std::string& name);
PangolinGl *FindContext(const std::string& name);
void SetCurrentContext(PangolinGl* newcontext);
PangolinGl* FindContext(const std::string& name);
void SetCurrentContext(std::shared_ptr<PangolinGl> newcontext);

}

2 changes: 1 addition & 1 deletion components/pango_display/src/default_font.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <pangolin/display/default_font.h>

#include "pangolin_gl.h"
#include <pangolin/display/pangolin_gl.h>

extern const unsigned char AnonymousPro_ttf[];

Expand Down
7 changes: 2 additions & 5 deletions components/pango_display/src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include <pangolin/image/image_io.h>
#include <pangolin/var/var.h>

#include "pangolin_gl.h"
#include <pangolin/display/pangolin_gl.h>

extern const unsigned char AnonymousPro_ttf[];

Expand All @@ -63,7 +63,6 @@ std::recursive_mutex contexts_mutex;

// Context active for current thread
__thread PangolinGl* context = 0;

void SetCurrentContext(PangolinGl* newcontext) {
context = newcontext;
}
Expand All @@ -85,7 +84,6 @@ PangolinGl *FindContext(const std::string& name)
WindowInterface& CreateWindowAndBind(std::string window_title, int w, int h, const Params& params)
{
std::unique_lock<std::recursive_mutex> l(contexts_mutex);

pangolin::Uri win_uri;

if(const char* extra_params = std::getenv("PANGOLIN_WINDOW_URI"))
Expand Down Expand Up @@ -178,7 +176,6 @@ void RegisterNewContext(const std::string& name, std::shared_ptr<PangolinGl> new
throw std::runtime_error("Context already exists.");
}
contexts[name] = newcontext;

// Process the following as if this context is now current.
PangolinGl *oldContext = context;
context = newcontext.get();
Expand Down Expand Up @@ -264,7 +261,7 @@ View& DisplayBase()

View& CreateDisplay()
{
int iguid = rand();
int iguid =std::chrono::high_resolution_clock::now().time_since_epoch().count();
std::stringstream ssguid;
ssguid << iguid;
return Display(ssguid.str());
Expand Down
2 changes: 1 addition & 1 deletion components/pango_display/src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <pangolin/handler/handler.h>
#include <pangolin/display/display.h>

#include "pangolin_gl.h"
#include <pangolin/display/pangolin_gl.h>

namespace pangolin
{
Expand Down
3 changes: 1 addition & 2 deletions components/pango_display/src/pangolin_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include "pangolin_gl.h"
#include <pangolin/display/pangolin_gl.h>
#include <pangolin/display/display.h>
#include <pangolin/console/ConsoleView.h>

Expand All @@ -36,7 +36,6 @@ PangolinGl::PangolinGl()
: user_app(0), quit(false), mouse_state(0),activeDisplay(0)
{
}

PangolinGl::~PangolinGl()
{
// Free displays owned by named_managed_views
Expand Down
4 changes: 2 additions & 2 deletions components/pango_display/src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <pangolin/display/process.h>
#include <pangolin/console/ConsoleView.h>
#include <pangolin/handler/handler.h>
#include "pangolin_gl.h"
#include <pangolin/display/pangolin_gl.h>

namespace pangolin
{
Expand All @@ -47,7 +47,7 @@ void Resize( int width, int height )

void Keyboard(unsigned char key, int x, int y, bool pressed, KeyModifierBitmask /*key_modifiers*/)
{
PangolinGl* context = GetCurrentContext();
PangolinGl* context = GetCurrentContext();

// Force coords to match OpenGl Window Coords
y = context->base.v.h - y;
Expand Down
2 changes: 1 addition & 1 deletion components/pango_display/src/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <pangolin/gl/opengl_render_state.h>
#include <pangolin/platform.h>

#include "pangolin_gl.h"
#include <pangolin/display/pangolin_gl.h>

namespace pangolin
{
Expand Down
2 changes: 1 addition & 1 deletion components/pango_display/src/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <pangolin/var/varextra.h>
#include <pangolin/utils/file_utils.h>

#include "pangolin_gl.h"
#include <pangolin/display/pangolin_gl.h>


using namespace std;
Expand Down
13 changes: 6 additions & 7 deletions components/pango_geometry/src/geometry_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ pangolin::Geometry LoadGeometryObj(const std::string& filename)
PANGO_ASSERT(attrib.texcoords.size() % 2 == 0);

// Load textures - a bit of a hack for now.
for(size_t i=0; i < materials.size(); ++i) {
if(!materials[i].diffuse_texname.empty()) {
const std::string tex_name = FormatString("texture_%",i);
for(const auto& material : materials) {
if(!material.diffuse_texname.empty()) {
try {
TypedImage& tex_image = geom.textures[tex_name];
tex_image = LoadImage(PathParent(filename) + "/" + materials[i].diffuse_texname);
TypedImage& tex_image = geom.textures[material.name];
tex_image = LoadImage(PathParent(filename) + "/" + material.diffuse_texname);
const int row_bytes = tex_image.w * tex_image.fmt.bpp / 8;
std::vector<unsigned char> tmp_row(row_bytes);
for (std::size_t y=0; y < (tex_image.h >> 1); ++y) {
Expand All @@ -115,8 +114,8 @@ pangolin::Geometry LoadGeometryObj(const std::string& filename)
std::memcpy(tex_image.RowPtr(tex_image.h - 1 - y), tmp_row.data(), row_bytes);
}
} catch(const std::exception&) {
pango_print_warn("Unable to read texture '%s'\n", tex_name.c_str());
geom.textures.erase(tex_name);
pango_print_warn("Unable to read texture '%s'\n", material.name.c_str());
geom.textures.erase(material.name);
}
}
}
Expand Down
59 changes: 31 additions & 28 deletions components/pango_glgeometry/src/glgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,47 +96,50 @@ void GlDraw(GlSlProgram& prog, const GlGeometry& geom, const GlTexture* matcap)
{
// Bind textures
int num_tex_bound = 0;
for(auto& tex : geom.textures) {
glActiveTexture(GL_TEXTURE0 + num_tex_bound);
tex.second.Bind();
prog.SetUniform(tex.first, (int)num_tex_bound);
++num_tex_bound;
for (const auto& buffer: geom.buffers) {
BindGlElement(prog, buffer.second);
}

if(matcap) {
glActiveTexture(GL_TEXTURE0 + num_tex_bound);
matcap->Bind();
prog.SetUniform("matcap", (int)num_tex_bound);
++num_tex_bound;
}

// Bind all attribute buffers
for(auto& buffer : geom.buffers) {
BindGlElement(prog, buffer.second);
}

// Draw all geometry
for(auto& buffer : geom.objects) {
auto it_indices = buffer.second.attributes.find("vertex_indices");
if(it_indices != buffer.second.attributes.end()) {
buffer.second.Bind();
auto& attrib = it_indices->second;
glDrawElements(
GL_TRIANGLES, attrib.count_per_element * attrib.num_elements,
attrib.gltype, reinterpret_cast<uint8_t*>(attrib.offset)
);
buffer.second.Unbind();
}else{
std::vector<std::string> texturesNames;
for (auto& tex: geom.textures) {
texturesNames.emplace_back(tex.first);
}
}
for (auto& texName: texturesNames) {
glActiveTexture(GL_TEXTURE0 + num_tex_bound);
geom.textures.at(texName).Bind();
prog.SetUniform("texture", (int) num_tex_bound);

auto& buffer = *geom.objects.equal_range(texName).first;
auto it_indices = buffer.second.attributes.find("vertex_indices");
if (it_indices != buffer.second.attributes.end()) {
buffer.second.Bind();
auto& attrib = it_indices->second;
glDrawElements(
GL_TRIANGLES, attrib.count_per_element * attrib.num_elements,
attrib.gltype, reinterpret_cast<uint8_t *>(attrib.offset)
);
buffer.second.Unbind();

}

++num_tex_bound;

// Unbind attribute buffers
for(auto& buffer : geom.buffers) {
UnbindGlElements(prog, buffer.second);
}
}

// Unbind textures
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);

// Unbind attribute buffers
for (const auto& buffer: geom.buffers) {
UnbindGlElements(prog, buffer.second);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
#include <pangolin/platform.h>
#include <pangolin/windowing/window.h>
#include <windowsx.h>

namespace pangolin
{

struct WinWindow : public WindowInterface
{
WinWindow(
Expand Down Expand Up @@ -70,7 +69,7 @@ struct WinWindow : public WindowInterface

LRESULT HandleWinMessages(UINT message, WPARAM wParam, LPARAM lParam);

void RegisterThisClass(HMODULE hCurrentInst);
void RegisterThisClass(HMODULE hCurrentInst,const std::string &window_title);

void SetupPixelFormat(HDC hdc);

Expand Down
12 changes: 4 additions & 8 deletions components/pango_windowing/src/display_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ inline void _CheckWLDieOnError( const char *sFile, const int nLine )

namespace pangolin
{

const char *className = "Pangolin";

////////////////////////////////////////////////////////////////////////
// Utils
////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -214,10 +212,10 @@ WinWindow::WinWindow(
std::cerr << "GetModuleHandle() failed" << std::endl;
CheckWGLDieOnError();
}
RegisterThisClass(hCurrentInst);
RegisterThisClass(hCurrentInst,window_title);

HWND thishwnd = CreateWindowA(
className, window_title.c_str(),
window_title.c_str(), window_title.c_str(),
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0, 0, width, height,
NULL, NULL, hCurrentInst, this);
Expand All @@ -229,7 +227,6 @@ WinWindow::WinWindow(
if( thishwnd != hWnd ) {
throw std::runtime_error("Pangolin Window Creation Failed.");
}

// Display Window
ShowWindow(hWnd, SW_SHOW);
}
Expand All @@ -242,7 +239,7 @@ WinWindow::~WinWindow()
}
}

void WinWindow::RegisterThisClass(HMODULE hCurrentInst)
void WinWindow::RegisterThisClass(HMODULE hCurrentInst,const std::string &window_title)
{
WNDCLASSA wndClass;
wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
Expand All @@ -254,7 +251,7 @@ void WinWindow::RegisterThisClass(HMODULE hCurrentInst)
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = className;
wndClass.lpszClassName = window_title.c_str();
if(!RegisterClassA(&wndClass)) {
std::cerr << "RegisterClass() failed" << std::endl;
CheckWGLDieOnError();
Expand Down Expand Up @@ -537,7 +534,6 @@ void WinWindow::Resize(unsigned int w, unsigned int h)
CheckWGLDieOnError();
}
}

void WinWindow::MakeCurrent()
{
if(wglMakeCurrent(hDC, hGLRC)==FALSE) {
Expand Down
7 changes: 4 additions & 3 deletions examples/HelloPangolinThreads/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.5 REQUIRED)
find_package(Pangolin 0.8 REQUIRED)

find_package(Threads QUIET)

if(Theads_FOUND)
if(Threads_FOUND)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(HelloPangolinThreads main.cpp)
target_include_directories(HelloPangolinThreads ${Pangolin_INCLUDE_DIRS})
target_link_libraries(HelloPangolinThreads pango_display Threads::Threads)
endif()
Loading
Loading