00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __RE_OGLRender__
00044 #define __RE_OGLRender__
00045
00046 #include "RE_API.h"
00047
00048 #include <SYS/SYS_Math.h>
00049 #include <tools/prisms.h>
00050
00051 #include <UT/UT_Defines.h>
00052 #include <UT/UT_Pointers.h>
00053 #include <UT/UT_PtrArray.h>
00054 #include <UT/UT_RefArray.h>
00055 #include <UT/UT_Color.h>
00056 #include <UT/UT_Floor.h>
00057 #include <UT/UT_IntArray.h>
00058 #include <UT/UT_Rect.h>
00059 #include <UT/UT_RefArray.h>
00060 #include <UT/UT_Thread.h>
00061 #include <UT/UT_ThreadSpecificValue.h>
00062 #include <UT/UT_SpinLock.h>
00063
00064 #include <TIL/TIL_Defines.h>
00065
00066 #include <UT/UT_VectorTypes.h>
00067 class UT_RGBA;
00068 class UT_WorkBuffer;
00069 class RE_Light;
00070 class IMG_Raster;
00071 class TIL_Raster;
00072 class PXL_Raster;
00073 class PXL_Lookup;
00074
00075 class RE_Cursor;
00076 class RE_Font;
00077 class RE_OGLFramebuffer;
00078 class RE_Material;
00079 class RE_OGLMaterial;
00080 class RE_OGLTexture2DMap;
00081 class RE_OGLTexture;
00082 class RE_Server;
00083 class RE_Uniform;
00084 class RE_Visual;
00085 class RE_Window;
00086 class RE_WindowList;
00087 class RE_OGLFramebuffer;
00088 class RE_GeometryObject;
00089 class RE_OcclusionQuery;
00090
00091 class RE_Tesselator;
00092 class RE_OGLExt;
00093 class RE_Shader;
00094 class RE_Render;
00095 class RE_SmartObject;
00096 class re_UniformEntry;
00097
00098 #include "RE_OGLState.h"
00099 #include "RE_OGLDisplayList.h"
00100 #include "RE_Extension.h"
00101 #include "RE_LightVal.h"
00102 #include "RE_OGLVertex.h"
00103 #include "RE_Uniform.h"
00104
00105 typedef RE_OGLDisplayList RE_CacheObject;
00106
00107 #define OPEN_GL
00108
00109
00110
00111 class RE_API RE_OGLRender
00112 {
00113 public:
00114 RE_OGLRender(int do_foreground, const char *appname = 0);
00115 virtual ~RE_OGLRender();
00116
00117 const char *className() const;
00118 static void initialize();
00119 bool isInitialized() const { return !myFirstInitialize; }
00120
00121
00122 virtual RE_Render *getRender() = 0;
00123
00124
00125
00126
00127
00128 static bool hasGL11();
00129 static bool hasGL12();
00130 static bool hasGL13();
00131 static bool hasGL14();
00132 static bool hasGL15();
00133 static bool hasGL20();
00134 static bool hasGL21();
00135 static int glMajorVersion();
00136 static int glMinorVersion();
00137
00138
00139 int glslMajorVersion();
00140 int glslMinorVersion();
00141
00142 int hasGLExtension(RE_Extension e) const;
00143
00144
00145 static bool hasShadersExt();
00146 static void disableShadersExt();
00147
00148
00149
00150
00151
00152
00153 static RE_GraphicsDevice getGraphicsDevice();
00154
00155
00156 static bool hasDriverVersion();
00157 static int getDriverMajorVersion();
00158 static int getDriverMinorVersion();
00159 static int getDriverBuildVersion();
00160 void getDriverInfo(UT_WorkBuffer &info);
00161
00162
00163
00164 RE_OGLExt *getExt() const;
00165
00166
00167
00168
00169 int64 getFreeTextureMemoryKB(int64 *largest_chunk = NULL);
00170 int64 getFreeBufferMemoryKB(int64 *largest_chunk = NULL);
00171 int64 getFreeFramebufferMemoryKB(int64 *largest_chunk = NULL);
00172
00173
00174 static int64 getInitialFreeMemoryKB();
00175
00176
00177
00178
00179
00180 static int resX();
00181 static int resY();
00182 static int virtualResX();
00183 static int virtualResY();
00184
00185 static void updateScreenSize();
00186
00187
00188
00189 static int getNumScreens();
00190 static UT_DimRect getScreen(int i);
00191 static UT_DimRect getWorkArea(int i);
00192 static int getScreenContaining(int x, int y,
00193 bool closest_if_none = false);
00194
00195 static bool areScreensUniform();
00196
00197
00198 static UT_DimRect getWorkAreaForScreen(UT_DimRect area);
00199
00200
00201 static UT_DimRect getTotalScreenArea();
00202 static UT_DimRect getTotalWorkArea();
00203 static void updateScreensAndWorkAreas();
00204
00205
00206
00207
00208
00209 static int positionOnScreen(UT_DimRect &area,
00210 int screen_hint=-1);
00211
00212
00213 static bool positionOkay(const UT_DimRect &area) ;
00214
00215 static short dpi();
00216 static float pixelsToInches(int n);
00217 static int inchesToPixels(float i);
00218 static void scaleDPI(fpreal dpi);
00219
00220
00221
00222
00223 RE_DisplayMode getMode() const;
00224 RE_VisualType getVisualType() const;
00225
00226 void enableMultisample(bool enable);
00227 bool isMultisampleEnabled() const;
00228
00229 void getMaxViewportSize(int &w, int &h) const;
00230
00231 static RE_Visual *getVisualForMode(RE_DisplayMode newmode);
00232 static RE_Server *getServer();
00233 static RE_Cursor *getCursor(const char *name);
00234
00235 #if RE_OGL_SINGLE_CONTEXT
00236 void setContext(RE_IDType wid, int force = 0);
00237 void setContext(RE_Window *, int force = 0);
00238 void pushContext(RE_IDType wid);
00239 void pushContext(RE_Window *);
00240 void popContext();
00241
00242 RE_IDType getContextID() const;
00243 bool contextIsValid() { return 0 != getContextID(); }
00244 #else
00245 void setWindow(RE_Window *);
00246
00247 bool makeCurrent();
00248 bool isCurrent() { return theCurrentRender.get() == this; }
00249 static void resetCurrent();
00250 bool contextIsValid() { return (bool)myContext; }
00251 RE_OGLContext getContext() const { return myContext; }
00252
00253
00254
00255 bool pushOffscreenBuffer(OGLDrawable type);
00256 void popOffscreenBuffer();
00257 #endif
00258
00259
00260 void setMainContext(RE_Window *w);
00261 static RE_Window *getMainContext();
00262
00263 static RE_OGLRender *getCurrentRender();
00264 static RE_WindowList *getWindowList();
00265 const RE_Window *getCurrentWindow() const;
00266 RE_Window *getCurrentWindow();
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 void lockContextForRender();
00288 void unlockContextAfterRender();
00289 bool tryLockContextForRender();
00290 bool isContextLocked() const;
00291
00292
00293 void setIconLoader(RE_IDType wid, RE_IconLoader loader);
00294 void clearIconLoader(RE_IDType wid);
00295
00296 void setIconLoader(RE_IconLoader loader);
00297
00298 void setIconImage(const char *filename);
00299
00300
00301
00302 int getGLError();
00303 int getNextGLError();
00304 void clearGLErrors();
00305 const char *getGLErrorString( int error );
00306 void printGLError(const char *header,
00307 bool assert = false );
00308 void printAllGLErrors( const char *header,
00309 bool assert = false );
00310
00311 void dumpState(bool extended_info = true) const;
00312 void dumpTextureState() const;
00313 void dumpLightState() const;
00314 void verifyState();
00315
00316
00317
00318
00319
00320
00321
00322 int pushDrawFramebuffer();
00323 int pushDrawFramebuffer(RE_OGLFramebuffer *fb);
00324 void setDrawFramebuffer(RE_OGLFramebuffer *fb);
00325 RE_OGLFramebuffer *getDrawFramebuffer();
00326 void popDrawFramebuffer(int *nest = NULL);
00327
00328 int pushReadFramebuffer();
00329 int pushReadFramebuffer(RE_OGLFramebuffer *fb);
00330 void setReadFramebuffer(RE_OGLFramebuffer *fb);
00331 RE_OGLFramebuffer *getReadFramebuffer();
00332 void popReadFramebuffer(int *nest = NULL);
00333
00334
00335 void updateFramebuffer();
00336
00337 void updateCurrentFramebuffer(RE_OGLFramebuffer *fb,
00338 bool for_draw);
00339
00340
00341
00342
00343
00344
00345 void clear();
00346 void clearZ(float z = 1.0);
00347 void clearCZ(float z = 1.0);
00348 void clearS();
00349
00350
00351
00352
00353
00354
00355
00356 void enableColorBufferWriting();
00357 void disableColorBufferWriting();
00358 bool getColorBufferWriting();
00359 void updateColorBufferWriting();
00360
00361
00362
00363
00364
00365 void enableDepthBufferWriting();
00366 void disableDepthBufferWriting();
00367 bool getDepthBufferWriting();
00368 void updateDepthBufferWriting();
00369
00370 int enableZbuffer(int state, int clear_it);
00371 void swapbuffers();
00372
00373
00374 int pushDrawBuffer( RE_RenderBuf buf = RE_BUFFER_UNINIT);
00375 void popDrawBuffer(int *nest = 0);
00376 void setDrawBuffer( RE_RenderBuf buf );
00377 RE_RenderBuf getDrawBuffer();
00378
00379 int pushReadBuffer( RE_RenderBuf buf = RE_BUFFER_UNINIT);
00380 void popReadBuffer(int *nest = 0);
00381 void setReadBuffer( RE_RenderBuf buf );
00382 RE_RenderBuf getReadBuffer();
00383
00384
00385
00386
00387 bool isFrontBufferDirty() const;
00388 void setFrontBufferDirty(bool d);
00389
00390 void flush(int wait=0) const;
00391 void waitForRetrace() const;
00392
00393
00394
00395 void ortho2DW(float l, float r, float b, float t);
00396 void ortho3DW(float l, float r, float b, float t, float n,float f);
00397
00398 void perspective(float fov_radians, float a, float n, float f);
00399 void window3DW( float l, float r, float b, float t,
00400 float near, float far );
00401 int mapWorld( float xs, float xy,
00402 float *x1, float *y1, float *z1,
00403 float *x2, float *y2, float *z2 );
00404 int mapWorld( float xs, float ys,
00405 const UT_DimRect &viewport,
00406 const UT_Matrix4 &proj,
00407 const UT_Matrix4 &view,
00408 float *x1, float *y1, float *z1,
00409 float *x2, float *y2, float *z2);
00410 int mapScreen( float xw, float yw, float zw,
00411 float *xs, float *ys );
00412 int mapScreen(float xw, float yw, float zw,
00413 const UT_DimRect &viewport,
00414 const UT_Matrix4 &proj,
00415 const UT_Matrix4 &view,
00416 float *xs, float *ys);
00417
00418
00419 void viewport2DI(const UT_DimRect &rect);
00420 void screenMask2DI(const UT_DimRect &rect);
00421 void disableScreenMask();
00422 void intersectMask2DI(const UT_DimRect &rect);
00423 UT_DimRect getScreenMask2DI();
00424 UT_DimRect getViewport2DI();
00425 bool getViewportMaskActive() const;
00426
00427
00428 void orthoFromViewport2DI(const UT_DimRect &viewport)
00429 {
00430 ortho2DW(viewport.x1(), viewport.x2e(),
00431 viewport.y1(), viewport.y2e());
00432 }
00433
00434
00435 void viewportOrtho2DI(const UT_DimRect &rect)
00436 { viewport2DI(rect); orthoFromViewport2DI(rect); }
00437
00438
00439 void clipPlane(int which, int onoff, const UT_Vector4 *parms = 0);
00440 int getOGLMaxClipPlanes();
00441
00442
00443 void setActiveOcclusionQuery(RE_OcclusionQuery *q);
00444 RE_OcclusionQuery *getActiveOcclusionQuery() const;
00445
00446
00447 int isBackface();
00448 void setBackface(int removeBackface = 0);
00449 int getReverseWinding();
00450 void setReverseWinding(int reverse_winding);
00451
00452
00453 bool isPointOffset();
00454 bool isLineOffset();
00455 bool isPolygonOffset();
00456 void pointOffset( bool onoff );
00457 void lineOffset( bool onoff );
00458 void polygonOffset( bool onoff );
00459 void setOffsetAmount( float variable, float constant );
00460 void getOffsetAmount( float* variable, float* constant );
00461
00462
00463
00464 void pushViewport();
00465 void popViewport();
00466
00467
00468 void pushState(int viewing);
00469 void popState();
00470
00471 void matrixMode(RE_MatrixMode mode);
00472 RE_MatrixMode getMatrixMode();
00473
00474 void pushMatrix(int update_projection=1);
00475 void popMatrix(int update_projection=1);
00476
00477 void loadIdentityMatrix();
00478 void loadMatrix(const UT_Matrix4 &m);
00479 void loadMatrix(const UT_DMatrix4 &m);
00480
00481 void getMatrix(UT_Matrix4 &m);
00482 void getAMatrix(RE_MatrixMode mmode, UT_Matrix4 &m);
00483 void getAMatrix(RE_MatrixMode mmode, UT_DMatrix4 &m);
00484
00485 void multiplyMatrix(const UT_Matrix4 &m);
00486 void multiplyMatrix(const UT_DMatrix4 &m);
00487
00488 void translate(float x, float y, float z = 0.0);
00489 void scale(float x = 1.0, float y = 1.0, float z = 1.0);
00490 void rotate(float angle, char axis);
00491
00492
00493
00494 void setColor(const UT_Color &c, float alpha=1.0);
00495 void setColor(float r, float g, float b, float a);
00496 void setColorMask(bool red, bool green, bool blue, bool alpha);
00497 void getColorMask(bool &red, bool &green, bool &blue, bool &alpha);
00498 void getColor(UT_Color &c) const;
00499 void setAlpha(float alpha);
00500 float getAlpha() const;
00501 int pushColor();
00502 void popColor(int *nest = NULL);
00503 int pushColor(const UT_Color &c, float alpha=1.0f);
00504 void resetColorCache();
00505
00506
00507
00508 int pushPattern(RE_FillPattern p);
00509 void popPattern(int *nest = NULL);
00510
00511 int pushLineStyle(RE_LineStyle s);
00512 void popLineStyle(int *nest = NULL);
00513
00514 int pushLineWidth(float w);
00515 void popLineWidth(int *nest = NULL);
00516 float getLineWidth() const;
00517 float getMaxSmoothLineWidth();
00518
00519 int pushPointSize(float size);
00520 void popPointSize(int *nest = NULL);
00521 void setPointSize(float size);
00522
00523
00524
00525
00526 void setZFunction(RE_ZFunction func);
00527 RE_ZFunction getZFunction() const;
00528 int isZbuffer();
00529 void updateZFunction() const;
00530
00531 void enableDepthClamp(bool b);
00532 bool getDepthClamp() const;
00533
00534 int pushStencilState();
00535 void popStencilState(int *nest = NULL);
00536 void setSClearValue(int clearValue);
00537 void setSWriteMask(int writeMask);
00538 void setSFunction(RE_SFunction func, int ref, int mask);
00539 void setSOperation(RE_SOperation sfail,
00540 RE_SOperation dpfail,
00541 RE_SOperation dppass);
00542 void updateStencilState();
00543 void resetSFunction();
00544 void resetSWriteMask();
00545 void resetSClearValue();
00546 void resetSOperation();
00547
00548 void enableLogicOp();
00549 void disableLogicOp();
00550 void invertPixels();
00551 void xorPixels();
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561 void beginXORDraw(RE_CacheObject *&id);
00562 void endXORDraw (RE_CacheObject *&id);
00563 void clearXORDraw(RE_CacheObject *&id);
00564 void resetXORDraw(RE_CacheObject *&id);
00565
00566
00567
00568
00569
00570 int pushBlendState();
00571 void popBlendState(int *nesting = 0);
00572
00573 bool isBlending() const;
00574 void blend(int onoff);
00575 void setBlendFunction(RE_BlendSourceFactor sourceFactor,
00576 RE_BlendDestFactor destFactor);
00577 bool setAlphaBlendFunction(RE_BlendSourceFactor sourceFactor,
00578 RE_BlendDestFactor destFactor,
00579 bool force = false);
00580 void getBlendFunction(RE_BlendSourceFactor* sourceFactor,
00581 RE_BlendDestFactor* destFactor);
00582 void getAlphaBlendFunction(RE_BlendSourceFactor *sourceFactor,
00583 RE_BlendDestFactor *destFactor);
00584
00585
00586
00587 void blendAlpha(int onoff, int usezbuffer=0);
00588 void blendAlphaPremult(bool onoff, int usezbuffer=0);
00589
00590 void alphaTest(int onoff);
00591 void setAlphaTestFunction(RE_ZFunction func, float val);
00592
00593 int pushSmoothLines();
00594 void popSmoothLines(int *nesting = 0);
00595 void forceSmooth();
00596 void smoothBlendLines(RE_SmoothMode mode);
00597 void smoothBlendLinesNoFlagChange(bool by_smooth);
00598 RE_SmoothMode getSmoothLines();
00599
00600 int getBlendSmoothLevel() const;
00601
00602 static void allowSmoothLines(int yn);
00603 static int allowsSmoothLines();
00604
00605 static int getGLBlendSource(RE_BlendSourceFactor sourceFactor);
00606 static int getGLBlendDest(RE_BlendDestFactor destFactor);
00607
00608
00609
00610 RE_CacheObject *startObjectDefine();
00611 void endObjectDefine(bool push_attribs = true);
00612 void deleteObject(RE_CacheObject *obj);
00613 void drawObject(RE_CacheObject *obj);
00614
00615 int useDisplayLists();
00616 int isCaching() const;
00617 void insertGeometryIntoCache(RE_GeometryObject *obj,
00618 const char *gname);
00619 void insertReferenceIntoCache(RE_GeometryObject *obj);
00620
00621
00622
00623
00624
00625
00626
00627
00628 RE_SmartObject *startSmartObjectDefine();
00629 bool endSmartObjectDefine(bool push_attribs = true);
00630 void deleteSmartObject(RE_SmartObject *obj);
00631 bool isSmartObjectDirty(RE_SmartObject *obj);
00632
00633 bool inObjectDefine() const;
00634 bool trackingObjectShaderUsage() const;
00635 bool trackingObjectTextureUsage() const;
00636
00637
00638 const UT_IntArray *getShadersUsedBySmartObject(RE_SmartObject *obj);
00639
00640
00641
00642
00643
00644
00645 static bool notifySmartObjectsOfShaderDeletion( int shader_idx );
00646 static bool notifySmartObjectsOfTextureDeletion( int texture_idx );
00647
00648
00649
00650 void deletePendingShadersFromSmartObjectCreation();
00651 void deletePendingTexturesFromSmartObjectCreation();
00652
00653
00654
00655 void recordShaderForSmartObject( int shader_idx );
00656
00657
00658 void recordTextureForSmartObject( int texture_idx );
00659
00660
00661
00662
00663
00664 void clearAllMaterials();
00665 void clearAllTextures();
00666
00667
00668
00669 void setMaterial(RE_Material &mat, int layer=0, bool texture=true);
00670 int pushMaterial(RE_Material *mat, int layer=0, bool texture=true);
00671 void popMaterial(int *nest = NULL);
00672
00673
00674
00675
00676 void pushMaterialDiffuse();
00677 void popMaterialDiffuse();
00678
00679
00680
00681
00682
00683 void setDiffuseMaterialFromMaterialStack();
00684
00685
00686 RE_Material *getDefaultMaterial();
00687
00688
00689 bool assignDefaultShader(RE_OGLMaterial *mat, int layer=0,
00690 bool textured = true);
00691 RE_Shader *getDefaultShader();
00692
00693
00694
00695 int pushShader();
00696 int pushShader(RE_Shader *s);
00697 void bindShader(RE_Shader *s);
00698 RE_Shader *getShader();
00699 void popShader(int *nest = NULL);
00700
00701 void updateShader(RE_Shader *s);
00702
00703
00704
00705
00706 void setUniform(RE_UniformBuiltIn builtin_var_type,
00707 RE_Uniform *var, bool owned);
00708 RE_Uniform *getUniform(RE_UniformBuiltIn builtin_var_type,
00709 bool &owned);
00710
00711
00712
00713 void printBuiltinUniforms(bool bound_only);
00714
00715 int pushUniform(RE_UniformBuiltIn builtin_var_type);
00716 void popUniform(int *level = NULL);
00717
00718
00719 void bindBuiltInUniforms(RE_Shader *s,
00720 RE_UniformBinding bind);
00721
00722
00723
00724
00725
00726 void enableTexture(RE_TextureDimension t,
00727 int textureunit = RE_ACTIVE_UNIT);
00728 void disableTexture(int textureunit = RE_ACTIVE_UNIT);
00729 bool isTextureEnabled(RE_TextureDimension t,
00730 int textureunit = RE_ACTIVE_UNIT) const;
00731
00732
00733
00734
00735
00736 void bindTexture(RE_OGLTexture *tex,
00737 int unit = RE_ACTIVE_UNIT,
00738 RE_TextureMode mode = RE_TEXTURE_UNKNOWN);
00739
00740 void unbindTexture(RE_OGLTexture *tex);
00741
00742
00743
00744 void setActiveTexture(int textureunit);
00745 int getActiveTexture() const;
00746
00747
00748 void setTextureMode(RE_TextureMode mode,
00749 int textureunit = RE_ACTIVE_UNIT);
00750 RE_TextureMode getTextureMode(int textureunit = RE_ACTIVE_UNIT) const;
00751
00752
00753
00754
00755
00756
00757 int pushTextureState(int textureunit = RE_ACTIVE_UNIT);
00758 void popTextureState(int *nest = NULL);
00759
00760
00761
00762 RE_TextureDimension getBoundTextureType(int texunit = RE_ACTIVE_UNIT) const;
00763 RE_OGLTexture *getBoundTexture(int texunit = RE_ACTIVE_UNIT) const;
00764
00765
00766
00767 void disableAllTextures();
00768
00769
00770 void updateTextureState() const;
00771
00772
00773 int getMaxTextureUnits() const
00774 { return myMaxTextureUnits; }
00775 int getMaxTextureCoords() const
00776 { return myMaxTextureCoords; }
00777 int getMaxShaderTextureUnits() const
00778 { return myMaxTextureShaderUnits; }
00779 int getMaxVertexTextureUnits() const
00780 { return myMaxTextureVertexUnits; }
00781 int getMaxFragmentTextureUnits() const
00782 { return myMaxTextureFragmentUnits; }
00783 int getTextureAnisotropyLimit() const
00784 { return myMaxTextureAnisotropy; }
00785
00786
00787
00788 int getMaxTextureSize() const { return myMaxTextureSize; }
00789 int getMaxTexture3DSize() const { return myMaxTexture3DSize; }
00790 int getMaxTextureRectangleSize();
00791
00792
00793
00794 int pushReadAlignment(const void *data, int scansize);
00795 void popReadAlignment(int *nest = NULL);
00796
00797 int pushWriteAlignment(const void *data, int scansize);
00798 void popWriteAlignment(int *nest = NULL);
00799
00800
00801 void useSeamlessMaps(bool enable);
00802 bool usingSeamlessMaps();
00803
00804
00805
00806
00807
00808
00809
00810 static int computeTextureRes(unsigned int res);
00811
00812 void removeTextureRefs(RE_OGLTexture *tex);
00813
00814
00815
00816
00817
00818
00819
00820 RE_OGLTexture *getRandomTexture(unsigned int seed, bool interp,
00821 int size = 64,
00822 bool owned = false);
00823
00824
00825
00826 void setLightModel(int local_viewer, int two_sided_lighting);
00827
00828
00829
00830 unsigned defineLight(const RE_Light &light, int light_flags = 0);
00831
00832 #if ! RE_OGL_SINGLE_CONTEXT
00833 bool isLightDefined(const RE_Light &light) const;
00834 void deNormalizeLightDefinition(const RE_Light &light);
00835 void setLightState(const RE_Light &light, int onoff);
00836 #endif
00837
00838 int whichGLLightIs(const RE_Light *light);
00839
00840 void deNormalizeLightDefinition(unsigned index);
00841 void undefineLight(unsigned index);
00842 void undefineAllLights();
00843 void setLightState(unsigned index, int onoff);
00844 bool getLightState(unsigned index);
00845 void allLightsOff();
00846 RE_Light *getLight(int index);
00847 int getNumLights();
00848 int getMaxLights() const;
00849 void setGLSpots(int f);
00850 void setAllowSpecular(int f);
00851 int getAllowSpecular() const;
00852 RE_Uniform *getLightEnabledUniform() const;
00853 void setNormalizeGlobalAmbient(bool normalize);
00854 bool getNormalizeGlobalAmbient() const;
00855
00856 RE_InterpMode getInterpMode();
00857 void interpMode(RE_InterpMode mode);
00858
00859
00860
00861
00862
00863
00864 void toggleLighting(int onoff);
00865 void toggleLightShading(int onoff);
00866
00867
00868 void setNonLitColor(const UT_Color &col);
00869
00870
00871
00872 void useProjectiveTexture(bool ison, RE_Light *light,
00873 RE_TextureCompress format,
00874 bool limitres, int maxw, int maxh,
00875 float texturescale,
00876 bool mipmap, int aniso_samples);
00877
00878
00879
00880 void getProjectiveTextureTransform(const RE_Light *light,
00881 bool bias, UT_Matrix4 &mat);
00882
00883
00884 void depthCueing(int state, int usegreyramp = 0);
00885
00886 void enableFog(int type, float density,
00887 float nearf, float farf,
00888 const float *col, float alpha);
00889 void disableFog();
00890 void useFogCoord(bool onoff);
00891
00892
00893
00894
00895 void fogCoord(const float z);
00896
00897
00898
00899
00900 void beginPicking(uint *buf, long bufsiz, short x, short y,
00901 short w, short h );
00902 long endPicking(uint *buf);
00903 int isPicking() const;
00904 void loadPickId(uint id);
00905 void pushPickId(uint id);
00906 void popPickId();
00907
00908 void scaleViewForPick(float *l, float *r, float *b, float *t);
00909
00910
00911
00912
00913 void zoomRaster(float xzoom, float yzoom = -1);
00914 void getRasterZoom(float &xzoom, float &yzoom) const;
00915
00916 void displayRaster(float x, float y, short w, short h,
00917 IMG_Raster *r, float zoom = -1.0f,
00918 int dither = 1);
00919 void displayRaster(float x, float y, short w, short h,
00920 UT_RGBA *r, short stride,
00921 float zoom=-1.0f, int dither = 1);
00922 void displayRaster(float x, float y,
00923 const PXL_Raster *raster,
00924 const RE_RasterOpts *opts = 0);
00925 void displayRasterTexture(float x, float y,
00926 const PXL_Raster *raster,
00927 const RE_RasterOpts *opts = 0);
00928
00929 float getRasterX() const;
00930 float getRasterY() const;
00931 float getRasterZ() const;
00932
00933
00934 void convertRasterToTexture(PXL_Raster *raster,
00935 int convert16bit = 0);
00936 void convertLUTToTexture(PXL_Lookup *lookup);
00937 bool setupShaderForLUT(RE_Shader *shader,
00938 PXL_Lookup *lookup,
00939 int lut_texture_unit = 1,
00940 float gamma = 1.0f,
00941 bool add_shader = true);
00942 bool is3DLUTSupported();
00943
00944 int isFloatZoomSupported();
00945 int getMaxPixelMapSize();
00946 int isHalfFloatSupported();
00947
00948 void copyToFront(short x, short y, short w, short h);
00949 void copyToBack(short x, short y, short w, short h);
00950 void saveFront(short x, short y, short w, short h);
00951 void restoreFront(short x, short y, short w, short h);
00952
00953
00954
00955
00956
00957 void saveRaster(short x, short y, short w, short h,
00958 IMG_Raster *r, bool use_backbuf = true);
00959 TIL_Raster * saveRaster(short x, short y, short w, short h,
00960 PXL_DataFormat format, bool alphatoo,
00961 bool use_backbuf = true);
00962
00963 void setDrawPixelsMode(RE_DrawPixelsMode new_mode);
00964 RE_DrawPixelsMode getDrawPixelsMode();
00965
00966
00967
00968 void rect2DW (float x1, float y1, float x2, float y2);
00969 void rect2DS (short x1, short y1, short x2, short y2);
00970 void rectf2DW(float x1, float y1, float x2, float y2);
00971 void rectf2DS(short x1, short y1, short x2, short y2);
00972 void box2DS (short x1, short y1, short x2, short y2);
00973 void boxf2DS (short x1, short y1, short x2, short y2);
00974
00975 void arcW(float x, float y, float r, short a, short b);
00976 void arcS(short x, short y, short r, short a, short b);
00977 void arcfW(float x, float y, float r, short a, short b);
00978 void arcfS(short x, short y, short r, short a, short b);
00979
00980 void sectorS(short x, short y, short ir, short outer,
00981 float a, float b, int slices = 20, int loops = 1);
00982 void sectorW(float x, float y, float ir, float outer,
00983 float a, float b, int slices = 20, int loops = 1);
00984
00985
00986
00987
00988 void circlefS(short x, short y, short innerr, short outerr,
00989 int slices = 50);
00990 void circlefW(float x, float y, float innerr, float outerr,
00991 int slices = 50);
00992
00993
00994 void circlefS(short x, short y, short r, int slices = 50);
00995 void circlefW(float x, float y, float r, int slices = 50);
00996
00997
00998 void circleS (short x, short y, short r, int slices = 50);
00999 void circleW (float x, float y, float r, int slices = 50);
01000
01001 void sphereW(float x, float y, float z, float r, int divs = 20);
01002 void spherefW(float x, float y, float z, float r, int divs = 20);
01003
01004
01005
01006 void textMove3S(short x, short y, short z);
01007 void textMove3W(float x, float y, float z);
01008 void textMoveS(short x, short y);
01009 void textMoveW(float x, float y);
01010
01011
01012
01013
01014
01015
01016
01017 void setViewportFontOffset(int x, int y);
01018 int getViewportFontOffsetX() const;
01019 int getViewportFontOffsetY() const;
01020
01021
01022
01023
01024
01025 static RE_Font *internalGetFont(const char *name, float size);
01026
01027
01028
01029 static RE_Font *getViewportFont();
01030
01031
01032
01033 static RE_Font *getViewportSymbolFont(float size);
01034
01035 static void setDefaultFont(const char *name, float size);
01036
01037 void getTextPos(short *x, short *y);
01038
01039
01040
01041
01042 void *createNurbsObject (void);
01043 void destroyNurbsObject(void *nurbsobj);
01044 void beginNurbsSurface(void *nurbsobj);
01045 void endNurbsSurface (void *nurbsobj);
01046 void nurbsSurface(int uklen, float *uknots, int vklen,
01047 float *vknots, int nrows, float *cvs,
01048 int uorder, int vorder, int rational,
01049 void *nurbsobj);
01050 void beginTrimLoop(void *nurbsobj);
01051 void endTrimLoop (void *nurbsobj);
01052 void polyTrimCurve (int nvtx, float *cvs, void *nurbsobj);
01053 void nurbsTrimCurve(int uklen, float *uknots, int order,
01054 float *cvs, int rational, void *nurbsobj);
01055 void setNurbsProperties(int autonormal, float tol,
01056 void *nurbsobj = 0);
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077 void end();
01078
01079
01080
01081
01082 void beginPolygon(int concave);
01083 void endPolygon();
01084 void beginLine();
01085 void endLine();
01086 void beginLines();
01087 void endLines();
01088
01089
01090 void beginClosedLine();
01091 void endClosedLine();
01092 void beginPoint();
01093 void endPoint();
01094 void beginTriangles();
01095 void endTriangles();
01096
01097
01098
01099
01100 void beginTriangleFan();
01101 void endTriangleFan();
01102
01103
01104
01105
01106
01107
01108 void beginTriMesh();
01109 void endTriMesh();
01110 void beginQuads();
01111 void endQuads();
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123 void beginQuadStrip();
01124 void endQuadStrip();
01125
01126 void v2DS(const short v[2]) { myVtxOut->v2DS(v); }
01127 void v2DI(const int v[2]) { myVtxOut->v2DI(v); }
01128 void v2DW(const float v[2]) { myVtxOut->v2DW(v); }
01129 void v3DS(const short v[3]) { myVtxOut->v3DS(v); }
01130 void v3DI(const int v[3]) { myVtxOut->v3DI(v); }
01131 void v3DW(const float v[3]) { myVtxOut->v3DW(v); }
01132
01133
01134
01135
01136
01137 void vertex2DI(int x, int y) { myVtxOut->vertex2DI(x, y); }
01138 void vertex2DS(short x, short y) { myVtxOut->vertex2DS(x, y); }
01139 void vertex2DW(float x, float y) { myVtxOut->vertex2DW(x, y); }
01140 void vertex3DI(int x, int y, int z)
01141 { myVtxOut->vertex3DS(x, y, z); }
01142 void vertex3DS(short x, short y, short z)
01143 { myVtxOut->vertex3DS(x, y, z); }
01144 void vertex3DW(float x, float y, float z)
01145 { myVtxOut->vertex3DW(x, y, z); }
01146
01147 #define SETGLCOLOR(r,g,b,a) \
01148 UT_ASSERT(a != -1); \
01149 myState->pushColorBuf(); \
01150 myState->myGLColor[0] = r; \
01151 myState->myGLColor[1] = g; \
01152 myState->myGLColor[2] = b; \
01153 myState->myGLColor[3] = a;
01154
01155 void c3DS(const short v[3])
01156 {
01157 myVtxOut->c3DS(v);
01158 SETGLCOLOR(v[0]/32768.0f, v[1]/32768.0f,
01159 v[2]/32768.0f, 1.0f);
01160 }
01161 void c3DW(const float v[3])
01162 {
01163 myVtxOut->c3DW(v);
01164 SETGLCOLOR(v[0], v[1], v[2], 1.0f);
01165 }
01166 void c4DW(const float v[4])
01167 {
01168 myVtxOut->c4DW(v);
01169 SETGLCOLOR(v[0], v[1], v[2], v[3]);
01170 }
01171 void cacheC3DW(const float v[3])
01172 {
01173 if (v[0] != myState->myGLColor[0] ||
01174 v[1] != myState->myGLColor[1] ||
01175 v[2] != myState->myGLColor[2] ||
01176 1.0f != myState->myGLColor[3])
01177 {
01178 c3DW(v);
01179 }
01180
01181 }
01182 void cacheC4DW(const float v[4])
01183 {
01184 if (v[0] != myState->myGLColor[0] ||
01185 v[1] != myState->myGLColor[1] ||
01186 v[2] != myState->myGLColor[2] ||
01187 v[3] != myState->myGLColor[3])
01188 {
01189 c4DW(v);
01190 }
01191 }
01192 #undef SETGLCOLOR
01193
01194 void n3DW(const float v[3]) { myVtxOut->n3DW(v); }
01195 void t2DW(const float v[2]) { myVtxOut->t2DW(v); }
01196 void t3DW(const float v[3]) { myVtxOut->t3DW(v); }
01197 void t4DW(const float v[4]) { myVtxOut->t4DW(v); }
01198 void mt2DW(const float v[2], unsigned int tclayer);
01199 void mt3DW(const float v[3], unsigned int tclayer);
01200 void a1DW(unsigned int loc, const float v[1])
01201 { myVtxOut->a1DW(loc, v); }
01202 void a2DW(unsigned int loc, const float v[2])
01203 { myVtxOut->a2DW(loc, v); }
01204 void a3DW(unsigned int loc, const float v[3])
01205 { myVtxOut->a3DW(loc, v); }
01206 void a4DW(unsigned int loc, const float v[4])
01207 { myVtxOut->a4DW(loc, v); }
01208
01209 void move2DW(float x, float y);
01210 void move2DS(short x, short y);
01211 void move3DW(float x, float y, float z);
01212 void move3DS(short x, short y, short z);
01213 void rmove2DW(float x, float y);
01214 void rmove2DS(short x, short y);
01215 void rmove3DW(float x, float y, float z);
01216 void rmove3DS(short x, short y, short z);
01217 void draw2DW(float x, float y);
01218 void draw2DS(short x, short y);
01219 void draw3DW(float x, float y, float z);
01220 void draw3DS(short x, short y, short z);
01221 void rdraw2DW(float x, float y);
01222 void rdraw2DS(short x, short y);
01223 void rdraw3DW(float x, float y, float z);
01224 void rdraw3DS(short x, short y, short z);
01225
01226 void enable( int state ) { enabled = state; }
01227
01228
01229
01230 static void destroyShaderObject(unsigned int progid, bool unreg,
01231 bool shader);
01232 static void destroyTextureObject(unsigned int texid, RE_OGLTexture *tex);
01233 static void destroyFramebufferObject(unsigned int fbo);
01234 static void destroyRenderbufferObject(unsigned int rb);
01235 static void destroyBufferObject(unsigned int buf);
01236 static void destroyDisplayList(unsigned int list);
01237 static void destroyOcclusionQuery(unsigned int query);
01238
01239
01240 #if RE_CHECK_STATE == 4
01241 #define CHECK_STATE(name, flag, expected) \
01242 if(!inObjectDefine()) \
01243 { int s; ::glGetIntegerv(flag, &s); UT_ASSERT(s == expected); }
01244 #else
01245 #define CHECK_STATE(n,f,e) { }
01246 #endif
01247
01248
01249 #define RE_FLAG_STATE(RE_NAME,GL_FLAG) \
01250 void enable##RE_NAME () { if( myState->my##RE_NAME##State != 1 ) { myState->pushEnable(); ::glEnable( GL_FLAG ); myState->my##RE_NAME##State = 1; } else CHECK_STATE(RE_NAME,GL_FLAG, 1); } \
01251 void disable##RE_NAME () { if( myState->my##RE_NAME##State != 0 ) { myState->pushEnable(); ::glDisable( GL_FLAG ); myState->my##RE_NAME##State = 0; } else CHECK_STATE(RE_NAME,GL_FLAG,0); } \
01252 bool get##RE_NAME () { if(myState->my##RE_NAME##State == 3) update##RE_NAME(); return (myState->my##RE_NAME##State ==1); } \
01253 void update##RE_NAME () { myState->my##RE_NAME##State = ::glIsEnabled( GL_FLAG ); } \
01254 void invalidate##RE_NAME() { myState->my##RE_NAME##State = 3; }
01255
01256 RE_FLAG_STATE(ColorMaterial,GL_COLOR_MATERIAL);
01257 RE_FLAG_STATE(DepthCueing,GL_FOG);
01258 RE_FLAG_STATE(DepthTest,GL_DEPTH_TEST);
01259 RE_FLAG_STATE(Dither,GL_DITHER);
01260 RE_FLAG_STATE(Lighting,GL_LIGHTING);
01261 RE_FLAG_STATE(Scissor,GL_SCISSOR_TEST);
01262 RE_FLAG_STATE(AlphaTest,GL_ALPHA_TEST);
01263 RE_FLAG_STATE(LineSmoothing,GL_LINE_SMOOTH);
01264 RE_FLAG_STATE(PointSmoothing,GL_POINT_SMOOTH);
01265 RE_FLAG_STATE(Stencil,GL_STENCIL_TEST);
01266 #undef RE_FLAG_STATE
01267
01268 #define RE_FLAG_11_STATE(RE_NAME,GL_FLAG) \
01269 void enable##RE_NAME () { if( (myState->my##RE_NAME##State) != 1 && hasGL11() ) { myState->pushEnable(); ::glEnable( GLenum(GL_FLAG) ); myState->my##RE_NAME##State = 1; } else if(hasGL11()) CHECK_STATE(RE_NAME,GL_FLAG,1); } \
01270 void disable##RE_NAME () { if( myState->my##RE_NAME##State && hasGL11() ) { myState->pushEnable(); ::glDisable( GLenum(GL_FLAG) ); myState->my##RE_NAME##State = 0; } else if(hasGL11()) CHECK_STATE(RE_NAME, GL_FLAG, 0); } \
01271 bool get##RE_NAME () { if(myState->my##RE_NAME##State == 3) update##RE_NAME(); return (myState->my##RE_NAME##State==1) ; } \
01272 void update##RE_NAME () { if( hasGL11() ) { myState->my##RE_NAME##State = ::glIsEnabled( GLenum(GL_FLAG) ); } else { myState->my##RE_NAME##State = 0; } } \
01273 void invalidate##RE_NAME() { if(hasGL11()) myState->my##RE_NAME##State=3; }
01274
01275 RE_FLAG_11_STATE(PointOffset,GL_POLYGON_OFFSET_POINT);
01276 RE_FLAG_11_STATE(LineOffset,GL_POLYGON_OFFSET_LINE);
01277 RE_FLAG_11_STATE(FillOffset,GL_POLYGON_OFFSET_FILL);
01278 #undef RE_FLAG_11_STATE
01279
01280
01281
01282 private:
01283 RE_PolyOffStrategy getPolygonOffsetStrategy() const;
01284 void updateOffsetAmount();
01285
01286 GLint getOGLMatrixMode();
01287 void setOGLMatrixMode( GLint mode );
01288 void updateOGLMaxClipPlanes();
01289
01290 static void initTextureCache();
01291 static void initTexture3DCache();
01292 static bool initGLVersionInfo();
01293 void initGLState();
01294 void initGLExtensions();
01295 void updateGLState();
01296 void updateStacks();
01297 void switchTexture(int textureunit, RE_OGLTexture *texture);
01298
01299
01300 inline int setConcave(int concave);
01301 UT_Bool updateRGBmode();
01302 static void determineTwinView();
01303 void switchContextForRender();
01304
01305 RE_CacheObject *allocRenderCache (bool smart_object);
01306 void beginCache ( RE_CacheObject *list);
01307 void executeCache ( RE_CacheObject *list);
01308 void endCache(bool push_attribs);
01309
01310 #if RE_OGL_SINGLE_CONTEXT
01311 void makeWindowCurrent(RE_Window *win);
01312 #endif
01313
01314 #ifdef WIN32
01315 public:
01316
01317
01318 static void internalAddScreen(UT_DimRect rect)
01319 { theScreens.append(rect); }
01320 static void internalAddWorkArea(UT_DimRect rect)
01321 { theWorkAreas.append(rect); }
01322 private:
01323 #endif
01324
01325 void updateBlendSmoothState();
01326 int privPushBlendSmoothState(bool smooth_too);
01327 void privPopBlendSmoothState(bool smooth_too, int *idx);
01328
01329
01330 void preDrawPixels( int allowDither = TRUE );
01331 void postDrawPixels();
01332 void initRasterCopy();
01333
01334 void freePendingObjects();
01335
01336
01337 void updateViewport();
01338
01339 void resetAmbientLight();
01340
01341 #if ! RE_OGL_SINGLE_CONTEXT
01342 RE_LightVal *validateLight(const RE_Light &light);
01343 #endif
01344
01345 RE_LightVal *validateLightIndex(unsigned index);
01346 void turnLightOn(unsigned int index);
01347 void turnLightOff(unsigned int index);
01348
01349 void displayClippedRaster(const unsigned char *base, int offset,
01350 int psize, int w, int h,
01351 GLenum type, GLenum format,
01352 float x, float y);
01353
01354 void setState( RE_State currentState, RE_State newState, int push);
01355
01356 UT_DimRect adjustFramebufferViewport(const UT_DimRect &rect, bool to_fbo);
01357
01358
01359 static RE_ZFunction oglToREzfunc( int oglZFunc );
01360 static int reToOGLzfunc( RE_ZFunction reZFunc );
01361 static RE_SFunction oglToREsfunc( int oglSFunc );
01362 static int reToOGLsfunc( RE_SFunction reSFunc );
01363 static RE_SOperation oglToREsoperation( int oglSOperation );
01364 static int reToOGLsoperation( RE_SOperation reSOperation );
01365
01366 private:
01367
01368
01369
01370 RE_OGLState *myState;
01371 RE_OGLState myNormalState;
01372 RE_OGLState myListState;
01373
01374
01375
01376
01377 bool myFirstInitialize;
01378 int beginBegun;
01379 int enabled;
01380 bool myPicking;
01381
01382 RE_OGLExt *myExt;
01383 RE_Window *currentWindow;
01384 RE_Window *mySavedMainThreadCurrentWindow;
01385
01386 RE_OGLVertex *myVtxOut;
01387
01388 #ifndef CELLBE
01389 RE_Tesselator *tesselator;
01390 #endif
01391 uint *pickBuffer;
01392 uint *realPickBuffer;
01393 long pickBufferSize;
01394
01395 float pickLeft;
01396 float pickRight;
01397 float pickBottom;
01398 float pickTop;
01399
01400 short currentDisplayMode;
01401 short currentDrawingMode;
01402 short currentMapSize;
01403
01404 short overlayMode;
01405 short fullScreenOverlayActive;
01406 UT_Bool isRGBmode;
01407 RE_OGLContext pushedGraphicsContext;
01408
01409 #if ! RE_OGL_SINGLE_CONTEXT
01410 RE_OGLContext myContext;
01411 bool myContextInitialized;
01412 OGLDrawable myDrawable;
01413 OGLDrawable myPushedDrawable;
01414
01415 UT_RecursiveSpinLock myOpenGLLock;
01416 int myOpenGLContextLockCount;
01417 #endif
01418
01419
01420 int myMaxTextureUnits;
01421 int myMaxTextureCoords;
01422 int myMaxTextureShaderUnits;
01423 int myMaxTextureVertexUnits;
01424 int myMaxTextureFragmentUnits;
01425 int myMaxTextureSize;
01426 int myMaxTexture3DSize;
01427 int myMaxTextureAnisotropy;
01428 GLint maxClipPlanes;
01429
01430 int myFloatZoomSupported;
01431 float myDefaultStacklessColor[4];
01432
01433 bool myFrontBufferDirty;
01434 int myXORDrawCount;
01435 RE_RenderBuf myDrawBuffer[RE_BUFFER_STACK_SIZE];
01436 int myDrawBufferIndex;
01437 RE_RenderBuf myReadBuffer[RE_BUFFER_STACK_SIZE];
01438 int myReadBufferIndex;
01439
01440 bool myMultisampleEnable;
01441
01442 int currGLError;
01443 int drawPixelsMode;
01444
01445 bool myInObjectDefine;
01446 bool myTrackingObjectShaderUsage;
01447 bool myTrackingObjectTextureUsage;
01448 bool myProjectingTexture;
01449
01450 void *saveBuffer;
01451 unsigned saveSize;
01452
01453 short cacheIndex;
01454
01455 RE_State stateStack[RE_STACK_DEPTH];
01456 short stateIndex;
01457
01458 #if RE_OGL_SINGLE_CONTEXT
01459 RE_Window *contextStack[CONTEXT_STACK_SIZE];
01460 short contextStackIndex;
01461 #endif
01462
01463 IMG_Raster *iconImage;
01464 RE_IconLoader iconLoader;
01465
01466 #ifndef CELLBE
01467 GLUquadricObj *filledQuadric();
01468 GLUquadricObj *unfilledQuadric();
01469 GLUquadricObj *myFilledQuadric, *myUnfilledQuadric;
01470 #endif
01471
01472
01473 RE_Uniform *myBuiltInUniforms[RE_UNIFORM_BUILT_IN__count];
01474 bool myBuiltInUniformsOwned[RE_UNIFORM_BUILT_IN__count];
01475
01476
01477 UT_RefArray<RE_LightVal> myLightArray;
01478 int * myLightStates;
01479 RE_Uniform *myLightEnabledUniform;
01480 unsigned myNumLightStates;
01481 bool myNormalizeGlobalAmbient;
01482 unsigned myLightModelSet:1,
01483 myUseOGLSpots:1,
01484 myAllowLightSpecular:1;
01485 int myViewportFontOffsetX, myViewportFontOffsetY;
01486 RE_CacheObject *myCurrentList;
01487 UT_PtrArray<re_UniformEntry *> myUniformStack;
01488
01489 RE_OGLTexture *myRandomTexture;
01490 unsigned int myRandomTexSeed;
01491 bool myRandomTexInterp;
01492
01493 RE_OcclusionQuery *myActiveQuery;
01494
01495 RE_Material *myMaterialStack[RE_MAX_TEXTURE_STATE_STACK];
01496 bool myMaterialTextureStack[RE_MAX_TEXTURE_STATE_STACK];
01497 int myMaterialLayerStack[RE_MAX_TEXTURE_STATE_STACK];
01498 bool myMaterialAlphaTest;
01499 bool myMaterialLighting;
01500 int myMatStackIndex;
01501
01502
01503
01504 static int majorGLVersion;
01505 static int minorGLVersion;
01506 int majorGLSLVersion;
01507 int minorGLSLVersion;
01508
01509 static RE_Server *theServer;
01510 static short theXRes;
01511 static short theYRes;
01512 static short theVirtualX;
01513 static short theVirtualY;
01514 static short theDotsPerInch;
01515 static bool theSmoothLinesAllowed;
01516
01517
01518
01519 static UT_RefArray<UT_DimRect> theScreens;
01520 static UT_RefArray<UT_DimRect> theWorkAreas;
01521
01522 static UT_Pointers theVisuals;
01523 static RE_WindowList *theWindowList;
01524 static RE_Window *theMainContextWindow;
01525
01526
01527 static RE_GraphicsDevice theDevice;
01528 static int theDriverMajor;
01529 static int theDriverMinor;
01530 static int theDriverBuild;
01531
01532 static bool theHasShadersExt;
01533 static bool theFastDisplayRasterHack;
01534
01535 static UT_IntArray thePendingDeleteTextures;
01536 static UT_IntArray thePendingDeleteShaders;
01537 static UT_IntArray thePendingDeleteShaderReg;
01538 static UT_IntArray thePendingDeleteShaderType;
01539 static UT_IntArray thePendingDeleteFBOs;
01540 static UT_IntArray thePendingDeleteRenderBuffers;
01541 static UT_IntArray thePendingDeleteBufferObjects;
01542 static UT_IntArray thePendingDeleteDisplayLists;
01543 static UT_IntArray thePendingDeleteOcclQueries;
01544 static UT_Lock thePendingDeleteLock;
01545
01546 protected:
01547 static UT_ThreadSpecificValue <RE_OGLRender*> theCurrentRender;
01548 #if ! RE_OGL_SINGLE_CONTEXT
01549 static UT_ThreadSpecificValue <RE_OGLRender*> theLastRender;
01550 #endif
01551
01552
01553 ut_thread_id_t myNativeThread;
01554 bool myIsAllowingOtherThreads;
01555 };
01556
01557 class RE_API RE_RenderAutoLock
01558 {
01559 public:
01560 RE_RenderAutoLock(RE_OGLRender *r)
01561 : myR(r)
01562 { myR->lockContextForRender(); }
01563
01564 ~RE_RenderAutoLock()
01565 { myR->unlockContextAfterRender(); }
01566 private:
01567 RE_OGLRender *myR;
01568 };
01569
01570
01571
01572
01573 class RE_API RE_SmartObject : public RE_CacheObject
01574 {
01575 public:
01576 virtual ~RE_SmartObject();
01577
01578 private:
01579 RE_SmartObject(unsigned int id);
01580
01581 UT_IntArray myShaderRefs;
01582 UT_IntArray myTextureRefs;
01583 bool myDirtyFlag;
01584
01585 friend class RE_OGLRender;
01586 };
01587
01588
01589
01590
01591 inline bool
01592 RE_OGLRender::hasGL11() { return ((majorGLVersion > 1) ||
01593 ((majorGLVersion >= 1) &&
01594 (minorGLVersion >= 1))); };
01595 inline bool
01596 RE_OGLRender::hasGL12() { return ((majorGLVersion > 1) ||
01597 ((majorGLVersion >= 1) &&
01598 (minorGLVersion >= 2))); };
01599 inline bool
01600 RE_OGLRender::hasGL13() { return ((majorGLVersion > 1) ||
01601 ((majorGLVersion >= 1) &&
01602 (minorGLVersion >= 3))); };
01603 inline bool
01604 RE_OGLRender::hasGL14() { return ((majorGLVersion > 1) ||
01605 ((majorGLVersion >= 1) &&
01606 (minorGLVersion >= 4))); };
01607 inline bool
01608 RE_OGLRender::hasGL15() { return ((majorGLVersion > 1) ||
01609 ((majorGLVersion >= 1) &&
01610 (minorGLVersion >= 5))); };
01611 inline bool
01612 RE_OGLRender::hasGL20() { return ((majorGLVersion > 2) ||
01613 ((majorGLVersion >= 2) &&
01614 (minorGLVersion >= 0))); };
01615 inline bool
01616 RE_OGLRender::hasGL21() { return ((majorGLVersion > 2) ||
01617 ((majorGLVersion >= 2) &&
01618 (minorGLVersion >= 1))); };
01619
01620 inline int RE_OGLRender::glMajorVersion() { return majorGLVersion; }
01621 inline int RE_OGLRender::glMinorVersion() { return minorGLVersion; }
01622
01623 inline int RE_OGLRender::glslMajorVersion() { return majorGLSLVersion; }
01624 inline int RE_OGLRender::glslMinorVersion() { return minorGLSLVersion; }
01625
01626 inline bool RE_OGLRender::hasShadersExt() { return theHasShadersExt; }
01627 inline void RE_OGLRender::disableShadersExt() { theHasShadersExt = false; }
01628
01629 inline RE_GraphicsDevice
01630 RE_OGLRender::getGraphicsDevice() { return theDevice; }
01631
01632 inline bool RE_OGLRender::hasDriverVersion() { return !(theDriverMajor == 0 &&
01633 theDriverMinor == 0 &&
01634 theDriverBuild == 0); }
01635 inline int RE_OGLRender::getDriverMajorVersion() { return theDriverMajor;}
01636 inline int RE_OGLRender::getDriverMinorVersion() { return theDriverMinor;}
01637 inline int RE_OGLRender::getDriverBuildVersion() { return theDriverBuild;}
01638
01639 inline RE_OGLExt *RE_OGLRender::getExt() const { return myExt; }
01640
01641 inline int RE_OGLRender::resX() { return theXRes; }
01642 inline int RE_OGLRender::resY() { return theYRes; }
01643 inline int RE_OGLRender::virtualResX() { return theVirtualX; }
01644 inline int RE_OGLRender::virtualResY() { return theVirtualY; }
01645 inline short RE_OGLRender::dpi() { return theDotsPerInch; }
01646
01647 inline void
01648 RE_OGLRender::updateScreensAndWorkAreas() { determineTwinView(); };
01649
01650 inline float
01651 RE_OGLRender::pixelsToInches(int n)
01652 {
01653 return (float)n / dpi();
01654 }
01655
01656 inline int
01657 RE_OGLRender::inchesToPixels(float i)
01658 {
01659 return (int)UTrint(i*(float)dpi());
01660 }
01661
01662 inline RE_Window *
01663 RE_OGLRender::getMainContext() { return theMainContextWindow; }
01664
01665 inline RE_OGLRender *
01666 RE_OGLRender::getCurrentRender() { return theCurrentRender.get(); }
01667
01668 inline RE_WindowList *
01669 RE_OGLRender::getWindowList() { return theWindowList; }
01670
01671 inline const RE_Window *
01672 RE_OGLRender::getCurrentWindow() const { return currentWindow; }
01673
01674 inline RE_Window *
01675 RE_OGLRender::getCurrentWindow() { return currentWindow; }
01676
01677 inline void
01678 RE_OGLRender::setIconLoader(RE_IconLoader loader)
01679 {
01680 iconLoader = loader;
01681 }
01682
01683 inline bool
01684 RE_OGLRender::isFrontBufferDirty() const
01685 { return myFrontBufferDirty;}
01686
01687 inline void
01688 RE_OGLRender::setFrontBufferDirty(bool d)
01689 { myFrontBufferDirty = d; }
01690
01691 inline int
01692 RE_OGLRender::getOGLMaxClipPlanes() { return maxClipPlanes; }
01693
01694 inline bool
01695 RE_OGLRender::isPointOffset() { return getPointOffset(); }
01696 inline bool
01697 RE_OGLRender::isLineOffset() { return getLineOffset(); }
01698
01699 inline void
01700 RE_OGLRender::pointOffset( bool onoff )
01701 {
01702 if( onoff )
01703 enablePointOffset();
01704 else
01705 disablePointOffset();
01706 }
01707
01708 inline void
01709 RE_OGLRender::lineOffset( bool onoff )
01710 {
01711 if( onoff )
01712 enableLineOffset();
01713 else
01714 disableLineOffset();
01715 }
01716
01717 inline void
01718 RE_OGLRender::getOffsetAmount( float* variable, float* constant )
01719 {
01720 *variable = myState->_offset_variable;
01721 *constant = myState->_offset_constant;
01722 }
01723
01724 inline int
01725 RE_OGLRender::pushColor(const UT_Color &c, float alpha)
01726 {
01727 int nest = pushColor();
01728 setColor(c, alpha);
01729 return nest;
01730 }
01731
01732 inline void
01733 RE_OGLRender::resetColorCache()
01734 {
01735 myState->myGLColor[0] = myState->myGLColor[1] = myState->myGLColor[2]
01736 = myState->myGLColor[3] = -1.0f;
01737 }
01738
01739 inline bool
01740 RE_OGLRender::isBlending() const
01741 {
01742 return myState->myBlendSmoothStack[myState->myBlendSmoothLevel].myBlend==1;
01743 }
01744 inline int
01745 RE_OGLRender::getBlendSmoothLevel() const
01746 {
01747 return myState->myBlendSmoothLevel;
01748 }
01749
01750 inline void RE_OGLRender::allowSmoothLines(int yn) { theSmoothLinesAllowed=yn; }
01751 inline int RE_OGLRender::allowsSmoothLines() { return theSmoothLinesAllowed; }
01752
01753 inline bool RE_OGLRender::inObjectDefine() const
01754 { return myInObjectDefine; }
01755
01756 inline bool RE_OGLRender:: trackingObjectShaderUsage() const
01757 { return myTrackingObjectShaderUsage; }
01758
01759 inline bool RE_OGLRender::trackingObjectTextureUsage() const
01760 { return myTrackingObjectTextureUsage; }
01761
01762 inline int
01763 RE_OGLRender::computeTextureRes(unsigned int res)
01764 {
01765 int m = 0;
01766 unsigned int a = res;
01767 while (a >>= 1) m++;
01768 int lbound = 1 << m;
01769
01770
01771 return (res > (lbound + (lbound >> 1))) ?
01772 (lbound << 1) : lbound;
01773 }
01774
01775 inline void
01776 RE_OGLRender::setGLSpots(int f) { myUseOGLSpots = f; }
01777
01778 inline void
01779 RE_OGLRender::setAllowSpecular(int f) { myAllowLightSpecular = f; }
01780 inline int
01781 RE_OGLRender::getAllowSpecular() const { return myAllowLightSpecular; }
01782
01783 inline RE_Uniform *
01784 RE_OGLRender::getLightEnabledUniform() const
01785 { return myLightEnabledUniform; }
01786
01787 inline void
01788 RE_OGLRender::setNormalizeGlobalAmbient(bool normalize)
01789 { myNormalizeGlobalAmbient = normalize; }
01790
01791 inline bool
01792 RE_OGLRender::getNormalizeGlobalAmbient() const
01793 { return myNormalizeGlobalAmbient; }
01794
01795 inline float RE_OGLRender::getRasterX() const { return myState->rx; }
01796 inline float RE_OGLRender::getRasterY() const { return myState->ry; }
01797 inline float RE_OGLRender::getRasterZ() const { return myState->rz; }
01798
01799 inline int
01800 RE_OGLRender::getViewportFontOffsetX() const
01801 { return myViewportFontOffsetX; }
01802
01803 inline int
01804 RE_OGLRender::getViewportFontOffsetY() const
01805 { return myViewportFontOffsetY; }
01806
01807
01808 inline int
01809 RE_OGLRender::isCaching() const { return cacheIndex; }
01810
01811 inline void
01812 RE_OGLRender::setOGLMatrixMode( GLint mode )
01813 {
01814 if( myState->_matrixMode != mode )
01815 {
01816 ::glMatrixMode( GLenum(mode) );
01817 myState->_matrixMode = mode;
01818 }
01819 }
01820
01821 inline void
01822 RE_OGLRender::updateOGLMaxClipPlanes()
01823 {
01824 ::glGetIntegerv( GL_MAX_CLIP_PLANES, &maxClipPlanes );
01825 }
01826
01827 #endif