Changed: #1275 Create an OpenGL ES driver

This commit is contained in:
kervala 2012-05-13 15:27:20 +02:00
parent a7d6082d49
commit 61d7295efa
7 changed files with 75 additions and 68 deletions

View file

@ -1521,7 +1521,7 @@ void registerGlExtensions(CGlExtensions &ext)
if(ext.NVVertexArrayRange) if(ext.NVVertexArrayRange)
{ {
GLint nverts = 10; GLint nverts = 10;
#ifndef USE_OPENGLES #ifndef USE_OPENGLES
glGetIntegerv((GLenum)GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV, &nverts); glGetIntegerv((GLenum)GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV, &nverts);
#endif #endif

View file

@ -1234,54 +1234,54 @@ void CDriverGL::setupSpecularPass(uint pass)
#ifdef USE_OPENGLES #ifdef USE_OPENGLES
#if 0 #if 0
// Ok we can do it in a single pass // Ok we can do it in a single pass
// Set Stage 1 // Set Stage 1
// Special: not the same special env if there is or not texture in stage 0. // Special: not the same special env if there is or not texture in stage 0.
CTexEnvSpecial newEnvStage1; CTexEnvSpecial newEnvStage1;
if( mat.getTexture(0) == NULL ) if( mat.getTexture(0) == NULL )
newEnvStage1= TexEnvSpecialSpecularStage1NoText; newEnvStage1= TexEnvSpecialSpecularStage1NoText;
else else
newEnvStage1= TexEnvSpecialSpecularStage1; newEnvStage1= TexEnvSpecialSpecularStage1;
// Test if same env as prec. // Test if same env as prec.
if(_CurrentTexEnvSpecial[1] != newEnvStage1) if(_CurrentTexEnvSpecial[1] != newEnvStage1)
{
// TexEnv is special.
_CurrentTexEnvSpecial[1] = newEnvStage1;
_DriverGLStates.activeTextureARB(1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
// Operator Add (Arg0*Arg2+Arg1)
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
// Arg0.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
// Arg2.
if( newEnvStage1 == TexEnvSpecialSpecularStage1NoText)
{ {
// TexEnv is special. glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_ZERO);
_CurrentTexEnvSpecial[1] = newEnvStage1; glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_ONE_MINUS_SRC_COLOR);
_DriverGLStates.activeTextureARB(1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
// Operator Add (Arg0*Arg2+Arg1)
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
// Arg0.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
// Arg2.
if( newEnvStage1 == TexEnvSpecialSpecularStage1NoText)
{
glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_ZERO);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_ONE_MINUS_SRC_COLOR);
}
else
{
glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
}
// Arg1.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
// Result : Texture*Previous.Alpha+Previous
// Setup Alpha Diffuse Copy
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
// Arg2.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_ZERO);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Arg1.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_ZERO );
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
} }
else
{
glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
}
// Arg1.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
// Result : Texture*Previous.Alpha+Previous
// Setup Alpha Diffuse Copy
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
// Arg2.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_ZERO);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Arg1.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_ZERO );
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
}
#endif #endif
#else #else
/// Support NVidia combine 4 extension to do specular map in a single pass /// Support NVidia combine 4 extension to do specular map in a single pass
@ -1398,7 +1398,8 @@ void CDriverGL::setupSpecularPass(uint pass)
// We have to do it in 2 passes // We have to do it in 2 passes
// For Both Pass, setup correct Env. // For Both Pass, setup correct Env.
if( pass == 0 ) if( pass == 0 )
{ // Just display the texture {
// Just display the texture
_DriverGLStates.enableBlend(false); _DriverGLStates.enableBlend(false);
_DriverGLStates.activeTextureARB(1); _DriverGLStates.activeTextureARB(1);
_DriverGLStates.setTextureMode(CDriverGLStates::TextureDisabled); _DriverGLStates.setTextureMode(CDriverGLStates::TextureDisabled);

View file

@ -705,8 +705,6 @@ void CDriverGLStates::setTexGenMode (uint stage, GLint mode)
} }
} }
// *************************************************************************** // ***************************************************************************
void CDriverGLStates::resetTextureMode() void CDriverGLStates::resetTextureMode()
{ {

View file

@ -1613,7 +1613,7 @@ bool CDriverGL::activateTexture(uint stage, ITexture *tex)
// This maps the CMaterial::TTexOperator // This maps the CMaterial::TTexOperator
static const GLenum OperatorLUT[9]= { GL_REPLACE, GL_MODULATE, GL_ADD, static const GLenum OperatorLUT[9]= { GL_REPLACE, GL_MODULATE, GL_ADD,
#ifdef USE_OPENGLES #ifdef USE_OPENGLES
GL_ADD_SIGNED, GL_INTERPOLATE, GL_INTERPOLATE, GL_INTERPOLATE, GL_INTERPOLATE GL_ADD_SIGNED, GL_INTERPOLATE, GL_INTERPOLATE, GL_INTERPOLATE, GL_INTERPOLATE, GL_INTERPOLATE
#else #else
GL_ADD_SIGNED_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_BUMP_ENVMAP_ATI GL_ADD_SIGNED_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_INTERPOLATE_EXT, GL_BUMP_ENVMAP_ATI
#endif #endif
@ -1986,7 +1986,6 @@ void CDriverGL::forceActivateTexEnvMode(uint stage, const CMaterial::CTexEnv &
{ {
// Operator. // Operator.
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, OperatorLUT[env.Env.OpRGB] ); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, OperatorLUT[env.Env.OpRGB] );
// Arg0. // Arg0.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, SourceLUT[env.Env.SrcArg0RGB] ); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, SourceLUT[env.Env.SrcArg0RGB] );
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, OperandLUT[env.Env.OpArg0RGB]); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, OperandLUT[env.Env.OpArg0RGB]);
@ -2038,7 +2037,6 @@ void CDriverGL::forceActivateTexEnvMode(uint stage, const CMaterial::CTexEnv &
{ {
// Operator. // Operator.
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, OperatorLUT[env.Env.OpAlpha] ); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, OperatorLUT[env.Env.OpAlpha] );
// Arg0. // Arg0.
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, SourceLUT[env.Env.SrcArg0Alpha] ); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, SourceLUT[env.Env.SrcArg0Alpha] );
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, OperandLUT[env.Env.OpArg0Alpha]); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, OperandLUT[env.Env.OpArg0Alpha]);

