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