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