- Clean-up OGL ES2 driver (mainly stuff related to textures).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@4481 dfc29bdd-3216-0410-991c-e03cc46cb475
master
nadro 2013-03-19 15:54:47 +00:00
parent f97abe8a38
commit 919c037d05
7 changed files with 936 additions and 864 deletions

View File

@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt
# Project target.
target=Google Inc.:Google APIs:16
target=android-10

View File

@ -220,7 +220,7 @@ namespace video
#endif
os::Printer::log("Creating EglContext...");
EglContext = eglCreateContext(EglDisplay, config, EGL_NO_CONTEXT, contextAttrib);
if (testEGLError())
if (EGL_NO_CONTEXT == EglContext)
{
os::Printer::log("FAILED\n");
os::Printer::log("Could not create Context for OpenGL-ES2 display.");
@ -349,9 +349,9 @@ namespace video
DriverAttributes->setAttribute("MaxTextures", MaxTextureUnits);
DriverAttributes->setAttribute("MaxSupportedTextures", MaxSupportedTextures);
DriverAttributes->setAttribute("MaxLights", MaxLights);
// DriverAttributes->setAttribute("MaxLights", MaxLights);
DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy);
DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes);
// DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes);
// DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers);
// DriverAttributes->setAttribute("MaxMultipleRenderTargets", MaxMultipleRenderTargets);
DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices);
@ -363,7 +363,7 @@ namespace video
glPixelStorei(GL_PACK_ALIGNMENT, 1);
// Reset The Current Viewport
glViewport(0, 0, screenSize.Width, screenSize.Height);
BridgeCalls->setViewport(core::rect<s32>(0, 0, screenSize.Width, screenSize.Height));
UserClipPlane.reallocate(0);
@ -1743,7 +1743,7 @@ namespace video
//! returns a device dependent texture from a software surface (IImage)
video::ITexture* COGLES2Driver::createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData)
{
return new COGLES2Texture(surface, name, this);
return new COGLES2Texture(surface, name, mipmapData, this);
}
@ -2204,7 +2204,7 @@ namespace video
//! returns the maximal amount of dynamic lights the device can handle
u32 COGLES2Driver::getMaximalDynamicLightAmount() const
{
return MaxLights;
return 8;
}
@ -2228,11 +2228,7 @@ namespace video
vp.clipAgainst(rendert);
if (vp.getHeight() > 0 && vp.getWidth() > 0)
{
glViewport(vp.UpperLeftCorner.X,
getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(),
vp.getWidth(), vp.getHeight());
}
BridgeCalls->setViewport(core::rect<s32>(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight()));
ViewPort = vp;
testGLError();
@ -2404,7 +2400,7 @@ namespace video
void COGLES2Driver::OnResize(const core::dimension2d<u32>& size)
{
CNullDriver::OnResize(size);
glViewport(0, 0, size.Width, size.Height);
BridgeCalls->setViewport(core::rect<s32>(0, 0, size.Width, size.Height));
testGLError();
}
@ -2541,9 +2537,6 @@ namespace video
video::ITexture* rtt = 0;
// if driver supports FrameBufferObjects, use them
if (queryFeature(EVDF_FRAMEBUFFER_OBJECT))
{
rtt = new COGLES2FBOTexture(size, name, this, format);
if (rtt)
{
@ -2567,17 +2560,6 @@ namespace video
rtt=0;
}
}
}
else
{
// the simple texture is only possible for size <= screensize
// we try to find an optimal size with the original constraints
core::dimension2du destSize(core::min_(size.Width, ScreenSize.Width), core::min_(size.Height, ScreenSize.Height));
destSize = destSize.getOptimalSize((size == size.getOptimalSize()), false, false);
rtt = addTexture(destSize, name, ECF_A8R8G8B8);
if (rtt)
static_cast<video::COGLES2Texture*>(rtt)->setIsRenderTarget(true);
}
//restore mip-mapping
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, generateMipLevels);
@ -2617,13 +2599,14 @@ namespace video
if (texture)
{
// we want to set a new target. so do this.
BridgeCalls->setViewport(core::rect<s32>(0, 0, texture->getSize().Width, texture->getSize().Height));
RenderTargetTexture = static_cast<COGLES2Texture*>(texture);
RenderTargetTexture->bindRTT();
CurrentRendertargetSize = texture->getSize();
}
else
{
glViewport(0, 0, ScreenSize.Width, ScreenSize.Height);
BridgeCalls->setViewport(core::rect<s32>(0, 0, ScreenSize.Width, ScreenSize.Height));
RenderTargetTexture = 0;
CurrentRendertargetSize = core::dimension2d<u32>(0, 0);
}
@ -2816,9 +2799,6 @@ namespace video
//! Enable/disable a clipping plane.
void COGLES2Driver::enableClipPlane(u32 index, bool enable)
{
if (index >= MaxUserClipPlanes)
return;
UserClipPlane[index].Enabled = enable;
}
@ -2861,6 +2841,38 @@ namespace video
return r;
}
GLenum COGLES2Driver::getZBufferBits() const
{
/*#if defined(GL_OES_depth24)
if (Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_OES_depth24))
InternalFormat = GL_DEPTH_COMPONENT24_OES;
else
#endif
#if defined(GL_OES_depth32)
if (Driver->queryOpenGLFeature(COGLES2ExtensionHandler::IRR_OES_depth32))
InternalFormat = GL_DEPTH_COMPONENT32_OES;
else
#endif*/
GLenum bits = GL_DEPTH_COMPONENT16;//0;
/*switch (Params.ZBufferBits)
{
case 16:
bits = GL_DEPTH_COMPONENT16;
break;
case 24:
bits = GL_DEPTH_COMPONENT24;
break;
case 32:
bits = GL_DEPTH_COMPONENT32;
break;
default:
bits = GL_DEPTH_COMPONENT;
break;
}*/
return bits;
}
const SMaterial& COGLES2Driver::getCurrentMaterial() const
{
return Material;
@ -2875,7 +2887,7 @@ namespace video
BlendSource(GL_ONE), BlendDestination(GL_ZERO), Blend(false),
CullFaceMode(GL_BACK), CullFace(false),
DepthFunc(GL_LESS), DepthMask(true), DepthTest(false),
Program(0), ActiveTexture(GL_TEXTURE0)
Program(0), ActiveTexture(GL_TEXTURE0), Viewport(core::rect<s32>(0, 0, 0, 0))
{
// Initial OpenGL values from specification.
@ -3003,13 +3015,22 @@ namespace video
setActiveTexture(GL_TEXTURE0 + stage);
if(Driver->CurrentTexture[stage])
glBindTexture(GL_TEXTURE_2D, static_cast<const COGLES2Texture*>(Driver->CurrentTexture[stage])->getOGLES2TextureName());
glBindTexture(GL_TEXTURE_2D, static_cast<const COGLES2Texture*>(Driver->CurrentTexture[stage])->getOpenGLTextureName());
Texture[stage] = Driver->CurrentTexture[stage];
}
}
}
void COGLES2CallBridge::setViewport(const core::rect<s32>& viewport)
{
if (Viewport != viewport)
{
glViewport(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y);
Viewport = viewport;
}
}
} // end namespace
} // end namespace

