Changeset View
Changeset View
Standalone View
Standalone View
libkwineffects/kwingltexture.cpp
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Line(s) | 195 | { | |||
---|---|---|---|---|---|
234 | unbind(); | 234 | unbind(); | ||
235 | } | 235 | } | ||
236 | 236 | | |||
237 | GLTexture::GLTexture(GLenum internalFormat, const QSize &size, int levels) | 237 | GLTexture::GLTexture(GLenum internalFormat, const QSize &size, int levels) | ||
238 | : GLTexture(internalFormat, size.width(), size.height(), levels) | 238 | : GLTexture(internalFormat, size.width(), size.height(), levels) | ||
239 | { | 239 | { | ||
240 | } | 240 | } | ||
241 | 241 | | |||
242 | GLTexture::GLTexture(GLuint textureId, GLenum internalFormat, const QSize &size, int levels) | ||||
243 | : d_ptr(new GLTexturePrivate()) | ||||
244 | { | ||||
245 | Q_D(GLTexture); | ||||
246 | d->m_foreign = true; | ||||
247 | d->m_texture = textureId; | ||||
248 | d->m_target = GL_TEXTURE_2D; | ||||
249 | d->m_scale.setWidth(1.0 / size.width()); | ||||
250 | d->m_scale.setHeight(1.0 / size.height()); | ||||
251 | d->m_size = size; | ||||
252 | d->m_canUseMipmaps = levels > 1; | ||||
253 | d->m_mipLevels = levels; | ||||
254 | d->m_filter = levels > 1 ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST; | ||||
255 | d->m_internalFormat = internalFormat; | ||||
256 | | ||||
257 | d->updateMatrix(); | ||||
258 | } | ||||
259 | | ||||
242 | GLTexture::~GLTexture() | 260 | GLTexture::~GLTexture() | ||
243 | { | 261 | { | ||
244 | } | 262 | } | ||
245 | 263 | | |||
246 | GLTexture& GLTexture::operator = (const GLTexture& tex) | 264 | GLTexture& GLTexture::operator = (const GLTexture& tex) | ||
247 | { | 265 | { | ||
248 | d_ptr = tex.d_ptr; | 266 | d_ptr = tex.d_ptr; | ||
249 | return *this; | 267 | return *this; | ||
250 | } | 268 | } | ||
251 | 269 | | |||
252 | GLTexturePrivate::GLTexturePrivate() | 270 | GLTexturePrivate::GLTexturePrivate() | ||
253 | : m_texture(0) | 271 | : m_texture(0) | ||
254 | , m_target(0) | 272 | , m_target(0) | ||
255 | , m_internalFormat(0) | 273 | , m_internalFormat(0) | ||
256 | , m_filter(GL_NEAREST) | 274 | , m_filter(GL_NEAREST) | ||
257 | , m_wrapMode(GL_REPEAT) | 275 | , m_wrapMode(GL_REPEAT) | ||
258 | , m_yInverted(false) | 276 | , m_yInverted(false) | ||
259 | , m_canUseMipmaps(false) | 277 | , m_canUseMipmaps(false) | ||
260 | , m_markedDirty(false) | 278 | , m_markedDirty(false) | ||
261 | , m_filterChanged(true) | 279 | , m_filterChanged(true) | ||
262 | , m_wrapModeChanged(false) | 280 | , m_wrapModeChanged(false) | ||
263 | , m_immutable(false) | 281 | , m_immutable(false) | ||
282 | , m_foreign(false) | ||||
264 | , m_mipLevels(1) | 283 | , m_mipLevels(1) | ||
265 | , m_unnormalizeActive(0) | 284 | , m_unnormalizeActive(0) | ||
266 | , m_normalizeActive(0) | 285 | , m_normalizeActive(0) | ||
267 | , m_vbo(nullptr) | 286 | , m_vbo(nullptr) | ||
268 | { | 287 | { | ||
269 | ++s_textureObjectCounter; | 288 | ++s_textureObjectCounter; | ||
270 | } | 289 | } | ||
271 | 290 | | |||
272 | GLTexturePrivate::~GLTexturePrivate() | 291 | GLTexturePrivate::~GLTexturePrivate() | ||
273 | { | 292 | { | ||
274 | delete m_vbo; | 293 | delete m_vbo; | ||
275 | if (m_texture != 0) { | 294 | if (m_texture != 0 && !m_foreign) { | ||
276 | glDeleteTextures(1, &m_texture); | 295 | glDeleteTextures(1, &m_texture); | ||
277 | } | 296 | } | ||
278 | // Delete the FBO if this is the last Texture | 297 | // Delete the FBO if this is the last Texture | ||
279 | if (--s_textureObjectCounter == 0 && s_fbo) { | 298 | if (--s_textureObjectCounter == 0 && s_fbo) { | ||
280 | glDeleteFramebuffers(1, &s_fbo); | 299 | glDeleteFramebuffers(1, &s_fbo); | ||
281 | s_fbo = 0; | 300 | s_fbo = 0; | ||
282 | } | 301 | } | ||
283 | } | 302 | } | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
328 | } | 347 | } | ||
329 | 348 | | |||
330 | void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &src) | 349 | void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &src) | ||
331 | { | 350 | { | ||
332 | if (image.isNull() || isNull()) | 351 | if (image.isNull() || isNull()) | ||
333 | return; | 352 | return; | ||
334 | 353 | | |||
335 | Q_D(GLTexture); | 354 | Q_D(GLTexture); | ||
355 | Q_ASSERT(!d->m_foreign); | ||||
336 | 356 | | |||
337 | bool useUnpack = !src.isNull() && d->s_supportsUnpack && d->s_supportsARGB32 && image.format() == QImage::Format_ARGB32_Premultiplied; | 357 | bool useUnpack = !src.isNull() && d->s_supportsUnpack && d->s_supportsARGB32 && image.format() == QImage::Format_ARGB32_Premultiplied; | ||
338 | 358 | | |||
339 | int width = image.width(); | 359 | int width = image.width(); | ||
340 | int height = image.height(); | 360 | int height = image.height(); | ||
341 | QImage tmpImage; | 361 | QImage tmpImage; | ||
342 | 362 | | |||
343 | if (!src.isNull()) { | 363 | if (!src.isNull()) { | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | |||||
505 | { | 525 | { | ||
506 | Q_D(const GLTexture); | 526 | Q_D(const GLTexture); | ||
507 | return d->m_internalFormat; | 527 | return d->m_internalFormat; | ||
508 | } | 528 | } | ||
509 | 529 | | |||
510 | void GLTexture::clear() | 530 | void GLTexture::clear() | ||
511 | { | 531 | { | ||
512 | Q_D(GLTexture); | 532 | Q_D(GLTexture); | ||
533 | Q_ASSERT(!d->m_foreign); | ||||
513 | if (!GLTexturePrivate::s_fbo && GLRenderTarget::supported() && | 534 | if (!GLTexturePrivate::s_fbo && GLRenderTarget::supported() && | ||
514 | GLPlatform::instance()->driver() != Driver_Catalyst) // fail. -> bug #323065 | 535 | GLPlatform::instance()->driver() != Driver_Catalyst) // fail. -> bug #323065 | ||
515 | glGenFramebuffers(1, &GLTexturePrivate::s_fbo); | 536 | glGenFramebuffers(1, &GLTexturePrivate::s_fbo); | ||
516 | 537 | | |||
517 | if (GLTexturePrivate::s_fbo) { | 538 | if (GLTexturePrivate::s_fbo) { | ||
518 | // Clear the texture | 539 | // Clear the texture | ||
519 | glBindFramebuffer(GL_FRAMEBUFFER, GLTexturePrivate::s_fbo); | 540 | glBindFramebuffer(GL_FRAMEBUFFER, GLTexturePrivate::s_fbo); | ||
520 | glClearColor(0, 0, 0, 0); | 541 | glClearColor(0, 0, 0, 0); | ||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |