00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "osMesaGraphicsBuffer.h"
00016 #include "config_mesadisplay.h"
00017 #include "osMesaGraphicsPipe.h"
00018 #include "osMesaGraphicsStateGuardian.h"
00019
00020 TypeHandle OsMesaGraphicsBuffer::_type_handle;
00021
00022
00023
00024
00025
00026
00027 OsMesaGraphicsBuffer::
00028 OsMesaGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe,
00029 const string &name,
00030 const FrameBufferProperties &fb_prop,
00031 const WindowProperties &win_prop,
00032 int flags,
00033 GraphicsStateGuardian *gsg,
00034 GraphicsOutput *host) :
00035 GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
00036 {
00037 _type = GL_UNSIGNED_BYTE;
00038 _screenshot_buffer_type = _draw_buffer_type;
00039 }
00040
00041
00042
00043
00044
00045
00046 OsMesaGraphicsBuffer::
00047 ~OsMesaGraphicsBuffer() {
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 bool OsMesaGraphicsBuffer::
00060 begin_frame(FrameMode mode, Thread *current_thread) {
00061 begin_frame_spam(mode);
00062 if (_gsg == (GraphicsStateGuardian *)NULL) {
00063 return false;
00064 }
00065
00066 OSMesaGraphicsStateGuardian *mesagsg;
00067 DCAST_INTO_R(mesagsg, _gsg, false);
00068 OSMesaMakeCurrent(mesagsg->_context, _image.p(), _type,
00069 _x_size, _y_size);
00070
00071 mesagsg->reset_if_new();
00072
00073 if (mode == FM_render) {
00074 CDLockedReader cdata(_cycler);
00075 for (size_t i = 0; i != cdata->_textures.size(); ++i) {
00076 const RenderTexture &rt = cdata->_textures[i];
00077 RenderTextureMode rtm_mode = rt._rtm_mode;
00078 if (rtm_mode == RTM_bind_or_copy) {
00079 CDWriter cdataw(_cycler, cdata, false);
00080 nassertr(cdata->_textures.size() == cdataw->_textures.size(), false);
00081 cdataw->_textures[i]._rtm_mode = RTM_copy_texture;
00082 }
00083 }
00084 clear_cube_map_selection();
00085 }
00086 _gsg->set_current_properties(&get_fb_properties());
00087 return _gsg->begin_frame(current_thread);
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097 void OsMesaGraphicsBuffer::
00098 end_frame(FrameMode mode, Thread *current_thread) {
00099 end_frame_spam(mode);
00100 nassertv(_gsg != (GraphicsStateGuardian *)NULL);
00101
00102 if (mode == FM_render) {
00103 copy_to_textures();
00104 }
00105
00106 _gsg->end_frame(current_thread);
00107
00108 if (mode == FM_render) {
00109 trigger_flip();
00110 clear_cube_map_selection();
00111 }
00112 }
00113
00114
00115
00116
00117
00118
00119
00120 void OsMesaGraphicsBuffer::
00121 close_buffer() {
00122 _image.clear();
00123 _is_valid = false;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133 bool OsMesaGraphicsBuffer::
00134 open_buffer() {
00135 if (_gsg == 0) {
00136 _gsg = new OSMesaGraphicsStateGuardian(_engine, _pipe, NULL);
00137 }
00138
00139 _image = PTA_uchar::empty_array(_x_size * _y_size * 4);
00140 _is_valid = true;
00141
00142
00143 _fb_properties.clear();
00144 _fb_properties.set_rgb_color(1);
00145 _fb_properties.set_color_bits(24);
00146 _fb_properties.set_alpha_bits(8);
00147 _fb_properties.set_stencil_bits(8);
00148 _fb_properties.set_depth_bits(16);
00149 _fb_properties.set_accum_bits(8);
00150 _fb_properties.set_force_software(1);
00151
00152 return true;
00153 }