EscapeTimeVisualWidget.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. #include "EscapeTimeVisualWidget.h"
  2. #include "Bitmap.h"
  3. #include <QOpenGLShaderProgram>
  4. #include <QOpenGLContext>
  5. #include <QOpenGLFunctions>
  6. #include <QOpenGLExtraFunctions>
  7. #include <QOpenGLFunctions_3_0>
  8. #include <QOpenGLFunctions_4_0_Core>
  9. #include <vector>
  10. ETVImage::ETVImage(EscapeTimeVisualWidget& owner,
  11. const Bitmap<float>& img) :
  12. owner{ owner }
  13. {
  14. auto& gl = *owner.context()->functions();
  15. gl.glGenTextures(1, &textureId);
  16. gl.glActiveTexture(GL_TEXTURE0);
  17. gl.glBindTexture(GL_TEXTURE_2D, textureId);
  18. gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, int(img.width), int(img.height), 0, GL_RED, GL_FLOAT, img.pixels.get());
  19. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  20. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  21. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  22. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  23. gl.glBindTexture(GL_TEXTURE_2D, 0);
  24. }
  25. ETVImage::~ETVImage(void)
  26. {
  27. auto& gl = *owner.context()->functions();
  28. gl.glDeleteTextures(1, &textureId);
  29. }
  30. void ETVImage::draw(float x, float y, float w, float h,
  31. float tx, float ty, float tw, float th)
  32. {
  33. auto& gl = *owner.context()->functions();
  34. auto& gle = *owner.context()->extraFunctions();
  35. GLfloat const fbVertices[] = {
  36. 0, 0, 0.0f,
  37. 0, 256, 0.0f,
  38. 256, 0, 0.0f,
  39. 256, 256, 0.0f,
  40. };
  41. GLfloat const vertices[] = {
  42. x, y, 0.0f,
  43. x, y + h, 0.0f,
  44. x + w, y, 0.0f,
  45. x + w, y + h, 0.0f,
  46. };
  47. GLfloat const texCoords[] = {
  48. tx, ty,
  49. tx, ty + th,
  50. tx + tw, ty,
  51. tx + tw, ty + th,
  52. };
  53. GLfloat const fullTexCoords[] = {
  54. 0, 0,
  55. 0, 1,
  56. 1, 0,
  57. 1, 1,
  58. };
  59. QColor color{ 255, 255, 255 };
  60. auto& program = owner.program;
  61. int vertexLoc = program->attributeLocation("vertex");
  62. int texCoordsLoc = program->attributeLocation("texCoord");
  63. int colorLocation = program->uniformLocation("color");
  64. int texLoc = program->uniformLocation("tex");
  65. int gradLoc = program->uniformLocation("gradient");
  66. int gradientScaler = program->uniformLocation("gradientScaler");
  67. int maxIterations = program->uniformLocation("maxIterations");
  68. program->setAttributeArray(vertexLoc, vertices, 3);
  69. program->setAttributeArray(texCoordsLoc, texCoords, 2);
  70. program->enableAttributeArray(vertexLoc);
  71. program->enableAttributeArray(texCoordsLoc);
  72. program->setUniformValue(colorLocation, color);
  73. program->setUniformValue(gradientScaler, 1.0f / float(owner.gradientTextureMax));
  74. program->setUniformValue(maxIterations, float(owner.maxIterations));
  75. QMatrix4x4 pmvMatrix;
  76. pmvMatrix.ortho(QRect{ 0, 0, owner.getResolutionX(), owner.getResolutionY() });
  77. int matrixLocation = program->uniformLocation("matrix");
  78. program->setUniformValue(matrixLocation, pmvMatrix);
  79. gl.glEnable(GL_TEXTURE_2D);
  80. owner.program->bind();
  81. //GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
  82. //gle.glDrawBuffers(1, drawBuffers);
  83. gl.glBindFramebuffer(GL_FRAMEBUFFER, owner.tileFramebuffer);
  84. gl.glDisable(GL_DEPTH_TEST);
  85. if(gl.glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
  86. printf("error intitializing framebuffer\n");
  87. }
  88. gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, owner.tileTexture, 0);
  89. //gl.glViewport(0, 0, 256, 256);
  90. gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
  91. gl.glUniform1i(texLoc, 0);
  92. gl.glUniform1i(gradLoc, 2);
  93. gl.glActiveTexture(GL_TEXTURE0);
  94. gl.glBindTexture(GL_TEXTURE_2D, textureId);
  95. gl.glActiveTexture(GL_TEXTURE2);
  96. gl.glBindTexture(GL_TEXTURE_2D, owner.gradientTextureId);
  97. gl.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  98. program->disableAttributeArray(vertexLoc);
  99. program->disableAttributeArray(texCoordsLoc);
  100. /*owner.renderTextures->bind();
  101. gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
  102. //gl.glViewport(0, 0, owner.getResolutionX(), owner.getResolutionY());
  103. int rtVertexLoc = owner.renderTextures->attributeLocation("vertex");
  104. int rtTexCoordsLoc = owner.renderTextures->attributeLocation("texCoord");
  105. int rtTexLoc = owner.renderTextures->attributeLocation("tex");
  106. gl.glActiveTexture(GL_TEXTURE0);
  107. gl.glUniform1i(rtTexLoc, 0);
  108. owner.renderTextures->setAttributeArray(rtVertexLoc, vertices, 3);
  109. owner.renderTextures->setAttributeArray(rtTexCoordsLoc, fullTexCoords, 2);
  110. owner.renderTextures->enableAttributeArray(rtVertexLoc);
  111. owner.renderTextures->enableAttributeArray(rtTexCoordsLoc);
  112. gl.glBindTexture(GL_TEXTURE_2D, owner.tileTexture);
  113. //if (rand() % 2)
  114. //gl.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  115. owner.renderTextures->disableAttributeArray(rtVertexLoc);
  116. owner.renderTextures->disableAttributeArray(rtTexCoordsLoc);
  117. */
  118. gl.glActiveTexture(GL_TEXTURE0);
  119. }
  120. EscapeTimeVisualWidget::EscapeTimeVisualWidget(QWidget* parent) :
  121. QOpenGLWidget{ parent },
  122. gradientTextureId{ 0 },
  123. gradientTextureMax{ 1.0f },
  124. gradientNeedsUpdate{ false }
  125. {
  126. }
  127. void EscapeTimeVisualWidget::setGradient(Gradient newGradient)
  128. {
  129. this->gradient = newGradient;
  130. gradientNeedsUpdate = true;
  131. update();
  132. }
  133. const Gradient& EscapeTimeVisualWidget::getGradient(void)
  134. {
  135. return gradient;
  136. }
  137. void EscapeTimeVisualWidget::initializeGL(void)
  138. {
  139. auto& gl = *this->context()->functions();
  140. gl.glClearColor(0, 0, 0, 0);
  141. gl.glDisable(GL_DEPTH_TEST);
  142. // looks not even better
  143. //gl.glEnable(GL_FRAMEBUFFER_SRGB);
  144. //glShadeModel(GL_SMOOTH);
  145. renderTextures = new QOpenGLShaderProgram{ this->context() };
  146. renderTextures->addShaderFromSourceCode(QOpenGLShader::Vertex,
  147. "attribute highp vec4 vertex;\n"
  148. "attribute highp vec2 texCoord;\n"
  149. "uniform highp mat4 matrix;\n"
  150. "varying highp vec2 texc;\n"
  151. "void main(void)\n"
  152. "{\n"
  153. " gl_Position = matrix * vertex;\n"
  154. " texc = texCoord;\n"
  155. "}");
  156. renderTextures->addShaderFromSourceCode(QOpenGLShader::Fragment,
  157. "#version 110\n"
  158. "uniform sampler2D tex;\n"
  159. "varying highp vec2 texc;\n"
  160. "void main(void)\n"
  161. "{\n"
  162. " gl_FragColor = texture2D(tex, texc);\n"
  163. "}");
  164. renderTextures->link();
  165. juliaPreviewer = new QOpenGLShaderProgram{ this->context() };
  166. juliaPreviewer->addShaderFromSourceCode(QOpenGLShader::Vertex,
  167. "attribute highp vec4 vertex;\n"
  168. "attribute highp vec2 texCoord;\n"
  169. "uniform highp mat4 matrix;\n"
  170. "varying highp vec2 texc;\n"
  171. "void main(void)\n"
  172. "{\n"
  173. " gl_Position = matrix * vertex;\n"
  174. " texc = texCoord;\n"
  175. "}");
  176. juliaPreviewer->addShaderFromSourceCode(QOpenGLShader::Fragment,
  177. "#version 110\n"
  178. "uniform sampler2D gradient;\n"
  179. "uniform highp float gradientScaler;\n"
  180. "uniform highp float maxIterations;\n"
  181. "varying highp vec2 texc;\n"
  182. "uniform highp float juliaX;\n"
  183. "uniform highp float juliaY;\n"
  184. "const highp float left = -1.5;\n"
  185. "const highp float right = 1.5;\n"
  186. "const highp float top = -1.5;\n"
  187. "const highp float bottom = 1.5;\n"
  188. "float map(float a, float b, float v) {\n"
  189. " return (1.0 - v) * a + b * v;\n"
  190. "}\n"
  191. "float iterate(float x, float y, float ca, float cb) {\n"
  192. " int k = 0;\n"
  193. " float a = x;\n"
  194. " float b = y;\n"
  195. " while(k <= 250) {\n"
  196. " float aa = a * a;\n"
  197. " float bb = b * b;\n"
  198. " float abab = 2.0 * a * b;\n"
  199. " a = aa - bb + ca;\n"
  200. " b = abab + cb;\n"
  201. " if (aa + bb >= 16.0) break;\n"
  202. " k = k + 1;\n"
  203. " }\n"
  204. " return float(k);\n"
  205. "}\n"
  206. "void main(void)\n"
  207. "{\n"
  208. " float x = map(left, right, texc.x);\n"
  209. " float y = map(top, bottom, texc.y);\n"
  210. " float v = iterate(x, y, juliaX, juliaY);\n"
  211. // " if (v >= maxIterations) { v = 0.0; }\n"
  212. " float vnorm = v * gradientScaler;\n"
  213. " gl_FragColor = texture2D(gradient, vec2(vnorm, 0.0));\n"
  214. //" gl_FragColor = vec4(vnorm, 0.0, 0.0, 0.0);\n"
  215. "}");
  216. juliaPreviewer->link();
  217. program = new QOpenGLShaderProgram{ this->context() };
  218. bool vert = program->addShaderFromSourceCode(QOpenGLShader::Vertex,
  219. "attribute highp vec4 vertex;\n"
  220. "attribute highp vec2 texCoord;\n"
  221. "uniform highp mat4 matrix;\n"
  222. "varying highp vec2 texc;\n"
  223. "void main(void)\n"
  224. "{\n"
  225. " gl_Position = matrix * vertex;\n"
  226. " texc = texCoord;\n"
  227. "}");
  228. // TODO rewrite this monster
  229. if (context()->versionFunctions<QOpenGLFunctions_4_0_Core>() != nullptr) {
  230. bool frag = program->addShaderFromSourceCode(QOpenGLShader::Fragment,
  231. "#version 400\n"
  232. "uniform sampler2D gradient;\n"
  233. "uniform sampler2D tex;\n"
  234. "uniform mediump vec4 color;\n"
  235. "uniform highp float gradientScaler;\n"
  236. "uniform highp float maxIterations;\n"
  237. "varying highp vec2 texc;\n"
  238. "vec4 colorize(float pos) {\n"
  239. " if (pos >= maxIterations) {\n"
  240. " return vec4(0.0, 0.0, 0.0, 1.0);\n"
  241. " } else {\n"
  242. " return texture2D(gradient, vec2(pos * gradientScaler, 0.0));\n"
  243. " }\n"
  244. "}\n"
  245. "void main(void)\n"
  246. "{\n"
  247. " vec2 size = textureSize(tex, 0);\n"
  248. " size = vec2(256.0, 256.0);\n"
  249. " vec2 accPoint = texc * size;\n"
  250. " vec2 ip = floor(accPoint);\n"
  251. " vec2 fp = fract(accPoint);\n"
  252. " vec4 inter = textureGather(tex, ip / size, 0);\n"
  253. " vec4 col1 = colorize(inter.x);\n"
  254. " vec4 col2 = colorize(inter.y);\n"
  255. " vec4 col3 = colorize(inter.z);\n"
  256. " vec4 col4 = colorize(inter.w);\n"
  257. " vec4 col = mix(mix(col4, col3, fp.x), mix(col1, col2, fp.x), fp.y);\n"
  258. " gl_FragColor = col;\n"
  259. // " gl_FragColor = gl_FragColor * texture2D(tex, texc);\n"
  260. // " float v = texture2D(tex, texc).r;\n"
  261. // " gl_FragColor = vec4(v, 1.0 - v, v*v, 1);\n"
  262. // " gl_FragColor.g = 0.3;\n"
  263. "}");
  264. }
  265. else {
  266. bool frag = program->addShaderFromSourceCode(QOpenGLShader::Fragment,
  267. "#version 110\n"
  268. "uniform sampler2D gradient;\n"
  269. "uniform sampler2D tex;\n"
  270. "uniform mediump vec4 color;\n"
  271. "uniform highp float gradientScaler;\n"
  272. "uniform highp float maxIterations;\n"
  273. "varying highp vec2 texc;\n"
  274. "void main(void)\n"
  275. "{\n"
  276. " float v = texture2D(tex, texc).r;\n"
  277. " if (v >= maxIterations) {\n"
  278. " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
  279. " } else {\n"
  280. " gl_FragColor = texture2D(gradient, vec2(v * gradientScaler, 0.0));\n"
  281. " }\n"
  282. // " gl_FragColor = gl_FragColor * texture2D(tex, texc);\n"
  283. // " float v = texture2D(tex, texc).r;\n"
  284. // " gl_FragColor = vec4(v, 1.0 - v, v*v, 1);\n"
  285. // " gl_FragColor.g = 0.3;\n"
  286. "}");
  287. }
  288. //program.link();
  289. bool bound = program->bind();
  290. bound = renderTextures->bind();
  291. int vertexLoc = program->attributeLocation("vertex");
  292. int texCoordsLoc = program->attributeLocation("texCoord");
  293. int colorLocation = program->uniformLocation("color");
  294. int texLoc = program->uniformLocation("tex");
  295. int gradLoc = program->uniformLocation("gradient");
  296. int gradientScaler = program->uniformLocation("gradientScaler");
  297. int maxIterations = program->uniformLocation("maxIterations");
  298. program->setUniformValue(gradientScaler, 0.005f);
  299. program->setUniformValue(maxIterations, 250.0f);
  300. auto& gle = *this->context()->extraFunctions();
  301. gl.glGenTextures(1, &tileTexture);
  302. gl.glBindTexture(GL_TEXTURE_2D, tileTexture);
  303. gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
  304. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  305. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  306. gl.glBindTexture(GL_TEXTURE_2D, 0);
  307. gl.glGenFramebuffers(1, &tileFramebuffer);
  308. gl.glBindFramebuffer(GL_FRAMEBUFFER, tileFramebuffer);
  309. gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tileTexture, 0);
  310. GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
  311. gle.glDrawBuffers(1, drawBuffers);
  312. if(gl.glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
  313. printf("error intitializing framebuffer\n");
  314. }
  315. gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
  316. unsigned char pix[] = { 255, 0, 0, 0, 255, 0, 0, 0, 255 };
  317. GLuint id;
  318. gl.glEnable(GL_TEXTURE_2D);
  319. gl.glGenTextures(1, &id);
  320. gl.glBindTexture(GL_TEXTURE_2D, id);
  321. gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 3, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, reinterpret_cast<char*> (pix));
  322. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  323. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  324. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  325. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  326. gl.glBindTexture(GL_TEXTURE_2D, 0);
  327. gradientTextureId = id;
  328. gl.glDisable(GL_DEPTH_TEST);
  329. //gl3.glBindSampler(0, id);
  330. }
  331. void EscapeTimeVisualWidget::resizeGL(int w, int h)
  332. {
  333. auto& gl = *this->context()->functions();
  334. float pixelRatio = this->devicePixelRatioF();
  335. //pixelRatio = 1.0 / 32;
  336. float newW = w * pixelRatio;
  337. float newH = h * pixelRatio;
  338. setResolutionX(newW);
  339. setResolutionY(newH);
  340. gl.glViewport(0, 0, newW, newH);
  341. QMatrix4x4 pmvMatrix;
  342. pmvMatrix.ortho(QRectF{ 0, 0, newW, newH });
  343. int matrixLocation = program->uniformLocation("matrix");
  344. int rtMatrixLocation = renderTextures->uniformLocation("matrix");
  345. int jMatrixLocation = juliaPreviewer->uniformLocation("matrix");
  346. program->setUniformValue(matrixLocation, pmvMatrix);
  347. renderTextures->setUniformValue(rtMatrixLocation, pmvMatrix);
  348. juliaPreviewer->setUniformValue(jMatrixLocation, pmvMatrix);
  349. }
  350. void EscapeTimeVisualWidget::paintGL(void)
  351. {
  352. if (gradientNeedsUpdate)
  353. updateGradient();
  354. /*ETVImage etvi{ *this };
  355. auto& gl = *this->context()->functions();
  356. gl.glClearColor(0.0, 0.2, 0.0, 1.0);
  357. gl.glClear(GL_COLOR_BUFFER_BIT);
  358. etvi.draw(100, 100, 700, 700);*/
  359. }
  360. void EscapeTimeVisualWidget::drawJulia(float jx, float jy)
  361. {
  362. int gradLoc = juliaPreviewer->uniformLocation("gradient");
  363. int gradientScaler = juliaPreviewer->uniformLocation("gradientScaler");
  364. int juliaX = juliaPreviewer->uniformLocation("juliaX");
  365. int juliaY = juliaPreviewer->uniformLocation("juliaY");
  366. int vertexLoc = juliaPreviewer->attributeLocation("vertex");
  367. int texCoordsLoc = juliaPreviewer->attributeLocation("texCoord");
  368. int maxIterLoc = juliaPreviewer->attributeLocation("maxIterations");
  369. const float x = 100;
  370. const float y = 100;
  371. const float w = 200;
  372. const float h = 200;
  373. GLfloat const vertices[] = {
  374. x, y, 0.0f,
  375. x, y + h, 0.0f,
  376. x + w, y, 0.0f,
  377. x + w, y + h, 0.0f,
  378. };
  379. GLfloat const texCoords[] = {
  380. 0, 0,
  381. 0, 1,
  382. 1, 0,
  383. 1, 1,
  384. };
  385. auto& gl = *this->context()->functions();
  386. gl.glEnable(GL_TEXTURE_2D);
  387. gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
  388. juliaPreviewer->setAttributeArray(vertexLoc, vertices, 3);
  389. juliaPreviewer->setAttributeArray(texCoordsLoc, texCoords, 2);
  390. juliaPreviewer->enableAttributeArray(vertexLoc);
  391. juliaPreviewer->enableAttributeArray(texCoordsLoc);
  392. juliaPreviewer->setUniformValue(gradientScaler, 1.0f / float(gradientTextureMax));
  393. juliaPreviewer->setUniformValue(maxIterLoc, float(250));
  394. juliaPreviewer->setUniformValue(juliaX, float(jx));
  395. juliaPreviewer->setUniformValue(juliaY, float(jy));
  396. juliaPreviewer->bind();
  397. gl.glUniform1i(gradLoc, 0);
  398. gl.glActiveTexture(GL_TEXTURE0);
  399. gl.glBindTexture(GL_TEXTURE_2D, gradientTextureId);
  400. gl.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  401. juliaPreviewer->disableAttributeArray(vertexLoc);
  402. juliaPreviewer->disableAttributeArray(texCoordsLoc);
  403. //juliaPreviewer->release();
  404. //program->bind();
  405. }
  406. void EscapeTimeVisualWidget::setMaxIterationCutoff(float maxIter)
  407. {
  408. this->maxIterations = maxIter;
  409. }
  410. void EscapeTimeVisualWidget::updateGradient(void)
  411. {
  412. auto& gl = *this->context()->functions();
  413. const int len = 1024;
  414. std::unique_ptr<uint8_t[]> pixels = std::make_unique<uint8_t[]>(len * 3);
  415. for (int i = 0; i < len; i++) {
  416. RGBColor c = gradient.get(gradient.getMax() * i / len);
  417. pixels[i * 3] = c.r;
  418. pixels[i * 3 + 1] = c.g;
  419. pixels[i * 3 + 2] = c.b;
  420. }
  421. gl.glEnable(GL_TEXTURE_2D);
  422. gl.glBindTexture(GL_TEXTURE_2D, gradientTextureId);
  423. gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, len, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, reinterpret_cast<unsigned char*> (pixels.get()));
  424. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  425. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  426. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  427. gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  428. gl.glBindTexture(GL_TEXTURE_2D, 0);
  429. this->gradientTextureMax = gradient.getMax();
  430. gradientNeedsUpdate = false;
  431. }
  432. void EscapeTimeVisualWidget::setResolutionX(int w)
  433. {
  434. resolutionX = w;
  435. }
  436. void EscapeTimeVisualWidget::setResolutionY(int h)
  437. {
  438. resolutionY = h;
  439. }
  440. int EscapeTimeVisualWidget::getResolutionX(void) const
  441. {
  442. return resolutionX;
  443. }
  444. int EscapeTimeVisualWidget::getResolutionY(void) const
  445. {
  446. return resolutionY;
  447. }