98 pagesV  1 2 3 4 5 6 > »  
 
REPLY
> OpenGL 2.0+ for Android
usnavii
Message#1
10.01.13, 22:39
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 967
Check in: 07.06.12

Reputation:-  115  +

What is this topic for?
Many created the illusion of the complexity of learning "OpenGL", and not understanding the simplicity of this library for a programmer.
And even using the "engine" you need to understand how it interacts with the OS, which can / cannot be specific devices.

In this article I will try to go beyond the standard examples - namely, I will try to tell why and for what.
(the more I promised it long ago)
Readers are required at least a superficial knowledge of any PL.

Corrections are welcome.

Everything further is devoted to the library OpenGL ES 2.0 for Android, and subsequent versions.

OpenGL Description
Introduction
What is the OpenGL ES 2.0 library?
At a basic level, OpenGL ES 2.0 is just a specification, that is, a document describing a set of functions and their exact behavior. Equipment manufacturers based on this specification create implementations - libraries of functions corresponding to a set of specification functions (W:).

OpenGL focuses on the following two tasks:
Hide the complexity of adapting various 3D accelerators, and provide the developer with a single API.

For the programmer, OpenGL provides a low-level library for accessingGPU ( GPU ).

Scheme of options for the implementation of the library (from the point of view of the programmer + for comparison DirectX):
Attached Image

Android 99.99% uses option B.
That is, the implementation of OpenGL ES is part of the driver,
unlike DirectX, which is rather a layer between the application and the driver.
There are still some OpenGL implementations, for example, Mesa3D, but they mostly develop quite slowly and often lag behind several generations of chip maker solutions.

Which is better, DirectX or OpenGL?
The question is not correct. For example, if you need multiplatform - you can forget about DirectX.
And in the opinion of the author DirectX is too “overgrown” with tails ... (but it is very subjective)
+ The comparison is not entirely correct, since DirectX, in addition to graphics, implements many interfaces (and quite kosher - including sound, input, network, etc.)

Which is faster, DirectX or OpenGL?

Also not a correct question, it all depends on the experience of the programmer.
But again, in the opinion of the author (me), non-standard features are easier to implement on modern versions of OpenGL and even more so.
this does not require transitions to new operating systems (unlike DirectX 10).
The time for studying is also much less. + portability.

Now a little about the GPU:
Currently (December 2012), Android devices have two generations of GPUs that support OpenGL ES 2.0 (almost 95%) and only support versions 1.0 and 1.1.
Hardware backward compatibility is NOT.
Therefore, to consider the version of the standard less than 2.0 in the opinion of the author except for archaeologists does not make sense.
(standard version 3.0 is backward compatible with 2.0)

The structure of the pipeline OpenGL 1.x:
Attached Image


The structure of the pipeline OpenGL 2.x +:
Attached Image


That is, part of the blocks with the "iron logic" was replaced by programmable processors.
Question: why?

And the whole thing is that the hardware has implemented quite a few functions, because of this, significant restrictions were created in the further development and flexibility was zero.
History (some):
The first attempts to transfer calculations from Cpu (central processor) were implemented in the first Geforce (and not in Voodoo, as many people think), to call the technology T & L.
It allowed the hardware to calculate the lighting on the GPU and to perform the simplest shaders.
It turned out "fast", but there was not even minimal flexibility left. There is a hardware-implemented lighting method, for example, using. No - and will not.
The next milestone is GeForce 3, which already had a completely programmable logic, but the processor units were not yet universal.
That is, the blocks were divided into machining vertices and fragment (machining pixels).
Some could be overloaded, others were idle ...
What is the point of increasing the processors (computing units) of the GPU?
The fact is that graphic errors are almost linearly scaled, that is, an increase in processors from 100 to 200, for example, gives almost 100% performance gains, since in computer graphics the current calculation usually does not depend on the previous one - that is, it is easy to pair.
But there are some limitations, which will be written below.
Now about OpenGL ES itself:

What can OpenGL ES do?
The basic principle of OpenGL is to obtain sets of vector graphics primitives in the form of points, lines and polygons, followed by mathematical processing of the data and the construction of raster images on the screen and / or in memory. Vector transformations and rasterization are performed by a graphics pipeline (graphics pipeline), which is essentially a discrete automaton. The absolute majority of OpenGL commands fall into one of two groups: either they add graphic primitives to the entrance to the pipeline, or they configure the pipeline for different transformations.
The key feature is that the CPU and GPU do not work synchronously, that is, the CPU does not wait until the end of execution of commands from the GPU, but continues to work (if there were no additional instructions).
There is a stack of commands (instructions) OpenGL.
(The stack is of two types, fifo and lifo. FIFO - the acronym "First In, First Out" (eng.). The principle of "first come, first go", LIFO - the acronym "Last In, First Out" (eng.), denoting the principle of “last came, first went.” OpenGL uses fifo (queue)).

