Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1139 → Rev 1138

/demos/trunk/mesaref/test.png
File deleted
\ No newline at end of file
/demos/trunk/mesaref/readme.txt
5,7 → 5,7
 
Giacomo Guidi <giacomo@gandalf.sssup.it>
 
Last update 20/03/2003
Last update 17/03/2003
--------------------------------------
 
This is a simple test demo for the MESA (5.0)
18,13 → 18,6
RAGE128 RADEON - driver name R128
SAVAGE VIRGE - driver neme SAVAGE
 
You need a test.png file present in the
same directory of the demo. Remember that
the file system support only a DOS FAT16 fs.
 
The PNGlib will load this file and it
will be used as a texture.
 
--------------------------------------
 
The demo is composed by:
31,9 → 24,8
 
MAKEFILE The makefile used to compile the application
README.TXT This file
INITFILE.C The init file (with fs initialization)
MESAREF.C The MESA Demo
TEST.PNG The PNG texture image
INITFILE.C The init file
MESAREF.C The MESA Demo
 
--------------------------------------
 
52,5 → 44,5
 
copy_videomem_16to16 links these buffers
 
- If the texture load fails, sys_end() is called
 
 
/demos/trunk/mesaref/mesaref.c
21,7 → 21,6
 
#include <GL/osmesa.h>
#include <GL/glut.h>
#include <ports/png.h>
 
#include <math.h>
#include <stdlib.h>
43,8 → 42,8
 
#define DEG2RAD (3.14159/180.0)
 
static GLint ImgWidth = 0, ImgHeight = 0;
static GLenum ImgFormat = 0;
static GLint ImgWidth, ImgHeight;
static GLenum ImgFormat;
static GLubyte *Image = NULL;
 
#define MAX_OBJECTS 2
54,6 → 53,8
static GLfloat xrot, yrot;
static GLfloat spin;
 
static GLboolean Anim = GL_TRUE;
 
OSMesaContext ctx;
 
unsigned char *rgb_565_buf = NULL; //RGB 16 bpp Buffer
62,6 → 63,8
unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16
unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem
 
static GLint w = WIDTH, h = HEIGHT;
 
unsigned long int PERIOD_REFRESH = 80000; //fps = 20
unsigned long int PERIOD_DISEGNA = 80000;
 
70,140 → 73,14
TASK refesh(void);
TASK disegna(void);
 
GLUquadricObj *q;
 
PID refresh_PID, disegna_PID;
 
void read_png_file(char *file_name, GLubyte **buffer, GLint *width, GLint *height, png_byte *color_type)
{
 
int y;
png_byte bit_depth;
 
png_structp png_ptr;
png_infop info_ptr;
int number_of_passes;
png_bytep * row_pointers;
 
char header[8]; // 8 is the maximum size that can be checked
 
/* open file and test for it being a png */
FILE *fp = fopen(file_name, "rb");
if (!fp) {
cprintf("[read_png_file] File %s could not be opened for reading", file_name);
sys_end();
}
fread(header, 1, 8, fp);
if (png_sig_cmp(header, 0, 8))
cprintf("[read_png_file] File %s is not recognized as a PNG file", file_name);
/* initialize stuff */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
cprintf("[read_png_file] png_create_read_struct failed");
 
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
cprintf("[read_png_file] png_create_info_struct failed");
 
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 8);
 
png_read_info(png_ptr, info_ptr);
 
*width = info_ptr->width;
*height = info_ptr->height;
*color_type = info_ptr->color_type;
bit_depth = info_ptr->bit_depth;
 
number_of_passes = png_set_interlace_handling(png_ptr);
cprintf("Open PNG W: %d H: %d CT: %d BD: %d\n",*width,*height,*color_type,bit_depth);
png_read_update_info(png_ptr, info_ptr);
 
row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * info_ptr->height);
for (y=0; y<info_ptr->height; y++)
row_pointers[y] = (png_byte*) malloc(info_ptr->rowbytes);
 
png_read_image(png_ptr, row_pointers);
 
if(info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
*buffer = malloc(info_ptr->height * info_ptr->rowbytes);
for(y=0; y<info_ptr->height; y++)
memcpy(*buffer+y*info_ptr->rowbytes,row_pointers[y],info_ptr->rowbytes);
}
 
fclose(fp);
}
 
static void make_table( void )
{
static GLfloat table_mat[] = { 1.0, 1.0, 1.0, 0.6 };
static GLfloat gray[] = { 0.4, 0.4, 0.4, 1.0 };
 
table_list = glGenLists(1);
glNewList( table_list, GL_COMPILE );
 
/* load table's texture */
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, table_mat );
/* glMaterialfv( GL_FRONT, GL_EMISSION, gray );*/
glMaterialfv( GL_FRONT, GL_DIFFUSE, table_mat );
glMaterialfv( GL_FRONT, GL_AMBIENT, gray );
/* draw textured square for the table */
glPushMatrix();
glScalef( 4.0, 4.0, 4.0 );
glBegin( GL_POLYGON );
glNormal3f( 0.0, 1.0, 0.0 );
glTexCoord2f( 0.0, 0.0 ); glVertex3f( 1.0, 0.0, -1.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1.0, 0.0, 1.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex3f( -1.0, 0.0, 1.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1.0, 0.0, -1.0 );
glEnd();
glPopMatrix();
 
glDisable( GL_TEXTURE_2D );
 
glEndList();
}
 
 
static void make_objects( void )
{
GLUquadricObj *q;
 
static GLfloat cyan[] = { 0.0, 1.0, 1.0, 1.0 };
static GLfloat green[] = { 0.2, 1.0, 0.2, 1.0 };
static GLfloat black[] = { 0.0, 0.0, 0.0, 0.0 };
 
q = gluNewQuadric();
gluQuadricDrawStyle( q, GLU_FILL );
gluQuadricNormals( q, GLU_SMOOTH );
 
objects_list[0] = glGenLists(1);
glNewList( objects_list[0], GL_COMPILE );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cyan );
glMaterialfv( GL_FRONT, GL_EMISSION, black );
gluCylinder( q, 0.5, 0.5, 1.0, 15, 1 );
glEndList();
 
objects_list[1] = glGenLists(1);
glNewList( objects_list[1], GL_COMPILE );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
glMaterialfv( GL_FRONT, GL_EMISSION, black );
gluCylinder( q, 1.5, 0.0, 2.5, 15, 1 );
glEndList();
}
 
static void gl_init( void )
{
png_byte img_color;
 
GLfloat yAspect = 2.5;
GLfloat xAspect = yAspect * (float) WIDTH / (float) HEIGHT;
GLfloat xAspect = yAspect * (float) w / (float) h;
 
//Create the OSMesa Context
ctx = OSMesaCreateContext(OSMESA_RGB_565, NULL);
211,17 → 88,22
//Make Current Context
OSMesaMakeCurrent(ctx, rgb_565_buf, GL_UNSIGNED_SHORT_5_6_5, WIDTH, HEIGHT);
 
read_png_file("test.png",&Image,&ImgWidth,&ImgHeight,&img_color);
if (img_color == PNG_COLOR_TYPE_RGB && Image != NULL)
ImgFormat = GL_RGB;
else {
cprintf("Texture Load Falied !!\n");
sys_end();
}
make_table();
make_objects();
q = gluNewQuadric();
gluQuadricDrawStyle( q, GLU_FILL );
gluQuadricNormals( q, GLU_SMOOTH );
 
ImgWidth = 100;
ImgHeight = 100;
ImgFormat = GL_RGB;
Image = malloc(ImgWidth * ImgHeight * 3);
/*Image = LoadRGBImage( TABLE_TEXTURE, &ImgWidth, &ImgHeight, &ImgFormat );
if (!Image) {
printf("Couldn't read %s\n", TABLE_TEXTURE);
exit(0);
}*/
 
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, ImgWidth, ImgHeight,
ImgFormat, GL_UNSIGNED_BYTE, Image);
 
243,7 → 125,7
 
glEnable( GL_NORMALIZE );
 
glViewport(0, 0, WIDTH, HEIGHT);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -xAspect, xAspect, yAspect, -yAspect, 10.0, 30.0 );
254,9 → 136,10
 
