Does not GLES20 Have GL_HALF_FLOAT_OES? - android

My question is simple. Why isn't there any GL_HALF_FLOAT_OES constant on Java side in GLES20.java class? However, "GLES2/gl2ext.h" on native side, has it... what happens if i specify value of this C constant on Java side manually? Do you think it is not valid and this is why they had not included it within GLES20.java class?

Float point textures are not a part of OpenGL ES 2.0 specs that's why they are not included in gl2ext.h. And please note that they are available only if GPU supports GL_EXT_color_buffer_half_float extension so you should check presence of this extension first.
Basically, you won't find constants for a lot of vendor-specific stuff too. This doesn't mean these values are invalid and it is absolutely OK to define these constants in code (my code has a lot of such constants, to name a few - constants for DXT/PVRTC compression and Tegra's CSAA).

Related

How to check if hidl_vec is empty?

In Android, we can use HIDL data types in lieu of normal C++ data types. Their functionality remains mostly the same, and this proxy code is for behind-the-scenes serialization and IPC which HIDL takes care of.
Now when I try to check if a HIDL vector is empty, I get the error that empty is not a member of hidl_vec. How then can I check this? Some other functions that work on a normal vector work with hidl_vec such as foo.size(), foo.begin(), foo.end() but I prefer to not use the size check for this reason.
#include "gmock/gmock.h"
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
hidl_vec<hidl_string> foo;
ASSERT_FALSE(foo.empty());
Throws the error:
error: no member named 'empty' in 'android::hardware::hidl_vecandroid::hardware::hidl_string'
ASSERT_FALSE(foo.empty());

How do I create my own data type with Arrow

What are the steps to create my own data type when using arrow.
It's simple to use something like Option with the provided extension constructors like Some(data) or None. However, how can I create my own data type that has functional operators like map() or flatMap()?
The steps to create data types in Arrow that conform to Type classes like Functor and therefore provide methods like map is outlined here:
Enable higher kinded type emulation. https://arrow-kt.io/docs/patterns/glossary/#higher-kinds
Implement the type class instance
https://arrow-kt.io/docs/patterns/glossary/#using-higher-kinds-with-typeclasses
In the two links above there is an example that uses ListK wrapping the std lib List. What the documentation example does not mention is that in order to expand the extensions which Functor would add over ListK including map, lift, etc as defined in the Functor interface it requires kapt and arrow meta.
kapt "io.arrow-kt:arrow-meta:$arrow_version"
Arrow meta is in charge of expanding Higher Kinds and Extensions for type class instances. One limitation in the current expansion is that if you plan to use both #higherkind and #extension in the same module it won't work due to the order in which kapt processes. For that you would need to have data types in one module and extensions in a different one. This is actually good practice and what we follow in Arrow because it allows user to import data types a la carte when they don't want the extensions.
If I'm understanding your question correctly:
https://arrow-kt.io/docs/patterns/glossary/
Note that the annotation processors should be able to generate the typeclass instances for you. But fundamentally you just need to decide which typeclasses your datatype will support and provide implementations for those typeclasses. (Note that the typeclasses form an inheritance hierarchy so (e.g.) if you implement Monad you (may) need to implement Functor.)

Why checkStartAndEnd is not found in Android java.util.Arrays?

I look at Android source code
https://android.googlesource.com/platform/libcore/+/cff1616/luni/src/main/java/java/util/Arrays.java#1742
I realize Android's Arrays contains a public static method named checkStartAndEnd, which is not found in Java standard SE.
However, when I type java.util.Arrays.checkStartAndEnd in Android Studio, or look at the documentation https://developer.android.com/reference/java/util/Arrays.html, I realize checkStartAndEnd isn't valid for Android's Arrays class.
May I know why is it so? Am I looking at wrong Android source code?
You cannot see / use it because it's hidden (check the #hide tag in the Javadoc). If you compare the Android Arrays class with the Java SE one, you'll see that this checkStartAndEnd basically equals to rangeCheck, which is a private method there as well. As to why did they rename it? I have no idea, maybe some licensing issue or something else.

Is there any renderscript documentation on datatype convertion functions?

After watching Jeff Sharkey great Google I/O presentation and kicking to write some renderscript to speed up my existing audio processing project. The first problem comes in is that in the example code given, the conversion function in the very first line of code isn't documented anywhere. As least not in http://developer.android.com/guide/topics/renderscript/reference.html
float4 inColor = convert_float4(*inPixel);
Well the function convert_float4() in the example is obvious enough to understand what it does. But in my case I would like to know if it exists other built-in conversions like from a char to a float which I guess could be convert_float(char*) ?
The generic answer is RS support conversion from all basic vector numeric types to other types of the same vector size. The casts are done as if they were a normal C cast for rounding.
The form is:
convert_[dest type](source type)
(2,3,4) vectors of char,uchar,int,uint,short,ushort, and float are supported.
Avoid:
float4 f = (float4)myInt4;
It doesn't do what you expect it to do.
Looks like there are no such built-ins. convert_float4() is the only conversion function declared in rc_core.c.

Why doesn't Android use more enums?

I've started to really like using C# and Java enums in my code for several reasons:
They are much more type-safe than integers, strings, or sets of boolean flags.
They lead to more readable code.
It's more difficult to set an enum to an invalid value than an int or string.
They make it easy to discover the allowed values for a variable or parameter.
Everything I've read indicates that they perform just as well as integers in C# and most JVMs.
However, the Android framework has numerous cases where flags of various types need to be passed around, but none of them seem to use enums. A couple of examples where I would think their use would be beneficial are Toast.LENGTH_SHORT / Toast.LENGTH_LONG and View.GONE, View.VISIBLE, etc.
Why is this? Do enums perform worse than simple integer values in Dalvik? Is there some other drawback I'm not aware of?
This answer is out of date as of March 2011.
Enums can be used on Froyo and up - according to this answer (Why was “Avoid Enums Where You Only Need Ints” removed from Android's performance tips?) from a member of the Android VM team (and his blog).
Previous Answer:
The official Android team recommendation is to avoid enums whenever you can avoid it:
Enums are very convenient, but
unfortunately can be painful when size
and speed matter. For example, this:
public enum Shrubbery { GROUND, CRAWLING, HANGING }
adds 740 bytes to
your .dex file compared to the
equivalent class with three public
static final ints. On first use, the
class initializer invokes the
method on objects representing each of
the enumerated values. Each object
gets its own static field, and the
full set is stored in an array (a
static field called "$VALUES"). That's
a lot of code and data, just for three
integers. Additionally, this:
Shrubbery shrub = Shrubbery.GROUND;
causes a static field lookup. If
"GROUND" were a static final int, the
compiler would treat it as a known
constant and inline it.
Source: Avoid Enums Where You Only Need Ints
Integers are smaller, and require less overhead, something that still matters on mobile devices.
A colleague of mine performed a small test regarding this situation. He auto generated a
class and an enum with the same amount of "enums". I believe he generated 30000 entries.
The results were:
.class for the class was roughly 1200KB
.class for the enum was roughly 800KB
Hope this helps someone.

Categories

Resources