Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
cf1729d5
Commit
cf1729d5
authored
19 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
merging offscreen rendering from brnach
parent
94a7756b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Graphics/PixelBuffer.h
+126
-0
126 additions, 0 deletions
Graphics/PixelBuffer.h
with
126 additions
and
0 deletions
Graphics/PixelBuffer.h
0 → 100644
+
126
−
0
View file @
cf1729d5
#ifndef _PIXEL_BUFFER_H_
#define _PIXEL_BUFFER_H_
/*
* Copyright (C) 1999-2006 Christophe Geuzaine <geuz@geuz.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of either:
*
* a) the GNU Library General Public License as published by the Free
* Software Foundation, either version 2 of the License, or (at your
* option) any later version; or
*
* b) the GL2PS License as published by Christophe Geuzaine, either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
* the GNU Library General Public License or the GL2PS License for
* more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library in the file named "COPYING.LGPL";
* if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
* Cambridge, MA 02139, USA.
*
* You should have received a copy of the GL2PS License with this
* library in the file named "COPYING.GL2PS"; if not, I will be glad
* to provide one.
*/
#include
"Gmsh.h"
#include
"GmshUI.h"
#include
"Draw.h"
#include
"Context.h"
extern
Context_T
CTX
;
#if defined(HAVE_OSMESA)
#include
<GL/osmesa.h>
#endif
class
PixelBuffer
{
private:
int
_width
,
_height
,
_numComp
,
_dataSize
;
GLenum
_format
,
_type
;
void
*
_pixels
;
public:
PixelBuffer
(
int
width
,
int
height
,
GLenum
format
,
GLenum
type
)
:
_width
(
width
),
_height
(
height
),
_format
(
format
),
_type
(
type
)
{
if
(
format
==
GL_RGB
){
_numComp
=
3
;
}
else
if
(
format
==
GL_RGBA
){
_numComp
=
4
;
}
else
{
Msg
(
GERROR
,
"Unknown pixel format: assuming RGB"
);
_format
=
GL_RGB
;
_numComp
=
3
;
}
if
(
type
==
GL_UNSIGNED_BYTE
){
_dataSize
=
sizeof
(
unsigned
char
);
}
else
if
(
type
==
GL_FLOAT
){
_dataSize
=
sizeof
(
float
);
}
else
{
Msg
(
GERROR
,
"Unknown pixel storage type: assuming unsigned byte"
);
_type
=
GL_UNSIGNED_BYTE
;
_dataSize
=
sizeof
(
unsigned
char
);
}
_pixels
=
Calloc
(
_numComp
*
_width
*
_height
,
_dataSize
);
}
~
PixelBuffer
()
{
Free
(
_pixels
);
}
int
GetWidth
(){
return
_width
;
}
int
GetHeight
(){
return
_height
;
}
int
GetNumComp
(){
return
_numComp
;
}
int
GetDataSize
(){
return
_dataSize
;
}
GLenum
GetFormat
(){
return
_format
;
}
GLenum
GetType
(){
return
_type
;
}
void
*
GetPixels
(){
return
_pixels
;
}
void
Fill
()
{
if
(
!
CTX
.
batch
){
SetOpenglContext
();
ClearOpengl
();
Draw3d
();
Draw2d
();
glFinish
();
glPixelStorei
(
GL_PACK_ALIGNMENT
,
1
);
glPixelStorei
(
GL_UNPACK_ALIGNMENT
,
1
);
glReadPixels
(
0
,
0
,
_width
,
_height
,
_format
,
_type
,
_pixels
);
}
else
{
#if defined(HAVE_OSMESA)
if
(
_format
!=
GL_RGB
&&
_type
!=
GL_UNSIGNED_BYTE
){
Msg
(
GERROR
,
"Offscreen rendering only implemented for GL_RGB/GL_UNSIGNED_BYTE"
);
return
;
}
OSMesaContext
ctx
=
OSMesaCreateContextExt
(
OSMESA_RGB
,
16
,
0
,
0
,
NULL
);
if
(
!
ctx
){
Msg
(
GERROR
,
"OSMesaCreateContext failed"
);
return
;
}
if
(
!
OSMesaMakeCurrent
(
ctx
,
_pixels
,
GL_UNSIGNED_BYTE
,
_width
,
_height
)){
Msg
(
GERROR
,
"OSMesaMakeCurrent failed"
);
}
ClearOpengl
();
Draw3d
();
//Draw2d();
glFinish
();
//OSMesaDestroyContext(ctx);
#else
Msg
(
WARNING
,
"Offscreen rendering not available in this version"
);
#endif
}
}
};
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment