[m-rev.] diff: use bitmaps for textures in opengl binding
Julien Fischer
juliensf at csse.unimelb.edu.au
Mon Feb 26 18:09:18 AEDT 2007
(Note: if you compile this in asm_fast grades at the moment you'll get
a bunch of warnings from the C compiler; this is because of the bug
with foreign_exports and sub-modules.)
Estimated hours taken: 0.2
Branches: main
Use bitmaps to represent textures in the OpenGL binding.
extras/graphics/mercury_opengl/mogl.m:
Redefine the pixel_data type as a bitmap rather than a foreign type.
Using a bitmap means that we no longer have to resort to using
foreign code to read in things like textures, we can just use the
stdlib predicates for reading bitmaps.
TODO: add some more sanity checking for texture data.
Fix a bit of formatting.
extras/graphics/mercury_opengl/.cvsignore:
Ignore mogl.type_tables.c.
Julien.
Index: .cvsignore
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/graphics/mercury_opengl/.cvsignore,v
retrieving revision 1.1
diff -u -r1.1 .cvsignore
--- .cvsignore 29 Jun 2005 05:21:43 -0000 1.1
+++ .cvsignore 26 Feb 2007 07:03:22 -0000
@@ -2,6 +2,7 @@
mglu.c
mtogl.c
mercury_opengl.c
+mogl.type_tables.c
*.c_date
*.d
*.int*
Index: mogl.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/graphics/mercury_opengl/mogl.m,v
retrieving revision 1.25
diff -u -r1.25 mogl.m
--- mogl.m 14 Feb 2007 04:43:35 -0000 1.25
+++ mogl.m 26 Feb 2007 07:02:08 -0000
@@ -534,23 +534,23 @@
:- inst border ---> 0 ; 1.
-:- type pixel_data.
+:- type pixel_data == bitmap.
:- pred tex_image_1d(texture_target::in(texture_1d), int::in,
texture_format::in, int::in, int::in(border),
pixel_format::in(pixel_format_non_stencil_or_depth),
- pixel_type::in, pixel_data::in, io::di, io::uo) is det.
+ pixel_type::in, pixel_data::bitmap_ui, io::di, io::uo) is det.
:- pred tex_image_2d(texture_target::in(texture_2d), int::in,
texture_format::in, int::in, int::in, int::in(border),
pixel_format::in(pixel_format_non_stencil_or_depth),
- pixel_type::in, pixel_data::in, io::di, io::uo) is det.
+ pixel_type::in, pixel_data::bitmap_ui, io::di, io::uo) is det.
% Requires OpenGL 1.2
% :- pred tex_image_3d(texture_target::in(texture_3d), int::in,
% texture_format::in, int::in, int::in, int::in, int::in(border),
% pixel_format::in(pixel_format_non_stencil_or_depth),
-% pixel_type::in, pixel_data::in, io::di, io::uo) is det.
+% pixel_type::in, pixel_data::bitmap_ui, io::di, io::uo) is det.
:- pred copy_tex_image_1d(texture_target::in(bound(texture_1d)), int::in,
texture_format::in, int::in, int::in, int::in, int::in(border),
@@ -1194,14 +1194,6 @@
:- pred pop_client_attrib(io::di, io::uo) is det.
%------------------------------------------------------------------------------%
-
-% A less public interface.
-
-:- interface.
-
-:- pragma foreign_type("C", pixel_data, "const GLvoid *").
-
-%------------------------------------------------------------------------------%
%------------------------------------------------------------------------------%
:- implementation.
@@ -2561,11 +2553,11 @@
").
:- type pixels
- ---> pixels(
- pixel_format :: int,
- pixel_type :: int,
- pixel_data :: pixel_data
- ).
+ ---> pixels(
+ pixel_format :: int,
+ pixel_type :: int,
+ pixel_data :: pixel_data
+ ).
read_buffer(Buffer, !IO) :-
read_buffer_to_int_and_offset(Buffer, BufferFlag, Offset),
@@ -3056,16 +3048,16 @@
pixel_format_to_int(Format), pixel_type_to_int(Type), Pixels, !IO).
:- pred tex_image_1d_2(int::in, int::in, int::in, int::in, int::in, int::in,
- int::in, pixel_data::in, io::di, io::uo) is det.
+ int::in, pixel_data::bitmap_ui, io::di, io::uo) is det.
:- pragma foreign_proc("C",
tex_image_1d_2(Target::in, Level::in, InternalFormat::in,
Width::in, Border::in, Format::in, Type::in,
- Pixels::in, IO0::di, IO::uo),
+ Pixels::bitmap_ui, IO0::di, IO::uo),
[will_not_call_mercury, tabled_for_io, promise_pure],
"
glTexImage1D(texture_target_flags[Target], Level,
texture_format_flags[InternalFormat], Width, Border,
- pixel_format_flags[Format], pixel_type_flags[Type], Pixels);
+ pixel_format_flags[Format], pixel_type_flags[Type], Pixels->elements);
IO = IO0;
").
@@ -3077,16 +3069,16 @@
pixel_format_to_int(Format), pixel_type_to_int(Type), Pixels, !IO).
:- pred tex_image_2d_2(int::in, int::in, int::in, int::in, int::in, int::in,
- int::in, int::in, pixel_data::in, io::di, io::uo) is det.
+ int::in, int::in, pixel_data::bitmap_ui, io::di, io::uo) is det.
:- pragma foreign_proc("C",
tex_image_2d_2(Target::in, Level::in, InternalFormat::in,
- Width::in, Height::in, Border::in, Format::in, Type::in, Pixels::in,
- IO0::di, IO::uo),
+ Width::in, Height::in, Border::in, Format::in, Type::in,
+ Pixels::bitmap_ui, IO0::di, IO::uo),
[will_not_call_mercury, tabled_for_io, promise_pure],
"
glTexImage2D(texture_target_flags[Target], Level,
texture_format_flags[InternalFormat], Width, Height, Border,
- pixel_format_flags[Format], pixel_type_flags[Type], Pixels);
+ pixel_format_flags[Format], pixel_type_flags[Type], Pixels->elements);
IO = IO0;
").
@@ -3100,7 +3092,7 @@
% !IO).
%
% :- pred tex_image_3d_2(int::in, int::in, int::in, int::in, int::in, int::in,
-% int::in, int::in, int::in, pixel_data::in, io::di, io::uo) is det.
+% int::in, int::in, int::in, pixel_data::bitmap_ui, io::di, io::uo) is det.
% :- pragma foreign_proc("C",
% tex_image_3d_2(Target::in, Level::in, InternalFormat::in,
% Width::in, Height::in, Depth::in, Border::in, Format::in, Type::in,
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list