Changed: #1275 Create an OpenGL ES driver

This commit is contained in:
kervala 2011-05-15 17:11:16 +02:00
parent 7edcf208d2
commit ae70be18fa
5 changed files with 119 additions and 10 deletions

View file

@ -35,10 +35,18 @@ static void convBlend(CMaterial::TBlend blend, GLenum& glenum)
case CMaterial::srccolor: glenum=GL_SRC_COLOR; break;
case CMaterial::invsrccolor:glenum=GL_ONE_MINUS_SRC_COLOR; break;
// Extended Blend modes.
#ifdef USE_OPENGLES
case CMaterial::blendConstantColor: glenum=GL_CONSTANT_COLOR; break;
case CMaterial::blendConstantInvColor: glenum=GL_ONE_MINUS_CONSTANT_COLOR; break;
case CMaterial::blendConstantAlpha: glenum=GL_CONSTANT_ALPHA; break;
case CMaterial::blendConstantInvAlpha: glenum=GL_ONE_MINUS_CONSTANT_ALPHA; break;
#else
case CMaterial::blendConstantColor: glenum=GL_CONSTANT_COLOR_EXT; break;
case CMaterial::blendConstantInvColor: glenum=GL_ONE_MINUS_CONSTANT_COLOR_EXT; break;
case CMaterial::blendConstantAlpha: glenum=GL_CONSTANT_ALPHA_EXT; break;
case CMaterial::blendConstantInvAlpha: glenum=GL_ONE_MINUS_CONSTANT_ALPHA_EXT; break;
#endif
default: nlstop;
}
}
@ -242,7 +250,9 @@ void CDriverGL::setTextureShaders(const uint8 *addressingModes, const CSmartPtr<
if (glAddrMode != _CurrentTexAddrMode[stage]) // addressing mode different from the one in the device?
{
_DriverGLStates.activeTextureARB(stage);
#ifndef USE_OPENGLES
glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, glAddrMode);
#endif
_CurrentTexAddrMode[stage] = glAddrMode;
}
}
@ -1971,7 +1981,9 @@ void CDriverGL::endCloudMultiPass()
nlassert(_CurrentMaterial->getShader() == CMaterial::Cloud);
if (ATICloudShaderHandle)
{
#ifndef USE_OPENGLES
glDisable(GL_FRAGMENT_SHADER_ATI);
#endif
}
}
@ -1989,7 +2001,9 @@ sint CDriverGL::beginWaterMultiPass()
*/
void CDriverGL::setupWaterPassR200(const CMaterial &mat)
{
H_AUTO_OGL(CDriverGL_setupWaterPassR200)
H_AUTO_OGL(CDriverGL_setupWaterPassR200);
#ifndef USE_OPENGLES
uint k;
ITexture *tex = mat.getTexture(0);
if (tex)
@ -2061,6 +2075,7 @@ void CDriverGL::setupWaterPassR200(const CMaterial &mat)
float cst[4] = { 1.f, 1.f, 1.f, 0.f };
nglSetFragmentShaderConstantATI(GL_CON_0_ATI, cst);
}
#endif
}
// ***************************************************************************
@ -2068,7 +2083,9 @@ void CDriverGL::setupWaterPassR200(const CMaterial &mat)
*/
void CDriverGL::setupWaterPassARB(const CMaterial &mat)
{
H_AUTO_OGL(CDriverGL_setupWaterPassARB)
H_AUTO_OGL(CDriverGL_setupWaterPassARB);
#ifndef USE_OPENGLES
uint k;
ITexture *tex = mat.getTexture(0);
if (tex)
@ -2147,6 +2164,7 @@ void CDriverGL::setupWaterPassARB(const CMaterial &mat)
}
}
}
#endif
}
// ***************************************************************************
@ -2175,6 +2193,7 @@ void CDriverGL::setupWaterPassNV20(const CMaterial &mat)
{
H_AUTO_OGL(CDriverGL_setupWaterPassNV20)
#ifndef USE_OPENGLES
static bool setupDone = false;
static CMaterial::CTexEnv texEnvReplace;
static CMaterial::CTexEnv texEnvModulate;
@ -2259,6 +2278,7 @@ void CDriverGL::setupWaterPassNV20(const CMaterial &mat)
activateTexEnvMode(2, texEnvReplace);
activateTexEnvMode(3, texEnvModulate);
}
#endif
}
// ***************************************************************************
@ -2286,7 +2306,9 @@ void CDriverGL::setupWaterPass(uint /* pass */)
// ***************************************************************************
void CDriverGL::endWaterMultiPass()
{
H_AUTO_OGL(CDriverGL_endWaterMultiPass)
H_AUTO_OGL(CDriverGL_endWaterMultiPass);
#ifndef USE_OPENGLES
nlassert(_CurrentMaterial->getShader() == CMaterial::Water);
// NB : as fragment shaders / programs bypass the texture envs, no special env enum is added (c.f CTexEnvSpecial)
if (_Extensions.NVTextureShader) return;
@ -2298,6 +2320,7 @@ void CDriverGL::endWaterMultiPass()
{
glDisable(GL_FRAGMENT_SHADER_ATI);
}
#endif
}
} // NL3D