View file

@ -103,10 +103,10 @@ bool CVertexArrayRangeNVidia::allocate(uint32 size, CVertexBuffer::TPreferredM
H_AUTO_OGL(CVertexArrayRangeNVidia_allocate) H_AUTO_OGL(CVertexArrayRangeNVidia_allocate)
nlassert(_VertexArrayPtr==NULL); nlassert(_VertexArrayPtr==NULL);
#ifdef NL_OS_WINDOWS
// try to allocate AGP or VRAM data. // try to allocate AGP or VRAM data.
switch(vbType) switch(vbType)
{ {
#ifdef NL_OS_WINDOWS
case CVertexBuffer::AGPPreferred: case CVertexBuffer::AGPPreferred:
_VertexArrayPtr= nwglAllocateMemoryNV(size, 0, 0, 0.5f); _VertexArrayPtr= nwglAllocateMemoryNV(size, 0, 0, 0.5f);
break; break;
@ -116,12 +116,9 @@ bool CVertexArrayRangeNVidia::allocate(uint32 size, CVertexBuffer::TPreferredM
else else
_VertexArrayPtr= nwglAllocateMemoryNV(size, 0, 0, 0.5f); _VertexArrayPtr= nwglAllocateMemoryNV(size, 0, 0, 0.5f);
break; break;
default: #elif defined(NL_OS_MAC)
break; // TODO: implement for Mac OS X
} #elif defined(NL_OS_UNIX)
#elif defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
switch(vbType)
{
case CVertexBuffer::AGPPreferred: case CVertexBuffer::AGPPreferred:
_VertexArrayPtr= nglXAllocateMemoryNV(size, 0, 0, 0.5f); _VertexArrayPtr= nglXAllocateMemoryNV(size, 0, 0, 0.5f);
break; break;
@ -131,11 +128,10 @@ bool CVertexArrayRangeNVidia::allocate(uint32 size, CVertexBuffer::TPreferredM
else else
_VertexArrayPtr= nglXAllocateMemoryNV(size, 0, 0, 0.5f); _VertexArrayPtr= nglXAllocateMemoryNV(size, 0, 0, 0.5f);
break; break;
#endif // NL_OS_WINDOWS
default: default:
break; break;
} }
#endif // NL_OS_WINDOWS
// init the allocator. // init the allocator.
if(_VertexArrayPtr) if(_VertexArrayPtr)
@ -175,7 +171,9 @@ void CVertexArrayRangeNVidia::free()
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
// Free special memory. // Free special memory.
nwglFreeMemoryNV(_VertexArrayPtr); nwglFreeMemoryNV(_VertexArrayPtr);
#elif defined(NL_OS_UNIX) && !defined(NL_OS_MAC) #elif defined(NL_OS_MAC)
// TODO: implement for Mac OS X
#elif defined(NL_OS_UNIX)
nglXFreeMemoryNV(_VertexArrayPtr); nglXFreeMemoryNV(_VertexArrayPtr);
#endif // NL_OS_WINDOWS #endif // NL_OS_WINDOWS

View file

@ -106,7 +106,7 @@ bool GlWndProc(CDriverGL *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
H_AUTO_OGL(DriverGL_WndProc) H_AUTO_OGL(DriverGL_WndProc);
// Get the driver pointer.. // Get the driver pointer..
CDriverGL *pDriver=(CDriverGL*)GetWindowLongPtr (hWnd, GWLP_USERDATA); CDriverGL *pDriver=(CDriverGL*)GetWindowLongPtr (hWnd, GWLP_USERDATA);

View file

@ -1,3 +1,15 @@
FIND_PACKAGE(OpenGLES)
IF(NOT WIN32)
IF(APPLE)
FIND_LIBRARY(CARBON NAMES Carbon)
FIND_LIBRARY(COCOA NAMES Cocoa)
ELSE(APPLE)
FIND_PACKAGE(X11)
FIND_PACKAGE(XF86VidMode)
ENDIF(APPLE)
ENDIF(NOT WIN32)
SET(SOURCE_DIR ${CMAKE_SOURCE_DIR}/nel/src/3d/driver/opengl) SET(SOURCE_DIR ${CMAKE_SOURCE_DIR}/nel/src/3d/driver/opengl)
FILE(GLOB SRC ${SOURCE_DIR}/*.cpp ${SOURCE_DIR}/*.h ${SOURCE_DIR}/*.def) FILE(GLOB SRC ${SOURCE_DIR}/*.cpp ${SOURCE_DIR}/*.h ${SOURCE_DIR}/*.def)
@ -8,6 +20,8 @@ IF(APPLE)
SET_SOURCE_FILES_PROPERTIES(${SRC} PROPERTIES COMPILE_FLAGS "-x objective-c++") SET_SOURCE_FILES_PROPERTIES(${SRC} PROPERTIES COMPILE_FLAGS "-x objective-c++")
ENDIF(APPLE) ENDIF(APPLE)
INCLUDE_DIRECTORIES(${SOURCE_DIR} ${OPENGLES_INCLUDE_DIR})
ADD_DEFINITIONS(-DUSE_OPENGLES) ADD_DEFINITIONS(-DUSE_OPENGLES)
IF(WIN32) IF(WIN32)
@ -18,9 +32,7 @@ ENDIF(WIN32)
NL_TARGET_DRIVER(${NLDRV_OGLES_LIB} ${SRC}) NL_TARGET_DRIVER(${NLDRV_OGLES_LIB} ${SRC})
INCLUDE_DIRECTORIES(${OPENGLES_INCLUDE_DIR}) TARGET_LINK_LIBRARIES(${NLDRV_OGLES_LIB} nel3d nelmisc ${OPENGLES_LIBRARIES})
TARGET_LINK_LIBRARIES(${NLDRV_OGLES_LIB} nel3d nelmisc ${OPENGL_gles_LIBRARY})
NL_DEFAULT_PROPS(${NLDRV_OGLES_LIB} "NeL, Driver, Video: OpenGL ES") NL_DEFAULT_PROPS(${NLDRV_OGLES_LIB} "NeL, Driver, Video: OpenGL ES")
NL_ADD_LIB_SUFFIX(${NLDRV_OGLES_LIB}) NL_ADD_LIB_SUFFIX(${NLDRV_OGLES_LIB})
NL_ADD_RUNTIME_FLAGS(${NLDRV_OGLES_LIB}) NL_ADD_RUNTIME_FLAGS(${NLDRV_OGLES_LIB})
@ -28,7 +40,7 @@ NL_ADD_RUNTIME_FLAGS(${NLDRV_OGLES_LIB})
IF(WIN32) IF(WIN32)
INCLUDE_DIRECTORIES(${DXSDK_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${DXSDK_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(${NLDRV_OGLES_LIB} ${DXSDK_DINPUT_LIBRARY} ${DXSDK_GUID_LIBRARY}) TARGET_LINK_LIBRARIES(${NLDRV_OGLES_LIB} ${DXSDK_DINPUT_LIBRARY} ${DXSDK_GUID_LIBRARY})
ADD_DEFINITIONS(/DDRIVER_OPENGL_EXPORTS) ADD_DEFINITIONS(/DDRIVER_OPENGLES_EXPORTS)
ENDIF(WIN32) ENDIF(WIN32)
IF(APPLE) IF(APPLE)