diff --git a/libobs-d3d11/GS_D3D11Texture2D.cpp b/libobs-d3d11/GS_D3D11Texture2D.cpp index 2ae5e54ed..555bcc4fa 100644 --- a/libobs-d3d11/GS_D3D11Texture2D.cpp +++ b/libobs-d3d11/GS_D3D11Texture2D.cpp @@ -18,11 +18,6 @@ #include "util/base.h" #include "GS_D3D11SubSystem.hpp" -static inline bool IsPow2(uint32_t num) -{ - return num >= 2 && (num & (num-1)) == 0; -} - static inline uint32_t numActualLevels(uint32_t levels, uint32_t width, uint32_t height) { @@ -162,15 +157,6 @@ gs_texture_2d::gs_texture_2d(device_t device, uint32_t width, uint32_t height, isRenderTarget ((flags & GS_RENDERTARGET) != 0), genMipmaps ((flags & GS_BUILDMIPMAPS) != 0) { - bool hasMips = genMipmaps || levels != 1; - if (hasMips && (!IsPow2(width) || !IsPow2(height))) { - blog(LOG_WARNING, "Cannot use mipmaps with a " - "non-power-of-two texture. Disabling " - "mipmaps for this texture."); - genMipmaps = false; - this->levels = 1; - } - InitTexture(data); InitResourceView(); diff --git a/libobs-opengl/gl-exports.h b/libobs-opengl/gl-exports.h index 0b67c7ecd..d366cccd4 100644 --- a/libobs-opengl/gl-exports.h +++ b/libobs-opengl/gl-exports.h @@ -1,3 +1,20 @@ +/****************************************************************************** + Copyright (C) 2013 by Hugh Bailey + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +******************************************************************************/ + #ifndef GS_GLEXPORTS #define GS_GLEXPORTS diff --git a/libobs-opengl/gl-helpers.h b/libobs-opengl/gl-helpers.h index 325f1d534..ea5f98237 100644 --- a/libobs-opengl/gl-helpers.h +++ b/libobs-opengl/gl-helpers.h @@ -1,3 +1,20 @@ +/****************************************************************************** + Copyright (C) 2013 by Hugh Bailey + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +******************************************************************************/ + #ifndef GL_HELPERS_H #define GL_HELPERS_H diff --git a/libobs-opengl/gl-subsystem.c b/libobs-opengl/gl-subsystem.c index 90d4588d5..ae2e6559b 100644 --- a/libobs-opengl/gl-subsystem.c +++ b/libobs-opengl/gl-subsystem.c @@ -1,3 +1,20 @@ +/****************************************************************************** + Copyright (C) 2013 by Hugh Bailey + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +******************************************************************************/ + #include "gl-subsystem.h" #include "gl-exports.h" diff --git a/libobs-opengl/gl-subsystem.h b/libobs-opengl/gl-subsystem.h index 8716de7d4..687812347 100644 --- a/libobs-opengl/gl-subsystem.h +++ b/libobs-opengl/gl-subsystem.h @@ -103,6 +103,7 @@ struct gs_texture_2d { uint32_t width; uint32_t height; + bool gen_mipmaps; }; struct gs_texture_cube { diff --git a/libobs-opengl/gl-texture2d.c b/libobs-opengl/gl-texture2d.c index 559eef5bf..ba9de4c79 100644 --- a/libobs-opengl/gl-texture2d.c +++ b/libobs-opengl/gl-texture2d.c @@ -1,3 +1,20 @@ +/****************************************************************************** + Copyright (C) 2013 by Hugh Bailey + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +******************************************************************************/ + #include "gl-subsystem.h" static inline bool upload_texture_data(struct gs_texture_2d *tex, void **data) @@ -20,6 +37,7 @@ texture_t device_create_texture(device_t device, uint32_t width, struct gs_texture_2d *tex = bmalloc(sizeof(struct gs_texture_2d)); memset(tex, 0, sizeof(struct gs_texture_2d)); + tex->base.device = device; tex->base.type = GS_TEXTURE_2D; tex->base.format = color_format; tex->base.gl_format = convert_gs_format(color_format); diff --git a/libobs-opengl/gl-windows.c b/libobs-opengl/gl-windows.c index 40658e55d..6418d9786 100644 --- a/libobs-opengl/gl-windows.c +++ b/libobs-opengl/gl-windows.c @@ -1,3 +1,20 @@ +/****************************************************************************** + Copyright (C) 2013 by Hugh Bailey + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +******************************************************************************/ + #define WIN32_LEAN_AND_MEAN #include diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 4d5971f66..f32eb50d3 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -725,11 +725,36 @@ uint32_t gs_getheight(void) return graphics->exports.device_getheight(graphics->device); } +static inline bool is_pow2(uint32_t size) +{ + return size >= 2 && (size & (size-1)) == 0; +} + texture_t gs_create_texture(uint32_t width, uint32_t height, enum gs_color_format color_format, uint32_t levels, void **data, uint32_t flags) { graphics_t graphics = thread_graphics; + bool pow2tex = is_pow2(width) && is_pow2(height); + bool uses_mipmaps = (flags & GS_BUILDMIPMAPS || levels != 1); + + if (uses_mipmaps && !pow2tex) { + blog(LOG_WARNING, "Cannot use mipmaps with a " + "non-power-of-two texture. Disabling " + "mipmaps for this texture."); + + uses_mipmaps = false; + flags &= ~GS_BUILDMIPMAPS; + levels = 1; + } + + if (uses_mipmaps && flags & GS_RENDERTARGET) { + blog(LOG_WARNING, "Cannot use mipmaps with render targets. " + "Disabling mipmaps for this texture."); + flags &= ~GS_BUILDMIPMAPS; + levels = 1; + } + return graphics->exports.device_create_texture(graphics->device, width, height, color_format, levels, data, flags); } @@ -739,6 +764,27 @@ texture_t gs_create_cubetexture(uint32_t size, void **data, uint32_t flags) { graphics_t graphics = thread_graphics; + bool pow2tex = is_pow2(size); + bool uses_mipmaps = (flags & GS_BUILDMIPMAPS || levels != 1); + + if (uses_mipmaps && !pow2tex) { + blog(LOG_WARNING, "Cannot use mipmaps with a " + "non-power-of-two texture. Disabling " + "mipmaps for this texture."); + + uses_mipmaps = false; + flags &= ~GS_BUILDMIPMAPS; + levels = 1; + } + + if (uses_mipmaps && flags & GS_RENDERTARGET) { + blog(LOG_WARNING, "Cannot use mipmaps with render targets. " + "Disabling mipmaps for this texture."); + flags &= ~GS_BUILDMIPMAPS; + levels = 1; + data = NULL; + } + return graphics->exports.device_create_cubetexture(graphics->device, size, color_format, levels, data, flags); }