Skip to content
This repository
Browse code

Merge pull request #1408 from FernetMenta/render

LinuxRenderer fixes
  • Loading branch information...
commit 77a49e8bb64e426b7da0e26315147d262d35c743 2 parents 922dfc4 + 13517cb
Rainer Hochecker authored October 10, 2012
84  xbmc/cores/VideoRenderers/LinuxRendererGL.cpp
@@ -256,6 +256,15 @@ bool CLinuxRendererGL::ValidateRenderTarget()
256 256
     else
257 257
       CLog::Log(LOGNOTICE,"Using GL_TEXTURE_2D");
258 258
 
  259
+    // function pointer for texture might change in
  260
+    // call to LoadShaders
  261
+    glFinish();
  262
+    for (int i = 0 ; i < m_NumYV12Buffers ; i++)
  263
+      (this->*m_textureDelete)(i);
  264
+
  265
+    // trigger update of video filters
  266
+    m_scalingMethodGui = (ESCALINGMETHOD)-1;
  267
+
259 268
      // create the yuv textures
260 269
     LoadShaders();
261 270
 
@@ -593,6 +602,7 @@ void CLinuxRendererGL::Flush()
593 602
 
594 603
   glFinish();
595 604
   m_bValidated = false;
  605
+  m_fbo.fbo.Cleanup();
596 606
 }
597 607
 
598 608
 void CLinuxRendererGL::Update(bool bPauseDrawing)
@@ -847,7 +857,7 @@ void CLinuxRendererGL::UpdateVideoFilter()
847 857
     delete m_pVideoFilterShader;
848 858
     m_pVideoFilterShader = NULL;
849 859
   }
850  
-  m_fbo.Cleanup();
  860
+  m_fbo.fbo.Cleanup();
851 861
 
852 862
   VerifyGLState();
853 863
 
@@ -888,13 +898,13 @@ void CLinuxRendererGL::UpdateVideoFilter()
888 898
   case VS_SCALINGMETHOD_CUBIC:
889 899
     if (m_renderMethod & RENDER_GLSL)
890 900
     {
891  
-      if (!m_fbo.Initialize())
  901
+      if (!m_fbo.fbo.Initialize())
892 902
       {
893 903
         CLog::Log(LOGERROR, "GL: Error initializing FBO");
894 904
         break;
895 905
       }
896 906
 
897  
-      if (!m_fbo.CreateAndBindToTexture(GL_TEXTURE_2D, m_sourceWidth, m_sourceHeight, GL_RGBA))
  907
+      if (!m_fbo.fbo.CreateAndBindToTexture(GL_TEXTURE_2D, m_sourceWidth, m_sourceHeight, GL_RGBA))
898 908
       {
899 909
         CLog::Log(LOGERROR, "GL: Error creating texture and binding to FBO");
900 910
         break;
@@ -932,7 +942,7 @@ void CLinuxRendererGL::UpdateVideoFilter()
932 942
     delete m_pVideoFilterShader;
933 943
     m_pVideoFilterShader = NULL;
934 944
   }
935  
-  m_fbo.Cleanup();
  945
+  m_fbo.fbo.Cleanup();
936 946
 
937 947
   SetTextureFilter(GL_LINEAR);
938 948
   m_renderQuality = RQ_SINGLEPASS;
@@ -1141,7 +1151,7 @@ void CLinuxRendererGL::UnInit()
1141 1151
     (this->*m_textureDelete)(i);
1142 1152
 
1143 1153
   // cleanup framebuffer object if it was in use
1144  
-  m_fbo.Cleanup();
  1154
+  m_fbo.fbo.Cleanup();
1145 1155
   m_bValidated = false;
1146 1156
   m_bImageReady = false;
1147 1157
   m_bConfigured = false;
@@ -1299,6 +1309,12 @@ void CLinuxRendererGL::RenderSinglePass(int index, int field)
1299 1309
 
1300 1310
 void CLinuxRendererGL::RenderMultiPass(int index, int field)
1301 1311
 {
  1312
+  RenderToFBO(index, field);
  1313
+  RenderFromFBO();
  1314
+}
  1315
+
  1316
+void CLinuxRendererGL::RenderToFBO(int index, int field)
  1317
+{
1302 1318
   YUVPLANES &planes = m_buffers[index].fields[field];
1303 1319
 
1304 1320
   if (m_reloadShaders)
@@ -1307,6 +1323,21 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1307 1323
     LoadShaders(m_currentField);
1308 1324
   }
1309 1325
 
  1326
+  if (!m_fbo.fbo.IsValid())
  1327
+  {
  1328
+    if (!m_fbo.fbo.Initialize())
  1329
+    {
  1330
+      CLog::Log(LOGERROR, "GL: Error initializing FBO");
  1331
+      return;
  1332
+    }
  1333
+
  1334
+    if (!m_fbo.fbo.CreateAndBindToTexture(GL_TEXTURE_2D, m_sourceWidth, m_sourceHeight, GL_RGBA))
  1335
+    {
  1336
+      CLog::Log(LOGERROR, "GL: Error creating texture and binding to FBO");
  1337
+      return;
  1338
+    }
  1339
+  }
  1340
+
1310 1341
   glDisable(GL_DEPTH_TEST);
1311 1342
 
1312 1343
   // Y
@@ -1337,7 +1368,7 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1337 1368
     return;
1338 1369
   }
