Changeset View
Changeset View
Standalone View
Standalone View
libkwineffects/kwinglutils.cpp
Show First 20 Lines • Show All 1089 Lines • ▼ Show 20 Line(s) | |||||
1090 | { | 1090 | { | ||
1091 | if (s_renderTargets.isEmpty()) { | 1091 | if (s_renderTargets.isEmpty()) { | ||
1092 | glGetIntegerv(GL_VIEWPORT, s_virtualScreenViewport); | 1092 | glGetIntegerv(GL_VIEWPORT, s_virtualScreenViewport); | ||
1093 | } | 1093 | } | ||
1094 | target->enable(); | 1094 | target->enable(); | ||
1095 | s_renderTargets.push(target); | 1095 | s_renderTargets.push(target); | ||
1096 | } | 1096 | } | ||
1097 | 1097 | | |||
1098 | void GLRenderTarget::pushRenderTargets(QStack <GLRenderTarget*> targets) | ||||
1099 | { | ||||
1100 | if (s_renderTargets.isEmpty()) { | ||||
1101 | glGetIntegerv(GL_VIEWPORT, s_virtualScreenViewport); | ||||
1102 | } | ||||
1103 | | ||||
1104 | s_renderTargets.reserve(s_renderTargets.size() + targets.size()); | ||||
fredrik: The reserve() call should be in the else {} clause. | |||||
1105 | | ||||
1106 | /* | ||||
1107 | * Merging the two stacks. | ||||
1108 | * We cheat a little bit by using the inherited QVector functions. | ||||
1109 | * This is to not have the targets stack in reverse order without | ||||
1110 | * having to use a helper QStack first to reverse the order. | ||||
1111 | */ | ||||
1112 | while (!targets.isEmpty()) { | ||||
1113 | s_renderTargets.push(targets.first()); | ||||
1114 | targets.removeFirst(); | ||||
1115 | } | ||||
You could also check if s_renderTargets is empty, and just do s_renderTargets = targets when that's the case. fredrik: You could also check if s_renderTargets is empty, and just do s_renderTargets = targets when… | |||||
1116 | | ||||
1117 | s_renderTargets.top()->enable(); | ||||
1118 | } | ||||
1119 | | ||||
1098 | GLRenderTarget* GLRenderTarget::popRenderTarget() | 1120 | GLRenderTarget* GLRenderTarget::popRenderTarget() | ||
1099 | { | 1121 | { | ||
1100 | GLRenderTarget* ret = s_renderTargets.pop(); | 1122 | GLRenderTarget* ret = s_renderTargets.pop(); | ||
1101 | ret->disable(); | 1123 | ret->setTextureDirty(); | ||
1102 | 1124 | | |||
1103 | if (!s_renderTargets.isEmpty()) { | 1125 | if (!s_renderTargets.isEmpty()) { | ||
1104 | s_renderTargets.top()->enable(); | 1126 | s_renderTargets.top()->enable(); | ||
1105 | } else { | 1127 | } else { | ||
1128 | ret->disable(); | ||||
1106 | glViewport (s_virtualScreenViewport[0], s_virtualScreenViewport[1], s_virtualScreenViewport[2], s_virtualScreenViewport[3]); | 1129 | glViewport (s_virtualScreenViewport[0], s_virtualScreenViewport[1], s_virtualScreenViewport[2], s_virtualScreenViewport[3]); | ||
1107 | } | 1130 | } | ||
1131 | | ||||
1108 | return ret; | 1132 | return ret; | ||
1109 | } | 1133 | } | ||
1110 | 1134 | | |||
1135 | GLRenderTarget::GLRenderTarget() | ||||
1136 | { | ||||
1137 | // Reset variables | ||||
1138 | mValid = false; | ||||
1139 | mTexture = GLTexture(); | ||||
1140 | } | ||||
1141 | | ||||
1111 | GLRenderTarget::GLRenderTarget(const GLTexture& color) | 1142 | GLRenderTarget::GLRenderTarget(const GLTexture& color) | ||
1112 | { | 1143 | { | ||
1113 | // Reset variables | 1144 | // Reset variables | ||
1114 | mValid = false; | 1145 | mValid = false; | ||
1115 | 1146 | | |||
1116 | mTexture = color; | 1147 | mTexture = color; | ||
1117 | 1148 | | |||
1118 | // Make sure FBO is supported | 1149 | // Make sure FBO is supported | ||
1119 | if (sSupported && !mTexture.isNull()) { | 1150 | if (sSupported && !mTexture.isNull()) { | ||
1120 | initFBO(); | 1151 | initFBO(); | ||
1121 | } else | 1152 | } else | ||
1122 | qCCritical(LIBKWINGLUTILS) << "Render targets aren't supported!"; | 1153 | qCCritical(LIBKWINGLUTILS) << "Render targets aren't supported!"; | ||
1123 | } | 1154 | } | ||
1124 | 1155 | | |||
1125 | GLRenderTarget::~GLRenderTarget() | 1156 | GLRenderTarget::~GLRenderTarget() | ||
1126 | { | 1157 | { | ||
1127 | if (mValid) { | 1158 | if (mValid) { | ||
1128 | glDeleteFramebuffers(1, &mFramebuffer); | 1159 | glDeleteFramebuffers(1, &mFramebuffer); | ||
1129 | } | 1160 | } | ||
1130 | } | 1161 | } | ||
1131 | 1162 | | |||
1132 | bool GLRenderTarget::enable() | 1163 | bool GLRenderTarget::enable() | ||
1133 | { | 1164 | { | ||
1165 | if (!mValid) { | ||||
1166 | initFBO(); | ||||
1167 | } | ||||
1168 | | ||||
1134 | if (!valid()) { | 1169 | if (!valid()) { | ||
1135 | qCCritical(LIBKWINGLUTILS) << "Can't enable invalid render target!"; | 1170 | qCCritical(LIBKWINGLUTILS) << "Can't enable invalid render target!"; | ||
1136 | return false; | 1171 | return false; | ||
1137 | } | 1172 | } | ||
1138 | 1173 | | |||
1139 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); | 1174 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); | ||
1140 | glViewport(0, 0, mTexture.width(), mTexture.height()); | 1175 | glViewport(0, 0, mTexture.width(), mTexture.height()); | ||
1141 | mTexture.setDirty(); | 1176 | mTexture.setDirty(); | ||
1142 | 1177 | | |||
1143 | return true; | 1178 | return true; | ||
1144 | } | 1179 | } | ||
1145 | 1180 | | |||
1146 | bool GLRenderTarget::disable() | 1181 | bool GLRenderTarget::disable() | ||
1147 | { | 1182 | { | ||
1183 | if (!mValid) { | ||||
1184 | initFBO(); | ||||
1185 | } | ||||
1186 | | ||||
1148 | if (!valid()) { | 1187 | if (!valid()) { | ||
1149 | qCCritical(LIBKWINGLUTILS) << "Can't disable invalid render target!"; | 1188 | qCCritical(LIBKWINGLUTILS) << "Can't disable invalid render target!"; | ||
1150 | return false; | 1189 | return false; | ||
1151 | } | 1190 | } | ||
1152 | 1191 | | |||
1153 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | 1192 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
1154 | mTexture.setDirty(); | 1193 | mTexture.setDirty(); | ||
1155 | 1194 | | |||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 1267 | #endif | |||
1244 | mValid = true; | 1283 | mValid = true; | ||
1245 | } | 1284 | } | ||
1246 | 1285 | | |||
1247 | void GLRenderTarget::blitFromFramebuffer(const QRect &source, const QRect &destination, GLenum filter) | 1286 | void GLRenderTarget::blitFromFramebuffer(const QRect &source, const QRect &destination, GLenum filter) | ||
1248 | { | 1287 | { | ||
1249 | if (!GLRenderTarget::blitSupported()) { | 1288 | if (!GLRenderTarget::blitSupported()) { | ||
1250 | return; | 1289 | return; | ||
1251 | } | 1290 | } | ||
1291 | | ||||
1292 | if (!mValid) { | ||||
1293 | initFBO(); | ||||
1294 | } | ||||
1295 | | ||||
1252 | GLRenderTarget::pushRenderTarget(this); | 1296 | GLRenderTarget::pushRenderTarget(this); | ||
1253 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer); | 1297 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer); | ||
1254 | glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); | 1298 | glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); | ||
1255 | const QRect s = source.isNull() ? s_virtualScreenGeometry : source; | 1299 | const QRect s = source.isNull() ? s_virtualScreenGeometry : source; | ||
1256 | const QRect d = destination.isNull() ? QRect(0, 0, mTexture.width(), mTexture.height()) : destination; | 1300 | const QRect d = destination.isNull() ? QRect(0, 0, mTexture.width(), mTexture.height()) : destination; | ||
1257 | 1301 | | |||
1258 | glBlitFramebuffer((s.x() - s_virtualScreenGeometry.x()) * s_virtualScreenScale, | 1302 | glBlitFramebuffer((s.x() - s_virtualScreenGeometry.x()) * s_virtualScreenScale, | ||
1259 | (s_virtualScreenGeometry.height() - s_virtualScreenGeometry.y() + s.y() - s.height()) * s_virtualScreenScale, | 1303 | (s_virtualScreenGeometry.height() - s_virtualScreenGeometry.y() + s.y() - s.height()) * s_virtualScreenScale, | ||
1260 | (s.x() - s_virtualScreenGeometry.x() + s.width()) * s_virtualScreenScale, | 1304 | (s.x() - s_virtualScreenGeometry.x() + s.width()) * s_virtualScreenScale, | ||
1261 | (s_virtualScreenGeometry.height() - s_virtualScreenGeometry.y() + s.y()) * s_virtualScreenScale, | 1305 | (s_virtualScreenGeometry.height() - s_virtualScreenGeometry.y() + s.y()) * s_virtualScreenScale, | ||
1262 | d.x(), mTexture.height() - d.y() - d.height(), d.x() + d.width(), mTexture.height() - d.y(), | 1306 | d.x(), mTexture.height() - d.y() - d.height(), d.x() + d.width(), mTexture.height() - d.y(), | ||
1263 | GL_COLOR_BUFFER_BIT, filter); | 1307 | GL_COLOR_BUFFER_BIT, filter); | ||
1264 | GLRenderTarget::popRenderTarget(); | 1308 | GLRenderTarget::popRenderTarget(); | ||
1265 | } | 1309 | } | ||
1266 | 1310 | | |||
1267 | void GLRenderTarget::attachTexture(const GLTexture& target) | 1311 | void GLRenderTarget::attachTexture(const GLTexture& target) | ||
1268 | { | 1312 | { | ||
1269 | if (!mValid || mTexture.texture() == target.texture()) { | 1313 | if (!mValid) { | ||
1314 | initFBO(); | ||||
1315 | } | ||||
1316 | | ||||
1317 | if (mTexture.texture() == target.texture()) { | ||||
1270 | return; | 1318 | return; | ||
1271 | } | 1319 | } | ||
1272 | 1320 | | |||
1273 | pushRenderTarget(this); | 1321 | pushRenderTarget(this); | ||
1274 | 1322 | | |||
1275 | mTexture = target; | 1323 | mTexture = target; | ||
1276 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 1324 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | ||
1277 | mTexture.target(), mTexture.texture(), 0); | 1325 | mTexture.target(), mTexture.texture(), 0); | ||
1278 | 1326 | | |||
1279 | popRenderTarget(); | 1327 | popRenderTarget(); | ||
1280 | } | 1328 | } | ||
1281 | 1329 | | |||
1330 | void GLRenderTarget::detachTexture() | ||||
1331 | { | ||||
1332 | if (mTexture.isNull()) { | ||||
1333 | return; | ||||
1334 | } | ||||
1335 | | ||||
1336 | pushRenderTarget(this); | ||||
1337 | | ||||
1338 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | ||||
1339 | mTexture.target(), 0, 0); | ||||
1340 | | ||||
1341 | popRenderTarget(); | ||||
1342 | } | ||||
1343 | | ||||
1282 | 1344 | | |||
1283 | // ------------------------------------------------------------------ | 1345 | // ------------------------------------------------------------------ | ||
1284 | 1346 | | |||
1285 | static const uint16_t indices[] = { | 1347 | static const uint16_t indices[] = { | ||
1286 | 1, 0, 3, 3, 2, 1, 5, 4, 7, 7, 6, 5, 9, 8, 11, 11, 10, 9, | 1348 | 1, 0, 3, 3, 2, 1, 5, 4, 7, 7, 6, 5, 9, 8, 11, 11, 10, 9, | ||
1287 | 13, 12, 15, 15, 14, 13, 17, 16, 19, 19, 18, 17, 21, 20, 23, 23, 22, 21, | 1349 | 13, 12, 15, 15, 14, 13, 17, 16, 19, 19, 18, 17, 21, 20, 23, 23, 22, 21, | ||
1288 | 25, 24, 27, 27, 26, 25, 29, 28, 31, 31, 30, 29, 33, 32, 35, 35, 34, 33, | 1350 | 25, 24, 27, 27, 26, 25, 29, 28, 31, 31, 30, 29, 33, 32, 35, 35, 34, 33, | ||
1289 | 37, 36, 39, 39, 38, 37, 41, 40, 43, 43, 42, 41, 45, 44, 47, 47, 46, 45, | 1351 | 37, 36, 39, 39, 38, 37, 41, 40, 43, 43, 42, 41, 45, 44, 47, 47, 46, 45, | ||
▲ Show 20 Lines • Show All 981 Lines • Show Last 20 Lines |
The reserve() call should be in the else {} clause.