Bläddra i källkod

Implement online method to create a renderer-dependent texture object

Daniele Bartolini 13 år sedan
förälder
incheckning
4fa30ca198
2 ändrade filer med 39 tillägg och 51 borttagningar
  1. 23 11
      src/TextureResource.cpp
  2. 16 40
      src/TextureResource.h

+ 23 - 11
src/TextureResource.cpp

@@ -4,6 +4,8 @@
 #include "FileStream.h"
 #include "FileStream.h"
 #include <cassert>
 #include <cassert>
 #include "Allocator.h"
 #include "Allocator.h"
+#include "Device.h"
+#include "Renderer.h"
 
 
 namespace crown
 namespace crown
 {
 {
@@ -19,19 +21,15 @@ TextureResource* TextureResource::load(Allocator& allocator, ResourceArchive* ar
 	{
 	{
 		TextureResource* resource = (TextureResource*)allocator.allocate(sizeof(TextureResource));
 		TextureResource* resource = (TextureResource*)allocator.allocate(sizeof(TextureResource));
 	
 	
-		stream->read(&resource->format, sizeof(PixelFormat));
-		stream->read(&resource->width, sizeof(uint16_t));
-		stream->read(&resource->height, sizeof(uint16_t));
-		
-		stream->read(&resource->mode, sizeof(TextureMode));
-		stream->read(&resource->filter, sizeof(TextureFilter));
-		stream->read(&resource->wrap, sizeof(TextureWrap));
+		stream->read(&resource->m_format, sizeof(PixelFormat));
+		stream->read(&resource->m_width, sizeof(uint16_t));
+		stream->read(&resource->m_height, sizeof(uint16_t));
 	
 	
-		size_t size = resource->width * resource->height * Pixel::GetBytesPerPixel(resource->format);
+		size_t size = resource->m_width * resource->m_height * Pixel::GetBytesPerPixel(resource->m_format);
 
 
-		resource->data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
+		resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
 
 
-		stream->read(resource->data, size);
+		stream->read(resource->m_data, size);
 
 
 		return resource;
 		return resource;
 	}
 	}
@@ -39,13 +37,27 @@ TextureResource* TextureResource::load(Allocator& allocator, ResourceArchive* ar
 	return NULL;
 	return NULL;
 }
 }
 
 
+//-----------------------------------------------------------------------------
+void TextureResource::online(TextureResource* texture)
+{
+	assert(texture != NULL);
+
+	texture->m_render_texture = GetDevice()->GetRenderer()->load_texture(texture);
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void TextureResource::unload(Allocator& allocator, TextureResource* resource)
 void TextureResource::unload(Allocator& allocator, TextureResource* resource)
 {
 {
 	assert(resource != NULL);
 	assert(resource != NULL);
 
 
-	allocator.deallocate(resource->data);
+	allocator.deallocate(resource->m_data);
 	allocator.deallocate(resource);
 	allocator.deallocate(resource);
 }
 }
 
 
+//-----------------------------------------------------------------------------
+void TextureResource::offline()
+{
+
+}
+
 } // namespace crown
 } // namespace crown

+ 16 - 40
src/TextureResource.h

@@ -28,43 +28,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Types.h"
 #include "Resource.h"
 #include "Resource.h"
 #include "Pixel.h"
 #include "Pixel.h"
+#include "Texture.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-enum TextureMode
-{
-	TM_MODULATE	= 0,	// Multiplies texel color by the geometry color after lighting
-	TM_REPLACE	= 1,	// Replaces the fragment color with the texel color
-	TM_DECAL	= 2,	// WTF?
-	TM_BLEND	= 3,	// Blends the texel color with a constant blending color
-	TM_ADD		= 4,	// Adds the texel color to the fragment color
-	TM_COUNT
-};
-
-
-/// Enumerates the hardware filter to use when applying a texture
-enum TextureFilter
-{
-	TF_NEAREST		= 0,
-	TF_LINEAR		= 1,
-	TF_BILINEAR		= 2,
-	TF_TRILINEAR	= 3,
-	TF_ANISOTROPIC	= 4,
-	TF_COUNT
-};
-
-
-/// Enumerates the wrapping mode to use when applying a texture
-enum TextureWrap
-{
-	TW_REPEAT			= 0,
-	TW_CLAMP			= 1,
-	TW_CLAMP_TO_EDGE	= 2,
-	TW_CLAMP_TO_BORDER	= 3,
-	TW_COUNT
-};
-
 class ResourceArchive;
 class ResourceArchive;
 class Allocator;
 class Allocator;
 
 
@@ -73,19 +41,27 @@ class TextureResource
 public:
 public:
 
 
 	static TextureResource*		load(Allocator& allocator, ResourceArchive* archive, ResourceId id);
 	static TextureResource*		load(Allocator& allocator, ResourceArchive* archive, ResourceId id);
+	static void					online(TextureResource* texture);
 	static void					unload(Allocator& allocator, TextureResource* texture);
 	static void					unload(Allocator& allocator, TextureResource* texture);
+	static void					offline();
+
+public:
+
+	PixelFormat					format() const { return m_format; }
+	uint16_t					width() const { return m_width; }
+	uint16_t					height() const { return m_height; }
+	const uint8_t*				data() const { return m_data; }
 
 
 private:
 private:
 
 
-	PixelFormat					format;
-	uint16_t					width;
-	uint16_t					height;
+	PixelFormat					m_format;
+	uint16_t					m_width;
+	uint16_t					m_height;
+	uint8_t*					m_data;
 
 
-	TextureMode					mode;
-	TextureFilter				filter;
-	TextureWrap					wrap;
+public:
 
 
-	uint8_t*					data;
+	TextureId					m_render_texture;
 };
 };
 
 
 } // namespace crown
 } // namespace crown