1339 1370
 
1340  
-  m_fbo.BeginRender();
  1371
+  m_fbo.fbo.BeginRender();
1341 1372
   VerifyGLState();
1342 1373
 
1343 1374
   m_pYUVShader->SetBlack(g_settings.m_currentVideoSettings.m_Brightness * 0.01f - 0.5f);
@@ -1375,15 +1406,15 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1375 1406
     CLog::Log(LOGERROR, "GL: Error enabling YUV shader");
1376 1407
   }
1377 1408
 
1378  
-  float imgwidth  = planes[0].rect.x2 - planes[0].rect.x1;
1379  
-  float imgheight = planes[0].rect.y2 - planes[0].rect.y1;
  1409
+  m_fbo.width  = planes[0].rect.x2 - planes[0].rect.x1;
  1410
+  m_fbo.height = planes[0].rect.y2 - planes[0].rect.y1;
1380 1411
   if (m_textureTarget == GL_TEXTURE_2D)
1381 1412
   {
1382  
-    imgwidth  *= planes[0].texwidth;
1383  
-    imgheight *= planes[0].texheight;
  1413
+    m_fbo.width  *= planes[0].texwidth;
  1414
+    m_fbo.height *= planes[0].texheight;
1384 1415
   }
1385  
-  imgwidth  *= planes[0].pixpertex_x;
1386  
-  imgheight *= planes[0].pixpertex_y;
  1416
+  m_fbo.width  *= planes[0].pixpertex_x;
  1417
+  m_fbo.height *= planes[0].pixpertex_y;
1387 1418
 
1388 1419
   // 1st Pass to video frame size
1389 1420
   glBegin(GL_QUADS);
@@ -1396,17 +1427,17 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1396 1427
   glMultiTexCoord2fARB(GL_TEXTURE0, planes[0].rect.x2, planes[0].rect.y1);
1397 1428
   glMultiTexCoord2fARB(GL_TEXTURE1, planes[1].rect.x2, planes[1].rect.y1);
1398 1429
   glMultiTexCoord2fARB(GL_TEXTURE2, planes[2].rect.x2, planes[2].rect.y1);
1399  
-  glVertex2f(imgwidth, 0.0f);
  1430
+  glVertex2f(m_fbo.width, 0.0f);
1400 1431
 
1401 1432
   glMultiTexCoord2fARB(GL_TEXTURE0, planes[0].rect.x2, planes[0].rect.y2);
1402 1433
   glMultiTexCoord2fARB(GL_TEXTURE1, planes[1].rect.x2, planes[1].rect.y2);
1403 1434
   glMultiTexCoord2fARB(GL_TEXTURE2, planes[2].rect.x2, planes[2].rect.y2);
1404  
-  glVertex2f(imgwidth, imgheight);
  1435
+  glVertex2f(m_fbo.width, m_fbo.height);
1405 1436
 
1406 1437
   glMultiTexCoord2fARB(GL_TEXTURE0, planes[0].rect.x1, planes[0].rect.y2);
1407 1438
   glMultiTexCoord2fARB(GL_TEXTURE1, planes[1].rect.x1, planes[1].rect.y2);
1408 1439
   glMultiTexCoord2fARB(GL_TEXTURE2, planes[2].rect.x1, planes[2].rect.y2);
1409  
-  glVertex2f(0.0f    , imgheight);
  1440
+  glVertex2f(0.0f    , m_fbo.height);
1410 1441
 
1411 1442
   glEnd();
1412 1443
   VerifyGLState();
@@ -1422,7 +1453,7 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1422 1453
   glMatrixMode(GL_MODELVIEW);
1423 1454
   VerifyGLState();
1424 1455
 
1425  
-  m_fbo.EndRender();
  1456
+  m_fbo.fbo.EndRender();
1426 1457
 
1427 1458
   glActiveTextureARB(GL_TEXTURE1);
1428 1459
   glDisable(m_textureTarget);
@@ -1430,9 +1461,12 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1430 1461
   glDisable(m_textureTarget);
1431 1462
   glActiveTextureARB(GL_TEXTURE0);
1432 1463
   glDisable(m_textureTarget);
  1464
+}
1433 1465
 
1434  
-  glEnable(GL_TEXTURE_2D);
1435  
-  glBindTexture(GL_TEXTURE_2D, m_fbo.Texture());
  1466
