Hey guys, just wondering if anyone has had any time to look at my
proposed patches. SiegeLord, you still want to commit these? Are they
okay as is?
-------- Forwarded Message --------
Subject: Re: [AD] Additional opengl functions
Date: Mon, 31 Oct 2016 22:30:09 -0500
From: Edgar Reynaldo <edgarreyna...@members.allegro.cc>
To: Allegro Developers <allegro-developers@gna.org>
On 10/29/2016 1:07 PM, SiegeLord wrote:
I'm kind of leaning on not having these included, as they seem just
simple wrappers over the existing (rarely used) functions, but I can
be swayed. Style-wise, you'll want to add spaces around your
operators, and name the functions with '_f' rather than just 'f' (e.g.
following the 'al_map_rgb_f' example).
-SL
On 10/24/2016 11:44 AM, Edgar Reynaldo wrote:
Hey guys,
I've been working with Allegro and OpenGL a bit lately, and I found that
the following additions to allegro/src/opengl/ogl_bitmap.c and
allegro/include/allegro5/allegro_opengl.h might be nice. Would you
consider them for addition, and let me know if they need to be modified,
or if they are suitable as is? If they're added, I will make a patch for
the docs to document them. The al_get_opengl_texture_positionf is to get
the u,v coordinates in fractional form, and the
al_get_opengl_texture_coordinates* functions would be to retrieve the
top left and bottom right coordinates, in pixels, and in fractional
parts of the parent texture.
My patch is attached.
Edgar
Hey SiegeLord,
I've updated the functions to use proper style and formatting. I've
added a al_get_opengl_texture_size_f function to get the fractional
width and height of a (sub) texture. I've changed
al_get_opengl_texture_position_f and al_get_opengl_texture_coordinates_f
to return bool because the underlying function call to
al_get_opengl_texture_size could fail if it's not an OpenGL texture.
Documentation has been added. The patch is attached below.
If there are any further changes or modifications you want me to make,
just let me know.
Thanks,
Edgar
docs/src/refman/opengl.txt | 45 ++++++++++++++++++++-
include/allegro5/allegro_opengl.h | 36 ++++++++++-------
src/opengl/ogl_bitmap.c | 84 +++++++++++++++++++++++++++++++++++++++
3 files changed, 149 insertions(+), 16 deletions(-)
diff --git a/docs/src/refman/opengl.txt b/docs/src/refman/opengl.txt
index ac968db..1fb779b 100644
--- a/docs/src/refman/opengl.txt
+++ b/docs/src/refman/opengl.txt
@@ -93,14 +93,55 @@ a sub-bitmap.
Returns true on success, false on failure.
Zero width and height are returned if the bitmap is not an OpenGL bitmap.
-See also: [al_get_opengl_texture_position]
+See also: [al_get_opengl_texture_position] [al_get_opengl_texture_size_f]
+
+## API: al_get_opengl_texture_size_f
+
+Retrieves the fractional size of the bitmap on its parent texture in the range
+[0.0 , 1.0]. The values may be less than 1.0 if it is a sub bitmap or the
parent
+texture is larger than the bitmap.
+
+Returns true on success, or false on failure. If the function fails, w and h
+remain unchanged.
+
+See also: [al_get_opengl_texture_size];
## API: al_get_opengl_texture_position
Returns the u/v coordinates for the top/left corner of the bitmap within the
used texture, in pixels.
-See also: [al_get_opengl_texture_size]
+See also: [al_get_opengl_texture_size] [al_get_opengl_texture_position_f]
+
+## API: al_get_opengl_texture_position_f
+
+Returns the u/v coordinates for the top left corner of the bitmap within the
+used texture, in fractional coordinates in the range [0.0 , 1.0].
+
+Returns true on success, false on failure. If the function fails, u and v
+are unchanged.
+
+See also : [al_get_opengl_texture_position]
+
+## API: al_get_opengl_texture_coordinates
+
+Returns the u/v coordinates for the top left and bottom right corners of the
+bitmap within the used texture, in pixels.
+
+See also : [al_get_opengl_texture_size] [al_get_opengl_texture_coordinates_f]
+
+## API: al_get_opengl_texture_coordinates_f
+
+Returns the u/v coordinates for the top left and bottom right corners of the
+bitmap within the used texture, in fractional coordinates in the range
+[0.0 , 1.0]. These are not guaranteed to be 0.0 and 1.0, as may be in the case
+of sub bitmaps and bitmaps smaller than the actual texture size, which may
+happen when bitmap sizes need to be powers of two.
+
+Returns true on success, false on failure. On failure, the data in the pointers
+passed into the function is unchanged.
+
+See also : [al_get_opengl_texture_coordinates]
## API: al_get_opengl_program_object
diff --git a/include/allegro5/allegro_opengl.h
b/include/allegro5/allegro_opengl.h
index 0f86a67..17b7081 100644
--- a/include/allegro5/allegro_opengl.h
+++ b/include/allegro5/allegro_opengl.h
@@ -164,20 +164,28 @@ typedef enum ALLEGRO_OPENGL_VARIANT {
ALLEGRO_OPENGL_ES
} ALLEGRO_OPENGL_VARIANT;
-AL_FUNC(uint32_t, al_get_opengl_version, (void));
-AL_FUNC(bool, al_have_opengl_extension, (const char
*extension));
-AL_FUNC(void*, al_get_opengl_proc_address, (const char
*name));
-AL_FUNC(ALLEGRO_OGL_EXT_LIST*, al_get_opengl_extension_list, (void));
-AL_FUNC(GLuint, al_get_opengl_texture,
(ALLEGRO_BITMAP *bitmap));
-AL_FUNC(void, al_remove_opengl_fbo,
(ALLEGRO_BITMAP *bitmap));
-AL_FUNC(GLuint, al_get_opengl_fbo,
(ALLEGRO_BITMAP *bitmap));
-AL_FUNC(bool, al_get_opengl_texture_size,
(ALLEGRO_BITMAP *bitmap,
- int *w, int
*h));
-AL_FUNC(void, al_get_opengl_texture_position,
(ALLEGRO_BITMAP *bitmap,
- int *u, int
*v));
-AL_FUNC(GLuint, al_get_opengl_program_object,
(ALLEGRO_SHADER *shader));
-AL_FUNC(void, al_set_current_opengl_context,
(ALLEGRO_DISPLAY *display));
-AL_FUNC(int, al_get_opengl_variant, (void));
+AL_FUNC(uint32_t, al_get_opengl_version, (void));
+AL_FUNC(bool, al_have_opengl_extension, (const char
*extension));
+AL_FUNC(void*, al_get_opengl_proc_address, (const char
*name));
+AL_FUNC(ALLEGRO_OGL_EXT_LIST*, al_get_opengl_extension_list, (void));
+AL_FUNC(GLuint, al_get_opengl_texture,
(ALLEGRO_BITMAP *bitmap));
+AL_FUNC(void, al_remove_opengl_fbo,
(ALLEGRO_BITMAP *bitmap));
+AL_FUNC(GLuint, al_get_opengl_fbo,
(ALLEGRO_BITMAP *bitmap));
+AL_FUNC(bool, al_get_opengl_texture_size,
(ALLEGRO_BITMAP *bitmap,
+ int *w,
int *h));
+AL_FUNC(bool, al_get_opengl_texture_size_f,
(ALLEGRO_BITMAP *bitmap,
+ float *w,
float *h));
+AL_FUNC(void, al_get_opengl_texture_position,
(ALLEGRO_BITMAP *bitmap,
+ int *u,
int *v));
+AL_FUNC(bool, al_get_opengl_texture_position_f,
(ALLEGRO_BITMAP* bitmap,
+ float* u ,
float* v));
+AL_FUNC(void, al_get_opengl_texture_coordinates,
(ALLEGRO_BITMAP* bitmap,
+ int* lx ,
int* ty , int* rx , int* by));
+AL_FUNC(bool,
al_get_opengl_texture_coordinates_f,(ALLEGRO_BITMAP* bitmap,
+ float* lx
, float* ty , float* rx , float* by));
+AL_FUNC(GLuint, al_get_opengl_program_object,
(ALLEGRO_SHADER *shader));
+AL_FUNC(void, al_set_current_opengl_context,
(ALLEGRO_DISPLAY *display));
+AL_FUNC(int, al_get_opengl_variant, (void));
#ifdef __cplusplus
}
diff --git a/src/opengl/ogl_bitmap.c b/src/opengl/ogl_bitmap.c
index cf76a1c..e9e270f 100644
--- a/src/opengl/ogl_bitmap.c
+++ b/src/opengl/ogl_bitmap.c
@@ -1212,6 +1212,25 @@ bool al_get_opengl_texture_size(ALLEGRO_BITMAP *bitmap,
int *w, int *h)
return true;
}
+/* Function: al_get_opengl_texture_size_f
+ */
+bool al_get_opengl_texture_size_f(ALLEGRO_BITMAP *bitmap, float *w, float *h)
+{
+ /* The designers of OpenGL ES 1.0 forgot to add a function to query
+ * texture sizes, so this will be the only way there to get the texture
+ * size. On normal OpenGL also glGetTexLevelParameter could be used.
+ */
+ int iw = 0;
+ int ih = 0;
+
+ if (!al_get_opengl_texture_size(&iw , &ih)) {
+ return false;
+ }
+ *w = al_get_bitmap_width(bitmap) / (float)iw;
+ *h = al_get_bitmap_height(bitmap) / (float)ih;
+ return true;
+}
+
/* Function: al_get_opengl_texture_position
*/
void al_get_opengl_texture_position(ALLEGRO_BITMAP *bitmap, int *u, int *v)
@@ -1224,4 +1243,69 @@ void al_get_opengl_texture_position(ALLEGRO_BITMAP
*bitmap, int *u, int *v)
*v = bitmap->yofs;
}
+/* Function: al_get_opengl_texture_position_f
+ */
+bool al_get_opengl_texture_position_f(ALLEGRO_BITMAP* bitmap , float* u ,
float* v)
+{
+ int iu = 0;
+ int iv = 0;
+ int tw = 0;
+ int th = 0;
+
+ ASSERT(bitmap);
+ ASSERT(u);
+ ASSERT(v);
+
+ al_get_opengl_texture_position(bitmap , &iu , &iv);
+ if (!al_get_opengl_texture_size(bitmap , &tw , &th)) {
+ return false;
+ }
+ *u = (float)iu / tw;
+ *v = (float)iv / th;
+ return true;
+}
+
+/* Function: al_get_opengl_texture_coordinates
+ */
+void al_get_opengl_texture_coordinates(ALLEGRO_BITMAP* bitmap , int* lx , int*
ty , int* rx , int* by)
+{
+ ASSERT(bitmap);
+ ASSERT(lx);
+ ASSERT(ty);
+ ASSERT(rx);
+ ASSERT(by);
+
+ al_get_opengl_texture_position(bitmap , lx , ty);
+ *rx = *lx + al_get_bitmap_width(bitmap);
+ *by = *ty + al_get_bitmap_height(bitmap);
+}
+
+/* Function: al_get_opengl_texture_coordinates_f
+ */
+bool al_get_opengl_texture_coordinates_f(ALLEGRO_BITMAP* bitmap , float* lx ,
float* ty , float* rx , float* by)
+{
+ int ilx = 0;
+ int ity = 0;
+ int irx = 0;
+ int iby = 0;
+ int tw = 0;
+ int th = 0;
+
+ ASSERT(bitmap);
+ ASSERT(lx);
+ ASSERT(ty);
+ ASSERT(rx);
+ ASSERT(by);
+
+ al_get_opengl_texture_coordinates(bitmap , &ilx , &ity , &irx , &iby);
+ if (!al_get_opengl_texture_size(bitmap , &tw , &th)) {
+ return false;
+ }
+ *lx = (float)ilx / tw;
+ *ty = (float)ity / th;
+ *rx = (float)irx / tw;
+ *by = (float)iby / th;
+ return true;
+}
+
/* vim: set sts=3 sw=3 et: */
_______________________________________________
Allegro-developers mailing list
Allegro-developers@gna.org
https://mail.gna.org/listinfo/allegro-developers