| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osg/GLExtensions> |
|---|
| 15 | #include <osg/TextureRectangle> |
|---|
| 16 | #include <osg/ImageSequence> |
|---|
| 17 | #include <osg/State> |
|---|
| 18 | #include <osg/GLU> |
|---|
| 19 | #include <osg/Notify> |
|---|
| 20 | |
|---|
| 21 | #include <osg/Timer> |
|---|
| 22 | |
|---|
| 23 | #ifndef GL_UNPACK_CLIENT_STORAGE_APPLE |
|---|
| 24 | #define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 |
|---|
| 25 | #endif |
|---|
| 26 | |
|---|
| 27 | #ifndef GL_APPLE_vertex_array_range |
|---|
| 28 | #define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D |
|---|
| 29 | #define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E |
|---|
| 30 | #define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F |
|---|
| 31 | #define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521 |
|---|
| 32 | #define GL_STORAGE_CACHED_APPLE 0x85BE |
|---|
| 33 | #define GL_STORAGE_SHARED_APPLE 0x85BF |
|---|
| 34 | #endif |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | using namespace osg; |
|---|
| 39 | |
|---|
| 40 | TextureRectangle::TextureRectangle(): |
|---|
| 41 | _textureWidth(0), |
|---|
| 42 | _textureHeight(0) |
|---|
| 43 | { |
|---|
| 44 | setWrap(WRAP_S, CLAMP); |
|---|
| 45 | setWrap(WRAP_T, CLAMP); |
|---|
| 46 | |
|---|
| 47 | setFilter(MIN_FILTER, LINEAR); |
|---|
| 48 | setFilter(MAG_FILTER, LINEAR); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | TextureRectangle::TextureRectangle(Image* image): |
|---|
| 52 | _textureWidth(0), |
|---|
| 53 | _textureHeight(0) |
|---|
| 54 | { |
|---|
| 55 | setWrap(WRAP_S, CLAMP); |
|---|
| 56 | setWrap(WRAP_T, CLAMP); |
|---|
| 57 | |
|---|
| 58 | setFilter(MIN_FILTER, LINEAR); |
|---|
| 59 | setFilter(MAG_FILTER, LINEAR); |
|---|
| 60 | |
|---|
| 61 | setImage(image); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | TextureRectangle::TextureRectangle(const TextureRectangle& text,const CopyOp& copyop): |
|---|
| 65 | Texture(text,copyop), |
|---|
| 66 | _image(copyop(text._image.get())), |
|---|
| 67 | _textureWidth(text._textureWidth), |
|---|
| 68 | _textureHeight(text._textureHeight), |
|---|
| 69 | _subloadCallback(text._subloadCallback) |
|---|
| 70 | { |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | TextureRectangle::~TextureRectangle() |
|---|
| 74 | { |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | int TextureRectangle::compare(const StateAttribute& sa) const |
|---|
| 78 | { |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | COMPARE_StateAttribute_Types(TextureRectangle,sa) |
|---|
| 82 | |
|---|
| 83 | if (_image!=rhs._image) |
|---|
| 84 | { |
|---|
| 85 | if (_image.valid()) |
|---|
| 86 | { |
|---|
| 87 | if (rhs._image.valid()) |
|---|
| 88 | { |
|---|
| 89 | int result = _image->compare(*rhs._image); |
|---|
| 90 | if (result!=0) return result; |
|---|
| 91 | } |
|---|
| 92 | else |
|---|
| 93 | { |
|---|
| 94 | return 1; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | else if (rhs._image.valid()) |
|---|
| 98 | { |
|---|
| 99 | return -1; |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | if (!_image && !rhs._image) |
|---|
| 104 | { |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | int result = compareTextureObjects(rhs); |
|---|
| 111 | if (result!=0) return result; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | int result = compareTexture(rhs); |
|---|
| 115 | if (result!=0) return result; |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | COMPARE_StateAttribute_Parameter(_textureWidth) |
|---|
| 119 | COMPARE_StateAttribute_Parameter(_textureHeight) |
|---|
| 120 | COMPARE_StateAttribute_Parameter(_subloadCallback) |
|---|
| 121 | |
|---|
| 122 | return 0; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | void TextureRectangle::setImage(Image* image) |
|---|
| 126 | { |
|---|
| 127 | if (_image == image) return; |
|---|
| 128 | |
|---|
| 129 | if (dynamic_cast<osg::ImageSequence*>(_image.get())) |
|---|
| 130 | { |
|---|
| 131 | setUpdateCallback(0); |
|---|
| 132 | setDataVariance(osg::Object::STATIC); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | dirtyTextureObject(); |
|---|
| 137 | |
|---|
| 138 | _image = image; |
|---|
| 139 | |
|---|
| 140 | if (dynamic_cast<osg::ImageSequence*>(_image.get())) |
|---|
| 141 | { |
|---|
| 142 | setUpdateCallback(new ImageSequence::UpdateCallback()); |
|---|
| 143 | setDataVariance(osg::Object::DYNAMIC); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | void TextureRectangle::apply(State& state) const |
|---|
| 149 | { |
|---|
| 150 | static bool s_rectangleSupported = |
|---|
| 151 | OSG_GL3_FEATURES || |
|---|
| 152 | isGLExtensionSupported(state.getContextID(),"GL_ARB_texture_rectangle") || |
|---|
| 153 | isGLExtensionSupported(state.getContextID(),"GL_EXT_texture_rectangle") || |
|---|
| 154 | isGLExtensionSupported(state.getContextID(),"GL_NV_texture_rectangle"); |
|---|
| 155 | |
|---|
| 156 | if (!s_rectangleSupported) |
|---|
| 157 | { |
|---|
| 158 | notify(WARN)<<"Warning: TextureRectangle::apply(..) failed, texture rectangle is not support by your OpenGL drivers."<<std::endl; |
|---|
| 159 | return; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | const unsigned int contextID = state.getContextID(); |
|---|
| 165 | |
|---|
| 166 | Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID).get(); |
|---|
| 167 | ElapsedTime elapsedTime(&(tom->getApplyTime())); |
|---|
| 168 | tom->getNumberApplied()++; |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | TextureObject* textureObject = getTextureObject(contextID); |
|---|
| 173 | |
|---|
| 174 | if (textureObject) |
|---|
| 175 | { |
|---|
| 176 | if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) |
|---|
| 177 | { |
|---|
| 178 | |
|---|
| 179 | computeInternalFormat(); |
|---|
| 180 | |
|---|
| 181 | GLsizei new_width, new_height, new_numMipmapLevels; |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | computeRequiredTextureDimensions(state, *_image, new_width, new_height, new_numMipmapLevels); |
|---|
| 185 | |
|---|
| 186 | if (!textureObject->match(GL_TEXTURE_RECTANGLE, new_numMipmapLevels, _internalFormat, new_width, new_height, 1, _borderWidth)) |
|---|
| 187 | { |
|---|
| 188 | Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get()); |
|---|
| 189 | _textureObjectBuffer[contextID] = 0; |
|---|
| 190 | textureObject = 0; |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | if (textureObject) |
|---|
| 196 | { |
|---|
| 197 | textureObject->bind(); |
|---|
| 198 | |
|---|
| 199 | if (getTextureParameterDirty(state.getContextID())) |
|---|
| 200 | applyTexParameters(GL_TEXTURE_RECTANGLE, state); |
|---|
| 201 | |
|---|
| 202 | if (_subloadCallback.valid()) |
|---|
| 203 | { |
|---|
| 204 | _subloadCallback->subload(*this, state); |
|---|
| 205 | } |
|---|
| 206 | else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) |
|---|
| 207 | { |
|---|
| 208 | applyTexImage_subload(GL_TEXTURE_RECTANGLE, _image.get(), state, _textureWidth, _textureHeight, _internalFormat); |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | getModifiedCount(contextID) = _image->getModifiedCount(); |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | else if (_subloadCallback.valid()) |
|---|
| 215 | { |
|---|
| 216 | |
|---|
| 217 | _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_RECTANGLE); |
|---|
| 218 | |
|---|
| 219 | textureObject->bind(); |
|---|
| 220 | |
|---|
| 221 | applyTexParameters(GL_TEXTURE_RECTANGLE, state); |
|---|
| 222 | |
|---|
| 223 | _subloadCallback->load(*this, state); |
|---|
| 224 | |
|---|
| 225 | textureObject->setAllocated(1,_internalFormat,_textureWidth,_textureHeight,1,0); |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | } |
|---|
| 233 | else if (_image.valid() && _image->data()) |
|---|
| 234 | { |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | osg::ref_ptr<osg::Image> image = _image; |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | computeInternalFormat(); |
|---|
| 242 | |
|---|
| 243 | _textureWidth = image->s(); |
|---|
| 244 | _textureHeight = image->t(); |
|---|
| 245 | |
|---|
| 246 | _textureObjectBuffer[contextID] = textureObject = generateTextureObject( |
|---|
| 247 | this, contextID,GL_TEXTURE_RECTANGLE,1,_internalFormat,_textureWidth,_textureHeight,1,0); |
|---|
| 248 | |
|---|
| 249 | textureObject->bind(); |
|---|
| 250 | |
|---|
| 251 | applyTexParameters(GL_TEXTURE_RECTANGLE, state); |
|---|
| 252 | |
|---|
| 253 | if (textureObject->isAllocated()) |
|---|
| 254 | { |
|---|
| 255 | applyTexImage_subload(GL_TEXTURE_RECTANGLE, _image.get(), state, _textureWidth, _textureHeight, _internalFormat); |
|---|
| 256 | } |
|---|
| 257 | else |
|---|
| 258 | { |
|---|
| 259 | applyTexImage_load(GL_TEXTURE_RECTANGLE, _image.get(), state, _textureWidth, _textureHeight); |
|---|
| 260 | textureObject->setAllocated(true); |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | if (state.getMaxTexturePoolSize()==0 && _unrefImageDataAfterApply && areAllTextureObjectsLoaded() && _image->getDataVariance()==STATIC) |
|---|
| 264 | { |
|---|
| 265 | TextureRectangle* non_const_this = const_cast<TextureRectangle*>(this); |
|---|
| 266 | non_const_this->_image = 0; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | } |
|---|
| 270 | else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) |
|---|
| 271 | { |
|---|
| 272 | _textureObjectBuffer[contextID] = textureObject = generateTextureObject( |
|---|
| 273 | this, contextID,GL_TEXTURE_RECTANGLE,0,_internalFormat,_textureWidth,_textureHeight,1,0); |
|---|
| 274 | |
|---|
| 275 | textureObject->bind(); |
|---|
| 276 | |
|---|
| 277 | applyTexParameters(GL_TEXTURE_RECTANGLE,state); |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | glTexImage2D( GL_TEXTURE_RECTANGLE, 0, _internalFormat, |
|---|
| 281 | _textureWidth, _textureHeight, _borderWidth, |
|---|
| 282 | _sourceFormat ? _sourceFormat : _internalFormat, |
|---|
| 283 | _sourceType ? _sourceType : GL_UNSIGNED_BYTE, |
|---|
| 284 | 0); |
|---|
| 285 | |
|---|
| 286 | if (_readPBuffer.valid()) |
|---|
| 287 | { |
|---|
| 288 | _readPBuffer->bindPBufferToTexture(GL_FRONT); |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | } |
|---|
| 292 | else |
|---|
| 293 | { |
|---|
| 294 | glBindTexture(GL_TEXTURE_RECTANGLE, 0); |
|---|
| 295 | } |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | void TextureRectangle::applyTexImage_load(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const |
|---|
| 299 | { |
|---|
| 300 | |
|---|
| 301 | if (!image || !image->data()) |
|---|
| 302 | return; |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | const unsigned int contextID = state.getContextID(); |
|---|
| 307 | const Extensions* extensions = getExtensions(contextID,true); |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | getModifiedCount(contextID) = image->getModifiedCount(); |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | computeInternalFormat(); |
|---|
| 314 | |
|---|
| 315 | glPixelStorei(GL_UNPACK_ALIGNMENT, image->getPacking()); |
|---|
| 316 | |
|---|
| 317 | bool useClientStorage = extensions->isClientStorageSupported() && getClientStorageHint(); |
|---|
| 318 | if (useClientStorage) |
|---|
| 319 | { |
|---|
| 320 | glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE,GL_TRUE); |
|---|
| 321 | |
|---|
| 322 | #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) |
|---|
| 323 | glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_PRIORITY,0.0f); |
|---|
| 324 | #endif |
|---|
| 325 | |
|---|
| 326 | #ifdef GL_TEXTURE_STORAGE_HINT_APPLE |
|---|
| 327 | glTexParameteri(target, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE); |
|---|
| 328 | #endif |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | const unsigned char* dataPtr = image->data(); |
|---|
| 332 | GLBufferObject* pbo = image->getOrCreateGLBufferObject(contextID); |
|---|
| 333 | if (pbo) |
|---|
| 334 | { |
|---|
| 335 | state.bindPixelBufferObject(pbo); |
|---|
| 336 | dataPtr = reinterpret_cast<unsigned char*>(pbo->getOffset(image->getBufferIndex())); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | if(isCompressedInternalFormat(_internalFormat) && extensions->isCompressedTexImage2DSupported()) |
|---|
| 340 | { |
|---|
| 341 | extensions->glCompressedTexImage2D(target, 0, _internalFormat, |
|---|
| 342 | image->s(), image->t(), 0, |
|---|
| 343 | image->getImageSizeInBytes(), |
|---|
| 344 | dataPtr); |
|---|
| 345 | } |
|---|
| 346 | else |
|---|
| 347 | { |
|---|
| 348 | glTexImage2D(target, 0, _internalFormat, |
|---|
| 349 | image->s(), image->t(), 0, |
|---|
| 350 | (GLenum)image->getPixelFormat(), |
|---|
| 351 | (GLenum)image->getDataType(), |
|---|
| 352 | dataPtr ); |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | if (pbo) |
|---|
| 357 | { |
|---|
| 358 | state.unbindPixelBufferObject(); |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | inwidth = image->s(); |
|---|
| 362 | inheight = image->t(); |
|---|
| 363 | |
|---|
| 364 | if (useClientStorage) |
|---|
| 365 | { |
|---|
| 366 | glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE,GL_FALSE); |
|---|
| 367 | } |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | void TextureRectangle::applyTexImage_subload(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLint& inInternalFormat) const |
|---|
| 371 | { |
|---|
| 372 | |
|---|
| 373 | if (!image || !image->data()) |
|---|
| 374 | return; |
|---|
| 375 | |
|---|
| 376 | if (image->s()!=inwidth || image->t()!=inheight || image->getInternalTextureFormat()!=inInternalFormat) |
|---|
| 377 | { |
|---|
| 378 | applyTexImage_load(target, image, state, inwidth, inheight); |
|---|
| 379 | return; |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | const unsigned int contextID = state.getContextID(); |
|---|
| 386 | const Extensions* extensions = getExtensions(contextID,true); |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | getModifiedCount(contextID) = image->getModifiedCount(); |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | computeInternalFormat(); |
|---|
| 394 | |
|---|
| 395 | glPixelStorei(GL_UNPACK_ALIGNMENT, image->getPacking()); |
|---|
| 396 | |
|---|
| 397 | #ifdef DO_TIMING |
|---|
| 398 | osg::Timer_t start_tick = osg::Timer::instance()->tick(); |
|---|
| 399 | osg::notify(osg::NOTICE)<<"TextureRectangle::apply pixelFormat = "<<std::hex<<image->getPixelFormat()<<std::dec<<std::endl; |
|---|
| 400 | #endif |
|---|
| 401 | const unsigned char* dataPtr = image->data(); |
|---|
| 402 | GLBufferObject* pbo = image->getOrCreateGLBufferObject(contextID); |
|---|
| 403 | if (pbo) |
|---|
| 404 | { |
|---|
| 405 | state.bindPixelBufferObject(pbo); |
|---|
| 406 | dataPtr = reinterpret_cast<unsigned char*>(pbo->getOffset(image->getBufferIndex())); |
|---|
| 407 | #ifdef DO_TIMING |
|---|
| 408 | osg::notify(osg::NOTICE)<<"after PBO "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; |
|---|
| 409 | #endif |
|---|
| 410 | } |
|---|
| 411 | else |
|---|
| 412 | { |
|---|
| 413 | osg::notify(osg::NOTICE)<<" no PixelBufferObject "<<image->getBufferObject()<<", "<<image->getPixelBufferObject()<<" pbo="<<pbo<<std::endl; |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | if(isCompressedInternalFormat(_internalFormat) && extensions->isCompressedTexSubImage2DSupported()) |
|---|
| 418 | { |
|---|
| 419 | extensions->glCompressedTexSubImage2D(target, 0, |
|---|
| 420 | 0,0, |
|---|
| 421 | image->s(), image->t(), |
|---|
| 422 | (GLenum)image->getPixelFormat(), |
|---|
| 423 | (GLenum)image->getDataType(), |
|---|
| 424 | dataPtr); |
|---|
| 425 | } |
|---|
| 426 | else |
|---|
| 427 | { |
|---|
| 428 | glTexSubImage2D(target, 0, |
|---|
| 429 | 0,0, |
|---|
| 430 | image->s(), image->t(), |
|---|
| 431 | (GLenum)image->getPixelFormat(), |
|---|
| 432 | (GLenum)image->getDataType(), |
|---|
| 433 | dataPtr); |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | if (pbo) |
|---|
| 437 | { |
|---|
| 438 | state.unbindPixelBufferObject(); |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | #ifdef DO_TIMING |
|---|
| 442 | osg::notify(osg::NOTICE)<<"glTexSubImage2D "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; |
|---|
| 443 | #endif |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | void TextureRectangle::computeInternalFormat() const |
|---|
| 447 | { |
|---|
| 448 | if (_image.valid()) computeInternalFormatWithImage(*_image); |
|---|
| 449 | else computeInternalFormatType(); |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | void TextureRectangle::copyTexImage2D(State& state, int x, int y, int width, int height ) |
|---|
| 453 | { |
|---|
| 454 | const unsigned int contextID = state.getContextID(); |
|---|
| 455 | |
|---|
| 456 | if (_internalFormat==0) _internalFormat=GL_RGBA; |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | TextureObject* textureObject = getTextureObject(contextID); |
|---|
| 460 | |
|---|
| 461 | if (textureObject) |
|---|
| 462 | { |
|---|
| 463 | if (width==(int)_textureWidth && height==(int)_textureHeight) |
|---|
| 464 | { |
|---|
| 465 | |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | copyTexSubImage2D(state,0 ,0, x, y, width, height); |
|---|
| 470 | return; |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | |
|---|
| 475 | dirtyTextureObject(); |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | _image = NULL; |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_RECTANGLE); |
|---|
| 489 | |
|---|
| 490 | textureObject->bind(); |
|---|
| 491 | |
|---|
| 492 | applyTexParameters(GL_TEXTURE_RECTANGLE,state); |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | glCopyTexImage2D( GL_TEXTURE_RECTANGLE, 0, _internalFormat, x, y, width, height, 0 ); |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | _textureWidth = width; |
|---|
| 520 | _textureHeight = height; |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | textureObject->setAllocated(1,_internalFormat,_textureWidth,_textureHeight,1,0); |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | void TextureRectangle::copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height ) |
|---|
| 531 | { |
|---|
| 532 | const unsigned int contextID = state.getContextID(); |
|---|
| 533 | |
|---|
| 534 | if (_internalFormat==0) _internalFormat=GL_RGBA; |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | TextureObject* textureObject = getTextureObject(contextID); |
|---|
| 538 | |
|---|
| 539 | if (textureObject) |
|---|
| 540 | { |
|---|
| 541 | |
|---|
| 542 | textureObject->bind(); |
|---|
| 543 | |
|---|
| 544 | applyTexParameters(GL_TEXTURE_RECTANGLE,state); |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | glCopyTexSubImage2D( GL_TEXTURE_RECTANGLE, 0, xoffset, yoffset, x, y, width, height); |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); |
|---|
| 571 | |
|---|
| 572 | } |
|---|
| 573 | else |
|---|
| 574 | { |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | copyTexImage2D(state,x,y,width,height); |
|---|
| 578 | } |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | void TextureRectangle::allocateMipmap(State&) const |
|---|
| 582 | { |
|---|
| 583 | osg::notify(osg::NOTICE)<<"Warning: TextureRectangle::allocateMipmap(State&) called eroneously, GL_TEXTURE_RECTANGLE does not support mipmapping."<<std::endl; |
|---|
| 584 | } |
|---|