void GLSurfaceView.IRenderer.OnDrawFrame(Javax.Microedition.Khronos.Opengles.IGL10 gl) { GLES20.GlClear(GLES20.GlColorBufferBit | GLES20.GlDepthBufferBit); mGrid.draw(mViewMatrix, mProjectionMatrix); mPointCloud.draw(mViewMatrix, mProjectionMatrix); mCameraFrustumAndAxis.draw(mViewMatrix, mProjectionMatrix); }
public void OnDrawFrame(Javax.Microedition.Khronos.Opengles.IGL10 gl) { Java.Util.Random r = new Java.Util.Random(); gl.GlClearColor(r.NextFloat(), r.NextFloat(), r.NextFloat(), 1); gl.GlClear(Javax.Microedition.Khronos.Opengles.GL10.GlColorBufferBit); }
// =========================================================== // Methods // =========================================================== public static void Reset(/* final */ GL10 pGL) { GLHelper.sCurrentHardwareBufferID = -1; GLHelper.sCurrentHardwareTextureID = -1; GLHelper.sCurrentMatrix = -1; GLHelper.sCurrentSourceBlendMode = -1; GLHelper.sCurrentDestinationBlendMode = -1; GLHelper.sCurrentTextureFloatBuffer = null; GLHelper.sCurrentVertexFloatBuffer = null; GLHelper.EnableDither(pGL); GLHelper.EnableLightning(pGL); GLHelper.EnableDepthTest(pGL); GLHelper.EnableMultisample(pGL); GLHelper.DisableBlend(pGL); GLHelper.DisableCulling(pGL); GLHelper.DisableTextures(pGL); GLHelper.DisableTexCoordArray(pGL); GLHelper.DisableVertexArray(pGL); GLHelper.sLineWidth = 1; GLHelper.sRed = -1; GLHelper.sGreen = -1; GLHelper.sBlue = -1; GLHelper.sAlpha = -1; GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS = false; GLHelper.EXTENSIONS_DRAWTEXTURE = false; }
// =========================================================== // Methods // =========================================================== public void OnDrawHUD(/* final */ GL10 pGL) { if (this.mHUD != null) { this.mHUD.OnDraw(pGL, this); } }
public static void EnableExtensions(/* final */ GL10 pGL, /* final */ RenderOptions pRenderOptions) { /* final */ String version = pGL.GlGetString(GL10Consts.GlVersion); /* final */ String renderer = pGL.GlGetString(GL10Consts.GlRenderer); /* final */ String extensions = pGL.GlGetString(GL10Consts.GlExtensions); Debug.D("RENDERER: " + renderer); Debug.D("VERSION: " + version); Debug.D("EXTENSIONS: " + extensions); /* final */ bool isOpenGL10 = version.Contains("1.0"); /* final */ bool isSoftwareRenderer = renderer.Contains("PixelFlinger"); /* final */ bool isVBOCapable = extensions.Contains("_vertex_buffer_object"); /* final */ bool isDrawTextureCapable = extensions.Contains("draw_texture"); //GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS = !pRenderOptions.isDisableExtensionVertexBufferObjects() && !isSoftwareRenderer && (isVBOCapable || !isOpenGL10); GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS = !pRenderOptions.IsDisableExtensionVertexBufferObjects() && !isSoftwareRenderer && (isVBOCapable || !isOpenGL10); GLHelper.EXTENSIONS_DRAWTEXTURE = isDrawTextureCapable; GLHelper.HackBrokenDevices(); Debug.D("EXTENSIONS_VERXTEXBUFFEROBJECTS = " + GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS); Debug.D("EXTENSIONS_DRAWTEXTURE = " + GLHelper.EXTENSIONS_DRAWTEXTURE); }
public /* override */ void OnSurfaceCreated(GL10 pGL, EGLConfig pConfig) { Debug.D("onSurfaceCreated"); GLHelper.Reset(pGL); GLHelper.SetPerspectiveCorrectionHintFastest(pGL); // pGL.glEnable(GL10.GL_POLYGON_SMOOTH); // pGL.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST); // pGL.glEnable(GL10.GL_LINE_SMOOTH); // pGL.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST); // pGL.glEnable(GL10.GL_POINT_SMOOTH); // pGL.glHint(GL10.GL_POINT_SMOOTH_HINT, GL10.GL_NICEST); GLHelper.SetShadeModelFlat(pGL); GLHelper.DisableLightning(pGL); GLHelper.DisableDither(pGL); GLHelper.DisableDepthTest(pGL); GLHelper.DisableMultisample(pGL); GLHelper.EnableBlend(pGL); GLHelper.EnableTextures(pGL); GLHelper.EnableTexCoordArray(pGL); GLHelper.EnableVertexArray(pGL); GLHelper.EnableCulling(pGL); pGL.GlFrontFace(GL10Consts.GlCcw); pGL.GlCullFace(GL10Consts.GlBack); // GLHelper.EnableExtensions(pGL, this.mEngine.getEngineOptions().getRenderOptions()); GLHelper.EnableExtensions(pGL, this.mEngine.EngineOptions.RenderOptions); }
// =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== public /* override */ void OnSurfaceChanged(GL10 pGL, int pWidth, int pHeight) { Debug.D("onSurfaceChanged: pWidth=" + pWidth + " pHeight=" + pHeight); this.mEngine.SetSurfaceSize(pWidth, pHeight); pGL.GlViewport(0, 0, pWidth, pHeight); pGL.GlLoadIdentity(); }
public void OnDrawFrame(Javax.Microedition.Khronos.Opengles.IGL10 gl) { // Draw background color GLES20.GlClear((int)GLES20.GlColorBufferBit); // Set the camera position (View matrix) Matrix.SetLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); // Calculate the projection and view transformation Matrix.MultiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); // Draw square mSquare.Draw(mMVPMatrix); // Create a rotation for the triangle // long time = SystemClock.UptimeMillis() % 4000L; // float angle = 0.090f * ((int) time); Matrix.SetRotateM(mRotationMatrix, 0, Angle, 0, 0, -1.0f); // Combine the rotation matrix with the projection and camera view Matrix.MultiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0); // Draw triangle mTriangle.Draw(mMVPMatrix); }
protected virtual void OnInitDraw(/* final */ GL10 pGL) { GLHelper.SetColor(pGL, this.mRed, this.mGreen, this.mBlue, this.mAlpha); GLHelper.EnableVertexArray(pGL); GLHelper.BlendFunction(pGL, this.mSourceBlendFunction, this.mDestinationBlendFunction); }
public static void VertexPointer(/* final */ GL10 pGL, /* final */ FastFloatBuffer pVertexFloatBuffer) { if (GLHelper.sCurrentVertexFloatBuffer != pVertexFloatBuffer) { GLHelper.sCurrentVertexFloatBuffer = pVertexFloatBuffer; pGL.GlVertexPointer(2, GL10Consts.GlFloat, 0, pVertexFloatBuffer.mByteBuffer); } }
public static void TexCoordPointer(/* final */ GL10 pGL, /* final */ FastFloatBuffer pTextureFloatBuffer) { if (GLHelper.sCurrentTextureFloatBuffer != pTextureFloatBuffer) { GLHelper.sCurrentTextureFloatBuffer = pTextureFloatBuffer; pGL.GlTexCoordPointer(2, GL10Consts.GlFloat, 0, pTextureFloatBuffer.mByteBuffer); } }
public static void DisableMultisample(/* final */ GL10 pGL) { if (GLHelper.sEnableMultisample) { GLHelper.sEnableMultisample = false; pGL.GlDisable(GL10Consts.GlMultisample); } }
public static void EnableMultisample(/* final */ GL10 pGL) { if (!GLHelper.sEnableMultisample) { GLHelper.sEnableMultisample = true; pGL.GlEnable(GL10Consts.GlMultisample); } }
public static void DisableDepthTest(/* final */ GL10 pGL) { if (GLHelper.sEnableDepthTest) { GLHelper.sEnableDepthTest = false; pGL.GlDisable(GL10Consts.GlDepthTest); } }
public static void EnableDepthTest(/* final */ GL10 pGL) { if (!GLHelper.sEnableDepthTest) { GLHelper.sEnableDepthTest = true; pGL.GlEnable(GL10Consts.GlDepthTest); } }
public static void DisableDither(/* final */ GL10 pGL) { if (GLHelper.sEnableDither) { GLHelper.sEnableDither = false; pGL.GlDisable(GL10Consts.GlDither); } }
public static void EnableDither(/* final */ GL10 pGL) { if (!GLHelper.sEnableDither) { GLHelper.sEnableDither = true; pGL.GlEnable(GL10Consts.GlDither); } }
public static void DisableTextures(/* final */ GL10 pGL) { if (GLHelper.sEnableTextures) { GLHelper.sEnableTextures = false; pGL.GlDisable(GL10Consts.GlTexture2d); } }
public static void LineWidth(/* final */ GL10 pGL, /* final */ float pLineWidth) { if (GLHelper.sLineWidth != pLineWidth) { GLHelper.sLineWidth = pLineWidth; pGL.GlLineWidth(pLineWidth); } }
public static void EnableTextures(/* final */ GL10 pGL) { if (!GLHelper.sEnableTextures) { GLHelper.sEnableTextures = true; pGL.GlEnable(GL10Consts.GlTexture2d); } }
public static void DisableBlend(/* final */ GL10 pGL) { if (GLHelper.sEnableBlend) { GLHelper.sEnableBlend = false; pGL.GlDisable(GL10Consts.GlBlend); } }
public static void EnableBlend(/* final */ GL10 pGL) { if (!GLHelper.sEnableBlend) { GLHelper.sEnableBlend = true; pGL.GlEnable(GL10Consts.GlBlend); } }
public static void DisableTexCoordArray(/* final */ GL10 pGL) { if (GLHelper.sEnableTexCoordArray) { GLHelper.sEnableTexCoordArray = false; pGL.GlDisableClientState(GL10Consts.GlTextureCoordArray); } }
public static void DisableVertexArray(/* final */ GL10 pGL) { if (GLHelper.sEnableVertexArray) { GLHelper.sEnableVertexArray = false; pGL.GlDisableClientState(GL10Consts.GlVertexArray); } }
public void OnSurfaceChanged(Javax.Microedition.Khronos.Opengles.IGL10 glUnused, int width, int height) { _width = width; _height = height; GLES20.GlViewport(0, 0, width, height); Android.Opengl.Matrix.FrustumM(projectionMatrix, 0, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 10.0f); }
protected virtual void OnApplyTransformations(/* final */ GL10 pGL) { this.ApplyTranslation(pGL); this.ApplyRotation(pGL); this.ApplyScale(pGL); }
public static void EnableLightning(/* final */ GL10 pGL) { if (!GLHelper.sEnableLightning) { GLHelper.sEnableLightning = true; pGL.GlEnable(GL10Consts.GlLighting); } }
public void OnSurfaceCreated(Javax.Microedition.Khronos.Opengles.IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config) { // Set the background frame color GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f); mTriangle = new Triangle(); mSquare = new Square(); }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== public override void OnDraw(GL10 pGL, Camera pCamera) { if (this.mColorEnabled) { pGL.GlClearColor(this.mRed, this.mGreen, this.mBlue, this.mAlpha); pGL.GlClear(Javax.Microedition.Khronos.Opengles.GL10Consts.GlColorBufferBit); } }
public static void DisableLightning(/* final */ GL10 pGL) { if (GLHelper.sEnableLightning) { GLHelper.sEnableLightning = false; pGL.GlDisable(GL10Consts.GlLighting); } }
protected override void OnManagedDraw(GL10 pGL, Camera pCamera) { //final ArrayList<IEntity> entities = this.mEntities; IList<IEntity> entities = mEntities; int entityCount = entities.Count; for (int i = 0; i < entityCount; i++) { entities[i].OnDraw(pGL, pCamera); } }
public void UpdateFonts(GL10 pGL) { //final ArrayList<Font> fonts = this.mFontsManaged; List<Font> fonts = this.mFontsManaged; int fontCount = fonts.Count; if (fontCount > 0) { for (int i = fontCount - 1; i >= 0; i--) { fonts[i].Update(pGL); } } }
protected override void OnInitDraw(GL10 pGL) { base.OnInitDraw(pGL); GLHelper.EnableTextures(pGL); GLHelper.EnableTexCoordArray(pGL); }
private void AllocateAndBindTextureOnHardware(GL10 pGL) { GLHelper.BindTexture(pGL, this.mHardwareTextureID); Texture.SendPlaceholderBitmapToHardware(this.mWidth, this.mHeight); }
private void DeleteTextureOnHardware(GL10 pGL) { GLHelper.DeleteTexture(pGL, this.mHardwareTextureID); }
public abstract void OnDraw(GL10 gl10, andengine.engine.camera.Camera camera);
private void WriteTextureToHardware(GL10 pGL) { bool preMultipyAlpha = this.mTextureOptions.mPreMultipyAlpha; //final ArrayList<TextureSourceWithLocation> textureSources = this.mTextureSources; List<TextureSourceWithLocation> textureSources = this.mTextureSources; int textureSourceCount = textureSources.Count; for (int j = 0; j < textureSourceCount; j++) { TextureSourceWithLocation textureSourceWithLocation = textureSources[j]; if (textureSourceWithLocation != null) { Bitmap bmp = textureSourceWithLocation.OnLoadBitmap(); try { if (bmp == null) { throw new IllegalArgumentException("TextureSource: " + textureSourceWithLocation.ToString() + " returned a null Bitmap."); } if (preMultipyAlpha) { GLUtils.TexSubImage2D(GL10Consts.GlTexture2d, 0, textureSourceWithLocation.GetTexturePositionX(), textureSourceWithLocation.GetTexturePositionY(), bmp, GL10Consts.GlRgba, GL10Consts.GlUnsignedByte); } else { GLHelper.GlTexSubImage2D(pGL, GL10Consts.GlTexture2d, 0, textureSourceWithLocation.GetTexturePositionX(), textureSourceWithLocation.GetTexturePositionY(), bmp, GL10Consts.GlRgba, GL10Consts.GlUnsignedByte); } bmp.Recycle(); } catch (IllegalArgumentException iae) { // TODO Load some static checkerboard or so to visualize that loading the texture has failed. Debug.E("Error loading: " + textureSourceWithLocation.ToString(), iae); if (this.mTextureStateListener != null) { this.mTextureStateListener.OnTextureSourceLoadExeption(this, textureSourceWithLocation.mTextureSource, iae); } else { throw iae; } } } } }
protected override void DrawVertices(/* final */ GL10 pGL, /* final */ Camera pCamera) { pGL.GlDrawArrays(GL10Consts.GlTriangleStrip, 0, 4); }
protected abstract void OnApplyVertices(/* final */ GL10 pGL);
protected abstract void DrawVertices(/* final */ GL10 pGL, /* final */ Camera pCamera);
protected override void OnManagedDraw(GL10 pGL, Camera pCamera) { if (this.mCamera != null) { pGL.GlMatrixMode(GL10Consts.GlProjection); this.mCamera.OnApplyCameraSceneMatrix(pGL); { pGL.GlMatrixMode(GL10Consts.GlModelview); pGL.GlPushMatrix(); pGL.GlLoadIdentity(); base.OnManagedDraw(pGL, pCamera); pGL.GlPopMatrix(); } pGL.GlMatrixMode(GL10Consts.GlProjection); } }
protected void ApplyScale(/* final */ GL10 pGL) { /* final */ float scaleX = this.mScaleX; /* final */ float scaleY = this.mScaleY; if (scaleX != 1 || scaleY != 1) { /* final */ float scaleCenterX = this.mScaleCenterX; /* final */ float scaleCenterY = this.mScaleCenterY; pGL.GlTranslatef(scaleCenterX, scaleCenterY, 0); pGL.GlScalef(scaleX, scaleY, 1); pGL.GlTranslatef(-scaleCenterX, -scaleCenterY, 0); } }
protected void ApplyRotation(/* final */ GL10 pGL) { /* final */ float rotation = this.mRotation; if (rotation != 0) { /* final */ float rotationCenterX = this.mRotationCenterX; /* final */ float rotationCenterY = this.mRotationCenterY; pGL.GlTranslatef(rotationCenterX, rotationCenterY, 0); pGL.GlRotatef(rotation, 0, 0, 1); pGL.GlTranslatef(-rotationCenterX, -rotationCenterY, 0); } }
protected void ApplyTranslation(/* final */ GL10 pGL) { pGL.GlTranslatef(this.mX, this.mY, 0); }
protected override void OnApplyTransformations(GL10 pGL) { base.OnApplyTransformations(pGL); this.mTextureRegion.OnApply(pGL); }
public void updateTextures(GL10 pGL) { HashSet<Texture> texturesManaged = this.mTexturesManaged; //final ArrayList<Texture> texturesLoaded = this.mTexturesLoaded; //final ArrayList<Texture> texturesToBeLoaded = this.mTexturesToBeLoaded; //final ArrayList<Texture> texturesToBeUnloaded = this.mTexturesToBeUnloaded; List<Texture> texturesLoaded = this.mTexturesLoaded; List<Texture> texturesToBeLoaded = this.mTexturesToBeLoaded; List<Texture> texturesToBeUnloaded = this.mTexturesToBeUnloaded; /* First reload Textures that need to be updated. */ int texturesLoadedCount = texturesLoaded.Count; if (texturesLoadedCount > 0) { for (int i = texturesLoadedCount - 1; i >= 0; i--) { Texture textureToBeUpdated = texturesLoaded[i]; if (textureToBeUpdated.IsUpdateOnHardwareNeeded()) { textureToBeUpdated.UnloadFromHardware(pGL); textureToBeUpdated.LoadToHardware(pGL); } } } /* Then load pending Textures. */ int texturesToBeLoadedCount = texturesToBeLoaded.Count; if (texturesToBeLoadedCount > 0) { for (int i = texturesToBeLoadedCount - 1; i >= 0; i--) { Texture textureToBeLoaded = texturesToBeLoaded[i]; texturesToBeLoaded.RemoveAt(i); if (!textureToBeLoaded.IsLoadedToHardware()) { textureToBeLoaded.LoadToHardware(pGL); } texturesLoaded.Add(textureToBeLoaded); } } /* Then unload pending Textures. */ int texturesToBeUnloadedCount = texturesToBeUnloaded.Count; if (texturesToBeUnloadedCount > 0) { for (int i = texturesToBeUnloadedCount - 1; i >= 0; i--) { Texture textureToBeUnloaded = texturesToBeUnloaded[i]; texturesToBeUnloaded.RemoveAt(i); if (textureToBeUnloaded.IsLoadedToHardware()) { textureToBeUnloaded.UnloadFromHardware(pGL); } texturesLoaded.Remove(textureToBeUnloaded); texturesManaged.Remove(textureToBeUnloaded); } } /* Finally invoke the GC if anything has changed. */ if (texturesToBeLoadedCount > 0 || texturesToBeUnloadedCount > 0) { //System.gc(); // TODO: See if any equivalent to System.gc(); is required } }
public void UnloadFromHardware(GL10 pGL) { GLHelper.EnableTextures(pGL); this.DeleteTextureOnHardware(pGL); this.mHardwareTextureID = -1; this.mLoadedToHardware = false; if (this.mTextureStateListener != null) { this.mTextureStateListener.OnUnloadedFromHardware(this); } }
private void ApplyTextureOptions(GL10 pGL) { TextureOptions textureOptions = this.mTextureOptions; pGL.GlTexParameterf(GL10Consts.GlTexture2d, GL10Consts.GlTextureMinFilter, textureOptions.mMinFilter); pGL.GlTexParameterf(GL10Consts.GlTexture2d, GL10Consts.GlTextureMagFilter, textureOptions.mMagFilter); pGL.GlTexParameterf(GL10Consts.GlTexture2d, GL10Consts.GlTextureWrapS, textureOptions.mWrapS); pGL.GlTexParameterf(GL10Consts.GlTexture2d, GL10Consts.GlTextureWrapT, textureOptions.mWrapT); pGL.GlTexEnvf(GL10Consts.GlTextureEnv, GL10Consts.GlTextureEnvMode, textureOptions.mTextureEnvironment); }
private static int GenerateHardwareTextureID(GL10 pGL) { pGL.GlGenTextures(1, Texture.HARDWARETEXTUREID_FETCHER, 0); return Texture.HARDWARETEXTUREID_FETCHER[0]; }
public void LoadToHardware(GL10 pGL) { GLHelper.EnableTextures(pGL); this.mHardwareTextureID = Texture.GenerateHardwareTextureID(pGL); this.AllocateAndBindTextureOnHardware(pGL); this.ApplyTextureOptions(pGL); this.WriteTextureToHardware(pGL); this.mUpdateOnHardwareNeeded = false; this.mLoadedToHardware = true; if (this.mTextureStateListener != null) { this.mTextureStateListener.OnLoadedToHardware(this); } }
protected override void OnManagedDraw(/* final */ GL10 pGL, /* final */ Camera pCamera) { if (this.mCullingEnabled == false || this.IsCulled(pCamera) == false) { this.OnInitDraw(pGL); pGL.GlPushMatrix(); { this.OnApplyVertices(pGL); this.OnApplyTransformations(pGL); this.DrawVertices(pGL, pCamera); } pGL.GlPopMatrix(); } }