osxGraphicsBuffer

This commit is contained in:
David Rose 2009-03-10 12:51:15 +00:00
parent 3cfc2b6427
commit a7678cb3e4
7 changed files with 80 additions and 29 deletions

View File

@ -65,7 +65,7 @@ init_libosxdisplay() {
}
initialized = true;
osxGraphicsStateGuardian::init_type();
osxGraphicsBuffer::init_type();
osxGraphicsPipe::init_type();
osxGraphicsWindow::init_type();
osxGraphicsStateGuardian::init_type();

View File

@ -37,7 +37,11 @@ osxGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe,
{
osxGraphicsPipe *osx_pipe;
DCAST_INTO_V(osx_pipe, _pipe);
_pbuffer = NULL;
// Since the pbuffer never gets flipped, we get screenshots from the
// same buffer we draw into.
_screenshot_buffer_type = _draw_buffer_type;
}
@ -48,6 +52,7 @@ osxGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe,
////////////////////////////////////////////////////////////////////
osxGraphicsBuffer::
~osxGraphicsBuffer() {
nassertv(_pbuffer == NULL);
}
////////////////////////////////////////////////////////////////////
@ -67,15 +72,23 @@ begin_frame(FrameMode mode, Thread *current_thread) {
if (_gsg == (GraphicsStateGuardian *)NULL) {
return false;
}
nassertr(_pbuffer != NULL, false);
osxGraphicsStateGuardian *osxgsg;
DCAST_INTO_R(osxgsg, _gsg, false);
// osxMakeCurrent(_display, _pbuffer, osxgsg->_context);
if (!aglSetPBuffer(osxgsg->get_context(), _pbuffer, 0, 0, 0)) {
aglReportError("aglSetPBuffer");
return false;
}
if (!aglSetCurrentContext(osxgsg->get_context())) {
aglReportError("aglSetCurrentContext");
return false;
}
osxgsg->reset_if_new();
if (mode == FM_render)
{
if (mode == FM_render) {
for (int i=0; i<count_textures(); i++) {
if (get_rtm_mode(i) == RTM_bind_or_copy) {
_textures[i]._rtm_mode = RTM_copy_texture;
@ -99,8 +112,7 @@ end_frame(FrameMode mode, Thread *current_thread) {
end_frame_spam(mode);
nassertv(_gsg != (GraphicsStateGuardian *)NULL);
if (mode == FM_render)
{
if (mode == FM_render) {
copy_to_textures();
}
@ -124,10 +136,14 @@ end_frame(FrameMode mode, Thread *current_thread) {
void osxGraphicsBuffer::
close_buffer() {
if (_gsg != (GraphicsStateGuardian *)NULL) {
//osxMakeCurrent(_display, None, NULL);
// aglSetPBuffer(osxgsg->get_context(), _pbuffer, 0, 0, 0);
_gsg.clear();
_active = false;
}
if (_pbuffer != NULL) {
aglDestroyPBuffer(_pbuffer);
_pbuffer = NULL;
}
_is_valid = false;
}
@ -140,11 +156,52 @@ close_buffer() {
////////////////////////////////////////////////////////////////////
bool osxGraphicsBuffer::
open_buffer() {
if (_gsg == 0) {
_gsg = new osxGraphicsStateGuardian(_engine, _pipe, NULL);
}
if (_pbuffer == NULL) {
if (!aglCreatePBuffer(_x_size, _y_size, GL_TEXTURE_2D, GL_RGBA, 0, &_pbuffer)) {
aglReportError("aglCreatePBuffer");
close_buffer();
return false;
}
}
osxGraphicsStateGuardian *osxgsg;
DCAST_INTO_R(osxgsg, _gsg, false);
OSStatus stat = osxgsg->buildGL(false, true, _fb_properties);
if (stat != noErr) {
return false;
}
if (!aglSetPBuffer(osxgsg->get_context(), _pbuffer, 0, 0, 0)) {
aglReportError("aglSetPBuffer");
close_buffer();
return false;
}
if (!aglSetCurrentContext(osxgsg->get_context())) {
aglReportError("aglSetCurrentContext");
return false;
}
osxgsg->reset_if_new();
if (!osxgsg->is_valid()) {
close_buffer();
return false;
}
/*
if (!osxgsg->get_fb_properties().verify_hardware_software
(_fb_properties, osxgsg->get_gl_renderer())) {
close_buffer();
return false;
}
_fb_properties = osxgsg->get_fb_properties();
*/
return false;
_is_valid = true;
return true;
}

View File

@ -23,12 +23,11 @@
#include "glgsg.h"
////////////////////////////////////////////////////////////////////
// Class : OSXGraphicsBuffer
// rhh mar-2006
// Sorry ... this is not functional at all... I have no need for it yet ?
//
// Class : osxGraphicsBuffer
// Description : An offscreen buffer in the OSX environment. This
// creates an AGLPbuffer.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAGL osxGraphicsBuffer : public GraphicsBuffer {
class osxGraphicsBuffer : public GraphicsBuffer {
public:
osxGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe,
const string &name,
@ -39,7 +38,6 @@ public:
GraphicsOutput *host);
virtual ~osxGraphicsBuffer();
virtual bool begin_frame(FrameMode mode, Thread *current_thread);
virtual void end_frame(FrameMode mode, Thread *current_thread);
@ -47,6 +45,8 @@ protected:
virtual void close_buffer();
virtual bool open_buffer();
private:
AGLPbuffer _pbuffer;
public:
static TypeHandle get_class_type() {
@ -54,7 +54,7 @@ public:
}
static void init_type() {
GraphicsBuffer::init_type();
register_type(_type_handle, "owsGraphicsBuffer",
register_type(_type_handle, "osxGraphicsBuffer",
GraphicsBuffer::get_class_type());
}
virtual TypeHandle get_type() const {

View File

@ -212,7 +212,6 @@ make_output(const string &name,
GraphicsOutput *host,
int retry,
bool &precertify) {
if (!_is_valid) {
return NULL;
}
@ -269,7 +268,6 @@ make_output(const string &name,
}
// Third thing to try: an osxGraphicsBuffer
/*
if (retry == 2) {
if ((!support_render_texture)||
((flags&BF_require_parasite)!=0)||
@ -282,7 +280,7 @@ make_output(const string &name,
return new osxGraphicsBuffer(engine, this, name, fb_prop, win_prop,
flags, gsg, host);
}
*/
// Nothing else left to try.
return NULL;
}

View File

@ -184,8 +184,7 @@ draw_resize_box() {
// Description: This function will build up a context for a gsg..
////////////////////////////////////////////////////////////////////
OSStatus osxGraphicsStateGuardian::
buildGL(osxGraphicsWindow &window, bool full_screen,
FrameBufferProperties &fb_props) {
buildGL(bool full_screen, bool pbuffer, FrameBufferProperties &fb_props) {
if (_aglcontext) {
describe_pixel_format(fb_props);
return noErr; // already built
@ -230,16 +229,14 @@ buildGL(osxGraphicsWindow &window, bool full_screen,
if (full_screen) {
attrib.push_back(AGL_FULLSCREEN);
}
if (pbuffer) {
attrib.push_back(AGL_PBUFFER);
}
// These are renderer modes, not pixel modes. Not sure if they have
// any meaning here; maybe we should handle these flags differently.
if (fb_props.get_force_hardware()) {
attrib.push_back(AGL_ACCELERATED);
attrib.push_back(AGL_NO_RECOVERY);
}
if (fb_props.get_force_software()) {
attrib.push_back(AGL_PBUFFER);
}
// Allow the system to choose the largest buffers requested that
// meets all our selections.

View File

@ -50,8 +50,7 @@ protected:
virtual void *get_extension_func(const char *prefix, const char *name);
public:
OSStatus buildGL(osxGraphicsWindow &window, bool full_screen,
FrameBufferProperties &fb_props);
OSStatus buildGL(bool full_screen, bool pbuffer, FrameBufferProperties &fb_props);
AGLContext get_context(void) { return _aglcontext; };
const AGLPixelFormat getAGlPixelFormat() const { return _aglPixFmt; };

View File

@ -692,7 +692,7 @@ buildGL(bool full_screen) {
// make sure the ggs is up and runnig..
osxGraphicsStateGuardian *osxgsg = NULL;
osxgsg = DCAST(osxGraphicsStateGuardian, _gsg);
OSStatus stat = osxgsg->buildGL(*this, full_screen, _fb_properties);
OSStatus stat = osxgsg->buildGL(full_screen, false, _fb_properties);
if(stat != noErr) {
return stat;