Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/OgreWin32RenderTexture.cpp @ 5

Last change on this file since 5 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 6.8 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
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
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29
30#include "OgreRoot.h"
31#include "OgreLogManager.h"
32#include "OgreRenderSystem.h"
33#include "OgreImageCodec.h"
34#include "OgreException.h"
35#include "OgreStringConverter.h"
36#include "OgreWin32RenderTexture.h"
37#include "OgreWin32GLSupport.h"
38#include "OgreWin32Context.h"
39
40namespace Ogre {
41
42         Win32PBuffer::Win32PBuffer(PixelComponentType format, size_t width, size_t height):
43                GLPBuffer(format, width, height),
44        mContext(0)
45        {
46                createPBuffer();
47
48        // Create context
49        mContext = new Win32Context(mHDC, mGlrc);
50#if 0
51                if(mUseBind)
52                {
53                        // Bind texture
54                        glBindTexture(GL_TEXTURE_2D, static_cast<GLTexture*>(mTexture.get())->getGLID());
55                        wglBindTexImageARB(mPBuffer, WGL_FRONT_LEFT_ARB);
56                }
57#endif
58        }
59         Win32PBuffer::~Win32PBuffer() 
60        {
61#if 0
62                if(mUseBind)
63                {
64                        // Unbind texture
65                        glBindTexture(GL_TEXTURE_2D,
66                                static_cast<GLTexture*>(mTexture.get())->getGLID());
67                        glBindTexture(GL_TEXTURE_2D,
68                                static_cast<GLTexture*>(mTexture.get())->getGLID());
69                        wglReleaseTexImageARB(mPBuffer, WGL_FRONT_LEFT_ARB);
70                }
71#endif
72        // Unregister and destroy mContext
73        delete mContext;       
74           
75                // Destroy pbuffer
76                destroyPBuffer();
77        }
78       
79        void Win32PBuffer::createPBuffer() 
80        {
81
82        // Process format
83        int bits=0;
84        bool isFloat=false;
85#if 0
86                bool hasAlpha=true;
87#endif
88        switch(mFormat)
89        {
90            case PCT_BYTE:
91                bits=8; isFloat=false;
92                break;
93            case PCT_SHORT:
94                bits=16; isFloat=false;
95                break;
96            case PCT_FLOAT16:
97                bits=16; isFloat=true;
98                break;
99            case PCT_FLOAT32:
100                bits=32; isFloat=true;
101                break;
102            default: break;
103        };
104                LogManager::getSingleton().logMessage(
105                        " Win32PBuffer::Creating PBuffer of format bits="+
106                        StringConverter::toString(bits)+
107                        " float="+StringConverter::toString(isFloat)
108            );
109
110
111                HDC old_hdc = wglGetCurrentDC();
112                HGLRC old_context = wglGetCurrentContext();
113
114                // Bind to RGB or RGBA texture
115                int bttype = 0;
116#if 0
117                if(mUseBind)
118                {
119                        // Only provide bind type when actually binding
120                        bttype = PixelUtil::hasAlpha(mInternalFormat)?
121                                WGL_BIND_TO_TEXTURE_RGBA_ARB : WGL_BIND_TO_TEXTURE_RGB_ARB;
122                }
123                int texformat = hasAlpha?
124                        WGL_TEXTURE_RGBA_ARB : WGL_TEXTURE_RGB_ARB;
125#endif
126                // Make a float buffer?
127        int pixeltype = isFloat?
128                        WGL_TYPE_RGBA_FLOAT_ARB: WGL_TYPE_RGBA_ARB;
129               
130                int attrib[] = {
131                        WGL_RED_BITS_ARB,bits,
132                        WGL_GREEN_BITS_ARB,bits,
133                        WGL_BLUE_BITS_ARB,bits,
134                        WGL_ALPHA_BITS_ARB,bits,
135                        WGL_STENCIL_BITS_ARB,1,
136                        WGL_DEPTH_BITS_ARB,15,
137                        WGL_DRAW_TO_PBUFFER_ARB,true,
138                        WGL_SUPPORT_OPENGL_ARB,true,
139                        WGL_PIXEL_TYPE_ARB,pixeltype,
140                        //WGL_DOUBLE_BUFFER_ARB,true,
141                        //WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB, // Make sure it is accelerated
142                        bttype,true, // must be last, as bttype can be zero
143                        0
144                };
145                int pattrib_default[] = { 
146                        0
147                };
148#if 0
149                int pattrib_bind[] = {
150                        WGL_TEXTURE_FORMAT_ARB, texformat,
151                        WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
152                        WGL_PBUFFER_LARGEST_ARB, true,
153                        0
154                };
155#endif
156                int format;
157                unsigned int count;
158
159                // Choose suitable pixel format
160                wglChoosePixelFormatARB(old_hdc,attrib,NULL,1,&format,&count);
161                if(count == 0)
162                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglChoosePixelFormatARB() failed", " Win32PBuffer::createPBuffer");
163
164                // Analyse pixel format
165                const int piAttributes[]={
166                                WGL_RED_BITS_ARB,WGL_GREEN_BITS_ARB,WGL_BLUE_BITS_ARB,WGL_ALPHA_BITS_ARB,
167                                WGL_DEPTH_BITS_ARB,WGL_STENCIL_BITS_ARB
168                };
169                int piValues[sizeof(piAttributes)/sizeof(const int)];
170                wglGetPixelFormatAttribivARB(old_hdc,format,0,sizeof(piAttributes)/sizeof(const int),piAttributes,piValues);
171
172        StringUtil::StrStreamType str;
173        str << " Win32PBuffer::PBuffer -- Chosen pixel format rgba="
174            << piValues[0] << "," 
175            << piValues[1] << "," 
176            << piValues[2] << "," 
177            << piValues[3] 
178            << " depth=" << piValues[4]
179            << " stencil=" << piValues[5];
180                LogManager::getSingleton().logMessage(
181                        LML_NORMAL, str.str());
182
183                mPBuffer = wglCreatePbufferARB(old_hdc,format,mWidth,mHeight,pattrib_default);
184                if(!mPBuffer)
185                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglCreatePbufferARB() failed", " Win32PBuffer::createPBuffer");
186
187                mHDC = wglGetPbufferDCARB(mPBuffer);
188                if(!mHDC) {
189                        wglDestroyPbufferARB(mPBuffer);
190                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglGetPbufferDCARB() failed", " Win32PBuffer::createPBuffer");
191                }
192                       
193                mGlrc = wglCreateContext(mHDC);
194                if(!mGlrc) {
195                        wglReleasePbufferDCARB(mPBuffer,mHDC);
196                        wglDestroyPbufferARB(mPBuffer);
197                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglCreateContext() failed", " Win32PBuffer::createPBuffer");
198                }
199
200                if(!wglShareLists(old_context,mGlrc)) {
201                        wglDeleteContext(mGlrc);
202                        wglReleasePbufferDCARB(mPBuffer,mHDC);
203                        wglDestroyPbufferARB(mPBuffer);
204                        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "wglShareLists() failed", " Win32PBuffer::createPBuffer");
205                }
206                               
207                // Query real width and height
208                int iWidth, iHeight;
209                wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_WIDTH_ARB, &iWidth);
210                wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_HEIGHT_ARB, &iHeight);
211                mWidth = iWidth; 
212                mHeight = iHeight;
213                str.str(StringUtil::BLANK);
214        str << "Win32RenderTexture::PBuffer created -- Real dimensions "
215            << mWidth << "x" << mHeight;
216                LogManager::getSingleton().logMessage(LML_NORMAL, str.str());
217        }
218        void Win32PBuffer::destroyPBuffer() 
219        {
220                wglDeleteContext(mGlrc);
221                wglReleasePbufferDCARB(mPBuffer,mHDC);
222                wglDestroyPbufferARB(mPBuffer);
223        }
224
225
226}
Note: See TracBrowser for help on using the repository browser.