View File

@ -58,6 +58,7 @@ namespace video
class COGLES2Driver : public CNullDriver, public IMaterialRendererServices, public COGLES2ExtensionHandler
{
friend class COGLES2CallBridge;
friend class COGLES2Texture;
public:
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_SDL_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_CONSOLE_DEVICE_)
@ -361,6 +362,9 @@ namespace video
//! Convert E_BLEND_FACTOR to OpenGL equivalent
GLenum getGLBlend(E_BLEND_FACTOR factor) const;
//! Get ZBuffer bits.
GLenum getZBufferBits() const;
//! Get current material.
const SMaterial& getCurrentMaterial() const;
@ -504,6 +508,10 @@ namespace video
void setTexture(u32 stage);
// Viewport calls.
void setViewport(const core::rect<s32>& viewport);
private:
COGLES2Driver* Driver;
@ -523,6 +531,8 @@ namespace video
GLenum ActiveTexture;
const ITexture* Texture[MATERIAL_MAX_TEXTURES];
core::rect<s32> Viewport;
};
} // end namespace video

View File

@ -160,9 +160,9 @@ namespace video
COGLES2ExtensionHandler::COGLES2ExtensionHandler() :
EGLVersion(0), Version(0), MaxTextureUnits(0), MaxSupportedTextures(0),
MaxLights(0), MaxAnisotropy(1), MaxUserClipPlanes(6), MaxTextureSize(1),
MaxIndices(0xffff), MaxTextureLODBias(0.f), MultiTextureExtension(false),
MultiSamplingExtension(false), StencilBuffer(false)
MaxAnisotropy(1), MaxTextureSize(1),
MaxIndices(0xffff), MaxTextureLODBias(0.f),
StencilBuffer(false)
{
for (u32 i=0; i<IRR_OGLES2_Feature_Count; ++i)
FeatureAvailable[i] = false;
@ -227,26 +227,30 @@ namespace video
delete [] str;
}
GLint val = 0;
GLint val=0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &val);
MaxSupportedTextures = core::min_(MATERIAL_MAX_TEXTURES, static_cast<u32>(val));
MultiTextureExtension = true;
//TODO : OpenGL ES 2.0 Port
//glGetIntegerv(GL_MAX_LIGHTS, &val);
MaxLights = 8;
#ifdef GL_EXT_texture_filter_anisotropic
#ifdef GL_EXT_texture_filter_anisotropic
if (FeatureAvailable[IRR_EXT_texture_filter_anisotropic])
{
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
MaxAnisotropy = static_cast<u8>(val);
}
#endif
#endif
#ifdef GL_MAX_ELEMENTS_INDICES
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val);
MaxIndices=val;
#endif
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val);
MaxTextureSize=static_cast<u32>(val);
#ifdef GL_EXT_texture_lod_bias
#ifdef GL_EXT_texture_lod_bias
if (FeatureAvailable[IRR_EXT_texture_lod_bias])
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias);
#endif
#endif
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
MaxTextureUnits = core::min_(MaxSupportedTextures, static_cast<u8>(MATERIAL_MAX_TEXTURES));
}