Lesson first end.
OpenGL is a finite state machine.
What does it mean?

Imagine the conveyor production Ded.moroz =)

On the one hand you throw blanks, on the other hand there is a finished product.
But you are standing at the console, which has several levers - and depending on the switching of these levers, tanks, dolls, crackers come out.
But a doll can never be born, that is, at a given time only one type of product is possible.
Line is locatedalways in one state onlyandcan only produce certain products at a time.

This is the final state machine. I can not easily explain. Who did not understand -here

Continued as a little sleep ...
(The next topic is what is behind GLSurfaceView, how is it bad and what is EGL.)
OpenGL 2.0+ for Android (Post Leopotam # 18544726)
What is behind GLSurfaceView or the EGL library. Detailed parsing of the initialization OpenGL ES.
GLSurfaceView. improved application framework using GLSurfaceView.
About engines, optimization and general rules. + specifically about java for Android.
OpenGL Es 2.0 primitives. Matrices, vectors and transformations in OpenGL. Coordinate system for Android.
Textures in OpenGL ES 2.0.
Shaders in OpenGL ES 2.0 and GLSL.
Particle systems. Billboards Dot sprites.

All articles in PDF, thanks to who-e,Attached fileoges2.zip(2.76 MB)
. I hope it will be useful. Thank you who-e.


There is no curator in the subject. If there is a user in the subject who wants to become a Curator and the correspondingRequirements for candidates, he can apply in the topicI want to be curator(after having studied the topic header and all materials for curators).
Prior to the appointment of the curator, on filling caps, please contactmoderatorssection through a buttonPictureunder the messages to which you want to add links.


Post has been editedvaalf - 23.11.17, 12:12
Leopotam
Message#2
10.01.13, 22:56
Veteran
********
[offline]

Group: Friendssavagemessiahzine.com
Messages 1949
Check in: 14.04.09
Apple iPad Pro Wi-Fi

Reputation:-  207  +

It would be nice to explain on fingers what a finite state machine is (more correct name, but not discrete) and that it is necessary to save / restore state changes of the state machine, since it is one for the whole application and changing flags in one place can cause funny glitches in another.

Post has been editedLeopotam - 10.01.13, 22:58
usnavii
Message#3
10.01.13, 22:57
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 967
Check in: 07.06.12

Reputation:-  115  +

Now an example of the simplest initialization of OpenGL ES 2.0 for Android (from Google’s premers, absolutely clumsy and not applicable in real life =)):

In the application, the OnCreate method:

super.onCreate (savedInstanceState);

requestWindowFeature (Window.FEATURE_NO_TITLE); // Remove the title
getWindow (). setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); // Set Fullscreen Mode

try {// try to initialize OpenGL
glSurfaceView = new GLSurfaceView (this);

// Next, install the OpenGL ES version equal to 2
glSurfaceView.setEGLContextClientVersion (2);

renderer = new nRender ();

glSurfaceView.setRenderer (renderer); // set up our implementation of GLSurfaceView.Renderer for event handling

glSurfaceView.setRenderMode (GLSurfaceView.RENDERMODE_CONTINUOUSLY); // frame shift mode
// RENDERMODE_CONTINUOUSLY - automatic frame change,
// RENDERMODE_WHEN_DIRTY - on request (glSurfaceView.requestRender ();)

setContentView (glSurfaceView);

} catch (RuntimeException e) {} // display the window "alas, the device is too high ..."


,

Next, create the nRender class.

package com.example.ogl1;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import java.util.Random;

public class nRender implements GLSurfaceView.Renderer
{
public nRender () {
}

public void onDrawFrame (GL10 glUnused) {// Frame rendering

Random rnd = new Random ();

// Set a random color and make epileptics go crazy =)
// Color is set in RGBA format, from 0.0f to 1.0f.
GLES20.glClearColor (((float) rnd.nextInt (2) /2.0f), ((float) rnd.nextInt (2) /2.0f), ((float) rnd.nextInt (2) /2.0f), 1.0 f);

GLES20.glClear (GLES20.GL_COLOR_BUFFER_BIT); // Clear the color buffer
}

public void onSurfaceChanged (GL10 glUnused, int width, int height) {// change the surface, for example, change the size

GLES20.glViewport (0, 0, width, height);
// Set the position and size of the viewport
// the viewport is set relative to the surface (OpenGLSurface), in this case, the entire screen.
// I note that GLES20.glClear cleans the entire surface, depending on the Viewport installation.
}

public void onSurfaceCreated (GL10 glUnused, EGLConfig config) {// called when creating a surface

}
}


