fork download
  1. #include "PCH.h"
  2. #include "OpenGLWidget.h"
  3. #include <Events/EventManager.h>
  4. #include <Events/SettingsEvent.h>
  5. #include <Logger/Logger.h>
  6.  
  7. using namespace MCRendererEngine;
  8. using namespace std;
  9.  
  10. namespace Widgets
  11. {
  12. OpenGLWidget::OpenGLWidget(QWidget* parent)
  13. : QGLWidget(parent)
  14. {
  15. //Register event listener
  16. Event::AddListener(this, &OpenGLWidget::OnArnoldResolutionChanged, SettingsEvent::c_iEventType);
  17. }
  18.  
  19. void OpenGLWidget::initializeGL()
  20. {
  21. //initializeGLFunctions();
  22. glewInit();
  23. glEnable(GL_TEXTURE_2D);
  24.  
  25. glGenBuffersARB(1, &m_uPBO);
  26. glGenTextures(1, &m_uTexture);
  27. }
  28.  
  29. void OpenGLWidget::paintGL()
  30. {
  31. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  32. glLoadIdentity();
  33.  
  34. glBindTexture(GL_TEXTURE_2D, m_uTexture);
  35.  
  36. glBegin(GL_QUADS);
  37. {
  38. glTexCoord2f(0.0f, 0.0f);
  39. glVertex2f(0.0f, width());
  40. glTexCoord2f(0.0f, m_iArnoldHeight);
  41. glVertex2f(0.0f, 0.0f);
  42. glTexCoord2f(m_iArnoldWidth, m_iArnoldHeight);
  43. glVertex2f(width(), 0.0f);
  44. glTexCoord2f(m_iArnoldWidth, 0.0f);
  45. glVertex2f(width(), height());
  46. }
  47. glEnd();
  48. }
  49.  
  50. void OpenGLWidget::resizeGL(int w, int h)
  51. {
  52. glViewport(0, 0, (GLint)w, (GLint)h);
  53. glMatrixMode(GL_PROJECTION);
  54. glLoadIdentity();
  55. //glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0);
  56. glOrtho((GLfloat)0, (GLfloat)w, (GLfloat)0, (GLfloat)h, -1.0, 1.0);
  57. glMatrixMode(GL_MODELVIEW);
  58. }
  59.  
  60. void OpenGLWidget::OnArnoldResolutionChanged(MCRendererEngine::IEventDataPtr p_pEvent)
  61. {
  62. auto pEvent = static_pointer_cast<SettingsEvent>(p_pEvent);
  63. ASSERT(pEvent != nullptr);
  64. if (pEvent->GetSettingsName() == SettingsEvent::c_sArnoldResolution)
  65. {
  66. //We should change texture resolution here
  67. //Creates our buffer
  68. pEvent->GetParams() >> m_iArnoldWidth;
  69. pEvent->GetParams() >> m_iArnoldHeight;
  70.  
  71. float* data = new float[m_iArnoldWidth *m_iArnoldHeight * 4];
  72.  
  73. for (int i = 0; i < m_iArnoldWidth *m_iArnoldHeight * 4; ++i)
  74. {
  75. data[i] = 1.0f;
  76. }
  77.  
  78. //glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_uPBO);
  79. //glBufferData(GL_PIXEL_UNPACK_BUFFER, m_iArnoldWidth * m_iArnoldHeight * 4 * sizeof(float), nullptr, GL_DYNAMIC_DRAW);
  80. glBindTexture(GL_TEXTURE_2D, m_uTexture);
  81. glTexImage2D(GL_TEXTURE_2D, 0, 3, m_iArnoldWidth, m_iArnoldHeight, 0, GL_RGBA, GL_FLOAT, data);
  82.  
  83. int size = 32;
  84. float* dataf = new float[size * size * 4];
  85. for (int i = 0; i < size * size * 4; ++i)
  86. {
  87. dataf[i] = 0.6f;
  88. }
  89. //glBindTexture(GL_TEXTURE_2D, m_uTexture);
  90. glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_RGBA, GL_FLOAT, dataf);
  91. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  92. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  93. }
  94. }
  95.  
  96. void OpenGLWidget::RenderBucketSlot(int x, int y, int w, int h, const void* data)
  97. {
  98. //const AtRGBA* pArnoldPixels = static_cast<const AtRGBA*>(data);
  99. /*glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_uPBO);
  100. GLfloat* pPBOData = (GLfloat*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
  101.  
  102. if (pPBOData != nullptr)
  103. {
  104. for (int i = 0; i < h; ++i)
  105. {
  106. for (int j = 0; j < w; ++j)
  107. {
  108. const AtRGBA& pixel = pArnoldPixels[i * w + j];
  109. pPBOData[((y + i)* m_iArnoldWidth + j + x) * sizeof(float)+0] = pixel.r;
  110. pPBOData[((y + i)* m_iArnoldWidth + j + x) * sizeof(float)+1] = pixel.g;
  111. pPBOData[((y + i)* m_iArnoldWidth + j + x) * sizeof(float)+2] = pixel.b;
  112. pPBOData[((y + i)* m_iArnoldWidth + j + x) * sizeof(float)+3] = pixel.a;
  113. }
  114. }
  115. glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
  116. }
  117.  
  118. //Copy data from PBO to our texture*/
  119. /*int size = 64;
  120. float* dataf = new float[size * size * 4];
  121. for (int i = 0; i < size * size * 4; ++i)
  122. {
  123. dataf[i] = 0.6f;
  124. }
  125. glBindTexture(GL_TEXTURE_2D, m_uTexture);
  126. glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_BGRA, GL_FLOAT, dataf);
  127. */
  128. //Redraw content
  129. updateGL();
  130. }
  131. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:17: fatal error: PCH.h: No such file or directory
 #include "PCH.h"
                 ^
compilation terminated.
stdout
Standard output is empty