diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2017-04-28 20:25:57 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2017-04-28 20:25:57 +0300 |
commit | b868f43fd382c0497b82f29685f6280d9692a0fb (patch) | |
tree | 7fac681bd1e08283cd3168a30b5362f250bf6da2 /intern/cycles/device/device_cuda.cpp | |
parent | ba4f47ce8eb00284da7d6b17bf9c3f02506617e3 (diff) |
Cycles support for preview on viewport with core profile
This upgrade the drawing code to use latest opengl calls.
Also, it adds a fallback shader for opencolorio.
Reviewers: sergey, brecht
Subscribers: merwin, fclem
Differential Revision: https://developer.blender.org/D2652
Diffstat (limited to 'intern/cycles/device/device_cuda.cpp')
-rw-r--r-- | intern/cycles/device/device_cuda.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp index ef283c9d455..3532e640eaa 100644 --- a/intern/cycles/device/device_cuda.cpp +++ b/intern/cycles/device/device_cuda.cpp @@ -1194,10 +1194,14 @@ public: } } - void draw_pixels(device_memory& mem, int y, int w, int h, int dx, int dy, int width, int height, bool transparent, + void draw_pixels( + device_memory& mem, int y, + int w, int h, int width, int height, + int dx, int dy, int dw, int dh, bool transparent, const DeviceDrawParams &draw_params) { if(!background) { + const bool use_fallback_shader = (draw_params.bind_display_space_shader_cb == NULL); PixelMem pmem = pixel_mem_map[mem.device_pointer]; float *vpointer; @@ -1214,10 +1218,12 @@ public: glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pmem.cuPBO); glBindTexture(GL_TEXTURE_2D, pmem.cuTexId); - if(mem.data_type == TYPE_HALF) + if(mem.data_type == TYPE_HALF) { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_HALF_FLOAT, (void*)offset); - else + } + else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, (void*)offset); + } glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glEnable(GL_TEXTURE_2D); @@ -1227,14 +1233,21 @@ public: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } - glColor3f(1.0f, 1.0f, 1.0f); - - if(draw_params.bind_display_space_shader_cb) { + GLint shader_program; + if(use_fallback_shader) { + if(!bind_fallback_display_space_shader(dw, dh)) { + return; + } + shader_program = fallback_shader_program; + } + else { draw_params.bind_display_space_shader_cb(); + glGetIntegerv(GL_CURRENT_PROGRAM, &shader_program); } - if(!vertex_buffer) + if(!vertex_buffer) { glGenBuffers(1, &vertex_buffer); + } glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); /* invalidate old contents - avoids stalling if buffer is still waiting in queue to be rendered */ @@ -1267,25 +1280,33 @@ public: glUnmapBuffer(GL_ARRAY_BUFFER); } - glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), 0); - glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), (char *)NULL + 2 * sizeof(float)); + GLuint vertex_array_object; + GLuint position_attribute, texcoord_attribute; - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glGenVertexArrays(1, &vertex_array_object); + glBindVertexArray(vertex_array_object); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + texcoord_attribute = glGetAttribLocation(shader_program, "texCoord"); + position_attribute = glGetAttribLocation(shader_program, "pos"); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + glEnableVertexAttribArray(texcoord_attribute); + glEnableVertexAttribArray(position_attribute); - glBindBuffer(GL_ARRAY_BUFFER, 0); + glVertexAttribPointer(texcoord_attribute, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)0); + glVertexAttribPointer(position_attribute, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)(sizeof(float) * 2)); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - if(draw_params.unbind_display_space_shader_cb) { + if(use_fallback_shader) { + glUseProgram(0); + } + else { draw_params.unbind_display_space_shader_cb(); } - if(transparent) + if(transparent) { glDisable(GL_BLEND); + } glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); @@ -1295,7 +1316,7 @@ public: return; } - Device::draw_pixels(mem, y, w, h, dx, dy, width, height, transparent, draw_params); + Device::draw_pixels(mem, y, w, h, width, height, dx, dy, dw, dh, transparent, draw_params); } void thread_run(DeviceTask *task) |