Next, we try to run, and get the dream epileptic ...

This example is canonical (according to the documentation), but wretched and ugly in all its manifestations ....

Post has been editedusnavii - 17.01.13, 11:55
usnavii
Message#4
10.01.13, 23:22
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 967
Check in: 07.06.12

Reputation:-  115  +

OpenGL is a finite state machine.


What does it mean?

Imagine the conveyor production Ded.moroz =)

On the one hand you throw blanks, on the other hand there is a finished product.
But you are standing at the console, which has several levers - and depending on the switching of these levers, tanks, dolls, crackers come out.
But a doll can never be born, that is, at a given time only one type of product is possible.
Line is locatedalways in one state onlyandcan only produce certain products at a time.

This is the final state machine. I can not easily explain. Who did not understand -here

Continued as a little sleep ...
(The next topic is what is behind GLSurfaceView, how is it bad and what is EGL.)

Post has been editedusnavii - 10.01.13, 23:26
Leopotam
Message#5
11.01.13, 10:01
Veteran
********
[offline]

Group: Friendssavagemessiahzine.com
Messages 1949
Check in: 14.04.09
Apple iPad Pro Wi-Fi

Reputation:-  207  +

A finite state machine is a system that contains several states, and you can clearly determine which of them is in it. This is if the clever and incomprehensible.
If closer to displaying graphics, for example, displaying a Santa Claus model on the screen:
*) there is a single conveyor belt for displaying the image on the screen, at the input of which Santa Claus models are fed, and at the output we get a 2d picture ready for display on the monitor. The pipeline performs data processing sequentially, without gaps. Models are a set of vertices and triangular faces (see P.S.1), connecting 3 adjacent vertices.
*) The main conveyor console has, for example, 5 toggle switches (P.S.2), each of which can be in the on / off state (see P.S.3):
-) tumbler "draw smoothly or with sharp edges."
-) toggle switch "draw with texture or just solid color". Under this toggle switch there is a photo frame for inserting the desired texture.
-) toggle switch "draw all faces or only faces" (for example, for transparent objects).
-) tumbler "clear only the depth buffer or the depth buffer and the color (image) buffer".
-) some more, with a red button.
*) The starting values ​​of the switches on the console are set at the time of initialization of OpenGL and stored in a special area called the context. Yes, OpenGL can display an image in 2 windows in one application, each of which will have its own independent context and its own independent pipeline.
*) The conveyor works throughout the life of the application window, using the current settings on the remote control for drawing Santa Clauses.There is no need to re-set the switches to the old position before each drawing.
*) Elves sitting inside the processing unit of incoming information through the conveyor do not immediately display the result on the screen, but only after performing the necessary rasterization-drawing operations inside themselves, parallelizing each other. The more sophisticated the graphics processor, the more elves able to work in parallel to draw dots sitting inside. At the same time, the conveyor is suspended until the whole model is processed. If there is a lot of data, the elves sitting inside will not have time to process such a volume and blocking the conveyor will cause a simple CPU that is waiting for the pipeline to become free - from here we see a drop in fps with a large flow of information weak GPU.

Example.
The conveyor launched, Santa Claus drove on the tape. And after 5 pieces, we remember that we do not need glamor-smooth, but only chopped with an ax, only hardcore models at the exit. We approach the console and perekchelkivaem first toggle switch (see above). All, all subsequent models will be drawn, like a woodcarver was drunk and forgot about polishing and other improvements.We do not need to click on the console before each subsequent model.
The Snow Maiden came running, watching all this indecency on the screen and said that it would be nice to color Santa Claus, because the glamorous pink something with inaccurate edges looks uncanonically on the screen, although she likes it. We take from her a photograph-picture of a real Santa Claus, slip it into the frame under the texturing tumbler and flick it. All, all subsequent Grandfathers Frost will look with superimposed image-texture and with unsmoothed edges.We do not need to click on the console before each subsequent model.
The Snow Maiden came in another 10 models, already a little drunk, and declared that Santa Claus would be better off to be glamorous and even, but should have a similarity to the photo. ok, let's click the smoothing switch and go ahead to celebrate NG. At the output we get a textured and smoothed Santa Claus for all subsequent models.We do not need to click on the console before each subsequent model.

P.S.1. In fact, OpenGL supports not only triangular faces, but it is better to use them to unify the whole process.
P.S.2. They are not 5, but much more - that's the point of the OpenGL state machine - there are a lot of settings, each of which is responsible for something different and which changes need to be closely monitored in order not to get Evil Santa, for example.
P.S.3. There can be more than two states if the setting implies several options of values.