View file

@ -20,12 +20,16 @@
#include "nel/misc/types_nl.h"
#include "nel/3d/vertex_buffer.h"
#ifdef USE_OPENGLES
# include <GLES/gl.h>
#else
# ifdef NL_OS_MAC
# define GL_GLEXT_LEGACY
# include <OpenGL/gl.h>
# else
# include <GL/gl.h>
# endif
#endif
namespace NL3D
@ -41,7 +45,7 @@ namespace NL3D
- GL_ALPHA_TEST
- GL_LIGHTING
- GL_LIGHT0 + i .....
- GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP_ARB.
- GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP_ARB/OES.
- GL_TEXTURE_GEN_S, GL_TEXTURE_GEN_T, GL_TEXTURE_GEN_R
- GL_COLOR_MATERIAL
- GL_FOG

View file

@ -155,7 +155,11 @@ bool CTextureDrvInfosGL::initFrameBufferObject(ITexture * tex)
// check status
GLenum status;
#ifdef USE_OPENGLES
status = (GLenum) nglCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
#else
status = (GLenum) nglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
#endif
switch(status) {
case GL_FRAMEBUFFER_COMPLETE_EXT:
InitFBO = true;
@ -204,12 +208,24 @@ bool CTextureDrvInfosGL::initFrameBufferObject(ITexture * tex)
// clean up resources if allocation failed
if (!InitFBO)
{
#ifdef USE_OPENGLES
nglDeleteFramebuffersOES(1, &FBOId);
#else
nglDeleteFramebuffersEXT(1, &FBOId);
#endif
if (AttachDepthStencil)
{
#ifdef USE_OPENGLES
nglDeleteRenderbuffersOES(1, &DepthFBOId);
#else
nglDeleteRenderbuffersEXT(1, &DepthFBOId);
#endif
if(!UsePackedDepthStencil)
#ifdef USE_OPENGLES
nglDeleteRenderbuffersOES(1, &StencilFBOId);
#else
nglDeleteRenderbuffersEXT(1, &StencilFBOId);
#endif
}
}
@ -226,14 +242,22 @@ bool CTextureDrvInfosGL::activeFrameBufferObject(ITexture * tex)
if(initFrameBufferObject(tex))
{
glBindTexture(TextureMode, 0);
#ifdef USE_OPENGLES
nglBindFramebufferOES(GL_FRAMEBUFFER_OES, FBOId);
#else
nglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBOId);
#endif
}
else
return false;
}
else
{
#ifdef USE_OPENGLES
nglBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
#else
nglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
#endif
}
return true;
@ -840,8 +864,13 @@ bool CDriverGL::setupTextureEx (ITexture& tex, bool bUpload, bool &bAllUploaded,
sint size= tex.getPixels(i).size();
if (bUpload)
{
#ifdef USE_OPENGLES
glCompressedTexImage2D (GL_TEXTURE_2D, i-decalMipMapResize, glfmt,
tex.getWidth(i),tex.getHeight(i), 0, size, ptr);
#else
nglCompressedTexImage2DARB (GL_TEXTURE_2D, i-decalMipMapResize, glfmt,
tex.getWidth(i),tex.getHeight(i), 0, size, ptr);
#endif
bAllUploaded = true;
}
else

View file

@ -69,7 +69,7 @@ IVertexBufferHardGL::~IVertexBufferHardGL()
H_AUTO_OGL(IVertexBufferHardGL_IVertexBufferHardGLDtor)
}
#ifndef USE_OPENGLES
// ***************************************************************************
// ***************************************************************************
@ -1133,7 +1133,7 @@ void CVertexArrayRangeMapObjectATI::updateLostBuffers()
}
#endif
#endif // USE_OPENGLES
// ***************************************************************************
@ -1328,6 +1328,12 @@ CVertexBufferHardARB::CVertexBufferHardARB(CDriverGL *drv, CVertexBuffer *vb) :
#ifdef NL_DEBUG
_Unmapping = false;
#endif
#ifdef USE_OPENGLES
_Buffer = NULL;
_BufferSize = 0;
_LastBufferSize = 0;
#endif
}
// ***************************************************************************
@ -1369,6 +1375,14 @@ CVertexBufferHardARB::~CVertexBufferHardARB()
_VertexArrayRange->_MappedVBList.erase(_IteratorInMappedVBList);
}
#endif
#ifdef USE_OPENGLES
if (_Buffer)
{
delete [] _Buffer;
_Buffer = NULL;
}
#endif
}
// ***************************************************************************
@ -1450,6 +1464,39 @@ void *CVertexBufferHardARB::lock()
beforeLock= CTime::getPerformanceTime();
}
_Driver->_DriverGLStates.bindARBVertexBuffer(_VertexObjectId);
#ifdef USE_OPENGLES
if (_Driver->_Extensions.OESMapBuffer)
{
_VertexPtr = nglMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
if (!_VertexPtr)
{
nglUnmapBufferOES(GL_ARRAY_BUFFER);
nlassert(glIsBuffer(_VertexObjectId));
invalidate();
return &_DummyVB[0];
}
}
else
{
const uint size = VB->getNumVertices() * VB->getVertexSize();
if (size > _BufferSize)
{
if (_Buffer) delete [] _Buffer;
_Buffer = new uint8[size+3];
_BufferSize = size;
}
uint8 offset = (size_t)_Buffer % 4;
if (offset > 0) offset = 4 - offset;
_VertexPtr = _Buffer + offset;
_LastBufferSize = size;
}
#else
_VertexPtr = nglMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
if (!_VertexPtr)
{
@ -1458,6 +1505,8 @@ void *CVertexBufferHardARB::lock()
invalidate();
return &_DummyVB[0];
}
#endif
#ifdef NL_DEBUG
_VertexArrayRange->_MappedVBList.push_front(this);
_IteratorInMappedVBList = _VertexArrayRange->_MappedVBList.begin();

View file

@ -2376,11 +2376,15 @@ void CDriverGL::getWindowSize(uint32 &width, uint32 &height)
if (_CurrentMode.OffScreen)
{
#ifdef NL_OS_WINDOWS
#ifndef USE_OPENGLES
if (_PBuffer)
{
nwglQueryPbufferARB( _PBuffer, WGL_PBUFFER_WIDTH_ARB, (int*)&width );
nwglQueryPbufferARB( _PBuffer, WGL_PBUFFER_HEIGHT_ARB, (int*)&height );
}
#endif
#endif
}
else