Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_texture.cc
| Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| bool Texture::init_buffer(GPUVertBuf *vbo, eGPUTextureFormat format) | bool Texture::init_buffer(GPUVertBuf *vbo, eGPUTextureFormat format) | ||||
| { | { | ||||
| /* See to_texture_format(). */ | /* See to_texture_format(). */ | ||||
| if (format == GPU_DEPTH_COMPONENT24) { | if (format == GPU_DEPTH_COMPONENT24) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| w_ = vbo->vertex_len; | w_ = GPU_vertbuf_get_vertex_len(vbo); | ||||
| h_ = 0; | h_ = 0; | ||||
| d_ = 0; | d_ = 0; | ||||
| format_ = format; | format_ = format; | ||||
| format_flag_ = to_format_flag(format); | format_flag_ = to_format_flag(format); | ||||
| type_ = GPU_TEXTURE_BUFFER; | type_ = GPU_TEXTURE_BUFFER; | ||||
| return this->init_internal(vbo); | return this->init_internal(vbo); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | for (int mip = 0; mip < miplen; mip++) { | ||||
| ofs += size; | ofs += size; | ||||
| } | } | ||||
| } | } | ||||
| return reinterpret_cast<GPUTexture *>(tex); | return reinterpret_cast<GPUTexture *>(tex); | ||||
| } | } | ||||
| GPUTexture *GPU_texture_create_from_vertbuf(const char *name, GPUVertBuf *vert) | GPUTexture *GPU_texture_create_from_vertbuf(const char *name, GPUVertBuf *vert) | ||||
| { | { | ||||
| eGPUTextureFormat tex_format = to_texture_format(&vert->format); | eGPUTextureFormat tex_format = to_texture_format(GPU_vertbuf_get_format(vert)); | ||||
| Texture *tex = GPUBackend::get()->texture_alloc(name); | Texture *tex = GPUBackend::get()->texture_alloc(name); | ||||
| bool success = tex->init_buffer(vert, tex_format); | bool success = tex->init_buffer(vert, tex_format); | ||||
| if (!success) { | if (!success) { | ||||
| delete tex; | delete tex; | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| return reinterpret_cast<GPUTexture *>(tex); | return reinterpret_cast<GPUTexture *>(tex); | ||||
| Show All 11 Lines | GPUTexture *GPU_texture_create_error(int dimension, bool is_array) | ||||
| type = (dimension == 2) ? (is_array ? GPU_TEXTURE_2D_ARRAY : GPU_TEXTURE_2D) : type; | type = (dimension == 2) ? (is_array ? GPU_TEXTURE_2D_ARRAY : GPU_TEXTURE_2D) : type; | ||||
| type = (dimension == 1) ? (is_array ? GPU_TEXTURE_1D_ARRAY : GPU_TEXTURE_1D) : type; | type = (dimension == 1) ? (is_array ? GPU_TEXTURE_1D_ARRAY : GPU_TEXTURE_1D) : type; | ||||
| return gpu_texture_create("invalid_tex", w, h, d, type, 1, GPU_RGBA8, pixel); | return gpu_texture_create("invalid_tex", w, h, d, type, 1, GPU_RGBA8, pixel); | ||||
| } | } | ||||
| void GPU_texture_update_mipmap(GPUTexture *tex_, | void GPU_texture_update_mipmap(GPUTexture *tex_, | ||||
| int miplvl, | int miplvl, | ||||
| eGPUDataFormat gpu_data_format, | eGPUDataFormat data_format, | ||||
| const void *pixels) | const void *pixels) | ||||
| { | { | ||||
| Texture *tex = reinterpret_cast<Texture *>(tex_); | Texture *tex = reinterpret_cast<Texture *>(tex_); | ||||
| int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0}; | int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0}; | ||||
| tex->mip_size_get(miplvl, extent); | tex->mip_size_get(miplvl, extent); | ||||
| reinterpret_cast<Texture *>(tex)->update_sub(miplvl, offset, extent, gpu_data_format, pixels); | reinterpret_cast<Texture *>(tex)->update_sub(miplvl, offset, extent, data_format, pixels); | ||||
| } | } | ||||
| void GPU_texture_update_sub(GPUTexture *tex, | void GPU_texture_update_sub(GPUTexture *tex, | ||||
| eGPUDataFormat gpu_data_format, | eGPUDataFormat data_format, | ||||
| const void *pixels, | const void *pixels, | ||||
| int offset_x, | int offset_x, | ||||
| int offset_y, | int offset_y, | ||||
| int offset_z, | int offset_z, | ||||
| int width, | int width, | ||||
| int height, | int height, | ||||
| int depth) | int depth) | ||||
| { | { | ||||
| int offset[3] = {offset_x, offset_y, offset_z}; | int offset[3] = {offset_x, offset_y, offset_z}; | ||||
| int extent[3] = {width, height, depth}; | int extent[3] = {width, height, depth}; | ||||
| reinterpret_cast<Texture *>(tex)->update_sub(0, offset, extent, gpu_data_format, pixels); | reinterpret_cast<Texture *>(tex)->update_sub(0, offset, extent, data_format, pixels); | ||||
| } | } | ||||
| void *GPU_texture_read(GPUTexture *tex_, eGPUDataFormat data_format, int miplvl) | void *GPU_texture_read(GPUTexture *tex_, eGPUDataFormat data_format, int miplvl) | ||||
| { | { | ||||
| Texture *tex = reinterpret_cast<Texture *>(tex_); | Texture *tex = reinterpret_cast<Texture *>(tex_); | ||||
| return tex->read(miplvl, data_format); | return tex->read(miplvl, data_format); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines | |||||