forked from blender/blender
Move to use the GPU API instead OpenGL #23
@ -12,7 +12,6 @@
|
||||
#include "BKE_camera.h"
|
||||
#include "BLI_math_matrix.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
#include "GPU_shader.h"
|
||||
#include "GPU_batch.h"
|
||||
// clang-format on
|
||||
|
||||
@ -133,20 +132,20 @@ pxr::GfCamera ViewSettings::gf_camera()
|
||||
(float)border[3] / screen_height));
|
||||
}
|
||||
|
||||
GLTexture::GLTexture() : gpu_texture(nullptr), width(0), height(0), channels(4)
|
||||
GLTexture::GLTexture() : texture(nullptr), width(0), height(0), channels(4)
|
||||
{
|
||||
}
|
||||
|
||||
GLTexture::~GLTexture()
|
||||
{
|
||||
if (gpu_texture) {
|
||||
if (texture) {
|
||||
free();
|
||||
}
|
||||
}
|
||||
|
||||
void GLTexture::set_buffer(pxr::HdRenderBuffer *buffer)
|
||||
{
|
||||
if (!gpu_texture) {
|
||||
if (!texture) {
|
||||
create(buffer);
|
||||
return;
|
||||
}
|
||||
@ -158,7 +157,7 @@ void GLTexture::set_buffer(pxr::HdRenderBuffer *buffer)
|
||||
}
|
||||
|
||||
void *data = buffer->Map();
|
||||
GPU_texture_update(gpu_texture, GPU_DATA_FLOAT, data);
|
||||
GPU_texture_update(texture, GPU_DATA_FLOAT, data);
|
||||
buffer->Unmap();
|
||||
}
|
||||
|
||||
@ -168,7 +167,7 @@ void GLTexture::create(pxr::HdRenderBuffer *buffer)
|
||||
height = buffer->GetHeight();
|
||||
channels = pxr::HdGetComponentCount(buffer->GetFormat());
|
||||
void *data = buffer->Map();
|
||||
gpu_texture = GPU_texture_create_2d("HydraRendeViewport",
|
||||
texture = GPU_texture_create_2d("HydraRendeViewport",
|
||||
width,
|
||||
height,
|
||||
1,
|
||||
@ -177,88 +176,38 @@ void GLTexture::create(pxr::HdRenderBuffer *buffer)
|
||||
(float *)data);
|
||||
buffer->Unmap();
|
||||
|
||||
GPU_texture_filter_mode(gpu_texture, true);
|
||||
GPU_texture_wrap_mode(gpu_texture, true, true);
|
||||
GPU_texture_filter_mode(texture, true);
|
||||
GPU_texture_wrap_mode(texture, true, true);
|
||||
}
|
||||
|
||||
void GLTexture::free()
|
||||
{
|
||||
GPU_texture_free(gpu_texture);
|
||||
gpu_texture = nullptr;
|
||||
GPU_texture_free(texture);
|
||||
texture = nullptr;
|
||||
}
|
||||
|
||||
void GLTexture::draw(float x, float y)
|
||||
void GLTexture::draw(GPUShader *shader, float x, float y)
|
||||
{
|
||||
/* Getting shader program */
|
||||
GPUShader *shader_program = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
|
||||
//GLint shader_program;
|
||||
//glGetIntegerv(GL_CURRENT_PROGRAM, &shader_program);
|
||||
|
||||
//// Generate vertex array
|
||||
//GLuint vertex_array;
|
||||
//glGenVertexArrays(1, &vertex_array);
|
||||
|
||||
//int position_location = GPU_shader_get_attribute(shader_program, "pos");
|
||||
//int texcoord_location = GPU_shader_get_attribute(shader_program, "texCoord");
|
||||
|
||||
//GLint texturecoord_location = glGetAttribLocation(shader_program, "texCoord");
|
||||
//GLint position_location = glGetAttribLocation(shader_program, "pos");
|
||||
|
||||
// Generate geometry buffers for drawing textured quad
|
||||
float position[8] = {x, y, x + width, y, x + width, y + height, x, y + height};
|
||||
float texcoord[8] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0};
|
||||
|
||||
GPUVertFormat format = {0};
|
||||
GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
GPU_vertformat_attr_add(&format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
|
||||
GPUVertBuf *vertex_buffer = GPU_vertbuf_create_with_format(&format);
|
||||
GPU_vertbuf_data_alloc(vertex_buffer, 4);
|
||||
GPU_vertbuf_attr_fill(vertex_buffer, 0, position);
|
||||
GPU_vertbuf_attr_fill(vertex_buffer, 1, texcoord);
|
||||
|
||||
//GLuint vertex_buffer[2];
|
||||
//glGenBuffers(2, vertex_buffer);
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[0]);
|
||||
//glBufferData(GL_ARRAY_BUFFER, 32, position, GL_STATIC_DRAW);
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[1]);
|
||||
//glBufferData(GL_ARRAY_BUFFER, 32, texcoord, GL_STATIC_DRAW);
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
int slot = GPU_shader_get_sampler_binding(shader, "image");
|
||||
GPU_texture_bind(texture, slot);
|
||||
GPU_shader_uniform_1i(shader, "image", slot);
|
||||
|
||||
|
||||
//// DRAWING
|
||||
GPUBatch *gpu_batch = GPU_batch_create(GPU_PRIM_TRI_FAN, vertex_buffer, nullptr);
|
||||
|
||||
|
||||
GPU_shader_bind(shader_program);
|
||||
int slot = GPU_shader_get_sampler_binding(shader_program, "image");
|
||||
GPU_texture_bind(gpu_texture, slot);
|
||||
GPU_shader_uniform_1i(shader_program, "image", slot);
|
||||
|
||||
//glActiveTexture(GL_TEXTURE0);
|
||||
//glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
|
||||
//glBindVertexArray(vertex_array);
|
||||
//glEnableVertexAttribArray(texturecoord_location);
|
||||
//glEnableVertexAttribArray(position_location);
|
||||
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[0]);
|
||||
//glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer[1]);
|
||||
//glVertexAttribPointer(texturecoord_location, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
GPU_batch_set_shader(gpu_batch, shader_program);
|
||||
GPU_batch_set_shader(gpu_batch, shader);
|
||||
GPU_batch_draw(gpu_batch);
|
||||
|
||||
//glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
//glBindVertexArray(0);
|
||||
//glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
//// DELETING
|
||||
//glDeleteBuffers(2, vertex_buffer);
|
||||
//glDeleteVertexArrays(1, &vertex_array);
|
||||
GPU_BATCH_DISCARD_SAFE(gpu_batch);
|
||||
}
|
||||
|
||||
void ViewportEngine::sync(Depsgraph *depsgraph,
|
||||
@ -319,8 +268,8 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
||||
engine->Execute(render_index.get(), &tasks);
|
||||
|
||||
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
||||
gpu_texture.set_buffer(render_task_delegate->get_renderer_aov(pxr::HdAovTokens->color));
|
||||
gpu_texture.draw(view_settings.border[0], view_settings.border[1]);
|
||||
texture.set_buffer(render_task_delegate->get_renderer_aov(pxr::HdAovTokens->color));
|
||||
texture.draw(shader, view_settings.border[0], view_settings.border[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <pxr/imaging/hd/renderBuffer.h>
|
||||
|
||||
#include "GPU_texture.h"
|
||||
#include "GPU_shader.h"
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
@ -18,13 +19,13 @@ class GLTexture {
|
||||
GLTexture();
|
||||
~GLTexture();
|
||||
void set_buffer(pxr::HdRenderBuffer *buffer);
|
||||
void draw(float x, float y);
|
||||
void draw(GPUShader *shader, float x, float y);
|
||||
|
||||
private:
|
||||
void create(pxr::HdRenderBuffer *buffer);
|
||||
void free();
|
||||
|
||||
GPUTexture *gpu_texture;
|
||||
GPUTexture *texture;
|
||||
int width, height, channels;
|
||||
};
|
||||
|
||||
@ -43,7 +44,7 @@ class ViewportEngine : public Engine {
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::steady_clock> time_begin;
|
||||
|
||||
GLTexture gpu_texture;
|
||||
GLTexture texture;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
Loading…
Reference in New Issue
Block a user