moved OpenGL wrappers to separate header
added GlBuffer, GlTexture and GpuMat support to InputArray replaced addTextOpenGl function by render + GlFont
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencv2/core/opengl_interop.hpp"
|
||||
|
||||
// in later times, use this file as a dispatcher to implementations like cvcap.cpp
|
||||
|
||||
@@ -284,7 +285,7 @@ namespace
|
||||
|
||||
struct GlObjTex : GlObjBase
|
||||
{
|
||||
cv::gpu::GlTexture tex;
|
||||
cv::GlTexture tex;
|
||||
};
|
||||
|
||||
void CV_CDECL glDrawTextureCallback(void* userdata)
|
||||
@@ -293,17 +294,17 @@ namespace
|
||||
|
||||
CV_DbgAssert(texObj->flag == CV_TEXTURE_MAGIC_VAL);
|
||||
|
||||
static cv::gpu::GlCamera glCamera;
|
||||
static cv::GlCamera glCamera;
|
||||
|
||||
glCamera.setupProjectionMatrix();
|
||||
|
||||
cv::gpu::render(texObj->tex);
|
||||
cv::render(texObj->tex);
|
||||
}
|
||||
|
||||
struct GlObjPointCloud : GlObjBase
|
||||
{
|
||||
cv::gpu::GlArrays arr;
|
||||
cv::gpu::GlCamera camera;
|
||||
cv::GlArrays arr;
|
||||
cv::GlCamera camera;
|
||||
};
|
||||
|
||||
void CV_CDECL glDrawPointCloudCallback(void* userdata)
|
||||
@@ -315,7 +316,7 @@ namespace
|
||||
pointCloudObj->camera.setupProjectionMatrix();
|
||||
pointCloudObj->camera.setupModelViewMatrix();
|
||||
|
||||
cv::gpu::render(pointCloudObj->arr);
|
||||
cv::render(pointCloudObj->arr);
|
||||
}
|
||||
|
||||
void CV_CDECL glCleanCallback(void* userdata)
|
||||
@@ -327,20 +328,31 @@ namespace
|
||||
}
|
||||
#endif // HAVE_OPENGL
|
||||
|
||||
#ifdef HAVE_OPENGL
|
||||
|
||||
namespace
|
||||
void cv::imshow( const string& winname, InputArray _img )
|
||||
{
|
||||
template <typename T> void imshowImpl(const std::string& winname, const T& img)
|
||||
#ifndef HAVE_OPENGL
|
||||
Mat img = _img.getMat();
|
||||
CvMat c_img = img;
|
||||
cvShowImage(winname.c_str(), &c_img);
|
||||
#else
|
||||
double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
|
||||
if (useGl <= 0)
|
||||
{
|
||||
Mat img = _img.getMat();
|
||||
CvMat c_img = img;
|
||||
cvShowImage(winname.c_str(), &c_img);
|
||||
}
|
||||
else
|
||||
{
|
||||
using namespace cv;
|
||||
|
||||
namedWindow(winname, WINDOW_OPENGL | WINDOW_AUTOSIZE);
|
||||
|
||||
double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
|
||||
|
||||
if (autoSize > 0)
|
||||
resizeWindow(winname, img.cols, img.rows);
|
||||
{
|
||||
Size size = _img.size();
|
||||
resizeWindow(winname, size.width, size.height);
|
||||
}
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
@@ -355,12 +367,12 @@ namespace
|
||||
if (glObj)
|
||||
{
|
||||
GlObjTex* texObj = static_cast<GlObjTex*>(glObj);
|
||||
texObj->tex.copyFrom(img);
|
||||
texObj->tex.copyFrom(_img);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObjTex* texObj = new GlObjTex;
|
||||
texObj->tex.copyFrom(img);
|
||||
texObj->tex.copyFrom(_img);
|
||||
|
||||
glObj = texObj;
|
||||
glObj->flag = CV_TEXTURE_MAGIC_VAL;
|
||||
@@ -375,99 +387,10 @@ namespace
|
||||
|
||||
updateWindow(winname);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENGL
|
||||
|
||||
void cv::imshow( const string& winname, InputArray _img )
|
||||
{
|
||||
Mat img = _img.getMat();
|
||||
|
||||
#ifndef HAVE_OPENGL
|
||||
CvMat c_img = img;
|
||||
cvShowImage(winname.c_str(), &c_img);
|
||||
#else
|
||||
double useGl = getWindowProperty(winname, WND_PROP_OPENGL);
|
||||
if (useGl <= 0)
|
||||
{
|
||||
CvMat c_img = img;
|
||||
cvShowImage(winname.c_str(), &c_img);
|
||||
}
|
||||
else
|
||||
{
|
||||
imshowImpl(winname, img);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::imshow(const string& winname, const gpu::GlBuffer& buf)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
imshowImpl(winname, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::imshow(const string& winname, const gpu::GpuMat& d_mat)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
setOpenGlContext(winname);
|
||||
gpu::GlBuffer buf(d_mat, gpu::GlBuffer::TEXTURE_BUFFER);
|
||||
imshow(winname, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::imshow(const string& winname, const gpu::GlTexture& tex)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
namedWindow(winname, WINDOW_OPENGL | WINDOW_AUTOSIZE);
|
||||
|
||||
double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
|
||||
|
||||
if (autoSize > 0)
|
||||
resizeWindow(winname, tex.cols, tex.rows);
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
GlObjBase* glObj = findGlObjByName(winname);
|
||||
|
||||
if (glObj && glObj->flag != CV_TEXTURE_MAGIC_VAL)
|
||||
{
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
||||
glObj = 0;
|
||||
}
|
||||
|
||||
if (glObj)
|
||||
{
|
||||
GlObjTex* texObj = static_cast<GlObjTex*>(glObj);
|
||||
texObj->tex = tex;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObjTex* texObj = new GlObjTex;
|
||||
texObj->tex = tex;
|
||||
|
||||
glObj = texObj;
|
||||
glObj->flag = CV_TEXTURE_MAGIC_VAL;
|
||||
glObj->winname = winname;
|
||||
|
||||
addGlObj(glObj);
|
||||
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback(winname, glDrawTextureCallback, glObj);
|
||||
|
||||
updateWindow(winname);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GlArrays& arr)
|
||||
void cv::pointCloudShow(const string& winname, const GlCamera& camera, const GlArrays& arr)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
@@ -511,104 +434,60 @@ void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, cons
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENGL
|
||||
|
||||
namespace
|
||||
void cv::pointCloudShow(const std::string& winname, const cv::GlCamera& camera, InputArray points, InputArray colors)
|
||||
{
|
||||
template <typename T> void pointCloudShowImpl(const std::string& winname, const cv::gpu::GlCamera& camera, const T& points, const T& colors)
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
namedWindow(winname, WINDOW_OPENGL);
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
GlObjBase* glObj = findGlObjByName(winname);
|
||||
|
||||
if (glObj && glObj->flag != CV_POINT_CLOUD_MAGIC_VAL)
|
||||
{
|
||||
using namespace cv;
|
||||
|
||||
namedWindow(winname, WINDOW_OPENGL);
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
GlObjBase* glObj = findGlObjByName(winname);
|
||||
|
||||
if (glObj && glObj->flag != CV_POINT_CLOUD_MAGIC_VAL)
|
||||
{
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
||||
glObj = 0;
|
||||
}
|
||||
|
||||
if (glObj)
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = static_cast<GlObjPointCloud*>(glObj);
|
||||
|
||||
pointCloudObj->arr.setVertexArray(points);
|
||||
if (colors.empty())
|
||||
pointCloudObj->arr.resetColorArray();
|
||||
else
|
||||
pointCloudObj->arr.setColorArray(colors);
|
||||
|
||||
pointCloudObj->camera = camera;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = new GlObjPointCloud;
|
||||
|
||||
pointCloudObj->arr.setVertexArray(points);
|
||||
if (!colors.empty())
|
||||
pointCloudObj->arr.setColorArray(colors);
|
||||
|
||||
pointCloudObj->camera = camera;
|
||||
|
||||
glObj = pointCloudObj;
|
||||
glObj->flag = CV_POINT_CLOUD_MAGIC_VAL;
|
||||
glObj->winname = winname;
|
||||
|
||||
addGlObj(glObj);
|
||||
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback(winname, glDrawPointCloudCallback, glObj);
|
||||
|
||||
updateWindow(winname);
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
||||
glObj = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENGL
|
||||
if (glObj)
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = static_cast<GlObjPointCloud*>(glObj);
|
||||
|
||||
void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GlBuffer& points, const gpu::GlBuffer& colors)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
pointCloudShowImpl(winname, camera, points, colors);
|
||||
pointCloudObj->arr.setVertexArray(points);
|
||||
if (colors.empty())
|
||||
pointCloudObj->arr.resetColorArray();
|
||||
else
|
||||
pointCloudObj->arr.setColorArray(colors);
|
||||
|
||||
pointCloudObj->camera = camera;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = new GlObjPointCloud;
|
||||
|
||||
pointCloudObj->arr.setVertexArray(points);
|
||||
if (!colors.empty())
|
||||
pointCloudObj->arr.setColorArray(colors);
|
||||
|
||||
pointCloudObj->camera = camera;
|
||||
|
||||
glObj = pointCloudObj;
|
||||
glObj->flag = CV_POINT_CLOUD_MAGIC_VAL;
|
||||
glObj->winname = winname;
|
||||
|
||||
addGlObj(glObj);
|
||||
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback(winname, glDrawPointCloudCallback, glObj);
|
||||
|
||||
updateWindow(winname);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GpuMat& points, const gpu::GpuMat& colors)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
pointCloudShowImpl(winname, camera, points, colors);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, InputArray points, InputArray colors)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
pointCloudShowImpl(winname, camera, points, colors);
|
||||
#endif
|
||||
}
|
||||
|
||||
// OpenGL text
|
||||
|
||||
void cv::addTextOpenGl(const string& winname, const string& text, Point org, Scalar color, const string& fontName, int fontHeight, int fontWeight, int fontStyle)
|
||||
{
|
||||
cvAddTextOpenGl(winname.c_str(), text.c_str(), org, color, fontName.c_str(), fontHeight, fontWeight, fontStyle);
|
||||
}
|
||||
|
||||
void cv::clearTextOpenGl(const string& winname)
|
||||
{
|
||||
cvClearTextOpenGl(winname.c_str());
|
||||
}
|
||||
|
||||
// Without OpenGL
|
||||
|
||||
#ifndef HAVE_OPENGL
|
||||
@@ -630,16 +509,6 @@ CV_IMPL void cvUpdateWindow(const char*)
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
}
|
||||
|
||||
CV_IMPL void cvAddTextOpenGl(const char*, const char*, CvPoint, CvScalar, const char*, int, int, int)
|
||||
{
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
}
|
||||
|
||||
CV_IMPL void cvClearTextOpenGl(const char*)
|
||||
{
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
}
|
||||
|
||||
void icvSetOpenGlCleanCallback(const char*, CvOpenGlCleanCallback, void*)
|
||||
{
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
|
@@ -60,7 +60,6 @@
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/core/gpumat.hpp"
|
||||
#include <GL\gl.h>
|
||||
#endif
|
||||
|
||||
@@ -137,216 +136,6 @@ typedef struct CvTrackbar
|
||||
}
|
||||
CvTrackbar;
|
||||
|
||||
// OpenGL support
|
||||
|
||||
#ifdef HAVE_OPENGL
|
||||
|
||||
namespace
|
||||
{
|
||||
class OpenGlFont
|
||||
{
|
||||
public:
|
||||
OpenGlFont(HDC hDC, const std::string& fontName, int fontHeight, int fontWeight, int fontStyle);
|
||||
~OpenGlFont();
|
||||
|
||||
void draw(const char* str, int len, CvPoint org, CvScalar color, int width, int height) const;
|
||||
|
||||
inline const std::string& fontName() const { return fontName_; }
|
||||
inline int fontHeight() const { return fontHeight_; }
|
||||
inline int fontWeight() const { return fontWeight_; }
|
||||
inline int fontStyle() const { return fontStyle_; }
|
||||
|
||||
private:
|
||||
std::string fontName_;
|
||||
int fontHeight_;
|
||||
int fontWeight_;
|
||||
int fontStyle_;
|
||||
|
||||
GLuint base_;
|
||||
|
||||
OpenGlFont(const OpenGlFont&);
|
||||
OpenGlFont& operator =(const OpenGlFont&);
|
||||
};
|
||||
|
||||
int getFontWidthW32(int fontWeight)
|
||||
{
|
||||
int weight = 0;
|
||||
|
||||
switch(fontWeight)
|
||||
{
|
||||
case CV_FONT_LIGHT:
|
||||
weight = 200;
|
||||
break;
|
||||
case CV_FONT_NORMAL:
|
||||
weight = FW_NORMAL;
|
||||
break;
|
||||
case CV_FONT_DEMIBOLD:
|
||||
weight = 550;
|
||||
break;
|
||||
case CV_FONT_BOLD:
|
||||
weight = FW_BOLD;
|
||||
break;
|
||||
case CV_FONT_BLACK:
|
||||
weight = FW_BLACK;
|
||||
break;
|
||||
default:
|
||||
cvError(CV_StsBadArg, "getFontWidthW32", "Unsopported font width", __FILE__, __LINE__);
|
||||
};
|
||||
|
||||
return weight;
|
||||
}
|
||||
|
||||
OpenGlFont::OpenGlFont(HDC hDC, const std::string& fontName, int fontHeight, int fontWeight, int fontStyle)
|
||||
: fontName_(), fontHeight_(0), fontWeight_(0), fontStyle_(0), base_(0)
|
||||
{
|
||||
base_ = glGenLists(96);
|
||||
|
||||
HFONT font = CreateFont
|
||||
(
|
||||
-fontHeight, // height
|
||||
0, // cell width
|
||||
0, // Angle of Escapement
|
||||
0, // Orientation Angle
|
||||
getFontWidthW32(fontWeight), // font weight
|
||||
fontStyle & CV_STYLE_ITALIC ? TRUE : FALSE, // Italic
|
||||
fontStyle & CV_STYLE_UNDERLINE ? TRUE : FALSE, // Underline
|
||||
FALSE, // StrikeOut
|
||||
ANSI_CHARSET, // CharSet
|
||||
OUT_TT_PRECIS, // OutPrecision
|
||||
CLIP_DEFAULT_PRECIS, // ClipPrecision
|
||||
ANTIALIASED_QUALITY, // Quality
|
||||
FF_DONTCARE | DEFAULT_PITCH, // PitchAndFamily
|
||||
fontName.c_str() // FaceName
|
||||
);
|
||||
|
||||
SelectObject(hDC, font);
|
||||
|
||||
if (!wglUseFontBitmaps(hDC, 32, 96, base_))
|
||||
cvError(CV_OpenGlApiCallError, "OpenGlFont", "Can't create font", __FILE__, __LINE__);
|
||||
|
||||
fontName_ = fontName;
|
||||
fontHeight_ = fontHeight;
|
||||
fontWeight_ = fontWeight;
|
||||
fontStyle_ = fontStyle;
|
||||
}
|
||||
|
||||
OpenGlFont::~OpenGlFont()
|
||||
{
|
||||
if (base_)
|
||||
glDeleteLists(base_, 96);
|
||||
}
|
||||
|
||||
void OpenGlFont::draw(const char* str, int len, CvPoint org, CvScalar color, int width, int height) const
|
||||
{
|
||||
if (base_)
|
||||
{
|
||||
glPushAttrib(GL_LIST_BIT);
|
||||
glListBase(base_ - 32);
|
||||
|
||||
glColor4dv(color.val);
|
||||
glRasterPos2f(static_cast<float>(org.x) / width, static_cast<float>((org.y + fontHeight_)) / height);
|
||||
glCallLists(len, GL_UNSIGNED_BYTE, str);
|
||||
|
||||
glPopAttrib();
|
||||
|
||||
CV_CheckGlError();
|
||||
}
|
||||
}
|
||||
|
||||
class OpenGlText
|
||||
{
|
||||
public:
|
||||
OpenGlText(HDC hDC);
|
||||
|
||||
void add(const std::string& text, CvPoint org, CvScalar color, const std::string& fontName, int fontHeight, int fontWeight, int fontStyle);
|
||||
inline void clear() { text_.clear(); }
|
||||
|
||||
void draw(int width, int height) const;
|
||||
|
||||
private:
|
||||
struct Text
|
||||
{
|
||||
std::string str;
|
||||
|
||||
CvPoint org;
|
||||
CvScalar color;
|
||||
|
||||
cv::Ptr<OpenGlFont> font;
|
||||
};
|
||||
|
||||
HDC hDC_;
|
||||
|
||||
std::vector< cv::Ptr<OpenGlFont> > fonts_;
|
||||
|
||||
std::vector<Text> text_;
|
||||
};
|
||||
|
||||
OpenGlText::OpenGlText(HDC hDC) : hDC_(hDC)
|
||||
{
|
||||
fonts_.reserve(5);
|
||||
text_.reserve(5);
|
||||
}
|
||||
|
||||
class FontCompare : public std::unary_function<cv::Ptr<OpenGlFont>, bool>
|
||||
{
|
||||
public:
|
||||
inline FontCompare(const std::string& fontName, int fontHeight, int fontWeight, int fontStyle)
|
||||
: fontName_(fontName), fontHeight_(fontHeight), fontWeight_(fontWeight), fontStyle_(fontStyle)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator ()(const cv::Ptr<OpenGlFont>& font)
|
||||
{
|
||||
return font->fontName() == fontName_ && font->fontHeight() == fontHeight_ && font->fontWeight() == fontWeight_ && font->fontStyle() == fontStyle_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string fontName_;
|
||||
int fontHeight_;
|
||||
int fontWeight_;
|
||||
int fontStyle_;
|
||||
};
|
||||
|
||||
void OpenGlText::add(const std::string& str, CvPoint org, CvScalar color, const std::string& fontName, int fontHeight, int fontWeight, int fontStyle)
|
||||
{
|
||||
std::vector< cv::Ptr<OpenGlFont> >::iterator fontIt =
|
||||
std::find_if(fonts_.begin(), fonts_.end(), FontCompare(fontName, fontHeight, fontWeight, fontStyle));
|
||||
|
||||
if (fontIt == fonts_.end())
|
||||
{
|
||||
fonts_.push_back(new OpenGlFont(hDC_, fontName, fontHeight, fontWeight, fontStyle));
|
||||
fontIt = fonts_.end() - 1;
|
||||
}
|
||||
|
||||
Text text;
|
||||
text.str = str;
|
||||
text.org = org;
|
||||
text.color = color;
|
||||
text.font = *fontIt;
|
||||
|
||||
text_.push_back(text);
|
||||
}
|
||||
|
||||
void OpenGlText::draw(int width, int height) const
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
static cv::gpu::GlCamera glCamera;
|
||||
glCamera.setupProjectionMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
for (size_t i = 0, size = text_.size(); i < size; ++i)
|
||||
{
|
||||
const Text& text = text_[i];
|
||||
text.font->draw(text.str.c_str(), text.str.length(), text.org, text.color, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENGL
|
||||
|
||||
|
||||
typedef struct CvWindow
|
||||
{
|
||||
@@ -391,9 +180,7 @@ typedef struct CvWindow
|
||||
CvOpenGlCleanCallback glCleanCallback;
|
||||
void* glCleanData;
|
||||
|
||||
cv::gpu::GlFuncTab* glFuncTab;
|
||||
|
||||
OpenGlText* glText;
|
||||
CvOpenGlFuncTab* glFuncTab;
|
||||
#endif
|
||||
}
|
||||
CvWindow;
|
||||
@@ -809,9 +596,26 @@ namespace
|
||||
typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
|
||||
typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target);
|
||||
|
||||
class GlFuncTab_W32 : public cv::gpu::GlFuncTab
|
||||
class GlFuncTab_W32 : public CvOpenGlFuncTab
|
||||
{
|
||||
public:
|
||||
GlFuncTab_W32(HDC hDC);
|
||||
|
||||
void genBuffers(int n, unsigned int* buffers) const;
|
||||
void deleteBuffers(int n, const unsigned int* buffers) const;
|
||||
|
||||
void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const;
|
||||
void bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const;
|
||||
|
||||
void bindBuffer(unsigned int target, unsigned int buffer) const;
|
||||
|
||||
void* mapBuffer(unsigned int target, unsigned int access) const;
|
||||
void unmapBuffer(unsigned int target) const;
|
||||
|
||||
void generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const;
|
||||
|
||||
bool isGlContextInitialized() const;
|
||||
|
||||
PFNGLGENBUFFERSPROC glGenBuffersExt;
|
||||
PFNGLDELETEBUFFERSPROC glDeleteBuffersExt;
|
||||
|
||||
@@ -825,142 +629,180 @@ namespace
|
||||
|
||||
bool initialized;
|
||||
|
||||
GlFuncTab_W32()
|
||||
{
|
||||
glGenBuffersExt = 0;
|
||||
glDeleteBuffersExt = 0;
|
||||
|
||||
glBufferDataExt = 0;
|
||||
glBufferSubDataExt = 0;
|
||||
|
||||
glBindBufferExt = 0;
|
||||
|
||||
glMapBufferExt = 0;
|
||||
glUnmapBufferExt = 0;
|
||||
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
void genBuffers(int n, unsigned int* buffers) const
|
||||
{
|
||||
CV_FUNCNAME( "genBuffers" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glGenBuffersExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glGenBuffersExt(n, buffers);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void deleteBuffers(int n, const unsigned int* buffers) const
|
||||
{
|
||||
CV_FUNCNAME( "deleteBuffers" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glDeleteBuffersExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glDeleteBuffersExt(n, buffers);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const
|
||||
{
|
||||
CV_FUNCNAME( "bufferData" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glBufferDataExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glBufferDataExt(target, size, data, usage);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const
|
||||
{
|
||||
CV_FUNCNAME( "bufferSubData" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glBufferSubDataExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glBufferSubDataExt(target, offset, size, data);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void bindBuffer(unsigned int target, unsigned int buffer) const
|
||||
{
|
||||
CV_FUNCNAME( "bindBuffer" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glBindBufferExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glBindBufferExt(target, buffer);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void* mapBuffer(unsigned int target, unsigned int access) const
|
||||
{
|
||||
CV_FUNCNAME( "mapBuffer" );
|
||||
|
||||
void* res = 0;
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glMapBufferExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
res = glMapBufferExt(target, access);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void unmapBuffer(unsigned int target) const
|
||||
{
|
||||
CV_FUNCNAME( "unmapBuffer" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glUnmapBufferExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glUnmapBufferExt(target);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
bool isGlContextInitialized() const
|
||||
{
|
||||
return initialized;
|
||||
}
|
||||
HDC hDC;
|
||||
};
|
||||
|
||||
GlFuncTab_W32::GlFuncTab_W32(HDC hDC_)
|
||||
{
|
||||
glGenBuffersExt = 0;
|
||||
glDeleteBuffersExt = 0;
|
||||
|
||||
glBufferDataExt = 0;
|
||||
glBufferSubDataExt = 0;
|
||||
|
||||
glBindBufferExt = 0;
|
||||
|
||||
glMapBufferExt = 0;
|
||||
glUnmapBufferExt = 0;
|
||||
|
||||
initialized = false;
|
||||
|
||||
hDC = hDC_;
|
||||
}
|
||||
|
||||
void GlFuncTab_W32::genBuffers(int n, unsigned int* buffers) const
|
||||
{
|
||||
CV_FUNCNAME( "GlFuncTab_W32::genBuffers" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glGenBuffersExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glGenBuffersExt(n, buffers);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void GlFuncTab_W32::deleteBuffers(int n, const unsigned int* buffers) const
|
||||
{
|
||||
CV_FUNCNAME( "GlFuncTab_W32::deleteBuffers" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glDeleteBuffersExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glDeleteBuffersExt(n, buffers);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void GlFuncTab_W32::bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const
|
||||
{
|
||||
CV_FUNCNAME( "GlFuncTab_W32::bufferData" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glBufferDataExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glBufferDataExt(target, size, data, usage);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void GlFuncTab_W32::bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const
|
||||
{
|
||||
CV_FUNCNAME( "GlFuncTab_W32::bufferSubData" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glBufferSubDataExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glBufferSubDataExt(target, offset, size, data);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void GlFuncTab_W32::bindBuffer(unsigned int target, unsigned int buffer) const
|
||||
{
|
||||
CV_FUNCNAME( "GlFuncTab_W32::bindBuffer" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glBindBufferExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glBindBufferExt(target, buffer);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void* GlFuncTab_W32::mapBuffer(unsigned int target, unsigned int access) const
|
||||
{
|
||||
CV_FUNCNAME( "GlFuncTab_W32::mapBuffer" );
|
||||
|
||||
void* res = 0;
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glMapBufferExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
res = glMapBufferExt(target, access);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void GlFuncTab_W32::unmapBuffer(unsigned int target) const
|
||||
{
|
||||
CV_FUNCNAME( "GlFuncTab_W32::unmapBuffer" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (!glUnmapBufferExt)
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Current OpenGL implementation doesn't support required extension");
|
||||
|
||||
glUnmapBufferExt(target);
|
||||
CV_CheckGlError();
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
void GlFuncTab_W32::generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const
|
||||
{
|
||||
HFONT font;
|
||||
|
||||
CV_FUNCNAME( "GlFuncTab_W32::generateBitmapFont" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
font = CreateFont
|
||||
(
|
||||
-height, // height
|
||||
0, // cell width
|
||||
0, // Angle of Escapement
|
||||
0, // Orientation Angle
|
||||
weight, // font weight
|
||||
italic ? TRUE : FALSE, // Italic
|
||||
underline ? TRUE : FALSE, // Underline
|
||||
FALSE, // StrikeOut
|
||||
ANSI_CHARSET, // CharSet
|
||||
OUT_TT_PRECIS, // OutPrecision
|
||||
CLIP_DEFAULT_PRECIS, // ClipPrecision
|
||||
ANTIALIASED_QUALITY, // Quality
|
||||
FF_DONTCARE | DEFAULT_PITCH, // PitchAndFamily
|
||||
family.c_str() // FaceName
|
||||
);
|
||||
|
||||
SelectObject(hDC, font);
|
||||
|
||||
if (!wglUseFontBitmaps(hDC, start, count, base))
|
||||
CV_ERROR(CV_OpenGlApiCallError, "Can't create font");
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
bool GlFuncTab_W32::isGlContextInitialized() const
|
||||
{
|
||||
return initialized;
|
||||
}
|
||||
|
||||
void initGl(CvWindow* window)
|
||||
{
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
|
||||
std::auto_ptr<GlFuncTab_W32> glFuncTab(new GlFuncTab_W32);
|
||||
std::auto_ptr<GlFuncTab_W32> glFuncTab(new GlFuncTab_W32(window->dc));
|
||||
|
||||
// Load extensions
|
||||
PROC func;
|
||||
@@ -990,7 +832,7 @@ namespace
|
||||
|
||||
window->glFuncTab = glFuncTab.release();
|
||||
|
||||
cv::gpu::setGlFuncTab(window->glFuncTab);
|
||||
icvSetOpenGlFuncTab(window->glFuncTab);
|
||||
}
|
||||
|
||||
void createGlContext(HWND hWnd, HDC& hGLDC, HGLRC& hGLRC, bool& useGl)
|
||||
@@ -1089,11 +931,6 @@ namespace
|
||||
|
||||
CV_CheckGlError();
|
||||
|
||||
if (window->glText)
|
||||
window->glText->draw(window->width, window->height);
|
||||
|
||||
CV_CheckGlError();
|
||||
|
||||
if (!SwapBuffers(window->dc))
|
||||
CV_ERROR( CV_OpenGlApiCallError, "Can't swap OpenGL buffers" );
|
||||
|
||||
@@ -1209,8 +1046,6 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
|
||||
|
||||
window->glCleanCallback = 0;
|
||||
window->glCleanData = 0;
|
||||
|
||||
window->glText = 0;
|
||||
#endif
|
||||
|
||||
window->last_key = 0;
|
||||
@@ -1261,68 +1096,7 @@ CV_IMPL void cvSetOpenGlContext(const char* name)
|
||||
if (!wglMakeCurrent(window->dc, window->hGLRC))
|
||||
CV_ERROR( CV_OpenGlApiCallError, "Can't Activate The GL Rendering Context" );
|
||||
|
||||
cv::gpu::setGlFuncTab(window->glFuncTab);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
CV_IMPL void cvAddTextOpenGl(const char* name, const char* text, CvPoint org, CvScalar color, const char* fontName, int fontHeight, int fontWeight, int fontStyle)
|
||||
{
|
||||
CV_FUNCNAME( "cvAddTextOpenGl" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvWindow* window;
|
||||
|
||||
if(!name)
|
||||
CV_ERROR( CV_StsNullPtr, "NULL name string" );
|
||||
|
||||
window = icvFindWindowByName( name );
|
||||
if (!window)
|
||||
CV_ERROR( CV_StsNullPtr, "NULL window" );
|
||||
|
||||
if (!window->useGl)
|
||||
CV_ERROR( CV_OpenGlNotSupported, "Window doesn't support OpenGL" );
|
||||
|
||||
if (!wglMakeCurrent(window->dc, window->hGLRC))
|
||||
CV_ERROR( CV_OpenGlApiCallError, "Can't Activate The GL Rendering Context" );
|
||||
|
||||
if (!window->glText)
|
||||
window->glText = new OpenGlText(window->dc);
|
||||
|
||||
window->glText->add(text, org, color, fontName, fontHeight, fontWeight, fontStyle);
|
||||
|
||||
InvalidateRect(window->hwnd, 0, 0);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
CV_IMPL void cvClearTextOpenGl(const char* name)
|
||||
{
|
||||
CV_FUNCNAME( "cvClearTextOpenGl" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
CvWindow* window;
|
||||
|
||||
if(!name)
|
||||
CV_ERROR( CV_StsNullPtr, "NULL name string" );
|
||||
|
||||
window = icvFindWindowByName( name );
|
||||
if (!window)
|
||||
CV_ERROR( CV_StsNullPtr, "NULL window" );
|
||||
|
||||
if (!window->useGl)
|
||||
CV_ERROR( CV_OpenGlNotSupported, "Window doesn't support OpenGL" );
|
||||
|
||||
if (!wglMakeCurrent(window->dc, window->hGLRC))
|
||||
CV_ERROR( CV_OpenGlApiCallError, "Can't Activate The GL Rendering Context" );
|
||||
|
||||
if (window->glText)
|
||||
{
|
||||
window->glText->clear();
|
||||
InvalidateRect(window->hwnd, 0, 0);
|
||||
}
|
||||
icvSetOpenGlFuncTab(window->glFuncTab);
|
||||
|
||||
__END__;
|
||||
}
|
||||
@@ -1406,9 +1180,6 @@ static void icvRemoveWindow( CvWindow* window )
|
||||
if (window->useGl)
|
||||
{
|
||||
wglMakeCurrent(window->dc, window->hGLRC);
|
||||
|
||||
if (window->glText)
|
||||
delete window->glText;
|
||||
|
||||
if (window->glCleanCallback)
|
||||
{
|
||||
|
Reference in New Issue
Block a user