static void draw_objects( GLfloat eyex, GLfloat eyey, GLfloat eyez )
{
(void) eyex;
(void) eyey;
(void) eyez;
static GLfloat cyan[] = { 0.0, 1.0, 1.0, 1.0 };
static GLfloat green[] = { 0.2, 1.0, 0.2, 1.0 };
static GLfloat black[] = { 0.0, 0.0, 0.0, 0.0 };
 
#ifndef USE_ZBUFFER
if (eyex<0.5) {
#endif
264,7 → 147,9
glTranslatef( 1.0, 1.5, 0.0 );
glRotatef( spin, 1.0, 0.5, 0.0 );
glRotatef( 0.5*spin, 0.0, 0.5, 1.0 );
glCallList( objects_list[0] );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cyan );
glMaterialfv( GL_FRONT, GL_EMISSION, black );
gluCylinder( q, 0.5, 0.5, 1.0, 15, 1 );
glPopMatrix();
glPushMatrix();
272,7 → 157,9
glRotatef( 0.5*spin, 0.0, 0.5, 1.0 );
glRotatef( spin, 1.0, 0.5, 0.0 );
glScalef( 0.5, 0.5, 0.5 );
glCallList( objects_list[1] );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
glMaterialfv( GL_FRONT, GL_EMISSION, black );
gluCylinder( q, 1.5, 0.0, 2.5, 15, 1 );
glPopMatrix();
#ifndef USE_ZBUFFER
}
282,7 → 169,9
glRotatef( 0.5*spin, 0.0, 0.5, 1.0 );
glRotatef( spin, 1.0, 0.5, 0.0 );
glScalef( 0.5, 0.5, 0.5 );
glCallList( objects_list[1] );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
glMaterialfv( GL_FRONT, GL_EMISSION, black );
gluCylinder( q, 1.5, 0.0, 2.5, 15, 1 );
glPopMatrix();
 
glPushMatrix();
289,27 → 178,48
glTranslatef( 1.0, 1.5, 0.0 );
glRotatef( spin, 1.0, 0.5, 0.0 );
glRotatef( 0.5*spin, 0.0, 0.5, 1.0 );
glCallList( objects_list[0] );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cyan );
glMaterialfv( GL_FRONT, GL_EMISSION, black );
gluCylinder( q, 0.5, 0.5, 1.0, 15, 1 );
glPopMatrix();
}
#endif
 
}
 
static void draw_table( void )
{
glCallList( table_list );
static GLfloat table_mat[] = { 1.0, 1.0, 1.0, 0.6 };
static GLfloat gray[] = { 0.4, 0.4, 0.4, 1.0 };
 
/* load table's texture */
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, table_mat );
glMaterialfv( GL_FRONT, GL_DIFFUSE, table_mat );
glMaterialfv( GL_FRONT, GL_AMBIENT, gray );
/* draw textured square for the table */
glPushMatrix();
glScalef( 4.0, 4.0, 4.0 );
glBegin( GL_POLYGON );
glNormal3f( 0.0, 1.0, 0.0 );
glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1.0, 0.0, 1.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1.0, 0.0, 1.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1.0, 0.0, -1.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1.0, 0.0, -1.0 );
glEnd();
glPopMatrix();
 
glDisable( GL_TEXTURE_2D );
 
}
 
static void draw( void )
{
static GLfloat light_pos[] = { 0.0, 20.0, 0.0, 1.0 };
GLfloat dist = 20.0;
GLfloat eyex, eyey, eyez;
static GLfloat dist = 20.0;
static GLfloat eyex, eyey, eyez;
 
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
 
eyex = dist * cos(yrot*DEG2RAD) * cos(xrot*DEG2RAD);
eyez = dist * sin(yrot*DEG2RAD) * cos(xrot*DEG2RAD);
eyey = dist * sin(xrot*DEG2RAD);
370,7 → 280,7
glPopMatrix();
 
glFinish();
 
}
 
static int screen(int mode)
470,9 → 380,11
HARD_TASK_MODEL ht_refresh, ht_disegna;
 
sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT);
 
clear();
WCET_REFRESH =((long int) PERIOD_REFRESH * (0.20));
WCET_DISEGNA =((long int) PERIOD_DISEGNA * (0.70));
WCET_REFRESH =((long int) PERIOD_REFRESH * (0.22));
WCET_DISEGNA =((long int) PERIOD_DISEGNA * (0.72));
 
