Преглед на файлове

Made mipmaps not generate for Screen mesh textures

Ivan Safrin преди 14 години
родител
ревизия
c2b21a5e41

+ 1 - 1
Core/Contents/Include/PolyGLRenderer.h

@@ -117,7 +117,7 @@ namespace Polycode {
 		void EndRender();
 		
 		Cubemap *createCubemap(Texture *t0, Texture *t1, Texture *t2, Texture *t3, Texture *t4, Texture *t5);
-		Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, int type = Image::IMAGE_RGBA);
+		Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, bool createMipmaps, int type = Image::IMAGE_RGBA);
 		void destroyTexture(Texture *texture);		
 		Texture *createFramebufferTexture(unsigned int width, unsigned int height);
 		void createRenderTextures(Texture **colorBuffer, Texture **depthBuffer, int width, int height);

+ 1 - 1
Core/Contents/Include/PolyGLTexture.h

@@ -45,7 +45,7 @@ namespace Polycode {
 	class _PolyExport OpenGLTexture : public Texture {
 		public:
 			OpenGLTexture(unsigned int width, unsigned int height);
-			OpenGLTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, int filteringMode, int type);
+			OpenGLTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, bool createMipmaps, int filteringMode, int type);
 			virtual ~OpenGLTexture();
 			
 			void recreateFromImageData();

+ 4 - 4
Core/Contents/Include/PolyMaterialManager.h

@@ -51,10 +51,10 @@ namespace Polycode {
 			* Creates a new framebuffer texture.
 			*/ 
 			Texture *createFramebufferTexture(int width, int height, int type);
-			Texture *createTexture(int width, int height, char *imageData, bool clamp=true, int type=Image::IMAGE_RGBA);
-			Texture *createNewTexture(int width, int height, bool clamp=true, int type=Image::IMAGE_RGBA);
-			Texture *createTextureFromImage(Image *image, bool clamp=true);
-			Texture *createTextureFromFile(const String& fileName, bool clamp=true);
+			Texture *createTexture(int width, int height, char *imageData, bool clamp=true, bool createMipmaps = true, int type=Image::IMAGE_RGBA);
+			Texture *createNewTexture(int width, int height, bool clamp=true, bool createMipmaps = true, int type=Image::IMAGE_RGBA);
+			Texture *createTextureFromImage(Image *image, bool clamp=true, bool createMipmaps = true);
+			Texture *createTextureFromFile(const String& fileName, bool clamp=true, bool createMipmaps = true);
 			void deleteTexture(Texture *texture);
 		
 			void reloadTextures();

+ 1 - 1
Core/Contents/Include/PolyRenderer.h

@@ -86,7 +86,7 @@ namespace Polycode {
 		virtual void EndRender() = 0;
 		
 		virtual Cubemap *createCubemap(Texture *t0, Texture *t1, Texture *t2, Texture *t3, Texture *t4, Texture *t5) = 0;		
-		virtual Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, int type=Image::IMAGE_RGBA) = 0;
+		virtual Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, bool createMipmaps, int type=Image::IMAGE_RGBA) = 0;
 		virtual void destroyTexture(Texture *texture) = 0;
 		virtual void createRenderTextures(Texture **colorBuffer, Texture **depthBuffer, int width, int height) = 0;
 		

+ 2 - 1
Core/Contents/Include/PolyTexture.h

