root/OpenSceneGraph/trunk/src/osg/GraphicsThread.cpp @ 13041

Revision 13041, 3.7 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14
15#include <osg/GraphicsThread>
16#include <osg/GraphicsContext>
17#include <osg/GLObjects>
18#include <osg/Notify>
19
20using namespace osg;
21using namespace OpenThreads;
22
23GraphicsThread::GraphicsThread()
24{
25}
26
27void GraphicsThread::run()
28{
29    // make the graphics context current.
30    GraphicsContext* graphicsContext = dynamic_cast<GraphicsContext*>(_parent.get());
31    if (graphicsContext)
32    {
33        graphicsContext->makeCurrent();
34
35        graphicsContext->getState()->initializeExtensionProcs();
36    }
37
38    OperationThread::run();
39
40    // release operations before the thread stops working.
41    _operationQueue->releaseAllOperations();
42
43    if (graphicsContext)
44    {
45        graphicsContext->releaseContext();
46    }
47
48}
49
50void GraphicsOperation::operator () (Object* object)
51{
52    osg::GraphicsContext* context = dynamic_cast<osg::GraphicsContext*>(object);
53    if (context) operator() (context);
54}
55
56void SwapBuffersOperation::operator () (GraphicsContext* context)
57{
58    context->swapBuffersCallbackOrImplemenation();
59    context->clear();
60}
61
62void BarrierOperation::release()
63{
64    Barrier::release();
65}
66
67void BarrierOperation::operator () (Object* /*object*/)
68{
69    if (_preBlockOp!=NO_OPERATION)
70    {
71        if (_preBlockOp==GL_FLUSH) glFlush();
72        else if (_preBlockOp==GL_FINISH) glFinish();
73    }
74
75    block();
76}
77
78void ReleaseContext_Block_MakeCurrentOperation::release()
79{
80    Block::release();
81}
82
83
84void ReleaseContext_Block_MakeCurrentOperation::operator () (GraphicsContext* context)
85{
86    // release the graphics context.
87    context->releaseContext();
88
89    // reset the block so that it the next call to block()
90    reset();
91
92    // block this thread, until the block is released externally.
93    block();
94
95    // re acquire the graphics context.
96    context->makeCurrent();
97}
98
99
100BlockAndFlushOperation::BlockAndFlushOperation():
101    GraphicsOperation("Block",false)
102{
103    reset();
104}
105
106void BlockAndFlushOperation::release()
107{
108    Block::release();
109}
110
111void BlockAndFlushOperation::operator () (GraphicsContext*)
112{
113    glFlush();
114    Block::release();
115}
116
117FlushDeletedGLObjectsOperation::FlushDeletedGLObjectsOperation(double availableTime, bool keep):
118    GraphicsOperation("FlushDeletedGLObjectsOperation",keep),
119    _availableTime(availableTime)
120{
121}
122
123void FlushDeletedGLObjectsOperation::operator () (GraphicsContext* context)
124{
125    State* state = context->getState();
126    unsigned int contextID = state ? state->getContextID() : 0;
127    const FrameStamp* frameStamp = state ? state->getFrameStamp() : 0;
128    double currentTime = frameStamp ? frameStamp->getReferenceTime() : 0.0;
129    double availableTime = _availableTime;
130
131    flushDeletedGLObjects(contextID, currentTime, availableTime);
132}
133
134
135void RunOperations::operator () (osg::GraphicsContext* context)
136{
137    context->runOperations();
138}
139
140
141/////////////////////////////////////////////////////////////////////////////
142//
143// EndOfDynamicDrawBlock
144//
145EndOfDynamicDrawBlock::EndOfDynamicDrawBlock(unsigned int numberOfBlocks):
146    BlockCount(numberOfBlocks)
147{
148}
149
150void EndOfDynamicDrawBlock::completed(osg::State* /*state*/)
151{
152    BlockCount::completed();
153}
Note: See TracBrowser for help on using the browser.