hard_task_default_model(ht_refresh);
hard_task_def_wcet(ht_refresh,WCET_REFRESH);
493,8 → 405,7
hard_task_def_group(ht_disegna,1);
hard_task_def_ctrl_jet(ht_disegna);
hard_task_def_usemath(ht_disegna);
hard_task_def_stack(ht_disegna, 60000);
 
disegna_PID = task_create("disegna", disegna, &ht_disegna, NULL);
if (disegna_PID == -1) {
sys_end();
/demos/trunk/mesaref/initfile.c
17,6 → 17,37
*/
 
/*
------------
CVS : $Id: initfile.c,v 1.1 2003-03-13 13:14:03 giacomo Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2003-03-13 13:14:03 $
------------
 
System initialization file
 
This file contains the 2 functions needed to initialize the system.
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a RR (Round Robin) level
a CBS (Costant Bandwidth Server) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
SOFT_TASK_MODEL (met, period) at level 1
NRT_TASK_MODEL at level 2
 
This file is similar to the configuration of kernel/init/hartik3.c
 
TICK is set to 0 (one-shot timer is used)
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
35,114 → 66,32
*
*/
 
/*
* CVS : $Id: initfile.c,v 1.2 2003-03-20 13:34:37 giacomo Exp $
*
* File: $File$
* Revision: $Revision: 1.2 $
* Last update: $Date: 2003-03-20 13:34:37 $
*/
 
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "modules/rr.h"
#include "modules/cbs.h"
#include "modules/dummy.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
#include "modules/pi.h"
#include "modules/pc.h"
#include "modules/srp.h"
#include "modules/npp.h"
#include "modules/nop.h"
#include "modules/nopm.h"
 
#include "fs/bdevinit.h"
#include "fs/fsinit.h"
#include "fs/bdev.h"
 
#include "drivers/keyb.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 1000
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
dev_t root_device=-1;
dev_t temp_device=-1;
 
int __register_sub_init(void)
{
#if defined(EDFSCHED)
extern void BD_EDF_register_module(void);
BD_EDF_register_module();
#elif defined(PSCANSCHED)
extern void BD_PSCAN_register_module(void);
BD_PSCAN_register_module();
#endif
return 0;
}
 
int choose_root_callback(dev_t dev,u_int8_t fs)
{
if (fs==FS_MSDOS) return dev;
return -1;
}
 
int choose_temp_callback(__dev_t dev,__uint8_t fs)
{
static int flag=0;
if (fs==FS_MSDOS) {
if (flag) return dev;
flag=1;
}
return -1;
}
 
int __bdev_sub_init(void)
{
BDEV_PARMS bdev=BASE_BDEV;
bdev_def_showinfo(bdev,FALSE);
bdev_init(&bdev);
 
root_device=bdev_scan_devices(choose_root_callback);
if (root_device<0) {
cprintf("can't find root device to mount on /!!!\n");
sys_end();
return -1;
}
 
return 0;
 
}
 
int __fs_sub_init(void)
{
extern int libc_initialize(void);
FILESYSTEM_PARMS fs=BASE_FILESYSTEM;
filesystem_def_rootdevice(fs,root_device);
filesystem_def_fs(fs,FS_MSDOS);
filesystem_def_showinfo(fs,FALSE);
filesystem_init(&fs);
 
libc_initialize();
 
return 0;
}
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
extern int __register_sub_init(void);
 
EDF_register_level(EDF_ENABLE_ALL);
CBS_register_level(CBS_ENABLE_ALL, 0);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
CBS_register_level(CBS_ENABLE_ALL, 0);
dummy_register_level();
 
SEM_register_module();
149,15 → 98,6
 
CABS_register_module();
 
PI_register_module();
PC_register_module();
NPP_register_module();
SRP_register_module();
NOP_register_module();
NOPM_register_module();
 
__register_sub_init();
return TICK;
}
 
164,17 → 104,15
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
KEYB_PARMS keyb = BASE_KEYB;
extern int __bdev_sub_init(void);
extern int __fs_sub_init(void);
 
KEYB_PARMS kparms = BASE_KEYB;
 
HARTPORT_init();
KEYB_init(&keyb);
 
__bdev_sub_init();
__fs_sub_init();
keyb_def_ctrlC(kparms, NULL);
keyb_def_map(kparms,itaMap);
KEYB_init(&kparms);
 
__call_main__(mb);
 
return (void *)0;