소스 검색

move around some graphics stuff and put in copyright comments

jp9000 12 년 전
부모
커밋
543d2481f1

+ 0 - 14
libobs-d3d11/GS_D3D11Texture2D.cpp

@@ -18,11 +18,6 @@
 #include "util/base.h"
 #include "util/base.h"
 #include "GS_D3D11SubSystem.hpp"
 #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,
 static inline uint32_t numActualLevels(uint32_t levels, uint32_t width,
 		uint32_t height)
 		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),
 	  isRenderTarget  ((flags & GS_RENDERTARGET) != 0),
 	  genMipmaps      ((flags & GS_BUILDMIPMAPS) != 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);
 	InitTexture(data);
 	InitResourceView();
 	InitResourceView();
 
 

+ 17 - 0
libobs-opengl/gl-exports.h

@@ -1,3 +1,20 @@
+/******************************************************************************
+    Copyright (C) 2013 by Hugh Bailey <[email protected]>
+
+    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 <http://www.gnu.org/licenses/>.
+******************************************************************************/
+
 #ifndef GS_GLEXPORTS
 #ifndef GS_GLEXPORTS
 #define GS_GLEXPORTS
 #define GS_GLEXPORTS
 
 

+ 17 - 0
libobs-opengl/gl-helpers.h

@@ -1,3 +1,20 @@
+/******************************************************************************
+    Copyright (C) 2013 by Hugh Bailey <[email protected]>
+
+    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 <http://www.gnu.org/licenses/>.
+******************************************************************************/
+
 #ifndef GL_HELPERS_H
 #ifndef GL_HELPERS_H
 #define GL_HELPERS_H
 #define GL_HELPERS_H
 
 

+ 17 - 0
libobs-opengl/gl-subsystem.c

@@ -1,3 +1,20 @@
+/******************************************************************************
+    Copyright (C) 2013 by Hugh Bailey <[email protected]>
+
+    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 <http://www.gnu.org/licenses/>.
+******************************************************************************/
+
 #include "gl-subsystem.h"
 #include "gl-subsystem.h"
 #include "gl-exports.h"
 #include "gl-exports.h"
 
 

+ 1 - 0
libobs-opengl/gl-subsystem.h

@@ -103,6 +103,7 @@ struct gs_texture_2d {
 
 
 	uint32_t             width;
 	uint32_t             width;
 	uint32_t             height;
 	uint32_t             height;
+	bool                 gen_mipmaps;
 };
 };
 
 
 struct gs_texture_cube {
 struct gs_texture_cube {

+ 18 - 0
libobs-opengl/gl-texture2d.c

@@ -1,3 +1,20 @@
+/******************************************************************************
+    Copyright (C) 2013 by Hugh Bailey <[email protected]>
+
+    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 <http://www.gnu.org/licenses/>.
+******************************************************************************/
+
 #include "gl-subsystem.h"
 #include "gl-subsystem.h"
 
 
 static inline bool upload_texture_data(struct gs_texture_2d *tex, void **data)
 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));
 	struct gs_texture_2d *tex = bmalloc(sizeof(struct gs_texture_2d));
 	memset(tex, 0, 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.type               = GS_TEXTURE_2D;
 	tex->base.format             = color_format;
 	tex->base.format             = color_format;
 	tex->base.gl_format          = convert_gs_format(color_format);
 	tex->base.gl_format          = convert_gs_format(color_format);

+ 17 - 0
libobs-opengl/gl-windows.c

@@ -1,3 +1,20 @@
+/******************************************************************************
+    Copyright (C) 2013 by Hugh Bailey <[email protected]>
+
+    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 <http://www.gnu.org/licenses/>.
+******************************************************************************/
+
 #define WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <windows.h>
 
 

+ 46 - 0
libobs/graphics/graphics.c

@@ -725,11 +725,36 @@ uint32_t gs_getheight(void)
 	return graphics->exports.device_getheight(graphics->device);
 	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,
 texture_t gs_create_texture(uint32_t width, uint32_t height,
 		enum gs_color_format color_format, uint32_t levels, void **data,
 		enum gs_color_format color_format, uint32_t levels, void **data,
 		uint32_t flags)
 		uint32_t flags)
 {
 {
 	graphics_t graphics = thread_graphics;
 	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,
 	return graphics->exports.device_create_texture(graphics->device,
 			width, height, color_format, levels, data, flags);
 			width, height, color_format, levels, data, flags);
 }
 }
@@ -739,6 +764,27 @@ texture_t gs_create_cubetexture(uint32_t size,
 		void **data, uint32_t flags)
 		void **data, uint32_t flags)
 {
 {
 	graphics_t graphics = thread_graphics;
 	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,
 	return graphics->exports.device_create_cubetexture(graphics->device,
 			size, color_format, levels, data, flags);
 			size, color_format, levels, data, flags);
 }
 }