Hi Dmitry-
At the moment, there are approximately
1483 OpenGL functions that need basic
(suffixed or not) perl bindings to be
completed---as discussed the _c to
get things done doesn't count. :-)
Once the basic functionality is working...
There are plenty of directions for providing
completely perlish bindings. Whether to move
the suffixed routines into their own module
versus tags for export or whatever would be
a nice problem to have with full OpenGL API
bindings in a first version.
Regarding performance, there have been
discussions of optimal performance from
perl with specific timings from Mithaldu
and the point being that for some ops,
overhead in the bindings can mean the
difference between 1000 sprites being
renderable from perl OpenGL or no.
Any specific decisions based on performance
would clearly need to be based on actual
timings. Personally, I think any specific
optimized implementations could have their
own suffix and can co-exist with any other
variants historical or going forward.
Cheers,
Chris
On 7/13/2017 18:10, Dmitry Karasik wrote:
> Hi Chris,
>
> I buy the compatibility argument, but I'm rather suspicious of the performance argument -
> I'd like to see the hard numbers. As for the compatibility though, I'd rather propose to break it,
> but provide OpenGL::Modern::Compat that exposes the suffixed calls for users who don't
> want to refactor.
>
> Dmitry
>
> On Thu, Jul 13, 2017 at 05:59:50PM -0400, Chris Marshall wrote:
>> Hi Dmitri-
>>
>> My goal for the function names is clarity, simplicity,
>> unambiguousness, and DWIM. In order to avoid breaking
>> compatibility we'll have the various suffixed names
>> which may always be used and may be desired for peak
>> performance and when things are stable and decided upon,
>> we'll make the prettiest name map to the appropriate
>> implementation. For example: my thought was the _g
>> implementation might be a candidate for the default,
>> non-suffixed name.
>>
>> NOTE: We should probably come up with a way to specify
>> mappings so that folks can use different maps but still
>> be compatible with the official versions.
>>
>> On Thu, Jul 13, 2017 at 5:07 PM, Dmitry Karasik <dm...@ka...>
>> wrote:
>>
>>> Hi Chris,
>>>
>>> I appreciate this effort, I think that shift towards more
>>> perlish API is what needed. The vision I have though is
>>> actually to go another step further - probably you mean the
>>> same by writing "... these bindings are interim only pending
>>> better more perlish or more direct implementations".
>> There are two stages here: (1) where the bindings use
>> perl native types to interface with OpenGL with XS used
>> for any translations needed from perl space to C space
>> (such as hand packing data and getting a pointer), and
>> (2) a more perlish interface that mates well with idiomatic
>> perl language usages and programmer expectations.
>>
>>> But still I'd like to explain what I have in mind, namely,
>>> just one perl function with the same name as the C function.
>>>
>>> I don't pretend I understand all use cases, but I think it will
>>> be possible to write the XS in such a way so that depending on
>>> type arguments passed, it will figure out whether the parameter
>>> is a list of values or a packed string. Also, it seems to be
>>> that _c functions won't be needed, because we can provide a
>>> special wrapper function that can convert an arbitrary memory
>>> buffer from C into a (read-only) perl scalar, which can be
>>> passed as a normal argument.
>> The _c variants are pretty much only to make something
>> operable until the stage 1 bindings are done. Users should
>> no have to pack and unpack data buffers or strings by hand.
>> A basic implementation with a switch based on the arg type
>> say ref($arg) eg ARRAY, SCALAR, PDL, OpenGL::Array along with
>> argument counting could make a seamless call for many use
>> cases.
>>
>>> Packed format will be tricky though. In Prima, I adopted a
>>> similar technique for Prima::array, which is just a blessed
>>> pointer to packed scalar. One can create and extend it in C,
>>> and one can create and extend it in Perl. But surely there are
>>> other ways too.
>> I don't understand why packed format is specifically tricky.
>> In fact, it seems to me to be an artifact of implementation
>> choice that OpenGL::Array uses its own malloc/free'd data
>> rather than the contents of a perl SV.
>>
>>> So as an example let's take a glProgramUniform4fv:
>>>
>>> Case 1: just a perlish call - that'll be glProgramUniform4fv($x,$y,$z,$t),
>>> but can be uneffective, because XS has to construct the memory buffer
>>> and pass it. Yet it will be perlish okay.
>> In OpenGL 4.x the C API call in perl notation is
>> glProgramUniform4fv($program,$location,$count,$values_4f) which I would
>> translate into glProgramUniform4fv($program,$location,@values_4f) or
>> glProgramUniform4fv($program,$location,[@values_4f]) since
>> the $count can be determined by the number of elements in @values_4f
>> by poking the array ref or just gotten from the number of args on
>> the XS call stack.
>>
>> This can still be efficient because in XS we could have a static
>> array of floats and just copy the @values_f4 into them for the call,
>> no malloc/free/New/SafeFree.
>>
>>> Case 2: packed array: that's be glProgramUniform4fv(
>> gl_pack('f',$x,$y,$z,$t))
>>> # f.ex. a OpenGL::Modern::array blessed scalar which will be more
>>> effective because result of gl_pack can be reused.
>> We don't want to make users do the packing but as below, I
>> don't believe special preference should be given to
>> OpenGL::Array objects over [any] other options. In fact,
>> I was thinking we could implement a simple, packed scalar
>> data blob type that could be used for many/most of the
>> OpenGL::Modern pointer/array objects. For example, it would
>> be easy to "cast" the packed data of a piddle into the
>> Packed::Array type for the OpenGL operations.
>>
>>> Case 3: SDL/PDL/memory buffer: glProgramUniform4fv( gl_ptr( $piddle ));
>>> gl_ptr() creates a readonly scalar pointing to the buffer; dangerous
>>> if buffer is freed before the scalar.
>> The usage for OpenGL 4.x would be
>> glProgramUniform4fv($program,$location,$oga) for the OpenGL::Array case,
>> glProgramUniform4fv($program,$location,$pdl) for the PDL case,
>> glProgramUniform4fv($program,$location,$packed_array_data) for Packed::Array
>> which might be a class but I was thinking could also be a role that we
>> check for and use. Then a module wanting to "just work with OpenGL::Modern"
>> could implement and/or compose the role for their object....
>>
>>> The getter, f.ex. glGetnUniformfv would be subject to similar cases:
>>>
>>> Case 1: perlish - @v = glGetnUniformfv(...)
>>>
>>> Case 2: packed array - glGetnUniformfv(..., $result_of_gl_pack); # can be
>> expanded, one shouldn't care for buffer overflow
>>> or, alternatively, using wantarray:
>>>
>>> @v = gl_unpack('f', glGetnUniformfv(...))
>>>
>>> or
>>>
>>> @v = @{ glGetnUniformfv(...) } if the representation of the packed array
>> implements Tie::Array::FETCH.
>>> Case 3: SDL/PDL - glGetnUniformfv(..., $result_of_gl_ptr); # won't be
>> expanded, will die if length is insufficient
>>> In my eyes it would be more DWIM'my to go in this direction, and cause
>> less
>>> confusion on guidelies how to implement new functions. I'm not aware of
>> OGA
>>> difficulties but I hope that this use case can be also handled in a smart
>> way
>>> by the XS.
>> Alot of these cases will depend on what users use. As mentioned
>> above, we'll already have suffixed routines to implement any
>> specific desired features.
>>
>> Thanks for the ideas,
>> Chris
>>
>>> On Thu, Jul 13, 2017 at 03:45:59PM -0400, Chris Marshall wrote:
>>>> This is a quick email on my current plans for OpenGL::Modern
>>>> bindings and the function naming convention(s). There are a
>>>> number of (possibly conflicting) goals:
>>>>
>>>> (1) Consistent and simple relation to the base C OpenGL API names
>>>>
>>>> To keep things simple, we need to have bindings for Perl that
>>>> correlate fully with the native C API. This makes for simple
>> translation
>>>> between C OpenGL program conventions and Perl OpenGL::Modern
>>>> program ones.
>>>>
>>>> The original Perl OpenGL module (POGL) had four classes of
>>>> routine names. For routines taking and/or returning *only* scalar
>>>> arguments (no pointers * or arrays []) the names were the same
>>>> as the C OpenGL routine being bound.
>>>>
>>>> Routines having pointers and/or C array data inputs or outputs
>>>> are given a suffix to indicate the implementation: '_c' for raw
>>>> C-pointer type binding, '_p' for a more perlish interface (for example
>>>> returning multiple args rather than using pointers valued inputs),
>>>> and '_s' for bindings using data in a packed scalar format (such
>>>> as SDL or PDL). While these general namings are used in
>>>> OpenGL::Modern as well, there are some inconsistencies that
>>>> will be noted and corresponding changes needed for clarity.
>>>>
>>>> (2) Maintain compatibility with POGL bindings as possible
>>>>
>>>> As with POGL, perl bindings to OpenGL API routine having
>>>> no pointer or C array input arguments or return values have
>>>> the identical name as the C API. These non-suffixed names
>>>> in OpenGL::Modern are the same where a POGL binding
>>>> exists although the POGL bindings cover about 1/4th of
>>>> the ones in OpenGL::Modern.
>>>>
>>>> Any OpenGL API routine having a pointer * or C array []
>>>> argument or return value have a binding with a '_c' suffix
>>>> that is implemented with raw C pointers. It is up to the
>>>> perl user to create the needed pointer values for input/output
>>>> and to translate the data sent/received correctly. These
>>>> bindings are interim only pending better more perlish or
>>>> more direct implementations:
>>>>
>>>> * null terminated strings map directly to/from perl
>>>> and their '_c' binding needs to be direct to perl with the
>>>> name either having '_p' or for single strings IN/OUT
>>>> the non-suffixed version is appropriate.
>>>>
>>>> * OpenGL routines with names like glXxxx[#][type]v should
>>>> take variable numbers of arguments and/or return an
>>>> array of results and be named with a '_p'.
>>>>
>>>> * Routines in POGL using OpenGL::Array arguments are
>>>> being renamed with a '_o' suffix for OGA from the confusing
>>>> '_p' name which preferentially selected OpenGL::Arrays as
>>>> the preferred binary data implementation over PDL or other
>>>> possible representation.
>>>>
>>>> (3) Make room for nice, friendly, default perlish bindings
>>>>
>>>> * Bindings that can handle multiple input options in a
>>>> simple and symmetric fashion are planned to be given
>>>> a '_g' suffix for general. If performance is sufficient, the
>>>> "friendly" bindings might eventually become the default,
>>>> non-suffixed version.
>>>>
>>>> * Generic bindings without specific numerical data types
>>>> could have an OpenGL::Modern name with all the [#][type]
>>>> stuff removed.
>>>>
>>>> * POGL used glp[A-Z]... to indicate new routines in the
>>>> perl bindings that were implemented. This can be maintained
>>>> for compatibility. In fact, the misleading glGetVersion() routine
>>>> will likely be renamed glpGetVersion() since there is no
>>>> OpenGL routine named glGetVersion().
>>>>
>>>> As OpenGL::Modern is still a work in progress, there is
>>>> room for comment and changes as things evolve. The above
>>>> naming strategy seems best suited to meet needs of
>>>> back-compatibility to POGL and yet having room for a
>>>> better set of bindings going forward.
>>>>
>>>> Cheers,
>>>> Chris
>> ------------------------------------------------------------------------------
>>>> Check out the vibrant tech community on one of the world's most
>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>>> _______________________________________________
>>>> Pogl-devel mailing list
>>>> Pog...@li...
>>>> https://lists.sourceforge.net/lists/listinfo/pogl-devel
>>>
>>> --
>>> Sincerely,
>>> Dmitry Karasik
>>>
>>>
|