Texture to other application

Hello everybody,
I wrote an application with the chromium embedded framework and it just simply renders a Webbrowser window to a texture in openGL.Now I want to use this texture in another application which also uses the openGL engine to render stuff.My question is now how can I share the texture with the other application ? The First application uses the following code to render the browser to a texture and bind it.I hope someone can help me with this problem :slight_smile:

render_handler.h:


#include <GL/glew.h>
#include <include/cef_render_handler.h>

class RenderHandler : public CefRenderHandler
{
public:
	RenderHandler();

public:
	void init();
	void resize(int w, int h);

	// CefRenderHandler interface
public:
	bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect);
	void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height);

	// CefBase interface
public:
	IMPLEMENT_REFCOUNTING(RenderHandler);

public:
	GLuint tex() const { return tex_; }

private:
	int width_;
	int height_;

	GLuint tex_;
};

render_handler.cpp:


#include "render_handler.h"

RenderHandler::RenderHandler()
	: width_(2), height_(2), tex_(0) 
{
}

void RenderHandler::init()
{
	glGenTextures(1, &tex_);
	glBindTexture(GL_TEXTURE_2D, tex_);

	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, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	// dummy texture data - for debugging
	const unsigned char data[] = {
		255, 0, 0, 255,
		0, 255, 0, 255,
		0, 0, 255, 255,
		255, 255, 255, 255,
	};
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

	glBindTexture(GL_TEXTURE_2D, 0);
}
void RenderHandler::resize(int w, int h)
{
	width_ = w;
	height_ = h;
}

bool RenderHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
{
	rect = CefRect(0, 0, width_, height_);
	return true;
}

void RenderHandler::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height)
{
	glBindTexture(GL_TEXTURE_2D, tex_);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, (unsigned char*)buffer);
	glBindTexture(GL_TEXTURE_2D, 0);
}

Nobody ? :slight_smile:

Well, I am not an expert, so maybe I am wrong but as far as I know there is no “legal” (officially supported) way to share the resources directly across program boundaries. The simplest way would be to save the texture to a temporary file and reload it into the other program. Another way is to establish some communication between both applications and transfer the texture data. There are libs that can do that. However, you can’t just pass the texture handle and use it. You need to upload the texture data again. So you do not really share the data, you just duplicate it.

In general, this isn’t possible.

Under X11, the EXT_import_context extension allows you to share indirect rendering contexts (with all their associated data) between processes using the same display.

Under X11 and Windows, the (Nvidia-specific) NV_copy_image extension provides functions similar to glCopyImageSubData() but which allow copying data between textures belonging to different contexts.