Post has been editedLeopotam - 11.01.13, 10:36
phonecrusher_nik
Message#6
11.01.13, 10:14
Reactive sloth
*********
[offline]

Group: Friendssavagemessiahzine.com
Messages 5243
Check in: 19.03.12
Sony Xperia XZ1 Compact

Reputation:-  502  +

very interesting, but in my opinion you should ask the moderators to fix this topic in important


--------------------
Apple MacBook Pro 15:i7, hd4600, g650m, 16GB RAM, Samsung Pro 840 500GB SSD, macOS Mojave
Apple MacBook Pro 13:i5, iris 650, 8GB RAM, SSD 256GB, macOS Mojave
Sony Xperia XZ1 Compact: Android 9
Leopotam
Message#7
11.01.13, 17:10
Veteran
********
[offline]

Group: Friendssavagemessiahzine.com
Messages 1949
Check in: 14.04.09
Apple iPad Pro Wi-Fi

Reputation:-  207  +

phonecrusher_nik @ 01/11/2013, 11:14*
very interesting

something, see, not very :)
phonecrusher_nik
Message#8
11.01.13, 20:00
Reactive sloth
*********
[offline]

Group: Friendssavagemessiahzine.com
Messages 5243
Check in: 19.03.12
Sony Xperia XZ1 Compact

Reputation:-  502  +

Leopotam
Well, not everyone wants to learn something, 70% of game developers from this site are always looking for something ready, and the remaining 30% do it themselves, for example, I want to do it myself, and I'm interested

+ in appearance, OpenGL is very difficult, so many just pass by


--------------------
Apple MacBook Pro 15:i7, hd4600, g650m, 16GB RAM, Samsung Pro 840 500GB SSD, macOS Mojave
Apple MacBook Pro 13:i5, iris 650, 8GB RAM, SSD 256GB, macOS Mojave
Sony Xperia XZ1 Compact: Android 9
xotta6bl4
Message#9
15.01.13, 11:11
Pinus nigra
*********
[offline]

Group: Honorary Gameday
Messages 3038
Check in: 03.07.10
Google Pixel 2 XL

Reputation:-  293  +

and the remaining 30% do it themselves

Yes, you, my friend, optimist.


--------------------
Motorola DROID [Steel Droid v.10.8], Galaxy Nexus (Sprint) [4.3 Stock, GJ04 radio, GJ04 modem], Lumia 735 [Windows 10], LeEco Le2 (EUI5.8.018), Google Pixel 2 XL

Suvitruf
Message#10
15.01.13, 12:12
Alea iacta est
*******
[offline]

Group: Developers
Messages 1295
Check in: 08.09.12
Sony Xperia X Compact

Reputation:-  174  +

Well, not everyone wants to learn something, 70% of game developers from this site are always looking for something ready, and the remaining 30% do it themselves, for example, I want to do it myself, and I'm interested


Here the situation is ambiguous.

Previously, there were not so many frameworks and engines. If you want to write a game, you need to know Open GL. Now with these designers, people do not even understand how the graphics pipeline works.

On the one hand, a higher abstraction over Open GL simplifies development, on the other hand, the basics and guts of engines should also be known.


--------------------
If someone does not remember, then it does not exist.
usnavii
Message#11
17.01.13, 12:56
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 967
Check in: 07.06.12

Reputation:-  115  +

3. What is behind GLSurfaceView or the EGL library. Detailed parsing of the initialization OpenGL ES.

BehindGLSurfaceViewOpenGL initialization is hidden using the EGL library.

EGL- the interface between the graphics adapter API, such asOpengl esandOpenvgand window control system platform. EGL also provides interoperability between APIs for efficient data transfer — for example, between a video subsystem running with OpenMAX AL and a GPU running OpenGL ES.

EGL provides mechanisms for creating a surface (Surface) on which an API client, such as OpenGL ES or OpenVG, creates graphics. EGL synchronizes the client API and the native visualization API for the platform (in the case of Android it is Skia). This allows seamless, high-performance, accelerated rendering using both OpenGL ES and OpenVG for mixed 2D and 3D rendering.

The native platform window system is a window system that provides standard tools and protocols for building a graphical user interface. In the case of Android, this is SurfaceFlinger, for * nix this is usually the X Window System, MacOs and Windows use their own, non-compatible system.

In early implementations of the OpenGL standard, there was an omission during the creation of the GLSurface surface in the context of a window system.
For initialization, it was necessary to use the tools of the operating system itself, which were very different from each other and it was not even always possible to provide the same look and functionality.
There were a lot of non-standard implementations - these are SDL, GLUT, CPW, NGL, etc.
But still there was no single standard.
The EGL library was created to close this space.