@@ -30,7 +30,7 @@ namespace Polycode {
 
 	class _PolyExport Texture : public Resource {
 		public:
-		Texture(unsigned int width, unsigned int height, char *textureData,bool clamp, int type=Image::IMAGE_RGBA);
+		Texture(unsigned int width, unsigned int height, char *textureData,bool clamp, bool createMipmaps, int type=Image::IMAGE_RGBA);
 			Texture(Image *image);
 			virtual ~Texture();
 
@@ -62,6 +62,7 @@ namespace Polycode {
 			int pixelSize;
 			int filteringMode;
 		
+			bool createMipmaps;
 			int width;
 			int height;
 			String resourcePath;

+ 2 - 0
Core/Contents/Include/PolyTimer.h

@@ -64,6 +64,8 @@ namespace Polycode {
 		* Returns the time elapsed in floating point microseconds.
 		*/
 		Number getElapsedf();		
+		
+		void setTimerInterval(int msecs);
 
 		static const int EVENT_TRIGGER = 0;
 		

+ 2 - 2
Core/Contents/Source/PolyGLRenderer.cpp

@@ -655,8 +655,8 @@ Cubemap *OpenGLRenderer::createCubemap(Texture *t0, Texture *t1, Texture *t2, Te
 	return newCubemap;
 }
 
-Texture *OpenGLRenderer::createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, int type) {
-	OpenGLTexture *newTexture = new OpenGLTexture(width, height, textureData, clamp, textureFilteringMode, type);	
+Texture *OpenGLRenderer::createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, bool createMipmaps, int type) {
+	OpenGLTexture *newTexture = new OpenGLTexture(width, height, textureData, clamp, createMipmaps, textureFilteringMode, type);
 	return newTexture;
 }
 

+ 15 - 7
Core/Contents/Source/PolyGLTexture.cpp

@@ -26,7 +26,7 @@
 
 using namespace Polycode;
 
-OpenGLTexture::OpenGLTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, int filteringMode, int type) : Texture(width, height, textureData,clamp, type) {
+OpenGLTexture::OpenGLTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, bool createMipmaps, int filteringMode, int type) : Texture(width, height, textureData,clamp, createMipmaps, type) {
 	this->filteringMode = filteringMode;
 	glTextureLoaded = false;
 	frameBufferID = 999999;
@@ -62,11 +62,19 @@ void OpenGLTexture::recreateFromImageData() {
 				glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
 			}
 		
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-			if(textureData) {
-				gluBuild2DMipmaps(GL_TEXTURE_2D, glTextureType, width, height, glTextureType, GL_UNSIGNED_BYTE, textureData );
-			}			
+			if(createMipmaps) {
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+				if(textureData) {
+					gluBuild2DMipmaps(GL_TEXTURE_2D, glTextureType, width, height, glTextureType, GL_UNSIGNED_BYTE, textureData );
+				}
+			} else {
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);		
+				if(textureData) {
+					glTexImage2D(GL_TEXTURE_2D, 0, glTextureType, width, height, 0, glTextureType, GL_UNSIGNED_BYTE, textureData);							
+				}						
+			}
 			break;
 		case Renderer::TEX_FILTERING_NEAREST:
 			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -80,7 +88,7 @@ void OpenGLTexture::recreateFromImageData() {
 	glTextureLoaded = true;
 }
 
-OpenGLTexture::OpenGLTexture(unsigned int width, unsigned int height) : Texture(width, height, NULL ,true) {
+OpenGLTexture::OpenGLTexture(unsigned int width, unsigned int height) : Texture(width, height, NULL ,true, true) {
 
 }
 

+ 7 - 7
Core/Contents/Source/PolyMaterialManager.cpp

@@ -84,7 +84,7 @@ void MaterialManager::addShaderModule(PolycodeShaderModule *module) {
 	shaderModules.push_back(module);
 }
 
-Texture *MaterialManager::createTextureFromFile(const String& fileName, bool clamp) {
+Texture *MaterialManager::createTextureFromFile(const String& fileName, bool clamp, bool createMipmaps) {
 	Texture *newTexture;
 	newTexture = getTextureByResourcePath(fileName);
 	if(newTexture) {
@@ -114,24 +114,24 @@ Texture *MaterialManager::createFramebufferTexture(int width, int height, int ty
 	return newTexture;
 }
 
-Texture *MaterialManager::createNewTexture(int width, int height, bool clamp, int type) {
+Texture *MaterialManager::createNewTexture(int width, int height, bool clamp, bool createMipmaps, int type) {
 	Image *newImage = new Image(width, height, type);
 	newImage->fill(1,1,1,1);
-	Texture *retTexture = createTextureFromImage(newImage, clamp);
+	Texture *retTexture = createTextureFromImage(newImage, clamp, createMipmaps);
 	delete newImage;
 	return retTexture;
 	
 }
 
-Texture *MaterialManager::createTexture(int width, int height, char *imageData, bool clamp, int type) {
-	Texture *newTexture = CoreServices::getInstance()->getRenderer()->createTexture(width, height, imageData,clamp, type);
+Texture *MaterialManager::createTexture(int width, int height, char *imageData, bool clamp, bool createMipmaps, int type) {
+	Texture *newTexture = CoreServices::getInstance()->getRenderer()->createTexture(width, height, imageData,clamp, createMipmaps, type);
 	textures.push_back(newTexture);
 	return newTexture;
 }
 
-Texture *MaterialManager::createTextureFromImage(Image *image, bool clamp) {
+Texture *MaterialManager::createTextureFromImage(Image *image, bool clamp, bool createMipmaps) {
 	Texture *newTexture;
-	newTexture = createTexture(image->getWidth(), image->getHeight(), image->getPixels(),clamp, image->getType());
+	newTexture = createTexture(image->getWidth(), image->getHeight(), image->getPixels(),clamp, createMipmaps, image->getType());
 	return newTexture; 
 }
 

+ 1 - 1
Core/Contents/Source/PolyScreenLabel.cpp

@@ -77,7 +77,7 @@ void ScreenLabel::setText(const String& newText) {
 	if(!label->getFont()->isValid())
 		return;				
 	
-	texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromImage(label);
+	texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromImage(label, true, false);
 	width = label->getWidth();
 	height = label->getHeight();
 	setShapeSize(width, height);

+ 2 - 2
Core/Contents/Source/PolyScreenMesh.cpp

@@ -54,11 +54,11 @@ void ScreenMesh::setTexture(Texture *texture) {
 }
 
 void ScreenMesh::loadTexture(const String& fileName) {
-	texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(fileName);
+	texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(fileName, true, false);
 }
 
 void ScreenMesh::loadTexture(Image *image) {
-	texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromImage(image);
+	texture = CoreServices::getInstance()->getMaterialManager()->createTextureFromImage(image, true, false);
 }
 
 void ScreenMesh::Render() {	

+ 2 - 1
Core/Contents/Source/PolyTexture.cpp

@@ -25,10 +25,11 @@
 
 using namespace Polycode;
 
-Texture::Texture(unsigned int width, unsigned int height, char *textureData,bool clamp, int type) : Resource(Resource::RESOURCE_TEXTURE) {
+Texture::Texture(unsigned int width, unsigned int height, char *textureData,bool clamp, bool createMipmaps, int type) : Resource(Resource::RESOURCE_TEXTURE) {
 	this->width = width;
 	this->height = height;
 	this->clamp = clamp;
+	this->createMipmaps = createMipmaps;
 	
 	switch (type) {
 		case Image::IMAGE_RGB:

+ 4 - 0
Core/Contents/Source/PolyTimer.cpp

@@ -35,6 +35,10 @@ Timer::Timer(bool triggerMode, int msecs) : EventDispatcher() {
 	CoreServices::getInstance()->getTimerManager()->addTimer(this);
 }
 
+void Timer::setTimerInterval(int msecs) {
+	this->msecs = msecs;
+}
+
 Timer::~Timer() {
 	CoreServices::getInstance()->getTimerManager()->removeTimer(this);
 }