00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __RE_OGLRender__
00019 #define __RE_OGLRender__
00020
00021 #include "RE_API.h"
00022
00023 #include <SYS/SYS_Math.h>
00024 #include <tools/prisms.h>
00025
00026 #include <UT/UT_Defines.h>
00027 #include <UT/UT_Pointers.h>
00028 #include <UT/UT_PtrArray.h>
00029 #include <UT/UT_RefArray.h>
00030 #include <UT/UT_Color.h>
00031 #include <UT/UT_Floor.h>
00032 #include <UT/UT_Rect.h>
00033 #include <UT/UT_RefArray.h>
00034 #include <UT/UT_Thread.h>
00035 #include <UT/UT_ThreadSpecificValue.h>
00036 #include <UT/UT_SpinLock.h>
00037
00038 #include <TIL/TIL_Defines.h>
00039
00040 class UT_DMatrix4;
00041 class UT_IntArray;
00042 class UT_RGBA;
00043 class UT_WorkBuffer;
00044 class RE_Light;
00045 class UT_Vector4;
00046 class IMG_Raster;
00047 class PXL_Raster;
00048 class PXL_Lookup;
00049
00050 class RE_Cursor;
00051 class RE_Font;
00052 class RE_Material;
00053 class RE_OGLTexture2DMap;
00054 class RE_Server;
00055 class RE_Uniform;
00056 class RE_Visual;
00057 class RE_Window;
00058 class RE_WindowList;
00059
00060 class RE_Tesselator;
00061 class RE_OGLExt;
00062 class RE_Shader;
00063
00064 #include "RE_Types.h"
00065 #include "RE_TextureTypes.h"
00066 #include "RE_Extension.h"
00067 #include "RE_LightVal.h"
00068 #include "RE_OGLVertex.h"
00069 #include "RE_Uniform.h"
00070
00071 #define OPEN_GL
00072
00073 #define RE_SYMBOL_FONT_SIZE_TINY 3.0f
00074 #define RE_SYMBOL_FONT_SIZE_SMALL 6.0f
00075 #define RE_SYMBOL_FONT_SIZE_SMEDIUM 8.0f
00076 #define RE_SYMBOL_FONT_SIZE_MEDIUM 9.0f
00077 #define RE_SYMBOL_FONT_SIZE_LARGE 12.0f
00078
00079
00080
00081 class RE_API RE_OGLRender
00082 {
00083 public:
00084 RE_OGLRender(int do_foreground, const char *appname = 0);
00085
00086 ~RE_OGLRender();
00087
00088 static void initialize();
00089
00090
00091
00092 static bool hasGL11() { return ((majorGLVersion > 1) ||
00093 ((majorGLVersion >= 1) &&
00094 (minorGLVersion >= 1))); };
00095 static bool hasGL12() { return ((majorGLVersion > 1) ||
00096 ((majorGLVersion >= 1) &&
00097 (minorGLVersion >= 2))); };
00098 static bool hasGL13() { return ((majorGLVersion > 1) ||
00099 ((majorGLVersion >= 1) &&
00100 (minorGLVersion >= 3))); };
00101 static bool hasGL14() { return ((majorGLVersion > 1) ||
00102 ((majorGLVersion >= 1) &&
00103 (minorGLVersion >= 4))); };
00104 static bool hasGL15() { return ((majorGLVersion > 1) ||
00105 ((majorGLVersion >= 1) &&
00106 (minorGLVersion >= 5))); };
00107 static bool hasGL20() { return ((majorGLVersion > 2) ||
00108 ((majorGLVersion >= 2) &&
00109 (minorGLVersion >= 0))); };
00110 static bool hasGL21() { return ((majorGLVersion > 2) ||
00111 ((majorGLVersion >= 2) &&
00112 (minorGLVersion >= 1))); };
00113
00114 static int glMajorVersion() { return majorGLVersion; }
00115 static int glMinorVersion() { return minorGLVersion; }
00116
00117
00118 static bool hasShadersExt() { return theHasShadersExt; }
00119 static void disableShadersExt() { theHasShadersExt = false; }
00120
00121
00122
00123
00124
00125
00126
00127 static RE_GraphicsDevice getGraphicsDevice() { return theDevice; }
00128
00129
00130 static int getDriverMajorVersion() { return theDriverMajor;}
00131 static int getDriverMinorVersion() { return theDriverMinor;}
00132 static int getDriverBuildVersion() { return theDriverBuild;}
00133
00134
00135 static const RE_Material *getDefaultMaterial();
00136
00137 void getDriverInfo(UT_WorkBuffer &info);
00138
00139
00140
00141 RE_OGLExt *getExt() const { return myExt; }
00142
00143 void pushState(int viewing);
00144 void popState();
00145
00146 short resC() const;
00147
00148
00149
00150 static short resX() { return theXRes; }
00151 static short resY() { return theYRes; }
00152 static short virtualResX() { return theVirtualX; }
00153 static short virtualResY() { return theVirtualY; }
00154
00155 static void updateScreenSize();
00156
00157
00158
00159 static int getNumScreens();
00160 static UT_DimRect getScreen(int i);
00161 static UT_DimRect getWorkArea(int i);
00162 static int getScreenContaining(int x, int y,
00163 bool closest_if_none = false);
00164
00165 static bool areScreensUniform();
00166
00167
00168 static UT_DimRect getWorkAreaForScreen(UT_DimRect area);
00169
00170
00171 static UT_DimRect getTotalScreenArea();
00172 static UT_DimRect getTotalWorkArea();
00173
00174
00175
00176
00177
00178 static int positionOnScreen(UT_DimRect &area,
00179 int screen_hint=-1);
00180
00181
00182 static bool positionOkay(const UT_DimRect &area) ;
00183
00184 static short dpi() { return theDotsPerInch; }
00185
00186 static float pixelsToInches(int n) { return (float)n / dpi(); }
00187
00188 static int inchesToPixels(float i) { return (int)UTrint(i*(float)dpi()); }
00189 static void scaleDPI(fpreal dpi);
00190
00191 float getRasterX() const { return rx; }
00192 float getRasterY() const { return ry; }
00193 float getRasterZ() const { return rz; }
00194
00195 int getViewportFontOffsetX() const { return myViewportFontOffsetX; }
00196 int getViewportFontOffsetY() const { return myViewportFontOffsetY; }
00197
00198 short getFullscreenX() const { return 0; }
00199 short getFullscreenY() const { return 0; }
00200
00201
00202 RE_DisplayMode mapBestMode(RE_DisplayMode mode);
00203 RE_DisplayMode getMode() const;
00204
00205 RE_VisualType getVisualType() const;
00206 static RE_Visual *getVisualForMode(RE_DisplayMode newmode);
00207 static RE_Server *getServer();
00208 static RE_Cursor *getCursor(const char *name);
00209
00210 #if RE_OGL_SINGLE_CONTEXT
00211 void setContext(RE_IDType wid, int force = 0);
00212 void setContext(RE_Window *, int force = 0);
00213 void pushContext(RE_IDType wid);
00214 void pushContext(RE_Window *);
00215 void popContext();
00216
00217 RE_IDType getContextID() const;
00218 bool contextIsValid() { return 0 != getContextID(); }
00219 #else
00220 void setWindow(RE_Window *);
00221
00222 void makeCurrent();
00223 bool isCurrent() { return theCurrentRender.get() == this; }
00224 static void resetCurrent();
00225 bool contextIsValid() { return (bool)myContext; }
00226 RE_OGLContext getContext() const { return myContext; }
00227
00228
00229
00230 void pushOffscreenBuffer(OGLDrawable type);
00231 void popOffscreenBuffer();
00232 #endif
00233
00234
00235 void setMainContext(RE_Window *w);
00236 static RE_Window *getMainContext() { return theMainContextWindow; }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 void lockContextForRender();
00258 void unlockContextAfterRender();
00259 bool tryLockContextForRender();
00260 bool isContextLocked() const;
00261
00262 void dumpState(bool extended_info = true) const;
00263 void dumpLightState() const;
00264
00265 void scaleViewForPick(float *l, float *r, float *b, float *t);
00266 void depthCueing(int state, int usegreyramp = 0);
00267
00268 void enableFog(int type, float density,
00269 float nearf, float farf,
00270 const float *col, float alpha);
00271 void disableFog();
00272 void useFogCoord(bool onoff);
00273
00274 void enableLogicOp(void);
00275 void disableLogicOp(void);
00276 void invertPixels(void);
00277 void xorPixels(void);
00278
00279 int overlaySupported() const { return 0; }
00280 void overlaySupported(int ) {}
00281
00282 void swapbuffers();
00283
00284
00285
00286
00287 bool isFrontBufferDirty() const
00288 { return myFrontBufferDirty; }
00289 void setFrontBufferDirty(bool dirty)
00290 { myFrontBufferDirty = dirty; }
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 void beginXORDraw(GLuint &id);
00301 void endXORDraw (GLuint &id);
00302 void clearXORDraw(GLuint &id);
00303 void resetXORDraw(GLuint &id);
00304
00305 RE_RenderBuf enablebuffers(RE_RenderBuf which);
00306 int enableZbuffer(int state, int clear_it);
00307 void setZFunction(RE_ZFunction func);
00308 RE_ZFunction getZFunction() const { return _z_function; };
00309 int isZbuffer();
00310
00311 void pushStencilState();
00312 void popStencilState();
00313 void setSClearValue(int clearValue);
00314 void setSWriteMask(int writeMask);
00315 void setSFunction(RE_SFunction func, int ref, int mask);
00316 void setSOperation(RE_SOperation sfail,
00317 RE_SOperation dpfail,
00318 RE_SOperation dppass);
00319
00320 RE_RenderBuf getDrawBuffer() { return drawBuffer; }
00321 void setDrawBuffer( RE_RenderBuf buf );
00322
00323 bool setCompactPick( bool c )
00324 {
00325 bool old = myCompactPick;
00326 myCompactPick = c;
00327 return old;
00328 }
00329
00330 private:
00331 static RE_ZFunction oglToREzfunc( int oglZFunc );
00332 static int reToOGLzfunc( RE_ZFunction reZFunc );
00333 void setZFunction();
00334 RE_ZFunction _z_function;
00335
00336 static RE_SFunction oglToREsfunc( int oglSFunc );
00337 static int reToOGLsfunc( RE_SFunction reSFunc );
00338 static RE_SOperation oglToREsoperation( int oglSOperation );
00339 static int reToOGLsoperation( RE_SOperation reSOperation );
00340 void setSClearValue();
00341 int _s_clear_value;
00342 void setSWriteMask();
00343 int _s_write_mask;
00344 void setSFunction();
00345 RE_SFunction _s_function;
00346 int _s_function_ref;
00347 int _s_function_mask;
00348 void setSOperation();
00349 RE_SOperation _s_operation_sfail;
00350 RE_SOperation _s_operation_dpfail;
00351 RE_SOperation _s_operation_dppass;
00352 public:
00353
00354 void copyToFront(short x, short y, short w, short h);
00355 void copyToBack(short x, short y, short w, short h);
00356 void saveFront(short x, short y, short w, short h);
00357 void restoreFront(short x, short y, short w, short h);
00358
00359
00360
00361
00362
00363 void saveRaster(short x, short y, short w, short h,
00364 IMG_Raster *r, bool use_backbuf = true);
00365 PXL_Raster * saveRaster(short x, short y, short w, short h,
00366 PXL_DataFormat format, bool alphatoo,
00367 bool use_backbuf = true);
00368 void displayRaster(float x, float y, short w, short h,
00369 IMG_Raster *r, float zoom = -1.0f,
00370 int dither = 1);
00371 void displayRaster(float x, float y, short w, short h,
00372 UT_RGBA *r, short stride,
00373 float zoom=-1.0f, int dither = 1);
00374 void displayRaster(float x, float y,
00375 const PXL_Raster *raster,
00376 const RE_RasterOpts *opts = 0);
00377 void displayRasterTexture(float x, float y,
00378 const PXL_Raster *raster,
00379 const RE_RasterOpts *opts = 0);
00380
00381
00382 void convertRasterToTexture(PXL_Raster *raster,
00383 int convert16bit = 0);
00384 void convertLUTToTexture(PXL_Lookup *raster, int size);
00385 bool is3DLUTSupported();
00386 int getMaxTextureRectangleSize();
00387
00388 int isFloatZoomSupported();
00389 int getMaxPixelMapSize();
00390 int isHalfFloatSupported();
00391
00392
00393 void zoomRaster(float xzoom, float yzoom = -1);
00394 void getRasterZoom(float &xzoom, float &yzoom) const;
00395
00396 void ortho2DW(float l, float r, float b, float t);
00397 void ortho3DW(float l, float r, float b, float t, float n,
00398 float f);
00399
00400
00401 void perspective(float fov, float a, float n, float f);
00402 void window3DW( float l, float r, float b, float t,
00403 float near, float far );
00404 int mapWorld( float xs, float xy,
00405 float *x1, float *y1, float *z1,
00406 float *x2, float *y2, float *z2 );
00407 int mapWorld( float xs, float ys,
00408 short vpl, short vpr, short vpb, short vpt,
00409 const UT_Matrix4 &proj,
00410 const UT_Matrix4 &view,
00411 float *x1, float *y1, float *z1,
00412 float *x2, float *y2, float *z2);
00413 int mapScreen( float xw, float yw, float zw,
00414 float *xs, float *ys );
00415 int mapScreen(float xw, float yw, float zw,
00416 short vpl, short vpr, short vpb, short vpt,
00417 const UT_Matrix4 &proj,
00418 const UT_Matrix4 &view,
00419 float *xs, float *ys);
00420 void viewport2DS(short l, short r, short b, short t);
00421 void screenMask2DS(short l, short r, short b, short t);
00422 void disableScreenMask();
00423 void intersectMask2DS(short l, short r, short b, short t);
00424 void getScreenMask2DS(short *l, short *r, short *b,
00425 short *t);
00426
00427 void getViewport2DS( int *l, int *r, int *b, int *t );
00428 bool getViewportMaskActive() const;
00429
00430 void enableMultisample(bool enable);
00431 bool isMultisampleEnabled() const;
00432
00433 void pushPattern(RE_FillPattern p);
00434 void popPattern();
00435
00436 void pushLineStyle(RE_LineStyle s);
00437 void popLineStyle();
00438
00439 void pushLineWidth(float w);
00440 void popLineWidth();
00441 float getLineWidth() const;
00442 float getMaxSmoothLineWidth();
00443
00444 void pushPointSize(float size);
00445 void popPointSize();
00446 void setPointSize(float size);
00447
00448
00449 void pushViewport();
00450 void popViewport();
00451
00452 void matrixMode(RE_MatrixMode mode);
00453 RE_MatrixMode getMatrixMode();
00454 void pushMatrix(int update_projection=1);
00455 void popMatrix(int update_projection=1);
00456 void loadMatrix(const UT_Matrix4 &m);
00457 void loadMatrix(const UT_DMatrix4 &m);
00458 void loadIdentityMatrix();
00459 void getMatrix( UT_Matrix4 &m);
00460 void getAMatrix(RE_MatrixMode mmode, UT_Matrix4 &m);
00461 void getAMatrix(RE_MatrixMode mmode, UT_DMatrix4 &m);
00462 void multiplyMatrix(const UT_Matrix4 &m);
00463 void multiplyMatrix(const UT_DMatrix4 &m);
00464
00465 void translate(float x, float y, float z = 0.0);
00466 void scale(float x = 1.0, float y = 1.0, float z = 1.0);
00467 void rotate(float angle, char axis);
00468
00469 #if RE_OGL_SINGLE_CONTEXT
00470 void getOrigin(long *x, long *y);
00471 #endif
00472 void getOverlayRelOrigin( short *x, short *y );
00473
00474 int startObjectDefine();
00475 void endObjectDefine();
00476 void deleteObject(int id);
00477 void drawObject(int id);
00478
00479
00480
00481
00482
00483
00484
00485 int startSmartObjectDefine();
00486 bool endSmartObjectDefine();
00487 void deleteSmartObject(int id);
00488 bool isSmartObjectDirty(int id);
00489
00490 bool inObjectDefine() const { return myInObjectDefine; }
00491 bool trackingObjectShaderUsage() const
00492 { return myTrackingObjectShaderUsage; }
00493 bool trackingObjectTextureUsage() const
00494 { return myTrackingObjectTextureUsage; }
00495
00496
00497 const UT_IntArray *getShadersUsedBySmartObject(int id);
00498
00499
00500
00501
00502
00503
00504 bool notifySmartObjectsOfShaderDeletion( int shader_idx );
00505 bool notifySmartObjectsOfTextureDeletion( int texture_idx );
00506
00507
00508
00509 void deletePendingShadersFromSmartObjectCreation();
00510 void deletePendingTexturesFromSmartObjectCreation();
00511
00512
00513
00514 void recordShaderForSmartObject( int shader_idx );
00515
00516
00517
00518 void setUniform(RE_UniformBuiltIn builtin_var_type,
00519 const RE_Uniform *var);
00520
00521
00522 void bindBuiltInUniforms(RE_Shader *s,
00523 RE_UniformBinding bind);
00524
00525 void setColor(const UT_Color &c, float alpha=1.0);
00526 void setColor(float r, float g, float b, float a);
00527 void setColorMask(int red, int green, int blue, int alpha);
00528 void getColor(UT_Color &c) const;
00529 void setAlpha(float alpha);
00530 float getAlpha() const;
00531 void pushColor();
00532 void popColor();
00533 void pushColor(const UT_Color &c, float alpha=1.0f)
00534 { pushColor(); setColor(c, alpha); }
00535 void resetColorCache()
00536 { myGLColor[0]=myGLColor[1]=myGLColor[2]=myGLColor[3]=-1.f; }
00537
00538 void clearAllMaterials(void) const;
00539 void clearAllTextures(void) const;
00540
00541
00542
00543 void setMaterial(RE_Material &mat, int layer = 0);
00544
00545 void pushMaterial(RE_Material *mat, int layer = 0);
00546 void popMaterial();
00547
00548
00549
00550
00551 void pushMaterialDiffuse();
00552 void popMaterialDiffuse();
00553
00554
00555
00556
00557
00558 void setDiffuseMaterialFromMaterialStack();
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568 static int computeTextureRes(unsigned int res)
00569 {
00570 int m = 0;
00571 unsigned int a = res;
00572 while (a >>= 1) m++;
00573 int lbound = 1 << m;
00574
00575
00576 return (res > (lbound + (lbound >> 1))) ?
00577 (lbound << 1) : lbound;
00578 }
00579
00580
00581 void useTexture2D(int idx);
00582 void useTexture3D(int idx);
00583 void useTextureCubeMap(int idx);
00584
00585
00586
00587 int getActiveTexture() const;
00588 void setActiveTexture(int tunit);
00589
00590
00591 void setTextureMode(RE_TextureMode mode);
00592 RE_TextureMode getTextureMode() const;
00593
00594
00595 int getMaxTextureUnits() const { return myMaxTextureUnits; }
00596
00597
00598
00599 int getMaxTextureSize() const { return myMaxTextureSize; }
00600
00601
00602 void enableTexture2D();
00603 void disableTexture2D();
00604 int getTexture2D();
00605 void enableTexture3D();
00606 void disableTexture3D();
00607 int getTexture3D();
00608 void enableTextureCubeMap();
00609 void disableTextureCubeMap();
00610 int getTextureCubeMap();
00611
00612
00613 void disableAllTextures();
00614
00615
00616 void initAllTextures();
00617
00618 void setLightModel(int local_viewer, int two_sided_lighting);
00619
00620
00621
00622
00623 unsigned defineLight(const RE_Light &light, bool normalize = false);
00624
00625 #if ! RE_OGL_SINGLE_CONTEXT
00626 bool isLightDefined(const RE_Light &light) const;
00627 void deNormalizeLightDefinition(const RE_Light &light);
00628 void setLightState(const RE_Light &light, int onoff);
00629 #endif
00630
00631 void deNormalizeLightDefinition(unsigned index);
00632 void undefineLight(unsigned index);
00633 void undefineAllLights();
00634 void setLightState(unsigned index, int onoff);
00635 bool getLightState(unsigned index);
00636 void allLightsOff();
00637 RE_Light *getLight(int index);
00638 int getNumLights();
00639 void setGLSpots(int f) { myUseOGLSpots = f; }
00640 void setAllowSpecular(int f) { myAllowLightSpecular = f; }
00641 int getAllowSpecular() const { return myAllowLightSpecular; }
00642 RE_Uniform *getLightEnabledUniform() const{ return myLightEnabledUniform; }
00643 void setNormalizeGlobalAmbient(bool normalize)
00644 { myNormalizeGlobalAmbient = normalize; }
00645 bool getNormalizeGlobalAmbient() const
00646 { return myNormalizeGlobalAmbient; }
00647
00648 private:
00649 void resetAmbientLight();
00650
00651 public:
00652
00653
00654
00655
00656
00657 void toggleLighting(int onoff);
00658 void toggleLightShading(int onoff);
00659 void setDefaultStacklessColor(const UT_Color &color);
00660
00661
00662
00663 void useProjectiveTexture(bool ison, RE_Light *light);
00664
00665
00666
00667 void setProjectiveTextureTransform(const RE_Light *light,
00668 bool bias);
00669
00670
00671
00672 void setSpotlightConeTransform(const RE_Light *light, bool bias);
00673
00674
00675
00676 void setShadowMapTransform(const RE_Light *light, bool bias);
00677
00678
00679
00680
00681
00682
00683
00684 bool prepShadowMapRender(const RE_Light *light);
00685
00686
00687
00688 void saveShadowMapToRaster(PXL_Raster &raster);
00689
00690
00691
00692 void finishShadowMapRender();
00693
00694
00695
00696
00697 void useShadowMap(bool ison, const RE_Light *light);
00698
00699 public:
00700
00701
00702 void clear();
00703 void clearZ();
00704 void clearCZ();
00705 void clearS();
00706
00707 void pushBlendState();
00708 void popBlendState();
00709
00710 int isBlending() const { return getBlending(); }
00711 void blend(int onoff);
00712 void setBlendFunction(RE_BlendSourceFactor sourceFactor,
00713 RE_BlendDestFactor destFactor);
00714 void getBlendFunction(RE_BlendSourceFactor* sourceFactor,
00715 RE_BlendDestFactor* destFactor);
00716 void blendAlpha(int onoff, int usezbuffer=0);
00717 void alphaTest(int onoff);
00718 void setAlphaTestFunction(RE_ZFunction func, float val);
00719
00720 void beginPicking(uint *buf, long bufsiz, short x, short y,
00721 short w, short h );
00722 long endPicking(uint *buf);
00723 int isPicking(void) const;
00724 void loadPickId(uint id);
00725 void pushPickId(uint id);
00726 void popPickId();
00727
00728 int isBackface() { return stateInfo.backface; }
00729 void setBackface(int removeBackface = 0);
00730 int getReverseWinding() { return stateInfo.reverse_winding; }
00731 void setReverseWinding(int reverse_winding);
00732
00733 int isCaching() const { return avoidCacheCount ? 1:cacheIndex; }
00734
00735 int avoidCache() const { return avoidCacheCount; }
00736 void bumpAvoidCache(int d) { avoidCacheCount += d; }
00737
00738 UT_Bool isPointOffset() const { return getPointOffset(); };
00739 UT_Bool isLineOffset() const { return getLineOffset(); };
00740 UT_Bool isPolygonOffset() const;
00741 void pointOffset( UT_Bool onoff ) { if( onoff ) enablePointOffset(); else disablePointOffset(); };
00742 void lineOffset( UT_Bool onoff ) { if( onoff ) enableLineOffset(); else disableLineOffset(); };
00743 void polygonOffset( UT_Bool onoff );
00744 void setOffsetAmount( float variable, float constant );
00745 void getOffsetAmount( float* variable, float* constant ) { (*variable) = _offset_variable; (*constant) = _offset_constant; };
00746
00747 private:
00748 RE_PolyOffStrategy getPolygonOffsetStrategy() const;
00749
00750 void setOffsetAmount();
00751 float _offset_variable;
00752 float _offset_constant;
00753
00754 public:
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769 void end();
00770
00771
00772
00773
00774 void beginPolygon(int concave);
00775 void endPolygon();
00776 void beginLine();
00777 void endLine();
00778 void beginLines();
00779 void endLines();
00780
00781
00782 void beginClosedLine();
00783 void endClosedLine();
00784 void beginPoint();
00785 void endPoint();
00786 void beginTriangles();
00787 void endTriangles();
00788
00789
00790
00791
00792 void beginTriangleFan();
00793 void endTriangleFan();
00794
00795
00796
00797
00798
00799
00800 void beginTriMesh();
00801 void endTriMesh();
00802 void beginQuads();
00803 void endQuads();
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815 void beginQuadStrip();
00816 void endQuadStrip();
00817
00818 void v2DS(const short v[2]) { myVtxOut->v2DS(v); }
00819 void v2DI(const int v[2]) { myVtxOut->v2DI(v); }
00820 void v2DW(const float v[2]) { myVtxOut->v2DW(v); }
00821 void v3DS(const short v[3]) { myVtxOut->v3DS(v); }
00822 void v3DI(const int v[3]) { myVtxOut->v3DI(v); }
00823 void v3DW(const float v[3]) { myVtxOut->v3DW(v); }
00824
00825
00826 int generateTexture();
00827 void bindTexture(int index);
00828 void bindTexture3D(int index);
00829 void bindTextureCubeMap(int index);
00830 void deleteTexture(int index);
00831
00832
00833
00834
00835 void vertex2DI(int x, int y) { myVtxOut->vertex2DI(x, y); }
00836 void vertex2DS(short x, short y) { myVtxOut->vertex2DS(x, y); }
00837 void vertex2DW(float x, float y) { myVtxOut->vertex2DW(x, y); }
00838 void vertex3DI(int x, int y, int z)
00839 { myVtxOut->vertex3DS(x, y, z); }
00840 void vertex3DS(short x, short y, short z)
00841 { myVtxOut->vertex3DS(x, y, z); }
00842 void vertex3DW(float x, float y, float z)
00843 { myVtxOut->vertex3DW(x, y, z); }
00844
00845 void c3DS(const short v[3])
00846 {
00847 myVtxOut->c3DS(v);
00848 myGLColor[0]=v[0]/32768.0f; myGLColor[1]=v[1]/32768.0f;
00849 myGLColor[2]=v[2]/32768.0f; myGLColor[3]=1.0f;
00850 }
00851 void c3DW(const float v[3])
00852 {
00853 myVtxOut->c3DW(v);
00854 myGLColor[0]=v[0]; myGLColor[1]=v[1];
00855 myGLColor[2]=v[2]; myGLColor[3]=1.0f;
00856 }
00857 void c4DW(const float v[4])
00858 {
00859 myVtxOut->c4DW(v);
00860 myGLColor[0]=v[0]; myGLColor[1]=v[1];
00861 myGLColor[2]=v[2]; myGLColor[3]=v[3];
00862 }
00863 void cacheC3DW(const float v[3])
00864 {
00865 if (v[0] != myGLColor[0] || v[1] != myGLColor[1] ||
00866 v[2] != myGLColor[2] || 1.0f != myGLColor[3])
00867 {
00868 c3DW(v);
00869 }
00870
00871 }
00872 void cacheC4DW(const float v[4])
00873 {
00874 if (v[0] != myGLColor[0] || v[1] != myGLColor[1] ||
00875 v[2] != myGLColor[2] || v[3] != myGLColor[3])
00876 {
00877 c4DW(v);
00878 }
00879 }
00880 void n3DW(const float v[3]) { myVtxOut->n3DW(v); }
00881 void t2DW(const float v[2]) { myVtxOut->t2DW(v); }
00882 void t3DW(const float v[3]) { myVtxOut->t3DW(v); }
00883 void t4DW(const float v[4]) { myVtxOut->t4DW(v); }
00884 void a1DW(unsigned int loc, const float v[1])
00885 { myVtxOut->a1DW(loc, v); }
00886 void a2DW(unsigned int loc, const float v[2])
00887 { myVtxOut->a2DW(loc, v); }
00888 void a3DW(unsigned int loc, const float v[3])
00889 { myVtxOut->a3DW(loc, v); }
00890 void a4DW(unsigned int loc, const float v[4])
00891 { myVtxOut->a4DW(loc, v); }
00892
00893
00894
00895
00896
00897 void fogCoord(const float z);
00898
00899 RE_InterpMode getInterpMode();
00900 void interpMode(RE_InterpMode mode);
00901
00902 void pushSmoothLines();
00903 void popSmoothLines();
00904 void forceSmooth();
00905 void smoothBlendLines(RE_SmoothMode mode);
00906 void smoothBlendLinesNoFlagChange();
00907 RE_SmoothMode getSmoothLines() { return mySmoothingLines ? RE_SMOOTH_ON : RE_SMOOTH_OFF; };
00908 void subPixel(int mode);
00909 void clipPlane(int which, int onoff, const UT_Vector4 *parms = 0);
00910
00911 void move2DW(float x, float y);
00912 void move2DS(short x, short y);
00913 void move3DW(float x, float y, float z);
00914 void move3DS(short x, short y, short z);
00915 void rmove2DW(float x, float y);
00916 void rmove2DS(short x, short y);
00917 void rmove3DW(float x, float y, float z);
00918 void rmove3DS(short x, short y, short z);
00919 void draw2DW(float x, float y);
00920 void draw2DS(short x, short y);
00921 void draw3DW(float x, float y, float z);
00922 void draw3DS(short x, short y, short z);
00923 void rdraw2DW(float x, float y);
00924 void rdraw2DS(short x, short y);
00925 void rdraw3DW(float x, float y, float z);
00926 void rdraw3DS(short x, short y, short z);
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939 void rect2DW (float x1, float y1, float x2, float y2);
00940 void rect2DS (short x1, short y1, short x2, short y2);
00941 void rectf2DW(float x1, float y1, float x2, float y2);
00942 void rectf2DS(short x1, short y1, short x2, short y2);
00943 void box2DS (short x1, short y1, short x2, short y2);
00944 void boxf2DS (short x1, short y1, short x2, short y2);
00945
00946 void arcW(float x, float y, float r, short a, short b);
00947 void arcS(short x, short y, short r, short a, short b);
00948 void arcfW(float x, float y, float r, short a, short b);
00949 void arcfS(short x, short y, short r, short a, short b);
00950
00951 void sectorS(short x, short y, short ir, short outer,
00952 float a, float b, int slices = 20, int loops = 1);
00953 void sectorW(float x, float y, float ir, float outer,
00954 float a, float b, int slices = 20, int loops = 1);
00955
00956
00957
00958
00959 void circlefS(short x, short y, short innerr, short outerr,
00960 int slices = 50);
00961 void circlefW(float x, float y, float innerr, float outerr,
00962 int slices = 50);
00963
00964
00965 void circlefS(short x, short y, short r, int slices = 50);
00966 void circlefW(float x, float y, float r, int slices = 50);
00967
00968
00969 void circleS (short x, short y, short r, int slices = 50);
00970 void circleW (float x, float y, float r, int slices = 50);
00971
00972 void sphereW(float x, float y, float z, float r, int divs = 20);
00973 void spherefW(float x, float y, float z, float r, int divs = 20);
00974
00975 void textMove3S(short x, short y, short z);
00976 void textMove3W(float x, float y, float z);
00977 void textMoveS(short x, short y);
00978 void textMoveW(float x, float y);
00979
00980
00981
00982
00983
00984
00985
00986 void setViewportFontOffset(int x, int y);
00987
00988
00989
00990
00991
00992 static RE_Font *internalGetFont(const char *name, float size);
00993
00994 public:
00995
00996
00997 static RE_Font *getViewportFont();
00998
00999
01000
01001 static RE_Font *getViewportSymbolFont(float size);
01002
01003 static void setDefaultFont(const char *name, float size);
01004
01005 void getTextPos(short *x, short *y);
01006
01007 void flush(int wait=0) const;
01008 void waitForRetrace() const;
01009
01010
01011 void *createNurbsObject (void);
01012 void destroyNurbsObject(void *nurbsobj);
01013 void beginNurbsSurface(void *nurbsobj);
01014 void endNurbsSurface (void *nurbsobj);
01015 void nurbsSurface(int uklen, float *uknots, int vklen,
01016 float *vknots, int nrows, float *cvs,
01017 int uorder, int vorder, int rational,
01018 void *nurbsobj);
01019 void beginTrimLoop(void *nurbsobj);
01020 void endTrimLoop (void *nurbsobj);
01021 void polyTrimCurve (int nvtx, float *cvs, void *nurbsobj);
01022 void nurbsTrimCurve(int uklen, float *uknots, int order,
01023 float *cvs, int rational, void *nurbsobj);
01024 void setNurbsProperties(int autonormal, float tol,
01025 void *nurbsobj = 0);
01026
01027 const char *className() const;
01028
01029 void setIconImage(const char *filename);
01030
01031 void setIconLoader(RE_IconLoader loader)
01032 {
01033 iconLoader = loader;
01034 }
01035
01036 void setIconLoader(RE_IDType wid, RE_IconLoader loader);
01037 void clearIconLoader(RE_IDType wid);
01038
01039 void initGLState();
01040
01041 int useDisplayLists();
01042
01043 static RE_WindowList *getWindowList() { return theWindowList; }
01044
01045 int getGLError();
01046 int getNextGLError();
01047 void clearGLErrors();
01048 const char *getGLErrorString( int error );
01049 void printGLError(const char *header,
01050 bool assert = false );
01051 void printAllGLErrors( const char *header,
01052 bool assert = false );
01053
01054 void setDrawPixelsMode(RE_DrawPixelsMode new_mode);
01055 RE_DrawPixelsMode getDrawPixelsMode();
01056 void enable( int state ) { enabled = state; }
01057
01058 static void allowSmoothLines(int yn)
01059 {
01060 theSmoothLinesAllowed = yn;
01061 }
01062 static int allowsSmoothLines()
01063 {
01064 return theSmoothLinesAllowed;
01065 }
01066
01067 const RE_Window *getCurrentWindow() const { return currentWindow; }
01068 RE_Window *getCurrentWindow() { return currentWindow; }
01069
01070 void updateScreensAndWorkAreas() { determineTwinView(); };
01071
01072 protected:
01073 void defineTexture(int idx, PXL_Raster *rp) const;
01074
01075 unsigned int allocRenderCache ( unsigned int num = 1 );
01076 void deleteRenderCache( unsigned int cache,
01077 unsigned int num = 1 );
01078 void beginCache ( unsigned int cache );
01079 void executeCache ( unsigned int cache );
01080 void endCache();
01081
01082
01083
01084 void recordTextureForSmartObject( int texture_idx );
01085
01086 private:
01087 static void initTextureCache();
01088 static void initTexture3DCache();
01089
01090 inline int setConcave(int concave);
01091 UT_Bool updateRGBmode();
01092 void determineTwinView();
01093 void switchContextForRender();
01094
01095 #if RE_OGL_SINGLE_CONTEXT
01096 void makeWindowCurrent(RE_Window *win);
01097 #endif
01098
01099 #ifdef WIN32
01100 public:
01101
01102
01103 void internalAddScreen(UT_DimRect rect)
01104 { theScreens.append(rect); }
01105 void internalAddWorkArea(UT_DimRect rect)
01106 { theWorkAreas.append(rect); }
01107 private:
01108 #endif
01109
01110 #if ! RE_OGL_SINGLE_CONTEXT
01111 RE_LightVal *validateLight(const RE_Light &light);
01112 #endif
01113
01114 RE_LightVal *validateLightIndex(unsigned index);
01115 void turnLightOn(unsigned int index);
01116 void turnLightOff(unsigned int index);
01117
01118 void displayClippedRaster(const unsigned char *base, int offset,
01119 int psize, int w, int h,
01120 GLenum type, GLenum format,
01121 float x, float y);
01122
01123 void setState( RE_State currentState, RE_State newState, int push );
01124 RE_State stateStack[RE_STACK_DEPTH];
01125 short stateIndex;
01126
01127 void *saveBuffer;
01128 unsigned saveSize;
01129
01130 #if RE_OGL_SINGLE_CONTEXT
01131 RE_Window *contextStack[CONTEXT_STACK_SIZE];
01132 short contextStackIndex;
01133 #endif
01134
01135 IMG_Raster *iconImage;
01136 RE_IconLoader iconLoader;
01137
01138 RE_CMMatrix projectionStack[PROJECTION_STACK_SIZE];
01139 float lineWidthStack[PATTERN_STACK_SIZE];
01140 unsigned short lineStyleStack[PATTERN_STACK_SIZE];
01141 short patternStack[PATTERN_STACK_SIZE];
01142 RE_ColorStack colorStack[RE_COLOR_STACK_SIZE];
01143 float pointSizeStack[PATTERN_STACK_SIZE];
01144 float myGLColor[4];
01145
01146 static bool theSmoothLinesAllowed;
01147 bool myForceSmoothLines;
01148 short mySmoothingLines;
01149 short myActuallySmoothingLines;
01150
01151 short myOverlaySupported;
01152
01153 bool myInObjectDefine;
01154 bool myTrackingObjectShaderUsage;
01155 bool myTrackingObjectTextureUsage;
01156 bool myProjectingTexture;
01157
01158 UT_RefArray<RE_LightVal> myLightArray;
01159 int * myLightStates;
01160 RE_Uniform *myLightEnabledUniform;
01161 unsigned myNumLightStates;
01162 bool myNormalizeGlobalAmbient;
01163 unsigned myLightModelSet:1,
01164 myUseOGLSpots:1,
01165 myAllowLightSpecular:1,
01166 myFirstInitialize:1;
01167
01168 RE_StateInfo stateInfo;
01169
01170 short projectionIndex;
01171 short lineWidthIndex;
01172 short lineStyleIndex;
01173 short patternIndex;
01174 short colorStackIndex;
01175 short pointSizeIndex;
01176
01177 float myXZoom;
01178 float myYZoom;
01179
01180 float zNear, zFar;
01181
01182 static short theXRes;
01183 static short theYRes;
01184 static short theVirtualX;
01185 static short theVirtualY;
01186 static short theDotsPerInch;
01187
01188 short currentDisplayMode;
01189 short currentDrawingMode;
01190 short currentMapSize;
01191
01192 short overlayMode;
01193 short fullScreenOverlayActive;
01194
01195 float pickLeft;
01196 float pickRight;
01197 float pickBottom;
01198 float pickTop;
01199
01200 UT_Bool isRGBmode;
01201
01202 static RE_Server *theServer;
01203
01204 RE_OGLContext pushedGraphicsContext;
01205
01206 #if ! RE_OGL_SINGLE_CONTEXT
01207 RE_OGLContext myContext;
01208 bool myContextInitialized;
01209 OGLDrawable myDrawable;
01210 OGLDrawable myPushedDrawable;
01211
01212 UT_SpinLock myOpenGLLock;
01213 int myOpenGLContextLockCount;
01214 #endif
01215
01216 static UT_Pointers theVisuals;
01217
01218 #ifndef CELLBE
01219 GLUquadricObj *filledQuadric();
01220 GLUquadricObj *unfilledQuadric();
01221 GLUquadricObj *myFilledQuadric, *myUnfilledQuadric;
01222 #endif
01223 float wPosX, wPosY, wPosZ;
01224
01225 short *scanline;
01226 short scanlength;
01227
01228 char scissorEnabled;
01229
01230 #ifndef CELLBE
01231 RE_Tesselator *tesselator;
01232 #endif
01233 float rx, ry, rz;
01234 int myViewportFontOffsetX, myViewportFontOffsetY;
01235
01236 uint *pickBuffer;
01237 uint *realPickBuffer;
01238 long pickBufferSize;
01239
01240 RE_Window *currentWindow;
01241 RE_Window *mySavedMainThreadCurrentWindow;
01242 static RE_WindowList *theWindowList;
01243 static RE_Window *theMainContextWindow;
01244
01245 int currGLError;
01246
01247 void initRasterCopy();
01248 void initGLExtensions();
01249 public:
01250 int hasGLExtension( RE_Extension ext ) const;
01251 private:
01252
01253
01254
01255 static int majorGLVersion;
01256 static int minorGLVersion;
01257
01258 static bool initGLVersionInfo();
01259
01260 int drawPixelsMode;
01261
01262
01263
01264
01265
01266 void getState();
01267
01268 public:
01269
01270 #define RE_FLAG_STATE(RE_NAME,GL_FLAG) \
01271 GLint _##RE_NAME ; \
01272 void enable##RE_NAME () { if( !_##RE_NAME ) { ::glEnable( GL_FLAG ); _##RE_NAME = GL_TRUE; } } \
01273 void disable##RE_NAME () { if( _##RE_NAME ) { ::glDisable( GL_FLAG ); _##RE_NAME = GL_FALSE; } } \
01274 int get##RE_NAME () const { return _##RE_NAME ; } \
01275 void set##RE_NAME () { _##RE_NAME = ::glIsEnabled( GL_FLAG ); }
01276
01277 RE_FLAG_STATE(ColorMaterial,GL_COLOR_MATERIAL);
01278 RE_FLAG_STATE(DepthCueing,GL_FOG);
01279 RE_FLAG_STATE(DepthTest,GL_DEPTH_TEST);
01280 RE_FLAG_STATE(Dither,GL_DITHER);
01281 RE_FLAG_STATE(Lighting,GL_LIGHTING);
01282 RE_FLAG_STATE(Scissor,GL_SCISSOR_TEST);
01283 RE_FLAG_STATE(Blending,GL_BLEND);
01284 RE_FLAG_STATE(AlphaTest,GL_ALPHA_TEST);
01285 RE_FLAG_STATE(LineSmoothing,GL_LINE_SMOOTH);
01286 RE_FLAG_STATE(PointSmoothing,GL_POINT_SMOOTH);
01287 RE_FLAG_STATE(Stencil,GL_STENCIL_TEST);
01288 #undef RE_FLAG_STATE
01289
01290 #define RE_FLAG_11_STATE(RE_NAME,GL_FLAG) \
01291 GLint _##RE_NAME ; \
01292 void enable##RE_NAME () { if( (!_##RE_NAME) && hasGL11() ) { ::glEnable( GLenum(GL_FLAG) ); _##RE_NAME = GL_TRUE; } } \
01293 void disable##RE_NAME () { if( _##RE_NAME && hasGL11() ) { ::glDisable( GLenum(GL_FLAG) ); _##RE_NAME = GL_FALSE; } } \
01294 int get##RE_NAME () const { return _##RE_NAME ; } \
01295 void set##RE_NAME () { if( hasGL11() ) { _##RE_NAME = ::glIsEnabled( GLenum(GL_FLAG) ); } else { _##RE_NAME = GL_FALSE; } }
01296
01297 RE_FLAG_11_STATE(PointOffset,GL_POLYGON_OFFSET_POINT);
01298 RE_FLAG_11_STATE(LineOffset,GL_POLYGON_OFFSET_LINE);
01299 RE_FLAG_11_STATE(FillOffset,GL_POLYGON_OFFSET_FILL);
01300 #undef RE_FLAG_11_STATE
01301
01302 void updateBlendState();
01303 void updateSmoothState();
01304 private:
01305 RE_RenderBuf drawBuffer;
01306
01307 GLint _matrixMode;
01308 GLint getOGLMatrixMode() { return _matrixMode; }
01309 void setOGLMatrixMode( GLint mode ) { if( _matrixMode != mode ) { ::glMatrixMode( GLenum(mode) ); _matrixMode = mode; } }
01310
01311 GLint maxClipPlanes;
01312 GLint getOGLMaxClipPlanes() { return maxClipPlanes; }
01313 void setOGLMaxClipPlanes() { ::glGetIntegerv( GL_MAX_CLIP_PLANES, &maxClipPlanes ); }
01314
01315 unsigned int getShadowFrameBuffer(GLuint &shadowtx);
01316
01317 private:
01318 UT_Bool _colorBufferWriting;
01319 UT_Bool _depthBufferWriting;
01320
01321 public:
01322
01323
01324
01325
01326
01327 void enableColorBufferWriting();
01328 void disableColorBufferWriting();
01329 UT_Bool getColorBufferWriting();
01330 void setColorBufferWriting();
01331
01332
01333
01334
01335
01336 void enableDepthBufferWriting();
01337 void disableDepthBufferWriting();
01338 UT_Bool getDepthBufferWriting();
01339 void setDepthBufferWriting();
01340
01341 void updateStacks();
01342
01343
01344
01345
01346
01347
01348 struct RE_OGLBox {
01349 GLint v[4];
01350
01351 GLint x() const { return v[0]; }
01352 GLint y() const { return v[1]; }
01353 GLint width() const { return v[2]; }
01354 GLint height() const { return v[3]; }
01355
01356 void x( GLint _x ) { v[0] = _x; }
01357 void y( GLint _y ) { v[1] = _y; }
01358 void width( GLint _w ) { v[2] = _w; }
01359 void height( GLint _h ) { v[3] = _h; }
01360
01361 GLint left() const { return v[0]; }
01362 GLint bottom() const { return v[1]; }
01363 GLint right() const { return left() + width() - 1; }
01364 GLint top() const { return bottom() + height() - 1; }
01365
01366 void leftRight( GLint l, GLint r) { v[0] = l; width( r - l + 1 ); }
01367 void bottomTop( GLint b, GLint t) { v[1] = b; height( t - b + 1 ); }
01368
01369 } scissorState, viewportState;
01370
01371 int viewportStateValid;
01372 int scissorStateValid;
01373
01374 void getViewport();
01375
01376
01377 unsigned lightingOn:2;
01378
01379
01380 void preDrawPixels( int allowDither = TRUE );
01381 void postDrawPixels();
01382
01383
01384
01385
01386 int beginBegun;
01387
01388
01389 RE_OGLVertex *myVtxOut;
01390
01391
01392
01393
01394 UT_RGBA *drScanline;
01395 int drScanlineWidth;
01396 int enabled;
01397
01398 short cacheIndex;
01399 short avoidCacheCount;
01400 int myFloatZoomSupported;
01401
01402 float myDefaultStacklessColor[4];
01403
01404
01405 int myActiveTexture;
01406 int myTexture2DFlags, myTexture3DFlags, myTextureCubeMapFlags;
01407 int myTextureMode[32];
01408 int myMaxTextureUnits;
01409 int myMaxTextureSize;
01410
01411 int myShadowMapSize;
01412
01413 bool myCompactPick;
01414
01415 RE_OGLExt * myExt;
01416
01417
01418 ut_thread_id_t myNativeThread;
01419
01420
01421 int myBlendLevel;
01422 re_BlendState myBlendStack[RE_BLEND_STACK_SIZE];
01423
01424
01425 int mySmoothLevel;
01426 re_SmoothState mySmoothStack[RE_SMOOTH_STACK_SIZE];
01427
01428
01429 int myStencilLevel;
01430 re_StencilState myStencilStack[RE_STENCIL_STACK_SIZE];
01431
01432
01433
01434 static UT_RefArray<UT_DimRect> theScreens;
01435 static UT_RefArray<UT_DimRect> theWorkAreas;
01436
01437 bool myFrontBufferDirty;
01438 int myXORDrawCount;
01439
01440 bool myMultisampleEnable;
01441 bool myIsAllowingOtherThreads;
01442
01443
01444 const RE_Uniform *myBuiltInUniforms[RE_UNIFORM_BUILT_IN__count];
01445
01446
01447 static RE_GraphicsDevice theDevice;
01448 static int theDriverMajor;
01449 static int theDriverMinor;
01450 static int theDriverBuild;
01451
01452 static bool theHasShadersExt;
01453 static bool theFastDisplayRasterHack;
01454
01455 static UT_ThreadSpecificValue <RE_OGLRender*> theCurrentRender;
01456 #if ! RE_OGL_SINGLE_CONTEXT
01457 static UT_ThreadSpecificValue <RE_OGLRender*> theLastRender;
01458 #endif
01459 };
01460
01461 class RE_API RE_RenderAutoLock
01462 {
01463 public:
01464 RE_RenderAutoLock(RE_OGLRender *r)
01465 : myR(r)
01466 { myR->lockContextForRender(); }
01467
01468 ~RE_RenderAutoLock()
01469 { myR->unlockContextAfterRender(); }
01470 private:
01471 RE_OGLRender *myR;
01472 };
01473
01474
01475 #endif