diff --git a/src/skel/symbian/symbian.cpp b/src/skel/symbian/symbian.cpp index 6ed083f..10fdf1e 100644 --- a/src/skel/symbian/symbian.cpp +++ b/src/skel/symbian/symbian.cpp @@ -339,7 +339,9 @@ public: CreateWindowL(); iAppUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape); SetExtentToWholeScreen(); +#ifdef RW_GL3 Window().EnableAdvancedPointers(); +#endif EnableDragEvents(); ActivateL(); @@ -353,13 +355,13 @@ public: RsGlobal.height = size.iHeight; EGLint attribs[] = { - EGL_BUFFER_SIZE, 16, + EGL_BUFFER_SIZE, 24, EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, 0, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, +#ifdef RW_GL3 EGL_SAMPLES, 0, EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER, - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, -#ifdef SYMBIAN3 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, #endif EGL_NONE @@ -367,15 +369,19 @@ public: eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(eglDisplay, NULL, NULL); -#ifdef SYMBIAN3 +#ifdef RW_GL3 eglBindAPI(EGL_OPENGL_ES_API); #endif EGLint numConfigs; eglChooseConfig(eglDisplay, attribs, &eglConfig, 1, &numConfigs); +#ifdef RW_GL3 EGLint contextAttribs[ 3 ] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, contextAttribs); +#else + eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, NULL); +#endif RWindow& window = Window(); eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, &window, NULL); diff --git a/vendor/librw/src/gles1/gl1device.cpp b/vendor/librw/src/gles1/gl1device.cpp index fd9190c..2722603 100644 --- a/vendor/librw/src/gles1/gl1device.cpp +++ b/vendor/librw/src/gles1/gl1device.cpp @@ -25,20 +25,12 @@ GlGlobals glGlobals; // terrible hack for GLES bool32 needToReadBackTextures; -int32 alphaFunc; float32 alphaRef; struct UniformState { - float32 alphaRefLow; - float32 alphaRefHigh; - int32 pad[2]; - float32 fogStart; float32 fogEnd; - float32 fogRange; - float32 fogDisable; - RGBAf fogColor; }; @@ -48,7 +40,7 @@ struct UniformScene float32 view[16]; }; -#define MAX_LIGHTS 4 +#define MAX_LIGHTS 8 struct UniformObject { @@ -73,25 +65,6 @@ static UniformState uniformState; static UniformScene uniformScene; static UniformObject uniformObject; -#ifndef RW_GL_USE_UBOS -// State -int32 u_alphaRef; -int32 u_fogData; -int32 u_fogColor; - -// Scene -int32 u_proj; -int32 u_view; - -// Object -int32 u_world; -int32 u_ambLight; -int32 u_lightParams; -int32 u_lightPosition; -int32 u_lightDirection; -int32 u_lightColor; -#endif - int32 u_matColor; int32 u_surfProps; @@ -383,38 +356,25 @@ setDepthWrite(bool32 enable) } } -static void -setAlphaTest(bool32 enable) +static void setAlphaTest(bool32 enable) { - uint32 shaderfunc; if(rwStateCache.alphaTestEnable != enable){ rwStateCache.alphaTestEnable = enable; - shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS; - if(alphaFunc != shaderfunc){ - alphaFunc = shaderfunc; - uniformStateDirty[RWGL_ALPHAFUNC] = true; - stateDirty = 1; - } + uniformStateDirty[RWGL_ALPHAFUNC] = true; + stateDirty = 1; } } -static void -setAlphaTestFunction(uint32 function) +static void setAlphaTestFunction(uint32 function) { - uint32 shaderfunc; if(rwStateCache.alphaFunc != function){ rwStateCache.alphaFunc = function; - shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS; - if(alphaFunc != shaderfunc){ - alphaFunc = shaderfunc; - uniformStateDirty[RWGL_ALPHAFUNC] = true; - stateDirty = 1; - } + uniformStateDirty[RWGL_ALPHAFUNC] = true; + stateDirty = 1; } } -static void -setVertexAlpha(bool32 enable) +void setVertexAlpha(bool32 enable) { if(rwStateCache.vertexAlpha != enable){ if(!rwStateCache.textureAlpha){ @@ -548,6 +508,7 @@ setRasterStageOnly(uint32 stage, Raster *raster) if(raster){ assert(raster->platform == PLATFORM_GLES1); Gl1Raster *natras = PLUGINOFFSET(Gl1Raster, raster, nativeRasterOffset); + glEnable(GL_TEXTURE_2D); bindTexture(natras->texid); rwStateCache.texstage[stage].filter = (rw::Texture::FilterMode)natras->filterMode; @@ -556,6 +517,7 @@ setRasterStageOnly(uint32 stage, Raster *raster) alpha = natras->hasAlpha; }else{ + glDisable(GL_TEXTURE_2D); bindTexture(whitetex); alpha = 0; } @@ -582,6 +544,7 @@ setRasterStage(uint32 stage, Raster *raster) if(raster){ assert(raster->platform == PLATFORM_GLES1); Gl1Raster *natras = PLUGINOFFSET(Gl1Raster, raster, nativeRasterOffset); + glEnable(GL_TEXTURE_2D); bindTexture(natras->texid); uint32 filter = rwStateCache.texstage[stage].filter; uint32 addrU = rwStateCache.texstage[stage].addressingU; @@ -607,6 +570,7 @@ setRasterStage(uint32 stage, Raster *raster) } alpha = natras->hasAlpha; }else{ + glDisable(GL_TEXTURE_2D); bindTexture(whitetex); alpha = 0; } @@ -884,12 +848,9 @@ static void resetRenderState(void) { rwStateCache.alphaFunc = ALPHAGREATEREQUAL; - alphaFunc = 0; alphaRef = 10.0f/255.0f; - uniformState.fogDisable = 1.0f; uniformState.fogStart = 0.0f; uniformState.fogEnd = 0.0f; - uniformState.fogRange = 0.0f; uniformState.fogColor.red = 1.0f; uniformState.fogColor.green = 1.0f; uniformState.fogColor.blue = 1.0f; @@ -943,15 +904,22 @@ resetRenderState(void) for(int i = 0; i < MAXNUMSTAGES; i++){ setActiveTexture(i); bindTexture(whitetex); + glDisable(GL_TEXTURE_2D); } setActiveTexture(0); + + glDisable(GL_LIGHTING); + glDisable(GL_FOG); + glDisable(GL_ALPHA_TEST); } void setWorldMatrix(Matrix *mat) { convMatrix(&uniformObject.world, mat); -// setUniform(u_world, &uniformObject.world); + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf(uniformScene.view); + glMultMatrixf((float*)&uniformObject.world); objectDirty = 1; } @@ -960,25 +928,27 @@ setLights(WorldLights *lightData) { int i, n; Light *l; - int32 bits; + int32 bits = 0; - uniformObject.ambLight = lightData->ambient; - - bits = 0; + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (GLfloat*)&lightData->ambient); if(lightData->numAmbients) bits |= VSLIGHT_AMBIENT; n = 0; + for(i = 0; i < MAX_LIGHTS; i++) + glDisable(GL_LIGHT0 + i); + for(i = 0; i < lightData->numDirectionals && i < 8; i++){ l = lightData->directionals[i]; - uniformObject.lightParams[n].type = 1.0f; - uniformObject.lightColor[n] = l->color; - memcpy(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d)); + glEnable(GL_LIGHT0 + n); + GLfloat dir[4] = { -l->getFrame()->getLTM()->at.x, -l->getFrame()->getLTM()->at.y, -l->getFrame()->getLTM()->at.z, 0.0f }; + glLightfv(GL_LIGHT0 + n, GL_POSITION, dir); + glLightfv(GL_LIGHT0 + n, GL_DIFFUSE, (GLfloat*)&l->color); + glLightfv(GL_LIGHT0 + n, GL_SPECULAR, (GLfloat*)&l->color); bits |= VSLIGHT_DIRECT; n++; - if(n >= MAX_LIGHTS) - goto out; + if(n >= MAX_LIGHTS) goto out; } for(i = 0; i < lightData->numLocals; i++){ @@ -986,44 +956,42 @@ setLights(WorldLights *lightData) switch(l->getType()){ case Light::POINT: - uniformObject.lightParams[n].type = 2.0f; - uniformObject.lightParams[n].radius = l->radius; - uniformObject.lightColor[n] = l->color; - memcpy(&uniformObject.lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d)); + glEnable(GL_LIGHT0 + n); + { + GLfloat pos[4] = { l->getFrame()->getLTM()->pos.x, l->getFrame()->getLTM()->pos.y, l->getFrame()->getLTM()->pos.z, 1.0f }; + glLightfv(GL_LIGHT0 + n, GL_POSITION, pos); + glLightfv(GL_LIGHT0 + n, GL_DIFFUSE, (GLfloat*)&l->color); + glLightf(GL_LIGHT0 + n, GL_CONSTANT_ATTENUATION, 1.0f); + glLightf(GL_LIGHT0 + n, GL_LINEAR_ATTENUATION, l->radius > 0.0f ? 1.0f / l->radius : 0.0f); + } bits |= VSLIGHT_POINT; n++; - if(n >= MAX_LIGHTS) - goto out; + if(n >= MAX_LIGHTS) goto out; break; case Light::SPOT: case Light::SOFTSPOT: - uniformObject.lightParams[n].type = 3.0f; - uniformObject.lightParams[n].minusCosAngle = l->minusCosAngle; - uniformObject.lightParams[n].radius = l->radius; - uniformObject.lightColor[n] = l->color; - memcpy(&uniformObject.lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d)); - memcpy(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d)); - // lower bound of falloff - if(l->getType() == Light::SOFTSPOT) - uniformObject.lightParams[n].hardSpot = 0.0f; - else - uniformObject.lightParams[n].hardSpot = 1.0f; + glEnable(GL_LIGHT0 + n); + { + GLfloat pos[4] = { l->getFrame()->getLTM()->pos.x, l->getFrame()->getLTM()->pos.y, l->getFrame()->getLTM()->pos.z, 1.0f }; + GLfloat dir[4] = { l->getFrame()->getLTM()->at.x, l->getFrame()->getLTM()->at.y, l->getFrame()->getLTM()->at.z, 0.0f }; + glLightfv(GL_LIGHT0 + n, GL_POSITION, pos); + glLightfv(GL_LIGHT0 + n, GL_SPOT_DIRECTION, dir); + glLightfv(GL_LIGHT0 + n, GL_DIFFUSE, (GLfloat*)&l->color); + glLightf(GL_LIGHT0 + n, GL_SPOT_CUTOFF, 45.0f); + } bits |= VSLIGHT_SPOT; n++; - if(n >= MAX_LIGHTS) - goto out; + if(n >= MAX_LIGHTS) goto out; break; } } - uniformObject.lightParams[n].type = 0.0f; - -// setUniform(u_ambLight, &uniformObject.ambLight); -// setUniform(u_lightParams, uniformObject.lightParams); -// setUniform(u_lightPosition, uniformObject.lightPosition); -// setUniform(u_lightDirection, uniformObject.lightDirection); -// setUniform(u_lightColor, uniformObject.lightColor); out: + if(n > 0 || lightData->numAmbients > 0) + glEnable(GL_LIGHTING); + else + glDisable(GL_LIGHTING); + objectDirty = 1; return bits; } @@ -1032,7 +1000,8 @@ void setProjectionMatrix(float32 *mat) { memcpy(&uniformScene.proj, mat, 64); -// setUniform(u_proj, uniformScene.proj); + glMatrixMode(GL_PROJECTION); + glLoadMatrixf(uniformScene.proj); sceneDirty = 1; } @@ -1040,7 +1009,9 @@ void setViewMatrix(float32 *mat) { memcpy(&uniformScene.view, mat, 64); -// setUniform(u_view, uniformScene.view); + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf(uniformScene.view); + glMultMatrixf((float*)&uniformObject.world); sceneDirty = 1; } @@ -1050,14 +1021,15 @@ setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops, float extr { rw::RGBAf col; convColor(&col, &color); -// setUniform(u_matColor, &col); - - float surfProps[4]; - surfProps[0] = surfaceprops.ambient; - surfProps[1] = surfaceprops.specular; - surfProps[2] = surfaceprops.diffuse; - surfProps[3] = extraSurfProp; -// setUniform(u_surfProps, surfProps); + glColor4f(col.red, col.green, col.blue, col.alpha); + + GLfloat ambient[4] = { col.red * surfaceprops.ambient, col.green * surfaceprops.ambient, col.blue * surfaceprops.ambient, col.alpha }; + GLfloat diffuse[4] = { col.red * surfaceprops.diffuse, col.green * surfaceprops.diffuse, col.blue * surfaceprops.diffuse, col.alpha }; + GLfloat specular[4] = { surfaceprops.specular, surfaceprops.specular, surfaceprops.specular, 1.0f }; + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); } void @@ -1065,96 +1037,48 @@ flushCache(void) { flushGlRenderState(); -#ifndef RW_GL_USE_UBOS - - // what's this doing here?? - uniformState.fogDisable = rwStateCache.fogEnable ? 0.0f : 1.0f; - uniformState.fogStart = rwStateCache.fogStart; - uniformState.fogEnd = rwStateCache.fogEnd; - uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd); - if(uniformStateDirty[RWGL_ALPHAFUNC] || uniformStateDirty[RWGL_ALPHAREF]){ - float alphaTest[4]; - switch(alphaFunc){ - case ALPHAALWAYS: - default: - alphaTest[0] = -1000.0f; - alphaTest[1] = 1000.0f; - break; - case ALPHAGREATEREQUAL: - alphaTest[0] = alphaRef; - alphaTest[1] = 1000.0f; - break; - case ALPHALESS: - alphaTest[0] = -1000.0f; - alphaTest[1] = alphaRef; - break; + if (rwStateCache.alphaTestEnable) { + glEnable(GL_ALPHA_TEST); + int func = GL_ALWAYS; + switch(rwStateCache.alphaFunc){ + case ALPHAALWAYS: + func = GL_ALWAYS; + break; + case ALPHAGREATEREQUAL: + func = GL_GEQUAL; + break; + case ALPHALESS: + func = GL_LESS; + break; + } + glAlphaFunc(func, alphaRef); + } else { + glDisable(GL_ALPHA_TEST); } -// setUniform(u_alphaRef, alphaTest); uniformStateDirty[RWGL_ALPHAFUNC] = false; uniformStateDirty[RWGL_ALPHAREF] = false; } if(uniformStateDirty[RWGL_FOG] || uniformStateDirty[RWGL_FOGSTART] || - uniformStateDirty[RWGL_FOGEND]){ - float fogData[4] = { - uniformState.fogStart, - uniformState.fogEnd, - uniformState.fogRange, - uniformState.fogDisable - }; -// setUniform(u_fogData, fogData); + uniformStateDirty[RWGL_FOGEND] || + uniformStateDirty[RWGL_FOGCOLOR]){ + if (rwStateCache.fogEnable) { + glEnable(GL_FOG); + glFogf(GL_FOG_MODE, GL_LINEAR); + glFogf(GL_FOG_START, rwStateCache.fogStart); + glFogf(GL_FOG_END, rwStateCache.fogEnd); + GLfloat fcolor[4] = { uniformState.fogColor.red, uniformState.fogColor.green, uniformState.fogColor.blue, uniformState.fogColor.alpha }; + glFogfv(GL_FOG_COLOR, fcolor); + } else { + glDisable(GL_FOG); + } uniformStateDirty[RWGL_FOG] = false; uniformStateDirty[RWGL_FOGSTART] = false; uniformStateDirty[RWGL_FOGEND] = false; - } - - if(uniformStateDirty[RWGL_FOGCOLOR]){ -// setUniform(u_fogColor, &uniformState.fogColor); uniformStateDirty[RWGL_FOGCOLOR] = false; } - -#else - if(objectDirty){ - glBindBuffer(GL_UNIFORM_BUFFER, ubo_object); - glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformObject), nil, GL_STREAM_DRAW); - glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformObject), &uniformObject, GL_STREAM_DRAW); - objectDirty = 0; - } - if(sceneDirty){ - glBindBuffer(GL_UNIFORM_BUFFER, ubo_scene); - glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformScene), nil, GL_STREAM_DRAW); - glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformScene), &uniformScene, GL_STREAM_DRAW); - sceneDirty = 0; - } - if(stateDirty){ - switch(alphaFunc){ - case ALPHAALWAYS: - default: - uniformState.alphaRefLow = -1000.0f; - uniformState.alphaRefHigh = 1000.0f; - break; - case ALPHAGREATEREQUAL: - uniformState.alphaRefLow = alphaRef; - uniformState.alphaRefHigh = 1000.0f; - break; - case ALPHALESS: - uniformState.alphaRefLow = -1000.0f; - uniformState.alphaRefHigh = alphaRef; - break; - } - uniformState.fogDisable = rwStateCache.fogEnable ? 0.0f : 1.0f; - uniformState.fogStart = rwStateCache.fogStart; - uniformState.fogEnd = rwStateCache.fogEnd; - uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd); - glBindBuffer(GL_UNIFORM_BUFFER, ubo_state); - glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformState), nil, GL_STREAM_DRAW); - glBufferData(GL_UNIFORM_BUFFER, sizeof(UniformState), &uniformState, GL_STREAM_DRAW); - stateDirty = 0; - } -#endif -// flushUniforms(); } static void @@ -1427,31 +1351,6 @@ stopSymbian(void) static int initOpenGL(void) { - -#ifndef RW_GL_USE_UBOS -// u_alphaRef = registerUniform("u_alphaRef", UNIFORM_VEC4); -// u_fogData = registerUniform("u_fogData", UNIFORM_VEC4); -// u_fogColor = registerUniform("u_fogColor", UNIFORM_VEC4); -// u_proj = registerUniform("u_proj", UNIFORM_MAT4); -// u_view = registerUniform("u_view", UNIFORM_MAT4); -// u_world = registerUniform("u_world", UNIFORM_MAT4); -// u_ambLight = registerUniform("u_ambLight", UNIFORM_VEC4); -// u_lightParams = registerUniform("u_lightParams", UNIFORM_VEC4, MAX_LIGHTS); -// u_lightPosition = registerUniform("u_lightPosition", UNIFORM_VEC4, MAX_LIGHTS); -// u_lightDirection = registerUniform("u_lightDirection", UNIFORM_VEC4, MAX_LIGHTS); -// u_lightColor = registerUniform("u_lightColor", UNIFORM_VEC4, MAX_LIGHTS); -// lastShaderUploaded = nil; -#else - registerBlock("Scene"); - registerBlock("Object"); - registerBlock("State"); -#endif -// u_matColor = registerUniform("u_matColor", UNIFORM_VEC4); -// u_surfProps = registerUniform("u_surfProps", UNIFORM_VEC4); - - // for im2d -// registerUniform("u_xform", UNIFORM_VEC4); - glClearColor(0.25, 0.25, 0.25, 1.0); byte whitepixel[4] = {0xFF, 0xFF, 0xFF, 0xFF}; @@ -1468,13 +1367,10 @@ initOpenGL(void) #ifndef __SYMBIAN32__ glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); - - if(gl3Caps.glversion >= 30){ - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - } #endif + glEnable(GL_NORMALIZE); + openIm2D(); openIm3D(); diff --git a/vendor/librw/src/gles1/gl1immed.cpp b/vendor/librw/src/gles1/gl1immed.cpp index e394b5a..eb4d9a0 100644 --- a/vendor/librw/src/gles1/gl1immed.cpp +++ b/vendor/librw/src/gles1/gl1immed.cpp @@ -41,11 +41,15 @@ static int primTypeMap[] = { void openIm2D(void) { + glGenBuffers(1, &im2DIbo); + glGenBuffers(1, &im2DVbo); } void closeIm2D(void) { + glDeleteBuffers(1, &im2DIbo); + glDeleteBuffers(1, &im2DVbo); } static Im2DVertex tmpprimbuf[3]; @@ -76,14 +80,39 @@ im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices) cam = (Camera*)engine->currentCamera; glBindBuffer(GL_ARRAY_BUFFER, im2DVbo); - glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Im2DVertex), vertices, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Im2DVertex), vertices, GL_DYNAMIC_DRAW); + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(Im2DVertex), (void*)0); + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Im2DVertex), (void*)offsetof(Im2DVertex, r)); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(Im2DVertex), (void*)offsetof(Im2DVertex, u)); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glOrthof(0.0f, (float)cam->frameBuffer->width, (float)cam->frameBuffer->height, 0.0f, -1000.0f, 1000.0f); flushCache(); + glDrawArrays(primTypeMap[primType], 0, numVertices); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); } -void -im2DRenderIndexedPrimitive(PrimitiveType primType, +void im2DRenderIndexedPrimitive(PrimitiveType primType, void *vertices, int32 numVertices, void *indices, int32 numIndices) { @@ -91,20 +120,42 @@ im2DRenderIndexedPrimitive(PrimitiveType primType, cam = (Camera*)engine->currentCamera; glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*2, indices, GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*2, indices, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, im2DVbo); - glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Im2DVertex), vertices, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Im2DVertex), vertices, GL_DYNAMIC_DRAW); + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(Im2DVertex), (void*)0); + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Im2DVertex), (void*)offsetof(Im2DVertex, r)); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(Im2DVertex), (void*)offsetof(Im2DVertex, u)); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrthof(0.0f, (float)cam->frameBuffer->width, (float)cam->frameBuffer->height, 0.0f, -1000.0f, 1000.0f); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); flushCache(); - glDrawElements(primTypeMap[primType], numIndices, - GL_UNSIGNED_SHORT, nil); + glDrawElements(primTypeMap[primType], numIndices, GL_UNSIGNED_SHORT, nil); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); } - // Im3D - static AttribDesc im3dattribDesc[3] = { { ATTRIB_POS, GL_FLOAT, GL_FALSE, 3, sizeof(Im3DVertex), 0 }, @@ -152,10 +203,20 @@ im3DTransform(void *vertices, int32 numVertices, Matrix *world, uint32 flags) void im3DRenderPrimitive(PrimitiveType primType) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo); + glBindBuffer(GL_ARRAY_BUFFER, im3DVbo); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(Im3DVertex), (void*)0); + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Im3DVertex), (void*)offsetof(Im3DVertex, r)); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(Im3DVertex), (void*)offsetof(Im3DVertex, u)); flushCache(); glDrawArrays(primTypeMap[primType], 0, num3DVertices); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); } void @@ -164,9 +225,20 @@ im3DRenderIndexedPrimitive(PrimitiveType primType, void *indices, int32 numIndic glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*2, indices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, im3DVbo); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(Im3DVertex), (void*)0); + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Im3DVertex), (void*)offsetof(Im3DVertex, r)); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(Im3DVertex), (void*)offsetof(Im3DVertex, u)); + flushCache(); - glDrawElements(primTypeMap[primType], numIndices, - GL_UNSIGNED_SHORT, nil); + glDrawElements(primTypeMap[primType], numIndices, GL_UNSIGNED_SHORT, nil); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); } void diff --git a/vendor/librw/src/gles1/gl1raster.cpp b/vendor/librw/src/gles1/gl1raster.cpp index be7118d..77c44a8 100644 --- a/vendor/librw/src/gles1/gl1raster.cpp +++ b/vendor/librw/src/gles1/gl1raster.cpp @@ -483,24 +483,24 @@ rasterUnlock(Raster *raster, int32 level) natras->backingStore->levels[level].size); } }else{ - if (raster->pixels != nil && natras->format == GL_RGBA && natras->type == GL_UNSIGNED_BYTE) { - // convert to 16-bit - uint16_t* pixels16 = (uint16_t*)malloc(raster->width * raster->height * sizeof(uint16_t)); - uint8_t* pixels8 = (uint8_t*)raster->pixels; - - for (int i = 0; i < raster->width * raster->height; i++) { - uint8_t r = pixels8[i * 4 + 0]; - uint8_t g = pixels8[i * 4 + 1]; - uint8_t b = pixels8[i * 4 + 2]; - uint8_t a = pixels8[i * 4 + 3]; - - pixels16[i] = ((r >> 4) << 12) | ((g >> 4) << 8) | ((b >> 4) << 4) | (a >> 4); - } - glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, raster->width, raster->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels16); - free(pixels16); - } else +// if (raster->pixels != nil && natras->format == GL_RGBA && natras->type == GL_UNSIGNED_BYTE) { +// // convert to 16-bit +// uint16_t* pixels16 = (uint16_t*)malloc(raster->width * raster->height * sizeof(uint16_t)); +// uint8_t* pixels8 = (uint8_t*)raster->pixels; +// +// for (int i = 0; i < raster->width * raster->height; i++) { +// uint8_t r = pixels8[i * 4 + 0]; +// uint8_t g = pixels8[i * 4 + 1]; +// uint8_t b = pixels8[i * 4 + 2]; +// uint8_t a = pixels8[i * 4 + 3]; +// +// pixels16[i] = ((r >> 4) << 12) | ((g >> 4) << 8) | ((b >> 4) << 4) | (a >> 4); +// } +// glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, raster->width, raster->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels16); +// free(pixels16); +// } else { -// glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat, raster->width, raster->height, 0, natras->format, natras->type, raster->pixels); diff --git a/vendor/librw/src/gles1/gl1render.cpp b/vendor/librw/src/gles1/gl1render.cpp index e621257..dc0861b 100644 --- a/vendor/librw/src/gles1/gl1render.cpp +++ b/vendor/librw/src/gles1/gl1render.cpp @@ -26,46 +26,10 @@ drawInst_simple(InstanceDataHeader *header, InstanceData *inst) GL_UNSIGNED_SHORT, (void*)(uintptr)inst->offset); } -// Emulate PS2 GS alpha test FB_ONLY case: failed alpha writes to frame- but not to depth buffer -void -drawInst_GSemu(InstanceDataHeader *header, InstanceData *inst) -{ - uint32 hasAlpha; - int alphafunc, alpharef, gsalpharef; - int zwrite; - hasAlpha = getAlphaBlend(); - if(hasAlpha){ - zwrite = rw::GetRenderState(rw::ZWRITEENABLE); - alphafunc = rw::GetRenderState(rw::ALPHATESTFUNC); - if(zwrite){ - alpharef = rw::GetRenderState(rw::ALPHATESTREF); - gsalpharef = rw::GetRenderState(rw::GSALPHATESTREF); - - SetRenderState(rw::ALPHATESTFUNC, rw::ALPHAGREATEREQUAL); - SetRenderState(rw::ALPHATESTREF, gsalpharef); - drawInst_simple(header, inst); - SetRenderState(rw::ALPHATESTFUNC, rw::ALPHALESS); - SetRenderState(rw::ZWRITEENABLE, 0); - drawInst_simple(header, inst); - SetRenderState(rw::ZWRITEENABLE, 1); - SetRenderState(rw::ALPHATESTFUNC, alphafunc); - SetRenderState(rw::ALPHATESTREF, alpharef); - }else{ - SetRenderState(rw::ALPHATESTFUNC, rw::ALPHAALWAYS); - drawInst_simple(header, inst); - SetRenderState(rw::ALPHATESTFUNC, alphafunc); - } - }else - drawInst_simple(header, inst); -} - void drawInst(InstanceDataHeader *header, InstanceData *inst) { -// if(rw::GetRenderState(rw::GSALPHATEST)) -// drawInst_GSemu(header, inst); -// else - drawInst_simple(header, inst); + drawInst_simple(header, inst); } @@ -74,6 +38,35 @@ setupVertexInput(InstanceDataHeader *header) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); glBindBuffer(GL_ARRAY_BUFFER, header->vbo); + bool hasNormal = false; + bool hasColor = false; + bool hasTex = false; + + for (int32 i = 0; i < header->numAttribs; i++) { + AttribDesc *a = &header->attribDesc[i]; + if (a->index == ATTRIB_POS) { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(a->size, a->type, a->stride, (void*)(uintptr)a->offset); + } else if (a->index == ATTRIB_NORMAL) { + glEnableClientState(GL_NORMAL_ARRAY); + glNormalPointer(a->type, a->stride, (void*)(uintptr)a->offset); + hasNormal = true; + } else if (a->index == ATTRIB_COLOR){ + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(a->size, a->type, a->stride, (void*)(uintptr)a->offset); + hasColor = true; + } else if(a->index == ATTRIB_TEXCOORDS0){ + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(a->size, a->type, a->stride, (void*)(uintptr)a->offset); + hasTex = true; + } + } + if (!hasNormal) glDisableClientState(GL_NORMAL_ARRAY); + if (!hasColor) { + glDisableClientState(GL_COLOR_ARRAY); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + if(!hasTex) glDisableClientState(GL_TEXTURE_COORD_ARRAY); } void diff --git a/vendor/librw/src/gles1/rwgles1.h b/vendor/librw/src/gles1/rwgles1.h index 14b8743..33732fd 100644 --- a/vendor/librw/src/gles1/rwgles1.h +++ b/vendor/librw/src/gles1/rwgles1.h @@ -209,6 +209,8 @@ void *destroyNativeData(void *object, int32, int32); ObjPipeline *makeDefaultPipeline(void); +void setVertexAlpha(bool32 enable); + // Native Texture and Raster struct Gl1Raster