Work on new graphics (tesselated AA hardware lines, single hardware array, VBO and programatic shader generation) (thank you Hugh)
This commit is contained in:
@@ -436,6 +436,8 @@ public:
|
||||
virtual bool getMultitouchSupported() { return false; }
|
||||
virtual void setMultitouchActive(bool inActive) { }
|
||||
virtual bool getMultitouchActive() { return false; }
|
||||
|
||||
virtual uint32 getBackgroundMask() { return 0xffffffff; }
|
||||
|
||||
Matrix GetFullMatrix(bool inStageScaling);
|
||||
bool FinishEditOnEnter();
|
||||
|
||||
@@ -456,84 +456,10 @@ struct RenderState
|
||||
};
|
||||
|
||||
|
||||
void ResetHardwareContext();
|
||||
class HardwareData;
|
||||
class HardwareContext;
|
||||
|
||||
|
||||
|
||||
enum PrimType { ptTriangleFan, ptTriangleStrip, ptTriangles, ptLineStrip, ptPoints, ptLines };
|
||||
|
||||
struct DrawElement
|
||||
{
|
||||
uint8 mPrimType;
|
||||
bool mBitmapRepeat;
|
||||
bool mBitmapSmooth;
|
||||
int mFirst;
|
||||
int mCount;
|
||||
uint32 mColour;
|
||||
float mWidth;
|
||||
StrokeScaleMode mScaleMode;
|
||||
};
|
||||
|
||||
typedef QuickVec<DrawElement> DrawElements;
|
||||
typedef QuickVec<UserPoint> Vertices;
|
||||
typedef QuickVec<UserPoint> TexCoords;
|
||||
typedef QuickVec<int> Colours;
|
||||
|
||||
void ReleaseVertexBufferObject(unsigned int inVBO);
|
||||
|
||||
void ConvertOutlineToTriangles(Vertices &ioOutline,const QuickVec<int> &inSubPolys);
|
||||
|
||||
struct HardwareArrays
|
||||
{
|
||||
enum
|
||||
{
|
||||
BM_ADD = 0x00000001,
|
||||
PERSPECTIVE = 0x00000002,
|
||||
RADIAL = 0x00000004,
|
||||
BM_MULTIPLY = 0x00000008,
|
||||
BM_SCREEN = 0x00000010,
|
||||
|
||||
AM_PREMULTIPLIED = 0x00000100,
|
||||
|
||||
FOCAL_MASK = 0x0000ff00,
|
||||
FOCAL_SIGN = 0x00010000,
|
||||
};
|
||||
|
||||
HardwareArrays(Surface *inSurface,unsigned int inFlags);
|
||||
~HardwareArrays();
|
||||
bool ColourMatch(bool inWantColour);
|
||||
|
||||
|
||||
DrawElements mElements;
|
||||
Vertices mVertices;
|
||||
TexCoords mTexCoords;
|
||||
Colours mColours;
|
||||
Surface *mSurface;
|
||||
unsigned int mFlags;
|
||||
//unsigned int mVertexBO;
|
||||
};
|
||||
|
||||
typedef QuickVec<HardwareArrays *> HardwareCalls;
|
||||
|
||||
class HardwareData
|
||||
{
|
||||
public:
|
||||
~HardwareData();
|
||||
|
||||
HardwareArrays &GetArrays(Surface *inSurface,bool inWithColour,unsigned int inFlags);
|
||||
|
||||
HardwareCalls mCalls;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
extern HardwareContext *gDirectRenderContext;
|
||||
|
||||
void BuildHardwareJob(const class GraphicsJob &inJob,const GraphicsPath &inPath,
|
||||
HardwareData &ioData, HardwareContext &inHardware);
|
||||
|
||||
int UpToPower2(int inX);
|
||||
inline int IsPower2(unsigned int inX) { return (inX & (inX-1))==0; }
|
||||
|
||||
|
||||
89
project/include/Hardware.h
Normal file
89
project/include/Hardware.h
Normal file
@@ -0,0 +1,89 @@
|
||||
#ifndef LIME_HARDWARE_H
|
||||
#define LIME_HARDWARE_H
|
||||
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace lime
|
||||
{
|
||||
|
||||
void ResetHardwareContext();
|
||||
|
||||
typedef QuickVec<UserPoint> Vertices;
|
||||
|
||||
enum PrimType { ptTriangleFan, ptTriangleStrip, ptTriangles, ptLineStrip, ptPoints, ptLines };
|
||||
|
||||
enum
|
||||
{
|
||||
DRAW_HAS_COLOUR = 0x00000001,
|
||||
DRAW_HAS_NORMAL = 0x00000002,
|
||||
DRAW_HAS_PERSPECTIVE = 0x00000004,
|
||||
DRAW_RADIAL = 0x00000008,
|
||||
|
||||
DRAW_HAS_TEX = 0x00000010,
|
||||
DRAW_BMP_REPEAT = 0x00000020,
|
||||
DRAW_BMP_SMOOTH = 0x00000040,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct DrawElement
|
||||
{
|
||||
uint8 mFlags;
|
||||
uint8 mPrimType;
|
||||
uint8 mBlendMode;
|
||||
uint8 mScaleMode;
|
||||
short mRadialPos;
|
||||
|
||||
uint8 mStride;
|
||||
int mCount;
|
||||
|
||||
int mVertexOffset;
|
||||
int mTexOffset;
|
||||
int mColourOffset;
|
||||
int mNormalOffset;
|
||||
|
||||
uint32 mColour;
|
||||
Surface *mSurface;
|
||||
|
||||
// For ptLineStrip/ptLines
|
||||
float mWidth;
|
||||
|
||||
};
|
||||
|
||||
typedef QuickVec<DrawElement> DrawElements;
|
||||
|
||||
class HardwareData
|
||||
{
|
||||
public:
|
||||
HardwareData();
|
||||
~HardwareData();
|
||||
|
||||
void releaseVbo();
|
||||
float scaleOf(const RenderState &inState) const;
|
||||
bool isScaleOk(const RenderState &inState) const;
|
||||
void clear();
|
||||
|
||||
DrawElements mElements;
|
||||
QuickVec<uint8> mArray;
|
||||
float mMinScale;
|
||||
float mMaxScale;
|
||||
|
||||
mutable HardwareContext *mVboOwner;
|
||||
mutable int mRendersWithoutVbo;
|
||||
mutable unsigned int mVertexBo;
|
||||
mutable int mContextId;
|
||||
};
|
||||
|
||||
|
||||
void ConvertOutlineToTriangles(Vertices &ioOutline,const QuickVec<int> &inSubPolys);
|
||||
|
||||
extern HardwareContext *gDirectRenderContext;
|
||||
|
||||
void BuildHardwareJob(const class GraphicsJob &inJob,const GraphicsPath &inPath,
|
||||
HardwareData &ioData, HardwareContext &inHardware,const RenderState &inState);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -27,14 +27,6 @@ enum PixelFormat
|
||||
pfSwapRB = 0x02,
|
||||
};
|
||||
|
||||
enum AlphaMode
|
||||
{
|
||||
amUnknown = 0x00,
|
||||
amPremultiplied = 0x01,
|
||||
amStraight = 0x02,
|
||||
amIgnore = 0x03,
|
||||
};
|
||||
|
||||
|
||||
typedef unsigned char Uint8;
|
||||
|
||||
|
||||
@@ -23,12 +23,13 @@ namespace lime {
|
||||
virtual void Clear (uint32 inColour, const Rect *inRect = 0) = 0;
|
||||
virtual class Texture *CreateTexture (class Surface *inSurface, unsigned int inFlags) = 0;
|
||||
virtual void DestroyNativeTexture (void *inNativeTexture) = 0;
|
||||
virtual void DestroyVbo (unsigned int inVbo) = 0;
|
||||
virtual void EndBitmapRender () = 0;
|
||||
virtual void EndRender () = 0;
|
||||
virtual void Flip () = 0;
|
||||
virtual int Height () const = 0;
|
||||
virtual bool Hits (const RenderState &inState, const HardwareCalls &inCalls);
|
||||
virtual void Render (const RenderState &inState, const HardwareCalls &inCalls) = 0;
|
||||
virtual bool Hits (const RenderState &inState, const HardwareData &inData);
|
||||
virtual void Render (const RenderState &inState, const HardwareData &inData) = 0;
|
||||
virtual void RenderBitmap (const Rect &inSrc, int inX, int inY) = 0;
|
||||
virtual void SetQuality (StageQuality inQuality) = 0;
|
||||
virtual void SetViewport (const Rect &inRect) = 0;
|
||||
@@ -41,4 +42,4 @@ namespace lime {
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace lime {
|
||||
void Clear (uint32 inColour, const Rect *inRect = 0) { mHardware->Clear (inColour, inRect); }
|
||||
void EndRender () { mHardware->EndRender (); }
|
||||
PixelFormat Format () const { return pfHardware; }
|
||||
AlphaMode GetAlphaMode () const { return mAlphaMode; }
|
||||
const uint8 *GetBase () const { return 0; }
|
||||
int GetStride () const { return 0; }
|
||||
int Height () const { return mHardware->Height (); }
|
||||
@@ -38,7 +37,6 @@ namespace lime {
|
||||
|
||||
private:
|
||||
|
||||
AlphaMode mAlphaMode;
|
||||
HardwareContext *mHardware;
|
||||
|
||||
};
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace lime {
|
||||
virtual void colorTransform (const Rect &inRect, ColorTransform &inTransform);
|
||||
virtual void StretchTo (const RenderTarget &outTarget, const Rect &inSrcRect, const DRect &inDestRect) const;
|
||||
|
||||
virtual void setAlphaMode (AlphaMode am) { mAlphaMode = am; }
|
||||
virtual void setGPUFormat (PixelFormat pf) { mGPUPixelFormat = pf; }
|
||||
|
||||
void applyFilter (Surface *inSrc, const Rect &inRect, ImagePoint inOffset, Filter *inFilter);
|
||||
@@ -43,7 +42,6 @@ namespace lime {
|
||||
void Zero ();
|
||||
|
||||
PixelFormat Format () const { return mPixelFormat; }
|
||||
AlphaMode GetAlphaMode () const { return mAlphaMode; }
|
||||
const uint8 *GetBase () const { return mBase; }
|
||||
int GetStride () const { return mStride; }
|
||||
int GPUFormat () const { return mGPUPixelFormat; }
|
||||
@@ -54,7 +52,6 @@ namespace lime {
|
||||
|
||||
~SimpleSurface ();
|
||||
|
||||
AlphaMode mAlphaMode;
|
||||
uint8 *mBase;
|
||||
int mGPUPixelFormat;
|
||||
int mHeight;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <ByteArray.h>
|
||||
#include "renderer/common/Texture.h"
|
||||
#include "renderer/common/HardwareContext.h"
|
||||
#include <Hardware.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
@@ -28,7 +29,6 @@ namespace lime {
|
||||
virtual void Clear (uint32 inColour, const Rect *inRect = 0) = 0;
|
||||
virtual void EndRender () = 0;
|
||||
virtual PixelFormat Format () const = 0;
|
||||
virtual AlphaMode GetAlphaMode () const = 0;
|
||||
virtual const uint8 *GetBase () const = 0;
|
||||
virtual int GetStride () const = 0;
|
||||
virtual int Height () const = 0;
|
||||
@@ -49,7 +49,6 @@ namespace lime {
|
||||
virtual int GPUFormat () const { return Format (); }
|
||||
virtual void multiplyAlpha () {}
|
||||
virtual void noise (unsigned int randomSeed, unsigned int low, unsigned int high, int channelOptions, bool grayScale) {}
|
||||
virtual void setAlphaMode (AlphaMode am) {}
|
||||
virtual void SetAllowTrans (bool inAllowTrans) { mAllowTrans = inAllowTrans; }
|
||||
virtual void SetFlags (unsigned int inFlags) { mFlags = inFlags; }
|
||||
virtual void setGPUFormat (PixelFormat pf) {}
|
||||
|
||||
@@ -200,20 +200,18 @@ namespace lime
|
||||
|
||||
Texture *OGLCreateTexture(Surface *inSurface,unsigned int inFlags);
|
||||
|
||||
enum GPUProgID
|
||||
enum
|
||||
{
|
||||
gpuNone = -1,
|
||||
gpuSolid,
|
||||
gpuColour,
|
||||
gpuColourTransform,
|
||||
gpuTexture,
|
||||
gpuTextureColourArray,
|
||||
gpuTextureTransform,
|
||||
gpuBitmap,
|
||||
gpuBitmapAlpha,
|
||||
gpuRadialGradient,
|
||||
gpuRadialFocusGradient,
|
||||
gpuSIZE,
|
||||
PROG_TEXTURE = 0x0001,
|
||||
PROG_ALPHA_TEXTURE = 0x0002,
|
||||
PROG_COLOUR_PER_VERTEX = 0x0004,
|
||||
PROG_NORMAL_DATA = 0x0008,
|
||||
PROG_RADIAL = 0x0010,
|
||||
PROG_RADIAL_FOCUS = 0x0020,
|
||||
PROG_TINT = 0x0040,
|
||||
PROG_COLOUR_OFFSET = 0x0080,
|
||||
|
||||
PROG_COUNT = 0x0100,
|
||||
};
|
||||
|
||||
typedef float Trans4x4[4][4];
|
||||
@@ -221,22 +219,22 @@ typedef float Trans4x4[4][4];
|
||||
class GPUProg
|
||||
{
|
||||
public:
|
||||
static GPUProg *create(GPUProgID inID, AlphaMode inAlphaMode);
|
||||
static GPUProg *create(unsigned int inID);
|
||||
|
||||
virtual ~GPUProg() {}
|
||||
|
||||
virtual bool bind() = 0;
|
||||
|
||||
virtual void setPositionData(const float *inData, bool inIsPerspective) = 0;
|
||||
virtual void setTexCoordData(const float *inData) = 0;
|
||||
virtual void setColourData(const int *inData) = 0;
|
||||
virtual void setColourTransform(const ColorTransform *inTransform) = 0;
|
||||
virtual int getTextureSlot() = 0;
|
||||
|
||||
virtual void disableSlots() = 0;
|
||||
virtual void setTransform(const Trans4x4 &inTrans) = 0;
|
||||
virtual void setTint(unsigned int inColour) = 0;
|
||||
virtual void setColourTransform(const ColorTransform *inTransform, unsigned int inColour) = 0;
|
||||
virtual void setGradientFocus(float inFocus) = 0;
|
||||
virtual void finishDrawing() = 0;
|
||||
|
||||
int vertexSlot;
|
||||
int textureSlot;
|
||||
int normalSlot;
|
||||
int colourSlot;
|
||||
|
||||
};
|
||||
|
||||
void InitOGL2Extensions();
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
#ifndef RENDERER_OPENGL2_CONTEXT_H
|
||||
#define RENDERER_OPENGL2_CONTEXT_H
|
||||
|
||||
|
||||
#include "OpenGLContext.h"
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
class OpenGL2Context : public OpenGLContext {
|
||||
|
||||
public:
|
||||
|
||||
OpenGL2Context (WinDC inDC, GLCtx inOGLCtx);
|
||||
~OpenGL2Context ();
|
||||
|
||||
virtual void CombineModelView (const Matrix &inModelView);
|
||||
virtual void FinishBitmapRender ();
|
||||
virtual void FinishDrawing ();
|
||||
virtual void OnBeginRender ();
|
||||
virtual void PopBitmapMatrix ();
|
||||
virtual void PrepareBitmapRender ();
|
||||
virtual bool PrepareDrawing ();
|
||||
virtual void PushBitmapMatrix ();
|
||||
virtual void SetBitmapData (const float *inPos, const float *inTex);
|
||||
virtual void SetColourArray (const int *inData);
|
||||
virtual void SetModulatingTransform (const ColorTransform *inTransform);
|
||||
virtual void setOrtho (float x0, float x1, float y0, float y1);
|
||||
virtual void SetPositionData (const float *inData, bool inPerspective);
|
||||
virtual void SetRadialGradient (bool inIsRadial, float inFocus);
|
||||
virtual void SetSolidColour (unsigned int col);
|
||||
virtual void SetTexture (Surface *inSurface, const float *inTexCoords);
|
||||
|
||||
Trans4x4 mBitmapTrans;
|
||||
const int *mColourArray;
|
||||
GPUProg *mCurrentProg;
|
||||
const ColorTransform *mColourTransform;
|
||||
bool mIsRadial;
|
||||
double mOffsetX;
|
||||
double mOffsetY;
|
||||
const float *mPosition;
|
||||
bool mPositionPerspective;
|
||||
GPUProg *mProg[gpuSIZE];
|
||||
float mRadialFocus;
|
||||
double mScaleX;
|
||||
double mScaleY;
|
||||
const float *mTexCoords;
|
||||
Surface *mTextureSurface;
|
||||
Trans4x4 mTrans;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -17,34 +17,21 @@ namespace lime {
|
||||
OpenGLContext (WinDC inDC, GLCtx inOGLCtx);
|
||||
~OpenGLContext ();
|
||||
|
||||
virtual void CombineModelView (const Matrix &inModelView);
|
||||
virtual void FinishDrawing ();
|
||||
virtual void FinishBitmapRender ();
|
||||
virtual void OnBeginRender ();
|
||||
virtual void PopBitmapMatrix ();
|
||||
virtual void PrepareBitmapRender ();
|
||||
virtual bool PrepareDrawing ();
|
||||
virtual void PushBitmapMatrix ();
|
||||
virtual void SetBitmapData (const float *inPos, const float *inTex);
|
||||
virtual void SetColourArray (const int *inData);
|
||||
virtual void SetModulatingTransform (const ColorTransform *inTransform);
|
||||
virtual void setOrtho (float x0,float x1, float y0, float y1);
|
||||
virtual void SetPositionData (const float *inData, bool inPerspective);
|
||||
virtual void SetRadialGradient (bool inIsRadial, float inFocus);
|
||||
virtual void SetSolidColour (unsigned int col);
|
||||
virtual void SetTexture (Surface *inSurface, const float *inTexCoords);
|
||||
|
||||
void BeginBitmapRender (Surface *inSurface, uint32 inTint, bool inRepeat, bool inSmooth);
|
||||
void BeginRender (const Rect &inRect, bool inForHitTest);
|
||||
void Clear (uint32 inColour, const Rect *inRect);
|
||||
void CombineModelView (const Matrix &inModelView);
|
||||
Texture *CreateTexture (Surface *inSurface, unsigned int inFlags);
|
||||
void DestroyNativeTexture (void *inNativeTexture);
|
||||
void DestroyVbo (unsigned int inVbo);
|
||||
void EndBitmapRender ();
|
||||
void EndRender ();
|
||||
void Flip ();
|
||||
void Render (const RenderState &inState, const HardwareCalls &inCalls);
|
||||
void Render (const RenderState &inState, const HardwareData &inData);
|
||||
void RenderBitmap (const Rect &inSrc, int inX, int inY);
|
||||
void RenderData (const HardwareData &inData, const ColorTransform *ctrans, const Trans4x4 &inTrans);
|
||||
void SetLineWidth (double inWidth);
|
||||
void setOrtho (float x0, float x1, float y0, float y1);
|
||||
void SetQuality (StageQuality inQ);
|
||||
void SetViewport (const Rect &inRect);
|
||||
void SetWindowSize (int inWidth, int inHeight);
|
||||
@@ -52,10 +39,9 @@ namespace lime {
|
||||
int Height () const { return mHeight; }
|
||||
int Width () const { return mWidth; }
|
||||
|
||||
AlphaMode mAlphaMode;
|
||||
Surface *mBitmapSurface;
|
||||
HardwareData mBitmapBuffer;
|
||||
Texture *mBitmapTexture;
|
||||
bool mColourArrayEnabled;
|
||||
Trans4x4 mBitmapTrans;
|
||||
WinDC mDC;
|
||||
int mHeight;
|
||||
double mLineScaleH;
|
||||
@@ -63,21 +49,25 @@ namespace lime {
|
||||
double mLineScaleV;
|
||||
double mLineWidth;
|
||||
Matrix mModelView;
|
||||
double mOffsetX;
|
||||
double mOffsetY;
|
||||
GLCtx mOGLCtx;
|
||||
bool mPointSmooth;
|
||||
bool mPointsToo;
|
||||
GPUProg *mProg[PROG_COUNT];
|
||||
StageQuality mQuality;
|
||||
double mScaleX;
|
||||
double mScaleY;
|
||||
ThreadId mThreadId;
|
||||
uint32 mTint;
|
||||
bool mUsingBitmapMatrix;
|
||||
Trans4x4 mTrans;
|
||||
Rect mViewport;
|
||||
int mWidth;
|
||||
QuickVec<GLuint> mZombieTextures;
|
||||
|
||||
QuickVec<GLuint> mZombieVbos;
|
||||
|
||||
};
|
||||
|
||||
|
||||
const double one_on_255 = 1.0 / 255.0;
|
||||
const double one_on_256 = 1.0 / 256.0;
|
||||
static GLuint sgOpenglType[] = { GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, GL_TRIANGLES, GL_LINE_STRIP, GL_POINTS, GL_LINES };
|
||||
|
||||
|
||||
|
||||
@@ -12,24 +12,19 @@ namespace lime {
|
||||
|
||||
public:
|
||||
|
||||
OpenGLProgram (const char *inVertProg, const char *inFragProg, AlphaMode inAlphaMode);
|
||||
OpenGLProgram (const std::string &inVertProg, const std::string &inFragProg);
|
||||
virtual ~OpenGLProgram ();
|
||||
|
||||
virtual bool bind ();
|
||||
virtual void setGradientFocus (float inFocus);
|
||||
|
||||
GLuint createShader (GLuint inType, const char *inShader);
|
||||
void finishDrawing ();
|
||||
void disableSlots ();
|
||||
int getTextureSlot ();
|
||||
void recreate ();
|
||||
void setColourData (const int *inData);
|
||||
void setColourTransform (const ColorTransform *inTransform);
|
||||
void setPositionData (const float *inData, bool inIsPerspective);
|
||||
void setTexCoordData (const float *inData);
|
||||
void setTint (unsigned int inColour);
|
||||
void setColourTransform (const ColorTransform *inTransform, unsigned int inColour);
|
||||
void setTransform (const Trans4x4 &inTrans);
|
||||
|
||||
AlphaMode mAlphaMode;
|
||||
GLint mASlot;
|
||||
GLint mColourArraySlot;
|
||||
GLint mColourOffsetSlot;
|
||||
@@ -37,17 +32,19 @@ namespace lime {
|
||||
const ColorTransform *mColourTransform;
|
||||
int mContextVersion;
|
||||
GLuint mFragId;
|
||||
const char *mFragProg;
|
||||
std::string mFragProg;
|
||||
GLint mFXSlot;
|
||||
GLint mImageSlot;
|
||||
GLint mOn2ASlot;
|
||||
GLuint mProgramId;
|
||||
GLint mTexCoordSlot;
|
||||
GLint mTextureSlot;
|
||||
GLint mTintSlot;
|
||||
GLint mTransformSlot;
|
||||
GLuint mVertId;
|
||||
const char *mVertProg;
|
||||
GLint mVertexSlot;
|
||||
std::string mVertProg;
|
||||
|
||||
//GLint colourSlot;
|
||||
//GLint normalSlot;
|
||||
//GLint textureSlot;
|
||||
//GLint vertexSlot;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user