Openvg- standard API designed for hardware-accelerated two-dimensionalvectorgraphics. Since on the Android platform, this API is not involved (it is even strange why this is the case) I will not consider it. = (

Let's see what doesGLSurfaceView (source):

(I highlight only the key points)


public class GLSurfaceView extends SurfaceView

From this line it is clear that GLSurfaceView is an extension of SurfaceView.

SurfaceView provides selected drawing surfaces built into the Activity hierarchy. You can control the format of this surface and, if you want, its size; SurfaceView takes care of placing the surface in the right place on the screen. Accordingly, you can place the view-shki as usual SurfaceView, or for example, embed GLSurfaceView into your control.

...
holder.setFormat (PixelFormat.RGB_565);
...

Next, GLSurfaceView sets the format of its surface as RGB_565 (16bit color).
It is worth paying attention to, details below.

Now the initialization of OpenGL:

...
EGL10 Egl = (EGL10) EGLContext.getEGL ();
...

Getting an instance of a wrapper EGL.

wrapper- library wrapper, is an intermediate layer between the application program and another library or application programming interface (API).
The purpose of writing a library wrapper may be to ensure the operability of the library (API) in any (often scripting) language in which a direct call to the functions of this library is difficult or impossible.
In Android, the GLES and EGL classes are wrappers for the native OpenGL and EGL libraries.

...
mEglDisplay = mEgl.eglGetDisplay (EGL10.EGL_DEFAULT_DISPLAY);
...

Getting reference to standard display.
There can be several displays in the system, if you need access to other displays, the constant EGL_DEFAULT_DISPLAY needs to be replaced with the corresponding one. All constants except EGL_DEFAULT_DISPLAY are platform dependent.

...
int] version = new int [2];
mEgl.eglInitialize (mEglDisplay, version);
...

Initialize EGL for a specific display.
Returns the EGL version in the version] array.

...
EGLConfig mEglConfig = mEGLConfigChooser.chooseConfig (mEgl, mEglDisplay);
...

Selects the OpenGL surface configuration.
This is the most important point in the initialization of OpenGL.
It is at this stage that you can set the color depth, buffers, anti-aliasing, and a bunch of parameters.
Below is a very detailed description.

...
mEglContext = egl.eglCreateContext (display, config, EGL10.EGL_NO_CONTEXT, mEGLContextClientVersion! = 0? attrib_list: null);
...

We create a context of a certain configuration.
Very "hard" operation.
At this very moment, a part of the graphics driver responsible for 3D starts up,
a lot of checks are happening, large amounts of memory are initialized, etc.

That's it, OpenGL is initialized.

Now create GLSurface:
...
egl.eglCreateWindowSurface (display, config, nativeWindow, null);
...

Creat one call. nativeWindow - link to the surface / window where the OpenGLSurface will be created.
(please pay attention to the fact that this method can only be called from SurfaceView or its heirs due to the restriction in the EGL wrapper)

And sets the current context:
...
mEgl.eglMakeCurrent (mEglDisplay, mEglSurface, mEglSurface, mEglContext);
...

That's all. You can draw.
OpenGL context is created in 7 EGL calls.

All the above was given to understand the initialization process.
I will not give a full working example of initialization, since it does not make sense to invent bicycles and the basis of the application
The following examples will be GLSurfaceView, with a few changes.

Another necessary function of EGL is frame change (swap buffers):
...
mEgl.eglSwapBuffers (mEglDisplay, mEglSurface)
...

Here I think everything is clear.


Now let's look at the GLSurface configurations.

OpenGLSurface configuration is the ability to create an OpenGLSurface with different parameters, such as color depth, anti-aliasing, Z-buffer / trap depth and a bunch of parameters.

For a programmer, a configuration pattern is a one-dimensional array of integers with key-value pairs (written in sequence).
The array must always end with the key EGL10.EGL_NONE.

An example of such an array:
int] configSpec = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_RENDERABLE_TYPE, 4,
EGL10.EGL_SAMPLE_BUFFERS, 1
EGL10.EGL_SAMPLES, 4,
EGL10.EGL_NONE
};


