[692] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | #include "OgreRoot.h"
|
---|
| 27 | #include "OgreLogManager.h"
|
---|
| 28 | #include "OgreRenderSystem.h"
|
---|
| 29 | #include "OgreImageCodec.h"
|
---|
| 30 | #include "OgreException.h"
|
---|
| 31 | #include "OgreStringConverter.h"
|
---|
| 32 | #include "OgreWin32RenderTexture.h"
|
---|
| 33 | #include "OgreWin32GLSupport.h"
|
---|
| 34 | #include "OgreWin32Context.h"
|
---|
| 35 |
|
---|
| 36 | namespace Ogre {
|
---|
| 37 |
|
---|
| 38 | Win32PBuffer::Win32PBuffer(PixelComponentType format, size_t width, size_t height):
|
---|
| 39 | GLPBuffer(format, width, height),
|
---|
| 40 | mContext(0)
|
---|
| 41 | {
|
---|
| 42 | createPBuffer();
|
---|
| 43 |
|
---|
| 44 | // Create context
|
---|
| 45 | mContext = new Win32Context(mHDC, mGlrc);
|
---|
| 46 | #if 0
|
---|
| 47 | if(mUseBind)
|
---|
| 48 | {
|
---|
| 49 | // Bind texture
|
---|
| 50 | glBindTexture(GL_TEXTURE_2D, static_cast<GLTexture*>(mTexture.get())->getGLID());
|
---|
| 51 | wglBindTexImageARB(mPBuffer, WGL_FRONT_LEFT_ARB);
|
---|
| 52 | }
|
---|
| 53 | #endif
|
---|
| 54 | }
|
---|
| 55 | Win32PBuffer::~Win32PBuffer()
|
---|
| 56 | {
|
---|
| 57 | #if 0
|
---|
| 58 | if(mUseBind)
|
---|
| 59 | {
|
---|
| 60 | // Unbind texture
|
---|
| 61 | glBindTexture(GL_TEXTURE_2D,
|
---|
| 62 | static_cast<GLTexture*>(mTexture.get())->getGLID());
|
---|
| 63 | glBindTexture(GL_TEXTURE_2D,
|
---|
| 64 | static_cast<GLTexture*>(mTexture.get())->getGLID());
|
---|
| 65 | wglReleaseTexImageARB(mPBuffer, WGL_FRONT_LEFT_ARB);
|
---|
| 66 | }
|
---|
| 67 | #endif
|
---|
| 68 | // Unregister and destroy mContext
|
---|
| 69 | delete mContext;
|
---|
| 70 |
|
---|
| 71 | // Destroy pbuffer
|
---|
| 72 | destroyPBuffer();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void Win32PBuffer::createPBuffer()
|
---|
| 76 | {
|
---|
| 77 |
|
---|
| 78 | // Process format
|
---|
| 79 | int bits=0;
|
---|
| 80 | bool isFloat=false;
|
---|
| 81 | bool hasAlpha=true;
|
---|
| 82 | switch(mFormat)
|
---|
| 83 | {
|
---|
| 84 | case PCT_BYTE:
|
---|
| 85 | bits=8; isFloat=false;
|
---|
| 86 | break;
|
---|
| 87 | case PCT_SHORT:
|
---|
| 88 | bits=16; isFloat=false;
|
---|
| 89 | break;
|
---|
| 90 | case PCT_FLOAT16:
|
---|
| 91 | bits=16; isFloat=true;
|
---|
| 92 | break;
|
---|
| 93 | case PCT_FLOAT32:
|
---|
| 94 | bits=32; isFloat=true;
|
---|
| 95 | break;
|
---|
| 96 | default: break;
|
---|
| 97 | };
|
---|
| 98 | LogManager::getSingleton().logMessage(
|
---|
| 99 | " Win32PBuffer::Creating PBuffer of format bits="+
|
---|
| 100 | StringConverter::toString(bits)+
|
---|
| 101 | " float="+StringConverter::toString(isFloat)
|
---|
| 102 | );
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | HDC old_hdc = wglGetCurrentDC();
|
---|
| 106 | HGLRC old_context = wglGetCurrentContext();
|
---|
| 107 |
|
---|
| 108 | // Bind to RGB or RGBA texture
|
---|
| 109 | int bttype = 0;
|
---|
| 110 | #if 0
|
---|
| 111 | if(mUseBind)
|
---|
| 112 | {
|
---|
| 113 | // Only provide bind type when actually binding
|
---|
| 114 | bttype = PixelUtil::hasAlpha(mInternalFormat)?
|
---|
| 115 | WGL_BIND_TO_TEXTURE_RGBA_ARB : WGL_BIND_TO_TEXTURE_RGB_ARB;
|
---|
| 116 | }
|
---|
| 117 | #endif
|
---|
| 118 | int texformat = hasAlpha?
|
---|
| 119 | WGL_TEXTURE_RGBA_ARB : WGL_TEXTURE_RGB_ARB;
|
---|
| 120 | // Make a float buffer?
|
---|
| 121 | int pixeltype = isFloat?
|
---|
| 122 | WGL_TYPE_RGBA_FLOAT_ARB: WGL_TYPE_RGBA_ARB;
|
---|
| 123 |
|
---|
| 124 | int attrib[] = {
|
---|
| 125 | WGL_RED_BITS_ARB,bits,
|
---|
| 126 | WGL_GREEN_BITS_ARB,bits,
|
---|
| 127 | WGL_BLUE_BITS_ARB,bits,
|
---|
| 128 | WGL_ALPHA_BITS_ARB,bits,
|
---|
| 129 | WGL_STENCIL_BITS_ARB,1,
|
---|
| 130 | WGL_DEPTH_BITS_ARB,15,
|
---|
| 131 | WGL_DRAW_TO_PBUFFER_ARB,true,
|
---|
| 132 | WGL_SUPPORT_OPENGL_ARB,true,
|
---|
| 133 | WGL_PIXEL_TYPE_ARB,pixeltype,
|
---|
| 134 | //WGL_DOUBLE_BUFFER_ARB,true,
|
---|
| 135 | //WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB, // Make sure it is accelerated
|
---|
| 136 | bttype,true, // must be last, as bttype can be zero
|
---|
| 137 | 0
|
---|
| 138 | };
|
---|
| 139 | int pattrib_default[] = {
|
---|
| 140 | 0
|
---|
| 141 | };
|
---|
| 142 | #if 0
|
---|
| 143 | int pattrib_bind[] = {
|
---|
| 144 | WGL_TEXTURE_FORMAT_ARB, texformat,
|
---|
| 145 | WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,
|
---|
| 146 | WGL_PBUFFER_LARGEST_ARB, true,
|
---|
| 147 | 0
|
---|
| 148 | };
|
---|
| 149 | #endif
|
---|
| 150 | int format;
|
---|
| 151 | unsigned int count;
|
---|
| 152 |
|
---|
| 153 | // Choose suitable pixel format
|
---|
| 154 | wglChoosePixelFormatARB(old_hdc,attrib,NULL,1,&format,&count);
|
---|
| 155 | if(count == 0)
|
---|
| 156 | OGRE_EXCEPT(0, "wglChoosePixelFormatARB() failed", " Win32PBuffer::createPBuffer");
|
---|
| 157 |
|
---|
| 158 | // Analyse pixel format
|
---|
| 159 | const int piAttributes[]={
|
---|
| 160 | WGL_RED_BITS_ARB,WGL_GREEN_BITS_ARB,WGL_BLUE_BITS_ARB,WGL_ALPHA_BITS_ARB,
|
---|
| 161 | WGL_DEPTH_BITS_ARB,WGL_STENCIL_BITS_ARB
|
---|
| 162 | };
|
---|
| 163 | int piValues[sizeof(piAttributes)/sizeof(const int)];
|
---|
| 164 | wglGetPixelFormatAttribivARB(old_hdc,format,0,sizeof(piAttributes)/sizeof(const int),piAttributes,piValues);
|
---|
| 165 |
|
---|
| 166 | StringUtil::StrStreamType str;
|
---|
| 167 | str << " Win32PBuffer::PBuffer -- Chosen pixel format rgba="
|
---|
| 168 | << piValues[0] << ","
|
---|
| 169 | << piValues[1] << ","
|
---|
| 170 | << piValues[2] << ","
|
---|
| 171 | << piValues[3]
|
---|
| 172 | << " depth=" << piValues[4]
|
---|
| 173 | << " stencil=" << piValues[5];
|
---|
| 174 | LogManager::getSingleton().logMessage(
|
---|
| 175 | LML_NORMAL, str.str());
|
---|
| 176 |
|
---|
| 177 | mPBuffer = wglCreatePbufferARB(old_hdc,format,mWidth,mHeight,pattrib_default);
|
---|
| 178 | if(!mPBuffer)
|
---|
| 179 | OGRE_EXCEPT(0, "wglCreatePbufferARB() failed", " Win32PBuffer::createPBuffer");
|
---|
| 180 |
|
---|
| 181 | mHDC = wglGetPbufferDCARB(mPBuffer);
|
---|
| 182 | if(!mHDC) {
|
---|
| 183 | wglDestroyPbufferARB(mPBuffer);
|
---|
| 184 | OGRE_EXCEPT(0, "wglGetPbufferDCARB() failed", " Win32PBuffer::createPBuffer");
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | mGlrc = wglCreateContext(mHDC);
|
---|
| 188 | if(!mGlrc) {
|
---|
| 189 | wglReleasePbufferDCARB(mPBuffer,mHDC);
|
---|
| 190 | wglDestroyPbufferARB(mPBuffer);
|
---|
| 191 | OGRE_EXCEPT(0, "wglCreateContext() failed", " Win32PBuffer::createPBuffer");
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | if(!wglShareLists(old_context,mGlrc)) {
|
---|
| 195 | wglDeleteContext(mGlrc);
|
---|
| 196 | wglReleasePbufferDCARB(mPBuffer,mHDC);
|
---|
| 197 | wglDestroyPbufferARB(mPBuffer);
|
---|
| 198 | OGRE_EXCEPT(0, "wglShareLists() failed", " Win32PBuffer::createPBuffer");
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | // Query real width and height
|
---|
| 202 | int iWidth, iHeight;
|
---|
| 203 | wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_WIDTH_ARB, &iWidth);
|
---|
| 204 | wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_HEIGHT_ARB, &iHeight);
|
---|
| 205 | mWidth = iWidth;
|
---|
| 206 | mHeight = iHeight;
|
---|
| 207 | str.str(StringUtil::BLANK);
|
---|
| 208 | str << "Win32RenderTexture::PBuffer created -- Real dimensions "
|
---|
| 209 | << mWidth << "x" << mHeight;
|
---|
| 210 | LogManager::getSingleton().logMessage(LML_NORMAL, str.str());
|
---|
| 211 | }
|
---|
| 212 | void Win32PBuffer::destroyPBuffer()
|
---|
| 213 | {
|
---|
| 214 | wglDeleteContext(mGlrc);
|
---|
| 215 | wglReleasePbufferDCARB(mPBuffer,mHDC);
|
---|
| 216 | wglDestroyPbufferARB(mPBuffer);
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | }
|
---|