View File

@ -190,9 +190,7 @@ namespace video
{
case EVDF_RENDER_TO_TARGET:
case EVDF_HARDWARE_TL:
return true;
case EVDF_MULTITEXTURE:
return MultiTextureExtension;
case EVDF_BILINEAR_FILTER:
case EVDF_MIP_MAP:
case EVDF_MIP_MAP_AUTO_UPDATE:
@ -235,15 +233,14 @@ namespace video
u16 Version;
u8 MaxTextureUnits;
u8 MaxSupportedTextures;
u8 MaxLights;
u8 MaxAnisotropy;
u8 MaxUserClipPlanes;
u32 MaxTextureSize;
u32 MaxIndices;
u32 MaxTextureSize;
f32 MaxTextureLODBias;
bool MultiTextureExtension;
bool MultiSamplingExtension;
//! Minimal and maximal supported thickness for lines without smoothing
GLfloat DimAliasedLine[2];
//! Minimal and maximal supported thickness for points without smoothing
GLfloat DimAliasedPoint[2];
bool StencilBuffer;
bool FeatureAvailable[IRR_OGLES2_Feature_Count];
};

File diff suppressed because it is too large Load Diff

View File

@ -8,24 +8,31 @@
#ifndef __C_OGLES2_TEXTURE_H_INCLUDED__
#define __C_OGLES2_TEXTURE_H_INCLUDED__
#include "SMaterialLayer.h"
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include <OpenGLES/ES2/gl.h>
#else
#include <GLES2/gl2.h>
#endif
#include "ITexture.h"
#include "IImage.h"
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OGLES2_
#include "SMaterialLayer.h"
namespace irr
{
namespace video
{
class COGLES2Driver;
class COGLES2Driver;
//! OGLES2 texture.
class COGLES2Texture : public ITexture
{
public:
//! OpenGL ES 2.0 texture.
class COGLES2Texture : public ITexture
{
public:
//! Cache structure.
struct SStatesCache
@ -47,7 +54,7 @@ namespace video
};
//! constructor
COGLES2Texture(IImage* surface, const io::path& name, COGLES2Driver* driver = 0);
COGLES2Texture(IImage* surface, const io::path& name, void* mipmapData=0, COGLES2Driver* driver=0);
//! destructor
virtual ~COGLES2Texture();
@ -74,12 +81,14 @@ namespace video
virtual u32 getPitch() const;
//! return open gl texture name
u32 getOGLES2TextureName() const;
GLuint getOpenGLTextureName() const;
//! return whether this texture has mipmaps
virtual bool hasMipMaps() const;
//! Regenerates the mip map levels of the texture.
/** Useful after locking and modifying the texture
\param mipmapData Pointer to raw mipmap data, including all necessary mip levels, in the same format as the main texture image. If not set the mipmaps are derived from the main image. */
virtual void regenerateMipMapLevels(void* mipmapData=0);
//! Is it a render target?
@ -89,10 +98,10 @@ namespace video
virtual bool isFrameBufferObject() const;
//! Bind RenderTargetTexture
void bindRTT();
virtual void bindRTT();
//! Unbind RenderTargetTexture
void unbindRTT();
virtual void unbindRTT();
//! sets whether this texture is intended to be used as a render target.
void setIsRenderTarget(bool isTarget);
@ -100,7 +109,7 @@ namespace video
//! Get an access to texture states cache.
SStatesCache& getStatesCache() const;
protected:
protected:
//! protected constructor with basic setup, no GL texture name created, for derived classes
COGLES2Texture(const io::path& name, COGLES2Driver* driver);
@ -108,38 +117,45 @@ namespace video
//! get the desired color format based on texture creation flags and the input format.
ECOLOR_FORMAT getBestColorFormat(ECOLOR_FORMAT format);
//! convert the image into an internal image with better properties for this driver.
void getImageData(IImage* image);
//! get important numbers of the image and hw texture
void getImageValues(IImage* image);
//! copies the the texture into an open gl texture.
void copyTexture(bool newTexture = true);
//! copies the texture into an OpenGL texture.
/** \param newTexture True if method is called for a newly created texture for the first time. Otherwise call with false to improve memory handling.
\param mipmapData Pointer to raw mipmap data, including all necessary mip levels, in the same format as the main texture image.
\param mipLevel If set to non-zero, only that specific miplevel is updated, using the MipImage member. */
void uploadTexture(bool newTexture=false, void* mipmapData=0, u32 mipLevel=0);
core::dimension2d<u32> ImageSize;
core::dimension2d<u32> TextureSize;
ECOLOR_FORMAT ColorFormat;
COGLES2Driver* Driver;
IImage* Image;
IImage* MipImage;
u32 TextureName;
s32 InternalFormat;
u32 PixelFormat;
u32 PixelType;
GLuint TextureName;
GLint InternalFormat;
GLenum PixelFormat;
GLenum PixelType;
u8 MipLevelStored;
bool HasMipMaps;
bool IsRenderTarget;
bool AutomaticMipmapUpdate;
bool UseStencil;
bool ReadOnlyLock;
bool KeepImage;
mutable SStatesCache StatesCache;
};
};
//! OGLES2 FBO texture.
class COGLES2FBOTexture : public COGLES2Texture
{
public:
//! OpenGL ES 2.0 FBO texture.
class COGLES2FBOTexture : public COGLES2Texture
{
public:
//! FrameBufferObject constructor
COGLES2FBOTexture(const core::dimension2d<u32>& size, const io::path& name, COGLES2Driver* driver = 0, ECOLOR_FORMAT format = ECF_UNKNOWN);
COGLES2FBOTexture(const core::dimension2d<u32>& size, const io::path& name,
COGLES2Driver* driver = 0, const ECOLOR_FORMAT format = ECF_UNKNOWN);
//! destructor
virtual ~COGLES2FBOTexture();
@ -154,17 +170,17 @@ namespace video
virtual void unbindRTT();
ITexture* DepthTexture;
protected:
u32 ColorFrameBuffer;
};
protected:
GLuint ColorFrameBuffer;
};
//! OGLES2 FBO depth texture.
class COGLES2FBODepthTexture : public COGLES2FBOTexture
{
public:
//! OpenGL ES 2.0 FBO depth texture.
class COGLES2FBODepthTexture : public COGLES2Texture
{
public:
//! FrameBufferObject depth constructor
COGLES2FBODepthTexture(const core::dimension2d<u32>& size, const io::path& name, COGLES2Driver* driver = 0, bool useStencil = false);
COGLES2FBODepthTexture(const core::dimension2d<u32>& size, const io::path& name, COGLES2Driver* driver=0, bool useStencil=false);
//! destructor
virtual ~COGLES2FBODepthTexture();
@ -175,13 +191,13 @@ namespace video
//! Unbind RenderTargetTexture
virtual void unbindRTT();
bool attach(ITexture* rtt);
bool attach(ITexture*);
protected:
u32 DepthRenderBuffer;
u32 StencilRenderBuffer;
protected:
GLuint DepthRenderBuffer;
GLuint StencilRenderBuffer;
bool UseStencil;
};
};
} // end namespace video