Possible configuration keys:
EGL_ALPHA_SIZE
EGL_ALPHA_MASK_SIZE
EGL_BIND_TO_TEXTURE_RGB
EGL_BIND_TO_TEXTURE_RGBA
EGL_BLUE_SIZE
EGL_BUFFER_SIZE
EGL_COLOR_BUFFER_TYPE
EGL_CONFIG_CAVEAT
EGL_CONFIG_ID
EGL_CONFORMANT
EGL_DEPTH_SIZE
EGL_GREEN_SIZE
EGL_LEVEL
EGL_LUMINANCE_SIZE
EGL_MAX_PBUFFER_WIDTH
EGL_MAX_PBUFFER_HEIGHT
EGL_MAX_PBUFFER_PIXELS
EGL_MAX_SWAP_INTERVAL
EGL_MIN_SWAP_INTERVAL
EGL_NATIVE_RENDERABLE
EGL_NATIVE_VISUAL_ID
EGL_NATIVE_VISUAL_TYPE
EGL_RED_SIZE
EGL_RENDERABLE_TYPE
EGL_SAMPLE_BUFFERS
EGL_SAMPLES
EGL_STENCIL_SIZE
EGL_SURFACE_TYPE
EGL_TRANSPARENT_TYPE
EGL_TRANSPARENT_RED_VALUE
EGL_TRANSPARENT_GREEN_VALUE
EGL_TRANSPARENT_BLUE_VALUE
...

+ there are still vendor-dependent keys,
such as EGL_COVERAGE_BUFFERS_NV (anti-aliasing for Tegra chips and others).


For us, only a few keys are important:

EGL_RED_SIZE - bit to red channel
EGL_GREEN_SIZE -bits on the green channel
EGL_BLUE_SIZE - bit to blue channel
EGL_ALPHA_SIZE - bit per alpha channel
EGL_DEPTH_SIZE - Z buffer depth
EGL_RENDERABLE_TYPE - API supported in this configuration. The value is a bitmask, since several APIs can correspond to the same configuration. OpenGL ES 2.0 corresponds to 4
EGL_SAMPLE_BUFFERS - Support for anti-aliasing
EGL_SAMPLES - number of samples per pixel
EGL_NONE - list completion

How it all works:
// Create a configuration template with [B] minimum [/ B] required parameters
int] configSpec = {
EGL10.EGL_RED_SIZE, 5, // minimum 16-bit color
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_DEPTH_SIZE, 16, // Buffer Z depth minimum 16bit
EGL10.EGL_RENDERABLE_TYPE, 4, // support GLES20
EGL10.EGL_SAMPLE_BUFFERS, 1, // anti-aliasing support
EGL10.EGL_SAMPLES, 2, // minimum 2 samples
EGL10.EGL_NONE
};

// Request a list of suitable configurations.
//
mValue = new int [1];
egl.eglChooseConfig (display, configSpec, null, 0, mValue);
int numConfigs = mValue [0]; // we get the number of configs suitable for our description.
// since the configuration template sets the MINIMUM requirements
// then in this case configurations with 32-bit color and smoothing, for example, 4 (or 8) samples will be included in the list.

if (numConfigs <= 0) {
EGLConfig] configs = new EGLConfig [numConfigs];
egl.eglChooseConfig (display, configSpec, configs, numConfigs, mValue); // Get the list of configurations.
// Now we have a filled configs configuration array
} else {No configurations were found matching the pattern.}


Important:

When more than one frame buffer configuration matches a pattern, a list of configurations is returned. The list is sorted according to the following priority rules, which are applied in order:

1. By EGL_CONFIG_CAVEAT, in the following order: EGL_NONE, EGL_SLOW_CONFIG and EGL_NON_CONFORMANT_CONFIG.
For example, the developer of the device (driver) has marked certain configurations as slow or not recommended - they will be at the bottom of the list.

2. according to EGL_COLOR_BUFFER_TYPE, in the order EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER (monochrome).

3. by the sum of the number of bits of all RGBA channels (or the depth of EGL_LUMINANCE_SIZE). That is, first in the list are configurations with a maximum color depth and then in descending order. You should pay special attention to this, because if you requested an RGB565 configuration without an alpha channel, then the first in the list will most likely be RGBA8888 configurations (with the same other parameters), since the sum of the bits of all the channels in them is larger.

4. EGL_BUFFER_SIZE in ascending order (that is, there will first be configurations with a minimum value).

5. EGL_SAMPLE_BUFFERS in ascending order.

6. EGL_SAMPLES in ascending order.

7. EGL_DEPTH_SIZE in ascending order.

8. EGL_STENCIL_SIZE in ascending order.

9. EGL_ALPHA_MASK_SIZE in ascending order.

10. EGL_NATIVE_VISUAL_TYPE (here, depending on the implementation, usually one value).

10. EGL_CONFIG_ID in ascending order (the last sorting option that guarantees uniqueness).