+void CLinuxRendererGL::RenderFromFBO()
  1467
+{
  1468
+  glEnable(m_textureTarget);
  1469
+  glActiveTextureARB(GL_TEXTURE0);
1436 1470
   VerifyGLState();
1437 1471
 
1438 1472
   // Use regular normalized texture coordinates
@@ -1445,7 +1479,7 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1445 1479
     if (!m_pVideoFilterShader->GetTextureFilter(filter))
1446 1480
       filter = m_scalingMethod == VS_SCALINGMETHOD_NEAREST ? GL_NEAREST : GL_LINEAR;
1447 1481
 
1448  
-    m_fbo.SetFiltering(GL_TEXTURE_2D, filter);
  1482
+    m_fbo.fbo.SetFiltering(m_textureTarget, filter);
1449 1483
     m_pVideoFilterShader->SetSourceTexture(0);
1450 1484
     m_pVideoFilterShader->SetWidth(m_sourceWidth);
1451 1485
     m_pVideoFilterShader->SetHeight(m_sourceHeight);
@@ -1462,17 +1496,18 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1462 1496
   else
1463 1497
   {
1464 1498
     GLint filter = m_scalingMethod == VS_SCALINGMETHOD_NEAREST ? GL_NEAREST : GL_LINEAR;
1465  
-    m_fbo.SetFiltering(GL_TEXTURE_2D, filter);
  1499
+    m_fbo.fbo.SetFiltering(m_textureTarget, filter);
  1500
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1466 1501
   }
1467 1502
 
1468 1503
   VerifyGLState();
1469 1504
 
1470  
-  imgwidth  /= m_sourceWidth;
1471  
-  imgheight /= m_sourceHeight;
  1505
+  float imgwidth = m_fbo.width / m_sourceWidth;
  1506
+  float imgheight = m_fbo.height / m_sourceHeight;
1472 1507
 
1473 1508
   glBegin(GL_QUADS);
1474 1509
 
1475  
-  glMultiTexCoord2fARB(GL_TEXTURE0, 0.0f    , 0.0f);
  1510
+  glMultiTexCoord2fARB(GL_TEXTURE0, 0.0f, 0.0f);
1476 1511
   glVertex4f(m_rotatedDestCoords[0].x, m_rotatedDestCoords[0].y, 0, 1.0f );
1477 1512
 
1478 1513
   glMultiTexCoord2fARB(GL_TEXTURE0, imgwidth, 0.0f);
@@ -1481,7 +1516,7 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1481 1516
   glMultiTexCoord2fARB(GL_TEXTURE0, imgwidth, imgheight);
1482 1517
   glVertex4f(m_rotatedDestCoords[2].x, m_rotatedDestCoords[2].y, 0, 1.0f );
1483 1518
   
1484  
-  glMultiTexCoord2fARB(GL_TEXTURE0, 0.0f    , imgheight);
  1519
+  glMultiTexCoord2fARB(GL_TEXTURE0, 0.0f, imgheight);
1485 1520
   glVertex4f(m_rotatedDestCoords[3].x, m_rotatedDestCoords[3].y, 0, 1.0f );
1486 1521
 
1487 1522
   glEnd();
@@ -1493,6 +1528,7 @@ void CLinuxRendererGL::RenderMultiPass(int index, int field)
1493 1528
 
1494 1529
   VerifyGLState();
1495 1530
 
  1531
+  glBindTexture(m_textureTarget, 0);
1496 1532
   glDisable(m_textureTarget);
1497 1533
   VerifyGLState();
1498 1534
 }
8  xbmc/cores/VideoRenderers/LinuxRendererGL.h
@@ -213,12 +213,18 @@ class CLinuxRendererGL : public CBaseRenderer
213 213
 
214 214
   // renderers
215 215
   void RenderMultiPass(int renderBuffer, int field);  // multi pass glsl renderer
  216
+  void RenderToFBO(int renderBuffer, int field);
  217
+  void RenderFromFBO();
216 218
   void RenderSinglePass(int renderBuffer, int field); // single pass glsl renderer
217 219
   void RenderSoftware(int renderBuffer, int field);   // single pass s/w yuv2rgb renderer
218 220
   void RenderVDPAU(int renderBuffer, int field);      // render using vdpau hardware
219 221
   void RenderVAAPI(int renderBuffer, int field);      // render using vdpau hardware
220 222
 
221  
-  CFrameBufferObject m_fbo;
  223
+  struct
  224
+  {
  225
+    CFrameBufferObject fbo;
  226
+    float width, height;
  227
+  } m_fbo;
222 228
 
223 229
   int m_iYV12RenderBuffer;
224 230
   int m_NumYV12Buffers;

0 notes on commit 77a49e8

Please sign in to comment.
Something went wrong with that request. Please try again.