source: OGRE/trunk/ogrenew/OgreMain/src/OgreHardwarePixelBuffer.cpp @ 692

Revision 692, 7.2 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26#include "OgreHardwarePixelBuffer.h"
27#include "OgreImage.h"
28#include "OgreException.h"
29
30namespace Ogre
31{
32 
33    //-----------------------------------------------------------------------------   
34    HardwarePixelBuffer::HardwarePixelBuffer(size_t width, size_t height, size_t depth,
35            PixelFormat format,
36            HardwareBuffer::Usage usage, bool useSystemMemory, bool useShadowBuffer):
37        HardwareBuffer(usage, useSystemMemory, useShadowBuffer),
38        mWidth(width), mHeight(height), mDepth(depth),
39        mFormat(format)
40    {
41        // Default
42        mRowPitch = mWidth;
43        mSlicePitch = mHeight*mWidth;
44                mSizeInBytes = mHeight*mWidth*PixelUtil::getNumElemBytes(mFormat);
45    }
46   
47    //-----------------------------------------------------------------------------   
48    HardwarePixelBuffer::~HardwarePixelBuffer()
49    {
50    }
51   
52    //-----------------------------------------------------------------------------   
53    void* HardwarePixelBuffer::lock(size_t offset, size_t length, LockOptions options)
54    {
55        assert(!isLocked() && "Cannot lock this buffer, it is already locked!");
56        assert(offset == 0 && length == mSizeInBytes && "Cannot lock memory region, most lock box or entire buffer");
57       
58        Image::Box myBox(0, 0, 0, mWidth, mHeight, mDepth);
59        const PixelBox &rv = lock(myBox, options);
60        return rv.data;
61    }
62   
63    //-----------------------------------------------------------------------------   
64    const PixelBox& HardwarePixelBuffer::lock(const Image::Box& lockBox, LockOptions options)
65    {
66        if (mUseShadowBuffer)
67        {
68            if (options != HBL_READ_ONLY)
69            {
70                // we have to assume a read / write lock so we use the shadow buffer
71                // and tag for sync on unlock()
72                mShadowUpdated = true;
73            }
74
75            mCurrentLock = static_cast<HardwarePixelBuffer*>(mpShadowBuffer)->lock(lockBox, options);
76        }
77        else
78        {
79            // Lock the real buffer if there is no shadow buffer
80            mCurrentLock = lockImpl(lockBox, options);
81            mIsLocked = true;
82        }
83
84        return mCurrentLock;
85    }
86   
87    //-----------------------------------------------------------------------------   
88    const PixelBox& HardwarePixelBuffer::getCurrentLock()
89        {
90        assert(isLocked() && "Cannot get current lock: buffer not locked");
91       
92        return mCurrentLock;
93    }
94   
95    //-----------------------------------------------------------------------------   
96    /// Internal implementation of lock()
97    void* HardwarePixelBuffer::lockImpl(size_t offset, size_t length, LockOptions options)
98    {
99        OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "lockImpl(offset,length) is not valid for PixelBuffers and should never be called",
100            "HardwarePixelBuffer::lockImpl");
101    }
102
103    //-----------------------------------------------------------------------------   
104
105    void HardwarePixelBuffer::blit(const HardwarePixelBufferSharedPtr &src, const Image::Box &srcBox, const Image::Box &dstBox)
106        {
107                if(isLocked() || src->isLocked())
108                {
109                        OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
110                                "Source and destination buffer may not be locked!",
111                                "HardwarePixelBuffer::blit");
112                }
113                if(src.getPointer() == this)
114                {
115                        OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
116                "Source must not be the same object",
117                "HardwarePixelBuffer::blit" ) ;
118                }
119                const PixelBox &srclock = src->lock(srcBox, HBL_READ_ONLY);
120
121                LockOptions method = HBL_NORMAL;
122                if(dstBox.left == 0 && dstBox.top == 0 && dstBox.front == 0 &&
123                   dstBox.right == mWidth && dstBox.bottom == mHeight &&
124                   dstBox.back == mDepth)
125                        // Entire buffer -- we can discard the previous contents
126                        method = HBL_DISCARD;
127                       
128                const PixelBox &dstlock = lock(dstBox, method);
129                if(dstlock.getWidth() != srclock.getWidth() ||
130                dstlock.getHeight() != srclock.getHeight() ||
131                dstlock.getDepth() != srclock.getDepth())
132                {
133                        // Scaling desired
134                        Image::scale(srclock, dstlock);
135                }
136                else
137                {
138                        // No scaling needed
139                        PixelUtil::bulkPixelConversion(srclock, dstlock);
140                }
141
142                unlock();
143                src->unlock();
144        }
145    //-----------------------------------------------------------------------------       
146    void HardwarePixelBuffer::blit(const HardwarePixelBufferSharedPtr &src)
147    {
148        blit(src,
149            Box(0,0,0,src->getWidth(),src->getHeight(),src->getDepth()),
150            Box(0,0,0,mWidth,mHeight,mDepth)
151        );
152    }
153    //-----------------------------------------------------------------------------   
154        void HardwarePixelBuffer::readData(size_t offset, size_t length, void* pDest)
155        {
156                // TODO
157                OGRE_EXCEPT(Exception::UNIMPLEMENTED_FEATURE,
158                                "Reading a byte range is not implemented. Use blitToMemory.",
159                                "HardwarePixelBuffer::readData");
160        }
161        //-----------------------------------------------------------------------------   
162
163        void HardwarePixelBuffer::writeData(size_t offset, size_t length, const void* pSource,
164                        bool discardWholeBuffer)
165        {
166                // TODO
167                OGRE_EXCEPT(Exception::UNIMPLEMENTED_FEATURE,
168                                "Writing a byte range is not implemented. Use blitFromMemory.",
169                                "HardwarePixelBuffer::writeData");
170        }
171    //-----------------------------------------------------------------------------   
172   
173    RenderTexture *HardwarePixelBuffer::getRenderTarget(size_t)
174    {
175        OGRE_EXCEPT(Exception::UNIMPLEMENTED_FEATURE,
176                                "Not yet implemented for this rendersystem.",
177                                "HardwarePixelBuffer::getRenderTarget");
178    }
179
180    //-----------------------------------------------------------------------------   
181   
182    HardwarePixelBufferSharedPtr::HardwarePixelBufferSharedPtr(HardwarePixelBuffer* buf)
183        : SharedPtr<HardwarePixelBuffer>(buf)
184    {
185
186    }   
187        //-----------------------------------------------------------------------------   
188
189        void HardwarePixelBuffer::_clearSliceRTT(size_t zoffset)
190        {
191        }
192
193};
Note: See TracBrowser for help on using the repository browser.