Sorting is not done by keys:
EGL_BIND_TO_TEXTURE_RGB, EGL_BIND_TO_TEXTURE_RGBA, EGL_CONFORMANT, EGL_LEVEL, EGL_NATIVE_RENDERABLE, EGL_MAX_SWAP_INTERVAL, EGL_MIN_SWAP_INTERVAL, EGL_RENDERABLE_TYPE, EGL_SURFACE_TYPE, EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RED_VALUE, EGL_TRANSPARENT_GREEN_VALUE, and EGL_TRANSPARENT_BLUE_VALUE.


Example. Displays all available configurations for OpenGL ES 2.0
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import javax.microedition.khronos.egl. *;

public class MyActivity extends Activity {

final int EGL_COVERAGE_BUFFERS_NV = 0x30E0;
final int EGL_COVERAGE_SAMPLES_NV = 0x30E1;

@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
getWindow (). setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

TextView textv = new TextView (this); // TextView with ScrollView to display the result
LinearLayout.LayoutParams blp = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PAREN
T);
ScrollView scrollv = new ScrollView (this);
scrollv.setLayoutParams (blp);
scrollv.addView (textv);
this.addContentView (scrollv, blp);

EGL10 Egl = (EGL10) EGLContext.getEGL (); // we get wrapper Egl
EGLDisplay EglDisplay = Egl.eglGetDisplay (EGL10.EGL_DEFAULT_DISPLAY); // get link to display
int] version = new int [2]; // array to get the EGL version
Egl.eglInitialize (EglDisplay, version); // Initialize EGL

int] configSpec = {// configuration template
EGL10.EGL_RENDERABLE_TYPE, 4, // support GLES20
EGL10.EGL_NONE // end
};
int] mValue = new int [1];
Egl.eglChooseConfig (EglDisplay, configSpec, null, 0, mValue); // get the number of configurations matching the pattern
int numConfigs = mValue [0];

EGLConfig] configs = new EGLConfig [numConfigs];
int] num_conf = new int [numConfigs];
Egl.eglChooseConfig (EglDisplay, configSpec, configs, numConfigs, mValue); // get an array of configurations

String text = "EGL version" + version [0] + "." + Version [1] + "\ n";
text + = printConfigs (configs, EglDisplay, Egl) + "\ n";

textv.setText (text);
}

private String printConfigs (EGLConfig] conf, EGLDisplay EglDisplay, EGL10 Egl) {
String text = "";
for (int i = 0; i int] value = new int [1];
if (conf [i]! = null)
{
text + = "==== Config No." + i + "==== \ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL10.EGL_RED_SIZE, value);
text + = "EGL_RED_SIZE =" + value [0] + "\ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL10.EGL_GREEN_SIZE, value);
text + = "EGL_GREEN_SIZE =" + value [0] + "\ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL10.EGL_BLUE_SIZE, value);
text + = "EGL_BLUE_SIZE =" + value [0] + "\ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL10.EGL_ALPHA_SIZE, value);
text + = "EGL_ALPHA_SIZE =" + value [0] + "\ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL10.EGL_DEPTH_SIZE, value);
text + = "EGL_DEPTH_SIZE =" + value [0] + "\ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL10.EGL_SAMPLE_BUFFERS, value);
text + = "EGL_SAMPLE_BUFFERS =" + value [0] + "\ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL10.EGL_SAMPLES, value);
text + = "EGL_SAMPLES =" + value [0] + "\ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL_COVERAGE_BUFFERS_NV, value);
text + = "EGL_COVERAGE_BUFFERS_NV =" + value [0] + "\ n";
Egl.eglGetConfigAttrib (EglDisplay, conf [i], EGL_COVERAGE_SAMPLES_NV, value);
text + = "EGL_COVERAGE_SAMPLES_NV =" + value [0] + "\ n \ n";
} else {break; }

}
return text;
}
}



About anti-aliasing (anti-aliasing):
Anti-aliasing is enabled at the driver level.
Using surfaces with EGL_SAMPLE_BUFFERS sets MSAA mode
EGL_SAMPLES sets the number of samples per pixel, for example, when 4 we get the mode MSAAx4
You cannot control MSAA anti-aliasing during the rendering process.

EGL_COVERAGE_BUFFERS_NV and EGL_COVERAGE_SAMPLES_NV set the CSAA mode in the same way.
Some chips, for example, Tegra can only work with CSAA anti-aliasing.
In the process of rendering it is possible to manage the CSAA.

But I would not advise using either mode - but usingFXAA.
It is much "easier" in terms of calculations, it is calculated in one pass of the post-processing and gives the best visual result.
FXAA is available only for OpenGL ES 2.0 and later.


One moment left.

Remember the line from GLSurfaceView:
...
holder.setFormat (PixelFormat.RGB_565);
...


What happens if we try to initialize the GLSurface in RGBA8888 mode with on the surface with PixelFormat.RGB_565?

Options:
1. The system will lead RGBA8888 to RGB565 and we get a 16bit color without transparency.
2. The system will normally display RGBA8888, spitting on RGB565.
3. Everything will fall with a bang.

In fact, any of these options can happen, so it is strongly recommended to bring the SurfaceView to the GLSurface format.

Bring SurfaceView to the desired format in approximately the following way:
...
GLSurfaceView.getHolder (). SetFormat (PixelFormat.RGBA_8888);
...


And yet, you never need to hamster and try to use the maximum configuration as you have to pay for everything with performance.

That's all about the initialization of OpenGL ES 2.0.

Further detailed consideration of GLSurfaceView, its methods and subclasses.

Post has been editedusnavii - 17.01.13, 15:17
Lirick
Message#12
18.01.13, 12:13
Local
*****
[offline]

Group: Friendssavagemessiahzine.com
Messages 309
Check in: 01.11.11

Reputation:-  23  +

One of the few topics that is pleasant and helpful to read.
Spectra
Message#13
18.01.13, 13:36
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 855
Check in: 25.05.11

Reputation:-  50  +

usnavii
One piece of advice, better make everything in a hat, but it’s not so convenient, and then you don’t have to search.
usnavii
Message#14
18.01.13, 21:56
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 967
Check in: 07.06.12

Reputation:-  115  +

Spectra @ 01/18/2013, 14:36*
Din advice, better make everything in a hat, but it’s not so convenient, and then you don’t have to look for it.


I rendered links in the first message (to the very beginning) ...
Or how best to do?
------------
Some sentences are clumsy =)
I simply translated from the original source (ENG, etc.), and then you yourself begin to make sentences in the style of the language.
Koryavosti will try to remove.

Post has been editedusnavii - 18.01.13, 21:59
Mmx ice
Message#15
25.01.13, 13:30
Local
*****
[offline]

Group: Friendssavagemessiahzine.com
Messages 106
Check in: 16.02.09
360 N4s

Reputation:-  2  +

And the sequel will be?
usnavii
Message#16
25.01.13, 15:40
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 967
Check in: 07.06.12

Reputation:-  115  +

MmX Ice @ 01/25/2013, 2:30 pm*
And the sequel will be?


Will be.
Today Tomorrow.

Alas, the faculty and other insuperable circumstances did not allow me to finish on time ... = (

UPD: less than a week ...

Post has been editedusnavii - 30.01.13, 15:22
Suvitruf
Message#17
25.01.13, 23:01
Alea iacta est
*******
[offline]

Group: Developers
Messages 1295
Check in: 08.09.12
Sony Xperia X Compact

Reputation:-  174  +

I am now engaged in the port of toys now. The whole game engine in C ++ is written.

And I'm wondering what will be faster - the whole game is in Java or is it in C ++ followed by a native call?


--------------------
If someone does not remember, then it does not exist.
usnavii
Message#18
26.01.13, 03:12
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 967
Check in: 07.06.12

Reputation:-  115  +

Suvitruf @ 01.26.2013, 00:01*
And I'm wondering what will be faster - the whole game is in Java or is it in C ++ followed by a native call?


Of course C ++.
In any case, saving memory several times.
When used properly.

On the other hand, the calls are not much slower, but taking into account the C ++ development tools for androyd ...
It can be called a stretch. Debugging at the level of the last decade of the last century.
flopsik
Message#19
26.01.13, 20:24
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 905
Check in: 25.01.12
Sony Ericsson Xperia Neo V

Reputation:-  80  +

is there an opengl book in russian? I would like to read. and did anyone use opengl with python? I installed everything and practically did not find Russian-language material on this topic :(


--------------------
usnavii
Message#20
27.01.13, 20:00
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 967
Check in: 07.06.12

Reputation:-  115  +

is there an opengl book in russian? I would like to read. and did anyone use opengl with python?


A bunch of. about OpenGL.

But OpenGL ES 2.0 is so different from the "simple" OpenGL as the old-Russian (now probably only the church) from the Russian.
It seems that the meaning is clear, and the words are similar to friends, but not that ...



Posted on 01/27/2013, 20:00:

python

Just wondering why python?

Post has been editedusnavii - 30.01.13, 15:23
flopsik
Message#21
27.01.13, 23:04
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 905
Check in: 25.01.12
Sony Ericsson Xperia Neo V

Reputation:-  80  +

It's just that the language I know best :) I can also use pro with c ++, but for mastering something new, I usually use Python 3, although I can also use 2 identities

And on android, what better to use opengl or opengl es? And actually in short, what is the backside?


--------------------

98 pagesV  1 2 3 4 5 6 > » 


 mobile version    Now: 20.05.19, 07:28